scanner_scanpixels prototype
[henge/webcc.git] / src / apc / scanner.c
index 0d51ffe..a999c7b 100644 (file)
 #include <stdlib.h> //exit
 #include <unistd.h> //chdir
 #include <dirent.h> //opendir
 #include <stdlib.h> //exit
 #include <unistd.h> //chdir
 #include <dirent.h> //opendir
-
+/* Libs */
+#include <png.h>
+/* Internal */
 #include "parser.tab.h"
 /* Public */
 int   scanner_init(void);
 void  scanner_quit(void);
 int   scanner(void);
 #include "parser.tab.h"
 /* Public */
 int   scanner_init(void);
 void  scanner_quit(void);
 int   scanner(void);
+int   scanner_scanpixels(int*,int);
 /* Private */
 #ifndef DL_STACKSIZE
 #define DL_STACKSIZE     64
 /* Private */
 #ifndef DL_STACKSIZE
 #define DL_STACKSIZE     64
@@ -110,8 +113,7 @@ void scanner_quit
    array, while placing all subdirectory entries in the current depth's child
    directory stack to be scanned later.
 
    array, while placing all subdirectory entries in the current depth's child
    directory stack to be scanned later.
 
-   Returns the number of elements added to the lexer's file array, or -1 on
-   error
+   Returns the number of tokens generated on success, -1 on error.
 */
 int scanner
 #define $($)#$ //stringifier
 */
 int scanner
 #define $($)#$ //stringifier
@@ -124,7 +126,8 @@ int scanner
 ()
 { struct dirent* direntp;
   struct DIR* DIRp;
 ()
 { struct dirent* direntp;
   struct DIR* DIRp;
- parse:
+  int ntok = 0;
+ scan:
   if (DL_CD_LEN() >= DL_CD_STACKSIZE)//fail if maxchildren exceeded
     { fprintf(stderr, ERR_CHILD);
       goto fail;
   if (DL_CD_LEN() >= DL_CD_STACKSIZE)//fail if maxchildren exceeded
     { fprintf(stderr, ERR_CHILD);
       goto fail;
@@ -132,7 +135,7 @@ int scanner
   if (DL_CD_LEN() > 0)               //There are entities to process
     { if ((direntp = DL_CD_POP()) == NULL)//If the dirent is null, the library
         goto libfail;                     //function in dirent has failed
   if (DL_CD_LEN() > 0)               //There are entities to process
     { 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
+      ntok += lexer_lex(direntp->d_name); //lex the directory name
       if (DL_LEN() >= DL_STACKSIZE)       //fail if maxdepth exceeded
         { fprintf(stderr, ERR_DEPTH);
           goto fail;
       if (DL_LEN() >= DL_STACKSIZE)       //fail if maxdepth exceeded
         { fprintf(stderr, ERR_DEPTH);
           goto fail;
@@ -143,22 +146,26 @@ int scanner
       if (DL_CURDIR() == NULL)            //open the cwd
        goto libfail;
       lexer_pushtok(CLOPEN, 0);           //Push "Open Directory" token
       if (DL_CURDIR() == NULL)            //open the cwd
        goto libfail;
       lexer_pushtok(CLOPEN, 0);           //Push "Open Directory" token
+      ntok++;
       return dredge_current_depth();      //Filter and sort the current depth
     }
   else if (DL_LEN() >= 0)            //Any dirs left? (Including root)
     { if (closedir(DL_POP()))             //close the directory we just left
         goto libfail;
       if (DL_LEN() == -1)                 //If we just popped root,
       return dredge_current_depth();      //Filter and sort the current depth
     }
   else if (DL_LEN() >= 0)            //Any dirs left? (Including root)
     { if (closedir(DL_POP()))             //close the directory we just left
         goto libfail;
       if (DL_LEN() == -1)                 //If we just popped root,
-        return 0;                         //we're done
+        goto done;                        //we're done
       lexer_pushtok(CLCLOSE, 0);          //Else push "Close Directory" token,
       lexer_pushtok(CLCLOSE, 0);          //Else push "Close Directory" token,
+      ntok++;
       if (!chdir(".."))                   //move up a directory and
       if (!chdir(".."))                   //move up a directory and
-        goto parse;                       //start over
+        goto scan;                        //start over
     }
   fprintf(stderr, ERR_DL);
  libfail:
   perror("parsedir");
  fail:
     }
   fprintf(stderr, ERR_DL);
  libfail:
   perror("parsedir");
  fail:
-  exit(EXIT_FAILURE);
+  return -1;
+ done:
+  return ntok;
 }
 
 /* Directory Entity Sort and Filter (Dredge)
 }
 
 /* Directory Entity Sort and Filter (Dredge)
@@ -170,7 +177,7 @@ int scanner
    Returns -1 if 'readdir' encounters an error, otherwise returns the number of
    directory entries sent to the external 'lexer_direntpa' array.
 */
    Returns -1 if 'readdir' encounters an error, otherwise returns the number of
    directory entries sent to the external 'lexer_direntpa' array.
 */
-typedef
+typedef //so we can typecast dirent's 'alphasort()' to take const void*s
 int (*qcomp)(const void*, const void*);
 static inline
 int dredge_current_depth
 int (*qcomp)(const void*, const void*);
 static inline
 int dredge_current_depth
@@ -207,3 +214,18 @@ int dredge_current_depth
 }
 
 
 }
 
 
+/* Scan Pixels 
+   Scans up to 'len' pixels from the current file into 'buf'.
+   Returns the number of pixels scanned from the file, or -1 on error.
+*/
+int scanner_scanpixels
+( int* buf,
+  int x
+)
+{ int pixels = 0;
+  //Open the current file if not yet open
+    //Identify file type
+    //Verify file contents and header
+  //Read pixels into buffer
+  return pixels;
+}