/*!@file \brief APC main driver \details The driver assumes the existence of a bison-generated parser, referenced by the external function 'yyparse'. It also assumes the existence of a lexer which must be initialized before parsing, referenced by the external function 'lexer_init' which assumes standard error handling. All input arguments are made available through the exposed (that is, non-static) array of character pointers 'cargs', which point to the non-duplicated strings in 'argv' directly from the system. \author Jordan Lavatai \date Aug 2016 ----------------------------------------------------------------------------*/ /* Standard */ #include //print #include //errors #include //strndupa /* Posix */ #include //exit #include //getopt /* Internal */ #include "parser.tab.h" //bison const char* cargs['Z'] = {0}; int main(int, char*[]); extern //bison int yyparse(void); extern //lexer.c int lexer_init(void); extern //ir.c int ir_init(void); extern //apc/parser.tab.c YYSTYPE yylval; extern //lexer.c int lexer(void); /* Main entry from terminal parses the command line and kicks off recursive scanning */ int main ( int argc, char* argv[] ) #define $($)#$ //stringifier #define MAXSTR 255 #define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt #define OPTS "d:o:h-" #define USAGE "Usage %s [-d dir_root][-o output_file][-h]\n", argv[0] #define USAGE_LONG \ "\tOptions:\n" \ "\t\t-d\tRoot directory to parse from \t[./]\n" \ "\t\t-o\tOutput filename \t\t[a.asspak]\n" \ "\t\t-h\tPrint this help\n" #define DONE -1 { int opt; getopt: switch (opt = getopt(argc, argv, OPTS)) { case DONE: break; case 'd' : case 'o' : if (strnlen(optarg, MAXSTR) != MAXSTR) { cargs[opt] = optarg; goto getopt; } fprintf(stderr, MAXERR); default : fprintf(stderr, USAGE); exit(EXIT_FAILURE); case 'h' : printf(USAGE); printf(USAGE_LONG); exit(EXIT_SUCCESS); } if (lexer_init() || ir_init()) { perror("init"); exit(EXIT_FAILURE); } yyparse(); exit(EXIT_SUCCESS); }