diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/misc.c | 34 | ||||
-rw-r--r-- | apps/misc.h | 6 | ||||
-rw-r--r-- | apps/settings.c | 33 |
3 files changed, 40 insertions, 33 deletions
diff --git a/apps/misc.c b/apps/misc.c index 701f766a8d..b92d8aefb8 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -16,6 +16,7 @@ | |||
16 | * KIND, either express or implied. | 16 | * KIND, either express or implied. |
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | #include <ctype.h> | ||
19 | #include "string.h" | 20 | #include "string.h" |
20 | #include "config.h" | 21 | #include "config.h" |
21 | #include "file.h" | 22 | #include "file.h" |
@@ -170,3 +171,36 @@ void screen_dump(void) | |||
170 | } | 171 | } |
171 | } | 172 | } |
172 | #endif | 173 | #endif |
174 | |||
175 | /* parse a line from a configuration file. the line format is: | ||
176 | |||
177 | name: value | ||
178 | |||
179 | Any whitespace before setting name or value (after ':') is ignored. | ||
180 | A # as first non-whitespace character discards the whole line. | ||
181 | Function sets pointers to null-terminated setting name and value. | ||
182 | Returns false if no valid config entry was found. | ||
183 | */ | ||
184 | |||
185 | bool settings_parseline(char* line, char** name, char** value) | ||
186 | { | ||
187 | char* ptr; | ||
188 | |||
189 | while ( isspace(*line) ) | ||
190 | line++; | ||
191 | |||
192 | if ( *line == '#' ) | ||
193 | return false; | ||
194 | |||
195 | ptr = strchr(line, ':'); | ||
196 | if ( !ptr ) | ||
197 | return false; | ||
198 | |||
199 | *name = line; | ||
200 | *ptr = 0; | ||
201 | ptr++; | ||
202 | while (isspace(*ptr)) | ||
203 | ptr++; | ||
204 | *value = ptr; | ||
205 | return true; | ||
206 | } | ||
diff --git a/apps/misc.h b/apps/misc.h index 329c62750c..df9eba8e55 100644 --- a/apps/misc.h +++ b/apps/misc.h | |||
@@ -16,6 +16,8 @@ | |||
16 | * KIND, either express or implied. | 16 | * KIND, either express or implied. |
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | #ifndef MISC_H | ||
20 | #define MISC_H | ||
19 | 21 | ||
20 | /* The point of this function would be to return a string of the input data, | 22 | /* The point of this function would be to return a string of the input data, |
21 | but never longer than 5 columns. Add suffix k and M when suitable... | 23 | but never longer than 5 columns. Add suffix k and M when suitable... |
@@ -35,3 +37,7 @@ int read_line(int fd, char* buffer, int buffer_size); | |||
35 | /* Save a .BMP file containing the current screen contents. */ | 37 | /* Save a .BMP file containing the current screen contents. */ |
36 | void screen_dump(void); | 38 | void screen_dump(void); |
37 | #endif | 39 | #endif |
40 | |||
41 | bool settings_parseline(char* line, char** name, char** value); | ||
42 | |||
43 | #endif | ||
diff --git a/apps/settings.c b/apps/settings.c index 17122ecd84..bc1e6c7506 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -836,39 +836,6 @@ void settings_load(int which) | |||
836 | } | 836 | } |
837 | } | 837 | } |
838 | 838 | ||
839 | /* parse a line from a configuration file. the line format is: | ||
840 | |||
841 | setting name: setting value | ||
842 | |||
843 | Any whitespace before setting name or value (after ':') is ignored. | ||
844 | A # as first non-whitespace character discards the whole line. | ||
845 | Function sets pointers to null-terminated setting name and value. | ||
846 | Returns false if no valid config entry was found. | ||
847 | */ | ||
848 | |||
849 | static bool settings_parseline(char* line, char** name, char** value) | ||
850 | { | ||
851 | char* ptr; | ||
852 | |||
853 | while ( isspace(*line) ) | ||
854 | line++; | ||
855 | |||
856 | if ( *line == '#' ) | ||
857 | return false; | ||
858 | |||
859 | ptr = strchr(line, ':'); | ||
860 | if ( !ptr ) | ||
861 | return false; | ||
862 | |||
863 | *name = line; | ||
864 | *ptr = 0; | ||
865 | ptr++; | ||
866 | while (isspace(*ptr)) | ||
867 | ptr++; | ||
868 | *value = ptr; | ||
869 | return true; | ||
870 | } | ||
871 | |||
872 | void set_file(char* filename, char* setting, int maxlen) | 839 | void set_file(char* filename, char* setting, int maxlen) |
873 | { | 840 | { |
874 | char* fptr = strrchr(filename,'/'); | 841 | char* fptr = strrchr(filename,'/'); |