2005-08-01 23:17:22 -04:00
|
|
|
/*
|
|
|
|
* Test harness for the parser
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2005-10-14 00:11:06 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "err.h"
|
2005-08-01 23:17:22 -04:00
|
|
|
#include "smart-parser.h"
|
|
|
|
|
2005-10-14 00:11:06 -04:00
|
|
|
void usage(void) {
|
|
|
|
printf("Usage:\n\n parser [-d <debug level>] \"phrase\"\n\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2005-08-01 23:17:22 -04:00
|
|
|
int main(int argc, char *argv[]) {
|
2005-10-14 00:11:06 -04:00
|
|
|
int option;
|
2005-08-01 23:17:22 -04:00
|
|
|
PARSETREE pt;
|
|
|
|
|
2005-10-14 00:11:06 -04:00
|
|
|
while((option = getopt(argc, argv, "d:")) != -1) {
|
|
|
|
switch(option) {
|
|
|
|
case 'd':
|
|
|
|
err_debuglevel = atoi(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr,"Error: unknown option (%c)\n\n",option);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
printf("Parsing %s\n",argv[optind]);
|
2005-08-01 23:17:22 -04:00
|
|
|
|
|
|
|
pt=sp_init();
|
2005-10-22 19:05:29 -04:00
|
|
|
if(!sp_parse(pt,argv[optind])) {
|
|
|
|
printf("%s\n",sp_get_error(pt));
|
|
|
|
} else {
|
|
|
|
printf("SQL: %s\n",sp_sql_clause(pt));
|
|
|
|
}
|
2005-10-21 03:48:07 -04:00
|
|
|
|
2005-08-01 23:17:22 -04:00
|
|
|
sp_dispose(pt);
|
|
|
|
|
|
|
|
printf("Done!\n");
|
|
|
|
return 0;
|
|
|
|
}
|