summaryrefslogtreecommitdiffstats
path: root/src/config-bison.y
blob: 944f59bda69b9480cc50d422a26fc8155e7a36e6 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
  Copyright (C) 2011 Jiri Olsa <olsajiri@gmail.com>

  This file is part of the latrace.

  The latrace is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  The latrace is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with the latrace (file COPYING).  If not, see
  <http://www.gnu.org/licenses/>.
*/

%name-prefix "lt_config_"

%{
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "lib-include.h"

struct lt_include *lt_config_sinc;
static struct lt_config_app *scfg;

int lt_config_lex(void);
void lt_config_error(const char *m);

#define ERROR(fmt, args...)          \
do {                                 \
	char ebuf[1024];             \
	sprintf(ebuf, fmt, ## args); \
	lt_config_error(ebuf);       \
	YYERROR;                     \
} while(0)

static LT_LIST_HEAD(opt_list);

#define OPTION_ADD(idx, sval, nval) \
do { \
	struct lt_config_opt *opt; \
	opt = lt_config_opt_new(scfg, idx, sval, nval); \
	if (!opt) \
		ERROR("failed to process option\n"); \
	lt_list_add_tail(&opt->list, &opt_list); \
} while(0)

static struct lt_list_head ln_names;

%}

%token INCLUDE NAME BOOL VALUE END
%token OPTIONS
%token OPT_HEADERS OPT_INDENT_SYM OPT_PIPE
%token OPT_TIMESTAMP OPT_FRAMESIZE OPT_FRAMESIZE_CHECK
%token OPT_HIDE_TID OPT_FOLLOW_FORK OPT_FOLLOW_EXEC
%token OPT_DEMANGLE OPT_BRACES OPT_ENABLE_ARGS
%token OPT_DETAIL_ARGS OPT_OUTPUT_TTY
%token OPT_LIBS OPT_LIBS_TO OPT_LIBS_FROM
%token OPT_SYM OPT_SYM_OMIT OPT_SYM_BELOW OPT_SYM_NOEXIT
%token OPT_ARGS_STRING_POINTER_LENGTH

%union
{
	char *s;
	unsigned long l;
}

%type <s> NAME
%type <s> BOOL
%type <l> VALUE

%%
entry:
entry include_def
|
entry options_def
|
entry END
{
	if (lt_inc_close(scfg->sh, lt_config_sinc))
		return 0;
}
|
/* left blank intentionally */

include_def: INCLUDE '"' NAME '"'
{
        if (lt_inc_open(scfg->sh, lt_config_sinc, $3))
                ERROR("failed to process include");
}

options_def: OPTIONS '{' OPTIONS_DEF '}'
{
	struct lt_config_opt *opt, *opth;

	if (lt_config_opt_process(scfg, &opt_list))
                ERROR("failed to process options");

	lt_list_for_each_entry_safe(opt, opth, &opt_list, list) {
		lt_list_del(&opt->list);
		free(opt);
	}
}

OPTIONS_DEF:
OPTIONS_DEF OPT_HEADERS '=' '"' NAME '"'
{
	OPTION_ADD(LT_OPT_HEADERS, $5, -1);
}
|
OPTIONS_DEF OPT_INDENT_SYM '=' VALUE
{
	OPTION_ADD(LT_OPT_INDENT_SYM, NULL, $4);
}
|
OPTIONS_DEF OPT_PIPE '=' BOOL
{
	OPTION_ADD(LT_OPT_PIPE, $4, -1);
}
|
OPTIONS_DEF OPT_TIMESTAMP '=' BOOL
{
	OPTION_ADD(LT_OPT_TIMESTAMP, $4, -1);
}
|
OPTIONS_DEF OPT_FRAMESIZE '=' VALUE
{
	OPTION_ADD(LT_OPT_FRAMESIZE, NULL, $4);
}
|
OPTIONS_DEF OPT_FRAMESIZE_CHECK '=' BOOL
{
	OPTION_ADD(LT_OPT_FRAMESIZE_CHECK, $4, -1);
}
|
OPTIONS_DEF OPT_HIDE_TID '=' BOOL
{
	OPTION_ADD(LT_OPT_HIDE_TID, $4, -1);
}
|
OPTIONS_DEF OPT_FOLLOW_FORK '=' BOOL
{
	OPTION_ADD(LT_OPT_FOLLOW_FORK, $4, -1);
}
|
OPTIONS_DEF OPT_FOLLOW_EXEC '=' BOOL
{
	OPTION_ADD(LT_OPT_FOLLOW_EXEC, $4, -1);
}
|
OPTIONS_DEF OPT_DEMANGLE '=' BOOL
{
	OPTION_ADD(LT_OPT_DEMANGLE, $4, -1);
}
|
OPTIONS_DEF OPT_BRACES '=' BOOL
{
	OPTION_ADD(LT_OPT_BRACES, $4, -1);
}
|
OPTIONS_DEF OPT_ENABLE_ARGS '=' BOOL
{
	OPTION_ADD(LT_OPT_ENABLE_ARGS, $4, -1);
}
|
OPTIONS_DEF OPT_DETAIL_ARGS '=' BOOL
{
	OPTION_ADD(LT_OPT_DETAIL_ARGS, $4, -1);
}
|
OPTIONS_DEF OPT_OUTPUT_TTY '=' '"' NAME '"'
{
	OPTION_ADD(LT_OPT_OUTPUT_TTY, $5, -1);
}
|
OPTIONS_DEF OPT_LIBS '=' list_names_comma
{
	char libs[LT_LIBS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, libs, LT_LIBS_MAXSIZE))
		ERROR("failed to process libs option");

	OPTION_ADD(LT_OPT_LIBS, libs, -1);
}
|
OPTIONS_DEF OPT_LIBS_TO '=' list_names_comma
{
	char libs_to[LT_LIBS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, libs_to, LT_LIBS_MAXSIZE))
		ERROR("failed to process libs_to option");

	OPTION_ADD(LT_OPT_LIBS_TO, libs_to, -1);
}
|
OPTIONS_DEF OPT_LIBS_FROM '=' list_names_comma
{
	char libs_from[LT_LIBS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, libs_from, LT_LIBS_MAXSIZE))
		ERROR("failed to process libs_from option");

	OPTION_ADD(LT_OPT_LIBS_FROM, libs_from, -1);
}
|
OPTIONS_DEF OPT_SYM '=' list_names_comma
{
	char sym[LT_LIBS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, sym, LT_LIBS_MAXSIZE))
		ERROR("failed to process sym option");

	OPTION_ADD(LT_OPT_SYM, sym, -1);
}
|
OPTIONS_DEF OPT_SYM_OMIT '=' list_names_comma
{
	char sym_omit[LT_SYMBOLS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, sym_omit, LT_SYMBOLS_MAXSIZE))
		ERROR("failed to process sym_omit option");

	OPTION_ADD(LT_OPT_SYM_OMIT, sym_omit, -1);
}
|
OPTIONS_DEF OPT_SYM_BELOW '=' list_names_comma
{
	char sym_below[LT_SYMBOLS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, sym_below, LT_SYMBOLS_MAXSIZE))
		ERROR("failed to process sym_below option");

	OPTION_ADD(LT_OPT_SYM_BELOW, sym_below, -1);
}
|
OPTIONS_DEF OPT_SYM_NOEXIT '=' list_names_comma
{
	char sym_noexit[LT_SYMBOLS_MAXSIZE];

	if (lt_config_ln_fill(&ln_names, sym_noexit, LT_SYMBOLS_MAXSIZE))
		ERROR("failed to process sym_below option");

	OPTION_ADD(LT_OPT_SYM_NOEXIT, sym_noexit, -1);
}
|
OPTIONS_DEF OPT_ARGS_STRING_POINTER_LENGTH '=' BOOL
{
	OPTION_ADD(LT_OPT_ARGS_STRING_POINTER_LENGTH, $4, -1);
}
|
/* left blank intentionally */

list_names_comma:
list_names_comma ',' NAME
{
	if (lt_config_ln_add(&ln_names, $3))
		ERROR("failed to add list name");
}
|
NAME
{
	if (lt_config_ln_add(&ln_names, $1))
		ERROR("failed to add list name");
}

%%

int lt_config_parse_init(struct lt_config_app *cfg, struct lt_include *inc)
{
        scfg = cfg;
        lt_config_sinc = inc;
	lt_init_list_head(&ln_names);
        return 0;
}