1 /* $XConsortium: genlib.c /main/5 1996/09/27 19:01:37 drk $ */
3 /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
4 /* All Rights Reserved */
6 /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
7 /* UNIX System Laboratories, Inc. */
8 /* The copyright notice above does not evidence any */
9 /* actual or intended publication of such source code. */
12 #include <sys/types.h>
31 static char * ReturnUsageMsg(
35 struct libstruct *All_libs;
67 case 0: errmsg = GETMESSAGE(9,1, "call [-F] [-n] [-r] function [arg] ... [++] [argModifier ...]");
69 case 1: errmsg = GETMESSAGE(9,2, "define [-R] name value");
71 case 2: errmsg = GETMESSAGE(9,3, "deflist [-p prefix] address");
73 case 3: errmsg = GETMESSAGE(9,4, "deref [-p] [-l] [-len] address [variable]");
75 case 4: errmsg = GETMESSAGE(9,5, "field_comp type address [criterion ...]");
77 case 5: errmsg = GETMESSAGE(9,6, "field_get [-v variable] type address [fieldName ...]");
79 case 6: errmsg = GETMESSAGE(9,7, "finddef definitionName [variable]");
81 case 7: errmsg = GETMESSAGE(9,8, "findsym symbolName [variable]");
83 case 8: errmsg = GETMESSAGE(9,9, "sizeof typeName [variable]");
85 case 9: errmsg = GETMESSAGE(9,10,"struct [-R] name fieldName[:type] ...");
87 case 10: errmsg = GETMESSAGE(9,11, "structlist [-i id] [-p prefix] address");
89 case 11: errmsg = GETMESSAGE(9,12, "symbolic [-m] -t type ... symbolic ...");
91 case 12: errmsg = GETMESSAGE(9,13,"typedef [-R] typeDescriptor typeName");
106 for (i = 0; i < sizeof(Xk_usage) / sizeof(struct usage); i++)
110 errmsg = strdup(ReturnUsageMsg(Xk_usage[i].msgId));
114 else if (!funcname || (strcmp(funcname, Xk_usage[i].funcname) == 0))
116 errhdr = strdup(GETMESSAGE(9,14, "Usage: %s"));
117 errmsg = strdup(ReturnUsageMsg(Xk_usage[i].msgId));
118 printerrf("", errhdr, errmsg, NULL, NULL, NULL, NULL, NULL, NULL,
125 return(funcname ? SH_FAIL : SH_SUCC);
133 #if defined(STATICLIB) || ( !defined(DYNLIB) && !defined(HPUX_DYNLIB))
134 struct symarray dummy;
141 #if defined(STATICLIB) || (!defined(DYNLIB) && !defined(HPUX_DYNLIB))
144 if ((found = (void *) bsearch((char *) &dummy, Symarray,
145 Symsize-1, sizeof(struct symarray), symcomp)) != NULL)
146 return(((struct symarray *) found)->addr);
147 #endif /* STATICLIB */
150 for (i = 0; i < Nlibs; i++)
151 for (j = 0; j < All_libs[i].nlibs; j++)
152 if ((found = dlsym(All_libs[i].libs[j].handle,
154 return((unsigned long) found);
161 if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
162 return((unsigned long) found);
163 if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
164 return((unsigned long) found);
165 handle = PROG_HANDLE;
166 if ((shl_findsym(&handle, str, TYPE_PROCEDURE, &found)) == 0)
167 return((unsigned long) found);
168 if ((shl_findsym(&handle, str, TYPE_DATA, &found)) == 0)
169 return((unsigned long) found);
171 #endif /* HPUX_DYNLIB */
183 struct symarray dummy;
189 if ((found = fsym(argv[1], -1)) != NULL) {
193 sprintf(buf, "%s=0x%lx", argv[2], found);
197 sprintf(xk_ret_buffer, "0x%lx", found);
198 xk_ret_buf = xk_ret_buffer;
202 errmsg = strdup(GetSharedMsg(DT_UNDEF_SYMBOL));
203 printerrf(argv[0], errmsg, argv[1], NULL, NULL,
204 NULL, NULL, NULL, NULL, NULL);
211 #ifndef SPRINTF_RET_LEN
213 * SYSTEM V sprintf() returns the length of the buffer, other versions
214 * of the UNIX System don't. So, if the SPRINTF_RET_LEN flag is not true,
215 * then we define an alternate function, lsprintf(), which has the SYSV
216 * behavior. Otherwise, lsprintf is #defined in exksh.h to be the
233 sprintf(buf, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7);