mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 21:05:08 +00:00
fixed undo within a global command (would corrupt the buffer)
changed move within a global to behave as in SunOS added a couple error messages
This commit is contained in:
parent
3340e10399
commit
10ca1c6c92
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=49
12
bin/ed/POSIX
12
bin/ed/POSIX
|
@ -48,3 +48,15 @@ Though ed is not a binary editor, it can be used (if painfully) to edit
|
||||||
binary files. To assist in binary editing, when a file containing at
|
binary files. To assist in binary editing, when a file containing at
|
||||||
least one ASCII NUL character is written, a newline is not appended
|
least one ASCII NUL character is written, a newline is not appended
|
||||||
if it did not already contain one upon reading.
|
if it did not already contain one upon reading.
|
||||||
|
|
||||||
|
Since the behavior of `u' (undo) within a `g' (global) command list is
|
||||||
|
not specified by POSIX D11/2, it follows the behavior of the SunOS ed
|
||||||
|
(this is the best way, I think, in that the alternatives are either too
|
||||||
|
complicated to implement or too confusing to use): undo forces a global
|
||||||
|
command list to be executed only once, rather than for each line matching
|
||||||
|
a global pattern. In addtion, each instance of `u' within a global command
|
||||||
|
undoes all previous commands (including undo's) in the command list.
|
||||||
|
|
||||||
|
The `m' (move) command within a `g' command list also follows the SunOS
|
||||||
|
ed implementation: any moved lines are removed from the global command's
|
||||||
|
`active' list.
|
||||||
|
|
|
@ -165,7 +165,11 @@ getaddr(lp)
|
||||||
|
|
||||||
while (cp != lp && (cp = cp->next) != &line0)
|
while (cp != lp && (cp = cp->next) != &line0)
|
||||||
n++;
|
n++;
|
||||||
return (cp != &line0) ? n : 0;
|
if (n && cp == &line0) {
|
||||||
|
sprintf(errmsg, "invalid address");
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
30
bin/ed/ed.1
30
bin/ed/ed.1
|
@ -92,9 +92,9 @@ commands have the structure:
|
||||||
.I [address [,address]]command[parameters]
|
.I [address [,address]]command[parameters]
|
||||||
.RE
|
.RE
|
||||||
.sp
|
.sp
|
||||||
The address(es) indicate the line(s) to be affected by the command.
|
The address(es) indicate the line or range of lines to be affected by the
|
||||||
If fewer addresses are given than the command accepts, then default
|
command. If fewer addresses are given than the command accepts, then
|
||||||
addresses are supplied.
|
default addresses are supplied.
|
||||||
|
|
||||||
.SS OPTIONS
|
.SS OPTIONS
|
||||||
.TP 8
|
.TP 8
|
||||||
|
@ -311,7 +311,7 @@ not listed below, including `{', '}', `(', `)', `<' and `>',
|
||||||
matches itself.
|
matches itself.
|
||||||
|
|
||||||
.TP 8
|
.TP 8
|
||||||
\fR\\\fIc\fR
|
\fR\e\fIc\fR
|
||||||
Any backslash-escaped character
|
Any backslash-escaped character
|
||||||
.IR c ,
|
.IR c ,
|
||||||
except for `{', '}', `(', `)', `<' and `>',
|
except for `{', '}', `(', `)', `<' and `>',
|
||||||
|
@ -389,28 +389,28 @@ anchors the regular expression to the end of a line.
|
||||||
Otherwise, it matches itself.
|
Otherwise, it matches itself.
|
||||||
|
|
||||||
.TP 8
|
.TP 8
|
||||||
\fR\\<\fR
|
\fR\e<\fR
|
||||||
Anchors the single character regular expression or subexpression
|
Anchors the single character regular expression or subexpression
|
||||||
immediately following it to the beginning of a word.
|
immediately following it to the beginning of a word.
|
||||||
(This may not be available)
|
(This may not be available)
|
||||||
|
|
||||||
.TP 8
|
.TP 8
|
||||||
\fR\\>\fR
|
\fR\e>\fR
|
||||||
Anchors the single character regular expression or subexpression
|
Anchors the single character regular expression or subexpression
|
||||||
immediately following it to the end of a word.
|
immediately following it to the end of a word.
|
||||||
(This may not be available)
|
(This may not be available)
|
||||||
|
|
||||||
.TP 8
|
.TP 8
|
||||||
\fR\\(\fIre\fR\\)\fR
|
\fR\e(\fIre\fR\e)\fR
|
||||||
Defines a subexpression
|
Defines a subexpression
|
||||||
.IR re .
|
.IR re .
|
||||||
Subexpressions may be nested.
|
Subexpressions may be nested.
|
||||||
A subsequent backreference of the form \fI`\\n'\fR, where
|
A subsequent backreference of the form \fI`\en'\fR, where
|
||||||
.I n
|
.I n
|
||||||
is a number in the range [1,9], expands to the text matched by the
|
is a number in the range [1,9], expands to the text matched by the
|
||||||
.IR n th
|
.IR n th
|
||||||
subexpression.
|
subexpression.
|
||||||
For example, the regular expression `\\(.*\\)\\1' matches any string
|
For example, the regular expression `\e(.*\e)\e1' matches any string
|
||||||
consisting of identical adjacent substrings.
|
consisting of identical adjacent substrings.
|
||||||
Subexpressions are ordered relative to
|
Subexpressions are ordered relative to
|
||||||
their left delimiter.
|
their left delimiter.
|
||||||
|
@ -426,7 +426,7 @@ the string `abbb' (as opposed to the substring `bbb'), since a null match
|
||||||
is the only left-most match.
|
is the only left-most match.
|
||||||
|
|
||||||
.TP 8
|
.TP 8
|
||||||
\fR\\{\fIn,m\fR\\}\fR or \fR\\{\fIn,\fR\\}\fR or \fR\\{\fIn\fR\\}\fR
|
\fR\e{\fIn,m\fR\e}\fR or \fR\e{\fIn,\fR\e}\fR or \fR\e{\fIn\fR\e}\fR
|
||||||
Matches the single character regular expression or subexpression
|
Matches the single character regular expression or subexpression
|
||||||
immediately preceding it at least
|
immediately preceding it at least
|
||||||
.I n
|
.I n
|
||||||
|
@ -735,7 +735,7 @@ An unescaped `&' in
|
||||||
.I replacement
|
.I replacement
|
||||||
is replaced by the currently matched text.
|
is replaced by the currently matched text.
|
||||||
The character sequence
|
The character sequence
|
||||||
\fI`\\m'\fR,
|
\fI`\em'\fR,
|
||||||
where
|
where
|
||||||
.I m
|
.I m
|
||||||
is a number in the range [1,9], is replaced by the
|
is a number in the range [1,9], is replaced by the
|
||||||
|
@ -912,8 +912,8 @@ that line.
|
||||||
Buffer file
|
Buffer file
|
||||||
.PD 0
|
.PD 0
|
||||||
.TP 20
|
.TP 20
|
||||||
\fR./ed.hup\fR, $HOME/ed.hup
|
ed.hup
|
||||||
First and second files to which
|
The file to which
|
||||||
.B ed
|
.B ed
|
||||||
attempts to write the buffer if the terminal hangs up.
|
attempts to write the buffer if the terminal hangs up.
|
||||||
|
|
||||||
|
@ -971,6 +971,10 @@ replaces any occurrences of
|
||||||
.I old
|
.I old
|
||||||
with
|
with
|
||||||
.IR new .
|
.IR new .
|
||||||
|
If the
|
||||||
|
.I `u'
|
||||||
|
(undo) command occurs in a global command list, then
|
||||||
|
the command list is executed only once.
|
||||||
|
|
||||||
If diagnostics are not disabled, attempting to quit
|
If diagnostics are not disabled, attempting to quit
|
||||||
.B ed
|
.B ed
|
||||||
|
|
|
@ -237,7 +237,7 @@ void lpqueue __P((line_t *));
|
||||||
void makekey __P((char *));
|
void makekey __P((char *));
|
||||||
char *makesub __P((int));
|
char *makesub __P((int));
|
||||||
char *translit __P((char *, int, int, int));
|
char *translit __P((char *, int, int, int));
|
||||||
int move __P((long));
|
int move __P((long, int));
|
||||||
int oddesc __P((char *, char *));
|
int oddesc __P((char *, char *));
|
||||||
void onhup __P((int));
|
void onhup __P((int));
|
||||||
void onintr __P((int));
|
void onintr __P((int));
|
||||||
|
@ -253,7 +253,7 @@ int catsub __P((char *, regmatch_t *, int));
|
||||||
int subst __P((pattern_t *, int));
|
int subst __P((pattern_t *, int));
|
||||||
int tobinhex __P((int, int));
|
int tobinhex __P((int, int));
|
||||||
int transfer __P((long));
|
int transfer __P((long));
|
||||||
int undo __P((void));
|
int undo __P((int));
|
||||||
undo_t *upush __P((int, long, long));
|
undo_t *upush __P((int, long, long));
|
||||||
void ureset __P((void));
|
void ureset __P((void));
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ optpat()
|
||||||
sprintf(errmsg, "invalid pattern delimiter");
|
sprintf(errmsg, "invalid pattern delimiter");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (*ibufp == delim) {
|
} else if (*ibufp == delim) {
|
||||||
sprintf(errmsg, "no previous pattern");
|
if (!exp) sprintf(errmsg, "no previous pattern");
|
||||||
return exp;
|
return exp;
|
||||||
} else if ((exps = getlhs(delim)) == NULL)
|
} else if ((exps = getlhs(delim)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
5
bin/ed/test/g3.d
Normal file
5
bin/ed/test/g3.d
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
line 1
|
||||||
|
line 2
|
||||||
|
line 3
|
||||||
|
line 4
|
||||||
|
line5
|
5
bin/ed/test/g3.r
Normal file
5
bin/ed/test/g3.r
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
linc 3
|
||||||
|
xine 1
|
||||||
|
xine 2
|
||||||
|
xinc 4
|
||||||
|
xinc5
|
4
bin/ed/test/g3.t
Normal file
4
bin/ed/test/g3.t
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
g/./s//x/\
|
||||||
|
3m0
|
||||||
|
g/./s/e/c/\
|
||||||
|
2,3m1
|
5
bin/ed/test/g4.d
Normal file
5
bin/ed/test/g4.d
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
line 1
|
||||||
|
line 2
|
||||||
|
line 3
|
||||||
|
line 4
|
||||||
|
line5
|
7
bin/ed/test/g4.r
Normal file
7
bin/ed/test/g4.r
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
hello
|
||||||
|
zine 1
|
||||||
|
line 2
|
||||||
|
line 3
|
||||||
|
line 4
|
||||||
|
line5
|
||||||
|
world
|
13
bin/ed/test/g4.t
Normal file
13
bin/ed/test/g4.t
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
g/./s/./x/\
|
||||||
|
u\
|
||||||
|
s/./y/\
|
||||||
|
u\
|
||||||
|
s/./z/\
|
||||||
|
u
|
||||||
|
u
|
||||||
|
0a
|
||||||
|
hello
|
||||||
|
.
|
||||||
|
$a
|
||||||
|
world
|
||||||
|
.
|
Loading…
Reference in a new issue