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.

376 lines
8.1 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* DEBUG.C -- Diagnostic routines for WRITE */
  5. #define NOCLIPBOARD
  6. #define NOGDICAPMASKS
  7. #define NOVIRTUALKEYCODES
  8. #define NOWINSTYLES
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #define NOKEYSTATE
  12. #define NOSYSCOMMANDS
  13. #define NOATOM
  14. #define NODRAWTEXT
  15. #define NOMETAFILE
  16. #define NOOPENFILE
  17. #define NOWH
  18. #define NOWINOFFSETS
  19. #define NOOPENFILE
  20. #define NORECT
  21. #define NOSOUND
  22. #define NOCOMM
  23. #include <windows.h>
  24. #include "mw.h"
  25. #define NOUAC
  26. #include "cmddefs.h"
  27. #include "wwdefs.h"
  28. #include "filedefs.h"
  29. #include "prmdefs.h"
  30. #include "editdefs.h"
  31. #include "docdefs.h"
  32. extern struct WWD rgwwd[];
  33. extern beep();
  34. extern toggleProf();
  35. #ifdef DEBUG
  36. BOOL fDebugOut = TRUE;
  37. fnTest()
  38. {
  39. beep();
  40. TestFormat();
  41. beep();
  42. beep();
  43. dbgWait(); /* for use by symdeb to check variables */
  44. }
  45. TestFormat()
  46. {
  47. //toggleProf();
  48. }
  49. dbgWait()
  50. {
  51. }
  52. /* --- Integrity check for all piece tables in all docs --- */
  53. CheckPctb()
  54. {
  55. extern int fnMac;
  56. extern int fPctbCheck;
  57. extern struct DOD (**hpdocdod) [];
  58. extern struct FCB (**hpfnfcb) [];
  59. extern int docMac;
  60. int doc;
  61. struct PCTB **hpctb;
  62. struct PCTB *ppctb;
  63. struct DOD *pdod;
  64. struct PCD *ppcd;
  65. int ipcd;
  66. if (!fPctbCheck)
  67. return;
  68. for ( doc = 0, pdod = &(**hpdocdod) [0] ; doc < docMac; doc++, pdod++ )
  69. if ((hpctb = pdod->hpctb) != 0)
  70. { /* Doc entry is nonempty -- check it */
  71. ppctb = *hpctb;
  72. /* # pieces used does not exceed # allocated */
  73. Assert( ppctb->ipcdMac <= ppctb->ipcdMax );
  74. Assert( ppctb->ipcdMac >= 1 );
  75. #ifndef OURHEAP
  76. /* handle contains enough space for pieces */
  77. Assert( LocalSize( (HANDLE)hpctb ) >= sizeof (struct PCTB) +
  78. (sizeof (struct PCD) * (ppctb->ipcdMax - cpcdInit)));
  79. #endif
  80. /* Now check the contents of the pieces */
  81. {
  82. /* cpMin of first piece is always 0 for nonnull piece table */
  83. Assert( ppctb->rgpcd [0].cpMin == cp0 || ppctb->rgpcd [0].fn == fnNil);
  84. for ( ipcd = 0, ppcd = &(ppctb->rgpcd [0]); ipcd < ppctb->ipcdMac;
  85. ipcd++, ppcd++ )
  86. {
  87. int fn = ppcd->fn;
  88. typeFC fc = ppcd->fc;
  89. unsigned sprm;
  90. struct FCB *pfcb;
  91. if (fn == fnNil)
  92. { /* end piece */
  93. /* first piece with fnNil is in fact the end piece */
  94. /* Assert( ipcd == ppctb->ipcdMac - 1 ); */
  95. /* end piece is intact */
  96. Assert( bPRMNIL(ppcd->prm) );
  97. break;
  98. }
  99. if (ipcd > 0)
  100. /* Pieces are in ascending cp order */
  101. Assert(ppcd->cpMin > (ppcd-1)->cpMin);
  102. /* fn is valid */
  103. Assert( (fn >= 0 && fn < fnMac) || fn == fnInsert );
  104. pfcb = &(**hpfnfcb) [fn];
  105. /* fn does not point to an unallocated fcb entry */
  106. Assert( pfcb->rfn != rfnFree );
  107. /* fc is reasonable for the fn */
  108. Assert( fc >= 0 );
  109. Assert( fc + (ppcd+1)->cpMin - ppcd->cpMin <= pfcb->fcMac );
  110. /* prm is a valid value */
  111. Assert( bPRMNIL(ppcd->prm) ||
  112. (((struct PRM *) &ppcd->prm)->fComplex) ||
  113. ((sprm = ((struct PRM *) &ppcd->prm)->sprm) > 0 &&
  114. sprm < sprmMax) );
  115. }
  116. }
  117. }
  118. }
  119. /* COMM Output routines */
  120. #define cchSzCommMax 100
  121. static CHAR szCRLF[] = "\r\n";
  122. BOOL vfCommDebug = fTrue; /* True for AUX, False for LPT */
  123. #if WINVER < 0x300
  124. /* This method isn't quite working under Win 3.0 ..pault */
  125. void CommSz( CHAR * ); /* Main string output, defined in doslib.asm */
  126. #else
  127. void CommSz( psz )
  128. register CHAR *psz;
  129. {
  130. CHAR szT[512];
  131. char *pszT;
  132. if (fDebugOut)
  133. {
  134. /* The following loops essentially copies psz to szT
  135. but with the addition that chars > 127 are changed
  136. to a representation readable on a dumb terminal, i.e.
  137. ASCII 164 shows up as '{164}' ..pault */
  138. for (pszT = szT; ; psz++)
  139. {
  140. if (*psz < 128)
  141. *(pszT++) = *psz;
  142. else
  143. {
  144. *(pszT++) = '{';
  145. ncvtu((int) *psz, &pszT);
  146. *(pszT++) = '}';
  147. }
  148. if (*psz == '\0') /* finally copied null terminator */
  149. break;
  150. }
  151. OutputDebugString( (LPSTR) szT );
  152. }
  153. }
  154. #endif
  155. CommSzNum( sz, num )
  156. CHAR *sz;
  157. int num;
  158. {
  159. CHAR szBuf[ cchSzCommMax ];
  160. CHAR *pch = szBuf;
  161. Assert( CchSz( sz ) <= cchSzCommMax );
  162. pch = &szBuf[ CchCopySz( sz, szBuf ) ];
  163. ncvtu( num, &pch );
  164. CchCopySz( szCRLF, pch );
  165. CommSz( szBuf );
  166. }
  167. /* This is extremely useful when displaying coordinates
  168. when the values are not in contiguous locations */
  169. CommSzNumNum( sz, num, num2 )
  170. CHAR *sz;
  171. int num, num2;
  172. {
  173. CHAR szBuf[ cchSzCommMax ];
  174. CHAR *pch = szBuf;
  175. Assert( CchSz( sz ) <= cchSzCommMax );
  176. pch = &szBuf[ CchCopySz( sz, szBuf ) ];
  177. ncvtu( num, &pch );
  178. *(pch++) = ' ';
  179. ncvtu( num2, &pch );
  180. CchCopySz( szCRLF, pch );
  181. CommSz( szBuf );
  182. }
  183. CommSzRgNum( sz, rgw, cw)
  184. CHAR *sz;
  185. int *rgw;
  186. int cw;
  187. {
  188. CHAR szBuf[ cchSzCommMax ];
  189. CHAR *pch = szBuf;
  190. Assert( CchSz( sz ) <= cchSzCommMax );
  191. pch = &szBuf[ CchCopySz( sz, szBuf ) ];
  192. for ( ; cw > 0; cw--)
  193. {
  194. ncvtu( *(rgw++), &pch );
  195. *(pch++) = ' ';
  196. }
  197. CchCopySz( szCRLF, pch );
  198. CommSz( szBuf );
  199. }
  200. CommSzSz( sz1, sz2 )
  201. CHAR *sz1, *sz2;
  202. {
  203. CHAR szBuf[ cchSzCommMax ];
  204. int cch;
  205. Assert( CchSz( sz1 ) + CchSz( sz2 ) - 1 <= cchSzCommMax );
  206. cch = CchCopySz( sz1, szBuf );
  207. cch += CchCopySz( sz2, &szBuf[ cch ] );
  208. CchCopySz( szCRLF, &szBuf[ cch ] );
  209. CommSz( szBuf );
  210. }
  211. /* ASSERT */
  212. Do_Assert(pch, line, f)
  213. PCH pch;
  214. int line;
  215. BOOL f;
  216. {
  217. extern HWND vhWndMsgBoxParent;
  218. extern FARPROC lpDialogAlert;
  219. static CHAR szAssert[] = "Assertion failure in ";
  220. static CHAR szLine[] = " at line ";
  221. if (f)
  222. return;
  223. else
  224. {
  225. #ifdef OURHEAP
  226. extern int cHpFreeze;
  227. int cHpFreezeT = cHpFreeze;
  228. #endif
  229. CHAR szAlertMsg[50];
  230. PCH pchtmp;
  231. int cch;
  232. int idi;
  233. HWND hWndParent = (vhWndMsgBoxParent == NULL) ?
  234. wwdCurrentDoc.wwptr : vhWndMsgBoxParent;
  235. bltbc((PCH)szAlertMsg, 0, 50);
  236. bltbyte((PCH)szAssert, (PCH)szAlertMsg, 21);
  237. pchtmp = (PCH)&szAlertMsg[21];
  238. bltbyte((PCH)pch, pchtmp, (cch = CchSz(pch) - 1));
  239. pchtmp += cch;
  240. bltbyte((PCH)szLine, pchtmp, 9);
  241. pchtmp += 9;
  242. ncvtu(line, (PCH)&pchtmp) - 1;
  243. #ifdef OURHEAP
  244. cHpFreeze = 0; /* So we don't panic in MdocLoseFocus */
  245. #endif
  246. do
  247. {
  248. idi = MessageBox( hWndParent, (LPSTR) szAlertMsg,
  249. (LPSTR)"Assert",
  250. MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL);
  251. switch (idi) {
  252. default:
  253. case IDABORT:
  254. case IDCANCEL:
  255. FatalExit( line );
  256. break;
  257. case IDIGNORE:
  258. #ifdef OURHEAP
  259. cHpFreeze = cHpFreezeT;
  260. #endif
  261. return;
  262. case IDRETRY:
  263. break;
  264. }
  265. } while (idi == IDRETRY);
  266. } /* end else */
  267. } /* end of _Assert */
  268. ShowDocPcd(szID, doc)
  269. CHAR *szID;
  270. int doc;
  271. {
  272. struct PCTB **hpctb;
  273. struct PCD *ppcdCur, *ppcdMac;
  274. extern struct DOD (**hpdocdod)[];
  275. hpctb = (**hpdocdod)[doc].hpctb;
  276. ppcdCur = &(**hpctb).rgpcd[0];
  277. ppcdMac = &(**hpctb).rgpcd[(**hpctb).ipcdMac];
  278. for (; ppcdCur < ppcdMac; ppcdCur++)
  279. {
  280. ShowPpcd(szID, ppcdCur);
  281. }
  282. }
  283. ShowPpcd(szID, ppcd)
  284. CHAR *szID;
  285. struct PCD *ppcd;
  286. {
  287. /* Dump a given piece descriptor on COM1: along with a
  288. given an ID string. */
  289. CommSz(szID);
  290. CommSz("\r\n");
  291. CommSzNum("ppcd: ", (int) ppcd);
  292. CommSzNum("cpMin: ", (int) (ppcd->cpMin));
  293. CommSzSz("fNoParaLast: ", (ppcd->fNoParaLast) ? "TRUE" : "FALSE");
  294. CommSzNum("fn: ", (int) (ppcd->fn));
  295. CommSzNum("fc: ", (int) (ppcd->fc));
  296. CommSzNum("prm: ", (int) *((int *) &(ppcd->prm)));
  297. }
  298. #endif /* DEBUG */
  299.