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.

986 lines
31 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* initialization codes for internal memory, page buffers, etc. */
  5. #define NOKEYSTATE
  6. #define NOCLIPBOARD
  7. #define NOGDICAPMASKS
  8. #define NOCTLMGR
  9. #define NOVIRTUALKEYCODES
  10. #define NOWINMESSAGES
  11. #define NOSYSMETRICS
  12. #define NOSYSCOMMANDS
  13. #define NOCOLOR
  14. #define NOCREATESTRUCT
  15. #define NOCTLMGR
  16. #define NODRAWTEXT
  17. #define NOSHOWWINDOW
  18. //#define NOATOM
  19. #define NOMENUS
  20. #define NOICON
  21. #define NOKEYSTATE
  22. #define NOSHOWWINDOW
  23. #define NOBITMAP
  24. #define NOSOUND
  25. #define NOCOMM
  26. #define NOOPENFILE
  27. #define NORESOURCE
  28. #define NOMETAFILE
  29. #define NOPEN
  30. #define NOREGION
  31. #define NOSCROLL
  32. #define NOWH
  33. #define NOWINOFFSETS
  34. /* need gdi, hdc, memmgr */
  35. #include <windows.h>
  36. #include "mw.h"
  37. #define NOUAC
  38. #include "cmddefs.h"
  39. #include "wwdefs.h"
  40. #include "docdefs.h"
  41. #include "editdefs.h"
  42. #include "propdefs.h"
  43. #include "fmtdefs.h"
  44. #include "filedefs.h"
  45. #include "fkpdefs.h"
  46. #include "stcdefs.h"
  47. #ifdef CASHMERE
  48. #include "txb.h"
  49. #endif /* CASHMERE */
  50. #include "fontdefs.h"
  51. #include "code.h"
  52. #include "heapdefs.h"
  53. #include "heapdata.h"
  54. #include "str.h"
  55. #include "ch.h"
  56. #if defined(OLE)
  57. #include "obj.h"
  58. #endif
  59. #ifdef DEBUG
  60. #define STATIC
  61. #else
  62. #define STATIC static
  63. #endif
  64. /* E X T E R N A L S */
  65. extern int ypMaxWwInit;
  66. extern int dypWwInit;
  67. extern int *memory;
  68. extern int *pmemMax;
  69. extern CHAR *pmemStart;
  70. extern unsigned vcbMemTotal;
  71. extern HWND hParentWw;
  72. extern HDC vhDCPrinter;
  73. extern int rfnMac;
  74. extern CHAR (*rgbp)[cbSector];
  75. extern int fnMac;
  76. extern typeTS tsMruRfn;
  77. extern struct ERFN dnrfn[];
  78. extern CHAR *rgibpHash;
  79. extern struct BPS *mpibpbps;
  80. extern typeTS tsMruBps;
  81. extern struct CHP vchpNormal;
  82. extern struct PAP *vppapNormal;
  83. extern struct SEP vsepNormal;
  84. extern struct CHP (**vhgchpFormat)[];
  85. extern int ichpMacFormat;
  86. extern struct CHP vchpInsert;
  87. extern struct CHP vchpSel;
  88. extern struct FCB (**hpfnfcb)[];
  89. extern struct FKPD vfkpdCharIns;
  90. extern struct FKPD vfkpdParaIns;
  91. extern struct PAP vpapPrevIns;
  92. extern struct FLI vfli;
  93. extern int docMac;
  94. extern struct DOD (**hpdocdod)[];
  95. extern int docScrap;
  96. extern int docUndo;
  97. #ifdef CASHMERE /* No docBuffer in WRITE */
  98. extern int docBuffer;
  99. #endif
  100. extern int docCur;
  101. extern CHAR (**hszSearch)[];
  102. extern CHAR (**hszReplace)[];
  103. extern CHAR (**hszFlatSearch)[];
  104. extern CHAR stBuf[];
  105. extern int vrefSystem;
  106. extern CHAR (**vhrgbSave)[];
  107. extern int vdxaPaper;
  108. extern int vdyaPaper;
  109. extern struct SEL selCur;
  110. extern BOOL vfPrinterValid;
  111. extern int dxaPrPage;
  112. extern int dyaPrPage;
  113. extern int dxpPrPage;
  114. extern int dypPrPage;
  115. extern int dxaPrOffset;
  116. extern int dyaPrOffset;
  117. extern HCURSOR vhcArrow;
  118. #ifdef UNUSED
  119. extern int vfCanPrint;
  120. #endif
  121. //Win3.1J
  122. #if defined(JAPAN) & defined(DBCS_IME) /* Doc for Insert IR_STRING from IME */
  123. extern int docIRString;
  124. #endif
  125. /* G L O B A L S -- used only in here */
  126. int rgwPapNormal[cwPAPBase + cwTBD] = {0};
  127. #ifdef STATICPAGES
  128. #ifdef MACHA
  129. #define ibpMaxStatic 79
  130. #define iibpHashMaxStatic 163
  131. #else /* not MACHA */
  132. #define ibpMaxStatic 7
  133. #define iibpHashMaxStatic 17
  134. #endif /* MACHA */
  135. CHAR rgbpStatic[ibpMaxStatic][cbSector];
  136. #endif /* STATICPAGES */
  137. extern typePN PnAlloc();
  138. STATIC int NEAR FInitDocs( void );
  139. STATIC int NEAR FInitProps( void );
  140. STATIC int NEAR FInitFiles( void );
  141. WORD wWinVer,fPrintOnly=FALSE;
  142. int FInitMemory()
  143. {
  144. extern HANDLE vhReservedSpace;
  145. int i;
  146. #ifdef UNUSED
  147. /* Initially assume that it is not possible to print */
  148. /* Formerly InitPrint was called here */
  149. vfCanPrint = false;
  150. #endif
  151. /** This is a glitch so that the fixed array for storing relocation
  152. information will be created immediately */
  153. wWinVer = (WORD)(GetVersion() & 0x0000FFFFL);
  154. if (((wWinVer & 0xFF) >= 3) && ((wWinVer & 0xFF00) >= 0x0A00))
  155. /* Windows Version >= 3.10 */
  156. {
  157. FARPROC LHandleDelta = GetProcAddress(GetModuleHandle((LPSTR)"KERNEL"),(LPSTR)0x136L);
  158. i = LHandleDelta(0);
  159. LHandleDelta(i*5); /* make a big finger table */
  160. vhReservedSpace = LocalAlloc(LHND, cbReserve);
  161. LocalFree(vhReservedSpace);
  162. LHandleDelta(i); /* resume to a smaller finger table if needed more */
  163. }
  164. else
  165. /* Windows Version < 3.10 */
  166. {
  167. /**
  168. This is heaping kludge upon kludge in the effort to be backwards
  169. compatible with past kludges. This is the old macro which with
  170. Win31 has become a function call. (3.11.91) D. Kent
  171. **/
  172. #define LocalHandleDelta(d) ((d) ? (*(pLocalHeap+9) = (d)) : *(pLocalHeap+9))
  173. i = LocalHandleDelta(0);
  174. LocalHandleDelta(i*5); /* make a big finger table */
  175. vhReservedSpace = LocalAlloc(LHND, cbReserve);
  176. LocalFree(vhReservedSpace);
  177. LocalHandleDelta(i); /* resume to a smaller finger table if needed more */
  178. }
  179. #ifdef OURHEAP
  180. /* reserve 1K for windows's memory manager for creating dialog boxes */
  181. vhReservedSpace = LocalAlloc(LPTR, cbReserve);
  182. CreateHeapI(); /* create heap first */
  183. if (!FCreateRgbp()) /* rgbp are expandable */
  184. return FALSE;
  185. /* now free the reserved space after our memory is set up. */
  186. /* hopefully we will get all the fixed objects created by
  187. dialog manager be placed above our memory chunk, so we can still
  188. expand our heap while a dialog box is up. */
  189. LocalFree(vhReservedSpace);
  190. #else
  191. if (!FCreateRgbp())
  192. return FALSE;
  193. vhReservedSpace = LocalAlloc(LHND, cbReserve); /* this is to make
  194. discardable when we are out of memory and try to bring up the
  195. save dialog box */
  196. #endif
  197. if (vhReservedSpace == NULL)
  198. return FALSE;
  199. /* formerly CreateHpfnfcb */
  200. hpfnfcb = (struct FCB (**)[])HAllocate(cwFCB * fnMax);
  201. if (FNoHeap(hpfnfcb))
  202. return FALSE;
  203. fnMac = fnMax;
  204. for (i = 0; i < fnMac; i++)
  205. (**hpfnfcb)[i].rfn = rfnFree;
  206. /* end of CreateHpfnfcb */
  207. if (!FSetScreenConstants())
  208. return FALSE;
  209. if ( !FInitDocs() ||
  210. #ifdef CASHMERE /* No glossary in MEMO */
  211. !FInitBufs() ||
  212. #endif /* CASHMERE */
  213. !FInitProps() ||
  214. !FInitFiles() )
  215. return FALSE;
  216. /* allocate emergency space for save operations */
  217. if (FNoHeap(vhrgbSave = (CHAR (**)[])HAllocate(cwSaveAlloc)))
  218. return FALSE;
  219. return TRUE;
  220. }
  221. /* end of F I n i t M e m o r y */
  222. int FInitArgs(sz)
  223. CHAR *sz;
  224. { /* Set extern int docCur to be a new doc, containing
  225. the file (if any) specified on the command line (sz).
  226. Initialize a wwd (window descriptor) structure for the document
  227. and set an appropriate title into the title bar.
  228. Set selCur to be an insertion point before the first char of the doc,
  229. and set vchpSel to be the char properties of the insertion point.
  230. Return TRUE if all is well, FALSE if something went wrong.
  231. A return of FALSE means that initialization should not continue.
  232. */
  233. extern typeCP cpMinDocument;
  234. extern struct WWD rgwwd[];
  235. extern int vfDiskError;
  236. extern int vfSysFull;
  237. extern int ferror;
  238. extern BOOL vfWarnMargins;
  239. int fn, doc;
  240. RECT rcCont;
  241. CHAR szT [ cchMaxFile ];
  242. register CHAR *pch;
  243. CHAR ch;
  244. int fEmptyLine = TRUE;
  245. CHAR (**hsz) [];
  246. int iT, cbsz;
  247. #ifdef INTL /* International version */
  248. int fWordDoc = FALSE;
  249. #endif /* International version */
  250. /* Decide whether we have anything but white space on the command line */
  251. for ( pch = sz; (ch = *pch) != '\0'; pch++ )
  252. if ((ch != ' ') && (ch != '\011'))
  253. {
  254. fEmptyLine = FALSE;
  255. break;
  256. }
  257. if (fEmptyLine)
  258. /* No filename; start with (Untitled) */
  259. goto Untitled;
  260. cbsz = CchSz (sz ) - 1;
  261. /* remove trailing spaces from sz */
  262. for ( pch = sz + cbsz - 1; pch >= sz; pch-- )
  263. if (*pch != ' ')
  264. break;
  265. else
  266. {
  267. *pch = '\0'; /* replace with null */
  268. cbsz--;
  269. }
  270. /* check for /p option (6.26.91) v-dougk */
  271. if ((sz[0] == '/') && (sz[1] == 'p'))
  272. {
  273. sz += 2;
  274. cbsz -= 2;
  275. fPrintOnly = TRUE;
  276. for (; *sz; sz++, cbsz-- ) // get to filename
  277. if ((*sz != ' ') && (*sz != '\011'))
  278. break;
  279. if (!*sz) /* No filename, abort */
  280. return FALSE;
  281. }
  282. /* convert to OEM */
  283. AnsiToOem(sz, sz);
  284. if (!FValidFile( sz, cbsz, &iT ) ||
  285. !FNormSzFile( szT, sz, dtyNormal ))
  286. { /* Bad filename -- it could not be normalized */
  287. extern int vfInitializing;
  288. char szMsg[cchMaxSz];
  289. char *pch;
  290. extern HWND vhWndMsgBoxParent;
  291. extern HANDLE hParentWw;
  292. vfInitializing = FALSE; /* Do not suppress reporting this err */
  293. MergeStrings (IDPMTBadFileName, sz, szMsg);
  294. /* if we're being called from a message box, then use it
  295. as the parent window, otherwise use main write window */
  296. IdPromptBoxSz(vhWndMsgBoxParent ? vhWndMsgBoxParent : hParentWw,
  297. szMsg, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
  298. ferror = TRUE; /* need to flag */
  299. vfInitializing = TRUE;
  300. goto Untitled;
  301. }
  302. if ((fn = FnOpenSz( szT, dtyNormal,
  303. index( szT, '/' ) == NULL &&
  304. index( szT,':') == NULL && index( szT, '\\') == NULL )) != fnNil)
  305. /* Opened file OK -- prefetch file contents into rgbp */
  306. {
  307. #ifdef INTL /* Kanji / International version */
  308. /* **************************************
  309. * added check for international version to
  310. do Word format conversion. If Word format,
  311. bring up another dialog box.
  312. * ************************************** */
  313. /* TestWordCvt return values:
  314. -1 means dialog box failed (error already sent)
  315. or cancel without conversion.
  316. FALSE means not a word document.
  317. TRUE means convert this word document.
  318. vfBackupSave is changed to reflect whether
  319. save is done with backup.
  320. */
  321. #ifdef KKBUGFIX // added by Hiraisi (BUG#2816 WIN31) in Japan
  322. if ((fWordDoc = TestWordCvt (fn, (HWND)NULL)) == -1 ||
  323. fWordDoc == -2)
  324. #else
  325. if ((fWordDoc = TestWordCvt (fn, (HWND)NULL)) == -1)
  326. #endif
  327. goto Untitled;
  328. /* if fWordDoc is true, will convert later */
  329. #endif /* International version */
  330. StartLongOp();
  331. ReadFilePages( fn );
  332. EndLongOp(vhcArrow);
  333. }
  334. else /* Could not open file */
  335. {
  336. if (fPrintOnly)
  337. return FALSE;
  338. else
  339. { /* use (Untitled) */
  340. Untitled:
  341. fn = fnNil;
  342. sz [0] = '\0';
  343. szT [0] = '\0';
  344. }
  345. }
  346. if (vfDiskError || vfSysFull)
  347. /* Serious disk error OR disk holding scratch file is full --
  348. bail out */
  349. return FALSE;
  350. if (fn != fnNil)
  351. { /* Opened file OK -- must account for the case when OpenFile
  352. returned a filename that differed from the one given it */
  353. bltsz( &(**(**hpfnfcb) [fn].hszFile) [0], szT );
  354. }
  355. if (FNoHeap(hsz=HszCreate( (PCH) szT )) ||
  356. (doc=DocCreate( fn, hsz, dtyNormal )) == docNil)
  357. { /* Could not create a doc */
  358. return FALSE;
  359. }
  360. if (WwNew(doc, dypWwInit, ypMaxWwInit) == wwNil)
  361. return FALSE;
  362. NewCurWw(0, true);
  363. if (fn != fnNil)
  364. {
  365. vfWarnMargins = TRUE;
  366. SetPageSize();
  367. vfWarnMargins = FALSE;
  368. }
  369. wwdCurrentDoc.cpFirst = selCur.cpLim = selCur.cpFirst = cpMinDocument;
  370. selCur.fForward = true;
  371. GetInsPtProps(selCur.cpFirst);
  372. #ifdef OURHEAP
  373. {
  374. extern int cwInitStorage;
  375. /* save this amount of heap as "100% free" */
  376. /* formerly CalcTot(true) */
  377. cwInitStorage = cwHeapMac - cwHeapFree;
  378. cbTot = (cwHeapMac - cwInitStorage) * sizeof(int);
  379. cbTotQuotient = (cbTot>>1)/100;
  380. }
  381. #endif
  382. #ifdef STYLES
  383. /* Set up scrap document to have a valid style sheet on start up. */
  384. (**hpdocdod)[docScrap].docSsht = (**hpdocdod)[docCur].docSsht;
  385. #endif /* STYLES */
  386. #ifdef INTL /* International version */
  387. /* if a word document to be converted, save
  388. it doing conversion. */
  389. if (fWordDoc == TRUE)
  390. {
  391. /* save file in write format. */
  392. ConvertFromWord();
  393. }
  394. #endif /* International version */
  395. SetTitle(szT);
  396. #if defined(OLE)
  397. ObjOpenedDoc(doc);
  398. #endif
  399. return TRUE;
  400. }
  401. /* end of F I n i t A r g s */
  402. #ifdef OURHEAP
  403. CreateHeapI()
  404. {
  405. FGR *pfgr, *pfgrLim;
  406. #ifdef WINBUG
  407. unsigned cb = (unsigned)GlobalCompact((DWORD)0);
  408. #endif
  409. ibpMax = ibpMaxSmall;
  410. if (cb > 0x4fff /* about 20K */)
  411. {
  412. HANDLE hTemp;
  413. /* we can start with a bigger page buffer */
  414. vcbMemTotal = (unsigned)LocalCompact((WORD)0);
  415. pmemStart = (CHAR *)LocalAlloc(LPTR, vcbMemTotal);
  416. /* get all we have and force a reallocation */
  417. hTemp = LocalReAlloc((HANDLE)pmemStart, 0x4fff, LPTR);
  418. if (hTemp != NULL)
  419. {
  420. LocalFree(hTemp);
  421. ibpMax = ibpMaxBig;
  422. }
  423. else
  424. {
  425. /* somehow we failed and went back to the small system */
  426. LocalFree((HANDLE)pmemStart);
  427. }
  428. }
  429. vcbMemTotal = (unsigned)LocalCompact((WORD)0);
  430. /* memory always bumped to point to the next available slot
  431. for allocation */
  432. /* take all the space as one chunk and do our own memory management */
  433. pmemStart = (CHAR *)LocalAlloc(LPTR, vcbMemTotal);
  434. memory = (int *)pmemStart;
  435. vcbMemTotal = (unsigned)LocalSize((HANDLE)pmemStart); /* in case
  436. we got more than we asked */
  437. pmemMax = (int *)((CHAR *)memory + vcbMemTotal);
  438. /* take half of heap space for page buffers
  439. ibpMax = (vcbMemTotal>>1)/cbSector;*/
  440. iibpHashMax = ibpMax * 2 + 1;
  441. /* Set finger table to low end of heap */
  442. rgfgr = (PFGR)memory;
  443. memory += ifgrInit;
  444. memory = (int *)(((unsigned) memory + 1) & ~1); /* word boundary */
  445. /* Here is our heap */
  446. pHeapFirst = (int *)memory;
  447. cwHeapMac = /* cwtotal */
  448. (((unsigned)pmemMax - (unsigned)pHeapFirst +
  449. sizeof(int) - 1) / sizeof(int)) -
  450. /* cw in rgibpHash */
  451. ((iibpHashMax * sizeof(CHAR) +
  452. sizeof(int) - 1) / sizeof(int)) -
  453. /* cw in mpibpbps */
  454. ((ibpMax * sizeof(struct BPS) +
  455. sizeof(int) - 1) / sizeof(int)) -
  456. /* cw in rgbp */
  457. ((ibpMax * cbSector * sizeof(CHAR) +
  458. sizeof(int) - 1) / sizeof(int));
  459. memory += cwHeapMac;
  460. #ifdef DEBUG
  461. cwHeapMac -= 16; /* Need spare words for shaking */
  462. /* This space is above the finger table */
  463. #endif
  464. cwHeapFree = cwHeapMac;
  465. phhMac = (HH *)(pHeapFirst + cwHeapMac);
  466. /* if DEBUG, then phhMac will point at the shake word;
  467. otherwise it will point to 1 cell after the heap */
  468. phhFree = (HH *) pHeapFirst;
  469. phhFree->cw = -cwHeapMac; /* whobj.heap is free */
  470. phhFree->phhNext = phhFree;
  471. phhFree->phhPrev = phhFree;
  472. pfgrMac = &rgfgr[ifgrInit];
  473. pfgrLim = pfgrMac - 1;
  474. /* thread the free fingers */
  475. for (pfgr = rgfgr; pfgr < pfgrLim; pfgr++)
  476. *pfgr = (FGR)(pfgr + 1);
  477. *pfgrLim = NULL; /* last free finger */
  478. pfgrFree = rgfgr;
  479. }
  480. /* end of C r e a t e H e a p I */
  481. #endif /* OURHEAP */
  482. STATIC int NEAR FInitDocs()
  483. { /* Initialize hpdocdod */
  484. struct DOD *pdod, *pdodLim;
  485. hpdocdod = (struct DOD (**)[])HAllocate(cwDOD * (docMac = cdocInit));
  486. if (FNoHeap(hpdocdod))
  487. return FALSE;
  488. pdod = &(**hpdocdod)[0];
  489. pdodLim = pdod + cdocInit;
  490. while (pdod < pdodLim)
  491. pdod++->hpctb = 0; /* Mark all doc entries as free */
  492. docScrap = DocCreate(fnNil, HszCreate((PCH)""), dtyBuffer); /* HM */
  493. //Win3.1J
  494. #if defined(JAPAN) & defined(DBCS_IME) /* Doc for Insert IR_STRING from IME */
  495. docIRString = DocCreate(fnNil, HszCreate((PCH)""), dtyBuffer); /* HM */
  496. #endif
  497. docUndo = DocCreate(fnNil, HszCreate((PCH)""), dtyBuffer); /* HM */
  498. #ifdef CASHMERE
  499. docBuffer = DocCreate(fnNil, HszCreate((PCH)""), dtyBuffer); /* HM */
  500. #endif
  501. docCur = docNil;
  502. NoUndo();
  503. hszSearch = HszCreate((PCH)""); /* No initial search string */
  504. hszReplace = HszCreate((PCH)""); /* No initial replace string */
  505. hszFlatSearch = HszCreate((PCH)""); /* No initial flattenned search string */
  506. if (docScrap == docNil || docUndo == docNil ||
  507. #if defined(JAPAN) & defined(DBCS_IME) /* Doc for Insert IR_STRING from IME */
  508. docIRString == docNil ||
  509. #endif
  510. #ifdef CASHMERE
  511. docBuffer == docNil ||
  512. #endif
  513. FNoHeap(hszFlatSearch))
  514. return FALSE;
  515. return TRUE;
  516. }
  517. /* end of F I n i t D o c s */
  518. #ifdef CASHMERE /* No glossary in MEMO */
  519. FInitBufs()
  520. {
  521. /* Initializes structures and data used in named buffer management.
  522. Allocates space for hgtxb, initializes itxbMac */
  523. struct TXB *ptxb;
  524. extern struct TXB (**hgtxb)[];
  525. extern short itxbMac;
  526. if (FNoHeap(hszGlosFile = HszCreate((PCH)"")))
  527. return FALSE;
  528. if (FNoHeap(hgtxb = (struct TXB (**)[])HAllocate(cwTxb)))
  529. return FALSE;
  530. ptxb = &(**hgtxb)[0];
  531. ptxb->hszName = hszNil;
  532. itxbMac = 0;
  533. return TRUE;
  534. }
  535. /* end of F I n i t B u f s */
  536. #endif /* CASHMERE */
  537. STATIC int NEAR FInitProps()
  538. { /* Initialize your basic properties */
  539. #ifndef FIXED_PAGE
  540. unsigned dxaRightMin;
  541. unsigned dyaBottomMin;
  542. #endif /* not FIXED_PAGE */
  543. vchpNormal.hps = hpsNormal; /* NOTE - this is the size we use for
  544. incremental encoding, the "default"
  545. size may differ */
  546. vchpNormal.ftc = 0; /* will be whatever the standard modern font is */
  547. vchpNormal.ftcXtra = 0;
  548. vchpNormal.fStyled = true;
  549. /* vchpNormal.stc = stcNormal; */
  550. vppapNormal = (struct PAP *)rgwPapNormal;
  551. /* vppapNormal->fStyled = false; */
  552. /* vppapNormal->stc = 0; */
  553. vppapNormal->stcNormChp = stcParaMin;
  554. /* vppapNormal->dxaRight = 0; */
  555. /* vppapNormal->dxaLeft = 0; */
  556. /* vppapNormal->dxaLeft1 = 0; */
  557. /* vppapNormal->jc = jcLeft; */
  558. /* vppapNormal->dyaBefore = 0; */
  559. /* vppapNormal->dtaAfter = 0; */
  560. vppapNormal->fStyled = true;
  561. vppapNormal->stc = stcParaMin;
  562. vppapNormal->dyaLine = czaLine;
  563. Assert(cwPAP == cwSEP);
  564. /* vsepNormal.fStyled = false; */
  565. /* vsepNormal.stc = 0; */
  566. vsepNormal.bkc = bkcPage;
  567. /* vsepNormal.nfcPgn = nfcArabic; */
  568. #ifdef FIXED_PAGE
  569. /* The "normal" page size is fixed at 8-1/2 by 11 inches. */
  570. vsepNormal.xaMac = cxaInch * 8 + cxaInch / 2;
  571. vsepNormal.xaLeft = cxaInch * 1 + cxaInch / 4;
  572. vsepNormal.dxaText = cxaInch * 6;
  573. vsepNormal.yaMac = cyaInch * 11;
  574. vsepNormal.yaTop = cyaInch * 1;
  575. vsepNormal.dyaText = cyaInch * 9;
  576. vsepNormal.yaRH1 = cyaInch * 3 / 4;
  577. vsepNormal.yaRH2 = cyaInch * 10 + cyaInch / 4;
  578. #else /* not FIXED_PAGE */
  579. /* The page size is determined by inquiring it from the printer. Then,
  580. other measurements can be derived from it. */
  581. Assert(vhDCPrinter);
  582. if (vfPrinterValid && vhDCPrinter != NULL)
  583. {
  584. POINT pt;
  585. /* Get the page size of the printer. */
  586. if (Escape(vhDCPrinter, GETPHYSPAGESIZE, 0, (LPSTR)NULL,
  587. (LPSTR)&pt))
  588. {
  589. vsepNormal.xaMac = MultDiv(pt.x, dxaPrPage, dxpPrPage);
  590. vsepNormal.yaMac = MultDiv(pt.y, dyaPrPage, dypPrPage);
  591. }
  592. else
  593. {
  594. /* The printer won't tell us it page size; we'll have to settle
  595. for the printable area. */
  596. vsepNormal.xaMac = ZaFromMm(GetDeviceCaps(vhDCPrinter,
  597. HORZSIZE));
  598. vsepNormal.yaMac = ZaFromMm(GetDeviceCaps(vhDCPrinter,
  599. VERTSIZE));
  600. }
  601. /* The page size cannot be smaller than the printable area. */
  602. if (vsepNormal.xaMac < dxaPrPage)
  603. {
  604. vsepNormal.xaMac = dxaPrPage;
  605. }
  606. if (vsepNormal.yaMac < dyaPrPage)
  607. {
  608. vsepNormal.yaMac = dyaPrPage;
  609. }
  610. /* Determine the offset of the printable area on the page. */
  611. if (Escape(vhDCPrinter, GETPRINTINGOFFSET, 0, (LPSTR)NULL,
  612. (LPSTR)&pt))
  613. {
  614. dxaPrOffset = MultDiv(pt.x, dxaPrPage, dxpPrPage);
  615. dyaPrOffset = MultDiv(pt.y, dyaPrPage, dypPrPage);
  616. }
  617. else
  618. {
  619. /* The printer won't tell us what the offset is; assume the
  620. printable area is centered on the page. */
  621. dxaPrOffset = (vsepNormal.xaMac - dxaPrPage) >> 1;
  622. dyaPrOffset = (vsepNormal.yaMac - dyaPrPage) >> 1;
  623. }
  624. /* Determine the minimum margins. */
  625. dxaRightMin = imax(0, vsepNormal.xaMac - dxaPrOffset - dxaPrPage);
  626. dyaBottomMin = imax(0, vsepNormal.yaMac - dyaPrOffset - dyaPrPage);
  627. }
  628. else
  629. {
  630. /* We have no printer; so, the page is 8-1/2" by 11" for now. */
  631. vsepNormal.xaMac = 8 * czaInch + czaInch / 2;
  632. vsepNormal.yaMac = 11 * czaInch;
  633. /* Assume the entire page can be printed. */
  634. dxaPrOffset = dyaPrOffset = dxaRightMin = dyaBottomMin = 0;
  635. }
  636. /* Ensure that the "normal" margins are larger than the minimum. */
  637. vsepNormal.xaLeft = umax(cxaInch * 1 + cxaInch / 4, dxaPrOffset);
  638. vsepNormal.dxaText = vsepNormal.xaMac - vsepNormal.xaLeft - umax(cxaInch
  639. * 1 + cxaInch / 4, dxaRightMin);
  640. vsepNormal.yaTop = umax(cyaInch * 1, dyaPrOffset);
  641. vsepNormal.dyaText = vsepNormal.yaMac - vsepNormal.yaTop - umax(cyaInch
  642. * 1, dyaBottomMin);
  643. /* Position the running-heads and the page numbers. */
  644. vsepNormal.yaRH1 = umax(cyaInch * 3 / 4, dyaPrOffset);
  645. vsepNormal.yaRH2 = vsepNormal.yaMac - umax(cyaInch * 3 / 4,
  646. dyaBottomMin);
  647. vsepNormal.xaPgn = vsepNormal.xaMac - umax(cxaInch * 1 + cxaInch / 4,
  648. dxaRightMin);
  649. vsepNormal.yaPgn = umax(cyaInch * 3 / 4, dyaPrOffset);
  650. #endif /* not FIXED_PAGE */
  651. vsepNormal.pgnStart = pgnNil;
  652. /* vsepNormal.fAutoPgn = false; */
  653. /* vsepNormal.fEndFtns = false; */
  654. vsepNormal.cColumns = 1;
  655. vsepNormal.dxaColumns = cxaInch / 2;
  656. /* vsepNormal.dxaGutter = 0; */
  657. vdxaPaper = vsepNormal.xaMac;
  658. vdyaPaper = vsepNormal.yaMac;
  659. vfli.doc = docNil; /* Invalidate vfli */
  660. ichpMacFormat = ichpMacInitFormat;
  661. vhgchpFormat = (struct CHP (**)[])HAllocate(ichpMacInitFormat * cwCHP);
  662. if (FNoHeap(vhgchpFormat))
  663. {
  664. return FALSE;
  665. }
  666. return TRUE;
  667. }
  668. /* end of F I n i t P r o p s */
  669. STATIC int NEAR FInitFiles()
  670. {
  671. extern WORD vwDosVersion;
  672. int fn;
  673. int cchT;
  674. struct FKP *pfkp;
  675. struct FCB *pfcb;
  676. int osfnExtra;
  677. CHAR sz [cchMaxFile];
  678. rfnMac = rfnMacEdit;
  679. /* Set DOS version we're running under */
  680. vwDosVersion = WDosVersion();
  681. InitBps();
  682. #ifdef CKSM
  683. #ifdef DEBUG
  684. {
  685. extern int ibpMax, ibpCksmMax;
  686. extern unsigned (**hpibpcksm) [];
  687. hpibpcksm = (unsigned (**) [])HAllocate( ibpMax );
  688. if (FNoHeap( hpibpcksm ))
  689. return FALSE;
  690. ibpCksmMax = ibpMax;
  691. }
  692. #endif
  693. #endif
  694. /* sz <-- name of new, unique file which will be fnScratch */
  695. sz[ 0 ] = '\0'; /* Create it in the root on a temp drive */
  696. if ((fn=FnCreateSz( sz, cpNil, dtyNetwork )) == fnNil )
  697. /* Couldn't create scratch file: fail */
  698. return FALSE;
  699. Assert(fn == fnScratch); /* fnScratch hardwired to 0 for efficiency */
  700. FreezeHp();
  701. pfcb = &(**hpfnfcb)[fnScratch];
  702. pfcb->fFormatted = true; /* Sort of a formatted file */
  703. pfcb->fDelete = true; /* Kill this file when we quit */
  704. MeltHp();
  705. vfkpdParaIns.brun = vfkpdCharIns.brun = 0;
  706. vfkpdParaIns.bchFprop = vfkpdCharIns.bchFprop = cbFkp;
  707. vfkpdParaIns.pn = PnAlloc(fnScratch);
  708. ((struct FKP *) PchGetPn(fnScratch, vfkpdParaIns.pn, &cchT, true))->fcFirst =
  709. fc0;
  710. vfkpdCharIns.pn = PnAlloc(fnScratch);
  711. ((struct FKP *) PchGetPn(fnScratch, vfkpdCharIns.pn, &cchT, true))->fcFirst =
  712. fc0;
  713. /* The following can really be allocated 0 words, but why push our luck? */
  714. vfkpdParaIns.hgbte = (struct BTE (**)[]) HAllocate(cwBTE);
  715. vfkpdCharIns.hgbte = (struct BTE (**)[]) HAllocate(cwBTE);
  716. vfkpdParaIns.ibteMac = vfkpdCharIns.ibteMac = 0;
  717. if (FNoHeap(vfkpdParaIns.hgbte) || FNoHeap(vfkpdCharIns.hgbte))
  718. return FALSE;
  719. blt(&vchpNormal, &vchpInsert, cwCHP);
  720. blt(&vchpNormal, &vchpSel, cwCHP);
  721. blt(vppapNormal, &vpapPrevIns, cwPAPBase + cwTBD);
  722. return TRUE;
  723. }
  724. /* end of F I n i t F i l e s */
  725. InitBps()
  726. {
  727. /* called from initfiles to set up the tables */
  728. int ibp, iibp;
  729. int rfn;
  730. int fn;
  731. /* In order impliment a LRU page swap strategy, a time stamp(TS) scheme is */
  732. /* used. Associated with each buffer slot is a time stamp. The least */
  733. /* recently used slot is found by locating the slot with the smallest time */
  734. /* stamp. Every time a new page is brought into the buffer, it TS is set */
  735. /* equal to the value of a incrimented global TS counter (tsMru...). */
  736. /* Initially, the time stamps are set so that they increase as we move */
  737. /* toward the end of the table. Thus, even though the entire buffer pool */
  738. /* is initially empty, slots at the beginning of the table will be */
  739. /* allocated first. */
  740. {
  741. register struct ERFN *perfn = &dnrfn [0];
  742. for (rfn = 0; rfn < rfnMac; rfn++, perfn++)
  743. {
  744. perfn->fn = fnNil;
  745. perfn->ts = rfn;
  746. }
  747. tsMruRfn = rfnMac /* + ? */;
  748. }
  749. for (iibp = 0; iibp < iibpHashMax; iibp++)
  750. rgibpHash[iibp] = ibpNil;
  751. {
  752. register struct BPS *pbps=&mpibpbps [0];
  753. for (ibp = 0; ibp < ibpMax; ++ibp, pbps++)
  754. {
  755. pbps->fn = fnNil;
  756. pbps->fDirty = false;
  757. pbps->ts = ibp;
  758. pbps->ibpHashNext = ibpNil;
  759. }
  760. tsMruBps = ibpMax + cbpMustKeep;
  761. }
  762. /* In IbpEnsureValid (file.c) we may not want to use the least */
  763. /* recently used slot for certain reasons. But, we do want to */
  764. /* be assured that we do not clobber the 'cbpMustKeep' most */
  765. /* recently used slots. Our check consists of making sure */
  766. /* (tsMruBps - ts_in_question) < cbpMustKeep. By the above */
  767. /* statement, we are assured that non of the empty slots satisfy */
  768. /* this condition. */
  769. /* Allocate initial checksum array */
  770. }
  771. /* end of I n i t B p s */
  772. #ifdef OURHEAP
  773. FCreateRgbp()
  774. {
  775. rgbp = (CHAR (*)[cbSector])memory;
  776. memory = (int *)((unsigned)memory + (unsigned)(ibpMax)
  777. * cbSector);
  778. memory = (int *)(((unsigned) memory + 1) & ~1); /* word boundary */
  779. rgibpHash = (CHAR *)memory;
  780. memory = (int *)((unsigned)memory +
  781. (unsigned)(iibpHashMax * sizeof(CHAR)));
  782. memory = (int *)(((unsigned) memory + 1) & ~1); /* word boundary */
  783. mpibpbps = (struct BPS *)memory;
  784. memory = (int *)((unsigned)memory +
  785. (unsigned)(ibpMax * sizeof(struct BPS)));
  786. memory = (int *)(((unsigned) memory + 1) & ~1);
  787. return (memory <= pmemMax);
  788. }
  789. /* end of F C r e a t e R g b p */
  790. #else /* use windows' memory manager */
  791. FCreateRgbp()
  792. {
  793. extern int vfLargeSys;
  794. long lcbFree;
  795. unsigned cb;
  796. ibpMax = ibpMaxSmall;
  797. lcbFree = GlobalCompact((DWORD)0);
  798. if (lcbFree > 0x00030D40 /* 200K */)
  799. {
  800. /* we can start with a bigger page buffer */
  801. ibpMax = ibpMaxBig;
  802. vfLargeSys = TRUE;
  803. }
  804. iibpHashMax = ibpMax * 2 + 1;
  805. cb = ((ibpMax * cbSector * sizeof(CHAR) + 1) & ~1) /* rgbp */
  806. + ((iibpHashMax * sizeof(CHAR) + 1) & ~1) /* rgibpHash */
  807. + ((ibpMax * sizeof(struct BPS) + 1) & ~1); /* mpibpbps */
  808. memory = (int *)LocalAlloc(LPTR, cb);
  809. if (memory == NULL)
  810. {
  811. ibpMax = ibpMaxSmall;
  812. iibpHashMax = ibpMax * 2 + 1;
  813. cb = ((ibpMax * cbSector * sizeof(CHAR) + 1) & ~1) /* rgbp */
  814. + ((iibpHashMax * sizeof(CHAR) + 1) & ~1) /* rgibpHash */
  815. + ((ibpMax * sizeof(struct BPS) + 1) & ~1); /* mpibpbps */
  816. memory = (int *)LocalAlloc(LPTR, cb);
  817. }
  818. if (memory == NULL)
  819. return FALSE;
  820. rgbp = (CHAR (*)[cbSector])memory;
  821. memory = (int *)((unsigned)memory + (unsigned)(ibpMax)
  822. * cbSector);
  823. memory = (int *)(((unsigned) memory + 1) & ~1); /* word boundary */
  824. rgibpHash = (CHAR *)memory;
  825. memory = (int *)((unsigned)memory +
  826. (unsigned)(iibpHashMax * sizeof(CHAR)));
  827. memory = (int *)(((unsigned) memory + 1) & ~1); /* word boundary */
  828. mpibpbps = (struct BPS *)memory;
  829. /*
  830. memory = (int *)((unsigned)memory +
  831. (unsigned)(ibpMax * sizeof(struct BPS)));
  832. memory = (int *)(((unsigned) memory + 1) & ~1);*/
  833. return TRUE;
  834. }
  835. #endif
  836.