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 2004 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>zonepath { return ZONEPATH; } 160 <CSTATE>zonepath { return ZONEPATH; } 161 162 <TSTATE>autoboot { return AUTOBOOT; } 163 <CSTATE>autoboot { return AUTOBOOT; } 164 165 <TSTATE>pool { return POOL; } 166 <CSTATE>pool { return POOL; } 167 168 <TSTATE>type { return TYPE; } 169 <CSTATE>type { return TYPE; } 170 171 <TSTATE>value { return VALUE; } 172 <CSTATE>value { return VALUE; } 173 174 <TSTATE>options { return OPTIONS; } 175 <CSTATE>options { return OPTIONS; } 176 177 <TSTATE>address { return ADDRESS; } 178 <CSTATE>address { return ADDRESS; } 179 180 <TSTATE>physical { return PHYSICAL; } 181 <CSTATE>physical { return PHYSICAL; } 182 183 <TSTATE>dir { return DIR; } 184 <CSTATE>dir { return DIR; } 185 186 <TSTATE>special { return SPECIAL; } 187 <CSTATE>special { return SPECIAL; } 188 189 <TSTATE>raw { return RAW; } 190 <CSTATE>raw { return RAW; } 191 192 <TSTATE>name { return NAME; } 193 <CSTATE>name { return NAME; } 194 195 <TSTATE>match { return MATCH; } 196 <CSTATE>match { return MATCH; } 197 198 <TSTATE>priv { return PRIV; } 199 <CSTATE>priv { return PRIV; } 200 201 <TSTATE>limit { return LIMIT; } 202 <CSTATE>limit { return LIMIT; } 203 204 <TSTATE>action { return ACTION; } 205 <CSTATE>action { return ACTION; } 206 207 <TSTATE>= { return EQUAL; } 208 <LSTATE>= { return EQUAL; } 209 <CSTATE>= { return EQUAL; } 210 211 <TSTATE>"[" { 212 BEGIN LSTATE; 213 state = LSTATE; 214 return OPEN_SQ_BRACKET; 215 } 216 217 <LSTATE>"]" { 218 BEGIN TSTATE; 219 state = TSTATE; 220 return CLOSE_SQ_BRACKET; 221 } 222 223 <TSTATE>"(" { 224 BEGIN CSTATE; 225 return OPEN_PAREN; 226 } 227 228 <LSTATE>"(" { 229 BEGIN CSTATE; 230 return OPEN_PAREN; 231 } 232 233 <CSTATE>")" { 234 BEGIN state; 235 return CLOSE_PAREN; 236 } 237 238 <LSTATE>"," { return COMMA; } 239 <CSTATE>"," { return COMMA; } 240 241 <TSTATE>[^ \t\n\";=\[\]\(\)]+ { 242 yylval.strval = safe_strdup(yytext); 243 return TOKEN; 244 } 245 246 <LSTATE>[^ \t\n\",;=\[\]\(\)]+ { 247 yylval.strval = safe_strdup(yytext); 248 return TOKEN; 249 } 250 251 <CSTATE>[^ \t\n\",;=\(\)]+ { 252 yylval.strval = safe_strdup(yytext); 253 return TOKEN; 254 } 255 256 <TSTATE>\"[^\"\n]*[\"\n] { 257 yylval.strval = safe_strdup(yytext + 1); 258 if (yylval.strval[yyleng - 2] == '"') 259 yylval.strval[yyleng - 2] = 0; 260 return TOKEN; 261 } 262 263 <LSTATE>\"[^\"\n]*[\"\n] { 264 yylval.strval = safe_strdup(yytext + 1); 265 if (yylval.strval[yyleng - 2] == '"') 266 yylval.strval[yyleng - 2] = 0; 267 return TOKEN; 268 } 269 270 ";" { 271 BEGIN INITIAL; 272 return (yytext[0]); 273 } 274 275 \n { 276 lex_lineno++; 277 BEGIN INITIAL; 278 return (yytext[0]); 279 } 280 281 [ \t] ; /* Ignore whitespace */ 282 283 . { 284 return (yytext[0]); 285 } 286 287 %% 288 289 char * 290 safe_strdup(char *s) 291 { 292 char *result; 293 294 if ((result = strdup(s)) == NULL) { 295 yyerror("Out of memory"); 296 exit(Z_ERR); 297 } 298 return (result); 299 } 300 301 void 302 yyerror(char *s) 303 { 304 /* feof(yyin) is not an error; anything else is, so we set saw_error */ 305 if (yytext[0] == '\0') { 306 if (!feof(yyin)) { 307 saw_error = TRUE; 308 (void) fprintf(stderr, gettext("%s, token expected\n"), 309 s); 310 } 311 return; 312 } 313 314 saw_error = TRUE; 315 if (cmd_file_mode) 316 (void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s, 317 lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext); 318 else 319 (void) fprintf(stderr, gettext("%s at '%s'\n"), s, 320 (yytext[0] == '\n') ? "\\n" : yytext); 321 usage(FALSE, HELP_SUBCMDS); 322 } 323