Changeset 2464 for neercs/trunk/src/configuration.c
- Timestamp:
- Jun 20, 2008, 2:09:15 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/configuration.c
r2463 r2464 30 30 FILE *fp; 31 31 struct stat st; 32 int size = 0, i = 0, total = 0, offset = 0 ;32 int size = 0, i = 0, total = 0, offset = 0, l = 1; 33 33 char *buffer = NULL; 34 34 … … 53 53 } 54 54 55 buffer = malloc(size );55 buffer = malloc(size + 1); 56 56 if(!buffer) 57 57 { … … 65 65 total+=i; 66 66 } 67 buffer[total] = '\n'; 67 68 68 69 fclose(fp); … … 75 76 { 76 77 offset+=i; 78 l++; 77 79 } 78 80 … … 167 169 line = realloc(line, l+1); 168 170 line[l] = 0; 171 169 172 get_key_value(line, option); 170 173 … … 183 186 int get_key_value(char *line, struct option *option) 184 187 { 185 unsigned int i, o = 0, b=0 ;188 unsigned int i, o = 0, b=0, end_spaces = 0; 186 189 char *cur = NULL; 187 190 option->value = NULL; … … 204 207 if(line[i] == ' ' && !b) continue; 205 208 209 206 210 if(line[i] == '=') 207 211 { 208 212 b = 0; 209 cur[o] = 0; 213 cur[o-end_spaces] = 0; 214 cur = realloc(cur, (o-end_spaces)+1); 210 215 o = 0; 211 216 option->key = cur; … … 214 219 else 215 220 { 221 if(line[i] == ' ') end_spaces++; 222 else end_spaces = 0; 223 216 224 cur = realloc(cur, o+2); 217 225 if(!cur) … … 223 231 o++; 224 232 b = 1; 233 225 234 } 226 235 } … … 228 237 cur[o] = 0; 229 238 option->value = cur; 239 240 230 241 return 0; 231 242 } 232 243 233 244 234 #define IS_TOKEN(t) (!strncmp(option->key, t, strlen( t)))235 #define IS_VALUE(t) (!strncmp(option->value, t, strlen( t)))245 #define IS_TOKEN(t) (!strncmp(option->key, t, strlen(option->key))) 246 #define IS_VALUE(t) (!strncmp(option->value, t, strlen(option->value))) 236 247 237 248 … … 265 276 else screen_list->mini = 0; 266 277 267 } else if(IS_TOKEN("status "))278 } else if(IS_TOKEN("status_bar")) 268 279 { 269 280 if (IS_VALUE("true") || IS_VALUE("1")) screen_list->status = 1; 270 281 else screen_list->status = 0; 271 282 283 } else if(IS_TOKEN("screensaver_timeout")) 284 { 285 screen_list->screensaver_timeout = atoi(option->value) * 1000000; 286 if(!screen_list->screensaver_timeout) screen_list->screensaver_timeout-=1; 272 287 } else 273 288 {
Note: See TracChangeset
for help on using the changeset viewer.