10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23*1414Scindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate *
260Sstevel@tonic-gate * ptree.c -- routines for printing the prop tree
270Sstevel@tonic-gate *
280Sstevel@tonic-gate * this module contains routines to print portions of the parse tree.
290Sstevel@tonic-gate */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <stdio.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <ctype.h>
370Sstevel@tonic-gate #include "out.h"
380Sstevel@tonic-gate #include "stable.h"
390Sstevel@tonic-gate #include "literals.h"
400Sstevel@tonic-gate #include "lut.h"
410Sstevel@tonic-gate #include "tree.h"
420Sstevel@tonic-gate #include "ptree.h"
430Sstevel@tonic-gate
440Sstevel@tonic-gate int Pchildgen;
450Sstevel@tonic-gate
460Sstevel@tonic-gate #ifdef FMAPLUGIN
470Sstevel@tonic-gate
480Sstevel@tonic-gate #include "itree.h"
490Sstevel@tonic-gate #include "eval.h"
500Sstevel@tonic-gate #include "config.h"
510Sstevel@tonic-gate
520Sstevel@tonic-gate static void
cp2num(struct config * cp,int * num)530Sstevel@tonic-gate cp2num(struct config *cp, int *num)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate config_getcompname(cp, NULL, num);
560Sstevel@tonic-gate }
570Sstevel@tonic-gate
580Sstevel@tonic-gate #else
590Sstevel@tonic-gate
600Sstevel@tonic-gate /*ARGSUSED*/
610Sstevel@tonic-gate static void
cp2num(struct config * cp,int * num)620Sstevel@tonic-gate cp2num(struct config *cp, int *num)
630Sstevel@tonic-gate {
640Sstevel@tonic-gate out(O_DIE, "ptree: non-NULL cp");
650Sstevel@tonic-gate }
660Sstevel@tonic-gate
670Sstevel@tonic-gate #endif /* FMAPLUGIN */
680Sstevel@tonic-gate
690Sstevel@tonic-gate static int
is_stmt(struct node * np)700Sstevel@tonic-gate is_stmt(struct node *np)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate switch (np->t) {
730Sstevel@tonic-gate case T_FAULT:
740Sstevel@tonic-gate case T_UPSET:
750Sstevel@tonic-gate case T_DEFECT:
760Sstevel@tonic-gate case T_ERROR:
770Sstevel@tonic-gate case T_EREPORT:
780Sstevel@tonic-gate case T_SERD:
79*1414Scindi case T_STAT:
800Sstevel@tonic-gate case T_PROP:
810Sstevel@tonic-gate case T_MASK:
820Sstevel@tonic-gate case T_ASRU:
830Sstevel@tonic-gate case T_FRU:
840Sstevel@tonic-gate case T_CONFIG:
850Sstevel@tonic-gate return (1);
860Sstevel@tonic-gate /*NOTREACHED*/
870Sstevel@tonic-gate break;
880Sstevel@tonic-gate default:
890Sstevel@tonic-gate break;
900Sstevel@tonic-gate }
910Sstevel@tonic-gate
920Sstevel@tonic-gate return (0);
930Sstevel@tonic-gate }
940Sstevel@tonic-gate
950Sstevel@tonic-gate void
ptree(int flags,struct node * np,int no_iterators,int fileline)960Sstevel@tonic-gate ptree(int flags, struct node *np, int no_iterators, int fileline)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate if (np == NULL)
990Sstevel@tonic-gate return;
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate switch (np->t) {
1020Sstevel@tonic-gate case T_NOTHING:
1030Sstevel@tonic-gate break;
1040Sstevel@tonic-gate case T_NAME:
1050Sstevel@tonic-gate out(flags|O_NONL, "%s", np->u.name.s);
1060Sstevel@tonic-gate if (!no_iterators) {
1070Sstevel@tonic-gate if (np->u.name.cp != NULL) {
1080Sstevel@tonic-gate int num;
1090Sstevel@tonic-gate cp2num(np->u.name.cp, &num);
1100Sstevel@tonic-gate out(flags|O_NONL, "%d", num);
1110Sstevel@tonic-gate } else if (np->u.name.it == IT_HORIZONTAL) {
1120Sstevel@tonic-gate if (np->u.name.child == NULL ||
1130Sstevel@tonic-gate (np->u.name.childgen && !Pchildgen))
1140Sstevel@tonic-gate out(flags|O_NONL, "<>");
1150Sstevel@tonic-gate else {
1160Sstevel@tonic-gate out(flags|O_NONL, "<");
1170Sstevel@tonic-gate ptree(flags, np->u.name.child,
1180Sstevel@tonic-gate no_iterators, fileline);
1190Sstevel@tonic-gate out(flags|O_NONL, ">");
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate } else if (np->u.name.child &&
1220Sstevel@tonic-gate (!np->u.name.childgen || Pchildgen)) {
1230Sstevel@tonic-gate if (np->u.name.it != IT_NONE)
1240Sstevel@tonic-gate out(flags|O_NONL, "[");
1250Sstevel@tonic-gate ptree(flags, np->u.name.child, no_iterators,
1260Sstevel@tonic-gate fileline);
1270Sstevel@tonic-gate if (np->u.name.it != IT_NONE)
1280Sstevel@tonic-gate out(flags|O_NONL, "]");
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate if (np->u.name.next) {
1320Sstevel@tonic-gate ASSERT(np->u.name.next->t == T_NAME);
1330Sstevel@tonic-gate if (np->u.name.it == IT_ENAME)
1340Sstevel@tonic-gate out(flags|O_NONL, ".");
1350Sstevel@tonic-gate else
1360Sstevel@tonic-gate out(flags|O_NONL, "/");
1370Sstevel@tonic-gate ptree(flags, np->u.name.next, no_iterators, fileline);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate break;
1400Sstevel@tonic-gate case T_TIMEVAL:
1410Sstevel@tonic-gate ptree_timeval(flags, &np->u.ull);
1420Sstevel@tonic-gate break;
1430Sstevel@tonic-gate case T_NUM:
1440Sstevel@tonic-gate out(flags|O_NONL, "%llu", np->u.ull);
1450Sstevel@tonic-gate break;
1460Sstevel@tonic-gate case T_QUOTE:
1470Sstevel@tonic-gate out(flags|O_NONL, "\"%s\"", np->u.quote.s);
1480Sstevel@tonic-gate break;
1490Sstevel@tonic-gate case T_GLOBID:
1500Sstevel@tonic-gate out(flags|O_NONL, "$%s", np->u.globid.s);
1510Sstevel@tonic-gate break;
1520Sstevel@tonic-gate case T_FUNC:
1530Sstevel@tonic-gate out(flags|O_NONL, "%s(", np->u.func.s);
1540Sstevel@tonic-gate ptree(flags, np->u.func.arglist, no_iterators, fileline);
1550Sstevel@tonic-gate out(flags|O_NONL, ")");
1560Sstevel@tonic-gate break;
1570Sstevel@tonic-gate case T_NVPAIR:
1580Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
1590Sstevel@tonic-gate out(flags|O_NONL, "=");
1600Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
1610Sstevel@tonic-gate break;
1620Sstevel@tonic-gate case T_EVENT:
1630Sstevel@tonic-gate ptree(flags, np->u.event.ename, no_iterators, fileline);
1640Sstevel@tonic-gate if (np->u.event.epname) {
1650Sstevel@tonic-gate out(flags|O_NONL, "@");
1660Sstevel@tonic-gate ptree(flags, np->u.event.epname,
1670Sstevel@tonic-gate no_iterators, fileline);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate if (np->u.event.eexprlist) {
1700Sstevel@tonic-gate out(flags|O_NONL, "{");
1710Sstevel@tonic-gate ptree(flags, np->u.event.eexprlist,
1720Sstevel@tonic-gate no_iterators, fileline);
1730Sstevel@tonic-gate out(flags|O_NONL, "}");
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate break;
1760Sstevel@tonic-gate case T_ASSIGN:
1770Sstevel@tonic-gate out(flags|O_NONL, "(");
1780Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
1790Sstevel@tonic-gate out(flags|O_NONL, "=");
1800Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
1810Sstevel@tonic-gate out(flags|O_NONL, ")");
1820Sstevel@tonic-gate break;
1830Sstevel@tonic-gate case T_NOT:
1840Sstevel@tonic-gate out(flags|O_NONL, "(");
1850Sstevel@tonic-gate out(flags|O_NONL, "!");
1860Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
1870Sstevel@tonic-gate out(flags|O_NONL, ")");
1880Sstevel@tonic-gate break;
1890Sstevel@tonic-gate case T_AND:
1900Sstevel@tonic-gate out(flags|O_NONL, "(");
1910Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
1920Sstevel@tonic-gate out(flags|O_NONL, "&&");
1930Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
1940Sstevel@tonic-gate out(flags|O_NONL, ")");
1950Sstevel@tonic-gate break;
1960Sstevel@tonic-gate case T_OR:
1970Sstevel@tonic-gate out(flags|O_NONL, "(");
1980Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
1990Sstevel@tonic-gate out(flags|O_NONL, "||");
2000Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2010Sstevel@tonic-gate out(flags|O_NONL, ")");
2020Sstevel@tonic-gate break;
2030Sstevel@tonic-gate case T_EQ:
2040Sstevel@tonic-gate out(flags|O_NONL, "(");
2050Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2060Sstevel@tonic-gate out(flags|O_NONL, "==");
2070Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2080Sstevel@tonic-gate out(flags|O_NONL, ")");
2090Sstevel@tonic-gate break;
2100Sstevel@tonic-gate case T_NE:
2110Sstevel@tonic-gate out(flags|O_NONL, "(");
2120Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2130Sstevel@tonic-gate out(flags|O_NONL, "!=");
2140Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2150Sstevel@tonic-gate out(flags|O_NONL, ")");
2160Sstevel@tonic-gate break;
2170Sstevel@tonic-gate case T_SUB:
2180Sstevel@tonic-gate out(flags|O_NONL, "(");
2190Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2200Sstevel@tonic-gate out(flags|O_NONL, "-");
2210Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2220Sstevel@tonic-gate out(flags|O_NONL, ")");
2230Sstevel@tonic-gate break;
2240Sstevel@tonic-gate case T_ADD:
2250Sstevel@tonic-gate out(flags|O_NONL, "(");
2260Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2270Sstevel@tonic-gate out(flags|O_NONL, "+");
2280Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2290Sstevel@tonic-gate out(flags|O_NONL, ")");
2300Sstevel@tonic-gate break;
2310Sstevel@tonic-gate case T_MUL:
2320Sstevel@tonic-gate out(flags|O_NONL, "(");
2330Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2340Sstevel@tonic-gate out(flags|O_NONL, "*");
2350Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2360Sstevel@tonic-gate out(flags|O_NONL, ")");
2370Sstevel@tonic-gate break;
2380Sstevel@tonic-gate case T_DIV:
2390Sstevel@tonic-gate out(flags|O_NONL, "(");
2400Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2410Sstevel@tonic-gate out(flags|O_NONL, "/");
2420Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2430Sstevel@tonic-gate out(flags|O_NONL, ")");
2440Sstevel@tonic-gate break;
2450Sstevel@tonic-gate case T_MOD:
2460Sstevel@tonic-gate out(flags|O_NONL, "(");
2470Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2480Sstevel@tonic-gate out(flags|O_NONL, "%%");
2490Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2500Sstevel@tonic-gate out(flags|O_NONL, ")");
2510Sstevel@tonic-gate break;
2520Sstevel@tonic-gate case T_LT:
2530Sstevel@tonic-gate out(flags|O_NONL, "(");
2540Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2550Sstevel@tonic-gate out(flags|O_NONL, "<");
2560Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2570Sstevel@tonic-gate out(flags|O_NONL, ")");
2580Sstevel@tonic-gate break;
2590Sstevel@tonic-gate case T_LE:
2600Sstevel@tonic-gate out(flags|O_NONL, "(");
2610Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2620Sstevel@tonic-gate out(flags|O_NONL, "<=");
2630Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2640Sstevel@tonic-gate out(flags|O_NONL, ")");
2650Sstevel@tonic-gate break;
2660Sstevel@tonic-gate case T_GT:
2670Sstevel@tonic-gate out(flags|O_NONL, "(");
2680Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2690Sstevel@tonic-gate out(flags|O_NONL, ">");
2700Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2710Sstevel@tonic-gate out(flags|O_NONL, ")");
2720Sstevel@tonic-gate break;
2730Sstevel@tonic-gate case T_GE:
2740Sstevel@tonic-gate out(flags|O_NONL, "(");
2750Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2760Sstevel@tonic-gate out(flags|O_NONL, ">=");
2770Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2780Sstevel@tonic-gate out(flags|O_NONL, ")");
2790Sstevel@tonic-gate break;
2800Sstevel@tonic-gate case T_BITNOT:
2810Sstevel@tonic-gate out(flags|O_NONL, "(");
2820Sstevel@tonic-gate out(flags|O_NONL, "~");
2830Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2840Sstevel@tonic-gate out(flags|O_NONL, ")");
2850Sstevel@tonic-gate break;
2860Sstevel@tonic-gate case T_BITAND:
2870Sstevel@tonic-gate out(flags|O_NONL, "(");
2880Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2890Sstevel@tonic-gate out(flags|O_NONL, "&");
2900Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2910Sstevel@tonic-gate out(flags|O_NONL, ")");
2920Sstevel@tonic-gate break;
2930Sstevel@tonic-gate case T_BITOR:
2940Sstevel@tonic-gate out(flags|O_NONL, "(");
2950Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
2960Sstevel@tonic-gate out(flags|O_NONL, "|");
2970Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
2980Sstevel@tonic-gate out(flags|O_NONL, ")");
2990Sstevel@tonic-gate break;
3000Sstevel@tonic-gate case T_BITXOR:
3010Sstevel@tonic-gate out(flags|O_NONL, "(");
3020Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
3030Sstevel@tonic-gate out(flags|O_NONL, "^");
3040Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
3050Sstevel@tonic-gate out(flags|O_NONL, ")");
3060Sstevel@tonic-gate break;
3070Sstevel@tonic-gate case T_LSHIFT:
3080Sstevel@tonic-gate out(flags|O_NONL, "(");
3090Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
3100Sstevel@tonic-gate out(flags|O_NONL, "<<");
3110Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
3120Sstevel@tonic-gate out(flags|O_NONL, ")");
3130Sstevel@tonic-gate break;
3140Sstevel@tonic-gate case T_RSHIFT:
3150Sstevel@tonic-gate out(flags|O_NONL, "(");
3160Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
3170Sstevel@tonic-gate out(flags|O_NONL, ">>");
3180Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
3190Sstevel@tonic-gate out(flags|O_NONL, ")");
3200Sstevel@tonic-gate break;
3210Sstevel@tonic-gate case T_CONDIF:
3220Sstevel@tonic-gate out(flags|O_NONL, "(");
3230Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
3240Sstevel@tonic-gate out(flags|O_NONL, "?");
3250Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
3260Sstevel@tonic-gate out(flags|O_NONL, ")");
3270Sstevel@tonic-gate break;
3280Sstevel@tonic-gate case T_CONDELSE:
3290Sstevel@tonic-gate out(flags|O_NONL, "(");
3300Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
3310Sstevel@tonic-gate out(flags|O_NONL, ":");
3320Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
3330Sstevel@tonic-gate out(flags|O_NONL, ")");
3340Sstevel@tonic-gate break;
3350Sstevel@tonic-gate case T_ARROW:
3360Sstevel@tonic-gate ptree(flags, np->u.arrow.lhs, no_iterators, fileline);
3370Sstevel@tonic-gate if (np->u.arrow.nnp) {
3380Sstevel@tonic-gate out(flags|O_NONL, "(");
3390Sstevel@tonic-gate ptree(flags, np->u.arrow.nnp, no_iterators, fileline);
3400Sstevel@tonic-gate out(flags|O_NONL, ")");
3410Sstevel@tonic-gate }
3420Sstevel@tonic-gate out(flags|O_NONL, "->");
3430Sstevel@tonic-gate if (np->u.arrow.knp) {
3440Sstevel@tonic-gate out(flags|O_NONL, "(");
3450Sstevel@tonic-gate ptree(flags, np->u.arrow.knp, no_iterators, fileline);
3460Sstevel@tonic-gate out(flags|O_NONL, ")");
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate ptree(flags, np->u.arrow.rhs, no_iterators, fileline);
3490Sstevel@tonic-gate break;
3500Sstevel@tonic-gate case T_LIST:
3510Sstevel@tonic-gate ptree(flags, np->u.expr.left, no_iterators, fileline);
3520Sstevel@tonic-gate if (np->u.expr.left && np->u.expr.right &&
3530Sstevel@tonic-gate (np->u.expr.left->t != T_LIST ||
3540Sstevel@tonic-gate ! is_stmt(np->u.expr.right)))
3550Sstevel@tonic-gate out(flags|O_NONL, ",");
3560Sstevel@tonic-gate ptree(flags, np->u.expr.right, no_iterators, fileline);
3570Sstevel@tonic-gate break;
3580Sstevel@tonic-gate case T_FAULT:
3590Sstevel@tonic-gate case T_UPSET:
3600Sstevel@tonic-gate case T_DEFECT:
3610Sstevel@tonic-gate case T_ERROR:
3620Sstevel@tonic-gate case T_EREPORT:
3630Sstevel@tonic-gate if (fileline)
3640Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
3650Sstevel@tonic-gate out(flags|O_NONL, "event ");
3660Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
3670Sstevel@tonic-gate if (np->u.stmt.nvpairs) {
3680Sstevel@tonic-gate out(flags|O_NONL, " ");
3690Sstevel@tonic-gate ptree(flags, np->u.stmt.nvpairs, no_iterators,
3700Sstevel@tonic-gate fileline);
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate out(flags, ";");
3730Sstevel@tonic-gate break;
3740Sstevel@tonic-gate case T_SERD:
375*1414Scindi case T_STAT:
3760Sstevel@tonic-gate if (fileline)
3770Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
3780Sstevel@tonic-gate out(flags|O_NONL, "engine ");
3790Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
3800Sstevel@tonic-gate if (np->u.stmt.nvpairs) {
3810Sstevel@tonic-gate out(flags|O_NONL, " ");
3820Sstevel@tonic-gate ptree(flags, np->u.stmt.nvpairs, no_iterators,
3830Sstevel@tonic-gate fileline);
3840Sstevel@tonic-gate } else if (np->u.stmt.lutp) {
3850Sstevel@tonic-gate struct plut_wlk_data pd;
3860Sstevel@tonic-gate
3870Sstevel@tonic-gate pd.flags = flags;
3880Sstevel@tonic-gate pd.first = 0;
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate lut_walk(np->u.stmt.lutp, ptree_plut, &pd);
3910Sstevel@tonic-gate }
3920Sstevel@tonic-gate out(flags, ";");
3930Sstevel@tonic-gate break;
3940Sstevel@tonic-gate case T_ASRU:
3950Sstevel@tonic-gate if (fileline)
3960Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
3970Sstevel@tonic-gate out(flags|O_NONL, "asru ");
3980Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
3990Sstevel@tonic-gate if (np->u.stmt.nvpairs) {
4000Sstevel@tonic-gate out(flags|O_NONL, " ");
4010Sstevel@tonic-gate ptree(flags, np->u.stmt.nvpairs, no_iterators,
4020Sstevel@tonic-gate fileline);
4030Sstevel@tonic-gate }
4040Sstevel@tonic-gate out(flags, ";");
4050Sstevel@tonic-gate break;
4060Sstevel@tonic-gate case T_FRU:
4070Sstevel@tonic-gate if (fileline)
4080Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
4090Sstevel@tonic-gate out(flags|O_NONL, "fru ");
4100Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
4110Sstevel@tonic-gate if (np->u.stmt.nvpairs) {
4120Sstevel@tonic-gate out(flags|O_NONL, " ");
4130Sstevel@tonic-gate ptree(flags, np->u.stmt.nvpairs, no_iterators,
4140Sstevel@tonic-gate fileline);
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate out(flags, ";");
4170Sstevel@tonic-gate break;
4180Sstevel@tonic-gate case T_CONFIG:
4190Sstevel@tonic-gate if (fileline)
4200Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
4210Sstevel@tonic-gate out(flags|O_NONL, "config ");
4220Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
4230Sstevel@tonic-gate if (np->u.stmt.nvpairs) {
4240Sstevel@tonic-gate out(flags|O_NONL, " ");
4250Sstevel@tonic-gate ptree(flags, np->u.stmt.nvpairs, no_iterators,
4260Sstevel@tonic-gate fileline);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate out(flags, ";");
4290Sstevel@tonic-gate break;
4300Sstevel@tonic-gate case T_PROP:
4310Sstevel@tonic-gate if (fileline)
4320Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
4330Sstevel@tonic-gate out(flags|O_NONL, "prop ");
4340Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
4350Sstevel@tonic-gate out(flags, ";");
4360Sstevel@tonic-gate break;
4370Sstevel@tonic-gate case T_MASK:
4380Sstevel@tonic-gate if (fileline)
4390Sstevel@tonic-gate out(flags, "# %d \"%s\"", np->line, np->file);
4400Sstevel@tonic-gate out(flags|O_NONL, "mask ");
4410Sstevel@tonic-gate ptree(flags, np->u.stmt.np, no_iterators, fileline);
4420Sstevel@tonic-gate out(flags, ";");
4430Sstevel@tonic-gate break;
4440Sstevel@tonic-gate default:
4450Sstevel@tonic-gate out(O_DIE,
4460Sstevel@tonic-gate "internal error: ptree unexpected nodetype: %d", np->t);
4470Sstevel@tonic-gate /*NOTREACHED*/
4480Sstevel@tonic-gate }
4490Sstevel@tonic-gate }
4500Sstevel@tonic-gate
4510Sstevel@tonic-gate void
ptree_plut(void * name,void * val,void * arg)4520Sstevel@tonic-gate ptree_plut(void *name, void *val, void *arg)
4530Sstevel@tonic-gate {
4540Sstevel@tonic-gate struct plut_wlk_data *pd = (struct plut_wlk_data *)arg;
4550Sstevel@tonic-gate int c;
4560Sstevel@tonic-gate static int indent;
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate indent++;
4590Sstevel@tonic-gate
4600Sstevel@tonic-gate if (pd->first == 0)
4610Sstevel@tonic-gate out(pd->flags, ",");
4620Sstevel@tonic-gate else
4630Sstevel@tonic-gate pd->first = 0;
4640Sstevel@tonic-gate
4650Sstevel@tonic-gate for (c = indent; c > 0; c--)
4660Sstevel@tonic-gate out(pd->flags|O_NONL, "\t");
4670Sstevel@tonic-gate out(pd->flags|O_NONL, "%s", (char *)name);
4680Sstevel@tonic-gate
4690Sstevel@tonic-gate out(pd->flags|O_NONL, "=");
4700Sstevel@tonic-gate ptree(pd->flags, val, 0, 0);
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate indent--;
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate
4750Sstevel@tonic-gate void
ptree_name(int flags,struct node * np)4760Sstevel@tonic-gate ptree_name(int flags, struct node *np)
4770Sstevel@tonic-gate {
4780Sstevel@tonic-gate ptree(flags, np, 1, 0);
4790Sstevel@tonic-gate }
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate void
ptree_name_iter(int flags,struct node * np)4820Sstevel@tonic-gate ptree_name_iter(int flags, struct node *np)
4830Sstevel@tonic-gate {
4840Sstevel@tonic-gate ptree(flags, np, 0, 0);
4850Sstevel@tonic-gate }
4860Sstevel@tonic-gate
4870Sstevel@tonic-gate const char *
ptree_nodetype2str(enum nodetype t)4880Sstevel@tonic-gate ptree_nodetype2str(enum nodetype t)
4890Sstevel@tonic-gate {
4900Sstevel@tonic-gate static char buf[100];
4910Sstevel@tonic-gate
4920Sstevel@tonic-gate switch (t) {
4930Sstevel@tonic-gate case T_NOTHING: return L_T_NOTHING;
4940Sstevel@tonic-gate case T_NAME: return L_T_NAME;
4950Sstevel@tonic-gate case T_GLOBID: return L_T_GLOBID;
4960Sstevel@tonic-gate case T_EVENT: return L_T_EVENT;
4970Sstevel@tonic-gate case T_ENGINE: return L_T_ENGINE;
4980Sstevel@tonic-gate case T_ASRU: return L_asru;
4990Sstevel@tonic-gate case T_FRU: return L_fru;
5000Sstevel@tonic-gate case T_CONFIG: return L_config;
5010Sstevel@tonic-gate case T_TIMEVAL: return L_T_TIMEVAL;
5020Sstevel@tonic-gate case T_NUM: return L_T_NUM;
5030Sstevel@tonic-gate case T_QUOTE: return L_T_QUOTE;
5040Sstevel@tonic-gate case T_FUNC: return L_T_FUNC;
5050Sstevel@tonic-gate case T_NVPAIR: return L_T_NVPAIR;
5060Sstevel@tonic-gate case T_ASSIGN: return L_T_ASSIGN;
5070Sstevel@tonic-gate case T_CONDIF: return L_T_CONDIF;
5080Sstevel@tonic-gate case T_CONDELSE: return L_T_CONDELSE;
5090Sstevel@tonic-gate case T_NOT: return L_T_NOT;
5100Sstevel@tonic-gate case T_AND: return L_T_AND;
5110Sstevel@tonic-gate case T_OR: return L_T_OR;
5120Sstevel@tonic-gate case T_EQ: return L_T_EQ;
5130Sstevel@tonic-gate case T_NE: return L_T_NE;
5140Sstevel@tonic-gate case T_SUB: return L_T_SUB;
5150Sstevel@tonic-gate case T_ADD: return L_T_ADD;
5160Sstevel@tonic-gate case T_MUL: return L_T_MUL;
5170Sstevel@tonic-gate case T_DIV: return L_T_DIV;
5180Sstevel@tonic-gate case T_MOD: return L_T_MOD;
5190Sstevel@tonic-gate case T_LT: return L_T_LT;
5200Sstevel@tonic-gate case T_LE: return L_T_LE;
5210Sstevel@tonic-gate case T_GT: return L_T_GT;
5220Sstevel@tonic-gate case T_GE: return L_T_GE;
5230Sstevel@tonic-gate case T_BITAND: return L_T_BITAND;
5240Sstevel@tonic-gate case T_BITOR: return L_T_BITOR;
5250Sstevel@tonic-gate case T_BITXOR: return L_T_BITXOR;
5260Sstevel@tonic-gate case T_BITNOT: return L_T_BITNOT;
5270Sstevel@tonic-gate case T_LSHIFT: return L_T_LSHIFT;
5280Sstevel@tonic-gate case T_RSHIFT: return L_T_RSHIFT;
5290Sstevel@tonic-gate case T_ARROW: return L_T_ARROW;
5300Sstevel@tonic-gate case T_LIST: return L_T_LIST;
5310Sstevel@tonic-gate case T_FAULT: return L_fault;
5320Sstevel@tonic-gate case T_UPSET: return L_upset;
5330Sstevel@tonic-gate case T_DEFECT: return L_defect;
5340Sstevel@tonic-gate case T_ERROR: return L_error;
5350Sstevel@tonic-gate case T_EREPORT: return L_ereport;
5360Sstevel@tonic-gate case T_SERD: return L_serd;
537*1414Scindi case T_STAT: return L_stat;
5380Sstevel@tonic-gate case T_PROP: return L_prop;
5390Sstevel@tonic-gate case T_MASK: return L_mask;
5400Sstevel@tonic-gate default:
5410Sstevel@tonic-gate (void) sprintf(buf, "[unexpected nodetype: %d]", t);
5420Sstevel@tonic-gate return (buf);
5430Sstevel@tonic-gate }
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate
5460Sstevel@tonic-gate const char *
ptree_nametype2str(enum nametype t)5470Sstevel@tonic-gate ptree_nametype2str(enum nametype t)
5480Sstevel@tonic-gate {
5490Sstevel@tonic-gate static char buf[100];
5500Sstevel@tonic-gate
5510Sstevel@tonic-gate switch (t) {
5520Sstevel@tonic-gate case N_UNSPEC: return L_N_UNSPEC;
5530Sstevel@tonic-gate case N_FAULT: return L_fault;
5540Sstevel@tonic-gate case N_DEFECT: return L_defect;
5550Sstevel@tonic-gate case N_UPSET: return L_upset;
5560Sstevel@tonic-gate case N_ERROR: return L_error;
5570Sstevel@tonic-gate case N_EREPORT: return L_ereport;
5580Sstevel@tonic-gate case N_SERD: return L_serd;
559*1414Scindi case N_STAT: return L_stat;
5600Sstevel@tonic-gate default:
5610Sstevel@tonic-gate (void) sprintf(buf, "[unexpected nametype: %d]", t);
5620Sstevel@tonic-gate return (buf);
5630Sstevel@tonic-gate }
5640Sstevel@tonic-gate }
5650Sstevel@tonic-gate
5660Sstevel@tonic-gate struct printer_info {
5670Sstevel@tonic-gate enum nodetype t;
5680Sstevel@tonic-gate const char *pat;
5690Sstevel@tonic-gate int flags;
5700Sstevel@tonic-gate };
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate static int
name_pattern_match(struct node * np,const char * pat)5730Sstevel@tonic-gate name_pattern_match(struct node *np, const char *pat)
5740Sstevel@tonic-gate {
5750Sstevel@tonic-gate const char *cend; /* first character not in component in pat */
5760Sstevel@tonic-gate
5770Sstevel@tonic-gate if (pat == NULL || *pat == '\0')
5780Sstevel@tonic-gate return (1); /* either no pattern or we've matched it all */
5790Sstevel@tonic-gate
5800Sstevel@tonic-gate if (np == NULL)
5810Sstevel@tonic-gate return (0); /* there's more pattern and nothing to match */
5820Sstevel@tonic-gate
5830Sstevel@tonic-gate ASSERTeq(np->t, T_NAME, ptree_nodetype2str);
5840Sstevel@tonic-gate
5850Sstevel@tonic-gate cend = strchr(pat, '/');
5860Sstevel@tonic-gate if (cend == NULL)
5870Sstevel@tonic-gate cend = strchr(pat, '.');
5880Sstevel@tonic-gate if (cend == NULL)
5890Sstevel@tonic-gate cend = &pat[strlen(pat)];
5900Sstevel@tonic-gate
5910Sstevel@tonic-gate while (np) {
5920Sstevel@tonic-gate const char *s = np->u.name.s;
5930Sstevel@tonic-gate
5940Sstevel@tonic-gate while (*s) {
5950Sstevel@tonic-gate const char *cstart = pat;
5960Sstevel@tonic-gate
5970Sstevel@tonic-gate while (*s && tolower(*s) == tolower(*cstart)) {
5980Sstevel@tonic-gate cstart++;
5990Sstevel@tonic-gate if (cstart == cend) {
6000Sstevel@tonic-gate /* component matched */
6010Sstevel@tonic-gate while (*cend == '/')
6020Sstevel@tonic-gate cend++;
6030Sstevel@tonic-gate return
6040Sstevel@tonic-gate name_pattern_match(np->u.name.next,
6050Sstevel@tonic-gate cend);
6060Sstevel@tonic-gate }
6070Sstevel@tonic-gate s++;
6080Sstevel@tonic-gate }
6090Sstevel@tonic-gate if (*s)
6100Sstevel@tonic-gate s++;
6110Sstevel@tonic-gate }
6120Sstevel@tonic-gate np = np->u.name.next;
6130Sstevel@tonic-gate }
6140Sstevel@tonic-gate return (0);
6150Sstevel@tonic-gate }
6160Sstevel@tonic-gate
6170Sstevel@tonic-gate static int
name_pattern_match_in_subtree(struct node * np,const char * pat)6180Sstevel@tonic-gate name_pattern_match_in_subtree(struct node *np, const char *pat)
6190Sstevel@tonic-gate {
6200Sstevel@tonic-gate if (pat == NULL || *pat == '\0')
6210Sstevel@tonic-gate return (1);
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate if (np == NULL)
6240Sstevel@tonic-gate return (0);
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate if (np->t == T_NAME)
6270Sstevel@tonic-gate return (name_pattern_match(np, pat));
6280Sstevel@tonic-gate else if (np->t == T_EVENT)
6290Sstevel@tonic-gate return (name_pattern_match_in_subtree(np->u.event.ename, pat) ||
6300Sstevel@tonic-gate name_pattern_match_in_subtree(np->u.event.epname, pat) ||
6310Sstevel@tonic-gate name_pattern_match_in_subtree(np->u.event.eexprlist, pat));
6320Sstevel@tonic-gate else if (np->t == T_ARROW)
6330Sstevel@tonic-gate return (name_pattern_match_in_subtree(np->u.arrow.lhs, pat) ||
6340Sstevel@tonic-gate name_pattern_match_in_subtree(np->u.arrow.rhs, pat));
6350Sstevel@tonic-gate else if (np->t == T_ASSIGN ||
6360Sstevel@tonic-gate np->t == T_CONDIF ||
6370Sstevel@tonic-gate np->t == T_CONDELSE ||
6380Sstevel@tonic-gate np->t == T_NOT ||
6390Sstevel@tonic-gate np->t == T_AND ||
6400Sstevel@tonic-gate np->t == T_OR ||
6410Sstevel@tonic-gate np->t == T_EQ ||
6420Sstevel@tonic-gate np->t == T_NE ||
6430Sstevel@tonic-gate np->t == T_SUB ||
6440Sstevel@tonic-gate np->t == T_ADD ||
6450Sstevel@tonic-gate np->t == T_MUL ||
6460Sstevel@tonic-gate np->t == T_DIV ||
6470Sstevel@tonic-gate np->t == T_MOD ||
6480Sstevel@tonic-gate np->t == T_LT ||
6490Sstevel@tonic-gate np->t == T_LE ||
6500Sstevel@tonic-gate np->t == T_GT ||
6510Sstevel@tonic-gate np->t == T_GE ||
6520Sstevel@tonic-gate np->t == T_BITAND ||
6530Sstevel@tonic-gate np->t == T_BITOR ||
6540Sstevel@tonic-gate np->t == T_BITXOR ||
6550Sstevel@tonic-gate np->t == T_BITNOT ||
6560Sstevel@tonic-gate np->t == T_LSHIFT ||
6570Sstevel@tonic-gate np->t == T_RSHIFT ||
6580Sstevel@tonic-gate np->t == T_LIST) {
6590Sstevel@tonic-gate return (name_pattern_match_in_subtree(np->u.expr.left, pat) ||
6600Sstevel@tonic-gate name_pattern_match_in_subtree(np->u.expr.right, pat));
6610Sstevel@tonic-gate } else if (np->t == T_FUNC) {
6620Sstevel@tonic-gate return (name_pattern_match_in_subtree(np->u.func.arglist, pat));
6630Sstevel@tonic-gate }
6640Sstevel@tonic-gate return (0);
6650Sstevel@tonic-gate }
6660Sstevel@tonic-gate
6670Sstevel@tonic-gate static void
byname_printer(struct node * lhs,struct node * rhs,void * arg)6680Sstevel@tonic-gate byname_printer(struct node *lhs, struct node *rhs, void *arg)
6690Sstevel@tonic-gate {
6700Sstevel@tonic-gate struct printer_info *infop = (struct printer_info *)arg;
6710Sstevel@tonic-gate
6720Sstevel@tonic-gate if (infop->t != T_NOTHING && rhs->t != infop->t)
6730Sstevel@tonic-gate return;
6740Sstevel@tonic-gate if (!name_pattern_match(lhs, infop->pat))
6750Sstevel@tonic-gate return;
6760Sstevel@tonic-gate ptree(infop->flags, rhs, 0, 0);
6770Sstevel@tonic-gate }
6780Sstevel@tonic-gate
6790Sstevel@tonic-gate static void
ptree_type_pattern(int flags,enum nodetype t,const char * pat)6800Sstevel@tonic-gate ptree_type_pattern(int flags, enum nodetype t, const char *pat)
6810Sstevel@tonic-gate {
6820Sstevel@tonic-gate struct printer_info info;
6830Sstevel@tonic-gate struct node *np;
6840Sstevel@tonic-gate
6850Sstevel@tonic-gate info.flags = flags;
6860Sstevel@tonic-gate info.pat = pat;
6870Sstevel@tonic-gate info.t = t;
6880Sstevel@tonic-gate
6890Sstevel@tonic-gate switch (t) {
6900Sstevel@tonic-gate case T_FAULT:
6910Sstevel@tonic-gate lut_walk(Faults, (lut_cb)byname_printer, (void *)&info);
6920Sstevel@tonic-gate return;
6930Sstevel@tonic-gate case T_UPSET:
6940Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)byname_printer, (void *)&info);
6950Sstevel@tonic-gate return;
6960Sstevel@tonic-gate case T_DEFECT:
6970Sstevel@tonic-gate lut_walk(Defects, (lut_cb)byname_printer, (void *)&info);
6980Sstevel@tonic-gate return;
6990Sstevel@tonic-gate case T_ERROR:
7000Sstevel@tonic-gate lut_walk(Errors, (lut_cb)byname_printer, (void *)&info);
7010Sstevel@tonic-gate return;
7020Sstevel@tonic-gate case T_EREPORT:
7030Sstevel@tonic-gate lut_walk(Ereports, (lut_cb)byname_printer, (void *)&info);
7040Sstevel@tonic-gate return;
7050Sstevel@tonic-gate case T_SERD:
7060Sstevel@tonic-gate lut_walk(SERDs, (lut_cb)byname_printer, (void *)&info);
7070Sstevel@tonic-gate return;
708*1414Scindi case T_STAT:
709*1414Scindi lut_walk(STATs, (lut_cb)byname_printer, (void *)&info);
710*1414Scindi return;
7110Sstevel@tonic-gate case T_ASRU:
7120Sstevel@tonic-gate lut_walk(ASRUs, (lut_cb)byname_printer, (void *)&info);
7130Sstevel@tonic-gate return;
7140Sstevel@tonic-gate case T_FRU:
7150Sstevel@tonic-gate lut_walk(FRUs, (lut_cb)byname_printer, (void *)&info);
7160Sstevel@tonic-gate return;
7170Sstevel@tonic-gate case T_CONFIG:
7180Sstevel@tonic-gate lut_walk(Configs, (lut_cb)byname_printer, (void *)&info);
7190Sstevel@tonic-gate return;
7200Sstevel@tonic-gate case T_PROP:
7210Sstevel@tonic-gate for (np = Props; np; np = np->u.stmt.next)
7220Sstevel@tonic-gate if (name_pattern_match_in_subtree(np->u.stmt.np, pat))
7230Sstevel@tonic-gate ptree(flags, np, 0, 0);
7240Sstevel@tonic-gate return;
7250Sstevel@tonic-gate case T_MASK:
7260Sstevel@tonic-gate for (np = Masks; np; np = np->u.stmt.next)
7270Sstevel@tonic-gate if (name_pattern_match_in_subtree(np->u.stmt.np, pat))
7280Sstevel@tonic-gate ptree(flags, np, 0, 0);
7290Sstevel@tonic-gate return;
7300Sstevel@tonic-gate default:
7310Sstevel@tonic-gate ptree(flags, tree_root(NULL), 0, 0);
7320Sstevel@tonic-gate }
7330Sstevel@tonic-gate }
7340Sstevel@tonic-gate
7350Sstevel@tonic-gate void
ptree_all(int flags,const char * pat)7360Sstevel@tonic-gate ptree_all(int flags, const char *pat)
7370Sstevel@tonic-gate {
7380Sstevel@tonic-gate ptree_type_pattern(flags, T_NOTHING, pat);
7390Sstevel@tonic-gate }
7400Sstevel@tonic-gate
7410Sstevel@tonic-gate void
ptree_fault(int flags,const char * pat)7420Sstevel@tonic-gate ptree_fault(int flags, const char *pat)
7430Sstevel@tonic-gate {
7440Sstevel@tonic-gate ptree_type_pattern(flags, T_FAULT, pat);
7450Sstevel@tonic-gate }
7460Sstevel@tonic-gate
7470Sstevel@tonic-gate void
ptree_upset(int flags,const char * pat)7480Sstevel@tonic-gate ptree_upset(int flags, const char *pat)
7490Sstevel@tonic-gate {
7500Sstevel@tonic-gate ptree_type_pattern(flags, T_UPSET, pat);
7510Sstevel@tonic-gate }
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate void
ptree_defect(int flags,const char * pat)7540Sstevel@tonic-gate ptree_defect(int flags, const char *pat)
7550Sstevel@tonic-gate {
7560Sstevel@tonic-gate ptree_type_pattern(flags, T_DEFECT, pat);
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate void
ptree_error(int flags,const char * pat)7600Sstevel@tonic-gate ptree_error(int flags, const char *pat)
7610Sstevel@tonic-gate {
7620Sstevel@tonic-gate ptree_type_pattern(flags, T_ERROR, pat);
7630Sstevel@tonic-gate }
7640Sstevel@tonic-gate
7650Sstevel@tonic-gate void
ptree_ereport(int flags,const char * pat)7660Sstevel@tonic-gate ptree_ereport(int flags, const char *pat)
7670Sstevel@tonic-gate {
7680Sstevel@tonic-gate ptree_type_pattern(flags, T_EREPORT, pat);
7690Sstevel@tonic-gate }
7700Sstevel@tonic-gate
7710Sstevel@tonic-gate void
ptree_serd(int flags,const char * pat)7720Sstevel@tonic-gate ptree_serd(int flags, const char *pat)
7730Sstevel@tonic-gate {
7740Sstevel@tonic-gate ptree_type_pattern(flags, T_SERD, pat);
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate void
ptree_stat(int flags,const char * pat)778*1414Scindi ptree_stat(int flags, const char *pat)
779*1414Scindi {
780*1414Scindi ptree_type_pattern(flags, T_STAT, pat);
781*1414Scindi }
782*1414Scindi
783*1414Scindi void
ptree_asru(int flags,const char * pat)7840Sstevel@tonic-gate ptree_asru(int flags, const char *pat)
7850Sstevel@tonic-gate {
7860Sstevel@tonic-gate ptree_type_pattern(flags, T_ASRU, pat);
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate void
ptree_fru(int flags,const char * pat)7900Sstevel@tonic-gate ptree_fru(int flags, const char *pat)
7910Sstevel@tonic-gate {
7920Sstevel@tonic-gate ptree_type_pattern(flags, T_FRU, pat);
7930Sstevel@tonic-gate }
7940Sstevel@tonic-gate
7950Sstevel@tonic-gate void
ptree_prop(int flags,const char * pat)7960Sstevel@tonic-gate ptree_prop(int flags, const char *pat)
7970Sstevel@tonic-gate {
7980Sstevel@tonic-gate ptree_type_pattern(flags, T_PROP, pat);
7990Sstevel@tonic-gate }
8000Sstevel@tonic-gate
8010Sstevel@tonic-gate void
ptree_mask(int flags,const char * pat)8020Sstevel@tonic-gate ptree_mask(int flags, const char *pat)
8030Sstevel@tonic-gate {
8040Sstevel@tonic-gate ptree_type_pattern(flags, T_MASK, pat);
8050Sstevel@tonic-gate }
8060Sstevel@tonic-gate
8070Sstevel@tonic-gate void
ptree_timeval(int flags,unsigned long long * ullp)8080Sstevel@tonic-gate ptree_timeval(int flags, unsigned long long *ullp)
8090Sstevel@tonic-gate {
8100Sstevel@tonic-gate unsigned long long val;
8110Sstevel@tonic-gate
8120Sstevel@tonic-gate #define NOREMAINDER(den, num, val) (((val) = ((den) / (num))) * (num) == (den))
8130Sstevel@tonic-gate if (*ullp == 0)
8140Sstevel@tonic-gate out(flags|O_NONL, "0us");
8150Sstevel@tonic-gate else if (*ullp >= TIMEVAL_EVENTUALLY)
8160Sstevel@tonic-gate out(flags|O_NONL, "infinity");
8170Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*365, val))
8180Sstevel@tonic-gate out(flags|O_NONL, "%lluyear%s", val, (val == 1) ? "" : "s");
8190Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*30, val))
8200Sstevel@tonic-gate out(flags|O_NONL, "%llumonth%s", val, (val == 1) ? "" : "s");
8210Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24*7, val))
8220Sstevel@tonic-gate out(flags|O_NONL, "%lluweek%s", val, (val == 1) ? "" : "s");
8230Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL*60*60*24, val))
8240Sstevel@tonic-gate out(flags|O_NONL, "%lluday%s", val, (val == 1) ? "" : "s");
8250Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL*60*60, val))
8260Sstevel@tonic-gate out(flags|O_NONL, "%lluhour%s", val, (val == 1) ? "" : "s");
8270Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL*60, val))
8280Sstevel@tonic-gate out(flags|O_NONL, "%lluminute%s", val, (val == 1) ? "" : "s");
8290Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000000ULL, val))
8300Sstevel@tonic-gate out(flags|O_NONL, "%llusecond%s", val, (val == 1) ? "" : "s");
8310Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000000ULL, val))
8320Sstevel@tonic-gate out(flags|O_NONL, "%llums", val);
8330Sstevel@tonic-gate else if (NOREMAINDER(*ullp, 1000ULL, val))
8340Sstevel@tonic-gate out(flags|O_NONL, "%lluus", val);
8350Sstevel@tonic-gate else
8360Sstevel@tonic-gate out(flags|O_NONL, "%lluns", *ullp);
8370Sstevel@tonic-gate }
838