1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include "config_internal.h"
#include "libconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern FILE *yyin;
extern int yyparse();
static config_t *config_table;
int set_config_int(char *option,int value)
{
config_t *item;
//printf("Setting %s to %i\n",option,value);
for(item=config_table;item->key;item++) {
if (!strcmp(item->key,option)) {
if ((item->type&TYPE_MASK) == TYPE_INT
|| ((item->type&TYPE_MASK)==TYPE_BOOL && (value==0 || value==1))) {
*((int *)item->value)=value;
return 0;
}
else {
printf("%s does not take an int\n",option);
}
}
}
printf("Unknown configuration option %s\n",option);
return 1;
}
int set_config_str(char *option,char *value)
{
config_t *item;
//printf("Setting %s to %s\n",option,value);
for(item=config_table;item->key;item++) {
if (!strcmp(item->key,option)) {
if ((item->type&TYPE_MASK) == TYPE_STR) {
if (*((char **)item->value))
free(*((char **)item->value));
*((char**)item->value)=value;
return 0;
}
else {
printf("%s does not take an string\n",option);
}
}
}
printf("Unknown configuration option %s\n",option);
return 1;
}
int parse_config(config_t *config,char *filename)
{
yyin = fopen(filename,"r");
config_table=config;
if (!yyin) {
return 1;
}
yyparse();
fclose(yyin);
return 0;
}
|