random things...

This commit is contained in:
tth 2019-01-18 17:09:15 +01:00
parent 5faccb1724
commit 254ae77e1a
6 changed files with 31 additions and 16 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ fake-values
essai essai
serial/t serial/t
core/t core/t
core/*.a
doc/*.toc doc/*.toc
doc/*.log doc/*.log

View File

@ -11,6 +11,7 @@ First step, build some parts of the core library :
Then you must have datas for working on. One source of datas Then you must have datas for working on. One source of datas
is the four values who came from the Arduino over serial line. is the four values who came from the Arduino over serial line.
At this time, you must look at the configuration file.
$ cd serial $ cd serial
$ make t $ make t

View File

@ -8,7 +8,7 @@ typedef struct {
int valid; int valid;
char *input_device;
} Configuration; } Configuration;

View File

@ -1,10 +1,9 @@
#
# experimental config file # experimental config file
#
input_device s /dev/ttyACM0
input_device s /def/ttyACM0 input_speed s 9600

View File

@ -10,13 +10,14 @@
extern int verbosity; extern int verbosity;
extern Configuration config; extern Configuration config;
#define CMP(a) (!strcmp(cptr, a)) #define CMP(a) (!strcmp(keyptr, a))
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
int parse_config(char *fname, int flags) int parse_config(char *fname, int flags)
{ {
FILE *fp; FILE *fp;
char line[SZ_STRINGS+1], *cptr; char line[SZ_STRINGS+1],
*keyptr, *typeptr, *cptr;
int numligne; int numligne;
#if DEBUG_LEVEL #if DEBUG_LEVEL
@ -49,23 +50,35 @@ while (fgets(line, SZ_STRINGS, fp))
} }
/* seek for the first token in this line */ /* seek for the first token in this line */
if (NULL==(cptr = strtok(line, " \t"))) { if (NULL==(keyptr = strtok(line, " \t"))) {
/* Got an empty line */ /* Got an empty line */
continue; continue;
} }
/* skip comments */ /* skip comments */
if ('#'==*cptr) continue; if ('#'==*keyptr) continue;
/* seek for the type field */
if(verbosity) fprintf(stderr, "[%s]\n", cptr); if (NULL==(typeptr = strtok(NULL, " \t"))) {
/* we can(t get a type flag ? wtf ? */
fprintf(stderr, "ERROR line %d : no type\n", numligne);
continue;
}
if(verbosity)
fprintf(stderr, "[%s] type %s\n", keyptr, typeptr);
if CMP("abort") {
fprintf(stderr, "abort in config file\n");
}
if (CMP("input_device")) {
config.input_device = strdup(strtok(NULL, " \t"));
continue;
}
} }
fclose(fp); fclose(fp);
return -1; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
int show_config(char *title) int show_config(char *title)
@ -75,7 +88,8 @@ if (verbosity) {
printf("********** %s **********\n", title); printf("********** %s **********\n", title);
} }
printf("valid %d\n", config.valid); printf("valid : %d\n", config.valid);
printf("input device : %s\n", config.input_device);
puts(""); puts("");
return 0; return 0;

View File

@ -42,7 +42,7 @@ while ((opt = getopt(argc, argv, "v")) != -1) {
} }
foo = parse_config(conffile, 1); foo = parse_config(conffile, 0);
fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo); fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
show_config("foo"); show_config("foo");