Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
5.9 KiB

4 years ago
  1. /*****************************************************************************
  2. * *
  3. * BTKTSZIS.C *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1989, 1990. *
  6. * All Rights reserved. *
  7. * *
  8. ******************************************************************************
  9. * *
  10. * Module Intent *
  11. * *
  12. * Functions for SZISCAND (0-terminated case insensitive Scandinavian *
  13. * string keys. *
  14. * *
  15. ******************************************************************************
  16. * *
  17. * Testing Notes *
  18. * *
  19. ******************************************************************************
  20. * *
  21. * Current Owner: JohnSc *
  22. * *
  23. ******************************************************************************
  24. * *
  25. * Released by Development: long, long ago *
  26. * *
  27. *****************************************************************************/
  28. /*****************************************************************************
  29. *
  30. * Revision History: Created 00/00/89 by JohnSc
  31. *
  32. * 08/21/90 JohnSc autodocified
  33. *
  34. *****************************************************************************/
  35. #include <windows.h>
  36. #include <orkin.h>
  37. #include "_mvfs.h"
  38. #include "imvfs.h"
  39. #include "btpriv.h"
  40. // _subsystem( btree );
  41. /***************************************************************************\
  42. *
  43. - Function: BkScanSziScandInternal( bk, key, wLevel, qbthr )
  44. -
  45. * Purpose: Scan an internal node for a key and return child BK.
  46. *
  47. * ASSUMES
  48. * args IN: bk - BK of internal node to scan
  49. * key - key to search for
  50. * wLevel - level of btree bk lives on
  51. * qbthr - btree header containing cache, and btree specs
  52. * qiKey - address of an int or NULL to not get it
  53. *
  54. * PROMISES
  55. * returns: bk of subtree that might contain key; bkNil on error
  56. * args OUT: qbthr->qCache - bk's block will be cached
  57. * qiKey - index into rgbBlock of first key >= key
  58. *
  59. * Side Effects: bk's block will be cached
  60. *
  61. \***************************************************************************/
  62. _private BK FAR PASCAL
  63. BkScanSziScandInternal(
  64. BK bk,
  65. KEY key,
  66. INT wLevel,
  67. QBTHR qbthr,
  68. QI qiKey)
  69. {
  70. QCB qcb;
  71. QB q;
  72. INT cKeys;
  73. if ( ( qcb = QFromBk( bk, wLevel, qbthr ) ) == NULL )
  74. {
  75. return bkNil;
  76. }
  77. q = qcb->db.rgbBlock;
  78. cKeys = qcb->db.cKeys;
  79. bk = *(BK FAR *)q;
  80. q += sizeof( BK );
  81. while ( cKeys-- > 0 )
  82. {
  83. if ( WCmpiScandSz( (SZ)key, (SZ)q ) >= 0 )
  84. {
  85. q += lstrlen( (SZ)q ) + 1;
  86. bk = *(BK FAR *)q;
  87. q += sizeof( BK );
  88. }
  89. else
  90. break;
  91. }
  92. if ( qiKey != NULL )
  93. {
  94. *qiKey = q - (QB)qcb->db.rgbBlock;
  95. }
  96. return bk;
  97. }
  98. /***************************************************************************\
  99. *
  100. - Function: RcScanSziScandLeaf( bk, key, wLevel, qbthr, qRec, qbtpos )
  101. -
  102. * Purpose: Scan a leaf node for a key and copy the associated data.
  103. *
  104. * ASSUMES
  105. * args IN: bk - the leaf block
  106. * key - the key we're looking for
  107. * wLevel - the level of leaves (unnecessary)
  108. * qbthr - the btree header
  109. *
  110. * PROMISES
  111. * returns: rcSuccess if found; rcNoExists if not found
  112. * args OUT: qRec - if found, record gets copied into this buffer
  113. * qbtpos - pos of first key >= key goes here
  114. *
  115. * Notes: If we are scanning for a key greater than any key in this
  116. * block, the pos returned will be invalid and will point just
  117. * past the last valid key in this block.
  118. *
  119. *
  120. \***************************************************************************/
  121. _private RC FAR PASCAL
  122. RcScanSziScandLeaf(
  123. BK bk,
  124. KEY key,
  125. INT wLevel,
  126. QBTHR qbthr,
  127. QV qRec,
  128. QBTPOS qbtpos)
  129. {
  130. QCB qcb;
  131. SZ sz;
  132. INT w, cKey;
  133. QB qb;
  134. if ( ( qcb = QFromBk( bk, wLevel, qbthr ) ) == NULL )
  135. {
  136. return RcGetBtreeError();
  137. }
  138. SetBtreeErrorRc(rcNoExists);
  139. sz = qcb->db.rgbBlock + 2 * sizeof( BK );
  140. for ( cKey = 0; cKey < qcb->db.cKeys; cKey++ )
  141. {
  142. w = WCmpiScandSz( (SZ)key, sz );
  143. if ( w > 0 ) /* still looking for key */
  144. {
  145. sz += lstrlen( sz ) + 1;
  146. sz += CbSizeRec( sz, qbthr );
  147. }
  148. else if ( w < 0 ) /* key not found */
  149. {
  150. break;
  151. }
  152. else /* matched the key */
  153. {
  154. if ( qRec != NULL )
  155. {
  156. qb = (QB)sz + lstrlen( sz ) + 1;
  157. QvCopy( qRec, qb, (LONG)CbSizeRec( qb, qbthr ) );
  158. }
  159. SetBtreeErrorRc(rcSuccess);
  160. break;
  161. }
  162. }
  163. if ( qbtpos != NULL )
  164. {
  165. qbtpos->bk = bk;
  166. qbtpos->cKey = cKey;
  167. qbtpos->iKey = (QB)sz - (QB)qcb->db.rgbBlock;
  168. }
  169. return RcGetBtreeError();
  170. }
  171. /* EOF */