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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
/*
* Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
*
* This program 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 2 of the License, or (at your
* option) any later version.
*
* This program 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.
*/
%{
#ifdef FLEX_SCANNER
int pmviewFlexInput (char * buf, int ms);
#undef YY_INPUT
#define YY_INPUT(b,r,ms) (r=pmviewFlexInput(b, ms))
#ifdef __cplusplus
extern "C" {
#endif
int yylex (void);
#ifdef __cplusplus
}
#endif
#else /* AT&T Lex */
#undef input
#undef unput
#undef yywrap
char input(void);
void unput(char);
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "viewobj.h"
#include "barobj.h"
#include "text.h"
#include "stackobj.h"
#include "gridobj.h"
#include "gram.h"
extern void yywarn(const char *);
extern void yyerror(const char *);
extern FILE *theAltConfig;
#ifdef YYLMAX
#undef YYLMAX
#endif
#define YYLMAX 2048
#ifdef LEX_DEBUG
#define RETURN(c) if (pmDebug & DBG_TRACE_APPL2) { pmprintf("Lex: %d\n", c); pmflush (); } return c
#else
#define RETURN(c) if (theAltConfig) fprintf(theAltConfig, "%s", yytext); return c
#endif
static void lexerror (const char * msg, const char * yytext);
%}
%%
[-]?[0-9]+[\.][0-9]+ {
yylval.y_real = strtod(yytext, (char **)0);
RETURN(REAL);
}
0[xX][0-9]+ {
yylval.y_int = (int)strtol(&yytext[2], (char **)0, 16);
RETURN(INT);
}
[-]?[0-9]+ {
yylval.y_int = atoi(yytext);
RETURN(INT);
}
[Pp][Mm][Vv][Ii][Ee][Ww][\t ]+[vV]ersion[\t ]+[0-9]+\.[0-9]+ {
yylval.y_str = strdup (yytext+15);
RETURN(PMVIEW);
}
_grid { RETURN(GRID); }
_bar { RETURN(BAR); }
_labeledbar { RETURN(BAR); }
_stack { RETURN(STACK); }
_util { RETURN(UTIL); }
_metrics { RETURN(METRICLIST); }
_color[lL]ist { RETURN(COLORLIST); }
_color[sS]cale { RETURN(COLORSCALE); }
_label { RETURN(LABEL); }
_metric[lL]abels { RETURN(METRICLABEL); }
_inst[lL]abels { RETURN(INSTLABEL); }
_direction { RETURN(DIRECTION); }
_size { RETURN(SIZE); }
_text { RETURN(TEXT); }
_scale { RETURN(SCALE); }
_history { RETURN(HISTORY); }
_bar[lL]ength { RETURN(BAR_LENGTH); }
_bar[xX][mM]argin { RETURN(MARGIN_WIDTH); }
_bar[yY][mM]argin { RETURN(MARGIN_DEPTH); }
_margin[wW]idth { RETURN(MARGIN_WIDTH); }
_margin[dD]epth { RETURN(MARGIN_DEPTH); }
_bar[hH]eight { RETURN(BAR_HEIGHT); }
_bar[bB]ase[hH]eight { RETURN(BASE_HEIGHT); }
_base[hH]eight { RETURN(BASE_HEIGHT); }
_stack[lL]ength { RETURN(BAR_LENGTH); }
_stack[xX][mM]argin { RETURN(MARGIN_WIDTH); }
_stack[yY][mM]argin { RETURN(MARGIN_DEPTH); }
_stack[hH]eight { RETURN(BAR_HEIGHT); }
_stack[bB]ase[hH]eight { RETURN(BASE_HEIGHT); }
_grid[sS]pace { RETURN(GRID_SPACE); }
_grid[wW]idth { RETURN(GRID_WIDTH); }
_grid[dD]epth { RETURN(GRID_DEPTH); }
_grid[hH]eight { RETURN(BASE_HEIGHT); }
_grid[cC]olor { RETURN(BASE_COLOR); }
_base[cC]olor { RETURN(BASE_COLOR); }
_gap[wW]idth { RETURN(GAP_WIDTH); }
_gap[dD]epth { RETURN(GAP_DEPTH); }
_gap[lL]abel { RETURN(GAP_LABEL); }
_label[mM]argin { RETURN(LABEL_MARGIN); }
_label[cC]olor { RETURN(LABEL_COLOR); }
_stack[lL]abel { RETURN(STACK_LABEL); }
_base[lL]abel { RETURN(BASE_LABEL); }
_box { RETURN(BOX); }
_pipe[Ll]ength { RETURN(PIPE_LENGTH); }
_pipe { RETURN(PIPE); }
_pipe[Tt]ag { RETURN(PIPETAG); }
_link { RETURN(GR_LINK); }
_xing { RETURN(GR_XING); }
_sceneFile { RETURN(SCENE_FILE); }
[_]?[nN] { yylval.y_align = ViewObj::north; RETURN(ALIGN); }
[_]?north { yylval.y_align = ViewObj::north; RETURN(ALIGN); }
[_]?[sS] { yylval.y_align = ViewObj::south; RETURN(ALIGN); }
[_]?south { yylval.y_align = ViewObj::south; RETURN(ALIGN); }
[_]?[eE] { yylval.y_align = ViewObj::east; RETURN(ALIGN); }
[_]?east { yylval.y_align = ViewObj::east; RETURN(ALIGN); }
[_]?[wW] { yylval.y_align = ViewObj::west; RETURN(ALIGN); }
[_]?west { yylval.y_align = ViewObj::west; RETURN(ALIGN); }
[_]?[nN][wW] { yylval.y_align = ViewObj::northWest; RETURN(ALIGN); }
[_]?northwest { yylval.y_align = ViewObj::northWest; RETURN(ALIGN); }
[_]?[nN][eE] { yylval.y_align = ViewObj::northEast; RETURN(ALIGN); }
[_]?northeast { yylval.y_align = ViewObj::northEast; RETURN(ALIGN); }
[_]?[sS][wW] { yylval.y_align = ViewObj::southWest; RETURN(ALIGN); }
[_]?southwest { yylval.y_align = ViewObj::southWest; RETURN(ALIGN); }
[_]?[sS][eE] { yylval.y_align = ViewObj::southEast; RETURN(ALIGN); }
[_]?southeast { yylval.y_align = ViewObj::southEast; RETURN(ALIGN); }
[_]?center { yylval.y_align = ViewObj::center; RETURN(ALIGN); }
[_]?up { yylval.y_textDir = Text::up; RETURN(DIRVAL); }
[_]?down { yylval.y_textDir = Text::down; RETURN(DIRVAL); }
[_]?left { yylval.y_textDir = Text::left; RETURN(DIRVAL); }
[_]?right { yylval.y_textDir = Text::right; RETURN(DIRVAL); }
[_]?small { yylval.y_fontSize = Text::small; RETURN(SIZ); }
[_]?medium { yylval.y_fontSize = Text::medium; RETURN(SIZ); }
[_]?large { yylval.y_fontSize = Text::large; RETURN(SIZ); }
[_]?show { yylval.y_bool = true; RETURN(BOOL); }
[_]?hide { yylval.y_bool = false; RETURN(BOOL); }
[_]?towards { yylval.y_labelDir = BarObj::towards; RETURN(LABEL_DIR); }
[_]?away { yylval.y_labelDir = BarObj::away; RETURN(LABEL_DIR); }
[_]?row { yylval.y_instDir = BarMod::instPerRow; RETURN(INST_DIR); }
[_]?col { yylval.y_instDir = BarMod::instPerCol; RETURN(INST_DIR); }
_cube { yylval.y_shape = ViewObj::cube; RETURN(SHAPE); }
_cylinder { yylval.y_shape = ViewObj::cylinder; RETURN(SHAPE); }
_[yY]mod { yylval.y_barMod = BarMod::yScale; RETURN(BAR_TYPE); }
_color[mM]od { yylval.y_barMod = BarMod::color; RETURN(BAR_TYPE); }
_color[yY][mM]od { yylval.y_barMod = BarMod::colYScale; RETURN(BAR_TYPE); }
_util[mM]od { yylval.y_stackMod = StackMod::util; RETURN(STACK_TYPE); }
_fill[mM]od { yylval.y_stackMod = StackMod::fixed; RETURN(STACK_TYPE); }
_group[bB]y[rR]ow { yylval.y_barGroup = BarMod::groupByRow; RETURN(GROUP); }
_group[bB]y[cC]ol { yylval.y_barGroup = BarMod::groupByCol; RETURN(GROUP); }
_group[bB]y[mM]etric { yylval.y_barGroup = BarMod::groupByMetric; RETURN(GROUP); }
_group[bB]y[iI]nst { yylval.y_barGroup = BarMod::groupByInst; RETURN(GROUP); }
[A-Za-z0-9_./\-,:?=+&]+(\[[ \t]*((\"[^\"\n]*\"|[^\"\n\]]*)[ \t]*\,?[ \t]*)+[ \t]*\]) {
/*
* Metric could be in the form: name + quoted instance or
* name + non-quoted instance (i,e no " between the [ ] ) or
* just name with no instance spec. Name with no instance spec
* is delegated to the NAME token, the rest is handled here.
*/
yylval.y_str = strdup (yytext);
RETURN(METRIC);
}
[A-Za-z0-9_\.\/\-\,:\?\=\+\&]+ {
/*
* While parsing, NAME token can be used both in general context
* or as name for METRIC. I don't want to do context-specific
* lexical analisys, so NAME is restricted to the list of chars
* above and it cannot have opening or closing square brackets
*/
yylval.y_str = strdup (yytext);
RETURN(NAME);
}
\"[^\"\n][^\"\n]*\" {
yylval.y_str = (char *)malloc(yyleng-1);
strncpy(yylval.y_str, &yytext[1], yyleng-2);
yylval.y_str[yyleng-2] = '\0';
RETURN(STRING);
}
\"[^\"\n][^\"\n]*\n {
lexerror("Expected closing \"", yytext);
/*NOTREACHED*/
}
\( { RETURN(OPENB); }
\) { RETURN(CLOSEB); }
\#.*\n {}
\n { if (theAltConfig) fputc('\n', theAltConfig); }
[\t ]+ { if (theAltConfig) fputc(' ', theAltConfig); }
. {
sprintf(theBuffer, "Illegal character '%c'", yytext[0]);
lexerror(theBuffer, yytext);
/*NOTREACHED*/
}
%%
static char *line;
static int linepos;
static int linelen;
static int mark = -1;
extern int lineNum;
#ifdef FLEX_SCANNER
static int in = '\0';
int yywrap(void)
{
return in == EOF;
}
int
pmviewFlexInput(char *buf, int ms)
{
if (in == '\n') {
lineNum++;
linepos=0;
}
if (linepos >= linelen - 1) {
if (linelen == 0)
linelen = 128;
else
linelen *= 2;
line = (char *)realloc(line, linelen * sizeof(char));
}
if (ms > 0) {
if ((in = fgetc(yyin)) != EOF) {
line[linepos++] = buf[0] = in & 0xFFU;
ms = 1;
} else {
ms = 0;
}
}
return ms;
}
void
skipAhead(void)
{
while ((in != '\n') && (in != EOF)) {
char c;
pmviewFlexInput(&c, 1);
}
}
char
input(void)
{
char c;
if (pmviewFlexInput(&c, 1))
return c;
return 0;
}
char
lastinput(void)
{
return (in & 0xFFU);
}
#else
static char lastc = 'A';
static char peekc = '\0';
extern int lineNum;
extern FILE *yyin;
int
yywrap(void)
{
return lastc == '\0';
}
char
input(void)
{
int get;
if (peekc != '\0') {
lastc = peekc;
peekc = '\0';
return lastc;
}
if (lastc == '\n') {
lineNum++;
linepos = 0;
}
else if (lastc == '\0') {
linepos = 0;
return lastc;
}
if (linepos >= linelen - 1) {
if (linelen == 0)
linelen = 128;
else
linelen *= 2;
line = (char *)realloc(line, linelen * sizeof(char));
}
get = fgetc(yyin);
if (get == EOF)
lastc = '\0';
else
lastc = get;
line[linepos++] = (char)get;
return lastc;
}
void
unput(char c)
{
peekc = c;
}
char
lastinput(void)
{
return lastc;
}
#endif
int
markpos(void)
{
mark = linepos;
return mark;
}
int
locateError(void)
{
int i;
if (mark < 0) {
pmprintf("%s: Unrecoverable internal error in locateError()\n",
pmProgname);
pmflush();
exit(1);
}
if (feof(yyin)) {
return 0;
}
for (i = 0; i < mark; i++)
if (line[i] == '\n' || line[i] == '\0')
break;
else
pmprintf("%c", line[i]);
pmprintf("\n");
for (i = 0; i < mark - 1; i++)
if (line[i] == '\n' || line[i] == '\0')
break;
else if (line[i] == '\t')
pmprintf("\t");
else
pmprintf(" ");
pmprintf("^ at or near here\n");
return 1;
}
/* This is 'die now' version of yyerror - static and only used for errors
* in lexer, i.e those, where we've got no reasonable chance to do any
* recovery. */
static void
lexerror(const char * msg, const char * yytext)
{
char *pos;
if ((pos = strstr(line, yytext)) != NULL) {
int i;
for (i = 0; (line[i] != '\n') && (line[i] != '\0'); i++)
pmprintf("%c", line[i]);
pmprintf("\n");
for (i = 0; line+i != pos; i++) {
if (line[i] == '\n' || line[i] == '\0')
break;
else if (line[i] == '\t')
pmprintf("\t");
else
pmprintf(" ");
}
pmprintf("^ at or near here\n");
}
pmprintf("%s: Fatal error in configuration file at line %d:\n\t%s\n",
pmProgname, lineNum + 1, msg);
pmflush();
exit(1);
}
|