Source code of Windows XP (NT5)
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.

146 lines
3.3 KiB

  1. /**************************************************************************
  2. *hlp_locate - locate line in help text
  3. *
  4. * Copyright <C> 1988, Microsoft Corporation
  5. *
  6. * Purpose:
  7. *
  8. * Revision History:
  9. *
  10. * 17-OCt-1990 RJSA translated to C
  11. * 25-Jan-1990 LN renamed to hlp_locate
  12. * 22-Dec-1988 LN Removed MASM High Level Lang support (Need
  13. * to control segments better than that will
  14. * let me)
  15. * 08-Dec-1988 LN CSEG
  16. * [] 18-Aug-1988 LN Created
  17. *
  18. *
  19. **************************************************************************/
  20. #include <stdio.h>
  21. #if defined (OS2)
  22. #define INCL_BASE
  23. #include <os2.h>
  24. #else
  25. #include <windows.h>
  26. #endif
  27. #include <help.h>
  28. #include <helpfile.h>
  29. #include <helpsys.h>
  30. /**** hlp_locate - locate a line in the buffer
  31. * uchar far * near pascal hlp_locate(
  32. * ushort ln,
  33. * uchar far *pTopic
  34. * )
  35. *
  36. * Purpose:
  37. * commonly used routine to find a line in the topic text.
  38. *
  39. * Entry:
  40. * ln = 1 based line number to look for (-1 means return number
  41. * of lines in topic)
  42. * pTopic = Topic text to look for it in
  43. *
  44. * Exit:
  45. * returns pointer to start of line
  46. *
  47. * Exceptions:
  48. * returns NULL on not found
  49. *
  50. **************************************************************************/
  51. PCHAR pascal
  52. hlp_locate (
  53. SHORT ln,
  54. PCHAR pTopic
  55. ){
  56. struct topichdr UNALIGNED *pT = (struct topichdr *)pTopic;
  57. PBYTE pSrc = (PBYTE)pTopic;
  58. SHORT lnOrig = ln;
  59. if (pT->lnCur <= (USHORT)ln) {
  60. // Use last past position calculated
  61. ln -= (pT->lnCur );
  62. pSrc += pT->lnOff;
  63. } else {
  64. // Start from beginning
  65. pSrc += sizeof(struct topichdr);
  66. }
  67. if (pT->ftype & FTCOMPRESSED) {
  68. // Compressed file. Walk over each text\attribute pair
  69. // until the desired line is found.
  70. while ( *pSrc && ln) {
  71. pSrc += *pSrc;
  72. pSrc += *(USHORT UNALIGNED *)pSrc;
  73. if ( *pSrc && *(pSrc+1) != pT->linChar ) {
  74. ln--;
  75. }
  76. }
  77. //while (*pSrc && ln) {
  78. //
  79. // if (*(pSrc + 1) != pT->linChar) {
  80. // ln--;
  81. // }
  82. // pSrc += *pSrc;
  83. // pSrc += *(PUSHORT)pSrc;
  84. //}
  85. } else {
  86. // ASCII file
  87. while (*pSrc && ln) {
  88. if (*pSrc != pT->linChar) {
  89. ln--;
  90. }
  91. while (*pSrc && *pSrc != 0x0A) {
  92. pSrc++;
  93. }
  94. if (*pSrc)
  95. pSrc++;
  96. }
  97. }
  98. if (*pSrc) {
  99. // Line found. Update the topic hdr with the pointers to the text
  100. // and line number that we just found, to help speed us up next time.
  101. pT->lnOff = (USHORT)((PBYTE)pSrc - (PBYTE)pT);
  102. pT->lnCur = lnOrig;
  103. } else {
  104. //
  105. // Line not found. Update nothing and return NULL
  106. // (Side Effect: line requested (ln) - line count left (ln) is the
  107. // number of lines in the topic! If original ln is -1, we'll return
  108. // that instead!
  109. if (lnOrig == -1)
  110. pSrc = (PBYTE)IntToPtr(lnOrig - ln);
  111. else
  112. pSrc = (PBYTE)0L;
  113. }
  114. return pSrc;
  115. }