3 \details The driver assumes the existence of a bison-generated parser,
4 referenced by the external function 'yyparse'.
5 It also assumes the existence of a lexer which must be initialized
6 before parsing, referenced by the external function 'lexer_init'
7 which assumes standard error handling.
8 All input arguments are made available through the exposed (that is,
9 non-static) array of character pointers 'cargs', which point
10 to the non-duplicated strings in 'argv' directly from the system.
11 \author Jordan Lavatai
13 ----------------------------------------------------------------------------*/
15 #include <stdio.h> //print
16 #include <errno.h> //errors
17 #include <string.h> //strndupa
19 #include <stdlib.h> //exit
20 #include <unistd.h> //getopt, sysconf
22 #include "parser.tab.h" //bison
25 #define DEFAULT_PAGESIZE 4096
29 int main(int, char*[]);
34 int scanner_init(void);
36 void scanner_quit(void);
38 int scanner_scanpath(char const*);
44 int ir_condenser(void);
48 /* Main entry from terminal
49 parses the command line and kicks off recursive scanning
55 #define $($)#$ //stringifier
57 #define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt
59 #define USAGE "Usage %s [-d dir_root][-o output_file][-h]\n", argv[0]
62 "\t\t-d\tRoot directory to parse from \t[./]\n" \
63 "\t\t-o\tOutput filename \t\t[a.asspak]\n" \
64 "\t\t-h\tPrint this help\n"
66 #define SCANPATH (cargs['d'] ? cargs['d'] : "./")
68 cargs
= (const char**) malloc('Z');
70 switch (opt
= getopt(argc
, argv
, OPTS
))
73 if (strnlen(optarg
, MAXSTR
) != MAXSTR
)
74 { cargs
[opt
] = optarg
;
77 fprintf(stderr
, MAXERR
);
79 fprintf(stderr
, USAGE
);
88 if ((sys_pagesize
= sysconf(_SC_PAGESIZE
)) == 0)
89 sys_pagesize
= DEFAULT_PAGESIZE
;
95 if (scanner_scanpath(SCANPATH
))