isminmax.c 5.7 KB

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