![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
2018 revision to classic DataBus AVC code.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Diff: Config.cpp
- Revision:
- 5:eff573d4ede7
- Parent:
- 4:de7feb458652
- Child:
- 6:83a6666a62d7
diff -r de7feb458652 -r eff573d4ede7 Config.cpp --- a/Config.cpp Mon Dec 03 21:51:14 2018 +0000 +++ b/Config.cpp Tue Dec 04 06:44:54 2018 +0000 @@ -1,4 +1,22 @@ #include "Config.h" +#include <ctype.h> + + +char *trim(char *s) +{ + char *t = s; + + // rtrim + t = s + strlen(s) - 1; + while (isspace(*t)) + *t = '\0'; + + // ltrim + while (*s && isspace(*s)) + s++; + + return s; +} int Config::load(char *filename) @@ -15,15 +33,28 @@ } else { while (!feof(fp)) { fgets(buf, MAXBUF-1, fp); - if (buf[0] != '#') { - key = strtok(buf, ":"); - value = strtok(NULL, ":"); - if (*key && *value) { - printf("<%s>=<%s>\n", key, value); - // look for key - // parse value - // set options + + char *t = buf; + char *s = buf; + // trim spaces and terminate at # + while (*t) { + if (isspace(*buf)) { + s = t; + } else if (*t == '#') { + *t = '\0'; } + t++; + } + + key = strtok(s, ":#"); + value = strtok(NULL, ":#"); + if (key && value && *key && *value) { + key = trim(key); + value = trim(value); + printf("<%s>=<%s>\n", key, value); + // look for key + // parse value + // set options } } fclose(fp);