From 2dfdc5653b9f85952119122cff72320540a342d2 Mon Sep 17 00:00:00 2001 From: ken Date: Mon, 26 Sep 2016 15:32:01 -0700 Subject: [PATCH] scanner needs lexer --- src/Makefile | 2 +- src/apc/scanner.c | 20 +++++++++++++------- src/bin/tools/apc.c | 13 ++++++++++--- src/henge/core/video.c | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Makefile b/src/Makefile index 83fb20f..7b718b5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -265,7 +265,7 @@ $(DRIVER_TARG): $(DRIVER_DEPS) | $(DRIVER_TARG_DIR) $(eval DRIVER_DBGTARG := $(DRIVER_TARG_DIR)$(basename $(notdir $(DRIVER_TARG)))-d$($2_OUT)) $(eval SCRUB_TARGETS += $(DRIVER_DBGTARG)) $(eval MAKE_DIRS += $(DRIVER_TARG_DIR).$($2_DBG)/) -$(DRIVER_DBGTARG): $(DRIVER_DBGDEPS) | $(DRIVER_TARG_DIR).$($2_DBG)/ +$(DRIVER_DBGTARG): $(DRIVER_DBGDEPS) | $(DRIVER_TARG_DIR) $($2_C) $($2_FLAGS) $(DRIVER_DBGSRC) -o $$@ # Make a rule to run this driver after building $(DRIVER_NAME)-run: $(DRIVER_TARG) diff --git a/src/apc/scanner.c b/src/apc/scanner.c index 089d0f3..b20a92f 100644 --- a/src/apc/scanner.c +++ b/src/apc/scanner.c @@ -19,6 +19,8 @@ #include //exit #include //chdir #include //opendir + +#include "parser.tab.h" /* Public */ int scanner_init(void); int scanner(void); @@ -37,7 +39,7 @@ static int dredge_current_depth(void); extern //lexer.c struct dirent* lexer_direntpa[]; -extern //main.c +extern //SRC_DIR/bin/tools/apc.c const char* cargs['Z']; struct dirlist @@ -102,24 +104,25 @@ int scanner_init Returns the number of elements added to the lexer's file array. */ int scanner -#define S(S)#S //stringifier -#define ERR_CHILD "Fatal: Maximum of " S(DL_CD_STACKSIZE) \ +#define $($)#$ //stringifier +#define ERR_CHILD "Fatal: Maximum of " $(DL_CD_STACKSIZE) \ " child directories exceeded for directory at depth %i\n" \ ,DL_LEN() -#define ERR_DEPTH "Fatal: Maximum directory depth of " S(DL_STACKSIZE) \ +#define ERR_DEPTH "Fatal: Maximum directory depth of " $(DL_STACKSIZE) \ " exceeded during directory scan\n" #define ERR_DL "Fatal: Directory List Stack Corruption %x\n", DL_LEN() #define TOK_CLOPEN 0x55, 0 //TODO #define TOK_CLCLOSE 0x56, 0 //TODO () { struct dirent* direntp; + struct DIR* DIRp; parse: if (DL_CD_LEN() >= DL_CD_STACKSIZE)//fail if maxchildren exceeded { fprintf(stderr, ERR_CHILD); goto fail; } if (DL_CD_LEN() > 0) //There are entities to process at this depth - { if (direntp = DL_CD_POP()) //If the dirent is null, the library + { if ((direntp = DL_CD_POP()) == NULL) //If the dirent is null, the library goto libfail; //function in dirent has failed lexer_lex(direntp->d_name); //lex the directory name if (DL_LEN() >= DL_STACKSIZE) //fail if maxdepth exceeded @@ -128,8 +131,11 @@ int scanner } if (chdir(direntp->d_name)) //move into the new directory goto libfail; - if (DL_PUSH(opendir(CWDSTR))) //open the cwd - goto libfail; + DL_PUSH(opendir(CWDSTR)); + if (DL_CURDIR() == NULL) //open the cwd + { printf("DL_PUSH(opendir failed.\n"); + goto libfail; + } lexer_pushtok(TOK_CLOPEN); //Push "Open Directory" token return dredge_current_depth(); //Filter and sort the current depth } diff --git a/src/bin/tools/apc.c b/src/bin/tools/apc.c index a22975d..de7bc34 100644 --- a/src/bin/tools/apc.c +++ b/src/bin/tools/apc.c @@ -18,16 +18,23 @@ /* Posix */ #include //exit #include //getopt +/* Internal */ +#include //bison const char* cargs['Z'] = {0}; int main(int, char*[]); extern //bison -void yyparse(void); +int yyparse(void); extern //lexer.c int lexer_init(void); +extern //apc/parser.tab.c +YYSTYPE yylval; +extern //lexer.c +int lexer(void); + /* Main entry from terminal parses the command line and kicks off recursive scanning */ @@ -35,9 +42,9 @@ int main ( int argc, char* argv[] ) -#define S(S)#S //stringifier +#define $($)#$ //stringifier #define MAXSTR 255 -#define MAXERR "-%c allows at most " S(MAXSTR) " input characters\n", opt +#define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt #define USAGE "Usage: %s [-r root]\n", argv[0] #define DONE -1 { int opt; diff --git a/src/henge/core/video.c b/src/henge/core/video.c index 2ddaaae..39a4be0 100644 --- a/src/henge/core/video.c +++ b/src/henge/core/video.c @@ -4,10 +4,10 @@ \author Mihrtec \date 2016 ----------------------------------------------------------------------------*/ -#include #include #include #include +#include #define ERROR_BUFFER_SIZE -- 2.18.0