xref: /titanic_50/usr/src/cmd/fm/eversholt/common/ptree.c (revision 7aec1d6e253b21f9e9b7ef68b4d81ab9859b51fe)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*7aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  * ptree.c -- routines for printing the prop tree
277c478bd9Sstevel@tonic-gate  *
287c478bd9Sstevel@tonic-gate  * this module contains routines to print portions of the parse tree.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <ctype.h>
377c478bd9Sstevel@tonic-gate #include "out.h"
387c478bd9Sstevel@tonic-gate #include "stable.h"
397c478bd9Sstevel@tonic-gate #include "literals.h"
407c478bd9Sstevel@tonic-gate #include "lut.h"
417c478bd9Sstevel@tonic-gate #include "tree.h"
427c478bd9Sstevel@tonic-gate #include "ptree.h"
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate int Pchildgen;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	FMAPLUGIN
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include "itree.h"
497c478bd9Sstevel@tonic-gate #include "eval.h"
507c478bd9Sstevel@tonic-gate #include "config.h"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static void
cp2num(struct config * cp,int * num)537c478bd9Sstevel@tonic-gate cp2num(struct config *cp, int *num)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	config_getcompname(cp, NULL, num);
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #else
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*ARGSUSED*/
617c478bd9Sstevel@tonic-gate static void
cp2num(struct config * cp,int * num)627c478bd9Sstevel@tonic-gate cp2num(struct config *cp, int *num)
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate 	out(O_DIE, "ptree: non-NULL cp");
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #endif	/* FMAPLUGIN */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static int
is_stmt(struct node * np)707c478bd9Sstevel@tonic-gate is_stmt(struct node *np)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	switch (np->t) {
737c478bd9Sstevel@tonic-gate 	case T_FAULT:
747c478bd9Sstevel@tonic-gate 	case T_UPSET:
757c478bd9Sstevel@tonic-gate 	case T_DEFECT:
767c478bd9Sstevel@tonic-gate 	case T_ERROR:
777c478bd9Sstevel@tonic-gate 	case T_EREPORT:
787c478bd9Sstevel@tonic-gate 	case T_SERD:
79*7aec1d6eScindi 	case T_STAT:
807c478bd9Sstevel@tonic-gate 	case T_PROP:
817c478bd9Sstevel@tonic-gate 	case T_MASK:
827c478bd9Sstevel@tonic-gate 	case T_ASRU:
837c478bd9Sstevel@tonic-gate 	case T_FRU:
847c478bd9Sstevel@tonic-gate 	case T_CONFIG:
857c478bd9Sstevel@tonic-gate 		return (1);
867c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
877c478bd9Sstevel@tonic-gate 		break;
887c478bd9Sstevel@tonic-gate 	default:
897c478bd9Sstevel@tonic-gate 		break;
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	return (0);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate void
ptree(int flags,struct node * np,int no_iterators,int fileline)967c478bd9Sstevel@tonic-gate ptree(int flags, struct node *np, int no_iterators, int fileline)
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate 	if (np == NULL)
997c478bd9Sstevel@tonic-gate 		return;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	switch (np->t) {
1027c478bd9Sstevel@tonic-gate 	case T_NOTHING:
1037c478bd9Sstevel@tonic-gate 		break;
1047c478bd9Sstevel@tonic-gate 	case T_NAME:
1057c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%s", np->u.name.s);
1067c478bd9Sstevel@tonic-gate 		if (!no_iterators) {
1077c478bd9Sstevel@tonic-gate 			if (np->u.name.cp != NULL) {
1087c478bd9Sstevel@tonic-gate 				int num;
1097c478bd9Sstevel@tonic-gate 				cp2num(np->u.name.cp, &num);
1107c478bd9Sstevel@tonic-gate 				out(flags|O_NONL, "%d", num);
1117c478bd9Sstevel@tonic-gate 			} else if (np->u.name.it == IT_HORIZONTAL) {
1127c478bd9Sstevel@tonic-gate 				if (np->u.name.child == NULL ||
1137c478bd9Sstevel@tonic-gate 				    (np->u.name.childgen && !Pchildgen))
1147c478bd9Sstevel@tonic-gate 					out(flags|O_NONL, "<>");
1157c478bd9Sstevel@tonic-gate 				else {
1167c478bd9Sstevel@tonic-gate 					out(flags|O_NONL, "<");
1177c478bd9Sstevel@tonic-gate 					ptree(flags, np->u.name.child,
1187c478bd9Sstevel@tonic-gate 					    no_iterators, fileline);
1197c478bd9Sstevel@tonic-gate 					out(flags|O_NONL, ">");
1207c478bd9Sstevel@tonic-gate 				}
1217c478bd9Sstevel@tonic-gate 			} else if (np->u.name.child &&
1227c478bd9Sstevel@tonic-gate 			    (!np->u.name.childgen || Pchildgen)) {
1237c478bd9Sstevel@tonic-gate 				if (np->u.name.it != IT_NONE)
1247c478bd9Sstevel@tonic-gate 					out(flags|O_NONL, "[");
1257c478bd9Sstevel@tonic-gate 				ptree(flags, np->u.name.child, no_iterators,
1267c478bd9Sstevel@tonic-gate 				    fileline);
1277c478bd9Sstevel@tonic-gate 				if (np->u.name.it != IT_NONE)
1287c478bd9Sstevel@tonic-gate 					out(flags|O_NONL, "]");
1297c478bd9Sstevel@tonic-gate 			}
1307c478bd9Sstevel@tonic-gate 		}
1317c478bd9Sstevel@tonic-gate 		if (np->u.name.next) {
1327c478bd9Sstevel@tonic-gate 			ASSERT(np->u.name.next->t == T_NAME);
1337c478bd9Sstevel@tonic-gate 			if (np->u.name.it == IT_ENAME)
1347c478bd9Sstevel@tonic-gate 				out(flags|O_NONL, ".");
1357c478bd9Sstevel@tonic-gate 			else
1367c478bd9Sstevel@tonic-gate 				out(flags|O_NONL, "/");
1377c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.name.next, no_iterators, fileline);
1387c478bd9Sstevel@tonic-gate 		}
1397c478bd9Sstevel@tonic-gate 		break;
1407c478bd9Sstevel@tonic-gate 	case T_TIMEVAL:
1417c478bd9Sstevel@tonic-gate 		ptree_timeval(flags, &np->u.ull);
1427c478bd9Sstevel@tonic-gate 		break;
1437c478bd9Sstevel@tonic-gate 	case T_NUM:
1447c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%llu", np->u.ull);
1457c478bd9Sstevel@tonic-gate 		break;
1467c478bd9Sstevel@tonic-gate 	case T_QUOTE:
1477c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "\"%s\"", np->u.quote.s);
1487c478bd9Sstevel@tonic-gate 		break;
1497c478bd9Sstevel@tonic-gate 	case T_GLOBID:
1507c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "$%s", np->u.globid.s);
1517c478bd9Sstevel@tonic-gate 		break;
1527c478bd9Sstevel@tonic-gate 	case T_FUNC:
1537c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%s(", np->u.func.s);
1547c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.func.arglist, no_iterators, fileline);
1557c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
1567c478bd9Sstevel@tonic-gate 		break;
1577c478bd9Sstevel@tonic-gate 	case T_NVPAIR:
1587c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
1597c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "=");
1607c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
1617c478bd9Sstevel@tonic-gate 		break;
1627c478bd9Sstevel@tonic-gate 	case T_EVENT:
1637c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.event.ename, no_iterators, fileline);
1647c478bd9Sstevel@tonic-gate 		if (np->u.event.epname) {
1657c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, "@");
1667c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.event.epname,
1677c478bd9Sstevel@tonic-gate 			    no_iterators, fileline);
1687c478bd9Sstevel@tonic-gate 		}
1697c478bd9Sstevel@tonic-gate 		if (np->u.event.eexprlist) {
1707c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, "{");
1717c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.event.eexprlist,
1727c478bd9Sstevel@tonic-gate 			    no_iterators, fileline);
1737c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, "}");
1747c478bd9Sstevel@tonic-gate 		}
1757c478bd9Sstevel@tonic-gate 		break;
1767c478bd9Sstevel@tonic-gate 	case T_ASSIGN:
1777c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
1787c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
1797c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "=");
1807c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
1817c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
1827c478bd9Sstevel@tonic-gate 		break;
1837c478bd9Sstevel@tonic-gate 	case T_NOT:
1847c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
1857c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "!");
1867c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
1877c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
1887c478bd9Sstevel@tonic-gate 		break;
1897c478bd9Sstevel@tonic-gate 	case T_AND:
1907c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
1917c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
1927c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "&&");
1937c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
1947c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
1957c478bd9Sstevel@tonic-gate 		break;
1967c478bd9Sstevel@tonic-gate 	case T_OR:
1977c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
1987c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
1997c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "||");
2007c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2017c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2027c478bd9Sstevel@tonic-gate 		break;
2037c478bd9Sstevel@tonic-gate 	case T_EQ:
2047c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2057c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2067c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "==");
2077c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2087c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2097c478bd9Sstevel@tonic-gate 		break;
2107c478bd9Sstevel@tonic-gate 	case T_NE:
2117c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2127c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2137c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "!=");
2147c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2157c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2167c478bd9Sstevel@tonic-gate 		break;
2177c478bd9Sstevel@tonic-gate 	case T_SUB:
2187c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2197c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2207c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "-");
2217c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2227c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2237c478bd9Sstevel@tonic-gate 		break;
2247c478bd9Sstevel@tonic-gate 	case T_ADD:
2257c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2267c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2277c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "+");
2287c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2297c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2307c478bd9Sstevel@tonic-gate 		break;
2317c478bd9Sstevel@tonic-gate 	case T_MUL:
2327c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2337c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2347c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "*");
2357c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2367c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2377c478bd9Sstevel@tonic-gate 		break;
2387c478bd9Sstevel@tonic-gate 	case T_DIV:
2397c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2407c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2417c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "/");
2427c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2437c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2447c478bd9Sstevel@tonic-gate 		break;
2457c478bd9Sstevel@tonic-gate 	case T_MOD:
2467c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2477c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2487c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%%");
2497c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2507c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2517c478bd9Sstevel@tonic-gate 		break;
2527c478bd9Sstevel@tonic-gate 	case T_LT:
2537c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2547c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2557c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "<");
2567c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2577c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2587c478bd9Sstevel@tonic-gate 		break;
2597c478bd9Sstevel@tonic-gate 	case T_LE:
2607c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2617c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2627c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "<=");
2637c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2647c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2657c478bd9Sstevel@tonic-gate 		break;
2667c478bd9Sstevel@tonic-gate 	case T_GT:
2677c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2687c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2697c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ">");
2707c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2717c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2727c478bd9Sstevel@tonic-gate 		break;
2737c478bd9Sstevel@tonic-gate 	case T_GE:
2747c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2757c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2767c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ">=");
2777c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2787c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2797c478bd9Sstevel@tonic-gate 		break;
2807c478bd9Sstevel@tonic-gate 	case T_BITNOT:
2817c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2827c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "~");
2837c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2847c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2857c478bd9Sstevel@tonic-gate 		break;
2867c478bd9Sstevel@tonic-gate 	case T_BITAND:
2877c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2887c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2897c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "&");
2907c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2917c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2927c478bd9Sstevel@tonic-gate 		break;
2937c478bd9Sstevel@tonic-gate 	case T_BITOR:
2947c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
2957c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
2967c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "|");
2977c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
2987c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
2997c478bd9Sstevel@tonic-gate 		break;
3007c478bd9Sstevel@tonic-gate 	case T_BITXOR:
3017c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
3027c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
3037c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "^");
3047c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
3057c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
3067c478bd9Sstevel@tonic-gate 		break;
3077c478bd9Sstevel@tonic-gate 	case T_LSHIFT:
3087c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
3097c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
3107c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "<<");
3117c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
3127c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
3137c478bd9Sstevel@tonic-gate 		break;
3147c478bd9Sstevel@tonic-gate 	case T_RSHIFT:
3157c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
3167c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
3177c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ">>");
3187c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
3197c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
3207c478bd9Sstevel@tonic-gate 		break;
3217c478bd9Sstevel@tonic-gate 	case T_CONDIF:
3227c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
3237c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
3247c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "?");
3257c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
3267c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
3277c478bd9Sstevel@tonic-gate 		break;
3287c478bd9Sstevel@tonic-gate 	case T_CONDELSE:
3297c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "(");
3307c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
3317c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ":");
3327c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
3337c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, ")");
3347c478bd9Sstevel@tonic-gate 		break;
3357c478bd9Sstevel@tonic-gate 	case T_ARROW:
3367c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.arrow.lhs, no_iterators, fileline);
3377c478bd9Sstevel@tonic-gate 		if (np->u.arrow.nnp) {
3387c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, "(");
3397c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.arrow.nnp, no_iterators, fileline);
3407c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, ")");
3417c478bd9Sstevel@tonic-gate 		}
3427c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "->");
3437c478bd9Sstevel@tonic-gate 		if (np->u.arrow.knp) {
3447c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, "(");
3457c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.arrow.knp, no_iterators, fileline);
3467c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, ")");
3477c478bd9Sstevel@tonic-gate 		}
3487c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.arrow.rhs, no_iterators, fileline);
3497c478bd9Sstevel@tonic-gate 		break;
3507c478bd9Sstevel@tonic-gate 	case T_LIST:
3517c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.left, no_iterators, fileline);
3527c478bd9Sstevel@tonic-gate 		if (np->u.expr.left && np->u.expr.right &&
3537c478bd9Sstevel@tonic-gate 		    (np->u.expr.left->t != T_LIST ||
3547c478bd9Sstevel@tonic-gate 		    ! is_stmt(np->u.expr.right)))
3557c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, ",");
3567c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.expr.right, no_iterators, fileline);
3577c478bd9Sstevel@tonic-gate 		break;
3587c478bd9Sstevel@tonic-gate 	case T_FAULT:
3597c478bd9Sstevel@tonic-gate 	case T_UPSET:
3607c478bd9Sstevel@tonic-gate 	case T_DEFECT:
3617c478bd9Sstevel@tonic-gate 	case T_ERROR:
3627c478bd9Sstevel@tonic-gate 	case T_EREPORT:
3637c478bd9Sstevel@tonic-gate 		if (fileline)
3647c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
3657c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "event ");
3667c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
3677c478bd9Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
3687c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, " ");
3697c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
3707c478bd9Sstevel@tonic-gate 			    fileline);
3717c478bd9Sstevel@tonic-gate 		}
3727c478bd9Sstevel@tonic-gate 		out(flags, ";");
3737c478bd9Sstevel@tonic-gate 		break;
3747c478bd9Sstevel@tonic-gate 	case T_SERD:
375*7aec1d6eScindi 	case T_STAT:
3767c478bd9Sstevel@tonic-gate 		if (fileline)
3777c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
3787c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "engine ");
3797c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
3807c478bd9Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
3817c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, " ");
3827c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
3837c478bd9Sstevel@tonic-gate 			    fileline);
3847c478bd9Sstevel@tonic-gate 		} else if (np->u.stmt.lutp) {
3857c478bd9Sstevel@tonic-gate 			struct plut_wlk_data pd;
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 			pd.flags = flags;
3887c478bd9Sstevel@tonic-gate 			pd.first = 0;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 			lut_walk(np->u.stmt.lutp, ptree_plut, &pd);
3917c478bd9Sstevel@tonic-gate 		}
3927c478bd9Sstevel@tonic-gate 		out(flags, ";");
3937c478bd9Sstevel@tonic-gate 		break;
3947c478bd9Sstevel@tonic-gate 	case T_ASRU:
3957c478bd9Sstevel@tonic-gate 		if (fileline)
3967c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
3977c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "asru ");
3987c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
3997c478bd9Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
4007c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, " ");
4017c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
4027c478bd9Sstevel@tonic-gate 			    fileline);
4037c478bd9Sstevel@tonic-gate 		}
4047c478bd9Sstevel@tonic-gate 		out(flags, ";");
4057c478bd9Sstevel@tonic-gate 		break;
4067c478bd9Sstevel@tonic-gate 	case T_FRU:
4077c478bd9Sstevel@tonic-gate 		if (fileline)
4087c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
4097c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "fru ");
4107c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
4117c478bd9Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
4127c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, " ");
4137c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
4147c478bd9Sstevel@tonic-gate 			    fileline);
4157c478bd9Sstevel@tonic-gate 		}
4167c478bd9Sstevel@tonic-gate 		out(flags, ";");
4177c478bd9Sstevel@tonic-gate 		break;
4187c478bd9Sstevel@tonic-gate 	case T_CONFIG:
4197c478bd9Sstevel@tonic-gate 		if (fileline)
4207c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
4217c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "config ");
4227c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
4237c478bd9Sstevel@tonic-gate 		if (np->u.stmt.nvpairs) {
4247c478bd9Sstevel@tonic-gate 			out(flags|O_NONL, " ");
4257c478bd9Sstevel@tonic-gate 			ptree(flags, np->u.stmt.nvpairs, no_iterators,
4267c478bd9Sstevel@tonic-gate 				fileline);
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 		out(flags, ";");
4297c478bd9Sstevel@tonic-gate 		break;
4307c478bd9Sstevel@tonic-gate 	case T_PROP:
4317c478bd9Sstevel@tonic-gate 		if (fileline)
4327c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
4337c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "prop ");
4347c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
4357c478bd9Sstevel@tonic-gate 		out(flags, ";");
4367c478bd9Sstevel@tonic-gate 		break;
4377c478bd9Sstevel@tonic-gate 	case T_MASK:
4387c478bd9Sstevel@tonic-gate 		if (fileline)
4397c478bd9Sstevel@tonic-gate 			out(flags, "# %d \"%s\"", np->line, np->file);
4407c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "mask ");
4417c478bd9Sstevel@tonic-gate 		ptree(flags, np->u.stmt.np, no_iterators, fileline);
4427c478bd9Sstevel@tonic-gate 		out(flags, ";");
4437c478bd9Sstevel@tonic-gate 		break;
4447c478bd9Sstevel@tonic-gate 	default:
4457c478bd9Sstevel@tonic-gate 		out(O_DIE,
4467c478bd9Sstevel@tonic-gate 		    "internal error: ptree unexpected nodetype: %d", np->t);
4477c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate }
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate void
ptree_plut(void * name,void * val,void * arg)4527c478bd9Sstevel@tonic-gate ptree_plut(void *name, void *val, void *arg)
4537c478bd9Sstevel@tonic-gate {
4547c478bd9Sstevel@tonic-gate 	struct plut_wlk_data *pd = (struct plut_wlk_data *)arg;
4557c478bd9Sstevel@tonic-gate 	int c;
4567c478bd9Sstevel@tonic-gate 	static int indent;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	indent++;
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 	if (pd->first == 0)
4617c478bd9Sstevel@tonic-gate 		out(pd->flags, ",");
4627c478bd9Sstevel@tonic-gate 	else
4637c478bd9Sstevel@tonic-gate 		pd->first = 0;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	for (c = indent; c > 0; c--)
4667c478bd9Sstevel@tonic-gate 		out(pd->flags|O_NONL, "\t");
4677c478bd9Sstevel@tonic-gate 	out(pd->flags|O_NONL, "%s", (char *)name);
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	out(pd->flags|O_NONL, "=");
4707c478bd9Sstevel@tonic-gate 	ptree(pd->flags, val, 0, 0);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	indent--;
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate void
ptree_name(int flags,struct node * np)4767c478bd9Sstevel@tonic-gate ptree_name(int flags, struct node *np)
4777c478bd9Sstevel@tonic-gate {
4787c478bd9Sstevel@tonic-gate 	ptree(flags, np, 1, 0);
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate void
ptree_name_iter(int flags,struct node * np)4827c478bd9Sstevel@tonic-gate ptree_name_iter(int flags, struct node *np)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	ptree(flags, np, 0, 0);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate const char *
ptree_nodetype2str(enum nodetype t)4887c478bd9Sstevel@tonic-gate ptree_nodetype2str(enum nodetype t)
4897c478bd9Sstevel@tonic-gate {
4907c478bd9Sstevel@tonic-gate 	static char buf[100];
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	switch (t) {
4937c478bd9Sstevel@tonic-gate 	case T_NOTHING: return L_T_NOTHING;
4947c478bd9Sstevel@tonic-gate 	case T_NAME: return L_T_NAME;
4957c478bd9Sstevel@tonic-gate 	case T_GLOBID: return L_T_GLOBID;
4967c478bd9Sstevel@tonic-gate 	case T_EVENT: return L_T_EVENT;
4977c478bd9Sstevel@tonic-gate 	case T_ENGINE: return L_T_ENGINE;
4987c478bd9Sstevel@tonic-gate 	case T_ASRU: return L_asru;
4997c478bd9Sstevel@tonic-gate 	case T_FRU: return L_fru;
5007c478bd9Sstevel@tonic-gate 	case T_CONFIG: return L_config;
5017c478bd9Sstevel@tonic-gate 	case T_TIMEVAL: return L_T_TIMEVAL;
5027c478bd9Sstevel@tonic-gate 	case T_NUM: return L_T_NUM;
5037c478bd9Sstevel@tonic-gate 	case T_QUOTE: return L_T_QUOTE;
5047c478bd9Sstevel@tonic-gate 	case T_FUNC: return L_T_FUNC;
5057c478bd9Sstevel@tonic-gate 	case T_NVPAIR: return L_T_NVPAIR;
5067c478bd9Sstevel@tonic-gate 	case T_ASSIGN: return L_T_ASSIGN;
5077c478bd9Sstevel@tonic-gate 	case T_CONDIF: return L_T_CONDIF;
5087c478bd9Sstevel@tonic-gate 	case T_CONDELSE: return L_T_CONDELSE;
5097c478bd9Sstevel@tonic-gate 	case T_NOT: return L_T_NOT;
5107c478bd9Sstevel@tonic-gate 	case T_AND: return L_T_AND;
5117c478bd9Sstevel@tonic-gate 	case T_OR: return L_T_OR;
5127c478bd9Sstevel@tonic-gate 	case T_EQ: return L_T_EQ;
5137c478bd9Sstevel@tonic-gate 	case T_NE: return L_T_NE;
5147c478bd9Sstevel@tonic-gate 	case T_SUB: return L_T_SUB;
5157c478bd9Sstevel@tonic-gate 	case T_ADD: return L_T_ADD;
5167c478bd9Sstevel@tonic-gate 	case T_MUL: return L_T_MUL;
5177c478bd9Sstevel@tonic-gate 	case T_DIV: return L_T_DIV;
5187c478bd9Sstevel@tonic-gate 	case T_MOD: return L_T_MOD;
5197c478bd9Sstevel@tonic-gate 	case T_LT: return L_T_LT;
5207c478bd9Sstevel@tonic-gate 	case T_LE: return L_T_LE;
5217c478bd9Sstevel@tonic-gate 	case T_GT: return L_T_GT;
5227c478bd9Sstevel@tonic-gate 	case T_GE: return L_T_GE;
5237c478bd9Sstevel@tonic-gate 	case T_BITAND: return L_T_BITAND;
5247c478bd9Sstevel@tonic-gate 	case T_BITOR: return L_T_BITOR;
5257c478bd9Sstevel@tonic-gate 	case T_BITXOR: return L_T_BITXOR;
5267c478bd9Sstevel@tonic-gate 	case T_BITNOT: return L_T_BITNOT;
5277c478bd9Sstevel@tonic-gate 	case T_LSHIFT: return L_T_LSHIFT;
5287c478bd9Sstevel@tonic-gate 	case T_RSHIFT: return L_T_RSHIFT;
5297c478bd9Sstevel@tonic-gate 	case T_ARROW: return L_T_ARROW;
5307c478bd9Sstevel@tonic-gate 	case T_LIST: return L_T_LIST;
5317c478bd9Sstevel@tonic-gate 	case T_FAULT: return L_fault;
5327c478bd9Sstevel@tonic-gate 	case T_UPSET: return L_upset;
5337c478bd9Sstevel@tonic-gate 	case T_DEFECT: return L_defect;
5347c478bd9Sstevel@tonic-gate 	case T_ERROR: return L_error;
5357c478bd9Sstevel@tonic-gate 	case T_EREPORT: return L_ereport;
5367c478bd9Sstevel@tonic-gate 	case T_SERD: return L_serd;
537*7aec1d6eScindi 	case T_STAT: return L_stat;
5387c478bd9Sstevel@tonic-gate 	case T_PROP: return L_prop;
5397c478bd9Sstevel@tonic-gate 	case T_MASK: return L_mask;
5407c478bd9Sstevel@tonic-gate 	default:
5417c478bd9Sstevel@tonic-gate 		(void) sprintf(buf, "[unexpected nodetype: %d]", t);
5427c478bd9Sstevel@tonic-gate 		return (buf);
5437c478bd9Sstevel@tonic-gate 	}
5447c478bd9Sstevel@tonic-gate }
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate const char *
ptree_nametype2str(enum nametype t)5477c478bd9Sstevel@tonic-gate ptree_nametype2str(enum nametype t)
5487c478bd9Sstevel@tonic-gate {
5497c478bd9Sstevel@tonic-gate 	static char buf[100];
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate 	switch (t) {
5527c478bd9Sstevel@tonic-gate 	case N_UNSPEC: return L_N_UNSPEC;
5537c478bd9Sstevel@tonic-gate 	case N_FAULT: return L_fault;
5547c478bd9Sstevel@tonic-gate 	case N_DEFECT: return L_defect;
5557c478bd9Sstevel@tonic-gate 	case N_UPSET: return L_upset;
5567c478bd9Sstevel@tonic-gate 	case N_ERROR: return L_error;
5577c478bd9Sstevel@tonic-gate 	case N_EREPORT: return L_ereport;
5587c478bd9Sstevel@tonic-gate 	case N_SERD: return L_serd;
559*7aec1d6eScindi 	case N_STAT: return L_stat;
5607c478bd9Sstevel@tonic-gate 	default:
5617c478bd9Sstevel@tonic-gate 		(void) sprintf(buf, "[unexpected nametype: %d]", t);
5627c478bd9Sstevel@tonic-gate 		return (buf);
5637c478bd9Sstevel@tonic-gate 	}
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate struct printer_info {
5677c478bd9Sstevel@tonic-gate 	enum nodetype t;
5687c478bd9Sstevel@tonic-gate 	const char *pat;
5697c478bd9Sstevel@tonic-gate 	int flags;
5707c478bd9Sstevel@tonic-gate };
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate static int
name_pattern_match(struct node * np,const char * pat)5737c478bd9Sstevel@tonic-gate name_pattern_match(struct node *np, const char *pat)
5747c478bd9Sstevel@tonic-gate {
5757c478bd9Sstevel@tonic-gate 	const char *cend;	/* first character not in component in pat */
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	if (pat == NULL || *pat == '\0')
5787c478bd9Sstevel@tonic-gate 		return (1);	/* either no pattern or we've matched it all */
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	if (np == NULL)
5817c478bd9Sstevel@tonic-gate 		return (0);	/* there's more pattern and nothing to match */
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	ASSERTeq(np->t, T_NAME, ptree_nodetype2str);
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	cend = strchr(pat, '/');
5867c478bd9Sstevel@tonic-gate 	if (cend == NULL)
5877c478bd9Sstevel@tonic-gate 		cend = strchr(pat, '.');
5887c478bd9Sstevel@tonic-gate 	if (cend == NULL)
5897c478bd9Sstevel@tonic-gate 		cend = &pat[strlen(pat)];
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	while (np) {
5927c478bd9Sstevel@tonic-gate 		const char *s = np->u.name.s;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 		while (*s) {
5957c478bd9Sstevel@tonic-gate 			const char *cstart = pat;
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 			while (*s && tolower(*s) == tolower(*cstart)) {
5987c478bd9Sstevel@tonic-gate 				cstart++;
5997c478bd9Sstevel@tonic-gate 				if (cstart == cend) {
6007c478bd9Sstevel@tonic-gate 					/* component matched */
6017c478bd9Sstevel@tonic-gate 					while (*cend == '/')
6027c478bd9Sstevel@tonic-gate 						cend++;
6037c478bd9Sstevel@tonic-gate 					return
6047c478bd9Sstevel@tonic-gate 					    name_pattern_match(np->u.name.next,
6057c478bd9Sstevel@tonic-gate 					    cend);
6067c478bd9Sstevel@tonic-gate 				}
6077c478bd9Sstevel@tonic-gate 				s++;
6087c478bd9Sstevel@tonic-gate 			}
6097c478bd9Sstevel@tonic-gate 			if (*s)
6107c478bd9Sstevel@tonic-gate 				s++;
6117c478bd9Sstevel@tonic-gate 		}
6127c478bd9Sstevel@tonic-gate 		np = np->u.name.next;
6137c478bd9Sstevel@tonic-gate 	}
6147c478bd9Sstevel@tonic-gate 	return (0);
6157c478bd9Sstevel@tonic-gate }
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate static int
name_pattern_match_in_subtree(struct node * np,const char * pat)6187c478bd9Sstevel@tonic-gate name_pattern_match_in_subtree(struct node *np, const char *pat)
6197c478bd9Sstevel@tonic-gate {
6207c478bd9Sstevel@tonic-gate 	if (pat == NULL || *pat == '\0')
6217c478bd9Sstevel@tonic-gate 		return (1);
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	if (np == NULL)
6247c478bd9Sstevel@tonic-gate 		return (0);
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	if (np->t == T_NAME)
6277c478bd9Sstevel@tonic-gate 		return (name_pattern_match(np, pat));
6287c478bd9Sstevel@tonic-gate 	else if (np->t == T_EVENT)
6297c478bd9Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.event.ename, pat) ||
6307c478bd9Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.event.epname, pat) ||
6317c478bd9Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.event.eexprlist, pat));
6327c478bd9Sstevel@tonic-gate 	else if (np->t == T_ARROW)
6337c478bd9Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.arrow.lhs, pat) ||
6347c478bd9Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.arrow.rhs, pat));
6357c478bd9Sstevel@tonic-gate 	else if (np->t == T_ASSIGN ||
6367c478bd9Sstevel@tonic-gate 			np->t == T_CONDIF ||
6377c478bd9Sstevel@tonic-gate 			np->t == T_CONDELSE ||
6387c478bd9Sstevel@tonic-gate 			np->t == T_NOT ||
6397c478bd9Sstevel@tonic-gate 			np->t == T_AND ||
6407c478bd9Sstevel@tonic-gate 			np->t == T_OR ||
6417c478bd9Sstevel@tonic-gate 			np->t == T_EQ ||
6427c478bd9Sstevel@tonic-gate 			np->t == T_NE ||
6437c478bd9Sstevel@tonic-gate 			np->t == T_SUB ||
6447c478bd9Sstevel@tonic-gate 			np->t == T_ADD ||
6457c478bd9Sstevel@tonic-gate 			np->t == T_MUL ||
6467c478bd9Sstevel@tonic-gate 			np->t == T_DIV ||
6477c478bd9Sstevel@tonic-gate 			np->t == T_MOD ||
6487c478bd9Sstevel@tonic-gate 			np->t == T_LT ||
6497c478bd9Sstevel@tonic-gate 			np->t == T_LE ||
6507c478bd9Sstevel@tonic-gate 			np->t == T_GT ||
6517c478bd9Sstevel@tonic-gate 			np->t == T_GE ||
6527c478bd9Sstevel@tonic-gate 			np->t == T_BITAND ||
6537c478bd9Sstevel@tonic-gate 			np->t == T_BITOR ||
6547c478bd9Sstevel@tonic-gate 			np->t == T_BITXOR ||
6557c478bd9Sstevel@tonic-gate 			np->t == T_BITNOT ||
6567c478bd9Sstevel@tonic-gate 			np->t == T_LSHIFT ||
6577c478bd9Sstevel@tonic-gate 			np->t == T_RSHIFT ||
6587c478bd9Sstevel@tonic-gate 			np->t == T_LIST) {
6597c478bd9Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.expr.left, pat) ||
6607c478bd9Sstevel@tonic-gate 		    name_pattern_match_in_subtree(np->u.expr.right, pat));
6617c478bd9Sstevel@tonic-gate 	} else if (np->t == T_FUNC) {
6627c478bd9Sstevel@tonic-gate 		return (name_pattern_match_in_subtree(np->u.func.arglist, pat));
6637c478bd9Sstevel@tonic-gate 	}
6647c478bd9Sstevel@tonic-gate 	return (0);
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate static void
byname_printer(struct node * lhs,struct node * rhs,void * arg)6687c478bd9Sstevel@tonic-gate byname_printer(struct node *lhs, struct node *rhs, void *arg)
6697c478bd9Sstevel@tonic-gate {
6707c478bd9Sstevel@tonic-gate 	struct printer_info *infop = (struct printer_info *)arg;
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate 	if (infop->t != T_NOTHING && rhs->t != infop->t)
6737c478bd9Sstevel@tonic-gate 		return;
6747c478bd9Sstevel@tonic-gate 	if (!name_pattern_match(lhs, infop->pat))
6757c478bd9Sstevel@tonic-gate 		return;
6767c478bd9Sstevel@tonic-gate 	ptree(infop->flags, rhs, 0, 0);
6777c478bd9Sstevel@tonic-gate }
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate static void
ptree_type_pattern(int flags,enum nodetype t,const char * pat)6807c478bd9Sstevel@tonic-gate ptree_type_pattern(int flags, enum nodetype t, const char *pat)
6817c478bd9Sstevel@tonic-gate {
6827c478bd9Sstevel@tonic-gate 	struct printer_info info;
6837c478bd9Sstevel@tonic-gate 	struct node *np;
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	info.flags = flags;
6867c478bd9Sstevel@tonic-gate 	info.pat = pat;
6877c478bd9Sstevel@tonic-gate 	info.t = t;
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate 	switch (t) {
6907c478bd9Sstevel@tonic-gate 	case T_FAULT:
6917c478bd9Sstevel@tonic-gate 		lut_walk(Faults, (lut_cb)byname_printer, (void *)&info);
6927c478bd9Sstevel@tonic-gate 		return;
6937c478bd9Sstevel@tonic-gate 	case T_UPSET:
6947c478bd9Sstevel@tonic-gate 		lut_walk(Upsets, (lut_cb)byname_printer, (void *)&info);
6957c478bd9Sstevel@tonic-gate 		return;
6967c478bd9Sstevel@tonic-gate 	case T_DEFECT:
6977c478bd9Sstevel@tonic-gate 		lut_walk(Defects, (lut_cb)byname_printer, (void *)&info);
6987c478bd9Sstevel@tonic-gate 		return;
6997c478bd9Sstevel@tonic-gate 	case T_ERROR:
7007c478bd9Sstevel@tonic-gate 		lut_walk(Errors, (lut_cb)byname_printer, (void *)&info);
7017c478bd9Sstevel@tonic-gate 		return;
7027c478bd9Sstevel@tonic-gate 	case T_EREPORT:
7037c478bd9Sstevel@tonic-gate 		lut_walk(Ereports, (lut_cb)byname_printer, (void *)&info);
7047c478bd9Sstevel@tonic-gate 		return;
7057c478bd9Sstevel@tonic-gate 	case T_SERD:
7067c478bd9Sstevel@tonic-gate 		lut_walk(SERDs, (lut_cb)byname_printer, (void *)&info);
7077c478bd9Sstevel@tonic-gate 		return;
708*7aec1d6eScindi 	case T_STAT:
709*7aec1d6eScindi 		lut_walk(STATs, (lut_cb)byname_printer, (void *)&info);
710*7aec1d6eScindi 		return;
7117c478bd9Sstevel@tonic-gate 	case T_ASRU:
7127c478bd9Sstevel@tonic-gate 		lut_walk(ASRUs, (lut_cb)byname_printer, (void *)&info);
7137c478bd9Sstevel@tonic-gate 		return;
7147c478bd9Sstevel@tonic-gate 	case T_FRU:
7157c478bd9Sstevel@tonic-gate 		lut_walk(FRUs, (lut_cb)byname_printer, (void *)&info);
7167c478bd9Sstevel@tonic-gate 		return;
7177c478bd9Sstevel@tonic-gate 	case T_CONFIG:
7187c478bd9Sstevel@tonic-gate 		lut_walk(Configs, (lut_cb)byname_printer, (void *)&info);
7197c478bd9Sstevel@tonic-gate 		return;
7207c478bd9Sstevel@tonic-gate 	case T_PROP:
7217c478bd9Sstevel@tonic-gate 		for (np = Props; np; np = np->u.stmt.next)
7227c478bd9Sstevel@tonic-gate 			if (name_pattern_match_in_subtree(np->u.stmt.np, pat))
7237c478bd9Sstevel@tonic-gate 				ptree(flags, np, 0, 0);
7247c478bd9Sstevel@tonic-gate 		return;
7257c478bd9Sstevel@tonic-gate 	case T_MASK:
7267c478bd9Sstevel@tonic-gate 		for (np = Masks; np; np = np->u.stmt.next)
7277c478bd9Sstevel@tonic-gate 			if (name_pattern_match_in_subtree(np->u.stmt.np, pat))
7287c478bd9Sstevel@tonic-gate 				ptree(flags, np, 0, 0);
7297c478bd9Sstevel@tonic-gate 		return;
7307c478bd9Sstevel@tonic-gate 	default:
7317c478bd9Sstevel@tonic-gate 		ptree(flags, tree_root(NULL), 0, 0);
7327c478bd9Sstevel@tonic-gate 	}
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate void
ptree_all(int flags,const char * pat)7367c478bd9Sstevel@tonic-gate ptree_all(int flags, const char *pat)
7377c478bd9Sstevel@tonic-gate {
7387c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_NOTHING, pat);
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate void
ptree_fault(int flags,const char * pat)7427c478bd9Sstevel@tonic-gate ptree_fault(int flags, const char *pat)
7437c478bd9Sstevel@tonic-gate {
7447c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_FAULT, pat);
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate void
ptree_upset(int flags,const char * pat)7487c478bd9Sstevel@tonic-gate ptree_upset(int flags, const char *pat)
7497c478bd9Sstevel@tonic-gate {
7507c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_UPSET, pat);
7517c478bd9Sstevel@tonic-gate }
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate void
ptree_defect(int flags,const char * pat)7547c478bd9Sstevel@tonic-gate ptree_defect(int flags, const char *pat)
7557c478bd9Sstevel@tonic-gate {
7567c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_DEFECT, pat);
7577c478bd9Sstevel@tonic-gate }
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate void
ptree_error(int flags,const char * pat)7607c478bd9Sstevel@tonic-gate ptree_error(int flags, const char *pat)
7617c478bd9Sstevel@tonic-gate {
7627c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_ERROR, pat);
7637c478bd9Sstevel@tonic-gate }
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate void
ptree_ereport(int flags,const char * pat)7667c478bd9Sstevel@tonic-gate ptree_ereport(int flags, const char *pat)
7677c478bd9Sstevel@tonic-gate {
7687c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_EREPORT, pat);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate void
ptree_serd(int flags,const char * pat)7727c478bd9Sstevel@tonic-gate ptree_serd(int flags, const char *pat)
7737c478bd9Sstevel@tonic-gate {
7747c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_SERD, pat);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate void
ptree_stat(int flags,const char * pat)778*7aec1d6eScindi ptree_stat(int flags, const char *pat)
779*7aec1d6eScindi {
780*7aec1d6eScindi 	ptree_type_pattern(flags, T_STAT, pat);
781*7aec1d6eScindi }
782*7aec1d6eScindi 
783*7aec1d6eScindi void
ptree_asru(int flags,const char * pat)7847c478bd9Sstevel@tonic-gate ptree_asru(int flags, const char *pat)
7857c478bd9Sstevel@tonic-gate {
7867c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_ASRU, pat);
7877c478bd9Sstevel@tonic-gate }
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate void
ptree_fru(int flags,const char * pat)7907c478bd9Sstevel@tonic-gate ptree_fru(int flags, const char *pat)
7917c478bd9Sstevel@tonic-gate {
7927c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_FRU, pat);
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate void
ptree_prop(int flags,const char * pat)7967c478bd9Sstevel@tonic-gate ptree_prop(int flags, const char *pat)
7977c478bd9Sstevel@tonic-gate {
7987c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_PROP, pat);
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate void
ptree_mask(int flags,const char * pat)8027c478bd9Sstevel@tonic-gate ptree_mask(int flags, const char *pat)
8037c478bd9Sstevel@tonic-gate {
8047c478bd9Sstevel@tonic-gate 	ptree_type_pattern(flags, T_MASK, pat);
8057c478bd9Sstevel@tonic-gate }
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate void
ptree_timeval(int flags,unsigned long long * ullp)8087c478bd9Sstevel@tonic-gate ptree_timeval(int flags, unsigned long long *ullp)
8097c478bd9Sstevel@tonic-gate {
8107c478bd9Sstevel@tonic-gate 	unsigned long long val;
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate #define	NOREMAINDER(den, num, val) (((val) = ((den) / (num))) * (num) == (den))
8137c478bd9Sstevel@tonic-gate 	if (*ullp == 0)
8147c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "0us");
8157c478bd9Sstevel@tonic-gate 	else if (*ullp >= TIMEVAL_EVENTUALLY)
8167c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "infinity");
8177c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*365, val))
8187c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluyear%s", val, (val == 1) ? "" : "s");
8197c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*30, val))
8207c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%llumonth%s", val, (val == 1) ? "" : "s");
8217c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*7, val))
8227c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluweek%s", val, (val == 1) ? "" : "s");
8237c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24, val))
8247c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluday%s", val, (val == 1) ? "" : "s");
8257c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60*60, val))
8267c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluhour%s", val, (val == 1) ? "" : "s");
8277c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL*60, val))
8287c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluminute%s", val, (val == 1) ? "" : "s");
8297c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000000ULL, val))
8307c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%llusecond%s", val, (val == 1) ? "" : "s");
8317c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000000ULL, val))
8327c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%llums", val);
8337c478bd9Sstevel@tonic-gate 	else if (NOREMAINDER(*ullp, 1000ULL, val))
8347c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluus", val);
8357c478bd9Sstevel@tonic-gate 	else
8367c478bd9Sstevel@tonic-gate 		out(flags|O_NONL, "%lluns", *ullp);
8377c478bd9Sstevel@tonic-gate }
838