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.

139 lines
4.0 KiB

  1. /**************************************************************************
  2. *HelpGetLine - Return a line of ascii text
  3. *
  4. * Copyright <C> 1988, Microsoft Corporation
  5. *
  6. * Revision History:
  7. *
  8. * 25-Jan-1990 ln LOCATE -> HLP_LOCATE
  9. * 22-Feb-1989 ln Check correctly for end of topic while copying
  10. * line.
  11. * 22-Dec-1988 LN Removed MASM High Level Lang support (Need
  12. * to control segments better than that will
  13. * let me)
  14. * 08-Dec-1988 LN CSEG
  15. * 11-Nov-1988 ln Adjust cbMax on entry
  16. * 03-Nov-1988 ln Added GQ sensitivity
  17. * [] 22-Sep-1988 LN Created
  18. *
  19. * Notes:
  20. *
  21. * Sensitive to the following switches:
  22. *
  23. * HOFFSET - If defined, handle/offset version
  24. * OS2 - If defined, OS/2 protect mode version
  25. * DSLOAD - If defined, causes DS to be reloaded, if needed
  26. * ASCII - If TRUE, includes ASCII support code
  27. * GQ - If defined, INC BP before saving & DEC before restore
  28. *
  29. **************************************************************************/
  30. #include <stdio.h>
  31. #if defined (OS2)
  32. #define INCL_BASE
  33. #include <os2.h>
  34. #else
  35. #include <windows.h>
  36. #endif
  37. #include <help.h>
  38. #include <helpfile.h>
  39. #include <helpsys.h>
  40. /**** HelpGetLine - Return a line of ascii text
  41. *
  42. * Interpret the help files stored format and return a line at a time of
  43. * ascii text.
  44. *
  45. * ushort far pascal LOADDS HelpGetLine (
  46. * ushort ln, = 1 based line number to return
  47. * ushort cbMax, = Max number of bytes to transfer
  48. * uchar far *pszDst, = pointer to destination
  49. * PB pbTopic = PB pointer to topic text
  50. *
  51. * Output:
  52. * Returns number of characters transfered, or 0 if that line does not exist.
  53. *
  54. *************************************************************************/
  55. USHORT pascal
  56. HelpGetLine (
  57. USHORT ln,
  58. USHORT cbMax,
  59. PUCHAR pszDst,
  60. PB pbTopic
  61. ) {
  62. struct topichdr *pT;
  63. USHORT cbTransfered = 0;
  64. PUCHAR pszDstOrg = pszDst;
  65. cbMax--; //adjust to account for terminating zero
  66. pT = PBLOCK(pbTopic);
  67. if (pT) {
  68. PCHAR pLine = hlp_locate(ln, (PCHAR)pT);
  69. if (pLine) {
  70. *pszDst = ' ';
  71. *(pszDst +1) = '\00'; // initialize dest.
  72. if (pT->ftype & FTCOMPRESSED) {
  73. // For compressed files, get the length of the line from the
  74. // first byte, and of course skip that byte. Form the
  75. // maximum byte count ot be transfered as the lesser of the
  76. // actual length of the line or caller cbMax.
  77. USHORT Len = (USHORT)*pLine++ - 1;
  78. if (Len) {
  79. ULONG LongLen;
  80. Len = (Len > cbMax) ? cbMax : Len;
  81. LongLen = Len/sizeof(ULONG);
  82. Len = (USHORT)(Len % sizeof(ULONG));
  83. while (LongLen--) {
  84. *((ULONG UNALIGNED*)pszDst)++ = *((ULONG UNALIGNED *)pLine)++;
  85. }
  86. while (Len--) {
  87. *pszDst++ = *pLine++;
  88. }
  89. *pszDst++ = '\00'; // Null terminate it
  90. cbTransfered = (USHORT)(pszDst - pszDstOrg);
  91. } else {
  92. cbTransfered = 2;
  93. }
  94. } else {
  95. // For non-compressed files, copy one line
  96. PCHAR pSrc = pLine;
  97. CHAR c = *pLine;
  98. if (c == '\n') {
  99. cbTransfered = 2;
  100. } else {
  101. while (c != '\00' && c != '\n') {
  102. c = *pszDst++ = *pLine++;
  103. }
  104. *(pszDst-1) = '\00'; // null terminate it
  105. cbTransfered = (USHORT)(pszDst - pszDstOrg);
  106. }
  107. }
  108. }
  109. PBUNLOCK(pbTopic);
  110. }
  111. return cbTransfered;
  112. }