owntone-server/src/parser-driver.c

94 lines
2.0 KiB
C
Raw Normal View History

/*
* Test harness for the parser
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "daapd.h"
#include "conf.h"
#include "db-generic.h"
#include "err.h"
#include "smart-parser.h"
CONFIG config;
2006-08-20 03:46:10 +00:00
char *scan_winamp_genre[] = { NULL };
void usage(void) {
2006-03-10 23:41:13 +00:00
printf("Usage:\n\n parser [-t <type (0/1)>] [-d <debug level>] \"phrase\"\n\n");
exit(0);
}
int main(int argc, char *argv[]) {
int option;
2006-03-10 23:41:13 +00:00
int type=0;
PARSETREE pt;
char *configfile = "/etc/mt-daapd.conf";
2006-08-20 03:59:37 +00:00
int debuglevel=0;
char db_type[40];
char db_parms[PATH_MAX];
int size;
int err;
char *perr;
2006-03-19 06:33:53 +00:00
while((option = getopt(argc, argv, "d:t:c:")) != -1) {
switch(option) {
case 'c':
configfile = optarg;
break;
case 'd':
2006-08-20 03:59:37 +00:00
debuglevel = atoi(optarg);
break;
2006-03-10 23:41:13 +00:00
case 't':
type = atoi(optarg);
break;
default:
fprintf(stderr,"Error: unknown option (%c)\n\n",option);
usage();
}
}
2006-08-20 03:59:37 +00:00
// err_setdebugmask("parse");
2006-03-19 06:43:32 +00:00
if(conf_read(configfile) != CONF_E_SUCCESS) {
fprintf(stderr,"could not read config file: %s\n",configfile);
exit(1);
}
2006-08-20 03:59:37 +00:00
if(debuglevel) {
printf("Setting debug level to %d\n",debuglevel);
err_setlevel(debuglevel);
err_setdest(LOGDEST_STDERR);
}
size = sizeof(db_type);
conf_get_string("general","db_type","sqlite",db_type,&size);
size = sizeof(db_parms);
conf_get_string("general","db_parms","/var/cache/mt-daapd",db_parms,&size);
err=db_open(&perr,db_type,db_parms);
if(err != DB_E_SUCCESS) {
fprintf(stderr,"Error opening db: %s\n",perr);
free(perr);
exit(1);
}
printf("Parsing %s\n",argv[optind]);
pt=sp_init();
2006-03-10 23:41:13 +00:00
if(!sp_parse(pt,argv[optind],type)) {
printf("%s\n",sp_get_error(pt));
} else {
printf("SQL: %s\n",sp_sql_clause(pt));
}
sp_dispose(pt);
conf_close();
printf("Done!\n");
return 0;
}