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 $ */
29 static char sccsid[] = "@(#)iskeyconv.c 1.4 89/07/17 Copyr 1988 Sun Micro";
33 * Copyright (c) 1988 by Sun Microsystems, Inc.
40 * Conversion functions between internal and external key descriptor
44 #include "isam_impl.h"
47 * _iskey_itox(pikdesc,pxkdesc)
49 * Convert internal key desc. to X/OPEN key descriptor.
51 * @param pikdesc NetISAM internal format
52 * @param pxkdesc X/OPEN format
55 _iskey_itox(struct keydesc2 *pikdesc, struct keydesc *pxkdesc)
60 memset ((char *)pxkdesc, 0, sizeof (*pxkdesc));
62 pxkdesc->k_flags = pikdesc->k2_flags;
63 nparts = pxkdesc->k_nparts = pikdesc->k2_nparts;
65 for (i = 0; i < nparts;i++) {
66 pxkdesc->k_part[i].kp_start = pikdesc->k2_part[i].kp2_start;
67 pxkdesc->k_part[i].kp_leng = pikdesc->k2_part[i].kp2_leng;
68 pxkdesc->k_part[i].kp_type = pikdesc->k2_part[i].kp2_type;
76 * Convert X/OPEN key descriptor to internal key descriptor.
78 * @param pikdesc NetISAM internal format
79 * @param pxkdesc X/OPEN format
82 _iskey_xtoi(struct keydesc2 *pikdesc, struct keydesc *pxkdesc)
86 int offset; /* Keep track of offset in key */
88 memset ((char *)pikdesc, 0, sizeof (*pikdesc));
90 pikdesc->k2_flags = pxkdesc->k_flags;
91 nparts = pikdesc->k2_nparts = pxkdesc->k_nparts;
95 * Every key entry starts with record number.
100 * If index allows duplicates, the key is augmented with duplicate
103 if ((pxkdesc->k_flags & DUPSMASK) == ISDUPS)
106 for (i = 0; i < nparts; i++) {
107 pikdesc->k2_part[i].kp2_start = pxkdesc->k_part[i].kp_start;
108 pikdesc->k2_part[i].kp2_leng = pxkdesc->k_part[i].kp_leng;
109 pikdesc->k2_part[i].kp2_type = pxkdesc->k_part[i].kp_type;
110 pikdesc->k2_part[i].kp2_offset = offset;
112 offset += pxkdesc->k_part[i].kp_leng;
115 /* Append recno to key descriptors. */
116 pikdesc->k2_part[i].kp2_start = 0; /* not used */
117 pikdesc->k2_part[i].kp2_leng = RECNOSIZE;
118 pikdesc->k2_part[i].kp2_type = RECNOTYPE;
119 pikdesc->k2_part[i].kp2_offset = KEY_RECNO_OFF; /* at the beginning of key */
121 if ((pxkdesc->k_flags & DUPSMASK) == ISDUPS) {
122 /* Append duplicate serial number to key descriptors. */
123 pikdesc->k2_part[i].kp2_start = 0; /* not used */
124 pikdesc->k2_part[i].kp2_leng = DUPIDSIZE;
125 pikdesc->k2_part[i].kp2_type = DUPIDTYPE;
126 pikdesc->k2_part[i].kp2_offset = KEY_DUPS_OFF; /* after recno field */
129 /* Round up to next multiple of 2. */
130 offset = (offset+1) & ~1;
132 pikdesc->k2_len = offset; /* Length of the entire key */