Home | History | Annotate | only in /src/lib/libedit
History log of /src/lib/libedit
RevisionDateAuthorComments
 1.1 30-Aug-2021  christos Add a changes file
 1.70 03-Aug-2023  rin Revert CC_WNO_USE_AFTER_FREE from Makefile's (thanks uwe@)
 1.69 03-Aug-2023  rin Sprinkle CC_WNO_USE_AFTER_FREE for GCC 12

All of them are blamed for idiom equivalent to:
newbuf = realloc(buf, size);
p = newbuf + (p - buf);
 1.68 20-Jun-2023  wiz install pkg-config file for libedit

version number matches portable libedit
--cflags output matches portable libedit, since users probably want the
readline interface
 1.67 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.66 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.65 30-Jun-2017  kre branches: 1.65.6;

Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)

Note: this has currently only been tested with everything ascii (C locale).
 1.64 27-Jun-2017  christos add literal escape sequence support, patterned after the tcsh ones.
 1.63 24-May-2016  christos branches: 1.63.8;
remove debug read (Ingo Schwarze)
 1.62 09-May-2016  christos Instead of compiling all the source files together in one big file, use
protected visibility to achieve the same effect.
 1.61 02-May-2016  wiz Add missing backslash that broke build.
 1.60 02-May-2016  christos Add more MLINKS, sort
 1.59 28-Apr-2016  christos new man page from Ingo Schwarze.
 1.58 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.57 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.56 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.55 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.54 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.53 29-Jan-2015  joerg Disable -Wcast-qual for clang for now.
 1.52 14-Jun-2014  mrg branches: 1.52.2;
remove remaining makefile support for GCC < 45 that i found.
 1.51 10-Aug-2012  joerg branches: 1.51.2; 1.51.8;
Don't depend on HAVE_GCC being always defined.
 1.50 21-Mar-2012  matt These directories default to WARNS?=5
 1.49 16-Aug-2011  christos branches: 1.49.2;
re-enable -Wconversion
 1.48 02-Aug-2011  joerg Only use -Wconversion if GCC is actually the active compiler.
 1.47 30-Jul-2011  tron Don't use "-Wconversion" with GCC 4.5 which will complain about all the
expressions where signed variables are converted to unsigned in an
expression e.g. "size_t foo = sizeof(something) * int_var;".
 1.46 29-Jul-2011  christos pass -Wconversion
 1.45 29-Jul-2011  christos add -Wunused-parameter
Is that the right way? Perhaps WARNS=5?
 1.44 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.43 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.42 21-Jun-2011  mrg add some XXX'd -Wno-foo if HAVE_GCC >= 45.

XXX: someone should look at these.
 1.41 03-Feb-2010  roy branches: 1.41.4;
Userland now builds and uses terminfo instead of termcap.

OK: core@, jdc@
 1.40 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.39 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.38 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.37 18-Jan-2009  lukem WARNS=4
 1.36 28-May-2007  tls Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.35 31-Aug-2006  rpaulo Rename TEST/test.c to avoid problems when doing a cleandir on case-insensitive
file systems.
ok'ed christos.
 1.34 28-May-2005  lukem clean up build of "test"
 1.33 28-May-2005  lukem MAKEVERBOSE support
 1.32 18-May-2005  christos Libedit depends on libterm. From Patrick Welche
 1.31 07-May-2005  dsl Make everything that uses makelist depend on Makefile - that way the
created files pick up new entries.
 1.30 07-May-2005  dsl Separate out the filename completion functions from the readline() code.
Pass in loads of parameters instead of relying on shed-loads of global
variables to modify the behaviour.
The filename completion code can now be enabled by code that uses el_gets().
(eg /bin/sh)
 1.29 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.28 01-Aug-2003  lukem Rework how dependency generation is performed:

* DPSRCS contains extra dependencies, but is _NOT_ added to CLEANFILES.
This is a change of behaviour. If a Makefile wants the clean semantics
it must specifically append to CLEANFILES.
Resolves PR toolchain/5204.

* To recap: .d (depend) files are generated for all files in SRCS and DPSRCS
that have a suffix of: .c .m .s .S .C .cc .cpp .cxx

* If YHEADER is set, automatically add the .y->.h to DPSRCS & CLEANFILES

* Ensure that ${OBJS} ${POBJS} ${LOBJS} ${SOBJS} *.d depend upon ${DPSRCS}

* Deprecate the (short lived) DEPENDSRCS


