aboutsummaryrefslogtreecommitdiffstats
path: root/wlp/C/commands.y
blob: 8b720d783a544a88868505e39f0255b20482d959 (plain) (blame)
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
107
108
109
110

%{
/*#define YYSTYPE 	char**/
/*#define DEBUG*/
#include "macro.h"
%}

%union {
	char *text;
	char c;
}

%token <text> VARID
%token <text> VALID
%token <text> OWNERID

%token ERROR
%token EOFTOK


%{
char left[80], right[80], owner[80];
char type = 0; /*unused*/
%}

%%


block:
	blockstatement
	| block  blockstatement
	;
	
blockstatement:
	owner '{' commandline '}'
	;	
	
commandline: 
	command | commandline command
	;
	
command:
	varpart '=' valpart { found(left,right,owner); }
	;
	
owner:
	OWNERID	{
			DBG("Owner %s\n",$1);
			strncpy(owner,$1,strlen($1)+1);
		}
	;

varpart:
	VARID	{
			DBG("Left %s\n",$1);
			strncpy(left,$1,strlen($1)+1);
		}
	;
	
valpart:
	VALID	{
			DBG("Right %s\n",$1);
			strncpy(right,$1,strlen($1)+1);
		}
	;

%%

#include <ctype.h>
#include <stdio.h>
#include "structs.h"

extern struct wlp_list_t *list;

int yyerror (char *s)  /* Called by yyparse on error */
{
	printf ("error: %s\n", s);
	return 1;
}

int found(const char* left, const char* right, const char *owner)
{
	static struct wlp_node_t *node;

	/* alloc node with non-empty fields (ie alloc them too)*/
	node = wlpn_alloc(FALSE);
	if(!node) {
		DBG("wlpn_alloc in found returned NULL\n");
	}
	
	strncpy(node->right,right,strlen(right));
	strncpy(node->left,left,strlen(left));
	strncpy(node->owner,owner,strlen(owner));

	#ifndef WITHQUOTES
	/* remove quotes of value part */
	node->right += 1;
	node->right[strlen(node->right)-1] = '\0';
	#endif
	#ifndef WITHANGBRACKETS
	/* remove angle brackets of owner part */
	node->owner += 1;
	node->owner[strlen(node->owner)-1] = '\0';
	#endif

	if(!list)
		list = wlpl_init(node);
	else
		wlpn_add(list,node);
}