X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=vppapigen%2Flex.c;h=b011044dd01ab8d4080b66c2ab8cd0b6757499ca;hb=9876520f9ba746ed4d9923f392911c4f1888a105;hp=b9dc833ad232a5c73add091d7e1eb72d257f7aeb;hpb=cb9cadad578297ffd78fa8a33670bdf1ab669e7e;p=vpp.git diff --git a/vppapigen/lex.c b/vppapigen/lex.c index b9dc833ad23..b011044dd01 100644 --- a/vppapigen/lex.c +++ b/vppapigen/lex.c @@ -28,8 +28,7 @@ #include "node.h" #include "gram.h" -FILE *ifp, *ofp, *javafp, *jnifp; -char *java_class = "vppApi"; +FILE *ifp, *ofp, *pythonfp; char *vlib_app_name = "vpp"; int dump_tree; time_t starttime; @@ -54,6 +53,7 @@ static void usage (char *); static int name_check (const char *, YYSTYPE *); static int name_compare (const char *, const char *); extern int yydebug; +extern YYSTYPE yylval; unsigned int crc32c_table[256] = { 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, @@ -257,8 +257,7 @@ int main (int argc, char **argv) { int curarg = 1; char *ofile=0; - char *jofile=0; - char *jnifile=0; + char *pythonfile=0; char *show_name=0; while (curarg < argc) { @@ -329,36 +328,23 @@ int main (int argc, char **argv) } continue; } - if (!strncmp (argv [curarg], "--java", 4)) { + if (!strncmp (argv [curarg], "--python", 8)) { curarg++; if (curarg < argc) { - javafp = fopen (argv[curarg], "w"); - if (javafp == NULL) { - fprintf (stderr, "Couldn't open java output file %s\n", - argv[curarg]); - exit (1); - } - jofile = argv[curarg]; - curarg++; - } else { - fprintf(stderr, "Missing filename after --java\n"); - exit(1); - } - continue; - } - if (!strncmp (argv [curarg], "--jni", 4)) { - curarg++; - if (curarg < argc) { - jnifp = fopen (argv[curarg], "w"); - if (jnifp == NULL) { - fprintf (stderr, "Couldn't open jni output file %s\n", + if (!strcmp(argv[curarg], "-")) { + pythonfp = stdout; + } else { + pythonfp = fopen(argv[curarg], "w"); + pythonfile = argv[curarg]; + } + if (pythonfp == NULL) { + fprintf (stderr, "Couldn't open python output file %s\n", argv[curarg]); exit (1); } - jnifile = argv[curarg]; curarg++; } else { - fprintf(stderr, "Missing filename after --jni\n"); + fprintf(stderr, "Missing filename after --python\n"); exit(1); } continue; @@ -374,17 +360,6 @@ int main (int argc, char **argv) } continue; } - if (!strncmp (argv [curarg], "--class", 3)) { - curarg++; - if (curarg < argc) { - java_class = argv[curarg]; - curarg++; - } else { - fprintf(stderr, "Missing class name after --class\n"); - exit(1); - } - continue; - } usage(argv[0]); exit (1); @@ -392,11 +367,8 @@ int main (int argc, char **argv) if (ofp == NULL) { ofile = 0; } - if (javafp == NULL) { - jofile = 0; - } - if (jnifp == NULL) { - jnifile = 0; + if (pythonfp == NULL) { + pythonfile = 0; } if (ifp == NULL) { fprintf(stderr, "No input file specified...\n"); @@ -415,30 +387,22 @@ int main (int argc, char **argv) printf ("Output written to %s\n", ofile); fclose (ofp); } - if (jofile) { - printf ("Java class defn written to %s\n", jofile); - fclose (javafp); - } - if (jnifile) { - printf ("Java native bindings written to %s\n", jnifile); - fclose (jnifp); + if (pythonfile) { + printf ("Python bindings written to %s\n", pythonfile); + fclose (pythonfp); } } else { fclose (ifp); - fclose (ofp); + if (ofp) + fclose (ofp); if (ofile) { printf ("Removing %s\n", ofile); unlink (ofile); } - fclose (javafp); - if (jofile) { - printf ("Removing %s\n", jofile); - unlink (jofile); - } - if (jnifile) { - printf ("Removing %s\n", jnifile); - unlink (jnifile); + if (pythonfile) { + printf ("Removing %s\n", pythonfile); + unlink (pythonfile); } exit (1); } @@ -451,7 +415,7 @@ int main (int argc, char **argv) static void usage (char *progname) { fprintf (stderr, - "usage: %s --input [--output ]\n%s", + "usage: %s --input [--output ] [--python ]\n%s", progname, " [--yydebug] [--dump-tree]\n"); exit (1); @@ -467,6 +431,12 @@ void yyerror (char *s) static char namebuf [MAXNAME]; +static inline char +getc_char (FILE *ifp) +{ + return ((char)(getc(ifp) & 0x7f)); +} + /* * yylex (well, yylex_1: The real yylex below does crc-hackery) */ @@ -474,7 +444,6 @@ static int yylex_1 (void) { int nameidx=0; char c; - int at_bol=1; enum { LP_INITIAL_WHITESPACE, LP_LINE_NUMBER, LP_PRE_FILENAME_WHITESPACE, LP_FILENAME, LP_POST_FILENAME, @@ -487,23 +456,16 @@ static int yylex_1 (void) * START state -- looking for something interesting */ case START_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); switch (c) { case '\n': the_lexer_linenumber++; - at_bol=1; goto again; case '#': - if (!at_bol) { - fprintf (stderr, "unknown token /%c at line %d\n", - c, the_lexer_linenumber); - return (BARF); - } - the_lexer_state = LINE_PRAGMA_STATE; lp_substate = LP_INITIAL_WHITESPACE; goto again; @@ -548,7 +510,7 @@ static int yylex_1 (void) goto again; case '/': - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); @@ -565,7 +527,7 @@ static int yylex_1 (void) } case '\\': - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); @@ -593,7 +555,7 @@ static int yylex_1 (void) * NAME state -- eat the rest of a name */ case NAME_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); @@ -614,7 +576,7 @@ static int yylex_1 (void) * NUMBER state -- eat the rest of a number */ case NUMBER_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); @@ -636,11 +598,11 @@ static int yylex_1 (void) * C_COMMENT state -- eat a peach */ case C_COMMENT_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); if (c == '*') { - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); if (c == '/') { @@ -657,7 +619,7 @@ static int yylex_1 (void) */ case CPP_COMMENT_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); if (c == '\n') { @@ -668,12 +630,12 @@ static int yylex_1 (void) goto again; case STRING_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); switch (c) { case '\\': - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); namebuf[nameidx++] = c; @@ -699,12 +661,12 @@ static int yylex_1 (void) break; case HELPER_STATE: - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); switch (c) { case '\\': - c = getc (ifp); + c = getc_char (ifp); if (feof (ifp)) return (EOF); namebuf[nameidx] = c; @@ -744,7 +706,7 @@ static int yylex_1 (void) switch (lp_substate) { case LP_INITIAL_WHITESPACE: /* no number seen yet */ - c = getc(ifp); + c = getc_char(ifp); if (feof(ifp)) return(EOF); if (c >= '0' && c <= '9') { @@ -760,7 +722,7 @@ static int yylex_1 (void) goto again; case LP_LINE_NUMBER: /* eating linenumber */ - c = getc(ifp); + c = getc_char(ifp); if (feof(ifp)) return(EOF); if (c >= '0' && c <= '9') { @@ -777,7 +739,7 @@ static int yylex_1 (void) goto again; case LP_PRE_FILENAME_WHITESPACE: /* awaiting filename */ - c = getc(ifp); + c = getc_char(ifp); if (feof(ifp)) return(EOF); @@ -794,7 +756,7 @@ static int yylex_1 (void) goto again; case LP_FILENAME: /* eating filename */ - c = getc(ifp); + c = getc_char(ifp); if (feof(ifp)) return(EOF); @@ -810,7 +772,7 @@ static int yylex_1 (void) case LP_POST_FILENAME: /* ignoring rest of line */ case LP_OTHER: - c = getc(ifp); + c = getc_char(ifp); if (feof(ifp)) return(EOF); @@ -830,7 +792,6 @@ static int yylex_1 (void) } lp_end_of_line: the_lexer_state = START_STATE; - at_bol = 1; nameidx = 0; } goto again; @@ -896,7 +857,6 @@ int yylex (void) case NOVERSION: crc = CRC16 (crc, 274); break; case MANUAL_PRINT: crc = CRC16 (crc, 275); break; case MANUAL_ENDIAN: crc = CRC16 (crc, 276); break; - case MANUAL_JAVA: crc = CRC16 (crc, 277); break; case TYPEONLY: crc = CRC16 (crc, 278); break; case DONT_TRACE: crc = CRC16 (crc, 279); break; @@ -935,7 +895,6 @@ static struct keytab { {"i64", NODE_I64}, {"i8", NODE_I8}, {"manual_endian", NODE_MANUAL_ENDIAN}, - {"manual_java", NODE_MANUAL_JAVA}, {"manual_print", NODE_MANUAL_PRINT}, {"noversion", NODE_NOVERSION}, {"packed", NODE_PACKED}, @@ -995,10 +954,6 @@ static int name_check (const char *s, YYSTYPE *token_value) *token_value = (YYSTYPE) NODE_FLAG_MANUAL_ENDIAN; return (MANUAL_ENDIAN); - case NODE_MANUAL_JAVA: - *token_value = (YYSTYPE) NODE_FLAG_MANUAL_JAVA; - return (MANUAL_JAVA); - case NODE_TYPEONLY: *token_value = (YYSTYPE) NODE_FLAG_TYPEONLY; return(TYPEONLY); @@ -1033,6 +988,11 @@ char *sxerox (const char *s) char *rv; rv = (char *) malloc (len+1); + if (rv == 0) { + fprintf(stderr, "Out of memory..."); + exit (1); + } + strcpy (rv, s); return (rv); }