From: ken Date: Sun, 9 Oct 2016 03:38:42 +0000 (-0700) Subject: testing upgrades X-Git-Url: https://git.kengrimes.com/?p=henge%2Fwebcc.git;a=commitdiff_plain;h=4da3506e5cf1a3eee35b60722b9c801867ef3f36 testing upgrades --- diff --git a/src/apc/lexer.c b/src/apc/lexer.c index 6ef1b4c..30566df 100644 --- a/src/apc/lexer.c +++ b/src/apc/lexer.c @@ -30,6 +30,7 @@ /* Public */ int lexer_init(void); int lexer(void); +int lexer_lexfile(const char*); void lexer_pushtok(int, YYSTYPE); extern //lexer_lex.rl int lexer_lex(const char*); @@ -117,7 +118,7 @@ int lexer () {start: while (DE_LEN() > 0) //lex any directory entries in our stack - if (lexer_lex(DE_POP()->d_name) == 0) //fail if it generates no tokens + if (lexer_lexfile(DE_POP()->d_name) == 0) FAIL("Lexer failed to tokenize [%s]\n",(*DE_STACKP)->d_name); if (TK_EMPTY) //if there are no tokens, { TK_INIT(); //initialize the token stack back to 0 @@ -152,3 +153,31 @@ void lexer_pushtok TK_PUSH(tok, lval); printf("Pushed Token %i | %i\n", TK_STACK[TK_LEN() - 1].tok_t, TK_STACK[TK_LEN() - 1].lval.val); } + +/* Lexical analysis of a file + Strips a filename to its base name, then sends it to lexer_lex +*/ +int lexer_lexfile +#define MAX_FNAME 2048 +#define HIDDEN_WARNING "%s is hidden and will not be parsed!\n", filename +( const char *filename +) +{ static char fname[MAX_FNAME]; + char *last_period = NULL, *iter; + + if (*filename == '.') + { fprintf (stderr, HIDDEN_WARNING); + return 0; + } + strncpy(fname,filename,MAX_FNAME); + last_period = NULL; + for (iter = fname; *iter; iter++) + if (*iter == '.') + { if (iter == fname) + last_period = iter; + } + if (last_period) + *last_period = '\0'; + + return lexer_lex(fname); +} diff --git a/src/apc/scanner.c b/src/apc/scanner.c index c669b10..8490e02 100644 --- a/src/apc/scanner.c +++ b/src/apc/scanner.c @@ -134,7 +134,6 @@ int scanner if (DL_CD_LEN() > 0) //There are entities to process { if ((direntp = DL_CD_POP()) == NULL)//If the dirent is null, the library goto libfail; //function in dirent has failed - printf("Lexdir %s\n",direntp->d_name); lexer_lex(direntp->d_name); //lex the directory name if (DL_LEN() >= DL_STACKSIZE) //fail if maxdepth exceeded { fprintf(stderr, ERR_DEPTH); diff --git a/src/bin/tools/apc.c b/src/bin/tools/apc.c index be902bd..a2ab6e7 100644 --- a/src/bin/tools/apc.c +++ b/src/bin/tools/apc.c @@ -45,6 +45,7 @@ int main #define $($)#$ //stringifier #define MAXSTR 255 #define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt +#define OPTS "d:o:h-" #define USAGE "Usage %s [-d dir_root][-o output_file][-h]\n", argv[0] #define USAGE_LONG \ "\tOptions:\n" \ @@ -55,7 +56,7 @@ int main { int opt; getopt: - switch (opt = getopt(argc, argv, "d:o:h-")) + switch (opt = getopt(argc, argv, OPTS)) { case DONE: break; case 'd' :