34 int i, ret, nr=0, line=0, eq_type=0, initial_key_nr=0, nonprintable=0;
35 char *allfile, *cptr, *key_ptr, *value_ptr, *eq_ptr, *eq_ptr2, *cmt_ptr;
36 char empty_char=(char)0;
41 if(verbose>0) printf(
"%s(*ift, %s)\n", __func__, filename);
42 if(ift==NULL)
return(1);
43 if(filename==NULL || strlen(filename)<1) {
49 if(strcasecmp(filename,
"stdin")==0) {
52 fp=fopen(filename,
"r");
53 if(fp==NULL) {
iftSetStatus(ift, IFT_CANNOTREAD);
return(2);}
57 nr=nonprintable=0;
while((ret=fgetc(fp))!=EOF) {
58 if(iscntrl(ret) && ret!=13 && ret!=10 && ret!=9) {
59 nonprintable=1;
break;}
63 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
73 if(verbose>1) printf(
" the size of file is %d bytes\n", nr);
75 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
81 allfile=(
char*)calloc((nr+3),
sizeof(
char));
83 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
88 i=0;
while((ret=fgetc(fp))!=EOF && i<nr) allfile[i++]=(char)ret;
89 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
91 if(allfile[i-1]!=10 && allfile[i-1]!=13) {allfile[i++]=(char)13; allfile[i++]=(char)10;}
95 cptr=strtok(allfile,
"\n\r"); line=0;
97 if(verbose>2) printf(
"line %d: '%s'\n", line, cptr);
99 i=strspn(cptr,
" \t"); cptr+=i;
100 if(strlen(cptr)<1) {cptr=strtok(NULL,
"\n\r"); line++;
continue;}
102 if((cmt_ptr=strchr(
"#!;%", cptr[0]))!=NULL) {
103 cmt_ptr=cptr; cptr++; i=strspn(cptr,
" \t"); cptr+=i;
104 if(strlen(cptr)<1) {cptr=strtok(NULL,
"\n\r"); line++;
continue;}
106 if(verbose>2) printf(
" line %d: '%s'\n", line, cptr);
113 if(eq_ptr!=NULL && strlen(cptr)>=strlen(eq_ptr)+2 &&
istime(eq_ptr-2)<=0) {
116 if(eq_ptr2!=NULL && strlen(cptr)>=strlen(eq_ptr2)+2) {
117 if(
istime(eq_ptr2-2)<=0) eq_ptr2=NULL;
else eq_ptr=eq_ptr2;
123 if(is_key_required) {cptr=strtok(NULL,
"\n\r"); line++;
continue;}
125 key_ptr=eq_ptr=&empty_char; value_ptr=cptr;
127 if(strncmp(eq_ptr,
":=", 2)==0) eq_type=1;
128 else if(strncmp(eq_ptr,
"=", 1)==0) eq_type=2;
129 else if(strncmp(eq_ptr,
":", 1)==0) eq_type=3;
131 *eq_ptr=(char)0; eq_ptr++; key_ptr=cptr;
133 i=strspn(eq_ptr,
":="); value_ptr=eq_ptr+i;
135 i=strspn(value_ptr,
" \t"); value_ptr+=i;
138 i=strlen(key_ptr);
while(i>0 && isspace((
int)key_ptr[i-1])) i--; key_ptr[i]=(char)0;
140 if(is_key_required) {cptr=strtok(NULL,
"\n\r"); line++;
continue;}
142 i=strlen(value_ptr);
while(i>0 && isspace((
int)value_ptr[i-1])) i--; value_ptr[i]=(char)0;
143 if(verbose>2) printf(
" key='%s' value='%s'\n", key_ptr, value_ptr);
145 i=strlen(key_ptr)-1;
if(i<0) i=0;
146 if((key_ptr[0]==
'\'' && key_ptr[i]==
'\'') || (key_ptr[0]==
'\"' && key_ptr[i]==
'\"')) {
147 key_ptr[i]=(char)0;
if(i>0) key_ptr++;}
148 if(strlen(key_ptr)<1) {
149 if(is_key_required) {cptr=strtok(NULL,
"\n\r"); line++;
continue;}
151 i=strlen(value_ptr)-1;
if(i<0) i=0;
152 if((value_ptr[0]==
'\'' && value_ptr[i]==
'\'') || (value_ptr[0]==
'\"' && value_ptr[i]==
'\"')) {
153 value_ptr[i]=(char)0;
if(i>0) value_ptr++;}
154 if(verbose>2) printf(
" key='%s' value='%s'\n", key_ptr, value_ptr);
156 ret=
iftPut(ift, key_ptr, value_ptr, cmt_ptr, verbose-1);
162 cptr=strtok(NULL,
"\n\r"); line++;
165 if(verbose>2) printf(
"eq_type=%d\n", eq_type);
329 int i, ret, nr=0, line=0, initial_key_nr=0, nonprintable=0;
330 char *allfile, *cptr, *key_ptr, *value_ptr, *cmt_ptr;
334 if(verbose>0) printf(
"%s(*ift, %s)\n", __func__, filename);
335 if(ift==NULL)
return(1);
336 if(filename==NULL || strlen(filename)<1) {
342 if(strcasecmp(filename,
"stdin")==0) {
345 fp=fopen(filename,
"r");
346 if(fp==NULL) {
iftSetStatus(ift, IFT_CANNOTREAD);
return(2);}
350 nr=nonprintable=0;
while((ret=fgetc(fp))!=EOF) {
351 if(iscntrl(ret) && ret!=13 && ret!=10 && ret!=9) {
352 nonprintable=1;
break;}
356 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
366 if(verbose>1) printf(
" the size of file is %d bytes\n", nr);
368 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
374 allfile=(
char*)malloc((nr+1)*
sizeof(
char));
376 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
381 i=0;
while((ret=fgetc(fp))!=EOF && i<nr) allfile[i++]=(char)ret;
383 if(strcasecmp(filename,
"stdin")!=0) fclose(fp);
387 cptr=strtok(allfile,
"\n\r"); line=0;
389 if(verbose>10) printf(
"line %d: '%s'\n", line, cptr);
391 i=strspn(cptr,
" \t"); cptr+=i;
392 if(strlen(cptr)<1) {cptr=strtok(NULL,
"\n\r");
continue;}
394 if((cmt_ptr=strchr(
"#!;%", cptr[0]))!=NULL) {
396 key_ptr=cptr; value_ptr=NULL;
397 ret=
iftPut(ift, key_ptr, value_ptr,
" ", verbose-2);
403 cptr=strtok(NULL,
"\n\r"); line++;
406 if(verbose>11) printf(
" line %d: '%s'\n", line, cptr);
408 key_ptr=cptr; cptr=strchr(cptr,
' ');
409 if(cptr!=NULL) {*cptr=(char)0; cptr++;}
411 if(cptr==NULL) value_ptr=NULL;
else value_ptr=cptr;
412 ret=
iftPut(ift, key_ptr, value_ptr,
" ", verbose-2);
418 cptr=strtok(NULL,
"\n\r"); line++;
int iftPut(IFT *ift, char *key, char *value, char *cmt_type, int verbose)