Browse Source

more work on config parser

tth 1 year ago
parent
commit
e5cc357130
5 changed files with 39 additions and 10 deletions
  1. 1
    0
      core/dd2-monitor.conf
  2. 28
    6
      core/parseconf.c
  3. 2
    2
      core/t.c
  4. 0
    2
      core/utils.c
  5. 8
    0
      core/utils.h

+ 1
- 0
core/dd2-monitor.conf View File

@@ -1,4 +1,5 @@
1 1
 
2
+# experimental config file
2 3
 
3 4
 
4 5
 input_device	s	/def/ttyACM0

+ 28
- 6
core/parseconf.c View File

@@ -1,5 +1,5 @@
1 1
 /*
2
- *		parseconf
2
+ *		core/parseconf.c
3 3
  */
4 4
 
5 5
 #include  <stdio.h>
@@ -10,12 +10,14 @@
10 10
 extern int 			verbosity;
11 11
 extern Configuration		config;
12 12
 
13
+#define  CMP(a)   (!strcmp(cptr, a))
14
+
13 15
 /* ---------------------------------------------------------------- */
14 16
 int parse_config(char *fname, int flags)
15 17
 {
16 18
 FILE		*fp;
17
-char		line[SZ_STRINGS+1];
18
-
19
+char		line[SZ_STRINGS+1], *cptr;
20
+int		numligne;
19 21
 
20 22
 #if DEBUG_LEVEL
21 23
 fprintf(stderr, ">>> %s ( '%s' $%x )\n", fname, flags);
@@ -28,18 +30,38 @@ if (NULL==(fp=fopen(fname, "r"))) {
28 30
 	return -2;
29 31
 	}
30 32
 
33
+numligne = 0;
34
+
31 35
 while (fgets(line, SZ_STRINGS, fp))
32 36
 	{
37
+	numligne++;
38
+	if ('\0'==line[0]) {
39
+		fprintf(stderr, "%s : short read line %d\n", 
40
+				fname, numligne);
41
+		fclose(fp);
42
+		return -1;
43
+		}
44
+
33 45
 	/* massage the end of line */
46
+	line[strlen(line)-1] = '\0';          /* kill EOL */
47
+	if (verbosity) {
48
+		fprintf(stderr, "%3d :\t%s\n", numligne, line);
49
+		}
34 50
 
35
-	/* skip comments */
51
+	/* seek for the first token in this line */
52
+	if (NULL==(cptr = strtok(line, " \t"))) {
53
+		/* Got an empty line */
54
+		continue;
55
+		}
36 56
 
37
-	/* seek for keyword */
57
+	/* skip comments */
58
+	if ('#'==*cptr)		continue;
38 59
 
60
+	if(verbosity)	fprintf(stderr, "[%s]\n", cptr);
39 61
 
40
-	}
41 62
 
42 63
 
64
+	}
43 65
 
44 66
 fclose(fp);
45 67
 

+ 2
- 2
core/t.c View File

@@ -33,7 +33,6 @@ while ((opt = getopt(argc, argv, "v")) != -1) {
33 33
 	switch (opt) {
34 34
 		case 'v':	verbosity++;		break;
35 35
 
36
-
37 36
 		default:
38 37
 			fprintf(stderr, "%s : uh ?", argv[0]);
39 38
 			exit(1);
@@ -47,9 +46,10 @@ foo = parse_config(conffile, 1);
47 46
 fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
48 47
 show_config("foo");
49 48
 
49
+/*
50 50
 foo = load_lut1024f("foo.lut1024f", NULL, 1);
51
-
52 51
 fprintf(stderr, "chargement de la lut --> %d\n\n", foo);
52
+*/
53 53
 
54 54
 return 0;
55 55
 }

+ 0
- 2
core/utils.c View File

@@ -21,7 +21,6 @@ v1 = getpid();		v2 = time(NULL);
21 21
 return v1 ^ v2;
22 22
 }
23 23
 /* --------------------------------------------------------------- */
24
-
25 24
 int random1000(int type)
26 25
 {
27 26
 int         value;
@@ -55,5 +54,4 @@ if (foo) fprintf(stderr, "got %d in %s\n", foo, __func__);
55 54
 
56 55
 return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
57 56
 }
58
-
59 57
 /* --------------------------------------------------------------- */

+ 8
- 0
core/utils.h View File

@@ -0,0 +1,8 @@
1
+/*
2
+ *		core/utils.h
3
+ */
4
+
5
+int	seed_my_rand(int foo);
6
+int	random1000(int type);
7
+
8
+double	dtime(void);

Loading…
Cancel
Save