iskeyconv.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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: iskeyconv.c /main/3 1995/10/23 11:41:54 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * iskeyconv.c
  33. *
  34. * Description:
  35. * Conversion functions between internal and external key descriptor
  36. *
  37. */
  38. #include "isam_impl.h"
  39. /*
  40. * _iskey_itox(pikdesc,pxkdesc)
  41. *
  42. * Convert internal key desc. to X/OPEN key descriptor.
  43. *
  44. * @param pikdesc NetISAM internal format
  45. * @param pxkdesc X/OPEN format
  46. */
  47. void
  48. _iskey_itox(struct keydesc2 *pikdesc, struct keydesc *pxkdesc)
  49. {
  50. int nparts;
  51. int i;
  52. memset ((char *)pxkdesc, 0, sizeof (*pxkdesc));
  53. pxkdesc->k_flags = pikdesc->k2_flags;
  54. nparts = pxkdesc->k_nparts = pikdesc->k2_nparts;
  55. for (i = 0; i < nparts;i++) {
  56. pxkdesc->k_part[i].kp_start = pikdesc->k2_part[i].kp2_start;
  57. pxkdesc->k_part[i].kp_leng = pikdesc->k2_part[i].kp2_leng;
  58. pxkdesc->k_part[i].kp_type = pikdesc->k2_part[i].kp2_type;
  59. }
  60. }
  61. /*
  62. * _iskey_xtoi()
  63. *
  64. * Convert X/OPEN key descriptor to internal key descriptor.
  65. *
  66. * @param pikdesc NetISAM internal format
  67. * @param pxkdesc X/OPEN format
  68. */
  69. void
  70. _iskey_xtoi(struct keydesc2 *pikdesc, struct keydesc *pxkdesc)
  71. {
  72. int nparts;
  73. int i;
  74. int offset; /* Keep track of offset in key */
  75. memset ((char *)pikdesc, 0, sizeof (*pikdesc));
  76. pikdesc->k2_flags = pxkdesc->k_flags;
  77. nparts = pikdesc->k2_nparts = pxkdesc->k_nparts;
  78. offset = 0;
  79. /*
  80. * Every key entry starts with record number.
  81. */
  82. offset += RECNOSIZE;
  83. /*
  84. * If index allows duplicates, the key is augmented with duplicate
  85. * serial number.
  86. */
  87. if ((pxkdesc->k_flags & DUPSMASK) == ISDUPS)
  88. offset += DUPIDSIZE;
  89. for (i = 0; i < nparts; i++) {
  90. pikdesc->k2_part[i].kp2_start = pxkdesc->k_part[i].kp_start;
  91. pikdesc->k2_part[i].kp2_leng = pxkdesc->k_part[i].kp_leng;
  92. pikdesc->k2_part[i].kp2_type = pxkdesc->k_part[i].kp_type;
  93. pikdesc->k2_part[i].kp2_offset = offset;
  94. offset += pxkdesc->k_part[i].kp_leng;
  95. }
  96. /* Append recno to key descriptors. */
  97. pikdesc->k2_part[i].kp2_start = 0; /* not used */
  98. pikdesc->k2_part[i].kp2_leng = RECNOSIZE;
  99. pikdesc->k2_part[i].kp2_type = RECNOTYPE;
  100. pikdesc->k2_part[i].kp2_offset = KEY_RECNO_OFF; /* at the beginning of key */
  101. if ((pxkdesc->k_flags & DUPSMASK) == ISDUPS) {
  102. /* Append duplicate serial number to key descriptors. */
  103. pikdesc->k2_part[i].kp2_start = 0; /* not used */
  104. pikdesc->k2_part[i].kp2_leng = DUPIDSIZE;
  105. pikdesc->k2_part[i].kp2_type = DUPIDTYPE;
  106. pikdesc->k2_part[i].kp2_offset = KEY_DUPS_OFF; /* after recno field */
  107. }
  108. /* Round up to next multiple of 2. */
  109. offset = (offset+1) & ~1;
  110. pikdesc->k2_len = offset; /* Length of the entire key */
  111. }