equal
deleted
inserted
replaced
73 /*--------------------------------------------------------------------------*/ |
73 /*--------------------------------------------------------------------------*/ |
74 static char * strstrip(const char * s) |
74 static char * strstrip(const char * s) |
75 { |
75 { |
76 static char l[ASCIILINESZ+1]; |
76 static char l[ASCIILINESZ+1]; |
77 char * last ; |
77 char * last ; |
78 |
78 |
79 if (s==NULL) return NULL ; |
79 if (s==NULL) return NULL ; |
80 |
80 |
81 while (isspace((int)*s) && *s) s++; |
81 while (isspace((int)*s) && *s) s++; |
82 memset(l, 0, ASCIILINESZ+1); |
82 memset(l, 0, ASCIILINESZ+1); |
83 strcpy(l, s); |
83 strcpy(l, s); |
84 last = l + strlen(l); |
84 last = l + strlen(l); |
85 while (last > l) { |
85 while (last > l) { |
290 sprintf(keym, "%s:", s); |
290 sprintf(keym, "%s:", s); |
291 |
291 |
292 for (j=0 ; j<d->size ; j++) { |
292 for (j=0 ; j<d->size ; j++) { |
293 if (d->key[j]==NULL) |
293 if (d->key[j]==NULL) |
294 continue ; |
294 continue ; |
295 if (!strncmp(d->key[j], keym, seclen+1)) |
295 if (!strncmp(d->key[j], keym, seclen+1)) |
296 nkeys++; |
296 nkeys++; |
297 } |
297 } |
298 |
298 |
299 return nkeys; |
299 return nkeys; |
300 |
300 |
308 @return pointer to statically allocated character strings |
308 @return pointer to statically allocated character strings |
309 |
309 |
310 This function queries a dictionary and finds all keys in a given section. |
310 This function queries a dictionary and finds all keys in a given section. |
311 Each pointer in the returned char pointer-to-pointer is pointing to |
311 Each pointer in the returned char pointer-to-pointer is pointing to |
312 a string allocated in the dictionary; do not free or modify them. |
312 a string allocated in the dictionary; do not free or modify them. |
313 |
313 |
314 This function returns NULL in case of error. |
314 This function returns NULL in case of error. |
315 */ |
315 */ |
316 /*--------------------------------------------------------------------------*/ |
316 /*--------------------------------------------------------------------------*/ |
317 char ** iniparser_getseckeys(dictionary * d, char * s) |
317 char ** iniparser_getseckeys(dictionary * d, char * s) |
318 { |
318 { |
332 |
332 |
333 keys = (char**) malloc(nkeys*sizeof(char*)); |
333 keys = (char**) malloc(nkeys*sizeof(char*)); |
334 |
334 |
335 seclen = (int)strlen(s); |
335 seclen = (int)strlen(s); |
336 sprintf(keym, "%s:", s); |
336 sprintf(keym, "%s:", s); |
337 |
337 |
338 i = 0; |
338 i = 0; |
339 |
339 |
340 for (j=0 ; j<d->size ; j++) { |
340 for (j=0 ; j<d->size ; j++) { |
341 if (d->key[j]==NULL) |
341 if (d->key[j]==NULL) |
342 continue ; |
342 continue ; |
555 static line_status iniparser_line( |
555 static line_status iniparser_line( |
556 const char * input_line, |
556 const char * input_line, |
557 char * section, |
557 char * section, |
558 char * key, |
558 char * key, |
559 char * value) |
559 char * value) |
560 { |
560 { |
561 line_status sta ; |
561 line_status sta ; |
562 char line[ASCIILINESZ+1]; |
562 char line[ASCIILINESZ+1]; |
563 int len ; |
563 int len ; |
564 |
564 |
565 strcpy(line, strstrip(input_line)); |
565 strcpy(line, strstrip(input_line)); |
569 if (len<1) { |
569 if (len<1) { |
570 /* Empty line */ |
570 /* Empty line */ |
571 sta = LINE_EMPTY ; |
571 sta = LINE_EMPTY ; |
572 } else if (line[0]=='#' || line[0]==';') { |
572 } else if (line[0]=='#' || line[0]==';') { |
573 /* Comment line */ |
573 /* Comment line */ |
574 sta = LINE_COMMENT ; |
574 sta = LINE_COMMENT ; |
575 } else if (line[0]=='[' && line[len-1]==']') { |
575 } else if (line[0]=='[' && line[len-1]==']') { |
576 /* Section name */ |
576 /* Section name */ |
577 sscanf(line, "[%[^]]", section); |
577 sscanf(line, "[%[^]]", section); |
578 strcpy(section, strstrip(section)); |
578 strcpy(section, strstrip(section)); |
579 strcpy(section, strlwc(section)); |
579 strcpy(section, strlwc(section)); |