Update the various Makefiles to these new semantics; generally either
adding to CLEANFILES (because DPSRCS doesn't do that anymore), or replacing
specific .o dependencies with DPSRCS entries.

Tested with "make -j 8 distribution" and "make distribution".
 1.27 31-Jul-2003  lukem tweak this unconventional (some might say "baroque") Makefile to work
with the new <bsd.dep.mk> *.d semantics.
fixes problems highlighted by Martin Husemann <martin@>
 1.26 08-May-2003  christos add a missing dependency (John Gordon)
 1.25 08-May-2003  christos Use ${HOST_SH}
 1.24 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.23 19-Aug-2002  lukem Explicitly move setting of NOxxx and USE_SHLIBDIR to the top of the
Makefile (before including <bsd.own.mk>)
 1.22 18-Mar-2002  christos Add a couple linted comment and enable WARNS=3
 1.21 28-Dec-2001  lukem * Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed
 1.20 05-Jan-2001  jdolecek Standard location of readline headers is /usr/include/readline/, so install
them there.
readline.h of libedit had to move to subdirectory 'readline', due to the way
BSD makefiles work; this is better than potentially fragile Makefile hacks
 1.19 15-Aug-2000  mrg use .tmp temporaries for generated files, to avoid having failed generated
output being used.
 1.18 06-Jul-1999  christos Use LIBEDITDIR instead of CURDIR so we can use that Makefile to compile
libedit from another directory.
 1.17 02-Jul-1999  simonb More trailing white space.
 1.16 04-Mar-1999  itohy Add minimal dependency to make "make depend" optional
after cleandir.
 1.15 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.14 13-Nov-1997  thorpej Build readline.o into debugging versions of libedit, too.
 1.13 26-Oct-1997  christos Make a link for history.h -> readline.h
 1.12 23-Oct-1997  christos PR/4301: Jaromir Dolecek. Add gnu-readline wrapper for editline.
 1.11 23-Oct-1997  lukem use CPPFLAGS instead of CFLAGS, fix building of test
 1.10 09-Oct-1997  lukem branches: 1.10.2;
- define WARNS?=1 in the top-level Makefile.inc, and don't define
anywhere else.
- for now, override WARNS=0 in librpcsvc and libwrap, until they're
cleaned up
- rcsid police

lib is now clean (except for librpcsvc and libwrap) on the i386, and
this should motivate the other ports to fix any other minor problems
that their compilers pick up that the i386 version doesn't.
 1.9 06-Jul-1997  christos Fix compiler warnings.
 1.8 09-May-1997  mycroft Eliminate bogus redefinitions of standard targets.
 1.7 24-Mar-1997  christos Makefile cleanups:
use INCS variable to install includes and FILES to install objects.
 1.6 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.5 09-Jan-1997  lukem * add a man page for the editline routines
* add a man page describing editrc
* fix bugs in el_parse():
* didn't execute command when program name matched (test reversed)
* was checking against empty string instead of program name
* after checks, command to run also pointed to empty string

[christos - the author of libedit - ok-ed the man pages in general (which I
wrote from scratch by RTFS) as well as the bugfix]
 1.4 18-Oct-1996  thorpej Use ${INSTALL}.
 1.3 01-Jun-1996  jtk merge bugfix from 1.2 branch: use includes target for include files
 1.2 06-May-1994  cgd branches: 1.2.8;
local
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.2.8.1 01-Jun-1996  jtk use includes target to install include files
 1.10.2.1 09-Nov-1997  lukem sync trunk's CPPFLAGS fix (approved by thorpej)
 1.41.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.49.2.2 30-Oct-2012  yamt sync with head
 1.49.2.1 17-Apr-2012  yamt sync with head
 1.51.8.1 10-Aug-2014  tls Rebase.
 1.51.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.52.2.1 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.63.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.65.6.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 02-Apr-2013  agc branches: 1.1.2;
file Version.map was initially added on branch agc-symver.
 1.1.2.1 02-Apr-2013  agc add symbol versioning info for:

libcrypt
libcurses
libedit
libmenu
libossaudio
libposix
libskey
 1.64 29-Jun-2024  christos Prevent testing out of bounds memory. From Robert Morris
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279762
 1.63 30-Oct-2022  christos improvements in malloc/free handling.
 1.62 08-Feb-2022  rillig libedit: fix typos, apply KNF to newly imported code (PR/56693)

No binary change.
 1.61 08-Feb-2022  christos PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key
 1.60 11-Jan-2022  christos PR/56618: Walter Lozano: Improve libedit compatibility with readline by
implementing:

rl_copy_text, rl_erase_empty_line, rl_message, rl_on_new_line,
rl_replace_line, rl_restore_prompt, rl_save_prompt
 1.59 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.58 23-Jul-2019  christos PR/54400: S�ren Tempel: out-of-bounds read in libedit c_delbefore
 1.57 11-Oct-2017  abhinav branches: 1.57.4;
Fix typo in comment
 1.56 22-May-2016  christos Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze
 1.55 09-May-2016  christos s/protected/libedit_private/g
 1.54 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.53 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.52 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.51 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.50 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.49 24-Feb-2016  christos A very simple, non-intrusive patch to fix a segfault (and a
functional error) in c_gets(), file chared.c.

Run any program using libedit in the default way. At the el_[w]gets()
prompt, invoke ed-command (for example, in emacs mode, press the
escape key, then type the letter 'x'). You should see a ": " prompt.
Type the letter 'x' again. Now press the backspace key a few times,
looking at the screen after each key press:

- The 1st BS deletes the 'x'.
- The 2nd BS deletes the blank after the prompt.
- The 3rd BS deletes the colon of the prompt.
- The 4th BS moves the cursor up one line.
- The 5th BS gives me "Segmentation fault (core dumped)".

Depending on your platform, it might take a few more or a few less
backspaces for the buffer underrun to trigger the segfault, but
you should be able to hit it sooner or later no matter what.

Run the same program again, connect again and invoke ed-command again.
Now type: 'b', backspace, 'i', backspace, 'n', backspace, 'd', enter.
The "bind" command gets executed, even though you deleted what you
typed before hitting enter.

From Ingo Schwatze.
 1.48 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.47 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.46 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.45 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.44 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.43 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.42 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.41 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.40 18-Jun-2014  christos Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
 1.39 12-Jul-2013  christos branches: 1.39.4;
cast to avoid warning.
 1.38 12-Jul-2013  christos Add a function to move the cursor.
 1.37 18-Jul-2012  christos branches: 1.37.2;
From Kamil Dudka: fix crash of el_insertstr() on incomplete multi-byte
 1.36 23-Oct-2011  christos branches: 1.36.2;
Fixed misplaced parenthesis (Nirbhay Choubey)
 1.35 16-Aug-2011  christos re-enable -Wconversion
 1.34 29-Jul-2011  christos pass -Wconversion
 1.33 29-Jul-2011  christos kill ifdef notdef
 1.32 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.31 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.30 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.29 28-Aug-2010  christos setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.
 1.28 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.27 15-Feb-2009  christos pass lint on _LP64.
 1.26 06-Feb-2009  sketch branches: 1.26.2;
de-__P()
 1.25 08-Aug-2005  christos The previous commit removed too much and forgot to reset the history event
number. From Kouichirou Hiratsuka, many thanks!
 1.24 01-Aug-2005  christos Don't reset the macro strings each time we enter el_gets(), otherwise
el_push() is unusable programmatically.
 1.23 01-Jun-2005  lukem Don't use non-standard uint or u_int.
 1.22 13-Aug-2004  mycroft Delete-previous-char and delete-next-char without an argument are not supposed
to modify the yank buffer in Emacs. Make it so.
 1.21 02-Nov-2003  christos Always use el->el_buffer, because newbuffer could have moved. From
Gerry Swislow gerry at certif dot com
 1.20 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 20-Nov-2002  christos Fix problem with previous patches that broke vi history.
- c_gets() was usually returning a length, but sometimes
one of the CC_xxx values (which are small +ve integers)!
- fixed c_gets() by putting a ' ' under the cursor.
From David Laight.
 1.17 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.16 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.15 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.14 17-May-2001  christos PR/12963:Jason Waterman: Fix signed cast problems.
 1.13 13-Apr-2001  lukem knf ch_enlargebufs(), to be *consistent* with the rest of this file...
 1.12 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.11 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.10 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.9 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.8 28-Feb-2000  chopps el_insertstr takes a "const char *" not "char *" now as it doesn't modify
the argument.
 1.7 02-Jul-1999  simonb More trailing white space.
 1.6 05-Feb-1999  christos delint.
 1.5 12-Dec-1998  christos delint
 1.4 03-Feb-1998  perry remove obsolete register declarations
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.26.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.36.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.2.1 30-Oct-2012  yamt sync with head
 1.37.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.39.4.1 10-Aug-2014  tls Rebase.
 1.57.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.30 22-May-2016  christos Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze
 1.29 09-May-2016  christos s/protected/libedit_private/g
 1.28 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.27 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.26 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.25 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.24 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.23 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.22 18-Jun-2014  christos Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
 1.21 28-Aug-2010  christos branches: 1.21.12; 1.21.22;
setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.
 1.20 15-Apr-2010  christos From Jess Thrysoee
- Fix wint_t to Int confusion
 1.19 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.18 15-Feb-2009  christos pass lint on _LP64.
 1.17 06-Mar-2006  christos branches: 1.17.28;
Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.16 08-Aug-2005  christos Spelling mistakes and comment errors (from FreeBSD via Stefan Farfeleder; many
thanks)
 1.15 01-Aug-2005  christos Don't reset the macro strings each time we enter el_gets(), otherwise
el_push() is unusable programmatically.
 1.14 13-Aug-2004  mycroft Delete-previous-char and delete-next-char without an argument are not supposed
to modify the yank buffer in Emacs. Make it so.
 1.13 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 20-Nov-2002  christos Fix problem with previous patches that broke vi history.
- c_gets() was usually returning a length, but sometimes
one of the CC_xxx values (which are small +ve integers)!
- fixed c_gets() by putting a ' ' under the cursor.
From David Laight.
 1.10 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.9 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.8 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.7 03-Feb-2002  christos Fixed an __P remnant
 1.6 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.5 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.4 02-Jul-1999  simonb More trailing white space.
 1.3 12-Dec-1998  christos delint
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.17.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.22.1 10-Aug-2014  tls Rebase.
 1.21.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.37 10-Aug-2023  mrg avoid various use-after-free issues.

create a ptrdiff_t offset between the start of an allocation region and
some interesting pointer, so it can be adjusted with this offset after
realloc() returns.

found by GCC 12.
 1.36 30-Oct-2022  christos improvements in malloc/free handling.
 1.35 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.34 25-Nov-2018  christos From Yuichiro Naito (FreeBSD):
hrs@ says that wctomb(3) has an internal shift state,
if wctomb(3) is called outside of libedit,
the internal state can be changed and causes miscalculate multibyte size.

So in this part, wcrtomb(3) should be used.
wcrtomb(3) requires that shift state is given in the argument.
We always initialize the shift state in ct_enc_width() to keep independent
from outside of libedit.
 1.33 18-Nov-2018  christos fix compilation
 1.32 18-Nov-2018  christos Remove utf-8 requirement (Yuichiro NAITO)
 1.31 09-Jan-2017  christos branches: 1.31.12; 1.31.14;
Make sure that argv is NULL terminated since functions like tty_stty rely
on it to be so (Gerry Swinslow)
 1.30 09-May-2016  christos branches: 1.30.2;
s/protected/libedit_private/g
 1.29 02-May-2016  christos eliminate static buffer with custom resizing code.
 1.28 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.27 11-Apr-2016  christos chartype cleanups from Ingo Schwarze:

- The file tokenizer.c no longer uses chartype.h,
so don't include the header.

- The dummy definitions of ct_{de,en}code_string() for the
NARROWCHAR case are only used in history.c, so move them there.

- Now the whole content of chartype.h is for the wide character
case only. So remove the NARROWCHAR ifdef and include the
header only in the wide character case.

- In chartype.h, move ct_encode_char() below the comment explaining it.

- No more need for underscores before ct_{de,en}code_string().

- Make the conversion buffer resize functions private.
They are only called from the decoding and encoding functions
inside chartype.c, and no need can possibly arise to call them
from anywhere else.
 1.26 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.25 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.24 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.23 28-Feb-2016  christos remove 4 clause licenses.
 1.22 24-Feb-2016  christos Tuck in mbstate_t to the wide char version only to avoid exposing the zeroing
hack and doing it in the narrow case.
 1.21 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.20 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.19 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.18 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.17 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.16 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.15 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.14 14-Feb-2016  christos From Ingo Schwartze:

Next step: Remove #ifdef'ing in read_char(), in the same style
as we did for setlocale(3) in el.c.

A few remarks are required to explain the choices made.

* On first sight, handling mbrtowc(3) seems a bit less trivial
than handling setlocale(3) because its prototype uses the data
type mbstate_t from <wchar.h>. However, it turns out that
"histedit.h" already includes <wchar.h> unconditionally (i don't
like headers including other headers, but that ship has sailed,
people are by now certainly used to the fact that including
"histedit.h" doesn't require including <wchar.h> before), and
"histedit.h" is of course included all over the place. So from
that perspective, there is no problem with using mbrtowc(3)
unconditionally ever for !WIDECHAR.

* However, <wchar.h> also defines the mbrtowc(3) prototype,
so we cannot just #define mbrtowc away, or including the header
will break. It would also be a bad idea to porovide a local
implementation of mbrtowc() and hope that it overrides the one
in libc. Besides, the required prototype is subtly different:
While mbrtowc(3) takes "wchar_t *" as its first argument, we
need a function that takes "Char *". So unfortunately, we have
to keep a ct_mbrtowc #define, at least until we can maybe get
rid of "Char *" in the more remote future.

* After getting rid of the #else clause in read_char(), we can
pull "return 1;" into the default: clause. After that, we can
get rid of the ugly "goto again_lastbyte;" and just "break;".
As a bonus, that also gets rid of the ugly CONSTCOND.

* While here, delete the unused ct_mbtowc() from chartype.h.
 1.13 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.12 22-Feb-2015  christos split the allocation functions, their mixed usage was too confusing.
 1.11 22-Feb-2015  christos PR/49683: Amir Plivatsky: Off-by-one comparison in ct_decode_string() leading
to out of bounds referrence.
XXX: pullup-7
 1.10 16-Aug-2011  christos branches: 1.10.20;
re-enable -Wconversion
 1.9 29-Jul-2011  christos pass -Wconversion
 1.8 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.7 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.6 28-Jul-2011  christos - fix memory allocation botch in wide strings
- check mbstowcs return code
 1.5 27-Jul-2011  christos fix buffer growing code.
 1.4 15-Apr-2010  christos From Jess Thrysoee
expose ct_enc_width()
 1.3 12-Jan-2010  christos - in the argv conversion, handle NULL as NULL
- when printing tab/nl print them, don't handle them specially.
 1.2 31-Dec-2009  christos expose the encode and decode string functions for the benefit of history
and readline.
 1.1 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.10.20.1 14-Apr-2015  snj Pull up following revision(s) (requested by christos in ticket #679):
lib/libedit/chartype.c: revisions 1.11, 1.12
lib/libedit/chartype.h: revisions 1.12, 1.13
PR/49683: Amir Plivatsky: Off-by-one comparison in ct_decode_string() leading
to out of bounds referrence.
--
split the allocation functions, their mixed usage was too confusing.
 1.30.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.31.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.31.14.1 10-Jun-2019  christos Sync with HEAD
 1.31.12.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.37 11-Apr-2022  tnn libedit/chartype.h: portability fix for OSF/1
 1.36 15-Sep-2019  christos Fix type and remove cast (Yuichiro NAITO/FreeBSD).
 1.35 22-May-2017  christos branches: 1.35.10;
Add DragonFly.
 1.34 09-May-2016  christos s/protected/libedit_private/g
 1.33 02-May-2016  christos eliminate static buffer with custom resizing code.
 1.32 02-May-2016  christos fix typos from Pedro Giffuni @FreeBSD
 1.31 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.30 11-Apr-2016  christos chartype cleanups from Ingo Schwarze:

- The file tokenizer.c no longer uses chartype.h,
so don't include the header.

- The dummy definitions of ct_{de,en}code_string() for the
NARROWCHAR case are only used in history.c, so move them there.

- Now the whole content of chartype.h is for the wide character
case only. So remove the NARROWCHAR ifdef and include the
header only in the wide character case.

- In chartype.h, move ct_encode_char() below the comment explaining it.

- No more need for underscores before ct_{de,en}code_string().

- Make the conversion buffer resize functions private.
They are only called from the decoding and encoding functions
inside chartype.c, and no need can possibly arise to call them
from anywhere else.
 1.29 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.28 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.27 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.26 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.25 07-Mar-2016  christos Remove advertising clause.
 1.24 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.23 24-Feb-2016  christos Tuck in mbstate_t to the wide char version only to avoid exposing the zeroing
hack and doing it in the narrow case.
 1.22 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.21 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.20 14-Feb-2016  christos From Ingo Schwarze:

el_getc() for the WIDECHAR case, that is, the version in eln.c.
For a UTF-8 locale, it is broken in four ways:

1. If the character read is outside the ASCII range, the function
does an undefined cast from wchar_t to char. Even if wchar_t
is internally represented as UCS-4, that is wrong and dangerous
because characters beyond codepoint U+0255 get their high bits
truncated, meaning that perfectly valid printable Unicode
characters get mapped to arbitrary bytes, even the ASCII escape
character for some Unicode characters. But wchar_t need not
be implemented in terms of UCS-4, so the outcome of this function
is undefined for any and all input.

2. If insufficient space is available for the result, the function
fails to detect failure and returns garbage rather than -1 as
specified in the documentation.

3. The documentation says that errno will be set on failure, but
that doesn't happen either in the above case.

4. Even for ASCII characters, the results may be wrong if wchar_t
is not using UCS-4.
 1.19 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.18 14-Feb-2016  christos From Ingo Schwartze:

Next step: Remove #ifdef'ing in read_char(), in the same style
as we did for setlocale(3) in el.c.

A few remarks are required to explain the choices made.

* On first sight, handling mbrtowc(3) seems a bit less trivial
than handling setlocale(3) because its prototype uses the data
type mbstate_t from <wchar.h>. However, it turns out that
"histedit.h" already includes <wchar.h> unconditionally (i don't
like headers including other headers, but that ship has sailed,
people are by now certainly used to the fact that including
"histedit.h" doesn't require including <wchar.h> before), and
"histedit.h" is of course included all over the place. So from
that perspective, there is no problem with using mbrtowc(3)
unconditionally ever for !WIDECHAR.

* However, <wchar.h> also defines the mbrtowc(3) prototype,
so we cannot just #define mbrtowc away, or including the header
will break. It would also be a bad idea to porovide a local
implementation of mbrtowc() and hope that it overrides the one
in libc. Besides, the required prototype is subtly different:
While mbrtowc(3) takes "wchar_t *" as its first argument, we
need a function that takes "Char *". So unfortunately, we have
to keep a ct_mbrtowc #define, at least until we can maybe get
rid of "Char *" in the more remote future.

* After getting rid of the #else clause in read_char(), we can
pull "return 1;" into the default: clause. After that, we can
get rid of the ugly "goto again_lastbyte;" and just "break;".
As a bonus, that also gets rid of the ugly CONSTCOND.

* While here, delete the unused ct_mbtowc() from chartype.h.
 1.17 11-Feb-2016  christos remove unused wrapper (Ingo Schwarze)
 1.16 08-Feb-2016  christos UTF-8 fixes from Ingo Schwarze:

1. Assume that errno is non-zero when entering read_char()
and that read(2) returns 0 (indicating end of file).
Then, the code will clear errno before returning.
(Obviously, the statement "errno = 0" is almost always
a bug unless there is save_errno = errno right before it
and the previous value is properly restored later,
in all reachable code paths.)

2. When encountering an invalid byte sequence, the code discards
all following bytes until MB_LEN_MAX overflows; consider, for
example, 0xc2 immediately followed by a few valid ASCII bytes.
Three of those ASCII bytes will be discarded.

3. On a POSIX system, EILSEQ will always be set after reading a
valid (yes, valid, not invalid!) UTF-8 character. The reason
is that mbtowc(3) will first be called with a length limit
(third argument) of 1, which will fail, return -1, and - on
a POSIX system - set errno to EILSEQ.
This third bug is mitigated a bit because i couldn't find any
system that actually conforms to POSIX in this respect: None
of OpenBSD, NetBSD, FreeBSD, Solaris 11, and glibc set errno
when an incomplete character is passed to mbtowc(3), even though
that is required by POSIX.
Anyway, that mbtowc(3) bug will be fixed at least in OpenBSD
after release unlock, so it would be good to fix this bug in
libedit before fixing the bug in mbtowc(3).

How can these three bugs be fixed?

1. As far as i understand it, the intention of the bogus errno = 0
is to undo the effects of failing system calls in el_wset(),
sig_set(), and read__fixio() if the subsequent read(2) indicates
end of file. So, restoring errno has to be moved right after
read__fixio(). Of course, neither 0 nor e is the right value
to restore: 0 is wrong if errno happened to be set on entry, e
would be wrong because if one read(2) fails but a second attempt
succeeds after read__fixio(), errno should not be touched. So,
the errno to be restored in this case has to be saved before
calling read(2) for the first time.

2. Solving the second issue requires distinguishing invalid and
incomplete characters, but that is impossible with the function
mbtowc(3) because it returns -1 in both cases and sets errno
to EILSEQ in both cases (once properly implemented).

It is vital that each input character is processed right away.
It is not acceptable to wait for the next input character before
processing the previous one because this is an interactive
library, not a batch system. Consequently, the only situation
where it is acceptable to wait for the next byte without first
processing the previous one(s) is when the previous one(s) form
an incomplete sequence that can be continued to form a valid
character.

Consequently, short of reimplementing a full UTF-8 state machine
by hand, the only correct way forward is to use mbrtowc(3).
Even then, care is needed to always have the state object
properly initialized before using it, and to not discard a valid
ASCII or UTF-8 lead byte if it happens to follow an invalid
sequence.

3. Fortunately, solution 2. also solves issue 3. as a side effect,
by no longer using mbtowc(3) in the first place.
 1.15 17-May-2015  christos add FreeBSD
 1.14 14-May-2015  christos fix warnings on ubuntu 32 bit (Miki Rozloznik)
 1.13 22-Feb-2015  christos split the allocation functions, their mixed usage was too confusing.
 1.12 22-Feb-2015  christos PR/49683: Amir Plivatsky: Off-by-one comparison in ct_decode_string() leading
to out of bounds referrence.
XXX: pullup-7
 1.11 17-Feb-2015  christos OpenBSD is like us.
 1.10 16-Nov-2011  christos branches: 1.10.18;
easier with an int for now.
 1.9 15-Nov-2011  christos Since Width() is used only for display purposes we don't want to pass -1 for
unprintable characters.
 1.8 29-Jul-2011  christos branches: 1.8.2;
pass -Wconversion
 1.7 16-Dec-2010  wiz Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.6 20-Apr-2010  christos Use the same hack for Solaris and MacOS/X. This is not right, we only really
support UTF-8, but it will get us going until this is fixed properly.
From Jess Thrysoee
 1.5 15-Apr-2010  christos From Jess Thrysoee
expose ct_enc_width()
 1.4 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.3 31-Dec-2009  christos expose the encode and decode string functions for the benefit of history
and readline.
 1.2 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.1 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.8.2.1 17-Apr-2012  yamt sync with head
 1.10.18.2 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.10.18.1 14-Apr-2015  snj Pull up following revision(s) (requested by christos in ticket #679):
lib/libedit/chartype.c: revisions 1.11, 1.12
lib/libedit/chartype.h: revisions 1.12, 1.13
PR/49683: Amir Plivatsky: Off-by-one comparison in ct_decode_string() leading
to out of bounds referrence.
--
split the allocation functions, their mixed usage was too confusing.
 1.35.10.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.50 30-Jun-2024  christos Avoid moving the cursor before the buffer (Robert Morris)
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279487
 1.49 30-Mar-2020  ryo branches: 1.49.8;
fix build error with SDEBUG, MAP_DEBUG, DEBUG_REFRESH
 1.48 26-Feb-2018  christos branches: 1.48.4;
PR/53058: Nikhil Benesch: use correctly typed variables (wchar_t vs wint_t)
as parameters.
 1.47 22-May-2016  christos Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze
 1.46 09-May-2016  christos s/protected/libedit_private/g
 1.45 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.44 17-Apr-2016  christos Remove empty callbacks (Ingo Schwartze)
 1.43 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.42 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.41 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.40 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.39 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.38 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.37 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.36 16-Feb-2016  christos get rid of bool_t (Ingo Schwarze)
 1.35 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.34 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.33 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.32 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.31 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.30 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.29 24-Mar-2012  christos From Jilles Tjoelker:
Do not move the cursor for ed-delete-next-char in emacs mode.
This makes ed-delete-next-char suitable for mapping to the <Delete> key.
Behaviour in vi mode is unchanged (for 'x').
 1.28 29-Jul-2011  christos branches: 1.28.2;
- fix unused params
- unconditionalize vis.h
 1.27 29-Jul-2011  christos kill ifdef notdef
 1.26 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.25 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.24 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.23 27-Feb-2009  msaitoh fix mis-evaluating whether a char is digit or not.
 1.22 15-Feb-2009  christos pass lint on _LP64.
 1.21 30-Sep-2008  aymeric branches: 1.21.4; 1.21.6; 1.21.10;
have '$' include the last character in the line when embedded in a command.
This fixes c$, d$, y$, and so on in vi mode.
 1.20 10-Sep-2008  christos Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.19 06-Mar-2006  christos branches: 1.19.4; 1.19.20;
Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.18 08-Aug-2005  christos Spelling mistakes and comment errors (from FreeBSD via Stefan Farfeleder; many
thanks)
 1.17 01-Aug-2005  christos Don't reset the macro strings each time we enter el_gets(), otherwise
el_push() is unusable programmatically.
 1.16 07-Aug-2003  agc branches: 1.16.6;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.15 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.14 20-Nov-2002  christos Fix problem with previous patches that broke vi history.
- c_gets() was usually returning a length, but sometimes
one of the CC_xxx values (which are small +ve integers)!
- fixed c_gets() by putting a ' ' under the cursor.
From David Laight.
 1.13 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.12 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.11 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.10 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.9 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.8 02-Jul-1999  simonb More trailing white space.
 1.7 12-Dec-1998  christos delint
 1.6 20-May-1998  christos Don't print to stderr, but to the editline error stream.
 1.5 03-Feb-1998  perry remove obsolete register declarations
 1.4 06-Jul-1997  christos Fix compiler warnings.
 1.3 14-Jan-1997  lukem Implement CC_REDISPLAY, which (unlink CC_REFRESH) redraws the entire input
line (a la ^R). This is useful if the binding outputs information and
mucks up the input line. To be used in ``list-choices'' bindings (refer
to the ^D binding in csh when filec is set)
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.16.6.1 23-Apr-2009  snj Pull up following revision(s) (requested by msaitoh in ticket #2006):
lib/libedit/common.c: revision 1.23
fix mis-evaluating whether a char is digit or not.
 1.19.20.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.19.4.1 30-Apr-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1307):
lib/libedit/common.c: revision 1.23
fix mis-evaluating whether a char is digit or not.
 1.21.10.1 21-Apr-2010  matt sync to netbsd-5
 1.21.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.4.1 03-May-2009  snj Pull up following revision(s) (requested by msaitoh in ticket #703):
lib/libedit/common.c: revision 1.23
fix mis-evaluating whether a char is digit or not.
 1.28.2.1 17-Apr-2012  yamt sync with head
 1.48.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.49.8.1 01-Jul-2024  perseant Sync with HEAD.
 1.10 04-Feb-2023  christos Remove unused stuff, and limit the scope of some of the used ones.
(from des@freebsd)
 1.9 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.8 16-Feb-2016  christos - don't set _GNU_SOURCE. We are not supposed to make decisions for others.
- don't special-case wcsdup()
From Ingo Schwarze.
 1.7 15-Feb-2016  christos OpenBSD readline.c rev. 1.14 2015/02/06 23:21:58 millert
use SIZE_MAX
 1.6 15-Feb-2016  christos change tests for fgetln.
 1.5 29-Jul-2011  christos better autoconf results
 1.4 28-Jul-2011  joerg Sync compat defines to unbreak build.

XXX Do a proper config.h update from configure
 1.3 28-Jul-2011  christos regen
 1.2 26-Jan-2009  apb Define HAVE_STRUCT_DIRENT_D_NAMLEN in config,h, and test it when
deciding whether to use entry->d_namlen or strlen(entry->d_name).
Addresses PR 40477 by Robert Millan.
 1.1 18-Mar-2002  christos oops, we need config.h now.
 1.1 21-Nov-2024  riastradh branches: 1.1.4;
libedit: Add expected symbols list.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 21-Nov-2024  perseant file edit.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:48 +0000
 1.102 04-Feb-2024  andvar s/interrrupt/interrupt/ in comment and editline(3) man page.
 1.101 15-Aug-2021  wiz Add verb to sentence.
 1.100 15-Aug-2021  christos Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.
 1.99 18-Nov-2018  christos Remove utf-8 requirement (Yuichiro NAITO)
 1.98 02-Sep-2017  wiz branches: 1.98.2; 1.98.4;
Remove trailing whitespace; convert Xr readline to Nm readline, since
we won't get a readline man page in base.
 1.97 01-Sep-2017  christos PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.96 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.95 27-Jun-2017  christos mention the limitation of the literal sequence delimiter.
 1.94 27-Jun-2017  kre Include EDITRC in doc.
 1.93 10-Apr-2017  abhinav branches: 1.93.4;
Add missing argument for H_SET.

ok christos@
 1.92 22-May-2016  christos branches: 1.92.2; 1.92.4;
documentation improvements (Ingo Schwarze)
 1.91 21-May-2016  christos Fix the prototype used by EL_GETCFN, mention the associated typedef
name, document the return values, expand the list of affected
functions, warn against using EL_GETCFN, and clarify some wording
and notation. (Ingo Schwarze)
 1.90 09-May-2016  christos GNU readline(3) regards history chronologically, that is, from the
perspective of the dawn of time, so "next" means "newer" and "previous"
means "older". Libedit, by contrast, uses reverse chronology and
regards history from the perspective of the present, such that "next"
means "longer ago" and "previous" means "not so long ago".

The following patch fixes previous_history() and next_history()
as proposed by Bastian Maerkisch.

But there is a related problem demonstrated by Bastian's regression
tests that his patch did not fix: next_history() can advance not
only to the newest entry, but beyond it, which core libedit cannot
do. So that feature must be implemented locally in readline.c.

With that, the last of Bastians tests is fixed, test_movement_direction().

This patch also improves libedit documentation to more clearly state
what "previous" and "next" mean. GNU readline documentation is
just as unclear, but we can't easily fix that since libedit doesn't
include its own readline.3 manual.

(Ingo Schwarze)
 1.89 28-Apr-2016  christos new man page from Ingo Schwarze.
 1.88 25-Feb-2016  wiz Use \- for minus sign, use Ev, use Er.
 1.87 24-Feb-2016  christos Fix el_{w,}getc documentation (Ingo Schwarze)
 1.86 24-Feb-2016  christos Fixes from OpenBSD via Ingo Schwarze:
1) Missing comma after tok_str in NAME.
OpenBSD rev. 1.38 Sep 10, 2015 (schwarze)
2) Style: void in argument list.
OpenBSD rev. 1.39 Sep 14, 2015 (schwarze)
3) English punctuation: stray comma.
OpenBSD rev. 1.37 Mar 13, 2015 (jmc)
 1.85 03-Nov-2015  christos Fix descriptions of el_set functions.
Americanise initialise :-)
 1.84 25-Dec-2014  wiz Bump date for previous.
 1.83 25-Dec-2014  wiz From Ingo Schwarze, based on changes from Kaspars Bankovskis:
* Document error handling of el_init(), el_set(), el_source(),
and history_init().
* Fix a typo an improve punctuation below H_SETUNIQUE.
* The ellipsis already implies "optional", no need for [].
* Sort options in editrc(5).
* Prevent e.g. rom being misconstrued as the end of a sentence.
* Drop a useless duplicate .Ar macro.
* Put telltc in its proper place in the alphabetical order.
* A few typos in vi editor command names.
* Some missing vi editor command names.
* Some missing author macros.
 1.82 11-May-2014  wiz branches: 1.82.2;
Add An to authors. Wording.
 1.81 11-May-2014  christos Add a history function that takes a FILE pointer; needed for Capsicum.
From Eitan Adler
 1.80 12-Jul-2013  christos branches: 1.80.4;
Add a function to move the cursor.
 1.79 22-Jan-2013  christos provide an el_init_fd function.
 1.78 10-Jan-2013  wiz In 2000, .editrc reading from $PWD was removed. Update the man page.
From LEVAI Daniel via jmc@OpenBSD.
 1.77 11-Sep-2012  christos branches: 1.77.2;
PR/46945: Steffen Nurpmeso; el_getc() doesn't document it's setting errno
 1.76 11-Sep-2012  christos PR/46941: Steffen Nurpmeso: document EL_BUFFERED
 1.75 27-Feb-2011  christos branches: 1.75.4;
Fix argument for EL_EDITOR from Jess Thrysoee
 1.74 16-Dec-2010  wiz branches: 1.74.2;
Observe the following spelling:
- wide character (noun)
- wide-character (adjective)

Inspired by jmc@OpenBSD.
 1.73 03-Jan-2010  wiz Bump date for historyw -> history_w.
 1.72 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.71 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.70 05-Jul-2009  perry note that the return value of el_gets doesn't remain valid across
calls.
 1.69 12-May-2009  wiz Punctuation nit.
 1.68 11-May-2009  christos restore binary compatibility by providing new prompt functions that take
an extra literal character.
 1.67 11-Apr-2009  joerg Don't use .Xo/.Xc to avoid ancient macro argument limit.
 1.66 01-Apr-2009  wiz Readability improvement. Whitespace nits.
 1.65 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.64 10-Mar-2009  wiz -1 is not a defined value, it is just a value.
On the other hand, minuses need backslashes, otherwise they become hyphens.
 1.63 10-Mar-2009  christos make el_gets set the count to -1 on error to distinguish between EOF and
error.
 1.62 09-Mar-2009  joerg Fix preamble to match order set out by mdoc(7). Discussed with wiz.
 1.61 21-Feb-2009  wiz Restore markup changes (probably accidentally) reverted in previous.
 1.60 21-Feb-2009  christos back out all prompt changes. they are not needed.
 1.59 19-Feb-2009  wiz Fix wordo, use more markup.
 1.58 19-Feb-2009  christos document extra argument.
 1.57 30-Apr-2008  martin branches: 1.57.8;
Convert TNF licenses to new 2 clause variant
 1.56 05-Apr-2008  christos branches: 1.56.2;
add EL_REFRESH for the benefit of readline
 1.55 12-Jan-2007  christos PR/35411: Matthew Wala: inconsistency in editline(3): rename "num" to the
appropriate parameter names.
 1.54 18-Dec-2006  wiz Fix xref section. Whitespace cleanups..
 1.53 15-Dec-2006  christos add EL_GETFP, and EL_SETFP.
 1.52 24-Nov-2006  christos - Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.51 21-Aug-2006  christos Change to a 3 clause copyright after permission of the holders.
 1.50 12-Oct-2005  wiz Add el_get to SYNOPSIS. From jmc@openbsd.
 1.49 09-Sep-2005  wiz Fix double if (from Alexey E. Suslikov via jmc@openbsd).
While here, re-word both H_[GS]ETUNIQUE descriptions so they make
more sense. Bump date.
 1.48 14-Jul-2005  wiz Drop trailing whitespace.
 1.47 14-Jul-2005  christos PR/30747: David N. Williams: libedit is missing remove_history()
Added, please test.
 1.46 19-Mar-2005  christos PR/29738: Rui Paulo: Incorrect tok_line and tok_str declarations.
 1.45 15-Apr-2004  wiz Remove duplicate word, from jfb@openbsd via jmc@openbsd.
 1.44 05-Dec-2003  wiz Use Aq instead of <>, quote a minus, drop trailing space.
 1.43 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.42 04-Nov-2003  christos s/wth/with/
 1.41 01-Nov-2003  christos Explain H_ADD better. from Otto Moerbeek otto at drijf dot net
 1.40 17-Oct-2003  wiz Bump date for previous. Replace > with \*[Gt].
 1.39 16-Oct-2003  christos More libedit readline emulation functions from: Gerry Swislow
<gerry at certif dot com>
 1.38 26-Sep-2003  wiz New sentence, new line; bump date for previous.
 1.37 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.36 16-Jul-2003  wiz Bump date for last.
 1.35 14-Jul-2003  jeremy Documented the return values from el_get().
 1.34 06-Jun-2003  wiz Use Aq Pa instead of Fd \*[Lt]...\*[Gt]. From jmc@openbsd.
 1.33 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.32 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.31 21-Jan-2003  wiz Replace -1 with \-1 for PostScript output; drop a trailing space and fix two typos.
 1.30 21-Jan-2003  christos Add a uniquefier for the history function.
 1.29 01-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.28 18-Aug-2002  yamt reflect reality.
(3rd arg of el_parse is const.)
 1.27 20-Feb-2002  wiz Close quoting.
 1.26 07-Feb-2002  ross Generate <>& symbolically.
 1.25 15-Jan-2002  wiz Punctuation and whitespace nits, fix a typo.
 1.24 09-Oct-2001  christos PR/14188: Anthony Mallet: Provide an opaque data pointer to client programs.
 1.23 04-Oct-2001  lukem a couple of minor fixes. originally by Ruslan Ermilov <ru@FreeBSD.org>,
highlighted to me by way of Mike Barcroft <mike@FreeBSD.org> (thanks!)
 1.22 27-Sep-2001  christos PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
 1.21 02-Apr-2001  wiz End sentence with a dot.
 1.20 28-Feb-2000  chopps el_insertstr takes a "const char *" not "char *" now as it doesn't modify
the argument.
 1.19 26-Nov-1999  lukem missing ,
 1.18 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.17 02-Jul-1999  simonb branches: 1.17.4;
More trailing white space.
 1.16 22-Mar-1999  garbled Last of the .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Wheee!
 1.15 05-Jan-1999  lukem fix history() prototype. (d@openbsd.org)
 1.14 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.13 08-Jun-1998  lukem documentation is always probably incomplete; don't make an issue of it
 1.12 01-Jun-1998  lukem * implement CC_REFRESH_BEEP; as per CC_REFRESH but beep as well. this
is useful in completion when a partial completion is found
* remove entry in BUGS about el_parse(); that was fixed a while ago
 1.11 20-May-1998  christos Add H_APPEND to simplify the interface.
 1.10 20-May-1998  christos Adjust for changes.
 1.9 05-Feb-1998  perry add LIBRARY section to man page
 1.8 21-Jan-1998  lukem in el_parse(), use a temporary buffer to store the program name when
comparing, preventing trashing of argv[0]. remove note in man page
warning of former behaviour.
 1.7 09-Nov-1997  lukem move description of history() return value
 1.6 14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.5 30-Jul-1997  jtc Fix files using old TNF copyright notice
 1.4 14-Jan-1997  lukem Implement CC_REDISPLAY, which (unlink CC_REFRESH) redraws the entire input
line (a la ^R). This is useful if the binding outputs information and
mucks up the input line. To be used in ``list-choices'' bindings (refer
to the ^D binding in csh when filec is set)
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 11-Jan-1997  lukem * in el_parse(), don't reference argv[0] if argc < 1 (return -1 instead)
* clarify return value of el_parse()
 1.1 09-Jan-1997  lukem * add a man page for the editline routines
* add a man page describing editrc
* fix bugs in el_parse():
* didn't execute command when program name matched (test reversed)
* was checking against empty string instead of program name
* after checks, command to run also pointed to empty string

[christos - the author of libedit - ok-ed the man pages in general (which I
wrote from scratch by RTFS) as well as the bugfix]
 1.17.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.56.2.1 18-May-2008  yamt sync with head.
 1.57.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.74.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.75.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.75.4.2 23-Jan-2013  yamt sync with head
 1.75.4.1 30-Oct-2012  yamt sync with head
 1.77.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.77.2.1 25-Feb-2013  tls resync with head
 1.80.4.1 10-Aug-2014  tls Rebase.
 1.82.2.1 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.92.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.92.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.93.4.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.98.4.1 10-Jun-2019  christos Sync with HEAD
 1.98.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.6 06-Apr-2024  christos update em-toggle-overwrite binding (Xose Vazquez Perez)
 1.5 09-May-2016  christos GNU readline(3) regards history chronologically, that is, from the
perspective of the dawn of time, so "next" means "newer" and "previous"
means "older". Libedit, by contrast, uses reverse chronology and
regards history from the perspective of the present, such that "next"
means "longer ago" and "previous" means "not so long ago".

The following patch fixes previous_history() and next_history()
as proposed by Bastian Maerkisch.

But there is a related problem demonstrated by Bastian's regression
tests that his patch did not fix: next_history() can advance not
only to the newest entry, but beyond it, which core libedit cannot
do. So that feature must be implemented locally in readline.c.

With that, the last of Bastians tests is fixed, test_movement_direction().

This patch also improves libedit documentation to more clearly state
what "previous" and "next" mean. GNU readline documentation is
just as unclear, but we can't easily fix that since libedit doesn't
include its own readline.3 manual.

(Ingo Schwarze)
 1.4 02-May-2016  wiz Fix Dd argument.
 1.3 02-May-2016  christos Add more explicit xrefs
 1.2 02-May-2016  wiz Fix Dd argument.
 1.1 28-Apr-2016  christos new man page from Ingo Schwarze.
 1.2 09-May-2016  christos Instead of compiling all the source files together in one big file, use
protected visibility to achieve the same effect.
 1.1 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.34 06-Dec-2022  uwe editrc(5): Markup fixes
 1.33 27-Jun-2017  kre Include EDITRC in doc.
 1.32 22-May-2016  christos branches: 1.32.8;
documentation improvements (Ingo Schwarze)
 1.31 28-Apr-2016  christos new man page from Ingo Schwarze.
 1.30 17-Apr-2016  christos Remove empty callbacks (Ingo Schwartze)
 1.29 25-Dec-2014  wiz Bump date for previous.
 1.28 25-Dec-2014  wiz From Ingo Schwarze, based on changes from Kaspars Bankovskis:
* Document error handling of el_init(), el_set(), el_source(),
and history_init().
* Fix a typo an improve punctuation below H_SETUNIQUE.
* The ellipsis already implies "optional", no need for [].
* Sort options in editrc(5).
* Prevent e.g. rom being misconstrued as the end of a sentence.
* Drop a useless duplicate .Ar macro.
* Put telltc in its proper place in the alphabetical order.
* A few typos in vi editor command names.
* Some missing vi editor command names.
* Some missing author macros.
 1.27 10-Jan-2013  wiz branches: 1.27.8;
Add FILES section.
From jmc@OpenBSD.
 1.26 02-Jun-2012  njoly branches: 1.26.2;
Switch from Op to Oo/Oc for nested block.
 1.25 25-Apr-2011  wiz branches: 1.25.4;
Markup consistency, from YOMURA Masanori. Add serial comma.
 1.24 11-Apr-2009  wiz Drop trailing whitespace.
 1.23 11-Apr-2009  joerg Don't use .Xo/.Xc to work around ancient macro argument limit in groff.
 1.22 09-Mar-2009  joerg Fix preamble to match order set out by mdoc(7). Discussed with wiz.
 1.21 30-Apr-2008  martin branches: 1.21.8;
Convert TNF licenses to new 2 clause variant
 1.20 21-Aug-2006  christos branches: 1.20.16;
Change to a 3 clause copyright after permission of the holders.
 1.19 01-Nov-2003  christos Document history builtin commands.
 1.18 19-Oct-2003  wiz Bump date for previous.
 1.17 18-Oct-2003  christos Allow setty to set chars using char=value
 1.16 27-Jun-2003  wiz Add Ns.
 1.15 14-May-2003  wiz setup -> set up, from jmc@openbsd.
 1.14 31-Mar-2003  perry em-gosmacs-traspose->em-gosmacs-transpose (Igor Sobrado, PR misc/19909)
 1.13 02-Oct-2002  wiz empty, not emptry. By Adrian Mrva.
 1.12 15-Jan-2002  wiz Punctuation nits.
 1.11 19-Jun-2001  wiz `existent', not `existant'
 1.10 08-Nov-2000  lukem improve description of line syntax
 1.9 21-Jun-2000  lukem * add -m option to makelist, which generates an mdoc table with the key
bindings and their descriptions
* manually add the output of 'sh ./makelist -m vi.c ed.c common.c' to
a new section in editrc(5) called `EDITOR COMMANDS'
 1.8 02-Jul-1999  simonb branches: 1.8.8;
More trailing white space.
 1.7 22-Mar-1999  garbled Last of the .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Wheee!
 1.6 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.5 30-Jul-1997  jtc Fix files using old TNF copyright notice
 1.4 24-Apr-1997  christos editrc -> editline
 1.3 11-Jan-1997  lukem * document ^char and \ escape sequences
* when parsing ^char control chars, check the correct char when determining
validity (previously, ^char was a NOP interpreted as the literal string
because of this bug)
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 09-Jan-1997  lukem * add a man page for the editline routines
* add a man page describing editrc
* fix bugs in el_parse():
* didn't execute command when program name matched (test reversed)
* was checking against empty string instead of program name
* after checks, command to run also pointed to empty string

[christos - the author of libedit - ok-ed the man pages in general (which I
wrote from scratch by RTFS) as well as the bugfix]
 1.8.8.1 23-Jun-2000  lukem Pull up editrc.5 revision 1.9
Pull up makelist revision 1.5
* add -m option to makelist, which generates an mdoc table with the key
bindings and their descriptions
* manually add the output of 'sh ./makelist -m vi.c ed.c common.c' to
a new section in editrc(5) called `EDITOR COMMANDS'
requested/approved by thorpej
 1.20.16.1 18-May-2008  yamt sync with head.
 1.21.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.25.4.2 23-Jan-2013  yamt sync with head
 1.25.4.1 30-Oct-2012  yamt sync with head
 1.26.2.1 25-Feb-2013  tls resync with head
 1.27.8.1 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.32.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.102 03-Jan-2025  rillig libedit: remove redundant break statements after EL_ABORT
 1.101 30-Oct-2022  christos branches: 1.101.4;
improvements in malloc/free handling.
 1.100 15-Aug-2021  christos Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.
 1.99 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.98 26-Apr-2019  christos Follow the man page for EL_GETTC and not require a NULL terminated argument
list: https://reviews.llvm.org/D61191
 1.97 18-Nov-2018  christos Remove utf-8 requirement (Yuichiro NAITO)
 1.96 01-Jan-2018  christos branches: 1.96.2; 1.96.4;
Only FLUSH if we are ending libedit; DRAIN if we suspend for readline.
This allows pasting multiline buffers (Gerry Swislow)
 1.95 05-Sep-2017  christos For readline emulation, don't reset the tty to "sane" (cooked) mode if we
did not start this way. Also set and reset the tty on entry and exit from
readline() since this is what readline does.
 1.94 27-Jun-2017  christos add literal escape sequence support, patterned after the tcsh ones.
 1.93 27-Jun-2017  kre Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
 1.92 22-May-2016  christos branches: 1.92.8;
Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze
 1.91 09-May-2016  christos s/protected/libedit_private/g
 1.90 02-May-2016  christos eliminate static buffer with custom resizing code.
 1.89 19-Apr-2016  christos From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "read.h" everywhere, but only in the two files
needing access to el_read, read.c and el.c.
- To functions that don't need more, pass the struct el_read_t *
rather than the full EditLine *.
- Of course, that means that read_init() can now fail from
memory exhaustion, but it's easy to clean up after that.
 1.88 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.87 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.86 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.85 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.84 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.83 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.82 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.81 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.80 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.79 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.78 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.77 15-Feb-2016  christos Use getline for better portability.
 1.76 15-Feb-2016  christos use fparseln() to avoid needing to deal with missing \n in the last line
and also to handle comments automatically.
 1.75 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.74 08-Dec-2015  christos Only reset the terminal if we have a tty (Boris Ranto)
 1.73 18-Jun-2014  christos Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
 1.72 22-Jan-2013  christos branches: 1.72.6;
provide an el_init_fd function.
 1.71 11-Sep-2012  christos branches: 1.71.2;
PR/46942: Steffen Nurpmeso: editline(3): el_get(): fix UNBUFFERED return
 1.70 11-Mar-2012  christos use arraycount
 1.69 18-Nov-2011  christos remove unrecheable code (Kamil Dudka)
 1.68 29-Jul-2011  christos branches: 1.68.2;
KNF return (\1); -> return \1;
 1.67 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.66 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.65 28-Jul-2011  christos avoid shadowed variable
 1.64 28-Jul-2011  christos term -> terminal
eliminate MAXPATHLEN
 1.63 26-Jul-2011  christos don't stop reading after empty lines from: Nirbhay Choubey
 1.62 20-Mar-2011  bouyer Fix use-after-free. Discovered by running tests with MALLOC_OPTIONS=J
(should this be the default for tests ?), pointed out by njoly@
 1.61 27-Jan-2011  christos don't turn on editing if stdout is not a tty.
 1.60 28-Aug-2010  christos branches: 1.60.2;
setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.
 1.59 15-Apr-2010  christos From Jess Thrysoee
- use nl_langinfo to test for UTF-8, because some locales are UTF-8 without
reflecting it in their names.
 1.58 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.57 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.56 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.55 25-Jul-2009  christos Ignore comment lines in .editrc from Jess Thrysoee
 1.54 22-Jul-2009  christos Only need path if we have issetugid... From Anon Ymous
 1.53 22-Jul-2009  christos Move filename to the scope it is being used.
From Michael Cook mcook at bbn dot com
 1.52 11-May-2009  christos restore binary compatibility by providing new prompt functions that take
an extra literal character.
 1.51 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.50 21-Feb-2009  christos back out all prompt changes. they are not needed.
 1.49 19-Feb-2009  cube Order of evaluation of arguments is undefined, so call va_arg() in an
explicit order. Fixes a segfault with bc reported by Patrick Welche on
current-users.
 1.48 17-Feb-2009  christos allow for a prompt argument.
 1.47 18-Jan-2009  lukem branches: 1.47.2;
fix -Wsign-compare issues
 1.46 10-Sep-2008  christos Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.45 05-Apr-2008  christos branches: 1.45.4;
add EL_REFRESH for the benefit of readline
 1.44 15-Dec-2006  christos add EL_GETFP, and EL_SETFP.
 1.43 25-Nov-2006  freza s/el->errfile/el->el_errfile/g in debug code, fixes MKDEBUGLIB build.
 1.42 24-Nov-2006  christos - Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.41 19-Aug-2005  christos PR/31012: Barry Naujok: libedit el_get with EL_EDITOR op does not work
Fixed as suggested.
 1.40 01-Aug-2005  christos Don't reset the macro strings each time we enter el_gets(), otherwise
el_push() is unusable programmatically.
 1.39 08-Jul-2004  christos PR/23486: Andreas Gustafsson: gdb no longer works with emacs
- make sure that we keep previous contents of the buffer in unbuffered mode.
- when turning editing on and off keep tty consistent.
 1.38 27-Feb-2004  christos branches: 1.38.2;
Better fix for rl_prep_terminal() from Gerry Swislow.
 1.37 21-Feb-2004  christos Separate tty separation from the prompt printing function. From Gerry Swislow.
 1.36 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.35 16-Oct-2003  christos More libedit readline emulation functions from: Gerry Swislow
<gerry at certif dot com>
 1.34 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.33 14-Sep-2003  christos - provide enough hooks to compile gdb-5.3
- fix el_get(e, EL_TERMINAL, (char **))
 1.32 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.31 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.30 12-Nov-2002  thorpej Avoid strict alias warning.
 1.29 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.28 03-Feb-2002  christos Don't use HAVE_ yet.
 1.27 03-Feb-2002  christos Fix a warning.
 1.26 08-Nov-2001  mycroft Remove an unused variable.
 1.25 02-Nov-2001  christos If term_init() fails, cleanup and return NULL. This avoids other lossage.
Pointed by charles.
 1.24 09-Oct-2001  christos PR/14188: Anthony Mallet: Provide an opaque data pointer to client programs.
 1.23 27-Sep-2001  christos PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
 1.22 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.21 05-Jan-2001  christos depoison the pure editline code from readline compatibility hacks.
 1.20 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.19 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.18 02-Aug-2000  chuck make xxgdb and a gdb linked with libedit's readline emulation work
properly together. xxgdb communicates with a gdb running on a pty
that it sets to -echo,-onlcr prior to forking the gdb process.
GNU readline preserves the -echo setting while libedit was undoing it
(setting the tty to a sane state and totally confusing xxgdb's parser).

this diff simply disables libedit if both readline emulation and
"stty -echo" are used/set. that is enough to make xxgdb work once
again, but (XXX) this is not how GNU readline handles stty -echo (it
does not echo anything, but editing commands like ^A,^K, etc.
still work), so the readline emulation isn't perfect.

change reviewed by christos.
 1.17 28-Jun-2000  sommerfeld Only look in home directory for .editrc. (Discussed with Christos.)
 1.16 15-May-2000  christos branches: 1.16.4;
don't dump core on empty files.
 1.15 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.14 21-Sep-1999  lukem branches: 1.14.4;
* in el_source():
- don't reopen fp if it was successfully opened in a previous check
- use strlcpy()/strlcat() instead of snprintf() to build a pathname,
since the former are more portable to other systems than the latter
* whitespace fascism
 1.13 02-Jul-1999  simonb More trailing white space.
 1.12 12-Dec-1998  christos branches: 1.12.2;
delint
 1.11 28-Sep-1998  christos fix core-dump caused by maps not being initialized before tty is called.
 1.10 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.9 20-May-1998  christos el_init takes a third stream argument and add el_beep.
 1.8 20-Dec-1997  christos Small optimization. Don't call isatty() on every invocation of el_gets, but
remember if the tty setup failed... Also trim the input line of trailing \r's.
 1.7 06-Jul-1997  christos Fix compiler warnings.
 1.6 24-Apr-1997  christos Handle properly the case where the last line in the sourced file does
not have a trailing '\n'. From Jeffrey C Honig.
 1.5 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.4 20-Mar-1997  christos Fix potential stack overflow; from Keith Bostic.
 1.3 17-Jan-1997  lukem fix el_source() - a block needed braces around it (the indenting fooled me)
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.12.2.1 29-Jun-2000  he Pull up revision 1.17 (via patch, requested by sommerfeld):
Only read .editrc from home directory.
 1.14.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.16.4.2 02-Aug-2000  chuck pull up 1.18 (approved by thorpej). allows a gdb linked with libedit's
readline emulation to work properly with xxgdb.
 1.16.4.1 28-Jun-2000  sommerfeld Pull up 1.17 (approved by thorpej): only look for .editrc in /d1/sommerfeld
 1.38.2.1 10-Jul-2004  tron Pull up revision 1.39 (requested by christos in ticket #620):
PR/23486: Andreas Gustafsson: gdb no longer works with emacs
- make sure that we keep previous contents of the buffer in unbuffered mode.
- when turning editing on and off keep tty consistent.
 1.45.4.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.47.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.60.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.68.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.68.2.2 30-Oct-2012  yamt sync with head
 1.68.2.1 17-Apr-2012  yamt sync with head
 1.71.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.71.2.1 25-Feb-2013  tls resync with head
 1.72.6.1 10-Aug-2014  tls Rebase.
 1.92.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.96.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.96.4.1 10-Jun-2019  christos Sync with HEAD
 1.96.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.101.4.1 02-Aug-2025  perseant Sync with HEAD
 1.48 03-Jan-2025  rillig libedit: remove redundant break statements after EL_ABORT
 1.47 17-May-2024  christos branches: 1.47.2;
When calling el_line make sure that we call the resizing function
callback because el_line updates the legacy LineInfo structure and
we need to notify that the cached copy of the the buffer has changed.
Of course the resizing function can call el_line itself to update
the buffer, so prevent recursion. Bug found by Peter Rufer at Arista.
 1.46 15-Aug-2021  christos Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.
 1.45 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.44 18-Nov-2018  christos Remove utf-8 requirement (Yuichiro NAITO)
 1.43 05-Sep-2017  christos branches: 1.43.2; 1.43.4;
For readline emulation, don't reset the tty to "sane" (cooked) mode if we
did not start this way. Also set and reset the tty on entry and exit from
readline() since this is what readline does.
 1.42 27-Jun-2017  christos add literal escape sequence support, patterned after the tcsh ones.
 1.41 24-May-2016  christos branches: 1.41.8;
From Ingo Schwarze:

Reduce obfuscation of errno handling. There is only one purpose
non-local errno handling is needed for: Inside el_wgets(), several
functions call down indirectly to el_wgetc(), many of them via the
dispatch table. When el_wgetc() fails, it does properly report
failure, but then various cleanup is done which may clobber errno.
But when returning due to failure, el_wgets() wants to have errno
set to the reason of the original read failure, not to the reason
of some subsequent failure of some cleanup operation. So el_wgetc()
needs to save errno, and if it's non-zero, el_wgets() needs to
restore it on failure.

This core logic is currently obscured by the fact that el_errno
is set and inspected at some additional places where it isn't needed.
Besides, since el_wgetc() and and el_wgets() are both in read.c,
el_errno does not need to be in struct editline, it can and should
be local to read.c in struct el_read_t.

Let's look at what can be simplified.

1. keymacro_get() abuses el_errno instead of having a proper
error return code. Adding that error return code is easy
because node_trav() already detects the condition and an
adequate code is already defined. Returning it, testing
for it in read_getcmd(), and returning with error from there
removes the need to inspect el_errno from el_wgets() after
calling read_getcmd().
Note that resetting lastchar and cursor and clearing buffer[0]
is irrelevant. The code returns from el_wgets() right afterwards.
Outside el_wgets(), these variables are no longer relevant.
When el_wgets() is called the next time, it will call ch_reset()
anyway, resetting the two pointers. And as long as lastchar
points to the beginning of the buffer, the contents of the
buffer won't be used for anything.

2. read_getcmd() doesn't need to set el_errno again after el_wgetc()
failure since el_wgetc() already did so. While here, remove
the silly "if EOF or error" comments from the el_wgetc()
return value tests. It's a public interface documented in a
manual, so people working on the implementation can obviously
be expected to know how it works. It's a case of

count++; /* Increment count. */

3. In the two code paths of el_wgets() that lead up to "goto noedit",
there is no need to save the errno because nothing that might
change it happens before returning.

For clarity, since el_wgets() is the function restoring the errno,
also move initializing it to the same function.

Finally, note that restoring errno when the saved value is zero is
wrong. No library code is ever allowed to clear a previously set
value of errno. Only application programs are allowed to do that,
and even they usually don't need to do so, except when using certain
ill-designed interfaces like strtol(3).

I tested that the behaviour remains sane in the following cases,
all during execution of el_wgets(3) and with a signal handler
for USR1 installed without SA_RESTART.

* Enter some text and maybe move around a bit.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press Ctrl-V to activate ed-quoted-insert.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
ed_quoted_insert() returns ed_end_of_file(), i.e. CC_EOF,
and el_wgets() returns 0.

* Press a key starting a keyboard macro.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press : to enter builtin command mode.
Start typing a command.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now c_gets() returns -1, ed_command() beeps and returns CC_REFRESH,
and el_wgets() resumes operation as it should.

I also tested with "el_set(el, EL_EDITMODE, 0)", and it returns
the right value and sets errno correctly.
 1.40 09-May-2016  christos s/protected/libedit_private/g
 1.39 02-May-2016  christos eliminate static buffer with custom resizing code.
 1.38 19-Apr-2016  christos From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "read.h" everywhere, but only in the two files
needing access to el_read, read.c and el.c.
- To functions that don't need more, pass the struct el_read_t *
rather than the full EditLine *.
- Of course, that means that read_init() can now fail from
memory exhaustion, but it's easy to clean up after that.
 1.37 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.36 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.35 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.34 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.33 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.32 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.31 16-Feb-2016  christos get rid of bool_t (Ingo Schwarze)
 1.30 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.29 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.28 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.27 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.26 12-Feb-2016  christos GC IGNORE_EXTCHARS and simplify code (Ingo Schwarze)
 1.25 29-Jul-2011  christos pass -Wconversion
 1.24 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.23 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.22 27-Jan-2011  christos don't turn on editing if stdout is not a tty.
 1.21 31-Dec-2009  christos branches: 1.21.2;
- Document and enable wide character support.
- Fix read function compatibility.
 1.20 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.19 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.18 15-Feb-2009  christos don't restart on EINTR, instead return NULL immediately. From Anon Ymous
 1.17 15-Dec-2006  christos branches: 1.17.20;
add EL_GETFP, and EL_SETFP.
 1.16 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.15 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.12 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.11 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.10 09-Oct-2001  christos PR/14188: Anthony Mallet: Provide an opaque data pointer to client programs.
 1.9 27-Sep-2001  christos PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
 1.8 06-Jan-2001  jdolecek el_line_t: make 'limit' const
 1.7 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.6 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.5 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.4 29-Jul-1998  lukem branches: 1.4.6;
* add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.3 20-Dec-1997  christos Small optimization. Don't call isatty() on every invocation of el_gets, but
remember if the tty setup failed... Also trim the input line of trailing \r's.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.4.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.20.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.41.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.43.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.43.4.1 10-Jun-2019  christos Sync with HEAD
 1.43.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.47.2.1 02-Aug-2025  perseant Sync with HEAD
 1.38 17-May-2024  christos When calling el_line make sure that we call the resizing function
callback because el_line updates the legacy LineInfo structure and
we need to notify that the cached copy of the the buffer has changed.
Of course the resizing function can call el_line itself to update
the buffer, so prevent recursion. Bug found by Peter Rufer at Arista.
 1.37 11-Jan-2022  christos PR/56618: Walter Lozano: Improve libedit compatibility with readline by
implementing:

rl_copy_text, rl_erase_empty_line, rl_message, rl_on_new_line,
rl_replace_line, rl_restore_prompt, rl_save_prompt
 1.36 15-Aug-2021  christos Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.
 1.35 26-Apr-2019  christos Follow the man page for EL_GETTC and not require a NULL terminated argument
list: https://reviews.llvm.org/D61191
 1.34 09-May-2016  christos branches: 1.34.16;
Elide gcc warning about intermediate const casts caused by visibility change.
 1.33 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.32 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.31 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.30 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.29 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.28 28-Feb-2016  christos remove 4 clause licenses.
 1.27 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.26 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.25 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.24 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.23 15-Feb-2016  christos OpenBSD eln.c rev. 1.3 2011/11/27 21:46:44 pascal
kill a C++-style comment
 1.22 14-Feb-2016  christos From Ingo Schwarze:

el_getc() for the WIDECHAR case, that is, the version in eln.c.
For a UTF-8 locale, it is broken in four ways:

1. If the character read is outside the ASCII range, the function
does an undefined cast from wchar_t to char. Even if wchar_t
is internally represented as UCS-4, that is wrong and dangerous
because characters beyond codepoint U+0255 get their high bits
truncated, meaning that perfectly valid printable Unicode
characters get mapped to arbitrary bytes, even the ASCII escape
character for some Unicode characters. But wchar_t need not
be implemented in terms of UCS-4, so the outcome of this function
is undefined for any and all input.

2. If insufficient space is available for the result, the function
fails to detect failure and returns garbage rather than -1 as
specified in the documentation.

3. The documentation says that errno will be set on failure, but
that doesn't happen either in the above case.

4. Even for ASCII characters, the results may be wrong if wchar_t
is not using UCS-4.
 1.21 12-Feb-2016  christos Avoid c99 for now.
 1.20 12-Feb-2016  christos GC IGNORE_EXTCHARS and simplify code (Ingo Schwarze)
 1.19 18-May-2015  christos make el_gets() return the number of characters read in wide mode (not the
number of wide characters) From khorben@ by FreeBSD:
https://svnweb.freebsd.org/ports/head/devel/libedit/files/patch-src_eln.c?\
revision=382458&view=markup
XXX: Pullup-7
 1.18 24-Mar-2015  christos save and restore IGNORE_EXTCHARS like we do in the getc case. From:
https://bugzilla.redhat.com/attachment.cgi?id=1001894
 1.17 18-Jun-2014  christos branches: 1.17.2;
Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
 1.16 20-May-2014  christos Always NULL terminate the argv[] array. From OpenBSD.
 1.15 26-Feb-2014  christos branches: 1.15.2;
Add missing EL_REFRESH
 1.14 11-Mar-2012  christos branches: 1.14.2;
include the NULL in the argv conversion
 1.13 16-Aug-2011  christos branches: 1.13.2;
re-enable -Wconversion
 1.12 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.11 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.10 20-Jun-2011  mrg various build fixes for gcc 4.5. from chuq. XXX i'm not sure all of
these work properly wtf pointer aliasing, but there are no casts at
least...

the lib/libpuffs/puffs_priv.h is definately a real bug fix.

from chuq.
 1.9 04-Nov-2010  christos branches: 1.9.4;
PR/43998, PR/44021: In narrow history emulation, don't treat UTF-8 character
sets specially as far as history goes since we always need to do the conversion
from narrow [history] to wide [editline].
 1.8 28-Aug-2010  christos setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.
 1.7 15-Apr-2010  christos From Jess Thrysoee
- NARROW_HISTORY and IGNORE_EXTCHARS should not take effect if locale is UTF-8
- account for multi byte char length in
 1.6 20-Jan-2010  christos PR/42646: Joachim Kuebart: Shell crashes in libedit when window size changes
(SIGWINCH). Return NULL if el_gets() gets interrupted.
 1.5 19-Jan-2010  christos Fix wrapper for EL_EDITOR, from Michael L. Hitch
 1.4 12-Jan-2010  christos - call the mapping function directly instead of el_wset().
- save the strings passed to the mapping function so that they don't get
re-used. This leaks. To fix it properly we could either pass a flag to
free particular entries before re-using, or allocate all of them.
Allocating all of them wastes memory, allocating some of them makes
the code more complex.
This fixes compatibility binding (shell tab completion for example)
 1.3 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.2 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.1 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.9.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.13.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.2.1 17-Apr-2012  yamt sync with head
 1.14.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.2.1 10-Aug-2014  tls Rebase.
 1.17.2.1 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.34.16.1 10-Jun-2019  christos Sync with HEAD
 1.38 29-Jun-2024  christos don't use oldc before it is set.
 1.37 29-Jun-2024  christos Retrieve the cursor position after calling c_insert, because c_insert could
enlarge the line buffer making the old cursor position point to freed memory.
From Robert Morris https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279772
 1.36 09-May-2016  christos s/protected/libedit_private/g
 1.35 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.34 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.33 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.32 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.31 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.30 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.29 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.28 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.27 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.26 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.25 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.24 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.23 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.22 15-Feb-2009  christos pass lint on _LP64.
 1.21 06-Mar-2006  christos branches: 1.21.28;
Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.20 08-Aug-2005  christos Spelling mistakes and comment errors (from FreeBSD via Stefan Farfeleder; many
thanks)
 1.19 28-Oct-2004  dsl Use (unsigned char) cast to sanitise arguments to ctype functions.
 1.18 27-Oct-2004  dsl Fix a load of international alphabet problems with isxxx() and toupper()
Change isspace(*char_ptr) to isspace(*char_ptr & 0xff) so that the correct
piece of memory is looked at for the bit mask.
gcc optimises out the '& 0xff' (on i386 at least).
Fixes problems found by gcc when the splurious (int) cast is removed
from the #defines in ctype.h
 1.17 13-Aug-2004  mycroft Delete-previous-char and delete-next-char without an argument are not supposed
to modify the yank buffer in Emacs. Make it so.
 1.16 02-Nov-2003  christos If the kill buffer is empty return normal. From Gerry Swislow gerry at certif
dot com
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.13 31-Mar-2003  perry em-gosmacs-traspose->em-gosmacs-transpose (Igor Sobrado, PR misc/19909)
 1.12 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.11 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.10 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.9 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.8 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.7 02-Jul-1999  simonb More trailing white space.
 1.6 20-May-1998  christos cast is*() arg to unsigned char
 1.5 03-Feb-1998  perry remove obsolete register declarations
 1.4 06-Jul-1997  christos Fix compiler warnings.
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 30-Aug-1994  cgd fix for pr 420, from Christos.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd branches: 1.1.1.1.2;
libedit!
 1.1.1.1.2.1 30-Aug-1994  cgd from trunk; pr 420
 1.21.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.73 25-Apr-2023  christos pass lint.
 1.72 03-Feb-2023  christos Add a entry point for the complete function for FreeBSD compatibility with sh.
 1.71 30-Oct-2022  christos improvements in malloc/free handling.
 1.70 12-Mar-2022  christos Fix filename autocompletion for strings like a\)b

An escaped character should unconditionally be skipped together with the
character that does the escaping. For example, in "a\)b" only the ")b"
part was skipped but then the loop stopped at the "\" since it's one of
the characters listed in word_break. (Piotr P. Stefaniak)
 1.69 26-Sep-2021  christos - Completion should not add a quote at the end of the line to match an
already quoted quote. (Piotr Stefaniak)
- fix lint unconst warnings for strchr
 1.68 05-May-2021  christos PR/56147: Miroslav Lichvar: Avoid memory leak if strdup fails.
 1.67 28-Mar-2021  christos Only unescape when we are quoting and don't add a space if we are quoting
(we already did) (Piotr Stefaniak)
 1.66 28-Mar-2021  christos Pass the unescaped filename the the append function so it has to do less work
(for example it can call stat(2) directly (Piotr Stefaniak)
 1.65 27-Mar-2021  christos Add fn_complete2() that controls the quoting of the returned match.
Before it was based on the heuristic that we were not supplied an
attempted_completion_function, which worked well because programs
that supplied that function were not shells and did not want/understand
shell quoting. Recently though Piotr Stefaniak wanted to enhance command
completion for the Bourne Shell and this could benefit quoting the returned
command. This function adds an extra flags argument that controls that quoting.
 1.64 05-Jan-2020  abhinav PR lib/54510 - when user supplied completion function is there,
don't unescape the string to be completed.
 1.63 05-Jan-2020  tih Summary: Remove over-simplified extraneous test

The file name matching code in libedit tries to adjust to the presence
of explicit " or ' characters in the input line, but tries too hard.
Remove a conditional that goes overboard, and causes the completion
code to fail if a quoted string is seen before the filename to be
expanded, as in

grep 'foo' bar<TAB>

Before this change, the above would not expand any possible
completions, even if they existed, because it would choose to look for
files whose names started with " bar".
 1.62 10-Dec-2019  christos When 'attempted_completion_function' non-NULL, with a 'single_match'
match, the expected space is not being added. Problem observed with
"chronyc" and "sqlite3" tab completion. That functionality got
moved to escape_filename() for the !attempted_completion_function
case, but the non-NULL 'attempted_completion_function' case must
also be handled. (Lonnie Abelbeck)
 1.61 09-Oct-2019  christos add +1 to strlcpy's (Patrick Welche)
 1.60 08-Oct-2019  christos remore error(1) comment
 1.59 08-Oct-2019  christos Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
 1.58 08-Sep-2019  abhinav PR lib/54510: Fix file completion inside quotes which broke in rev 1.53

While there also fix handling character appending in the file completions when
inside quotes. For example when inside a quote, if the completion is a directory then
append a '/' but don't close the quote. On the other hand when inside a quote if the
completion is a file name and it is the only match then we can close the quote.
 1.57 28-Jul-2019  christos PR/54415: Ricky Zhou: libedit stats completions for non-file completions
Use the proper completion function and account for the character appended
by the function when computing the number of columns.
 1.56 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.55 20-Apr-2019  abhinav PR lib/54131 - declare the loop variable outside the for loop
 1.54 12-Apr-2019  christos PR/54117: Paavo Helde: Fix memory overrun: Account for the closing quote
in memory allocation if quoted.
 1.53 31-Mar-2019  abhinav Perform quoting of filename completions when there are multiple matches as well

Quoting of special characters in filename completion was implemented for single match
case, this enables it for multiple matches as well. For example:

$ touch 'foo bar'
$ touch 'foo baz'
$ ls fo<TAB>
autocompletes to =>
$ ls foo\ ba
hitting <TAB> again shows:
foo bar foo baz

This required unescaping escape sequences generated during last completion
in order to find the word to complete.

While there, also update the test to include cases for multiple matches.

Reviewed by christos
 1.52 24-Mar-2019  abhinav Only quote the completion matches if we are doing filename completion

If the user supplies a value for the attempted_completion_function parameter
then we cannot be sure if the completion is for filename or something else, in such
a case don't attempt to quote the completion matches.

Reviewed by christos

This should address PR lib/54067
 1.51 04-May-2018  christos branches: 1.51.2;
fix uninitialized
 1.50 04-May-2018  abhinav Handle filename autocompletion when the cursor is at a backslash or quote character

For example, handle following case:
$ touch 'foo bar'
$ ls foo\<TAB> --> $ ls foo\ bar

Also add test cases for this.

Thanks to Christos for review
 1.49 02-May-2018  abhinav Add '*' and '[' to the list of characters which need escaping during autocompletion
 1.48 27-Oct-2017  abhinav branches: 1.48.2;
Add NULL check after doing memory allocation at a couple of places

ok christos@
 1.47 15-Oct-2017  abhinav Add support for escaping special characters when doing filename completion.

For instance if the file name is "foo bar":
$ ls foo<TAB>
should get autocompleted to:
$ ls foo\ bar

Works for similar other characters too, which need escaping.

Also, add an accompanying test program to ensure the escaping is correct
in various scenarios (within quotes, without quotes, with other special characeters)

Thanks to Christos for reviews, help and feedback.
 1.46 16-Sep-2017  abhinav Fix indentation (convert spaces to tab)
 1.45 21-Apr-2017  abhinav When doing filename autocompletion, append a trailing slash at the end of directory
names. We already do this when there is only one completion option but
in case of of multiple completion options, it wasn't being done.

ok christos@
 1.44 31-Oct-2016  abhinav branches: 1.44.2;
Fix file name auto completion in one specific case.

For example if you do
$mkdir -p /tmp/dir1/dir2

Then:
$ls /tmp/di <TAB> auto completes to
$ls /tmp/dir1/

Hitting <TAB> again auto completes to
$ls /tmp/dir1/dir2

Whereas it should auto complete to
$ls /tmp/dir1/dir2/


Essentially, in cases like above where you have to hit <TAB> twice to get
to the match and there is only one match (because only one file/sub-directory) then
auto complete doesn't work correctly. It doesn't append a trailing slash (in case
of directory) or a space (in case of a file) to the match name.

I have tested file name completion in sh(1) and symbol completion in gdb after
this change.
 1.43 11-Apr-2016  christos branches: 1.43.2;
Char -> wchar_t from Ingo Schwarze.
 1.42 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.41 09-Apr-2016  christos Change some 0's to NULL's from Pedro Giffuni
 1.40 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.39 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.38 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.37 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.36 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.35 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.34 18-Oct-2014  riz callers's -> caller's
 1.33 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.32 05-Jun-2014  christos branches: 1.32.2;
PR/48876: Dmitriy Grigoryev: Core dump in readline lib on attempted expansion
Make sure we have 2 matches before calling strcmp().
 1.31 16-Sep-2011  plunky branches: 1.31.8; 1.31.18;
NULL does not need a cast, here
 1.30 16-Aug-2011  christos re-enable -Wconversion
 1.29 29-Jul-2011  christos pass -Wconversion
 1.28 29-Jul-2011  christos - fix unused params
- unconditionalize vis.h
 1.27 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.26 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.25 28-Jul-2011  christos fix unused variable warnings on systems without _r functions
 1.24 28-Jul-2011  christos eliminate alloca for portability
portable getpw{nam,uid}
 1.23 06-Dec-2010  dholland Improve previous to avoid changing the interface of an externally
exposed function. (But note that this function is neither documented
nor declared in any installed header file, and it probably should not
be externally exposed.) Related to PR 44183, closes PR 44186.
 1.22 02-Dec-2010  dholland add const, from PR 44183.
 1.21 02-Dec-2010  dholland Fix up bodgy code for printing completion matches; it used to sometimes
skip entries, print (null), run off the end of the array, or occasionally
receive SIGSEGV, and now will, hopefully at least, do none of that.

Based in part on the patch in PR 44183 from Sergio Acereda; I also
did some tidyup and fixed it to print top-to-bottom first like ls(1).
 1.20 15-Nov-2010  christos don't increment i twice in the loop. From Michael Byrnes
 1.19 01-Jun-2010  christos tidy up memory allocation and don't unnecessarily print "./" before names.
 1.18 18-Jan-2010  christos PR/42637: Joachim Kuebart: Shell tab completion crashes due to libedit stack
smashing
 1.17 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.16 28-Dec-2009  christos improve on the listing display by printing only one character after the
filename not two, and no trailing blanks. I will revisit this when I write
the ls-F code.
 1.15 16-Feb-2009  christos fix sign compare issues.
 1.14 15-Feb-2009  christos pass lint on _LP64.
 1.13 26-Jan-2009  apb branches: 1.13.2;
Define HAVE_STRUCT_DIRENT_D_NAMLEN in config,h, and test it when
deciding whether to use entry->d_namlen or strlen(entry->d_name).
Addresses PR 40477 by Robert Millan.
 1.12 11-Jan-2009  christos - insert a space after the recognized string if it was an exact match
- initialize properly the string used for completion.
From Alex Bligh alex at alex dot org dot uk
- Make char constants consistent
 1.11 29-Apr-2008  martin Convert to new 2 clause license
 1.10 09-Nov-2006  christos branches: 1.10.16;
don't use alloca with ssp.
 1.9 21-Aug-2006  christos Change to a 3 clause copyright after permission of the holders.
 1.8 03-Aug-2005  christos Fix reversed test; from Gerry Swislow
 1.7 11-Jun-2005  christos PR/30500: Paul Shupak: Inconsistent definition of tilde_expand().
Provide a layer of indirection between the readline compatibility functions
and our internal implementation, so that we have the freedom to change the
function signature.
 1.6 10-Jun-2005  christos Bug reported from Martin Dietze:

The place to change the completion_append_character is
usually somewhere in the `rl_completion_entry_function'
callback which is where one usually can distinguish between
file- or dir-like entries to append a slash for dirs etc.

This does no longer work since `fn_complete()' takes the
`append_character' as argument before the callback is executed,
so that changes to the variable `rl_completion_append_character'
have in fact no effect for the current completion.

Fix by adding a function that returns the rl_completion_append_character,
when it gets passed in a filename in readline emulation.
 1.5 18-May-2005  christos Make completion_matches non-static since readline wants it.
 1.4 12-May-2005  christos PR/30215: Kouichirou Hiratsuka: /bin/sh dumps core with tabcomplete
Don't core-dump when trying to complete an empty line; instead assume ./
 1.3 09-May-2005  dsl Use getpwuid_r(getuid(), ...) to expand ~/....
Don't replace ~xyz with /home/xyz when expanding ~
 1.2 07-May-2005  dsl gdb directly calls filename_completion_function()
 1.1 07-May-2005  dsl Separate out the filename completion functions from the readline() code.
Pass in loads of parameters instead of relying on shed-loads of global
variables to modify the behaviour.
The filename completion code can now be enabled by code that uses el_gets().
(eg /bin/sh)
 1.10.16.1 18-May-2008  yamt sync with head.
 1.13.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.31.18.1 10-Aug-2014  tls Rebase.
 1.31.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.32.2.1 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.43.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.43.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.44.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.48.2.1 21-May-2018  pgoyette Sync with HEAD
 1.51.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.51.2.1 10-Jun-2019  christos Sync with HEAD
 1.15 25-Apr-2023  christos pass lint.
 1.14 26-Sep-2021  christos make flag unsigned to match prototype of the function used
 1.13 28-Mar-2021  christos document the flag
 1.12 27-Mar-2021  christos Add fn_complete2() that controls the quoting of the returned match.
Before it was based on the heuristic that we were not supplied an
attempted_completion_function, which worked well because programs
that supplied that function were not shells and did not want/understand
shell quoting. Recently though Piotr Stefaniak wanted to enhance command
completion for the Bourne Shell and this could benefit quoting the returned
command. This function adds an extra flags argument that controls that quoting.
 1.11 21-Apr-2017  abhinav When doing filename autocompletion, append a trailing slash at the end of directory
names. We already do this when there is only one completion option but
in case of of multiple completion options, it wasn't being done.

ok christos@
 1.10 11-Apr-2016  christos branches: 1.10.2; 1.10.4;
Char -> wchar_t from Ingo Schwarze.
 1.9 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.8 16-Feb-2009  christos fix sign compare issues.
 1.7 15-Feb-2009  christos pass lint on _LP64.
 1.6 29-Apr-2008  martin branches: 1.6.8;
Convert to new 2 clause license
 1.5 21-Aug-2006  christos branches: 1.5.16;
Change to a 3 clause copyright after permission of the holders.
 1.4 11-Jun-2005  christos PR/30500: Paul Shupak: Inconsistent definition of tilde_expand().
Provide a layer of indirection between the readline compatibility functions
and our internal implementation, so that we have the freedom to change the
function signature.
 1.3 10-Jun-2005  christos Bug reported from Martin Dietze:

The place to change the completion_append_character is
usually somewhere in the `rl_completion_entry_function'
callback which is where one usually can distinguish between
file- or dir-like entries to append a slash for dirs etc.

This does no longer work since `fn_complete()' takes the
`append_character' as argument before the callback is executed,
so that changes to the variable `rl_completion_append_character'
have in fact no effect for the current completion.

Fix by adding a function that returns the rl_completion_append_character,
when it gets passed in a filename in readline emulation.
 1.2 07-May-2005  dsl gdb directly calls filename_completion_function()
 1.1 07-May-2005  dsl Separate out the filename completion functions from the readline() code.
Pass in loads of parameters instead of relying on shed-loads of global
variables to modify the behaviour.
The filename completion code can now be enabled by code that uses el_gets().
(eg /bin/sh)
 1.5.16.1 18-May-2008  yamt sync with head.
 1.6.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.10.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.10.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.34 23-Jul-2019  christos put the NULL check immediately after the allocation
 1.33 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.32 05-Mar-2017  christos branches: 1.32.12;
one extra char for NUL.
 1.31 05-Mar-2017  christos Grow the buffer for event search if there was not enough space.
From Gerry Swislow
 1.30 07-Nov-2016  christos branches: 1.30.2;
Change the way the built-in history works; some programs enter history
with the trailing newline, others don't so don't make any assumptions
about it when printing. Also print the correct event number (generated),
separate the event number from the event with a tab, and visually encode
the string (don't encode tabs and spaces though).
 1.29 09-May-2016  christos branches: 1.29.2;
s/protected/libedit_private/g
 1.28 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.27 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.26 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.25 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.24 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.23 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.22 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.21 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.20 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.19 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.18 28-Jul-2011  christos fix confusion with wide functions.
 1.17 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.16 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.15 01-Nov-2003  christos Fixes from Otto Moerbeek otto at drijf dot net
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.12 21-Jan-2003  christos Add a uniquefier for the history function.
 1.11 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.10 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.9 17-May-2001  christos PR/12963:Jason Waterman: Fix signed cast problems.
 1.8 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.7 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.6 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.5 02-Jul-1999  simonb More trailing white space.
 1.4 14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.29.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.29.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.30.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.32.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.23 01-Sep-2017  christos PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.22 09-May-2016  christos s/protected/libedit_private/g
 1.21 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.20 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.19 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.18 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.17 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.16 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.15 30-Jan-2016  christos Whitespace fix (Ingo Schwarze)
 1.14 11-May-2014  christos Add a history function that takes a FILE pointer; needed for Capsicum.
From Eitan Adler
 1.13 28-Jul-2011  christos branches: 1.13.2; 1.13.8; 1.13.18;
kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.12 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.11 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 21-Jan-2003  christos Add a uniquefier for the history function.
 1.8 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.7 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.6 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.5 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.4 14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 15-Oct-1995  christos Added history load and save to file functions.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.13.18.1 10-Aug-2014  tls Rebase.
 1.13.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.13.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.62 03-Feb-2023  christos Add a entry point for the complete function for FreeBSD compatibility with sh.
 1.61 08-Feb-2022  rillig libedit: fix typos, apply KNF to newly imported code (PR/56693)

No binary change.
 1.60 08-Feb-2022  christos PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key
 1.59 11-Jan-2022  christos PR/56618: Walter Lozano: Improve libedit compatibility with readline by
implementing:

rl_copy_text, rl_erase_empty_line, rl_message, rl_on_new_line,
rl_replace_line, rl_restore_prompt, rl_save_prompt
 1.58 15-Aug-2021  christos Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.
 1.57 01-Sep-2017  christos PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.56 19-Apr-2016  christos From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "read.h" everywhere, but only in the two files
needing access to el_read, read.c and el.c.
- To functions that don't need more, pass the struct el_read_t *
rather than the full EditLine *.
- Of course, that means that read_init() can now fail from
memory exhaustion, but it's easy to clean up after that.
 1.55 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.54 16-Feb-2016  christos - don't set _GNU_SOURCE. We are not supposed to make decisions for others.
- don't special-case wcsdup()
From Ingo Schwarze.
 1.53 18-Jun-2014  christos Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
 1.52 11-May-2014  christos Add a history function that takes a FILE pointer; needed for Capsicum.
From Eitan Adler
 1.51 12-Jul-2013  christos branches: 1.51.4;
Add a function to move the cursor.
 1.50 22-Jan-2013  christos provide an el_init_fd function.
 1.49 31-May-2012  christos branches: 1.49.2;
remove stdint.h; it is not used.
 1.48 28-Jul-2011  christos branches: 1.48.2;
kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.47 28-Aug-2010  christos setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.
 1.46 15-Apr-2010  christos From Jess Thrysoee: add ifndef around def of _GNU_SOURCE
 1.45 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.44 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.43 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.42 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.41 07-Sep-2009  christos apply apple patches from:
http://opensource.apple.com/source/libedit/libedit-11/patches/
 1.40 11-May-2009  christos restore binary compatibility by providing new prompt functions that take
an extra literal character.
 1.39 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.38 21-Feb-2009  christos back out all prompt changes. they are not needed.
 1.37 19-Feb-2009  christos bump version for prompt arg.
 1.36 17-Feb-2009  christos allow for a prompt argument.
 1.35 05-Feb-2009  christos branches: 1.35.2;
match documentation in el_push
 1.34 05-Apr-2008  christos bump minor.
 1.33 05-Apr-2008  christos add EL_REFRESH for the benefit of readline
 1.32 10-Jun-2007  christos Fix tab/space confusion; from Stefan Farfeleder
 1.31 15-Dec-2006  christos add EL_GETFP, and EL_SETFP.
 1.30 24-Nov-2006  christos bump minor.
 1.29 24-Nov-2006  christos - Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.28 14-Jul-2005  christos PR/30747: David N. Williams: libedit is missing remove_history()
Added, please test.
 1.27 12-Jun-2005  christos make this useable from c++.
 1.26 07-May-2005  dsl Separate out the filename completion functions from the readline() code.
Pass in loads of parameters instead of relying on shed-loads of global
variables to modify the behaviour.
The filename completion code can now be enabled by code that uses el_gets().
(eg /bin/sh)
 1.25 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.24 16-Oct-2003  christos More libedit readline emulation functions from: Gerry Swislow
<gerry at certif dot com>
 1.23 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.22 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.21 21-Jan-2003  christos Add a uniquefier for the history function.
 1.20 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.19 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.18 09-Oct-2001  christos PR/14188: Anthony Mallet: Provide an opaque data pointer to client programs.
 1.17 27-Sep-2001  christos PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
 1.16 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.15 28-Feb-2000  chopps el_insertstr takes a "const char *" not "char *" now as it doesn't modify
the argument.
 1.14 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.13 20-Sep-1999  lukem branches: 1.13.4;
more whitespace fascism
 1.12 02-Jul-1999  simonb More trailing white space.
 1.11 20-Dec-1998  kleink Change multiple inclusion protection symbol name to NetBSD convention which
doesn't violate namespace rules.
 1.10 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.9 01-Jun-1998  lukem * implement CC_REFRESH_BEEP; as per CC_REFRESH but beep as well. this
is useful in completion when a partial completion is found
* remove entry in BUGS about el_parse(); that was fixed a while ago
 1.8 20-May-1998  christos Add H_APPEND to simplify the interface.
 1.7 20-May-1998  christos - add extra argument to el_init
- fix history functions
- add el_beep()
 1.6 14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.5 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.4 14-Jan-1997  lukem Implement CC_REDISPLAY, which (unlink CC_REFRESH) redraws the entire input
line (a la ^R). This is useful if the binding outputs information and
mucks up the input line. To be used in ``list-choices'' bindings (refer
to the ^D binding in csh when filec is set)
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 15-Oct-1995  christos Added history load and save to file functions.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.13.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.35.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.48.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.48.2.1 30-Oct-2012  yamt sync with head
 1.49.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.49.2.1 25-Feb-2013  tls resync with head
 1.51.4.1 10-Aug-2014  tls Rebase.
 1.64 11-Jul-2024  kre Don't fchmod(fileno(fp), ...) in history_save_fp().

There are two reasons for this, first, the permissions of the history
file should be able to be set by the user, not forced to 0600 every
time the history file is overwritten (or appended to).

And more importantly, the fp used for fileno(fp) might have come
from fmemopen() or funopen() (etc) - none of which put a file
descriptor in the "fd" field (ie: fileno(fp) == -1).

To compensate for that, when a history file is opened (in history_save())
set the default permissions then - if the file is actually created.
As fopen() cannot do that (it simply uses 0666&~umask) create the
(normal type) of fp using (approximately) fdopen(open(...), ...)
where the open supplies the 0600 default permissions that are
desired here (which might still be restricted even more by the
umask). Callers using history(...,H_SAVE_FP,...) or
history(...,H_NSAVE_FP,...) now need to look after any permission
setting required themselves (but as the doc says absolutely
nothing about that, one way or the other, what happens in this
area has always been unspecified, and still is)

One "feature" of the fchmod() method is lost here - apart from forcing
the 0600 permissions (which isn't really desirable) that fchmod()
would also have failed if the current (effective) uid is not the owner of
the history file (or root). If that is required, a test for it could
be added later - the effect would be as it has always been, the file
named must have been writable (or its directory writable if the file
did not exist) the open would occur (potentially truncating the file)
after which the fchmod() would be attempted, possibly failing, and if
so, never writing anything. Any new uid test would work the same way.

OK christos@
 1.63 08-Oct-2019  christos branches: 1.63.10;
Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
 1.62 13-Sep-2018  kre Fix editing mistake, remove ) from func call that is now gone.
 1.61 13-Sep-2018  christos more efficient to use decode_result :-) Pointed out by kre@
 1.60 12-Sep-2018  christos PR/53597: Yasuhiro Horimoto: Avoid segmentation fault in bad history file.
 1.59 23-Dec-2017  uwe branches: 1.59.2; 1.59.4;
The order in which the arguments to a function are evaluated is
undefined, so don't use va_arg() twice.

PR lib/52849
 1.58 01-Sep-2017  christos PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.57 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.56 11-Apr-2016  christos chartype cleanups from Ingo Schwarze:

- The file tokenizer.c no longer uses chartype.h,
so don't include the header.

- The dummy definitions of ct_{de,en}code_string() for the
NARROWCHAR case are only used in history.c, so move them there.

- Now the whole content of chartype.h is for the wide character
case only. So remove the NARROWCHAR ifdef and include the
header only in the wide character case.

- In chartype.h, move ct_encode_char() below the comment explaining it.

- No more need for underscores before ct_{de,en}code_string().

- Make the conversion buffer resize functions private.
They are only called from the decoding and encoding functions
inside chartype.c, and no need can possibly arise to call them
from anywhere else.
 1.55 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.54 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.53 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.52 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.51 15-Feb-2016  christos Don't free getline memory (Ingo Schwarze).
 1.50 15-Feb-2016  christos Use getline for better portability.
 1.49 15-Feb-2016  christos Change the test for the size of encoded buffer to include the NULL, from
OpenBSD; no functional change.
 1.48 15-Feb-2016  christos Use fparseln to avoid newline hacks.
 1.47 11-May-2014  christos Add a history function that takes a FILE pointer; needed for Capsicum.
From Eitan Adler
 1.46 18-Nov-2011  christos branches: 1.46.6; 1.46.16;
Add coverity annotations about unreachable code (Kamil Dudka)
 1.45 29-Jul-2011  christos branches: 1.45.2;
pass -Wconversion
 1.44 29-Jul-2011  christos - fix unused params
- unconditionalize vis.h
 1.43 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.42 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.41 28-Jul-2011  christos include vis.h from dot.
 1.40 27-Jul-2011  christos fix narrow compilation
 1.39 27-Jul-2011  christos - don't leave cursor dangling on memory failure or after clearing the list
- compute the string length to be strvis'ed after the string is encoded
 1.38 16-Jan-2011  christos off by one in fetching history data. From: Gerry Swislow
 1.37 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.36 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.35 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.34 07-Sep-2009  christos apply apple patches from:
http://opensource.apple.com/source/libedit/libedit-11/patches/
 1.33 06-Feb-2009  sketch Plug memory leak, from MySQL.
 1.32 28-Sep-2006  christos Fix memory leak found by valgrind (Julien Torres)
 1.31 01-Aug-2005  christos Don't forget to initialize h_del; from Julien Torres.
 1.30 14-Jul-2005  christos PR/30747: David N. Williams: libedit is missing remove_history()
Added, please test.
 1.29 06-Jul-2005  christos Fix memory leaks found by valgrind. From Julien Torres
 1.28 27-Nov-2004  christos PR/26785: Jess Thrysoee: libedit - H_NEXT and H_PREV shifts cursor on failure
 1.27 24-Aug-2004  christos make sure that we round up to 1K.
 1.26 20-Aug-2004  christos PR/26725: Sergey S. Kostyliov: Typo in libedit, possible buffer overflow in src/lib/libedit/history.c:history_save()
 1.25 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.24 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.23 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.22 21-Jan-2003  christos Add a uniquefier for the history function.
 1.21 27-Oct-2002  christos don't crash in memory shortage conditions.
 1.20 13-Oct-2002  christos write the vis(3) converted string into the file, not the original one.
Noted by Tim Robbins. Hi luke!
 1.19 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.18 29-Sep-2001  jdolecek history_def_enter: fix off-by-one mistake in delete condition (the behaviour
to keep at least one entry on the history list is retained)
This fixes lib/9704 by Phil Nelson.
 1.17 20-Mar-2001  christos chmod the history file to 600 so that only the owner can read it.
[inspired by the openbsd fix to readline]
 1.16 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.15 29-Aug-2000  lukem history_def_set has a `const int' as a third arg, not an `int'.
picked up by the ultrix compiler, reported by simonb@ ...
 1.14 02-Jul-1999  simonb More trailing white space.
 1.13 06-Mar-1999  mycroft Add missing , in he_errlist[] initializer. Yay lint.
 1.12 05-Feb-1999  christos Encode the history lines using strvis() before saving it. Fixes gdb history
problem with missing newlines.
 1.11 12-Dec-1998  christos - missing error message from array could cause core dump
- delint
 1.10 03-Dec-1998  cgd per e-mail with christos: history_next_event() should return -1, not NULL,
in case of error, just like history_prev_event() does.
 1.9 20-May-1998  christos Add H_APPEND to simplify the interface.
 1.8 20-May-1998  christos Add a function to be able to set the cursor to a given event number.
 1.7 14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.6 06-Jul-1997  christos Fix compiler warnings.
 1.5 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.4 23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 15-Oct-1995  christos Added history load and save to file functions.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.45.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.2.1 17-Apr-2012  yamt sync with head
 1.46.16.1 10-Aug-2014  tls Rebase.
 1.46.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.59.4.1 10-Jun-2019  christos Sync with HEAD
 1.59.2.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.63.10.1 02-Aug-2025  perseant Sync with HEAD
 1.1 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.24 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.23 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.22 21-Feb-2009  christos more size_t stuff.
 1.21 16-Feb-2009  christos fix sign compare issues.
 1.20 15-Feb-2009  christos pass lint on _LP64.
 1.19 23-Mar-2006  christos branches: 1.19.28;
move declaration to header file.
 1.18 06-Mar-2006  christos Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.17 08-Aug-2005  christos Spelling mistakes and comment errors (from FreeBSD via Stefan Farfeleder; many
thanks)
 1.16 06-Jul-2005  christos Fix memory leaks found by valgrind. From Julien Torres
 1.15 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.12 17-May-2001  christos PR/12963:Jason Waterman: Fix signed cast problems.
 1.11 23-Jan-2001  jdolecek sprinkle couple const
 1.10 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.9 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.8 04-Oct-2000  sommerfeld format string audit (silence warnings, save space)
 1.7 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.6 19-Jan-2000  christos PR/9244: Kevin Schoedel: libedit dumps bindings inconsistently
 1.5 02-Jul-1999  simonb More trailing white space.
 1.4 12-Dec-1998  christos delint
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.19.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.14 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.13 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.12 21-Feb-2009  christos more size_t stuff.
 1.11 15-Feb-2009  christos pass lint on _LP64.
 1.10 23-Mar-2006  christos branches: 1.10.28;
move declaration to header file.
 1.9 06-Mar-2006  christos Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.6 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.5 23-Jan-2001  jdolecek sprinkle couple const
 1.4 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.3 02-Jul-1999  simonb More trailing white space.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.10.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.25 03-Jan-2025  rillig libedit: remove redundant break statements after EL_ABORT
 1.24 23-Jul-2019  christos branches: 1.24.12;
PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.23 24-May-2016  christos branches: 1.23.16;
From Ingo Schwarze:

Reduce obfuscation of errno handling. There is only one purpose
non-local errno handling is needed for: Inside el_wgets(), several
functions call down indirectly to el_wgetc(), many of them via the
dispatch table. When el_wgetc() fails, it does properly report
failure, but then various cleanup is done which may clobber errno.
But when returning due to failure, el_wgets() wants to have errno
set to the reason of the original read failure, not to the reason
of some subsequent failure of some cleanup operation. So el_wgetc()
needs to save errno, and if it's non-zero, el_wgets() needs to
restore it on failure.

This core logic is currently obscured by the fact that el_errno
is set and inspected at some additional places where it isn't needed.
Besides, since el_wgetc() and and el_wgets() are both in read.c,
el_errno does not need to be in struct editline, it can and should
be local to read.c in struct el_read_t.

Let's look at what can be simplified.

1. keymacro_get() abuses el_errno instead of having a proper
error return code. Adding that error return code is easy
because node_trav() already detects the condition and an
adequate code is already defined. Returning it, testing
for it in read_getcmd(), and returning with error from there
removes the need to inspect el_errno from el_wgets() after
calling read_getcmd().
Note that resetting lastchar and cursor and clearing buffer[0]
is irrelevant. The code returns from el_wgets() right afterwards.
Outside el_wgets(), these variables are no longer relevant.
When el_wgets() is called the next time, it will call ch_reset()
anyway, resetting the two pointers. And as long as lastchar
points to the beginning of the buffer, the contents of the
buffer won't be used for anything.

2. read_getcmd() doesn't need to set el_errno again after el_wgetc()
failure since el_wgetc() already did so. While here, remove
the silly "if EOF or error" comments from the el_wgetc()
return value tests. It's a public interface documented in a
manual, so people working on the implementation can obviously
be expected to know how it works. It's a case of

count++; /* Increment count. */

3. In the two code paths of el_wgets() that lead up to "goto noedit",
there is no need to save the errno because nothing that might
change it happens before returning.

For clarity, since el_wgets() is the function restoring the errno,
also move initializing it to the same function.

Finally, note that restoring errno when the saved value is zero is
wrong. No library code is ever allowed to clear a previously set
value of errno. Only application programs are allowed to do that,
and even they usually don't need to do so, except when using certain
ill-designed interfaces like strtol(3).

I tested that the behaviour remains sane in the following cases,
all during execution of el_wgets(3) and with a signal handler
for USR1 installed without SA_RESTART.

* Enter some text and maybe move around a bit.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press Ctrl-V to activate ed-quoted-insert.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
ed_quoted_insert() returns ed_end_of_file(), i.e. CC_EOF,
and el_wgets() returns 0.

* Press a key starting a keyboard macro.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press : to enter builtin command mode.
Start typing a command.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now c_gets() returns -1, ed_command() beeps and returns CC_REFRESH,
and el_wgets() resumes operation as it should.

I also tested with "el_set(el, EL_EDITMODE, 0)", and it returns
the right value and sets errno correctly.
 1.22 09-May-2016  christos s/protected/libedit_private/g
 1.21 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.20 12-Apr-2016  christos From Ingo Schwarze:

* Delete the stubs of the XK_EXE mechanism that was never implemented.
From a security, stability, and simplicity perspective, i would
consider implementing it a truly terrible idea, so let's better
get rid of it.

* Do not use the local variable "num" in el_wgets() alternately for
two completely different purposes. Only use it for the number
of characters read, as stated in the comment (or -1 as long as
that number is still unknown), not for the (more or less boolean)
return value of read_getcmd(). Actually, there is no need at
all to save the latter return value after testing it once.

* The function read_getcmd() has very unusual return values:
It returns -1 for success and 0 for EOF/error. Switch that around
to 0 for success and -1 for EOF/error to be less confusing, and
get rid of the OKCMD preprocessor macro.

* Get rid of one #ifdef section in el_wgets() by using
el->el_chared.c_macro directly at the only place
where it is used.

* Delete the unused MIN() macro.
 1.19 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.18 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.17 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.16 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.15 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.14 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.13 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.12 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.11 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.10 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.9 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.8 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.7 16-Aug-2011  christos re-enable -Wconversion
 1.6 29-Jul-2011  christos pass -Wconversion
 1.5 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.4 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.3 28-Jul-2011  christos whitespace
 1.2 28-Jul-2011  christos whitespace
 1.1 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.23.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.24.12.1 02-Aug-2025  perseant Sync with HEAD
 1.6 09-May-2016  christos s/protected/libedit_private/g
 1.5 12-Apr-2016  christos From Ingo Schwarze:

* Delete the stubs of the XK_EXE mechanism that was never implemented.
From a security, stability, and simplicity perspective, i would
consider implementing it a truly terrible idea, so let's better
get rid of it.

* Do not use the local variable "num" in el_wgets() alternately for
two completely different purposes. Only use it for the number
of characters read, as stated in the comment (or -1 as long as
that number is still unknown), not for the (more or less boolean)
return value of read_getcmd(). Actually, there is no need at
all to save the latter return value after testing it once.

* The function read_getcmd() has very unusual return values:
It returns -1 for success and 0 for EOF/error. Switch that around
to 0 for success and -1 for EOF/error to be less confusing, and
get rid of the OKCMD preprocessor macro.

* Get rid of one #ifdef section in el_wgets() by using
el->el_chared.c_macro directly at the only place
where it is used.

* Delete the unused MIN() macro.
 1.4 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.3 29-Jan-2016  christos One macro is enough (Ingo Schwarze)
 1.2 28-Jul-2011  christos whitespace and comments
 1.1 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.2 21-Jun-2023  wiz libedit: fix pkg-config to really provide readline directory as intended
 1.1 20-Jun-2023  wiz install pkg-config file for libedit

version number matches portable libedit
--cflags output matches portable libedit, since users probably want the
readline interface
 1.6 05-Dec-2024  christos Don't eat 0 width characters, print them.
 1.5 23-Jul-2019  christos branches: 1.5.12;
remove stray brace
 1.4 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.3 30-Jun-2017  kre branches: 1.3.4; 1.3.8;

Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)

Note: this has currently only been tested with everything ascii (C locale).
 1.2 29-Jun-2017  kre Fix an obvious, but almost invisible typo (avoid some core dumps).
 1.1 27-Jun-2017  christos add literal escape sequence support, patterned after the tcsh ones.
 1.3.8.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.4.2 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.3.4.1 30-Jun-2017  snj file literal.c was added on branch netbsd-8 on 2017-07-23 14:41:26 +0000
 1.5.12.1 02-Aug-2025  perseant Sync with HEAD
 1.2 30-Jun-2017  kre branches: 1.2.4;

Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)

Note: this has currently only been tested with everything ascii (C locale).
 1.1 27-Jun-2017  christos add literal escape sequence support, patterned after the tcsh ones.
 1.2.4.2 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.2.4.1 30-Jun-2017  snj file literal.h was added on branch netbsd-8 on 2017-07-23 14:41:26 +0000
 1.29 09-May-2016  christos s/protected/libedit_private/g
 1.28 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.27 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.26 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.25 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.24 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.23 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.22 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.21 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.20 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.19 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.18 21-Mar-2012  matt Use C89 functions definitions.
 1.17 28-Jul-2011  christos branches: 1.17.2;
include config.h for all c files.
 1.16 18-Apr-2010  christos shame on solaris that is the last OS not supporting $()
 1.15 15-Apr-2010  christos From Jess Thrysoee
- Fix wint_t to Int confusion
 1.14 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.13 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.12 12-Feb-2009  sketch More fixes for existing portability stuff.
 1.11 22-Oct-2005  christos branches: 1.11.28;
change tr '[a-z]' '[A-Z]' to tr '[:lower:]' '[:upper:]' so that POSIX systems
work properly regardless of environment variable settings.
 1.10 08-Aug-2005  christos Don't add an extra { NULL, 0, NULL } element to the help array. Instead keep
it always the same size as the function array for consistency. Reported in
FreeBSD PR 82381, but fixed differently.
 1.9 16-May-2005  lukem Remove clause 3 from the UCB license.
 1.8 10-Mar-2003  christos don't use the path for awk
 1.7 09-Jan-2001  jdolecek make array of functions and help array const
 1.6 04-Sep-2000  lukem - generate ansi prototypes instead of using __P(). noted by christos
- fix a couple of comments
 1.5 21-Jun-2000  lukem * add -m option to makelist, which generates an mdoc table with the key
bindings and their descriptions
* manually add the output of 'sh ./makelist -m vi.c ed.c common.c' to
a new section in editrc(5) called `EDITOR COMMANDS'
 1.4 02-Jul-1999  simonb branches: 1.4.8;
More trailing white space.
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 07-Jun-1995  cgd be a bit more careful when splitting pathnames
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.4.8.1 23-Jun-2000  lukem Pull up editrc.5 revision 1.9
Pull up makelist revision 1.5
* add -m option to makelist, which generates an mdoc table with the key
bindings and their descriptions
* manually add the output of 'sh ./makelist -m vi.c ed.c common.c' to
a new section in editrc(5) called `EDITOR COMMANDS'
requested/approved by thorpej
 1.11.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.17.2.1 17-Apr-2012  yamt sync with head
 1.56 03-Jan-2025  rillig libedit: remove redundant break statements after EL_ABORT
 1.55 30-Oct-2022  christos branches: 1.55.4;
improvements in malloc/free handling.
 1.54 29-Aug-2021  christos ^W is traditionally bound to ed-delete-prev-word and not kill-region
^R is traditionally bound to em-inc-search-next and not redisplay
This is what mksh, zsh bash, readline do (Baptiste Daroussin)
 1.53 30-Mar-2020  ryo fix build error with SDEBUG, MAP_DEBUG, DEBUG_REFRESH
 1.52 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.51 09-May-2016  christos branches: 1.51.16;
s/protected/libedit_private/g
 1.50 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.49 17-Apr-2016  christos Remove empty callbacks (Ingo Schwartze)
 1.48 12-Apr-2016  christos From Ingo Schwarze:

* Delete the stubs of the XK_EXE mechanism that was never implemented.
From a security, stability, and simplicity perspective, i would
consider implementing it a truly terrible idea, so let's better
get rid of it.

* Do not use the local variable "num" in el_wgets() alternately for
two completely different purposes. Only use it for the number
of characters read, as stated in the comment (or -1 as long as
that number is still unknown), not for the (more or less boolean)
return value of read_getcmd(). Actually, there is no need at
all to save the latter return value after testing it once.

* The function read_getcmd() has very unusual return values:
It returns -1 for success and 0 for EOF/error. Switch that around
to 0 for success and -1 for EOF/error to be less confusing, and
get rid of the OKCMD preprocessor macro.

* Get rid of one #ifdef section in el_wgets() by using
el->el_chared.c_macro directly at the only place
where it is used.

* Delete the unused MIN() macro.
 1.47 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.46 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.45 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.44 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.43 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.42 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.41 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.40 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.39 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.38 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.37 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.36 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.35 14-May-2015  christos fix warnings on ubuntu 32 bit (Miki Rozloznik)
 1.34 06-Jul-2014  christos Bounds search for reallocated index, from OpenBSD via Andreas Fett
 1.33 01-Jan-2013  christos branches: 1.33.6;
remove dead assignment (Christoph Mallon)
 1.32 01-Jan-2013  christos Fix pasto that affected bind -k (Christoph Mallon)
 1.31 18-Nov-2011  christos branches: 1.31.6;
Add coverity annotations about unreachable code (Kamil Dudka)
 1.30 16-Aug-2011  christos branches: 1.30.2;
re-enable -Wconversion
 1.29 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.28 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.27 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.26 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.25 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.24 09-Apr-2006  christos fix debugging printf format.
 1.23 06-Mar-2006  christos Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.22 09-Aug-2005  christos Fix two more help iterators. Thanks Stefan Farfeleder!
 1.21 08-Aug-2005  christos Don't add an extra { NULL, 0, NULL } element to the help array. Instead keep
it always the same size as the function array for consistency. Reported in
FreeBSD PR 82381, but fixed differently.
 1.20 13-Aug-2004  mycroft Delete-previous-char and delete-next-char without an argument are not supposed
to modify the yank buffer in Emacs. Make it so.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.17 31-Oct-2002  christos support for % command [matching parens/brackets/braces] on vi modes.
From David Laight, thanks!
 1.16 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.15 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.14 09-Jan-2001  jdolecek make constant arrays a const
 1.13 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.12 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.11 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.10 15-Oct-1999  jdolecek don't assume locales are not working - it may not be the case
re_refresh(): cast the character passed to re_addc() to unsigned char,
so we don't end up calling isprint() with negative value
when chars are signed and character value is >= 128
 1.9 02-Jul-1999  simonb branches: 1.9.2;
More trailing white space.
 1.8 12-Dec-1998  christos delint
 1.7 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.6 30-Mar-1998  mrg use int rather than char as an array index.
 1.5 03-Feb-1998  perry remove obsolete register declarations
 1.4 06-Jul-1997  christos Fix compiler warnings.
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 27-Apr-1995  mycroft Trivial code ordering change.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.9.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.30.2.2 23-Jan-2013  yamt sync with head
 1.30.2.1 17-Apr-2012  yamt sync with head
 1.31.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.31.6.1 25-Feb-2013  tls resync with head
 1.33.6.1 10-Aug-2014  tls Rebase.
 1.51.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.51.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.55.4.1 02-Aug-2025  perseant Sync with HEAD
 1.13 09-May-2016  christos s/protected/libedit_private/g
 1.12 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.11 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.10 06-Jul-2014  christos Bounds search for reallocated index, from OpenBSD via Andreas Fett
 1.9 30-Dec-2009  christos branches: 1.9.12; 1.9.22;
Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.6 09-Jan-2001  jdolecek make constant arrays a const
 1.5 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.4 02-Jul-1999  simonb More trailing white space.
 1.3 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.9.22.1 10-Aug-2014  tls Rebase.
 1.9.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.42 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.41 29-Nov-2018  christos Fix off by one <tsahara at iij>
 1.40 09-May-2016  christos branches: 1.40.14; 1.40.16;
s/protected/libedit_private/g
 1.39 11-Apr-2016  christos Fix indentation, Ingo Schwarze
 1.38 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.37 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.36 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.35 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.34 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.33 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.32 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.31 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.30 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.29 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.28 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.27 06-Jul-2014  christos Bounds search for reallocated index, from OpenBSD via Andreas Fett
 1.26 16-Aug-2011  christos branches: 1.26.8; 1.26.18;
re-enable -Wconversion
 1.25 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.24 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.23 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.22 29-May-2005  lukem Update for recent parse__escape() prototype change
 1.21 29-May-2005  christos PR/25694: Luke Mewburn: Don't abuse unconstify'ing a string and writing to
it, because you'll core dump. Also remove extra const that gives pain to
the irix compiler.
 1.20 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.19 02-Nov-2003  christos Handle M- as escape. XXX: should probably select the meta-map instead.
From Gerry Swislow gerry at certif com
 1.18 15-Oct-2003  christos don't limit ^c to alpha c, and add VIS_NOSLASH so that vis(3) does not
produce \^c
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.16 21-Jan-2003  christos Add a uniquefier for the history function.
 1.15 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.14 23-Jan-2001  jdolecek sprinkle couple const
 1.13 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.12 10-Mar-2000  jdolecek include <stdlib.h> to get definition of malloc() and free(), so it's
possible to compile this file separately when debugging
 1.11 02-Jul-1999  simonb More trailing white space.
 1.10 05-Feb-1999  christos M-X:<enter> core-dumped.
 1.9 12-Dec-1998  christos delint
 1.8 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.7 21-Jan-1998  lukem in el_parse(), use a temporary buffer to store the program name when
comparing, preventing trashing of argv[0]. remove note in man page
warning of former behaviour.
 1.6 06-Jul-1997  christos Fix compiler warnings.
 1.5 11-Jan-1997  lukem * document ^char and \ escape sequences
* when parsing ^char control chars, check the correct char when determining
validity (previously, ^char was a NOP interpreted as the literal string
because of this bug)
 1.4 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.3 11-Jan-1997  lukem * in el_parse(), don't reference argv[0] if argc < 1 (return -1 instead)
* clarify return value of el_parse()
 1.2 09-Jan-1997  lukem * add a man page for the editline routines
* add a man page describing editrc
* fix bugs in el_parse():
* didn't execute command when program name matched (test reversed)
* was checking against empty string instead of program name
* after checks, command to run also pointed to empty string

[christos - the author of libedit - ok-ed the man pages in general (which I
wrote from scratch by RTFS) as well as the bugfix]
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.26.18.1 10-Aug-2014  tls Rebase.
 1.26.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.40.16.1 10-Jun-2019  christos Sync with HEAD
 1.40.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.9 09-May-2016  christos s/protected/libedit_private/g
 1.8 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.7 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.6 29-May-2005  lukem Update for recent parse__escape() prototype change
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.4 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.3 02-Jul-1999  simonb More trailing white space.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.27 27-Jun-2017  christos add literal escape sequence support, patterned after the tcsh ones.
 1.26 09-May-2016  christos branches: 1.26.8;
s/protected/libedit_private/g
 1.25 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.24 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.23 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.22 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.21 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.20 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.19 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.18 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.17 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.16 17-Jul-2009  christos handle prompt_esc properly.
 1.15 16-Apr-2009  christos PR/41230: -current: sh(1) endlessly looping in interactive
Fix proposed from Matthew Mondor
 1.14 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.13 21-Feb-2009  christos back out all prompt changes. they are not needed.
 1.12 17-Feb-2009  christos allow for a prompt argument.
 1.11 07-Aug-2003  agc branches: 1.11.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.9 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.8 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.7 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.6 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.5 02-Jul-1999  simonb branches: 1.5.4;
More trailing white space.
 1.4 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.5.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.11.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.26.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.15 09-May-2016  christos s/protected/libedit_private/g
 1.14 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.13 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.12 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.11 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.10 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.9 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.8 21-Feb-2009  christos back out all prompt changes. they are not needed.
 1.7 17-Feb-2009  christos allow for a prompt argument.
 1.6 07-Aug-2003  agc branches: 1.6.40;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.5 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.4 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.3 29-Jul-1998  lukem branches: 1.3.6;
* add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.3.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.109 03-Jan-2025  rillig libedit: remove redundant break statements after EL_ABORT
 1.108 30-Oct-2022  christos branches: 1.108.4;
improvements in malloc/free handling.
 1.107 15-Aug-2021  christos Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.
 1.106 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.105 25-Nov-2018  christos From Yuichiro Naito (FreeBSD):

hrs@ says that
(cbp >= MB_LEN_MAX) condition is necessary for checking invalid
byte sequences. If malicious input was given, libedit would read
byte sequences forever.
 1.104 18-Nov-2018  christos Remove utf-8 requirement (Yuichiro NAITO)
 1.103 27-Jun-2017  christos branches: 1.103.4; 1.103.6;
remove unused variable
 1.102 11-Dec-2016  christos branches: 1.102.6;
PR/51706: Amir Plivatsky: Fix memory leak
 1.101 25-May-2016  christos branches: 1.101.2;
abstract read code to a single function (Ingo Schwarze)
 1.100 24-May-2016  christos el_map.alt can't be NULL here (Ingo Schwarze)
 1.99 24-May-2016  christos remove debug read (Ingo Schwarze)
 1.98 24-May-2016  christos From Ingo Schwarze:

Reduce obfuscation of errno handling. There is only one purpose
non-local errno handling is needed for: Inside el_wgets(), several
functions call down indirectly to el_wgetc(), many of them via the
dispatch table. When el_wgetc() fails, it does properly report
failure, but then various cleanup is done which may clobber errno.
But when returning due to failure, el_wgets() wants to have errno
set to the reason of the original read failure, not to the reason
of some subsequent failure of some cleanup operation. So el_wgetc()
needs to save errno, and if it's non-zero, el_wgets() needs to
restore it on failure.

This core logic is currently obscured by the fact that el_errno
is set and inspected at some additional places where it isn't needed.
Besides, since el_wgetc() and and el_wgets() are both in read.c,
el_errno does not need to be in struct editline, it can and should
be local to read.c in struct el_read_t.

Let's look at what can be simplified.

1. keymacro_get() abuses el_errno instead of having a proper
error return code. Adding that error return code is easy
because node_trav() already detects the condition and an
adequate code is already defined. Returning it, testing
for it in read_getcmd(), and returning with error from there
removes the need to inspect el_errno from el_wgets() after
calling read_getcmd().
Note that resetting lastchar and cursor and clearing buffer[0]
is irrelevant. The code returns from el_wgets() right afterwards.
Outside el_wgets(), these variables are no longer relevant.
When el_wgets() is called the next time, it will call ch_reset()
anyway, resetting the two pointers. And as long as lastchar
points to the beginning of the buffer, the contents of the
buffer won't be used for anything.

2. read_getcmd() doesn't need to set el_errno again after el_wgetc()
failure since el_wgetc() already did so. While here, remove
the silly "if EOF or error" comments from the el_wgetc()
return value tests. It's a public interface documented in a
manual, so people working on the implementation can obviously
be expected to know how it works. It's a case of

count++; /* Increment count. */

3. In the two code paths of el_wgets() that lead up to "goto noedit",
there is no need to save the errno because nothing that might
change it happens before returning.

For clarity, since el_wgets() is the function restoring the errno,
also move initializing it to the same function.

Finally, note that restoring errno when the saved value is zero is
wrong. No library code is ever allowed to clear a previously set
value of errno. Only application programs are allowed to do that,
and even they usually don't need to do so, except when using certain
ill-designed interfaces like strtol(3).

I tested that the behaviour remains sane in the following cases,
all during execution of el_wgets(3) and with a signal handler
for USR1 installed without SA_RESTART.

* Enter some text and maybe move around a bit.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press Ctrl-V to activate ed-quoted-insert.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
ed_quoted_insert() returns ed_end_of_file(), i.e. CC_EOF,
and el_wgets() returns 0.

* Press a key starting a keyboard macro.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now el_wgets() sets errno=EINTR and returns -1.

* Press : to enter builtin command mode.
Start typing a command.
Then send a USR1 signal.
The signal gets processed, then read_char() resumes reading.
Send another USR1 signal.
Now c_gets() returns -1, ed_command() beeps and returns CC_REFRESH,
and el_wgets() resumes operation as it should.

I also tested with "el_set(el, EL_EDITMODE, 0)", and it returns
the right value and sets errno correctly.
 1.97 22-May-2016  christos Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze
 1.96 09-May-2016  christos s/protected/libedit_private/g
 1.95 19-Apr-2016  christos From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "read.h" everywhere, but only in the two files
needing access to el_read, read.c and el.c.
- To functions that don't need more, pass the struct el_read_t *
rather than the full EditLine *.
- Of course, that means that read_init() can now fail from
memory exhaustion, but it's easy to clean up after that.
 1.94 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.93 12-Apr-2016  christos FIONREAD takes int as an argument (Ingo Schwarze)
 1.92 12-Apr-2016  christos From Ingo Schwarze:

* Delete the stubs of the XK_EXE mechanism that was never implemented.
From a security, stability, and simplicity perspective, i would
consider implementing it a truly terrible idea, so let's better
get rid of it.

* Do not use the local variable "num" in el_wgets() alternately for
two completely different purposes. Only use it for the number
of characters read, as stated in the comment (or -1 as long as
that number is still unknown), not for the (more or less boolean)
return value of read_getcmd(). Actually, there is no need at
all to save the latter return value after testing it once.

* The function read_getcmd() has very unusual return values:
It returns -1 for success and 0 for EOF/error. Switch that around
to 0 for success and -1 for EOF/error to be less confusing, and
get rid of the OKCMD preprocessor macro.

* Get rid of one #ifdef section in el_wgets() by using
el->el_chared.c_macro directly at the only place
where it is used.

* Delete the unused MIN() macro.
 1.91 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.90 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.89 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.88 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.87 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.86 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.85 24-Feb-2016  christos Tuck in mbstate_t to the wide char version only to avoid exposing the zeroing
hack and doing it in the narrow case.
 1.84 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.83 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.82 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.81 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.80 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.79 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.78 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.77 14-Feb-2016  christos From Ingo Schwartze:

Next step: Remove #ifdef'ing in read_char(), in the same style
as we did for setlocale(3) in el.c.

A few remarks are required to explain the choices made.

* On first sight, handling mbrtowc(3) seems a bit less trivial
than handling setlocale(3) because its prototype uses the data
type mbstate_t from <wchar.h>. However, it turns out that
"histedit.h" already includes <wchar.h> unconditionally (i don't
like headers including other headers, but that ship has sailed,
people are by now certainly used to the fact that including
"histedit.h" doesn't require including <wchar.h> before), and
"histedit.h" is of course included all over the place. So from
that perspective, there is no problem with using mbrtowc(3)
unconditionally ever for !WIDECHAR.

* However, <wchar.h> also defines the mbrtowc(3) prototype,
so we cannot just #define mbrtowc away, or including the header
will break. It would also be a bad idea to porovide a local
implementation of mbrtowc() and hope that it overrides the one
in libc. Besides, the required prototype is subtly different:
While mbrtowc(3) takes "wchar_t *" as its first argument, we
need a function that takes "Char *". So unfortunately, we have
to keep a ct_mbrtowc #define, at least until we can maybe get
rid of "Char *" in the more remote future.

* After getting rid of the #else clause in read_char(), we can
pull "return 1;" into the default: clause. After that, we can
get rid of the ugly "goto again_lastbyte;" and just "break;".
As a bonus, that also gets rid of the ugly CONSTCOND.

* While here, delete the unused ct_mbtowc() from chartype.h.
 1.76 12-Feb-2016  christos GC IGNORE_EXTCHARS and simplify code (Ingo Schwarze)
 1.75 12-Feb-2016  christos From Ingo Schwarze:

If CHARSET_IS_UTF8 is not set, read_char() is broken in a large
number of ways:

1. The isascii(3) check can yield false positives. If a string in
an arbitrary encoding contains a byte in the range 0..127,
that does not at all imply that it forms a character all by
itself, and even less that it represents the same character
as in ASCII. Consequently, read_char() may return characters
the user never typed.
Even if the encoding is not state dependent, the assumption that
bytes in the range 0..127 represent ASCII characters is broken.
Consider UTF-16, for example.

2. The reverse problem can also occur. In an arbitrary encoding,
there is no guarantee that a character that can be represented
by ASCII is represented by a seven-bit byte, and even less by
the same byte as in ASCII.
Even for single-byte encodings, these assumptions are broken.
Consider the ISO 646 national variants, for example.
Consequently, the current code is insufficient to keep ASCII
characters working even for single-byte encodings.

3. The condition "++cbp != 1" can never trigger (because initially,
cbp is 0, and the code can only go back up via the final goto,
which has another cbp = 0 right before it) and it has no effect
(because cbp isn't used afterwards).

4. bytes = ct_mbtowc(cp, cbuf, cbp) is broken. If this returns -1,
the code assumes that is can just call mbtowc(3) again for later
input bytes. In some implementations, that may even be broken
for state-independent encodings, but trying again after mbtowc(3)
failure certainly produces completely erratic and meaningless
results in state-dependent encodings.

5. The assignment "*cp = (Char)(unsigned char)cbuf[0]" is
completely bogus. Even if the byte cbuf[0] represents a
character all by itself, which it usually will not, whether
or not the cast produces the desired result depends on the
internal representation of wchar_t in the C library, which
the application program can know nothing about. Even for ASCII
in the C/POSIX locale, an ASCII character other than '\0' ==
L'\0' == 0 need not have the same numeric value as a char and
as a wchar_t.

To summarize, this code only works if all of the following
conditions hold:

- The encoding is a single-byte encoding.
- ASCII is a subset of the encoding.
- The implementation of mbtowc(3) in the C library does not
require re-initialization after encoding errors.
- The implementation of wchar_t in the C library uses the
same numerical values as ASCII.

Otherwise, it silently produces wrong results.

The simplest way to fix this is to just use the same code as for
UTF-8 (right above). Of course, that causes functional changes
but that shouldn't matter since current behaviour is undefined.

The patch below provides the following improvements:

- It works for all stateless single-byte encodings, no matter
whether they are somehow related to ASCII, no matter how
mb[r]towc(3) are internally implemented, and no matter how
wchar_t is internally represented.
- Instead of producing unpredictable and definitely wrong
results for non-UTF-8 multibyte characters, it behaves in
a well-defined way: It aborts input processing, sets errno,
and returns failure.
Note that short of providing full support for arbitrary locales,
it is impossible to do better. We cannot know whether a given
unsupported locale is state-dependent, and for a state-dependent
locale, it makes no sense to retry parsing after an encoding
error, so the best we can do is abort processing for *any*
unsupported multi-byte character.
- Note that single-byte characters in arbitrary state-independent
locales still work, even in locales that may potentially also
contain multibyte characters, as long as those don't occur in
input. I'm not sure whether any such locales exist in practice...

Tested with UTF-8 and C/POSIX on OpenBSD. Also tested that in the
C/POSIX locale, non-ASCII bytes get through unmangled. You may
wish to test with ISO-LATIN on NetBSD if NetBSD supports that.

----
Also use a constant for meta to avoid warnings.
 1.74 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.73 11-Feb-2016  christos Remove utf8_islead() mbrtowc() handles this just fine (Ingo Schwarze)
 1.72 08-Feb-2016  christos UTF-8 fixes from Ingo Schwarze:

1. Assume that errno is non-zero when entering read_char()
and that read(2) returns 0 (indicating end of file).
Then, the code will clear errno before returning.
(Obviously, the statement "errno = 0" is almost always
a bug unless there is save_errno = errno right before it
and the previous value is properly restored later,
in all reachable code paths.)

2. When encountering an invalid byte sequence, the code discards
all following bytes until MB_LEN_MAX overflows; consider, for
example, 0xc2 immediately followed by a few valid ASCII bytes.
Three of those ASCII bytes will be discarded.

3. On a POSIX system, EILSEQ will always be set after reading a
valid (yes, valid, not invalid!) UTF-8 character. The reason
is that mbtowc(3) will first be called with a length limit
(third argument) of 1, which will fail, return -1, and - on
a POSIX system - set errno to EILSEQ.
This third bug is mitigated a bit because i couldn't find any
system that actually conforms to POSIX in this respect: None
of OpenBSD, NetBSD, FreeBSD, Solaris 11, and glibc set errno
when an incomplete character is passed to mbtowc(3), even though
that is required by POSIX.
Anyway, that mbtowc(3) bug will be fixed at least in OpenBSD
after release unlock, so it would be good to fix this bug in
libedit before fixing the bug in mbtowc(3).

How can these three bugs be fixed?

1. As far as i understand it, the intention of the bogus errno = 0
is to undo the effects of failing system calls in el_wset(),
sig_set(), and read__fixio() if the subsequent read(2) indicates
end of file. So, restoring errno has to be moved right after
read__fixio(). Of course, neither 0 nor e is the right value
to restore: 0 is wrong if errno happened to be set on entry, e
would be wrong because if one read(2) fails but a second attempt
succeeds after read__fixio(), errno should not be touched. So,
the errno to be restored in this case has to be saved before
calling read(2) for the first time.

2. Solving the second issue requires distinguishing invalid and
incomplete characters, but that is impossible with the function
mbtowc(3) because it returns -1 in both cases and sets errno
to EILSEQ in both cases (once properly implemented).

It is vital that each input character is processed right away.
It is not acceptable to wait for the next input character before
processing the previous one because this is an interactive
library, not a batch system. Consequently, the only situation
where it is acceptable to wait for the next byte without first
processing the previous one(s) is when the previous one(s) form
an incomplete sequence that can be continued to form a valid
character.

Consequently, short of reimplementing a full UTF-8 state machine
by hand, the only correct way forward is to use mbrtowc(3).
Even then, care is needed to always have the state object
properly initialized before using it, and to not discard a valid
ASCII or UTF-8 lead byte if it happens to follow an invalid
sequence.

3. Fortunately, solution 2. also solves issue 3. as a side effect,
by no longer using mbtowc(3) in the first place.
 1.71 06-Jul-2014  christos Bounds search for reallocated index, from OpenBSD via Andreas Fett
 1.70 27-May-2013  christos branches: 1.70.4;
Test early for EOF to avoid infinite loop in the wide char case. From
Linas Vepstas: linasvepstas at gmail dot com
 1.69 11-Sep-2012  christos branches: 1.69.2;
return !OKCMD on error.
 1.68 10-Sep-2012  christos PR/46935: Steffen Nurpmeso: editline(3) (libedit): faulty errno handling,
faulty reuse of val in wrong context
 1.67 16-Aug-2011  christos branches: 1.67.2;
re-enable -Wconversion
 1.66 29-Jul-2011  christos pass -Wconversion
 1.65 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.64 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.63 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.62 28-Jul-2011  christos term -> terminal
fix wide function confusion
 1.61 09-Jul-2011  christos make obvious what we are trying to do...
 1.60 09-Jul-2011  tron Try to fix build of port where "char" is unsigned.
 1.59 08-Jul-2011  christos Support other non-latin1 single byte character sets.
From: Alexander Barkov and Nirbhay Choubey at oracle dot com
 1.58 18-Feb-2011  christos PR/44599: Steven Vernon: libedit acts as if no data read if editmode is turned
off because nread is uninitialized in the edit disabled case.
 1.57 21-Jul-2010  christos branches: 1.57.2;
refresh only on SIGCONT not SIGWINCH from Edward Sheldrake
 1.56 19-Jul-2010  christos retry the read after sigwinch too, from Edward Sheldrake
 1.55 22-Mar-2010  christos https://bugzilla.redhat.com/show_bug.cgi?id=575383
Handle EINTR properly.
 1.54 31-Dec-2009  christos - Document and enable wide character support.
- Fix read function compatibility.
 1.53 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.52 22-Jul-2009  christos Always initialize nread since it is an out param.
From Michael Cook mcook at bbn dot com
 1.51 09-Jun-2009  christos decrement the number of levels after the loop (Julien Torres)
 1.50 08-Jun-2009  christos from Julien Torres, flip the order we pop in the macro array.
 1.49 10-Mar-2009  christos make el_gets set the count to -1 on error to distinguish between EOF and
error.
 1.48 21-Feb-2009  christos remove VEOF test. the tty is in cooked mode when we are not editing and
the tty driver does the check for us.
 1.47 21-Feb-2009  christos use the VEOF character from the terminal, instead of hard-coding 4.
 1.46 19-Feb-2009  christos reset and redraw on sigcont. From Anon Ymous.
 1.45 15-Feb-2009  christos pass lint on _LP64.
 1.44 15-Feb-2009  christos don't restart on EINTR, instead return NULL immediately. From Anon Ymous
 1.43 05-Feb-2009  christos branches: 1.43.2;
match documentation in el_push
 1.42 18-Jan-2009  lukem fix -Wsign-compare issues
 1.41 10-Sep-2008  christos Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.40 01-Mar-2007  christos branches: 1.40.12;
Fix bug with multiple pending el_pushes. Reported by Julien Torres.
 1.39 02-Aug-2005  christos On a fatal error, we want to stop processing the macro buffers.
 1.38 02-Aug-2005  tron Add missing second argument to another call of ch_reset().
 1.37 01-Aug-2005  christos Don't reset the macro strings each time we enter el_gets(), otherwise
el_push() is unusable programmatically.
 1.36 01-Jun-2005  lukem Don't use non-standard uint or u_int.
 1.35 09-Mar-2005  christos Make sure we flush after we prepare when we are unbuffered otherwise the
prompt will not appear immediately.
 1.34 08-Jul-2004  christos PR/23486: Andreas Gustafsson: gdb no longer works with emacs
- make sure that we keep previous contents of the buffer in unbuffered mode.
- when turning editing on and off keep tty consistent.
 1.33 27-Feb-2004  christos branches: 1.33.2;
Better fix for rl_prep_terminal() from Gerry Swislow.
 1.32 21-Feb-2004  christos Separate tty separation from the prompt printing function. From Gerry Swislow.
 1.31 17-Jan-2004  christos portability fixes.
 1.30 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.29 09-Oct-2003  christos PR/23107: Nathan Williams: ^D as the first char on the command line does
not DTRT in readline compatibility mode
 1.28 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.27 13-Sep-2003  mycroft Fix something that's been annoying me for a while...
Pull in <fcntl.h>, so that the fcntl #defines are present, and we build in the
automatic reset of non-blocking mode, rather than beeping like mad.
 1.26 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.25 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.24 20-Nov-2002  christos Fix problem with previous patches that broke vi history.
- c_gets() was usually returning a length, but sometimes
one of the CC_xxx values (which are small +ve integers)!
- fixed c_gets() by putting a ' ' under the cursor.
From David Laight.
 1.23 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.22 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.21 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.20 27-Sep-2001  christos PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
 1.19 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.18 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.17 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.16 19-Jan-2000  christos PR/9243: Kevin Schoedel: libedit ignores repeat count
 1.15 04-Oct-1999  lukem remove some lint
 1.14 08-Aug-1999  sommerfeld branches: 1.14.2;
minor tweak to previous fix: don't spuriously truncate final newline
under emacs.
 1.13 02-Aug-1999  sommerfeld Fix PR7685 (gdb under emacs prints spurious ^M and messes up terminal)
plus a few bogons noted along the way:
1) Set EDIT_DISABLED if terminal type is emacs.
2) fix bug in NO_TTY mode which caused it to not notice CR or LF
3) implement EDIT_DISABLED within libedit to be somewhat like NO_TTY,
except that a prompt is printed first.
 1.12 02-Jul-1999  simonb More trailing white space.
 1.11 11-Jan-1999  kleink In userland, pull in <errno.h> instead of <sys/errno.h> for the declaration
of errno.
 1.10 12-Dec-1998  christos delint
 1.9 01-Jun-1998  lukem * implement CC_REFRESH_BEEP; as per CC_REFRESH but beep as well. this
is useful in completion when a partial completion is found
* remove entry in BUGS about el_parse(); that was fixed a while ago
 1.8 21-Jan-1998  lukem fix compile errors if FIONREAD is defined. noted by
David Holland <dholland@bordeaux.eecs.harvard.edu> in [bin/4012].
 1.7 20-Dec-1997  christos Small optimization. Don't call isatty() on every invocation of el_gets, but
remember if the tty setup failed... Also trim the input line of trailing \r's.
 1.6 26-Oct-1997  christos Make el_gets() work when the input is not a tty.
 1.5 06-Jul-1997  christos Fix compiler warnings.
 1.4 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.3 14-Jan-1997  lukem Implement CC_REDISPLAY, which (unlink CC_REFRESH) redraws the entire input
line (a la ^R). This is useful if the binding outputs information and
mucks up the input line. To be used in ``list-choices'' bindings (refer
to the ^D binding in csh when filec is set)
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.14.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.33.2.1 10-Jul-2004  tron Pull up revision 1.34 (requested by christos in ticket #620):
PR/23486: Andreas Gustafsson: gdb no longer works with emacs
- make sure that we keep previous contents of the buffer in unbuffered mode.
- when turning editing on and off keep tty consistent.
 1.40.12.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.43.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.57.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.67.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.67.2.1 30-Oct-2012  yamt sync with head
 1.69.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.69.2.1 23-Jun-2013  tls resync from head
 1.70.4.1 10-Aug-2014  tls Rebase.
 1.101.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.102.6.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.103.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.103.6.1 10-Jun-2019  christos Sync with HEAD
 1.103.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.108.4.1 02-Aug-2025  perseant Sync with HEAD
 1.13 30-Oct-2022  christos improvements in malloc/free handling.
 1.12 22-May-2016  christos Stop the read module from poking the el_chared.c_macro data structure
currently belonging to the chared module. The read module does so
from three of its functions, while no other module uses the macro
data, not even the chared module itself. That's quite logical
because macros are a feature of input handling, all of which is
done by the read module, and none by the chared module. So move
the data into the read modules's own opaque data structure, struct
el_read_t.

That simplifies internal interfaces in several respects: The
semi-public chared.h has one fewer struct, one fewer #define, and
one fewer member in struct el_chared_t; all three move to one single
C file, read.c, and are now module-local. And the internal interface
function ch_reset() needs one fewer argument, making the code of many
functions in various modules more readable.

The price is one additional internal interface function, read_end(),
10 lines long including comments, called publicly from exactly one
place: el_end() in el.c. That's hardly an increase in complexity
since most other modules already have their *_end() function, read.c
was the odd one out not having one.

From Ingo Schwarze
 1.11 09-May-2016  christos s/protected/libedit_private/g
 1.10 19-Apr-2016  christos From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
- Make el_read in struct editline an opaque pointer rather
than an embedded struct.
- Do not include "read.h" everywhere, but only in the two files
needing access to el_read, read.c and el.c.
- To functions that don't need more, pass the struct el_read_t *
rather than the full EditLine *.
- Of course, that means that read_init() can now fail from
memory exhaustion, but it's easy to clean up after that.
 1.9 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.8 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.7 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.6 29-Apr-2008  martin Convert to new 2 clause license
 1.5 21-Aug-2006  christos branches: 1.5.16;
Change to a 3 clause copyright after permission of the holders.
 1.4 27-Feb-2004  christos Better fix for rl_prep_terminal() from Gerry Swislow.
 1.3 21-Feb-2004  christos Separate tty separation from the prompt printing function. From Gerry Swislow.
 1.2 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.1 27-Sep-2001  christos PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
 1.5.16.1 18-May-2008  yamt sync with head.
 1.183 14-Jun-2025  christos Change kill(0, signo) -> raise(signo) so that we only signal the current
process not the whole process group. Pointed out by geoff thomas. Related
issues:
https://www.postgresql.org/message-id/271520.1713052173%40sss.pgh.pa.us
https://github.com/astral-sh/python-build-standalone/pull/652\
#issuecomment-2972762033
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=159226
 1.182 26-Mar-2024  christos branches: 1.182.2;
fix insert key (Xose Vazquez Perez)
 1.181 25-Apr-2023  christos pass lint.
 1.180 24-Apr-2023  christos PR/57376: Jorge Giner: readline file completion does not quote; do the same.
 1.179 21-Apr-2023  christos Align types with readline-8.2 (wiz@)
 1.178 02-Dec-2022  christos PR/57095: Yilei Yang: Change readline's replace_history_entry to not make a copy
of the string to replace since H_REPLACE already makes a copy (fixes memory leak)
 1.177 30-Oct-2022  christos improvements in malloc/free handling.
 1.176 21-Sep-2022  christos PR/57016: Ricky Zhou: declare lastidx
 1.175 20-Sep-2022  christos PR/57016: Ricky Zhou: Revert to trimming the last newline instead of the
first one so that multi-line commands work again.
 1.174 08-Apr-2022  christos PR/56778: Detlev Casanova: Missing rl_initialize call in rl_copy_text
 1.173 19-Feb-2022  christos PR/56695: Walter Lozano: Correct declaration of hook functions.
 1.172 08-Feb-2022  christos PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key
 1.171 31-Jan-2022  christos PR/56622: Walter Lozano: Improve readline compatibility by adding
rl_readline_state support.
 1.170 29-Jan-2022  christos Add more refreshes from Walter Lozano. The readline example in
http://www.mcld.co.uk/blog/2009/simple-gnu-readline-callback-style-example.html
still does not work, but it is better.
 1.169 11-Jan-2022  christos PR/56618: Walter Lozano: Improve libedit compatibility with readline by
implementing:

rl_copy_text, rl_erase_empty_line, rl_message, rl_on_new_line,
rl_replace_line, rl_restore_prompt, rl_save_prompt
 1.168 10-Sep-2021  rillig libedit: fix indentation

No change to the resulting object files.
 1.167 10-Sep-2021  christos rl_startup_hook should be called each time. From Carlos Henrique Lima Melara
 1.166 09-Sep-2021  christos fix memory issues found by fuzzing (double frees and buffer overflows)
 1.165 03-Sep-2021  christos Try to refactor this in order to correct some of the memory issues
reported by Christian Holler.
 1.164 21-Aug-2021  christos PR/56370: mirabilos: libedit change from 2017 kills history in gdb
 1.163 21-Aug-2021  christos Add more api to make gdb-11 happy (but not gdbtui as usual)
 1.162 15-Aug-2021  rillig libedit: simplify calls to macro ADD_STRING

The lint comments CONSTCOND and LINTED were not necessary. It is
simpler to just specify what to free. GCC optimizes free(NULL) to be a
no-op.

No functional change.
 1.161 15-Aug-2021  rillig readline: fix lint warning about effective unconst cast

Calling strchr to avoid the syntactical unconst cast is not necessary
here. A simple pointer assignment is enough.

No functional change.
 1.160 15-Aug-2021  christos Add a LINTED comment... Why doesn't NOTREACHED work?
 1.159 09-Oct-2019  christos add +1 to strlcpy's (Patrick Welche)
 1.158 08-Oct-2019  christos Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
 1.157 21-Aug-2019  christos Increment offset when adding an element to history to keep it aligned with
the last element entered (Sandy Li Changqing)
 1.156 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.155 07-Jun-2019  christos PR/54281: Jonathan Perkins: NUL terminate rl_line_buffer on modification
to avoid completion leak.
 1.154 07-Jun-2019  christos PR/54280: rl_completer_quote_characters should be const for readline compat
 1.153 07-Jun-2019  christos PR/54279: Jonathan Perkins: Ignore adjacent start/end prompt ignore.
 1.152 26-Apr-2019  christos Follow the man page for EL_GETTC and not require a NULL terminated argument
list: https://reviews.llvm.org/D61191
 1.151 15-Feb-2019  christos PR/53983: Jonathan Perkins: Fix types for readline compatibility
 1.150 14-Feb-2019  christos PR/53981: Jonathan Perkins: history_list should null-terminate
 1.149 10-Jan-2019  christos PR/53856: F. Aragon: editline/libedit not prompting colors in readline mode
 1.148 02-Dec-2018  christos Add a couple more readline compat functions.
 1.147 09-Jun-2018  christos branches: 1.147.2;
Provide more compatibility with readline headers; now python-3.6.5 works
when changing 'readline' -> 'edit' in setup.py.
Revert previous conditional setting of unbuffered.
 1.146 01-Jan-2018  christos branches: 1.146.2;
Only FLUSH if we are ending libedit; DRAIN if we suspend for readline.
This allows pasting multiline buffers (Gerry Swislow)
 1.145 08-Dec-2017  christos For applications that don't issue their own prompt (like python)
don't set unbuffered unless they've already printed the prompt.
This avoids printing the prompt before the application has a chance
to process the input line.
From sjg@
 1.144 17-Sep-2017  kre PR lib/52547 - read_history (readline.c) should now sets history_length.

Patch from Yen Chi Hsuan in the PR, extracted from Apple's version of
readline.c, then modified by me to be consistent about what the return
value really is.
 1.143 05-Sep-2017  christos For readline emulation, don't reset the tty to "sane" (cooked) mode if we
did not start this way. Also set and reset the tty on entry and exit from
readline() since this is what readline does.
 1.142 01-Sep-2017  christos PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.141 21-Apr-2017  abhinav When doing filename autocompletion, append a trailing slash at the end of directory
names. We already do this when there is only one completion option but
in case of of multiple completion options, it wasn't being done.

ok christos@
 1.140 09-Jan-2017  christos branches: 1.140.2;
Make sure we take into account history_base when computing negative history
offsets. (Gerry Swinslow)
 1.139 28-Oct-2016  christos pass the stream to the getc function
 1.138 01-Sep-2016  mbalmer fix typo
 1.137 24-Aug-2016  christos more compatible with readline history functions.
 1.136 02-Jun-2016  christos branches: 1.136.2;
Fix previous to better match readline behavior (Ingo Schwarze)
 1.135 02-Jun-2016  christos From Ingo Schwarze:

In libedit, the only way how H_ENTER can fail is memory exhaustion,
too, and of course it is handled gracefully, returning -1 from
history(). So of course, we will continue to handle it gracefully
in add_history() as well, but we are free to decide what to do with
the library state in this case because GNU just dies...

I think the most reasonable course of action is to simply not change
the library state in any way when add_history() fails due to memory
exhaustion, but just return.

If H_ENTER does not fail, we know that the history now contains at
least one entry, so there is no need any longer to check the H_GETSIZE
return value. And we can of course always set current_history_valid.

While testing these changes, i noticed three problems so closely
related that i'd like to fix them in the same diff.

1. libedit has the wrong prototype for add_history().
GNU readline-6.3 defines it as void add_history(const char *).
Of course, that is very stupid - no way to report problems to
the caller! But the whole point of a compatibility mode is
being compatible, so we should ultimately change this.
Of course, changing the prototype of a public symbol requires
a libedit major bump. I don't want to do that casually.
Rather, i will take a note and change the prototype the next
time we need a libedit major bump for more important reasons.
For now, let's just always return 0.

2. While *implicitely* pushing an old entry off the history
increments history_base in GNU readline, testing reveals that
*explicitly* deleting one does not. Again, this is not
documented, but it applies to both remove_history() and
stifle_history(). So delete history_base manipulation
from stifle_history(), which also allows to simplify the
code and delete two automatic variables.

3. GNU readline add_history(NULL) crashes with a segfault.
There is nothing wrong with having a public interface
behave that way. Many standard interfaces do, including
strlen(3). Such crashes can even be useful to catch
buggy application programs.
In libedit/readline.c rev. 1.104, Christos made add_history()
silently ignore this coding error, according to the commit
message to hide a bug in nslookup(1). That change was never
merged to OpenBSD. I strongly disagree with this change.
If nslookup(1) is still broken, that program needs to be
fixed instead. In any case, delete the bogus check; hiding
bugs is dangerous.
 1.134 31-May-2016  christos remove the right history entry (Ingo Schwarze)
 1.133 13-May-2016  christos From Bastian Maerkisch, via Igno Schwarze:

Even though section "2.3.3 Information About the History List"
of the history(3) info(1) manual only says

-- Function: int where_history (void)
Returns the offset of the current history element.

which maybe isn't completely clear, a plausible implementation
is that the offset returned is the same offset that can be used
for history_set_pos(), i.e. that it is 0 for the oldest entry
and increases with time, and that's how the GNU implementation
behaves indeed.

The libedit implementation, on the other hand, returns 1 for the
newest entry and increases going back in time.
 1.132 09-May-2016  christos GNU readline(3) regards history chronologically, that is, from the
perspective of the dawn of time, so "next" means "newer" and "previous"
means "older". Libedit, by contrast, uses reverse chronology and
regards history from the perspective of the present, such that "next"
means "longer ago" and "previous" means "not so long ago".

The following patch fixes previous_history() and next_history()
as proposed by Bastian Maerkisch.

But there is a related problem demonstrated by Bastian's regression
tests that his patch did not fix: next_history() can advance not
only to the newest entry, but beyond it, which core libedit cannot
do. So that feature must be implemented locally in readline.c.

With that, the last of Bastians tests is fixed, test_movement_direction().

This patch also improves libedit documentation to more clearly state
what "previous" and "next" mean. GNU readline documentation is
just as unclear, but we can't easily fix that since libedit doesn't
include its own readline.3 manual.

(Ingo Schwarze)
 1.131 09-May-2016  christos The libedit implementation of history_get() also differs from the GNU
implementation: libedit goes to the entry with the given number
stored in the HistEvent structure, while GNU subtracts history_base,
then advances that many entries from the oldest one. If entries were
removed in between, GNU advances further than libedit.

The call sequence H_CURR, H_DELDATA, H_CURR, H_NEXT_EVDATA looks
weird, as if part of that must somehow be redundant. But actually,
the user interface is so counter-intuitive that every single step
is really required.

- The first H_CURR is needed to be able to go back after an error.
- The H_DELDATA is needed to move the cursor. Even though it takes
a pointer to ev, that structure is not filled in when the call
succeeds. H_DELDATA only moves the cursor, it doesn't tell us
the new event number.
- Consequently, the second H_CURR is required to get ev.num filled
in. But it doesn't return the data because ev has no field for
that.
- So even though the cursor is already positioned correctly,
H_NEXT_EVDATA is needed as the final step merely to get the data.

(Ingo Schwarze)
 1.130 08-May-2016  christos In stiffle_history(), trim excessive entries from the history and advance
history_base like the GNU implementation does. (from Bastian Maerkisch)
 1.129 06-May-2016  christos fix logic (Ingo Schwarze)
 1.128 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.127 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.126 24-Feb-2016  christos Make the read_char function always take a wchar_t * argument (Ingo Schwarze)
 1.125 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.124 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.123 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.122 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.121 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.120 15-Feb-2016  christos attribute unused
 1.119 15-Feb-2016  christos OpenBSD readline.c rev. 1.14 2015/02/06 23:21:58 millert
use SIZE_MAX
 1.118 15-Feb-2016  christos OpenBSD readline.c rev. 1.13 2015/01/13 08:33:12 reyk
rl_set_keyboard_input_timeout() for readline 4.2 compat
 1.117 02-Jun-2015  christos Adjust API to a more modern readline (Ryo Onodera)
 1.116 26-May-2015  christos - fix types of rl_completion_entry_function and rl_add_defun
- call update pos before completion to refresh the screen
From Thomas Eriksson
 1.115 01-Apr-2015  christos Fix overlapping strcpy (Gerry Swislow)
 1.114 24-Mar-2015  christos set some readline compatibility default key settings.
https://bugzilla.redhat.com/attachment.cgi?id=1001895
 1.113 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.112 15-Aug-2014  christos Fix typo in comment (Tobias Stoeckmann)
 1.111 06-Jul-2014  christos branches: 1.111.2;
PR/48957: Federico G. Schwindt: Restore commented out code that broke
rl_callback_handler.
 1.110 21-Jan-2014  christos branches: 1.110.2;
... if called prior to using_history(). This needed to be worked around
in PHP: http://git.php.net/?p=php-src.git;a=commitdiff;h=31d67bd3

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1055409
 1.109 28-Aug-2013  christos get rid of PATH_MAX.
 1.108 28-May-2013  christos expose rl_catch_signals and explain what we are doing.
 1.107 13-Jan-2013  christos explicitly pass (void *)0 instead of NULL.
 1.106 12-Oct-2012  christos Add trailing NULL's to the varargs functions as required. (John Spencer)
 1.105 12-Jul-2012  christos branches: 1.105.2;
PR/46678: Ian Wienand: Add stub implementation for rl_free_line_state()
 1.104 05-Jun-2012  christos don't crash if add_history is called from an empty line. Called from
nslookup in new bind.
XXX: pullup to 6
 1.103 15-May-2012  christos define the new variable
 1.102 15-May-2012  christos Add rl_completion_word_break_hook from:
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/\
5ec6a45fa762b8cbd0305ca06acb8780335a486a
 1.101 21-Mar-2012  matt Use C89 functions definitions.
Remove use of __P
 1.100 18-Nov-2011  christos branches: 1.100.2;
Add missing *
 1.99 16-Aug-2011  christos branches: 1.99.2;
re-enable -Wconversion
 1.98 29-Jul-2011  christos pass -Wconversion
 1.97 29-Jul-2011  christos - fix unused params
- unconditionalize vis.h
 1.96 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.95 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.94 28-Jul-2011  christos handle systems without getpwent_r
 1.93 28-Jul-2011  christos use vis.h from .
 1.92 16-Sep-2010  christos unbreak readline history.
 1.91 28-Aug-2010  christos setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.
 1.90 04-Aug-2010  christos provide rl_on_newline
 1.89 15-Apr-2010  christos From Jess Thrysoee
- Fix wint_t to Int confusion
 1.88 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.87 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.86 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.85 07-Sep-2009  christos apply apple patches from:
http://opensource.apple.com/source/libedit/libedit-11/patches/
 1.84 22-Jul-2009  christos Fix memory leaks in error paths.
From Michael Cook mcook at bbn dot com
 1.83 08-Apr-2009  christos Fix off by one error reported by: Caleb Welton cwelton at greenplum dot com
 1.82 31-Mar-2009  christos implement RL_PROMPT_{START,END}_IGNORE
 1.81 21-Feb-2009  christos more size_t stuff.
 1.80 15-Feb-2009  christos pass lint on _LP64.
 1.79 12-Feb-2009  sketch More fixes for existing portability stuff.
 1.78 05-Feb-2009  christos branches: 1.78.2;
add rl_set_prompt
 1.77 18-Jan-2009  lukem fix -Wsign-compare issues
 1.76 11-Jan-2009  christos - insert a space after the recognized string if it was an exact match
- initialize properly the string used for completion.
From Alex Bligh alex at alex dot org dot uk
- Make char constants consistent
 1.75 29-Apr-2008  martin Convert to new 2 clause license
 1.74 05-Apr-2008  christos branches: 1.74.2;
add EL_REFRESH for the benefit of readline
 1.73 04-Apr-2008  christos Add rl_forced_update_display() from Gerry Swislow
 1.72 12-Aug-2007  christos patches from Axel Thimm
 1.71 27-May-2007  christos Add rl_completion_matches, fix remove_history
 1.70 24-Nov-2006  christos - Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.69 21-Aug-2006  christos Change to a 3 clause copyright after permission of the holders.
 1.68 23-Jul-2006  christos PR/34062: Tanaka Akira: rl_deprep_term_function is NULL in libedit.
Default to rl_deprep_terminal as suggested; do the same for
rl_prep_term_function
 1.67 25-Mar-2006  rtr remove if/free block checking known condition

coverity 2762 / run 11
 1.66 21-Mar-2006  christos Coverity CID 2743: Not really a memory leak, but make it obvious that we
always free tmp.
 1.65 18-Mar-2006  christos Lint comment.
 1.64 18-Mar-2006  christos Coverity CID 1666: Plug memory leak.
 1.63 18-Mar-2006  christos Coverity CID 1667: Plug memory leak
 1.62 18-Mar-2006  christos Coverity CID 1662: Memory leak.
 1.61 06-Mar-2006  christos use the tty chars for reprint and eof instead of hard-coded ^R and ^D
 1.60 13-Feb-2006  christos PR/32817: Magnus Svensson: write_history and read_history returncode is not
readline compatible.
 1.59 12-Feb-2006  christos Partial rl_getc_function support from Jess Thrysoee.
 1.58 14-Jul-2005  christos PR/30747: David N. Williams: libedit is missing remove_history()
Added, please test.
 1.57 11-Jun-2005  christos PR/30500: Paul Shupak: Inconsistent definition of tilde_expand().
Provide a layer of indirection between the readline compatibility functions
and our internal implementation, so that we have the freedom to change the
function signature.
 1.56 10-Jun-2005  christos Bug reported from Martin Dietze:

The place to change the completion_append_character is
usually somewhere in the `rl_completion_entry_function'
callback which is where one usually can distinguish between
file- or dir-like entries to append a slash for dirs etc.

This does no longer work since `fn_complete()' takes the
`append_character' as argument before the callback is executed,
so that changes to the variable `rl_completion_append_character'
have in fact no effect for the current completion.

Fix by adding a function that returns the rl_completion_append_character,
when it gets passed in a filename in readline emulation.
 1.55 27-May-2005  agc Use the correct type for the stored callback function
 1.54 27-May-2005  agc Sync the alternative readline interface with reality:

+ the rl_callback_handler_install takes a pointer to a void function
which has one char * argument (it's called that way in the readline
emulation source, otherwise there's no way to pass the line buffer
to the function which processes the line when EOL is encountered)

+ provide a prototype for that function signature and use it

Makes the callback readline interface work now.
 1.53 07-May-2005  dsl Separate out the filename completion functions from the readline() code.
Pass in loads of parameters instead of relying on shed-loads of global
variables to modify the behaviour.
The filename completion code can now be enabled by code that uses el_gets().
(eg /bin/sh)
 1.52 19-Apr-2005  christos check for pwd != NULL, fix a missed getpwnam.
 1.51 12-Apr-2005  christos PR/29958: Peter Bex: add rl_variable_bind and rl_attempted_completion_over
 1.50 02-Apr-2005  christos use getpwent_r
 1.49 10-Mar-2005  christos branches: 1.49.2;
Always update the position variables before the map function is called.
From Rob Rodgers, thanks!
 1.48 09-Mar-2005  christos set UNBUFFERED again after you do the line callback so that the new line
gets refreshed.
 1.47 08-Sep-2004  christos cut out the middle-man and use el_insertstr() directly.
 1.46 27-Feb-2004  christos Better fix for rl_prep_terminal() from Gerry Swislow.
 1.45 17-Jan-2004  christos portability fixes.
 1.44 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.43 03-Nov-2003  christos Fix uninitialized variable.
 1.42 02-Nov-2003  christos From: Gerry Swislow gerry at certif dot com

1) File name completion should list the files in the current directory
if no text is entered. The previous version wouldn't list anything if
the text to complete was empty.

2) When listing directories, the entries "." and ".." shouldn't be
shown.

