summaryrefslogtreecommitdiffstats
path: root/agents/virt/config/config.l
blob: 78462f3a08a1b62c4b7d750c5736bf8ee5178939 (plain)
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
105
106
%{
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include "config-stack.h"
#include "y.tab.h"
#include "simpleconfig.h"

/* Some distributions can't use the output from flex without help */
#define ECHO if(fwrite( yytext, yyleng, 1, yyout ))

struct value *val_list = NULL;
struct node *node_list = NULL;
struct parser_context *context_stack = NULL;

int _line_count = 1;

%}
%%
[\n] {
	++_line_count;
}

[ \t]* {}

\#[^\n]* {}

"{" {
	struct parser_context *c = NULL;
	//printf("obrace\n");

	c = malloc(sizeof(*c));
	assert(c);

	c->next = context_stack;
	c->val_list = val_list;
	c->node_list = node_list;

	context_stack = c;
	val_list = NULL;
	node_list = NULL;

	return T_OBRACE;
}

"}" {
	return T_CBRACE;
}

";" {
	return T_SEMI;
}

"=" {
	return T_EQ;
}

[^ \t{};=\"\n]+ {
	yylval.sval = strdup(yytext);
	return T_ID;
}

\"[^\"]+\" {
	yylval.sval = strdup(yytext+1);
	yylval.sval[strlen(yytext)-2] = 0;
	return T_VAL;
}

%%
int
yywrap(void)
{
	return 1;
}


#ifdef STANDALONE
int
main(int argc, char *argv[])
{
	char value[80];
	config_object_t *c = NULL;

	yyout = fopen("/dev/null","w");

	c = sc_init();
	sc_parse(c, NULL);
	sc_dump(c, stdout);
	if (argc == 2) {
		if (sc_get(c, argv[1], value, sizeof(value)) == 0)
			printf("%s = %s\n", argv[1], value);
		else
			printf("Not found\n");
	} else if (argc == 3) {
		printf("---------\n");
		if (sc_set(c, argv[1], argv[2]) == 0)
			sc_dump(c, stdout);
	}

	sc_release(c);

	return 0;
}
#endif