File: conf.c

package info (click to toggle)
gcrontab 0.8.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,184 kB
  • ctags: 1,440
  • sloc: ansic: 6,240; sh: 5,526; makefile: 390; yacc: 318
file content (67 lines) | stat: -rw-r--r-- 1,796 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "conf.h"

int 
conf_Load (char *IN_fname, Conf_load_callback_descr *IN_cfgcb)
{
   FILE *pf;
   char s[80], *fld;
 
   pf=fopen(IN_fname,"r");
   if(!pf) return(1);
	
   fgets(s,80,pf); 
   while(!feof(pf))        
      {
           
           if(s[0]) if(s[strlen(s)-1]=='\n') s[strlen(s)-1]=0;           
           /*g_print("[%s]\n",s);*/
           if(s[0])                      
           {				           	
              if(s[0]!='#')
                  {
                    int i,found;
                    i=found=0;
                                        
                    fld=(char *)strdup(strtok(s,"="));                    
                    while( (IN_cfgcb[i].name) && (! found ) )
                      {
                         if(!strcmp(IN_cfgcb[i].name,fld)){
                             int retv;
                             
							 /*printf("<%s>\n",IN_cfgcb[i].name);*/
                             retv=IN_cfgcb[i].cb((char *)strtok(NULL,"="));					                           
                             if(retv)
                                return(retv);
                                
                             found=1;
                         }                         
                         i++;                             
                      }
                    free(fld);                    
                  }
	    }			   
		fgets(s,80,pf); 
       }
       return(0);
}


int 
conf_Save(char *IN_fname, Conf_save_callback_descr *IN_cfgcb)
{
   FILE *pf;
   char s[80], *fld;
   int i;
 
   pf=fopen(IN_fname,"w");
   if(!pf) return(1);
	
   i=0;
   while(IN_cfgcb[i].name)        
      {
           fprintf(pf,"%s=%s\n",IN_cfgcb[i].name,IN_cfgcb[i].cb());
           i++;		   
       }
   fclose(pf);    
   return(0);
}