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 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: isfcbindex.c /main/3 1995/10/23 11:38:43 rswiston $ */
29 static char sccsid[] = "@(#)isfcbindex.c 1.3 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
39 * Functions that deal with the key descriptors in FCB
44 #include "isam_impl.h"
46 Static int _keypart2cmp();
48 * _isfcb_primkeyadd(fcb, keydesc2)
50 * Add priamry key descriptor to FCB.
55 _isfcb_primkeyadd(fcb, keydesc2)
62 keydesc2->k2_keyid = ++fcb->lastkeyid;
64 fcb->keys[0] = *keydesc2;
70 * _isfcb_primkeyel(fcb)
77 _isfcb_primkeydel(fcb)
80 if (FCB_NOPRIMARY_KEY(fcb))
83 memset((char *)&fcb->keys[0], 0, sizeof(fcb->keys[0]));
89 * _isfcb_altkeyadd(fcb, keydesc2)
91 * Add alternate key descriptor to FCB.
96 _isfcb_altkeyadd(fcb, keydesc2)
100 assert (fcb->nkeys < MAXNKEYS);
105 keydesc2->k2_keyid = ++fcb->lastkeyid;
108 * Reallocate fcb->keys table.
110 fcb->keys = (Keydesc2 *)
111 _isrealloc((char *)fcb->keys,
112 (unsigned) (sizeof(Keydesc2) * (fcb->nkeys + 1)));
114 fcb->keys[fcb->nkeys] = *keydesc2;
122 * pkeydesc2 = _isfcb_findkey(fcb, keydesc2)
124 * Find key descriptor.
129 _isfcb_findkey(fcb, keydesc2)
133 int nkeys = fcb->nkeys;
134 register Keydesc2 *kp2;
138 for (i = 0; i < nkeys; i++) {
141 if (keydesc2->k2_nparts == kp2->k2_nparts) {
143 nparts = keydesc2->k2_nparts;
144 for (j = 0; j < nparts; j++) {
145 if (_keypart2cmp(keydesc2->k2_part + j, kp2->k2_part + j) != 0)
154 return ((struct keydesc2 *) 0); /* Key descriptor not found */
158 * pkeydesc2 = _isfcb_altkeydel(fcb, keydesc2)
160 * Delete key descriptor from FCB.
165 _isfcb_altkeydel(fcb, keydesc2)
169 int nkeys = fcb->nkeys;
171 register Keydesc2 *kp2;
174 for (i = 0; i < nkeys; i++) {
177 if (keydesc2->k2_nparts == kp2->k2_nparts) {
179 nparts = keydesc2->k2_nparts;
180 for (j = 0; j < nparts; j++) {
181 if (_keypart2cmp(keydesc2->k2_part + j, kp2->k2_part + j) != 0)
186 break; /* Key found */
191 return (EBADKEY); /* Key descriptor not found */
194 return (EPRIMKEY); /* Cannot delete primary key */
198 * Shift the end of the table toward the beginning to delete the entry.
201 memcpy( (char *)(fcb->keys + i),(char *)(fcb->keys + i + 1),
202 (nkeys - 1 - i) * sizeof (fcb->keys[0]));
210 /* compare key parts */
213 register struct keypart2 *l, *r;
215 return !(l->kp2_type == r->kp2_type && l->kp2_start == r->kp2_start &&
216 l->kp2_leng == r->kp2_leng);
220 * pkeydesc2 = _isfcb_indfindkey(fcb, keyind)
222 * Find key descriptor by its keyind value.
227 _isfcb_indfindkey(fcb, keyid)
231 int nkeys = fcb->nkeys;
232 register Keydesc2 *keys = fcb->keys;
235 for (i = 0; i < nkeys; i++) {
236 if (keys[i].k2_keyid == keyid)
240 return ((i == nkeys) ? NULL : keys + i);