17c478bd9Sstevel@tonic-gate %{ 27c478bd9Sstevel@tonic-gate /* 37c478bd9Sstevel@tonic-gate * CDDL HEADER START 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 6*3eae19d9Swesolows * Common Development and Distribution License (the "License"). 7*3eae19d9Swesolows * You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*3eae19d9Swesolows */ 22*3eae19d9Swesolows 23*3eae19d9Swesolows /* 24*3eae19d9Swesolows * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_BLOCK_DECL_UNUSED) 317c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_EQUALITY_NOT_ASSIGNMENT) 327c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_FUNC_RET_MAYBE_IGNORED2) 337c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_STMT_NOT_REACHED) 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <libintl.h> 367c478bd9Sstevel@tonic-gate #include <string.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include "svccfg.h" 397c478bd9Sstevel@tonic-gate #include "svccfg_grammar.h" 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * We need to undefine lex's input, unput, and output macros so that references 437c478bd9Sstevel@tonic-gate * to these call the functions we provide at the end of this source file, 447c478bd9Sstevel@tonic-gate * instead of the default versions based on libc's stdio. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate #ifdef input 477c478bd9Sstevel@tonic-gate #undef input 487c478bd9Sstevel@tonic-gate #endif 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #ifdef unput 517c478bd9Sstevel@tonic-gate #undef unput 527c478bd9Sstevel@tonic-gate #endif 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #ifdef output 557c478bd9Sstevel@tonic-gate #undef output 567c478bd9Sstevel@tonic-gate #endif 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate static int input(void); 597c478bd9Sstevel@tonic-gate static void unput(int); 607c478bd9Sstevel@tonic-gate static void output(int); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate int parens = 0; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate extern int yyerror(const char *); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate %} 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * Since command tokens are only valid at the beginning of the command (or 707c478bd9Sstevel@tonic-gate * after help), we'll only return them in the INITIAL state, and report them 717c478bd9Sstevel@tonic-gate * as SCV_WORDs afterwards. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate %Start WORD 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate %% 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #.*$ ; /* comments */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate <INITIAL>validate { BEGIN WORD; return (SCC_VALIDATE); } 807c478bd9Sstevel@tonic-gate <INITIAL>import { BEGIN WORD; return (SCC_IMPORT); } 817c478bd9Sstevel@tonic-gate <INITIAL>export { BEGIN WORD; return (SCC_EXPORT); } 827c478bd9Sstevel@tonic-gate <INITIAL>archive { BEGIN WORD; return (SCC_ARCHIVE); } 83*3eae19d9Swesolows <INITIAL>restore { BEGIN WORD; return (SCC_RESTORE); } 847c478bd9Sstevel@tonic-gate <INITIAL>apply { BEGIN WORD; return (SCC_APPLY); } 857c478bd9Sstevel@tonic-gate <INITIAL>extract { BEGIN WORD; return (SCC_EXTRACT); } 867c478bd9Sstevel@tonic-gate <INITIAL>repository { BEGIN WORD; return (SCC_REPOSITORY); } 877c478bd9Sstevel@tonic-gate <INITIAL>inventory { BEGIN WORD; return (SCC_INVENTORY); } 887c478bd9Sstevel@tonic-gate <INITIAL>set { BEGIN WORD; return (SCC_SET); } 897c478bd9Sstevel@tonic-gate <INITIAL>end { BEGIN WORD; return (SCC_END); } 907c478bd9Sstevel@tonic-gate <INITIAL>exit { BEGIN WORD; return (SCC_END); } 917c478bd9Sstevel@tonic-gate <INITIAL>quit { BEGIN WORD; return (SCC_END); } 927c478bd9Sstevel@tonic-gate <INITIAL>help { return (SCC_HELP); } 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate <INITIAL>list { BEGIN WORD; return (SCC_LIST); } 957c478bd9Sstevel@tonic-gate <INITIAL>add { BEGIN WORD; return (SCC_ADD); } 967c478bd9Sstevel@tonic-gate <INITIAL>delete { BEGIN WORD; return (SCC_DELETE); } 977c478bd9Sstevel@tonic-gate <INITIAL>select { BEGIN WORD; return (SCC_SELECT); } 987c478bd9Sstevel@tonic-gate <INITIAL>unselect { BEGIN WORD; return (SCC_UNSELECT); } 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate <INITIAL>listpg { BEGIN WORD; return (SCC_LISTPG); } 1017c478bd9Sstevel@tonic-gate <INITIAL>addpg { BEGIN WORD; return (SCC_ADDPG); } 1027c478bd9Sstevel@tonic-gate <INITIAL>delpg { BEGIN WORD; return (SCC_DELPG); } 1037c478bd9Sstevel@tonic-gate <INITIAL>listprop { BEGIN WORD; return (SCC_LISTPROP); } 1047c478bd9Sstevel@tonic-gate <INITIAL>setprop { BEGIN WORD; return (SCC_SETPROP); } 1057c478bd9Sstevel@tonic-gate <INITIAL>delprop { BEGIN WORD; return (SCC_DELPROP); } 1067c478bd9Sstevel@tonic-gate <INITIAL>editprop { BEGIN WORD; return (SCC_EDITPROP); } 1077c478bd9Sstevel@tonic-gate <INITIAL>addpropvalue { BEGIN WORD; return (SCC_ADDPROPVALUE); } 1087c478bd9Sstevel@tonic-gate <INITIAL>delpropvalue { BEGIN WORD; return (SCC_DELPROPVALUE); } 1097c478bd9Sstevel@tonic-gate <INITIAL>setenv { BEGIN WORD; return (SCC_SETENV); } 1107c478bd9Sstevel@tonic-gate <INITIAL>unsetenv { BEGIN WORD; return (SCC_UNSETENV); } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate <INITIAL>listsnap { BEGIN WORD; return (SCC_LISTSNAP); } 1137c478bd9Sstevel@tonic-gate <INITIAL>selectsnap { BEGIN WORD; return (SCC_SELECTSNAP); } 1147c478bd9Sstevel@tonic-gate <INITIAL>revert { BEGIN WORD; return (SCC_REVERT); } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate [^ \t\n">=()]+ { 1177c478bd9Sstevel@tonic-gate if ((yylval.str = strdup(yytext)) == NULL) { 1187c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 1197c478bd9Sstevel@tonic-gate exit(UU_EXIT_FATAL); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate return SCV_WORD; 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate \"([^"\\]|\\.)*\" { 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * double-quoted strings start at a 1287c478bd9Sstevel@tonic-gate * double-quote, include characters other than 1297c478bd9Sstevel@tonic-gate * double-quote and backslash, and 1307c478bd9Sstevel@tonic-gate * backslashed-characters, and end with a 1317c478bd9Sstevel@tonic-gate * double-quote. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate char *str, *cp; 1357c478bd9Sstevel@tonic-gate int shift; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate if ((str = strdup(yytext)) == NULL) { 1387c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 1397c478bd9Sstevel@tonic-gate exit(UU_EXIT_FATAL); 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* Strip out the backslashes. */ 1437c478bd9Sstevel@tonic-gate for (cp = str, shift = 0; *cp != '\0'; ++cp) { 1447c478bd9Sstevel@tonic-gate if (*cp == '\\') { 1457c478bd9Sstevel@tonic-gate ++cp; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * This can't be null because 1497c478bd9Sstevel@tonic-gate * the string always ends with 1507c478bd9Sstevel@tonic-gate * a double-quote. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate ++shift; 1547c478bd9Sstevel@tonic-gate *(cp - shift) = *cp; 1557c478bd9Sstevel@tonic-gate } else if (shift != 0) 1567c478bd9Sstevel@tonic-gate *(cp - shift) = *cp; 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* Nullify everything after trailing quote */ 1607c478bd9Sstevel@tonic-gate *(cp - shift) = '\0'; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate yylval.str = str; 1637c478bd9Sstevel@tonic-gate return SCV_STRING; 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate \n { 1677c478bd9Sstevel@tonic-gate est->sc_cmd_lineno++; 1687c478bd9Sstevel@tonic-gate BEGIN INITIAL; 1697c478bd9Sstevel@tonic-gate return (SCS_NEWLINE); 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate [ \t]+ ; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate ">" { return SCS_REDIRECT; } 1757c478bd9Sstevel@tonic-gate "=" { return SCS_EQUALS; } 1767c478bd9Sstevel@tonic-gate "(" { ++parens; return SCS_LPAREN; } 1777c478bd9Sstevel@tonic-gate ")" { --parens; return SCS_RPAREN; } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate . { 1807c478bd9Sstevel@tonic-gate uu_die(gettext("unrecognized character %s\n"), 1817c478bd9Sstevel@tonic-gate yytext); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate %% 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate int 1877c478bd9Sstevel@tonic-gate yyerror(const char *s) 1887c478bd9Sstevel@tonic-gate { 1897c478bd9Sstevel@tonic-gate return (0); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate static int 1937c478bd9Sstevel@tonic-gate input(void) 1947c478bd9Sstevel@tonic-gate { 1957c478bd9Sstevel@tonic-gate static int saw_eof = 0; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate int c = engine_cmd_getc(est); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * To ensure input is terminated, slip in a newline on EOF. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate if (c == EOF) { 2037c478bd9Sstevel@tonic-gate if (saw_eof) 2047c478bd9Sstevel@tonic-gate return (0); 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate saw_eof = 1; 2077c478bd9Sstevel@tonic-gate return ('\n'); 2087c478bd9Sstevel@tonic-gate } else 2097c478bd9Sstevel@tonic-gate saw_eof = 0; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate if (c == '\n') 2127c478bd9Sstevel@tonic-gate yylineno++; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate return (c); 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate static void 2187c478bd9Sstevel@tonic-gate unput(int c) 2197c478bd9Sstevel@tonic-gate { 2207c478bd9Sstevel@tonic-gate if (c == '\n') 2217c478bd9Sstevel@tonic-gate yylineno--; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate (void) engine_cmd_ungetc(est, c == 0 ? EOF : c); 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate static void 2277c478bd9Sstevel@tonic-gate output(int c) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate char ch = c; 2307c478bd9Sstevel@tonic-gate engine_cmd_nputs(est, &ch, sizeof (ch)); 2317c478bd9Sstevel@tonic-gate } 232