4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
32 /* we need to define this to get strtok_r from string.h */
33 /* SEEMS LIKE A BUG TO ME */
67 static boolean_t
matchattrs(expr_t
* expr_p
, const char *attrs
);
68 static void matchvals(spec_t
* spec_p
, char *attrstr
,
69 char *valstr
, void *calldatap
);
70 static void matched(spec_t
* spec_p
, char *valstr
, void *calldatap
);
73 /* ---------------------------------------------------------------- */
74 /* ----------------------- Public Functions ----------------------- */
75 /* ---------------------------------------------------------------- */
78 * expr() - builds an expr
88 queue_init(&new_p
->qn
);
89 new_p
->left_p
= left_p
;
90 new_p
->right_p
= right_p
;
98 * expr_dup() - duplicates an expression list
102 expr_dup(expr_t
* list_p
)
110 /* copy the first node */
111 head_p
= expr(spec_dup(list_p
->left_p
),
112 spec_dup(list_p
->right_p
));
114 /* append each additional node */
116 while (expr_p
= (expr_t
*) queue_next(&list_p
->qn
, &expr_p
->qn
)) {
119 new_p
= expr(spec_dup(expr_p
->left_p
),
120 spec_dup(expr_p
->right_p
));
121 (void) queue_append(&head_p
->qn
, &new_p
->qn
);
130 * expr_destroy() - destroys an expression list
134 expr_destroy(expr_t
* list_p
)
138 while (expr_p
= (expr_t
*) queue_next(&list_p
->qn
, &list_p
->qn
)) {
139 (void) queue_remove(&expr_p
->qn
);
142 spec_destroy(expr_p
->left_p
);
144 spec_destroy(expr_p
->right_p
);
149 spec_destroy(list_p
->left_p
);
151 spec_destroy(list_p
->right_p
);
154 } /* end expr_destroy */
158 * expr_list() - append a expr_t to a list
162 expr_list(expr_t
* h
,
165 /* queue append handles the NULL cases OK */
166 return ((expr_t
*) queue_append(&h
->qn
, &f
->qn
));
168 } /* end expr_list */
172 * expr_print() - pretty prints an expr list
176 expr_print(FILE * stream
,
179 expr_t
*expr_p
= NULL
;
181 while ((expr_p
= (expr_t
*) queue_next(&list_p
->qn
, &expr_p
->qn
))) {
182 spec_print(stream
, expr_p
->left_p
);
183 (void) fprintf(stream
, "=");
184 spec_print(stream
, expr_p
->right_p
);
185 (void) fprintf(stream
, " ");
188 } /* end expr_print */
192 * expr_match() - figures out whether a probe matches in an expression list
196 expr_match(expr_t
* list_p
,
199 expr_t
*expr_p
= NULL
;
201 while ((expr_p
= (expr_t
*) queue_next(&list_p
->qn
, &expr_p
->qn
))) {
202 if (matchattrs(expr_p
, attrs
))
208 } /* end expr_match */
211 /* ---------------------------------------------------------------- */
212 /* ----------------------- Private Functions ---------------------- */
213 /* ---------------------------------------------------------------- */
215 typedef struct matchargs
{
222 matchattrs(expr_t
* expr_p
,
227 args
.spec_p
= expr_p
->right_p
;
228 args
.match
= B_FALSE
;
230 spec_attrtrav(expr_p
->left_p
,
231 (char *) attrs
, matchvals
, (void *) &args
);
235 } /* end matchattrs */
240 matchvals(spec_t
* spec_p
,
245 matchargs_t
*args_p
= (matchargs_t
*) calldatap
;
247 spec_valtrav(args_p
->spec_p
, valstr
, matched
, calldatap
);
254 matched(spec_t
* spec_p
,
258 matchargs_t
*args_p
= (matchargs_t
*) calldatap
;
260 args_p
->match
= B_TRUE
;