diff options
Diffstat (limited to 'src/genjsbind.c')
-rw-r--r-- | src/genjsbind.c | 88 |
1 files changed, 22 insertions, 66 deletions
diff --git a/src/genjsbind.c b/src/genjsbind.c index 89d2fb0..fcdc944 100644 --- a/src/genjsbind.c +++ b/src/genjsbind.c @@ -9,75 +9,16 @@ #include "webidl-ast.h" #include "webidl-parser.h" #include "genjsbind-parser.h" +#include "jsapi-binding.h" #include "genjsbind.h" -extern int webidl_debug; -extern int webidl__flex_debug; -extern void webidl_restart(FILE*); -extern int webidl_parse(void); - extern int genjsbind_debug; extern int genjsbind__flex_debug; extern void genjsbind_restart(FILE*); extern int genjsbind_parse(void); -struct options { - char *outfilename; - char *infilename; - char *idlpath; - bool verbose; - bool debug; -}; - struct options *options; -static FILE *idlopen(const char *filename) -{ - FILE *idlfile; - - if (options->idlpath == NULL) { - if (options->verbose) { - printf("Opening IDL file %s\n", filename); - } - idlfile = fopen(filename, "r"); - } else { - char *fullname; - int fulllen = strlen(options->idlpath) + strlen(filename) + 2; - fullname = malloc(fulllen); - snprintf(fullname, fulllen, "%s/%s", options->idlpath, filename); - if (options->verbose) { - printf("Opening IDL file %s\n", fullname); - } - idlfile = fopen(fullname, "r"); - free(fullname); - } - return idlfile; -} - -int loadwebidl(char *filename) -{ - /* set flex to read from file */ - FILE *idlfile; - idlfile = idlopen(filename); - if (!idlfile) { - fprintf(stderr, "Error opening %s: %s\n", - filename, - strerror(errno)); - return 2; - } - - if (options->debug) { - webidl_debug = 1; - webidl__flex_debug = 1; - } - - webidl_restart(idlfile); - - /* parse the file */ - return webidl_parse(); -} - - static struct options* process_cmdline(int argc, char **argv) { int opt; @@ -131,7 +72,7 @@ static struct options* process_cmdline(int argc, char **argv) int main(int argc, char **argv) { FILE *infile; - int parse_res; + int res; options = process_cmdline(argc, argv); if (options == NULL) { @@ -143,6 +84,12 @@ int main(int argc, char **argv) return 2; } + res = genjsbind_outputopen(options->outfilename); + if (res != 0) { + return res; + } + + /* open input file */ if ((options->infilename[0] == '-') && (options->infilename[1] == 0)) { if (options->verbose) { @@ -170,11 +117,20 @@ int main(int argc, char **argv) /* set flex to read from file */ genjsbind_restart(infile); - - parse_res = genjsbind_parse(); - if (parse_res) { - fprintf(stderr, "parse result was %d\n", parse_res); - return parse_res; + + /* initialise root node */ + webidl_root = webidl_new_node(WEBIDL_NODE_TYPE_ROOT); + + /* process binding */ + res = genjsbind_parse(); + + genjsbind_outputclose(); + + if (res != 0) { + fprintf(stderr, "Error parse failed with code %d\n", res); + return res; } + + return 0; } |