37 int verbose=0;
if(status!=NULL) verbose=status->
verbose-1;
38 if(verbose>10) printf(
"%s(*ift, %d, fp)\n", __func__, item);
43 if(item<0 || item>=ift->
keyNr) {
51 case 1: strcpy(eq_sign,
":=");
break;
52 case 2: strcpy(eq_sign,
"=");
break;
53 case 3: strcpy(eq_sign,
":");
break;
54 case 4: strcpy(eq_sign,
" ");
break;
55 case 5: strcpy(eq_sign,
"\t");
break;
56 case 6: strcpy(eq_sign,
",");
break;
57 case 7: strcpy(eq_sign,
";");
break;
58 default: strcpy(eq_sign,
":=");
break;
61 int n=5;
if(ift->
item[item].
key!=NULL) n+=strlen(ift->
item[item].
key);
64 if(verbose>100) printf(
" n := %d\n", n);
67 if(ift->
item[item].
comment!=0) strcpy(cmt,
"# ");
else strcpy(cmt,
"");
70 sprintf(line,
"%s%s", cmt, ift->
item[item].
value);
74 sprintf(line,
"%s%s%s%s", cmt, ift->
item[item].
key, eq_sign, ift->
item[item].
value);
76 sprintf(line,
"%s%s %s%s", cmt, ift->
item[item].
key, eq_sign, ift->
item[item].
value);
78 sprintf(line,
"%s%s%s %s", cmt, ift->
item[item].
key, eq_sign, ift->
item[item].
value);
80 sprintf(line,
"%s%s %s %s", cmt, ift->
item[item].
key, eq_sign, ift->
item[item].
value);
83 if(fprintf(fp,
"%s\n", line) < (
int)strlen(line)) {
145 int is_comment_accepted,
151 int verbose=0;
if(status!=NULL) verbose=status->
verbose-1;
153 printf(
"%s(*ift, fp, %d, %d)\n", __func__, is_key_required, is_comment_accepted);
156 int initial_key_nr=0;
if(ift->
keyNr>0) initial_key_nr=ift->
keyNr;
158 printf(
" initial_key_nr := %d\n", initial_key_nr);
164 if(verbose>11) {printf(
" ASCII size := %d\n", (
int)fsize); fflush(stdout);}
166 if( fsize<1 || (is_key_required && fsize<3) ) {
186 while((line=
strTokenDup(cptr,
"\n\r", &j))!=NULL) {
187 if(verbose>15) {printf(
" '%s'\n", line); fflush(stdout);}
188 ret=
iftPutFromString(ift, line, is_key_required, is_comment_accepted, status);
189 if(verbose>1 && ret!=0) {
190 fprintf(stderr,
"Warning: cannot read line %d: '%s'.\n", i, line);
193 free(line); cptr+=j; i++;
197 if(initial_key_nr==ift->
keyNr && is_key_required) {
199 while((line=
strTokenDup(cptr,
"\n\r", &j))!=NULL) {
201 if(verbose>1 && ret!=0)
202 fprintf(stderr,
"Warning: cannot read line %d: '%s'.\n", i, line);
203 free(line); cptr+=j; i++;
245 int is_comment_accepted,
250 if(line==NULL || strlen(line)<1) {
254 int verbose=0;
if(status!=NULL) verbose=status->
verbose-1;
256 printf(
"%s(ift, ", __func__);
257 if(line!=NULL) printf(
"\"%s\", ", line);
else printf(
"NULL, ");
258 printf(
"%d, %d)\n", is_key_required, is_comment_accepted);
261 if(is_key_required==2) {
266 char *lptr=(
char*)line;
int i;
char cmt;
269 if((is_comment_accepted==0 && cmt) || (is_comment_accepted==2 && !cmt)) {
280 while(eq_ptr==NULL) {
281 if(verbose>100) printf(
"cptr2 := '%s'\n", cptr2);
283 if(eq_ptr[1]==
'\\') {
285 cptr2=eq_ptr+2; eq_ptr=NULL;
continue;
287 if(verbose>100) printf(
"eq_ptr := '%s'\n", eq_ptr);
288 if(strlen(cptr2)-strlen(eq_ptr)<2)
break;
289 if(verbose>100) printf(
"is this time '%s'\n", eq_ptr-2);
292 if(verbose>100) printf(
"yes it was\n");
293 cptr2=eq_ptr+6; eq_ptr=NULL;
297 if(is_key_required!=0 && eq_ptr==NULL) {
298 if(verbose>50) printf(
"key required but equals sign not found\n");
303 char *key=NULL, *value=NULL;
311 key=
strndup(lptr, strlen(lptr)-strlen(eq_ptr));
312 if(verbose>100) printf(
"key before cleaning is '%s'\n", key);
314 if(verbose>100) printf(
"key after cleaning is '%s'\n", key);
316 int j=strspn(eq_ptr,
":="); value=
strdup(eq_ptr+j);
317 if(verbose>100) printf(
"value before cleaning is '%s'\n", value);
319 if(verbose>100) printf(
"value after cleaning is '%s'\n", value);
322 int ret=
iftPut(ift, key, value, cmt, status);
323 free(key); free(value);
349 int is_comment_accepted,
354 if(line==NULL || strlen(line)<1) {
358 int verbose=0;
if(status!=NULL) verbose=status->
verbose-1;
360 printf(
"%s(ift, ", __func__);
361 if(line!=NULL) printf(
"\"%s\", ", line);
else printf(
"NULL, ");
362 printf(
"%d)\n", is_comment_accepted);
366 char *lptr=(
char*)line;
int i;
char cmt;
369 if((is_comment_accepted==0 && cmt) || (is_comment_accepted==2 && !cmt)) {
381 if(verbose>50) printf(
"key required but space not found\n");
386 char *key=NULL, *value=NULL;
388 key=
strndup(lptr, strlen(lptr)-strlen(eq_ptr));
389 if(verbose>100) printf(
"key before cleaning is '%s'\n", key);
391 if(verbose>100) printf(
"key after cleaning is '%s'\n", key);
393 int j=strspn(eq_ptr,
" \t"); value=
strdup(eq_ptr+j);
394 if(verbose>100) printf(
"value before cleaning is '%s'\n", value);
396 if(verbose>100) printf(
"value after cleaning is '%s'\n", value);
398 int ret=
iftPut(ift, key, value, cmt, status);
399 free(key); free(value);
int iftPut(IFT *ift, const char *key, const char *value, char comment, TPCSTATUS *status)
int iftRead(IFT *ift, FILE *fp, int is_key_required, int is_comment_accepted, TPCSTATUS *status)