From 751839d208b02af3d0a2329e6d75a90d51a247ff Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 10 Sep 2012 00:51:28 +0100 Subject: make comment header output work --- src/jsapi-libdom.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index 3d07161..c925ef9 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -14,10 +14,11 @@ #include "webidl-ast.h" #include "jsapi-libdom.h" -/* #define HDR_COMMENT_SEP "\n * " +#define HDR_COMMENT_PREABLE "Generated by nsgenjsapi" + +/* #define HDR_COMMENT_SEP_LEN 4 -#define HDR_COMMENT_PREABLE "Generated by nsgenjsapi"HDR_COMMENT_SEP int genbind_header_comment(char *comment) { @@ -45,6 +46,37 @@ int genbind_header_comment(char *comment) */ +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) +{ + FILE *outfile = 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; @@ -70,9 +102,13 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) { FILE *outfile = NULL; struct webidl_node *webidl_ast = NULL; + int res; - read_webidl(genbind_ast, &webidl_ast); - + res = read_webidl(genbind_ast, &webidl_ast); + if (res != 0) { + fprintf(stderr, "Error reading Web IDL files\n"); + return 5; + } /* open output file */ if (outfilename == NULL) { @@ -88,6 +124,8 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) return 4; } + output_header_comments(outfile, genbind_ast); + /* fprintf(outfile, " %s\n \n\n", genbind_ast->hdr_comments); fprintf(outfile, "%s", genbind_ast->preamble); -- cgit v1.2.3