wip
[henge/apc.git] / src / scanner.c
index 55245af..14266ca 100644 (file)
@@ -31,7 +31,7 @@ int   scanner(void);
 int   scanner_scanpixels(int*,int);
 /* Private */
 extern //lexer.c
-int   lexer_lexstring(const uint8_t*);
+int   lexer_lexstring(const char*);
 extern //lexer.c
 void  lexer_pushtok(int, int);
 static
@@ -41,12 +41,9 @@ extern //lexer.c
 struct dirent* lexer_direntpa[], **lexer_direntpp;
 extern //SRC_DIR/bin/tools/apc.c
 const char* cargs['Z'];
-#ifndef DL_STACKSIZE
 #define DL_STACKSIZE     64
-#endif
-#ifndef DL_CD_STACKSIZE
 #define DL_CD_STACKSIZE  DL_STACKSIZE //square tree
-#endif
+
 static
 struct dirlist
 { DIR*           dirp;
@@ -74,8 +71,8 @@ FILE* current_open_file = NULL;
 #define DL_CD_STACK     ((*DL_STACKP).child_directory_stack)
 #define DL_CD_STACKP    ((*DL_STACKP).cds)
 #define DL_CURDIR()     ((*DL_STACKP).dirp)
-#define DL_LEN()        (DL_STACKP - DL_STACK)
-#define DL_CD_LEN()     (DL_CD_STACKP - DL_CD_STACK)
+#define DL_LEN()        ((int)(DL_STACKP - DL_STACK))
+#define DL_CD_LEN()     ((int)(DL_CD_STACKP - DL_CD_STACK))
 #define DL_INIT()       (DL_STACKP = DL_STACK)
 #define DL_CD_INIT()    (DL_CD_STACKP = DL_CD_STACK)
 #define DL_POP()        ((*DL_STACKP--).dirp)
@@ -127,12 +124,11 @@ void scanner_quit
 */
 int scanner
 #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 " $(DL_STACKSIZE)     \
+#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 " $(DL_STACKSIZE)        \
   " exceeded during directory scan\n"
-#define ERR_DL     "Fatal: Directory List Stack Corruption %x\n", DL_LEN()
+#define ERR_DL     "Fatal: Directory List Stack Corruption %i\n", DL_LEN()
 ()
 { int ntok = 0;
  scan:
@@ -143,11 +139,7 @@ int scanner
   if (DL_CD_LEN() > 0)               //There are entities to process
     { if (DL_CD_POP() == NULL)            //If the dirent is null, then the
         goto libfail;                       //lib function in dirent has failed
-<<<<<<< HEAD
       ntok += lexer_lexstring(DL_CD_CURNAME());//lex the directory name
-=======
-      ntok += lexer_lexstring(DL_CD_CURNAME());  //lex the directory name
->>>>>>> 15d3ab5e7871ff459af13089b82bf5f17f731ebd
       if (DL_LEN() >= DL_STACKSIZE)       //fail if maxdepth exceeded
         { fprintf(stderr, ERR_DEPTH);
           goto fail;
@@ -187,7 +179,7 @@ int scanner_scanpixels
 ( int*  buf,
   int   max_len
 )
-{ static int col_len, row_len, row;
+{ static int /*col_len,*/ row_len = 0, row;
   //Open the current file if not yet open
   if (current_open_file == NULL) 
     { if ((current_open_file = fopen(DL_CD_CURNAME(),"rb")) == NULL)
@@ -227,12 +219,15 @@ int dredge_current_depth
 #define DPS_LEN()     (lexer_direntpp - lexer_direntpa)
 #define DPS_PUSH(E)   (*lexer_direntpp++ = E)
 ()
-{ struct dirent**  direntpp = lexer_direntpa;
-  DIR*             cwd      = DL_CURDIR();
-  struct dirent*   direntp;
+{ DIR*           cwd      = DL_CURDIR();
+  struct dirent* direntp;
   DL_CD_INIT();
  scan_next:
-  if ((direntp = readdir(cwd)) != NULL)
+  errno = 0;
+  direntp = readdir(cwd);
+  if (errno)
+    return -1;
+  if (direntp != NULL)
     { switch (direntp->d_type)
         { case DT_REG:
             DPS_PUSH(direntp);
@@ -248,8 +243,6 @@ int dredge_current_depth
             goto scan_next;
         }
     }
-  if (errno)
-    return -1;
   qsort(lexer_direntpa, DPS_LEN(), sizeof direntp, (qcomp)alphasort);
   return DPS_LEN();
 }