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: iskeycmp.c /main/3 1995/10/23 11:41:41 rswiston $ */
30 * Copyright (c) 1988 by Sun Microsystems, Inc.
37 * ISAM index comparison functions
40 #include "isam_impl.h"
42 static struct keypart2 *_curtab; /* Current comparison */
43 /* descriptor table */
44 static int _ncurtab; /* Number of entries */
49 * Set key decriptor and number of parts for subsequent key comparison.s
50 * nparts, Use only so many parts
54 _iskeycmp_set (Keydesc2 *pkeydesc2, int nparts)
57 _curtab = pkeydesc2->k2_part;
58 assert(_ncurtab <= pkeydesc2->k2_nparts + 1); /* + 1 for recno */
62 * Return number that is > 0 if l > r,
68 _iskeycmp(char *lkey, char *rkey)
74 double ldouble, rdouble;
77 for (i = 0, p = _curtab; ret == 0 && i < _ncurtab;i++, p++) {
79 l = lkey + p->kp2_offset;
80 r = rkey + p->kp2_offset;
82 switch (p->kp2_type) {
85 ret = memcmp(l, r, p->kp2_leng);
94 else if (llong < rlong)
99 llong = (long)ldshort(l);
100 rlong = (long)ldshort(r);
104 else if (llong < rlong)
112 if (ldouble > rdouble)
114 else if (ldouble < rdouble)
119 ldouble = (double)ldfloat(l);
120 rdouble = (double)ldfloat(r);
122 if (ldouble > rdouble)
124 else if (ldouble < rdouble)
128 case CHARTYPE + ISDESC:
129 case BINTYPE + ISDESC:
130 ret = memcmp(r, l, p->kp2_leng);
133 case LONGTYPE + ISDESC:
139 else if (llong < rlong)
143 case SHORTTYPE + ISDESC:
144 llong = (long)ldshort(l);
145 rlong = (long)ldshort(r);
149 else if (llong < rlong)
153 case DOUBLETYPE + ISDESC:
157 if (ldouble > rdouble)
159 else if (ldouble < rdouble)
163 case FLOATTYPE + ISDESC:
164 ldouble = (double)ldfloat(l);
165 rdouble = (double)ldfloat(r);
167 if (ldouble > rdouble)
169 else if (ldouble < rdouble)
174 _isfatal_error("Bad data conversion descriptor");