2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: genlib.c /main/5 1996/09/27 19:01:37 drk $ */
25 /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
26 /* All Rights Reserved */
28 /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
29 /* UNIX System Laboratories, Inc. */
30 /* The copyright notice above does not evidence any */
31 /* actual or intended publication of such source code. */
34 #include <sys/types.h>
53 static char * ReturnUsageMsg(
57 struct libstruct *All_libs;
89 case 0: errmsg = GETMESSAGE(9,1, "call [-F] [-n] [-r] function [arg] ... [++] [argModifier ...]");
91 case 1: errmsg = GETMESSAGE(9,2, "define [-R] name value");
93 case 2: errmsg = GETMESSAGE(9,3, "deflist [-p prefix] address");
95 case 3: errmsg = GETMESSAGE(9,4, "deref [-p] [-l] [-len] address [variable]");
97 case 4: errmsg = GETMESSAGE(9,5, "field_comp type address [criterion ...]");
99 case 5: errmsg = GETMESSAGE(9,6, "field_get [-v variable] type address [fieldName ...]");
101 case 6: errmsg = GETMESSAGE(9,7, "finddef definitionName [variable]");
103 case 7: errmsg = GETMESSAGE(9,8, "findsym symbolName [variable]");
105 case 8: errmsg = GETMESSAGE(9,9, "sizeof typeName [variable]");
107 case 9: errmsg = GETMESSAGE(9,10,"struct [-R] name fieldName[:type] ...");
109 case 10: errmsg = GETMESSAGE(9,11, "structlist [-i id] [-p prefix] address");
111 case 11: errmsg = GETMESSAGE(9,12, "symbolic [-m] -t type ... symbolic ...");
113 case 12: errmsg = GETMESSAGE(9,13,"typedef [-R] typeDescriptor typeName");
128 for (i = 0; i < sizeof(Xk_usage) / sizeof(struct usage); i++)
132 errmsg = strdup(ReturnUsageMsg(Xk_usage[i].msgId));
136 else if (!funcname || (strcmp(funcname, Xk_usage[i].funcname) == 0))
138 errhdr = strdup(GETMESSAGE(9,14, "Usage: %s"));
139 errmsg = strdup(ReturnUsageMsg(Xk_usage[i].msgId));
140 printerrf("", errhdr, errmsg, NULL, NULL, NULL, NULL, NULL, NULL,
147 return(funcname ? SH_FAIL : SH_SUCC);
155 #if defined(STATICLIB) || ( !defined(DYNLIB) && !defined(HPUX_DYNLIB))
156 struct symarray dummy;
163 #if defined(STATICLIB) || (!defined(DYNLIB) && !defined(HPUX_DYNLIB))
166 if ((found = (void *) bsearch((char *) &dummy, Symarray,
167 Symsize-1, sizeof(struct symarray), symcomp)) != NULL)
168 return(((struct symarray *) found)->addr);
169 #endif /* STATICLIB */
172 for (i = 0; i < Nlibs; i++)
173 for (j = 0; j < All_libs[i].nlibs; j++)
174 if ((found = dlsym(All_libs[i].libs[j].handle,
176 return((unsigned long) found);
183 if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
184 return((unsigned long) found);
185 if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
186 return((unsigned long) found);
187 handle = PROG_HANDLE;
188 if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
189 return((unsigned long) found);
190 if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
191 return((unsigned long) found);
193 #endif /* HPUX_DYNLIB */
205 struct symarray dummy;
211 if ((found = fsym(argv[1], -1)) != NULL) {
215 sprintf(buf, "%s=0x%lx", argv[2], found);
219 sprintf(xk_ret_buffer, "0x%lx", found);
220 xk_ret_buf = xk_ret_buffer;
224 errmsg = strdup(GetSharedMsg(DT_UNDEF_SYMBOL));
225 printerrf(argv[0], errmsg, argv[1], NULL, NULL,
226 NULL, NULL, NULL, NULL, NULL);
233 #ifndef SPRINTF_RET_LEN
235 * SYSTEM V sprintf() returns the length of the buffer, other versions
236 * of the UNIX System don't. So, if the SPRINTF_RET_LEN flag is not true,
237 * then we define an alternate function, lsprintf(), which has the SYSV
238 * behavior. Otherwise, lsprintf is #defined in exksh.h to be the
255 sprintf(buf, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7);