forked from ffimnsr-archive/ex-vi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_vadj.c
1162 lines (1087 loc) · 27.6 KB
/
ex_vadj.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
/*
* This code contains changes by
* Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
*
* Conditions 1, 2, and 4 and the no-warranty notice below apply
* to these changes.
*
*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* Redistributions of source code and documentation must retain the
* above copyright notice, this list of conditions and the following
* disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed or owned by Caldera
* International, Inc.
* Neither the name of Caldera International, Inc. nor the names of
* other contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
* INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
* LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
#ifdef DOSCCS
static char sccsid[] = "@(#)ex_vadj.c 1.11 (gritter) 3/4/05";
#endif
#endif
/* from ex_vadj.c 7.9 (Berkeley) 6/7/85 */
#include "ex.h"
#include "ex_tty.h"
#include "ex_vis.h"
/*
* Routines to deal with management of logical versus physical
* display, opening and redisplaying lines on the screen, and
* use of intelligent terminal operations. Routines to deal with
* screen cleanup after a change.
*/
/*
* Display a new line at physical line p, returning
* the depth of the newly displayed line. We may decide
* to expand the window on an intelligent terminal if it is
* less than a full screen by deleting a line above the top of the
* window before doing an insert line to keep all the good text
* on the screen in which case the line may actually end up
* somewhere other than line p.
*/
void
vopen(line *tp, int p)
{
register int cnt;
register struct vlinfo *vp, *vpc;
#ifdef ADEBUG
if (trace != NULL)
tfixnl(), fprintf(trace, "vopen(%d, %d)\n", lineno(tp), p);
#endif
if (state != VISUAL) {
if (vcnt)
if (hold & HOLDROL)
vup1();
else
vclean();
/*
* Forget all that we once knew.
*/
vcnt = vcline = 0;
p = WBOT; LASTLINE = WBOT + 1;
state = bastate;
WTOP = basWTOP;
WLINES = basWLINES;
}
vpc = &vlinfo[vcline];
for (vp = &vlinfo[vcnt]; vp >= vpc; vp--)
vlcopy(vp[1], vp[0]);
vcnt++;
if (Pline == numbline)
/*
* Dirtying all the lines is rather inefficient
* internally, but number mode is used rarely
* and so its not worth optimizing.
*/
vdirty(vcline+1, WECHO);
getline(*tp);
/*
* If we are opening at the top of the window, can try a window
* expansion at the top.
*/
if (state == VISUAL && vcline == 0 && vcnt > 1 && p > ZERO) {
cnt = p + vdepth() - LINE(1);
if (cnt > 0) {
p -= cnt;
if (p < ZERO)
p = ZERO;
WTOP = p;
WLINES = WBOT - WTOP + 1;
}
}
vpc->vliny = p, vpc->vdepth = 0, vpc->vflags = 0;
cnt = vreopen(p, lineno(tp), vcline);
if (vcline + 1 == vcnt)
LINE(vcnt) = LINE(vcline) + cnt;
}
/*
* Redisplay logical line l at physical line p with line number lineno.
*/
int
vreopen(int p, int lineno, int l)
{
register int d;
register struct vlinfo *vp = &vlinfo[l];
if (p < 0)
error("Line too long to fit on screen");
d = vp->vdepth;
if (d == 0 || (vp->vflags & VDIRT))
vp->vdepth = d = vdepth();
vp->vliny = p, vp->vflags &= ~VDIRT;
/*
* Try to win by making the screen larger rather than inserting
* a line and driving text off the bottom.
*/
p = vglitchup(l, 0);
/*
* BUG: Should consider using CE here to clear to end of line.
* As it stands we always strike over the current text.
* Since often the current text is the same as what
* we are overstriking with, it tends not to show.
* On the other hand if it is different and we end up
* spacing out a lot of text, we could have won with
* a CE. This is probably worthwhile at low speed
* only however, since clearly computation will be
* necessary to determine which way to go.
*/
vigoto(p, 0);
pline(lineno);
/*
* When we are typing part of a line for hardcopy open, don't
* want to type the '$' marking an end of line if in list mode.
*/
if (hold & HOLDDOL)
return (d);
if (Putchar == listchar)
putchar('$');
/*
* Optimization of cursor motion may prevent screen rollup if the
* line has blanks/tabs at the end unless we force the cursor to appear
* on the last line segment.
*/
if (vp->vliny + d - 1 > WBOT)
vcsync();
/*
* Switch into hardcopy open mode if we are in one line (adm3)
* open mode and this line is now too long. If in hardcopy
* open mode, then call sethard to move onto the next line
* with appropriate positioning.
*/
if (state == ONEOPEN) {
WCOLS = OCOLUMNS;
if (vdepth() > 1) {
WCOLS = TUBECOLS;
sethard();
} else
WCOLS = TUBECOLS;
} else if (state == HARDOPEN)
sethard();
/*
* Unless we filled (completely) the last line we typed on,
* we have to clear to the end of the line
* in case stuff is left from before.
*/
if (vp->vliny + d > destline) {
if (IN && destcol == WCOLS)
vigoto(vp->vliny + d - 1, 0);
vclreol();
}
return (d);
}
/*
* Real work for winning growing of window at top
* when inserting in the middle of a partially full
* screen on an intelligent terminal. We have as argument
* the logical line number to be inserted after, and the offset
* from that line where the insert will go.
* We look at the picture of depths and positions, and if we can
* delete some (blank) lines from the top of the screen so that
* later inserts will not push stuff off the bottom.
*/
int
vglitchup(int l, int o)
{
register struct vlinfo *vp = &vlinfo[l];
register int need;
register int p = vp->vliny;
short oldhold = 0, oldheldech = 0;
bool glitched = 0;
if (l < vcnt - 1) {
need = p + vp->vdepth - (vp+1)->vliny;
if (need > 0) {
if (state == VISUAL && WTOP - ZERO >= need && AL && DL) {
glitched++;
WTOP -= need;
WLINES = WBOT - WTOP + 1;
p -= need;
if (p + o == WTOP) {
vp->vliny = WTOP;
return (WTOP + o);
}
vdellin(WTOP, need, -1);
oldheldech = heldech;
oldhold = hold;
hold |= HOLDECH;
}
vinslin((vp+1)->vliny, need, l);
if (glitched) {
hold = oldhold;
heldech = oldheldech;
}
}
} else
vp[1].vliny = vp[0].vliny + vp->vdepth;
return (p + o);
}
/*
* Insert cnt blank lines before line p,
* logically and (if supported) physically.
*/
void
vinslin(register int p, register int cnt, int l)
{
register int i;
bool could = 1;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vinslin(%d, %d, %d)\n", p, cnt, l);
#endif
if (p + cnt > WBOT && CD) {
/*
* Really quick -- clear to end of screen.
*/
cnt = WECHO + 1 - p;
vgoto(p, 0), vputp(CD, cnt);
vclrech(1);
vadjAL(p, cnt);
} else if (SR && p == WTOP && costSR < costAL) {
/*
* Use reverse scroll mode of the terminal, at
* the top of the window. Reverse linefeed works
* too, since we only use it from line WTOP.
*/
for (i = cnt; i > 0; i--) {
vgoto(p, 0), vputp(SR, 0);
if (i > 1 && (hold & HOLDAT) == 0)
putchar('@');
/*
* If we are at the top of the screen, and the
* terminal retains display above, then we
* should try to clear to end of line.
* Have to use CE since we don't remember what is
* actually on the line.
*/
if (CE && (DA || p != 0))
vputp(CE, 1);
}
vadjAL(p, cnt);
} else if (AL) {
/*
* Use insert line.
*/
vgoto(p, 0);
if (AL_PARM && (cnt>1 || *AL==0)) {
/* insert cnt lines. Should do @'s too. */
vputp(tgoto(AL_PARM, p, cnt), WECHO+1-p);
}
else if (xCS && *AL==0) {
/* vt100 change scrolling region to fake AL */
vputp(SC, 1);
vputp(tgoto(xCS, TLINES-1,p), 1);
vputp(RC, 1); /* xCS homes stupid cursor */
for (i=cnt; i>0; i--)
vputp(SR, 1); /* should do @'s */
vputp(tgoto(xCS, TLINES-1,0), 1);
vputp(RC, 1); /* Once again put it back */
}
else {
vputp(AL, WECHO + 1 - p);
for (i = cnt - 1; i > 0; i--) {
vgoto(outline+1, 0);
vputp(AL, WECHO + 1 - outline);
if ((hold & HOLDAT) == 0)
putchar('@');
}
}
vadjAL(p, cnt);
} else
could = 0;
vopenup(cnt, could, l);
}
/*
* Logically open up after line l, cnt of them.
* We need to know if it was done ``physically'' since in this
* case we accept what the hardware gives us. If we have to do
* it ourselves (brute force) we will squish out @ lines in the process
* if this will save us work.
*/
void
vopenup(int cnt, int could, int l)
{
register struct vlinfo *vc = &vlinfo[l + 1];
register struct vlinfo *ve = &vlinfo[vcnt];
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vopenup(%d, %d, %d)\n", cnt, could, l);
#endif
if (could)
/*
* This will push @ lines down the screen,
* just as the hardware did. Since the default
* for intelligent terminals is to never have @
* lines on the screen, this should never happen,
* and the code makes no special effort to be nice in this
* case, e.g. squishing out the @ lines by delete lines
* before doing append lines.
*/
for (; vc <= ve; vc++)
vc->vliny += cnt;
else {
/*
* Will have to clean up brute force eventually,
* so push the line data around as little as possible.
*/
vc->vliny += cnt, vc->vflags |= VDIRT;
while (vc < ve) {
register int i = vc->vliny + vc->vdepth;
vc++;
if (i <= vc->vliny)
break;
vc->vliny = i, vc->vflags |= VDIRT;
}
}
vscrap();
}
/*
* Adjust data structure internally to account for insertion of
* blank lines on the screen.
*/
void
vadjAL(int p, int cnt)
{
cell *tlines[TUBELINES];
register int from, to;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vadjal(%d, %d)\n", p, cnt);
#endif
copy(tlines, vtube, sizeof vtube); /*SASSIGN*/
for (from = p, to = p + cnt; to <= WECHO; from++, to++)
vtube[to] = tlines[from];
for (to = p; from <= WECHO; from++, to++) {
vtube[to] = tlines[from];
vclrcell(vtube[to], WCOLS);
}
/*
* Have to clear the echo area since its contents aren't
* necessarily consistent with the rest of the display.
*/
vclrech(0);
}
/*
* Roll the screen up logically and physically
* so that line dl is the bottom line on the screen.
*/
void
vrollup(int dl)
{
register int cnt;
register int dc = destcol;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vrollup(%d)\n", dl);
#endif
cnt = dl - (splitw ? WECHO : WBOT);
if (splitw && (state == VISUAL || state == CRTOPEN))
holdupd = 1;
vmoveitup(cnt, 1);
vscroll(cnt);
destline = dl - cnt, destcol = dc;
}
void
vup1(void)
{
vrollup(WBOT + 1);
}
/*
* Scroll the screen up cnt lines physically.
* If doclr is true, do a clear eol if the terminal
* has standout (to prevent it from scrolling up)
*/
void
vmoveitup(register int cnt, int doclr)
{
if (cnt == 0)
return;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vmoveitup(%d)\n", cnt);
#endif
if (doclr && (SO || SE))
vclrech(0);
if (SF) {
destline = WECHO;
destcol = (NONL ? 0 : outcol % WCOLS);
fgoto();
while (cnt > 0)
vputp(SF, 0), cnt--;
return;
}
destline = WECHO + cnt;
destcol = (NONL ? 0 : outcol % WCOLS);
fgoto();
if (state == ONEOPEN || state == HARDOPEN) {
outline = destline = 0;
vclrcell(vtube[0], WCOLS);
}
}
/*
* Scroll the screen up cnt lines logically.
*/
void
vscroll(register int cnt)
{
register int from, to;
cell *tlines[TUBELINES];
#ifdef ADEBUG
if (trace)
fprintf(trace, "vscroll(%d)\n", cnt);
#endif
if (cnt < 0 || cnt > TUBELINES)
error(catgets(catd, 1, 219, "Internal error: vscroll"));
if (cnt == 0)
return;
copy(tlines, vtube, sizeof vtube);
for (to = ZERO, from = ZERO + cnt; to <= WECHO - cnt; to++, from++)
vtube[to] = tlines[from];
for (from = ZERO; to <= WECHO; to++, from++) {
vtube[to] = tlines[from];
vclrcell(vtube[to], WCOLS);
}
for (from = 0; from <= vcnt; from++)
LINE(from) -= cnt;
}
/*
* Discard logical lines due to physical wandering off the screen.
*/
void
vscrap(void)
{
register int i, j;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vscrap\n"), tvliny();
#endif
if (splitw)
return;
if (vcnt && WBOT != WECHO && LINE(0) < WTOP && LINE(0) >= ZERO) {
WTOP = LINE(0);
WLINES = WBOT - WTOP + 1;
}
for (j = 0; j < vcnt; j++)
if (LINE(j) >= WTOP) {
if (j == 0)
break;
/*
* Discard the first j physical lines off the top.
*/
vcnt -= j, vcline -= j;
for (i = 0; i <= vcnt; i++)
vlcopy(vlinfo[i], vlinfo[i + j]);
break;
}
/*
* Discard lines off the bottom.
*/
if (vcnt) {
for (j = 0; j <= vcnt; j++)
if (LINE(j) > WBOT || LINE(j) + DEPTH(j) - 1 > WBOT) {
vcnt = j;
break;
}
LASTLINE = LINE(vcnt-1) + DEPTH(vcnt-1);
}
#ifdef ADEBUG
if (trace)
tvliny();
#endif
/*
* May have no lines!
*/
}
/*
* Repaint the screen, with cursor at curs, aftern an arbitrary change.
* Handle notification on large changes.
*/
void
vrepaint(char *curs)
{
wdot = NOLINE;
/*
* In open want to notify first.
*/
noteit(0);
vscrap();
/*
* Deal with a totally useless display.
*/
if (vcnt == 0 || vcline < 0 || vcline > vcnt || holdupd && state != VISUAL) {
register line *odol = dol;
vcnt = 0;
if (holdupd)
if (state == VISUAL)
ignore(peekkey());
else
vup1();
holdupd = 0;
if (odol == zero)
fixzero();
vcontext(dot, '.');
noteit(1);
if (noteit(1) == 0 && odol == zero) {
CATCH
error(catgets(catd, 1, 220,
"No lines in buffer"));
ENDCATCH
linebuf[0] = 0;
splitw = 0;
}
vnline(curs);
return;
}
/*
* Have some useful displayed text; refresh it.
*/
getDOT();
/*
* This is for boundary conditions in open mode.
*/
if (FLAGS(0) & VDIRT)
vsync(WTOP);
/*
* If the current line is after the last displayed line
* or the bottom of the screen, then special effort is needed
* to get it on the screen. We first try a redraw at the
* last line on the screen, hoping it will fill in where @
* lines are now. If this doesn't work, then roll it onto
* the screen.
*/
if (vcline >= vcnt || LINE(vcline) > WBOT) {
short oldhold = hold;
hold |= HOLDAT, vredraw(LASTLINE), hold = oldhold;
if (vcline >= vcnt) {
register int i = vcline - vcnt + 1;
dot -= i;
vcline -= i;
vroll(i);
} else
vsyncCL();
} else
vsync(vcline > 0 ? LINE(vcline - 1) : WTOP);
/*
* Notification on large change for visual
* has to be done last or we may lose
* the echo area with redisplay.
*/
noteit(1);
/*
* Finally. Move the cursor onto the current line.
*/
vnline(curs);
}
/*
* Fully cleanup the screen, leaving no @ lines except at end when
* line after last won't completely fit. The routine vsync is
* more conservative and much less work on dumb terminals.
*/
void
vredraw(register int p)
{
register int l;
register line *tp;
char temp[LBSIZE];
bool anydl = 0;
short oldhold = hold;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vredraw(%d)\n", p), tvliny();
#endif
if (holdupd) {
holdupd = 3;
return;
}
if (state == HARDOPEN || splitw)
return;
if (p < 0 /* || p > WECHO */)
error(catgets(catd, 1, 221, "Internal error: vredraw"));
/*
* Trim the ragged edges (lines which are off the screen but
* not yet logically discarded), save the current line, and
* search for first logical line affected by the redraw.
*/
vscrap();
CP(temp, linebuf);
l = 0;
tp = dot - vcline;
if (vcnt == 0)
LINE(0) = WTOP;
while (l < vcnt && LINE(l) < p)
l++, tp++;
/*
* We hold off echo area clearing during the redraw in deference
* to a final clear of the echo area at the end if appropriate.
*/
heldech = 0;
hold |= HOLDECH;
for (; l < vcnt && Peekkey != ATTN; l++) {
if (l == vcline)
strcLIN(temp);
else
getline(*tp);
/*
* Delete junk between displayed lines.
*/
if (LINE(l) != LINE(l + 1) && LINE(l) != p) {
if (anydl == 0 && DB && CD) {
hold = oldhold;
vclrech(0);
anydl = 1;
hold |= HOLDECH;
heldech = 0;
}
vdellin(p, LINE(l) - p, l);
}
/*
* If line image is not know to be up to date, then
* redisplay it; else just skip onward.
*/
LINE(l) = p;
if (FLAGS(l) & VDIRT) {
DEPTH(l) = vdepth();
if (l != vcline && p + DEPTH(l) - 1 > WBOT) {
vscrap();
break;
}
FLAGS(l) &= ~VDIRT;
vreopen(p, lineno(tp), l);
p = LINE(l) + DEPTH(l);
} else
p += DEPTH(l);
tp++;
}
/*
* That takes care of lines which were already partially displayed.
* Now try to fill the rest of the screen with text.
*/
if (state == VISUAL && p <= WBOT) {
int ovcline = vcline;
vcline = l;
for (; tp <= dol && Peekkey != ATTN; tp++) {
getline(*tp);
if (p + vdepth() - 1 > WBOT)
break;
vopen(tp, p);
p += DEPTH(vcline);
vcline++;
}
vcline = ovcline;
}
/*
* Thats all the text we can get on.
* Now rest of lines (if any) get either a ~ if they
* are past end of file, or an @ if the next line won't fit.
*/
for (; p <= WBOT && Peekkey != ATTN; p++)
vclrlin(p, tp);
strcLIN(temp);
hold = oldhold;
if (heldech)
vclrech(0);
#ifdef ADEBUG
if (trace)
tvliny();
#endif
}
/*
* Do the real work in deleting cnt lines starting at line p from
* the display. First affected line is line l.
*/
void
vdellin(int p, int cnt, int l)
{
register int i;
if (cnt == 0)
return;
if (DL == NOSTR || cnt < 0) {
/*
* Can't do it; just remember that line l is munged.
*/
FLAGS(l) |= VDIRT;
return;
}
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vdellin(%d, %d, %d)\n", p, cnt, l);
#endif
/*
* Send the deletes to the screen and then adjust logical
* and physical internal data structures.
*/
vgoto(p, 0);
if (DL_PARM && (cnt>1 || *DL==0)) {
vputp(tgoto(DL_PARM, p, cnt), WECHO-p);
}
else if (xCS && *DL==0) {
/* vt100: fake DL by changing scrolling region */
vputp(SC, 1); /* Save since xCS homes stupid cursor */
vputp(tgoto(xCS, TLINES-1, p), 1);
vputp(tgoto(CM, 0, TLINES-1), 1);/* Go to lower left corner */
for (i=0; i<cnt; i++) /* .. and scroll cnt times */
putch('\n'); /* should check NL too */
vputp(tgoto(xCS, TLINES-1, 0), 1);/* restore scrolling region */
vputp(RC, 1); /* put cursor back */
}
else {
for (i = 0; i < cnt; i++)
vputp(DL, WECHO - p);
}
vadjDL(p, cnt);
vcloseup(l, cnt);
}
/*
* Adjust internal physical screen image to account for deleted lines.
*/
void
vadjDL(int p, int cnt)
{
cell *tlines[TUBELINES];
register int from, to;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vadjDL(%d, %d)\n", p, cnt);
#endif
/*
* Would like to use structured assignment but early
* v7 compiler (released with phototypesetter for v6)
* can't hack it.
*/
copy(tlines, vtube, sizeof vtube); /*SASSIGN*/
for (from = p + cnt, to = p; from <= WECHO; from++, to++)
vtube[to] = tlines[from];
for (from = p; to <= WECHO; from++, to++) {
vtube[to] = tlines[from];
vclrcell(vtube[to], WCOLS);
}
}
/*
* Sync the screen, like redraw but more lazy and willing to leave
* @ lines on the screen. VsyncCL syncs starting at the current line.
* In any case, if the redraw option is set then all syncs map to redraws
* as if vsync didn't exist.
*/
void
vsyncCL(void)
{
vsync(LINE(vcline));
}
void
vsync(register int p)
{
if (value(REDRAW))
vredraw(p);
else
vsync1(p);
}
/*
* The guts of a sync. Similar to redraw but
* just less ambitous.
*/
void
vsync1(register int p)
{
register int l;
char temp[LBSIZE];
register struct vlinfo *vp = &vlinfo[0];
short oldhold = hold;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vsync1(%d)\n", p), tvliny();
#endif
if (holdupd) {
if (holdupd < 3)
holdupd = 2;
return;
}
if (state == HARDOPEN || splitw)
return;
vscrap();
CP(temp, linebuf);
if (vcnt == 0)
LINE(0) = WTOP;
l = 0;
while (l < vcnt && vp->vliny < p)
l++, vp++;
heldech = 0;
hold |= HOLDECH;
while (p <= WBOT && Peekkey != ATTN) {
/*
* Want to put a line here if not in visual and first line
* or if there are lies left and this line starts before
* the current line, or if this line is piled under the
* next line (vreplace does this and we undo it).
*/
if (l == 0 && state != VISUAL ||
(l < vcnt && (vp->vliny <= p || vp[0].vliny == vp[1].vliny))) {
if (l == 0 || vp->vliny < p || (vp->vflags & VDIRT)) {
if (l == vcline)
strcLIN(temp);
else
getline(dot[l - vcline]);
/*
* Be careful that a long line doesn't cause the
* screen to shoot up.
*/
if (l != vcline && (vp->vflags & VDIRT)) {
vp->vdepth = vdepth();
vp->vflags &= ~VDIRT;
if (p + vp->vdepth - 1 > WBOT)
break;
}
vreopen(p, lineDOT() + (l - vcline), l);
}
p = vp->vliny + vp->vdepth;
vp++;
l++;
} else
/*
* A physical line between logical lines,
* so we settle for an @ at the beginning.
*/
vclrlin(p, dot + (l - vcline)), p++;
}
strcLIN(temp);
hold = oldhold;
if (heldech)
vclrech(0);
}
/*
* Subtract (logically) cnt physical lines from the
* displayed position of lines starting with line l.
*/
void
vcloseup(int l, register int cnt)
{
register int i;
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "vcloseup(%d, %d)\n", l, cnt);
#endif
for (i = l + 1; i <= vcnt; i++)
LINE(i) -= cnt;
}
/*
* Workhorse for rearranging line descriptors on changes.
* The idea here is that, starting with line l, cnt lines
* have been replaced with newcnt lines. All of these may
* be ridiculous, i.e. l may be -1000, cnt 50 and newcnt 0,
* since we may be called from an undo after the screen has
* moved a lot. Thus we have to be careful.
*
* Many boundary conditions here.
*/
void
vreplace(int l, int cnt, int newcnt)
{
register int from, to, i;
bool savenote = 0;
#ifdef ADEBUG
if (trace) {
tfixnl(), fprintf(trace, "vreplace(%d, %d, %d)\n", l, cnt, newcnt);