496a6fa1573ee81c19413aba727fd7e2347d870e
[oweals/cde.git] / cde / lib / tt / mini_isam / isminmax.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: isminmax.c /main/3 1995/10/23 11:42:16 rswiston $                                                    */
28 #ifndef lint
29 static char sccsid[] = "@(#)isminmax.c 1.4 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31
32 /*
33  * Copyright (c) 1988 by Sun Microsystems, Inc.
34  */
35
36 /*
37  * isminmax.c 
38  *
39  * Description:
40  *      NetISAM minimum and maximum values functions
41  */
42
43 #include "isam_impl.h"
44
45 static unsigned char ismaxlongarr[LONGSIZE] = ISMAXLONG;
46 static unsigned char isminlongarr[LONGSIZE] = ISMINLONG;
47
48 static unsigned char ismaxshortarr[SHORTSIZE] = ISMAXSHORT;
49 static unsigned char isminshortarr[SHORTSIZE] = ISMINSHORT;
50
51 static unsigned char ismaxdoublearr[DOUBLESIZE] = ISMAXDOUBLE;
52 static unsigned char ismindoublearr[DOUBLESIZE] = ISMINDOUBLE;
53
54 static unsigned char ismaxfloatarr[FLOATSIZE] = ISMAXFLOAT;
55 static unsigned char isminfloatarr[FLOATSIZE] = ISMINFLOAT;
56
57 /* These two are used globally. */
58 long *ismaxlong = (long *)ismaxlongarr;
59 long *isminlong = (long *)isminlongarr;
60
61 static short *ismaxshort = (short *)ismaxshortarr;
62 static short *isminshort = (short *)isminshortarr;
63
64 static double *ismaxdouble = (double *)ismaxdoublearr;
65 static double *ismindouble = (double *)ismindoublearr;
66
67 static float *ismaxfloat = (float *)ismaxfloatarr;
68 static float *isminfloat = (float *)isminfloatarr;
69
70
71 /* 
72  * _iskey_fillmax() 
73  *
74  * Fill key buffer with maximum values 
75  */
76
77 void
78 _iskey_fillmax(struct keydesc2 *pkeydesc2, register char *keybuf)
79 {
80     register int        i;
81     register struct keypart2 *ppart;
82     int                 nparts;
83
84     nparts = pkeydesc2->k2_nparts;
85     ppart = pkeydesc2->k2_part;
86
87     for (i = 0; i < nparts + 1;i++) {        /* +1 is for recnum part */
88         switch (ppart->kp2_type) {
89         case CHARTYPE:
90             (void) memset (keybuf + ppart->kp2_offset, ISMAXCHAR, 
91                            ppart->kp2_leng);
92             break;
93         case BINTYPE:
94             (void) memset (keybuf + ppart->kp2_offset, ISMAXBIN, 
95                            ppart->kp2_leng);
96             break;
97         case LONGTYPE:
98             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxlong, LONGSIZE);
99             break;
100         case SHORTTYPE:
101             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxshort, SHORTSIZE);
102             break;
103         case FLOATTYPE:
104             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxfloat, FLOATSIZE);
105             break;
106         case DOUBLETYPE:
107             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxdouble, DOUBLESIZE);
108             break;
109
110         case CHARTYPE + ISDESC:
111             (void) memset (keybuf + ppart->kp2_offset, ISMINCHAR, 
112                            ppart->kp2_leng);
113             break;
114         case BINTYPE + ISDESC:
115             (void) memset (keybuf + ppart->kp2_offset, ISMINBIN, 
116                            ppart->kp2_leng);
117             break;
118         case LONGTYPE + ISDESC:
119             memcpy ( keybuf + ppart->kp2_offset,(char *)isminlong, LONGSIZE);
120             break;
121         case SHORTTYPE + ISDESC:
122             memcpy ( keybuf + ppart->kp2_offset,(char *)isminshort, SHORTSIZE);
123             break;
124         case FLOATTYPE + ISDESC:
125             memcpy ( keybuf + ppart->kp2_offset,(char *)isminfloat, FLOATSIZE);
126             break;
127         case DOUBLETYPE + ISDESC:
128             memcpy ( keybuf + ppart->kp2_offset,(char *)ismindouble, DOUBLESIZE);
129             break;
130         default:
131             _isfatal_error("_iskey_fillmax");
132         }
133         ppart++;
134     }
135 }
136
137 /* 
138  * _iskey_fillmin() 
139  *
140  * Fill key buffer with minimum values 
141  */
142
143 void
144 _iskey_fillmin(struct keydesc2 *pkeydesc2, register char *keybuf)
145 {
146     register int        i;
147     register struct keypart2 *ppart;
148     int                 nparts;
149
150     nparts = pkeydesc2->k2_nparts;
151     ppart = pkeydesc2->k2_part;
152
153     for (i = 0; i < nparts + 1;i++) {        /* +1 is for recnum part */
154         switch (ppart->kp2_type) {
155         case CHARTYPE:
156             (void) memset (keybuf + ppart->kp2_offset, ISMINCHAR, 
157                            ppart->kp2_leng);
158             break;
159         case BINTYPE:
160             (void) memset (keybuf + ppart->kp2_offset, ISMINBIN, 
161                            ppart->kp2_leng);
162             break;
163         case LONGTYPE:
164             memcpy ( keybuf + ppart->kp2_offset,(char *)isminlong, LONGSIZE);
165             break;
166         case SHORTTYPE:
167             memcpy ( keybuf + ppart->kp2_offset,(char *)isminshort, SHORTSIZE);
168             break;
169         case FLOATTYPE:
170             memcpy ( keybuf + ppart->kp2_offset,(char *)isminfloat, FLOATSIZE);
171             break;
172         case DOUBLETYPE:
173             memcpy ( keybuf + ppart->kp2_offset,(char *)ismindouble, DOUBLESIZE);
174             break;
175
176         case CHARTYPE + ISDESC:
177             (void) memset (keybuf + ppart->kp2_offset, ISMAXCHAR, 
178                            ppart->kp2_leng);
179             break;
180         case BINTYPE + ISDESC:
181             (void) memset (keybuf + ppart->kp2_offset, ISMAXBIN, 
182                            ppart->kp2_leng);
183             break;
184         case LONGTYPE + ISDESC:
185             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxlong, LONGSIZE);
186             break;
187         case SHORTTYPE + ISDESC:
188             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxshort, SHORTSIZE);
189             break;
190         case FLOATTYPE + ISDESC:
191             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxfloat, FLOATSIZE);
192             break;
193         case DOUBLETYPE + ISDESC:
194             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxdouble, DOUBLESIZE);
195             break;
196         default:
197             _isfatal_error("_iskey_fillmin");
198         }
199         ppart++;
200     }
201 }