*/
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);