%{ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma ident "%Z%%M% %I% %E% SMI" #include #include #include "zonecfg.h" #include "zonecfg_grammar.tab.h" int lex_lineno = 1; /* line number for error reporting */ static int state = INITIAL; extern bool cmd_file_mode; extern bool saw_error; extern void yyerror(char *s); char *safe_strdup(char *s); %} %a 4000 %{ /* * The three states below are for tokens, lists and complex property values. * Note that simple property values are a subset of tokens. */ %} %s TSTATE %s LSTATE %s CSTATE %% "#"[^\n]* { } add { BEGIN TSTATE; state = TSTATE; return ADD; } cancel { BEGIN TSTATE; state = TSTATE; return CANCEL; } commit { BEGIN TSTATE; state = TSTATE; return COMMIT; } create { BEGIN TSTATE; state = TSTATE; return CREATE; } delete { BEGIN TSTATE; state = TSTATE; return DELETE; } end { BEGIN TSTATE; state = TSTATE; return END; } exit { BEGIN TSTATE; state = TSTATE; return EXIT; } export { BEGIN TSTATE; state = TSTATE; return EXPORT; } "?"|help { BEGIN TSTATE; state = TSTATE; return HELP; } info { BEGIN TSTATE; state = TSTATE; return INFO; } remove { BEGIN TSTATE; state = TSTATE; return REMOVE; } revert { BEGIN TSTATE; state = TSTATE; return REVERT; } select { BEGIN TSTATE; state = TSTATE; return SELECT; } set { BEGIN TSTATE; state = TSTATE; return SET; } verify { BEGIN TSTATE; state = TSTATE; return VERIFY; } net { return NET; } fs { return FS; } inherit-pkg-dir { return IPD; } device { return DEVICE; } rctl { return RCTL; } attr { return ATTR; } zonename { return ZONENAME; } zonename { return ZONENAME; } dataset { return DATASET; } zonepath { return ZONEPATH; } zonepath { return ZONEPATH; } autoboot { return AUTOBOOT; } autoboot { return AUTOBOOT; } pool { return POOL; } pool { return POOL; } limitpriv { return LIMITPRIV; } limitpriv { return LIMITPRIV; } bootargs { return BOOTARGS; } bootargs { return BOOTARGS; } type { return TYPE; } type { return TYPE; } value { return VALUE; } value { return VALUE; } options { return OPTIONS; } options { return OPTIONS; } address { return ADDRESS; } address { return ADDRESS; } physical { return PHYSICAL; } physical { return PHYSICAL; } dir { return DIR; } dir { return DIR; } special { return SPECIAL; } special { return SPECIAL; } raw { return RAW; } raw { return RAW; } name { return NAME; } name { return NAME; } match { return MATCH; } match { return MATCH; } priv { return PRIV; } priv { return PRIV; } limit { return LIMIT; } limit { return LIMIT; } action { return ACTION; } action { return ACTION; } = { return EQUAL; } = { return EQUAL; } = { return EQUAL; } "[" { BEGIN LSTATE; state = LSTATE; return OPEN_SQ_BRACKET; } "]" { BEGIN TSTATE; state = TSTATE; return CLOSE_SQ_BRACKET; } "(" { BEGIN CSTATE; return OPEN_PAREN; } "(" { BEGIN CSTATE; return OPEN_PAREN; } ")" { BEGIN state; return CLOSE_PAREN; } "," { return COMMA; } "," { return COMMA; } [^ \t\n\";=\[\]\(\)]+ { yylval.strval = safe_strdup(yytext); return TOKEN; } [^ \t\n\",;=\[\]\(\)]+ { yylval.strval = safe_strdup(yytext); return TOKEN; } [^ \t\n\",;=\(\)]+ { yylval.strval = safe_strdup(yytext); return TOKEN; } \"[^\"\n]*[\"\n] { yylval.strval = safe_strdup(yytext + 1); if (yylval.strval[yyleng - 2] == '"') yylval.strval[yyleng - 2] = 0; return TOKEN; } \"[^\"\n]*[\"\n] { yylval.strval = safe_strdup(yytext + 1); if (yylval.strval[yyleng - 2] == '"') yylval.strval[yyleng - 2] = 0; return TOKEN; } ";" { BEGIN INITIAL; return (yytext[0]); } \n { lex_lineno++; BEGIN INITIAL; return (yytext[0]); } [ \t] ; /* Ignore whitespace */ . { return (yytext[0]); } %% char * safe_strdup(char *s) { char *result; if ((result = strdup(s)) == NULL) { yyerror("Out of memory"); exit(Z_ERR); } return (result); } void yyerror(char *s) { /* feof(yyin) is not an error; anything else is, so we set saw_error */ if (yytext[0] == '\0') { if (!feof(yyin)) { saw_error = TRUE; (void) fprintf(stderr, gettext("%s, token expected\n"), s); } return; } saw_error = TRUE; if (cmd_file_mode) (void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s, lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext); else (void) fprintf(stderr, gettext("%s at '%s'\n"), s, (yytext[0] == '\n') ? "\\n" : yytext); usage(FALSE, HELP_SUBCMDS); }