35 InitConfig *load_init_config(char *file) { |
35 InitConfig *load_init_config(char *file) { |
36 FILE *in = fopen(file, "r"); |
36 FILE *in = fopen(file, "r"); |
37 if(in == NULL) { |
37 if(in == NULL) { |
38 return NULL; |
38 return NULL; |
39 } |
39 } |
40 |
40 |
41 InitConfig *conf = malloc(sizeof(InitConfig)); |
41 InitConfig *conf = malloc(sizeof(InitConfig)); |
42 conf->parser.parse = initconf_parse; |
42 conf->parser.parse = initconf_parse; |
43 conf->file = file; |
43 conf->file = file; |
|
44 conf->directives = NULL; |
44 |
45 |
45 int r = cfg_parse_basic_file((ConfigParser*)conf, in); |
46 int r = cfg_parse_basic_file((ConfigParser*)conf, in); |
46 if(r != 0) { |
47 if(r != 0) { |
47 // TODO: free |
48 // TODO: free |
48 return NULL; |
49 return NULL; |
62 free(conf); |
63 free(conf); |
63 } |
64 } |
64 |
65 |
65 int initconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
66 int initconf_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
66 InitConfig *conf = p; |
67 InitConfig *conf = p; |
67 |
68 |
68 // parse directive |
69 // parse directive |
69 ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); |
70 ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp); |
70 if(d == NULL) { |
71 if(d == NULL) { |
71 fprintf(stderr, "Error: initconf_parse: directive is null\n"); |
72 fprintf(stderr, "Error: initconf_parse: directive is null\n"); |
72 return 0; |
73 return 0; |