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.

138 lines
3.8 KiB

  1. /*** helpcell.c - HelpGetCells routine.
  2. *
  3. * Copyright <C> 1988, Microsoft Corporation
  4. *
  5. * Purpose:
  6. *
  7. * Revision History:
  8. *
  9. * 25-Jan-1990 ln locate -> hlp_locate
  10. * [] 04-Aug-1988 LN Created...split from helpif.c. Added auto-fill.
  11. *
  12. *************************************************************************/
  13. #include <stdio.h>
  14. #if defined (OS2)
  15. #else
  16. #include <windows.h>
  17. #endif
  18. #include "help.h"
  19. #include "helpfile.h"
  20. #include "helpsys.h"
  21. /************************************************************************
  22. **
  23. ** Foward Declarations
  24. */
  25. uchar near pascal toupr(uchar);
  26. /************************************************************************
  27. **
  28. ** HelpGetCells - Return a string of character / attribute pairs from helpfile
  29. **
  30. ** Purpose:
  31. ** Interpret the help files stored format and return a line at a time of
  32. ** character & attribute information.
  33. **
  34. ** Entry:
  35. ** ln = 1 based line number to return
  36. ** cbMax = Max number of characters to transfer
  37. ** pbDst = pointer to destination
  38. ** pbTopic = pointer to topic text
  39. ** prgAttr = pointer to array of character attributes
  40. **
  41. ** Exit:
  42. ** returns number of bytes transfered, or -1 if that line does not exist.
  43. ** DOES blank fill to the cbMax width.
  44. **
  45. ** Exceptions:
  46. **
  47. */
  48. int far pascal LOADDS HelpGetCells(ln,cbMax,pbDst,pbTopic,prgAttr)
  49. int ln;
  50. int cbMax;
  51. char far *pbDst;
  52. PB pbTopic;
  53. uchar far *prgAttr;
  54. {
  55. ushort cbAttr; /* length of current attribute */
  56. ushort cbAttrCur = 0; /* length of current attribute */
  57. ushort cbSrc; /* count of source characters */
  58. uchar cAttrCur; /* current attribute */
  59. uchar iAttrCur; /* index to current attribute */
  60. uchar far *pTopic; /* pointer to topic */
  61. uchar far *pchSrc; /* pointer to source characters */
  62. topichdr far *pHdr; /* pointer to topic header */
  63. pTopic = PBLOCK (pbTopic);
  64. pHdr = (topichdr far *)pTopic;
  65. if ((pTopic = hlp_locate((ushort)ln,pTopic)) == NULL)/* locate line */
  66. ln = -1;
  67. else if (pHdr->ftype & FTCOMPRESSED) {
  68. ln=0;
  69. pchSrc = pTopic; /* point to character data */
  70. pTopic += (*pTopic); /* point to attribute data */
  71. cbAttr = *((ushort far UNALIGNED *)pTopic)++ - (ushort)sizeof(ushort);/* count of attribute bytes */
  72. cbSrc = (ushort)((*pchSrc++) -1); /* get count of characters */
  73. while (cbSrc-- && cbMax--) { /* while characters to get */
  74. /*
  75. * Time for a new attribute. If there are attributes left (cbAttr > 0) then
  76. * just get the next one (length & index). If there weren't any left, or the
  77. * last one had an index of 0xff (indicating end), then we'll use the index
  78. * zero attribute byte, else pick up the current attribute byte and move on
  79. * in the attribute string.
  80. */
  81. if (cbAttrCur == 0) {
  82. if (cbAttr > 0) {
  83. cbAttrCur = ((intlineattr far UNALIGNED *)pTopic)->cb;
  84. iAttrCur = ((intlineattr far UNALIGNED *)pTopic)->attr;
  85. }
  86. if ((cbAttr <= 0) || (iAttrCur == 0xff))
  87. cAttrCur = prgAttr[0];
  88. else {
  89. cAttrCur = prgAttr[iAttrCur];
  90. ((intlineattr far *)pTopic)++;
  91. cbAttr -= 2;
  92. }
  93. }
  94. *((ushort far UNALIGNED *)pbDst)++ = (ushort)((cAttrCur << 8) | *pchSrc++); /* stuff char & attr*/
  95. cbAttrCur--;
  96. ln += 2;
  97. }
  98. }
  99. #if ASCII
  100. else {
  101. /*
  102. ** For ascii files, just copy line over with attr[0]
  103. */
  104. ln=0;
  105. while (*pTopic && (*pTopic != '\r') && cbMax--) {
  106. if (*pTopic == '\t') {
  107. pTopic++;
  108. do {
  109. *((ushort far UNALIGNED *)pbDst)++ = (ushort)((prgAttr[0] << 8) | ' ');
  110. ln += 2;
  111. }
  112. while ((ln % 16) && cbMax--);
  113. }
  114. else {
  115. *((ushort far UNALIGNED *)pbDst)++ = (ushort)((prgAttr[0] << 8) | *pTopic++);
  116. ln += 2;
  117. }
  118. }
  119. }
  120. #endif
  121. #if 0
  122. /*
  123. * blank fill the rest of the line
  124. */
  125. while (cbMax--)
  126. *((ushort far UNALIGNED *)pbDst)++ = (prgAttr[0] << 8) | ' '; /* stuff char & attr*/
  127. #endif
  128. PBUNLOCK (pbTopic);
  129. return ln;
  130. /* end HelpGetCells */}