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"
51 static queue_node_t g_cmdlist
= {
57 * cmd_set() - creates a cmd using a named set and adds it to the global list
61 cmd_set(char *setname_p
, cmd_kind_t kind
, char *fcnname_p
)
66 set_p
= set_find(setname_p
);
68 semantic_err(gettext("no set named \"$%s\""), setname_p
);
71 if (kind
== CMD_CONNECT
&& !fcn_find(fcnname_p
)) {
72 semantic_err(gettext("no function named \"&%s\""), fcnname_p
);
76 queue_init(&new_p
->qn
);
78 new_p
->isnamed
= B_TRUE
;
79 new_p
->expr
.setname_p
= setname_p
;
81 new_p
->isnamed
= B_FALSE
;
82 new_p
->expr
.expr_p
= expr_dup(set_p
->exprlist_p
);
84 new_p
->isnew
= B_TRUE
;
86 new_p
->fcnname_p
= fcnname_p
;
88 (void) queue_append(&g_cmdlist
, &new_p
->qn
);
95 * cmd_expr() - creates a cmd using a set and adds it to the global list
99 cmd_expr(expr_t
* expr_p
, cmd_kind_t kind
, char *fcnname_p
)
103 if (kind
== CMD_CONNECT
&& !fcn_find(fcnname_p
)) {
104 semantic_err(gettext("no function named \"&%s\""), fcnname_p
);
108 queue_init(&new_p
->qn
);
109 new_p
->isnamed
= B_FALSE
;
110 new_p
->expr
.expr_p
= expr_p
;
111 new_p
->isnew
= B_TRUE
;
113 new_p
->fcnname_p
= fcnname_p
;
115 (void) queue_append(&g_cmdlist
, &new_p
->qn
);
127 cmd_destroy(cmd_t
* cmd_p
)
132 if (!queue_isempty(&cmd_p
->qn
))
133 (void) queue_remove(&cmd_p
->qn
);
136 expr_destroy(cmd_p
->expr
.expr_p
);
140 } /* end cmd_destroy */
145 * cmd_list() - pretty prints the global cmdlist
155 cmd_p
= (cmd_t
*) & g_cmdlist
;
156 while ((cmd_p
= (cmd_t
*) queue_next(&g_cmdlist
, &cmd_p
->qn
))) {
157 switch (cmd_p
->kind
) {
180 (void) printf("[%d] %s ", i
++, str_p
);
182 if (cmd_p
->kind
== CMD_CONNECT
) {
183 (void) printf("&%s ", cmd_p
->fcnname_p
);
185 if (!cmd_p
->isnamed
) {
186 expr_print(stdout
, cmd_p
->expr
.expr_p
);
196 * cmd_traverse() - calls the suppied traversal function on each command.
200 cmd_traverse(cmd_traverse_func_t percmdfunc
, void *calldata_p
)
203 tnfctl_errcode_t err
= TNFCTL_ERR_NONE
;
205 cmd_p
= (cmd_t
*) & g_cmdlist
;
206 while ((cmd_p
= (cmd_t
*) queue_next(&g_cmdlist
, &cmd_p
->qn
))) {
210 if (!cmd_p
->isnamed
) {
211 expr_p
= cmd_p
->expr
.expr_p
;
214 if (cmd_p
->kind
== CMD_CONNECT
) {
215 fcn_p
= fcn_find(cmd_p
->fcnname_p
);
221 err
= (*percmdfunc
) (expr_p
,
223 fcn_p
, cmd_p
->isnew
, calldata_p
);
228 } /* end cmd_traverse */
232 * cmd_traverse() - calls the suppied traversal function on each command.
236 cmd_callback(cmd_t
*cmd_p
, cmd_traverse_func_t percmdfunc
, void *calldata_p
)
238 tnfctl_errcode_t err
= TNFCTL_ERR_NONE
;
242 if (!cmd_p
->isnamed
) {
243 expr_p
= cmd_p
->expr
.expr_p
;
246 if (cmd_p
->kind
== CMD_CONNECT
) {
247 fcn_p
= fcn_find(cmd_p
->fcnname_p
);
253 err
= (*percmdfunc
) (expr_p
, cmd_p
->kind
, fcn_p
, cmd_p
->isnew
,
261 * cmd_mark() - mark all of the commands in the global list as old
269 cmd_p
= (cmd_t
*) & g_cmdlist
;
270 while ((cmd_p
= (cmd_t
*) queue_next(&g_cmdlist
, &cmd_p
->qn
))) {
271 cmd_p
->isnew
= B_FALSE
;
281 cmd_delete(int cmdnum
)
286 cmd_p
= (cmd_t
*) & g_cmdlist
;
287 while ((cmd_p
= (cmd_t
*) queue_next(&g_cmdlist
, &cmd_p
->qn
))) {
295 } /* end cmd_delete */