-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.c
More file actions
2180 lines (1924 loc) · 47.9 KB
/
display.c
File metadata and controls
2180 lines (1924 loc) · 47.9 KB
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
/*
* The functions in this file handle redisplay. There are two halves, the
* ones that update the virtual display screen, and the ones that make the
* physical display screen the same as the virtual display screen. These
* functions use hints that are left in the windows by the commands.
*
*/
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
NOSHARE VIDEO **vscreen; /* Virtual screen. */
#if SCROLL
NOSHARE VIDEO **vsave; /* Used for scrolling. */
#endif
#if MEMMAP == 0
static VIDEO **pscreen; /* Physical screen. */
#if SCROLL
static VIDEO **psave; /* Used for scrolling. */
#endif
#endif
NOSHARE int didlins, didldel;
static int curcol; /* Cursor column */
/* define the character mapping table */
#if DISPSEVEN | DECEDT
NOSHARE int me_char_len[256]; /* length of charname entries */
CONST char FAR *me_char_name[256] = {
/* 0 0 */ "^@",
/* 1 1 */ "^A",
/* 2 2 */ "^B",
/* 3 3 */ "^C",
/* 4 4 */ "^D",
/* 5 5 */ "^E",
/* 6 6 */ "^F",
/* 7 7 */ "^G",
/* 8 8 */ "^H",
/* 9 9 */ "^I",
/* 10 a */ "^J",
/* 11 b */ "^K",
/* 12 c */ "^L",
/* 13 d */ "^M",
/* 14 e */ "^N",
/* 15 f */ "^O",
/* 16 10 */ "^P",
/* 17 11 */ "^Q",
/* 18 12 */ "^R",
/* 19 13 */ "^S",
/* 20 14 */ "^T",
/* 21 15 */ "^U",
/* 22 16 */ "^V",
/* 23 17 */ "^W",
/* 24 18 */ "^X",
/* 25 19 */ "^Y",
/* 26 1a */ "^Z",
/* 27 1b */ "^[",
/* 28 1c */ "^\\",
/* 29 1d */ "^]",
/* 30 1e */ "^^",
/* 31 1f */ "^_",
/* 32 20 */ " ",
/* 33 21 */ "!",
/* 34 22 */ "\"",
/* 35 23 */ "#",
/* 36 24 */ "$",
/* 37 25 */ "%",
/* 38 26 */ "&",
/* 39 27 */ "'",
/* 40 28 */ "(",
/* 41 29 */ ")",
/* 42 2a */ "*",
/* 43 2b */ "+",
/* 44 2c */ ",",
/* 45 2d */ "-",
/* 46 2e */ ".",
/* 47 2f */ "/",
/* 48 30 */ "0",
/* 49 31 */ "1",
/* 50 32 */ "2",
/* 51 33 */ "3",
/* 52 34 */ "4",
/* 53 35 */ "5",
/* 54 36 */ "6",
/* 55 37 */ "7",
/* 56 38 */ "8",
/* 57 39 */ "9",
/* 58 3a */ ":",
/* 59 3b */ ";",
/* 60 3c */ "<",
/* 61 3d */ "=",
/* 62 3e */ ">",
/* 63 3f */ "?",
/* 64 40 */ "@",
/* 65 41 */ "A",
/* 66 42 */ "B",
/* 67 43 */ "C",
/* 68 44 */ "D",
/* 69 45 */ "E",
/* 70 46 */ "F",
/* 71 47 */ "G",
/* 72 48 */ "H",
/* 73 49 */ "I",
/* 74 4a */ "J",
/* 75 4b */ "K",
/* 76 4c */ "L",
/* 77 4d */ "M",
/* 78 4e */ "N",
/* 79 4f */ "O",
/* 80 50 */ "P",
/* 81 51 */ "Q",
/* 82 52 */ "R",
/* 83 53 */ "S",
/* 84 54 */ "T",
/* 85 55 */ "U",
/* 86 56 */ "V",
/* 87 57 */ "W",
/* 88 58 */ "X",
/* 89 59 */ "Y",
/* 90 5a */ "Z",
/* 91 5b */ "[",
/* 92 5c */ "\\",
/* 93 5d */ "]",
/* 94 5e */ "^",
/* 95 5f */ "_",
/* 96 60 */ "`",
/* 97 61 */ "a",
/* 98 62 */ "b",
/* 99 63 */ "c",
/* 100 64 */ "d",
/* 101 65 */ "e",
/* 102 66 */ "f",
/* 103 67 */ "g",
/* 104 68 */ "h",
/* 105 69 */ "i",
/* 106 6a */ "j",
/* 107 6b */ "k",
/* 108 6c */ "l",
/* 109 6d */ "m",
/* 110 6e */ "n",
/* 111 6f */ "o",
/* 112 70 */ "p",
/* 113 71 */ "q",
/* 114 72 */ "r",
/* 115 73 */ "s",
/* 116 74 */ "t",
/* 117 75 */ "u",
/* 118 76 */ "v",
/* 119 77 */ "w",
/* 120 78 */ "x",
/* 121 79 */ "y",
/* 122 7a */ "z",
/* 123 7b */ "{",
/* 124 7c */ "|",
/* 125 7d */ "}",
/* 126 7e */ "~",
/* 127 7f */ "^?",
/* 128 80 */ "^!@",
/* 129 81 */ "^!A",
/* 130 82 */ "^!B",
/* 131 83 */ "^!C",
/* 132 84 */ "^!D",
/* 133 85 */ "^!E",
/* 134 86 */ "^!F",
/* 135 87 */ "^!G",
/* 136 88 */ "^!H",
/* 137 89 */ "^!I",
/* 138 8a */ "^!J",
/* 139 8b */ "^!K",
/* 140 8c */ "^!L",
/* 141 8d */ "^!M",
/* 142 8e */ "^!N",
/* 143 8f */ "^!O",
/* 144 90 */ "^!P",
/* 145 91 */ "^!Q",
/* 146 92 */ "^!R",
/* 147 93 */ "^!S",
/* 148 94 */ "^!T",
/* 149 95 */ "^!U",
/* 150 96 */ "^!V",
/* 151 97 */ "^!W",
/* 152 98 */ "^!X",
/* 153 99 */ "^!Y",
/* 154 9a */ "^!Z",
/* 155 9b */ "^![",
/* 156 9c */ "^!\\",
/* 157 9d */ "^!]",
/* 158 9e */ "^!^",
/* 159 9f */ "^!_",
/* 160 a0 */ "{NB space}",
/* 161 a1 */ "{!!}", /* inverted ! */
/* 162 a2 */ "{cc}", /* cent */
/* 163 a3 */ "{LL}", /* pound */
/* 164 a4 */ "{ll}", /* loz */
/* 165 a5 */ "{y_}", /* yen */
/* 166 a6 */ "{||}", /* pipe */
/* 167 a7 */ "{SS}", /* section */
/* 168 a8 */ "{\"\"}", /* uml */
/* 169 a9 */ "{C*}", /* (C) */
/* 170 aa */ "{a_}",
/* 171 ab */ "{<<}",
/* 172 ac */ "{|_}", /* not */
/* 173 ad */ "{Soft Hyp}",
/* 174 ae */ "{R*}", /* (R) */
/* 175 af */ "{__}", /* macr */
/* 176 b0 */ "{0^}",
/* 177 b1 */ "{+-}",
/* 178 b2 */ "{2^}",
/* 179 b3 */ "{3^}",
/* 180 b4 */ "{''}", /* acute */
/* 181 b5 */ "{m,}", /* mu */
/* 182 b6 */ "{PP}", /* paragraph */
/* 183 b7 */ "{**}", /* small bullet */
/* 184 b8 */ "{,,}", /* ced */
/* 185 b9 */ "{1^}",
/* 186 ba */ "{o_}",
/* 187 bb */ "{>>}",
/* 188 bc */ "{1/4}",
/* 189 bd */ "{1/2}",
/* 190 be */ "{3/4}",
/* 191 bf */ "{??}", /* inverted ? */
/* 192 c0 */ "{A`}",
/* 193 c1 */ "{A'}",
/* 194 c2 */ "{A^}",
/* 195 c3 */ "{A~}",
/* 196 c4 */ "{A\"}",
/* 197 c5 */ "{A*}",
/* 198 c6 */ "{AE}",
/* 199 c7 */ "{C,}",
/* 200 c8 */ "{E`}",
/* 201 c9 */ "{E'}",
/* 202 ca */ "{E^}",
/* 203 cb */ "{E\"}",
/* 204 cc */ "{I`}",
/* 205 cd */ "{I'}",
/* 206 ce */ "{I^}",
/* 207 cf */ "{I\"}",
/* 208 d0 */ "{D_}",
/* 209 d1 */ "{N~}",
/* 210 d2 */ "{O`}",
/* 211 d3 */ "{O'}",
/* 212 d4 */ "{O^}",
/* 213 d5 */ "{O~}",
/* 214 d6 */ "{O\"}",
/* 215 d7 */ "{xx}", /* cross */
/* 216 d8 */ "{O/}",
/* 217 d9 */ "{U`}",
/* 218 da */ "{U'}",
/* 219 db */ "{U^}",
/* 220 dc */ "{U\"}",
/* 221 dd */ "{Y'}",
/* 222 de */ "{T_}", /* TH */
/* 223 df */ "{ss}",
/* 224 e0 */ "{a`}",
/* 225 e1 */ "{a'}",
/* 226 e2 */ "{a^}",
/* 227 e3 */ "{a~}",
/* 228 e4 */ "{a\"}",
/* 229 e5 */ "{a*}",
/* 230 e6 */ "{ae}",
/* 231 e7 */ "{c,}",
/* 232 e8 */ "{e`}",
/* 233 e9 */ "{e'}",
/* 234 ea */ "{e^}",
/* 235 eb */ "{e\"}",
/* 236 ec */ "{i`}",
/* 237 ed */ "{i'}",
/* 238 ee */ "{i^}",
/* 239 ef */ "{i\"}",
/* 240 f0 */ "{d_}",
/* 241 f1 */ "{n~}",
/* 242 f2 */ "{o`}",
/* 243 f3 */ "{o'}",
/* 244 f4 */ "{o^}",
/* 245 f5 */ "{o~}",
/* 246 f6 */ "{o\"}",
/* 247 f7 */ "{//}", /* division */
/* 248 f8 */ "{o/}",
/* 249 f9 */ "{u`}",
/* 250 fa */ "{u'}",
/* 251 fb */ "{u^}",
/* 252 fc */ "{u\"}",
/* 253 fd */ "{y'}",
/* 254 fe */ "{t_}", /* th */
/* 255 ff */ "^!?"
} ;
#endif
#define fastputc(c) TTputc(c)
/* these declarations must match termio.c */
#if VMS & ~WINMOD
NOSHARE extern char obuf[NOBUF]; /* Output buffer */
NOSHARE extern int nobuf; /* # of bytes in above */
#undef fastputc
#define fastputc(c) {if (nobuf >= NOBUF) ttflush(); obuf[nobuf++] = (c);}
#endif
#if (V7 | USG | BSD) & ~WINMOD
#undef fastputc
#define fastputc(c) putc((c), stdout)
#endif
#if SCROLL & COLOR
NOSHARE extern int usedcolor;
#endif
NOSHARE extern int termflag;
static VOID updall PP((WINDOW *wp));
static VOID upddex PP((void));
static VOID updgar PP((void));
static VOID updext PP((void));
static VOID updone PP((WINDOW *wp));
static VOID updscroll PP((WINDOW *wp));
static VOID updpos PP((void));
static int updupd PP((int force));
static int reframe PP((WINDOW *wp));
static VOID mlputli PP((long l, int r, int len));
static VOID mlputi PP((int i, int r, int len));
static VOID vteeol PP((void));
static VOID vtmove PP((int row, int col));
static VOID vtputc PP((int c));
static VOID vtputl PP((LINE *lp));
static int vtputs PP((CONSTA char *s));
static VOID modeline PP((WINDOW *wp));
#if MEMMAP
static VOID lupdate PP((int row, VIDEO *vp1));
#else
static VOID lupdate PP((int row, VIDEO *vp1, VIDEO *vp2));
#endif
/*
* Initialize the data structures used by the display code. The edge vectors
* used to access the screens are set up. The operating system's terminal I/O
* channel is set up. All the other things get initialized at compile time.
* The original window has "WFCHG" set, so that it will get completely
* redrawn on the first call to "update".
*/
VOID vtinit()
{
register int i;
register VIDEO *vp;
int video_size;
static VIDEO *vpsave;
#if MEMMAP == 0
register VIDEO *vm;
static VIDEO *vmsave;
#endif
#if DISPSEVEN | DECEDT
for (i = 0; i < 256; i++) me_char_len[ i ] = (int) strlen(me_char_name[ i ]);
#endif
TTopen(); /* open the screen */
TTkopen(); /* open the keyboard */
TTrev(FALSE);
if (firstflag) {
vscreen = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
#if SCROLL
vsave = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
#endif
}
if (vscreen == NULL) exit(1);
#if SCROLL
if (vsave == NULL) exit(1);
#endif
#if MEMMAP == 0
if (firstflag) {
pscreen = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
#if SCROLL
psave = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
#endif
}
if (pscreen == NULL) exit(1);
#if SCROLL
if (psave == NULL) exit(1);
#endif
#endif
video_size = sizeof(VIDEO);
if (term.t_mcol > V_TEXT_SIZE)
video_size = video_size + term.t_mcol - V_TEXT_SIZE;
video_size = ((video_size - 1) | (sizeof(int) - 1)) + 1;
if (firstflag) {
vpsave = (VIDEO *) malloc(term.t_mrow*video_size);
#if MEMMAP == 0
vmsave = (VIDEO *) malloc(term.t_mrow*video_size);
#endif
}
vp = vpsave;
#if MEMMAP == 0
vm = vmsave;
#endif
for (i = 0; i < term.t_mrow; ++i)
{
if (vp == NULL)
exit(1);
vp->v_flag = 0;
#if COLOR
vp->v_rfcolor = 7;
vp->v_rbcolor = 0;
#endif
vscreen[i] = vp;
vp = (VIDEO *) (((char *)vp) + video_size);
#if MEMMAP == 0
if (vm == NULL)
exit(1);
vm->v_flag = 0;
pscreen[i] = vm;
vm = (VIDEO *) (((char *)vm) + video_size);
#endif
}
}
/*
* Clean up the virtual terminal system, in anticipation for a return to the
* operating system. Move down to the last line and clear it out (the next
* system prompt will be written in the line). Shut down the channel to the
* terminal.
*/
VOID vttidy()
{
#if SCROLL
ttscroll(0, term.t_nrow, 0);
#endif
mlerase();
movecursor(term.t_nrow, 0);
TTflush();
TTclose();
TTkclose();
}
/*
* Set the virtual cursor to the specified row and column on the virtual
* screen. There is no checking for nonsense values; this might be a good
* idea during the early stages.
*/
static VOID vtmove(row, col)
int row, col;
{
vtrow = row;
vtcol = col;
}
/* Write a character to the virtual screen. The virtual row and
column are updated. If we are not yet on left edge, don't print
it yet. If the line is too long put a "$" in the last column.
This routine only puts printing characters into the virtual
terminal buffers. Only column overflow is checked.
*/
static VOID vtputc(c)
int c;
{
register VIDEO *vp; /* ptr to line being updated */
#if DISPSEVEN
CONST char *s;
#endif
vp = vscreen[vtrow];
if (c == '\t') {
do {
vtputc(' ');
} while (((vtcol + taboff) % tabsize) != 0);
} else if (vtcol >= term.t_ncol) {
++vtcol;
vp->v_text[term.t_ncol - 1] = '$';
#if DISPSEVEN
} else if (dispseven) {
if (c >= 0x20 && c < 0x7F) {
if (vtcol >= 0) vp->v_text[vtcol] = (char) c;
++vtcol;
} else {
s = me_char_name[ c & 0xFF ];
while (*s != '\0') {
if (vtcol >= term.t_ncol) {
++vtcol;
vp->v_text[term.t_ncol - 1] = '$';
break;
}
if (vtcol >= 0) vp->v_text[vtcol] = *s;
vtcol++;
s++;
}
}
#endif
} else if ((c&0x7F) < 0x20 || (c&0x7F) == 0x7F ||
(disphigh && ((c&0x80) != 0))) {
vtputc('^');
if (disphigh && ((c&0x80) != 0)) vtputc('!');
vtputc((c&0x7F) ^ 0x40);
} else {
if (vtcol >= 0)
vp->v_text[vtcol] = (char) c;
++vtcol;
}
}
/* Write a line to the virtual screen. Does equivalent of
for (j=0; j<llength(lp); ++j) vtputc(lgetc(lp, j));
*/
static VOID vtputl(lp)
LINE *lp; /* line to update */
{
register VIDEO *vp; /* ptr to line being updated */
register int i, c;
#if DISPSEVEN
CONST char *s;
#endif
vp = vscreen[vtrow];
for (i = 0; i < llength(lp); ++i) {
c = lgetc(lp, i);
if (c == '\t') {
do {
if (vtcol >= term.t_ncol) {
vp->v_text[term.t_ncol - 1] = '$';
return;
} else {
if (vtcol >= 0)
vp->v_text[vtcol] = ' ';
++vtcol;
}
} while (((vtcol + taboff) % tabsize) != 0);
} else if (vtcol >= term.t_ncol) {
vp->v_text[term.t_ncol - 1] = '$';
return;
} else if (c < 0x20 || c >= 0x7F) {
#if DISPSEVEN
if (dispseven) {
s = me_char_name[ c&0xFF ];
while (*s != '\0') {
if (vtcol >= term.t_ncol) {
++vtcol;
vp->v_text[term.t_ncol-1] = '$';
return;
}
if (vtcol >= 0) vp->v_text[vtcol] = *s;
vtcol++;
s++;
}
continue; /* skip extra vtcol increment */
}
#endif
if ((c&0x7F) < 0x20 || (c&0x7F) == 0x7F ||
(disphigh && ((c&0x80) != 0))) {
if (vtcol >= 0) vp->v_text[vtcol] = '^';
++vtcol;
if (disphigh && ((c&0x80) != 0) &&
vtcol < term.t_ncol) {
if (vtcol >= 0) vp->v_text[vtcol] = '!';
++vtcol;
}
if (vtcol >= term.t_ncol) {
vp->v_text[term.t_ncol - 1] = '$';
return;
} else if (vtcol >= 0)
vp->v_text[vtcol] =
(char) ((c&0x7F) ^ 0x40);
} else if (vtcol >= 0)
vp->v_text[vtcol] = (char) c;
++vtcol;
} else {
if (vtcol >= 0)
vp->v_text[vtcol] = (char) c;
++vtcol;
}
}
}
/* Write a string to the virtual screen and return its length */
static int vtputs(s)
CONSTA char *s;
{
register VIDEO *vp; /* ptr to line being updated */
register int i;
vp = vscreen[vtrow];
for (i = 0; *s != '\0' && vtcol < term.t_ncol; ++i) {
if (vtcol >= 0) vp->v_text[vtcol] = *(s++);
++vtcol;
}
return(i);
}
/*
* Erase from the end of the software cursor to the end of the line on which
* the software cursor is located.
*/
static VOID vteeol()
{
register VIDEO *vp;
vp = vscreen[vtrow];
if (vtcol < 0) vtcol = 0;
while (vtcol < term.t_ncol)
vp->v_text[vtcol++] = ' ';
}
/* upscreen: user routine to force a screen update
always finishes complete update */
int upscreen(f, n)
int f, n;
{
UNUSED_ARGS_FN;
update(TRUE);
return(TRUE);
}
/*
* Make sure that the display is right. This is a three part process. First,
* scan through all of the windows looking for dirty ones. Check the framing,
* and refresh the screen. Second, make sure that "currow" and "curcol" are
* correct for the current window. Third, make the virtual and physical
* screens the same.
* force == HOOK like FALSE, but also does not update cursor
* (for edt page scrolling)
*/
int update(force)
int force; /* force update past type ahead? */
{
register WINDOW *wp;
#if TYPEAH
if (force != TRUE && typahead())
return(TRUE);
#endif
#if VISMAC == 0
if (force != TRUE && kbdmode == PLAY)
return(TRUE);
#endif
/* update any windows that need refreshing */
wp = wheadp;
while (wp != NULL) {
if (wp->w_flag) {
/* if the window has changed, service it */
reframe(wp); /* check the framing */
if ((wp->w_flag & ~WFMODE) == WFEDIT)
updone(wp); /* update EDITed line */
else if ((wp->w_flag & ~(WFMODE | WFMOVE)) == WFSCROL)
updscroll(wp);
else if (wp->w_flag & ~WFMOVE)
updall(wp); /* update all lines */
if (wp->w_flag & WFMODE)
modeline(wp); /* update modeline */
wp->w_flag = 0;
wp->w_force = 0;
}
/* on to the next window */
wp = wp->w_wndp;
}
/* recalc the current hardware cursor location */
updpos();
#if MEMMAP
/* update the cursor and flush the buffers */
movecursor(currow, curcol - lbound);
#endif
/* check for lines to de-extend */
upddex();
/* if screen is garbage, re-plot it */
if (sgarbf != FALSE)
updgar();
/* update the virtual screen to the physical screen */
if (updupd(force) != ABORT) {
/* update the cursor and flush the buffers */
#if MEMMAP | RAINBOW
#else
/* Fast way to move the cursor a little bit */
if (ttrow == currow &&
ttcol < curcol - lbound &&
ttcol + 5 > curcol - lbound) {
#if COLOR
TTforg(vscreen[currow]->v_rfcolor);
TTbacg(vscreen[currow]->v_rbcolor);
#endif
do {fastputc(pscreen[currow]->v_text[ttcol]);++ttcol;}
while (ttcol < curcol - lbound);
}
#endif
if (force != HOOK)
movecursor(currow, curcol - lbound);
}
if (force != HOOK) TTflush();
return(TRUE);
}
/* reframe: check to see if the cursor is on in the window
and re-frame it if needed or wanted */
static int reframe(wp)
WINDOW *wp;
{
register LINE *lp, *blp;
register int i;
int scrolled;
#if SCROLL
register LINE *slp;
int top, bot, j, k;
VIDEO *vp;
#endif
scrolled = 0;
blp = wp->w_bufp->b_linep; /* last line of buffer */
/* if not a requested reframe, check for a needed one */
if ((wp->w_flag & WFFORCE) == 0) {
lp = wp->w_linep;
for (i = 0; i < wp->w_ntrows; i++) {
/* if the line is in the window, no reframe */
if (lp == wp->w_dotp)
return(TRUE);
/* if we are at the end of the file, reframe */
if (lp == blp)
break;
/* on to the next line */
lp = lforw(lp);
}
}
/* reaching here, we need a window refresh */
i = wp->w_force;
/* how far back to reframe? */
if (i > 0) { /* only one screen worth of lines max */
if (--i >= wp->w_ntrows)
i = wp->w_ntrows - 1;
} else if (i < 0) { /* negative update???? */
i += wp->w_ntrows;
if (i < 0)
i = 0;
} else
i = wp->w_ntrows / 2;
/* backup to new line at top of window */
lp = wp->w_dotp;
while (i != 0 && lback(lp) != blp) {
--i;
lp = lback(lp);
}
#if SCROLL
if (isvt100 && (termflag&2) == 0) {
/* backup to get end of buffer on last line */
i = wp->w_ntrows - 2;
if (lp != blp) {
slp = lp;
if (wp->w_dotp != blp)
slp = lforw(slp);
if (slp != blp)
while(i > 0 && lforw(slp) != blp) {
--i;
slp = lforw(slp);
}
while(i > 0 && lback(lp) != blp) {
--i;
lp = lback(lp);
}
}
}
/* check if scrolling possible */
if (sgarbf == FALSE && isvt100 == TRUE && wp->w_ntrows > 2 &&
(termflag&2) == 0) {
slp = wp->w_linep;
i = 0;
while (i < wp->w_ntrows && slp != lp && slp != blp)
{++i; slp = lforw(slp);}
if (slp != lp) {
slp = wp->w_linep;
i = 0;
while (-i < wp->w_ntrows && slp != lp && slp != blp)
{--i; slp = lback(slp);}
}
scrolled = (slp == lp);
if (slp == lp && i != 0) {
top = wp->w_toprow + menuflag;
bot = top + wp->w_ntrows - 1;
ttscroll(top, bot, i);
if (i > 0) { /* scroll page up */
for (j = top; j < top + i; j++) {
vp = pscreen[j];
psave[bot + top - j] = vp;
vsave[bot + top - j] = vscreen[j];
vsave[bot + top - j]->v_flag |= VFSCROL;
for(k = 0; k < term.t_ncol; k++)
vp->v_text[k] = ' ';
#if COLOR
if (usedcolor) {
vp = vscreen[j];
vp->v_fcolor = 7;
vp->v_bcolor = 0;
vp->v_flag |= VFCHG | VFCOL;
}
#endif
}
for (j = top + i; j <= bot; j++) {
psave[j - i] = pscreen[j];
vsave[j - i] = vscreen[j];
}
}
else { /* scroll page down */
i = -i;
for (j = bot + 1 - i; j <= bot; j++) {
vp = pscreen[j];
psave[bot + top - j] = vp;
vsave[bot + top - j] = vscreen[j];
vsave[bot + top - j]->v_flag |= VFSCROL;
for(k = 0; k < term.t_ncol; k++)
vp->v_text[k] = ' ';
#if COLOR
if (usedcolor) {
vp = vscreen[j];
vp->v_fcolor = 7;
vp->v_bcolor = 0;
vp->v_flag |= VFCHG | VFCOL;
}
#endif
}
for (j = top; j < bot + 1 - i; j++) {
psave[j + i] = pscreen[j];
vsave[j + i] = vscreen[j];
}
}
for (j = top; j <= bot; j++) {
pscreen[j] = psave[j];
vscreen[j] = vsave[j];
}
}
}
#endif
/* and reset the current line at top of window */
wp->w_linep = lp;
if (scrolled) {
wp->w_flag |= WFSCROL;
if (wheadp->w_wndp == NULL) didlins = didldel = 0;
}
else wp->w_flag |= WFHARD;
wp->w_flag &= ~WFFORCE;
return(TRUE);
}
/* updone: update the current line to the virtual screen */
static VOID updone(wp)
WINDOW *wp; /* window to update current line in */
{
register LINE *lp; /* line to update */
register int sline; /* physical screen line to update */
/* search down the line we want */
lp = wp->w_linep;
sline = wp->w_toprow + menuflag;
while (lp != wp->w_dotp) {
++sline;
lp = lforw(lp);
}
/* and update the virtual line */
vscreen[sline]->v_flag |= VFCHG;
vscreen[sline]->v_flag &= ~VFREQ;
taboff = wp->w_fcol;
vtmove(sline, -taboff);
vtputl(lp);
#if COLOR
vscreen[sline]->v_rfcolor = wp->w_fcolor;
vscreen[sline]->v_rbcolor = wp->w_bcolor;
#endif
vteeol();
taboff = 0;
}
/* updscroll: update scrolled lines in a window on the virtual screen */
static VOID updscroll(wp)
WINDOW *wp; /* window to update lines in */
{
register LINE *lp; /* line to update */
register int sline; /* physical screen line to update */
/* search down the lines, updating them */
lp = wp->w_linep;
sline = wp->w_toprow + menuflag;
while (sline < wp->w_toprow + wp->w_ntrows + menuflag) {
if (vscreen[sline]->v_flag & VFSCROL) {
vscreen[sline]->v_flag |= VFCHG;
vscreen[sline]->v_flag &= ~VFREQ;
taboff = wp->w_fcol;
vtmove(sline, -taboff);
if (lp != wp->w_bufp->b_linep) vtputl(lp);
#if COLOR
vscreen[sline]->v_rfcolor = wp->w_fcolor;
vscreen[sline]->v_rbcolor = wp->w_bcolor;
#endif
vteeol();
}
if (lp != wp->w_bufp->b_linep) lp = lforw(lp);
++sline;
}
}
/* updall: update all the lines in a window on the virtual screen */
static VOID updall(wp)
WINDOW *wp; /* window to update lines in */
{
register LINE *lp; /* line to update */
register int sline; /* physical screen line to update */
#if MENUS
/* menu line */
if (menuflag) {
vscreen[0]->v_flag |= (VFCHG | VFREQ);
taboff = 0;
vtmove(0, 0);
vtputl(menuline);
#if COLOR
vscreen[0]->v_rfcolor = gbcolor;
vscreen[0]->v_rbcolor = gfcolor;
#endif
vteeol();
}
#endif
/* search down the lines, updating them */
lp = wp->w_linep;
sline = wp->w_toprow + menuflag;
while (sline < wp->w_toprow + wp->w_ntrows + menuflag) {
/* and update the virtual line */
vscreen[sline]->v_flag |= VFCHG;
vscreen[sline]->v_flag &= ~VFREQ;
taboff = wp->w_fcol;
vtmove(sline, -taboff);
if (lp != wp->w_bufp->b_linep) {
/* if we are not at the end */
vtputl(lp);
lp = lforw(lp);
}
/* on to the next one */
#if COLOR
vscreen[sline]->v_rfcolor = wp->w_fcolor;
vscreen[sline]->v_rbcolor = wp->w_bcolor;
#endif
vteeol();
++sline;