-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWMEX.C
1482 lines (1226 loc) · 38.5 KB
/
WMEX.C
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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************
* "Copyright (C) 1985, Digital Research, Inc. All Rights *
* Reserved. The Software Code contained in this listing is *
* proprietary to Digital Research Inc., Monterey, California *
* and is covered by U.S. and other copyright protection. *
* Unauthorized copying, adaptation, distribution, use or *
* display is prohibited and may be subject to civil and *
* criminal penalties. Disclosure to others is prohibited. For *
* the terms and conditions of software code use refer to the *
* appropriate Digital Research License Agreement." *
*****************************************************************/
/*===============================================================*
* Version 2.0 WMEX.C *
* Window Manager. *
*---------------------------------------------------------------*
* VERSION DATE BY CHANGE/COMMENTS *
*---------------------------------------------------------------*
* *
* 2.0 03/05/86 ma Fix previous fix so that logoff *
* occurs only when no windows left.*
* 1.9 02/20/86 ma Do a logoff if shell returns *
* negative error code. *
* 1.8 08/14/85 jsr Modified to allow dcnum to be a *
* vcon and not always a physical. *
* 1.7 07/23/85 jsr Make all MSGPIP errors non-fatal *
* for each vcon, fixed MSGPIPE *
* create size problem, modified *
* for CCUTLS changes, removed *
* STDIO defines, modified MSGPIPE *
* read/write code, set no echo on *
* special windows. *
* 1.6 07/17/85 jsr Fixed: Border size = 0 on vcreat *
* if no border, don't exit if ROOT,*
* unkctrl the desk before exit, *
* shut off wrap on special windows,*
* print and accept REAL window #s, *
* cleaned up event stuff, fixed *
* MSGPIPE create access problem. *
* 1.5 06/06/85 jsr Fixed: Logoff stuff, *
* 1.4 05/10/85 jsr Create mpipes w/o write access, *
* check for full LONG E_LOGOFF and *
* save and restore entry SMODE and *
* KMODE. *
* 1.3 05/10/85 jsr Restructured exit code, fixed *
* wndw# problem for <HELP>, and *
* input problem in invcmd(). Also *
* now create mpipes of unique *
* names and define con: for shell. *
* 1.2 05/06/85 jsr Fixed create(vc) error logic to *
* only abort new window, not WMEX. *
* Also added mssgact report in STAT*
* 1.1 04/26/85 jsr Added setattrib() escape seq's. *
* Also fixed async error code. *
* 1.0 04/23/85 jsr *
* *
*===============================================================*/
/*
Assumes:
Defined name "con:" is a virtual or physical console name.
Defined name "shell" is an executable program to run in
each virtual console.
Defined name "prn:" is an output device for PRINTSCREEN.
*/
/*
Suggested additional features:
1) Create all windows as full sized, but set view size as
configured. Add a new key <WTGL> to toggle window between
FULL and SIZED.
2) If above is implemented, then add another flags field to
WNDWDESC structure that includes the three flags associated
with cursor tracking (see VCON table - keyboard mode bits).
OR in these bits when setting KMODE.
3) Add create time options to set foreground and background
colors, window sizing, and KMODE control bits.
*/
/* include some header files */
/* C defines */
#include "portab.h"
/* Concurrent DOS defines */
#include "flags.h"
#include "wmchar.h"
#include "wmos.h"
/* utility defines */
#include "ccutls.h"
#include "utlerrs.h"
/* WMEX specific defines */
#include "wmex.h"
/* declare local (global) variables */
/* general use variables */
BYTE mygroup; /* LOGIN group number */
BYTE myuser; /* LOGIN user number */
BYTE pathchar[2]; /* pathchar */
BYTE topbuf[CMAXW]; /* buffer for top border assembly */
BYTE pconame[NAMELEN]; /* name of physical console */
WORD tlvl; /* top level index for ltop[] */
UWORD ch16; /* 16 bit character cell */
UWORD wtop; /* Screen currently on top */
UWORD ltop[LTOPMAX]; /* Last screen on top */
UWORD nstart; /* number of USRx wndws to start up */
UWORD cnrows; /* nrows from CONSOLE table */
UWORD cncols; /* ncols from CONSOLE table */
UWORD viewrow; /* viewrow from PCON or VCON */
UWORD viewcol; /* viewcol from PCON or VCON */
UWORD smode, kmode; /* entry SMODE and KMODE from console table */
BOOLEAN fninit; /* set if all FNUMs initialized */
BOOLEAN pflags[MAXVC-WNDWUSR1]; /* array of process found flags (STAT) */
BOOLEAN logoff; /* logoff requested flag */
BOOLEAN exitflg; /* exit flag */
BOOLEAN mssgact; /* WNDWMSSG is active */
BOOLEAN statact; /* WNDWSTAT is active */
BOOLEAN killstat; /* exit the STATUS window */
BOOLEAN kcflag; /* set for STATUS wndw on most kctrl keys */
BOOLEAN modeflg; /* set if S/KMODE values are valid */
LONG rcode; /* wmex return code */
LONG wmexpid; /* pid of WMEX */
LONG etable[NOSEVENTS]; /* array of event masks */
MPIPE mpipe; /* message pipe structure for <HELP> */
WVARS wvars[MAXVC]; /* array of window variable structures */
PCONSOLE pcns; /* pcns table */
jumpbuff jmpbuf; /* error abort control info */
/* DESK window specials */
LONG dcnum; /* DESK window file number */
RECT r_dwndw; /* DESK window area */
FRAME f_dwndw; /* DESK window area frame */
/* MSSG window specials */
LONG rsppfnum; /* reponse pipe file number */
RECT r_minfoa; /* MSSG window info area */
RECT r_mmorea; /* MSSG window more area */
RECT r_mpmpta; /* MSSG window pmpt area */
/* STAT window specials */
RECT r_sinfoa; /* STAT window info area */
RECT r_smorea; /* STAT window more area */
RECT r_spmpta; /* STAT window pmpt area */
/* PRINTSCREEN specials */
BYTE *ps_bbase; /* base of PRINTSCREEN buffer */
BYTE *ps_bptr; /* pointer to PRINTSCREEN buffer */
UWORD ps_rcnt; /* count of printed rows */
UWORD ps_nrow; /* number of rows to be printed */
UWORD ps_ncol; /* number of columns to be printed per row */
BOOLEAN ps_active; /* PRINTSCREEN active flag */
LONG ps_fnum; /* printer file number */
/* cast local procedures */
LONG wmex();
VOID create();
VOID message();
VOID newvcon();
VOID printscrn();
VOID setupd();
VOID setupw();
VOID status();
VOID wminit();
VOID wmshell();
/* declare external procedures */
/* from WMUTLS.L86 */
EXTERN BYTE *fixnum();
EXTERN WORD getpcns();
EXTERN WORD nextvc();
EXTERN BOOLEAN center();
EXTERN BOOLEAN chksproc();
EXTERN BOOLEAN statcmd();
EXTERN LONG erdelim();
EXTERN VOID abortall();
EXTERN VOID bldspec();
EXTERN VOID bottom();
EXTERN VOID clrwrect();
EXTERN VOID crlfs();
EXTERN VOID dopmpt();
EXTERN VOID getvcinfo();
EXTERN VOID helpmsg();
EXTERN VOID kbevent();
EXTERN VOID killall();
EXTERN VOID killvcon();
EXTERN VOID noabt();
EXTERN VOID prnstatic();
EXTERN VOID prntext();
EXTERN VOID setattrib();
EXTERN VOID setconmode();
EXTERN VOID setcurpos();
EXTERN VOID setvcinfo();
EXTERN VOID top();
EXTERN VOID vcswitch();
EXTERN VOID wrtpline();
/* from CCUTLS.L86 */
EXTERN BYTE *utskpwht();
EXTERN BYTE *utui2ds();
EXTERN BYTE *utul2ds();
EXTERN BOOLEAN utisroot();
EXTERN VOID utfarjmp();
EXTERN VOID utgtpch();
EXTERN VOID utscat();
EXTERN VOID utscopy();
EXTERN LONG utprnmsg();
EXTERN LONG utslen();
EXTERN LONG utstjmp();
/* from CCRTL.L86 */
EXTERN LONG s_alter();
EXTERN LONG s_cancel();
EXTERN LONG e_command();
EXTERN LONG s_copy();
EXTERN LONG s_close();
EXTERN LONG s_create();
EXTERN LONG s_define();
EXTERN LONG s_disable();
EXTERN LONG s_get();
EXTERN LONG s_kctrl();
EXTERN LONG s_lookup();
EXTERN LONG s_malloc();
EXTERN LONG s_mfree();
EXTERN LONG s_open();
EXTERN LONG s_order();
EXTERN LONG s_rdelim();
EXTERN LONG e_read();
EXTERN LONG s_return();
EXTERN LONG e_termevent();
EXTERN LONG s_vccreate();
EXTERN LONG s_wait();
EXTERN LONG e_write();
EXTERN LONG s_write();
/* declare external variables */
/* from WMEXDATA.C */
EXTERN UBYTE wm0010;
EXTERN UBYTE wm0100, wm0110, wm0120;
EXTERN UBYTE *wm0260[];
EXTERN UBYTE wm0299[];
EXTERN UBYTE wm9009[];
EXTERN WNDWDESC wd_mssg, wd_stat, wd_usr1, wd_usr2;
EXTERN WNDWDESC wd_usr3, wd_usr4, wd_usr5, wd_usr6;
EXTERN WNDWSPEC ws_mssg, ws_stat;
/* from WMEXNUT.C */
EXTERN UBYTE wm8000[], wm8001[], wm8002[], wm8003[];
EXTERN UBYTE wm8004[], wm8005[], wm8006[], wm8007[];
EXTERN UBYTE wm8100[], wm8110[], wm8130[];
EXTERN UBYTE wm8170[];
EXTERN UBYTE wm9003[], wm9004;
/* start of code */
/* wmex() : initialization and main routine */
LONG wmex()
{
BYTE specbuf[BUFSIZ];
BYTE alterb[PL_NPLANE * 2];
LONG dmask, emask;
REG WORD i, event, vc, dosflgs;
/* prevent external termination */
e_termevent((LONG)&noabt, (LONG)0);
s_disable();
restart:
/* set error control info */
dcnum = FNUMINIT;
fninit = exitflg = logoff = FALSE;
/* set error abort information */
if(rcode = utstjmp(jmpbuf))
{
killall(); /* go kill off all vcon processes */
bailout:
/* any terminate events left ? */
for(i = OSEVUSR1; ((i <= OSEVUSR6) && (!etable[i])); ++i);
if(i <= OSEVUSR6)
goto eventhndlr; /* go wait on TERMINATE events */
/* close up special windows */
killvcon(WNDWSTAT);
killvcon(WNDWMSSG);
/* close up response pipe */
if(rsppfnum != FNUMINIT)
{
s_close(0x0000, rsppfnum);
rsppfnum = FNUMINIT;
}
/* close up PRN: file */
if(ps_fnum != FNUMINIT)
{
s_mfree((LONG)ps_bbase);
s_close(0x0000, ps_fnum);
ps_fnum = FNUMINIT;
}
/* close up DESK last */
if(modeflg)
setconmode(dcnum, smode, kmode);
if(dcnum != FNUMINIT)
{
s_kctrl(dcnum, 0x0001, CI_PSCRN, CI_HELP); /* unkctrl DESK */
wvars[WNDWDESK].wv_flags &= ~WV_INUSE;
s_close(0x0000, dcnum);
dcnum = FNUMINIT;
}
if(logoff)
rcode = E_LOGOFF;
return(rcode); /* RETURN FROM HERE */
}
/* initialize global variables */
wminit();
/* initialize local variables */
dmask = 0;
/* setup DESK window */
dosflgs =
(pcns.pc_planes & wm0100 & W_ATTRIBS) ? (A_CHARPL|A_ATTRPL) : A_CHARPL;
alterb[ALB_CAND] = alterb[ALB_AAND] = alterb[ALB_EAND] =
alterb[ALB_EXOR] = 0;
alterb[ALB_CXOR] = wm0110;
alterb[ALB_AXOR] = (dosflgs & A_ATTRPL) ? wm0120 : 0;
if((rcode = s_alter(dosflgs, dcnum, (LONG)0, (LONG)&r_dwndw,
(LONG)alterb)) < SUCCESS)
utfarjmp(jmpbuf, rcode);
/* set keyboard mode, kctrl ranges for wmex special keys */
if((rcode = s_kctrl(dcnum,0x0001, CI_HELP, CI_PSCRN)) < SUCCESS)
utfarjmp(jmpbuf, rcode);
setconmode(dcnum, 0x0000, (CKM_NAB|CKM_SXB|CKM_NEC));
/* initialize stuff for message window */
newvcon(WNDWMSSG);
prnstatic(WNDWMSSG);
setconmode(wvars[WNDWMSSG].wv_cnum, 0x0000, (CKM_NAB|CKM_NEC));
/* initialize stuff for Status Window */
newvcon(WNDWSTAT);
prnstatic(WNDWSTAT);
setconmode(wvars[WNDWSTAT].wv_cnum, 0x0000, (CKM_NAB|CKM_NEC));
/* create and open message pipe */
bldspec(WNDWSTAT, S_PIP, specbuf);
dosflgs = (A_SET|A_READ|A_SHARE|A_TEMP|A_SECURITY);
wvars[WNDWSTAT].wv_pnum = s_create((BYTE)0x00, dosflgs, (LONG)specbuf,
0x0000,(FS_OD|FS_OE|FS_OW|FS_OR),(LONG)sizeof(MPIPE));
if((etable[OSEVMPST] = e_read((LONG)0, A_FPOFF, wvars[WNDWSTAT].wv_pnum,
(LONG)&(wvars[WNDWSTAT].wv_mph), (LONG)sizeof(wvars[WNDWSTAT].wv_mph),
(LONG)0)) < SUCCESS)
etable[OSEVMPST] = 0;
/* fire up nstart number of USRx windows */
startup:
for(i = 0, vc = WNDWUSR1; i < nstart; ++i, ++vc)
{
create(vc);
if((i == 0) && (!(wvars[vc].wv_flags & WV_INUSE)))
utfarjmp(jmpbuf, rcode);
}
/* allow keyboard events */
if((etable[OSEVKEYBD] = e_read((LONG)0, 0x0000, dcnum, (LONG)&(ch16),
(LONG)sizeof(ch16), (LONG)0)) < SUCCESS)
{
rcode = etable[OSEVKEYBD];
etable[OSEVKEYBD] = 0;
utfarjmp(jmpbuf, rcode);
}
eventhndlr: /* EVENT HANDLER */
for (;;)
{
/* Build WAIT mask */
emask = 0;
for (i = 0; i < NOSEVENTS; i++)
emask |= etable[i];
/* Wait for event(s) to complete */
emask = s_wait(emask);
emask |= dmask; /* OR in any outstanding events too. */
dmask = 0;
/* handle multiple events */
for(event = 0; event < NOSEVENTS; ++event)
{
/* find an event */
if(!(etable[event] & emask))
continue;
/* We have an event completion and we know who it is */
rcode = s_return(etable[event]);
etable[event] = 0;
switch(event)
{
case OSEVUSR1: /* USRx shell terminated */
case OSEVUSR2:
case OSEVUSR3:
case OSEVUSR4:
case OSEVUSR5:
case OSEVUSR6:
/* kill off this vcon */
killvcon(event);
/* go kill all if LOGOFF */
if(rcode == E_LOGOFF)
{
logoff = TRUE;
killall();
}
/* any open user windows ? */
for(i=WNDWUSR1;
((i<MAXVC) && (!(wvars[i].wv_flags&WV_INUSE))); ++i);
/* all windows closed ? */
if(i >= MAXVC)
{
if((!exitflg) && (!logoff) && (rcode > 0L))
{ /* not exit or logoff or bad exit? */
dmask = s_cancel(etable[OSEVKEYBD]);
etable[OSEVKEYBD] = 0;
nstart = 1;
goto startup;
}
else
{
if(utisroot())
goto restart;
else
goto bailout;
}
}
break;
case OSEVMPST: /* STAT <HELP> or else */
case OSEVMPU1: /* USRx sent a message */
case OSEVMPU2:
case OSEVMPU3:
case OSEVMPU4:
case OSEVMPU5:
case OSEVMPU6:
message(event - MAXVC);
break;
case OSEVKEYBD: /* KCTRL keyboard event */
kbevent();
break;
case OSEVPRNT: /* <PSCN> line write */
wrtpline();
break;
case OSEVHELP: /* <HELP> msgpipe write done */
case OSEVRSPP: /* MSSG response pipe write done */
rcode = SUCCESS;
break;
case NOSEVENTS:
default:
utfarjmp(jmpbuf, (UR_SOURCE | UR_INTERNAL));
break;
} /* end of event SWITCH */
} /* end of multiple event FOR loop */
} /* end of event handler FOR loop (endless) */
} /* end of WMEX procedure */
/* local utility procedures */
/* wminit() : initialize some global variables and structures */
VOID wminit()
{
BYTE specbuf[BUFSIZ];
ENVIRON env;
CONSOLE ct;
VCONSOLE vcon;
REG WORD i, vc;
ps_fnum = rsppfnum = FNUMINIT;
ps_rcnt = ps_nrow = ps_ncol = 0;
ps_active = mssgact = statact = modeflg = FALSE;
/* initialize event table */
for (i = 0; i < NOSEVENTS; i++)
etable[i] = 0;
nstart =
((wm0010 > 0) && (wm0010 < MAXVC - 2)) ? (UWORD)wm0010 : 1;
/* close up standard input devices */
s_close(0x0000, STDIN);
s_close(0x0000, STDOUT);
s_close(0x0000, STDERR);
pathchar[0] = utgtpch(); /* get the path character */
pathchar[1] = NULL;
/* get physical console info */
vc = getpcns();
/* open console file */
if(vc)
bldspec(vc, (S_DEV|S_VCR|S_CON), specbuf);
else
bldspec(0, (S_DEV|S_CON), specbuf);
if((dcnum = s_open((A_READ|A_WRITE|A_SET|A_SHARE|A_SHFP),
(LONG)specbuf)) < SUCCESS)
utfarjmp(jmpbuf, rcode);
/* get the CONSOLE information */
if((rcode = s_get(T_CON, dcnum, (LONG)&ct, (LONG)sizeof(ct))) < SUCCESS)
utfarjmp(jmpbuf, rcode);
/* save size info */
cnrows = ct.cn_nrows;
cncols = ct.cn_ncols;
/* save entry SMODE and KMODE */
smode = ct.cn_smode;
kmode = ct.cn_kmode;
modeflg = TRUE;
vcon.vc_viewrow = RMIN;
vcon.vc_viewcol = CMIN;
if(vc) /* get the VCONSOLE information */
s_get(T_VCON, dcnum, (LONG)&vcon, (LONG)sizeof(vcon));
viewrow = vcon.vc_viewrow;
viewcol = vcon.vc_viewcol;
tlvl = 0;
wtop = ltop[tlvl] = MAXVC + 1;
/* get group, user and process id's */
if((rcode = s_get(T_ENV, (LONG)0, (LONG)&env,
(LONG)sizeof(env))) < SUCCESS)
utfarjmp(jmpbuf, rcode);
/* save a copy */
myuser = env.en_user;
mygroup = env.en_group;
wmexpid = env.en_pid;
for(i = WNDWDESK; i < MAXVC; ++i)
{
switch(i)
{
case WNDWDESK:
setupd();
break;
case WNDWMSSG:
setupw(i, &wd_mssg);
break;
case WNDWSTAT:
setupw(i, &wd_stat);
break;
case WNDWUSR1:
setupw(i, &wd_usr1);
break;
case WNDWUSR2:
setupw(i, &wd_usr2);
break;
case WNDWUSR3:
setupw(i, &wd_usr3);
break;
case WNDWUSR4:
setupw(i, &wd_usr4);
break;
case WNDWUSR5:
setupw(i, &wd_usr5);
break;
case WNDWUSR6:
setupw(i, &wd_usr6);
break;
}
}
fninit = TRUE; /* fnums initialized */
}
/* setupd() : set up DESK RECT and FRAME */
VOID setupd()
{
REG RECT *rpw;
REG FRAME *fpw;
wvars[WNDWDESK].wv_flags = WV_INUSE;
rpw = &r_dwndw;
fpw = &f_dwndw;
rpw->r_row = RMIN;
rpw->r_col = CMIN;
rpw->r_nrow = fpw->fr_nrow = cnrows;
rpw->r_ncol = fpw->fr_ncol = cncols;
fpw->fr_pl[PL_CHAR] = &wm0110;
fpw->fr_pl[PL_ATTR] =
(pcns.pc_planes & wm0100 & W_ATTRIBS) ? &wm0120 : (LONG)0;
fpw->fr_pl[PL_EXTN] = (LONG)0;
fpw->fr_use = (LONG)0;
}
/* setupw() : set up non-DESK window variables */
VOID setupw(vc, wdp)
REG WORD vc;
REG WNDWDESC *wdp;
{
RECT *rpt, *rpl;
RECT *rpi, *rpm, *rpp;
FRAME *fpt, *fpb, *fpl, *fpr;
WNDWSPEC *wsp;
REG WORD baflag;
REG RECT *rpw;
REG WVARS *wvp;
wvp = &wvars[vc];
wvp->wv_pid = 0;
wvp->wv_fid = 0;
wvp->wv_flags = 0;
wvp->wv_wdp = wdp; /* set pointer to WNDWDESC struct */
wvp->wv_vnum = wvp->wv_cnum = wvp->wv_tnum = wvp->wv_bnum =
wvp->wv_lnum = wvp->wv_rnum = wvp->wv_pnum = FNUMINIT;
/* set RECT pointers */
rpw = &wvp->wv_rwndw;
rpt = &wvp->wv_rtbb;
rpl = &wvp->wv_rlrb;
/* set FRAME pointers */
fpt = &wvp->wv_ftop;
fpb = &wvp->wv_fbtm;
fpl = &wvp->wv_flft;
fpr = &wvp->wv_frgt;
/* set origin indexes */
rpw->r_row = RMIN;
rpw->r_col = CMIN;
/* set lengths to largest size */
rpw->r_nrow = (wdp->wd_rmax) ? wdp->wd_rmax : cnrows;
rpw->r_ncol = (wdp->wd_cmax) ? wdp->wd_cmax : cncols;
/* adjust lengths to fit, error if not enough room */
while((rpw->r_row + rpw->r_nrow) > cnrows)
--rpw->r_nrow;
if((cnrows < rpw->r_nrow) || (rpw->r_nrow < wdp->wd_rmin))
utfarjmp(jmpbuf, (UR_SOURCE | UR_PARM));
while((rpw->r_col + rpw->r_ncol) > cncols)
--rpw->r_ncol;
if((cncols < rpw->r_ncol) || (rpw->r_ncol < wdp->wd_cmin))
utfarjmp(jmpbuf, (UR_SOURCE | UR_PARM));
/* check if borders desired */
if(wdp->wd_flags & W_BORDERS)
{
/* flag = 0 if no border attributes */
baflag = (wdp->wd_flags & W_ATTRIBS & pcns.pc_planes);
rpt->r_row = rpl->r_row = RMIN;
rpt->r_col = rpl->r_col = CMIN;
rpt->r_nrow = fpt->fr_nrow = fpb->fr_nrow = BRWIDTH;
rpl->r_ncol = fpl->fr_ncol = fpr->fr_ncol = BCWIDTH;
rpt->r_ncol = fpt->fr_ncol = fpb->fr_ncol = rpw->r_ncol;
/* adjust window RECT size for borders */
rpw->r_nrow -= (BRWIDTH * 2);
rpw->r_ncol -= (BCWIDTH * 2);
rpl->r_nrow = fpl->fr_nrow = fpr->fr_nrow = rpw->r_nrow;
fpt->fr_pl[PL_CHAR] = (BYTE *)topbuf;
fpb->fr_pl[PL_CHAR] = &wdp->wd_bfill;
fpl->fr_pl[PL_CHAR] = &wdp->wd_lfill;
fpr->fr_pl[PL_CHAR] = &wdp->wd_rfill;
fpt->fr_pl[PL_ATTR] = fpb->fr_pl[PL_ATTR] = fpl->fr_pl[PL_ATTR] =
fpr->fr_pl[PL_ATTR] = (baflag) ? &wdp->wd_battr : (LONG)0;
fpt->fr_pl[PL_EXTN] = fpb->fr_pl[PL_EXTN] = fpl->fr_pl[PL_EXTN] =
fpr->fr_pl[PL_EXTN] = (LONG)0;
fpt->fr_use = PL_USE0;
fpb->fr_use = fpl->fr_use = fpr->fr_use = (LONG)0;
}
if((vc == WNDWMSSG) || (vc == WNDWSTAT))
{
if(vc == WNDWMSSG)
{
wsp = &ws_mssg;
rpi = &r_minfoa;
rpm = &r_mmorea;
rpp = &r_mpmpta;
}
else
{
wsp = &ws_stat;
rpi = &r_sinfoa;
rpm = &r_smorea;
rpp = &r_spmpta;
}
wsp->ws_actinfo = rpw->r_nrow - wdp->wd_rmin + wsp->ws_mininfo;
if(wdp->wd_flags & W_BORDERS)
wsp->ws_actinfo += (BRWIDTH * 2);
rpi->r_col = rpm->r_col = rpp->r_col = rpw->r_col;
rpi->r_ncol = rpm->r_ncol = rpp->r_ncol = rpw->r_ncol;
rpi->r_row = rpw->r_row + wsp->ws_numhdr;
rpm->r_row = rpi->r_row + wsp->ws_actinfo;
rpp->r_row = rpm->r_row + wsp->ws_nummore;
rpp->r_row = (wvp->wv_wdp->wd_flags & W_PMPTHLP) ?
rpp->r_row : rpp->r_row + wsp->ws_numhelp;
rpi->r_nrow = wsp->ws_actinfo;
rpm->r_nrow = wsp->ws_nummore;
rpp->r_nrow = wsp->ws_numpmpt;
}
}
/* newvcon() : set up new virtual console */
VOID newvcon(vc)
REG WORD vc;
{
BYTE alterb[PL_NPLANE * 2];
BYTE specbuf[BUFSIZ];
REG BYTE rw, cw;
REG WORD dosflgs;
REG RECT *rpw;
REG WVARS *wvp;
REG VCONSOLE *vcp;
/* set pointers, mark as INUSE */
wvp = &(wvars[vc]);
vcp = &(wvp->wv_vct);
rpw = &(wvp->wv_rwndw);
wvp->wv_flags = WV_INUSE;
dosflgs = (A_SIZE | A_TEMP);
rw = (wvp->wv_wdp->wd_flags & W_BORDERS) ? BRWIDTH : 0;
cw = (wvp->wv_wdp->wd_flags & W_BORDERS) ? BCWIDTH : 0;
if((wvp->wv_vnum = s_vccreate(dosflgs, dcnum, rpw->r_nrow,
rpw->r_ncol, rw, rw, cw, cw)) < SUCCESS)
{
rcode = wvp->wv_vnum;
killvcon(vc);
return;
}
if((vc == WNDWMSSG) || (vc == WNDWSTAT))
{
if((rcode = s_order(ORD_BTM, wvp->wv_vnum)) < SUCCESS)
{
killvcon(vc);
return;
}
}
/* get virtual console information */
getvcinfo(vc);
/* set view parms to top/left */
vcp->vc_viewrow = RMIN;
vcp->vc_viewcol = CMIN;
/* set window size */
vcp->vc_nrow = rpw->r_nrow;
vcp->vc_ncol = rpw->r_ncol;
/* set position row/col */
vcp->vc_posrow = wvp->wv_wdp->wd_rorg;
vcp->vc_poscol = wvp->wv_wdp->wd_corg;
if(wvp->wv_wdp->wd_flags & W_BORDERS)
{
vcp->vc_posrow += BRWIDTH;
vcp->vc_poscol += BCWIDTH;
}
/* open console file */
bldspec(vc, (S_DEV|S_VCP|S_CON), specbuf);
if((wvp->wv_cnum = s_open((A_READ|A_WRITE|A_SET|A_SHARE|A_SHFP),
(LONG)specbuf)) < SUCCESS)
{
rcode = wvp->wv_cnum;
killvcon(vc);
return;
}
/* set flags for copy/alter */
dosflgs =
(pcns.pc_planes & wvp->wv_wdp->wd_flags & W_ATTRIBS) ?
(A_CHARPL|A_ATTRPL) : A_CHARPL;
alterb[ALB_CAND] = alterb[ALB_AAND] = alterb[ALB_EAND] =
alterb[ALB_EXOR] = 0;
/* handle borders if there */
if(wvp->wv_wdp->wd_flags & W_BORDERS)
{
/* open TOP */
bldspec(vc, (S_DEV|S_VCP|S_TOP), specbuf);
if((wvp->wv_tnum = s_open(A_WRITE, (LONG)specbuf)) < SUCCESS)
{
rcode = wvp->wv_tnum;
killvcon(vc);
return;
}
/* open BTM */
bldspec(vc, (S_DEV|S_VCP|S_BTM), specbuf);
if((wvp->wv_bnum = s_open(A_WRITE, (LONG)specbuf)) < SUCCESS)
{
rcode = wvp->wv_bnum;
killvcon(vc);
return;
}
/* open LFT */
bldspec(vc, (S_DEV|S_VCP|S_LFT), specbuf);
if((wvp->wv_lnum = s_open(A_WRITE, (LONG)specbuf)) < SUCCESS)
{
rcode = wvp->wv_lnum;
killvcon(vc);
return;
}
/* open RGT */
bldspec(vc, (S_DEV|S_VCP|S_RGT), specbuf);
if((wvp->wv_rnum = s_open(A_WRITE, (LONG)specbuf)) < SUCCESS)
{
rcode = wvp->wv_rnum;
killvcon(vc);
return;
}
/* center the top border header text */
if(center((rpw->r_ncol + (BCWIDTH * 2)), wvp->wv_wdp->wd_tbhdr,
topbuf, wvp->wv_wdp->wd_tfill))
{
rcode = (UR_SOURCE | UR_PARM);
killvcon(vc);
return;
}
/* copy TOP pattern */
if((rcode = s_copy(dosflgs, wvp->wv_tnum, (LONG)0,
(LONG)&(wvp->wv_rtbb), (LONG)&(wvp->wv_ftop),
(LONG)&(wvp->wv_rtbb))) < SUCCESS)
{
killvcon(vc);
return;
}
/* set BTM pattern */
alterb[ALB_CXOR] = wvp->wv_wdp->wd_bfill;
alterb[ALB_AXOR] = (dosflgs & A_ATTRPL) ? wvp->wv_wdp->wd_battr : 0;
if((rcode = s_alter(dosflgs, wvp->wv_bnum, (LONG)0,
(LONG)&(wvp->wv_rtbb), (LONG)alterb)) < SUCCESS)
{
killvcon(vc);
return;
}
/* set LFT pattern */
alterb[ALB_CXOR] = wvp->wv_wdp->wd_lfill;
alterb[ALB_AXOR] = (dosflgs & A_ATTRPL) ? wvp->wv_wdp->wd_battr : 0;
if((rcode = s_alter(dosflgs, wvp->wv_lnum, (LONG)0,
(LONG)&(wvp->wv_rlrb), (LONG)alterb)) < SUCCESS)
{
killvcon(vc);
return;
}
/* set RGT pattern */
alterb[ALB_CXOR] = wvp->wv_wdp->wd_rfill;
alterb[ALB_AXOR] = (dosflgs & A_ATTRPL) ? wvp->wv_wdp->wd_battr : 0;
if((rcode = s_alter(dosflgs, wvp->wv_rnum, (LONG)0,
(LONG)&(wvp->wv_rlrb), (LONG)alterb)) < SUCCESS)
{
killvcon(vc);
return;
}
}
/* clear the entire window */
alterb[ALB_CXOR] = wvp->wv_wdp->wd_wfill;
alterb[ALB_AXOR] = (dosflgs & A_ATTRPL) ? wvp->wv_wdp->wd_wattr : 0;
if((rcode = s_alter(dosflgs, wvp->wv_cnum, (LONG)0,
(LONG)&(wvp->wv_rwndw), (LONG)alterb)) < SUCCESS)
{
killvcon(vc);
return;
}
/* send out ESCAPE sequences for attributes */
setattrib(wvp);
/* close USER windows, shut off wrap on SPECIAL windows */
if((vc != WNDWMSSG) && (vc != WNDWSTAT))
{
s_close(0x0000, wvp->wv_cnum);
wvp->wv_cnum = FNUMINIT;
}
else
s_write(A_EOFOFF, wvp->wv_cnum, (LONG)wm9009, utslen(wm9009), (LONG)0);
/* set the vcon tbl with new values */
setvcinfo(vc);
}
/* wmshell() : fire off a shell for window */
VOID wmshell(vc)
REG WORD vc;
{
BYTE buf1[BUFSIZ], buf2[BUFSIZ];
REG WORD dosflgs;
PINFO p;
PROCESS proc;
REG WVARS *wvp;
wvp = &(wvars[vc]);
/* define new con: */
bldspec(vc, (S_DEV|S_VCP), buf1);
if((rcode = s_define(0x0000, (LONG)wm8000, (LONG)buf1,
utslen(buf1))) < SUCCESS)
{
killvcon(vc);
return;
}
/* NOTE: This causes STDIO to be redefined indirectly, since it is defined */
/* on entry to con:/console (which is also what "con" is defined as). */
/* get defined name for SHELL */
if((rcode = s_lookup(T_PNAME, 0x0000, (LONG)wm8100, (LONG)buf1,
(LONG)BUFSIZ, (LONG)BUFSIZ, (LONG)0)) < SUCCESS)
{
killvcon(vc);
return;
}
/* setup PINFO structure for COMMAND */
p.pi_addm = 0;
p.pi_maxm = PIMAXM;
p.pi_prior = SHLPRI;
utscopy(p.pi_pname, wm8100);
wvp->wv_pid = wvp->wv_fid = 0;
/* create and open message pipe */
bldspec(vc, S_PIP, buf2);
dosflgs = (A_SET|A_READ|A_SHARE|A_TEMP|A_SECURITY);
wvp->wv_pnum = s_create((BYTE)0x00, dosflgs, (LONG)buf2, 0x0000,
(FS_OD|FS_OE|FS_OW|FS_OR), CMAXL);
/* NOTE: CMAXL must be at least as large as an MPHDR structure. */
/* define wmessage = pipe name */