Debugging text for lexer + directory spec CLI
authorken <ken@mihrtec.com>
Tue, 27 Sep 2016 01:26:52 +0000 (18:26 -0700)
committerken <ken@mihrtec.com>
Tue, 27 Sep 2016 01:26:52 +0000 (18:26 -0700)
src/apc/scanner.c
src/bin/tools/apc.c

index b20a92f..580ad12 100644 (file)
@@ -83,11 +83,11 @@ struct dirlist
 */
 int scanner_init
 #define CWDSTR  "./"
-#define ROOTDIR (cargs['r'] ? cargs['r'] : CWDSTR)
+#define ROOTDIR (cargs['d'] ? cargs['d'] : CWDSTR)
 ()
 { DL_INIT();
   DL_STACK[0].dirp = opendir(ROOTDIR);
-  return DL_STACK[0].dirp == NULL || dredge_current_depth() == 0;
+  return !chdir(ROOTDIR) && (DL_STACK[0].dirp == NULL || dredge_current_depth() == 0);
 }
 
 /* Scanner
@@ -130,12 +130,10 @@ int scanner
           goto fail;
         }
       if (chdir(direntp->d_name))     //move into the new directory
-        goto libfail;
+       goto libfail;
       DL_PUSH(opendir(CWDSTR));
       if (DL_CURDIR() == NULL)   //open the cwd
-       { printf("DL_PUSH(opendir failed.\n");
-         goto libfail;
-       }
+       goto libfail;
       lexer_pushtok(TOK_CLOPEN);      //Push "Open Directory" token
       return dredge_current_depth();  //Filter and sort the current depth
     }
@@ -181,10 +179,14 @@ int dredge_current_depth
   if ((direntp = readdir(cwd)) != NULL)
     { switch (direntp->d_type)
         { case DT_REG:
+           printf("String to tokenize %s\n", direntp->d_name);
             DPS_PUSH(direntp);
             goto scan_next;
           case DT_DIR:
-            DL_CD_PUSH(direntp);
+           if (*(direntp->d_name) == '.') //skip hidden files and relative dirs
+              goto scan_next;
+            printf("Pushing child directory %s\n", direntp->d_name);
+           DL_CD_PUSH(direntp);
             goto scan_next;
           case DT_UNKNOWN:
             warnx("unknown file %s: ignoring", direntp->d_name);
index de7bc34..be902bd 100644 (file)
@@ -45,15 +45,20 @@ int main
 #define $($)#$ //stringifier
 #define MAXSTR 255
 #define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt
-#define USAGE  "Usage: %s [-r root]\n", argv[0]
+#define USAGE "Usage %s [-d dir_root][-o output_file][-h]\n", argv[0]
+#define USAGE_LONG                                     \
+  "\tOptions:\n"                                       \
+  "\t\t-d\tRoot directory to parse from \t[./]\n"      \
+  "\t\t-o\tOutput filename \t\t[a.asspak]\n"           \
+  "\t\t-h\tPrint this help\n"
 #define DONE   -1
 { int   opt;
 
  getopt:
-  switch (opt = getopt(argc, argv, "r:o:"))
+  switch (opt = getopt(argc, argv, "d:o:h-"))
   { case DONE:
       break;
-    case 'r' :
+    case 'd' :
     case 'o' :
       if (strnlen(optarg, MAXSTR) != MAXSTR)
         { cargs[opt] = optarg;
@@ -63,6 +68,10 @@ int main
     default :
       fprintf(stderr, USAGE);
       exit(EXIT_FAILURE);
+    case 'h' :
+      printf(USAGE);
+      printf(USAGE_LONG);
+      exit(EXIT_SUCCESS);
   }
   if (lexer_init())
     { perror("lexer");