diff options
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r-- | apps/plugins/lib/configfile.c | 25 | ||||
-rw-r--r-- | apps/plugins/lib/configfile.h | 11 |
2 files changed, 25 insertions, 11 deletions
diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c index 419109f904..063efdde2e 100644 --- a/apps/plugins/lib/configfile.c +++ b/apps/plugins/lib/configfile.c | |||
@@ -59,15 +59,21 @@ int configfile_save(const char *filename, struct configdata *cfg, | |||
59 | /* pre-allocate 10 bytes for INT */ | 59 | /* pre-allocate 10 bytes for INT */ |
60 | rb->fdprintf(fd, "%s: %10d\n", | 60 | rb->fdprintf(fd, "%s: %10d\n", |
61 | cfg[i].name, | 61 | cfg[i].name, |
62 | *cfg[i].val); | 62 | *cfg[i].int_p); |
63 | break; | ||
64 | |||
65 | case TYPE_BOOL: | ||
66 | rb->fdprintf(fd, "%s: 10%d\n", | ||
67 | cfg[i].name, | ||
68 | (int)*cfg[i].bool_p); | ||
63 | break; | 69 | break; |
64 | 70 | ||
65 | case TYPE_ENUM: | 71 | case TYPE_ENUM: |
66 | rb->fdprintf(fd, "%s: %s\n", | 72 | rb->fdprintf(fd, "%s: %s\n", |
67 | cfg[i].name, | 73 | cfg[i].name, |
68 | cfg[i].values[*cfg[i].val]); | 74 | cfg[i].values[*cfg[i].int_p]); |
69 | break; | 75 | break; |
70 | 76 | ||
71 | case TYPE_STRING: | 77 | case TYPE_STRING: |
72 | rb->fdprintf(fd, "%s: %s\n", | 78 | rb->fdprintf(fd, "%s: %s\n", |
73 | cfg[i].name, | 79 | cfg[i].name, |
@@ -116,17 +122,22 @@ int configfile_load(const char *filename, struct configdata *cfg, | |||
116 | tmp = rb->atoi(val); | 122 | tmp = rb->atoi(val); |
117 | /* Only set it if it's within range */ | 123 | /* Only set it if it's within range */ |
118 | if(tmp >= cfg[i].min && tmp <= cfg[i].max) | 124 | if(tmp >= cfg[i].min && tmp <= cfg[i].max) |
119 | *cfg[i].val = tmp; | 125 | *cfg[i].int_p = tmp; |
120 | break; | 126 | break; |
121 | 127 | ||
128 | case TYPE_BOOL: | ||
129 | tmp = rb->atoi(val); | ||
130 | *cfg[i].bool_p = (bool)tmp; | ||
131 | break; | ||
132 | |||
122 | case TYPE_ENUM: | 133 | case TYPE_ENUM: |
123 | for(j = 0;j < cfg[i].max;j++) { | 134 | for(j = 0;j < cfg[i].max;j++) { |
124 | if(!rb->strcmp(cfg[i].values[j], val)) { | 135 | if(!rb->strcmp(cfg[i].values[j], val)) { |
125 | *cfg[i].val = j; | 136 | *cfg[i].int_p = j; |
126 | } | 137 | } |
127 | } | 138 | } |
128 | break; | 139 | break; |
129 | 140 | ||
130 | case TYPE_STRING: | 141 | case TYPE_STRING: |
131 | rb->strncpy(cfg[i].string, val, cfg[i].max); | 142 | rb->strncpy(cfg[i].string, val, cfg[i].max); |
132 | break; | 143 | break; |
diff --git a/apps/plugins/lib/configfile.h b/apps/plugins/lib/configfile.h index 0804a5930d..5dc31735a3 100644 --- a/apps/plugins/lib/configfile.h +++ b/apps/plugins/lib/configfile.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #define TYPE_INT 1 | 24 | #define TYPE_INT 1 |
25 | #define TYPE_ENUM 2 | 25 | #define TYPE_ENUM 2 |
26 | #define TYPE_STRING 3 | 26 | #define TYPE_STRING 3 |
27 | #define TYPE_BOOL 4 | ||
27 | 28 | ||
28 | struct configdata | 29 | struct configdata |
29 | { | 30 | { |
@@ -31,12 +32,14 @@ struct configdata | |||
31 | int min; /* Min value for integers, should be 0 for enums */ | 32 | int min; /* Min value for integers, should be 0 for enums */ |
32 | int max; /* Max value for enums and integers, | 33 | int max; /* Max value for enums and integers, |
33 | buffer size for strings */ | 34 | buffer size for strings */ |
34 | int *val; /* Pointer to integer/enum value, | 35 | union |
35 | NULL if the item is a string */ | 36 | { |
37 | int *int_p; | ||
38 | bool *bool_p; | ||
39 | char *string; | ||
40 | }; /* Pointer to value, a union of the possible types */ | ||
36 | char *name; /* Pointer to the name of the item */ | 41 | char *name; /* Pointer to the name of the item */ |
37 | char **values; /* List of strings for enums, NULL if not enum */ | 42 | char **values; /* List of strings for enums, NULL if not enum */ |
38 | char *string; /* Pointer to a string buffer if the item is a string, | ||
39 | NULL otherwise */ | ||
40 | }; | 43 | }; |
41 | 44 | ||
42 | /* configfile_save - Given configdata entries this function will | 45 | /* configfile_save - Given configdata entries this function will |