rendered paste body%{
#define YYERROR_VERBOSE
#include <stdio.h>
#include <string.h>
#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 <string> DBPATH
%token <string> DBTYPE
%token <string> FILENAME
%token <string> LOGFILE
%token <number> LOGLEVEL
%token <string> MOUNTPOINT;
%token <number> NUMBER
%token <string> PKGDIR
%token <string> STRING
%token <string> 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;
}
;
%%