Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell
Config.cpp
- Committer:
- shimniok
- Date:
- 2018-12-04
- Revision:
- 6:83a6666a62d7
- Parent:
- 5:eff573d4ede7
- Child:
- 7:1f2661b840ed
File content as of revision 6:83a6666a62d7:
#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;
}