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
|
/*
* Copyright (c) 1997-2000 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (c) 2011 Ken McDonell. 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
%{
/*
* pmlogrewrite configfile lexical scanner
*/
#include "pmapi.h"
#include "impl.h"
#include "logger.h"
#include <errno.h>
char mess[256];
#define LEX_NONE 0
#define LEX_GLOBAL 1
#define LEX_INDOM 2
#define LEX_METRIC 3
int mystate = LEX_NONE;
static int comma_count;
#include "gram.tab.h"
static char *
dupstr(char *s, int strip_quotes)
{
char *p;
if (strip_quotes)
p = strdup(&s[1]);
else
p = strdup(s);
if (p == NULL) {
fprintf(stderr, "Failed strdup(\"%s\") in lexer: %s\n", s, strerror(errno));
abandon();
/*NOTREACHED*/
}
if (strip_quotes) {
char *pend = p;
while (*pend != '\0')
pend++;
*--pend = '\0';
}
return p;
}
%}
%option noinput
%option nounput
%{
#ifdef FLEX_SCANNER
#ifndef YY_NO_UNPUT
#define YY_NO_UNPUT
#endif
#endif
%}
%s none glob host indom metric type sem units space time count output
%option case-insensitive
%%
<INITIAL>"global" { mystate= LEX_GLOBAL; return TOK_GLOBAL; }
<INITIAL>"metric" { mystate = LEX_METRIC; return TOK_METRIC; }
<INITIAL>"indom" { mystate = LEX_INDOM; return TOK_INDOM; }
<glob>"hostname" { BEGIN(host); return TOK_HOSTNAME; }
<glob>"time" { return TOK_TIME; }
<glob>"tz" { return TOK_TZ; }
/* Hostname */
<host>[A-Za-z0-9][A-Za-z0-9.-]* { yylval.str = dupstr(yytext, 0); BEGIN(glob); return TOK_HNAME; }
<indom,metric>"delete" { return TOK_DELETE; }
<indom>"indom" { return TOK_INDOM; }
<indom>"duplicate" { return TOK_DUPLICATE; }
<indom>"iname" { return TOK_INAME; }
<indom>"inst" { return TOK_INST; }
<metric>"name" { return TOK_NAME; }
<metric>"pmid" { return TOK_PMID; }
<metric>"type" { BEGIN(type); return TOK_TYPE; }
<metric>"indom" { return TOK_INDOM; }
<metric>"NULL" { return TOK_NULL_INT; }
<metric>"output" { BEGIN(output); return TOK_OUTPUT; }
<metric>"sem" { BEGIN(sem); return TOK_SEM; }
<metric>"units" { BEGIN(units); comma_count = 0; return TOK_UNITS; }
<type>"32" { yylval.ival = PM_TYPE_32; BEGIN(metric); return TOK_TYPE_NAME; }
<type>"U32" { yylval.ival = PM_TYPE_U32; BEGIN(metric); return TOK_TYPE_NAME; }
<type>"64" { yylval.ival = PM_TYPE_64; BEGIN(metric); return TOK_TYPE_NAME; }
<type>"U64" { yylval.ival = PM_TYPE_U64; BEGIN(metric); return TOK_TYPE_NAME; }
<type>"FLOAT" { yylval.ival = PM_TYPE_FLOAT; BEGIN(metric); return TOK_TYPE_NAME; }
<type>"DOUBLE" { yylval.ival = PM_TYPE_DOUBLE; BEGIN(metric); return TOK_TYPE_NAME; }
<output>"first" { yylval.ival = OUTPUT_FIRST; BEGIN(metric); return TOK_OUTPUT_TYPE; }
<output>"last" { yylval.ival = OUTPUT_LAST; BEGIN(metric); return TOK_OUTPUT_TYPE; }
<output>"min" { yylval.ival = OUTPUT_MIN; BEGIN(metric); return TOK_OUTPUT_TYPE; }
<output>"max" { yylval.ival = OUTPUT_MAX; BEGIN(metric); return TOK_OUTPUT_TYPE; }
<output>"sum" { yylval.ival = OUTPUT_SUM; BEGIN(metric); return TOK_OUTPUT_TYPE; }
<output>"avg" { yylval.ival = OUTPUT_AVG; BEGIN(metric); return TOK_OUTPUT_TYPE; }
<output>"inst" { BEGIN(metric); return TOK_INST; }
<output>"iname" { BEGIN(metric); return TOK_INAME; }
<sem>"COUNTER" { yylval.ival = PM_SEM_COUNTER; BEGIN(metric); return TOK_SEM_NAME; }
<sem>"INSTANT" { yylval.ival = PM_SEM_INSTANT; BEGIN(metric); return TOK_SEM_NAME; }
<sem>"DISCRETE" { yylval.ival = PM_SEM_DISCRETE; BEGIN(metric); return TOK_SEM_NAME; }
<units>"," {
++comma_count;
switch (comma_count) {
case 1:
case 2:
break;
case 3:
BEGIN(space);
break;
case 4:
BEGIN(time);
break;
case 5:
BEGIN(count);
break;
}
return TOK_COMMA;
}
<metric>"rescale" { return TOK_RESCALE; }
<space>"BYTE" { yylval.ival = PM_SPACE_BYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"KBYTE" { yylval.ival = PM_SPACE_KBYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"MBYTE" { yylval.ival = PM_SPACE_MBYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"GBYTE" { yylval.ival = PM_SPACE_GBYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"TBYTE" { yylval.ival = PM_SPACE_TBYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"PBYTE" { yylval.ival = PM_SPACE_PBYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"EBYTE" { yylval.ival = PM_SPACE_EBYTE; BEGIN(units); return TOK_SPACE_NAME; }
<space>"0" { yylval.ival = 0; BEGIN(units); return TOK_SPACE_NAME; }
<time>"NSEC" { yylval.ival = PM_TIME_NSEC; BEGIN(units); return TOK_TIME_NAME; }
<time>"USEC" { yylval.ival = PM_TIME_USEC; BEGIN(units); return TOK_TIME_NAME; }
<time>"MSEC" { yylval.ival = PM_TIME_MSEC; BEGIN(units); return TOK_TIME_NAME; }
<time>"SEC" { yylval.ival = PM_TIME_SEC; BEGIN(units); return TOK_TIME_NAME; }
<time>"MIN" { yylval.ival = PM_TIME_MIN; BEGIN(units); return TOK_TIME_NAME; }
<time>"HOUR" { yylval.ival = PM_TIME_HOUR; BEGIN(units); return TOK_TIME_NAME; }
<time>"0" { yylval.ival = 0; BEGIN(units); return TOK_TIME_NAME; }
<count>"ONE" { yylval.ival = PM_COUNT_ONE; BEGIN(metric); return TOK_COUNT_NAME; }
<count>[0-9]+ { yylval.ival = atoi(yytext); BEGIN(metric); return TOK_COUNT_NAME; }
\"[^\"\n][^\"\n]*\" { yylval.str = dupstr(yytext, 1); return TOK_STRING; }
[0-9]+ { yylval.str = dupstr(yytext, 0); return TOK_NUMBER; }
[0-9]+\.[0-9]* { yylval.str = dupstr(yytext, 0); return TOK_FLOAT; }
[0-9]+\.\* { yylval.str = dupstr(yytext, 0); return TOK_INDOM_STAR; }
[0-9]+\.[0-9]+\.[0-9]+ { yylval.str = dupstr(yytext, 0); return TOK_PMID_INT; }
[0-9]+\.[0-9]+\.\* { yylval.str = dupstr(yytext, 0); return TOK_PMID_STAR; }
[0-9]+\.\*\.\* { yylval.str = dupstr(yytext, 0); return TOK_PMID_STAR; }
/* Generic name, e.g. for identifier or metric or hostname */
[A-Za-z][A-Za-z0-9_.]* { yylval.str = dupstr(yytext, 0); return TOK_GNAME; }
\#.* { }
[ \t\r]+ { }
"->" { return TOK_ASSIGN; }
"{" {
if (mystate == LEX_GLOBAL) BEGIN(glob);
if (mystate == LEX_INDOM) BEGIN(indom);
if (mystate == LEX_METRIC) BEGIN(metric);
#if PCP_DEBUG
if ((pmDebug & (DBG_TRACE_APPL0 | DBG_TRACE_APPL1)) == (DBG_TRACE_APPL0 | DBG_TRACE_APPL1))
fprintf(stderr, "lex: [%d] { begin state=%d\n", lineno, mystate);
#endif
return TOK_LBRACE;
}
"}" {
#if PCP_DEBUG
if ((pmDebug & (DBG_TRACE_APPL0 | DBG_TRACE_APPL1)) == (DBG_TRACE_APPL0 | DBG_TRACE_APPL1))
fprintf(stderr, "lex: [%d] } end state=%d\n", lineno, mystate);
#endif
mystate = LEX_NONE;
BEGIN(INITIAL); return TOK_RBRACE;
}
"+" { return TOK_PLUS; }
"-" { return TOK_MINUS; }
":" { return TOK_COLON; }
"," { return TOK_COMMA; }
\n { lineno++; }
. {
snprintf(mess, sizeof(mess), "Unexpected character '%c'",
yytext[0]);
yyerror(mess);
}
%%
int
yywrap(void)
{
return(1);
}
|