diff options
author | Vincent Sanders <vince@kyllikki.org> | 2012-10-21 12:56:50 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2012-10-21 12:56:50 +0100 |
commit | d264e721abc7848ae4f82fbaae444245f0e1e2b9 (patch) | |
tree | 00255013bf0803c4badfa02313af5cdec4ff054d /src | |
parent | 903f328e2ea9405a0d351c828389cf0080670b6c (diff) | |
download | nsgenbind-d264e721abc7848ae4f82fbaae444245f0e1e2b9.tar.gz nsgenbind-d264e721abc7848ae4f82fbaae444245f0e1e2b9.tar.bz2 |
add includes in binding files to allow binding definitions to be split up
Diffstat (limited to 'src')
-rw-r--r-- | src/genjsbind-ast.c | 65 | ||||
-rw-r--r-- | src/genjsbind-ast.h | 2 | ||||
-rw-r--r-- | src/genjsbind-lexer.l | 41 | ||||
-rw-r--r-- | src/webidl-ast.c | 24 |
4 files changed, 116 insertions, 16 deletions
diff --git a/src/genjsbind-ast.c b/src/genjsbind-ast.c index 21be715..c3329cf 100644 --- a/src/genjsbind-ast.c +++ b/src/genjsbind-ast.c @@ -267,6 +267,66 @@ int genbind_ast_dump(struct genbind_node *node, int indent) return 0; } +FILE *genbindopen(const char *filename) +{ + FILE *genfile; + char *fullname; + int fulllen; + static char *prevfilepath = NULL; + + /* try filename raw */ + genfile = fopen(filename, "r"); + if (genfile != NULL) { + if (options->verbose) { + printf("Opened Genbind file %s\n", filename); + } + if (prevfilepath == NULL) { + fullname = strrchr(filename, '/'); + if (fullname == NULL) { + fulllen = strlen(filename); + } else { + fulllen = fullname - filename; + } + prevfilepath = strndup(filename,fulllen); + } + return genfile; + } + + /* try based on previous filename */ + if (prevfilepath != NULL) { + fulllen = strlen(prevfilepath) + strlen(filename) + 2; + fullname = malloc(fulllen); + snprintf(fullname, fulllen, "%s/%s", prevfilepath, filename); + if (options->debug) { + printf("Attempting to open Genbind file %s\n", fullname); + } + genfile = fopen(fullname, "r"); + if (genfile != NULL) { + if (options->verbose) { + printf("Opened Genbind file %s\n", fullname); + } + free(fullname); + return genfile; + } + free(fullname); + } + + /* try on idl path */ + if (options->idlpath != NULL) { + fulllen = strlen(options->idlpath) + strlen(filename) + 2; + fullname = malloc(fulllen); + snprintf(fullname, fulllen, "%s/%s", options->idlpath, filename); + genfile = fopen(fullname, "r"); + if ((genfile != NULL) && options->verbose) { + printf("Opend Genbind file %s\n", fullname); + } + + free(fullname); + } + + return genfile; +} + int genbind_parsefile(char *infilename, struct genbind_node **ast) { FILE *infile; @@ -279,10 +339,7 @@ int genbind_parsefile(char *infilename, struct genbind_node **ast) } infile = stdin; } else { - if (options->verbose) { - printf("Opening binding file %s\n", options->infilename); - } - infile = fopen(infilename, "r"); + infile = genbindopen(infilename); } if (!infile) { diff --git a/src/genjsbind-ast.h b/src/genjsbind-ast.h index 6be13f9..416fa7b 100644 --- a/src/genjsbind-ast.h +++ b/src/genjsbind-ast.h @@ -32,6 +32,8 @@ typedef int (genbind_callback_t)(struct genbind_node *node, void *ctx); int genbind_cmp_node_type(struct genbind_node *node, void *ctx); +FILE *genbindopen(const char *filename); + int genbind_parsefile(char *infilename, struct genbind_node **ast); char *genbind_strapp(char *a, char *b); diff --git a/src/genjsbind-lexer.l b/src/genjsbind-lexer.l index 2282c5e..3701252 100644 --- a/src/genjsbind-lexer.l +++ b/src/genjsbind-lexer.l @@ -13,6 +13,7 @@ #include <string.h> #include "genjsbind-parser.h" +#include "genjsbind-ast.h" #define YY_USER_ACTION yylloc->first_line = yylloc->last_line; \ yylloc->first_column = yylloc->last_column + 1; \ @@ -60,8 +61,13 @@ cblockopen \%\{ cblockclose \%\} +/* used for #include directive */ +poundsign ^{whitespace}*# + %x cblock +%x incl + %% {whitespace} ++yylloc->last_column;/* nothing */ @@ -104,12 +110,45 @@ operation return TOK_OPERATION; {multicomment} /* nothing */ +{poundsign}include BEGIN(incl); + {other} return (int) yytext[0]; . /* nothing */ <cblock>[^\%]* yylval->text = strdup(yytext); return TOK_CCODE_LITERAL; <cblock>{cblockclose} BEGIN(INITIAL); -<cblock>\% yylval->text = strdup(yytext); return TOK_CCODE_LITERAL; +<cblock>\% yylval->text = strdup(yytext); return TOK_CCODE_LITERAL; + + +<incl>[ \t]*\" /* eat the whitespace and open quotes */ + +<incl>[^\t\n\"]+ { + /* got the include file name */ + yyin = genbindopen(yytext); + + if (! yyin) { + fprintf(stderr, "Unable to open include %s\n", yytext); + exit(3); + } + yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE )); + + BEGIN(INITIAL); + } + +<incl>\n BEGIN(INITIAL); + +<incl>. /* nothing */ + +<<EOF>> { + yypop_buffer_state(); + + if ( !YY_CURRENT_BUFFER ) { + yyterminate(); + } else { + BEGIN(incl); + } + + } %% diff --git a/src/webidl-ast.c b/src/webidl-ast.c index 75dbdeb..7e6fc2c 100644 --- a/src/webidl-ast.c +++ b/src/webidl-ast.c @@ -359,23 +359,25 @@ int webidl_ast_dump(struct webidl_node *node, int indent) static FILE *idlopen(const char *filename) { FILE *idlfile; + char *fullname; + int fulllen; 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 fopen(filename, "r"); + } + + 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; } |