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