X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fwebcc.git;a=blobdiff_plain;f=src%2Fbin%2Ftools%2Fapc.c;fp=src%2Fbin%2Ftools%2Fapc.c;h=a22975d6d55d8fc1f659ca3819ea40e35fb0a192;hp=0000000000000000000000000000000000000000;hb=c0288501d87f8aaacba73daee346e5adf71a9bd2;hpb=e77819fa39836d4fe0f81895297a4e78c95f5572 diff --git a/src/bin/tools/apc.c b/src/bin/tools/apc.c new file mode 100644 index 0000000..a22975d --- /dev/null +++ b/src/bin/tools/apc.c @@ -0,0 +1,67 @@ +/*!@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 //strnlen +/* Posix */ +#include //exit +#include //getopt + +const char* cargs['Z'] = {0}; + +int main(int, char*[]); + +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 S(S)#S //stringifier +#define MAXSTR 255 +#define MAXERR "-%c allows at most " S(MAXSTR) " input characters\n", 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, MAXSTR) != MAXSTR) + { 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); +} +