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.

345 lines
8.5 KiB

  1. /*** mhutil - utilities for the help extension for the Microsoft Editor
  2. *
  3. * Copyright <C> 1988, Microsoft Corporation
  4. *
  5. * Revision History (most recent first):
  6. *
  7. * 01-Dec-1988 ln Cleanup & dislog help
  8. * 28-Sep-1988 ln Correct GrabWord return value
  9. * 02-Sep-1988 ln Make all data inited. Add info in debug vers.
  10. * [] 16-May-1988 Extracted from mehelp.c
  11. *
  12. *************************************************************************/
  13. #include <string.h> /* string functions */
  14. #include <malloc.h>
  15. #include "mh.h" /* help extension include file */
  16. /************************************************************************
  17. **
  18. ** procArgs
  19. **
  20. ** Purpose:
  21. ** decode arguments passed into extension into commonly used variables.
  22. **
  23. ** Entry:
  24. ** pArg = pointer to arg structure, courtesy of Z
  25. **
  26. ** Exit:
  27. ** returns pArg->argType. Global variables updated.
  28. */
  29. int pascal near procArgs (pArg)
  30. ARG far *pArg; /* argument data */
  31. {
  32. buf[0] = 0;
  33. pArgWord = pArgText = 0;
  34. rnArg.flFirst.col = rnArg.flLast.col = 0;
  35. rnArg.flFirst.lin = rnArg.flLast.lin = 0;
  36. cArg = 0;
  37. opendefault ();
  38. pFileCur = FileNameToHandle ("", ""); /* get current file handle */
  39. fnCur[0] = 0;
  40. GetEditorObject(RQ_FILE_NAME,0,fnCur); /* get filename */
  41. fnExtCur = strchr (fnCur, '.'); /* and pointer to extension */
  42. switch (pArg->argType) {
  43. case NOARG: /* <function> only, no arg */
  44. cArg = 0;
  45. pArgText = NULL;
  46. break;
  47. case NULLARG: /* <arg><function> */
  48. cArg = pArg->arg.nullarg.cArg; /* get <arg> count */
  49. GrabWord (); /* get argtext and argword */
  50. break;
  51. case STREAMARG: /* <arg>line movement<function> */
  52. cArg = pArg->arg.streamarg.cArg;/* get <arg> count */
  53. rnArg.flFirst.col = pArg->arg.streamarg.xStart;
  54. rnArg.flLast.col = pArg->arg.streamarg.xEnd;
  55. rnArg.flFirst.lin = pArg->arg.streamarg.yStart;
  56. if (GetLine(rnArg.flFirst.lin, buf, pFileCur) > rnArg.flFirst.col) {
  57. pArgText = &buf[rnArg.flFirst.col]; /* point at word */
  58. buf[rnArg.flLast.col] = 0; /* terminate string */
  59. }
  60. break;
  61. case TEXTARG: /* <arg> text <function> */
  62. cArg = pArg->arg.textarg.cArg; /* get <arg> count */
  63. pArgText = pArg->arg.textarg.pText;
  64. break;
  65. }
  66. return pArg->argType;
  67. /* end procArgs */}
  68. /************************************************************************
  69. **
  70. ** GrabWord - Grab the word under the editor cursor
  71. **
  72. ** Purpose:
  73. ** grabs the word underneath the cursor for context sensitive help look-up.
  74. **
  75. ** Entry:
  76. ** none
  77. **
  78. ** Returns:
  79. ** nothing. pArgWord points to word, if it was parsed.
  80. */
  81. void pascal near GrabWord () {
  82. pArgText = pArgWord = 0;
  83. pFileCur = FileNameToHandle ("", ""); /* get current file handle */
  84. GetTextCursor (&rnArg.flFirst.col, &rnArg.flFirst.lin);
  85. if (GetLine(rnArg.flFirst.lin, buf, pFileCur)) { /* get line */
  86. pArgText = &buf[rnArg.flFirst.col]; /* point at word */
  87. while (!wordSepar((int)*pArgText))
  88. pArgText++; /* search for end */
  89. *pArgText = 0; /* and terminate */
  90. pArgWord = pArgText = &buf[rnArg.flFirst.col]; /* point at word */
  91. while ((pArgWord > &buf[0]) && !wordSepar ((int)*(pArgWord-1)))
  92. pArgWord--;
  93. }
  94. /* end GrabWord */}
  95. /*** appTitle - Append help file title to buffer
  96. *
  97. * Read in the title of a help file and append it to a buffer.
  98. *
  99. * Input:
  100. * fpDest - far pointer to destination of string
  101. * ncInit - Any nc of file to get title for
  102. *
  103. * Output:
  104. * Returns
  105. *
  106. *************************************************************************/
  107. void pascal near appTitle (
  108. char far *pDest,
  109. nc ncInit
  110. ) {
  111. /*
  112. ** first, point to end of string to append to
  113. */
  114. while (*pDest)
  115. pDest++;
  116. /*
  117. ** Start by getting the info on the file referenced, so that we can get the
  118. ** ncInit for that file.
  119. */
  120. if (!HelpGetInfo (ncInit, &hInfoCur, sizeof(hInfoCur))) {
  121. ncInit = NCINIT(&hInfoCur);
  122. /*
  123. ** Find the context string, and read the topic. Then just read the first
  124. ** line into the destination
  125. */
  126. ncInit = HelpNc ("h.title",ncInit);
  127. if (ncInit.cn && (fReadNc(ncInit))) {
  128. pDest += HelpGetLine (1, BUFLEN, pDest, pTopic);
  129. *pDest = 0;
  130. free (pTopic);
  131. pTopic = NULL;
  132. }
  133. /*
  134. ** If no title was found, then just place the help file name there.
  135. */
  136. else
  137. strcpy (pDest, HFNAME(&hInfoCur));
  138. }
  139. /*
  140. ** If we couldn't even get the info, then punt...
  141. */
  142. else
  143. strcpy (pDest, "** unknown **");
  144. /* end appTitle */}
  145. /*** errstat - display error status message
  146. *
  147. * In non cw, just display the strings on the status line. In CW, bring up
  148. * a message box.
  149. *
  150. * Input:
  151. * sz1 = first error message line
  152. * sz2 = second. May be NULL.
  153. *
  154. * Output:
  155. * Returns FALSE
  156. *************************************************************************/
  157. flagType
  158. pascal
  159. near
  160. errstat (
  161. char *sz1,
  162. char *sz2
  163. )
  164. {
  165. #if defined(PWB)
  166. DoMessageBox (sz1, sz2, NULL, MBOX_OK);
  167. #else
  168. buffer L_buf = {0};
  169. strncpy (L_buf, sz1, sizeof(L_buf)-1);
  170. if (sz2) {
  171. strcat (L_buf, " ");
  172. strncat (L_buf, sz2, sizeof(L_buf)-strlen(L_buf));
  173. }
  174. stat (buf);
  175. #endif
  176. return FALSE;
  177. /* end errstat */}
  178. /*** stat - display status line message
  179. *
  180. * Places extension name and message on the status line
  181. *
  182. * Entry:
  183. * pszFcn - Pointer to string to be prepended.
  184. *
  185. * Exit:
  186. * none
  187. *
  188. *************************************************************************/
  189. void pascal near stat(char *pszFcn)
  190. {
  191. buffer L_buf = {0}; /* message buffer */
  192. strncat(L_buf,"mhelp: ", sizeof(L_buf)-1); /* start with name */
  193. if (strlen(pszFcn) > 72) {
  194. pszFcn+= strlen(pszFcn) - 69;
  195. strncat (L_buf, "...", sizeof(L_buf)-1-strlen(L_buf));
  196. }
  197. strncat(L_buf,pszFcn,sizeof(L_buf)-1-strlen(L_buf)); /* append message */
  198. DoMessage (L_buf); /* display */
  199. }
  200. #ifdef DEBUG
  201. buffer debstring = {0};
  202. extern int delay; /* message delay */
  203. /*** debhex - output long in hex
  204. *
  205. * Display the value of a long in hex
  206. *
  207. * Input:
  208. * lval = long value
  209. *
  210. * Output:
  211. * Returns nothing
  212. *
  213. *************************************************************************/
  214. void pascal near debhex (
  215. long lval
  216. ) {
  217. char lbuf[10];
  218. _ultoa (lval, lbuf, 16);
  219. debmsg (lbuf);
  220. /* end debhex */}
  221. /*** debmsg - piece together debug message
  222. *
  223. * Outputs a the cummulative message formed by successive calls.
  224. *
  225. * Input:
  226. * psz = pointer to message part
  227. *
  228. * Output:
  229. * Returns nothing
  230. *************************************************************************/
  231. void pascal near debmsg (
  232. char far *psz
  233. ) {
  234. _stat (strcat (debstring, psz ? psz : "<NULL>" ));
  235. /* end debmsg */}
  236. /*** debend - terminates message accumulation & pauses
  237. *
  238. * Terminates the message accumulation, displays the final message, and
  239. * pauses, either for the pause time, or for a keystroke.
  240. *
  241. * Input:
  242. * fWait = TRUE => wait for a keystroke
  243. *
  244. * Output:
  245. * Returns nothing
  246. *
  247. *************************************************************************/
  248. void pascal near debend (
  249. flagType fWait
  250. ) {
  251. if (fWait && delay) {
  252. #if defined(PWB)
  253. DoMessageBox (debstring, NULL, NULL, MBOX_OK);
  254. #else
  255. _stat (strcat (debstring, " Press a key..."));
  256. ReadChar ();
  257. #endif
  258. }
  259. #ifdef OS2
  260. else if (delay)
  261. DosSleep ((long)delay);
  262. #endif
  263. debstring[0] = 0;
  264. /* end debend */}
  265. /*** _mhassertexit - display assertion message and exit
  266. *
  267. * Input:
  268. * pszExp - expression which failed
  269. * pszFn - filename containing failure
  270. * line - line number failed at
  271. *
  272. * Output:
  273. * Doesn't return
  274. *
  275. *************************************************************************/
  276. void pascal near _mhassertexit (
  277. char *pszExp,
  278. char *pszFn,
  279. int line
  280. ) {
  281. char lbuf[10];
  282. _ultoa (line, lbuf, 10);
  283. strcpy (buf, pszExp);
  284. strcat (buf, " in ");
  285. strcat (buf, pszFn);
  286. strcat (buf, ": line ");
  287. strcat (buf, lbuf);
  288. errstat ("Help assertion failed", buf);
  289. fExecute ("exit");
  290. /* end _mhassertexit */}
  291. #endif
  292. flagType pascal wordSepar (int i) {
  293. CHAR c = (CHAR)i;
  294. if (((c >= 'a') && (c <= 'z')) ||
  295. ((c >= 'A') && (c <= 'Z')) ||
  296. ((c >= '0') && (c <= '9')) ||
  297. ( c == '_' ) ||
  298. ( c == '$' ) ) {
  299. return FALSE;
  300. } else {
  301. return TRUE;
  302. }
  303. }
  304. char far * pascal near xrefCopy (char far *dst, char far *src)
  305. {
  306. if ( *src ) {
  307. strcpy( dst, src );
  308. } else {
  309. dst[0] = src[0];
  310. dst[1] = src[1];
  311. dst[2] = src[2];
  312. }
  313. return dst;
  314. }