lib/tt/mini_isam: remove register keyword
[oweals/cde.git] / cde / lib / tt / mini_isam / iskeycmp.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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 $                                                    */
28 #ifndef lint
29 static char sccsid[] = "@(#)iskeycmp.c 1.5 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31
32 /*
33  * Copyright (c) 1988 by Sun Microsystems, Inc.
34  */
35
36 /*
37  * iskeycmp.c
38  *
39  * Description:
40  *      ISAM index comparison functions
41  */
42
43 #include "isam_impl.h"
44
45 static struct keypart2 *_curtab;                     /* Current comparison */
46                                              /* descriptor table */
47 static int _ncurtab;                         /* Number of entries */
48
49 /*
50  * _iskeycmp_set()
51  *
52  * Set key decriptor and number of parts for subsequent key comparison.s
53  * nparts, Use only so many parts
54  */
55
56 void
57 _iskeycmp_set (Keydesc2 *pkeydesc2, int nparts)
58 {
59     _ncurtab = nparts;
60     _curtab = pkeydesc2->k2_part;
61     assert(_ncurtab <= pkeydesc2->k2_nparts + 1); /* + 1 for recno */
62 }
63
64 /*
65  * Return number that is > 0 if l > r,
66  *                       = 0 if l = r,
67  *                       < 0 if l < r.
68  */
69
70 int
71 _iskeycmp(char *lkey, char *rkey)
72 {
73     int                      i, ret;
74     struct keypart2 *p;
75       char           *l, *r;
76     long             llong, rlong;
77     double                   ldouble, rdouble;
78
79     ret = 0;
80     for (i = 0, p = _curtab; ret == 0 && i < _ncurtab;i++, p++) {
81         
82         l = lkey + p->kp2_offset;
83         r = rkey + p->kp2_offset;
84
85         switch (p->kp2_type) {
86         case CHARTYPE:
87         case BINTYPE:
88             ret = memcmp(l, r, p->kp2_leng);
89             break;
90
91         case LONGTYPE:
92             llong = ldlong(l);
93             rlong = ldlong(r);
94
95             if (llong > rlong)
96                 ret = 1;
97             else if (llong < rlong)
98                 ret = -1;
99             break;
100
101         case SHORTTYPE:
102             llong = (long)ldshort(l);
103             rlong = (long)ldshort(r);
104
105             if (llong > rlong)
106                 ret = 1;
107             else if (llong < rlong)
108                 ret = -1;
109             break;
110
111         case DOUBLETYPE:
112             ldouble = lddbl(l);
113             rdouble = lddbl(r);
114
115             if (ldouble > rdouble)
116                 ret = 1;
117             else if (ldouble < rdouble)
118                 ret = -1;
119             break;
120
121         case FLOATTYPE:
122             ldouble = (double)ldfloat(l);
123             rdouble = (double)ldfloat(r);
124
125             if (ldouble > rdouble)
126                 ret = 1;
127             else if (ldouble < rdouble)
128                 ret = -1;
129             break;
130
131         case CHARTYPE + ISDESC:
132         case BINTYPE + ISDESC:
133             ret = memcmp(r, l, p->kp2_leng);
134             break;
135
136         case LONGTYPE + ISDESC:
137             llong = ldlong(l);
138             rlong = ldlong(r);
139
140             if (llong > rlong)
141                 ret = -1;
142             else if (llong < rlong)
143                 ret = 1;
144             break;
145
146         case SHORTTYPE + ISDESC:
147             llong = (long)ldshort(l);
148             rlong = (long)ldshort(r);
149
150             if (llong > rlong)
151                 ret = -1;
152             else if (llong < rlong)
153                 ret = 1;
154             break;
155
156         case DOUBLETYPE + ISDESC:
157             ldouble = lddbl(l);
158             rdouble = lddbl(r);
159
160             if (ldouble > rdouble)
161                 ret = -1;
162             else if (ldouble < rdouble)
163                 ret = 1;
164             break;
165
166         case FLOATTYPE + ISDESC:
167             ldouble = (double)ldfloat(l);
168             rdouble = (double)ldfloat(r);
169
170             if (ldouble > rdouble)
171                 ret = -1;
172             else if (ldouble < rdouble)
173                 ret = 1;
174             break;
175
176         default:
177             _isfatal_error("Bad data conversion descriptor");
178             break;
179         }
180     }
181     return (ret);
182 }