-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.c
More file actions
105 lines (89 loc) · 2.37 KB
/
configure.c
File metadata and controls
105 lines (89 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*############################################################################
# Title: Configure.c
# Author: C. Johnson
# Date: 6/2/14
# Description: This is a configuration system. '#' denotes a comment. 1
# variable is configured per line
#
#############################################################################*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ecat_ng.h"
#define KEYWORD 0
#define VALUE 1
#define VALUE2 2
#define MINFIELDS 2
#define MAXFIELDS 3
/*############################################################################
# Title: init()
# Author: C. Johnson
# Date: 6/2/14
# Args: N/A
# Description: Initializes the system to a basic set of data so it will run
#
#############################################################################*/
void init()
{
sprintf(DEVID, "%s", "rt0");
}
/*############################################################################
# Title: configure()
# Author: C. Johnson
# Date: 6/2/14
# Args: N/A
# Description: Reads a config file named "ngindi.conf". each line should
# have a keword and a value, whitespace delimited. ignores everything
# on a line after the first '#'
#
#############################################################################*/
int configure()
{
FILE *fp;
char line[80];
char buff[80];
char *search = " \t";
char *token;
char words[MAXFIELDS][50];
fp=fopen("soem.conf", "r");
int wordctr=0, linectr=0;
char *ticky;
init(); //init with defaults
while( fgets(line,1024,fp) )
{
linectr++;
if(line[strlen(line)-1]=='\n')
line[strlen(line)-1]='\0';
wordctr=0;
//printf("Configure: %s\n",line);
ticky=strtok(line, search);
if(ticky!=NULL)
{
if(ticky[0] == '#'){continue;}
}
while (ticky!= NULL)
{
if(ticky[0] == '#'){break;}
//printf( "Word %i = %s\n", wordctr, ticky);
sprintf(words[wordctr], "%s", ticky);
wordctr++;
if (wordctr>=MAXFIELDS){break;}
ticky=strtok(NULL, search);
}
//printf("Line %i: ", linectr);
if (wordctr < MINFIELDS)
{
printf("invalid line: not enough fields -- \" %s \" -- ignoring\n", line);
}
else if (strcmp(words[KEYWORD], "DEVID") == 0) //device ID (eg. eth0, fxp0, en0)
{
printf("\tdevID = %s\n", words[VALUE]);
sprintf(DEVID, "%s", words[VALUE]);
}
else
{
//printf("unrecognized keyword: %s -- ignoring\n", words[KEYWORD]);
}
}
//printf("Configuration Done!\n");
}