1 /* $XConsortium: nametbl.c /main/1 1996/04/21 19:24:03 drk $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
16 #define MAX_CAL_TBL_SIZE 23
17 #define MAX_ENTRY_TBL_SIZE 37
19 extern _DtCmNameTable *
20 _DtCm_make_name_table(int size, char **names)
25 if ((tbl = (_DtCmNameTable *)calloc(1, sizeof(_DtCmNameTable))) == NULL)
28 if ((tbl->tbl = _DtCmMakeHash(MAX_CAL_TBL_SIZE)) == NULL) {
33 if ((tbl->names = (char **)malloc(sizeof(char *) * (size+1))) == NULL) {
34 _DtCm_free_name_table(tbl);
38 for (i = 1; i <= size; i++) {
39 if ((tbl->names[i] = strdup(names[i])) == NULL) {
41 _DtCm_free_name_table(tbl);
45 *(int *)_DtCmGetHash(tbl->tbl, (unsigned char *)names[i]) = i;
54 _DtCm_free_name_table(_DtCmNameTable *tbl)
58 if (tbl == NULL) return;
61 _DtCmDestroyHash(tbl->tbl, NULL, NULL);
63 for (i = 1; i <= tbl->size; i++)
73 * if index == 0, then add one more element to the table
74 * otherwise use the index to add the new name and extend the
75 * table by (index - size)
77 extern CSA_return_code
78 _DtCm_add_name_to_table(_DtCmNameTable *tbl, int index, char *newname)
83 if (index > 0 && index <= tbl->size && tbl->names[index])
84 return (CSA_E_INVALID_PARAMETER);
87 index = tbl->size + 1;
89 /* add new name to table */
90 ptr = (int *)_DtCmGetHash(tbl->tbl, (unsigned char *)newname);
94 if (index > tbl->size) {
95 if ((newptr = (char **)realloc(tbl->names,
96 sizeof(char *)*(index + 1))) == NULL) {
98 return (CSA_E_INSUFFICIENT_MEMORY);
101 memset((void *)&tbl->names[tbl->size+1], NULL,
102 sizeof(char *)*(index - tbl->size));
106 if ((tbl->names[index] = strdup(newname)) == NULL) {
109 return (CSA_E_INSUFFICIENT_MEMORY);
112 if (index > tbl->size)
116 return (CSA_SUCCESS);
120 _DtCm_get_index_from_table(_DtCmNameTable *tbl, char *name)
124 ptr = (int *)_DtCmFindHash(tbl->tbl, (unsigned char *)name);
133 * if index == 0, then add one more element to the table
134 * other use the index to add the new name and extend the
135 * table by (index - size)
137 extern CSA_return_code
138 _DtCmExtendNameTable(
142 _DtCmNameTable *base,
145 _DtCmNameTable **tbl,
148 _DtCmNameTable *ntbl;
152 if (index > 0 && index <= (*tbl)->size)
153 return (CSA_E_INVALID_PARAMETER);
156 if ((ntbl = _DtCm_make_name_table(basesize, basenames)) == NULL)
159 return (CSA_E_INSUFFICIENT_MEMORY);
165 newindex = (index == 0) ? (*tbl)->size+1 : index;
166 if ((newarray = (int *)realloc(*types,
167 sizeof(int) * (newindex+1))) == NULL) {
168 return (CSA_E_INSUFFICIENT_MEMORY);
171 (*types)[newindex] = type;
175 return (_DtCm_add_name_to_table(*tbl, index, name));