testing upgrades
authorken <ken@mihrtec.com>
Sun, 9 Oct 2016 03:38:42 +0000 (20:38 -0700)
committerken <ken@mihrtec.com>
Sun, 9 Oct 2016 03:38:42 +0000 (20:38 -0700)
src/apc/lexer.c
src/apc/scanner.c
src/bin/tools/apc.c

index 6ef1b4c..30566df 100644 (file)
@@ -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);
+}
index c669b10..8490e02 100644 (file)
@@ -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);
index be902bd..a2ab6e7 100644 (file)
@@ -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' :