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 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * Portions Copyright 2008 Denis Cheng 27 */ 28 29 %{ 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 %} 32 33 %{ 34 35 #include <stdlib.h> 36 #include <sys/types.h> 37 #include <assert.h> 38 #include <string.h> 39 #include <errno.h> 40 #ifdef HAVE_STDINT_H 41 #include <stdint.h> 42 #endif 43 44 #include "filebench.h" 45 #include "parsertypes.h" 46 #include "utils.h" 47 #include "parser_gram.h" 48 49 int lex_lineno = 1; /* line-number for error reporting */ 50 extern void yyerror(char *s); 51 extern int dofile; /* are we processing a file? */ 52 %} 53 54 %s WHITESTRINGSTATE 55 56 %a 50000 57 %p 50000 58 %o 50000 59 %n 5000 60 61 %% 62 63 \n { lex_lineno++; } 64 65 <INITIAL>[ \t]+ ; 66 67 <INITIAL>#.* ; 68 69 eventgen { return FSC_EVENTGEN; } 70 create { return FSC_CREATE; } 71 define { return FSC_DEFINE; } 72 debug { return FSC_DEBUG; } 73 echo { return FSC_ECHO; } 74 exit { return FSC_QUIT; } 75 foreach { return FSC_FOREACH; } 76 flowop { return FSC_FLOWOP; } 77 help { return FSC_HELP; } 78 list { return FSC_LIST; } 79 load { return FSC_LOAD; } 80 log { return FSC_LOG; } 81 run { return FSC_RUN; } 82 set { return FSC_SET; } 83 shutdown { return FSC_SHUTDOWN; } 84 sleep { return FSC_SLEEP; } 85 stats { return FSC_STATS; } 86 system { return FSC_SYSTEM; } 87 usage { return FSC_USAGE; } 88 vars { return FSC_VARS; } 89 version { return FSC_VERSION; } 90 quit { return FSC_QUIT; } 91 92 file[s]* { return FSE_FILE; } 93 fileset[s]* { return FSE_FILESET; } 94 directory { return FSE_DIRECTORY; } 95 command { return FSE_COMMAND; } 96 process[es]* { return FSE_PROC; } 97 thread { return FSE_THREAD; } 98 randvar { return FSE_RAND; } 99 clear { return FSE_CLEAR; } 100 snap { return FSE_SNAP; } 101 dump { return FSE_DUMP; } 102 xmldump { return FSE_XMLDUMP; } 103 all { return FSE_ALL; } 104 mode { return FSE_MODE; } 105 106 cached { return FSA_CACHED; } 107 dirwidth { return FSA_DIRWIDTH; } 108 dirdepthrv { return FSA_DIRDEPTHRV; } 109 dirgamma { return FSA_DIRGAMMA; } 110 namelength { return FSA_NAMELENGTH; } 111 filesize { return FSA_SIZE; } 112 filesizegamma { return FSA_FILESIZEGAMMA; } 113 directio { return FSA_DIRECTIO; } 114 dsync { return FSA_DSYNC; } 115 fd { return FSA_FD; } 116 srcfd { return FSA_SRCFD; } 117 opennext { return FSA_ROTATEFD; } 118 filename { return FSA_FILE; } 119 filesetname { return FSA_FILE; } 120 instances { return FSA_INSTANCES;} 121 iosize { return FSA_IOSIZE; } 122 iters { return FSA_ITERS;} 123 memsize { return FSA_MEMSIZE; } 124 name { return FSA_NAME;} 125 nice { return FSA_NICE;} 126 entries { return FSA_ENTRIES;} 127 prealloc { return FSA_PREALLOC; } 128 paralloc { return FSA_PARALLOC; } 129 reuse { return FSA_REUSE; } 130 path { return FSA_PATH; } 131 procname { return FSA_PROCESS; } 132 random { return FSA_RANDOM;} 133 rate { return FSA_RATE;} 134 size { return FSA_SIZE; } 135 target { return FSA_TARGET;} 136 useism { return FSA_USEISM;} 137 value { return FSA_VALUE;} 138 workingset { return FSA_WSS; } 139 blocking { return FSA_BLOCKING; } 140 highwater { return FSA_HIGHWATER; } 141 alldone { return FSA_ALLDONE; } 142 firstdone { return FSA_FIRSTDONE; } 143 timeout { return FSA_TIMEOUT; } 144 type { return FSA_TYPE; } 145 seed { return FSA_RANDSEED; } 146 gamma { return FSA_RANDGAMMA; } 147 mean { return FSA_RANDMEAN; } 148 min { return FSA_RANDMIN; } 149 round { return FSA_RANDROUND; } 150 randsrc { return FSA_RANDSRC; } 151 randtable { return FSA_RANDTABLE; } 152 uniform { return FSV_RANDUNI; } 153 tabular { return FSV_RANDTAB; } 154 "."type { return FSS_TYPE; } 155 "."seed { return FSS_SEED; } 156 "."gamma { return FSS_GAMMA; } 157 "."mean { return FSS_MEAN; } 158 "."min { return FSS_MIN; } 159 "."round { return FSS_ROUND; } 160 "."randsrc { return FSS_SRC; } 161 urandom { return FSV_URAND; } 162 rand48 { return FSV_RAND48; } 163 164 165 <INITIAL>\" { 166 BEGIN WHITESTRINGSTATE; 167 return FSK_QUOTE; 168 } 169 170 <WHITESTRINGSTATE>\" { 171 BEGIN INITIAL; 172 return FSK_QUOTE; 173 } 174 175 <WHITESTRINGSTATE>[^$^\\^"][^$^"]*[^\\^$^"] { 176 if ((yylval.sval = strdup(yytext)) == NULL) { 177 yyerror("Out of memory"); 178 filebench_shutdown(E_ERROR); 179 } 180 return FSV_WHITESTRING; 181 } 182 183 <WHITESTRINGSTATE>\\n { 184 yylval.sval = "\n"; 185 return FSV_WHITESTRING; 186 } 187 188 189 <WHITESTRINGSTATE>\\$[^"^$^\\]+ { 190 if ((yylval.sval = strdup(yytext + 1)) == NULL) { 191 yyerror("Out of memory"); 192 filebench_shutdown(E_ERROR); 193 } 194 return FSV_WHITESTRING; 195 } 196 197 <WHITESTRINGSTATE>[^$^\\^"] { 198 if ((yylval.sval = strdup(yytext)) == NULL) { 199 yyerror("Out of memory"); 200 filebench_shutdown(E_ERROR); 201 } 202 return FSV_WHITESTRING; 203 } 204 205 206 <INITIAL>\{ { return FSK_OPENLST; } 207 <INITIAL>\} { return FSK_CLOSELST; } 208 <INITIAL>= { return FSK_ASSIGN; } 209 <INITIAL>\, { return FSK_SEPLST; } 210 <INITIAL>in { return FSK_IN; } 211 212 <INITIAL>[0-9]+ { 213 errno = 0; 214 yylval.ival = strtoll(yytext, NULL, 10); 215 if (errno == EINVAL || errno == ERANGE) { 216 (void) filebench_log(LOG_ERROR, 217 "Invalid I value '%s':%s", yytext, 218 strerror(errno)); 219 } 220 return FSV_VAL_INT; 221 } 222 223 <INITIAL>[0-9]+k { 224 errno = 0; 225 yylval.ival = KB * strtoll(yytext, NULL, 10); 226 if (errno == EINVAL || errno == ERANGE) { 227 (void) filebench_log(LOG_ERROR, 228 "Invalid I value '%s':%s", yytext, 229 strerror(errno)); 230 } 231 return FSV_VAL_INT; 232 } 233 234 <INITIAL>[0-9]+m { 235 errno = 0; 236 yylval.ival = MB * strtoll(yytext, NULL, 10); 237 if (errno == EINVAL || errno == ERANGE) { 238 (void) filebench_log(LOG_ERROR, 239 "Invalid I value '%s':%s", yytext, 240 strerror(errno)); 241 } 242 return FSV_VAL_INT; 243 } 244 245 <INITIAL>[0-9]+g { 246 errno = 0; 247 yylval.ival = GB * strtoll(yytext, NULL, 10); 248 if (errno == EINVAL || errno == ERANGE) { 249 (void) filebench_log(LOG_ERROR, 250 "Invalid I value '%s':%s", yytext, 251 strerror(errno)); 252 } 253 return FSV_VAL_INT; 254 } 255 256 <INITIAL>true { 257 yylval.bval = TRUE; 258 return FSV_VAL_BOOLEAN; 259 } 260 261 <INITIAL>false { 262 yylval.bval = FALSE; 263 return FSV_VAL_BOOLEAN; 264 } 265 266 $[({A-Za-z][A-Za-z0-9_]*[A-Za-z0-9][)}]* { 267 if ((yylval.sval = strdup(yytext)) == NULL) { 268 yyerror("Out of memory"); 269 filebench_shutdown(E_ERROR); 270 } 271 272 return FSV_VARIABLE; 273 } 274 275 276 $[({A-Za-z][A-Za-z0-9_]*"."[A-Za-z0-9][)}]* { 277 int backtrack; 278 279 if ((backtrack = 280 var_is_set4_randvar(yytext)) != 0) 281 yyless(yyleng - backtrack); 282 283 if ((yylval.sval = strdup(yytext)) == NULL) { 284 yyerror("Out of memory"); 285 filebench_shutdown(E_ERROR); 286 } 287 288 return FSV_RANDVAR; 289 } 290 291 292 <INITIAL>[/A-Za-z-][/A-Za-z0-9._-]* { 293 if ((yylval.sval = strdup(yytext)) == NULL) { 294 yyerror("Out of memory"); 295 filebench_shutdown(E_ERROR); 296 } 297 return FSV_STRING; 298 } 299 300 301 . { 302 yyerror("Illegal character"); 303 } 304 305 %% 306 307 void 308 yyerror(char *s) 309 { 310 if (dofile == FS_TRUE) { 311 if (yytext[0] == '\0') { 312 filebench_log(LOG_ERROR, 313 "%s, token expected", 314 s); 315 return; 316 } 317 (void) filebench_log(LOG_ERROR, 318 "%s at '%s'", 319 s, 320 yytext); 321 } else { 322 if (yytext[0] == '\0') { 323 (void) filebench_log(LOG_ERROR, 324 "%s, token expected", s); 325 return; 326 } 327 (void) filebench_log(LOG_ERROR, "%s at '%s'", s, yytext); 328 } 329 } 330 331 struct yy_buffer_state *parent; 332 struct yy_buffer_state *script; 333 334 int 335 yy_switchfileparent(FILE *file) 336 { 337 script = YY_CURRENT_BUFFER; 338 parent = (struct yy_buffer_state *)yy_create_buffer(yyin, 128); 339 yy_switch_to_buffer(parent); 340 return (0); 341 } 342 343 int 344 yy_switchfilescript(FILE *file) 345 { 346 yy_switch_to_buffer(script); 347 return (0); 348 } 349 350