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.

441 lines
14 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* trans4.c -- routines brought from trans2.c due to compiler stack overflow */
  5. #define NOWINMESSAGES
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINSTYLES
  8. #define NOCLIPBOARD
  9. #define NOGDICAPMASKS
  10. #define NOSYSMETRICS
  11. #define NOMENUS
  12. #define NOKEYSTATE
  13. #define NOGDI
  14. #define NORASTEROPS
  15. #define NOSYSCOMMANDS
  16. #define NOSHOWWINDOW
  17. #define NOCOLOR
  18. #define NOATOM
  19. #define NOBITMAP
  20. #define NOICON
  21. #define NOBRUSH
  22. #define NOCREATESTRUCT
  23. #define NOMB
  24. #define NOFONT
  25. #define NOMSG
  26. #define NOOPENFILE
  27. #define NOPEN
  28. #define NOPOINT
  29. #define NOREGION
  30. #define NOSCROLL
  31. #define NOSOUND
  32. #define NOWH
  33. #define NOWINOFFSETS
  34. #define NOWNDCLASS
  35. #define NOCOMM
  36. #include <windows.h>
  37. #include "mw.h"
  38. #include "doslib.h"
  39. #include "propdefs.h"
  40. #define NOUAC
  41. #include "cmddefs.h"
  42. #include "docdefs.h"
  43. #include "filedefs.h"
  44. #include "fkpdefs.h"
  45. #include "editdefs.h"
  46. #include "printdef.h"
  47. #define NOKCCODES
  48. #include "ch.h"
  49. #define NOSTRUNDO
  50. #define NOSTRERRORS
  51. #include "str.h"
  52. #include "debug.h"
  53. #include "fontdefs.h"
  54. CHAR *PchGetPn();
  55. CHAR *PchFromFc();
  56. typePN PnAllocT2();
  57. struct PGTB **HpgtbGet();
  58. extern int vfnWriting;
  59. extern struct BPS *mpibpbps;
  60. extern typeTS tsMruBps;
  61. extern int vibpWriting;
  62. extern CHAR (**vhrgbSave)[];
  63. extern struct DOD (**hpdocdod)[];
  64. extern int docCur;
  65. extern int docMac;
  66. extern int docScrap;
  67. extern int docUndo;
  68. extern struct FCB (**hpfnfcb)[];
  69. extern int fnMac;
  70. extern int wwMac;
  71. extern int vfBuffersDirty;
  72. extern int vfDiskFull;
  73. extern int vfDiskError;
  74. extern typeCP vcpFetch;
  75. extern CHAR *vpchFetch;
  76. extern int vccpFetch;
  77. extern typeFC fcMacPapIns;
  78. extern typeFC fcMacChpIns;
  79. extern typeCP vcpLimParaCache;
  80. extern struct FKPD vfkpdCharIns;
  81. extern struct FKPD vfkpdParaIns;
  82. extern struct PAP vpapPrevIns;
  83. extern struct PAP vpapAbs;
  84. extern struct PAP *vppapNormal;
  85. extern struct CHP vchpNormal;
  86. extern struct CHP vchpInsert;
  87. extern struct CHP vchpFetch;
  88. extern unsigned cwHeapFree;
  89. extern struct FPRM fprmCache;
  90. extern int ferror;
  91. extern CHAR szExtBackup[];
  92. extern CHAR (**hszTemp)[];
  93. #ifdef INTL /* International version */
  94. extern int vWordFmtMode; /* used during saves. If false, no conversion is
  95. done. True is convert to Word format,CVTFROMWORD
  96. is translate chars from Word character set at
  97. save */
  98. #endif /* International version */
  99. /*** WriteUnformatted - Write unformatted document to file
  100. *
  101. *
  102. *
  103. */
  104. WriteUnformatted(fn, doc)
  105. int fn;
  106. int doc;
  107. {
  108. extern typeCP vcpLimParaCache;
  109. extern typeCP cpMinCur, cpMacCur;
  110. typeCP cpMinCurT = cpMinCur;
  111. typeCP cpMacCurT = cpMacCur;
  112. typeCP cpNow;
  113. typeCP cpLimPara;
  114. typeCP cpMac = (**hpdocdod) [doc].cpMac;
  115. /* Expand range of interest to whole document (for CachePara) */
  116. cpMinCur = cp0;
  117. cpMacCur = cpMac;
  118. /* Loop on paras */
  119. cpNow = cp0;
  120. for ( cpNow = cp0; cpNow < cpMac; cpNow = cpLimPara )
  121. {
  122. LRestart:
  123. CachePara( doc, cpNow );
  124. cpLimPara = vcpLimParaCache;
  125. if (vpapAbs.fGraphics)
  126. continue;
  127. /* Now write out the para, a run at a time */
  128. while ((cpNow < cpLimPara && cpNow < cpMacCur)
  129. && !(vfDiskFull || vfDiskError))
  130. {
  131. extern typeCP CpMin();
  132. extern int vccpFetch;
  133. int ccpAccept;
  134. CHAR bufT[cbSector + 1];
  135. CHAR *pch;
  136. FetchCp( doc, cpNow, 0, fcmChars + fcmNoExpand );
  137. Assert (vccpFetch <= cbSector);
  138. #ifdef WINVER >= 0x300
  139. if (vccpFetch == 0)
  140. {
  141. /* In this case we've had an error with a "hole" in the
  142. the piece table due to hitting a mem-alloc error -- we
  143. won't ever advance cpNow! To get around this we bump
  144. cpNow to the cpMin of the next piece and continue by
  145. doing a CachePara on the next piece 3/14/90..pault */
  146. struct PCTB *ppctb = *(**hpdocdod)[doc].hpctb;
  147. int ipcd = IpcdFromCp(ppctb, cpNow);
  148. struct PCD *ppcd = &ppctb->rgpcd[ipcd + 1]; /* NEXT piece */
  149. cpNow = ppcd->cpMin;
  150. goto LRestart;
  151. }
  152. #endif
  153. ccpAccept = (int) CpMin( (typeCP)vccpFetch, (cpLimPara - cpNow));
  154. #ifdef INTL /* International version */
  155. if (vWordFmtMode != TRUE) /* no character set conversion */
  156. #endif /* International version */
  157. WriteRgch( fn, vpchFetch, ccpAccept );
  158. #ifdef INTL /* International version */
  159. else /* convert to OEM set */
  160. {
  161. /* convert ANSI chars to OEM for Word format file */
  162. /* load chars into bufT and translate to OEM
  163. chars, and write out */
  164. pch = (CHAR *) bltbyte(vpchFetch, bufT,
  165. (int)ccpAccept);
  166. *pch = '\0';
  167. AnsiToOem((LPSTR)bufT, (LPSTR)bufT);
  168. WriteRgch(fn, bufT, (int)ccpAccept);
  169. }
  170. #endif /* International version */
  171. cpNow += ccpAccept;
  172. }
  173. if ((vfDiskFull || vfDiskError))
  174. break;
  175. }
  176. /* Restore cpMinCur, cpMacCur */
  177. cpMinCur = cpMinCurT;
  178. cpMacCur = cpMacCurT;
  179. }
  180. /*** PurgeTemps - Delete all temporary files not referenced in any doc
  181. *
  182. */
  183. PurgeTemps()
  184. { /* Delete all temporary files not referenced in any doc */
  185. int fn;
  186. struct FCB *pfcb, *mpfnfcb;
  187. struct DOD *pdod;
  188. struct PCD *ppcd;
  189. int doc;
  190. Assert(fnScratch == 0);
  191. FreezeHp();
  192. mpfnfcb = &(**hpfnfcb)[0];
  193. #ifdef DFILE
  194. CommSz("PurgeTemps:\n\r");
  195. #endif
  196. /* Prime the doc/piece table loop */
  197. /* Find the first valid doc (there is guaranteed to be one) */
  198. /* Set up doc, pdod, ppcd */
  199. for (doc = 0, pdod = &(**hpdocdod)[0]; pdod->hpctb == 0; doc++, pdod++)
  200. continue;
  201. ppcd = &(**pdod->hpctb).rgpcd[0];
  202. /* Now go through the deletable files, looking for references */
  203. for (fn = fnScratch + 1, pfcb = &mpfnfcb[fnScratch + 1];
  204. fn < fnMac; fn++, pfcb++)
  205. { /* For each file (don't bother with scratch file) */
  206. /* Fn must be valid, deletable, and not previously referenced */
  207. /* if (pfcb->rfn != rfnFree && pfcb->fDelete && !pfcb->fReferenced &&
  208. fn != fnPrint) */
  209. if (pfcb->rfn != rfnFree && pfcb->fDelete && !pfcb->fReferenced)
  210. { /* For each deletable fn */
  211. int fnT;
  212. for (;;)
  213. { /* Until we determine there is or isn't a ref */
  214. if (doc >= docMac)
  215. goto OutOfDocs;
  216. while ((fnT = ppcd->fn) == fnNil)
  217. { /* End of pctb */
  218. #ifdef CASHMERE
  219. struct SETB **hsetb = pdod->hsetb;
  220. if (hsetb != 0)
  221. { /* Check section table. Doesn't need to be quite
  222. as smart as piece table checker; smaller. */
  223. int csed = (**hsetb).csed;
  224. struct SED *psed = &(**hsetb).rgsed[0];
  225. while (csed--)
  226. {
  227. fnT = psed->fn;
  228. if (fnT == fn) /* Referenced. */
  229. goto NextFn;
  230. if (fnT > fn) /* Future fn referenced */
  231. mpfnfcb[fnT].fReferenced = true;
  232. psed++;
  233. }
  234. }
  235. #endif
  236. while (++doc < docMac && (++pdod)->hpctb == 0)
  237. continue;
  238. if (doc >= docMac)
  239. {
  240. OutOfDocs: /* No references to this fn, delete it */
  241. MeltHp();
  242. #ifdef DFILE
  243. {
  244. char rgch[200];
  245. wsprintf(rgch," fn %d, %s \n\r", fn,(LPSTR)(**pfcb->hszFile));
  246. CommSz(rgch);
  247. }
  248. #endif
  249. FDeleteFn(fn); /* HEAP MOVEMENT */
  250. FreezeHp();
  251. /* NOTE: Once we get here, there is no */
  252. /* further use of pdod or ppcd; we zip */
  253. /* through the remaining fn's and just */
  254. /* test fcb fields. Therefore, pdod */
  255. /* and ppcd are not updated although */
  256. /* there was (maybe) heap movement above */
  257. mpfnfcb = &(**hpfnfcb)[0];
  258. pfcb = &mpfnfcb[fn];
  259. goto NextFn;
  260. }
  261. ppcd = &(**pdod->hpctb).rgpcd[0];
  262. }
  263. if (fnT == fn) /* A reference to this fn */
  264. goto NextFn;
  265. if (fnT > fn) /* Ref to a future fn */
  266. mpfnfcb[fnT].fReferenced = true;
  267. ++ppcd;
  268. }
  269. }
  270. else
  271. pfcb->fReferenced = false;
  272. NextFn: ;
  273. }
  274. MeltHp();
  275. }
  276. #if WINVER >= 0x300
  277. /* We only use one document at a time, thus in general we won't have
  278. doc's referencing pieces from multiple fns (unless they've been
  279. pasted and reference docscrap or something).
  280. In any case we want to free up these files esp. for network user
  281. convenience. The dilemma in particular is when someone's opened
  282. a file on the net and then does a File.New, File.SaveAs, or File.Open
  283. and is using another file -- we don't release the previous one so
  284. another user will get a sharing error even though it seems that file
  285. should be free!
  286. Modeled after PurgeTemps() above ..pault 10/23/89 */
  287. void FreeUnreferencedFns()
  288. {
  289. int fn;
  290. struct FCB *pfcb, *mpfnfcb;
  291. struct DOD *pdod;
  292. struct PCD *ppcd;
  293. int doc;
  294. Assert(fnScratch == 0);
  295. FreezeHp();
  296. mpfnfcb = &(**hpfnfcb)[0];
  297. /* Prime the doc/piece table loop */
  298. /* Find the first valid doc (there is guaranteed to be one) */
  299. /* Set up doc, pdod, ppcd */
  300. for (doc = 0, pdod = &(**hpdocdod)[0]; pdod->hpctb == 0; doc++, pdod++)
  301. continue;
  302. ppcd = &(**pdod->hpctb).rgpcd[0];
  303. #ifdef DFILE
  304. CommSz("FreeUnreferencedFns: \n\r");
  305. #endif
  306. for (fn = fnScratch + 1, pfcb = &mpfnfcb[fnScratch + 1]; fn < fnMac; fn++, pfcb++)
  307. { /* For each file (don't bother with scratch file) */
  308. #ifdef DFILE
  309. {
  310. char rgch[200];
  311. wsprintf(rgch," fn %d, %s \trfnFree %d fRefd %d fDelete %d ",
  312. fn,(LPSTR)(**pfcb->hszFile),pfcb->rfn==rfnFree,pfcb->fReferenced,pfcb->fDelete);
  313. CommSz(rgch);
  314. }
  315. #endif
  316. /* For each unreferenced fn, we ask: is this file the current
  317. document being edited? If so then we definitely don't want
  318. to free up the file. However PREVIOUS documents that were
  319. being edited can now "be free". Temp files are not freed
  320. here because we want them to be remembered so they are deleted
  321. at the end of the Write session 2/1/90 ..pault */
  322. if ((WCompSz(*(**hpdocdod)[ docCur ].hszFile,**pfcb->hszFile)==0)
  323. || pfcb->fDelete)
  324. goto LRefd;
  325. else if (pfcb->rfn != rfnFree && !pfcb->fReferenced)
  326. {
  327. int fnT;
  328. for (;;)
  329. { /* Until we determine there is or isn't a ref */
  330. if (doc >= docMac)
  331. {
  332. goto OutOfDocs;
  333. }
  334. while ((fnT = ppcd->fn) == fnNil)
  335. { /* End of pctb */
  336. while (++doc < docMac && (++pdod)->hpctb == 0)
  337. continue;
  338. if (doc >= docMac)
  339. {
  340. OutOfDocs: /* No references to this fn, delete it */
  341. MeltHp();
  342. #ifdef DFILE
  343. CommSz(" FREEING!");
  344. #endif
  345. FreeFn(fn); /* HEAP MOVEMENT */
  346. FreezeHp();
  347. /* NOTE: Once we get here, there is no */
  348. /* further use of pdod or ppcd; we zip */
  349. /* through the remaining fn's and just */
  350. /* test fcb fields. Therefore, pdod */
  351. /* and ppcd are not updated although */
  352. /* there was (maybe) heap movement above */
  353. mpfnfcb = &(**hpfnfcb)[0];
  354. pfcb = &mpfnfcb[fn];
  355. goto NextFn;
  356. }
  357. ppcd = &(**pdod->hpctb).rgpcd[0];
  358. }
  359. if (fnT == fn) /* A reference to this fn */
  360. {
  361. goto NextFn;
  362. }
  363. if (fnT > fn) /* Ref to a future fn */
  364. {
  365. mpfnfcb[fnT].fReferenced = true;
  366. }
  367. ++ppcd;
  368. }
  369. }
  370. else
  371. {
  372. LRefd:
  373. pfcb->fReferenced = false;
  374. }
  375. NextFn: ;
  376. #ifdef DFILE
  377. CommSz("\n\r");
  378. #endif
  379. }
  380. MeltHp();
  381. }
  382. #endif /* WIN30 */
  383.