diff options
author | Vincent Sanders <vince@kyllikki.org> | 2012-09-06 02:59:31 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2012-09-06 02:59:31 +0100 |
commit | c1db25526a6990263e9703634401178975cf9d61 (patch) | |
tree | ba737f0e32cfa287c5f4a746fa0679924adaf80a /src/webidl-ast.c | |
parent | da234bc3e4e44693a6464140d2dee91a948a6145 (diff) | |
download | nsgenbind-c1db25526a6990263e9703634401178975cf9d61.tar.gz nsgenbind-c1db25526a6990263e9703634401178975cf9d61.tar.bz2 |
initial output generation
Diffstat (limited to 'src/webidl-ast.c')
-rw-r--r-- | src/webidl-ast.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/webidl-ast.c b/src/webidl-ast.c new file mode 100644 index 0000000..b300383 --- /dev/null +++ b/src/webidl-ast.c @@ -0,0 +1,71 @@ +#include <stdbool.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include "webidl-ast.h" +#include "genjsbind.h" + +extern int webidl_debug; +extern int webidl__flex_debug; +extern void webidl_restart(FILE*); +extern int webidl_parse(void); + +struct webidl_node *webidl_root; + +struct webidl_node *webidl_new_node(enum webidl_node_type type) +{ + struct webidl_node *nnode; + nnode = calloc(1, sizeof(struct webidl_node)); + if (nnode != NULL) { + nnode->type = type; + } + return nnode; +} + +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 webidl_parsefile(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(); +} |