Commit 53c2314b authored by Lev Lamberov's avatar Lev Lamberov

New upstream version 1.14.2

parent 82a16ee8
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
......@@ -77,7 +76,7 @@ modification follow.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
......@@ -510,7 +509,7 @@ actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
......@@ -673,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
2017-02-22 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.14.2 released.
* main.c (show_strerror) Revert to using '!scripted' instead of
'verbose' to suppress diagnostics.
2017-01-10 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.14.1 released.
* Print counts, messages, '?' and '!' to stdout instead of stderr.
* buffer.c (append_lines): Fixed current address after empty 'i'.
* regex.c (set_subst_regex): Treat missing delimiters consistently.
(extract_replacement): Don't replace 'a' with '%' in 's/a/%'.
Fixed infinite loop with EOF in the middle of a replacement.
Don't accept newlines in replacement in a global command.
Last delimiter can't be omitted if not last in command list.
(search_and_replace): Set current address to last line modified.
* main_loop.c (extract_addresses): Fixed address offsets;
'3 ---- 2' was calculated as -2 instead of 1.
Accept ranges with the first address omitted.
(exec_command): Fixed current address after empty replacement
text in 'c' command.
Don't clear the modified status after writing the buffer to a
shell command. (Reported by Jérôme Frgacic).
(get_command_suffix): Don't allow repeated print suffixes.
(command_s): Accept suffixes in any order.
Don't allow multiple count suffixes.
'sp' now toggles all print suffixes.
(main_loop): Make EOF on stdin behave as a 'q' command.
* ed.texi: Fixed the description of commands 'acegijkmqrsuw'.
Documented that ed allows any combination of print suffixes.
* testsuite: Improved most tests. Simplified bug reporting.
* configure: Avoid warning on some shells when testing for gcc.
* Makefile.in: Detect the existence of install-info.
2016-01-24 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.13 released.
* buffer.c (put_sbuf_line): Fixed a memory leak.
* io.c (read_file, write_file): Close file on error.
(Both issues reported by Cédric Picard).
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.
* main_loop.c (exec_command): Fixed 'z' command.
(zN printed N + 1 lines).
* ed.texi: Documented the window size used by the 'z' command.
* Makefile.in: Added new targets 'install*-compress'.
* Restored original copyright notices in the code. I assigned to
the FSF the copyright on changes made to the part of ed already
copyrighted by the FSF, which seems to be just the manual.
2014-01-22 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.10 released.
......@@ -6,7 +64,7 @@
2013-06-18 Antonio Diaz Diaz <antonio@gnu.org>
* Version 1.9 released.
* check.sh: Do not feed shell scripts to ed.
* check.sh: Don't feed shell scripts to ed.
* configure: Options now accept a separate argument.
2013-04-23 Antonio Diaz Diaz <antonio@gnu.org>
......@@ -51,8 +109,8 @@
* buffer.c (append_lines): Fixed 'a', 'c' and 'i' commands.
(When used in a global command list, the commands following
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_loop.c (exec_command): Fixed 'e' command.
(It quitted when invoked a second time with a modified buffer).
* main.c: Added new option '--restricted'.
* 'red' has been converted to a script invoking 'ed --restricted'.
* Description of ed in the manual has been changed.
......@@ -208,8 +266,7 @@ Dec 1993 Fran
Copyright (C) 1993 François Pinard
Copyright (C) 1994 Andrew Moore
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
Free Software Foundation, Inc.
Copyright (C) 2006-2017 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 4.8.1 and 3.3.6, but the code should compile with any
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.
......@@ -32,7 +32,11 @@ the main archive.
5. Type 'make install' to install the program and any data files and
documentation.
You can install only the program, the info manual or the man page
Or type 'make install-compress', which additionally compresses the
info manual and the man page after installation. (Installing
compressed docs may become the default in the future).
You can install only the program, the info manual or the man page by
typing 'make install-bin', 'make install-info' or 'make install-man'
respectively.
......@@ -54,8 +58,7 @@ After running 'configure', you can run 'make' and 'make install' as
explained above.
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
Antonio Diaz Diaz.
Copyright (C) 2006-2017 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute and modify it.
......@@ -6,21 +6,21 @@ INSTALL_SCRIPT = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_DIR = $(INSTALL) -d -m 755
SHELL = /bin/sh
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
objs = buffer.o carg_parser.o global.o io.o main.o main_loop.o regex.o signal.o
.PHONY : all install install-bin install-info install-man install-strip \
.PHONY : all install install-bin install-info install-man \
install-strip install-compress install-strip-compress \
install-bin-strip install-info-compress install-man-compress \
uninstall uninstall-bin uninstall-info uninstall-man \
doc info man check dist clean distclean
all : $(progname) r$(progname)
$(progname) : $(objs)
$(CC) $(LDFLAGS) -o $@ $(objs)
$(progname)_profiled : $(objs)
$(CC) $(LDFLAGS) -pg -o $@ $(objs)
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs)
r$(progname) : r$(progname).in
cat $(VPATH)/r$(progname).in > $@
......@@ -56,39 +56,56 @@ check : all
@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
install : install-bin install-info install-man
install-strip : install-bin-strip install-info install-man
install-compress : install-bin install-info-compress install-man-compress
install-strip-compress : install-bin-strip install-info-compress install-man-compress
install-bin : all
if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(program_prefix)$(progname)"
$(INSTALL_SCRIPT) ./r$(progname) "$(DESTDIR)$(bindir)/$(program_prefix)r$(progname)"
install-bin-strip : all
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
install-info :
if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*
$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
-install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
-if $(CAN_RUN_INSTALLINFO) ; then \
install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info" ; \
fi
install-info-compress : install-info
lzip -v -9 "$(DESTDIR)$(infodir)/$(pkgname).info"
install-man :
if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"*
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"*
$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"
cd "$(DESTDIR)$(mandir)/man1" && ln -s "$(program_prefix)$(progname).1" "$(program_prefix)r$(progname).1"
install-strip : all
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
install-man-compress : install-man
lzip -v -9 "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"*
cd "$(DESTDIR)$(mandir)/man1" && ln -s "$(program_prefix)$(progname).1.lz" "$(program_prefix)r$(progname).1.lz"
uninstall : uninstall-bin uninstall-info uninstall-man
uninstall : uninstall-man uninstall-info uninstall-bin
uninstall-bin :
-rm -f "$(DESTDIR)$(bindir)/$(program_prefix)$(progname)"
-rm -f "$(DESTDIR)$(bindir)/$(program_prefix)r$(progname)"
uninstall-info :
-install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
-rm -f "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
-if $(CAN_RUN_INSTALLINFO) ; then \
install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info" ; \
fi
-rm -f "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"*
uninstall-man :
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"*
-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"*
dist : doc
ln -sf $(VPATH) $(DISTNAME)
......@@ -107,19 +124,19 @@ dist : doc
$(DISTNAME)/doc/$(pkgname).texi \
$(DISTNAME)/doc/fdl.texi \
$(DISTNAME)/r$(progname).in \
$(DISTNAME)/*.h \
$(DISTNAME)/*.c \
$(DISTNAME)/testsuite/check.sh \
$(DISTNAME)/testsuite/*.t \
$(DISTNAME)/testsuite/*.d \
$(DISTNAME)/testsuite/test.bin \
$(DISTNAME)/testsuite/test.txt \
$(DISTNAME)/testsuite/*.ed \
$(DISTNAME)/testsuite/*.r \
$(DISTNAME)/testsuite/*.pr \
$(DISTNAME)/testsuite/*.err \
$(DISTNAME)/*.h \
$(DISTNAME)/*.c
$(DISTNAME)/testsuite/*.err
rm -f $(DISTNAME)
lzip -v -9 $(DISTNAME).tar
clean :
-rm -f $(progname) r$(progname) $(progname)_profiled $(objs)
-rm -f $(progname) r$(progname) $(objs)
distclean : clean
-rm -f Makefile config.status *.tar *.tar.lz
Changes in version 1.10:
Changes in version 1.14:
"ed.texinfo" has been renamed to "ed.texi".
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. ;-)
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.
The current address is now correctly set to the addressed line after an
empty insert command.
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).
's/a/%' has been fixed. It incorrectly replaced 'a' with '%' instead of
using the replacement from the last substitution.
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.
......@@ -53,7 +53,7 @@ EXTENSIONS
* BSD commands have been implemented wherever they do not conflict with
the POSIX standard. The BSD-ism's included are:
* 's' (i.e., s[n][rgp]*) to repeat a previous substitution,
* 's' (i.e., s[1-9rgp]*) to repeat a previous substitution,
* 'W' for appending text to an existing file,
* 'wq' for exiting after a write, and
* 'z' for scrolling through the buffer.
......@@ -65,11 +65,11 @@ EXTENSIONS
backslash (\).
* The file commands 'E', 'e', 'r', 'W' and 'w' process a <file>
argument for backslash escapes; i.e., any character preceded by a
backslash is interpreted literally. If the first unescaped character
of a <file> argument is a bang (!), then the rest of the line is
interpreted as a shell command, and no escape processing is performed
by GNU ed.
argument for backslash escapes; i.e., any character preceded by a
backslash is interpreted literally. If the first character of a
<file> argument is a bang (!), then the rest of the line is
interpreted as a shell command, and no escape processing is
performed by GNU ed.
* For SunOS ed(1) compatibility, GNU ed runs in restricted mode if invoked
as red. This limits editing of files in the local directory only and
......@@ -77,14 +77,10 @@ EXTENSIONS
DEVIATIONS
----------
* For backwards compatibility, the POSIX rule that says a range of
addresses cannot be used where only a single address is expected has
been relaxed.
* To support the BSD 's' command (see EXTENSIONS above),
substitution patterns cannot be delimited by numbers or the characters
'r', 'g' and 'p'. In contrast, POSIX specifies any character expect
space or newline can used as a delimiter.
* To support the BSD 's' command (see EXTENSIONS above), substitution
patterns cannot be delimited by the digits '1' to '9' or by the
characters 'r', 'g' and 'p'. In contrast, POSIX specifies that any
character except space and newline can be used as a delimiter.
* Since the behavior of 'u' (undo) within a 'g' (global) command list is
not specified by POSIX, GNU ed follows the behavior of the SunOS ed:
......@@ -99,11 +95,6 @@ DEVIATIONS
ed implementation: any moved lines are removed from the global command's
'active' list.
* If GNU ed is invoked with a name argument prefixed by a bang (!), then
the remainder of the argument is interpreted as a shell command. To invoke
ed on a file whose name starts with bang, prefix the name with a
(quoted) backslash.
* For backwards compatibility, errors in piped scripts do not force ed
to exit. POSIX only specifies ed's response for input via regular
files (including here documents) or tty's.
......@@ -111,23 +102,23 @@ DEVIATIONS
TESTSUITE
---------
The files in the 'testsuite' directory with suffixes '.t', '.d', '.r',
'.pr' and '.err' are used for testing ed. To run the tests, configure
the package and type 'make check' from the build directory. The tests do
not exhaustively verify POSIX compliance nor do they verify correct
8-bit or long line support.
The test file suffixes have the following meanings:
.t Template - a list of ed commands from which an ed script is
constructed
.d Data - read by an ed script
The files in the 'testsuite' directory with extensions '.ed', '.r', and
'.err' are used for testing ed. To run the tests, configure the package
and type 'make check' from the build directory. The tests do not
exhaustively verify POSIX compliance nor do they verify correct 8-bit or
long line support.
The test file extensions have the following meanings:
.ed Ed script - a list of ed commands.
.r Result - the expected output after processing data via an ed
script.
.pr Result from a piped ed script.
.err Error - invalid ed commands that should generate an error
.err Error - invalid ed commands that should generate an error.
The output of the .ed scripts is written to files with .o extension and
compared with their corresponding .r result files. The .err scripts
should exit with non-zero status without altering the contents of the
buffer.
The output of the tests is written to files with .o and .ro suffixes and
compared with their corresponding .r and .pr result files.
If any test fails, the error messages look like:
*** The script u.ed exited abnormally ***
......@@ -136,8 +127,7 @@ or:
Copyright (C) 1993, 1994 Andrew Moore
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
Free Software Foundation, Inc.
Copyright (C) 2006-2017 Antonio Diaz Diaz.
This file is free documentation: you have unlimited permission to copy,
distribute and modify it.
......
Some missing tests:
0) g/./s^@^@ - okay: NULs in commands
1) g/./s/^@/ - okay: NULs in patterns
2) a
hello^V^Jworld
. - okay: embedded newlines in insert mode
1) g/./s^@^@ - okay: NULs in commands
2) g/./s/^@/ - okay: NULs in patterns
3) ed -x - verify: 8-bit clean
4) ed - verify: long-line support
5) ed - verify: interactive/help mode
......
/* 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, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
Free Software Foundation, Inc.
Copyright (C) 2006-2017 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
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
......@@ -34,7 +33,6 @@ static int current_addr_ = 0; /* current address in editor buffer */
static int last_addr_ = 0; /* last address in editor buffer */
static bool isbinary_ = false; /* if set, buffer contains ASCII NULs */
static bool modified_ = false; /* if set, buffer modified since last write */
static bool newline_added_ = false; /* if set, newline appended to input file */
static bool seek_write = false; /* seek before writing */
static FILE * sfp = 0; /* scratch file pointer */
......@@ -57,9 +55,6 @@ void set_binary( void ) { isbinary_ = true; }
bool modified( void ) { return modified_; }
void set_modified( const bool m ) { modified_ = m; }
bool newline_added( void ) { return newline_added_; }
void set_newline_added( void ) { newline_added_ = true; }
int inc_addr( int addr )
{ if( ++addr > last_addr_ ) addr = 0; return addr; }
......@@ -82,10 +77,11 @@ static void insert_node( line_t * const lp, line_t * const prev )
/* add a line node in the editor buffer after the given line */
static void add_line_node( line_t * const lp, const int addr )
static void add_line_node( line_t * const lp )
{
line_t * const prev = search_line_node( addr );
line_t * const prev = search_line_node( current_addr_ );
insert_node( lp, prev );
++current_addr_;
++last_addr_;
}
......@@ -107,9 +103,9 @@ 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.
Return false if insertion fails. */
Returns false if insertion fails. */
bool append_lines( const char ** const ibufpp, const int addr,
const bool isglobal )
bool insert, const bool isglobal )
{
int size = 0;
undo_t * up = 0;
......@@ -119,10 +115,9 @@ bool append_lines( const char ** const ibufpp, const int addr,
{
if( !isglobal )
{
*ibufpp = get_tty_line( &size );
if( !*ibufpp ) return false;
if( size == 0 || (*ibufpp)[size-1] != '\n' )
{ clearerr( stdin ); return ( size == 0 ); }
*ibufpp = get_stdin_line( &size );
if( !*ibufpp ) return false; /* error */
if( size <= 0 ) return true; /* EOF */
}
else
{
......@@ -131,7 +126,8 @@ bool append_lines( const char ** const ibufpp, const int addr,
}
if( size == 2 && **ibufpp == '.' ) { *ibufpp += size; return true; }
disable_interrupts();
if( !put_sbuf_line( *ibufpp, size, current_addr_ ) )
if( insert ) { insert = false; if( current_addr_ > 0 ) --current_addr_; }
if( !put_sbuf_line( *ibufpp, size ) )
{ enable_interrupts(); return false; }
if( up ) up->tail = search_line_node( current_addr_ );
else
......@@ -203,7 +199,7 @@ bool copy_lines( const int first_addr, const int second_addr, const int addr )
disable_interrupts();
lp = dup_line_node( np );
if( !lp ) { enable_interrupts(); return false; }
add_line_node( lp, current_addr_++ );
add_line_node( lp );
if( up ) up->tail = lp;
else
{
......@@ -231,7 +227,7 @@ bool delete_lines( const int from, const int to, const bool isglobal )
if( isglobal ) unset_active_nodes( p->q_forw, n );
link_nodes( p, n );
last_addr_ -= to - from + 1;
current_addr_ = from - 1;
current_addr_ = min( from, last_addr_ );
modified_ = true;
enable_interrupts();
return true;
......@@ -320,12 +316,12 @@ bool join_lines( const int from, const int to, const bool isglobal )
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();
if( !put_sbuf_line( buf, size, current_addr_ ) ||
if( !put_sbuf_line( buf, size ) ||
!push_undo_atom( UADD, current_addr_, current_addr_ ) )
{ enable_interrupts(); return false; }
modified_ = true;
......@@ -382,7 +378,7 @@ bool move_lines( const int first_addr, const int second_addr, const int addr,
/* open scratch file */
bool open_sbuf( void )
{
isbinary_ = newline_added_ = false;
isbinary_ = false; reset_unterminated_line();
sfp = tmpfile();
if( !sfp )
{
......@@ -420,7 +416,7 @@ bool put_lines( const int addr )
disable_interrupts();
p = dup_line_node( lp );
if( !p ) { enable_interrupts(); return false; }
add_line_node( p, current_addr_++ );
add_line_node( p );
if( up ) up->tail = p;
else
{
......@@ -436,15 +432,13 @@ bool put_lines( const int addr )
/* write a line of text to the scratch file and add a line node to the
editor buffer; return a pointer to the end of the text */
const char * put_sbuf_line( const char * const buf, const int size,
const int addr )
editor buffer; return a pointer to the end of the text, or 0 if error */
const char * put_sbuf_line( const char * const buf, const int size )
{
line_t * const lp = dup_line_node( 0 );
const char * const p = (const char *) memchr( buf, '\n', size );
line_t * lp;
int len;
if( !lp ) return 0;
if( !p ) { set_error_msg( "Line too long" ); return 0; }
len = p - buf;
/* out of position */
......@@ -466,9 +460,10 @@ const char * put_sbuf_line( const char * const buf, const int size,
set_error_msg( "Cannot write temp file" );
return 0;
}
lp = dup_line_node( 0 );
if( !lp ) return 0;
lp->pos = sfpos; lp->len = len;
add_line_node( lp, addr );
++current_addr_;
add_line_node( lp );
sfpos += len; /* update file position */
return p + 1;
}
......@@ -492,7 +487,7 @@ line_t * search_line_node( const int addr )
}
}
else if( o_addr <= 2 * addr )
while( o_addr > addr ) { --o_addr; lp = lp->q_back; }
while( o_addr > addr ) { --o_addr; lp = lp->q_back; }
else
{ lp = &buffer_head; o_addr = 0;
while( o_addr < addr ) { ++o_addr; lp = lp->q_forw; } }
......@@ -542,6 +537,7 @@ void clear_undo_stack( void )
{
line_t * const lp = bp->q_forw;
unmark_line_node( bp );
unmark_unterminated_line( bp );
free( bp );
bp = lp;
}
......
/* Arg_parser - POSIX/GNU command line argument parser. (C version)
Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
Antonio Diaz Diaz.
Copyright (C) 2006-2017 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 3 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.
*/