38 sstr_t mline; |
38 sstr_t mline; |
39 mline.ptr = NULL; |
39 mline.ptr = NULL; |
40 mline.length = 0; |
40 mline.length = 0; |
41 ConfigLine *start_line; |
41 ConfigLine *start_line; |
42 ConfigLine *end_line; |
42 ConfigLine *end_line; |
43 |
43 |
44 // read file |
44 // read file |
45 sstr_t l; |
45 sstr_t l; |
46 while((l = cfg_readln(in)).ptr != NULL) { |
46 while((l = cfg_readln(in)).ptr != NULL) { |
|
47 void *org_ptr = l.ptr; |
|
48 |
47 // put the line to the list |
49 // put the line to the list |
48 ConfigLine *line = OBJ_NEW(parser->mp, ConfigLine); |
50 ConfigLine *line = OBJ_NEW(parser->mp, ConfigLine); |
49 line->line = sstrdub(l); |
51 line->line = sstrdup_mp(parser->mp, l); // TODO: check for 0-len str |
50 line->object = NULL; |
52 line->object = NULL; |
51 line->type = LINE_OTHER; |
53 line->type = LINE_OTHER; |
52 parser->lines = ucx_dlist_append(parser->lines, line); |
54 parser->lines = ucx_dlist_append(parser->lines, line); |
53 |
55 |
54 // check if the line contains something |
56 // check if the line contains something |
57 |
59 |
58 if(line->type == LINE_OTHER) { |
60 if(line->type == LINE_OTHER) { |
59 // check for multi line |
61 // check for multi line |
60 if(mline.ptr != NULL) { |
62 if(mline.ptr != NULL) { |
61 // concate lines |
63 // concate lines |
62 char *ptr = malloc(mline.length + l.length + 1); |
64 char *ptr = ucx_mempool_malloc( |
|
65 parser->mp, |
|
66 mline.length + l.length + 1); |
|
67 |
63 memcpy(ptr, mline.ptr, mline.length); |
68 memcpy(ptr, mline.ptr, mline.length); |
64 memcpy(ptr + mline.length - 1, l.ptr, l.length); |
69 memcpy(ptr + mline.length - 1, l.ptr, l.length); |
65 mline.length += l.length; |
70 mline.length += l.length; |
66 free(mline.ptr); |
71 free(mline.ptr); |
67 mline.ptr = ptr; |
72 mline.ptr = ptr; |
71 |
76 |
72 line->type = LINE_MULTI; |
77 line->type = LINE_MULTI; |
73 } |
78 } |
74 if(l.ptr[l.length - 1] == '\\') { |
79 if(l.ptr[l.length - 1] == '\\') { |
75 if(mline.ptr == NULL) { |
80 if(mline.ptr == NULL) { |
76 mline = sstrdub(l); |
81 mline = sstrdup_mp(parser->mp, l); |
77 start_line = line; |
82 start_line = line; |
78 } |
83 } |
79 } else { |
84 } else { |
80 // this line is complete so we can parse it |
85 // this line is complete so we can parse it |
81 sstr_t ll; // we parse this line |
86 sstr_t ll; // we parse this line |
274 name.ptr = line.ptr; |
281 name.ptr = line.ptr; |
275 name.length = i; |
282 name.length = i; |
276 |
283 |
277 // create directive object |
284 // create directive object |
278 ConfigDirective *directive = OBJ_NEW(mp, ConfigDirective); |
285 ConfigDirective *directive = OBJ_NEW(mp, ConfigDirective); |
279 directive->directive_type = sstrdub(name); |
286 directive->directive_type = sstrdup_mp(mp, name); |
280 directive->type_num = cfg_get_directive_type_num(name); |
287 directive->type_num = cfg_get_directive_type_num(name); |
281 directive->condition = NULL; // set later by main parsing function |
288 directive->condition = NULL; // set later by main parsing function |
282 directive->param = NULL; |
289 directive->param = NULL; |
283 |
290 |
284 sstr_t param_str; |
291 sstr_t param_str; |
294 } |
301 } |
295 |
302 |
296 |
303 |
297 // create param object |
304 // create param object |
298 ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
305 ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
299 /* |
306 param->name = sstrdup_mp(mp, pname); |
300 * TODO: |
|
301 * Wenn man sstrdub_mp statt sstrdub nimmt, wird der Inhalt von pname |
|
302 * verunstaltet. Warum? |
|
303 */ |
|
304 param->name = sstrdub(pname); |
|
305 |
307 |
306 if(pvalue.length > 0) { |
308 if(pvalue.length > 0) { |
307 param->value = sstrdub(pvalue); |
309 param->value = sstrdup_mp(mp, pvalue); |
308 } else { |
310 } else { |
309 param->value.ptr = NULL; |
311 param->value.ptr = NULL; |
310 param->value.length = 0; |
312 param->value.length = 0; |
311 } |
313 } |
312 |
314 |
368 int cfg_get_line_type(sstr_t line) { |
370 int cfg_get_line_type(sstr_t line) { |
369 if(line.length < 3) { |
371 if(line.length < 3) { |
370 // this line is to short to be correct |
372 // this line is to short to be correct |
371 return LINE_ERROR; |
373 return LINE_ERROR; |
372 } |
374 } |
373 |
375 |
374 if(line.ptr[0] == '<') { |
376 if(line.ptr[0] == '<') { |
375 // start or end tag |
377 // start or end tag |
376 // TODO: check for space between '<' and '/' |
378 // TODO: check for space between '<' and '/' |
377 if(line.ptr[1] == '/') { |
379 if(line.ptr[1] == '/') { |
378 return LINE_END_TAG; |
380 return LINE_END_TAG; |
472 break; |
474 break; |
473 } |
475 } |
474 |
476 |
475 // create param object |
477 // create param object |
476 ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
478 ConfigParam *param = OBJ_NEW(mp, ConfigParam); |
477 param->name = sstrdub_mp(mp, pname); |
479 param->name = sstrdup_mp(mp, pname); |
478 if(pvalue.length > 0) { |
480 if(pvalue.length > 0) { |
479 param->value = sstrdub_mp(mp, pvalue); |
481 param->value = sstrdup_mp(mp, pvalue); |
480 } else { |
482 } else { |
481 param->value.ptr = NULL; |
483 param->value.ptr = NULL; |
482 param->value.length = 0; |
484 param->value.length = 0; |
483 } |
485 } |
484 |
486 |