summaryrefslogtreecommitdiff
path: root/src/genjsbind-ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/genjsbind-ast.c')
-rw-r--r--src/genjsbind-ast.c67
1 files changed, 21 insertions, 46 deletions
diff --git a/src/genjsbind-ast.c b/src/genjsbind-ast.c
index ccadc7f..a2e17df 100644
--- a/src/genjsbind-ast.c
+++ b/src/genjsbind-ast.c
@@ -31,56 +31,58 @@ extern int genjsbind_parse(void);
#define HDR_COMMENT_PREABLE "Generated by nsgenjsapi"HDR_COMMENT_SEP
/* current state */
-static char *hdr_comments = NULL;
-static char *preamble = NULL;
-static char *ifname;
+struct genbind_ast *genbind_ast;
-int genjsbind_header_comment(char *comment)
+int genbind_header_comment(char *comment)
{
char *fullstr;
int fulllen;
- fulllen = strlen(hdr_comments) + strlen(comment) + HDR_COMMENT_SEP_LEN + 1;
+ fulllen = strlen(genbind_ast->hdr_comments) +
+ strlen(comment) + HDR_COMMENT_SEP_LEN + 1;
fullstr = malloc(fulllen);
- snprintf(fullstr, fulllen, "%s"HDR_COMMENT_SEP"%s", hdr_comments , comment);
- free(hdr_comments);
+ snprintf(fullstr, fulllen, "%s"HDR_COMMENT_SEP"%s", genbind_ast->hdr_comments , comment);
+ free(genbind_ast->hdr_comments);
free(comment);
- hdr_comments = fullstr;
+ genbind_ast->hdr_comments = fullstr;
return 0;
}
-int genjsbind_preamble(char *ccode)
+int genbind_preamble(char *ccode)
{
char *fullstr;
int fulllen;
- fulllen = strlen(preamble) + strlen(ccode) + 1;
+ fulllen = strlen(genbind_ast->preamble) + strlen(ccode) + 1;
fullstr = malloc(fulllen);
- snprintf(fullstr, fulllen, "%s%s", preamble , ccode);
- free(preamble);
+ snprintf(fullstr, fulllen, "%s%s", genbind_ast->preamble , ccode);
+ free(genbind_ast->preamble);
free(ccode);
- preamble = fullstr;
+ genbind_ast->preamble = fullstr;
return 0;
}
-int genjsbind_interface(char *interface)
+int genbind_interface(char *interface)
{
- ifname = interface;
+ genbind_ast->ifname = interface;
return 0;
}
static void init_state(void)
{
- /* initialise root node */
+ /* allocate state */
+ genbind_ast = calloc(1, sizeof(struct genbind_ast));
+
+ /* initialise root IDL node */
webidl_root = webidl_new_node(WEBIDL_NODE_TYPE_ROOT);
/* set default comment header text */
- hdr_comments = strdup(HDR_COMMENT_PREABLE);
+ genbind_ast->hdr_comments = strdup(HDR_COMMENT_PREABLE);
- preamble = strdup("");
+ genbind_ast->preamble = strdup("");
}
-int genjsbind_parsefile(char *infilename)
+int genbind_parsefile(char *infilename)
{
FILE *infile;
@@ -121,31 +123,4 @@ int genjsbind_parsefile(char *infilename)
}
-int genjsbind_output(char *outfilename)
-{
- FILE *outfile = NULL;
- /* 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;
- }
-
- fprintf(outfile, "/* %s\n */\n\n", hdr_comments);
-
- fprintf(outfile, "%s", preamble);
-
- fprintf(outfile, "/* interface %s */\n\n", ifname);
-
- fclose(outfile);
-
- return 0;
-}