-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex_vput.c
1630 lines (1530 loc) · 38.1 KB
/
ex_vput.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_vput.c 1.52 (gritter) 12/25/06";
#endif
#endif
/* from ex_vput.c 7.4.1 (2.11BSD GTE) 12/9/94 */
#include "ex.h"
#include "ex_tty.h"
#include "ex_vis.h"
/*
* Deal with the screen, clearing, cursor positioning, putting characters
* into the screen image, and deleting characters.
* Really hard stuff here is utilizing insert character operations
* on intelligent terminals which differs widely from terminal to terminal.
*/
void
vclear(void)
{
#ifdef ADEBUG
if (trace)
tfixnl(), fprintf(trace, "------\nvclear\n");
#endif
tputs(CL, TLINES, putch);
destcol = 0;
outcol = 0;
destline = 0;
outline = 0;
if (inopen)
vclrcell(vtube0, WCOLS * (WECHO - ZERO + 1));
}
/*
* Clear memory.
*/
void
vclrcell(register cell *cp, register int i)
{
if (i > 0)
do
*cp++ = 0;
while (--i != 0);
}
/*
* Clear a physical display line, high level.
*/
void
vclrlin(int l, line *tp)
{
vigoto(l, 0);
if ((hold & HOLDAT) == 0)
#ifndef UCVISUAL
putchar(tp > dol ? '~' : '@');
#else
putchar(tp > dol ? ((UPPERCASE || xHZ) ? '^' : '~') : '@');
#endif
if (state == HARDOPEN)
sethard();
vclreol();
}
/*
* Clear to the end of the current physical line
*/
void
vclreol(void)
{
register int i, j;
register cell *tp;
if (destcol == WCOLS)
return;
destline += destcol / WCOLS;
destcol %= WCOLS;
if (destline < 0 || destline > WECHO)
error(catgets(catd, 1, 237, "Internal error: vclreol"));
i = WCOLS - destcol;
tp = vtube[destline] + destcol;
if (CE) {
if (IN && *tp || !ateopr()) {
vcsync();
vputp(CE, 1);
}
vclrcell(tp, i);
return;
}
if (*tp == 0)
return;
while (i > 0 && (j = *tp & (QUOTE|TRIM|MULTICOL))) {
if ((j != ' ' && (j & QUOTE) == 0)) {
destcol = WCOLS - i;
vputchar(' ');
}
--i, *tp++ = 0;
}
}
/*
* Clear the echo line.
* If didphys then its been cleared physically (as
* a side effect of a clear to end of display, e.g.)
* so just do it logically.
* If work here is being held off, just remember, in
* heldech, if work needs to be done, don't do anything.
*/
void
vclrech(bool didphys)
{
if (Peekkey == ATTN)
return;
if (hold & HOLDECH) {
heldech = !didphys;
return;
}
if (!didphys && (CD || CE)) {
splitw++;
/*
* If display is retained below, then MUST use CD or CE
* since we don't really know whats out there.
* Vigoto might decide (incorrectly) to do nothing.
*/
if (DB) {
vgoto(WECHO, 0);
vputp(CD ? CD : CE, 1);
} else {
if (XT) {
/*
* This code basically handles the t1061
* where positioning at (0, 0) won't work
* because the terminal won't let you put
* the cursor on it's magic cookie.
*
* Should probably be XS above, or even a
* new X? glitch, but right now t1061 is the
* only terminal with XT.
*/
vgoto(WECHO, 0);
vputp(DL, 1);
} else {
vigoto(WECHO, 0);
vclreol();
}
}
splitw = 0;
didphys = 1;
}
if (didphys && vtube)
vclrcell(vtube[WECHO], WCOLS);
heldech = 0;
}
/*
* Fix the echo area for use, setting
* the state variable splitw so we wont rollup
* when we move the cursor there.
*/
void
fixech(void)
{
splitw++;
if (state != VISUAL && state != CRTOPEN) {
vclean();
vcnt = 0;
}
vgoto(WECHO, 0); flusho();
}
/*
* Put the cursor ``before'' cp.
*/
void
vcursbef(register char *cp)
{
if (cp <= linebuf)
vgotoCL(value(NUMBER) << 3);
else
vgotoCL(column(cp - 1) - 1);
}
/*
* Put the cursor ``at'' cp.
*/
void
vcursat(register char *cp)
{
if (cp <= linebuf && linebuf[0] == 0)
vgotoCL(value(NUMBER) << 3);
else
vgotoCL(column(cp + skipleft(linebuf, cp)));
}
/*
* Put the cursor ``after'' cp.
*/
void
vcursaft(register char *cp)
{
vgotoCL(column(cp));
}
/*
* Fix the cursor to be positioned in the correct place
* to accept a command.
*/
void
vfixcurs(void)
{
vsetcurs(cursor);
}
/*
* Compute the column position implied by the cursor at ``nc'',
* and move the cursor there.
*/
void
vsetcurs(register char *nc)
{
register int col;
col = column(nc);
if (linebuf[0])
col--;
vgotoCL(col);
cursor = vcolbp;
}
/*
* Move the cursor invisibly, i.e. only remember to do it.
*/
void
vigoto(int y, int x)
{
destline = y;
destcol = x;
}
/*
* Move the cursor to the position implied by any previous
* vigoto (or low level hacking with destcol/destline as in readecho).
*/
void
vcsync(void)
{
vgoto(destline, destcol);
}
/*
* Goto column x of the current line.
*/
void
vgotoCL(register int x)
{
if (splitw)
vgoto(WECHO, x);
else
vgoto(LINE(vcline), x);
}
/*
* Invisible goto column x of current line.
*/
void
vigotoCL(register int x)
{
if (splitw)
vigoto(WECHO, x);
else
vigoto(LINE(vcline), x);
}
/*
* Move cursor to line y, column x, handling wraparound and scrolling.
*/
void
vgoto(register int y, register int x)
{
register cell *tp;
register int c;
/*
* Fold the possibly too large value of x.
*/
if (x >= WCOLS) {
y += x / WCOLS;
x %= WCOLS;
}
#ifdef MB
if (y >= 0 && y <= WLINES && mb_cur_max > 1 && !insmode) {
while (x > 0 && (vtube[y][x]&(MULTICOL|TRIM)) == MULTICOL &&
vtube[y][x-1] & MULTICOL &&
(vtube[y][x-1]&(MULTICOL|TRIM)) != MULTICOL)
x--;
}
#endif /* MB */
if (y < 0)
error(catgets(catd, 1, 238, "Internal error: vgoto"));
if (outcol >= WCOLS) {
if (AM) {
outline += outcol / WCOLS;
outcol %= WCOLS;
} else
outcol = WCOLS - 1;
}
/*
* In a hardcopy or glass crt open, print the stuff
* implied by a motion, or backspace.
*/
if (state == HARDOPEN || state == ONEOPEN) {
if (y != outline)
error(catgets(catd, 1, 239, "Line too long for open"));
if (x + 1 < outcol - x || (outcol > x && !BS))
destcol = 0, fgoto();
tp = vtube[WBOT] + outcol;
while (outcol != x)
if (outcol < x) {
if (*tp == 0)
*tp = ' ';
c = *tp++ & TRIM;
vputc(c && (!OS || EO) ? c : ' ');
outcol++;
} else {
if (BC)
vputp(BC, 0);
else
vputc('\b');
outcol--;
}
destcol = outcol = x;
destline = outline;
return;
}
/*
* If the destination position implies a scroll, do it.
*/
destline = y;
if (destline > WBOT && (!splitw || destline > WECHO)) {
endim();
vrollup(destline);
}
/*
* If there really is a motion involved, do it.
* The check here is an optimization based on profiling.
*/
destcol = x;
if ((destline - outline) * WCOLS != destcol - outcol) {
if (!MI)
endim();
fgoto();
}
}
/*
* This is the hardest code in the editor, and deals with insert modes
* on different kinds of intelligent terminals. The complexity is due
* to the cross product of three factors:
*
* 1. Lines may display as more than one segment on the screen.
* 2. There are 2 kinds of intelligent terminal insert modes.
* 3. Tabs squash when you insert characters in front of them,
* in a way in which current intelligent terminals don't handle.
*
* The two kinds of terminals are typified by the DM2500 or HP2645 for
* one and the CONCEPT-100 or the FOX for the other.
*
* The first (HP2645) kind has an insert mode where the characters
* fall off the end of the line and the screen is shifted rigidly
* no matter how the display came about.
*
* The second (CONCEPT-100) kind comes from terminals which are designed
* for forms editing and which distinguish between blanks and ``spaces''
* on the screen, spaces being like blank, but never having had
* and data typed into that screen position (since, e.g. a clear operation
* like clear screen). On these terminals, when you insert a character,
* the characters from where you are to the end of the screen shift
* over till a ``space'' is found, and the null character there gets
* eaten up.
*
*
* The code here considers the line as consisting of several parts
* the first part is the ``doomed'' part, i.e. a part of the line
* which is being typed over. Next comes some text up to the first
* following tab. The tab is the next segment of the line, and finally
* text after the tab.
*
* We have to consider each of these segments and the effect of the
* insertion of a character on them. On terminals like HP2645's we
* must simulate a multi-line insert mode using the primitive one
* line insert mode. If we are inserting in front of a tab, we have
* to either delete characters from the tab or insert white space
* (when the tab reaches a new spot where it gets larger) before we
* insert the new character.
*
* On a terminal like a CONCEPT our strategy is to make all
* blanks be displayed, while trying to keep the screen having ``spaces''
* for portions of tabs. In this way the terminal hardward does some
* of the hacking for compression of tabs, although this tends to
* disappear as you work on the line and spaces change into blanks.
*
* There are a number of boundary conditions (like typing just before
* the first following tab) where we can avoid a lot of work. Most
* of them have to be dealt with explicitly because performance is
* much, much worse if we don't.
*
* A final thing which is hacked here is two flavors of insert mode.
* Datamedia's do this by an insert mode which you enter and leave
* and by having normal motion character operate differently in this
* mode, notably by having a newline insert a line on the screen in
* this mode. This generally means it is unsafe to move around
* the screen ignoring the fact that we are in this mode.
* This is possible on some terminals, and wins big (e.g. HP), so
* we encode this as a ``can move in insert capability'' mi,
* and terminals which have it can do insert mode with much less
* work when tabs are present following the cursor on the current line.
*/
/*
* Routine to expand a tab, calling the normal Outchar routine
* to put out each implied character. Note that we call outchar
* with a QUOTE. We use QUOTE internally to represent a position
* which is part of the expansion of a tab.
*/
void
vgotab(void)
{
register int i = tabcol(destcol, value(TABSTOP)) - destcol;
do
(*Outchar)(QUOTE);
while (--i);
}
/*
* Variables for insert mode.
*/
int linend; /* The column position of end of line */
int tabstart; /* Column of start of first following tab */
int tabend; /* Column of end of following tabs */
int tabsize; /* Size of the following tabs */
int tabslack; /* Number of ``spaces'' in following tabs */
int inssiz; /* Number of characters to be inserted */
int inscol; /* Column where insertion is taking place */
int insmc0; /* Multi-column character before insertion */
int insmc1; /* Multi-column character at insertion */
int shft; /* Amount tab expansion shifted rest of line */
int slakused; /* This much of tabslack will be used up */
/*
* This routine MUST be called before insert mode is run,
* and brings all segments of the current line to the top
* of the screen image buffer so it is easier for us to
* maniuplate them.
*/
void
vprepins(void)
{
register int i;
register cell *cp = vtube0;
for (i = 0; i < DEPTH(vcline); i++) {
vmaktop(LINE(vcline) + i, cp);
cp += WCOLS;
}
}
void
vmaktop(register int p, cell *cp)
{
register int i;
cell temp[TUBECOLS];
if (p < 0 || vtube[p] == cp)
return;
for (i = ZERO; i <= WECHO; i++)
if (vtube[i] == cp) {
copy(temp, vtube[i], WCOLS * sizeof *temp);
copy(vtube[i], vtube[p], WCOLS * sizeof *temp);
copy(vtube[p], temp, WCOLS * sizeof *temp);
vtube[i] = vtube[p];
vtube[p] = cp;
return;
}
error(catgets(catd, 1, 240, "Line too long"));
}
/*
* Insert character c at current cursor position.
* Multi-character inserts occur only as a result
* of expansion of tabs (i.e. inssize == 1 except
* for tabs) and code assumes this in several place
* to make life simpler.
*/
int
vinschar(int c)
/* int c; /\* mjm: char --> int */
{
register int i;
register cell *tp;
char *OIM;
bool OXN;
int noim, filler = 0;
insmc1 = colsc(c) - 1;
if ((!IM || !EI) && ((hold & HOLDQIK) || !value(REDRAW) || value(SLOWOPEN))) {
/*
* Don't want to try to use terminal
* insert mode, or to try to fake it.
* Just put the character out; the screen
* will probably be wrong but we will fix it later.
*/
if (c == '\t') {
vgotab();
return c;
}
vputchar(c);
#ifdef MB
if (insmc1 == 0 && (vtube0[destcol]&(TRIM|MULTICOL))==MULTICOL)
vtube0[destcol] = INVBIT;
#endif /* MB */
if (DEPTH(vcline) * WCOLS + !value(REDRAW) >
(destline - LINE(vcline)) * WCOLS + destcol)
return c;
/*
* The next line is about to be clobbered
* make space for another segment of this line
* (on an intelligent terminal) or just remember
* that next line was clobbered (on a dumb one
* if we don't care to redraw the tail.
*/
if (AL) {
vnpins(0);
} else {
c = LINE(vcline) + DEPTH(vcline);
if (c < LINE(vcline + 1) || c > WBOT)
return c;
i = destcol;
vinslin(c, 1, vcline);
DEPTH(vcline)++;
vigoto(c, i);
vprepins();
}
return c;
}
/*
* Compute the number of positions in the line image of the
* current line. This is done from the physical image
* since that is faster. Note that we have no memory
* from insertion to insertion so that routines which use
* us don't have to worry about moving the cursor around.
*/
if (*vtube0 == 0)
linend = 0;
else {
/*
* Search backwards for a non-null character
* from the end of the displayed line.
*/
i = WCOLS * DEPTH(vcline);
if (i == 0)
i = WCOLS;
tp = vtube0 + i;
while (*--tp == 0)
if (--i == 0)
break;
linend = i + insmc1;
}
/*
* We insert at a position based on the physical location
* of the output cursor.
*/
inscol = destcol + (destline - LINE(vcline)) * WCOLS;
insmc0 = 0;
#ifdef MB
i = 0;
while (inscol+i < LBSIZE && vtube0[inscol+i]&MULTICOL &&
(vtube0[inscol+insmc0+i]&(MULTICOL|TRIM)) != MULTICOL)
i++;
while (inscol+insmc0+i < LBSIZE &&
(vtube0[inscol+insmc0+i]&(MULTICOL|TRIM)) == MULTICOL)
insmc0++;
#endif /* MB */
if (c == '\t') {
/*
* Characters inserted from a tab must be
* remembered as being part of a tab, but we can't
* use QUOTE here since we really need to print blanks.
* QUOTE|' ' is the representation of this.
*/
inssiz = tabcol(inscol+insmc0, value(TABSTOP)) - inscol - insmc0;
c = ' ' | QUOTE;
} else
inssiz = 1;
/*
* If the text to be inserted is less than the number
* of doomed positions, then we don't need insert mode,
* rather we can just typeover.
*/
if (inssiz + insmc1 <= doomed) {
endim();
if (inscol + insmc0 != linend)
doomed -= inssiz + insmc1;
#ifdef MB
if (insmc1 == 0 && c != '\t' &&
vtube0[inscol+insmc0] & MULTICOL)
vtube0[inscol+insmc0] = INVBIT;
#endif /* MB */
do
vputchar(c);
while (--inssiz);
return c;
}
/*
* Have to really do some insertion, thus
* stake out the bounds of the first following
* group of tabs, computing starting position,
* ending position, and the number of ``spaces'' therein
* so we can tell how much it will squish.
*/
tp = vtube0 + inscol + insmc0;
for (i = inscol + insmc0; i < linend; i++) {
if (*tp++ & QUOTE) {
--tp;
break;
}
}
tabstart = tabend = i;
tabslack = 0;
while (tabend < linend) {
i = *tp++;
if ((i & QUOTE) == 0)
break;
if ((i & (TRIM|MULTICOL)) == 0)
tabslack++;
tabsize++;
tabend++;
}
tabsize = tabend - tabstart;
/*
* For HP's and DM's, e.g. tabslack has no meaning.
*/
if (!IN)
tabslack = 0;
#ifdef IDEBUG
if (trace) {
fprintf(trace, "inscol %d, inssiz %d, tabstart %d, ",
inscol, inssiz, tabstart);
fprintf(trace, "tabend %d, tabslack %d, linend %d\n",
tabend, tabslack, linend);
}
#endif
OIM = IM;
OXN = XN;
noim = 0;
#ifdef MB
if (mb_cur_max > 1) {
if (destcol + 1 + insmc1 == WCOLS + 1) {
noim = 1;
if (insmc1 == 1 && insmc0 == 0)
filler = 1;
}
for (i = inscol; vtube0[i]; i++)
if (i + 1 >= WCOLS && vtube0[i] & MULTICOL) {
noim = 1;
break;
}
}
#endif /* MB */
if (noim) {
endim();
IM = 0;
XN = 0;
}
/*
* The real work begins.
*/
slakused = 0;
shft = 0;
if (tabsize) {
/*
* There are tabs on this line.
* If they need to expand, then the rest of the line
* will have to be shifted over. In this case,
* we will need to make sure there are no ``spaces''
* in the rest of the line (on e.g. CONCEPT-100)
* and then grab another segment on the screen if this
* line is now deeper. We then do the shift
* implied by the insertion.
*/
if (inssiz >= doomed + tabcol(tabstart, value(TABSTOP)) - tabstart) {
if (IN)
vrigid();
vneedpos(value(TABSTOP));
vishft();
}
} else if (inssiz + insmc1 > doomed)
/*
* No tabs, but line may still get deeper.
*/
vneedpos(inssiz + insmc1 - doomed);
/*
* Now put in the inserted characters.
*/
viin(c);
/*
* Now put the cursor in its final resting place.
*/
destline = LINE(vcline);
destcol = inscol + inssiz + insmc1 + filler;
vcsync();
if (IM != OIM) {
IM = OIM;
XN = OXN;
}
return c;
}
/*
* Rigidify the rest of the line after the first
* group of following tabs, typing blanks over ``spaces''.
*/
void
vrigid(void)
{
register int col;
register cell *tp = vtube0 + tabend;
for (col = tabend; col < linend; col++) {
if ((*tp++ & TRIM) == 0) {
endim();
vgotoCL(col);
vputchar(' ' | QUOTE);
}
}
}
/*
* We need cnt more positions on this line.
* Open up new space on the screen (this may in fact be a
* screen rollup).
*
* On a dumb terminal we may infact redisplay the rest of the
* screen here brute force to keep it pretty.
*/
void
vneedpos(int npcnt)
{
register int d = DEPTH(vcline);
register int rmdr = d * WCOLS - linend;
/*
* Delete the showmode string on wraparound to last line. Cannot use
* vclrech() since the mode string is printed on the echo area, but
* not actually a part of it.
*/
if (value(SHOWMODE) && (value(REDRAW) || (IM && EI)) &&
npcnt == rmdr - IN && LINE(vcline) + d == WECHO) {
int sdc, sdl;
char *ocurs;
endim();
sdc = destcol, sdl = destline, ocurs = cursor;
splitw++;
vgoto(WECHO, 0);
if (CD) {
vputp(CD, 1);
} else if (CE) {
vputp(CE, 1);
} else {
int i;
for (i = 1; i < WCOLS; i++)
vputchar(' ');
}
destcol = sdc, destline = sdl; cursor = ocurs;
splitw = 0;
}
if (npcnt <= rmdr - IN)
return;
endim();
vnpins(1);
}
void
vnpins(int dosync)
{
register int d = DEPTH(vcline);
register int e;
e = LINE(vcline) + DEPTH(vcline);
if (e < LINE(vcline + 1)) {
vigoto(e, 0);
vclreol();
return;
}
DEPTH(vcline)++;
if (e < WECHO) {
e = vglitchup(vcline, d);
vigoto(e, 0); vclreol();
if (dosync) {
int (*Ooutchar)(int) = Outchar;
Outchar = vputchar;
vsync(e + 1);
Outchar = Ooutchar;
}
} else {
vup1();
vigoto(WBOT, 0);
vclreol();
}
vprepins();
}
/*
* Do the shift of the next tabstop implied by
* insertion so it expands.
*/
void
vishft(void)
{
int tshft = 0;
int j;
register int i;
register cell *tp = vtube0;
register cell *up;
short oldhold = hold;
shft = value(TABSTOP);
hold |= HOLDPUPD;
if (!IM && !EI) {
/*
* Dumb terminals are easy, we just have
* to retype the text.
*/
vigotoCL(tabend + shft);
up = tp + tabend;
for (i = tabend; i < linend; i++)
vputchar(*up++);
} else if (IN) {
/*
* CONCEPT-like terminals do most of the work for us,
* we don't have to muck with simulation of multi-line
* insert mode. Some of the shifting may come for free
* also if the tabs don't have enough slack to take up
* all the inserted characters.
*/
i = shft;
slakused = inssiz - doomed;
if (slakused > tabslack) {
i -= slakused - tabslack;
slakused -= tabslack;
}
if (i > 0 && tabend != linend) {
tshft = i;
vgotoCL(tabend);
goim();
do
vputchar(' ' | QUOTE);
while (--i);
}
} else {
/*
* HP and Datamedia type terminals have to have multi-line
* insert faked. Hack each segment after where we are
* (going backwards to where we are.) We then can
* hack the segment where the end of the first following
* tab group is.
*/
for (j = DEPTH(vcline) - 1; j > (tabend + shft) / WCOLS; j--) {
vgotoCL(j * WCOLS);
goim();
up = tp + j * WCOLS - shft;
i = shft;
do {
if (*up)
vputchar(*up++);
else
break;
} while (--i);
}
vigotoCL(tabstart);
i = shft - (inssiz - doomed);
if (i > 0) {
tabslack = inssiz - doomed;
vcsync();
goim();
do
vputchar(' ');
while (--i);
}
}
/*
* Now do the data moving in the internal screen
* image which is common to all three cases.
*/
tp += linend;
up = tp + shft;
i = linend - tabend;
if (i > 0)
do
*--up = *--tp;
while (--i);
if (IN && tshft) {
i = tshft;
do