Merge branch 'cde-fixups-1' of ssh://git.code.sf.net/p/cdesktopenv/code into cde...
[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(pkeydesc2, keybuf)
79     struct keydesc2     *pkeydesc2;
80     register char       *keybuf;
81 {
82     register int        i;
83     register struct keypart2 *ppart;
84     int                 nparts;
85
86     nparts = pkeydesc2->k2_nparts;
87     ppart = pkeydesc2->k2_part;
88
89     for (i = 0; i < nparts + 1;i++) {        /* +1 is for recnum part */
90         switch (ppart->kp2_type) {
91         case CHARTYPE:
92             (void) memset (keybuf + ppart->kp2_offset, ISMAXCHAR, 
93                            ppart->kp2_leng);
94             break;
95         case BINTYPE:
96             (void) memset (keybuf + ppart->kp2_offset, ISMAXBIN, 
97                            ppart->kp2_leng);
98             break;
99         case LONGTYPE:
100             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxlong, LONGSIZE);
101             break;
102         case SHORTTYPE:
103             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxshort, SHORTSIZE);
104             break;
105         case FLOATTYPE:
106             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxfloat, FLOATSIZE);
107             break;
108         case DOUBLETYPE:
109             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxdouble, DOUBLESIZE);
110             break;
111
112         case CHARTYPE + ISDESC:
113             (void) memset (keybuf + ppart->kp2_offset, ISMINCHAR, 
114                            ppart->kp2_leng);
115             break;
116         case BINTYPE + ISDESC:
117             (void) memset (keybuf + ppart->kp2_offset, ISMINBIN, 
118                            ppart->kp2_leng);
119             break;
120         case LONGTYPE + ISDESC:
121             memcpy ( keybuf + ppart->kp2_offset,(char *)isminlong, LONGSIZE);
122             break;
123         case SHORTTYPE + ISDESC:
124             memcpy ( keybuf + ppart->kp2_offset,(char *)isminshort, SHORTSIZE);
125             break;
126         case FLOATTYPE + ISDESC:
127             memcpy ( keybuf + ppart->kp2_offset,(char *)isminfloat, FLOATSIZE);
128             break;
129         case DOUBLETYPE + ISDESC:
130             memcpy ( keybuf + ppart->kp2_offset,(char *)ismindouble, DOUBLESIZE);
131             break;
132         default:
133             _isfatal_error("_iskey_fillmax");
134         }
135         ppart++;
136     }
137 }
138
139 /* 
140  * _iskey_fillmin() 
141  *
142  * Fill key buffer with minimum values 
143  */
144
145 void
146 _iskey_fillmin(pkeydesc2, keybuf)
147     struct keydesc2     *pkeydesc2;
148     register char       *keybuf;
149 {
150     register int        i;
151     register struct keypart2 *ppart;
152     int                 nparts;
153
154     nparts = pkeydesc2->k2_nparts;
155     ppart = pkeydesc2->k2_part;
156
157     for (i = 0; i < nparts + 1;i++) {        /* +1 is for recnum part */
158         switch (ppart->kp2_type) {
159         case CHARTYPE:
160             (void) memset (keybuf + ppart->kp2_offset, ISMINCHAR, 
161                            ppart->kp2_leng);
162             break;
163         case BINTYPE:
164             (void) memset (keybuf + ppart->kp2_offset, ISMINBIN, 
165                            ppart->kp2_leng);
166             break;
167         case LONGTYPE:
168             memcpy ( keybuf + ppart->kp2_offset,(char *)isminlong, LONGSIZE);
169             break;
170         case SHORTTYPE:
171             memcpy ( keybuf + ppart->kp2_offset,(char *)isminshort, SHORTSIZE);
172             break;
173         case FLOATTYPE:
174             memcpy ( keybuf + ppart->kp2_offset,(char *)isminfloat, FLOATSIZE);
175             break;
176         case DOUBLETYPE:
177             memcpy ( keybuf + ppart->kp2_offset,(char *)ismindouble, DOUBLESIZE);
178             break;
179
180         case CHARTYPE + ISDESC:
181             (void) memset (keybuf + ppart->kp2_offset, ISMAXCHAR, 
182                            ppart->kp2_leng);
183             break;
184         case BINTYPE + ISDESC:
185             (void) memset (keybuf + ppart->kp2_offset, ISMAXBIN, 
186                            ppart->kp2_leng);
187             break;
188         case LONGTYPE + ISDESC:
189             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxlong, LONGSIZE);
190             break;
191         case SHORTTYPE + ISDESC:
192             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxshort, SHORTSIZE);
193             break;
194         case FLOATTYPE + ISDESC:
195             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxfloat, FLOATSIZE);
196             break;
197         case DOUBLETYPE + ISDESC:
198             memcpy ( keybuf + ppart->kp2_offset,(char *)ismaxdouble, DOUBLESIZE);
199             break;
200         default:
201             _isfatal_error("_iskey_fillmin");
202         }
203         ppart++;
204     }
205 }