3) The filename completion should be used if the user's
rl_attempted_completion_function doesn't return any matches. The
previous version didn't do that.
 1.41 01-Nov-2003  christos initialize ptr.
 1.40 27-Oct-2003  christos Make readline csh-like history work.
From Gerry Swislow <gerry at certif dot com>.
 1.39 19-Oct-2003  christos add rl_catch_signals
 1.38 16-Oct-2003  christos More libedit readline emulation functions from: Gerry Swislow
<gerry at certif dot com>
 1.37 15-Oct-2003  christos don't limit ^c to alpha c, and add VIS_NOSLASH so that vis(3) does not
produce \^c
 1.36 09-Oct-2003  christos PR/23107: Nathan Williams: ^D as the first char on the command line does
not DTRT in readline compatibility mode
 1.35 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.34 14-Sep-2003  christos Match the stupid function pointer declarations with actual readline's 4.0.
This is gross.
 1.33 14-Sep-2003  christos make this compile.
 1.32 14-Sep-2003  christos - provide enough hooks to compile gdb-5.3
- fix el_get(e, EL_TERMINAL, (char **))
 1.31 19-Jun-2003  christos From michael@moria.de:
Fix realloc case where we could be running out of space if too many matches.
 1.30 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.29 29-Mar-2003  wiz Consistently spell occurrence with two rs.
 1.28 10-Mar-2003  christos null is not 0
 1.27 10-Mar-2003  christos include alloca.h for systems that need it.
 1.26 21-Jan-2003  christos fix directory descriptor leak [from michael at moria dot de]
 1.25 27-Oct-2002  christos remove unused variables.
 1.24 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.23 27-Oct-2002  christos don't crash in memory shortage conditions.
 1.22 09-Apr-2002  thorpej _rl_qsort_string_compare(): Fix casts. This makes gcc 3.2 happy,
