preparation de la lecture du fichier de conf
This commit is contained in:
@@ -2,11 +2,19 @@
|
||||
#
|
||||
#
|
||||
|
||||
OBJS = lut1024f.o parseconf.o
|
||||
|
||||
lut1024f.o: lut1024f.c lut1024.h
|
||||
gcc -Wall -c $<
|
||||
|
||||
t: t.c lut1024f.o lut1024.h
|
||||
gcc -Wall $< lut1024f.o -o $@
|
||||
|
||||
parseconf.o: parseconf.c config.h
|
||||
gcc -Wall -c $<
|
||||
|
||||
|
||||
|
||||
t: t.c ${OBJS} lut1024.h config.h
|
||||
gcc -Wall $< ${OBJS} -o $@
|
||||
|
||||
foo.lut1024f: mklut.pl Makefile
|
||||
./mklut.pl quux > $@
|
||||
|
||||
21
core/config.h
Normal file
21
core/config.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* config.h
|
||||
*/
|
||||
|
||||
#define SZ_STRINGS 200
|
||||
|
||||
typedef struct {
|
||||
|
||||
int valid;
|
||||
|
||||
|
||||
|
||||
|
||||
} Configuration;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int parse_config(char *fname, int flags);
|
||||
int show_config(char *title);
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
10
core/dd2-monitor.conf
Normal file
10
core/dd2-monitor.conf
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
|
||||
input_device s /def/ttyACM0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
61
core/parseconf.c
Normal file
61
core/parseconf.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* parseconf
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
extern int verbosity;
|
||||
extern Configuration config;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int parse_config(char *fname, int flags)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[SZ_STRINGS+1];
|
||||
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' $%x )\n", fname, flags);
|
||||
#endif
|
||||
|
||||
config.valid = 49;
|
||||
|
||||
if (NULL==(fp=fopen(fname, "r"))) {
|
||||
perror(fname);
|
||||
return -2;
|
||||
}
|
||||
|
||||
while (fgets(line, SZ_STRINGS, fp))
|
||||
{
|
||||
/* massage the end of line */
|
||||
|
||||
/* skip comments */
|
||||
|
||||
/* seek for keyword */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int show_config(char *title)
|
||||
{
|
||||
|
||||
if (verbosity) {
|
||||
printf("********** %s **********\n", title);
|
||||
}
|
||||
|
||||
printf("valid %d\n", config.valid);
|
||||
|
||||
puts("");
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
16
core/t.c
16
core/t.c
@@ -7,20 +7,28 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "lut1024.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
Configuration config;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
char *conffile = "dd2-monitor.conf";
|
||||
|
||||
|
||||
fprintf(stderr, "+\n+ DD2 MONITOR\n+\n");
|
||||
|
||||
/* set some default values */
|
||||
verbosity = 0;
|
||||
|
||||
|
||||
|
||||
while ((opt = getopt(argc, argv, "v")) != -1) {
|
||||
switch (opt) {
|
||||
case 'v': verbosity++; break;
|
||||
@@ -35,9 +43,13 @@ while ((opt = getopt(argc, argv, "v")) != -1) {
|
||||
}
|
||||
|
||||
|
||||
foo = parse_config(conffile, 1);
|
||||
fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
|
||||
show_config("foo");
|
||||
|
||||
foo = load_lut1024f("foo.lut1024f", NULL, 1);
|
||||
|
||||
fprintf(stderr, "chargement de la lut --> %d\n", foo);
|
||||
fprintf(stderr, "chargement de la lut --> %d\n\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user