2 \brief lexical analyzer implementation for APC
3 \details this lexer scans a root directory given from the command line
4 for subdirectories and files structured for the APC grammar.
7 ----------------------------------------------------------------------------*/
16 #include "fileparser.tab.h"
17 #define TOKEN_BUF_SIZE 1024
18 #define DIRP_STACK_SIZE 512
27 int token_buf
[TOKEN_BUF_SIZE
], *tbp
, *tbx
;
29 DIR* dirp_stack
[DIRP_STACK_SIZE
], *dsp
;
31 /* Initialize pointers */
34 { tbp
= tbx
= token_buf
;
39 /* Returns a token identifier and sets yylval */
42 { if (lexer_scan() == 0)
49 Scans a filename from its alphabetically ordered list of file elements
50 and tokenizes the result. If the file list is empty, then the stack of
51 directory elements will be popped and processed as they are encountered.
53 Returns the number of tokens generated.
55 #define MAX_ENTITIES 256
58 { static struct dirent
* entity
;
59 static struct dirent
* files
[MAX_ENTITIES
];
60 static struct dirent
* dirs
= files
+ MAX_ENTITIES
- 1;
61 static int num_files
= 0;
62 static int num_dirs
= 0;
64 //sort out files and directories, grow directories from bottom up
65 while ((entity
= readdir(dirp
)) != NULL
)
66 { switch (entity
->d_type
)
69 files
[num_files
++] = entity
;
72 *(dirs
- num_dirs
++) = entity
;
76 printf("Ignoring unknown file: %s\n", entity
->d_name
);
82 qsort(&files
[0], num_files
, sizeof struct dirent
*, qalpha
);
83 num_ents
= scandirat(dirfd
, ".", &namelist
, scanfilter
, scancompar
);
85 { perror("scandirat");
90 //recurse into directories