8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / tnf / prex / set.c
blobdb7f4fb29a339b3a52a1505249ac9ff2e415a40f
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Includes
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include "queue.h"
36 #include "set.h"
37 #include "new.h"
41 * Globals
44 static queue_node_t g_setlist = {
45 &g_setlist,
46 &g_setlist};
50 * Forward Declarations
53 static void set_destroy(set_t * set_p);
54 static void set_print(FILE * stream, set_t * set_p);
58 * set() - creates a set
61 set_t *
62 set(char *setname_p, expr_t * exprlist_p)
64 set_t *new_p;
65 set_t *old_p;
67 /* does this setname exist already? */
68 old_p = set_find(setname_p);
69 if (old_p)
70 set_destroy(old_p);
72 /* create a new set */
73 new_p = new(set_t);
74 queue_init(&new_p->qn);
75 new_p->setname_p = setname_p;
76 new_p->exprlist_p = exprlist_p;
78 /* append the new set to the global list */
79 (void) queue_append(&g_setlist, &new_p->qn);
81 return (new_p);
83 } /* end set */
87 * set_destroy() - destroys a set and related resources
90 static void
91 set_destroy(set_t * set_p)
93 if (!set_p)
94 return;
96 /* remove ourselves from any list */
97 if (!queue_isempty(&set_p->qn))
98 (void) queue_remove(&set_p->qn);
100 if (set_p->setname_p)
101 free(set_p->setname_p);
103 /* destroy the exprlist */
104 expr_destroy(set_p->exprlist_p);
106 free(set_p);
108 } /* end set_destroy */
112 * set_list() - pretty prints the global setlist
115 void
116 set_list(void)
118 set_t *set_p;
120 set_p = (set_t *) & g_setlist;
121 while ((set_p = (set_t *) queue_next(&g_setlist, &set_p->qn))) {
122 (void) printf("$%-8s ", set_p->setname_p);
123 set_print(stdout, set_p);
124 (void) printf("\n");
127 } /* end set_list */
131 * set_print() - pretty prints a set
134 static void
135 set_print(FILE * stream, set_t * set_p)
137 if (!set_p)
138 return;
140 expr_print(stream, set_p->exprlist_p);
142 } /* end set_print */
145 #ifdef OLD
147 * set_match() - discerns whether a probe is in a set
150 boolean_t
151 set_match(set_t * set_p, const char *name, const char *keys)
153 if (!set_p)
154 return (B_FALSE);
156 return (expr_match(set_p->exprlist_p, name, keys));
158 } /* end set_match */
159 #endif
163 * set_find() - finds a set by name
166 set_t *
167 set_find(char *setname_p)
169 set_t *set_p;
171 if (!setname_p)
172 return (NULL);
174 set_p = (set_t *) & g_setlist;
175 while ((set_p = (set_t *) queue_next(&g_setlist, &set_p->qn)))
176 if (strcmp(setname_p, set_p->setname_p) == 0)
177 return (set_p);
179 return (NULL);
181 } /* end set_find */