![](/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
Config.cpp
- Committer:
- shimniok
- Date:
- 2018-12-04
- Revision:
- 5:eff573d4ede7
- Parent:
- 4:de7feb458652
- Child:
- 6:83a6666a62d7
File content as of revision 5:eff573d4ede7:
#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) { char buf[MAXBUF]; char *key; char *value; int status=0; FILE *fp; fp = fopen(filename, "r"); if (fp == NULL) { status = -1; } else { while (!feof(fp)) { fgets(buf, MAXBUF-1, fp); 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); }; return status; } /** Attach a setter for each key. The type of the setter's arg will be * enforced by the parser when the config file is loaded. */ void Config::attach(Callback<void(char *)> set, char *key) { } void Config::attach(Callback<void(int)> set, char *key) { } void Config::attach(Callback<void(float)> set, char *key) { } void Config::attach(Callback<void(double)> set, char *key) { }