and also allows both LINTED comments to be removed.
 1.21 18-Mar-2002  christos Add a couple linted comment and enable WARNS=3
 1.20 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.19 10-Jan-2001  jdolecek fix partial completion - we failed to refresh screen in that case
 1.18 05-Jan-2001  christos depoison the pure editline code from readline compatibility hacks.
 1.17 05-Jan-2001  jdolecek Standard location of readline headers is /usr/include/readline/, so install
them there.
readline.h of libedit had to move to subdirectory 'readline', due to the way
BSD makefiles work; this is better than potentially fragile Makefile hacks
 1.16 04-Jan-2001  christos fix lint problems.
 1.15 01-Jan-2001  jdolecek Add support for rl_completion_append_character and rl_special_prefixes.
This addresses lib/10513 by Giles Lean. Tested with PostgreSQL 7.0.2 psql.
 1.14 01-Jan-2001  jdolecek history_tokenize(): fix one off-by-one bug
rl_complete_internal(): only replace the completed string with common part
of possible matches if there is a possible completion
 1.13 31-Dec-2000  jdolecek rl_display_match_list():
* pad entries shorter than 'max' by spaces correctly
* fix off-by-one error which caused extra newline to be printed
if the list fit exactly to a screen
* fix typo in _rl_qsort_string_compare, which caused the list to not
be sorted after all
 1.12 23-Dec-2000  jdolecek completion_matches(): fix a off-by-one bug, fix variable name typo
