xref: /onnv-gate/usr/src/cmd/filebench/common/parser_lex.l (revision 5184:da60d2b4a9e2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 %{
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 %}
30 
31 %{
32 
33 #include <stdlib.h>
34 #include <sys/types.h>
35 #include <assert.h>
36 #include <string.h>
37 #include <errno.h>
38 #ifdef HAVE_STDINT_H
39 #include <stdint.h>
40 #endif
41 #include "parsertypes.h"
42 #include "utils.h"
43 #include "filebench.h"
44 
45 #include "parser_gram.h"
46 
47 int lex_lineno = 1;		/* line-number for error reporting */
48 extern void yyerror(char *s);
49 extern int dofile;			/* are we processing a file? */
50 %}
51 
52 %s WHITESTRINGSTATE
53 
54 %a 50000
55 %p 50000
56 %o 50000
57 %n 5000
58 
59 %%
60 
61 \n			{ lex_lineno++; }
62 
63 <INITIAL>[ \t]+			;
64 
65 <INITIAL>#.*			;
66 
67 eventgen                { return FSC_EVENTGEN; }
68 create                  { return FSC_CREATE; }
69 define			{ return FSC_DEFINE; }
70 debug                   { return FSC_DEBUG; }
71 echo                    { return FSC_ECHO; }
72 exit		        { return FSC_QUIT; }
73 foreach                 { return FSC_FOREACH; }
74 flowop		        { return FSC_FLOWOP; }
75 help		        { return FSC_HELP; }
76 list		        { return FSC_LIST; }
77 load                    { return FSC_LOAD; }
78 log		        { return FSC_LOG; }
79 run                     { return FSC_RUN; }
80 set                     { return FSC_SET; }
81 shutdown                { return FSC_SHUTDOWN; }
82 sleep                   { return FSC_SLEEP; }
83 stats                   { return FSC_STATS; }
84 system                  { return FSC_SYSTEM; }
85 usage                   { return FSC_USAGE; }
86 vars                    { return FSC_VARS; }
87 quit		        { return FSC_QUIT; }
88 
89 file[s]*       	        { return FSE_FILE; }
90 fileset[s]*             { return FSE_FILESET; }
91 directory               { return FSE_DIRECTORY; }
92 command                 { return FSE_COMMAND; }
93 process[es]*	        { return FSE_PROC; }
94 thread		        { return FSE_THREAD; }
95 clear                   { return FSE_CLEAR; }
96 snap                    { return FSE_SNAP; }
97 dump                    { return FSE_DUMP; }
98 xmldump                 { return FSE_XMLDUMP; }
99 all                     { return FSE_ALL; }
100 
101 cached                  { return FSA_CACHED; }
102 dirwidth                { return FSA_DIRWIDTH; }
103 dirgamma                { return FSA_DIRGAMMA; }
104 namelength              { return FSA_NAMELENGTH; }
105 filesize                { return FSA_FILESIZE; }
106 filesizegamma           { return FSA_FILESIZEGAMMA; }
107 directio                { return FSA_DIRECTIO; }
108 dsync                   { return FSA_DSYNC;  }
109 fd                      { return FSA_FD; }
110 srcfd                   { return FSA_SRCFD; }
111 opennext                { return FSA_ROTATEFD; }
112 filename                { return FSA_FILE; }
113 filesetname             { return FSA_FILE; }
114 instances               { return FSA_INSTANCES;}
115 iosize                  { return FSA_IOSIZE; }
116 iters                   { return FSA_ITERS;}
117 memsize                 { return FSA_MEMSIZE; }
118 name                    { return FSA_NAME;}
119 nice                    { return FSA_NICE;}
120 entries                 { return FSA_ENTRIES;}
121 prealloc                { return FSA_PREALLOC; }
122 paralloc                { return FSA_PARALLOC; }
123 reuse                   { return FSA_REUSE; }
124 path                    { return FSA_PATH; }
125 procname                { return FSA_PROCESS; }
126 random                  { return FSA_RANDOM;}
127 rate                    { return FSA_RATE;}
128 size                    { return FSA_SIZE; }
129 target                  { return FSA_TARGET;}
130 useism                  { return FSA_USEISM;}
131 value                   { return FSA_VALUE;}
132 workingset              { return FSA_WSS; }
133 blocking                { return FSA_BLOCKING; }
134 highwater               { return FSA_HIGHWATER; }
135 
136 <INITIAL>\"			{
137                                 BEGIN WHITESTRINGSTATE;
138                                 return FSK_QUOTE;
139                         }
140 
141 <WHITESTRINGSTATE>\"    {
142                                 BEGIN INITIAL;
143                                 return FSK_QUOTE;
144                         }
145 
146 <WHITESTRINGSTATE>[^$^\\^"][^$^"]*[^\\^$^"] {
147 				if ((yylval.sval = strdup(yytext)) == NULL) {
148 					yyerror("Out of memory");
149 					filebench_shutdown(E_ERROR);
150 				}
151  				return FSV_WHITESTRING;
152 	       	}
153 
154 <WHITESTRINGSTATE>\\n	{
155 				yylval.sval = "\n";
156  				return FSV_WHITESTRING;
157 	       	}
158 
159 
160 <WHITESTRINGSTATE>\\$[^"^$^\\]+	{
161 				if ((yylval.sval = strdup(yytext + 1)) == NULL) {
162 					yyerror("Out of memory");
163 					filebench_shutdown(E_ERROR);
164 				}
165  				return FSV_WHITESTRING;
166 	       	}
167 
168 <WHITESTRINGSTATE>[^$^\\^"] {
169 				if ((yylval.sval = strdup(yytext)) == NULL) {
170 					yyerror("Out of memory");
171 					filebench_shutdown(E_ERROR);
172 				}
173  				return FSV_WHITESTRING;
174 	       	}
175 
176 
177 <INITIAL>\{			{ return FSK_OPENLST; }
178 <INITIAL>\}			{ return FSK_CLOSELST; }
179 <INITIAL>=			{ return FSK_ASSIGN; }
180 <INITIAL>\,			{ return FSK_SEPLST; }
181 <INITIAL>in                     { return FSK_IN; }
182 
183 <INITIAL>[0-9]+	{
184                                 errno = 0;
185 				yylval.ival = strtoll(yytext, NULL, 10);
186 				if (errno == EINVAL || errno == ERANGE) {
187                                         (void) filebench_log(LOG_ERROR,
188 						"Invalid I value '%s':%s", yytext,
189 						strerror(errno));
190 				}
191                                 return FSV_VAL_INT;
192 }
193 
194 <INITIAL>[0-9]+k	{
195                                 errno = 0;
196 				yylval.ival = KB * strtoll(yytext, NULL, 10);
197 				if (errno == EINVAL || errno == ERANGE) {
198                                         (void) filebench_log(LOG_ERROR,
199 						"Invalid I value '%s':%s", yytext,
200 						strerror(errno));
201 				}
202                                 return FSV_VAL_INT;
203 }
204 
205 <INITIAL>[0-9]+m	{
206                                 errno = 0;
207 				yylval.ival = MB * strtoll(yytext, NULL, 10);
208 				if (errno == EINVAL || errno == ERANGE) {
209                                         (void) filebench_log(LOG_ERROR,
210 						"Invalid I value '%s':%s", yytext,
211 						strerror(errno));
212 				}
213                                 return FSV_VAL_INT;
214 }
215 
216 <INITIAL>[0-9]+g	{
217                                 errno = 0;
218 				yylval.ival = GB * strtoll(yytext, NULL, 10);
219 				if (errno == EINVAL || errno == ERANGE) {
220                                         (void) filebench_log(LOG_ERROR,
221 						"Invalid I value '%s':%s", yytext,
222 						strerror(errno));
223 				}
224                                 return FSV_VAL_INT;
225 }
226 
227 <INITIAL>true|false	{
228 				if (strcmp(yytext, "true") == 0)
229 					yylval.bval = 1;
230 				else
231 					yylval.bval = 0;
232 				return FSV_VAL_BOOLEAN;
233 		}
234 
235 
236 
237 $[({A-Za-z][A-Za-z0-9._]*[A-Za-z0-9][)}]*	{
238 				if ((yylval.sval = strdup(yytext)) == NULL) {
239 					yyerror("Out of memory");
240 					filebench_shutdown(E_ERROR);
241 				}
242  				return FSV_VARIABLE;
243 			}
244 
245 <INITIAL>[/A-Za-z-][/A-Za-z0-9._-]*	{
246 				if ((yylval.sval = strdup(yytext)) == NULL) {
247 					yyerror("Out of memory");
248 					filebench_shutdown(E_ERROR);
249 				}
250  				return FSV_STRING;
251 			}
252 
253 .			{
254 				yyerror("Illegal character");
255 			}
256 
257 %%
258 
259 void
260 yyerror(char *s)
261 {
262 	if (dofile == FS_TRUE) {
263 		if (yytext[0] == '\0') {
264 			filebench_log(LOG_ERROR,
265 				      "%s, token expected",
266 				      s);
267 			return;
268 		}
269 		(void) filebench_log(LOG_ERROR,
270 				     "%s at '%s'",
271 				     s,
272 				     yytext);
273 	} else {
274 		if (yytext[0] == '\0') {
275 			(void) filebench_log(LOG_ERROR,
276 					     "%s, token expected", s);
277 			return;
278 		}
279 		(void) filebench_log(LOG_ERROR, "%s at '%s'", s, yytext);
280 	}
281 }
282 
283 struct yy_buffer_state *parent;
284 struct yy_buffer_state *script;
285 
286 int
287 yy_switchfileparent(FILE *file)
288 {
289 	script = YY_CURRENT_BUFFER;
290 	parent = (struct yy_buffer_state *)yy_create_buffer(yyin, 128);
291 	yy_switch_to_buffer(parent);
292 	return (0);
293 }
294 
295 int
296 yy_switchfilescript(FILE *file)
297 {
298 	yy_switch_to_buffer(script);
299 	return (0);
300 }
301 
302