1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
|
/************************************************************/
/* Windows Write, Copyright 1985-1992 Microsoft Corporation */
/************************************************************/
#define NOSCALABLEFONT
#define NOSYSPARAMSINFO
#define NODBCS
#define NODRIVERS
#define NODEFERWINDOWPOS
#define NOPROFILER
#define NOHELP
#define NOKEYSTATES
#define NOWINMESSAGES
#define NOATOM
#define NOCLIPBOARD
#define NOCOLOR
#define NOCOMM
#define NODRAWTEXT
#define NOGDI
#define NOGDIOBJ
#define NOGDICAPMASKS
#define NOBITMAP
#define NOKEYSTATE
#define NOMENUS
#define NOMETAFILE
#define NOPEN
#define NOOPENFILE
#define NORASTEROPS
#define NORECT
#define NOSCROLL
#define NOSHOWWINDOW
#define NOSOUND
#define NOSYSCOMMANDS
#define NOSYSMETRICS
#define NOTEXTMETRIC
#define NOVIRTUALKEYCODES
#define NOWH
#define NOWINOFFSETS
#define NOWINSTYLES
#define NOUAC
#define NOIDISAVEPRINT
#define NOSTRUNDO
#define NOCTLMGR
#include <windows.h>
#include "mw.h"
#include "cmddefs.h"
#include "docdefs.h"
#include "filedefs.h"
#include "code.h"
#include "debug.h"
#include "dlgdefs.h"
#include "str.h"
#include "propdefs.h"
#include "wwdefs.h"
extern struct WWD rgwwd[];
extern int utCur;
extern int vfInitializing;
extern CHAR szAppName[];
extern struct FCB (**hpfnfcb)[];
extern struct BPS *mpibpbps;
extern int ibpMax;
extern typeTS tsMruBps;
extern int vfSysFull;
extern int ferror;
extern int vfnWriting;
extern int vibpWriting;
extern HANDLE hMmwModInstance;
extern HWND vhWndMsgBoxParent;
extern int vfMemMsgReported;
extern int vfDeactByOtherApp;
extern MSG vmsgLast;
extern HWND vhDlgFind;
extern HWND vhDlgChange;
extern HWND vhDlgRunningHead;
extern HANDLE hParentWw;
HANDLE hszNoMemory = NULL;
HANDLE hszDirtyDoc = NULL;
HANDLE hszCantPrint = NULL;
HANDLE hszPRFAIL = NULL;
HANDLE hszCantRunM = NULL;
HANDLE hszCantRunF = NULL;
HANDLE hszWinFailure = NULL;
BOOL vfWinFailure = FALSE;
#ifdef INEFFLOCKDOWN
FARPROC lpDialogBadMargins;
#endif
#define FInModeless(hWnd) (hWnd == vhDlgFind || hWnd == vhDlgChange || \
hWnd == vhDlgRunningHead)
CHAR *PchFillPchId( CHAR *, int, int );
NEAR WaitBeforePostMsg(int);
#ifdef CANCELMSG /* During debug, permit an abort for stack traces */
#define MB_MESSAGE (MB_OKCANCEL | MB_APPLMODAL | MB_ICONASTERISK)
#define MB_ERROR (MB_OKCANCEL | MB_APPLMODAL | MB_ICONEXCLAMATION)
#define MB_TROUBLE (MB_OKCANCEL | MB_APPLMODAL | MB_ICONHAND)
#else
#define MB_MESSAGE (MB_OK | MB_APPLMODAL | MB_ICONASTERISK)
#define MB_ERROR (MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION)
#define MB_TROUBLE (MB_OK | MB_APPLMODAL | MB_ICONHAND)
#endif
#define MB_DEFYESQUESTION (MB_YESNOCANCEL | MB_APPLMODAL | MB_ICONHAND)
#define MB_DEFNOQUESTION (MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_APPLMODAL | MB_ICONHAND)
ErrorLevel(IDPMT idpmt)
{
/* A long story. But to fix Winbug #1097, we need to take special
exception for this error message -- when this is displayed in a
low mem situation, this must be system modal (match params used
in FRenderAll() ...pault */
if (idpmt == IDPMTClipLarge)
return(MB_OK | MB_SYSTEMMODAL | MB_ICONHAND);
else
switch (idpmt & MB_ERRMASK)
{
case MB_ERRASTR: /* * level */
return(MB_MESSAGE);
case MB_ERREXCL: /* ! level */
return(MB_ERROR);
case MB_ERRQUES: /* ? level */
return(MB_DEFYESQUESTION);
case MB_ERRHAND: /* HAND level */
return(MB_TROUBLE);
default:
Assert(FALSE);
}
}
int far Abort(response)
int response;
{
for( ; ; );
}
#ifdef DEBUG
ErrorWithMsg(IDPMT idpmt, CHAR *szMessage)
{
#ifdef REALDEBUG
extern int vfOutOfMemory;
CHAR szBuf[cchMaxSz];
int errlevel = ErrorLevel(idpmt);
BOOL fDisableParent = FALSE;
register HWND hWndParent = (vhWndMsgBoxParent == NULL) ?
hParentWw : vhWndMsgBoxParent;
Assert(IsWindow(hWndParent));
if (idpmt == IDPMTNoMemory)
{
vfOutOfMemory = TRUE;
if (vfMemMsgReported)
{
return;
}
vfMemMsgReported = TRUE;
}
if (ferror)
return;
ferror = TRUE;
if (vfInitializing)
return;
CchCopySz( szMessage, PchFillPchId( szBuf, idpmt, sizeof(szBuf) ) );
if (vfDeactByOtherApp && !InSendMessage())
WaitBeforePostMsg(errlevel);
/* force user to answer the error msg */
if (hWndParent != NULL && FInModeless(hWndParent))
{
EnableExcept(hWndParent, FALSE);
}
else
{
if (hWndParent != NULL && !IsWindowEnabled(hWndParent))
{
EnableWindow(hWndParent, TRUE);
fDisableParent = TRUE;
}
EnableOtherModeless(FALSE);
}
if (MessageBox(hWndParent, (LPSTR)szBuf,
(LPSTR)NULL, errlevel) == IDCANCEL)
/* A debugging feature -- show stack trace if he hit "cancel" */
FatalExit( 0 );
if (hWndParent != NULL && FInModeless(hWndParent))
{
EnableExcept(hWndParent, TRUE);
}
else
{
if (fDisableParent)
{
EnableWindow(hWndParent, FALSE);
}
EnableOtherModeless(TRUE);
}
#else
Error( idpmt );
#endif
}
#endif /* DEBUG */
void Error(IDPMT idpmt)
{
extern int vfOutOfMemory;
CHAR szBuf [cchMaxSz];
HANDLE hMsg;
LPCH lpch;
static int nRecurse=0;
int errlevel = ErrorLevel(idpmt);
register HWND hWndParent = (vhWndMsgBoxParent == NULL) ? hParentWw :
vhWndMsgBoxParent;
if (nRecurse)
return;
++nRecurse;
Assert((hWndParent == NULL) || IsWindow(hWndParent));
if (idpmt == IDPMTNoMemory)
{
vfOutOfMemory = TRUE;
if (vfMemMsgReported)
{
goto end;
}
vfMemMsgReported = TRUE;
}
if (!ferror && !vfInitializing)
{
CloseEveryRfn( FALSE );
switch (idpmt)
{
case IDPMTNoMemory:
hMsg = hszNoMemory;
GetMsg:
if (hMsg == NULL || (lpch = GlobalLock(hMsg)) == NULL)
{
goto end;
}
bltbx(lpch, (LPCH)szBuf, LOWORD(GlobalSize(hMsg)));
GlobalUnlock(hMsg);
break;
case IDPMTCantPrint:
hMsg = hszCantPrint;
goto GetMsg;
case IDPMTPRFAIL:
hMsg = hszPRFAIL;
goto GetMsg;
case IDPMTCantRunM:
hMsg = hszCantRunM;
goto GetMsg;
case IDPMTCantRunF:
hMsg = hszCantRunF;
goto GetMsg;
case IDPMTWinFailure:
hMsg = hszWinFailure;
goto GetMsg;
default:
PchFillPchId( szBuf, idpmt, sizeof(szBuf) );
break;
}
if (vfDeactByOtherApp && !InSendMessage())
{
WaitBeforePostMsg(errlevel);
}
#ifdef CANCELMSG
if (IdPromptBoxSz( hWndParent, szBuf, errlevel ) == IDCANCEL)
{
/* A debugging feature -- show stack trace if he hit "cancel" */
FatalExit( 100 );
}
#else
IdPromptBoxSz( hWndParent, szBuf, errlevel );
#endif
}
if (errlevel != MB_MESSAGE)
{
ferror = TRUE;
}
end:
--nRecurse;
}
/* end of E r r o r */
IdPromptBoxSz( hWndParent, sz, mb )
HWND hWndParent;
CHAR sz[];
int mb;
{ /* Put up a message box with string sz. mb specifies buttons to display,
"level" of message (HAND, EXCL, etc.).
hWndParent is the parent of the message box.
Returns the id of the button selected by the user */
int id;
BOOL fDisableParent = FALSE;
extern int wwMac;
int wwMacSave=wwMac;
Assert((hWndParent == NULL) || IsWindow(hWndParent));
if ((mb == MB_ERROR) || (mb == MB_TROUBLE))
{
extern int ferror;
extern int vfInitializing;
if (ferror)
return;
ferror = TRUE;
if (vfInitializing)
return;
}
CloseEveryRfn( FALSE ); /* Protect against disk swap while in message box */
/* don't allow painting doc, it may be in an unpaintable state (5.8.91) v-dougk */
if (mb == MB_TROUBLE)
wwMac=0;
/* force user to answer the msg */
if (hWndParent != NULL && FInModeless(hWndParent))
{
EnableExcept(hWndParent, FALSE);
}
else
{
if (hWndParent != NULL && !IsWindowEnabled(hWndParent))
{
EnableWindow(hWndParent, TRUE);
fDisableParent = TRUE;
}
EnableOtherModeless(FALSE);
}
/* We almost ALWAYS want the parent window to be passed to MessageBox
except in a couple RARE cases where even Write's main text window
hasn't yet gotten displayed. In that case we'll rip out of Windows
if we DO tell MessageBox about it... so NULL is the prescribed hwnd
to pass ..pault */
id = MessageBox((hWndParent == hParentWw && !IsWindowVisible(hWndParent)) ?
NULL : hWndParent, (LPSTR)sz, (LPSTR)szAppName, mb);
if (hWndParent != NULL && FInModeless(hWndParent))
{
EnableExcept(hWndParent, TRUE);
}
else
{
if (fDisableParent)
{
EnableWindow(hWndParent, FALSE);
}
EnableOtherModeless(TRUE);
}
wwMac = wwMacSave;
return id;
}
WinFailure()
{
/* Windows has run out of memory. All we can do is discard all of our
Windows objects and pray the problem goes away. At the very worst, the
might be stuck with a saved document and unable to edit. */
/* FM 9/4/87 - Take out the call to FreeMemoryDC, hopefully to allow
Write to continue formatting lines. */
extern int vfOutOfMemory;
vfOutOfMemory = TRUE;
if (!vfWinFailure)
{
Error(IDPMTWinFailure);
vfWinFailure = TRUE;
}
}
#ifdef DEBUG
DiskErrorWithMsg(idpmt, szMessage)
IDPMT idpmt;
CHAR *szMessage;
#else
DiskError(idpmt)
IDPMT idpmt;
#endif
{ /* Description: Given an error message descriptor,
outputs an Alert Box. If the message indicates a serious disk
error, all files are closed and a flag set so that
the user will be restricted to the "Save" option only.
Returns: nothing
*/
extern HWND hParentWw;
extern int vfDiskError;
extern int vfInitializing;
int errlevel = ErrorLevel( idpmt );
CHAR rgch[cchMaxSz];
CHAR *pch, *PchFillPchId();
register HWND hWndParent = (vhWndMsgBoxParent == NULL) ? hParentWw : vhWndMsgBoxParent;
Assert( (hWndParent == NULL) || IsWindow(hWndParent));
if (idpmt == IDPMTSDE || idpmt == IDPMTSDE2)
/* Serious disk error, put the guy in "SAVE-ONLY" state */
if (!vfDiskError)
{
vfDiskError = TRUE;
CloseEveryRfn( TRUE );
}
if (ferror || vfInitializing)
/* Only report one error per operation */
/* Don't report errors during inz; FInitWinInfo handles them */
return;
CloseEveryRfn( FALSE ); /* Close floppy files so the guy can change
disks while in the message box. */
pch = PchFillPchId( rgch, idpmt, sizeof(rgch) );
#ifdef REALDEBUG /* Only enable extra message if really debugging */
CchCopySz( szMessage, pch );
#endif
if (vfDeactByOtherApp && !InSendMessage())
WaitBeforePostMsg(errlevel);
#ifdef CANCELMSG
if (IdPromptBoxSz( hWndParent, rgch, errlevel ) == IDCANCEL)
/* A debugging feature -- show stack trace if he hit "cancel" */
FatalExit( 0 );
#else
IdPromptBoxSz( hWndParent, rgch, errlevel );
#endif
ferror = TRUE;
}
/* end of D i s k E r r o r */
ErrorBadMargins(hWnd, xaLeft, xaRight, yaTop, yaBottom)
HWND hWnd;
unsigned xaLeft;
unsigned xaRight;
unsigned yaTop;
unsigned yaBottom;
{
/* Warn the user that the margins for this page must be xaLeft, xaRight,
yaTop, and yaBottom. */
extern CHAR *vpDlgBuf;
extern HANDLE hMmwModInstance;
extern int vfDeactByOtherApp;
unsigned rgzaMargin[4];
#ifndef INEFFLOCKDOWN
extern BOOL far PASCAL DialogBadMargins(HWND, unsigned, WORD, LONG);
FARPROC lpDialogBadMargins;
if (!(lpDialogBadMargins = MakeProcInstance(DialogBadMargins, hMmwModInstance)))
{
WinFailure();
return;
}
#endif
/* These values are kept on the stact to cut down on static variables. */
rgzaMargin[0] = xaLeft;
rgzaMargin[1] = xaRight;
rgzaMargin[2] = yaTop;
rgzaMargin[3] = yaBottom;
vpDlgBuf = (CHAR *)&rgzaMargin[0];
if (vfDeactByOtherApp && !InSendMessage())
WaitBeforePostMsg(MB_ERROR);
/* Create the "error" dialog box. */
DialogBox(hMmwModInstance, MAKEINTRESOURCE(dlgBadMargins), hWnd,
lpDialogBadMargins);
#ifndef INEFFLOCKDOWN
FreeProcInstance(lpDialogBadMargins);
#endif
}
BOOL far PASCAL DialogBadMargins(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
/* This routine handles the messages for the Bad Margins dialog box. */
extern CHAR *vpDlgBuf;
extern HWND vhWndMsgBoxParent;
int idi;
unsigned *prgzaMargin = (unsigned *)vpDlgBuf;
switch (message)
{
case WM_INITDIALOG:
/* Disable modeless dialog boxes. */
EnableOtherModeless(FALSE);
/* Set the values of the margins on the dialog box. */
for (idi = idiBMrgLeft; idi <= idiBMrgBottom; idi++, prgzaMargin++)
{
CHAR szT[cchMaxNum];
CHAR *pch = &szT[0];
CchExpZa(&pch, *prgzaMargin, utCur, cchMaxNum);
SetDlgItemText(hDlg, idi, (LPSTR)szT);
}
return (TRUE);
case WM_ACTIVATE:
if (wParam)
{
vhWndMsgBoxParent = hDlg;
}
return(FALSE); /* so that we leave the activate message to
the dialog manager to take care of setting the focus correctly */
case WM_COMMAND:
if (wParam == idiOk)
{
/* Destroy the tabs dialog box and enable any existing modeless
dialog boxes.*/
OurEndDialog(hDlg, NULL);
return (TRUE);
}
}
return (FALSE);
}
/******************* ERROR SITUATION ROUTINES **************************/
FGrowRgbp(cbp)
int cbp;
{
#ifdef CKSM
#ifdef DEBUG
extern unsigned (**hpibpcksm) [];
extern int ibpCksmMax;
#endif
#endif
extern CHAR (*rgbp)[cbSector];
extern CHAR *rgibpHash;
extern int fIbpCheck;
extern int vcCount;
int ibpMaxNew = ibpMax + cbp;
int iibpHashMaxNew;
int cbNew;
extern int ibpMaxFloat;
if (ibpMaxNew > ibpMaxFloat)
return(FALSE);
iibpHashMaxNew = ibpMaxNew * 2 + 1;
cbNew = ibpMaxNew * cbSector * sizeof(CHAR) +
((iibpHashMaxNew * sizeof(CHAR) + sizeof(int) - 1) & ~1) +
((ibpMaxNew * sizeof(struct BPS) + sizeof(int) - 1) & ~1);
if (LocalReAlloc((HANDLE)rgbp, cbNew, LPTR) == (HANDLE)NULL
#ifdef CKSM
#ifdef DEBUG
|| !FChngSizeH( hpibpcksm, ibpMaxNew, FALSE )
#endif
#endif
)
{
if (cbp == 1)
{
#ifdef CHIC
CommSzNum("Can't grow any more, current ibpMax = ", ibpMax);
#endif
vcCount = 1024; /* so that we wait for a longer period before attemp again */
}
return(FALSE);
}
else
{
int cbRgbpTotalNew = ibpMaxNew * cbSector;
int cbHashOrg = (iibpHashMax * sizeof(CHAR) + sizeof(int) - 1) & ~1;
int cbHashTotalNew = (iibpHashMaxNew * sizeof(CHAR) + sizeof(int) - 1) & ~1;
int cbBpsOrg = (ibpMax * sizeof(struct BPS) + sizeof(int) - 1) & ~1;
int ibp;
struct BPS *pbps;
CHAR *pNew;
/* blt tail end stuff first, in the following order --
mpibpbps, rgibpHash */
pNew = (CHAR *)rgbp + cbRgbpTotalNew + cbHashTotalNew;
bltbyte((CHAR*)mpibpbps, pNew, cbBpsOrg);
mpibpbps = (struct BPS *)pNew;
pNew = (CHAR *)rgbp + cbRgbpTotalNew;
bltbyte((CHAR *)rgibpHash, pNew, cbHashOrg);
rgibpHash = pNew;
for (ibp = 0, pbps = &mpibpbps[0]; ibp < ibpMaxNew; ibp++, pbps++)
{
if (ibp >= ibpMax)
{
/* initialize new bps */
pbps->fn = fnNil;
pbps->ts = tsMruBps - (ibpMax * 4);
}
pbps->ibpHashNext = ibpNil;
}
ibpMax = ibpMaxNew;
iibpHashMax = iibpHashMaxNew;
#ifdef CKSM
#ifdef DEBUG
ibpCksmMax = ibpMax;
#endif
#endif
RehashRgibpHash();
#ifdef CHIC
CommSzNum("ibpMax = ", ibpMax);
#endif
return(TRUE);
}
}
FStillOutOfMemory()
{
/* Return FALSE if there is enough memory available to pop us out of the "out of
memory" state; TRUE otherwise */
extern HANDLE vhReservedSpace;
/* If we have had to give up our reserved space block, re-establish it BEFORE
testing memory availability */
//return vfWinFailure;
if (vhReservedSpace == NULL && (vhReservedSpace = LocalAlloc(LHND, cbReserve))
== NULL)
{
/* Nothing we can do. */
return (TRUE);
}
/* OK, we have our reserve block, but do we have any other memory? (The use of
cbReserve here is abritrary.) */
if (LocalCompact(0) < cbReserve)
{
HANDLE hBuf = LocalAlloc(LMEM_MOVEABLE, cbReserve);
if (hBuf == NULL)
{
return(TRUE);
}
else
{
LocalFree(hBuf);
if (GlobalCompact(0) < cbReserve)
{
HANDLE hBuf = GlobalAlloc(GMEM_MOVEABLE, cbReserve);
if (hBuf == NULL)
{
return(TRUE);
}
else
{
GlobalFree(hBuf);
return(FALSE);
}
}
}
}
return(FALSE);
}
IbpFindSlot(fn)
int fn;
{ /*
Description: Called from IbpEnsureValid (file.c) when a disk
full error is generated while trying to write out
scratch file records. A buffer slot for a piece of
file fn must be found
which is either non-dirty or is dirty but does
not contain scratch file information. We search
for the least recently used slot with the above
requirements.
If fn == fnScratch, we are trying to find a buffer
slot for a scratch file page. We may not put it in
the beginning cbpMustKeep slots.
Returns: ibp (slot #).
*/
int ibpOuterLoop;
int ibpNextTry;
int ibpStart;
typeTS ts, tsLastTry = 0;
int ibp;
#ifdef DEBUG
Assert(vfSysFull);
#endif
if (fn == fnScratch) ibpStart = cbpMustKeep;
else ibpStart = 0;
/* In LRU timestamp order, we are looking for any slot */
/* which is non dirty or is dirty but is not part of the */
/* scratch file. */
for (ibpOuterLoop = ibpStart; ibpOuterLoop < ibpMax; ibpOuterLoop++)
{
struct BPS *pbps = &mpibpbps[ibpStart];
typeTS tsNextTry = -1;/* largest possible timestamp */
for(ibp = ibpStart; ibp < ibpMax; ibp++, pbps++)
{
ts = pbps->ts - (tsMruBps + 1);
if ((ts <= tsNextTry) && (ts > tsLastTry))
{
tsNextTry = ts;
ibpNextTry = ibp;
}
}
if (mpibpbps[ibpNextTry].fDirty == fFalse) break;
if (mpibpbps[ibpNextTry].fn != fnScratch)
{
FFlushFn(mpibpbps[ibpNextTry].fn);
/* We need not check a return value.
If the flush failed, vfDiskFull
will get set */
break;
}
else tsLastTry = tsNextTry;
}
if (ibpOuterLoop < ibpMax)
{
if (fn == vfnWriting) vibpWriting = ibpNextTry;
return(ibpNextTry);
}
#ifdef DEBUG
Assert(FALSE); /* there just had to be some slot available */
/* not used by the scratch file */
#endif
} /* end IbpFindSlot */
NEAR WaitBeforePostMsg(errlevel)
int errlevel;
{
extern int flashID;
extern HWND hwndWait;
BOOL fParentEnable = IsWindowEnabled(hParentWw) || hwndWait;
MessageBeep(errlevel);
Diag(CommSzNum("WAITBEFOREPOSTMSG: vfDeactByOtherApp==",vfDeactByOtherApp));
if (!fParentEnable)
EnableWindow(hParentWw, TRUE); /* make sure parent window is enabled
to let the user click in it */
flashID = SetTimer(hParentWw, NULL, 500, (FARPROC)NULL);
while (vfDeactByOtherApp)
{
if (PeekMessage((LPMSG)&vmsgLast, (HWND)NULL, NULL, NULL, PM_REMOVE))
{
if (vfDeactByOtherApp)
{
TranslateMessage( (LPMSG)&vmsgLast);
DispatchMessage((LPMSG)&vmsgLast);
}
}
}
if (!fParentEnable)
EnableWindow(hParentWw, FALSE); /* reset */
}
EnableExcept(hWnd, fEnable)
HWND hWnd;
BOOL fEnable;
{ /* Enable hParentWw and all modeless except hWnd according to fEnable */
extern HWND vhDlgChange;
extern HWND vhDlgFind;
extern HWND vhDlgRunningHead;
extern HWND hParentWw;
if (hWnd != vhDlgChange && IsWindow(vhDlgChange))
{
EnableWindow(vhDlgChange, fEnable);
}
if (hWnd != vhDlgFind && IsWindow(vhDlgFind))
{
EnableWindow(vhDlgFind, fEnable);
}
if (hWnd != vhDlgRunningHead && IsWindow(vhDlgRunningHead))
{
EnableWindow(vhDlgRunningHead, fEnable);
}
EnableWindow(hParentWw, fEnable);
}
|