-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuconfig.c
executable file
·51 lines (47 loc) · 1.27 KB
/
uconfig.c
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
#include <stdio.h>
#include <string.h>
#include "uconfig.h"
const char* filename = "vm.config";
//DEFAULT VALUES
int READ_ANNOTATION=0;
int processConfigFile()
{
FILE *pFile;
pFile = fopen(filename, "r");
char line[256];
int linenum = 0;
if(pFile == NULL)
{
printf("No vm.config file included. Using defaults defined in uconfig.c\n");
}
else
{
while(fgets(line, 256, pFile) != NULL)
{
char key[256];
int value;
linenum++;
if(line[0] == '#') continue; //Comment, ignore
if(line[0] == '\n') continue; //Blank line, ignore
if(sscanf(line, "%s %d", key, &value) != 2)
{
fprintf(stderr, "Syntax error, line %d\n", linenum);
continue;
}
//printf("Line %d: Key: %s Value %d\n", linenum, key, value);
keyValueStateMachine(key, value);
}
}
return 1;
}
/*************************************************************************
* State Machine which sets the config variable that corresponds
* to the given key with the given value.
*************************************************************************/
static void keyValueStateMachine(char *key, int value)
{
if(!strcmp(key, "READ_ANNOTATION"))
READ_ANNOTATION = value;
else
printf("Invalid key\n");
}