/*!@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 /* Posix */ #include //getopt int main(int, char*[]); const char* cargs['Z'] = {0}; extern //bison void yyparse(void); extern //lexer.c int lexer_init(void); /* Main entry from terminal parses the command line and kicks off recursive scanning */ int main ( int argc, char* argv[] ) #define MAXERR "-%c allows at most " #MAX_STR_LEN " input characters", opt #define USAGE "Usage: %s [-r root]\n", argv[0] #define DONE -1 { int opt; getopt: switch (opt = getopt(argc, argv, "r:o:")) { case DONE: break; case 'r' : case 'o' : if (strnlen(optarg, MAX_STR_LEN) != MAX_STR_LEN) { cargs[opt] = optarg; goto getopt; } fprintf(stderr, MAXERR); default : fprintf(stderr, USAGE); exit(EXIT_FAILURE); } if (lexer_init()) { perror("lexer"); exit(EXIT_FAILURE); } yyparse(); exit(EXIT_SUCCESS); }