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: iskeyconv.c /main/3 1995/10/23 11:41:54 rswiston $ */
30 * Copyright (c) 1988 by Sun Microsystems, Inc.
37 * Conversion functions between internal and external key descriptor
41 #include "isam_impl.h"
44 * _iskey_itox(pikdesc,pxkdesc)
46 * Convert internal key desc. to X/OPEN key descriptor.
48 * @param pikdesc NetISAM internal format
49 * @param pxkdesc X/OPEN format
52 _iskey_itox(struct keydesc2 *pikdesc, struct keydesc *pxkdesc)
57 memset ((char *)pxkdesc, 0, sizeof (*pxkdesc));
59 pxkdesc->k_flags = pikdesc->k2_flags;
60 nparts = pxkdesc->k_nparts = pikdesc->k2_nparts;
62 for (i = 0; i < nparts;i++) {
63 pxkdesc->k_part[i].kp_start = pikdesc->k2_part[i].kp2_start;
64 pxkdesc->k_part[i].kp_leng = pikdesc->k2_part[i].kp2_leng;
65 pxkdesc->k_part[i].kp_type = pikdesc->k2_part[i].kp2_type;
73 * Convert X/OPEN key descriptor to internal key descriptor.
75 * @param pikdesc NetISAM internal format
76 * @param pxkdesc X/OPEN format
79 _iskey_xtoi(struct keydesc2 *pikdesc, struct keydesc *pxkdesc)
83 int offset; /* Keep track of offset in key */
85 memset ((char *)pikdesc, 0, sizeof (*pikdesc));
87 pikdesc->k2_flags = pxkdesc->k_flags;
88 nparts = pikdesc->k2_nparts = pxkdesc->k_nparts;
92 * Every key entry starts with record number.
97 * If index allows duplicates, the key is augmented with duplicate
100 if ((pxkdesc->k_flags & DUPSMASK) == ISDUPS)
103 for (i = 0; i < nparts; i++) {
104 pikdesc->k2_part[i].kp2_start = pxkdesc->k_part[i].kp_start;
105 pikdesc->k2_part[i].kp2_leng = pxkdesc->k_part[i].kp_leng;
106 pikdesc->k2_part[i].kp2_type = pxkdesc->k_part[i].kp_type;
107 pikdesc->k2_part[i].kp2_offset = offset;
109 offset += pxkdesc->k_part[i].kp_leng;
112 /* Append recno to key descriptors. */
113 pikdesc->k2_part[i].kp2_start = 0; /* not used */
114 pikdesc->k2_part[i].kp2_leng = RECNOSIZE;
115 pikdesc->k2_part[i].kp2_type = RECNOTYPE;
116 pikdesc->k2_part[i].kp2_offset = KEY_RECNO_OFF; /* at the beginning of key */
118 if ((pxkdesc->k_flags & DUPSMASK) == ISDUPS) {
119 /* Append duplicate serial number to key descriptors. */
120 pikdesc->k2_part[i].kp2_start = 0; /* not used */
121 pikdesc->k2_part[i].kp2_leng = DUPIDSIZE;
122 pikdesc->k2_part[i].kp2_type = DUPIDTYPE;
123 pikdesc->k2_part[i].kp2_offset = KEY_DUPS_OFF; /* after recno field */
126 /* Round up to next multiple of 2. */
127 offset = (offset+1) & ~1;
129 pikdesc->k2_len = offset; /* Length of the entire key */