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.

490 lines
14 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* fetch.c -- MW routines for obtaining attributes associated with cp's */
  5. #define NOCLIPBOARD
  6. #define NOGDICAPMASKS
  7. #define NOCTLMGR
  8. #define NOVIRTUALKEYCODES
  9. #define NOWINMESSAGES
  10. #define NOWINSTYLES
  11. #define NOSYSMETRICS
  12. #define NOMENUS
  13. #define NOICON
  14. #define NOKEYSTATE
  15. #define NORASTEROPS
  16. #define NOSHOWWINDOW
  17. #define NOSYSCOMMANDS
  18. #define NOCREATESTRUCT
  19. #define NOATOM
  20. #define NOMETAFILE
  21. #define NOGDI
  22. #define NOFONT
  23. #define NOBRUSH
  24. #define NOPEN
  25. #define NOBITMAP
  26. #define NOCOLOR
  27. #define NODRAWTEXT
  28. #define NOWNDCLASS
  29. #define NOSOUND
  30. #define NOCOMM
  31. #define NOMB
  32. #define NOMSG
  33. #define NOOPENFILE
  34. #define NORESOURCE
  35. #define NOPOINT
  36. #define NORECT
  37. #define NOREGION
  38. #define NOSCROLL
  39. #define NOTEXTMETRIC
  40. #define NOWH
  41. #define NOWINOFFSETS
  42. #include <windows.h>
  43. #include "mw.h"
  44. #include "editdefs.h"
  45. #include "propdefs.h"
  46. #include "docdefs.h"
  47. #include "cmddefs.h"
  48. #include "filedefs.h"
  49. /*
  50. #include "code.h"
  51. */
  52. #include "ch.h"
  53. #include "fkpdefs.h"
  54. #include "prmdefs.h"
  55. /*
  56. #include "stcdefs.h"
  57. */
  58. static SetChp(struct CHP *pchp, int *pcfcChp, int fn, typeFC fc, struct PRM prm);
  59. extern typeCP vcpFetch;
  60. extern int vichFetch;
  61. extern int vdocFetch;
  62. extern int vccpFetch;
  63. extern int vcchFetch;
  64. extern CHAR *vpchFetch;
  65. extern struct CHP vchpFetch;
  66. extern CHAR (**hgchExpand)[];
  67. extern int vdocExpFetch;
  68. extern struct CHP vchpAbs;
  69. extern int vfDiskError;
  70. #ifdef CASHMERE
  71. extern int docBuffer;
  72. #endif
  73. extern struct PAP vpapAbs;
  74. extern struct CHP vchpNormal;
  75. extern struct DOD (**hpdocdod)[];
  76. extern CHAR rgchInsert[];
  77. extern int ichInsert;
  78. extern struct CHP vchpInsert;
  79. extern typeCP vcpFirstParaCache;
  80. extern typeCP vcpLimParaCache;
  81. extern struct PAP vpapCache;
  82. extern struct FCB (**hpfnfcb)[];
  83. extern struct FKPD vfkpdCharIns;
  84. extern typeFC fcMacChpIns;
  85. typePN PnFkpFromFcScr();
  86. CHAR *PchFromFc();
  87. #ifdef BOGUS
  88. #ifdef DEBUG
  89. typeCP cpExpFetch;
  90. CHAR *pchExpFetch;
  91. int cchExpFetch;
  92. int ccpExpFetch;
  93. #endif /* DEBUG */
  94. #endif
  95. FetchCp(doc, cp, ich, fcm)
  96. int doc, ich, fcm;
  97. typeCP cp;
  98. { /*
  99. Inputs:
  100. doc
  101. Starting cp
  102. ich within cp (for cp's which can cross line boundaries)
  103. fcm tells whether to get chars, props, or both
  104. Outputs:
  105. (in vcpFetch) starting cp
  106. (in vichFetch) starting ich within expanded cp
  107. (in vdocFetch) doc
  108. (in vccpFetch) number of cp's fetched (0 if expanded cp)
  109. (in vcchFetch) number of ch's fetched
  110. (in vpchFetch) characters fetched
  111. (in vchpFetch) char prop of fetched chars
  112. */
  113. struct PCD *ppcd;
  114. static int fn;
  115. static typeFC fc;
  116. static struct PRM prm;
  117. static typeCP ccpChp, ccpPcd, ccpFile;
  118. static int ipcd;
  119. static typeCP cpExpFetch;
  120. static CHAR *pchExpFetch;
  121. static int cchExpFetch;
  122. static int ccpExpFetch;
  123. if (doc == docNil)
  124. { /* Sequential call to FetchCp */
  125. /* If last piece was Q&D insert, skip remainder of piece */
  126. if (fn == fnInsert && (fc + vccpFetch) >= ichInsert)
  127. vccpFetch = ccpPcd; /* Use whole piece */
  128. vcpFetch += vccpFetch; /* Go to where we left off */
  129. if (vccpFetch == 0)
  130. vichFetch += vcchFetch;
  131. else
  132. vichFetch = 0;
  133. fc += vccpFetch;
  134. }
  135. else
  136. { /* Random-access call */
  137. vcpFetch = cp;
  138. vichFetch = ich;
  139. vdocFetch = doc;
  140. ccpChp = ccpPcd = ccpFile = 0;
  141. }
  142. if (vcpFetch >= (**hpdocdod)[vdocFetch].cpMac)
  143. { /* Use std looks for end mark */
  144. vccpFetch = 0;
  145. /* vcchFetch == 0 should not be used for endmark indications because of
  146. empty QD runs. */
  147. vcchFetch = 1;
  148. if (fcm & fcmProps)
  149. {
  150. blt(&vchpNormal, &vchpFetch, cwCHP);
  151. blt(&vchpNormal, &vchpAbs, cwCHP);
  152. }
  153. return;
  154. }
  155. #ifdef STYLES
  156. if ((fcm & (fcmChars + fcmNoExpand)) == fcmChars &&
  157. (**hpdocdod)[vdocFetch].dty == dtySsht)
  158. { /* Style sheet; expand encoded text */
  159. if (fcm & fcmProps)
  160. {
  161. blt(&vchpNormal, &vchpFetch, cwCHP);
  162. blt(&vchpNormal, &vchpAbs, cwCHP);
  163. }
  164. if (vdocExpFetch == vdocFetch && vcpFetch == cpExpFetch + ccpExpFetch)
  165. { /* Give back the last EOL in the expansion */
  166. vccpFetch = vcchFetch = 1;
  167. vpchFetch = &(**hgchExpand)[cchExpFetch];
  168. return;
  169. }
  170. else if (vdocExpFetch != vdocFetch || cpExpFetch != vcpFetch)
  171. { /* New expansion */
  172. int ich = vichFetch;
  173. vdocExpFetch = vdocFetch;
  174. cpExpFetch = vcpFetch;
  175. pchExpFetch = PchExpStyle(&cchExpFetch, &ccpExpFetch, vdocFetch,
  176. vcpFetch); /* Uses FetchCp, so better save v's */
  177. vcpFetch = cpExpFetch; /* Got changed by PchExpStyle */
  178. vichFetch = ich; /* Ditto */
  179. if (fcm & fcmProps) /* Ditto */
  180. {
  181. blt(&vchpNormal, &vchpFetch, cwCHP);
  182. blt(&vchpNormal, &vchpAbs, cwCHP);
  183. }
  184. }
  185. if (vichFetch >= cchExpFetch)
  186. { /* End of expansion; skip cp's */
  187. vccpFetch = ccpExpFetch;
  188. vcchFetch = 0;
  189. ccpPcd = ccpFile = ccpChp = 0;
  190. }
  191. else
  192. {
  193. vccpFetch = 0;
  194. vcchFetch = cchExpFetch - vichFetch;
  195. }
  196. vpchFetch = pchExpFetch + vichFetch;
  197. return;
  198. }
  199. #endif /* STYLES */
  200. if (ccpPcd > vccpFetch)
  201. ccpPcd -= vccpFetch;
  202. else
  203. {
  204. struct PCTB *ppctb = *(**hpdocdod)[vdocFetch].hpctb;
  205. if (doc == docNil)
  206. ++ipcd; /* Save some work on sequential call */
  207. else
  208. { /* Search for piece and remember index for next time */
  209. ipcd = IpcdFromCp(ppctb, vcpFetch);
  210. }
  211. ppcd = &ppctb->rgpcd[ipcd];
  212. ccpPcd = (ppcd + 1)->cpMin - vcpFetch;
  213. ccpChp = ccpFile = 0; /* Invalidate everything; new piece */
  214. fc = ppcd->fc + vcpFetch - ppcd->cpMin;
  215. if ((fn = ppcd->fn) == fnInsert)
  216. { /* Special quick and dirty insert mode */
  217. vpchFetch = rgchInsert + fc;
  218. ccpChp = ccpFile = vccpFetch = max(0, ichInsert - (int) fc);
  219. if (fcm & fcmProps)
  220. {
  221. ccpChp = vccpFetch;
  222. blt(&vchpInsert, &vchpFetch, cwCHP);
  223. #ifdef STYLES
  224. blt(PpropXlate(vdocFetch, &vchpFetch, &vpapAbs), &vchpAbs,
  225. cwCHP);
  226. #else
  227. blt(&vchpFetch, &vchpAbs, cwCHP);
  228. #endif
  229. goto ParseCaps;
  230. }
  231. return;
  232. }
  233. prm = ppcd->prm;
  234. }
  235. /* No monkeying with files after this statement, or we may page out */
  236. if (fcm & fcmChars)
  237. {
  238. #ifdef ENABLE /* In WRITE, we cannot assume that vpchFetch will remain
  239. valid, because we do our reading in multi-page chunks;
  240. also, rgbp can move */
  241. if (ccpFile > vccpFetch)
  242. {
  243. ccpFile -= vccpFetch;
  244. vpchFetch += vccpFetch;
  245. }
  246. else
  247. #endif
  248. {
  249. int ccpT;
  250. vpchFetch = PchFromFc(fn, fc, &ccpT); /* Read in buffer */
  251. ccpFile = ccpT;
  252. }
  253. }
  254. if (fcm & fcmProps)
  255. { /* There must be enough page buffers so that this will not
  256. page out vpchFetch! */
  257. if (ccpChp > vccpFetch)
  258. ccpChp -= vccpFetch;
  259. else
  260. { /* CachePara must have been called prior to FetchCp */
  261. int ccpT;
  262. SetChp(&vchpFetch, &ccpT, fn, fc, prm);
  263. ccpChp = ccpT;
  264. #ifdef CASHMERE /* no docBuffer in WRITE */
  265. if(vdocFetch != docBuffer)
  266. #endif
  267. #ifdef STYLES
  268. blt(PpropXlate(vdocFetch, &vchpFetch, &vpapAbs), &vchpAbs,
  269. cwCHP);
  270. #else
  271. blt(&vchpFetch, &vchpAbs, cwCHP);
  272. #endif
  273. }
  274. }
  275. /* Set vccpFetch to minimum of various restraining ccp's */
  276. vccpFetch = (ccpPcd >= 32767) ? 32767 : ccpPcd;
  277. if ((fcm & fcmChars) && ccpFile < vccpFetch) vccpFetch = ccpFile;
  278. if ((fcm & fcmProps) && ccpChp < vccpFetch) vccpFetch = ccpChp;
  279. ParseCaps:
  280. #ifdef CASHMERE
  281. if ((fcm & fcmParseCaps) != 0)
  282. {
  283. CHAR *pch;
  284. int cch;
  285. /* Brodie says this will not work for style sheet */
  286. if (vchpFetch.csm == csmSmallCaps)
  287. { /* Parse small caps into runs */
  288. pch = &vpchFetch[0];
  289. cch = vccpFetch - 1;
  290. /* This either */
  291. blt(&vchpFetch, &vchpAbs, cwCHP); /* because vchpAbs could be modified */
  292. if (islower(*pch++))
  293. {
  294. while ((islower(*pch) || *pch == chSpace)
  295. && cch-- != 0)
  296. pch++;
  297. #ifndef SAND
  298. vchpAbs.hps =
  299. max(1, (vchpAbs.hps * 4 + 2) / 5);
  300. #endif
  301. }
  302. else
  303. {
  304. while (!islower(*pch) && cch-- != 0)
  305. pch++;
  306. vchpAbs.csm = csmNormal;
  307. }
  308. vccpFetch = min((int)ccpChp, pch - vpchFetch);
  309. }
  310. }
  311. #endif /* CASHMERE */
  312. vcchFetch = vccpFetch;
  313. } /* end of F e t c h C p */
  314. FetchRgch(pcch, pch, doc, cp, cpMac, cchMax)
  315. int *pcch, doc, cchMax;
  316. CHAR *pch;
  317. typeCP cp, cpMac;
  318. {
  319. int cch = 0;
  320. FetchCp(doc, cp, 0, fcmChars + fcmNoExpand);
  321. while (cch < cchMax && vcpFetch < cpMac)
  322. {
  323. #ifdef INEFFICIENT
  324. int ccp = (int) CpMin((typeCP) min(cchMax - cch, vccpFetch),
  325. cpMac - vcpFetch);
  326. #endif
  327. int ccp = cchMax - cch;
  328. if (ccp > vccpFetch)
  329. ccp = vccpFetch;
  330. if (ccp > cpMac - vcpFetch)
  331. ccp = cpMac - vcpFetch;
  332. bltbyte(vpchFetch, pch, ccp);
  333. pch += ccp;
  334. cch += ccp;
  335. if (ccp < vccpFetch)
  336. break; /* Save some work */
  337. FetchCp(docNil, cpNil, 0, fcmChars + fcmNoExpand);
  338. }
  339. *pcch = cch;
  340. } /* end of F e t c h R g c h */
  341. int IpcdFromCp(ppctb, cp)
  342. struct PCTB *ppctb;
  343. typeCP cp;
  344. { /* Binary search piece table for cp; return index */
  345. int ipcdLim = ppctb->ipcdMac;
  346. int ipcdMin = 0;
  347. struct PCD *rgpcd = ppctb->rgpcd;
  348. while (ipcdMin + 1 < ipcdLim)
  349. {
  350. int ipcdGuess = (ipcdMin + ipcdLim) >> 1;
  351. typeCP cpGuess;
  352. if ((cpGuess = rgpcd[ipcdGuess].cpMin) <= cp)
  353. {
  354. ipcdMin = ipcdGuess;
  355. if (cp == cpGuess)
  356. break; /* Hit it on the nose! */
  357. }
  358. else
  359. ipcdLim = ipcdGuess;
  360. }
  361. return ipcdMin;
  362. } /* end of I p c d F r o m C p */
  363. static SetChp(struct CHP *pchp, int *pcfcChp, int fn, typeFC fc, struct PRM prm)
  364. { /* Fill pchp with char props; return length of run in *pcfcChp */
  365. struct FKP *pfkp;
  366. struct FCHP *pfchp;
  367. typeFC cfcChp;
  368. struct FCB *pfcb;
  369. pfcb = &(**hpfnfcb)[fn];
  370. cfcChp = pfcb->fcMac - fc;
  371. FreezeHp();
  372. if (fn == fnScratch && fc >= fcMacChpIns)
  373. {
  374. blt(&vchpInsert, pchp, cwCHP);
  375. }
  376. else
  377. {
  378. if (pfcb->fFormatted)
  379. { /* Copy necessary amt of formatting info over std CHP */
  380. typeFC fcMac;
  381. int cchT;
  382. int bfchp;
  383. blt(&vchpNormal, pchp, cwCHP);
  384. pfkp = (struct FKP *) PchGetPn(fn, fn == fnScratch ?
  385. PnFkpFromFcScr(&vfkpdCharIns, fc) :
  386. pfcb->pnChar + IFromFc(**pfcb->hgfcChp, fc),
  387. &cchT, false);
  388. if (vfDiskError)
  389. /* Serious disk error -- use default props */
  390. goto DefaultCHP;
  391. { /* In-line, fast substitute for BFromFc */
  392. register struct RUN *prun = (struct RUN *) pfkp->rgb;
  393. while (prun->fcLim <= fc)
  394. prun++;
  395. fcMac = prun->fcLim;
  396. bfchp = prun->b;
  397. }
  398. if (bfchp != bNil)
  399. {
  400. pfchp = (struct FCHP *) &pfkp->rgb[bfchp];
  401. bltbyte(pfchp->rgchChp, pchp, pfchp->cch);
  402. }
  403. cfcChp = fcMac - fc;
  404. }
  405. else
  406. {
  407. DefaultCHP:
  408. blt(&vchpNormal, pchp, cwCHP);
  409. /* in case default size is different "normal" (which is
  410. used for encoding our bin files */
  411. pchp->hps = hpsDefault;
  412. }
  413. }
  414. if (!bPRMNIL(prm))
  415. DoPrm(pchp, (struct PAP *) 0, prm);
  416. if (cfcChp > 32767)
  417. *pcfcChp = 32767;
  418. else
  419. *pcfcChp = cfcChp;
  420. MeltHp();
  421. } /* end of S e t C h p */
  422. typePN PnFkpFromFcScr(pfkpd, fc)
  423. struct FKPD *pfkpd;
  424. typeFC fc;
  425. { /* Return page number in scratch file with props for char at fc. */
  426. struct BTE *pbte = **pfkpd->hgbte;
  427. int ibte = pfkpd->ibteMac;
  428. /* A short table, linear search? */
  429. while (ibte--)
  430. if (pbte->fcLim > fc)
  431. return pbte->pn;
  432. else
  433. pbte++;
  434. return pfkpd->pn; /* On current page. */
  435. } /* end of P n F k p F r o m F c S c r */
  436.