%{ #define YYERROR_VERBOSE #include #include #include "conf.h" #include "conf_parser.h" #include "ilist.h" config_t *conf; void yyerror(const char *str) { fprintf(stderr, "error: %s\n", str); } int conf_load(const char *file) { extern FILE *yyin; if ((yyin = fopen(file, "r")) == NULL) { perror("fopen"); return -1; } conf = malloc(sizeof(config_t)); memset(conf, 0, sizeof(config_t)); yyparse(); return 0; } %} %debug %defines %locations %token NEWLINE READONLY TOKDEBUG %token DBPATH %token DBTYPE %token FILENAME %token LOGFILE %token LOGLEVEL %token MOUNTPOINT; %token NUMBER %token PKGDIR %token STRING %token WORD %union { int number; char *string; } %% commands: /* empty */ | commands command NEWLINE ; command: dbpath | dbtype | debug | logfile | loglevel | mountpoint | pkgdir | readonly; dbpath: DBPATH FILENAME { conf->dbpath = $2; } ; dbtype: DBTYPE WORD { conf->dbtype = $2; } ; debug: TOKDEBUG { conf->debug = true; } ; logfile: LOGFILE FILENAME { conf->logfile = $2; } ; loglevel: LOGLEVEL NUMBER { conf->loglevel = atoi($2); } ; mountpoint: MOUNTPOINT FILENAME { conf->mountpoint = $2; } ; pkgdir: PKGDIR FILENAME { conf->pkgdirs = ilist_push(&conf->pkgdirs, $2); } ; readonly: READONLY { conf->readonly = true; } ; %%