*/
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
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
}
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);
#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;
default :
fprintf(stderr, USAGE);
exit(EXIT_FAILURE);
+ case 'h' :
+ printf(USAGE);
+ printf(USAGE_LONG);
+ exit(EXIT_SUCCESS);
}
if (lexer_init())
{ perror("lexer");