2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_append.c,v 8.6 1993/11/23 11:18:06 bostic Exp $ (Berkeley) $Date: 1993/11/23 11:18:06 $";
12 #include <sys/types.h>
17 enum which
{APPEND
, CHANGE
, INSERT
};
19 static int aci
__P((SCR
*, EXF
*, EXCMDARG
*, enum which
));
22 * ex_append -- :[line] a[ppend][!]
23 * Append one or more lines of new text after the specified line,
24 * or the current line if no address is specified.
27 ex_append(sp
, ep
, cmdp
)
32 return (aci(sp
, ep
, cmdp
, APPEND
));
36 * ex_change -- :[line[,line]] c[hange][!] [count]
37 * Change one or more lines to the input text.
40 ex_change(sp
, ep
, cmdp
)
45 return (aci(sp
, ep
, cmdp
, CHANGE
));
49 * ex_insert -- :[line] i[nsert][!]
50 * Insert one or more lines of new text before the specified line,
51 * or the current line if no address is specified.
54 ex_insert(sp
, ep
, cmdp
)
59 return (aci(sp
, ep
, cmdp
, INSERT
));
63 aci(sp
, ep
, cmdp
, cmd
)
75 * The ! flag turns off autoindent for append, change and
78 if (F_ISSET(cmdp
, E_FORCE
)) {
79 aiset
= O_ISSET(sp
, O_AUTOINDENT
);
80 O_CLR(sp
, O_AUTOINDENT
);
85 * If doing a change, replace lines as long as possible.
86 * Then, append more lines or delete remaining lines.
87 * Inserts are the same as appends to the previous line.
97 if (m
.lno
> cmdp
->addr2
.lno
) {
102 switch (sp
->s_get(sp
, ep
, &sp
->tiq
, 0,
103 TXT_BEAUTIFY
| TXT_CR
| TXT_NLECHO
)) {
111 tp
= sp
->tiq
.cqh_first
;
112 if (tp
->len
== 1 && tp
->lb
[0] == '.') {
114 (cmdp
->addr2
.lno
- m
.lno
) + 1; cnt
--;)
115 if (file_dline(sp
, ep
, m
.lno
)) {
121 if (file_sline(sp
, ep
, m
.lno
, tp
->lb
, tp
->len
)) {
129 switch (sp
->s_get(sp
, ep
, &sp
->tiq
, 0,
130 TXT_BEAUTIFY
| TXT_CR
| TXT_NLECHO
)) {
138 tp
= sp
->tiq
.cqh_first
;
139 if (tp
->len
== 1 && tp
->lb
[0] == '.')
141 if (file_aline(sp
, ep
, 1, m
.lno
, tp
->lb
, tp
->len
)) {
151 O_SET(sp
, O_AUTOINDENT
);