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 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * Portions Copyright 2008 Denis Cheng 27 */ 28 29 %option nounput 30 %option noyywrap 31 32 %{ 33 34 #include <stdlib.h> 35 #include <sys/types.h> 36 #include <assert.h> 37 #include <string.h> 38 #include <errno.h> 39 #ifdef HAVE_STDINT_H 40 #include <stdint.h> 41 #endif 42 43 #include "filebench.h" 44 #include "parsertypes.h" 45 #include "utils.h" 46 #include "parser_gram.h" 47 48 int lex_lineno = 1; /* line-number for error reporting */ 49 extern void yyerror(char *s); 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 create { return FSC_CREATE; } 68 define { return FSC_DEFINE; } 69 debug { return FSC_DEBUG; } 70 domultisync { return FSC_DOMULTISYNC; } 71 echo { return FSC_ECHO; } 72 enable { return FSC_ENABLE; } 73 eventgen { return FSC_EVENTGEN; } 74 quit { return FSC_QUIT; } 75 list { return FSC_LIST; } 76 run { return FSC_RUN; } 77 psrun { return FSC_PSRUN; } 78 set { return FSC_SET; } 79 sleep { return FSC_SLEEP; } 80 system { return FSC_SYSTEM; } 81 version { return FSC_VERSION; } 82 83 file { return FSE_FILE; } 84 files { return FSE_FILES; } 85 fileset[s]* { return FSE_FILESET; } 86 process[es]* { return FSE_PROC; } 87 thread { return FSE_THREAD; } 88 flowop { return FSE_FLOWOP; } 89 randvar { return FSE_RAND; } 90 mode { return FSE_MODE; } 91 multi { return FSE_MULTI; } 92 cvar { return FSE_CVAR; } 93 94 alldone { return FSA_ALLDONE; } 95 blocking { return FSA_BLOCKING; } 96 client { return FSA_CLIENT; } 97 dirwidth { return FSA_DIRWIDTH; } 98 dirdepthrv { return FSA_DIRDEPTHRV; } 99 directio { return FSA_DIRECTIO; } 100 dirgamma { return FSA_DIRGAMMA; } 101 dsync { return FSA_DSYNC; } 102 entries { return FSA_ENTRIES;} 103 fd { return FSA_FD; } 104 filename { return FSA_FILENAME; } 105 filesetname { return FSA_FILENAME; } 106 filesize { return FSA_SIZE; } 107 firstdone { return FSA_FIRSTDONE; } 108 gamma { return FSA_RANDGAMMA; } 109 highwater { return FSA_HIGHWATER; } 110 indexed { return FSA_INDEXED; } 111 instances { return FSA_INSTANCES;} 112 iosize { return FSA_IOSIZE; } 113 iters { return FSA_ITERS;} 114 leafdirs { return FSA_LEAFDIRS;} 115 master { return FSA_MASTER; } 116 mean { return FSA_RANDMEAN; } 117 memsize { return FSA_MEMSIZE; } 118 ioprio { return FSA_IOPRIO; } 119 min { return FSA_MIN; } 120 max { return FSA_MAX; } 121 name { return FSA_NAME;} 122 nice { return FSA_NICE;} 123 opennext { return FSA_ROTATEFD; } 124 paralloc { return FSA_PARALLOC; } 125 parameters { return FSA_PARAMETERS; } 126 path { return FSA_PATH; } 127 prealloc { return FSA_PREALLOC; } 128 random { return FSA_RANDOM;} 129 randsrc { return FSA_RANDSRC; } 130 randtable { return FSA_RANDTABLE; } 131 rate { return FSA_RATE;} 132 readonly { return FSA_READONLY; } 133 writeonly { return FSA_WRITEONLY; } 134 reuse { return FSA_REUSE; } 135 round { return FSA_ROUND; } 136 seed { return FSA_RANDSEED; } 137 size { return FSA_SIZE; } 138 srcfd { return FSA_SRCFD; } 139 target { return FSA_TARGET;} 140 timeout { return FSA_TIMEOUT; } 141 trusttree { return FSA_TRUSTTREE; } 142 type { return FSA_TYPE; } 143 useism { return FSA_USEISM;} 144 value { return FSA_VALUE;} 145 workingset { return FSA_WSS; } 146 nousestats { return FSA_NOUSESTATS; } 147 lathist { return FSA_LATHIST; } 148 149 uniform { return FSV_RANDUNI; } 150 tabular { return FSV_RANDTAB; } 151 urandom { return FSV_URAND; } 152 rand48 { return FSV_RAND48; } 153 noreadahead { return FSA_NOREADAHEAD; } 154 155 156 <INITIAL>\" { 157 BEGIN WHITESTRINGSTATE; 158 return FSK_QUOTE; 159 } 160 161 <WHITESTRINGSTATE>\" { 162 BEGIN INITIAL; 163 return FSK_QUOTE; 164 } 165 166 <WHITESTRINGSTATE>[^$\\"][^$"]*[^\\$"] { 167 if ((yylval.sval = strdup(yytext)) == NULL) { 168 yyerror("Out of memory"); 169 filebench_shutdown(1); 170 } 171 return FSV_WHITESTRING; 172 } 173 174 <WHITESTRINGSTATE>\\n { 175 yylval.sval = "\n"; 176 return FSV_WHITESTRING; 177 } 178 179 180 <WHITESTRINGSTATE>\\$[^"$\\]+ { 181 if ((yylval.sval = strdup(yytext + 1)) == NULL) { 182 yyerror("Out of memory"); 183 filebench_shutdown(1); 184 } 185 return FSV_WHITESTRING; 186 } 187 188 <WHITESTRINGSTATE>[^$\\"] { 189 if ((yylval.sval = strdup(yytext)) == NULL) { 190 yyerror("Out of memory"); 191 filebench_shutdown(1); 192 } 193 return FSV_WHITESTRING; 194 } 195 196 197 <INITIAL>\{ { return FSK_OPENLST; } 198 <INITIAL>\} { return FSK_CLOSELST; } 199 <INITIAL>\( { return FSK_OPENPAR; } 200 <INITIAL>\) { return FSK_CLOSEPAR; } 201 <INITIAL>= { return FSK_ASSIGN; } 202 <INITIAL>\, { return FSK_SEPLST; } 203 <INITIAL>in { return FSK_IN; } 204 205 <INITIAL>[0-9]+ { 206 errno = 0; 207 yylval.ival = 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_POSINT; 214 } 215 216 <INITIAL>-[0-9]+ { 217 errno = 0; 218 yylval.ival = 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_NEGINT; 225 } 226 227 <INITIAL>[0-9]+k { 228 errno = 0; 229 yylval.ival = KB * strtoll(yytext, NULL, 10); 230 if (errno == EINVAL || errno == ERANGE) { 231 (void) filebench_log(LOG_ERROR, 232 "Invalid I value '%s':%s", yytext, 233 strerror(errno)); 234 } 235 return FSV_VAL_POSINT; 236 } 237 238 <INITIAL>[0-9]+m { 239 errno = 0; 240 yylval.ival = MB * strtoll(yytext, NULL, 10); 241 if (errno == EINVAL || errno == ERANGE) { 242 (void) filebench_log(LOG_ERROR, 243 "Invalid I value '%s':%s", yytext, 244 strerror(errno)); 245 } 246 return FSV_VAL_POSINT; 247 } 248 249 <INITIAL>[0-9]+g { 250 errno = 0; 251 yylval.ival = GB * strtoll(yytext, NULL, 10); 252 if (errno == EINVAL || errno == ERANGE) { 253 (void) filebench_log(LOG_ERROR, 254 "Invalid I value '%s':%s", yytext, 255 strerror(errno)); 256 } 257 return FSV_VAL_POSINT; 258 } 259 260 <INITIAL>true { 261 yylval.bval = TRUE; 262 return FSV_VAL_BOOLEAN; 263 } 264 265 <INITIAL>false { 266 yylval.bval = FALSE; 267 return FSV_VAL_BOOLEAN; 268 } 269 270 $[({A-Za-z][A-Za-z0-9_]*[A-Za-z0-9][)}]* { 271 if ((yylval.sval = strdup(yytext)) == NULL) { 272 yyerror("Out of memory"); 273 filebench_shutdown(1); 274 } 275 276 return FSV_VARIABLE; 277 } 278 279 <INITIAL>[/A-Za-z-][/A-Za-z0-9._:;-]* { 280 if ((yylval.sval = strdup(yytext)) == NULL) { 281 yyerror("Out of memory"); 282 filebench_shutdown(1); 283 } 284 return FSV_STRING; 285 } 286 287 288 . { 289 yyerror("Illegal character"); 290 } 291 292 %% 293 294 void 295 yyerror(char *s) 296 { 297 if (yytext[0] == '\0') { 298 (void)filebench_log(LOG_ERROR, "%s, token expected", s); 299 return; 300 } 301 302 (void)filebench_log(LOG_ERROR, "%s at '%s'", s, yytext); 303 } 304 305 struct yy_buffer_state *parent; 306 struct yy_buffer_state *script; 307 308 int 309 yy_switchfileparent(FILE *file) 310 { 311 script = YY_CURRENT_BUFFER; 312 parent = (struct yy_buffer_state *)yy_create_buffer(yyin, 128); 313 yy_switch_to_buffer(parent); 314 return (0); 315 } 316 317 int 318 yy_switchfilescript(FILE *file) 319 { 320 yy_switch_to_buffer(script); 321 return (0); 322 } 323 324