Leaked source code of windows server 2003
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.

308 lines
9.4 KiB

  1. /*** helpif.c - help routines for user interface assistance.
  2. *
  3. * Copyright <C> 1988, Microsoft Corporation
  4. *
  5. * Purpose:
  6. * These routines aid in the interpretation of help text by applications.
  7. * After decompression, the help text is encoded into a line oriented format
  8. * which includes text, highlighting and cross reference information.
  9. *
  10. * Each line of text is formatted in the database as:
  11. *
  12. * +--------+----------------+--------+---------------+------+---------------+
  13. * | cbText | - Ascii Text - | cbAttr | - Attr info - | 0xff | - Xref Info - |
  14. * +--------+----------------+--------+---------------+------+---------------+
  15. *
  16. * Where:
  17. *
  18. * cbText - a BYTE which contains the length of the ascii text plus
  19. * one (for itself).
  20. * Ascii Text - Just that, the ascii text to be displayed
  21. * cbAttr - a WORD which contains the length of the attribute
  22. * information *plus* the cross reference information.
  23. * Attr info - attribute/length pairs of highlighting information plus
  24. * two (for itself).
  25. * 0xff - Attr info terminator byte (present ONLY IF Xref
  26. * information follows)
  27. * Xref Info - Cross Referencing information.
  28. *
  29. * Notes:
  30. * If the LAST attributes on a line are "plain", then the attribute/length
  31. * pair is omitted, and the rest of the line is assumed plain.
  32. *
  33. * Given a pointer to a line, a pointer to the next line is:
  34. *
  35. * Pointer + cbText + cbAttr
  36. *
  37. * A line which has no cross-reference or highlighting will have a cbAttr of
  38. * 2, and nothing else.
  39. *
  40. * Revision History:
  41. *
  42. * 25-Jan-1990 ln locate -> hlp_locate
  43. * 19-Aug-1988 ln Move "locate" to assembly language hloc.asm
  44. * [] 26-Jan-1988 LN Created
  45. *
  46. *************************************************************************/
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #if defined (OS2)
  50. #else
  51. #include <windows.h>
  52. #endif
  53. #include "help.h"
  54. #include "helpfile.h"
  55. #include "helpsys.h"
  56. /************************************************************************
  57. **
  58. ** Foward Declarations
  59. */
  60. uchar near pascal toupr(uchar);
  61. /*** HelpGetLineAttr - Return attributes associated with a line of ascii text
  62. *
  63. * Interprets the help files stored format and return a line at a time of
  64. * attribute information.
  65. *
  66. * Input:
  67. * ln = 1 based line number to return
  68. * cbMax = Max number of bytes to transfer
  69. * pbDst = pointer to destination
  70. * pbTopic = PB pointer to topic text
  71. *
  72. * Output:
  73. * Returns number of characters transfered (not including terminating 0xffff
  74. * attribute), or 0 if that line does not exist.
  75. *
  76. *************************************************************************/
  77. ushort far pascal LOADDS HelpGetLineAttr(
  78. ushort ln,
  79. int cbMax,
  80. lineattr far *pbDst,
  81. PB pbTopic
  82. ) {
  83. lineattr far *pbDstBegin;
  84. uchar far *pTopic;
  85. /*
  86. ** Form valid (locked) pointer to topic text & working pointer to detination
  87. */
  88. pTopic = PBLOCK (pbTopic);
  89. pbDstBegin = pbDst;
  90. /*
  91. ** Information is on present in compressed files. Locate the line in the text,
  92. ** and then point at the attribute information therein.
  93. */
  94. #if ASCII
  95. if (((topichdr far *)pTopic)->ftype & FTCOMPRESSED) {
  96. #endif
  97. if (pTopic = hlp_locate(ln,pTopic)) {
  98. pTopic += *pTopic;
  99. /*
  100. ** Start by giving ln the count of encoded bytes. Then while there are
  101. ** bytes, and we have enough room in the destination, AND we haven't reached
  102. ** the end of the attribute information, then for each cb/attr pair, copy
  103. ** them over, converting from our internal byte-per format to the external
  104. ** word-per format.
  105. */
  106. ln = *((ushort far UNALIGNED *)pTopic)++ - (ushort)2;
  107. while ( ln
  108. && (cbMax >= sizeof(lineattr))
  109. && (((intlineattr far *)pTopic)->attr != (uchar)0xff)
  110. ) {
  111. *(ushort UNALIGNED *)&(pbDst->cb) = ((intlineattr far UNALIGNED *)pTopic)->cb;
  112. *(ushort UNALIGNED *)&(pbDst->attr) = ((intlineattr far UNALIGNED *)pTopic)->attr;
  113. pbDst++;
  114. ((intlineattr *)pTopic)++;
  115. cbMax -= sizeof(lineattr);
  116. ln -= sizeof(intlineattr);
  117. }
  118. }
  119. #if ASCII
  120. }
  121. #endif
  122. PBUNLOCK (pbTopic);
  123. /*
  124. ** Finally, if there is room in the destination buffer, terminate the
  125. ** attributes with "default attributes to the end of line", and then
  126. ** attribute ffff, signalling the end of the buffer.
  127. */
  128. if (cbMax >= sizeof(lineattr)) {
  129. pbDst->cb = 0xffff;
  130. pbDst->attr = 0;
  131. cbMax -= sizeof(lineattr);
  132. pbDst++;
  133. }
  134. if (cbMax >= sizeof(pbDst->attr))
  135. pbDst->attr = 0xffff;
  136. /*
  137. ** return the number of bytes transferred, not including the terminating
  138. ** word.
  139. */
  140. return (ushort)((uchar far *)pbDst - (uchar far *)pbDstBegin);
  141. /* end HelpGetLineAttr */}
  142. /************************************************************************
  143. **
  144. ** HelpHlNext - Locate next cross reference
  145. **
  146. ** Purpose:
  147. ** Locates the next cross reference in the help topic. Locates either the
  148. ** next physical cross reference, or the next referece beginning with a
  149. ** particular character (case insensitive!). Locates either forward or
  150. ** backward.
  151. **
  152. ** Entry:
  153. ** cLead = leading character, or flag, indicating direction and type
  154. ** of search. May be:
  155. ** NULL: Get next sequential cross reference
  156. ** -1: Get previous sequential cross reference
  157. ** char: Get next cross reference beginning with 'char'
  158. ** -char: Get previous cross reference beginning with
  159. ** 'char'
  160. ** pbTopic = pointer to topic text.
  161. ** photspot = pointer to hotspot structure to recive info. (line and col
  162. ** indicate starting point)
  163. **
  164. ** Exit:
  165. ** returns TRUE if cross reference found, hotspot structure updated.
  166. **
  167. ** Exceptions:
  168. ** returns 0 if no such cross reference.
  169. */
  170. f pascal far LOADDS HelpHlNext(cLead,pbTopic, photspot)
  171. int cLead;
  172. PB pbTopic;
  173. hotspot far *photspot;
  174. {
  175. ushort cbAttr;
  176. ushort col;
  177. ushort ln;
  178. uchar far *pbEnd; /* pointer to next line */
  179. uchar far *pbLineCur; /* pointer to current line */
  180. uchar far *pbFound = 0; /* found entry, perhaps */
  181. uchar far *pText;
  182. uchar far *pTopic;
  183. pTopic = PBLOCK (pbTopic);
  184. col = photspot->col; /* save these */
  185. ln = photspot->line;
  186. if (((topichdr far *)pTopic)->ftype & FTCOMPRESSED) {
  187. while (1) {
  188. if (ln == 0) break; /* if not found, ret */
  189. pbLineCur = hlp_locate(ln,pTopic); /* find line */
  190. if (pbLineCur == 0) break; /* if not found, ret */
  191. pText = pbLineCur; /* point at topic text */
  192. pbLineCur += *pbLineCur; /* skip the topic text */
  193. cbAttr = *((ushort far UNALIGNED *)pbLineCur)++ - (ushort)sizeof(ushort);
  194. pbEnd = pbLineCur + cbAttr; /* next line */
  195. while (cbAttr && (((intlineattr far UNALIGNED *)pbLineCur)->attr != 0xff)) {
  196. pbLineCur += sizeof(intlineattr);
  197. cbAttr -=sizeof(intlineattr);
  198. }
  199. if (cbAttr)
  200. pbLineCur += sizeof(uchar); /* skip (0xff) attr */
  201. while (pbLineCur < pbEnd) { /* scan rest for data */
  202. /*
  203. ** in a forward scan, the first cross reference (with appropriate char) that is
  204. ** greater than our current position, is the correct one.
  205. */
  206. if (cLead >= 0) { /* forward scan */
  207. if (col <= *(pbLineCur+1)) /* if found */
  208. if ((cLead == 0) /* and criteria met */
  209. || (toupr(*(pText + *pbLineCur)) == (uchar)cLead)) {
  210. pbFound = pbLineCur;
  211. break;
  212. }
  213. }
  214. /*
  215. ** in a backward scan, we accept the LAST item we find which is less than
  216. ** the current position.
  217. */
  218. else {
  219. if (col > *(pbLineCur)) /* if a candidate found */
  220. if ((cLead == -1) /* and criteria met */
  221. || (toupr(*(pText + *pbLineCur)) == (uchar)-cLead))
  222. pbFound = pbLineCur;/* remember it */
  223. }
  224. pbLineCur += 2; /* skip column spec */
  225. if (*pbLineCur)
  226. while (*pbLineCur++); /* skip string */
  227. else
  228. pbLineCur += 3;
  229. }
  230. if (pbFound) { /* if we found one */
  231. *(ushort UNALIGNED *)&(photspot->line) = ln;
  232. *(ushort UNALIGNED *)&(photspot->col) = (ushort)*pbFound++;
  233. *(ushort UNALIGNED *)&(photspot->ecol) = (ushort)*pbFound++;
  234. *(uchar *UNALIGNED *)&(photspot->pXref) = pbFound;
  235. PBUNLOCK (pbTopic);
  236. return TRUE;
  237. }
  238. /*
  239. ** move on to next line.
  240. */
  241. if (cLead >= 0) {
  242. ln++;
  243. col = 0;
  244. }
  245. else {
  246. ln--;
  247. col = 127;
  248. }
  249. }
  250. }
  251. PBUNLOCK (pbTopic);
  252. return FALSE;
  253. /* end HelpHlNext */}
  254. /************************************************************************
  255. **
  256. ** HelpXRef - Return pointer to Xref String
  257. **
  258. ** Purpose:
  259. ** Given a row, column (in a hotspot structure) and topic, return a pointer
  260. ** to a cross reference string.
  261. **
  262. ** Entry:
  263. ** pbTopic = Pointer to topic text
  264. ** photspot = Pointer to hotspot structure to update
  265. **
  266. ** Exit:
  267. ** returns far pointer into topic text of cross reference string & updates
  268. ** hotspot structure.
  269. **
  270. ** Exceptions:
  271. ** returns NULL if no cross reference for that line.
  272. **
  273. */
  274. char far * pascal far LOADDS HelpXRef(pbTopic, photspot)
  275. PB pbTopic;
  276. hotspot far *photspot;
  277. {
  278. uchar far *pTopic;
  279. ushort col; /* column requested */
  280. ushort ln; /* line requested */
  281. pTopic = PBLOCK (pbTopic);
  282. col = photspot->col; /* save these */
  283. ln = photspot->line;
  284. if (((topichdr far *)pTopic)->ftype & FTCOMPRESSED)
  285. if (HelpHlNext(0,pbTopic,photspot)) /* if xref found */
  286. if ( (photspot->line == ln) /* & our req. in range */
  287. && ( (col >= photspot->col)
  288. && (col <= photspot->ecol))) {
  289. PBUNLOCK (pbTopic);
  290. return photspot->pXref; /* return ptr */
  291. }
  292. PBUNLOCK (pbTopic);
  293. return 0;
  294. /* end HelpXRef */}