/* binding output generator for jsapi(spidermonkey) to libdom * * This file is part of nsgenjsbind. * Licensed under the MIT License, * http://www.opensource.org/licenses/mit-license.php * Copyright 2012 Vincent Sanders */ #include #include #include #include #include "options.h" #include "genjsbind-ast.h" #include "webidl-ast.h" #include "jsapi-libdom.h" #define HDR_COMMENT_SEP "\n * " #define HDR_COMMENT_PREABLE "Generated by nsgenjsapi" static int webidl_hdrcomments_cb(struct genbind_node *node, void *ctx) { FILE *outfile = ctx; char *txt; txt = genbind_node_gettext(node); fprintf(outfile, HDR_COMMENT_SEP"%s",txt); return 0; } static int webidl_hdrcomment_cb(struct genbind_node *node, void *ctx) { genbind_node_for_each_type(genbind_node_getnode(node), GENBIND_NODE_TYPE_STRING, webidl_hdrcomments_cb, ctx); return 0; } static int output_header_comments(FILE *outfile, struct genbind_node *genbind_ast) { fprintf(outfile, "/* "HDR_COMMENT_PREABLE); genbind_node_for_each_type(genbind_ast, GENBIND_NODE_TYPE_HDRCOMMENT, webidl_hdrcomment_cb, outfile); fprintf(outfile,"\n */\n\n"); return 0; } static int webidl_file_cb(struct genbind_node *node, void *ctx) { struct webidl_node **webidl_ast = ctx; char *filename; filename = genbind_node_gettext(node); return webidl_parsefile(filename, webidl_ast); } static int read_webidl(struct genbind_node *genbind_ast, struct webidl_node **webidl_ast) { return genbind_node_for_each_type(genbind_ast, GENBIND_NODE_TYPE_WEBIDLFILE, webidl_file_cb, webidl_ast); } int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) { FILE *outfile = NULL; struct webidl_node *webidl_ast = NULL; int res; res = read_webidl(genbind_ast, &webidl_ast); if (res != 0) { fprintf(stderr, "Error reading Web IDL files\n"); return 5; } if (options->verbose) { webidl_ast_dump(webidl_ast); } /* open output file */ if (outfilename == NULL) { outfile = stdout; } else { outfile = fopen(outfilename, "w"); } if (!outfile) { fprintf(stderr, "Error opening output %s: %s\n", outfilename, strerror(errno)); return 4; } output_header_comments(outfile, genbind_ast); /* fprintf(outfile, " %s\n \n\n", genbind_ast->hdr_comments); fprintf(outfile, "%s", genbind_ast->preamble); fprintf(outfile, " interface %s \n\n", genbind_ast->ifname); */ fclose(outfile); return 0; }