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, Version 1.0 only 7 * (the "License"). You may not use this file except in compliance 8 * with the License. 9 * 10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 * or http://www.opensolaris.org/os/licensing. 12 * See the License for the specific language governing permissions 13 * and limitations under the License. 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 * If applicable, add the following below this CDDL HEADER, with the 18 * fields enclosed by brackets "[]" replaced with your own identifying 19 * information: Portions Copyright [yyyy] [name of copyright owner] 20 * 21 * CDDL HEADER END 22 * 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <string.h> 30 #include <libintl.h> 31 #include "zonecfg.h" 32 #include "zonecfg_grammar.tab.h" 33 34 int lex_lineno = 1; /* line number for error reporting */ 35 static int state = INITIAL; 36 extern bool cmd_file_mode; 37 extern bool saw_error; 38 extern void yyerror(char *s); 39 char *safe_strdup(char *s); 40 %} 41 42 %a 3000 43 44 %{ 45 /* 46 * The three states below are for tokens, lists and complex property values. 47 * Note that simple property values are a subset of tokens. 48 */ 49 %} 50 %s TSTATE 51 %s LSTATE 52 %s CSTATE 53 %% 54 55 <INITIAL>"#"[^\n]* { } 56 57 <INITIAL>add { 58 BEGIN TSTATE; 59 state = TSTATE; 60 return ADD; 61 } 62 63 <INITIAL>cancel { 64 BEGIN TSTATE; 65 state = TSTATE; 66 return CANCEL; 67 } 68 69 <INITIAL>commit { 70 BEGIN TSTATE; 71 state = TSTATE; 72 return COMMIT; 73 } 74 75 <INITIAL>create { 76 BEGIN TSTATE; 77 state = TSTATE; 78 return CREATE; 79 } 80 81 <INITIAL>delete { 82 BEGIN TSTATE; 83 state = TSTATE; 84 return DELETE; 85 } 86 87 <INITIAL>end { 88 BEGIN TSTATE; 89 state = TSTATE; 90 return END; 91 } 92 93 <INITIAL>exit { 94 BEGIN TSTATE; 95 state = TSTATE; 96 return EXIT; 97 } 98 99 <INITIAL>export { 100 BEGIN TSTATE; 101 state = TSTATE; 102 return EXPORT; 103 } 104 105 <INITIAL>"?"|help { 106 BEGIN TSTATE; 107 state = TSTATE; 108 return HELP; 109 } 110 111 <INITIAL>info { 112 BEGIN TSTATE; 113 state = TSTATE; 114 return INFO; 115 } 116 117 <INITIAL>remove { 118 BEGIN TSTATE; 119 state = TSTATE; 120 return REMOVE; 121 } 122 123 <INITIAL>revert { 124 BEGIN TSTATE; 125 state = TSTATE; 126 return REVERT; 127 } 128 129 <INITIAL>select { 130 BEGIN TSTATE; 131 state = TSTATE; 132 return SELECT; 133 } 134 135 <INITIAL>set { 136 BEGIN TSTATE; 137 state = TSTATE; 138 return SET; 139 } 140 141 <INITIAL>verify { 142 BEGIN TSTATE; 143 state = TSTATE; 144 return VERIFY; 145 } 146 147 <TSTATE>net { return NET; } 148 149 <TSTATE>fs { return FS; } 150 151 <TSTATE>inherit-pkg-dir { return IPD; } 152 153 <TSTATE>device { return DEVICE; } 154 155 <TSTATE>rctl { return RCTL; } 156 157 <TSTATE>attr { return ATTR; } 158 159 <TSTATE>zonename { return ZONENAME; } 160 <CSTATE>zonename { return ZONENAME; } 161 162 <TSTATE>dataset { return DATASET; } 163 164 <TSTATE>zonepath { return ZONEPATH; } 165 <CSTATE>zonepath { return ZONEPATH; } 166 167 <TSTATE>autoboot { return AUTOBOOT; } 168 <CSTATE>autoboot { return AUTOBOOT; } 169 170 <TSTATE>pool { return POOL; } 171 <CSTATE>pool { return POOL; } 172 173 <TSTATE>type { return TYPE; } 174 <CSTATE>type { return TYPE; } 175 176 <TSTATE>value { return VALUE; } 177 <CSTATE>value { return VALUE; } 178 179 <TSTATE>options { return OPTIONS; } 180 <CSTATE>options { return OPTIONS; } 181 182 <TSTATE>address { return ADDRESS; } 183 <CSTATE>address { return ADDRESS; } 184 185 <TSTATE>physical { return PHYSICAL; } 186 <CSTATE>physical { return PHYSICAL; } 187 188 <TSTATE>dir { return DIR; } 189 <CSTATE>dir { return DIR; } 190 191 <TSTATE>special { return SPECIAL; } 192 <CSTATE>special { return SPECIAL; } 193 194 <TSTATE>raw { return RAW; } 195 <CSTATE>raw { return RAW; } 196 197 <TSTATE>name { return NAME; } 198 <CSTATE>name { return NAME; } 199 200 <TSTATE>match { return MATCH; } 201 <CSTATE>match { return MATCH; } 202 203 <TSTATE>priv { return PRIV; } 204 <CSTATE>priv { return PRIV; } 205 206 <TSTATE>limit { return LIMIT; } 207 <CSTATE>limit { return LIMIT; } 208 209 <TSTATE>action { return ACTION; } 210 <CSTATE>action { return ACTION; } 211 212 <TSTATE>= { return EQUAL; } 213 <LSTATE>= { return EQUAL; } 214 <CSTATE>= { return EQUAL; } 215 216 <TSTATE>"[" { 217 BEGIN LSTATE; 218 state = LSTATE; 219 return OPEN_SQ_BRACKET; 220 } 221 222 <LSTATE>"]" { 223 BEGIN TSTATE; 224 state = TSTATE; 225 return CLOSE_SQ_BRACKET; 226 } 227 228 <TSTATE>"(" { 229 BEGIN CSTATE; 230 return OPEN_PAREN; 231 } 232 233 <LSTATE>"(" { 234 BEGIN CSTATE; 235 return OPEN_PAREN; 236 } 237 238 <CSTATE>")" { 239 BEGIN state; 240 return CLOSE_PAREN; 241 } 242 243 <LSTATE>"," { return COMMA; } 244 <CSTATE>"," { return COMMA; } 245 246 <TSTATE>[^ \t\n\";=\[\]\(\)]+ { 247 yylval.strval = safe_strdup(yytext); 248 return TOKEN; 249 } 250 251 <LSTATE>[^ \t\n\",;=\[\]\(\)]+ { 252 yylval.strval = safe_strdup(yytext); 253 return TOKEN; 254 } 255 256 <CSTATE>[^ \t\n\",;=\(\)]+ { 257 yylval.strval = safe_strdup(yytext); 258 return TOKEN; 259 } 260 261 <TSTATE>\"[^\"\n]*[\"\n] { 262 yylval.strval = safe_strdup(yytext + 1); 263 if (yylval.strval[yyleng - 2] == '"') 264 yylval.strval[yyleng - 2] = 0; 265 return TOKEN; 266 } 267 268 <LSTATE>\"[^\"\n]*[\"\n] { 269 yylval.strval = safe_strdup(yytext + 1); 270 if (yylval.strval[yyleng - 2] == '"') 271 yylval.strval[yyleng - 2] = 0; 272 return TOKEN; 273 } 274 275 ";" { 276 BEGIN INITIAL; 277 return (yytext[0]); 278 } 279 280 \n { 281 lex_lineno++; 282 BEGIN INITIAL; 283 return (yytext[0]); 284 } 285 286 [ \t] ; /* Ignore whitespace */ 287 288 . { 289 return (yytext[0]); 290 } 291 292 %% 293 294 char * 295 safe_strdup(char *s) 296 { 297 char *result; 298 299 if ((result = strdup(s)) == NULL) { 300 yyerror("Out of memory"); 301 exit(Z_ERR); 302 } 303 return (result); 304 } 305 306 void 307 yyerror(char *s) 308 { 309 /* feof(yyin) is not an error; anything else is, so we set saw_error */ 310 if (yytext[0] == '\0') { 311 if (!feof(yyin)) { 312 saw_error = TRUE; 313 (void) fprintf(stderr, gettext("%s, token expected\n"), 314 s); 315 } 316 return; 317 } 318 319 saw_error = TRUE; 320 if (cmd_file_mode) 321 (void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s, 322 lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext); 323 else 324 (void) fprintf(stderr, gettext("%s at '%s'\n"), s, 325 (yytext[0] == '\n') ? "\\n" : yytext); 326 usage(FALSE, HELP_SUBCMDS); 327 } 328