zonecfg_lex.l revision 12734:76969fc28795
1%{ 2/* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23/* 24 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 25 */ 26 27#include <string.h> 28#include <libintl.h> 29#include "zonecfg.h" 30#include "zonecfg_grammar.tab.h" 31 32int lex_lineno = 1; /* line number for error reporting */ 33static int state = INITIAL; 34extern boolean_t cmd_file_mode; 35extern boolean_t saw_error; 36extern void yyerror(char *s); 37char *safe_strdup(char *s); 38%} 39 40%a 7000 41%p 5000 42%e 2000 43%n 1000 44 45%{ 46/* 47 * The three states below are for tokens, lists and complex property values. 48 * Note that simple property values are a subset of tokens. 49 */ 50%} 51%s TSTATE 52%s LSTATE 53%s CSTATE 54%% 55 56<INITIAL>"#"[^\n]* { } 57 58<INITIAL>add { 59 BEGIN TSTATE; 60 state = TSTATE; 61 return ADD; 62 } 63 64<INITIAL>cancel { 65 BEGIN TSTATE; 66 state = TSTATE; 67 return CANCEL; 68 } 69 70<INITIAL>commit { 71 BEGIN TSTATE; 72 state = TSTATE; 73 return COMMIT; 74 } 75 76<INITIAL>create { 77 BEGIN TSTATE; 78 state = TSTATE; 79 return CREATE; 80 } 81 82<INITIAL>delete { 83 BEGIN TSTATE; 84 state = TSTATE; 85 return DELETE; 86 } 87 88<INITIAL>end { 89 BEGIN TSTATE; 90 state = TSTATE; 91 return END; 92 } 93 94<INITIAL>exit { 95 BEGIN TSTATE; 96 state = TSTATE; 97 return EXIT; 98 } 99 100<INITIAL>export { 101 BEGIN TSTATE; 102 state = TSTATE; 103 return EXPORT; 104 } 105 106<INITIAL>"?"|help { 107 BEGIN TSTATE; 108 state = TSTATE; 109 return HELP; 110 } 111 112<INITIAL>info { 113 BEGIN TSTATE; 114 state = TSTATE; 115 return INFO; 116 } 117 118<INITIAL>remove { 119 BEGIN TSTATE; 120 state = TSTATE; 121 return REMOVE; 122 } 123 124<INITIAL>revert { 125 BEGIN TSTATE; 126 state = TSTATE; 127 return REVERT; 128 } 129 130<INITIAL>select { 131 BEGIN TSTATE; 132 state = TSTATE; 133 return SELECT; 134 } 135 136<INITIAL>set { 137 BEGIN TSTATE; 138 state = TSTATE; 139 return SET; 140 } 141 142<INITIAL>clear { 143 BEGIN TSTATE; 144 state = TSTATE; 145 return CLEAR; 146 } 147 148<INITIAL>verify { 149 BEGIN TSTATE; 150 state = TSTATE; 151 return VERIFY; 152 } 153 154<TSTATE>net { return NET; } 155 156<TSTATE>fs { return FS; } 157 158<TSTATE>device { return DEVICE; } 159 160<TSTATE>rctl { return RCTL; } 161 162<TSTATE>attr { return ATTR; } 163 164<TSTATE>admin { return ADMIN; } 165 166<TSTATE>zonename { return ZONENAME; } 167<CSTATE>zonename { return ZONENAME; } 168 169<TSTATE>dataset { return DATASET; } 170 171<TSTATE>dedicated-cpu { return PSET; } 172 173<TSTATE>capped-cpu { return PCAP; } 174 175<TSTATE>capped-memory { return MCAP; } 176 177<TSTATE>zonepath { return ZONEPATH; } 178<CSTATE>zonepath { return ZONEPATH; } 179 180<TSTATE>brand { return BRAND; } 181<CSTATE>brand { return BRAND; } 182 183<TSTATE>autoboot { return AUTOBOOT; } 184<CSTATE>autoboot { return AUTOBOOT; } 185 186<TSTATE>ip-type { return IPTYPE; } 187<CSTATE>ip-type { return IPTYPE; } 188 189<TSTATE>pool { return POOL; } 190<CSTATE>pool { return POOL; } 191 192<TSTATE>limitpriv { return LIMITPRIV; } 193<CSTATE>limitpriv { return LIMITPRIV; } 194 195<TSTATE>bootargs { return BOOTARGS; } 196<CSTATE>bootargs { return BOOTARGS; } 197 198<TSTATE>type { return TYPE; } 199<CSTATE>type { return TYPE; } 200 201<TSTATE>value { return VALUE; } 202<CSTATE>value { return VALUE; } 203 204<TSTATE>options { return OPTIONS; } 205<CSTATE>options { return OPTIONS; } 206 207<TSTATE>address { return ADDRESS; } 208<CSTATE>address { return ADDRESS; } 209 210<TSTATE>physical { return PHYSICAL; } 211<CSTATE>physical { return PHYSICAL; } 212 213<TSTATE>defrouter { return DEFROUTER; } 214<CSTATE>defrouter { return DEFROUTER; } 215 216<TSTATE>dir { return DIR; } 217<CSTATE>dir { return DIR; } 218 219<TSTATE>special { return SPECIAL; } 220<CSTATE>special { return SPECIAL; } 221 222<TSTATE>raw { return RAW; } 223<CSTATE>raw { return RAW; } 224 225<TSTATE>name { return NAME; } 226<CSTATE>name { return NAME; } 227 228<TSTATE>match { return MATCH; } 229<CSTATE>match { return MATCH; } 230 231<TSTATE>priv { return PRIV; } 232<CSTATE>priv { return PRIV; } 233 234<TSTATE>limit { return LIMIT; } 235<CSTATE>limit { return LIMIT; } 236 237<TSTATE>action { return ACTION; } 238<CSTATE>action { return ACTION; } 239 240<TSTATE>ncpus { return NCPUS; } 241<CSTATE>ncpus { return NCPUS; } 242 243<TSTATE>locked { return LOCKED; } 244<CSTATE>locked { return LOCKED; } 245 246<TSTATE>swap { return SWAP; } 247<CSTATE>swap { return SWAP; } 248 249<TSTATE>importance { return IMPORTANCE; } 250<CSTATE>importance { return IMPORTANCE; } 251 252<TSTATE>cpu-shares { return SHARES; } 253<CSTATE>cpu-shares { return SHARES; } 254 255<TSTATE>max-lwps { return MAXLWPS; } 256<CSTATE>max-lwps { return MAXLWPS; } 257 258<TSTATE>max-processes { return MAXPROCS; } 259<CSTATE>max-processes { return MAXPROCS; } 260 261<TSTATE>max-shm-memory { return MAXSHMMEM; } 262<CSTATE>max-shm-memory { return MAXSHMMEM; } 263 264<TSTATE>max-shm-ids { return MAXSHMIDS; } 265<CSTATE>max-shm-ids { return MAXSHMIDS; } 266 267<TSTATE>max-msg-ids { return MAXMSGIDS; } 268<CSTATE>max-msg-ids { return MAXMSGIDS; } 269 270<TSTATE>max-sem-ids { return MAXSEMIDS; } 271<CSTATE>max-sem-ids { return MAXSEMIDS; } 272 273<TSTATE>scheduling-class { return SCHED; } 274<CSTATE>scheduling-class { return SCHED; } 275 276<TSTATE>hostid { return HOSTID; } 277<CSTATE>hostid { return HOSTID; } 278 279<TSTATE>user { return USER; } 280<CSTATE>user { return USER; } 281 282<TSTATE>auths { return AUTHS; } 283<CSTATE>auths { return AUTHS; } 284 285<TSTATE>fs-allowed { return FS_ALLOWED; } 286<CSTATE>fs-allowed { return FS_ALLOWED; } 287 288<TSTATE>= { return EQUAL; } 289<LSTATE>= { return EQUAL; } 290<CSTATE>= { return EQUAL; } 291 292<TSTATE>"[" { 293 BEGIN LSTATE; 294 state = LSTATE; 295 return OPEN_SQ_BRACKET; 296 } 297 298<LSTATE>"]" { 299 BEGIN TSTATE; 300 state = TSTATE; 301 return CLOSE_SQ_BRACKET; 302 } 303 304<TSTATE>"(" { 305 BEGIN CSTATE; 306 return OPEN_PAREN; 307 } 308 309<LSTATE>"(" { 310 BEGIN CSTATE; 311 return OPEN_PAREN; 312 } 313 314<CSTATE>")" { 315 BEGIN state; 316 return CLOSE_PAREN; 317 } 318 319<LSTATE>"," { return COMMA; } 320<CSTATE>"," { return COMMA; } 321 322<TSTATE>[^ \t\n\";=\[\]\(\)]+ { 323 yylval.strval = safe_strdup(yytext); 324 return TOKEN; 325 } 326 327<LSTATE>[^ \t\n\",;=\[\]\(\)]+ { 328 yylval.strval = safe_strdup(yytext); 329 return TOKEN; 330 } 331 332<CSTATE>[^ \t\n\",;=\(\)]+ { 333 yylval.strval = safe_strdup(yytext); 334 return TOKEN; 335 } 336 337<TSTATE>\"[^\"\n]*[\"\n] { 338 yylval.strval = safe_strdup(yytext + 1); 339 if (yylval.strval[yyleng - 2] == '"') 340 yylval.strval[yyleng - 2] = 0; 341 return TOKEN; 342 } 343 344<LSTATE>\"[^\"\n]*[\"\n] { 345 yylval.strval = safe_strdup(yytext + 1); 346 if (yylval.strval[yyleng - 2] == '"') 347 yylval.strval[yyleng - 2] = 0; 348 return TOKEN; 349 } 350 351";" { 352 BEGIN INITIAL; 353 return (yytext[0]); 354 } 355 356\n { 357 lex_lineno++; 358 BEGIN INITIAL; 359 return (yytext[0]); 360 } 361 362[ \t] ; /* Ignore whitespace */ 363 364. { 365 return (yytext[0]); 366 } 367 368%% 369 370char * 371safe_strdup(char *s) 372{ 373 char *result; 374 375 if ((result = strdup(s)) == NULL) { 376 yyerror("Out of memory"); 377 exit(Z_ERR); 378 } 379 return (result); 380} 381 382void 383yyerror(char *s) 384{ 385 /* feof(yyin) is not an error; anything else is, so we set saw_error */ 386 if (yytext[0] == '\0') { 387 if (!feof(yyin)) { 388 saw_error = B_TRUE; 389 (void) fprintf(stderr, gettext("%s, token expected\n"), 390 s); 391 } 392 return; 393 } 394 395 saw_error = B_TRUE; 396 if (cmd_file_mode) 397 (void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s, 398 lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext); 399 else 400 (void) fprintf(stderr, gettext("%s at '%s'\n"), s, 401 (yytext[0] == '\n') ? "\\n" : yytext); 402 usage(B_FALSE, HELP_SUBCMDS); 403} 404