-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSCREEN.C
1419 lines (1250 loc) · 32.1 KB
/
SCREEN.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) 1990,1991,1992 Chris and John Downey */
#ifndef lint
static char *sccsid = "@(#)screen.c 2.3 (Chris & John Downey) 9/4/92";
#endif
/***
* program name:
xvi
* function:
PD version of UNIX "vi" editor, with extensions.
* module name:
screen.c
* module function:
Screen handling functions.
* history:
STEVIE - ST Editor for VI Enthusiasts, Version 3.10
Originally by Tim Thompson (twitch!tjt)
Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
Heavily modified by Chris & John Downey
***/
#include "xvi.h"
/*
* Size of command buffer - we won't allow anything more
* to be typed when we get to this limit.
*/
#define CMDSZ 80
/*
* The following is used to optimise screen updating; we
* keep a record of the real screen state and compare it
* with the new version before actually doing any updating.
*
* The l_line part is guaranteed to be always null-terminated.
*/
typedef struct line_struct {
char *l_line; /* storage for characters in line */
int l_used; /* number of bytes actually used */
unsigned int l_flags; /* information bits */
} Sline;
/*
* Bit definitions for l_flags.
*/
#define L_TEXT 0x01 /* is an ordinary text line */
#define L_MARKER 0x02 /* is a marker line ('@' or '~') */
#define L_DIRTY 0x04 /* has been modified */
#define L_MESSAGE 0x08 /* is a message line */
#define L_COMMAND 0x10 /* is a command line */
#define L_READONLY 0x20 /* message line for readonly buffer */
#define L_STATUS (L_MESSAGE | L_COMMAND) /* is a status line */
static Sline *new_screen; /* screen being updated */
static Sline *real_screen; /* state of real screen */
/*
* Status line glitch handling.
*
* Some terminals leave a space when changing colour. The number of spaces
* left is returned by the v_colour_cost() method within the VirtScr, and
* stored in the colour_cost variable herein - this is not perfect, it should
* really be in the Xviwin structure, but what the hell.
*
* "st_spare_cols" is the number of columns which are not used at the
* end of the status line; this is to prevent wrapping on this line,
* as this can do strange things to some terminals.
*/
static int colour_cost = 0;
static int st_spare_cols = 1;
static int line_to_new P((Xviwin *, Line *, int, long));
static void file_to_new P((Xviwin *));
static void new_to_screen P((VirtScr *, int, int));
static void do_sline P((Xviwin *));
static void clrline P((int));
/*
* This routine must be called to set up the screen memory -
* if it is not, we will probably get a core dump.
*
* Note that, at the moment, it must be called with a whole-screen
* window, i.e. the first window, and only that window, so that the
* nrows and ncols fields represent the whole screen.
*/
/*ARGSUSED*/
void
init_screen(win)
Xviwin *win;
{
static char *real_area, *new_area;
register int count;
VirtScr *vs;
vs = win->w_vs;
colour_cost = VScolour_cost(vs);
st_spare_cols = 1 + (colour_cost * 2);
/*
* If we're changing the size of the screen, free the old stuff.
*/
if (real_screen != NULL) {
free((char *) real_screen);
free((char *) new_screen);
free(real_area);
free(new_area);
}
/*
* Allocate space for the lines, and for the structure holding
* information about each line. Notice that we allocate an
* extra byte at the end of each line for null termination.
*/
real_screen = (Sline *) malloc((unsigned) VSrows(vs) * sizeof(Sline));
new_screen = (Sline *) malloc((unsigned) VSrows(vs) * sizeof(Sline));
real_area = malloc((unsigned) VSrows(vs) * (VScols(vs) + 1));
new_area = malloc((unsigned) VSrows(vs) * (VScols(vs) + 1));
if (real_screen == NULL || new_screen == NULL ||
real_area == NULL || new_area == NULL) {
/* What to do now? */
sys_exit(0);
}
/*
* Now assign all the rows ...
*/
for (count = 0; count < VSrows(vs); count++) {
register Sline *rp, *np;
register int offset;
rp = &real_screen[count];
np = &new_screen[count];
offset = count * (VScols(vs) + 1);
rp->l_line = real_area + offset;
np->l_line = new_area + offset;
rp->l_line[0] = np->l_line[0] = '\0';
rp->l_used = np->l_used = 0;
rp->l_flags = np->l_flags = 0;
}
}
/*
* Set the L_DIRTY bit for a given line in both real_screen &
* new_screen if the stored representations are in fact different:
* otherwise clear it.
*/
static void
mark_dirty(row)
int row;
{
Sline *rp;
Sline *np;
int used;
rp = &real_screen[row];
np = &new_screen[row];
if (
(rp->l_flags & ~L_DIRTY) != (np->l_flags & ~L_DIRTY)
||
(used = rp->l_used) != np->l_used
||
strncmp(rp->l_line, np->l_line, used) != 0
) {
/*
* The lines are different.
*/
np->l_flags |= L_DIRTY;
rp->l_flags |= L_DIRTY;
} else {
rp->l_flags = (np->l_flags &= ~L_DIRTY);
}
}
/*
* Transfer the specified window line into the "new" screen array, at
* the given row. Returns the number of screen lines taken up by the
* logical buffer line lp, or 0 if the line would not fit; this happens
* with longlines at the end of the screen. In this case, the lines
* which could not be displayed will have been marked with an '@'.
*/
static int
line_to_new(window, lp, start_row, line)
Xviwin *window;
Line *lp;
int start_row;
long line;
{
register unsigned c; /* next character from file */
register Sline *curr_line; /* output line - used for efficiency */
register char *ltext; /* pointer to text of line */
register int curr_index; /* current index in line */
bool_t eoln; /* true when line is done */
char extra[MAX_TABSTOP];
/* Stack for extra characters. */
int nextra = 0; /* index into stack */
int srow, scol; /* current screen row and column */
int vcol; /* virtual column */
ltext = lp->l_text;
srow = start_row;
scol = vcol = 0;
curr_line = &new_screen[srow];
curr_index = 0;
eoln = FALSE;
if (Pb(P_number)) {
static Flexbuf ftmp;
flexclear(&ftmp);
(void) lformat(&ftmp, NUM_FMT, line);
(void) strcpy(curr_line->l_line, flexgetstr(&ftmp));
scol += NUM_SIZE;
}
while (!eoln) {
/*
* Get the next character to put on the screen.
*/
/*
* "extra" is a stack containing any extra characters
* we have to put on the screen - this is for chars
* which have a multi-character representation, and
* for the $ at end-of-line in list mode.
*/
if (nextra > 0) {
c = extra[--nextra];
} else {
unsigned n;
c = (unsigned char) (ltext[curr_index++]);
/*
* Deal with situations where it is not
* appropriate just to copy characters
* straight onto the screen.
*/
if (c == '\0') {
if (Pb(P_list)) {
/*
* Have to show a '$' sign in list mode.
*/
extra[nextra++] = '\0';
c = '$';
}
} else {
char *p;
n = vischar((int) c, &p, vcol);
/*
* This is a bit paranoid assuming
* that Pn(P_tabstop) can never be
* greater than sizeof (extra), but
* so what.
*/
if (nextra + n > sizeof extra)
n = (sizeof extra - nextra);
/*
* Stack the extra characters so that
* they appear in the right order.
*/
while (n > 1) {
extra[nextra++] = p[--n];
}
c = p[0];
}
}
if (c == '\0') {
/*
* End of line. Terminate it and finish.
*/
eoln = TRUE;
curr_line->l_flags = L_TEXT;
curr_line->l_used = scol;
curr_line->l_line[scol] = '\0';
mark_dirty(srow);
break;
} else {
/*
* Sline folding.
*/
if (scol >= window->w_ncols) {
curr_line->l_flags = L_TEXT;
curr_line->l_used = scol;
curr_line->l_line[scol] = '\0';
mark_dirty(srow);
srow += 1;
scol = 0;
curr_line = &new_screen[srow];
}
if (srow >= window->w_cmdline) {
for (srow = start_row; srow < window->w_cmdline; srow++) {
curr_line = &new_screen[srow];
curr_line->l_flags = L_MARKER;
curr_line->l_used = 1;
curr_line->l_line[0] = '@';
curr_line->l_line[1] = '\0';
mark_dirty(srow);
}
return(0);
}
/*
* Store the character in new_screen.
*/
curr_line->l_line[scol++] = c;
vcol++;
}
}
return((srow - start_row) + 1);
}
/*
* file_to_new()
*
* Based on the current value of topline, transfer a screenful
* of stuff from file to new_screen, and update botline.
*/
static void
file_to_new(win)
register Xviwin *win;
{
register int row;
register Line *line;
register Buffer *buffer;
long lnum;
buffer = win->w_buffer;
row = win->w_winpos;
line = win->w_topline;
lnum = lineno(buffer, line);
while (row < win->w_cmdline && line != buffer->b_lastline) {
int nlines;
nlines = line_to_new(win, line, row, lnum);
if (nlines == 0) {
/*
* Make it look like we have updated
* all the screen lines, since they
* have '@' signs on them.
*/
row = win->w_cmdline;
break;
} else {
row += nlines;
line = line->l_next;
lnum++;
}
}
win->w_botline = line;
/*
* If there are any lines remaining, fill them in
* with '~' characters.
*/
for ( ; row < win->w_cmdline; row++) {
register Sline *curr_line;
curr_line = &new_screen[row];
curr_line->l_flags = L_MARKER;
curr_line->l_used = 1;
curr_line->l_line[0] = '~';
curr_line->l_line[1] = '\0';
mark_dirty(row);
}
}
/*
* new_to_screen
*
* Transfer the contents of new_screen to the screen,
* starting at "start_row", for "nlines" lines,
* using real_screen to avoid unnecessary output.
*/
static void
new_to_screen(vs, start_row, nlines)
VirtScr *vs;
int start_row;
int nlines;
{
int row; /* current row */
int end_row; /* row after last one to be updated */
int columns;
columns = VScols(vs);
if (!(echo & e_CHARUPDATE)) {
return;
}
end_row = start_row + nlines;
VSset_colour(vs, Pn(P_colour));
for (row = start_row; row < end_row; row++) {
register int ncol; /* current column in new_screen */
register Sline *new,
*real; /* pointers to current lines */
register unsigned nflags;
unsigned rflags; /* flags for current lines */
register char *ntextp,
*rtextp;
/* pointers to line text */
register int nc; /* current character in new_screen */
int n_used,
r_used;
nflags = (new = &new_screen[row])->l_flags;
rflags = (real = &real_screen[row])->l_flags;
/*
* If the real and new screens are both "clean",
* don't bother.
*/
if (!((nflags & L_DIRTY) || (rflags & L_DIRTY))) {
continue;
}
ntextp = new->l_line;
rtextp = real->l_line;
n_used = new->l_used;
r_used = real->l_used;
if ((nflags & L_MESSAGE) ||
(rflags & L_STATUS) != (nflags & L_STATUS)) {
/*
* If it's a message line, or its status (text line,
* command line or message line) has changed, and either
* the real line or the new line is "dirty", better update
* the whole thing; if any colour changes are required,
* the effects of cursor movements may not be predictable
* on some terminals.
*/
VSgoto(vs, row, 0);
if (nflags & L_STATUS) {
VSset_colour(vs, (nflags & L_READONLY) ? Pn(P_roscolour) :
Pn(P_statuscolour));
}
if ((nc = ntextp[0]) != '\0') {
VSputc(vs, row, 0, nc);
}
/*
* For command lines, only the first character should be
* highlighted.
*/
if (nflags & L_COMMAND) {
VSset_colour(vs, Pn(P_colour));
}
if (nc != '\0') {
VSwrite(vs, row, 1, &ntextp[1]);
}
/*
* Clear the rest of the line, if
* there is any left to be cleared.
*/
if (n_used < columns) {
VSclear_line(vs, row, n_used);
}
/*
* Change back to text colour if we have to.
*/
if ((nflags & L_MESSAGE) != 0) {
VSset_colour(vs, Pn(P_colour));
}
(void) strncpy(rtextp, ntextp, (int) (columns - st_spare_cols));
} else {
/*
* Look at each character in the line, comparing
* the new version with the one on the screen.
* If they differ, put it out.
*
* There is some optimisation here to avoid large
* use of tty_goto.
*/
register int scol;
/* current column on physical screen */
register int last_ncol;
/* last column to be updated */
for (ncol = scol = last_ncol = 0;
ncol < n_used && ncol < r_used;
(ncol++, scol++)) {
if ((nc = ntextp[ncol]) != rtextp[ncol]) {
/*
* They are different. Get to the right
* place before putting out the char.
*/
if (ncol != 0) {
VSadvise(vs, row, last_ncol + 1,
ncol - last_ncol - 1,
ntextp + last_ncol + 1);
} else {
VSgoto(vs, row, scol);
/*
* A command line should have the first character
* - and only the first character - highlighted.
*/
if (ncol == 0 && (nflags & L_STATUS) != 0) {
VSset_colour(vs, (nflags & L_READONLY) ?
Pn(P_roscolour) : Pn(P_statuscolour));
}
}
VSputc(vs, row, ncol, nc);
if (ncol == 0 && (nflags & L_COMMAND) != 0) {
VSset_colour(vs, Pn(P_colour));
}
last_ncol = ncol;
rtextp[ncol] = nc;
}
if (ncol == 0 && (nflags & L_COMMAND) != 0) {
scol += (colour_cost * 2);
}
}
if (n_used > r_used) {
/*
* We have got to the end of the previous
* screen line; if there is anything left,
* we should just display it.
*/
(void) strcpy(&rtextp[ncol], &ntextp[ncol]);
if (ncol == 0 && (nflags & L_COMMAND) != 0) {
/*
* A command line should have the first character
* - and only the first character - highlighted.
*/
VSgoto(vs, row, 0);
VSset_colour(vs, Pn(P_statuscolour));
VSputc(vs, row, 0, ntextp[0]);
VSset_colour(vs, Pn(P_colour));
ncol = 1;
} else {
/*
* Skip over initial whitespace.
*/
while (ntextp[ncol] == ' ') {
ncol++;
scol++;
}
}
if (ncol < columns)
VSwrite(vs, row, scol, &ntextp[ncol]);
} else if (r_used > n_used) {
/*
* We have got to the end of the new screen
* line, but the old one still has stuff on
* it. We must therefore clear it.
*/
VSclear_line(vs, row, scol);
}
}
real->l_line[n_used] = '\0';
real->l_used = n_used;
/*
* The real screen line is a message or command line if the
* newly-updated one was. Otherwise, it isn't.
*
* Both the new and real screens may now be considered
* "clean".
*/
real->l_flags = (
/*
* Turn these flags off first ...
*/
(rflags & ~(L_STATUS | L_DIRTY))
/*
* ... then set whatever L_STATUS flags are
* set in new_screen.
*/
| (nflags & L_STATUS)
);
new->l_flags &= ~L_DIRTY;
}
}
/*
* Update the status line of the given window, and cause the status
* line to be written out. Note that we call new_to_screen() to cause
* the output to be generated; since there will be no other changes,
* only the status line will be changed on the screen.
*/
void
update_sline(win)
Xviwin *win;
{
do_sline(win);
new_to_screen(win->w_vs, (int) win->w_cmdline, 1);
VSflush(win->w_vs);
}
/*
* Update the status line of the given window,
* from the one in win->w_statusline.
*/
static void
do_sline(win)
Xviwin *win;
{
register char *from;
register char *to;
register char *end;
Sline *slp;
from = flexgetstr(&win->w_statusline);
slp = &new_screen[win->w_cmdline];
to = slp->l_line;
end = to + win->w_ncols - st_spare_cols;
while (*from != '\0' && to < end) {
*to++ = *from++;
}
/*
* Fill with spaces, and null-terminate.
*/
while (to < end) {
*to++ = ' ';
}
*to = '\0';
slp->l_used = win->w_ncols - st_spare_cols;
slp->l_flags = L_MESSAGE;
if (is_readonly(win->w_buffer)) {
slp->l_flags |= L_READONLY;
}
mark_dirty(win->w_cmdline);
}
void
update_cline(win)
Xviwin *win;
{
Sline *clp;
unsigned width, maxwidth;
clp = &new_screen[win->w_cmdline];
maxwidth = win->w_ncols - st_spare_cols;
if ((width = flexlen(&win->w_statusline)) > maxwidth) {
width = maxwidth;
}
(void) strncpy(clp->l_line, flexgetstr(&win->w_statusline),
(int) width);
clp->l_used = width;
clp->l_line[width] = '\0';
clp->l_flags = (L_COMMAND | L_DIRTY);
/*
* We don't bother calling mark_dirty() here: it isn't worth
* it because the line's contents have almost certainly
* changed.
*/
new_to_screen(win->w_vs, (int) win->w_cmdline, 1);
VSflush(win->w_vs);
}
/*
* updateline() - update the line the cursor is on
*
* Updateline() is called after changes that only affect the line that
* the cursor is on. This improves performance tremendously for normal
* insert mode operation. The only thing we have to watch for is when
* the cursor line grows or shrinks around a row boundary. This means
* we have to repaint other parts of the screen appropriately.
*/
void
updateline(window)
Xviwin *window;
{
Line *currline;
int nlines;
int curs_row;
currline = window->w_cursor->p_line;
/*
* Find out which screen line the cursor line starts on.
* This is not necessarily the same as window->w_row,
* because longlines are different.
*/
if (plines(window, currline) > 1) {
curs_row = (int) cntplines(window, window->w_topline, currline);
} else {
curs_row = window->w_row;
}
nlines = line_to_new(window, currline,
(int) (curs_row + window->w_winpos),
(long) lineno(window->w_buffer, currline));
if (nlines != window->w_c_line_size) {
update_buffer(window->w_buffer);
} else {
new_to_screen(window->w_vs,
(int) (curs_row + window->w_winpos), nlines);
VSflush(window->w_vs);
}
}
/*
* Completely update the representation of the given window.
*/
void
update_window(window)
Xviwin *window;
{
if (window->w_nrows > 1) {
file_to_new(window);
new_to_screen(window->w_vs,
(int) window->w_winpos, (int) window->w_nrows);
VSflush(window->w_vs);
}
}
/*
* Update all windows.
*/
void
update_all()
{
Xviwin *w = curwin;
do {
if (w->w_nrows > 1) {
file_to_new(w);
}
if (w->w_nrows > 0) {
do_sline(w);
}
} while ((w = next_window(w)) != curwin);
new_to_screen(w->w_vs, 0, (int) VSrows(w->w_vs));
VSflush(w->w_vs);
}
/*
* Totally redraw the screen.
*/
void
redraw_screen()
{
if (curwin != NULL) {
clear(curwin);
update_all();
}
}
void
clear(win)
Xviwin *win;
{
register int row;
int nrows;
nrows = VSrows(win->w_vs);
VSset_colour(win->w_vs, Pn(P_colour));
VSclear_all(win->w_vs);
/*
* Clear the real screen lines, and mark them as modified.
*/
for (row = 0; row < nrows; row++) {
clrline(row);
}
}
/*
* The rest of the routines in this file perform screen manipulations.
* The given operation is performed physically on the screen. The
* corresponding change is also made to the internal screen image. In
* this way, the editor anticipates the effect of editing changes on
* the appearance of the screen. That way, when we call screenupdate a
* complete redraw isn't usually necessary. Another advantage is that
* we can keep adding code to anticipate screen changes, and in the
* meantime, everything still works.
*/
/*
* s_ins(win, row, nlines) - insert 'nlines' lines at 'row'
*/
void
s_ins(win, row, nlines)
Xviwin *win;
register int row;
int nlines;
{
register int from, to;
int count;
VirtScr *vs;
if (!(echo & e_SCROLL))
return;
/*
* There's no point in scrolling more lines than there are
* (below row) in the window, or in scrolling 0 lines.
*/
if (nlines == 0 || nlines + row >= win->w_nrows - 1)
return;
/*
* The row specified is relative to the top of the window;
* add the appropriate offset to make it into a screen row.
*/
row += win->w_winpos;
/*
* Note that we avoid the use of 1-line scroll regions; these
* only ever occur at the bottom of a window, and it is better
* just to leave the line to be updated in the best way by
* update{line,screen}.
*/
if (nlines == 1 && row + 1 == win->w_cmdline) {
return;
}
vs = win->w_vs;
if (vs->v_scroll != NULL) {
if (!VSscroll(vs, row, (int) win->w_cmdline - 1, -nlines)) {
/*
* Can't scroll what we were asked to - try scrolling
* the whole window including the status line.
*/
VSclear_line(vs, (int) win->w_cmdline, 0);
clrline(win->w_cmdline);
if (!VSscroll(vs, row, (int) win->w_cmdline, -nlines)) {
/*
* Failed.
*/
return;
}
}
} else {
return;
}
/*
* Update the stored screen image so it matches what has
* happened on the screen.
*/
/*
* Move section of text down to the bottom.
*
* We do this by rearranging the pointers within the Slines,
* rather than copying the characters.
*/
for (to = win->w_cmdline - 1, from = to - nlines; from >= row;
--from, --to) {
register char *temp;
temp = real_screen[to].l_line;
real_screen[to].l_line = real_screen[from].l_line;
real_screen[from].l_line = temp;
real_screen[to].l_used = real_screen[from].l_used;
}
/*
* Clear the newly inserted lines.
*/
for (count = row; count < row + nlines; count++) {
clrline(count);
}
}
/*
* s_del(win, row, nlines) - delete 'nlines' lines starting at 'row'.
*/
void
s_del(win, row, nlines)
register Xviwin *win;
int row;
int nlines;
{
register int from, to;
int count;
VirtScr *vs;
if (!(echo & e_SCROLL))
return;
/*
* There's no point in scrolling more lines than there are
* (below row) in the window, or in scrolling 0 lines.
*/
if (nlines == 0 || nlines + row >= win->w_nrows - 1)
return;
/*
* The row specified is relative to the top of the window;
* add the appropriate offset to make it into a screen row.
*/
row += win->w_winpos;
/*
* We avoid the use of 1-line scroll regions, since they don't
* work with many terminals, especially if we are using
* (termcap) DO to scroll the region.
*/
if (nlines == 1 && row + 1 == win->w_cmdline) {
return;
}
vs = win->w_vs;
if (vs->v_scroll != NULL) {
if (!VSscroll(vs, row, (int) win->w_cmdline - 1, nlines)) {
/*
* Can't scroll what we were asked to - try scrolling
* the whole window including the status line.
*/
VSclear_line(vs, (int) win->w_cmdline, 0);
clrline(win->w_cmdline);
if (!VSscroll(vs, row, (int) win->w_cmdline, nlines)) {
/*
* Failed.
*/
return;
}
}
} else {
return;
}
/*
* Update the stored screen image so it matches what has
* happened on the screen.
*/
/*
* Move section of text up from the bottom.
*
* We do this by rearranging the pointers within the Slines,
* rather than copying the characters.
*/
for (to = row, from = to + nlines;
from < win->w_cmdline;
from++, to++) {
register char *temp;
temp = real_screen[to].l_line;
real_screen[to].l_line = real_screen[from].l_line;
real_screen[from].l_line = temp;
real_screen[to].l_used = real_screen[from].l_used;
}
/*
* Clear the deleted lines.
*/
for (count = win->w_cmdline - nlines; count < win->w_cmdline; count++) {
clrline(count);
}
}
/*
* Insert a character at the cursor position, updating the screen as
* necessary. Note that this routine doesn't have to do anything, as
* the screen will eventually be correctly updated anyway; it's just
* here for speed of screen updating.
*/
void
s_inschar(window, newchar)
Xviwin *window;
int newchar;
{
register char *curp;
register char *cp;
register char *sp;
Sline *rp;
Posn *pp;
VirtScr *vs; /* the VirtScr for this window */
char *newstr; /* printable string for newchar */