1 | #ifndef RCCONFIG_H |
---|
2 | #define RCCONFIG_H |
---|
3 | |
---|
4 | struct clist* addrcconfigtmp(char *key, char *value) |
---|
5 | { |
---|
6 | return addlisttmp(rcconfig, key, value); |
---|
7 | } |
---|
8 | |
---|
9 | struct clist* addrcconfigdef(char *key, char *value) |
---|
10 | { |
---|
11 | return addlistdef(rcconfig, key, value); |
---|
12 | } |
---|
13 | |
---|
14 | struct clist* addrcconfig(char *key, char *value) |
---|
15 | { |
---|
16 | struct clist* node = NULL; |
---|
17 | |
---|
18 | node = addlist(rcconfig, key, value); |
---|
19 | if(node != NULL) |
---|
20 | status.writercconfig = 1; |
---|
21 | |
---|
22 | return node; |
---|
23 | } |
---|
24 | |
---|
25 | struct clist* addrcconfigscreentmp(char *key, struct skin *node) |
---|
26 | { |
---|
27 | struct clist* ret = NULL; |
---|
28 | |
---|
29 | if(key != NULL && node != NULL && node->ret != NULL) |
---|
30 | ret = addrcconfigtmp(key, node->ret); |
---|
31 | |
---|
32 | return ret; |
---|
33 | } |
---|
34 | |
---|
35 | struct clist* addrcconfigscreentmpcheck(char *key, struct skin *node, char* check) |
---|
36 | { |
---|
37 | if(ostrcmp(node->ret, check) == 0) |
---|
38 | return addrcconfigtmp(key, ""); |
---|
39 | else |
---|
40 | return addrcconfigscreentmp(key, node); |
---|
41 | } |
---|
42 | |
---|
43 | struct clist* addrcconfigscreen(char *key, struct skin *node) |
---|
44 | { |
---|
45 | struct clist* ret = NULL; |
---|
46 | |
---|
47 | if(key != NULL && node != NULL && node->ret != NULL) |
---|
48 | ret = addrcconfig(key, node->ret); |
---|
49 | |
---|
50 | return ret; |
---|
51 | } |
---|
52 | |
---|
53 | struct clist* addrcconfigint(char *key, int value) |
---|
54 | { |
---|
55 | debug(1000, "in"); |
---|
56 | char* fileline = NULL; |
---|
57 | struct clist* ret = NULL; |
---|
58 | |
---|
59 | fileline = oitoa(value); |
---|
60 | ret = addrcconfig(key, fileline); |
---|
61 | |
---|
62 | free(fileline); |
---|
63 | debug(1000, "out"); |
---|
64 | return ret; |
---|
65 | } |
---|
66 | |
---|
67 | int readrcconfig(const char *filename, struct clist** tmprcconfig) |
---|
68 | { |
---|
69 | debug(1000, "in"); |
---|
70 | FILE *fd = NULL; |
---|
71 | char *fileline = NULL, *pos; |
---|
72 | |
---|
73 | fileline = malloc(MINMALLOC); |
---|
74 | if(fileline == NULL) |
---|
75 | { |
---|
76 | err("no memory"); |
---|
77 | return 1; |
---|
78 | } |
---|
79 | |
---|
80 | fd = fopen(filename, "r"); |
---|
81 | if(fd == NULL) |
---|
82 | { |
---|
83 | perr("can't open %s", filename); |
---|
84 | free(fileline); |
---|
85 | return 1; |
---|
86 | } |
---|
87 | |
---|
88 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
89 | { |
---|
90 | if(fileline[0] == '#' || fileline[0] == '\n') |
---|
91 | continue; |
---|
92 | if(fileline[strlen(fileline) - 1] == '\n') |
---|
93 | fileline[strlen(fileline) - 1] = '\0'; |
---|
94 | if(fileline[strlen(fileline) - 1] == '\r') |
---|
95 | fileline[strlen(fileline) - 1] = '\0'; |
---|
96 | |
---|
97 | pos = strchr(fileline, '='); |
---|
98 | if(pos != NULL) |
---|
99 | { |
---|
100 | pos[0] = '\0'; |
---|
101 | addlist(tmprcconfig, fileline, pos + 1); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | fclose(fd); |
---|
106 | free(fileline); |
---|
107 | debug(1000, "out"); |
---|
108 | return 0; |
---|
109 | } |
---|
110 | |
---|
111 | int writercconfigtmp() |
---|
112 | { |
---|
113 | int ret = 0; |
---|
114 | |
---|
115 | if(writelisttmp(rcconfig) == 0) |
---|
116 | status.writercconfig = 1; |
---|
117 | |
---|
118 | return ret; |
---|
119 | } |
---|
120 | |
---|
121 | int writercconfig(const char *filename) |
---|
122 | { |
---|
123 | return writelist(rcconfig, filename); |
---|
124 | } |
---|
125 | |
---|
126 | char* getrcconfig(char *key, char *ext) |
---|
127 | { |
---|
128 | return getlist(rcconfig, key, ext); |
---|
129 | } |
---|
130 | |
---|
131 | int getrcconfigint(char *key, char *ext) |
---|
132 | { |
---|
133 | char *ret = NULL; |
---|
134 | |
---|
135 | ret = getlist(rcconfig, key, ext); |
---|
136 | if(ret != NULL) |
---|
137 | return atoi(ret); |
---|
138 | else |
---|
139 | return 0; |
---|
140 | } |
---|
141 | |
---|
142 | void delrcconfigtmpall() |
---|
143 | { |
---|
144 | dellisttmpall(rcconfig); |
---|
145 | } |
---|
146 | |
---|
147 | void delrcconfigtmp(char *key) |
---|
148 | { |
---|
149 | dellisttmp(rcconfig, key); |
---|
150 | } |
---|
151 | |
---|
152 | void delrcconfig(char *key) |
---|
153 | { |
---|
154 | status.writercconfig = 1; |
---|
155 | dellist(rcconfig, key, 0); |
---|
156 | } |
---|
157 | |
---|
158 | void freercconfig() |
---|
159 | { |
---|
160 | freelist(rcconfig); |
---|
161 | } |
---|
162 | |
---|
163 | int reloadrcconfig(char *filename) |
---|
164 | { |
---|
165 | debug(1000, "in"); |
---|
166 | int ret = 0; |
---|
167 | |
---|
168 | freercconfig(); |
---|
169 | ret = readrcconfig(filename, rcconfig); |
---|
170 | if(ret != 0) |
---|
171 | { |
---|
172 | debug(1000, "out -> readrcconfig fail"); |
---|
173 | return 1; |
---|
174 | } |
---|
175 | |
---|
176 | debug(1000, "out"); |
---|
177 | return 0; |
---|
178 | } |
---|
179 | |
---|
180 | #endif |
---|