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 63eae19d9Swesolows * Common Development and Distribution License (the "License"). 73eae19d9Swesolows * 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 213eae19d9Swesolows */ 223eae19d9Swesolows 233eae19d9Swesolows /* 24*f6e214c7SGavin Maltby * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_BLOCK_DECL_UNUSED) 297c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_EQUALITY_NOT_ASSIGNMENT) 307c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_FUNC_RET_MAYBE_IGNORED2) 317c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_STMT_NOT_REACHED) 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <libintl.h> 347c478bd9Sstevel@tonic-gate #include <string.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include "svccfg.h" 377c478bd9Sstevel@tonic-gate #include "svccfg_grammar.h" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * We need to undefine lex's input, unput, and output macros so that references 417c478bd9Sstevel@tonic-gate * to these call the functions we provide at the end of this source file, 427c478bd9Sstevel@tonic-gate * instead of the default versions based on libc's stdio. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #ifdef input 457c478bd9Sstevel@tonic-gate #undef input 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef unput 497c478bd9Sstevel@tonic-gate #undef unput 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #ifdef output 537c478bd9Sstevel@tonic-gate #undef output 547c478bd9Sstevel@tonic-gate #endif 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate static int input(void); 577c478bd9Sstevel@tonic-gate static void unput(int); 587c478bd9Sstevel@tonic-gate static void output(int); 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate int parens = 0; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate extern int yyerror(const char *); 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate %} 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Since command tokens are only valid at the beginning of the command (or 687c478bd9Sstevel@tonic-gate * after help), we'll only return them in the INITIAL state, and report them 697c478bd9Sstevel@tonic-gate * as SCV_WORDs afterwards. 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate %Start WORD 727c478bd9Sstevel@tonic-gate 73*f6e214c7SGavin Maltby /* 74*f6e214c7SGavin Maltby * The default value of lex for transitions is 2000 and it seems we reached it. 75*f6e214c7SGavin Maltby * So we are bumping it up! 76*f6e214c7SGavin Maltby */ 77*f6e214c7SGavin Maltby %a 3000 78*f6e214c7SGavin Maltby 797c478bd9Sstevel@tonic-gate %% 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate #.*$ ; /* comments */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate <INITIAL>validate { BEGIN WORD; return (SCC_VALIDATE); } 847c478bd9Sstevel@tonic-gate <INITIAL>import { BEGIN WORD; return (SCC_IMPORT); } 859444c26fSTom Whitten <INITIAL>cleanup { BEGIN WORD; return (SCC_CLEANUP); } 867c478bd9Sstevel@tonic-gate <INITIAL>export { BEGIN WORD; return (SCC_EXPORT); } 877c478bd9Sstevel@tonic-gate <INITIAL>archive { BEGIN WORD; return (SCC_ARCHIVE); } 883eae19d9Swesolows <INITIAL>restore { BEGIN WORD; return (SCC_RESTORE); } 897c478bd9Sstevel@tonic-gate <INITIAL>apply { BEGIN WORD; return (SCC_APPLY); } 907c478bd9Sstevel@tonic-gate <INITIAL>extract { BEGIN WORD; return (SCC_EXTRACT); } 917c478bd9Sstevel@tonic-gate <INITIAL>repository { BEGIN WORD; return (SCC_REPOSITORY); } 927c478bd9Sstevel@tonic-gate <INITIAL>inventory { BEGIN WORD; return (SCC_INVENTORY); } 937c478bd9Sstevel@tonic-gate <INITIAL>set { BEGIN WORD; return (SCC_SET); } 947c478bd9Sstevel@tonic-gate <INITIAL>end { BEGIN WORD; return (SCC_END); } 957c478bd9Sstevel@tonic-gate <INITIAL>exit { BEGIN WORD; return (SCC_END); } 967c478bd9Sstevel@tonic-gate <INITIAL>quit { BEGIN WORD; return (SCC_END); } 977c478bd9Sstevel@tonic-gate <INITIAL>help { return (SCC_HELP); } 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate <INITIAL>list { BEGIN WORD; return (SCC_LIST); } 1007c478bd9Sstevel@tonic-gate <INITIAL>add { BEGIN WORD; return (SCC_ADD); } 1017c478bd9Sstevel@tonic-gate <INITIAL>delete { BEGIN WORD; return (SCC_DELETE); } 1027c478bd9Sstevel@tonic-gate <INITIAL>select { BEGIN WORD; return (SCC_SELECT); } 1037c478bd9Sstevel@tonic-gate <INITIAL>unselect { BEGIN WORD; return (SCC_UNSELECT); } 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate <INITIAL>listpg { BEGIN WORD; return (SCC_LISTPG); } 1067c478bd9Sstevel@tonic-gate <INITIAL>addpg { BEGIN WORD; return (SCC_ADDPG); } 1077c478bd9Sstevel@tonic-gate <INITIAL>delpg { BEGIN WORD; return (SCC_DELPG); } 10870cbfe41SPhilippe Jung <INITIAL>delhash { BEGIN WORD; return (SCC_DELHASH); } 1097c478bd9Sstevel@tonic-gate <INITIAL>listprop { BEGIN WORD; return (SCC_LISTPROP); } 1107c478bd9Sstevel@tonic-gate <INITIAL>setprop { BEGIN WORD; return (SCC_SETPROP); } 1117c478bd9Sstevel@tonic-gate <INITIAL>delprop { BEGIN WORD; return (SCC_DELPROP); } 1127c478bd9Sstevel@tonic-gate <INITIAL>editprop { BEGIN WORD; return (SCC_EDITPROP); } 1131f6eb021SLiane Praza <INITIAL>describe { BEGIN WORD; return (SCC_DESCRIBE); } 1147c478bd9Sstevel@tonic-gate <INITIAL>addpropvalue { BEGIN WORD; return (SCC_ADDPROPVALUE); } 1157c478bd9Sstevel@tonic-gate <INITIAL>delpropvalue { BEGIN WORD; return (SCC_DELPROPVALUE); } 1167c478bd9Sstevel@tonic-gate <INITIAL>setenv { BEGIN WORD; return (SCC_SETENV); } 1177c478bd9Sstevel@tonic-gate <INITIAL>unsetenv { BEGIN WORD; return (SCC_UNSETENV); } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate <INITIAL>listsnap { BEGIN WORD; return (SCC_LISTSNAP); } 1207c478bd9Sstevel@tonic-gate <INITIAL>selectsnap { BEGIN WORD; return (SCC_SELECTSNAP); } 1217c478bd9Sstevel@tonic-gate <INITIAL>revert { BEGIN WORD; return (SCC_REVERT); } 122347a77f2Samaguire <INITIAL>refresh { BEGIN WORD; return (SCC_REFRESH); } 1237c478bd9Sstevel@tonic-gate 124*f6e214c7SGavin Maltby <INITIAL>delnotify { BEGIN WORD; return (SCC_DELNOTIFY); } 125*f6e214c7SGavin Maltby <INITIAL>listnotify { BEGIN WORD; return (SCC_LISTNOTIFY); } 126*f6e214c7SGavin Maltby <INITIAL>setnotify { BEGIN WORD; return (SCC_SETNOTIFY); } 127*f6e214c7SGavin Maltby 1287c478bd9Sstevel@tonic-gate [^ \t\n">=()]+ { 1297c478bd9Sstevel@tonic-gate if ((yylval.str = strdup(yytext)) == NULL) { 1307c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 1317c478bd9Sstevel@tonic-gate exit(UU_EXIT_FATAL); 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate return SCV_WORD; 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate \"([^"\\]|\\.)*\" { 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * double-quoted strings start at a 1407c478bd9Sstevel@tonic-gate * double-quote, include characters other than 1417c478bd9Sstevel@tonic-gate * double-quote and backslash, and 1427c478bd9Sstevel@tonic-gate * backslashed-characters, and end with a 1437c478bd9Sstevel@tonic-gate * double-quote. 1447c478bd9Sstevel@tonic-gate */ 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate char *str, *cp; 1477c478bd9Sstevel@tonic-gate int shift; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate if ((str = strdup(yytext)) == NULL) { 1507c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 1517c478bd9Sstevel@tonic-gate exit(UU_EXIT_FATAL); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* Strip out the backslashes. */ 1557c478bd9Sstevel@tonic-gate for (cp = str, shift = 0; *cp != '\0'; ++cp) { 1567c478bd9Sstevel@tonic-gate if (*cp == '\\') { 1577c478bd9Sstevel@tonic-gate ++cp; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * This can't be null because 1617c478bd9Sstevel@tonic-gate * the string always ends with 1627c478bd9Sstevel@tonic-gate * a double-quote. 1637c478bd9Sstevel@tonic-gate */ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate ++shift; 1667c478bd9Sstevel@tonic-gate *(cp - shift) = *cp; 1677c478bd9Sstevel@tonic-gate } else if (shift != 0) 1687c478bd9Sstevel@tonic-gate *(cp - shift) = *cp; 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* Nullify everything after trailing quote */ 1727c478bd9Sstevel@tonic-gate *(cp - shift) = '\0'; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate yylval.str = str; 1757c478bd9Sstevel@tonic-gate return SCV_STRING; 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate \n { 1797c478bd9Sstevel@tonic-gate est->sc_cmd_lineno++; 1807c478bd9Sstevel@tonic-gate BEGIN INITIAL; 1817c478bd9Sstevel@tonic-gate return (SCS_NEWLINE); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate [ \t]+ ; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate ">" { return SCS_REDIRECT; } 1877c478bd9Sstevel@tonic-gate "=" { return SCS_EQUALS; } 1887c478bd9Sstevel@tonic-gate "(" { ++parens; return SCS_LPAREN; } 1897c478bd9Sstevel@tonic-gate ")" { --parens; return SCS_RPAREN; } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate . { 1927c478bd9Sstevel@tonic-gate uu_die(gettext("unrecognized character %s\n"), 1937c478bd9Sstevel@tonic-gate yytext); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate %% 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate int 1997c478bd9Sstevel@tonic-gate yyerror(const char *s) 2007c478bd9Sstevel@tonic-gate { 2017c478bd9Sstevel@tonic-gate return (0); 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate static int 2057c478bd9Sstevel@tonic-gate input(void) 2067c478bd9Sstevel@tonic-gate { 2077c478bd9Sstevel@tonic-gate static int saw_eof = 0; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate int c = engine_cmd_getc(est); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * To ensure input is terminated, slip in a newline on EOF. 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate if (c == EOF) { 2157c478bd9Sstevel@tonic-gate if (saw_eof) 2167c478bd9Sstevel@tonic-gate return (0); 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate saw_eof = 1; 2197c478bd9Sstevel@tonic-gate return ('\n'); 2207c478bd9Sstevel@tonic-gate } else 2217c478bd9Sstevel@tonic-gate saw_eof = 0; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate if (c == '\n') 2247c478bd9Sstevel@tonic-gate yylineno++; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate return (c); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate static void 2307c478bd9Sstevel@tonic-gate unput(int c) 2317c478bd9Sstevel@tonic-gate { 2327c478bd9Sstevel@tonic-gate if (c == '\n') 2337c478bd9Sstevel@tonic-gate yylineno--; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate (void) engine_cmd_ungetc(est, c == 0 ? EOF : c); 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate static void 2397c478bd9Sstevel@tonic-gate output(int c) 2407c478bd9Sstevel@tonic-gate { 2417c478bd9Sstevel@tonic-gate char ch = c; 2427c478bd9Sstevel@tonic-gate engine_cmd_nputs(est, &ch, sizeof (ch)); 2437c478bd9Sstevel@tonic-gate } 244