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 librararies 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: define.c /main/4 1995/11/01 15:51:03 rswiston $ */
24 /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
25 /* All Rights Reserved */
27 /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
28 /* UNIX System Laboratories, Inc. */
29 /* The copyright notice above does not evidence any */
30 /* actual or intended publication of such source code. */
33 #include "exksh.h" /* which includes sys/types.h */
34 #include <sys/param.h>
45 static growdef( void ) ;
46 static int add_deflist(
47 struct symarray *defptr,
49 static def_init( void ) ;
53 static struct symarray *Dyndef = NULL;
54 static int Ndyndef = 0;
55 static int Sdyndef = 0;
56 static char defInited = 0;
58 static char use[] = "0x%x";
59 static char use2[] = "%s=0x%x";
64 struct symarray *defs;
67 struct deflist *Deflist = NULL;
79 if (!(Dyndef = (struct symarray *) realloc(Dyndef, (Sdyndef + 20) *
80 sizeof(struct symarray))))
84 Deflist->defs = Dyndef;
85 memset(((char *) Dyndef) + Sdyndef * sizeof(struct symarray), '\0',
86 20 * sizeof(struct symarray));
95 int i, argstart, redo;
97 struct symarray *found, dummy;
102 if (argc > 1 && C_PAIR(argv[1], '-', 'R'))
113 if ((argstart +1) >= argc)
116 name = argv[argstart++];
118 found = (struct symarray *) bsearch((char *) &dummy, Dyndef, Ndyndef,
119 sizeof(struct symarray), symcomp);
129 if (Sdyndef == Ndyndef)
133 for (i = Ndyndef - 1; i > 0; i--)
135 if (strcmp(name, Dyndef[i - 1].str) >= 0)
137 Dyndef[i] = Dyndef[i - 1];
141 Dyndef[i].str = strdup(name);
144 RIF(xk_par_int(argv + argstart, &Dyndef[i].addr, NULL));
153 struct symarray *found, dummy;
160 for (i = 0; i < Ndeflist; i++)
164 if (Deflist[i].size < 0)
166 found = (struct symarray *) lfind((char *) &dummy, Deflist[i].defs,
167 (unsigned int *) &Deflist[i].size, sizeof(struct symarray),
172 found = (struct symarray *) bsearch((char *) &dummy,
173 Deflist[i].defs, Deflist[i].size, sizeof(struct symarray),
194 struct symarray *defptr = NULL;
197 for (i = 1; (i < argc) && argv[i]; i++)
199 if (argv[i][0] == '-')
201 for (j = 1; argv[i][j]; j++)
209 prefix = argv[i] + j;
210 j += strlen(prefix) - 2;
215 j = strlen(prefix) - 1;
223 if ((defptr = (struct symarray *) getaddr(argv[i])) == NULL)
225 errmsg=strdup(GETMESSAGE(3,1,
226 "Unable to locate the definition list '%s'"));
227 printerrf(argv[0], errmsg, argv[i], NULL, NULL,
228 NULL, NULL, NULL, NULL, NULL);
240 for (i = 0; i < Ndeflist; i++)
241 if ((Deflist[i].defs == defptr) &&
242 (!prefix || (strcmp(Deflist[i].prefix, prefix) == 0)))
247 return(add_deflist(defptr, prefix));
252 struct symarray *defptr,
259 Deflist = (struct deflist *) malloc((Ndeflist + 1) *
260 sizeof(struct deflist));
264 Deflist = (struct deflist *) realloc(Deflist, (Ndeflist + 1) *
265 sizeof(struct deflist));
271 Deflist[Ndeflist].defs = defptr;
272 Deflist[Ndeflist].prefix = strdup(prefix);
274 Deflist[Ndeflist].size = 0;
277 for (i = 1; defptr[i].str && defptr[i].str[0]; i++)
278 if (symcomp((void *) (defptr + i), (void *) (defptr + i - 1)) < 0)
281 if (!(defptr[i].str && defptr[i].str[0]))
282 Deflist[Ndeflist].size = i;
284 Deflist[Ndeflist].size = -1;
296 struct symarray dummy;
302 if (fdef(argv[1], &found))
308 sprintf(buf, use2, argv[2], found);
313 sprintf(xk_ret_buffer, use, found);
314 xk_ret_buf = xk_ret_buffer;
318 errmsg = strdup(GETMESSAGE(3, 2, "Unable to locate the define '%s'"));
319 printerrf(argv[0], errmsg, argv[1], NULL, NULL, NULL,
320 NULL, NULL, NULL, NULL);
332 if (!(Dyndef = (struct symarray *) malloc(20 * sizeof(struct symarray))))
334 errhdr = strdup(GetSharedMsg(DT_ERROR));
335 errmsg = strdup(GetSharedMsg(DT_ALLOC_FAILURE));
336 printerr(errhdr, errmsg, NULL);
341 Dyndef[0].str = NULL;
344 add_deflist(Dyndef, "dynamic");
345 add_deflist(basedefs, "base");