xref: /onnv-gate/usr/src/cmd/svc/svccfg/svccfg.l (revision 12967:ab9ae749152f)
10Sstevel@tonic-gate %{
20Sstevel@tonic-gate /*
30Sstevel@tonic-gate  * CDDL HEADER START
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
65040Swesolows  * Common Development and Distribution License (the "License").
75040Swesolows  * You may not use this file except in compliance with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
215040Swesolows  */
225040Swesolows 
235040Swesolows /*
24*12967Sgavin.maltby@oracle.com  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #pragma error_messages(off, E_BLOCK_DECL_UNUSED)
290Sstevel@tonic-gate #pragma error_messages(off, E_EQUALITY_NOT_ASSIGNMENT)
300Sstevel@tonic-gate #pragma error_messages(off, E_FUNC_RET_MAYBE_IGNORED2)
310Sstevel@tonic-gate #pragma error_messages(off, E_STMT_NOT_REACHED)
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <libintl.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include "svccfg.h"
370Sstevel@tonic-gate #include "svccfg_grammar.h"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * We need to undefine lex's input, unput, and output macros so that references
410Sstevel@tonic-gate  * to these call the functions we provide at the end of this source file,
420Sstevel@tonic-gate  * instead of the default versions based on libc's stdio.
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate #ifdef input
450Sstevel@tonic-gate #undef input
460Sstevel@tonic-gate #endif
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #ifdef unput
490Sstevel@tonic-gate #undef unput
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #ifdef output
530Sstevel@tonic-gate #undef output
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static int input(void);
570Sstevel@tonic-gate static void unput(int);
580Sstevel@tonic-gate static void output(int);
590Sstevel@tonic-gate 
600Sstevel@tonic-gate int parens = 0;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate extern int yyerror(const char *);
630Sstevel@tonic-gate 
640Sstevel@tonic-gate %}
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * Since command tokens are only valid at the beginning of the command (or
680Sstevel@tonic-gate  * after help), we'll only return them in the INITIAL state, and report them
690Sstevel@tonic-gate  * as SCV_WORDs afterwards.
700Sstevel@tonic-gate  */
710Sstevel@tonic-gate %Start	WORD
720Sstevel@tonic-gate 
73*12967Sgavin.maltby@oracle.com /*
74*12967Sgavin.maltby@oracle.com  * The default value of lex for transitions is 2000 and it seems we reached it.
75*12967Sgavin.maltby@oracle.com  * So we are bumping it up!
76*12967Sgavin.maltby@oracle.com  */
77*12967Sgavin.maltby@oracle.com %a 3000
78*12967Sgavin.maltby@oracle.com 
790Sstevel@tonic-gate %%
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #.*$			;	/* comments */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate <INITIAL>validate	{ BEGIN WORD; return (SCC_VALIDATE); }
840Sstevel@tonic-gate <INITIAL>import		{ BEGIN WORD; return (SCC_IMPORT); }
8511996SThomas.Whitten@Sun.COM <INITIAL>cleanup	{ BEGIN WORD; return (SCC_CLEANUP); }
860Sstevel@tonic-gate <INITIAL>export		{ BEGIN WORD; return (SCC_EXPORT); }
870Sstevel@tonic-gate <INITIAL>archive	{ BEGIN WORD; return (SCC_ARCHIVE); }
885040Swesolows <INITIAL>restore	{ BEGIN WORD; return (SCC_RESTORE); }
890Sstevel@tonic-gate <INITIAL>apply		{ BEGIN WORD; return (SCC_APPLY); }
900Sstevel@tonic-gate <INITIAL>extract	{ BEGIN WORD; return (SCC_EXTRACT); }
910Sstevel@tonic-gate <INITIAL>repository	{ BEGIN WORD; return (SCC_REPOSITORY); }
920Sstevel@tonic-gate <INITIAL>inventory	{ BEGIN WORD; return (SCC_INVENTORY); }
930Sstevel@tonic-gate <INITIAL>set		{ BEGIN WORD; return (SCC_SET); }
940Sstevel@tonic-gate <INITIAL>end		{ BEGIN WORD; return (SCC_END); }
950Sstevel@tonic-gate <INITIAL>exit		{ BEGIN WORD; return (SCC_END); }
960Sstevel@tonic-gate <INITIAL>quit		{ BEGIN WORD; return (SCC_END); }
970Sstevel@tonic-gate <INITIAL>help		{ return (SCC_HELP); }
980Sstevel@tonic-gate 
990Sstevel@tonic-gate <INITIAL>list		{ BEGIN WORD; return (SCC_LIST); }
1000Sstevel@tonic-gate <INITIAL>add		{ BEGIN WORD; return (SCC_ADD); }
1010Sstevel@tonic-gate <INITIAL>delete		{ BEGIN WORD; return (SCC_DELETE); }
1020Sstevel@tonic-gate <INITIAL>select		{ BEGIN WORD; return (SCC_SELECT); }
1030Sstevel@tonic-gate <INITIAL>unselect	{ BEGIN WORD; return (SCC_UNSELECT); }
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate <INITIAL>listpg		{ BEGIN WORD; return (SCC_LISTPG); }
1060Sstevel@tonic-gate <INITIAL>addpg		{ BEGIN WORD; return (SCC_ADDPG); }
1070Sstevel@tonic-gate <INITIAL>delpg		{ BEGIN WORD; return (SCC_DELPG); }
1087475SPhilippe.Jung@Sun.COM <INITIAL>delhash	{ BEGIN WORD; return (SCC_DELHASH); }
1090Sstevel@tonic-gate <INITIAL>listprop	{ BEGIN WORD; return (SCC_LISTPROP); }
1100Sstevel@tonic-gate <INITIAL>setprop	{ BEGIN WORD; return (SCC_SETPROP); }
1110Sstevel@tonic-gate <INITIAL>delprop	{ BEGIN WORD; return (SCC_DELPROP); }
1120Sstevel@tonic-gate <INITIAL>editprop	{ BEGIN WORD; return (SCC_EDITPROP); }
1137887SLiane.Praza@Sun.COM <INITIAL>describe	{ BEGIN WORD; return (SCC_DESCRIBE); }
1140Sstevel@tonic-gate <INITIAL>addpropvalue	{ BEGIN WORD; return (SCC_ADDPROPVALUE); }
1150Sstevel@tonic-gate <INITIAL>delpropvalue	{ BEGIN WORD; return (SCC_DELPROPVALUE); }
1160Sstevel@tonic-gate <INITIAL>setenv		{ BEGIN WORD; return (SCC_SETENV); }
1170Sstevel@tonic-gate <INITIAL>unsetenv	{ BEGIN WORD; return (SCC_UNSETENV); }
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate <INITIAL>listsnap	{ BEGIN WORD; return (SCC_LISTSNAP); }
1200Sstevel@tonic-gate <INITIAL>selectsnap	{ BEGIN WORD; return (SCC_SELECTSNAP); }
1210Sstevel@tonic-gate <INITIAL>revert		{ BEGIN WORD; return (SCC_REVERT); }
1225841Samaguire <INITIAL>refresh	{ BEGIN WORD; return (SCC_REFRESH); }
1230Sstevel@tonic-gate 
124*12967Sgavin.maltby@oracle.com <INITIAL>delnotify	{ BEGIN WORD; return (SCC_DELNOTIFY); }
125*12967Sgavin.maltby@oracle.com <INITIAL>listnotify	{ BEGIN WORD; return (SCC_LISTNOTIFY); }
126*12967Sgavin.maltby@oracle.com <INITIAL>setnotify	{ BEGIN WORD; return (SCC_SETNOTIFY); }
127*12967Sgavin.maltby@oracle.com 
1280Sstevel@tonic-gate [^ \t\n">=()]+		{
1290Sstevel@tonic-gate 				if ((yylval.str = strdup(yytext)) == NULL) {
1300Sstevel@tonic-gate 					yyerror(gettext("Out of memory"));
1310Sstevel@tonic-gate 					exit(UU_EXIT_FATAL);
1320Sstevel@tonic-gate 				}
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 				return SCV_WORD;
1350Sstevel@tonic-gate 			}
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate \"([^"\\]|\\.)*\"	{
1380Sstevel@tonic-gate 				/*
1390Sstevel@tonic-gate 				 * double-quoted strings start at a
1400Sstevel@tonic-gate 				 * double-quote, include characters other than
1410Sstevel@tonic-gate 				 * double-quote and backslash, and
1420Sstevel@tonic-gate 				 * backslashed-characters, and end with a
1430Sstevel@tonic-gate 				 * double-quote.
1440Sstevel@tonic-gate 				 */
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 				char *str, *cp;
1470Sstevel@tonic-gate 				int shift;
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 				if ((str = strdup(yytext)) == NULL) {
1500Sstevel@tonic-gate 					yyerror(gettext("Out of memory"));
1510Sstevel@tonic-gate 					exit(UU_EXIT_FATAL);
1520Sstevel@tonic-gate 				}
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 				/* Strip out the backslashes. */
1550Sstevel@tonic-gate 				for (cp = str, shift = 0; *cp != '\0'; ++cp) {
1560Sstevel@tonic-gate 					if (*cp == '\\') {
1570Sstevel@tonic-gate 						++cp;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 						/*
1600Sstevel@tonic-gate 						 * This can't be null because
1610Sstevel@tonic-gate 						 * the string always ends with
1620Sstevel@tonic-gate 						 * a double-quote.
1630Sstevel@tonic-gate 						 */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 						++shift;
1660Sstevel@tonic-gate 						*(cp - shift) = *cp;
1670Sstevel@tonic-gate 					} else if (shift != 0)
1680Sstevel@tonic-gate 						*(cp - shift) = *cp;
1690Sstevel@tonic-gate 				}
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 				/* Nullify everything after trailing quote */
1720Sstevel@tonic-gate 				*(cp - shift) = '\0';
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 				yylval.str = str;
1750Sstevel@tonic-gate 				return SCV_STRING;
1760Sstevel@tonic-gate 			}
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate \n			{
1790Sstevel@tonic-gate 				est->sc_cmd_lineno++;
1800Sstevel@tonic-gate 				BEGIN INITIAL;
1810Sstevel@tonic-gate 				return (SCS_NEWLINE);
1820Sstevel@tonic-gate 			}
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate [ \t]+			;
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate ">"			{ return SCS_REDIRECT; }
1870Sstevel@tonic-gate "="			{ return SCS_EQUALS; }
1880Sstevel@tonic-gate "("			{ ++parens; return SCS_LPAREN; }
1890Sstevel@tonic-gate ")"			{ --parens; return SCS_RPAREN; }
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate .			{
1920Sstevel@tonic-gate 				uu_die(gettext("unrecognized character %s\n"),
1930Sstevel@tonic-gate 				    yytext);
1940Sstevel@tonic-gate 			}
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate %%
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate int
1990Sstevel@tonic-gate yyerror(const char *s)
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate 	return (0);
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate static int
2050Sstevel@tonic-gate input(void)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate 	static int saw_eof = 0;
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 	int c = engine_cmd_getc(est);
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 	/*
2120Sstevel@tonic-gate 	 * To ensure input is terminated, slip in a newline on EOF.
2130Sstevel@tonic-gate 	 */
2140Sstevel@tonic-gate 	if (c == EOF) {
2150Sstevel@tonic-gate 		if (saw_eof)
2160Sstevel@tonic-gate 			return (0);
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 		saw_eof = 1;
2190Sstevel@tonic-gate 		return ('\n');
2200Sstevel@tonic-gate 	} else
2210Sstevel@tonic-gate 		saw_eof = 0;
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	if (c == '\n')
2240Sstevel@tonic-gate 		yylineno++;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	return (c);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate static void
2300Sstevel@tonic-gate unput(int c)
2310Sstevel@tonic-gate {
2320Sstevel@tonic-gate 	if (c == '\n')
2330Sstevel@tonic-gate 		yylineno--;
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	(void) engine_cmd_ungetc(est, c == 0 ? EOF : c);
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate static void
2390Sstevel@tonic-gate output(int c)
2400Sstevel@tonic-gate {
2410Sstevel@tonic-gate 	char ch = c;
2420Sstevel@tonic-gate 	engine_cmd_nputs(est, &ch, sizeof (ch));
2430Sstevel@tonic-gate }
244