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: symbolic.c /main/4 1995/11/01 15:56:54 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. */
35 #include "exksh.h" /* which includes sys/types.h */
36 #include "struct.h" /* which includes sys/types.h */
40 struct symlist *Symlist = NULL;
44 ** There is an implicit dirty trick going on here. It is effective,
45 ** efficient and will work anywhere but it is tricky. A memtbl has
46 ** strings in it. The fact that a byte-by-byte comparison is being
47 ** done on a memtbl means that pointers are being compared. This
48 ** means that EVERY UNIQUE MEMTBL SHOULD HAVE SOME UNIQUE FIELD (i.e.
49 ** in this case, the string for the name field). If somebody uses
50 ** an algorithm in do_struct() that saves string space (by seeing if
51 ** the same string is lying around) this code will break and an ID
52 ** field will be necessary to maintain uniqueness.
62 for (i = 0; i < Nsymlist; i++)
63 if (memcmp(tbl, &Symlist[i].tbl, sizeof(struct memtbl)) == 0)
75 struct symarray syms[50];
83 for (i = 1; (i < argc) && argv[i]; i++) {
84 if (argv[i][0] == '-') {
85 for (j = 1; argv[i][j]; j++) {
92 type = argv[i] + j + 1;
95 j = strlen(argv[i]) - 1;
101 syms[nsyms++].str = argv[i];
106 if ((type == NULL) || (!nsyms)) {
109 if (p = strchr(type, '.')) {
111 if ((tbl = all_tbl_search(type, 0)) == NULL) {
113 errmsg = strdup(GetSharedMsg(DT_UNDEF_TYPE));
114 printerrf(argv[0], errmsg, type, NULL, NULL,
115 NULL, NULL, NULL, NULL, NULL);
119 if ((tbl = ffind(tbl, p + 1, NULL)) == NULL) {
120 errmsg=strdup(GETMESSAGE(13,1,
121 "Unable to locate a field named '%s' for the type '%s'"));
122 printerrf(argv[0], errmsg, p + 1, type, NULL,
123 NULL, NULL, NULL, NULL, NULL);
130 else if ((tbl = all_tbl_search(type, 0)) == NULL) {
131 errmsg = strdup(GetSharedMsg(DT_UNDEF_TYPE));
132 printerrf(argv[0], errmsg, type, NULL, NULL,
133 NULL, NULL, NULL, NULL, NULL);
138 for (i = 0; i < nsyms; i++) {
139 if (!fdef(syms[i].str, &j)) {
140 errmsg=strdup(GETMESSAGE(13,2,
141 "The name '%s' has not been defined"));
142 printerrf(argv[0], errmsg, syms[i].str,
143 NULL, NULL, NULL, NULL, NULL, NULL, NULL);
147 syms[i].str = strdup(syms[i].str);
150 add_symbolic(isflag, tbl, syms, nsyms);
158 struct symarray *syms,
161 struct symlist *symptr;
163 if ((symptr = fsymbolic(tbl)) == NULL) {
165 Symlist = (struct symlist *) malloc((Nsymlist + 1) * sizeof(struct symlist));
167 Symlist = (struct symlist *) realloc(Symlist, (Nsymlist + 1) * sizeof(struct symlist));
170 symptr = Symlist + Nsymlist;
176 symptr->nsyms = nsyms;
177 symptr->isflag = isflag;
178 symptr->syms = (struct symarray *) malloc(nsyms * sizeof(struct symarray));
179 memcpy(symptr->syms, syms, nsyms * sizeof(struct symarray));