/* 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*);
()
{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
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);
+}
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);
#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" \
{ int opt;
getopt:
- switch (opt = getopt(argc, argv, "d:o:h-"))
+ switch (opt = getopt(argc, argv, OPTS))
{ case DONE:
break;
case 'd' :