"Fossies" - the Fresh Open Source Software Archive 
Member "srg-1.3.6/libconfig/libconfig.c" (5 Aug 2009, 1387 Bytes) of package /linux/privat/old/srg-1.3.6.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #include "config_internal.h"
2 #include "libconfig.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 extern FILE *yyin;
8
9 extern int yyparse();
10
11 static config_t *config_table;
12
13 int set_config_int(char *option,int value)
14 {
15 config_t *item;
16 //printf("Setting %s to %i\n",option,value);
17 for(item=config_table;item->key;item++) {
18 if (!strcmp(item->key,option)) {
19 if ((item->type&TYPE_MASK) == TYPE_INT
20 || ((item->type&TYPE_MASK)==TYPE_BOOL && (value==0 || value==1))) {
21 *((int *)item->value)=value;
22 return 0;
23 }
24 else {
25 printf("%s does not take an int\n",option);
26 }
27 }
28 }
29 printf("Unknown configuration option %s\n",option);
30 return 1;
31 }
32
33 int set_config_str(char *option,char *value)
34 {
35 config_t *item;
36 //printf("Setting %s to %s\n",option,value);
37 for(item=config_table;item->key;item++) {
38 if (!strcmp(item->key,option)) {
39 if ((item->type&TYPE_MASK) == TYPE_STR) {
40 if (*((char **)item->value))
41 free(*((char **)item->value));
42 *((char**)item->value)=value;
43 return 0;
44 }
45 else {
46 printf("%s does not take an string\n",option);
47 }
48 }
49 }
50 printf("Unknown configuration option %s\n",option);
51 return 1;
52 }
53
54 int parse_config(config_t *config,char *filename)
55 {
56 yyin = fopen(filename,"r");
57 config_table=config;
58 if (!yyin) {
59 return 1;
60 }
61 yyparse();
62 fclose(yyin);
63 return 0;
64 }