2 * LEVEE, or Captain Video; A vi clone
4 * Copyright (c) 1982-1997 David L Parsons
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by David L Parsons (orc@pell.chi.il.us). My name may not be used
13 * to endorse or promote products derived from this software without
14 * specific prior written permission. THIS SOFTWARE IS PROVIDED
15 * AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16 * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
17 * FITNESS FOR A PARTICULAR PURPOSE.
23 insertion(count
, openflag
, dp
, yp
, visual
)
30 int rp
; /* number of spaces to diddle */
31 int ts
, ss
; /* tabs && spaces to insert */
32 register cp
; /* current position */
33 int i
; /* random index */
34 int endd
; /* last open place */
35 register rsize
; /* size of upper buffer */
36 int currDLE
= 0; /* what DLE is now */
37 int len
; /* full insert size */
40 if (openflag
!= 0) { /* opening a line above || below */
41 if (openflag
<0 && bufmax
>0 && curr
<bufmax
) {
46 else { /* open above current line */
51 currDLE
= findDLE(lstart
, &i
, skipws(lstart
),0);
56 if (OL
&& (*yp
) < LINES
-2) {
70 currDLE
= findDLE(lstart
, &i
, curr
, 0);
72 if (!delete_to_undo(&undo
, lstart
, i
-lstart
))
78 rsize
= (bufmax
-curr
); /* amount of stuff above curr */
79 endd
= SIZE
- rsize
; /* split the buffer */
81 moveright(&core
[curr
], &core
[endd
], rsize
);
84 do { /* Insert loop */
85 Dflag
= (cp
==0 || core
[cp
-1]==EOL
);
88 while ((cmd
=peekc()) == 0x14 || cmd
== 0x04) { /* handle ^T, ^D */
89 if (readchar() == 0x14)
90 currDLE
= min(COLS
,currDLE
+shiftwidth
);
92 currDLE
= max(0,currDLE
-shiftwidth
);
95 } while (!(c
= line(core
, cp
, endd
-1, &len
)));
96 if (Dflag
&& (len
> 0 || c
== ESC
)) {
97 /* makeDLE : optimize leading whitespace for insert */
98 currDLE
= findDLE(cp
, &rp
, cp
+len
, currDLE
);
101 moveleft(&core
[rp
], &core
[cp
], len
); /* squash whitespace */
103 if (currDLE
> 0) { /* create DLE indent */
104 ts
= currDLE
/ tabsize
;
105 ss
= currDLE
% tabsize
;
106 moveright(&core
[cp
], &core
[cp
+ts
+ss
], len
);
108 fillchar(&core
[cp
], ts
, TAB
);
109 fillchar(&core
[cp
+ts
], ss
, 32);
113 if (c
== EOL
) { /* Diddle-Diddle */
114 core
[cp
++] = EOL
; /* add in a \n */
115 strput(CE
); /* clear this line */
119 /* at OL at bottom kludge... */
120 if (OL
&& (*yp
) < LINES
-2) {
130 if (!autoindent
) /* reset currDLE? */
134 } while (c
!= ESC
&& cp
<= endd
-INSSIZE
);
135 *dp
= cp
; /* start display here */
137 if (count
> 1) { /* repeated insertion */
139 if ((count
-1)*len
< endd
-cp
)
140 for (i
= 1;i
<count
;i
++) {
141 moveright(&core
[cp
-len
], &core
[cp
], len
);
146 if (openflag
!= 0 /* open or insert at end of buffer */
147 || (rsize
< 1 && cp
> curr
&& core
[cp
-1] != EOL
))
151 if (rsize
> 0) /* if not at end of buffer, stitch things together */
152 moveleft(&core
[endd
], &core
[cp
], rsize
);
153 insert_to_undo(&undo
, curr
, len
);