implement displaying of possible completions, add hook to display the list
on second rl_complete() invocation in row (typically, double <TAB>)

This addresses the completion part of lib/11581 by Richard Earnshaw.
 1.11 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.10 10-Mar-2000  jdolecek Fix _rl_compat_sub() to really honour 'globally' flag instead
of making the substitution always globally - affects
_history_expand_command() and in turn history_expand()

All praise lint :)
 1.9 10-Mar-2000  jdolecek readline(): don't dereference NULL pointer if prompt is NULL
history_tokenize(): avoid stepping too far if backslash is last character
on the passed string
update some comments

This makes gdb \ escaping work reliably and fixes lib/9511 by Assar Westerlund.
 1.8 03-Jul-1999  lukem don't try to free() something allocated with alloca() in rl_complete_internal().
(noticed while using completion in gdb and getting inundated with warnings from
the new free())
 1.7 02-Jul-1999  simonb More trailing white space.
 1.6 12-Jun-1999  christos Make this compile under linux
 1.5 12-Dec-1998  christos many problems; variables hidden by others, size_t <-> confusion
 1.4 20-May-1998  christos Adjust to the libedit api changes.
 1.3 12-Nov-1997  thorpej el_gets() takes an int *, not a size_t *.
 1.2 23-Oct-1997  christos Const de-poisoning :-( Unfortunately the default gnu readline does not
have full prototypes... With those changes, and a single line change in
gdb/top.c, gdb links with -ledit
 1.1 23-Oct-1997  christos PR/4301: Jaromir Dolecek. Add gnu-readline wrapper for editline.
 1.49.2.4 12-Jul-2005  tron Pull up revision 1.52 (requested by lukem in ticket #542):
check for pwd != NULL, fix a missed getpwnam.
 1.49.2.3 12-Jul-2005  tron Pull up revision 1.50 (requested by lukem in ticket #542):
use getpwent_r
 1.49.2.2 28-May-2005  tron Pull up revision 1.55 (requested by agc in ticket #353):
Use the correct type for the stored callback function
 1.49.2.1 28-May-2005  tron Pull up revision 1.54 (requested by agc in ticket #353):
Sync the alternative readline interface with reality:
+ the rl_callback_handler_install takes a pointer to a void function
which has one char * argument (it's called that way in the readline
emulation source, otherwise there's no way to pass the line buffer
to the function which processes the line when EOL is encountered)
+ provide a prototype for that function signature and use it
Makes the callback readline interface work now.
 1.74.2.1 18-May-2008  yamt sync with head.
 1.78.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.99.2.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.99.2.4 23-Jan-2013  yamt sync with head
 1.99.2.3 30-Oct-2012  yamt sync with head
 1.99.2.2 23-May-2012  yamt sync with head.
 1.99.2.1 17-Apr-2012  yamt sync with head
 1.100.2.1 05-Jun-2012  bouyer Pull up following revision(s) (requested by christos in ticket #309):
lib/libedit/readline.c: revision 1.104
don't crash if add_history is called from an empty line. Called from
nslookup in new bind.
XXX: pullup to 6
 1.105.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.105.2.3 23-Jun-2013  tls resync from head
 1.105.2.2 25-Feb-2013  tls resync with head
 1.105.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.110.2.1 10-Aug-2014  tls Rebase.
 1.111.2.1 13-May-2015  martin Sync lib/libedit with head, requested by christos in #753:

lib/libedit/Makefile 1.53
lib/libedit/chartype.h 1.13
lib/libedit/editline.3 1.83-1.84
lib/libedit/editrc.5 1.28-1.29
lib/libedit/eln.c 1.18
lib/libedit/filecomplete.c 1.33-1.34
lib/libedit/readline.c 1.112-1.115

Man page improvements, fix overlapping strcpy, improve readline
compatibility, clang build fix.
 1.136.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.136.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.136.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.140.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.146.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.146.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.146.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.147.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.147.2.1 10-Jun-2019  christos Sync with HEAD
 1.182.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 05-Jan-2001  jdolecek Standard location of readline headers is /usr/include/readline/, so install
them there.
readline.h of libedit had to move to subdirectory 'readline', due to the way
BSD makefiles work; this is better than potentially fragile Makefile hacks
 1.5 01-Jan-2001  jdolecek Add support for rl_completion_append_character and rl_special_prefixes.
This addresses lib/10513 by Giles Lean. Tested with PostgreSQL 7.0.2 psql.
 1.4 23-Dec-2000  jdolecek completion_matches(): fix a off-by-one bug, fix variable name typo
implement displaying of possible completions, add hook to display the list
on second rl_complete() invocation in row (typically, double <TAB>)

This addresses the completion part of lib/11581 by Richard Earnshaw.
 1.3 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.2 23-Oct-1997  christos Const de-poisoning :-( Unfortunately the default gnu readline does not
have full prototypes... With those changes, and a single line change in
gdb/top.c, gdb links with -ledit
 1.1 23-Oct-1997  christos PR/4301: Jaromir Dolecek. Add gnu-readline wrapper for editline.
 1.60 05-Dec-2024  christos Don't eat 0 width characters, print them.
 1.59 30-Jun-2024  christos Handle the case where the cursor is on the first character.
set -o vi
x ESC ~
(Robert Morris)
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279545
 1.58 09-Sep-2021  christos branches: 1.58.4;
Add casts to appease conversions between wchar_t and wint_t
 1.57 30-Mar-2020  ryo fix build error with SDEBUG, MAP_DEBUG, DEBUG_REFRESH
 1.56 04-Jan-2019  uwe Fix mis-applied change in previous. Don't increment r_oldcv twice.
PR lib/53803
 1.55 23-Oct-2018  christos Apply revisions 1.21, 1.22 from OpenBSD:

In re_fastputc(), set lastline to the new line, not the previous
line so it gets initialized properly. Fixes a crash in bc with
MALLOC_OPTIONS=UJ. OK deraadt@, committing on behalf of yasuoka@

Initialize "old" screen buffer lines before use; otherwise, they would
never get NUL-terminated and cause read buffer overruns.
This fixes for example segfaults in sftp(1) that could be triggered
by typing in an extremely long string (more than one line - the longer,
the likelier to crash), then hitting backspace once.
Problem reported and patch OK'ed by sthen@.

XXX: pullup-8
 1.54 30-Jun-2017  kre branches: 1.54.4; 1.54.6;

Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)

Note: this has currently only been tested with everything ascii (C locale).
 1.53 27-Jun-2017  christos fix comment
 1.52 27-Jun-2017  christos - add literal sequence handling.
 1.51 09-May-2016  christos branches: 1.51.8;
s/protected/libedit_private/g
 1.50 02-May-2016  christos fix typos from Pedro Giffuni @FreeBSD
 1.49 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.48 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.47 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.46 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.45 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.44 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.43 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.42 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.41 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.40 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.39 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.38 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.37 29-Jul-2011  christos pass -Wconversion
 1.36 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.35 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.34 28-Dec-2009  christos reduce diff with tcsh
 1.33 28-Dec-2009  christos Fix bug where tab completion on the second or > line that caused listing
ended up corrupting the display by an extra space in the beginning. Reported
by Mac Chan.
 1.32 17-Jul-2009  christos Simplify the code. No functional change.
 1.31 19-May-2009  christos always scroll when we advance past bottom. From Caleb Welton
cwelton at greenplum dot com
 1.30 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.29 15-Feb-2009  christos pass lint on _LP64.
 1.28 10-Sep-2008  christos branches: 1.28.6;
Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.27 09-Nov-2005  christos branches: 1.27.20;
Refresh bug reported by Julien Torres:

going from:
activate -verbose
to:
reset -activation
results in:
reset -activationverbose"
instead of:
reset -activation

This is because we choose to insert "reset -" before the current line,
and the delete "e -" and insert "ion" in the appropriate place. The
cleareol code did not handle this case properly; we now cleareol to
the maximum number of characters of the first difference, the second
difference and the difference in line length.
 1.26 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.25 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.24 10-Mar-2003  christos s/u_int32_t/unsigned int/
 1.23 15-Nov-2002  christos de-lint
 1.22 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.21 12-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.20 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.19 27-Oct-2002  christos PR/17954: SAITOH Masanobu: since we have opost and onlcr set, we don't need
to output \r to go to the end of line; \n is enough. From David Laight.
 1.18 18-Mar-2002  christos branches: 1.18.2;
- constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.17 13-Apr-2001  lukem rename 3 arg ELRE_DEBUG to ELRE_ASSERT, add 2 arg ELRE_DEBUG, and change all
occurences of ELRE_DEBUG(foo,bar,) -> ELRE_DEBUG(foo,bar). some compilers
(e.g, gcc on darwin) bitch about the former (`not enough args').
 1.16 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.15 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.14 13-Mar-2000  soren branches: 1.14.4;
Fix doubled 'the's.
 1.13 19-Feb-2000  mycroft Fix refresh glitches when using auto-margin.
 1.12 20-Jan-2000  christos Add support for automatic and magic margins (from tcsh)
This makes the rightmost column usable on all programs
that use editline.
 1.11 13-Nov-1999  lukem instead of using a private coord_t global variable to store the size of the
rprompt, use the previously unused coord_t el->el_rprompt.p_pos
 1.10 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.9 15-Oct-1999  jdolecek don't assume locales are not working - it may not be the case
re_refresh(): cast the character passed to re_addc() to unsigned char,
so we don't end up calling isprint() with negative value
when chars are signed and character value is >= 128
 1.8 02-Jul-1999  simonb branches: 1.8.2;
More trailing white space.
 1.7 12-Jun-1999  christos Make this compile under linux
 1.6 05-Feb-1999  christos delint.
 1.5 12-Dec-1998  christos delint
 1.4 20-May-1998  christos cast is*() arg to unsigned char
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.8.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.14.4.1 15-Mar-2003  he Pull up revision 1.19 (via patch, requested by msaitoh in ticket #14):
Since we have opost and onlcr set, we don't need to output \r;
\n is sufficient. Fixes PR#17954.
 1.18.2.1 05-Jan-2003  jmc Pull up revisions 1.18-1.19 (requested by masanobu in ticket #1048)
PR/17954: SAITOH Masanobu: since we have opost and onlcr set, we don't need
to output \r to go to the end of line; \n is enough. From David Laight.
 1.27.20.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.28.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.51.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.54.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.54.6.1 10-Jun-2019  christos Sync with HEAD
 1.54.4.2 18-Jan-2019  pgoyette Synch with HEAD
 1.54.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.58.4.2 02-Aug-2025  perseant Sync with HEAD
 1.58.4.1 01-Jul-2024  perseant Sync with HEAD.
 1.11 27-Jun-2017  christos - add literal sequence handling.
 1.10 09-May-2016  christos branches: 1.10.8;
s/protected/libedit_private/g
 1.9 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.8 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.7 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.6 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.4 10-Jan-2001  jdolecek Enlarge editline buffers as needed to support arbitrary length lines.
This also addresses lib/9712 by Phil Nelson.
 1.3 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.10.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.52 30-Jun-2024  christos Prevent reading before the line buffer (try ^R^W in emacs mode at the
beginning of the line) (Robert Morris)
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=279426
 1.51 30-Mar-2020  ryo branches: 1.51.8;
patbuf must be updated if the length of patbuf is greater than or equal to 0. (that is always)
fix of r1.7 was incorrect.
 1.50 30-Mar-2020  ryo fix build error with SDEBUG, MAP_DEBUG, DEBUG_REFRESH
 1.49 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.48 26-Feb-2018  christos branches: 1.48.4;
PR/53058: Nikhil Benesch: use correctly typed variables (wchar_t vs wint_t)
as parameters.
 1.47 09-May-2016  christos s/protected/libedit_private/g
 1.46 28-Apr-2016  christos Initialize patbuf (Ingo Schwarze)
 1.45 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.44 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.43 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.42 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.41 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.40 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.39 24-Feb-2016  christos Get split el_getc and el_wgetc completely and call el_wgetc internally.
Change some character constants to they wide versions. (Ingo Schwarze)
 1.38 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.37 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.36 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.35 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.34 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.33 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.32 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.31 30-Jan-2016  christos Fix misplaced parentheses (Ingo Schwarze)
 1.30 04-Oct-2011  christos fixed warnings where wint_t is unsigned.
 1.29 16-Aug-2011  christos re-enable -Wconversion
 1.28 29-Jul-2011  christos pass -Wconversion
 1.27 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.26 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.25 28-Jul-2011  christos term -> terminal
 1.24 15-Apr-2010  christos From Jess Thrysoee
- Fix wint_t to Int confusion
 1.23 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.22 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.21 15-Feb-2009  christos pass lint on _LP64.
 1.20 04-Nov-2004  christos branches: 1.20.34;
Make EM_DELETE_PREV_CHAR behave like ED_DELETE_PREV_CHAR in incremental
search. From Gerry Swislow.
 1.19 25-Oct-2003  christos Another fix for incremental search prev.
 1.18 18-Oct-2003  christos make forward incremental search work better.
 1.17 17-Oct-2003  christos When searching backwards don't include the characters after the cursor in
the search.
 1.16 16-Oct-2003  christos Fix incremental search which was badly busted.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.14 20-Nov-2002  christos Fix problem with previous patches that broke vi history.
- c_gets() was usually returning a length, but sometimes
one of the CC_xxx values (which are small +ve integers)!
- fixed c_gets() by putting a ' ' under the cursor.
From David Laight.
 1.13 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.12 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.11 23-Jan-2001  jdolecek sprinkle couple const
 1.10 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.9 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.8 02-Jul-1999  simonb More trailing white space.
 1.7 05-Feb-1999  christos delint.
 1.6 02-Sep-1998  christos PR/6081: Wolfgang Helbig: search broken in vi mode. When patbuf was changed
to be dynamically allocated, sizeof was not changed appropriately.
 1.5 06-Jul-1997  christos Fix compiler warnings.
 1.4 23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 02-Oct-1994  jtc Added code so that POSIX.2 regular expresion functions are used if REGEX
is defined, V8 regular expresion functions are used if REGEXP is defined,
and BSD regular expression functions are used if neither are defined.
And defined REGEX in sys.h so that programs using libedit don't have
to link with libcompat.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd branches: 1.1.1.1.2;
libedit!
 1.1.1.1.2.1 07-Oct-1994  mycroft Update from trunk.
 1.20.34.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.48.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.48.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51.8.1 01-Jul-2024  perseant Sync with HEAD.
 1.14 09-May-2016  christos s/protected/libedit_private/g
 1.13 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.12 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.11 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.10 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.9 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.8 18-Oct-2003  christos make forward incremental search work better.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.6 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.5 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.4 02-Jul-1999  simonb More trailing white space.
 1.3 12-Dec-1998  christos delint
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.19 22-Jan-2013  christos provide an el_init_fd function.
 1.18 11-Jan-2009  christos branches: 1.18.8; 1.18.14;
bump shared libraries.
 1.17 05-Apr-2008  christos bump minor.
 1.16 24-Nov-2006  christos - Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.15 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.14 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.13 14-Sep-2003  christos - provide enough hooks to compile gdb-5.3
- fix el_get(e, EL_TERMINAL, (char **))
 1.12 09-Oct-2001  christos PR/14188: Anthony Mallet: Provide an opaque data pointer to client programs.
 1.11 01-Jan-2001  jdolecek bump libedit minor - addition of rl_special_prefixes and rl_completion_append_character
 1.10 23-Dec-2000  jdolecek bump libedit minor - added some public stuff for readline emulation
 1.9 12-Nov-1999  lukem - implement printing a right-side prompt. code derived from similar work
I wrote for tcsh(1) three years ago.
- implement EL_RPROMPT, which allows a setting/getting of a function which
returns a string to be used as the right-side prompt.
- improve HISTORY and AUTHORS sections in editline(3).
- bump shlib minor version for EL_RPROMPT.

XXX: due to an implementation issue, the rprompt has a 1 space gap before the
edge of the logical screen. editline's logical screen is 1 space less
than the full screen width, so there's a 2 space gap between the rprompt
and the right end of the physical screen. i'm not concerned about this.
 1.8 25-Feb-1999  abs branches: 1.8.6;
Add a note to update src/distrib/sets/lists/base/shl.*, and add a missing
RCS Id.
 1.7 29-Jul-1998  lukem * add more checks for NULL pointers in passed arguments
* implement el_get(EditLine *, int op, void *result), which does the
inverse of el_set()
* add EL_EDITMODE operation to el_set and el_get; if non zero editing
is enabled (the default).
* add "edit on | off" editrc command, which modifies EL_EDITMODE.
users can now add '*:edit off' in ~/.editrc as an advisory to
disable editing.

NOTE: at this time EL_EDITMODE is just an indication of the
state of the 'edit' command. It's up to the application to check
this after el_source() or el_parse() to determine if editing is still
required.
 1.6 01-Jun-1998  lukem * implement CC_REFRESH_BEEP; as per CC_REFRESH but beep as well. this
is useful in completion when a partial completion is found
* remove entry in BUGS about el_parse(); that was fixed a while ago
 1.5 20-May-1998  christos Bump!
 1.4 05-Jan-1998  perry RCSID Police.
 1.3 23-Oct-1997  christos PR/4301: Jaromir Dolecek. Add gnu-readline wrapper for editline.
 1.2 14-Oct-1997  christos PR/4257: Jaromir Dolecek: history() has no generic error handling and isn't
reentrant. This changes the interface of the history function, so we need
a major number bump.
 1.1 06-May-1994  cgd local
 1.8.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.14.1 25-Feb-2013  tls resync with head
 1.18.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.29 14-Jun-2025  christos Change kill(0, signo) -> raise(signo) so that we only signal the current
process not the whole process group. Pointed out by geoff thomas. Related
issues:
https://www.postgresql.org/message-id/271520.1713052173%40sss.pgh.pa.us
https://github.com/astral-sh/python-build-standalone/pull/652\
#issuecomment-2972762033
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=159226
 1.28 18-Dec-2024  christos From tkoeppe@github: Specify SA_ONSTACK when setting up a signal
handler. This allows the handler to use the alternate signal stack
if one is available in the handling thread, but has no effect
otherwise.

This change makes the signal handler respect existing choices
better. Specifically, this allows signal handlers to be set when
the process includes a Go runtime, since Go enforces that all signal
handlers in the process use the SA_ONSTACK flag (e.g. see
golang/go#20400).
 1.27 03-Feb-2023  christos branches: 1.27.2;
Don't clear the handle to el "sel" and set it earlier to prevent handling
a signal before the handle is set. (From: des at FreeBSD)
 1.26 09-May-2016  christos s/protected/libedit_private/g
 1.25 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.24 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.23 16-Feb-2016  christos include errno.h
 1.22 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.21 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.20 16-Feb-2016  christos one more
 1.19 16-Feb-2016  christos include explicitly errno.h since we use it.
 1.18 15-Feb-2016  christos OpenBSD sig.c rev. 1.6 2001/12/06 04:26:00 deraadt
save and restore errno in signal handler
 1.17 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.16 28-Jul-2011  christos term -> terminal
 1.15 19-Feb-2009  christos reset and redraw on sigcont. From Anon Ymous.
 1.14 18-Feb-2009  christos SA_RESTART for all signals but SIGINT. From Anon Ymous.
 1.13 15-Feb-2009  christos in order for read() to return EINTR we need to use sigaction, not signal,
otherwise SA_RESTART is set.
 1.12 10-Sep-2008  christos branches: 1.12.6;
Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.11 07-Aug-2003  agc branches: 1.11.32;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.10 10-Mar-2003  christos sig_t is non portable
 1.9 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.8 09-Jan-2001  jdolecek make constant arrays a const
 1.7 04-Jan-2001  christos fix dumb typo in signal setup [from OpenBSD]
return -1 if alloc fails.
 1.6 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.5 02-Jul-1999  simonb More trailing white space.
 1.4 06-Jul-1997  christos Fix compiler warnings.
 1.3 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.11.32.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.12.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.27.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 09-May-2016  christos s/protected/libedit_private/g
 1.10 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.9 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.8 19-Feb-2009  christos reset and redraw on sigcont. From Anon Ymous.
 1.7 15-Feb-2009  christos in order for read() to return EINTR we need to use sigaction, not signal,
otherwise SA_RESTART is set.
 1.6 12-Jul-2008  christos branches: 1.6.6;
Don't bother with SIGSTOP it cannot be caught or ignored. From Jess Thrysoee
 1.5 07-Aug-2003  agc branches: 1.5.32;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.4 10-Mar-2003  christos sig_t is non portable
 1.3 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.5.32.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.29 25-Apr-2023  christos pass lint.
 1.28 04-Feb-2023  christos Remove unused stuff, and limit the scope of some of the used ones.
(from des@freebsd)
 1.27 09-May-2016  christos s/protected/libedit_private/g
 1.26 09-May-2016  christos Instead of compiling all the source files together in one big file, use
protected visibility to achieve the same effect.
 1.25 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.24 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.23 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.22 16-Feb-2016  christos - don't set _GNU_SOURCE. We are not supposed to make decisions for others.
- don't special-case wcsdup()
From Ingo Schwarze.
 1.21 15-Feb-2016  christos OpenBSD readline.c rev. 1.14 2015/02/06 23:21:58 millert
use SIZE_MAX
 1.20 15-Feb-2016  christos forgot one fgetln define
 1.19 15-Feb-2016  christos change tests for fgetln.
 1.18 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.17 28-Sep-2011  christos include <wchar.h> if we don't have wcsdup()
 1.16 29-Jul-2011  christos kill ifdef notdef
 1.15 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.14 28-Jul-2011  christos more portability defines
 1.13 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.12 31-Aug-2009  christos delete defined(sun), it could be invaded in the user namespace. Suggested
by mrg@
 1.11 30-Aug-2009  christos use __sun || sun instead of _SunOS, from Jess Thrysoee
 1.10 06-Feb-2009  sketch SUNOS is spelt __SunOS. Add missing prototypes.
 1.9 17-Jan-2004  christos portability fixes.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.7 19-Jun-2003  christos provide a definition for __attribute__
 1.6 10-Mar-2003  christos - include cdefs.h early in the game
- ifdef notdef the sunos stuff
- no need for sig_t
 1.5 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.4 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 02-Oct-1994  jtc Added code so that POSIX.2 regular expresion functions are used if REGEX
is defined, V8 regular expresion functions are used if REGEXP is defined,
and BSD regular expression functions are used if neither are defined.
And defined REGEX in sys.h so that programs using libedit don't have
to link with libcompat.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd branches: 1.1.1.1.2;
libedit!
 1.1.1.1.2.1 07-Oct-1994  mycroft Update from trunk.
 1.58 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.57 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.56 28-Dec-2009  christos Reduce diff with tcsh's editor. No functional change intended.
 1.55 31-Aug-2009  christos delete defined(sun), it could be invaded in the user namespace. Suggested
by mrg@
 1.54 30-Aug-2009  christos use __sun || sun instead of _SunOS, from Jess Thrysoee
 1.53 17-Jul-2009  christos - off by one in the term.h case.
- make code more similar to tcsh (if we want to handle wide chars, this is
needed; for now it is a no-op)
 1.52 31-Mar-2009  christos cast to size_t to avoid sign / unsigned comparison warning.
 1.51 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.50 15-Feb-2009  christos pass lint on _LP64.
 1.49 12-Feb-2009  sketch More fixes for existing portability stuff.
 1.48 06-Feb-2009  sketch branches: 1.48.2;
SUNOS is spelt __SunOS. Add missing prototypes.
 1.47 10-Sep-2008  christos Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.46 24-Nov-2006  christos branches: 1.46.18;
- Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.45 18-Mar-2006  christos Fix compilation.
 1.44 18-Mar-2006  christos Coverity CID 1668: Plug memory leak.
 1.43 18-Mar-2006  christos Coverity CID 806: Prevent NULL deref
 1.42 06-Mar-2006  christos Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.41 08-Aug-2005  christos Spelling mistakes and comment errors (from FreeBSD via Stefan Farfeleder; many
thanks)
 1.40 22-May-2004  christos branches: 1.40.2;
fix memory leak; thanks to Logan Gabriel
 1.39 17-Jan-2004  christos portability fixes.
 1.38 14-Sep-2003  christos - provide enough hooks to compile gdb-5.3
- fix el_get(e, EL_TERMINAL, (char **))
 1.37 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.36 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.35 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.34 08-Nov-2001  mycroft In the `not what I asked for' department:
Do NOT return an error from term_init() if term_set() fails. Otherwise
el_init() barfs and libedit fails to work.
 1.33 02-Nov-2001  christos Finish initializing all the term data structures even if the terminal init
fails. This makes editline work on dumb terminals again. Noted by mycroft.
Oops, too agressive error checking.
 1.32 23-Jan-2001  jdolecek sprinkle couple const
 1.31 10-Jan-2001  jdolecek term_rebuffer_display(): set el->el_term.t_size.v to terminals
height, not a magic value, so that e.g. el_display[] and el_vdisplay[]
are not bigger than needed.
Discussed with Christos Zoulas.
 1.30 09-Jan-2001  jdolecek term_beep(): use ordinary bell, don't attempt to use visual bell - if user wants
visual instead of ordinary bell, they should set their environment
appropriately
 1.29 09-Jan-2001  jdolecek make constant arrays a const
 1.28 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.27 30-Dec-2000  jdolecek term_beep(): if terminal supports both visual and ordinary bell, 'ring' both
 1.26 28-Nov-2000  jmc Alloc the keys structure with A_K_NKEYS as the multiplier rather than a
hardcoded value of 4.

A_K_NKEYS is currently 6 and this mismatch was stomping memory when
initializing the keys. (specifically gdb lost the exec file name if it was
a long path name).
 1.25 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.24 04-Oct-2000  sommerfeld format string audit (silence warnings, save space)
 1.23 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.22 02-Jun-2000  lukem use strtol() (instead of atoi()) for sane error detection
 1.21 19-Feb-2000  mycroft branches: 1.21.2;
Fix refresh glitches when using auto-margin.
 1.20 20-Jan-2000  christos Add support for automatic and magic margins (from tcsh)
This makes the rightmost column usable on all programs
that use editline.
 1.19 24-Oct-1999  lukem Fix pointer arithmatic (caused problems on LP64, including ftp dumping
core when `edit' was turned off then on).
Problem solved by David Huggins-Daines <dhd@eradicator.org>
 1.18 04-Oct-1999  lukem update post change to return value of tputs() third argument
 1.17 02-Aug-1999  sommerfeld branches: 1.17.2;
Fix PR7685 (gdb under emacs prints spurious ^M and messes up terminal)
plus a few bogons noted along the way:
1) Set EDIT_DISABLED if terminal type is emacs.
2) fix bug in NO_TTY mode which caused it to not notice CR or LF
3) implement EDIT_DISABLED within libedit to be somewhat like NO_TTY,
except that a prompt is printed first.
 1.16 02-Jul-1999  simonb More trailing white space.
 1.15 12-Dec-1998  christos delint
 1.14 20-May-1998  christos remove term_beep hack.
 1.13 30-Jan-1998  perry update to lite-2 (just an sccsid change)
 1.12 13-Nov-1997  thorpej Un-"protect" term_beep() and rename it to __term_beep() to keep it out
of the user's namespace. We need to do this because the readline
emulation functions call term_beep(), but readline isn't built using
the same (funky) namespace-protection method as the rest of libedit (it's
included like a normal library object).

Without this (fairly disgusting) hack, any program linked against
libedit will fail to link with an unresolved reference to term_beep()
if using an Elf toolchain (e.g. on the Alpha).

XXX Why this doesn't happen with NetBSD's a.out toolchain is a mystery
XXX to me, and I'm not sure I really want to know (given that a.out
XXX _should_ break the same way as Elf does in this case).
 1.11 13-Oct-1997  lukem use <termcap.h> instead of "termcap.h" (which was repository copied to libterm)
 1.10 06-Jul-1997  christos Fix compiler warnings.
 1.9 11-Apr-1997  christos Return -1 if the terminal set operation resulted in dumb terminal settings.
 1.8 23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.7 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.6 29-Apr-1995  christos Fixed the key mapping code and reverted Charles' changes.
 1.5 27-Apr-1995  mycroft Remove dead code that can't possibly work.
 1.4 07-Oct-1994  mycroft Fix typo.
 1.3 02-Oct-1994  mycroft Don't even *try* to print out the name of the termcap file; it's hidden
in libtermcap, and it normally uses the DB file anyway.
 1.2 02-Oct-1994  mycroft Nuke bogus baud rate conversion code.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 30-Jan-1998  perry import lite-2
 1.1.1.1 06-May-1994  cgd branches: 1.1.1.1.2;
libedit!
 1.1.1.1.2.1 07-Oct-1994  mycroft Update from trunk.
 1.17.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.2.1 23-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.40.2.1 23-Apr-2009  snj Apply patch (requested by msaitoh in ticket #2007):
Coverity CID 1668: Plug memory leak when malloc() failed.
 1.46.18.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.48.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.21 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.20 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.19 10-Sep-2008  christos branches: 1.19.6;
Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.18 24-Nov-2006  christos branches: 1.18.18;
- Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.17 06-Mar-2006  christos Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.16 15-Mar-2005  christos Add missing define, needed for debugging (from Rob Rodgers)
 1.15 14-Sep-2003  christos - provide enough hooks to compile gdb-5.3
- fix el_get(e, EL_TERMINAL, (char **))
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.13 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.12 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.11 11-Nov-2000  christos - add support for home and end keys.
- improve debugging support
 1.10 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.9 20-Jan-2000  christos Add support for automatic and magic margins (from tcsh)
This makes the rightmost column usable on all programs
that use editline.
 1.8 04-Oct-1999  lukem update post change to return value of tputs() third argument
 1.7 02-Jul-1999  simonb branches: 1.7.2;
More trailing white space.
 1.6 20-May-1998  christos remove term_beep hack.
 1.5 13-Nov-1997  thorpej Un-"protect" term_beep() and rename it to __term_beep() to keep it out
of the user's namespace. We need to do this because the readline
emulation functions call term_beep(), but readline isn't built using
the same (funky) namespace-protection method as the rest of libedit (it's
included like a normal library object).

Without this (fairly disgusting) hack, any program linked against
libedit will fail to link with an unresolved reference to term_beep()
if using an Elf toolchain (e.g. on the Alpha).

XXX Why this doesn't happen with NetBSD's a.out toolchain is a mystery
XXX to me, and I'm not sure I really want to know (given that a.out
XXX _should_ break the same way as Elf does in this case).
 1.4 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.3 29-Apr-1995  christos Fixed the key mapping code and reverted Charles' changes.
 1.2 27-Apr-1995  mycroft Remove dead code that can't possibly work.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.7.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.18.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.19.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.3 13-Oct-1997  mrg termcap.h moves to libterm.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.46 04-Feb-2023  christos Remove unused stuff, and limit the scope of some of the used ones.
(from des@freebsd)
 1.45 30-Oct-2022  christos improvements in malloc/free handling.
 1.44 09-Sep-2021  christos Add casts to appease conversions between wchar_t and wint_t
 1.43 10-Jul-2020  christos Fix numeric variable handling in settc (lyzliyuzhi at 163 dot com)
 1.42 31-May-2020  christos use strlcpy() instead of strncpy() for gcc happiness
 1.41 12-Nov-2019  christos PR/54654: Soren Tempel: Make sure el_cursor.v < el_terminal.t_size.v when
moving around.
 1.40 15-Sep-2019  christos Fix type and remove cast (Yuichiro NAITO/FreeBSD).
 1.39 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.38 30-Jun-2019  christos Add a comment explaining why we don't use DO here. Correct the attribution
on the previous patch: The patch was from Jordan Lewis and the report from
Raphael Poss.
 1.37 29-Jun-2019  christos PR/54329: Raphael Ross: According to https://www.gnu.org/software/termutils/\
manual/termcap-1.3/html_chapter/termcap_4.html#SEC23 the cursor move multiple
escapes have undefined results when moving out of the screen. Stop using DO
to move down multiple lines and use a loop of newlines instead.
 1.36 12-Apr-2019  christos PR/52359: Benjamin Lorenz: When resizing because of a signal save and restore
the cursor position, since it does not change.
 1.35 15-Feb-2019  christos PR/53983: Jonathan Perkins: Fix types for readline compatibility
 1.34 24-Nov-2018  christos PR/53682: Jordan Lewis: use newlines instead of padded spaces when restoring
multi-line histories.
 1.33 27-Jun-2017  christos branches: 1.33.4; 1.33.6;
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
 1.32 09-May-2016  christos branches: 1.32.8;
s/protected/libedit_private/g
 1.31 02-May-2016  christos eliminate static buffer with custom resizing code.
 1.30 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.29 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.28 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.27 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.26 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.25 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.24 22-Mar-2016  christos put back NUL check (Ingo Schwarze)
 1.23 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.22 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.21 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.20 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.19 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.18 15-Feb-2016  christos OpenBSD term.c rev. 1.7 2002/11/29 20:13:39 deraadt
spelling
 1.17 15-Feb-2016  christos OpenBSD term.c rev. 1.13 2009/12/11 18:58:59 jacekm
fix two memory leaks
 1.16 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.15 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.14 30-May-2012  christos don't include both term.h and termcap.h
 1.13 24-Mar-2012  christos From: Jilles Tjoelker: Add a mapping for the cursor delete key
 1.12 18-Nov-2011  christos Initialize termbuf (Kamil Dudka)
 1.11 18-Nov-2011  christos check for negative return of ct_visual_char (Kamil Dudka)
 1.10 04-Oct-2011  christos branches: 1.10.2;

fixed warnings where wint_t is unsigned.
 1.9 03-Oct-2011  christos fix broken change (parenthesis in the wrong place). From Nirbhay Choubey
 1.8 16-Aug-2011  christos re-enable -Wconversion
 1.7 29-Jul-2011  christos pass -Wconversion
 1.6 29-Jul-2011  christos kill ifdef notdef
 1.5 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.4 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.3 28-Jul-2011  christos whitespace
 1.2 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.1 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.10.2.2 30-Oct-2012  yamt sync with head
 1.10.2.1 17-Apr-2012  yamt sync with head
 1.32.8.1 23-Jul-2017  snj Pull up following revision(s) (requested by kre in ticket #102):
lib/libedit/Makefile: 1.64-1.65
lib/libedit/editline.3: 1.94-1.96
lib/libedit/editrc.5: 1.33
lib/libedit/el.c: 1.93-1.94
lib/libedit/el.h: 1.42
lib/libedit/literal.c: 1.1-1.3
lib/libedit/literal.h: 1.1-1.2
lib/libedit/prompt.c: 1.27
lib/libedit/read.c: 1.103
lib/libedit/refresh.c: 1.52-1.54
lib/libedit/refresh.h: 1.11
lib/libedit/terminal.c: 1.33
Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise. Better support for this in sh coming.
--
Include EDITRC in doc.
--
mention the limitation of the literal sequence delimiter.
--
- handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
--
- add literal sequence handling.
--
remove unused variable
--
add literal escape sequence support, patterned after the tcsh ones.
--
fix comment
--
Fix an obvious, but almost invisible typo (avoid some core dumps).
--
Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
to be (perhaps part of) the "invisible" characters in a prompt, or the
required prompt character which follows the literal sequence (this character
must be one with a printing column width >= 1). The literal indicator
character (which is just a marker, and not printed anywhere) (the PSlit
parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t,
encoded as that by sh(1) or other applications that support this.)
Note: this has currently only been tested with everything ascii (C locale).
--
Remove workaround for ancient HTML generation code.
 1.33.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.33.6.1 10-Jun-2019  christos Sync with HEAD
 1.33.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.9 09-May-2016  christos s/protected/libedit_private/g
 1.8 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.7 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.6 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.5 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.4 24-Mar-2012  christos From: Jilles Tjoelker: Add a mapping for the cursor delete key
 1.3 29-Jul-2011  christos branches: 1.3.2;
pass -Wconversion
 1.2 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.1 28-Jul-2011  christos term -> terminal
XXX: need to rename key_ too.
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.29 30-May-2023  christos Fix some const qual (Piotr Pawel Stefaniak)
 1.28 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.27 11-Apr-2016  christos chartype cleanups from Ingo Schwarze:

- The file tokenizer.c no longer uses chartype.h,
so don't include the header.

- The dummy definitions of ct_{de,en}code_string() for the
NARROWCHAR case are only used in history.c, so move them there.

- Now the whole content of chartype.h is for the wide character
case only. So remove the NARROWCHAR ifdef and include the
header only in the wide character case.

- In chartype.h, move ct_encode_char() below the comment explaining it.

- No more need for underscores before ct_{de,en}code_string().

- Make the conversion buffer resize functions private.
They are only called from the decoding and encoding functions
inside chartype.c, and no need can possibly arise to call them
from anywhere else.
 1.26 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.25 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.24 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.23 15-Feb-2016  christos OpenBSD tokenizer.c rev. 1.8 2003/08/11 18:21:40 deraadt
don't increase amax on realloc failure
 1.22 30-Jan-2016  christos Fix misplaced parentheses (Ingo Schwarze)
 1.21 16-Aug-2011  christos re-enable -Wconversion
 1.20 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.19 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.18 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.17 30-Dec-2009  christos Fix wide build, test it, but don't turn it on yet.
 1.16 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.15 15-Feb-2009  christos pass lint on _LP64.
 1.14 05-Dec-2003  lukem branches: 1.14.40;
Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.13 18-Oct-2003  christos change allocation policy in el_push to allocate the string itself.
fix issues with strdup.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.11 27-Oct-2002  christos don't crash in memory shortage conditions.
 1.10 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.9 31-Jan-2002  christos don't forget to re-adjust the limit.
 1.8 31-Jan-2002  christos make pointer arithmetic more palatable.
 1.7 04-Jan-2001  christos consistently check for allocation failures and return -1, if we could not
get more memory.
 1.6 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.5 02-Jul-1999  simonb More trailing white space.
 1.4 12-Dec-1998  christos delint
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.14.40.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.7 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.5 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.4 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.3 02-Jul-1999  simonb More trailing white space.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.1 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.70 14-Jul-2021  christos Via Jess Thrysoee, from Adrian Bunk: Fix libedit build on Linux/Alpha
Alpha is the only Linux architecture that has SIGINFO:
https://sources.debian.org/src/manpages/5.10-1/man7/signal.7/#L522

But even on Alpha Ctrl-T is not supported, and therefore no VSTATUS:
https://sources.debian.org/src/manpages/5.10-1/man3/termios.3/#L603-L608

For consistency check both signal existence and character existence
 1.69 31-May-2020  christos use strlcpy() instead of strncpy() for gcc happiness
 1.68 02-Dec-2018  christos Add a couple more readline compat functions.
 1.67 01-Jan-2018  christos branches: 1.67.2; 1.67.4;
Only FLUSH if we are ending libedit; DRAIN if we suspend for readline.
This allows pasting multiline buffers (Gerry Swislow)
 1.66 05-Sep-2017  christos For readline emulation, don't reset the tty to "sane" (cooked) mode if we
did not start this way. Also set and reset the tty on entry and exit from
readline() since this is what readline does.
 1.65 09-May-2016  christos s/protected/libedit_private/g
 1.64 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.63 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.62 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.61 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.60 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.59 22-Mar-2016  christos Fix reversed condition in tty_end() (Ingo Schwarze)
Also don't succeed if calling setup twice.
 1.58 27-Feb-2016  christos PR/50863: John Hein: libedit el_end() messes up term settings if piped
Keep track if we initialized the tty, and only reset it if we did.
 1.57 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.56 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.55 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.54 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.53 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.52 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.51 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.50 11-Feb-2016  christos - Add some more Char casts
- reduce ifdefs by providing empty defs for nls functions (Ingo Schwarze)
 1.49 08-Dec-2015  gson unbreak the build
 1.48 08-Dec-2015  christos If we did not setup the tty, don't reset it.
 1.47 14-May-2015  christos fix warnings on ubuntu 32 bit (Miki Rozloznik)
 1.46 18-Jun-2014  christos Add stdlib.h for abort() (Jess Thrysoee)
 1.45 19-May-2014  christos PR/48821: If called from tty_stty(), recalculate flags.
 1.44 19-May-2014  christos more tty modes refactoring, no functional change intended.
 1.43 19-May-2014  christos Factor out some common code (more to be done) from PR/48821
 1.42 15-May-2012  christos branches: 1.42.2; 1.42.8;
save and restore the tty settings on entry and exit respectively.
cleanup debugging printfs.
 1.41 04-Oct-2011  christos branches: 1.41.2;

fixed warnings where wint_t is unsigned.
 1.40 16-Aug-2011  christos re-enable -Wconversion
 1.39 29-Jul-2011  christos kill ifdef notdef
 1.38 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.37 28-Jul-2011  christos Rename key to keymacro to avoid conflicts with term.h. The renaming of term
to terminal was again to avoid conflicts with term.h. term.h is a moving
namespace violation.
 1.36 28-Jul-2011  christos term -> terminal
 1.35 28-Jan-2011  christos fix pasto
 1.34 27-Jan-2011  christos don't turn on editing if stdout is not a tty.
 1.33 18-Apr-2010  christos branches: 1.33.2;
ffs needs strings.h
 1.32 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.31 22-Jul-2009  christos Don't depend on side effects inside an assert
From Michael Cook mcook at bbn dot com
 1.30 16-Feb-2009  christos fix sign compare issues.
 1.29 15-Feb-2009  christos pass lint on _LP64.
 1.28 06-Feb-2009  sketch branches: 1.28.2;
Needs errno.h
 1.27 10-Sep-2008  christos Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
using multiple EditLine objects. Mostly from Preston A. Elder.
 1.26 30-Jul-2008  christos handle EINTR in the termios operations, reported by the GHC folks
 1.25 18-Mar-2006  christos branches: 1.25.20;
Coverity CID 597: remove dead code.
 1.24 18-Mar-2006  christos Coverity CID 1216: Prevent negative index use.
 1.23 01-Jun-2005  lukem Don't use non-standard uint or u_int.
 1.22 29-May-2005  christos PR/25694: Luke Mewburn: Don't abuse unconstify'ing a string and writing to
it, because you'll core dump. Also remove extra const that gives pain to
the irix compiler.
 1.21 13-Aug-2004  mycroft Delete-previous-char and delete-next-char without an argument are not supposed
to modify the yank buffer in Emacs. Make it so.
 1.20 18-Oct-2003  christos remove debugging printf.
 1.19 18-Oct-2003  christos Allow setty to set chars using char=value
 1.18 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.17 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.16 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.15 17-May-2001  christos PR/12963:Jason Waterman: Fix signed cast problems.
 1.14 09-Jan-2001  jdolecek make constant arrays a const
 1.13 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.12 02-Aug-1999  sommerfeld Fix PR7685 (gdb under emacs prints spurious ^M and messes up terminal)
plus a few bogons noted along the way:
1) Set EDIT_DISABLED if terminal type is emacs.
2) fix bug in NO_TTY mode which caused it to not notice CR or LF
3) implement EDIT_DISABLED within libedit to be somewhat like NO_TTY,
except that a prompt is printed first.
 1.11 02-Jul-1999  simonb More trailing white space.
 1.10 07-Feb-1999  christos PR/6957: Wolfgang Helbig: libedit swaps CR and LF control chars.
 1.9 27-Sep-1998  christos Obey incoming tty char settings.
 1.8 20-May-1998  christos change M_* constants to MD_* to avoid clashes with <stream.h>
 1.7 30-Mar-1998  mrg use int rather than char as an array index.
 1.6 20-Oct-1997  scottr Add support for DTR/CTS flow control, from Bill Studenmund.
 1.5 09-Oct-1997  christos PR/4211: Dave Huang: don't lose VSTATUS and VEOL and any other characters that
are VDISABLED by default.
 1.4 06-Jul-1997  christos Fix compiler warnings.
 1.3 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.25.20.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.25.20.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.28.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.33.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.41.2.1 23-May-2012  yamt sync with head.
 1.42.8.1 10-Aug-2014  tls Rebase.
 1.42.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.67.4.1 10-Jun-2019  christos Sync with HEAD
 1.67.2.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.24 31-Jul-2021  andvar s/dependend/dependent/
 1.23 02-Dec-2018  christos Add a couple more readline compat functions.
 1.22 01-Jan-2018  christos branches: 1.22.2; 1.22.4;
Only FLUSH if we are ending libedit; DRAIN if we suspend for readline.
This allows pasting multiline buffers (Gerry Swislow)
 1.21 09-May-2016  christos s/protected/libedit_private/g
 1.20 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.19 27-Feb-2016  christos PR/50863: John Hein: libedit el_end() messes up term settings if piped
Keep track if we initialized the tty, and only reset it if we did.
 1.18 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.17 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.16 16-Feb-2016  christos No need to include "sys.h" from here; it is included from config.h
 1.15 19-May-2014  christos more tty modes refactoring, no functional change intended.
 1.14 15-May-2012  christos branches: 1.14.2; 1.14.8;
save and restore the tty settings on entry and exit respectively.
cleanup debugging printfs.
 1.13 16-Aug-2011  christos branches: 1.13.2;
re-enable -Wconversion
 1.12 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.11 01-Jun-2005  lukem Don't use non-standard uint or u_int.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.9 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.8 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.7 26-Sep-1999  lukem apparantly need <unistd.h> for portable way of getting _POSIX_VDISABLE
 1.6 02-Jul-1999  simonb branches: 1.6.2;
More trailing white space.
 1.5 20-May-1998  christos change M_* constants to MD_* to avoid clashes with <stream.h>
 1.4 11-Apr-1997  christos Don't allow CSWTCH to interfere with CSUSP on __SVR4 systems.
 1.3 11-Apr-1997  christos Portability fixes:
__const -> const
BADSIG -> SIG_ERR
int flags -> u_int flags
#if __STDC__ -> #ifdef __STDC__
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.6.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.2.1 23-May-2012  yamt sync with head.
 1.14.8.1 10-Aug-2014  tls Rebase.
 1.14.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.4.1 10-Jun-2019  christos Sync with HEAD
 1.22.2.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.64 28-Aug-2021  christos Respect $EDITOR when execution one (Baptiste Daroussin)
 1.63 23-Jul-2019  christos PR/54399: S�ren Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
 1.62 09-May-2016  christos branches: 1.62.16;
s/protected/libedit_private/g
 1.61 18-Apr-2016  christos From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
and include it only in the one file needing it, map.c.
* Combine help.h and help.c into a simplified help.h
and include it only in the one file needing it, map.c.
* Check the very simple, static files editline.c, historyn.c, and
tokenizern.c into CVS rather than needlessly generating them.
* So we no longer autogenerate any C files. :-)
* Shorten and simplify makelist by deleting the options -n, -e, -bc,
and -m; the latter was unused and useless in the first place.
* Move the declaration of el_func_t from fcns.h to the header
actually needing it, map.h. Since that header is already
included by el.h for unrelated reasons, that makes el_func_t
just as globally available as before.
* No longer include the simplified fcns.h into el.h,
include it directly into the *.c files needing it.
 1.60 11-Apr-2016  christos Get rid of private/public; keep protected (Ingo Schwarze)
 1.59 11-Apr-2016  christos Char -> wchar_t from Ingo Schwarze.
 1.58 11-Apr-2016  christos more macro WIDECHAR undoing from Ingo Schwarze.
 1.57 09-Apr-2016  christos Change some 0's to NULL's from Pedro Giffuni
 1.56 09-Apr-2016  christos More WIDECHAR elimination (Ingo Schwarze)
 1.55 02-Mar-2016  christos PR/50880: David Binderman: Remove redundant code.
While here, fix all debugging formats.
 1.54 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.53 16-Feb-2016  christos More header cleanups from Ingo Schwarze.
 1.52 16-Feb-2016  christos more include file cleanup (Ingo Schwarze)
 1.51 16-Feb-2016  christos From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times. That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
 1.50 16-Feb-2016  christos cleanup chartype.h includes (Ingo Schwarze)
 1.49 16-Feb-2016  christos cleanup inclusion of histedit.h (Ingo Schwarze)
 1.48 14-Feb-2016  christos From Ingo Schwarze:

As we have seen before, "histedit.h" can never get rid of including
the <wchar.h> header because using the data types defined there is
deeply ingrained in the public interfaces of libedit.

Now POSIX unconditionally requires that <wchar.h> defines the type
wint_t. Consequently, it can be used unconditionally, no matter
whether WIDECHAR is active or not. Consequently, the #define Int
is pointless.

Note that removing it is not gratuitious churn. Auditing for
integer signedness problems is already hard when only fundamental
types like "int" and "unsigned" are involved. It gets very hard
when types come into the picture that have platform-dependent
signedness, like "char" and "wint_t". Adding yet another layer
on top, changing both the signedness and the width in a platform-
dependent way, makes auditing yet harder, which IMHO is really
dangerous. Note that while removing the #define, i already found
one bug caused by this excessive complication - in the function
re_putc() in refresh.c. If WIDECHAR was defined, it printed an
Int = wint_t value with %c. Fortunately, that bug only affects
debugging, not production. The fix is contained in the patch.

With WIDECHAR, this doesn't change anything. For the case without
WIDECHAR, i checked that none of the places wants to store values
that might not fit in wint_t.

This only changes internal interfaces; public ones remain unchanged.
 1.47 21-Oct-2015  christos Use the full buffer for the conversion; ideally we should be dynamically
allocating this. From Jilles Tjoelker
 1.46 19-Oct-2015  christos make sure we have space for NUL and NUL terminate buffer array (Jilles Tjoelker)
 1.45 18-Jun-2014  christos Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
 1.44 18-Jun-2014  christos accomodate FreeBSD's flavor of weak references.
 1.43 16-Jan-2012  christos branches: 1.43.6; 1.43.16;
PR/45843: Henning Petersen: Fix resource leak on error.
 1.42 18-Nov-2011  christos Off by one in allocation could cause buffer overflow (Kamil Dudka)
 1.41 04-Oct-2011  christos branches: 1.41.2;

fixed warnings where wint_t is unsigned.
 1.40 16-Aug-2011  christos re-enable -Wconversion
 1.39 29-Jul-2011  christos pass -Wconversion
 1.38 29-Jul-2011  christos - fix unused params
- unconditionalize vis.h
 1.37 29-Jul-2011  christos KNF return (\1); -> return \1;
 1.36 28-Jul-2011  christos kill ptr_t and ioctl_t, add * sizeof(*foo) to all allocations.
 1.35 28-Jul-2011  christos term -> terminal
 1.34 22-Feb-2011  joerg Introduce __weakref_visible to handle the different required visibility
for weak references. GCC 4.2+ and Clang require static, older GCC wants
extern. Change __weak_reference to include sym. This requires changes
the existing users to not reuse the name of the symbol, but avoids
further differences between GCC 4.1 and GCC 4.2+/clang.
 1.33 17-Feb-2011  joerg Deal with changes in the weak_reference semantic in GCC 4.2 and later.
 1.32 23-Oct-2010  christos branches: 1.32.2;
fix fd leak found by Igor Zinovik
 1.31 30-Dec-2009  christos Wide character support (UTF-8) from Johny Mattsson; currently disabled.
 1.30 21-Feb-2009  christos more size_t stuff.
 1.29 15-Feb-2009  christos pass lint on _LP64.
 1.28 06-Feb-2009  sketch branches: 1.28.2;
Portability fix.
 1.27 22-Oct-2006  mrg __weakref__ attribute can not be applied to anything when inside function
scope, so, move the extern of get_alias_text outside vi_alias().

fixes build problems with GCC 4.1-20061021.
 1.26 18-May-2006  christos change __weak_extern to __weak_reference so that gcc4 works.
 1.25 06-Mar-2006  christos Print the actual eofc, instead of ^D\b\b.
Change internal character decoding to prevent buffer oveflows.
 1.24 10-Aug-2005  christos Don't save the el->el_line.cursor over a cv_insert call and use it later
because it might change. From Stefan Farfedeler.
 1.23 09-Aug-2005  christos Don't delete the current line in vi mode when typing 'yy'.
From Stefan Farfeleder.
 1.22 08-Aug-2005  christos Spelling mistakes and comment errors (from FreeBSD via Stefan Farfeleder; many
thanks)
 1.21 25-Apr-2005  matt Terminate the arglist with a NULL instead of 0. (Shuts up gcc4.x)
 1.20 13-Aug-2004  mycroft Delete-previous-char and delete-next-char without an argument are not supposed
to modify the yank buffer in Emacs. Make it so.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.18 19-Jun-2003  christos From michael@moria.de:
- use __attribute__((__unused__)) in arguments where appropriate.
- some int -> size_t and char * to const char * conversions.
 1.17 04-Jun-2003  matt Only return CC_EOF if ^D (VEOF) was the only thing on the line. Otherwise
beep and don't do anything else. This mimics the behavor of ^D outside in
normal terminal mode. (^D in vi scrolls forwards and as such isn't
appropriate to emulation)
 1.16 10-Mar-2003  dsl Put the __weak_extern() back inside vi_alias, but after the extern for
get_alias_text().
 1.15 10-Mar-2003  he Move the __weak_extern() (ifdef'ed) outside of the vi_alias()
function, so that this compiles again.
 1.14 10-Mar-2003  christos if no __weak_extern, don't even try to do vi_alias.
 1.13 10-Mar-2003  christos fix uninitialized variable.
grr, I want gcc-3.3
 1.12 15-Nov-2002  christos PR/18995: David Laight: libedit fixes for posix conformant sh

The posix 'sh' specification defines vi-mode editing quite tightly.
The netbsd libedit code (used by sh to do this) was missing several
features, there were also minor errors in others.

Compare netbsd sh to the definition available from:
http://www.opengroup.org/onlinepubs/007904975/utilities/sh.html
In particular the following were not supported:
U - undo all changes to line
| - goto column
Y - yank to end of line
y - yank
# - comment out current line
@ - take input from shell alias [1]
G - goto numbered line in history buffer
v - edit history line with vi
_ - append word from last input line
. - redo last command
Other minor changes have also been made.

[1] This needs the shell to define an appropriate routine to
return the text of the alias. There is no requirement that
such a function exist.
 1.11 31-Oct-2002  christos support for % command [matching parens/brackets/braces] on vi modes.
From David Laight, thanks!
 1.10 27-Oct-2002  christos vi mode and memory fixes from david laight.
 1.9 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.8 04-Sep-2000  lukem convert to new style guide, which includes:
- ansi prototypes & features (such as stdargs)
- 8 space indents
 1.7 02-Jul-1999  simonb More trailing white space.
 1.6 05-Feb-1999  christos delint.
 1.5 12-Dec-1998  christos delint
 1.4 03-Feb-1998  perry remove obsolete register declarations
 1.3 06-Jul-1997  christos Fix compiler warnings.
 1.2 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.28.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.32.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.41.2.1 17-Apr-2012  yamt sync with head
 1.43.16.1 10-Aug-2014  tls Rebase.
 1.43.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.62.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8 15-Oct-2017  abhinav Add support for escaping special characters when doing filename completion.

For instance if the file name is "foo bar":
$ ls foo<TAB>
should get autocompleted to:
$ ls foo\ bar

Works for similar other characters too, which need escaping.

Also, add an accompanying test program to ensure the escaping is correct
in various scenarios (within quotes, without quotes, with other special characeters)

Thanks to Christos for reviews, help and feedback.
 1.7 23-Mar-2016  christos Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
 1.6 15-Feb-2016  christos Compile with WIDECHAR the same way the main Makefile does (Ingo Schwarze)
 1.5 03-Feb-2010  roy Userland now builds and uses terminfo instead of termcap.

OK: core@, jdc@
 1.4 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.3 31-Aug-2006  rpaulo Rename TEST/test.c to avoid problems when doing a cleandir on case-insensitive
file systems.
ok'ed christos.
 1.2 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.1 16-Oct-2003  christos I got tired of typing a cc line.
 1.1 10-Sep-2021  christos Add an LLVM fuzzing wrapper for the portable libedit (Christian Holler)
 1.2 29-Feb-2016  christos convert to 2 clause
 1.1 16-Sep-2010  christos unbreak readline history.
 1.7 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.6 18-Jun-2014  christos cast gotsig because it is long on some systems.
 1.5 18-Apr-2010  christos branches: 1.5.12; 1.5.22;
\033 is more portable than \e still.
 1.4 15-Apr-2010  christos From Jess Thrysoee: call setlocale so we can test UTF-8
 1.3 17-Jul-2009  christos Use the proper prompt printing function.
 1.2 31-Mar-2009  christos Implement literal prompt sequences. Now someone can implement
RL_PROMPT_START_LITERAL/RL_PROMPT_END_LITERAL :-)
 1.1 31-Aug-2006  rpaulo branches: 1.1.26;
Rename TEST/test.c to avoid problems when doing a cleandir on case-insensitive
file systems.
ok'ed christos.
 1.1.26.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.5.22.1 10-Aug-2014  tls Rebase.
 1.5.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19 31-Aug-2006  rpaulo Rename TEST/test.c to avoid problems when doing a cleandir on case-insensitive
file systems.
ok'ed christos.
 1.18 01-Jun-2005  lukem Don't use non-standard uint or u_int.
 1.17 28-May-2005  lukem fix for WARNS=3
 1.16 18-May-2005  christos Make signal handler safe. From Michael Knudsen, many thanks.
 1.15 08-Dec-2003  lukem update for function name change
 1.14 05-Dec-2003  lukem Tokenization function enhancements:
* Make tok_init(), tok_end(), tok_reset(), tok_line() and tok_str()
publically available in <histedit.h>
* Documented the public functions in editline(3)
* Renamed tok_line() -> tok_str()
* Added new tok_line() which takes a "const LineInfo *" instead of
"const char *" (the former has "cursor" information), and optionally
return the argv index ("int *cursorc") and offset within that index
("int *cursorv"). This means that completion routines can use the
tokenization code to crack the line and easily find which word the
cursor is at. (mmm, context sensitive completion :)
* Fixed TEST/test.c when using "continuation" lines (unmatched quote
or \ at EOL), and added some more DEBUG messages including highlighting
where the cursor is (with a `_').
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.12 09-Aug-2002  soren Remove extraneous \n's in {err,warn}{,x}.
 1.11 23-Mar-2002  christos make sure this compiles cleanly and works.
 1.10 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.9 04-Sep-2000  lukem convert to new style guide
 1.8 21-Sep-1999  lukem fix id header...
 1.7 02-Jul-1999  simonb More trailing white space.
 1.6 20-May-1998  christos Show the simpler way.
 1.5 20-May-1998  christos Fix for api changes.
 1.4 23-Oct-1997  lukem make this compile with the new libedit history()
 1.3 11-Jan-1997  lukem RCSid police
editline first appeared in 4.4BSD not NetBSD1.0
 1.2 15-Oct-1995  christos Added history load and save to file functions.
 1.1 06-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1994  cgd libedit!
 1.5 08-Sep-2019  abhinav PR lib/54510: Fix file completion inside quotes which broke in rev 1.53

While there also fix handling character appending in the file completions when
inside quotes. For example when inside a quote, if the completion is a directory then
append a '/' but don't close the quote. On the other hand when inside a quote if the
completion is a file name and it is the only match then we can close the quote.
 1.4 31-Mar-2019  abhinav Perform quoting of filename completions when there are multiple matches as well

Quoting of special characters in filename completion was implemented for single match
case, this enables it for multiple matches as well. For example:

$ touch 'foo bar'
$ touch 'foo baz'
$ ls fo<TAB>
autocompletes to =>
$ ls foo\ ba
hitting <TAB> again shows:
foo bar foo baz

This required unescaping escape sequences generated during last completion
in order to find the word to complete.

While there, also update the test to include cases for multiple matches.

Reviewed by christos
 1.3 04-May-2018  abhinav branches: 1.3.2;
Handle filename autocompletion when the cursor is at a backslash or quote character

For example, handle following case:
$ touch 'foo bar'
$ ls foo\<TAB> --> $ ls foo\ bar

Also add test cases for this.

Thanks to Christos for review
 1.2 15-Oct-2017  abhinav branches: 1.2.2;
Add copyright and rcs header to the test program.
Also, remove a test case which was not supposed to be there.
(While that test case works with the changes I committed, testing that
test case with the test program is not possible in its current form. I'm
working on that.)
 1.1 15-Oct-2017  abhinav Add support for escaping special characters when doing filename completion.

For instance if the file name is "foo bar":
$ ls foo<TAB>
should get autocompleted to:
$ ls foo\ bar

Works for similar other characters too, which need escaping.

Also, add an accompanying test program to ensure the escaping is correct
in various scenarios (within quotes, without quotes, with other special characeters)

Thanks to Christos for reviews, help and feedback.
 1.2.2.1 21-May-2018  pgoyette Sync with HEAD
 1.3.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.1 10-Jun-2019  christos Sync with HEAD
 1.8 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.7 18-Jun-2014  christos cast gotsig because it is long on some systems.
 1.6 18-Nov-2011  christos branches: 1.6.6; 1.6.16;
Initialize res (Kamil Dudka)
 1.5 04-Aug-2011  christos branches: 1.5.2;
need err.h now
 1.4 28-Jul-2011  christos - check and don't cast malloc return
- more wide function use
 1.3 27-Jul-2011  christos add history testing code.
 1.2 18-Apr-2010  christos \033 is more portable than \e still.
 1.1 03-Jan-2010  christos rename historyw -> history_w for consistency.
add wide tst code and make it the default.
 1.5.2.1 17-Apr-2012  yamt sync with head
 1.6.16.1 10-Aug-2014  tls Rebase.
 1.6.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8 17-Feb-2016  christos whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.7 03-Aug-2003  lukem Add INCSYMLINKS to <bsd.inc.mk> and <bsd.kinc.mk>, and use that instead of
SYMLINKS to install symlinked header files. INCSYMLINKS are installed with
'make includes'. This avoids using SYMLINKS and hacks with the 'linkinstall'
target in <bsd.links.mk>, as linksinstall occurs in 'make install' and hacks
to get it to occur in 'make includes' weren't robust, as seen in lib/libdes.

Yet more improvements to bsd.README.
 1.6 19-Aug-2002  lukem More use of ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.5 12-Dec-2001  tv Readability cleanups; MKfoo=no -> NOfoo.
 1.4 16-May-2001  enami Use relative path for symlink target so that it won't point outside of tree.
 1.3 14-May-2001  jdolecek Back off previous and do differently:
Ensure that the <readline/history.h> link to <readline/readline.h> is
installed too for 'make includes'. Also, avoid creating obj dir.
This is finally real fix for lib/12929.
XXX Is this right?
 1.2 14-May-2001  jdolecek Use <bsd.inc.mk>, instead of <bsd.prog.mk>, so that the readline.h header
is installed during the 'make includes'.
Fixes lib/12929 by Martin Husemann.
 1.1 05-Jan-2001  jdolecek Standard location of readline headers is /usr/include/readline/, so install
them there.
readline.h of libedit had to move to subdirectory 'readline', due to the way
BSD makefiles work; this is better than potentially fragile Makefile hacks
 1.55 25-Apr-2023  christos pass lint.
 1.54 21-Apr-2023  christos Align types with readline-8.2 (wiz@)
 1.53 19-Feb-2022  christos PR/56695: Walter Lozano: Correct declaration of hook functions.
 1.52 08-Feb-2022  christos PR/56693: Walter Lozano: Add support for rl_delete_text and rl_set_key
 1.51 31-Jan-2022  christos PR/56622: Walter Lozano: Improve readline compatibility by adding
rl_readline_state support.
 1.50 14-Jan-2022  christos Don't use __printflike, use the explicit attribute so that this works outside
NetBSD.
 1.49 14-Jan-2022  tnn libedit: rl_message: annotate __printflike
 1.48 11-Jan-2022  christos PR/56618: Walter Lozano: Improve libedit compatibility with readline by
implementing:

rl_copy_text, rl_erase_empty_line, rl_message, rl_on_new_line,
rl_replace_line, rl_restore_prompt, rl_save_prompt
 1.47 21-Aug-2021  christos Add more api to make gdb-11 happy (but not gdbtui as usual)
 1.46 07-Jun-2019  christos PR/54280: rl_completer_quote_characters should be const for readline compat
 1.45 15-Feb-2019  christos PR/53983: Jonathan Perkins: Fix types for readline compatibility
 1.44 02-Dec-2018  christos Add a couple more readline compat functions.
 1.43 09-Jun-2018  christos branches: 1.43.2;
Provide more compatibility with readline headers; now python-3.6.5 works
when changing 'readline' -> 'edit' in setup.py.
Revert previous conditional setting of unbuffered.
 1.42 01-Sep-2017  christos branches: 1.42.2;
PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
callint it from rl_initialize breaks python, because the callback ends
up being invoked before the readline module is installed, and we end up
dereferencing a NULL pointer.
3. add el_resize_terminal.

With those changes, s/lreadline/ledit/g in python works.
 1.41 28-Oct-2016  christos export rl_done
 1.40 24-Aug-2016  christos more compatible with readline history functions.
 1.39 17-Feb-2016  christos branches: 1.39.2;
whitespace and header sorting changes (Ingo Schwarze). No functional changes.
 1.38 15-Feb-2016  christos OpenBSD readline.c rev. 1.13 2015/01/13 08:33:12 reyk
rl_set_keyboard_input_timeout() for readline 4.2 compat
 1.37 02-Jun-2015  christos remove duplicate declaration
 1.36 02-Jun-2015  christos Adjust API to a more modern readline (Ryo Onodera)
 1.35 26-May-2015  christos - fix types of rl_completion_entry_function and rl_add_defun
- call update pos before completion to refresh the screen
From Thomas Eriksson
 1.34 28-May-2013  christos expose rl_catch_signals and explain what we are doing.
 1.33 15-May-2012  christos branches: 1.33.2;
Add rl_completion_word_break_hook from:
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/\
5ec6a45fa762b8cbd0305ca06acb8780335a486a
 1.32 16-Sep-2010  christos branches: 1.32.6;
unbreak readline history.
 1.31 04-Aug-2010  christos provide rl_on_newline
 1.30 07-Sep-2009  christos apply apple patches from:
http://opensource.apple.com/source/libedit/libedit-11/patches/
 1.29 31-Aug-2009  christos delete defined(sun), it could be invaded in the user namespace. Suggested
by mrg@
 1.28 30-Aug-2009  christos use __sun || sun instead of _SunOS, from Jess Thrysoee
 1.27 09-Jul-2009  christos add stdio.h since we are using FILE. From Grant Erickson
 1.26 31-Mar-2009  christos implement RL_PROMPT_{START,END}_IGNORE
 1.25 12-Feb-2009  sketch More fixes for existing portability stuff.
 1.24 05-Feb-2009  christos branches: 1.24.2;
add rl_set_prompt
 1.23 29-Apr-2008  martin Convert to new 2 clause license
 1.22 04-Apr-2008  christos branches: 1.22.2;
Add rl_forced_update_display() from Gerry Swislow
 1.21 12-Aug-2007  christos patches from Axel Thimm
 1.20 27-May-2007  christos Add rl_completion_matches, fix remove_history
 1.19 24-Nov-2006  christos - Add more readline functions, enough for gdb-6.5
- Make el_get varyadic, and implement EL_GETTC.
- XXX: the EL_SETTC api will change in the future.
 1.18 21-Aug-2006  christos Change to a 3 clause copyright after permission of the holders.
 1.17 14-Jul-2005  christos PR/30747: David N. Williams: libedit is missing remove_history()
Added, please test.
 1.16 11-Jun-2005  christos PR/30500: Paul Shupak: Inconsistent definition of tilde_expand().
Provide a layer of indirection between the readline compatibility functions
and our internal implementation, so that we have the freedom to change the
function signature.
 1.15 10-Jun-2005  christos tilde expand should take a const argument.
 1.14 27-May-2005  agc Sync the alternative readline interface with reality:

+ the rl_callback_handler_install takes a pointer to a void function
which has one char * argument (it's called that way in the readline
emulation source, otherwise there's no way to pass the line buffer
to the function which processes the line when EOL is encountered)

+ provide a prototype for that function signature and use it

Makes the callback readline interface work now.
 1.13 12-Apr-2005  christos PR/29958: Peter Bex: add rl_variable_bind and rl_attempted_completion_over
 1.12 08-Sep-2004  christos branches: 1.12.2;
make rl_inhibit_completion visible.
 1.11 17-Jan-2004  christos portability fixes.
 1.10 27-Oct-2003  christos Make readline csh-like history work.
From Gerry Swislow <gerry at certif dot com>.
 1.9 16-Oct-2003  christos More libedit readline emulation functions from: Gerry Swislow
<gerry at certif dot com>
 1.8 26-Sep-2003  christos Implement enough of readline's 4.0 async mode to make gdb happy. This is
not complete yet, but it seems to work...
This required to introduce an unbuffered mode to el_gets(), but that was
a minor change.
 1.7 15-Sep-2003  tron Include "sys/ttydefaults.h" to get standard definition of "CTRL" macro
which avoids clash with custom one.
 1.6 15-Sep-2003  christos kludge around CTRL redef.
 1.5 14-Sep-2003  christos Match the stupid function pointer declarations with actual readline's 4.0.
This is gross.
 1.4 14-Sep-2003  christos Avoid pre-ansi warning.
 1.3 14-Sep-2003  christos - provide enough hooks to compile gdb-5.3
- fix el_get(e, EL_TERMINAL, (char **))
 1.2 18-Mar-2002  christos - constify; passes all gcc and lint strict checks.
- add config.h [Jason Evans], to create a portable version of libedit that
can be easily compiled on other OS's.
 1.1 05-Jan-2001  jdolecek Standard location of readline headers is /usr/include/readline/, so install
them there.
readline.h of libedit had to move to subdirectory 'readline', due to the way
BSD makefiles work; this is better than potentially fragile Makefile hacks
 1.12.2.1 28-May-2005  tron Pull up revision 1.14 (requested by agc in ticket #353):
Sync the alternative readline interface with reality:
+ the rl_callback_handler_install takes a pointer to a void function
which has one char * argument (it's called that way in the readline
emulation source, otherwise there's no way to pass the line buffer
to the function which processes the line when EOL is encountered)
+ provide a prototype for that function signature and use it
Makes the callback readline interface work now.
 1.22.2.1 18-May-2008  yamt sync with head.
 1.24.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.32.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.32.6.1 23-May-2012  yamt sync with head.
 1.33.2.1 23-Jun-2013  tls resync from head
 1.39.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.42.2.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.42.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.43.2.1 10-Jun-2019  christos Sync with HEAD

RSS XML Feed