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