Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | |
2 | #include <stdio.h> |
||
3 | #include <string.h> |
||
4 | #include "hconf.h" |
||
5 | |||
6 | static char buffer[1024]; |
||
7 | static char name[64]; |
||
8 | static char value[64]; |
||
9 | |||
10 | static int read_h(char *filename) |
||
11 | { |
||
12 | FILE *fin; |
||
13 | struct variable *var; |
||
14 | int res; |
||
15 | |||
16 | fin=fopen(filename,"rt"); |
||
17 | if (fin==NULL) return -1; |
||
18 | |||
19 | while (fgets(buffer,sizeof(buffer),fin)!=NULL) { |
||
20 | res=sscanf(buffer,"#define %s %s",name,value); |
||
21 | if (res==2) { |
||
22 | var=findvar(name); |
||
23 | if (var==NULL) continue; |
||
24 | switch (var->type) { |
||
25 | case RANGEVAR: |
||
26 | copystring(&var->value,value); |
||
27 | continue; |
||
28 | case BOOLVAR: |
||
29 | copystring(&var->value,"y"); |
||
30 | continue; |
||
31 | case TRISTATEVAR: |
||
32 | if (*value=='0') copystring(&var->value,"m"); |
||
33 | else copystring(&var->value,"y"); |
||
34 | continue; |
||
35 | case CHOICEVAR: |
||
36 | copystring(&var->value,"y"); |
||
37 | continue; |
||
38 | } |
||
39 | } |
||
40 | res=sscanf(buffer,"#undef %s",name); |
||
41 | if (res==1) { |
||
42 | var=findvar(name); |
||
43 | if (var==NULL) continue; |
||
44 | copystring(&var->value,"n"); |
||
45 | continue; |
||
46 | } |
||
47 | res=sscanf(buffer,"/* var %s %s */",name,value); |
||
48 | if (res==2) { |
||
49 | var=findvar(name); |
||
50 | if (var==NULL) continue; |
||
51 | copystring(&var->value,value); |
||
52 | continue; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | fclose(fin); |
||
57 | return 0; |
||
58 | } |
||
59 | |||
60 | /* -- */ |
||
61 | |||
62 | int readconfig(char *srcfilename) |
||
63 | { |
||
64 | char buffer[256]; |
||
65 | char *ptr; |
||
66 | |||
67 | ptr=strstr(srcfilename,".in"); |
||
68 | if (ptr!=NULL) *ptr='\0'; |
||
69 | else { |
||
70 | ptr=strchr(srcfilename,'.'); |
||
71 | if (ptr!=NULL) *ptr='\0'; |
||
72 | } |
||
73 | |||
74 | strcpy(buffer,srcfilename); |
||
75 | strcat(buffer,".h"); |
||
76 | read_h(buffer); |
||
77 | |||
78 | return 0; |
||
79 | } |