xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/ptree.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * ptree.c -- routines for printing the prop tree
27*0Sstevel@tonic-gate  *
28*0Sstevel@tonic-gate  * this module contains routines to print portions of the parse tree.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <stdio.h>
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate #include <string.h>
36*0Sstevel@tonic-gate #include <ctype.h>
37*0Sstevel@tonic-gate #include "out.h"
38*0Sstevel@tonic-gate #include "stable.h"
39*0Sstevel@tonic-gate #include "literals.h"
40*0Sstevel@tonic-gate #include "lut.h"
41*0Sstevel@tonic-gate #include "tree.h"
42*0Sstevel@tonic-gate #include "ptree.h"
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate int Pchildgen;
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate #ifdef	FMAPLUGIN
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #include "itree.h"
49*0Sstevel@tonic-gate #include "eval.h"
50*0Sstevel@tonic-gate #include "config.h"
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate static void
53*0Sstevel@tonic-gate cp2num(struct config *cp, int *num)
54*0Sstevel@tonic-gate {
55*0Sstevel@tonic-gate 	config_getcompname(cp, NULL, num);
56*0Sstevel@tonic-gate }
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate #else
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate /*ARGSUSED*/
61*0Sstevel@tonic-gate static void
62*0Sstevel@tonic-gate cp2num(struct config *cp, int *num)
63*0Sstevel@tonic-gate {
64*0Sstevel@tonic-gate 	out(O_DIE, "ptree: non-NULL cp");
65*0Sstevel@tonic-gate }
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate #endif	/* FMAPLUGIN */
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate static int
70*0Sstevel@tonic-gate is_stmt(struct node *np)
71*0Sstevel@tonic-gate {
72*0Sstevel@tonic-gate 	switch (np->t) {
73*0Sstevel@tonic-gate 	case T_FAULT:
74*0Sstevel@tonic-gate 	case T_UPSET:
75*0Sstevel@tonic-gate 	case T_DEFECT:
76*0Sstevel@tonic-gate 	case T_ERROR:
77*0Sstevel@tonic-gate 	case T_EREPORT:
78*0Sstevel@tonic-gate 	case T_SERD:
79*0Sstevel@tonic-gate 	case T_PROP:
80*0Sstevel@tonic-gate 	case T_MASK:
81*0Sstevel@tonic-gate 	case T_ASRU:
82*0Sstevel@tonic-gate 	case T_FRU:
83*0Sstevel@tonic-gate 	case T_CONFIG:
84*0Sstevel@tonic-gate 		return (1);
85*0Sstevel@tonic-gate 		/*NOTREACHED*/
86*0Sstevel@tonic-gate 		break;
87*0Sstevel@tonic-gate 	default:
88*0Sstevel@tonic-gate 		break;
89*0Sstevel@tonic-gate 	}
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate 	return (0);
92*0Sstevel@tonic-gate }
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate void
95*0Sstevel@tonic-gate ptree(int flags, struct node *np, int no_iterators, int fileline)
96*0Sstevel@tonic-gate {
97*0Sstevel@tonic-gate 	if (np == NULL)
98*0Sstevel@tonic-gate 		return;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate 	switch (np->t) {
101*0Sstevel@tonic-gate 	case T_NOTHING:
102*0Sstevel@tonic-gate 		break;
103*0Sstevel@tonic-gate 	case T_NAME:
104*0Sstevel@tonic-gate 		out(flags|O_NONL, "%s", np->u.name.s);
105*0Sstevel@tonic-gate 		if (!no_iterators) {
106*0Sstevel@tonic-gate 			if (np->u.name.cp != NULL) {
107*0Sstevel@tonic-gate 				int num;
108*0Sstevel@tonic-gate 				cp2num(np->u.name.cp, &num);
109*0Sstevel@tonic-gate 				out(flags|O_NONL, "%d", num);
110*0Sstevel@tonic-gate 			} else if (np->u.name.it == IT_HORIZONTAL) {
111*0Sstevel@tonic-gate 				if (np->u.name.child == NULL ||
112*0Sstevel@tonic-gate 				    (np->u.name.childgen && !Pchildgen))
113*0Sstevel@tonic-gate 					out(flags|O_NONL, "<>");
114*0Sstevel@tonic-gate 				else {
115*0Sstevel@tonic-gate 					out(flags|O_NONL, "<");
116*0Sstevel@tonic-gate 					ptree(flags, np->u.name.child,
117*0Sstevel@tonic-gate 					    no_iterators, fileline);
118*0Sstevel@tonic-gate 					out(flags|O_NONL, ">");
119*0Sstevel@tonic-gate 				}
120*0Sstevel@tonic-gate 			} else if (np->u.name.child &&
121*0Sstevel@tonic-gate 			    (!np->u.name.childgen || Pchildgen)) {
122*0Sstevel@tonic-gate 				if (np->u.name.it != IT_NONE)
123*0Sstevel@tonic-gate 					out(flags|O_NONL, "[");
124*0Sstevel@tonic-gate 				ptree(flags, np->u.name.child, no_iterators,
125*0Sstevel@tonic-gate 				    fileline);
126*0Sstevel@tonic-gate 				if (np->u.name.it != IT_NONE)
127*0Sstevel@tonic-gate 					out(flags|O_NONL, "]");
128*0Sstevel@tonic-gate 			}
129*0Sstevel@tonic-gate 		}
130*0Sstevel@tonic-gate 		if (np->u.name.next) {
131*0Sstevel@tonic-gate 			ASSERT(np->u.name.next->t == T_NAME);
132*0Sstevel@tonic-gate 			if (np->u.name.it == IT_ENAME)
133*0Sstevel@tonic-gate 				out(flags|O_NONL, ".");
134*0Sstevel@tonic-gate 			else
135*0Sstevel@tonic-gate 				out(flags|O_NONL, "/");
136*0Sstevel@tonic-gate 			ptree(flags, np->u.name.next, no_iterators, fileline);
137*0Sstevel@tonic-gate 		}
138*0Sstevel@tonic-gate 		break;
139*0Sstevel@tonic-gate 	case T_TIMEVAL:
140*0Sstevel@tonic-gate 		ptree_timeval(flags, &np->u.ull);
141*0Sstevel@tonic-gate 		break;
142*0Sstevel@tonic-gate 	case T_NUM:
143*0Sstevel@tonic-gate 		out(flags|O_NONL, "%llu", np->u.ull);
144*0Sstevel@tonic-gate 		break;
145*0Sstevel@tonic-gate 	case T_QUOTE:
146*0Sstevel@tonic-gate 		out(flags|O_NONL, "\"%s\"", np->u.quote.s);
147*0Sstevel@tonic-gate 		break;
148*0Sstevel@tonic-gate 	case T_GLOBID:
149*0Sstevel@tonic-gate 		out(flags|O_NONL, "$%s", np->u.globid.s);
150*0Sstevel@tonic-gate 		break;
151*0Sstevel@tonic-gate 	case T_FUNC:
152*0Sstevel@tonic-gate 		out(flags|O_NONL, "%s(", np->u.func.s);
153*0Sstevel@tonic-gate 		ptree(flags, np->u.func.arglist, no_iterators, fileline);
154*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
155*0Sstevel@tonic-gate 		break;
156*0Sstevel@tonic-gate 	case T_NVPAIR:
157*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
158*0Sstevel@tonic-gate 		out(flags|O_NONL, "=");
159*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
160*0Sstevel@tonic-gate 		break;
161*0Sstevel@tonic-gate 	case T_EVENT:
162*0Sstevel@tonic-gate 		ptree(flags, np->u.event.ename, no_iterators, fileline);
163*0Sstevel@tonic-gate 		if (np->u.event.epname) {
164*0Sstevel@tonic-gate 			out(flags|O_NONL, "@");
165*0Sstevel@tonic-gate 			ptree(flags, np->u.event.epname,
166*0Sstevel@tonic-gate 			    no_iterators, fileline);
167*0Sstevel@tonic-gate 		}
168*0Sstevel@tonic-gate 		if (np->u.event.eexprlist) {
169*0Sstevel@tonic-gate 			out(flags|O_NONL, "{");
170*0Sstevel@tonic-gate 			ptree(flags, np->u.event.eexprlist,
171*0Sstevel@tonic-gate 			    no_iterators, fileline);
172*0Sstevel@tonic-gate 			out(flags|O_NONL, "}");
173*0Sstevel@tonic-gate 		}
174*0Sstevel@tonic-gate 		break;
175*0Sstevel@tonic-gate 	case T_ASSIGN:
176*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
177*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
178*0Sstevel@tonic-gate 		out(flags|O_NONL, "=");
179*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
180*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
181*0Sstevel@tonic-gate 		break;
182*0Sstevel@tonic-gate 	case T_NOT:
183*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
184*0Sstevel@tonic-gate 		out(flags|O_NONL, "!");
185*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
186*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
187*0Sstevel@tonic-gate 		break;
188*0Sstevel@tonic-gate 	case T_AND:
189*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
190*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
191*0Sstevel@tonic-gate 		out(flags|O_NONL, "&&");
192*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
193*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
194*0Sstevel@tonic-gate 		break;
195*0Sstevel@tonic-gate 	case T_OR:
196*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
197*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
198*0Sstevel@tonic-gate 		out(flags|O_NONL, "||");
199*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
200*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
201*0Sstevel@tonic-gate 		break;
202*0Sstevel@tonic-gate 	case T_EQ:
203*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
204*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
205*0Sstevel@tonic-gate 		out(flags|O_NONL, "==");
206*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
207*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
208*0Sstevel@tonic-gate 		break;
209*0Sstevel@tonic-gate 	case T_NE:
210*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
211*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
212*0Sstevel@tonic-gate 		out(flags|O_NONL, "!=");
213*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
214*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
215*0Sstevel@tonic-gate 		break;
216*0Sstevel@tonic-gate 	case T_SUB:
217*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
218*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
219*0Sstevel@tonic-gate 		out(flags|O_NONL, "-");
220*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
221*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
222*0Sstevel@tonic-gate 		break;
223*0Sstevel@tonic-gate 	case T_ADD:
224*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
225*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
226*0Sstevel@tonic-gate 		out(flags|O_NONL, "+");
227*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
228*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
229*0Sstevel@tonic-gate 		break;
230*0Sstevel@tonic-gate 	case T_MUL:
231*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
232*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
233*0Sstevel@tonic-gate 		out(flags|O_NONL, "*");
234*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
235*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
236*0Sstevel@tonic-gate 		break;
237*0Sstevel@tonic-gate 	case T_DIV:
238*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
239*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
240*0Sstevel@tonic-gate 		out(flags|O_NONL, "/");
241*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
242*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
243*0Sstevel@tonic-gate 		break;
244*0Sstevel@tonic-gate 	case T_MOD:
245*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
246*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
247*0Sstevel@tonic-gate 		out(flags|O_NONL, "%%");
248*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
249*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
250*0Sstevel@tonic-gate 		break;
251*0Sstevel@tonic-gate 	case T_LT:
252*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
253*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
254*0Sstevel@tonic-gate 		out(flags|O_NONL, "<");
255*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
256*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
257*0Sstevel@tonic-gate 		break;
258*0Sstevel@tonic-gate 	case T_LE:
259*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
260*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
261*0Sstevel@tonic-gate 		out(flags|O_NONL, "<=");
262*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
263*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
264*0Sstevel@tonic-gate 		break;
265*0Sstevel@tonic-gate 	case T_GT:
266*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
267*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
268*0Sstevel@tonic-gate 		out(flags|O_NONL, ">");
269*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
270*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
271*0Sstevel@tonic-gate 		break;
272*0Sstevel@tonic-gate 	case T_GE:
273*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
274*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
275*0Sstevel@tonic-gate 		out(flags|O_NONL, ">=");
276*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
277*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
278*0Sstevel@tonic-gate 		break;
279*0Sstevel@tonic-gate 	case T_BITNOT:
280*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
281*0Sstevel@tonic-gate 		out(flags|O_NONL, "~");
282*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
283*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
284*0Sstevel@tonic-gate 		break;
285*0Sstevel@tonic-gate 	case T_BITAND:
286*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
287*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
288*0Sstevel@tonic-gate 		out(flags|O_NONL, "&");
289*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
290*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
291*0Sstevel@tonic-gate 		break;
292*0Sstevel@tonic-gate 	case T_BITOR:
293*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
294*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
295*0Sstevel@tonic-gate 		out(flags|O_NONL, "|");
296*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
297*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
298*0Sstevel@tonic-gate 		break;
299*0Sstevel@tonic-gate 	case T_BITXOR:
300*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
301*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
302*0Sstevel@tonic-gate 		out(flags|O_NONL, "^");
303*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
304*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
305*0Sstevel@tonic-gate 		break;
306*0Sstevel@tonic-gate 	case T_LSHIFT:
307*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
308*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
309*0Sstevel@tonic-gate 		out(flags|O_NONL, "<<");
310*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
311*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
312*0Sstevel@tonic-gate 		break;
313*0Sstevel@tonic-gate 	case T_RSHIFT:
314*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
315*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
316*0Sstevel@tonic-gate 		out(flags|O_NONL, ">>");
317*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
318*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
319*0Sstevel@tonic-gate 		break;
320*0Sstevel@tonic-gate 	case T_CONDIF:
321*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
322*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
323*0Sstevel@tonic-gate 		out(flags|O_NONL, "?");
324*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
325*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
326*0Sstevel@tonic-gate 		break;
327*0Sstevel@tonic-gate 	case T_CONDELSE:
328*0Sstevel@tonic-gate 		out(flags|O_NONL, "(");
329*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
330*0Sstevel@tonic-gate 		out(flags|O_NONL, ":");
331*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
332*0Sstevel@tonic-gate 		out(flags|O_NONL, ")");
333*0Sstevel@tonic-gate 		break;
334*0Sstevel@tonic-gate 	case T_ARROW:
335*0Sstevel@tonic-gate 		ptree(flags, np->u.arrow.lhs, no_iterators, fileline);
336*0Sstevel@tonic-gate 		if (np->u.arrow.nnp) {
337*0Sstevel@tonic-gate 			out(flags|O_NONL, "(");
338*0Sstevel@tonic-gate 			ptree(flags, np->u.arrow.nnp, no_iterators, fileline);
339*0Sstevel@tonic-gate 			out(flags|O_NONL, ")");
340*0Sstevel@tonic-gate 		}
341*0Sstevel@tonic-gate 		out(flags|O_NONL, "->");
342*0Sstevel@tonic-gate 		if (np->u.arrow.knp) {
343*0Sstevel@tonic-gate 			out(flags|O_NONL, "(");
344*0Sstevel@tonic-gate 			ptree(flags, np->u.arrow.knp, no_iterators, fileline);
345*0Sstevel@tonic-gate 			out(flags|O_NONL, ")");
346*0Sstevel@tonic-gate 		}
347*0Sstevel@tonic-gate 		ptree(flags, np->u.arrow.rhs, no_iterators, fileline);
348*0Sstevel@tonic-gate 		break;
349*0Sstevel@tonic-gate 	case T_LIST:
350*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
351*0Sstevel@tonic-gate 		if (np->u.expr.left && np->u.expr.right &&
352*0Sstevel@tonic-gate 		    (np->u.expr.left->t != T_LIST ||
353*0Sstevel@tonic-gate 		    ! is_stmt(np->u.expr.right)))
354*0Sstevel@tonic-gate 			out(flags|O_NONL, ",");
355*0Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
356*0Sstevel@tonic-gate 		break;
357*0Sstevel@tonic-gate 	case T_FAULT:
358*0Sstevel@tonic-gate 	case T_UPSET:
359*0Sstevel@tonic-gate 	case T_DEFECT:
360*0Sstevel@tonic-gate 	case T_ERROR:
361*0Sstevel@tonic-gate 	case T_EREPORT:
362*0Sstevel@tonic-gate 		if (fileline)
363*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
364*0Sstevel@tonic-gate 		out(flags|O_NONL, "event ");
365*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
366*0Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
367*0Sstevel@tonic-gate 			out(flags|O_NONL, " ");
368*0Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
369*0Sstevel@tonic-gate 			    fileline);
370*0Sstevel@tonic-gate 		}
371*0Sstevel@tonic-gate 		out(flags, ";");
372*0Sstevel@tonic-gate 		break;
373*0Sstevel@tonic-gate 	case T_SERD:
374*0Sstevel@tonic-gate 		if (fileline)
375*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
376*0Sstevel@tonic-gate 		out(flags|O_NONL, "engine ");
377*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
378*0Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
379*0Sstevel@tonic-gate 			out(flags|O_NONL, " ");
380*0Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
381*0Sstevel@tonic-gate 			    fileline);
382*0Sstevel@tonic-gate 		} else if (np->u.stmt.lutp) {
383*0Sstevel@tonic-gate 			struct plut_wlk_data pd;
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 			pd.flags = flags;
386*0Sstevel@tonic-gate 			pd.first = 0;
387*0Sstevel@tonic-gate 
388*0Sstevel@tonic-gate 			lut_walk(np->u.stmt.lutp, ptree_plut, &pd);
389*0Sstevel@tonic-gate 		}
390*0Sstevel@tonic-gate 		out(flags, ";");
391*0Sstevel@tonic-gate 		break;
392*0Sstevel@tonic-gate 	case T_ASRU:
393*0Sstevel@tonic-gate 		if (fileline)
394*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
395*0Sstevel@tonic-gate 		out(flags|O_NONL, "asru ");
396*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
397*0Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
398*0Sstevel@tonic-gate 			out(flags|O_NONL, " ");
399*0Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
400*0Sstevel@tonic-gate 			    fileline);
401*0Sstevel@tonic-gate 		}
402*0Sstevel@tonic-gate 		out(flags, ";");
403*0Sstevel@tonic-gate 		break;
404*0Sstevel@tonic-gate 	case T_FRU:
405*0Sstevel@tonic-gate 		if (fileline)
406*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
407*0Sstevel@tonic-gate 		out(flags|O_NONL, "fru ");
408*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
409*0Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
410*0Sstevel@tonic-gate 			out(flags|O_NONL, " ");
411*0Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
412*0Sstevel@tonic-gate 			    fileline);
413*0Sstevel@tonic-gate 		}
414*0Sstevel@tonic-gate 		out(flags, ";");
415*0Sstevel@tonic-gate 		break;
416*0Sstevel@tonic-gate 	case T_CONFIG:
417*0Sstevel@tonic-gate 		if (fileline)
418*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
419*0Sstevel@tonic-gate 		out(flags|O_NONL, "config ");
420*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
421*0Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
422*0Sstevel@tonic-gate 			out(flags|O_NONL, " ");
423*0Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
424*0Sstevel@tonic-gate 				fileline);
425*0Sstevel@tonic-gate 		}
426*0Sstevel@tonic-gate 		out(flags, ";");
427*0Sstevel@tonic-gate 		break;
428*0Sstevel@tonic-gate 	case T_PROP:
429*0Sstevel@tonic-gate 		if (fileline)
430*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
431*0Sstevel@tonic-gate 		out(flags|O_NONL, "prop ");
432*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
433*0Sstevel@tonic-gate 		out(flags, ";");
434*0Sstevel@tonic-gate 		break;
435*0Sstevel@tonic-gate 	case T_MASK:
436*0Sstevel@tonic-gate 		if (fileline)
437*0Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
438*0Sstevel@tonic-gate 		out(flags|O_NONL, "mask ");
439*0Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
440*0Sstevel@tonic-gate 		out(flags, ";");
441*0Sstevel@tonic-gate 		break;
442*0Sstevel@tonic-gate 	default:
443*0Sstevel@tonic-gate 		out(O_DIE,
444*0Sstevel@tonic-gate 		    "internal error: ptree unexpected nodetype: %d", np->t);
445*0Sstevel@tonic-gate 		/*NOTREACHED*/
446*0Sstevel@tonic-gate 	}
447*0Sstevel@tonic-gate }
448*0Sstevel@tonic-gate 
449*0Sstevel@tonic-gate void
450*0Sstevel@tonic-gate ptree_plut(void *name, void *val, void *arg)
451*0Sstevel@tonic-gate {
452*0Sstevel@tonic-gate 	struct plut_wlk_data *pd = (struct plut_wlk_data *)arg;
453*0Sstevel@tonic-gate 	int c;
454*0Sstevel@tonic-gate 	static int indent;
455*0Sstevel@tonic-gate 
456*0Sstevel@tonic-gate 	indent++;
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate 	if (pd->first == 0)
459*0Sstevel@tonic-gate 		out(pd->flags, ",");
460*0Sstevel@tonic-gate 	else
461*0Sstevel@tonic-gate 		pd->first = 0;
462*0Sstevel@tonic-gate 
463*0Sstevel@tonic-gate 	for (c = indent; c > 0; c--)
464*0Sstevel@tonic-gate 		out(pd->flags|O_NONL, "\t");
465*0Sstevel@tonic-gate 	out(pd->flags|O_NONL, "%s", (char *)name);
466*0Sstevel@tonic-gate 
467*0Sstevel@tonic-gate 	out(pd->flags|O_NONL, "=");
468*0Sstevel@tonic-gate 	ptree(pd->flags, val, 0, 0);
469*0Sstevel@tonic-gate 
470*0Sstevel@tonic-gate 	indent--;
471*0Sstevel@tonic-gate }
472*0Sstevel@tonic-gate 
473*0Sstevel@tonic-gate void
474*0Sstevel@tonic-gate ptree_name(int flags, struct node *np)
475*0Sstevel@tonic-gate {
476*0Sstevel@tonic-gate 	ptree(flags, np, 1, 0);
477*0Sstevel@tonic-gate }
478*0Sstevel@tonic-gate 
479*0Sstevel@tonic-gate void
480*0Sstevel@tonic-gate ptree_name_iter(int flags, struct node *np)
481*0Sstevel@tonic-gate {
482*0Sstevel@tonic-gate 	ptree(flags, np, 0, 0);
483*0Sstevel@tonic-gate }
484*0Sstevel@tonic-gate 
485*0Sstevel@tonic-gate const char *
486*0Sstevel@tonic-gate ptree_nodetype2str(enum nodetype t)
487*0Sstevel@tonic-gate {
488*0Sstevel@tonic-gate 	static char buf[100];
489*0Sstevel@tonic-gate 
490*0Sstevel@tonic-gate 	switch (t) {
491*0Sstevel@tonic-gate 	case T_NOTHING: return L_T_NOTHING;
492*0Sstevel@tonic-gate 	case T_NAME: return L_T_NAME;
493*0Sstevel@tonic-gate 	case T_GLOBID: return L_T_GLOBID;
494*0Sstevel@tonic-gate 	case T_EVENT: return L_T_EVENT;
495*0Sstevel@tonic-gate 	case T_ENGINE: return L_T_ENGINE;
496*0Sstevel@tonic-gate 	case T_ASRU: return L_asru;
497*0Sstevel@tonic-gate 	case T_FRU: return L_fru;
498*0Sstevel@tonic-gate 	case T_CONFIG: return L_config;
499*0Sstevel@tonic-gate 	case T_TIMEVAL: return L_T_TIMEVAL;
500*0Sstevel@tonic-gate 	case T_NUM: return L_T_NUM;
501*0Sstevel@tonic-gate 	case T_QUOTE: return L_T_QUOTE;
502*0Sstevel@tonic-gate 	case T_FUNC: return L_T_FUNC;
503*0Sstevel@tonic-gate 	case T_NVPAIR: return L_T_NVPAIR;
504*0Sstevel@tonic-gate 	case T_ASSIGN: return L_T_ASSIGN;
505*0Sstevel@tonic-gate 	case T_CONDIF: return L_T_CONDIF;
506*0Sstevel@tonic-gate 	case T_CONDELSE: return L_T_CONDELSE;
507*0Sstevel@tonic-gate 	case T_NOT: return L_T_NOT;
508*0Sstevel@tonic-gate 	case T_AND: return L_T_AND;
509*0Sstevel@tonic-gate 	case T_OR: return L_T_OR;
510*0Sstevel@tonic-gate 	case T_EQ: return L_T_EQ;
511*0Sstevel@tonic-gate 	case T_NE: return L_T_NE;
512*0Sstevel@tonic-gate 	case T_SUB: return L_T_SUB;
513*0Sstevel@tonic-gate 	case T_ADD: return L_T_ADD;
514*0Sstevel@tonic-gate 	case T_MUL: return L_T_MUL;
515*0Sstevel@tonic-gate 	case T_DIV: return L_T_DIV;
516*0Sstevel@tonic-gate 	case T_MOD: return L_T_MOD;
517*0Sstevel@tonic-gate 	case T_LT: return L_T_LT;
518*0Sstevel@tonic-gate 	case T_LE: return L_T_LE;
519*0Sstevel@tonic-gate 	case T_GT: return L_T_GT;
520*0Sstevel@tonic-gate 	case T_GE: return L_T_GE;
521*0Sstevel@tonic-gate 	case T_BITAND: return L_T_BITAND;
522*0Sstevel@tonic-gate 	case T_BITOR: return L_T_BITOR;
523*0Sstevel@tonic-gate 	case T_BITXOR: return L_T_BITXOR;
524*0Sstevel@tonic-gate 	case T_BITNOT: return L_T_BITNOT;
525*0Sstevel@tonic-gate 	case T_LSHIFT: return L_T_LSHIFT;
526*0Sstevel@tonic-gate 	case T_RSHIFT: return L_T_RSHIFT;
527*0Sstevel@tonic-gate 	case T_ARROW: return L_T_ARROW;
528*0Sstevel@tonic-gate 	case T_LIST: return L_T_LIST;
529*0Sstevel@tonic-gate 	case T_FAULT: return L_fault;
530*0Sstevel@tonic-gate 	case T_UPSET: return L_upset;
531*0Sstevel@tonic-gate 	case T_DEFECT: return L_defect;
532*0Sstevel@tonic-gate 	case T_ERROR: return L_error;
533*0Sstevel@tonic-gate 	case T_EREPORT: return L_ereport;
534*0Sstevel@tonic-gate 	case T_SERD: return L_serd;
535*0Sstevel@tonic-gate 	case T_PROP: return L_prop;
536*0Sstevel@tonic-gate 	case T_MASK: return L_mask;
537*0Sstevel@tonic-gate 	default:
538*0Sstevel@tonic-gate 		(void) sprintf(buf, "[unexpected nodetype: %d]", t);
539*0Sstevel@tonic-gate 		return (buf);
540*0Sstevel@tonic-gate 	}
541*0Sstevel@tonic-gate }
542*0Sstevel@tonic-gate 
543*0Sstevel@tonic-gate const char *
544*0Sstevel@tonic-gate ptree_nametype2str(enum nametype t)
545*0Sstevel@tonic-gate {
546*0Sstevel@tonic-gate 	static char buf[100];
547*0Sstevel@tonic-gate 
548*0Sstevel@tonic-gate 	switch (t) {
549*0Sstevel@tonic-gate 	case N_UNSPEC: return L_N_UNSPEC;
550*0Sstevel@tonic-gate 	case N_FAULT: return L_fault;
551*0Sstevel@tonic-gate 	case N_DEFECT: return L_defect;
552*0Sstevel@tonic-gate 	case N_UPSET: return L_upset;
553*0Sstevel@tonic-gate 	case N_ERROR: return L_error;
554*0Sstevel@tonic-gate 	case N_EREPORT: return L_ereport;
555*0Sstevel@tonic-gate 	case N_SERD: return L_serd;
556*0Sstevel@tonic-gate 	default:
557*0Sstevel@tonic-gate 		(void) sprintf(buf, "[unexpected nametype: %d]", t);
558*0Sstevel@tonic-gate 		return (buf);
559*0Sstevel@tonic-gate 	}
560*0Sstevel@tonic-gate }
561*0Sstevel@tonic-gate 
562*0Sstevel@tonic-gate struct printer_info {
563*0Sstevel@tonic-gate 	enum nodetype t;
564*0Sstevel@tonic-gate 	const char *pat;
565*0Sstevel@tonic-gate 	int flags;
566*0Sstevel@tonic-gate };
567*0Sstevel@tonic-gate 
568*0Sstevel@tonic-gate static int
569*0Sstevel@tonic-gate name_pattern_match(struct node *np, const char *pat)
570*0Sstevel@tonic-gate {
571*0Sstevel@tonic-gate 	const char *cend;	/* first character not in component in pat */
572*0Sstevel@tonic-gate 
573*0Sstevel@tonic-gate 	if (pat == NULL || *pat == '\0')
574*0Sstevel@tonic-gate 		return (1);	/* either no pattern or we've matched it all */
575*0Sstevel@tonic-gate 
576*0Sstevel@tonic-gate 	if (np == NULL)
577*0Sstevel@tonic-gate 		return (0);	/* there's more pattern and nothing to match */
578*0Sstevel@tonic-gate 
579*0Sstevel@tonic-gate 	ASSERTeq(np->t, T_NAME, ptree_nodetype2str);
580*0Sstevel@tonic-gate 
581*0Sstevel@tonic-gate 	cend = strchr(pat, '/');
582*0Sstevel@tonic-gate 	if (cend == NULL)
583*0Sstevel@tonic-gate 		cend = strchr(pat, '.');
584*0Sstevel@tonic-gate 	if (cend == NULL)
585*0Sstevel@tonic-gate 		cend = &pat[strlen(pat)];
586*0Sstevel@tonic-gate 
587*0Sstevel@tonic-gate 	while (np) {
588*0Sstevel@tonic-gate 		const char *s = np->u.name.s;
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate 		while (*s) {
591*0Sstevel@tonic-gate 			const char *cstart = pat;
592*0Sstevel@tonic-gate 
593*0Sstevel@tonic-gate 			while (*s && tolower(*s) == tolower(*cstart)) {
594*0Sstevel@tonic-gate 				cstart++;
595*0Sstevel@tonic-gate 				if (cstart == cend) {
596*0Sstevel@tonic-gate 					/* component matched */
597*0Sstevel@tonic-gate 					while (*cend == '/')
598*0Sstevel@tonic-gate 						cend++;
599*0Sstevel@tonic-gate 					return
600*0Sstevel@tonic-gate 					    name_pattern_match(np->u.name.next,
601*0Sstevel@tonic-gate 					    cend);
602*0Sstevel@tonic-gate 				}
603*0Sstevel@tonic-gate 				s++;
604*0Sstevel@tonic-gate 			}
605*0Sstevel@tonic-gate 			if (*s)
606*0Sstevel@tonic-gate 				s++;
607*0Sstevel@tonic-gate 		}
608*0Sstevel@tonic-gate 		np = np->u.name.next;
609*0Sstevel@tonic-gate 	}
610*0Sstevel@tonic-gate 	return (0);
611*0Sstevel@tonic-gate }
612*0Sstevel@tonic-gate 
613*0Sstevel@tonic-gate static int
614*0Sstevel@tonic-gate name_pattern_match_in_subtree(struct node *np, const char *pat)
615*0Sstevel@tonic-gate {
616*0Sstevel@tonic-gate 	if (pat == NULL || *pat == '\0')
617*0Sstevel@tonic-gate 		return (1);
618*0Sstevel@tonic-gate 
619*0Sstevel@tonic-gate 	if (np == NULL)
620*0Sstevel@tonic-gate 		return (0);
621*0Sstevel@tonic-gate 
622*0Sstevel@tonic-gate 	if (np->t == T_NAME)
623*0Sstevel@tonic-gate 		return (name_pattern_match(np, pat));
624*0Sstevel@tonic-gate 	else if (np->t == T_EVENT)
625*0Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.event.ename, pat) ||
626*0Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.event.epname, pat) ||
627*0Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.event.eexprlist, pat));
628*0Sstevel@tonic-gate 	else if (np->t == T_ARROW)
629*0Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.arrow.lhs, pat) ||
630*0Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.arrow.rhs, pat));
631*0Sstevel@tonic-gate 	else if (np->t == T_ASSIGN ||
632*0Sstevel@tonic-gate 			np->t == T_CONDIF ||
633*0Sstevel@tonic-gate 			np->t == T_CONDELSE ||
634*0Sstevel@tonic-gate 			np->t == T_NOT ||
635*0Sstevel@tonic-gate 			np->t == T_AND ||
636*0Sstevel@tonic-gate 			np->t == T_OR ||
637*0Sstevel@tonic-gate 			np->t == T_EQ ||
638*0Sstevel@tonic-gate 			np->t == T_NE ||
639*0Sstevel@tonic-gate 			np->t == T_SUB ||
640*0Sstevel@tonic-gate 			np->t == T_ADD ||
641*0Sstevel@tonic-gate 			np->t == T_MUL ||
642*0Sstevel@tonic-gate 			np->t == T_DIV ||
643*0Sstevel@tonic-gate 			np->t == T_MOD ||
644*0Sstevel@tonic-gate 			np->t == T_LT ||
645*0Sstevel@tonic-gate 			np->t == T_LE ||
646*0Sstevel@tonic-gate 			np->t == T_GT ||
647*0Sstevel@tonic-gate 			np->t == T_GE ||
648*0Sstevel@tonic-gate 			np->t == T_BITAND ||
649*0Sstevel@tonic-gate 			np->t == T_BITOR ||
650*0Sstevel@tonic-gate 			np->t == T_BITXOR ||
651*0Sstevel@tonic-gate 			np->t == T_BITNOT ||
652*0Sstevel@tonic-gate 			np->t == T_LSHIFT ||
653*0Sstevel@tonic-gate 			np->t == T_RSHIFT ||
654*0Sstevel@tonic-gate 			np->t == T_LIST) {
655*0Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.expr.left, pat) ||
656*0Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.expr.right, pat));
657*0Sstevel@tonic-gate 	} else if (np->t == T_FUNC) {
658*0Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.func.arglist, pat));
659*0Sstevel@tonic-gate 	}
660*0Sstevel@tonic-gate 	return (0);
661*0Sstevel@tonic-gate }
662*0Sstevel@tonic-gate 
663*0Sstevel@tonic-gate static void
664*0Sstevel@tonic-gate byname_printer(struct node *lhs, struct node *rhs, void *arg)
665*0Sstevel@tonic-gate {
666*0Sstevel@tonic-gate 	struct printer_info *infop = (struct printer_info *)arg;
667*0Sstevel@tonic-gate 
668*0Sstevel@tonic-gate 	if (infop->t != T_NOTHING && rhs->t != infop->t)
669*0Sstevel@tonic-gate 		return;
670*0Sstevel@tonic-gate 	if (!name_pattern_match(lhs, infop->pat))
671*0Sstevel@tonic-gate 		return;
672*0Sstevel@tonic-gate 	ptree(infop->flags, rhs, 0, 0);
673*0Sstevel@tonic-gate }
674*0Sstevel@tonic-gate 
675*0Sstevel@tonic-gate static void
676*0Sstevel@tonic-gate ptree_type_pattern(int flags, enum nodetype t, const char *pat)
677*0Sstevel@tonic-gate {
678*0Sstevel@tonic-gate 	struct printer_info info;
679*0Sstevel@tonic-gate 	struct node *np;
680*0Sstevel@tonic-gate 
681*0Sstevel@tonic-gate 	info.flags = flags;
682*0Sstevel@tonic-gate 	info.pat = pat;
683*0Sstevel@tonic-gate 	info.t = t;
684*0Sstevel@tonic-gate 
685*0Sstevel@tonic-gate 	switch (t) {
686*0Sstevel@tonic-gate 	case T_FAULT:
687*0Sstevel@tonic-gate 		lut_walk(Faults, (lut_cb)byname_printer, (void *)&info);
688*0Sstevel@tonic-gate 		return;
689*0Sstevel@tonic-gate 	case T_UPSET:
690*0Sstevel@tonic-gate 		lut_walk(Upsets, (lut_cb)byname_printer, (void *)&info);
691*0Sstevel@tonic-gate 		return;
692*0Sstevel@tonic-gate 	case T_DEFECT:
693*0Sstevel@tonic-gate 		lut_walk(Defects, (lut_cb)byname_printer, (void *)&info);
694*0Sstevel@tonic-gate 		return;
695*0Sstevel@tonic-gate 	case T_ERROR:
696*0Sstevel@tonic-gate 		lut_walk(Errors, (lut_cb)byname_printer, (void *)&info);
697*0Sstevel@tonic-gate 		return;
698*0Sstevel@tonic-gate 	case T_EREPORT:
699*0Sstevel@tonic-gate 		lut_walk(Ereports, (lut_cb)byname_printer, (void *)&info);
700*0Sstevel@tonic-gate 		return;
701*0Sstevel@tonic-gate 	case T_SERD:
702*0Sstevel@tonic-gate 		lut_walk(SERDs, (lut_cb)byname_printer, (void *)&info);
703*0Sstevel@tonic-gate 		return;
704*0Sstevel@tonic-gate 	case T_ASRU:
705*0Sstevel@tonic-gate 		lut_walk(ASRUs, (lut_cb)byname_printer, (void *)&info);
706*0Sstevel@tonic-gate 		return;
707*0Sstevel@tonic-gate 	case T_FRU:
708*0Sstevel@tonic-gate 		lut_walk(FRUs, (lut_cb)byname_printer, (void *)&info);
709*0Sstevel@tonic-gate 		return;
710*0Sstevel@tonic-gate 	case T_CONFIG:
711*0Sstevel@tonic-gate 		lut_walk(Configs, (lut_cb)byname_printer, (void *)&info);
712*0Sstevel@tonic-gate 		return;
713*0Sstevel@tonic-gate 	case T_PROP:
714*0Sstevel@tonic-gate 		for (np = Props; np; np = np->u.stmt.next)
715*0Sstevel@tonic-gate 			if (name_pattern_match_in_subtree(np->u.stmt.np, pat))
716*0Sstevel@tonic-gate 				ptree(flags, np, 0, 0);
717*0Sstevel@tonic-gate 		return;
718*0Sstevel@tonic-gate 	case T_MASK:
719*0Sstevel@tonic-gate 		for (np = Masks; np; np = np->u.stmt.next)
720*0Sstevel@tonic-gate 			if (name_pattern_match_in_subtree(np->u.stmt.np, pat))
721*0Sstevel@tonic-gate 				ptree(flags, np, 0, 0);
722*0Sstevel@tonic-gate 		return;
723*0Sstevel@tonic-gate 	default:
724*0Sstevel@tonic-gate 		ptree(flags, tree_root(NULL), 0, 0);
725*0Sstevel@tonic-gate 	}
726*0Sstevel@tonic-gate }
727*0Sstevel@tonic-gate 
728*0Sstevel@tonic-gate void
729*0Sstevel@tonic-gate ptree_all(int flags, const char *pat)
730*0Sstevel@tonic-gate {
731*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_NOTHING, pat);
732*0Sstevel@tonic-gate }
733*0Sstevel@tonic-gate 
734*0Sstevel@tonic-gate void
735*0Sstevel@tonic-gate ptree_fault(int flags, const char *pat)
736*0Sstevel@tonic-gate {
737*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_FAULT, pat);
738*0Sstevel@tonic-gate }
739*0Sstevel@tonic-gate 
740*0Sstevel@tonic-gate void
741*0Sstevel@tonic-gate ptree_upset(int flags, const char *pat)
742*0Sstevel@tonic-gate {
743*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_UPSET, pat);
744*0Sstevel@tonic-gate }
745*0Sstevel@tonic-gate 
746*0Sstevel@tonic-gate void
747*0Sstevel@tonic-gate ptree_defect(int flags, const char *pat)
748*0Sstevel@tonic-gate {
749*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_DEFECT, pat);
750*0Sstevel@tonic-gate }
751*0Sstevel@tonic-gate 
752*0Sstevel@tonic-gate void
753*0Sstevel@tonic-gate ptree_error(int flags, const char *pat)
754*0Sstevel@tonic-gate {
755*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_ERROR, pat);
756*0Sstevel@tonic-gate }
757*0Sstevel@tonic-gate 
758*0Sstevel@tonic-gate void
759*0Sstevel@tonic-gate ptree_ereport(int flags, const char *pat)
760*0Sstevel@tonic-gate {
761*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_EREPORT, pat);
762*0Sstevel@tonic-gate }
763*0Sstevel@tonic-gate 
764*0Sstevel@tonic-gate void
765*0Sstevel@tonic-gate ptree_serd(int flags, const char *pat)
766*0Sstevel@tonic-gate {
767*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_SERD, pat);
768*0Sstevel@tonic-gate }
769*0Sstevel@tonic-gate 
770*0Sstevel@tonic-gate void
771*0Sstevel@tonic-gate ptree_asru(int flags, const char *pat)
772*0Sstevel@tonic-gate {
773*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_ASRU, pat);
774*0Sstevel@tonic-gate }
775*0Sstevel@tonic-gate 
776*0Sstevel@tonic-gate void
777*0Sstevel@tonic-gate ptree_fru(int flags, const char *pat)
778*0Sstevel@tonic-gate {
779*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_FRU, pat);
780*0Sstevel@tonic-gate }
781*0Sstevel@tonic-gate 
782*0Sstevel@tonic-gate void
783*0Sstevel@tonic-gate ptree_prop(int flags, const char *pat)
784*0Sstevel@tonic-gate {
785*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_PROP, pat);
786*0Sstevel@tonic-gate }
787*0Sstevel@tonic-gate 
788*0Sstevel@tonic-gate void
789*0Sstevel@tonic-gate ptree_mask(int flags, const char *pat)
790*0Sstevel@tonic-gate {
791*0Sstevel@tonic-gate 	ptree_type_pattern(flags, T_MASK, pat);
792*0Sstevel@tonic-gate }
793*0Sstevel@tonic-gate 
794*0Sstevel@tonic-gate void
795*0Sstevel@tonic-gate ptree_timeval(int flags, unsigned long long *ullp)
796*0Sstevel@tonic-gate {
797*0Sstevel@tonic-gate 	unsigned long long val;
798*0Sstevel@tonic-gate 
799*0Sstevel@tonic-gate #define	NOREMAINDER(den, num, val) (((val) = ((den) / (num))) * (num) == (den))
800*0Sstevel@tonic-gate 	if (*ullp == 0)
801*0Sstevel@tonic-gate 		out(flags|O_NONL, "0us");
802*0Sstevel@tonic-gate 	else if (*ullp >= TIMEVAL_EVENTUALLY)
803*0Sstevel@tonic-gate 		out(flags|O_NONL, "infinity");
804*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*365, val))
805*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluyear%s", val, (val == 1) ? "" : "s");
806*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*30, val))
807*0Sstevel@tonic-gate 		out(flags|O_NONL, "%llumonth%s", val, (val == 1) ? "" : "s");
808*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*7, val))
809*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluweek%s", val, (val == 1) ? "" : "s");
810*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24, val))
811*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluday%s", val, (val == 1) ? "" : "s");
812*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60, val))
813*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluhour%s", val, (val == 1) ? "" : "s");
814*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60, val))
815*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluminute%s", val, (val == 1) ? "" : "s");
816*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL, val))
817*0Sstevel@tonic-gate 		out(flags|O_NONL, "%llusecond%s", val, (val == 1) ? "" : "s");
818*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000ULL, val))
819*0Sstevel@tonic-gate 		out(flags|O_NONL, "%llums", val);
820*0Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000ULL, val))
821*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluus", val);
822*0Sstevel@tonic-gate 	else
823*0Sstevel@tonic-gate 		out(flags|O_NONL, "%lluns", *ullp);
824*0Sstevel@tonic-gate }
825