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 $ */
29 static char sccsid[] = "@(#)iskeycmp.c 1.5 89/07/17 Copyr 1988 Sun Micro";
33 * Copyright (c) 1988 by Sun Microsystems, Inc.
40 * ISAM index comparison functions
43 #include "isam_impl.h"
45 static struct keypart2 *_curtab; /* Current comparison */
46 /* descriptor table */
47 static int _ncurtab; /* Number of entries */
52 * Set key decriptor and number of parts for subsequent key comparison.s
53 * nparts, Use only so many parts
57 _iskeycmp_set (Keydesc2 *pkeydesc2, int nparts)
60 _curtab = pkeydesc2->k2_part;
61 assert(_ncurtab <= pkeydesc2->k2_nparts + 1); /* + 1 for recno */
65 * Return number that is > 0 if l > r,
71 _iskeycmp(char *lkey, char *rkey)
77 double ldouble, rdouble;
80 for (i = 0, p = _curtab; ret == 0 && i < _ncurtab;i++, p++) {
82 l = lkey + p->kp2_offset;
83 r = rkey + p->kp2_offset;
85 switch (p->kp2_type) {
88 ret = memcmp(l, r, p->kp2_leng);
97 else if (llong < rlong)
102 llong = (long)ldshort(l);
103 rlong = (long)ldshort(r);
107 else if (llong < rlong)
115 if (ldouble > rdouble)
117 else if (ldouble < rdouble)
122 ldouble = (double)ldfloat(l);
123 rdouble = (double)ldfloat(r);
125 if (ldouble > rdouble)
127 else if (ldouble < rdouble)
131 case CHARTYPE + ISDESC:
132 case BINTYPE + ISDESC:
133 ret = memcmp(r, l, p->kp2_leng);
136 case LONGTYPE + ISDESC:
142 else if (llong < rlong)
146 case SHORTTYPE + ISDESC:
147 llong = (long)ldshort(l);
148 rlong = (long)ldshort(r);
152 else if (llong < rlong)
156 case DOUBLETYPE + ISDESC:
160 if (ldouble > rdouble)
162 else if (ldouble < rdouble)
166 case FLOATTYPE + ISDESC:
167 ldouble = (double)ldfloat(l);
168 rdouble = (double)ldfloat(r);
170 if (ldouble > rdouble)
172 else if (ldouble < rdouble)
177 _isfatal_error("Bad data conversion descriptor");