Commit 5fb5faaa authored by Lev Lamberov's avatar Lev Lamberov

New upstream version 1.15

parent 53c2314b
2019-01-01 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.15 released.
* io.c (print_line): Make 'l' command print '\\' before every
'$' within the text. (Reported by Ori Avtalion).
* main_loop.c (extract_addresses): Fixed address ',,' to mean
'$,$' instead of '1,$'. (Reported by Matthieu Felix).
* regex.c (extract_replacement): Allow newlines even if global.
* main_loop.c (exec_command): Make 'c' command reject address 0.
* ed.texi: Minor fixes.
* configure: Accept appending to CFLAGS, 'CFLAGS+=OPTIONS'.
2017-02-22 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.14.2 released.
......@@ -111,10 +123,10 @@
them in the list were ignored).
* main_loop.c (exec_command): Fixed 'e' command.
(It quitted when invoked a second time with a modified buffer).
* main.c: Added new option '--restricted'.
* main.c: Added new option '-r, --restricted'.
* 'red' has been converted to a script invoking 'ed --restricted'.
* Description of ed in the manual has been changed.
* testsuite: Modified some tests and removed obsolete posix tests.
* testsuite: Modified some tests and removed obsolete POSIX tests.
* main_loop.c: 'ibufp' variable made local to main_loop.
* Defined type bool to make clear which functions and variables
are Boolean.
......@@ -205,10 +217,11 @@
* Version 0.3 released.
* buffer.c (open_sbuf): Fixed symlink vulnerability using 'tmpfile'.
* signal.c: Fixed signal handling for SIGINT.
* main_loop.c (exec_command): Fixed 'c' and 'i' commands with
address 0.
* main_loop.c (exec_command): Modified 'c' and 'i' commands to
treat address 0 a synonym for address 1, as per POSIX.
* The pause mode has been removed.
* main.c: Added new options '--loose-exit-status' and '--verbose'.
* main.c: Added new option '-l, --loose-exit-status'.
* main.c: Added new option '-v, --verbose'.
* carg_parser.c: New argument parser that replaces 'getopt_long'.
* 'configure' and 'Makefile.in' have been replaced.
* Removed recursive make for testsuite.
......@@ -266,7 +279,7 @@ Dec 1993 Fran
Copyright (C) 1993 François Pinard
Copyright (C) 1994 Andrew Moore
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This file is a collection of facts, and thus it is not copyrightable,
but just in case, you have unlimited permission to copy, distribute and
......
Requirements
------------
You will need a C compiler and a C library compatible with GNU libc.
I use gcc 5.3.0 and 4.1.2, but the code should compile with any
standards compliant compiler.
I use gcc 5.3.0 and 4.1.2, but the code should compile with any standards
compliant compiler.
Gcc is available at http://gcc.gnu.org.
......@@ -58,7 +58,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above.
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute and modify it.
Changes in version 1.14:
Changes in version 1.15:
Version 1.14 is the largest bug hunt ever attempted in GNU ed. Other
goals of version 1.14 are to complete the documentation and to remove
any gratuitous incompatibilities with the POSIX standard. Thanks to Ori
Avtalion for initiating all this with a couple bug reports. ;-)
The list command has been fixed to print a backslash before every '$'
character within the text. (Reported by Ori Avtalion).
Byte counts, informative messages, command error messages, and the '?'
and '!' prompts are now written to stdout instead of to stderr. The
standard error (stderr) is now used only for diagnostic messages.
Address ',,' has been fixed to mean '$,$' instead of '1,$'.
(Reported by Matthieu Felix).
The current address is now correctly set to the addressed line after an
empty insert command.
A 's' command that is part of a 'g' or 'v' command-list can again split
a line by including a newline escaped with a backslash '\' in the
replacement string. For this to work, the closing delimiter of the
replacement string can't be omitted unless the 's' command is the last
command in the list, because otherwise the meaning of the escaped
newline would become ambiguous.
Fixed inconsistent behavior of the substitute command. It incorrectly
reported 'Invalid pattern delimiter' when the two last delimiters were
omitted after a null regular expression. Now it consistently reports
'Missing pattern delimiter' if the two last delimiters are omitted after
any regular expression (null or not).
Following a recent change in the POSIX standard, the 'c' command no
longer accepts an address of 0, and the documentation for the 'i'
command now explains that it treats address 0 as meaning "at the
beginning of the buffer", instead of as a synonym for address 1.
's/a/%' has been fixed. It incorrectly replaced 'a' with '%' instead of
using the replacement from the last substitution.
Minor fixes have been made to the manual.
An infinite loop, happening when EOF was found in the middle of a
replacement string, has been fixed.
Ed no longer accepts newlines in the replacement of a 's' command if it
is part of the command list of a global command, because in this case
the meaning of the newline becomes ambiguous. For the same reason, the
last delimiter can't be omitted if the 's' command is not the last
command in the command list.
The substitute command now correctly sets the current address to the
address of the last line on which a substitution occurred, and leaves it
unchanged if no substitution is performed.
A bug in the calculation of address offsets has been fixed. '3 ---- 2'
was calculated as address -2 instead of the correct address 1.
Address ranges with the first address omitted are now accepted.
The current address is now correctly set to the addressed line (or to
the new last line if at EOF) after an empty replacement text in the
change command.
Repeated print suffixes are now rejected. It has been documented that ed
allows any combination of non-repeated print suffixes and combines their
effects.
The substitute command now accepts suffixes in any order.
The 'repeat substitution' command now rejects multiple count suffixes.
The 'p' suffix of the 'repeat substitution' command now toggles all the
print suffixes of the last substitution.
End of file on standard input now behaves as a 'q' command.
The modified status is no longer cleared after writing the buffer to the
standard input of a shell command. (Reported by Jérôme Frgacic).
The descriptions of the 'a', 'c', 'e', 'g', 'i', 'j', 'k', 'm', 'q',
'r', 's', 'u' and 'w' commands in the manual have been fixed.
Most tests in the testsuite have been improved. Bug reporting has been
simplified; only the failed logs and results are kept in the test
directory, which can then be (tarred, compressed, and) attached to the
bug report.
The configure script now accepts appending options to CFLAGS using the
syntax 'CFLAGS+=OPTIONS'.
......@@ -4,7 +4,7 @@ GNU ed is a line-oriented text editor. It is used to create, display,
modify and otherwise manipulate text files, both interactively and via
shell scripts. A restricted version of ed, red, can only edit files in
the current directory and cannot execute shell commands. Ed is the
"standard" text editor in the sense that it is the original editor for
'standard' text editor in the sense that it is the original editor for
Unix, and thus widely available. For most purposes, however, it is
superseded by full-screen editors such as GNU Emacs or GNU Moe.
......@@ -12,7 +12,7 @@ Extensions to and deviations from the POSIX standard are described below.
See the file INSTALL for compilation and installation instructions.
Try "ed --help" for usage instructions.
Try 'ed --help' for usage instructions.
Report bugs to bug-ed@gnu.org
......@@ -127,7 +127,7 @@ or:
Copyright (C) 1993, 1994 Andrew Moore
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute and modify it.
......
/* buffer.c: scratch-file buffer routines for the ed line editor. */
/* GNU ed - The GNU line editor.
Copyright (C) 1993, 1994 Andrew Moore, Talke Studio
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -102,7 +102,7 @@ static line_t * dup_line_node( line_t * const lp )
/* Insert text from stdin (or from command buffer if global) to after
line n; stop when either a single period is read or EOF.
line n; stop when either a single period is read or at EOF.
Returns false if insertion fails. */
bool append_lines( const char ** const ibufpp, const int addr,
bool insert, const bool isglobal )
......
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
......
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
......
#! /bin/sh
# configure script for GNU ed - The GNU line editor
# Copyright (C) 2006-2017 Antonio Diaz Diaz.
# Copyright (C) 2006-2019 Antonio Diaz Diaz.
#
# This configure script is free software: you have unlimited permission
# to copy, distribute and modify it.
pkgname=ed
pkgversion=1.14.2
pkgversion=1.15
progname=ed
srctrigger=doc/${pkgname}.texi
......@@ -58,7 +58,7 @@ while [ $# != 0 ] ; do
echo "To assign makefile variables (e.g., CC, CFLAGS...), specify them as"
echo "arguments to configure in the form VAR=VALUE."
echo
echo "Options: [defaults in brackets]"
echo "Options and variables: [defaults in brackets]"
echo " -h, --help display this help and exit"
echo " -V, --version output version information and exit"
echo " --srcdir=DIR find the sources in DIR [. or ..]"
......@@ -72,6 +72,7 @@ while [ $# != 0 ] ; do
echo " CC=COMPILER C compiler to use [${CC}]"
echo " CPPFLAGS=OPTIONS command line options for the preprocessor [${CPPFLAGS}]"
echo " CFLAGS=OPTIONS command line options for the C compiler [${CFLAGS}]"
echo " CFLAGS+=OPTIONS append options to the current value of CFLAGS"
echo " LDFLAGS=OPTIONS command line options for the linker [${LDFLAGS}]"
echo
exit 0 ;;
......@@ -97,10 +98,11 @@ while [ $# != 0 ] ; do
--program-prefix=*) program_prefix=${optarg} ;;
--no-create) no_create=yes ;;
CC=*) CC=${optarg} ;;
CPPFLAGS=*) CPPFLAGS=${optarg} ;;
CFLAGS=*) CFLAGS=${optarg} ;;
LDFLAGS=*) LDFLAGS=${optarg} ;;
CC=*) CC=${optarg} ;;
CPPFLAGS=*) CPPFLAGS=${optarg} ;;
CFLAGS=*) CFLAGS=${optarg} ;;
CFLAGS+=*) CFLAGS="${CFLAGS} ${optarg}" ;;
LDFLAGS=*) LDFLAGS=${optarg} ;;
--*)
echo "configure: WARNING: unrecognized option: '${option}'" 1>&2 ;;
......@@ -173,7 +175,7 @@ echo "LDFLAGS = ${LDFLAGS}"
rm -f Makefile
cat > Makefile << EOF
# Makefile for GNU ed - The GNU line editor
# Copyright (C) 2006-2017 Antonio Diaz Diaz.
# Copyright (C) 2006-2019 Antonio Diaz Diaz.
# This file was generated automatically by configure. Don't edit.
#
# This Makefile is free software: you have unlimited permission
......
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1.
.TH ED "1" "February 2017" "ed 1.14.2" "User Commands"
.TH ED "1" "January 2019" "ed 1.15" "User Commands"
.SH NAME
ed \- line-oriented text editor
.SH SYNOPSIS
.B ed
[\fI\,options\/\fR] [\fI\,file\/\fR]
.SH DESCRIPTION
GNU Ed \- The GNU line editor.
GNU ed is a line\-oriented text editor. It is used to create, display,
modify and otherwise manipulate text files, both interactively and via
shell scripts. A restricted version of ed, red, can only edit files in
the current directory and cannot execute shell commands. Ed is the
\&'standard' text editor in the sense that it is the original editor for
Unix, and thus widely available. For most purposes, however, it is
superseded by full\-screen editors such as GNU Emacs or GNU Moe.
.SH OPTIONS
.TP
\fB\-h\fR, \fB\-\-help\fR
......@@ -49,7 +55,7 @@ General help using GNU software: http://www.gnu.org/gethelp
.SH COPYRIGHT
Copyright \(co 1994 Andrew L. Moore.
.br
Copyright \(co 2017 Antonio Diaz Diaz.
Copyright \(co 2019 Antonio Diaz Diaz.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
.br
This is free software: you are free to change and redistribute it.
......
......@@ -5,7 +5,7 @@ START-INFO-DIR-ENTRY
* Ed: (ed). The GNU line editor
END-INFO-DIR-ENTRY
Copyright (C) 1993, 1994, 2006-2017 Free Software Foundation, Inc.
Copyright (C) 1993, 1994, 2006-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
......@@ -18,14 +18,14 @@ File: ed.info, Node: Top, Next: Overview, Up: (dir)
The GNU ed line editor
**********************
This manual is for GNU ed (version 1.14.2, 22 February 2017).
This manual is for GNU ed (version 1.15, 1 January 2019).
GNU ed is a line-oriented text editor. It is used to create, display,
modify and otherwise manipulate text files, both interactively and via
shell scripts. A restricted version of ed, red, can only edit files in
the current directory and cannot execute shell commands. Ed is the
"standard" text editor in the sense that it is the original editor for
'standard' text editor in the sense that it is the original editor for
Unix, and thus widely available. For most purposes, however, it is
superseded by full-screen editors such as GNU Emacs or GNU Moe.
......@@ -43,7 +43,7 @@ superseded by full-screen editors such as GNU Emacs or GNU Moe.
* GNU Free Documentation License:: How you can copy and share this manual
Copyright (C) 1993, 1994, 2006-2017 Free Software Foundation, Inc.
Copyright (C) 1993, 1994, 2006-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
......@@ -328,6 +328,7 @@ prefixed with a bang.
'-V'
'--version'
Print the version number of 'ed' on the standard output and exit.
This version number should be included in all bug reports.
'-G'
'--traditional'
......@@ -381,8 +382,8 @@ file. In general, the current address is set to the address of the last
line affected by a command.
One exception to the rule that addresses represent line numbers is
the address '0' (zero). This means "before the first line", and is
valid wherever it makes sense.
the address '0' (zero). This means "at the beginning of the buffer",
and is valid wherever it makes sense.
An address range is two addresses separated either by a comma (',')
or a semicolon (';'). In a semicolon-delimited range, the current
......@@ -437,12 +438,12 @@ requires zero addresses.
'/RE/'
The next line containing the regular expression RE. The search
wraps to the beginning of the buffer and continues down to the
current line, if necessary. A null RE '//' repeats the last search.
current line, if necessary.
'?RE?'
The previous line containing the regular expression RE. The search
wraps to the end of the buffer and continues up to the current
line, if necessary. A null RE '??' repeats the last search.
line, if necessary.
''x'
The apostrophe-x character pair addresses the line previously
......@@ -482,11 +483,15 @@ the 'ed' command
prints all lines containing STRING. Regular expressions are also used
by the 's' command for selecting old text to be replaced with new text.
In addition to a specifying string literals, regular expressions can
In addition to specifying string literals, regular expressions can
represent classes of strings. Strings thus represented are said to be
matched by the corresponding regular expression. If it is possible for a
regular expression to match several strings in a line, then the
left-most longest match is the one selected.
left-most match is the one selected. If the regular expression permits a
variable number of matching characters, the longest sequence starting at
that point is matched.
A null RE is equivalent to the last RE encountered.
The following symbols are used in constructing regular expressions:
......@@ -548,13 +553,14 @@ left-most longest match is the one selected.
ordered relative to their left delimiter.
'*'
Matches the single character regular expression or subexpression
immediately preceding it zero or more times. If '*' is the first
character of a regular expression or subexpression, then it matches
itself. The '*' operator sometimes yields unexpected results. For
example, the regular expression 'b*' matches the beginning of the
string 'abbb', as opposed to the substring 'bbb', since a null
match is the only left-most match.
Matches zero or more repetitions of the regular expression
immediately preceding it. The regular expression can be either a
single character regular expression or a subexpression. If '*' is
the first character of a regular expression or subexpression, then
it matches itself. The '*' operator sometimes yields unexpected
results. For example, the regular expression 'b*' matches the
beginning of the string 'abbb', as opposed to the substring 'bbb',
since a null match is the only left-most match.
'\{N,M\}'
'\{N,\}'
......@@ -594,7 +600,7 @@ distinguish them from traditional 'ed' syntax.
'\+'
Matches the single character regular expression or subexpression
immediately preceding it one or more times. So the regular
expression 'a+' is shorthand for 'aa*'. If '\+' occurs at the
expression 'a\+' is shorthand for 'aa*'. If '\+' occurs at the
beginning of a regular expression or subexpression, then it
matches a literal '+'.
......@@ -629,7 +635,8 @@ commands accept a print suffix, which is any of 'p' (print), 'l'
(list), or 'n' (enumerate), to print the last line affected by the
command. It is not portable to give more than one print suffix, but
'ed' allows any combination of non-repeated print suffixes and combines
their effects.
their effects. If any suffix letter is given, it must immediately
follow the command.
An interrupt (typically <Control-C>) has the effect of aborting the
current command and returning the editor to command mode.
......@@ -728,10 +735,10 @@ specified (in parenthesis).
'(.)i'
Inserts text in the buffer before the addressed line. The address
'0' (zero) is valid for this command; it is equivalent to address
'1'. Text is entered in input mode. The current address is set to
the address of the last line entered or, if there were none, to the
addressed line.
'0' (zero) is valid for this command; it places the entered text at
the beginning of the buffer. Text is entered in input mode. The
current address is set to the address of the last line entered or,
if there were none, to the addressed line.
'(.,.+1)j'
Joins the addressed lines, replacing them by a single line
......@@ -822,7 +829,7 @@ specified (in parenthesis).
specified. The last delimiter can't be omitted if the 's' command
is part of a 'g' or 'v' COMMAND-LIST and is not the last command
in the list, because the meaning of the following escaped newline
becomes ambiguous.
would become ambiguous.
An unescaped '&' in REPLACEMENT is replaced by the currently
matched text. The character sequence '\M' where M is a number in
......@@ -833,10 +840,8 @@ specified (in parenthesis).
REPLACEMENT from the last substitution is used.
A line can be split by including a newline escaped with a backslash
('\') in REPLACEMENT, except if the 's' command is part of a 'g'
or 'v' COMMAND-LIST, because in this case the meaning of the
escaped newline becomes ambiguous. Each backslash in REPLACEMENT
removes the special meaning (if any) of the following character.
('\') in REPLACEMENT. Each backslash in REPLACEMENT removes the
special meaning (if any) of the following character.
'(.,.)s'
Repeats the last substitution. This form of the 's' command accepts
......@@ -844,9 +849,9 @@ specified (in parenthesis).
of the suffixes 'p' and 'r'. The 'g' suffix toggles the global
suffix of the last substitution and resets COUNT to 1. The 'p'
suffix toggles the print suffixes of the last substitution. The
'r' suffix causes the regular expression of the last search to be
used instead of that of the last substitution (if the search
happened after the substitution).
'r' suffix causes the RE of the last search to be used instead of
the RE of the last substitution (if the search happened after the
substitution).
'(.,.)t(.)'
Copies (i.e., transfers) the addressed lines to after the
......@@ -1477,17 +1482,17 @@ permit their use in free software.

Tag Table:
Node: Top535
Node: Overview2198
Node: Introduction to line editing4254
Node: Invoking ed11527
Node: Line addressing13529
Node: Regular expressions17242
Node: Commands22586
Ref: shell escape command36495
Node: Limitations37517
Node: Diagnostics38162
Node: Problems38807
Node: GNU Free Documentation License39340
Node: Overview2194
Node: Introduction to line editing4250
Node: Invoking ed11523
Node: Line addressing13589
Node: Regular expressions17231
Node: Commands22829
Ref: shell escape command36677
Node: Limitations37699
Node: Diagnostics38344
Node: Problems38989
Node: GNU Free Documentation License39522

End Tag Table
......
......@@ -6,8 +6,8 @@
@finalout
@c %**end of header
@set UPDATED 22 February 2017
@set VERSION 1.14.2
@set UPDATED 1 January 2019
@set VERSION 1.15
@dircategory Basics
@direntry
......@@ -15,8 +15,7 @@
@end direntry
@copying
Copyright @copyright{} 1993, 1994, 2006-2017
Free Software Foundation, Inc.
Copyright @copyright{} 1993, 1994, 2006-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
......@@ -50,7 +49,7 @@ GNU ed is a line-oriented text editor. It is used to create, display,
modify and otherwise manipulate text files, both interactively and via
shell scripts. A restricted version of ed, red, can only edit files in
the current directory and cannot execute shell commands. Ed is the
"standard" text editor in the sense that it is the original editor for
'standard' text editor in the sense that it is the original editor for
Unix, and thus widely available. For most purposes, however, it is
superseded by full-screen editors such as GNU Emacs or GNU Moe.
@end ifnottex
......@@ -382,6 +381,7 @@ Print an informative help message describing the options and exit.
@item -V
@itemx --version
Print the version number of @command{ed} on the standard output and exit.
This version number should be included in all bug reports.
@item -G
@itemx --traditional
......@@ -435,8 +435,8 @@ of the file. In general, the current address is set to the address of
the last line affected by a command.
One exception to the rule that addresses represent line numbers is the
address @samp{0} (zero). This means "before the first line", and is
valid wherever it makes sense.
address @samp{0} (zero). This means "at the beginning of the buffer",
and is valid wherever it makes sense.
An address range is two addresses separated either by a comma (@samp{,})
or a semicolon (@samp{;}). In a semicolon-delimited range, the current
......@@ -493,12 +493,12 @@ address range @samp{.;$}.
@item /@var{re}/
The next line containing the regular expression @var{re}. The search
wraps to the beginning of the buffer and continues down to the current
line, if necessary. A null @var{re} @samp{//} repeats the last search.
line, if necessary.
@item ?@var{re}?
The previous line containing the regular expression @var{re}. The search
wraps to the end of the buffer and continues up to the current line, if
necessary. A null @var{re} @samp{??} repeats the last search.
necessary.
@item 'x
The apostrophe-x character pair addresses the line previously marked by
......@@ -546,11 +546,15 @@ prints all lines containing @var{string}. Regular expressions are also
used by the @samp{s} command for selecting old text to be replaced with
new text.
In addition to a specifying string literals, regular expressions can
In addition to specifying string literals, regular expressions can
represent classes of strings. Strings thus represented are said to be
matched by the corresponding regular expression. If it is possible for a
regular expression to match several strings in a line, then the
left-most longest match is the one selected.
left-most match is the one selected. If the regular expression permits a
variable number of matching characters, the longest sequence starting at
that point is matched.
A null @var{re} is equivalent to the last @var{re} encountered.
The following symbols are used in constructing regular expressions:
......@@ -623,8 +627,9 @@ the @var{n}th subexpression. For example, the regular expression
delimiter.
@item *
Matches the single character regular expression or subexpression
immediately preceding it zero or more times. If @samp{*} is the first
Matches zero or more repetitions of the regular expression immediately
preceding it. The regular expression can be either a single character
regular expression or a subexpression. If @samp{*} is the first
character of a regular expression or subexpression, then it matches
itself. The @samp{*} operator sometimes yields unexpected results. For
example, the regular expression @samp{b*} matches the beginning of the
......@@ -670,7 +675,7 @@ expressions or subexpression, then it matches a literal @samp{?}.
@item \+
Matches the single character regular expression or subexpression
immediately preceding it one or more times. So the regular expression
@samp{a+} is shorthand for @samp{aa*}. If @samp{\+} occurs at the
@samp{a\+} is shorthand for @samp{aa*}. If @samp{\+} occurs at the
beginning of a regular expression or subexpression, then it matches a
literal @samp{+}.
......@@ -705,7 +710,8 @@ commands accept a print suffix, which is any of @samp{p} (print),
@samp{l} (list), or @samp{n} (enumerate), to print the last line
affected by the command. It is not portable to give more than one print
suffix, but @command{ed} allows any combination of non-repeated print
suffixes and combines their effects.
suffixes and combines their effects. If any suffix letter is given, it
must immediately follow the command.
An interrupt (typically @key{Control-C}) has the effect of aborting the
current command and returning the editor to command mode.
......@@ -804,10 +810,10 @@ to aid in debugging.
@item (.)i
Inserts text in the buffer before the addressed line. The address
@samp{0} (zero) is valid for this command; it is equivalent to address
@samp{1}. Text is entered in input mode. The current address is set to
the address of the last line entered or, if there were none, to the
addressed line.
@samp{0} (zero) is valid for this command; it places the entered text at
the beginning of the buffer. Text is entered in input mode. The current
address is set to the address of the last line entered or, if there were
none, to the addressed line.
@item (.,.+1)j
Joins the addressed lines, replacing them by a single line containing
......@@ -895,7 +901,7 @@ the last line affected is printed as if the print suffix @samp{p} were
specified. The last delimiter can't be omitted if the @samp{s} command
is part of a @samp{g} or @samp{v} @var{command-list} and is not the last
command in the list, because the meaning of the following escaped
newline becomes ambiguous.
newline would become ambiguous.
An unescaped @samp{&} in @var{replacement} is replaced by the currently
matched text. The character sequence @samp{\@var{m}} where @var{m} is a
......@@ -907,11 +913,8 @@ single @samp{%}, then @var{replacement} from the last substitution is
used.
A line can be split by including a newline escaped with a backslash
(@samp{\}) in @var{replacement}, except if the @samp{s} command is part
of a @samp{g} or @samp{v} @var{command-list}, because in this case the
meaning of the escaped newline becomes ambiguous. Each backslash in
@var{replacement} removes the special meaning (if any) of the following
character.
(@samp{\}) in @var{replacement}. Each backslash in @var{replacement}
removes the special meaning (if any) of the following character.
@item (.,.)s
Repeats the last substitution. This form of the @samp{s} command accepts
......@@ -919,8 +922,8 @@ the @samp{g} and @samp{@var{count}} suffixes described above, and any
combination of the suffixes @samp{p} and @samp{r}. The @samp{g} suffix
toggles the global suffix of the last substitution and resets
@var{count} to 1. The @samp{p} suffix toggles the print suffixes of the
last substitution. The @samp{r} suffix causes the regular expression of
the last search to be used instead of that of the last substitution (if
last substitution. The @samp{r} suffix causes the @var{re} of the last
search to be used instead of the @var{re} of the last substitution (if
the search happened after the substitution).
@item (.,.)t(.)
......
/* Global declarations for the ed editor. */
/* GNU ed - The GNU line editor.
Copyright (C) 1993, 1994 Andrew Moore, Talke Studio
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* global.c: global command routines for the ed line editor */
/* GNU ed - The GNU line editor.
Copyright (C) 1993, 1994 Andrew Moore, Talke Studio
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* io.c: i/o routines for the ed line editor */
/* GNU ed - The GNU line editor.
Copyright (C) 1993, 1994 Andrew Moore, Talke Studio
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -42,8 +42,8 @@ int linenum( void ) { return linenum_; }
/* print text to stdout */
static void print_line( const char * p, int len, const int pflags )
{
const char escapes[] = "\a\b\f\n\r\t\v\\";
const char escchars[] = "abfnrtv\\";
const char escapes[] = "\a\b\f\n\r\t\v";
const char escchars[] = "abfnrtv";
int col = 0;
if( pflags & GNP ) { printf( "%d\t", current_addr() ); col = 8; }
......@@ -54,7 +54,9 @@ static void print_line( const char * p, int len, const int pflags )
else
{
if( ++col > window_columns() ) { col = 1; fputs( "\\\n", stdout ); }
if( ch >= 32 && ch <= 126 && ch != '\\' ) putchar( ch );
if( ch >= 32 && ch <= 126 )
{ if( ch == '$' || ch == '\\' ) { ++col; putchar('\\'); }
putchar( ch ); }
else
{
char * const p = strchr( escapes, ch );
......@@ -105,6 +107,7 @@ static bool trailing_escape( const char * const s, int len )
/* If *ibufpp contains an escaped newline, get an extended line (one
with escaped newlines) from stdin.
The backslashes escaping the newlines are stripped.
Return line length in *lenp, including the trailing newline. */
bool get_extended_line( const char ** const ibufpp, int * const lenp,
const bool strip_escaped_newlines )
......@@ -116,7 +119,7 @@ bool get_extended_line( const char ** const ibufpp, int * const lenp,
for( len = 0; (*ibufpp)[len++] != '\n'; ) ;
if( len < 2 || !trailing_escape( *ibufpp, len - 1 ) )
{ if( lenp ) *lenp = len; return true; }
if( !resize_buffer( &buf, &bufsz, len ) ) return false;
if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return false;
memcpy( buf, *ibufpp, len );
--len; buf[len-1] = '\n'; /* strip trailing esc */
if( strip_escaped_newlines ) --len; /* strip newline */
......@@ -126,14 +129,13 @@ bool get_extended_line( const char ** const ibufpp, int * const lenp,
const char * const s = get_stdin_line( &len2 );
if( !s ) return false; /* error */
if( len2 <= 0 ) return false; /* EOF */
if( !resize_buffer( &buf, &bufsz, len + len2 ) ) return false;
if( !resize_buffer( &buf, &bufsz, len + len2 + 1 ) ) return false;
memcpy( buf + len, s, len2 );
len += len2;
if( len2 < 2 || !trailing_escape( buf, len - 1 ) ) break;
--len; buf[len-1] = '\n'; /* strip trailing esc */
if( strip_escaped_newlines ) --len; /* strip newline */
}
if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return false;
buf[len] = 0;
*ibufpp = buf;
if( lenp ) *lenp = len;
......
/* GNU ed - The GNU line editor.
Copyright (C) 2006-2017 Antonio Diaz Diaz.
Copyright (C) 2006-2019 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -42,9 +42,8 @@
#include "ed.h"
static const char * const Program_name = "GNU Ed";
static const char * const program_name = "ed";
static const char * const program_year = "2017";
static const char * const program_year = "2019";
static const char * invocation_name = 0;
static bool restricted_ = false; /* if set, run in restricted mode */
......@@ -60,8 +59,14 @@ bool traditional( void ) { return traditional_; }
static void show_help( void )
{
printf( "%s - The GNU line editor.\n", Program_name );
printf( "\nUsage: %s [options] [file]\n", invocation_name );
printf( "GNU ed is a line-oriented text editor. It is used to create, display,\n"
"modify and otherwise manipulate text files, both interactively and via\n"
"shell scripts. A restricted version of ed, red, can only edit files in\n"
"the current directory and cannot execute shell commands. Ed is the\n"
"'standard' text editor in the sense that it is the original editor for\n"
"Unix, and thus widely available. For most purposes, however, it is\n"
"superseded by full-screen editors such as GNU Emacs or GNU Moe.\n"
"\nUsage: %s [options] [file]\n", invocation_name );
printf( "\nOptions:\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
......@@ -107,11 +112,9 @@ void show_strerror( const char * const filename, const int errcode )
static void show_error( const char * const msg, const int errcode, const bool help )
{
if( msg && msg[0] )
{
fprintf( stderr, "%s: %s", program_name, msg );
if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) );
fputc( '\n', stderr );
}
fprintf( stderr, "%s: %s%s%s\n", program_name, msg,
( errcode > 0 ) ? ": " : "",
( errcode > 0 ) ? strerror( errcode ) : "" );