summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2012-09-09 12:23:28 +0100
committerVincent Sanders <vince@kyllikki.org>2012-09-09 12:23:28 +0100
commit640ed1da81d909bb3c2f01a481e7e8d3336f336c (patch)
tree62213942cc809b290f5738fac6379a4d1ddc2acc /src
parent03d0a9abbd49e099e4ef522bf60d621b9092ecc5 (diff)
downloadnsgenbind-640ed1da81d909bb3c2f01a481e7e8d3336f336c.tar.gz
nsgenbind-640ed1da81d909bb3c2f01a481e7e8d3336f336c.tar.bz2
split out output geenration
Diffstat (limited to 'src')
-rw-r--r--src/Makefile2
-rw-r--r--src/genjsbind-ast.c67
-rw-r--r--src/genjsbind-ast.h17
-rw-r--r--src/genjsbind-parser.y10
-rw-r--r--src/genjsbind.c5
-rw-r--r--src/jsapi-libdom.c42
-rw-r--r--src/jsapi-libdom.h1
7 files changed, 85 insertions, 59 deletions
diff --git a/src/Makefile b/src/Makefile
index 1116400..530dd4b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,7 @@
CFLAGS := $(CFLAGS) -I$(BUILDDIR) -Isrc/ -g
# Sources in this directory
-DIR_SOURCES := genjsbind.c webidl-ast.c genjsbind-ast.c
+DIR_SOURCES := genjsbind.c webidl-ast.c genjsbind-ast.c jsapi-libdom.c
SOURCES := $(SOURCES) $(BUILDDIR)/genjsbind-parser.c $(BUILDDIR)/genjsbind-lexer.c $(BUILDDIR)/webidl-parser.c $(BUILDDIR)/webidl-lexer.c
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;
-}
diff --git a/src/genjsbind-ast.h b/src/genjsbind-ast.h
index d94eda6..0f7c2d2 100644
--- a/src/genjsbind-ast.h
+++ b/src/genjsbind-ast.h
@@ -9,10 +9,17 @@
#ifndef genjsbind_genjsbind_ast_h
#define genjsbind_genjsbind_ast_h
-int genjsbind_parsefile(char *infilename);
-int genjsbind_output(char *outfilename);
-int genjsbind_header_comment(char *);
-int genjsbind_interface(char *);
-int genjsbind_preamble(char *ccode);
+int genbind_parsefile(char *infilename);
+int genbind_header_comment(char *);
+int genbind_interface(char *);
+int genbind_preamble(char *ccode);
+
+struct genbind_ast {
+ char *hdr_comments;
+ char *preamble;
+ char *ifname;
+};
+
+extern struct genbind_ast *genbind_ast;
#endif
diff --git a/src/genjsbind-parser.y b/src/genjsbind-parser.y
index 9ed4f21..0e68a47 100644
--- a/src/genjsbind-parser.y
+++ b/src/genjsbind-parser.y
@@ -104,12 +104,12 @@ HdrStrings
:
TOK_STRING_LITERAL
{
- genjsbind_header_comment($1);
+ genbind_header_comment($1);
}
|
HdrStrings TOK_STRING_LITERAL
{
- genjsbind_header_comment($2);
+ genbind_header_comment($2);
}
;
@@ -122,12 +122,12 @@ CBlock
:
TOK_CCODE_LITERAL
{
- genjsbind_preamble($1);
+ genbind_preamble($1);
}
|
CBlock TOK_CCODE_LITERAL
{
- genjsbind_preamble($2);
+ genbind_preamble($2);
}
;
@@ -171,7 +171,7 @@ Interface
:
TOK_INTERFACE TOK_IDENTIFIER ';'
{
- genjsbind_interface($2);
+ genbind_interface($2);
}
;
diff --git a/src/genjsbind.c b/src/genjsbind.c
index dd5b242..21bf8b1 100644
--- a/src/genjsbind.c
+++ b/src/genjsbind.c
@@ -15,6 +15,7 @@
#include <errno.h>
#include "genjsbind-ast.h"
+#include "jsapi-libdom.h"
#include "options.h"
struct options *options;
@@ -85,13 +86,13 @@ int main(int argc, char **argv)
return 2;
}
- res = genjsbind_parsefile(options->infilename);
+ res = genbind_parsefile(options->infilename);
if (res != 0) {
fprintf(stderr, "Error: parse failed with code %d\n", res);
return res;
}
- res = genjsbind_output(options->outfilename);
+ res = jsapi_libdom_output(options->outfilename);
if (res != 0) {
fprintf(stderr, "Error: output failed with code %d\n", res);
unlink(options->outfilename);
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c
new file mode 100644
index 0000000..02033e1
--- /dev/null
+++ b/src/jsapi-libdom.c
@@ -0,0 +1,42 @@
+/* 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 <vince@netsurf-browser.org>
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "genjsbind-ast.h"
+#include "jsapi-libdom.h"
+
+int jsapi_libdom_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", genbind_ast->hdr_comments);
+
+ fprintf(outfile, "%s", genbind_ast->preamble);
+
+ fprintf(outfile, "/* interface %s */\n\n", genbind_ast->ifname);
+
+ fclose(outfile);
+
+ return 0;
+}
diff --git a/src/jsapi-libdom.h b/src/jsapi-libdom.h
new file mode 100644
index 0000000..6ee8db7
--- /dev/null
+++ b/src/jsapi-libdom.h
@@ -0,0 +1 @@
+int jsapi_libdom_output(char *outfile);