xref: /titanic_52/usr/src/cmd/tnf/prex/prexlex.l (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate %{
2*7c478bd9Sstevel@tonic-gate /*
3*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate  *
5*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate  * with the License.
9*7c478bd9Sstevel@tonic-gate  *
10*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
14*7c478bd9Sstevel@tonic-gate  *
15*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate  *
23*7c478bd9Sstevel@tonic-gate  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24*7c478bd9Sstevel@tonic-gate  */
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate %}
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate %a 10000
30*7c478bd9Sstevel@tonic-gate %o 10000
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate %{
33*7c478bd9Sstevel@tonic-gate #include "spec.h"
34*7c478bd9Sstevel@tonic-gate #include "expr.h"
35*7c478bd9Sstevel@tonic-gate #include "y.tab.h"
36*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
37*7c478bd9Sstevel@tonic-gate #include <string.h>
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate char *	qtstr		(char *		instr);
40*7c478bd9Sstevel@tonic-gate char *	rgstr		(char *		instr);
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate ** we substitute i/o routines defined in main.c for the
44*7c478bd9Sstevel@tonic-gate ** standard fare.  This allows us to support the "source"
45*7c478bd9Sstevel@tonic-gate ** function by redirecting the input stream from different
46*7c478bd9Sstevel@tonic-gate ** places
47*7c478bd9Sstevel@tonic-gate */
48*7c478bd9Sstevel@tonic-gate #include "source.h"
49*7c478bd9Sstevel@tonic-gate #undef input
50*7c478bd9Sstevel@tonic-gate #undef unput
51*7c478bd9Sstevel@tonic-gate #undef output
52*7c478bd9Sstevel@tonic-gate #define	input()		source_input()
53*7c478bd9Sstevel@tonic-gate #define	unput(c)	source_unput(c)
54*7c478bd9Sstevel@tonic-gate #define	output(c)	source_output(c)
55*7c478bd9Sstevel@tonic-gate %}
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate IDFIRST			[a-zA-Z_\.%]
58*7c478bd9Sstevel@tonic-gate IDCHAR			({IDFIRST}|[0-9])
59*7c478bd9Sstevel@tonic-gate ID			{IDFIRST}{IDCHAR}*
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate %%
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #.*			;		/* eat comments */
64*7c478bd9Sstevel@tonic-gate [ \t]+			;		/* eats whitespace */
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate \n			{ source_nl(); return NL; }
67*7c478bd9Sstevel@tonic-gate \\\n			{ source_nl(); } /* escaped newline */
68*7c478bd9Sstevel@tonic-gate =			return (EQ);
69*7c478bd9Sstevel@tonic-gate \,			return (COMMA);
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate add			{ yylval.intval = ADD; return (ADD); }
72*7c478bd9Sstevel@tonic-gate alloc			{ yylval.intval = ALLOC; return (ALLOC); }
73*7c478bd9Sstevel@tonic-gate buffer			{ yylval.intval = BUFFER; return (BUFFER); }
74*7c478bd9Sstevel@tonic-gate clear			{ yylval.intval = CLEAR; return (CLEAR); }
75*7c478bd9Sstevel@tonic-gate connect			{ yylval.intval = CONNECT; return (CONNECT); }
76*7c478bd9Sstevel@tonic-gate continue		{ yylval.intval = CONTINUE; return (CONTINUE); }
77*7c478bd9Sstevel@tonic-gate create			{ yylval.intval = CREATE; return (CREATE); }
78*7c478bd9Sstevel@tonic-gate dealloc			{ yylval.intval = DEALLOC; return (DEALLOC); }
79*7c478bd9Sstevel@tonic-gate delete			{ yylval.intval = DELETE; return (DELETE); }
80*7c478bd9Sstevel@tonic-gate disable			{ yylval.intval = DISABLE; return (DISABLE); }
81*7c478bd9Sstevel@tonic-gate enable			{ yylval.intval = ENABLE; return (ENABLE); }
82*7c478bd9Sstevel@tonic-gate fcns			{ yylval.intval = FCNS; return (FCNS); }
83*7c478bd9Sstevel@tonic-gate filter			{ yylval.intval = FILTER; return (FILTER); }
84*7c478bd9Sstevel@tonic-gate help			{ yylval.intval = HELP; return (HELP); }
85*7c478bd9Sstevel@tonic-gate history			{ yylval.intval = HISTORY; return (HISTORY); }
86*7c478bd9Sstevel@tonic-gate tracefile		{ yylval.intval = TRACEFILE; return (TRACEFILE); }
87*7c478bd9Sstevel@tonic-gate kill			{ yylval.intval = KILL; return (KILL); }
88*7c478bd9Sstevel@tonic-gate ktrace			{ yylval.intval = KTRACE; return (KTRACE); }
89*7c478bd9Sstevel@tonic-gate list			{ yylval.intval = LIST; return (LIST); }
90*7c478bd9Sstevel@tonic-gate off			{ yylval.intval = OFF; return (OFF); }
91*7c478bd9Sstevel@tonic-gate on			{ yylval.intval = ON; return (ON); }
92*7c478bd9Sstevel@tonic-gate pfilter			{ yylval.intval = PFILTER; return (PFILTER); }
93*7c478bd9Sstevel@tonic-gate probes			{ yylval.intval = PROBES; return (PROBES); }
94*7c478bd9Sstevel@tonic-gate quit			{ yylval.intval = QUIT; return (QUIT); }
95*7c478bd9Sstevel@tonic-gate resume			{ yylval.intval = RESUME; return (RESUME); }
96*7c478bd9Sstevel@tonic-gate sets			{ yylval.intval = SETS; return (SETS); }
97*7c478bd9Sstevel@tonic-gate source			{ yylval.intval = SOURCE; return (SOURCE); }
98*7c478bd9Sstevel@tonic-gate suspend			{ yylval.intval = SUSPEND; return (SUSPEND); }
99*7c478bd9Sstevel@tonic-gate trace			{ yylval.intval = TRACE; return (TRACE); }
100*7c478bd9Sstevel@tonic-gate untrace			{ yylval.intval = UNTRACE; return (UNTRACE); }
101*7c478bd9Sstevel@tonic-gate values			{ yylval.intval = VALUES; return (VALUES); }
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate ${ID}			{ yylval.strval = strdup(&yytext[1]); return SETNAME; }
104*7c478bd9Sstevel@tonic-gate &{ID}			{ yylval.strval = strdup(&yytext[1]); return FCNNAME; }
105*7c478bd9Sstevel@tonic-gate {ID}			{ yylval.strval = strdup(yytext); return IDENT; }
106*7c478bd9Sstevel@tonic-gate \'[^'\n]*\'		{ yylval.strval = qtstr(yytext); return VALSTR; }
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate \/([^/\\\n]|\\.)*\/	{ yylval.strval = rgstr(yytext); return REGEXP; }
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate [0-9]+[KkMm]?		{
111*7c478bd9Sstevel@tonic-gate 				char scale = yytext[yyleng - 1];
112*7c478bd9Sstevel@tonic-gate 				yylval.intval = atoi(yytext);
113*7c478bd9Sstevel@tonic-gate 				if (scale == 'k' || scale == 'K')
114*7c478bd9Sstevel@tonic-gate 					yylval.intval *= 1024;
115*7c478bd9Sstevel@tonic-gate 				else if (scale == 'm' || scale == 'M')
116*7c478bd9Sstevel@tonic-gate 					yylval.intval *= 1024 * 1024;
117*7c478bd9Sstevel@tonic-gate 				return (SCALED_INT);
118*7c478bd9Sstevel@tonic-gate 			}
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate .			return (INVAL);	/* barf on anything else */
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate %%
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate /****************************************************************
125*7c478bd9Sstevel@tonic-gate qtstr() - shucks a quoted str, and copies it into new memory
126*7c478bd9Sstevel@tonic-gate ****************************************************************/
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate char *
129*7c478bd9Sstevel@tonic-gate qtstr		(char *		instr)
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate 	char	*ptr;
132*7c478bd9Sstevel@tonic-gate 	int	indx;
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	/* skip the leading quote in the copy */
135*7c478bd9Sstevel@tonic-gate 	ptr = strdup(&instr[1]);
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	/* null out the trailing quote */
138*7c478bd9Sstevel@tonic-gate 	indx = strlen(ptr) - 1;
139*7c478bd9Sstevel@tonic-gate 	indx = (indx < 0) ? 0 : indx;
140*7c478bd9Sstevel@tonic-gate 	ptr[indx] = '\0';
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	return ptr;
143*7c478bd9Sstevel@tonic-gate }   /* end qtstr */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate /****************************************************************
147*7c478bd9Sstevel@tonic-gate rgstr() - shucks a decorated regular expression, and copies it
148*7c478bd9Sstevel@tonic-gate into new memory
149*7c478bd9Sstevel@tonic-gate ****************************************************************/
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate char *
152*7c478bd9Sstevel@tonic-gate rgstr		(char *		instr)
153*7c478bd9Sstevel@tonic-gate {
154*7c478bd9Sstevel@tonic-gate 	char	*ptr;
155*7c478bd9Sstevel@tonic-gate 	int	indx;
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 	/* skip the leading slash in the copy */
158*7c478bd9Sstevel@tonic-gate 	ptr = strdup(&instr[1]);
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	/* null out the trailing slash */
161*7c478bd9Sstevel@tonic-gate 	indx = strlen(ptr) - 1;
162*7c478bd9Sstevel@tonic-gate 	indx = (indx < 0) ? 0 : indx;
163*7c478bd9Sstevel@tonic-gate 	ptr[indx] = '\0';
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	return (ptr);
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate }   /* end rgstr */
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 
170