summaryrefslogtreecommitdiffstats
path: root/lib/parse_ini.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse_ini.c')
-rw-r--r--lib/parse_ini.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index c915d79..b555316 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -85,14 +85,14 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
85 /* if a file was specified or if we're using the default file */ 85 /* if a file was specified or if we're using the default file */
86 if(i.file != NULL && strlen(i.file) > 0){ 86 if(i.file != NULL && strlen(i.file) > 0){
87 if(strcmp(i.file, "-")==0){ 87 if(strcmp(i.file, "-")==0){
88 inifile=stdout; 88 inifile=stdout; /* FIXME: Shouldn't it be 'stdin' ??? */
89 } else { 89 } else {
90 inifile=fopen(i.file, "r"); 90 inifile=fopen(i.file, "r");
91 } 91 }
92 if(inifile==NULL) die(STATE_UNKNOWN, _("Config file error")); 92 if(inifile==NULL) die(STATE_UNKNOWN, _("Config file error"));
93 defaults=read_defaults(inifile, i.stanza); 93 defaults=read_defaults(inifile, i.stanza);
94 free(i.file); 94 free(i.file);
95 if(inifile!=stdout) fclose(inifile); 95 if(inifile!=stdout) fclose(inifile); /* FIXME: Shouldn't it be 'stdin' ??? */
96 } 96 }
97 free(i.stanza); 97 free(i.stanza);
98 return defaults; 98 return defaults;
@@ -126,9 +126,9 @@ static np_arg_list* read_defaults(FILE *f, const char *stanza){
126 stanzastate=WRONGSTANZA; 126 stanzastate=WRONGSTANZA;
127 for(i=0; i<stanza_len; i++){ 127 for(i=0; i<stanza_len; i++){
128 c=fgetc(f); 128 c=fgetc(f);
129 /* nope, read to the end of the stanza header */ 129 /* nope, read to the end of the line */
130 if(c!=stanza[i]) { 130 if(c!=stanza[i]) {
131 GOBBLE_TO(f, c, ']'); 131 GOBBLE_TO(f, c, '\n');
132 break; 132 break;
133 } 133 }
134 } 134 }
@@ -215,14 +215,18 @@ static int add_option(FILE *f, np_arg_list **optlst){
215 for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++); 215 for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++);
216 /* continue to the end of value (FIXME: watching for trailing comments) */ 216 /* continue to the end of value (FIXME: watching for trailing comments) */
217 for(valend=valptr; valend<lineend; valend++) 217 for(valend=valptr; valend<lineend; valend++)
218 /* FIXME: N::P doesn't allow comments. Remove next line and parse_ini won't either */ 218 /* FIXME: N::P doesn't allow comments here. Remove next line and parse_ini won't either */
219 if(*valend=='#') break; 219 if(*valend=='#') break;
220 --valend; 220 --valend;
221 /* Finally trim off trailing spaces */ 221 /* Finally trim off trailing spaces */
222 for(valend; isspace(*valend); valend--); 222 for(valend; isspace(*valend); valend--);
223 /* calculate the length of "--foo" */ 223 /* calculate the length of "--foo" */
224 opt_len=1+optend-optptr; 224 opt_len=1+optend-optptr;
225 cfg_len=2+(opt_len); 225 /* 1-character params needs only one dash */
226 if (opt_len==1)
227 cfg_len=1+(opt_len);
228 else
229 cfg_len=2+(opt_len);
226 /* if valptr<lineend then we have to also allocate space for "=bar" */ 230 /* if valptr<lineend then we have to also allocate space for "=bar" */
227 if(valptr<lineend) { 231 if(valptr<lineend) {
228 equals=value=1; 232 equals=value=1;
@@ -243,7 +247,14 @@ static int add_option(FILE *f, np_arg_list **optlst){
243 247
244 read_pos=0; 248 read_pos=0;
245 optnew->arg=(char *)malloc(cfg_len+1); 249 optnew->arg=(char *)malloc(cfg_len+1);
246 strncpy(&optnew->arg[read_pos], "--", 2); read_pos+=2; 250 /* 1-character params needs only one dash */
251 if (opt_len==1) {
252 strncpy(&optnew->arg[read_pos], "-", 1);
253 read_pos+=1;
254 } else {
255 strncpy(&optnew->arg[read_pos], "--", 2);
256 read_pos+=2;
257 }
247 strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len; 258 strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len;
248 if(equals) optnew->arg[read_pos++]='='; 259 if(equals) optnew->arg[read_pos++]='=';
249 if(value) { 260 if(value) {