+2015-07-04 Antonio Diaz Diaz <antonio@gnu.org>
+
+ * Version 1.12 released.
+ * ed.texi: Removed extra spaces from some commands.
+
2015-03-30 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.11 released.
Requirements
------------
You will need a C compiler and a C library compatible with GNU libc.
-I use gcc 4.9.1 and 3.3.6, but the code should compile with any
+I use gcc 4.9.1 and 4.1.2, but the code should compile with any
standards compliant compiler.
Gcc is available at http://gcc.gnu.org.
all : $(progname) r$(progname)
$(progname) : $(objs)
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs)
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs)
r$(progname) : r$(progname).in
cat $(VPATH)/r$(progname).in > $@
chmod a+x $@
main.o : main.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
+ $(CC) $(CPPFLAGS) $(CFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
%.o : %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
$(objs) : Makefile ed.h
carg_parser.o : carg_parser.h
-Changes in version 1.11:
+Changes in version 1.12:
-The "z" command has been fixed. ("zN" printed N + 1 lines). This bug was
-present since at least ed-0.2.
-
-The window size used by the "z" command has been documented in the
+Extra spaces have been removed from the synopses of some commands in the
manual.
-The targets "install-compress", "install-strip-compress",
-"install-info-compress" and "install-man-compress" have been added to
-the Makefile.
+Minor documentation fixes.
bp = bp->q_forw;
}
if( !resize_buffer( &buf, &bufsz, size + 2 ) ) return false;
- memcpy( buf + size, "\n", 2 );
- size += 2;
+ buf[size++] = '\n';
+ buf[size++] = 0;
if( !delete_lines( from, to, isglobal ) ) return false;
current_addr_ = from - 1;
disable_interrupts();
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2006-2015 Antonio Diaz Diaz.
- This library is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
+ This library is free software. 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.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this library. If not, see <http://www.gnu.org/licenses/>.
-
- As a special exception, you may use this file as part of a free
- software library without restriction. Specifically, if other files
- instantiate templates or use macros or inline functions from this
- file, or you compile this file and link it with other files to
- produce an executable, this file does not by itself cause the
- resulting executable to be covered by the GNU General Public
- License. This exception does not however invalidate any other
- reasons why the executable file might be covered by the GNU General
- Public License.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdlib.h>
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2006-2015 Antonio Diaz Diaz.
- This library is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
+ This library is free software. 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.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this library. If not, see <http://www.gnu.org/licenses/>.
-
- As a special exception, you may use this file as part of a free
- software library without restriction. Specifically, if other files
- instantiate templates or use macros or inline functions from this
- file, or you compile this file and link it with other files to
- produce an executable, this file does not by itself cause the
- resulting executable to be covered by the GNU General Public
- License. This exception does not however invalidate any other
- reasons why the executable file might be covered by the GNU General
- Public License.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* Arg_parser reads the arguments in 'argv' and creates a number of
# to copy, distribute and modify it.
pkgname=ed
-pkgversion=1.11
+pkgversion=1.12
progname=ed
srctrigger=doc/${pkgname}.texi
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.46.1.
-.TH ED "1" "March 2015" "ed 1.11" "User Commands"
+.TH ED "1" "July 2015" "ed 1.12" "User Commands"
.SH NAME
ed \- line-oriented text editor
.SH SYNOPSIS
The GNU ed line editor
**********************
-This manual is for GNU ed (version 1.11, 30 March 2015).
+This manual is for GNU ed (version 1.12, 4 July 2015).
GNU ed is a line-oriented text editor. It is used to create, display,
followed by a single character command and possibly additional
parameters; i.e., commands have the structure:
- [ADDRESS [,ADDRESS]]COMMAND[PARAMETERS]
+ [ADDRESS[,ADDRESS]]COMMAND[PARAMETERS]
The ADDRESSes indicate the line or range of lines to be affected by
the command. If fewer addresses are given than the command accepts,
of input. So when we speak of "entering" a command or some text in
'ed', <RETURN> is implied at the end of each line. Prior to typing
<RETURN>, corrections to the line may be made by typing either
-<BACKSPACE> (sometimes labeled <DELETE> or <DEL>) to erase characters
-backwards, or <CONTROL>-u (i.e., hold the CONTROL key and type u) to
-erase the whole line.
+<BACKSPACE> to erase characters backwards, or <CONTROL>-u (i.e., hold
+the CONTROL key and type u) to erase the whole line.
When 'ed' first opens, it expects to be told what to do but doesn't
prompt us like the shell. So let's begin by telling 'ed' to do so with
*
Now let's write the buffer contents to a file named 'junk' with the
-<w> ("write") command. Again, we use the <,> prefix to indicate that
-it's the whole buffer we want:
+<w> ("write") command:
- *,w junk
+ *w junk
137
*
The sample sessions below illustrate some basic concepts of line
editing with 'ed'. We begin by creating a file, 'sonnet', with some
help from Shakespeare. As with the shell, all input to 'ed' must be
-followed by a <newline> character. Comments begin with a '#'.
+followed by a <newline> character. Commands beginning with '#' are
+taken as comments and ignored. Input mode lines that begin with '#' are
+just more input.
$ ed
# The 'a' command is for appending text to the editor buffer.
'-r'
'--restricted'
- Run in restricted mode. This mode disables edition of files out of
+ Run in restricted mode. This mode disables editing of files out of
the current directory and execution of shell commands.
'-s'
Sets the default filename to FILE. If FILE is not specified, then
the default unescaped filename is printed.
-'(1,$)g /RE/COMMAND-LIST'
+'(1,$)g/RE/COMMAND-LIST'
Global command. Applies COMMAND-LIST to each of the addressed
lines matching a regular expression RE. The current address is set
to the line currently matched before COMMAND-LIST is executed. At
command. If 'ed' is invoked with the command-line option '-G',
then a newline in COMMAND-LIST is equivalent to a '.+1p' command.
-'(1,$)G /RE/'
+'(1,$)G/RE/'
Interactive global command. Interactively edits the addressed lines
matching a regular expression RE. For each matching line, the line
is printed, the current address is set, and the user is prompted to
A newline alone acts as a null command list. A single '&' repeats
the last non-null command list.
+'h'
+ Prints an explanation of the last error.
+
'H'
Toggles the printing of error explanations. By default,
explanations are not printed. It is recommended that ed scripts
begin with this command to aid in debugging.
-'h'
- Prints an explanation of the last error.
-
'(.)i'
Inserts text in the buffer before the current line. The address '0'
(zero) is valid for this command; it is equivalent to address '1'.
'!command', (see the '!' command below). The default filename is
unchanged. The current address is set to the last line read.
-'(.,.)s /RE/REPLACEMENT/'
-'(.,.)s /RE/REPLACEMENT/g'
-'(.,.)s /RE/REPLACEMENT/N'
+'(.,.)s/RE/REPLACEMENT/'
+'(.,.)s/RE/REPLACEMENT/g'
+'(.,.)s/RE/REPLACEMENT/N'
Replaces text in the addressed lines matching a regular expression
RE with REPLACEMENT. By default, only the first match in each line
is replaced. If the 'g' (global) suffix is given, then every match
'V' are treated as a single command by undo. 'u' is its own
inverse.
-'(1,$)v /RE/COMMAND-LIST'
+'(1,$)v/RE/COMMAND-LIST'
This is similar to the 'g' command except that it applies
COMMAND-LIST to each of the addressed lines not matching the
regular expression RE.
-'(1,$)V /RE/'
+'(1,$)V/RE/'
This is similar to the 'G' command except that it interactively
edits the addressed lines not matching the regular expression RE.
buffer is overwritten by subsequent 'y', 's', 'j', 'd', or 'c'
commands. The current address is unchanged.
-'(.+1)z N'
+'(.+1)zN'
Scrolls N lines at a time starting at addressed line, and sets
window size to N. If N is not specified, then the current window
size is used. Window size defaults to screen size minus two lines,
'(.+1)<newline>'
An address alone prints the addressed line. A <newline> alone is
- equivalent to '+1p'. the current address is set to the address of
+ equivalent to '+1p'. The current address is set to the address of
the printed line.
7 Limitations
*************
-If the terminal hangs up, 'ed' attempts to write the buffer to file
+If the terminal hangs up, 'ed' attempts to write the buffer to the file
'ed.hup' or, if this fails, to '$HOME/ed.hup'.
'ed' processes FILE arguments for backslash escapes, i.e., in a
\1f
Tag Table:
Node: Top\7f535
-Node: Overview\7f2193
-Node: Introduction to line editing\7f4250
-Node: Invoking ed\7f11491
-Node: Line addressing\7f13292
-Node: Regular expressions\7f16369
-Node: Commands\7f21713
-Node: Limitations\7f32993
-Node: Diagnostics\7f33634
-Node: Problems\7f34335
-Node: GNU Free Documentation License\7f34868
+Node: Overview\7f2191
+Node: Introduction to line editing\7f4247
+Node: Invoking ed\7f11466
+Node: Line addressing\7f13267
+Node: Regular expressions\7f16344
+Node: Commands\7f21688
+Node: Limitations\7f32960
+Node: Diagnostics\7f33605
+Node: Problems\7f34306
+Node: GNU Free Documentation License\7f34839
\1f
End Tag Table
@finalout
@c %**end of header
-@set UPDATED 30 March 2015
-@set VERSION 1.11
+@set UPDATED 4 July 2015
+@set VERSION 1.12
@dircategory Basics
@direntry
additional parameters; i.e., commands have the structure:
@example
-[@var{address} [,@var{address}]]@var{command}[@var{parameters}]
+[@var{address}[,@var{address}]]@var{command}[@var{parameters}]
@end example
The @var{address}es indicate the line or range of lines to be affected
of input. So when we speak of "entering" a command or some text in
@command{ed}, @key{RETURN} is implied at the end of each line. Prior to
typing @key{RETURN}, corrections to the line may be made by typing
-either @key{BACKSPACE} (sometimes labeled @key{DELETE} or @key{DEL}) to
-erase characters backwards, or @key{CONTROL}-u (i.e., hold the CONTROL
-key and type u) to erase the whole line.
+either @key{BACKSPACE} to erase characters backwards, or @key{CONTROL}-u
+(i.e., hold the CONTROL key and type u) to erase the whole line.
When @command{ed} first opens, it expects to be told what to do but
doesn't prompt us like the shell. So let's begin by telling @command{ed}
@end example
Now let's write the buffer contents to a file named @code{junk} with the
-@key{w} (@dfn{write}) command. Again, we use the @key{,} prefix to
-indicate that it's the whole buffer we want:
+@key{w} (@dfn{write}) command:
@example
-*,w junk
+*w junk
137
*
@end example
The sample sessions below illustrate some basic concepts of line editing
with @command{ed}. We begin by creating a file, @samp{sonnet}, with some
help from Shakespeare. As with the shell, all input to @command{ed} must
-be followed by a @key{newline} character. Comments begin with a @samp{#}.
+be followed by a @key{newline} character. Commands beginning with
+@samp{#} are taken as comments and ignored. Input mode lines that begin
+with @samp{#} are just more input.
@example
$ ed
@item -r
@itemx --restricted
-Run in restricted mode. This mode disables edition of files out of the
+Run in restricted mode. This mode disables editing of files out of the
current directory and execution of shell commands.
@item -s
Sets the default filename to @var{file}. If @var{file} is not specified,
then the default unescaped filename is printed.
-@item (1,$)g /@var{re}/@var{command-list}
+@item (1,$)g/@var{re}/@var{command-list}
Global command. Applies @var{command-list} to each of the addressed
lines matching a regular expression @var{re}. The current address is set
to the line currently matched before @var{command-list} is executed. At
is invoked with the command-line option @samp{-G}, then a newline in
@var{command-list} is equivalent to a @samp{.+1p} command.
-@item (1,$)G /@var{re}/
+@item (1,$)G/@var{re}/
Interactive global command. Interactively edits the addressed lines
matching a regular expression @var{re}. For each matching line, the line
is printed, the current address is set, and the user is prompted to
command. A newline alone acts as a null command list. A single @samp{&}
repeats the last non-null command list.
+@item h
+Prints an explanation of the last error.
+
@item H
Toggles the printing of error explanations. By default, explanations are
not printed. It is recommended that ed scripts begin with this command
to aid in debugging.
-@item h
-Prints an explanation of the last error.
-
@item (.)i
Inserts text in the buffer before the current line. The address @samp{0}
(zero) is valid for this command; it is equivalent to address @samp{1}.
@samp{!command}, (see the @samp{!} command below). The default filename
is unchanged. The current address is set to the last line read.
-@item (.,.)s /@var{re}/@var{replacement}/
-@itemx (.,.)s /@var{re}/@var{replacement}/g
-@itemx (.,.)s /@var{re}/@var{replacement}/@var{n}
+@item (.,.)s/@var{re}/@var{replacement}/
+@itemx (.,.)s/@var{re}/@var{replacement}/g
+@itemx (.,.)s/@var{re}/@var{replacement}/@var{n}
Replaces text in the addressed lines matching a regular expression
@var{re} with @var{replacement}. By default, only the first match in
each line is replaced. If the @samp{g} (global) suffix is given, then
and @samp{V} are treated as a single command by undo. @samp{u} is its
own inverse.
-@item (1,$)v /@var{re}/@var{command-list}
+@item (1,$)v/@var{re}/@var{command-list}
This is similar to the @samp{g} command except that it applies
@var{command-list} to each of the addressed lines not matching the
regular expression @var{re}.
-@item (1,$)V /@var{re}/
+@item (1,$)V/@var{re}/
This is similar to the @samp{G} command except that it interactively
edits the addressed lines not matching the regular expression @var{re}.
overwritten by subsequent @samp{y}, @samp{s}, @samp{j}, @samp{d}, or
@samp{c} commands. The current address is unchanged.
-@item (.+1)z @var{n}
+@item (.+1)z@var{n}
Scrolls @var{n} lines at a time starting at addressed line, and sets
window size to @var{n}. If @var{n} is not specified, then the current
window size is used. Window size defaults to screen size minus two
@item (.+1)@key{newline}
An address alone prints the addressed line. A @key{newline} alone is
-equivalent to @samp{+1p}. the current address is set to the address of
+equivalent to @samp{+1p}. The current address is set to the address of
the printed line.
@end table
@chapter Limitations
If the terminal hangs up, @command{ed} attempts to write the buffer to
-file @file{ed.hup} or, if this fails, to @file{$HOME/ed.hup}.
+the file @file{ed.hup} or, if this fails, to @file{$HOME/ed.hup}.
@command{ed} processes @var{file} arguments for backslash escapes, i.e.,
in a filename, any character preceded by a backslash (@samp{\}) is
struct line * q_forw;
struct line * q_back;
long pos; /* position of text in scratch buffer */
- int len; /* length of line */
+ int len; /* length of line ('\n' is not stored) */
}
line_t;
{
if( !scripted_ )
{
- if( filename && filename[0] != 0 )
- fprintf( stderr, "%s: ", filename );
+ if( filename && filename[0] ) fprintf( stderr, "%s: ", filename );
fprintf( stderr, "%s\n", strerror( errcode ) );
}
}
{
fprintf( stderr, "%s: %s", program_name, msg );
if( errcode > 0 ) fprintf( stderr, ": %s", strerror( errcode ) );
- fprintf( stderr, "\n" );
+ fputc( '\n', stderr );
}
if( help )
fprintf( stderr, "Try '%s --help' for more information.\n",
if( !fnp ) return ERR;
if( system( fnp + 1 ) < 0 )
{ set_error_msg( "Can't create shell process" ); return ERR; }
- if( !scripted() ) printf( "!\n" );
+ if( !scripted() ) fputs( "!\n", stdout );
break;
case '\n': first_addr = 1;
if( !check_addr_range( first_addr, current_addr() +
fflush( stdout );
if( status < 0 && verbose )
{ fprintf( stderr, "%s\n", errmsg ); fflush( stderr ); }
- if( prompt_on ) { printf( "%s", prompt_str ); fflush( stdout ); }
+ if( prompt_on ) { fputs( prompt_str, stdout ); fflush( stdout ); }
ibufp = get_tty_line( &len );
if( !ibufp ) return err_status;
if( !len )