8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / tnf / prex / fcn.c
blob527bc5fc20063eb3d853848ae7b92598d032cdc9
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 <stdlib.h>
33 #include <string.h>
34 #include <libintl.h>
35 #include "queue.h"
36 #include "set.h"
37 #include "fcn.h"
38 #include "new.h"
39 #include "source.h"
43 * Globals
46 static queue_node_t g_fcnlist = {
47 &g_fcnlist,
48 &g_fcnlist};
51 * Forward Declarations
54 static void fcn_destroy(fcn_t * fcn_p);
55 static void fcn_print(FILE * stream, fcn_t * fcn_p);
59 * fcn() - builds a function block and inserts it on the global list.
62 #define NSYMS 1
64 void
65 fcn(char *name_p, char *entry_name_p)
67 fcn_t *new_p;
68 fcn_t *old_p;
70 /* does this setname exist already? */
71 old_p = fcn_find(name_p);
72 if (old_p)
73 fcn_destroy(old_p);
75 /* create a new set */
76 new_p = new(fcn_t);
77 queue_init(&new_p->qn);
78 new_p->name_p = name_p;
79 new_p->entry_name_p = entry_name_p;
81 #ifdef OLD
83 * allocate a target function block, and stuff the init and fini
84 * addrs
86 prbstat = prb_targmem_alloc(g_procfd, sizeof (probe_funcs_t),
87 &new_p->funcs_p);
88 if (prbstat) {
89 semantic_err(gettext("problem allocating target memory"));
90 goto Error;
92 prbstat = prb_proc_write(g_procfd, new_p->funcs_p,
93 &new_p->funcs, sizeof (probe_funcs_t));
94 if (prbstat) {
95 semantic_err(gettext(
96 "setup problem, initial/final "
97 "funcs in target memory"));
98 goto Error;
100 #endif
102 /* append the new set to the global list */
103 (void) queue_append(&g_fcnlist, &new_p->qn);
105 return;
107 Error:
108 if (new_p)
109 free(new_p);
110 return;
112 } /* end fcn */
116 * fcn_destroy() - destroys a fcn and related resources
119 static void
120 fcn_destroy(fcn_t * fcn_p)
122 if (!fcn_p)
123 return;
125 /* remove ourselves from any list */
126 if (!queue_isempty(&fcn_p->qn))
127 (void) queue_remove(&fcn_p->qn);
129 if (fcn_p->name_p)
130 free(fcn_p->name_p);
131 if (fcn_p->entry_name_p)
132 free(fcn_p->entry_name_p);
134 free(fcn_p);
136 } /* end fcn_destroy */
140 * fcn_list() - pretty prints the global fcnlist
143 void
144 fcn_list(void)
146 fcn_t *fcn_p;
148 fcn_p = (fcn_t *) & g_fcnlist;
149 while ((fcn_p = (fcn_t *) queue_next(&g_fcnlist, &fcn_p->qn))) {
150 fcn_print(stdout, fcn_p);
153 } /* end fcn_list */
157 * fcn_print() - pretty prints a fcn
160 static void
161 fcn_print(FILE * stream, fcn_t * fcn_p)
163 if (!fcn_p)
164 return;
166 (void) fprintf(stream, "&%-8s %-24s\n",
167 fcn_p->name_p, fcn_p->entry_name_p);
169 } /* end fcn_print */
173 * fcn_findname() - find the created name, given an entry name
176 char *
177 fcn_findname(const char * const entry_p)
179 fcn_t *fcn_p;
181 if (!entry_p)
182 return (NULL);
184 fcn_p = (fcn_t *) & g_fcnlist;
185 while ((fcn_p = (fcn_t *) queue_next(&g_fcnlist, &fcn_p->qn)))
186 if (strcmp(entry_p, fcn_p->entry_name_p) == 0)
187 return (fcn_p->name_p);
189 return (NULL);
191 } /* end fcn_findname */
195 * fcn_find() - finds a fcn by name
198 fcn_t *
199 fcn_find(char *fcnname_p)
201 fcn_t *fcn_p;
203 if (!fcnname_p)
204 return (NULL);
206 fcn_p = (fcn_t *) & g_fcnlist;
207 while ((fcn_p = (fcn_t *) queue_next(&g_fcnlist, &fcn_p->qn)))
208 if (strcmp(fcnname_p, fcn_p->name_p) == 0)
209 return (fcn_p);
211 return (NULL);
213 } /* end set_find */