//#include "xtradecls.h" /* declares yyparse() */ #include /* for printf() */ #include "jqplib.h" /* has getTree() and setTree() */ #include "bintree.h" /* has struct bintree functions */ #include /* for getopt_long_only() */ #include /* for exit() */ /* $Id: jqpmain.c,v 1.14 2005/09/04 14:14:46 joshr Exp $ */ /* By Josh Rabinowitz 2005 */ /* we must provide the main() which calls yyparse() */ int main (int argc, char** argv) { /* int getopt_long_only(int argc, char * const *argv, const char *optstring, */ /* const struct option *longopts, int *longindex); */ yyparse(); /* call the yaccer, which calls the lexer. setTree() is called */ if ( getTree() ) { print_inorder( getTree(), 0 ); printf("\n"); } return 0; } /* prints usage statement and exits */ void usage (int argc, char **argv) { printf("%s: USAGE STATEMENT\n", argv[0]); exit(1); } int parse_command_line (int argc, char ** argv) { /* based on 'man getopt_long' */ /* so far this is purely for dev -- it doesn't work (yet) */ int bflag, ch, fd; int daggerset; /* options descriptor */ /* static */ struct option longopts[] = { { "buffy", no_argument, NULL, 'b' }, { "fluoride", required_argument, NULL, 'f' }, { "daggerset", no_argument, &daggerset, 1 }, { NULL, 0, NULL, 0 } }; bflag = 0; while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) switch (ch) { case 'b': bflag = 1; break; case 'f': /* if ((fd = open(optarg, O_RDONLY, 0)) == -1) err(1, "unable to open %s", optarg); */ break; case 0: if (daggerset) { fprintf(stderr,"Buffy will use her dagger to " "apply fluoride to dracula's teeth\n"); } break; default: usage(argc, argv); } argc -= optind; argv += optind; return 0; } /* this creates a small tree and prints it out, for testing */ void test_tree() { bintree *tree0 = init_new_node("test0", 0, NULL, NULL); /* name, token, leftchild, rightchild */ bintree *tree1 = init_new_node("test1", 0, NULL, NULL); bintree *tree2 = init_new_node("test2", 0, tree0, tree1); bintree *tree3 = init_new_node("test3", 0, NULL, tree2); print_inorder(tree3, 0); printf("\n"); }