X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Fscanner.c;h=d01be156a96d2812beeaef6ab635c0a8501bb109;hp=d9aa426e5f8b523dd4b8cd48de056f4cf7410e6d;hb=25a23e5134b1d9649f0279a4028b887c9deb9987;hpb=4fd7e754caf964df899d9a41b6cf10fc2a1d90bf diff --git a/src/scanner.c b/src/scanner.c index d9aa426..d01be15 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -24,43 +24,22 @@ /* Internal */ #include "parser.tab.h" /* Public */ -int scanner_init(void); void scanner_quit(void); int scanner_scanpath(char const*); int scanner_scandir(DIR*); -yypstate* apc_pstate; -yycstate* apc_cstate; /* Private */ +static +int scanner_scandir_r(DIR*); +extern //lexer.rl +int lexer_init(void); +extern //lexer.rl +void lexer_quit(void); extern //lexer.rl int lexer_lexfile(uint8_t*); extern //lexer.rl int lexer_lexdir(uint8_t*); extern //lexer.rl void lexer_closedir(void); - -/* Init - Establishes yy states -*/ -int scanner_init -( void ) -{ if (apc_pstate != NULL || apc_cstate != NULL) - scanner_quit(); - apc_pstate = yypstate_new(); - apc_cstate = yycstate_new(); - return (apc_pstate == NULL || apc_cstate == NULL); -} - -/* Quit - Free initialized memory -*/ -void scanner_quit -( void ) -{ yypstate_delete(apc_pstate); - yycstate_delete(apc_cstate); - apc_pstate = NULL; - apc_cstate = NULL; -} - /* Scan the provided path Changes working directory to the provided pathname and, if successful, sends a directory stream of the provided path to scanner_scandir @@ -84,6 +63,17 @@ int scanner_scanpath */ int scanner_scandir ( DIR* dirp ) +{ int scandir_status; + if (lexer_init()) + return -1; + scandir_status = scanner_scandir_r(dirp); + lexer_quit(); + return scandir_status; +} + +static +int scanner_scandir_r +( DIR* dirp ) { DIR* cdirp; struct dirent* direntp; scan_next_dirent: @@ -105,7 +95,7 @@ int scanner_scandir errno = 0; if ((cdirp = opendir(".")) == NULL || errno) //open it goto libfail; - if(scanner_scandir(cdirp)) //scan the directory + if(scanner_scandir_r(cdirp)) //scan the directory goto libfail; if (chdir("..")) //return to the parent dir goto libfail;