xref: /titanic_51/usr/src/cmd/fs.d/udfs/fsdb/fsdb_yacc.y (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) 1999-2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <locale.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate char	shell_name[128] = "/bin/sh";
35*7c478bd9Sstevel@tonic-gate extern char	prompt[];
36*7c478bd9Sstevel@tonic-gate extern uint16_t ricb_prn;
37*7c478bd9Sstevel@tonic-gate extern uint32_t ricb_loc;
38*7c478bd9Sstevel@tonic-gate extern int32_t bsize, bmask, l2d, l2b;
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate int	base = 16;
41*7c478bd9Sstevel@tonic-gate int	old_value = 0;
42*7c478bd9Sstevel@tonic-gate int	value = 0;
43*7c478bd9Sstevel@tonic-gate int	count = 0;
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate int	last_op_type = 0;
47*7c478bd9Sstevel@tonic-gate #define	TYPE_NONE	0
48*7c478bd9Sstevel@tonic-gate #define	TYPE_INODE	1
49*7c478bd9Sstevel@tonic-gate #define	TYPE_DIRENT	2
50*7c478bd9Sstevel@tonic-gate #define	TYPE_BLOCK	3
51*7c478bd9Sstevel@tonic-gate #define	TYPE_CD		4
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate uint32_t i_number = 0;
54*7c478bd9Sstevel@tonic-gate uint32_t d_entry = 0;
55*7c478bd9Sstevel@tonic-gate int	error_override = 0;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate int	register_array[256];
58*7c478bd9Sstevel@tonic-gate char	cwd[MAXPATHLEN] = "/";
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate int32_t ls_flags;
61*7c478bd9Sstevel@tonic-gate #define	LONG_LIST	0x1
62*7c478bd9Sstevel@tonic-gate #define	RECU_LIST	0x2
63*7c478bd9Sstevel@tonic-gate #define	LIST_LS		0x4
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate int32_t find_flags;
66*7c478bd9Sstevel@tonic-gate #define	FIND_DIR	0x1
67*7c478bd9Sstevel@tonic-gate #define	FIND_NAME	0x2
68*7c478bd9Sstevel@tonic-gate #define	FIND_INODE	0x4
69*7c478bd9Sstevel@tonic-gate #define	FIND_DONE	0x8
70*7c478bd9Sstevel@tonic-gate char find_dir[1024];
71*7c478bd9Sstevel@tonic-gate char find_name[1024];
72*7c478bd9Sstevel@tonic-gate uint32_t find_in;
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate %}
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate %union
77*7c478bd9Sstevel@tonic-gate {
78*7c478bd9Sstevel@tonic-gate 	uint8_t		*strval;
79*7c478bd9Sstevel@tonic-gate 	uint64_t	intval;
80*7c478bd9Sstevel@tonic-gate };
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate %token BASE BLOCK CD DIRECTORY TFILE FIND FILL
83*7c478bd9Sstevel@tonic-gate %token INODE LS OVERRIDE PROMPT PWD QUIT TAG BANG
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate %token AVD MVDS RVDS INTS FSDS ROOT
86*7c478bd9Sstevel@tonic-gate %token ATTZ ATYE ATMO ATDA ATHO ATMI ATSE ATCE ATHU ATMIC
87*7c478bd9Sstevel@tonic-gate %token CTTZ CTYE CTMO CTDA CTHO CTMI CTSE CTCE CTHU CTMIC
88*7c478bd9Sstevel@tonic-gate %token MTTZ MTYE MTMO MTDA MTHO MTMI MTSE MTCE MTHU MTMIC
89*7c478bd9Sstevel@tonic-gate %token GID LN MD MAJ MIO NM SZ UID UNIQ
90*7c478bd9Sstevel@tonic-gate %token DOT
91*7c478bd9Sstevel@tonic-gate %token NL
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate %token WORD
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate %left '-' '+'
96*7c478bd9Sstevel@tonic-gate %left '*' '%'
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate %type <strval>	WORD
99*7c478bd9Sstevel@tonic-gate %type <intval> expr
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate %%
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate session		: statement_list
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate statement_list	: /* empty */			{ print_prompt(); }
106*7c478bd9Sstevel@tonic-gate 		| statement_list statement
107*7c478bd9Sstevel@tonic-gate 			{
108*7c478bd9Sstevel@tonic-gate 				ls_flags = 0;
109*7c478bd9Sstevel@tonic-gate 			}
110*7c478bd9Sstevel@tonic-gate 		;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate statement	: empty_statement
113*7c478bd9Sstevel@tonic-gate 		| current_value
114*7c478bd9Sstevel@tonic-gate 		| register
115*7c478bd9Sstevel@tonic-gate 		| base | block | cd | directory | file | find | fill
116*7c478bd9Sstevel@tonic-gate 		| inode | ls | override | nprompt | pwd | quit | tag | shell
117*7c478bd9Sstevel@tonic-gate 		| avd | mvds | rvds | ints | fsds | root
118*7c478bd9Sstevel@tonic-gate 		| at | ct | gid | ln | mt | md
119*7c478bd9Sstevel@tonic-gate 		| maj | min | nm | sz | uid | uniq
120*7c478bd9Sstevel@tonic-gate 		| dump | texpr
121*7c478bd9Sstevel@tonic-gate 		| error	{ yyclearin; yyerrok; }
122*7c478bd9Sstevel@tonic-gate 		;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate empty_statement	: NL
125*7c478bd9Sstevel@tonic-gate 			{
126*7c478bd9Sstevel@tonic-gate 				print_prompt();
127*7c478bd9Sstevel@tonic-gate 			}
128*7c478bd9Sstevel@tonic-gate 		;
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate current_value	: DOT
132*7c478bd9Sstevel@tonic-gate 			{
133*7c478bd9Sstevel@tonic-gate 				if (last_op_type == TYPE_INODE) {
134*7c478bd9Sstevel@tonic-gate 					print_inode(i_number << l2b);
135*7c478bd9Sstevel@tonic-gate 				} else if (last_op_type == TYPE_DIRENT) {
136*7c478bd9Sstevel@tonic-gate 					print_dent(i_number << l2b, d_entry);
137*7c478bd9Sstevel@tonic-gate 				} else {
138*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
139*7c478bd9Sstevel@tonic-gate 						gettext("%x\n"), value);
140*7c478bd9Sstevel@tonic-gate 				}
141*7c478bd9Sstevel@tonic-gate 			}
142*7c478bd9Sstevel@tonic-gate 			;
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate register	: '<' WORD
145*7c478bd9Sstevel@tonic-gate 			{
146*7c478bd9Sstevel@tonic-gate 				if ((strlen((caddr_t)$2) == 1) &&
147*7c478bd9Sstevel@tonic-gate 					((($2[0] >= 'a') &&
148*7c478bd9Sstevel@tonic-gate 						($2[0] <= 'z')) ||
149*7c478bd9Sstevel@tonic-gate 					(($2[0] >= 'A') &&
150*7c478bd9Sstevel@tonic-gate 						($2[0] <= 'Z')))) {
151*7c478bd9Sstevel@tonic-gate 					value = register_array[$2[0]];
152*7c478bd9Sstevel@tonic-gate 				} else {
153*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
154*7c478bd9Sstevel@tonic-gate 						gettext("Registers can"
155*7c478bd9Sstevel@tonic-gate 						" be only a-z or A-Z\n"));
156*7c478bd9Sstevel@tonic-gate 				}
157*7c478bd9Sstevel@tonic-gate 			}
158*7c478bd9Sstevel@tonic-gate 		| '>' WORD
159*7c478bd9Sstevel@tonic-gate 			{
160*7c478bd9Sstevel@tonic-gate 				if ((strlen((caddr_t)$2) == 1) &&
161*7c478bd9Sstevel@tonic-gate 					((($2[0] >= 'a') &&
162*7c478bd9Sstevel@tonic-gate 						($2[0] <= 'z')) ||
163*7c478bd9Sstevel@tonic-gate 					(($2[0] >= 'A') &&
164*7c478bd9Sstevel@tonic-gate 						($2[0] <= 'Z')))) {
165*7c478bd9Sstevel@tonic-gate 					register_array[$2[0]] = value;
166*7c478bd9Sstevel@tonic-gate 				} else {
167*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
168*7c478bd9Sstevel@tonic-gate 						gettext("Registers can"
169*7c478bd9Sstevel@tonic-gate 						" be only a-z or A-Z\n"));
170*7c478bd9Sstevel@tonic-gate 				}
171*7c478bd9Sstevel@tonic-gate 			}
172*7c478bd9Sstevel@tonic-gate 		;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate base		: BASE '=' expr
175*7c478bd9Sstevel@tonic-gate 			{
176*7c478bd9Sstevel@tonic-gate 				if (($3 == 8) || ($3 == 10) || ($3 == 16)) {
177*7c478bd9Sstevel@tonic-gate 					base = $3;
178*7c478bd9Sstevel@tonic-gate 				} else {
179*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
180*7c478bd9Sstevel@tonic-gate 						gettext("Requested %x Only"
181*7c478bd9Sstevel@tonic-gate 						" Oct, Dec and"
182*7c478bd9Sstevel@tonic-gate 						" Hex are Supported\n"), $3);
183*7c478bd9Sstevel@tonic-gate 				}
184*7c478bd9Sstevel@tonic-gate 			}
185*7c478bd9Sstevel@tonic-gate 		| BASE
186*7c478bd9Sstevel@tonic-gate 			{
187*7c478bd9Sstevel@tonic-gate 				fprintf(stdout,
188*7c478bd9Sstevel@tonic-gate 					gettext("Current Base in Decimal"
189*7c478bd9Sstevel@tonic-gate 					" : %d\n"), base);
190*7c478bd9Sstevel@tonic-gate 			}
191*7c478bd9Sstevel@tonic-gate 		;
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate block		: BLOCK
194*7c478bd9Sstevel@tonic-gate 			{
195*7c478bd9Sstevel@tonic-gate 				last_op_type = TYPE_NONE;
196*7c478bd9Sstevel@tonic-gate 				value = value * DEV_BSIZE;
197*7c478bd9Sstevel@tonic-gate 			}
198*7c478bd9Sstevel@tonic-gate 		;
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate cd		: CD ' ' WORD
201*7c478bd9Sstevel@tonic-gate 			{
202*7c478bd9Sstevel@tonic-gate 				uint8_t fl;
203*7c478bd9Sstevel@tonic-gate 				uint32_t temp;
204*7c478bd9Sstevel@tonic-gate 				char temp_cwd[MAXPATHLEN];
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 				strcpy(temp_cwd, cwd);
207*7c478bd9Sstevel@tonic-gate 				if (strcmp((caddr_t)$3, "..") == 0) {
208*7c478bd9Sstevel@tonic-gate 					if (strlen(temp_cwd) == 1) {
209*7c478bd9Sstevel@tonic-gate 						if (temp_cwd[0] != '/') {
210*7c478bd9Sstevel@tonic-gate 							fprintf(stdout,
211*7c478bd9Sstevel@tonic-gate 							gettext("cwd is invalid"
212*7c478bd9Sstevel@tonic-gate 							"setting to /\n"));
213*7c478bd9Sstevel@tonic-gate 							strcpy(temp_cwd, "/");
214*7c478bd9Sstevel@tonic-gate 						}
215*7c478bd9Sstevel@tonic-gate 					} else {
216*7c478bd9Sstevel@tonic-gate 						dirname(temp_cwd);
217*7c478bd9Sstevel@tonic-gate 					}
218*7c478bd9Sstevel@tonic-gate 				} else {
219*7c478bd9Sstevel@tonic-gate 					int32_t len;
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 					len = strlen(temp_cwd);
222*7c478bd9Sstevel@tonic-gate 					if (temp_cwd[len - 1] != '/') {
223*7c478bd9Sstevel@tonic-gate 						temp_cwd[len] = '/';
224*7c478bd9Sstevel@tonic-gate 						temp_cwd[len + 1] = '\0';
225*7c478bd9Sstevel@tonic-gate 					}
226*7c478bd9Sstevel@tonic-gate 					strcat(temp_cwd, (caddr_t)$3);
227*7c478bd9Sstevel@tonic-gate 				}
228*7c478bd9Sstevel@tonic-gate 				if (inode_from_path(temp_cwd, &temp,
229*7c478bd9Sstevel@tonic-gate 							&fl) != 0) {
230*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
231*7c478bd9Sstevel@tonic-gate 						gettext("Could not locate inode"
232*7c478bd9Sstevel@tonic-gate 						" for path %s\n"), temp_cwd);
233*7c478bd9Sstevel@tonic-gate 					strcpy(temp_cwd, "/");
234*7c478bd9Sstevel@tonic-gate 					if ((temp = ud_xlate_to_daddr(ricb_prn,
235*7c478bd9Sstevel@tonic-gate 						ricb_loc)) == 0) {
236*7c478bd9Sstevel@tonic-gate 						fprintf(stdout,
237*7c478bd9Sstevel@tonic-gate 						gettext("Failed to translate"
238*7c478bd9Sstevel@tonic-gate 						" prn %x loc %x\n"),
239*7c478bd9Sstevel@tonic-gate 						ricb_prn, ricb_loc);
240*7c478bd9Sstevel@tonic-gate 					}
241*7c478bd9Sstevel@tonic-gate 				} else {
242*7c478bd9Sstevel@tonic-gate 					if ((fl & FID_DIR) == 0) {
243*7c478bd9Sstevel@tonic-gate 						fprintf(stdout,
244*7c478bd9Sstevel@tonic-gate 						gettext("%s is not a"
245*7c478bd9Sstevel@tonic-gate 						" directory\n"), temp_cwd);
246*7c478bd9Sstevel@tonic-gate 					} else {
247*7c478bd9Sstevel@tonic-gate 						strcpy(cwd, temp_cwd);
248*7c478bd9Sstevel@tonic-gate 						value = temp << l2b;
249*7c478bd9Sstevel@tonic-gate 						last_op_type = TYPE_CD;
250*7c478bd9Sstevel@tonic-gate 						i_number = temp;
251*7c478bd9Sstevel@tonic-gate 					}
252*7c478bd9Sstevel@tonic-gate 				}
253*7c478bd9Sstevel@tonic-gate 			}
254*7c478bd9Sstevel@tonic-gate 		| CD
255*7c478bd9Sstevel@tonic-gate 			{
256*7c478bd9Sstevel@tonic-gate 				uint32_t block;
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 				(void) strcpy(cwd, "/");
259*7c478bd9Sstevel@tonic-gate 				/*
260*7c478bd9Sstevel@tonic-gate 				 * set current value to root icb
261*7c478bd9Sstevel@tonic-gate 				 */
262*7c478bd9Sstevel@tonic-gate 				if ((block = ud_xlate_to_daddr(ricb_prn,
263*7c478bd9Sstevel@tonic-gate 						ricb_loc)) == 0) {
264*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
265*7c478bd9Sstevel@tonic-gate 						gettext("Failed to translate "
266*7c478bd9Sstevel@tonic-gate 						"prn %x loc %x\n"),
267*7c478bd9Sstevel@tonic-gate 						ricb_prn, ricb_loc);
268*7c478bd9Sstevel@tonic-gate 				} else {
269*7c478bd9Sstevel@tonic-gate 					value = block << l2b;
270*7c478bd9Sstevel@tonic-gate 					last_op_type = TYPE_CD;
271*7c478bd9Sstevel@tonic-gate 					i_number = block;
272*7c478bd9Sstevel@tonic-gate 				}
273*7c478bd9Sstevel@tonic-gate 			}
274*7c478bd9Sstevel@tonic-gate 		;
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate directory	: DIRECTORY
277*7c478bd9Sstevel@tonic-gate 			{
278*7c478bd9Sstevel@tonic-gate 				if (verify_dent(i_number << l2b, value) == 0) {
279*7c478bd9Sstevel@tonic-gate 					last_op_type = TYPE_DIRENT;
280*7c478bd9Sstevel@tonic-gate 					d_entry = value;
281*7c478bd9Sstevel@tonic-gate 				}
282*7c478bd9Sstevel@tonic-gate 			}
283*7c478bd9Sstevel@tonic-gate 		;
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate file		: TFILE
286*7c478bd9Sstevel@tonic-gate 			{
287*7c478bd9Sstevel@tonic-gate 			}
288*7c478bd9Sstevel@tonic-gate 		;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate find		: xfind
291*7c478bd9Sstevel@tonic-gate 			{
292*7c478bd9Sstevel@tonic-gate 				if ((find_flags & (FIND_NAME | FIND_INODE)) &&
293*7c478bd9Sstevel@tonic-gate 					(find_flags & FIND_DONE)) {
294*7c478bd9Sstevel@tonic-gate 					if (find_dir[0] != '/') {
295*7c478bd9Sstevel@tonic-gate 						char buf[1024];
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 						strcpy(buf, find_dir);
298*7c478bd9Sstevel@tonic-gate 						if ((strlen(cwd) == 1) &&
299*7c478bd9Sstevel@tonic-gate 							(cwd[0] == '/')) {
300*7c478bd9Sstevel@tonic-gate 							strcpy(find_dir, "/");
301*7c478bd9Sstevel@tonic-gate 						} else {
302*7c478bd9Sstevel@tonic-gate 							strcpy(find_dir, cwd);
303*7c478bd9Sstevel@tonic-gate 							strcat(find_dir, "/");
304*7c478bd9Sstevel@tonic-gate 						}
305*7c478bd9Sstevel@tonic-gate 						strcat(find_dir, buf);
306*7c478bd9Sstevel@tonic-gate 					}
307*7c478bd9Sstevel@tonic-gate 					find_it(find_dir, find_name, find_in,
308*7c478bd9Sstevel@tonic-gate 				(find_flags & (FIND_NAME | FIND_INODE)));
309*7c478bd9Sstevel@tonic-gate 				}
310*7c478bd9Sstevel@tonic-gate 				find_flags = 0;
311*7c478bd9Sstevel@tonic-gate 				find_dir[0] = '\0';
312*7c478bd9Sstevel@tonic-gate 				find_name[0] = '\0';
313*7c478bd9Sstevel@tonic-gate 				find_in = 0;
314*7c478bd9Sstevel@tonic-gate 			}
315*7c478bd9Sstevel@tonic-gate 		;
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate xfind		: FIND WORD
318*7c478bd9Sstevel@tonic-gate 			{
319*7c478bd9Sstevel@tonic-gate 				strcpy(find_dir, (char *)$2);
320*7c478bd9Sstevel@tonic-gate 				find_flags = FIND_DIR;
321*7c478bd9Sstevel@tonic-gate 			}
322*7c478bd9Sstevel@tonic-gate 		| xfind ' ' WORD
323*7c478bd9Sstevel@tonic-gate 			{
324*7c478bd9Sstevel@tonic-gate 				if (find_flags == FIND_DIR) {
325*7c478bd9Sstevel@tonic-gate 					if (strcmp((char *)$3, "-name") == 0) {
326*7c478bd9Sstevel@tonic-gate 						find_flags = FIND_NAME;
327*7c478bd9Sstevel@tonic-gate 					} else if (strcmp((char *)$3, "-inum")
328*7c478bd9Sstevel@tonic-gate 							== 0) {
329*7c478bd9Sstevel@tonic-gate 						find_flags = FIND_INODE;
330*7c478bd9Sstevel@tonic-gate 					} else {
331*7c478bd9Sstevel@tonic-gate 						fprintf(stdout,
332*7c478bd9Sstevel@tonic-gate 				gettext("find dir-name {-name n | -inum n}\n"));
333*7c478bd9Sstevel@tonic-gate 					}
334*7c478bd9Sstevel@tonic-gate 				} else if (find_flags == FIND_NAME) {
335*7c478bd9Sstevel@tonic-gate 					strcpy(find_name, (char *)$3);
336*7c478bd9Sstevel@tonic-gate 					find_flags |= FIND_DONE;
337*7c478bd9Sstevel@tonic-gate 				} else if (find_flags == FIND_INODE) {
338*7c478bd9Sstevel@tonic-gate 					uint64_t temp;
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 					if (check_and_get_int($3, &temp) ==
341*7c478bd9Sstevel@tonic-gate 						0) {
342*7c478bd9Sstevel@tonic-gate 						find_in = temp;
343*7c478bd9Sstevel@tonic-gate 						find_flags |= FIND_DONE;
344*7c478bd9Sstevel@tonic-gate 					} else {
345*7c478bd9Sstevel@tonic-gate 						fprintf(stdout,
346*7c478bd9Sstevel@tonic-gate 				gettext("find dir-name {-name n | -inum n}\n"));
347*7c478bd9Sstevel@tonic-gate 					}
348*7c478bd9Sstevel@tonic-gate 				} else {
349*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
350*7c478bd9Sstevel@tonic-gate 				gettext("find dir-name {-name n | -inum n}\n"));
351*7c478bd9Sstevel@tonic-gate 				}
352*7c478bd9Sstevel@tonic-gate 			}
353*7c478bd9Sstevel@tonic-gate 		| xfind ' ' expr
354*7c478bd9Sstevel@tonic-gate 			{
355*7c478bd9Sstevel@tonic-gate 				if (find_flags == FIND_INODE) {
356*7c478bd9Sstevel@tonic-gate 					find_in = $3;
357*7c478bd9Sstevel@tonic-gate 					find_flags |= FIND_DONE;
358*7c478bd9Sstevel@tonic-gate 				} else {
359*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
360*7c478bd9Sstevel@tonic-gate 				gettext("find dir-name {-name n | -inum n}\n"));
361*7c478bd9Sstevel@tonic-gate 				}
362*7c478bd9Sstevel@tonic-gate 			}
363*7c478bd9Sstevel@tonic-gate 		;
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate fill		: FILL '=' WORD
367*7c478bd9Sstevel@tonic-gate 			{
368*7c478bd9Sstevel@tonic-gate 				fill_pattern(value, count, $3);
369*7c478bd9Sstevel@tonic-gate 			}
370*7c478bd9Sstevel@tonic-gate 		;
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate inode		: INODE
373*7c478bd9Sstevel@tonic-gate 			{
374*7c478bd9Sstevel@tonic-gate 				uint32_t temp;
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate 				if (last_op_type == TYPE_CD) {
377*7c478bd9Sstevel@tonic-gate 					temp = value;
378*7c478bd9Sstevel@tonic-gate 				} else {
379*7c478bd9Sstevel@tonic-gate 					temp = value << l2b;
380*7c478bd9Sstevel@tonic-gate 				}
381*7c478bd9Sstevel@tonic-gate 				last_op_type = TYPE_INODE;
382*7c478bd9Sstevel@tonic-gate 				if (verify_inode(temp, 0) != 0) {
383*7c478bd9Sstevel@tonic-gate 					i_number = temp >> l2b;
384*7c478bd9Sstevel@tonic-gate 					d_entry = 0;
385*7c478bd9Sstevel@tonic-gate 				}
386*7c478bd9Sstevel@tonic-gate 			}
387*7c478bd9Sstevel@tonic-gate 		;
388*7c478bd9Sstevel@tonic-gate 
389*7c478bd9Sstevel@tonic-gate ls		: xls
390*7c478bd9Sstevel@tonic-gate 			{
391*7c478bd9Sstevel@tonic-gate 				if (ls_flags & LIST_LS) {
392*7c478bd9Sstevel@tonic-gate 					list(".", i_number, ls_flags);
393*7c478bd9Sstevel@tonic-gate 				}
394*7c478bd9Sstevel@tonic-gate 			}
395*7c478bd9Sstevel@tonic-gate 		;
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate xls		: LS
398*7c478bd9Sstevel@tonic-gate 			{
399*7c478bd9Sstevel@tonic-gate 				/* Do nothing */
400*7c478bd9Sstevel@tonic-gate 				ls_flags = LIST_LS;
401*7c478bd9Sstevel@tonic-gate 			}
402*7c478bd9Sstevel@tonic-gate 		| xls ' ' WORD
403*7c478bd9Sstevel@tonic-gate 			{
404*7c478bd9Sstevel@tonic-gate 				if (strcmp((caddr_t)$3, "-l") == 0) {
405*7c478bd9Sstevel@tonic-gate 					ls_flags |= LONG_LIST;
406*7c478bd9Sstevel@tonic-gate 				} else if (strcmp((caddr_t)$3, "-R") == 0) {
407*7c478bd9Sstevel@tonic-gate 					ls_flags |= RECU_LIST;
408*7c478bd9Sstevel@tonic-gate 				} else if ((strcmp((caddr_t)$3, "-lR") == 0) ||
409*7c478bd9Sstevel@tonic-gate 					(strcmp((caddr_t)$3, "-Rl") == 0)) {
410*7c478bd9Sstevel@tonic-gate 					ls_flags |= LONG_LIST | RECU_LIST;
411*7c478bd9Sstevel@tonic-gate 				} else {
412*7c478bd9Sstevel@tonic-gate 					list(".", i_number, ls_flags);
413*7c478bd9Sstevel@tonic-gate 					ls_flags &= ~LIST_LS;
414*7c478bd9Sstevel@tonic-gate 				}
415*7c478bd9Sstevel@tonic-gate 			}
416*7c478bd9Sstevel@tonic-gate 		;
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate override	: OVERRIDE
419*7c478bd9Sstevel@tonic-gate 			{
420*7c478bd9Sstevel@tonic-gate 				if (error_override == 0) {
421*7c478bd9Sstevel@tonic-gate 					error_override = 1;
422*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stdout,
423*7c478bd9Sstevel@tonic-gate 					gettext("error checking on\n"));
424*7c478bd9Sstevel@tonic-gate 				} else {
425*7c478bd9Sstevel@tonic-gate 					error_override = 0;
426*7c478bd9Sstevel@tonic-gate 					(void) fprintf(stdout,
427*7c478bd9Sstevel@tonic-gate 					gettext("error checking off\n"));
428*7c478bd9Sstevel@tonic-gate 				}
429*7c478bd9Sstevel@tonic-gate 			}
430*7c478bd9Sstevel@tonic-gate 		;
431*7c478bd9Sstevel@tonic-gate 
432*7c478bd9Sstevel@tonic-gate nprompt		: PROMPT '=' WORD
433*7c478bd9Sstevel@tonic-gate 			{
434*7c478bd9Sstevel@tonic-gate 				(void) strcpy(prompt, (caddr_t)$3);
435*7c478bd9Sstevel@tonic-gate 			}
436*7c478bd9Sstevel@tonic-gate 		;
437*7c478bd9Sstevel@tonic-gate 
438*7c478bd9Sstevel@tonic-gate pwd		: PWD
439*7c478bd9Sstevel@tonic-gate 			{
440*7c478bd9Sstevel@tonic-gate 				fprintf(stdout, gettext("%s\n"), cwd);
441*7c478bd9Sstevel@tonic-gate 			}
442*7c478bd9Sstevel@tonic-gate 		;
443*7c478bd9Sstevel@tonic-gate 
444*7c478bd9Sstevel@tonic-gate quit		: QUIT
445*7c478bd9Sstevel@tonic-gate 			{
446*7c478bd9Sstevel@tonic-gate 				exit (0);
447*7c478bd9Sstevel@tonic-gate 			}
448*7c478bd9Sstevel@tonic-gate 		;
449*7c478bd9Sstevel@tonic-gate 
450*7c478bd9Sstevel@tonic-gate tag		: TAG
451*7c478bd9Sstevel@tonic-gate 			{
452*7c478bd9Sstevel@tonic-gate 				print_desc(value, 0);
453*7c478bd9Sstevel@tonic-gate 			}
454*7c478bd9Sstevel@tonic-gate 		;
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate shell		: BANG
457*7c478bd9Sstevel@tonic-gate 			{
458*7c478bd9Sstevel@tonic-gate 				system(shell_name);
459*7c478bd9Sstevel@tonic-gate 			}
460*7c478bd9Sstevel@tonic-gate 		;
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate avd		: AVD	{ print_desc(NULL, AVD); }
463*7c478bd9Sstevel@tonic-gate 		;
464*7c478bd9Sstevel@tonic-gate mvds		: MVDS	{ print_desc(NULL, MVDS); }
465*7c478bd9Sstevel@tonic-gate 		;
466*7c478bd9Sstevel@tonic-gate rvds		: RVDS	{ print_desc(NULL, RVDS); }
467*7c478bd9Sstevel@tonic-gate 		;
468*7c478bd9Sstevel@tonic-gate ints		: INTS	{ print_desc(NULL, INTS); }
469*7c478bd9Sstevel@tonic-gate 		;
470*7c478bd9Sstevel@tonic-gate fsds		: FSDS	{ print_desc(NULL, FSDS); }
471*7c478bd9Sstevel@tonic-gate 		;
472*7c478bd9Sstevel@tonic-gate root		: ROOT	{ print_desc(NULL, ROOT); }
473*7c478bd9Sstevel@tonic-gate 		;
474*7c478bd9Sstevel@tonic-gate 
475*7c478bd9Sstevel@tonic-gate at		: ATTZ '=' expr	{ set_file(ATTZ, i_number << l2b, $3); }
476*7c478bd9Sstevel@tonic-gate 		| ATYE '=' expr	{ set_file(ATYE, i_number << l2b, $3); }
477*7c478bd9Sstevel@tonic-gate 		| ATMO '=' expr	{ set_file(ATMO, i_number << l2b, $3); }
478*7c478bd9Sstevel@tonic-gate 		| ATDA '=' expr	{ set_file(ATDA, i_number << l2b, $3); }
479*7c478bd9Sstevel@tonic-gate 		| ATHO '=' expr	{ set_file(ATHO, i_number << l2b, $3); }
480*7c478bd9Sstevel@tonic-gate 		| ATMI '=' expr	{ set_file(ATMI, i_number << l2b, $3); }
481*7c478bd9Sstevel@tonic-gate 		| ATSE '=' expr	{ set_file(ATSE, i_number << l2b, $3); }
482*7c478bd9Sstevel@tonic-gate 		| ATCE '=' expr	{ set_file(ATCE, i_number << l2b, $3); }
483*7c478bd9Sstevel@tonic-gate 		| ATHU '=' expr	{ set_file(ATHU, i_number << l2b, $3); }
484*7c478bd9Sstevel@tonic-gate 		| ATMIC '=' expr
485*7c478bd9Sstevel@tonic-gate 			{
486*7c478bd9Sstevel@tonic-gate 				set_file(ATMIC, i_number << l2b, $3);
487*7c478bd9Sstevel@tonic-gate 			}
488*7c478bd9Sstevel@tonic-gate 		;
489*7c478bd9Sstevel@tonic-gate 
490*7c478bd9Sstevel@tonic-gate ct		: CTTZ '=' expr	{ set_file(CTTZ, i_number << l2b, $3); }
491*7c478bd9Sstevel@tonic-gate 		| CTYE '=' expr	{ set_file(CTYE, i_number << l2b, $3); }
492*7c478bd9Sstevel@tonic-gate 		| CTMO '=' expr	{ set_file(CTMO, i_number << l2b, $3); }
493*7c478bd9Sstevel@tonic-gate 		| CTDA '=' expr	{ set_file(CTDA, i_number << l2b, $3); }
494*7c478bd9Sstevel@tonic-gate 		| CTHO '=' expr	{ set_file(CTHO, i_number << l2b, $3); }
495*7c478bd9Sstevel@tonic-gate 		| CTMI '=' expr	{ set_file(CTMI, i_number << l2b, $3); }
496*7c478bd9Sstevel@tonic-gate 		| CTSE '=' expr	{ set_file(CTSE, i_number << l2b, $3); }
497*7c478bd9Sstevel@tonic-gate 		| CTCE '=' expr	{ set_file(CTCE, i_number << l2b, $3); }
498*7c478bd9Sstevel@tonic-gate 		| CTHU '=' expr	{ set_file(CTHU, i_number << l2b, $3); }
499*7c478bd9Sstevel@tonic-gate 		| CTMIC '=' expr
500*7c478bd9Sstevel@tonic-gate 			{
501*7c478bd9Sstevel@tonic-gate 				set_file(CTMIC, i_number << l2b, $3);
502*7c478bd9Sstevel@tonic-gate 			}
503*7c478bd9Sstevel@tonic-gate 		;
504*7c478bd9Sstevel@tonic-gate 
505*7c478bd9Sstevel@tonic-gate mt		: MTTZ '=' expr	{ set_file(MTTZ, i_number << l2b, $3); }
506*7c478bd9Sstevel@tonic-gate 		| MTYE '=' expr	{ set_file(MTYE, i_number << l2b, $3); }
507*7c478bd9Sstevel@tonic-gate 		| MTMO '=' expr	{ set_file(MTMO, i_number << l2b, $3); }
508*7c478bd9Sstevel@tonic-gate 		| MTDA '=' expr	{ set_file(MTDA, i_number << l2b, $3); }
509*7c478bd9Sstevel@tonic-gate 		| MTHO '=' expr	{ set_file(MTHO, i_number << l2b, $3); }
510*7c478bd9Sstevel@tonic-gate 		| MTMI '=' expr	{ set_file(MTMI, i_number << l2b, $3); }
511*7c478bd9Sstevel@tonic-gate 		| MTSE '=' expr	{ set_file(MTSE, i_number << l2b, $3); }
512*7c478bd9Sstevel@tonic-gate 		| MTCE '=' expr	{ set_file(MTCE, i_number << l2b, $3); }
513*7c478bd9Sstevel@tonic-gate 		| MTHU '=' expr	{ set_file(MTHU, i_number << l2b, $3); }
514*7c478bd9Sstevel@tonic-gate 		| MTMIC '=' expr
515*7c478bd9Sstevel@tonic-gate 			{
516*7c478bd9Sstevel@tonic-gate 				set_file(MTMIC, i_number << l2b, $3);
517*7c478bd9Sstevel@tonic-gate 			}
518*7c478bd9Sstevel@tonic-gate 		;
519*7c478bd9Sstevel@tonic-gate 
520*7c478bd9Sstevel@tonic-gate 
521*7c478bd9Sstevel@tonic-gate gid		: GID '=' expr	{ set_file(GID, i_number << l2b, $3); }
522*7c478bd9Sstevel@tonic-gate 		;
523*7c478bd9Sstevel@tonic-gate 
524*7c478bd9Sstevel@tonic-gate ln		: LN '=' expr	{ set_file(LN, i_number << l2b, $3); }
525*7c478bd9Sstevel@tonic-gate 		;
526*7c478bd9Sstevel@tonic-gate 
527*7c478bd9Sstevel@tonic-gate md		: MD '=' expr	{ set_file(MD, i_number << l2b, $3); }
528*7c478bd9Sstevel@tonic-gate 		;
529*7c478bd9Sstevel@tonic-gate 
530*7c478bd9Sstevel@tonic-gate maj		: MAJ '=' expr	{ set_file(MAJ, i_number << l2b, $3); }
531*7c478bd9Sstevel@tonic-gate 		;
532*7c478bd9Sstevel@tonic-gate 
533*7c478bd9Sstevel@tonic-gate min		: MIO '=' expr	{ set_file(MIO, i_number << l2b, $3); }
534*7c478bd9Sstevel@tonic-gate 		;
535*7c478bd9Sstevel@tonic-gate 
536*7c478bd9Sstevel@tonic-gate nm		: NM '=' expr	{ set_file(NM, i_number << l2b, $3); }
537*7c478bd9Sstevel@tonic-gate 		;
538*7c478bd9Sstevel@tonic-gate 
539*7c478bd9Sstevel@tonic-gate sz		: SZ '=' expr	{ set_file(SZ, i_number << l2b, $3); }
540*7c478bd9Sstevel@tonic-gate 		;
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate uid		: UID '=' expr	{ set_file(UID, i_number << l2b, $3); }
543*7c478bd9Sstevel@tonic-gate 		;
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate uniq		: UNIQ '=' expr	{ set_file(UNIQ, i_number << l2b, $3); }
546*7c478bd9Sstevel@tonic-gate 		;
547*7c478bd9Sstevel@tonic-gate 
548*7c478bd9Sstevel@tonic-gate dump		: '/' WORD
549*7c478bd9Sstevel@tonic-gate 			{
550*7c478bd9Sstevel@tonic-gate 				if (strlen((char *)$2) != 1) {
551*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
552*7c478bd9Sstevel@tonic-gate 						gettext("Invalid command\n"));
553*7c478bd9Sstevel@tonic-gate 				} else {
554*7c478bd9Sstevel@tonic-gate 					dump_disk(value, count, $2);
555*7c478bd9Sstevel@tonic-gate 				}
556*7c478bd9Sstevel@tonic-gate 			}
557*7c478bd9Sstevel@tonic-gate 		| '?' WORD
558*7c478bd9Sstevel@tonic-gate 			{
559*7c478bd9Sstevel@tonic-gate 				if (strcmp((char *)$2, "i") == 0) {
560*7c478bd9Sstevel@tonic-gate 					if (verify_inode(value << l2b,
561*7c478bd9Sstevel@tonic-gate 							0) != 0) {
562*7c478bd9Sstevel@tonic-gate 						print_inode(value << l2b);
563*7c478bd9Sstevel@tonic-gate 						i_number = value;
564*7c478bd9Sstevel@tonic-gate 						last_op_type == TYPE_INODE;
565*7c478bd9Sstevel@tonic-gate 					}
566*7c478bd9Sstevel@tonic-gate 				} else if (strcmp((char *)$2, "d") == 0) {
567*7c478bd9Sstevel@tonic-gate 					if (verify_dent(i_number << l2b,
568*7c478bd9Sstevel@tonic-gate 							value) == 0) {
569*7c478bd9Sstevel@tonic-gate 						print_dent(i_number << l2b,
570*7c478bd9Sstevel@tonic-gate 							value);
571*7c478bd9Sstevel@tonic-gate 						d_entry = value;
572*7c478bd9Sstevel@tonic-gate 						last_op_type == TYPE_DIRENT;
573*7c478bd9Sstevel@tonic-gate 					}
574*7c478bd9Sstevel@tonic-gate 				} else {
575*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
576*7c478bd9Sstevel@tonic-gate 						gettext("Invalid command\n"));
577*7c478bd9Sstevel@tonic-gate 				}
578*7c478bd9Sstevel@tonic-gate 			}
579*7c478bd9Sstevel@tonic-gate 		;
580*7c478bd9Sstevel@tonic-gate 
581*7c478bd9Sstevel@tonic-gate texpr		: expr
582*7c478bd9Sstevel@tonic-gate 			{
583*7c478bd9Sstevel@tonic-gate 				value = $1;
584*7c478bd9Sstevel@tonic-gate 				count = 0;
585*7c478bd9Sstevel@tonic-gate 			}
586*7c478bd9Sstevel@tonic-gate 		| expr ',' expr
587*7c478bd9Sstevel@tonic-gate 			{
588*7c478bd9Sstevel@tonic-gate 				value = $1;
589*7c478bd9Sstevel@tonic-gate 				count = $3;
590*7c478bd9Sstevel@tonic-gate 			}
591*7c478bd9Sstevel@tonic-gate 		;
592*7c478bd9Sstevel@tonic-gate 
593*7c478bd9Sstevel@tonic-gate expr		: '+'
594*7c478bd9Sstevel@tonic-gate 			{
595*7c478bd9Sstevel@tonic-gate 				if (last_op_type == TYPE_INODE) {
596*7c478bd9Sstevel@tonic-gate 					if (verify_inode((i_number + 1) << l2b,
597*7c478bd9Sstevel@tonic-gate 							0) != 0) {
598*7c478bd9Sstevel@tonic-gate 						i_number ++;
599*7c478bd9Sstevel@tonic-gate 						print_inode(i_number << l2b);
600*7c478bd9Sstevel@tonic-gate 						$$ = i_number << l2b;
601*7c478bd9Sstevel@tonic-gate 					}
602*7c478bd9Sstevel@tonic-gate 				} else if (last_op_type == TYPE_DIRENT) {
603*7c478bd9Sstevel@tonic-gate 					if (verify_dent(i_number << l2b,
604*7c478bd9Sstevel@tonic-gate 							d_entry + 1) == 0) {
605*7c478bd9Sstevel@tonic-gate 						d_entry ++;
606*7c478bd9Sstevel@tonic-gate 						print_dent(i_number << l2b,
607*7c478bd9Sstevel@tonic-gate 							d_entry);
608*7c478bd9Sstevel@tonic-gate 					}
609*7c478bd9Sstevel@tonic-gate 				} else {
610*7c478bd9Sstevel@tonic-gate 					count = 0; $$ = value++;
611*7c478bd9Sstevel@tonic-gate 				}
612*7c478bd9Sstevel@tonic-gate 			}
613*7c478bd9Sstevel@tonic-gate 		| '-'
614*7c478bd9Sstevel@tonic-gate 			{
615*7c478bd9Sstevel@tonic-gate 				if (last_op_type == TYPE_INODE) {
616*7c478bd9Sstevel@tonic-gate 					if (verify_inode((i_number - 1) << l2b,
617*7c478bd9Sstevel@tonic-gate 							0) != 0) {
618*7c478bd9Sstevel@tonic-gate 						i_number --;
619*7c478bd9Sstevel@tonic-gate 						print_inode(i_number << l2b);
620*7c478bd9Sstevel@tonic-gate 						$$ = i_number << l2b;
621*7c478bd9Sstevel@tonic-gate 					}
622*7c478bd9Sstevel@tonic-gate 				} else if (last_op_type == TYPE_DIRENT) {
623*7c478bd9Sstevel@tonic-gate 					if (verify_dent(i_number << l2b,
624*7c478bd9Sstevel@tonic-gate 							d_entry - 1) == 0) {
625*7c478bd9Sstevel@tonic-gate 						d_entry --;
626*7c478bd9Sstevel@tonic-gate 						print_dent(i_number << l2b,
627*7c478bd9Sstevel@tonic-gate 							d_entry);
628*7c478bd9Sstevel@tonic-gate 					}
629*7c478bd9Sstevel@tonic-gate 				} else {
630*7c478bd9Sstevel@tonic-gate 					count = 0; $$ = value--;
631*7c478bd9Sstevel@tonic-gate 				}
632*7c478bd9Sstevel@tonic-gate 			}
633*7c478bd9Sstevel@tonic-gate 		| '-' WORD
634*7c478bd9Sstevel@tonic-gate 			{
635*7c478bd9Sstevel@tonic-gate 				uint64_t number;
636*7c478bd9Sstevel@tonic-gate 
637*7c478bd9Sstevel@tonic-gate 				if (check_and_get_int($2, &number) == 0) {
638*7c478bd9Sstevel@tonic-gate 					count = 0;
639*7c478bd9Sstevel@tonic-gate 					$$ = value - number;
640*7c478bd9Sstevel@tonic-gate 				}
641*7c478bd9Sstevel@tonic-gate 			}
642*7c478bd9Sstevel@tonic-gate 		| '+' WORD
643*7c478bd9Sstevel@tonic-gate 			{
644*7c478bd9Sstevel@tonic-gate 				uint64_t number;
645*7c478bd9Sstevel@tonic-gate 
646*7c478bd9Sstevel@tonic-gate 				if (check_and_get_int($2, &number) == 0) {
647*7c478bd9Sstevel@tonic-gate 					count = 0;
648*7c478bd9Sstevel@tonic-gate 					$$ = value + number;
649*7c478bd9Sstevel@tonic-gate 				}
650*7c478bd9Sstevel@tonic-gate 			}
651*7c478bd9Sstevel@tonic-gate 		| '*' WORD
652*7c478bd9Sstevel@tonic-gate 			{
653*7c478bd9Sstevel@tonic-gate 				uint64_t number;
654*7c478bd9Sstevel@tonic-gate 
655*7c478bd9Sstevel@tonic-gate 				if (check_and_get_int($2, &number) == 0) {
656*7c478bd9Sstevel@tonic-gate 					count = 0;
657*7c478bd9Sstevel@tonic-gate 					$$ = value * number;
658*7c478bd9Sstevel@tonic-gate 				}
659*7c478bd9Sstevel@tonic-gate 			}
660*7c478bd9Sstevel@tonic-gate 		| '%' WORD
661*7c478bd9Sstevel@tonic-gate 			{
662*7c478bd9Sstevel@tonic-gate 				uint64_t number;
663*7c478bd9Sstevel@tonic-gate 
664*7c478bd9Sstevel@tonic-gate 				if (check_and_get_int($2, &number) == 0) {
665*7c478bd9Sstevel@tonic-gate 					if (number == 0) {
666*7c478bd9Sstevel@tonic-gate 						fprintf(stdout,
667*7c478bd9Sstevel@tonic-gate 						gettext("Divide by zero ?\n"));
668*7c478bd9Sstevel@tonic-gate 					} else {
669*7c478bd9Sstevel@tonic-gate 						count = 0;
670*7c478bd9Sstevel@tonic-gate 						$$ = value / number;
671*7c478bd9Sstevel@tonic-gate 					}
672*7c478bd9Sstevel@tonic-gate 				}
673*7c478bd9Sstevel@tonic-gate 			}
674*7c478bd9Sstevel@tonic-gate 		| expr '-' expr		{ count = 0; $$ = $1 - $3; }
675*7c478bd9Sstevel@tonic-gate 		| expr '+' expr		{ count = 0; $$ = $1 + $3; }
676*7c478bd9Sstevel@tonic-gate 		| expr '*' expr		{ count = 0; $$ = $1 * $3; }
677*7c478bd9Sstevel@tonic-gate 		| expr '%' expr
678*7c478bd9Sstevel@tonic-gate 			{
679*7c478bd9Sstevel@tonic-gate 				if ($3 == 0) {
680*7c478bd9Sstevel@tonic-gate 					fprintf(stdout,
681*7c478bd9Sstevel@tonic-gate 						gettext("Divide by zero ?\n"));
682*7c478bd9Sstevel@tonic-gate 				} else {
683*7c478bd9Sstevel@tonic-gate 					$$ = $1 / $3;
684*7c478bd9Sstevel@tonic-gate 				}
685*7c478bd9Sstevel@tonic-gate 				count = 0;
686*7c478bd9Sstevel@tonic-gate 			}
687*7c478bd9Sstevel@tonic-gate 		| WORD
688*7c478bd9Sstevel@tonic-gate 			{
689*7c478bd9Sstevel@tonic-gate 				uint64_t number;
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate 				count = 0;
692*7c478bd9Sstevel@tonic-gate 				if (check_and_get_int($1, &number) == 0) {
693*7c478bd9Sstevel@tonic-gate 					$$ = number;
694*7c478bd9Sstevel@tonic-gate 				}
695*7c478bd9Sstevel@tonic-gate 			}
696*7c478bd9Sstevel@tonic-gate 		;
697*7c478bd9Sstevel@tonic-gate 
698*7c478bd9Sstevel@tonic-gate %%
699*7c478bd9Sstevel@tonic-gate 
700*7c478bd9Sstevel@tonic-gate int32_t
701*7c478bd9Sstevel@tonic-gate check_and_get_int(uint8_t *str, uint64_t *value)
702*7c478bd9Sstevel@tonic-gate {
703*7c478bd9Sstevel@tonic-gate 	int32_t length, cbase, index, cvalue;
704*7c478bd9Sstevel@tonic-gate 
705*7c478bd9Sstevel@tonic-gate 	*value = 0;
706*7c478bd9Sstevel@tonic-gate 	length = strlen((caddr_t)str);
707*7c478bd9Sstevel@tonic-gate 	/*
708*7c478bd9Sstevel@tonic-gate 	 * Decide on what base to be used
709*7c478bd9Sstevel@tonic-gate 	 * and strip off the base specifier
710*7c478bd9Sstevel@tonic-gate 	 */
711*7c478bd9Sstevel@tonic-gate 	if ((str[0] == '0') && (str[1] == 'x')) {
712*7c478bd9Sstevel@tonic-gate 		cbase = 0x10;
713*7c478bd9Sstevel@tonic-gate 		index = 2;
714*7c478bd9Sstevel@tonic-gate 	} else if ((str[0] == '0') && (str[1] == 't')) {
715*7c478bd9Sstevel@tonic-gate 		cbase = 0xa;
716*7c478bd9Sstevel@tonic-gate 		index = 2;
717*7c478bd9Sstevel@tonic-gate 	} else if (str[0] == '0') {
718*7c478bd9Sstevel@tonic-gate 		cbase = 0x8;
719*7c478bd9Sstevel@tonic-gate 		index = 1;
720*7c478bd9Sstevel@tonic-gate 	} else {
721*7c478bd9Sstevel@tonic-gate 		cbase = base;
722*7c478bd9Sstevel@tonic-gate 		index = 0;
723*7c478bd9Sstevel@tonic-gate 	}
724*7c478bd9Sstevel@tonic-gate 
725*7c478bd9Sstevel@tonic-gate 	/*
726*7c478bd9Sstevel@tonic-gate 	 * Verify if the string is integer
727*7c478bd9Sstevel@tonic-gate 	 * and convert to a binary value
728*7c478bd9Sstevel@tonic-gate 	 */
729*7c478bd9Sstevel@tonic-gate 	for ( ; index < length; index++) {
730*7c478bd9Sstevel@tonic-gate 		if (cbase == 0x8) {
731*7c478bd9Sstevel@tonic-gate 			if ((str[index] < '0') ||
732*7c478bd9Sstevel@tonic-gate 				(str[index] > '7')) {
733*7c478bd9Sstevel@tonic-gate 				fprintf(stdout,
734*7c478bd9Sstevel@tonic-gate 					gettext("Invalid Octal Number %s\n"),
735*7c478bd9Sstevel@tonic-gate 					str);
736*7c478bd9Sstevel@tonic-gate 				return (1);
737*7c478bd9Sstevel@tonic-gate 			}
738*7c478bd9Sstevel@tonic-gate 			cvalue = str[index] - '0';
739*7c478bd9Sstevel@tonic-gate 		} else if (cbase == 0xa) {
740*7c478bd9Sstevel@tonic-gate 			if ((str[index] < '0') ||
741*7c478bd9Sstevel@tonic-gate 				(str[index] > '9' )) {
742*7c478bd9Sstevel@tonic-gate 				fprintf(stdout,
743*7c478bd9Sstevel@tonic-gate 					gettext("Invalid Decimal Number %s\n"),
744*7c478bd9Sstevel@tonic-gate 					str);
745*7c478bd9Sstevel@tonic-gate 				return (1);
746*7c478bd9Sstevel@tonic-gate 			}
747*7c478bd9Sstevel@tonic-gate 			cvalue = str[index] - '0';
748*7c478bd9Sstevel@tonic-gate 		} else {
749*7c478bd9Sstevel@tonic-gate 			if ((str[index] >= '0') &&
750*7c478bd9Sstevel@tonic-gate 					(str[index] <= '9')) {
751*7c478bd9Sstevel@tonic-gate 				cvalue = str[index] - '0';
752*7c478bd9Sstevel@tonic-gate 			} else if ((str[index] >= 'a') &&
753*7c478bd9Sstevel@tonic-gate 					(str[index] <= 'f')) {
754*7c478bd9Sstevel@tonic-gate 				cvalue = str[index] - 'a' + 10;
755*7c478bd9Sstevel@tonic-gate 			} else if ((str[index] >= 'A') &&
756*7c478bd9Sstevel@tonic-gate 					(str[index] <= 'F')) {
757*7c478bd9Sstevel@tonic-gate 				cvalue = str[index] - 'A' + 10;
758*7c478bd9Sstevel@tonic-gate 			} else {
759*7c478bd9Sstevel@tonic-gate 				fprintf(stdout,
760*7c478bd9Sstevel@tonic-gate 					gettext("Invalid Hex Number %s\n"),
761*7c478bd9Sstevel@tonic-gate 					str);
762*7c478bd9Sstevel@tonic-gate 				return (1);
763*7c478bd9Sstevel@tonic-gate 			}
764*7c478bd9Sstevel@tonic-gate 		}
765*7c478bd9Sstevel@tonic-gate 		*value = *value * cbase + cvalue;
766*7c478bd9Sstevel@tonic-gate 	}
767*7c478bd9Sstevel@tonic-gate 	return (0);
768*7c478bd9Sstevel@tonic-gate }
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate void print_prompt();
771*7c478bd9Sstevel@tonic-gate extern FILE *yyin;
772*7c478bd9Sstevel@tonic-gate 
773*7c478bd9Sstevel@tonic-gate void
774*7c478bd9Sstevel@tonic-gate print_prompt()
775*7c478bd9Sstevel@tonic-gate {
776*7c478bd9Sstevel@tonic-gate 	fprintf(stdout, gettext("%s"), prompt);
777*7c478bd9Sstevel@tonic-gate }
778*7c478bd9Sstevel@tonic-gate 
779*7c478bd9Sstevel@tonic-gate int32_t
780*7c478bd9Sstevel@tonic-gate run_fsdb()
781*7c478bd9Sstevel@tonic-gate {
782*7c478bd9Sstevel@tonic-gate 	yyin = stdin;
783*7c478bd9Sstevel@tonic-gate 	if (yyparse() != 0)
784*7c478bd9Sstevel@tonic-gate 		return (-1);
785*7c478bd9Sstevel@tonic-gate 	return 0;
786*7c478bd9Sstevel@tonic-gate }
787