diff options
author | Haibo Huang <hhb@google.com> | 2019-11-25 15:32:55 -0800 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2019-11-25 15:34:35 -0800 |
commit | 892b8b381ae82ac3184900d989a516854d8b1197 (patch) | |
tree | 0d37bcbdabcdd0602b5444ceb0bb9af20a4496f3 | |
parent | 459326d0af95beb84e0c94da3bc63ba9d764b3ea (diff) | |
download | libedit-892b8b381ae82ac3184900d989a516854d8b1197.tar.gz |
Upgrade libedit to 20191025HEADmastermainllvm-r487747llvm-r450784llvm-r416183llvm-r399163bllvm-r383902b
Test: build
Change-Id: I35977af76e0a89667a1858cffb1f1cb019ba4899
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | Makefile.in | 13 | ||||
-rw-r--r-- | aclocal.m4 | 36 | ||||
-rwxr-xr-x | configure | 56 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | doc/Makefile.in | 8 | ||||
-rw-r--r-- | examples/Makefile.in | 8 | ||||
-rw-r--r-- | src/Makefile.in | 8 | ||||
-rw-r--r-- | src/chared.c | 20 | ||||
-rw-r--r-- | src/chartype.c | 6 | ||||
-rw-r--r-- | src/chartype.h | 4 | ||||
-rw-r--r-- | src/editline/readline.h | 4 | ||||
-rw-r--r-- | src/el.c | 22 | ||||
-rw-r--r-- | src/el.h | 3 | ||||
-rw-r--r-- | src/eln.c | 14 | ||||
-rw-r--r-- | src/filecomplete.c | 183 | ||||
-rw-r--r-- | src/hist.c | 8 | ||||
-rw-r--r-- | src/history.c | 14 | ||||
-rw-r--r-- | src/keymacro.c | 6 | ||||
-rw-r--r-- | src/literal.c | 8 | ||||
-rw-r--r-- | src/map.c | 12 | ||||
-rw-r--r-- | src/parse.c | 6 | ||||
-rw-r--r-- | src/read.c | 7 | ||||
-rw-r--r-- | src/readline.c | 55 | ||||
-rw-r--r-- | src/search.c | 6 | ||||
-rw-r--r-- | src/terminal.c | 47 | ||||
-rw-r--r-- | src/vi.c | 8 |
28 files changed, 274 insertions, 305 deletions
@@ -1,6 +1,12 @@ * See also NetBSD changelog: http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit +2019-10-25 Jess Thrysoee + + * version-info: 0:61:0 + + * all: sync with upstream source + 2019-03-24 Jess Thrysoee * version-info: 0:60:0 @@ -7,12 +7,12 @@ third_party { } url { type: ARCHIVE - value: "https://www.thrysoee.dk/editline/libedit-20190324-3.1.tar.gz" + value: "https://www.thrysoee.dk/editline/libedit-20191025-3.1.tar.gz" } - version: "20190324-3.1" + version: "20191025-3.1" last_upgrade_date { year: 2019 - month: 8 - day: 28 + month: 11 + day: 25 } } diff --git a/Makefile.in b/Makefile.in index 4a0ef37..f66abff 100644 --- a/Makefile.in +++ b/Makefile.in @@ -192,8 +192,7 @@ CSCOPE = cscope DIST_SUBDIRS = src examples doc am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ $(srcdir)/libedit.pc.in COPYING ChangeLog INSTALL THANKS \ - compile config.guess config.sub depcomp install-sh ltmain.sh \ - missing + compile config.guess config.sub install-sh ltmain.sh missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -277,7 +276,6 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ LT_VERSION = @LT_VERSION@ -MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MANTYPE = @MANTYPE@ @@ -347,7 +345,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -369,7 +366,7 @@ all: config.h .SUFFIXES: am--refresh: Makefile @: -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -395,9 +392,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) +$(top_srcdir)/configure: $(am__configure_deps) $(am__cd) $(srcdir) && $(AUTOCONF) -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): @@ -408,7 +405,7 @@ config.h: stamp-h1 stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status @rm -f stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status config.h -$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) +$(srcdir)/config.h.in: $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ @@ -635,42 +635,6 @@ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) -# Add --enable-maintainer-mode option to configure. -*- Autoconf -*- -# From Jim Meyering - -# Copyright (C) 1996-2018 Free Software Foundation, Inc. -# -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# AM_MAINTAINER_MODE([DEFAULT-MODE]) -# ---------------------------------- -# Control maintainer-specific portions of Makefiles. -# Default is to disable them, unless 'enable' is passed literally. -# For symmetry, 'disable' may be passed as well. Anyway, the user -# can override the default with the --enable/--disable switch. -AC_DEFUN([AM_MAINTAINER_MODE], -[m4_case(m4_default([$1], [disable]), - [enable], [m4_define([am_maintainer_other], [disable])], - [disable], [m4_define([am_maintainer_other], [enable])], - [m4_define([am_maintainer_other], [enable]) - m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) -AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) - dnl maintainer-mode's default is 'disable' unless 'enable' is passed - AC_ARG_ENABLE([maintainer-mode], - [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode], - am_maintainer_other[ make rules and dependencies not useful - (and sometimes confusing) to the casual installer])], - [USE_MAINTAINER_MODE=$enableval], - [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) - AC_MSG_RESULT([$USE_MAINTAINER_MODE]) - AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) - MAINT=$MAINTAINER_MODE_TRUE - AC_SUBST([MAINT])dnl -] -) - # Check to see how 'make' treats includes. -*- Autoconf -*- # Copyright (C) 2001-2018 Free Software Foundation, Inc. @@ -586,7 +586,7 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libedit' -PACKAGE_TARNAME='libedit-20190903' +PACKAGE_TARNAME='libedit-20191025' PACKAGE_VERSION='3.1' PACKAGE_STRING='libedit 3.1' PACKAGE_BUGREPORT='' @@ -720,9 +720,6 @@ CPPFLAGS LDFLAGS CFLAGS CC -MAINT -MAINTAINER_MODE_FALSE -MAINTAINER_MODE_TRUE target_alias host_alias build_alias @@ -742,7 +739,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -766,7 +762,6 @@ am__quote' ac_subst_files='' ac_user_opts=' enable_option_checking -enable_maintainer_mode enable_dependency_tracking enable_silent_rules enable_shared @@ -828,7 +823,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1081,15 +1075,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1227,7 +1212,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1380,7 +1365,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1390,7 +1374,7 @@ Fine tuning of the installation directories: --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root - [DATAROOTDIR/doc/libedit-20190903] + [DATAROOTDIR/doc/libedit-20191025] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] @@ -1420,9 +1404,6 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --enable-maintainer-mode - enable make rules and dependencies not useful (and - sometimes confusing) to the casual installer --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking @@ -2356,29 +2337,6 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_config_headers="$ac_config_headers config.h" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 -$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } - # Check whether --enable-maintainer-mode was given. -if test "${enable_maintainer_mode+set}" = set; then : - enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval -else - USE_MAINTAINER_MODE=no -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 -$as_echo "$USE_MAINTAINER_MODE" >&6; } - if test $USE_MAINTAINER_MODE = yes; then - MAINTAINER_MODE_TRUE= - MAINTAINER_MODE_FALSE='#' -else - MAINTAINER_MODE_TRUE='#' - MAINTAINER_MODE_FALSE= -fi - - MAINT=$MAINTAINER_MODE_TRUE - - - # features of Posix that are extensions to C (define _GNU_SOURCE) ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do @@ -4265,7 +4223,7 @@ fi # Define the identity of the package. - PACKAGE='libedit-20190903' + PACKAGE='libedit-20191025' VERSION='3.1' @@ -12160,7 +12118,7 @@ CC=$lt_save_CC # libtool -version-info -LT_VERSION=0:60:0 +LT_VERSION=0:61:0 # Check whether --enable-silent-rules was given. @@ -13881,10 +13839,6 @@ LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs -if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then - as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. -Usually this means the macro was only invoked conditionally." "$LINENO" 5 -fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 $as_echo_n "checking that generated files are newer than configure... " >&6; } if test -n "$am_sleep_pid"; then diff --git a/configure.ac b/configure.ac index 61be43e..f07d42e 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,6 @@ AC_INIT(libedit, [EL_RELEASE],, libedit-[EL_TIMESTAMP]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src/strlcat.c]) AC_CONFIG_HEADER([config.h]) -AM_MAINTAINER_MODE # features of Posix that are extensions to C (define _GNU_SOURCE) AC_USE_SYSTEM_EXTENSIONS @@ -36,7 +35,7 @@ AM_INIT_AUTOMAKE AC_PROG_LIBTOOL # libtool -version-info -AC_SUBST(LT_VERSION, [0:60:0]) +AC_SUBST(LT_VERSION, [0:61:0]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) diff --git a/doc/Makefile.in b/doc/Makefile.in index 8108957..204d17a 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -196,7 +196,6 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ LT_VERSION = @LT_VERSION@ -MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MANTYPE = @MANTYPE@ @@ -266,7 +265,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -291,7 +289,7 @@ EXTRA_DIST = editline.3.roff editline.7.roff editrc.5.roff mdoc2man.awk all: all-am .SUFFIXES: -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -315,9 +313,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) +$(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): diff --git a/examples/Makefile.in b/examples/Makefile.in index b339bf3..4f02cc3 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -224,7 +224,6 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ LT_VERSION = @LT_VERSION@ -MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MANTYPE = @MANTYPE@ @@ -294,7 +293,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -312,7 +310,7 @@ all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -336,9 +334,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) +$(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): diff --git a/src/Makefile.in b/src/Makefile.in index cc2b067..7877ddf 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -285,7 +285,6 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ LT_VERSION = @LT_VERSION@ -MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MANTYPE = @MANTYPE@ @@ -355,7 +354,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -387,7 +385,7 @@ all: $(BUILT_SOURCES) .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -411,9 +409,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) +$(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) +$(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): diff --git a/src/chared.c b/src/chared.c index 0c527a6..a96322a 100644 --- a/src/chared.c +++ b/src/chared.c @@ -1,4 +1,4 @@ -/* $NetBSD: chared.c,v 1.57 2017/10/11 06:49:03 abhinav Exp $ */ +/* $NetBSD: chared.c,v 1.59 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: chared.c,v 1.57 2017/10/11 06:49:03 abhinav Exp $"); +__RCSID("$NetBSD: chared.c,v 1.59 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -174,7 +174,7 @@ c_delbefore(EditLine *el, int num) wchar_t *cp; for (cp = el->el_line.cursor - num; - cp <= el->el_line.lastchar; + &cp[num] <= el->el_line.lastchar; cp++) *cp = cp[num]; @@ -396,26 +396,22 @@ cv__endword(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t)) libedit_private int ch_init(EditLine *el) { - el->el_line.buffer = el_malloc(EL_BUFSIZ * + el->el_line.buffer = el_calloc(EL_BUFSIZ, sizeof(*el->el_line.buffer)); if (el->el_line.buffer == NULL) return -1; - (void) memset(el->el_line.buffer, 0, EL_BUFSIZ * - sizeof(*el->el_line.buffer)); el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer; el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE]; - el->el_chared.c_undo.buf = el_malloc(EL_BUFSIZ * + el->el_chared.c_undo.buf = el_calloc(EL_BUFSIZ, sizeof(*el->el_chared.c_undo.buf)); if (el->el_chared.c_undo.buf == NULL) return -1; - (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ * - sizeof(*el->el_chared.c_undo.buf)); el->el_chared.c_undo.len = -1; el->el_chared.c_undo.cursor = 0; - el->el_chared.c_redo.buf = el_malloc(EL_BUFSIZ * + el->el_chared.c_redo.buf = el_calloc(EL_BUFSIZ, sizeof(*el->el_chared.c_redo.buf)); if (el->el_chared.c_redo.buf == NULL) return -1; @@ -426,12 +422,10 @@ ch_init(EditLine *el) el->el_chared.c_vcmd.action = NOP; el->el_chared.c_vcmd.pos = el->el_line.buffer; - el->el_chared.c_kill.buf = el_malloc(EL_BUFSIZ * + el->el_chared.c_kill.buf = el_calloc(EL_BUFSIZ, sizeof(*el->el_chared.c_kill.buf)); if (el->el_chared.c_kill.buf == NULL) return -1; - (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ * - sizeof(*el->el_chared.c_kill.buf)); el->el_chared.c_kill.mark = el->el_line.buffer; el->el_chared.c_kill.last = el->el_chared.c_kill.buf; el->el_chared.c_resizefun = NULL; diff --git a/src/chartype.c b/src/chartype.c index 79429d6..3df4af6 100644 --- a/src/chartype.c +++ b/src/chartype.c @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.c,v 1.34 2018/11/25 16:20:28 christos Exp $ */ +/* $NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: chartype.c,v 1.34 2018/11/25 16:20:28 christos Exp $"); +__RCSID("$NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $"); #endif /* not lint && not SCCSID */ #include <ctype.h> @@ -157,7 +157,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1) return NULL; - wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv)); + wargv = el_calloc((size_t)(argc + 1), sizeof(*wargv)); for (i = 0, p = conv->wbuff; i < argc; ++i) { if (!argv[i]) { /* don't pass null pointers to mbstowcs */ diff --git a/src/chartype.h b/src/chartype.h index 4cdd981..bfa3d54 100644 --- a/src/chartype.h +++ b/src/chartype.h @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.h,v 1.35 2017/05/22 19:16:25 christos Exp $ */ +/* $NetBSD: chartype.h,v 1.36 2019/09/15 21:09:11 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -87,7 +87,7 @@ libedit_private size_t ct_enc_width(wchar_t); /* The terminal is thought of in terms of X columns by Y lines. In the cases * where a wide character takes up more than one column, the adjacent * occupied column entries will contain this faux character. */ -#define MB_FILL_CHAR ((wchar_t)-1) +#define MB_FILL_CHAR ((wint_t)-1) /* Visual width of character c, taking into account ^? , \0177 and \U+nnnnn * style visual expansions. */ diff --git a/src/editline/readline.h b/src/editline/readline.h index 5f101e7..7e53f41 100644 --- a/src/editline/readline.h +++ b/src/editline/readline.h @@ -1,4 +1,4 @@ -/* $NetBSD: readline.h,v 1.45 2019/02/15 23:20:35 christos Exp $ */ +/* $NetBSD: readline.h,v 1.46 2019/06/07 15:19:29 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -108,7 +108,7 @@ extern int history_base, history_length; extern int max_input_history; extern const char *rl_basic_word_break_characters; extern char *rl_completer_word_break_characters; -extern char *rl_completer_quote_characters; +extern const char *rl_completer_quote_characters; extern rl_compentry_func_t *rl_completion_entry_function; extern char *(*rl_completion_word_break_hook)(void); extern rl_completion_func_t *rl_attempted_completion_function; @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.97 2018/11/18 17:09:39 christos Exp $ */ +/* $NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; #else -__RCSID("$NetBSD: el.c,v 1.97 2018/11/18 17:09:39 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -98,13 +98,11 @@ libedit_private EditLine * el_init_internal(const char *prog, FILE *fin, FILE *fout, FILE *ferr, int fdin, int fdout, int fderr, int flags) { - EditLine *el = el_malloc(sizeof(*el)); + EditLine *el = el_calloc(1, sizeof(*el)); if (el == NULL) return NULL; - memset(el, 0, sizeof(EditLine)); - el->el_infile = fin; el->el_outfile = fout; el->el_errfile = ferr; @@ -466,15 +464,11 @@ el_wget(EditLine *el, int op, ...) case EL_GETTC: { static char name[] = "gettc"; - char *argv[20]; - int i; - - for (i = 1; i < (int)__arraycount(argv); i++) - if ((argv[i] = va_arg(ap, char *)) == NULL) - break; - + char *argv[3]; argv[0] = name; - rv = terminal_gettc(el, i, argv); + argv[1] = va_arg(ap, char *); + argv[2] = va_arg(ap, void *); + rv = terminal_gettc(el, 3, argv); break; } @@ -565,7 +559,7 @@ el_source(EditLine *el, const char *fname) if ((ptr = getenv("HOME")) == NULL) return -1; plen += strlen(ptr); - if ((path = el_malloc(plen * sizeof(*path))) == NULL) + if ((path = el_calloc(plen, sizeof(*path))) == NULL) return -1; (void)snprintf(path, plen, "%s%s", ptr, elpath + (*ptr == '\0')); @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.44 2018/11/18 17:09:39 christos Exp $ */ +/* $NetBSD: el.h,v 1.45 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -89,6 +89,7 @@ typedef struct el_state_t { * Until we come up with something better... */ #define el_malloc(a) malloc(a) +#define el_calloc(a,b) calloc(a, b) #define el_realloc(a,b) realloc(a, b) #define el_free(a) free(a) @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.34 2016/05/09 21:37:34 christos Exp $ */ +/* $NetBSD: eln.c,v 1.35 2019/04/26 16:56:57 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: eln.c,v 1.34 2016/05/09 21:37:34 christos Exp $"); +__RCSID("$NetBSD: eln.c,v 1.35 2019/04/26 16:56:57 christos Exp $"); #endif /* not lint && not SCCSID */ #include <errno.h> @@ -321,14 +321,12 @@ el_get(EditLine *el, int op, ...) break; case EL_GETTC: { - char *argv[20]; + char *argv[3]; static char gettc[] = "gettc"; - int i; - for (i = 1; i < (int)__arraycount(argv); ++i) - if ((argv[i] = va_arg(ap, char *)) == NULL) - break; argv[0] = gettc; - ret = terminal_gettc(el, i, argv); + argv[1] = va_arg(ap, char *); + argv[2] = va_arg(ap, void *); + ret = terminal_gettc(el, 3, argv); break; } diff --git a/src/filecomplete.c b/src/filecomplete.c index c3a9675..189798c 100644 --- a/src/filecomplete.c +++ b/src/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.51 2018/05/04 20:38:26 christos Exp $ */ +/* $NetBSD: filecomplete.c,v 1.61 2019/10/09 14:31:07 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: filecomplete.c,v 1.51 2018/05/04 20:38:26 christos Exp $"); +__RCSID("$NetBSD: filecomplete.c,v 1.61 2019/10/09 14:31:07 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/types.h> @@ -84,11 +84,10 @@ fn_tilde_expand(const char *txt) } else { /* text until string after slash */ len = (size_t)(temp - txt + 1); - temp = el_malloc(len * sizeof(*temp)); + temp = el_calloc(len, sizeof(*temp)); if (temp == NULL) return NULL; - (void)strncpy(temp, txt + 1, len - 2); - temp[len - 2] = '\0'; + (void)strlcpy(temp, txt + 1, len - 1); } if (temp[0] == 0) { #ifdef HAVE_GETPW_R_POSIX @@ -119,7 +118,7 @@ fn_tilde_expand(const char *txt) txt += len; len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1; - temp = el_malloc(len * sizeof(*temp)); + temp = el_calloc(len, sizeof(*temp)); if (temp == NULL) return NULL; (void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt); @@ -160,8 +159,41 @@ needs_escaping(char c) } } +static int +needs_dquote_escaping(char c) +{ + switch (c) { + case '"': + case '\\': + case '`': + case '$': + return 1; + default: + return 0; + } +} + + +static wchar_t * +unescape_string(const wchar_t *string, size_t length) +{ + size_t i; + size_t j = 0; + wchar_t *unescaped = el_calloc(length + 1, sizeof(*string)); + if (unescaped == NULL) + return NULL; + for (i = 0; i < length ; i++) { + if (string[i] == '\\') + continue; + unescaped[j++] = string[i]; + } + unescaped[j] = 0; + return unescaped; +} + static char * -escape_filename(EditLine * el, const char *filename) +escape_filename(EditLine * el, const char *filename, int single_match, + const char *(*app_func)(const char *)) { size_t original_len = 0; size_t escaped_character_count = 0; @@ -173,11 +205,15 @@ escape_filename(EditLine * el, const char *filename) size_t d_quoted = 0; /* does the input contain a double quote */ char *escaped_str; wchar_t *temp = el->el_line.buffer; + const char *append_char = NULL; + + if (filename == NULL) + return NULL; while (temp != el->el_line.cursor) { /* - * If we see a single quote but have not seen a double quote so far - * set/unset s_quote + * If we see a single quote but have not seen a double quote + * so far set/unset s_quote */ if (temp[0] == '\'' && !d_quoted) s_quoted = !s_quoted; @@ -200,7 +236,7 @@ escape_filename(EditLine * el, const char *filename) continue; } /* Inside double quotes only ", \, ` and $ need escaping */ - if (d_quoted && (c == '"' || c == '\\' || c == '`' || c == '$')) { + if (d_quoted && needs_dquote_escaping(c)) { escaped_character_count++; continue; } @@ -209,6 +245,12 @@ escape_filename(EditLine * el, const char *filename) } newlen = original_len + escaped_character_count + 1; + if (s_quoted || d_quoted) + newlen++; + + if (single_match && app_func) + newlen++; + if ((escaped_str = el_malloc(newlen)) == NULL) return NULL; @@ -238,7 +280,7 @@ escape_filename(EditLine * el, const char *filename) /* No escaping needed inside a double quoted string either * unless we see a '$', '\', '`', or '"' (itself) */ - if (d_quoted && c != '"' && c != '$' && c != '\\' && c != '`') { + if (d_quoted && !needs_dquote_escaping(c)) { escaped_str[offset++] = c; continue; } @@ -248,11 +290,24 @@ escape_filename(EditLine * el, const char *filename) escaped_str[offset++] = c; } - /* close the quotes */ - if (s_quoted) - escaped_str[offset++] = '\''; - else if (d_quoted) - escaped_str[offset++] = '"'; + if (single_match && app_func) { + escaped_str[offset] = 0; + append_char = app_func(escaped_str); + /* we want to append space only if we are not inside quotes */ + if (append_char[0] == ' ') { + if (!s_quoted && !d_quoted) + escaped_str[offset++] = append_char[0]; + } else + escaped_str[offset++] = append_char[0]; + } + + /* close the quotes if single match and the match is not a directory */ + if (single_match && (append_char && append_char[0] == ' ')) { + if (s_quoted) + escaped_str[offset++] = '\''; + else if (d_quoted) + escaped_str[offset++] = '"'; + } escaped_str[offset] = 0; return escaped_str; @@ -299,8 +354,7 @@ fn_filename_completion_function(const char *text, int state) return NULL; } dirname = nptr; - (void)strncpy(dirname, text, len); - dirname[len] = '\0'; + (void)strlcpy(dirname, text, len + 1); } else { el_free(filename); if (*text == 0) @@ -367,7 +421,7 @@ fn_filename_completion_function(const char *text, int state) len = strlen(entry->d_name); len = strlen(dirname) + len + 1; - temp = el_malloc(len * sizeof(*temp)); + temp = el_calloc(len, sizeof(*temp)); if (temp == NULL) return NULL; (void)snprintf(temp, len, "%s%s", dirname, entry->d_name); @@ -443,13 +497,12 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int)) max_equal = i; } - retstr = el_malloc((max_equal + 1) * sizeof(*retstr)); + retstr = el_calloc(max_equal + 1, sizeof(*retstr)); if (retstr == NULL) { el_free(match_list); return NULL; } - (void)strncpy(retstr, match_list[1], max_equal); - retstr[max_equal] = '\0'; + (void)strlcpy(retstr, match_list[1], max_equal + 1); match_list[0] = retstr; /* add NULL as last pointer to the array */ @@ -495,7 +548,7 @@ fn_display_match_list(EditLine * el, char **matches, size_t num, size_t width, * Find out how many entries can be put on one line; count * with one space between strings the same way it's printed. */ - cols = (size_t)screenwidth / (width + 1); + cols = (size_t)screenwidth / (width + 2); if (cols == 0) cols = 1; @@ -515,7 +568,7 @@ fn_display_match_list(EditLine * el, char **matches, size_t num, size_t width, break; (void)fprintf(el->el_outfile, "%s%s%s", col == 0 ? "" : " ", matches[thisguy], - append_char_function(matches[thisguy])); + (*app_func)(matches[thisguy])); (void)fprintf(el->el_outfile, "%-*s", (int) (width - strlen(matches[thisguy])), ""); } @@ -529,9 +582,7 @@ find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer, { /* We now look backwards for the start of a filename/variable word */ const wchar_t *ctemp = cursor; - int cursor_at_quote; size_t len; - wchar_t *temp; /* if the cursor is placed at a slash or a quote, we need to find the * word before it @@ -541,30 +592,42 @@ find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer, case '\\': case '\'': case '"': - cursor_at_quote = 1; ctemp--; break; default: - cursor_at_quote = 0; + break; } - } else - cursor_at_quote = 0; + } - while (ctemp > buffer - && !wcschr(word_break, ctemp[-1]) - && (!special_prefixes || !wcschr(special_prefixes, ctemp[-1]))) + for (;;) { + if (ctemp <= buffer) + break; + if (wcschr(word_break, ctemp[-1])) { + if (ctemp - buffer >= 2 && ctemp[-2] == '\\') { + ctemp -= 2; + continue; + } else if (ctemp - buffer >= 2 && + (ctemp[-2] == '\'' || ctemp[-2] == '"')) { + ctemp--; + continue; + } else + break; + } + if (special_prefixes && wcschr(special_prefixes, ctemp[-1])) + break; ctemp--; + } - len = (size_t) (cursor - ctemp - cursor_at_quote); - temp = el_malloc((len + 1) * sizeof(*temp)); - if (temp == NULL) - return NULL; - (void) wcsncpy(temp, ctemp, len); - temp[len] = '\0'; - if (cursor_at_quote) - len++; + len = (size_t) (cursor - ctemp); + if (len == 1 && (ctemp[0] == '\'' || ctemp[0] == '"')) { + len = 0; + ctemp++; + } *length = len; - return temp; + wchar_t *unescaped_word = unescape_string(ctemp, len); + if (unescaped_word == NULL) + return NULL; + return unescaped_word; } /* @@ -590,6 +653,7 @@ fn_complete(EditLine *el, const LineInfoW *li; wchar_t *temp; char **matches; + char *completion; size_t len; int what_to_do = '\t'; int retval = CC_NORM; @@ -643,30 +707,31 @@ fn_complete(EditLine *el, retval = CC_REFRESH; if (matches[0][0] != '\0') { - el_deletestr(el, (int) len); + el_deletestr(el, (int)len); + if (!attempted_completion_function) + completion = escape_filename(el, matches[0], + single_match, app_func); + else + completion = strdup(matches[0]); + if (completion == NULL) + goto out; if (single_match) { - /* - * We found exact match. Add a space after - * it, unless we do filename completion and the - * object is a directory. Also do necessary escape quoting + /* We found exact match. Add a space after it, + * unless we do filename completion and the + * object is a directory. Also do necessary + * escape quoting */ - char *escaped_completion = escape_filename(el, matches[0]); - if (escaped_completion == NULL) - goto out; el_winsertstr(el, - ct_decode_string(escaped_completion, &el->el_scratch)); - el_winsertstr(el, - ct_decode_string((*app_func)(escaped_completion), - &el->el_scratch)); - free(escaped_completion); + ct_decode_string(completion, &el->el_scratch)); } else { - /* - * Only replace the completed string with common part of - * possible matches if there is possible completion. + /* Only replace the completed string with + * common part of possible matches if there is + * possible completion. */ el_winsertstr(el, - ct_decode_string(matches[0], &el->el_scratch)); + ct_decode_string(completion, &el->el_scratch)); } + free(completion); } @@ -1,4 +1,4 @@ -/* $NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $ */ +/* $NetBSD: hist.c,v 1.34 2019/07/23 10:19:35 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $"); +__RCSID("$NetBSD: hist.c,v 1.34 2019/07/23 10:19:35 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -59,10 +59,10 @@ hist_init(EditLine *el) el->el_history.fun = NULL; el->el_history.ref = NULL; - el->el_history.buf = el_malloc(EL_BUFSIZ * sizeof(*el->el_history.buf)); - el->el_history.sz = EL_BUFSIZ; + el->el_history.buf = el_calloc(EL_BUFSIZ, sizeof(*el->el_history.buf)); if (el->el_history.buf == NULL) return -1; + el->el_history.sz = EL_BUFSIZ; el->el_history.last = el->el_history.buf; return 0; } diff --git a/src/history.c b/src/history.c index 7f7a94c..2a8ca1a 100644 --- a/src/history.c +++ b/src/history.c @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.62 2018/09/13 09:03:40 kre Exp $ */ +/* $NetBSD: history.c,v 1.63 2019/10/08 19:17:57 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: history.c,v 1.62 2018/09/13 09:03:40 kre Exp $"); +__RCSID("$NetBSD: history.c,v 1.63 2019/10/08 19:17:57 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -414,21 +414,23 @@ static int history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str) { history_t *h = (history_t *) p; - size_t len; + size_t len, elen, slen; Char *s; HistEventPrivate *evp = (void *)&h->cursor->ev; if (h->cursor == &h->list) return history_def_enter(p, ev, str); - len = Strlen(evp->str) + Strlen(str) + 1; + elen = Strlen(evp->str); + slen = Strlen(str); + len = elen + slen + 1; s = h_malloc(len * sizeof(*s)); if (s == NULL) { he_seterrev(ev, _HE_MALLOC_FAILED); return -1; } - (void) Strncpy(s, h->cursor->ev.str, len); + memcpy(s, evp->str, elen * sizeof(*s)); + memcpy(s + elen, str, slen * sizeof(*s)); s[len - 1] = '\0'; - (void) Strncat(s, str, len - Strlen(s) - 1); h_free(evp->str); evp->str = s; *ev = h->cursor->ev; diff --git a/src/keymacro.c b/src/keymacro.c index 13d2089..cef24a1 100644 --- a/src/keymacro.c +++ b/src/keymacro.c @@ -1,4 +1,4 @@ -/* $NetBSD: keymacro.c,v 1.23 2016/05/24 15:00:45 christos Exp $ */ +/* $NetBSD: keymacro.c,v 1.24 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: keymacro.c,v 1.23 2016/05/24 15:00:45 christos Exp $"); +__RCSID("$NetBSD: keymacro.c,v 1.24 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -105,7 +105,7 @@ libedit_private int keymacro_init(EditLine *el) { - el->el_keymacro.buf = el_malloc(KEY_BUFSIZ * + el->el_keymacro.buf = el_calloc(KEY_BUFSIZ, sizeof(*el->el_keymacro.buf)); if (el->el_keymacro.buf == NULL) return -1; diff --git a/src/literal.c b/src/literal.c index 5d07b1d..3c56816 100644 --- a/src/literal.c +++ b/src/literal.c @@ -1,4 +1,4 @@ -/* $NetBSD: literal.c,v 1.3 2017/06/30 20:26:52 kre Exp $ */ +/* $NetBSD: literal.c,v 1.5 2019/07/23 13:10:11 christos Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 -__RCSID("$NetBSD: literal.c,v 1.3 2017/06/30 20:26:52 kre Exp $"); +__RCSID("$NetBSD: literal.c,v 1.5 2019/07/23 13:10:11 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -100,8 +100,8 @@ literal_add(EditLine *el, const wchar_t *buf, const wchar_t *end, int *wp) return 0; for (n = 0, i = 0; i < len; i++) - n += ct_encode_char(b + n, w - n, buf[i]); - n += ct_encode_char(b + n, w - n, end[1]); + n += ct_encode_char(b + n, (size_t)(w - n), buf[i]); + n += ct_encode_char(b + n, (size_t)(w - n), end[1]); b[n] = '\0'; /* @@ -1,4 +1,4 @@ -/* $NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $ */ +/* $NetBSD: map.c,v 1.52 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.52 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -913,21 +913,21 @@ map_init(EditLine *el) EL_ABORT((el->errfile, "Vi insert map incorrect\n")); #endif - el->el_map.alt = el_malloc(sizeof(*el->el_map.alt) * N_KEYS); + el->el_map.alt = el_calloc(N_KEYS, sizeof(*el->el_map.alt)); if (el->el_map.alt == NULL) return -1; - el->el_map.key = el_malloc(sizeof(*el->el_map.key) * N_KEYS); + el->el_map.key = el_calloc(N_KEYS, sizeof(*el->el_map.key)); if (el->el_map.key == NULL) return -1; el->el_map.emacs = el_map_emacs; el->el_map.vic = el_map_vi_command; el->el_map.vii = el_map_vi_insert; - el->el_map.help = el_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS); + el->el_map.help = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.help)); if (el->el_map.help == NULL) return -1; (void) memcpy(el->el_map.help, el_func_help, sizeof(*el->el_map.help) * EL_NUM_FCNS); - el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS); + el->el_map.func = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.func)); if (el->el_map.func == NULL) return -1; memcpy(el->el_map.func, el_func, sizeof(*el->el_map.func) diff --git a/src/parse.c b/src/parse.c index 75c611e..2620f41 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.41 2018/11/29 03:10:20 christos Exp $ */ +/* $NetBSD: parse.c,v 1.42 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: parse.c,v 1.41 2018/11/29 03:10:20 christos Exp $"); +__RCSID("$NetBSD: parse.c,v 1.42 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -112,7 +112,7 @@ el_wparse(EditLine *el, int argc, const wchar_t *argv[]) if (ptr == argv[0]) return 0; l = (size_t)(ptr - argv[0]); - tprog = el_malloc((l + 1) * sizeof(*tprog)); + tprog = el_calloc(l + 1, sizeof(*tprog)); if (tprog == NULL) return 0; (void) wcsncpy(tprog, argv[0], l); @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.105 2018/11/25 16:21:04 christos Exp $ */ +/* $NetBSD: read.c,v 1.106 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.105 2018/11/25 16:21:04 christos Exp $"); +__RCSID("$NetBSD: read.c,v 1.106 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -89,8 +89,7 @@ read_init(EditLine *el) return -1; ma = &el->el_read->macros; - if ((ma->macro = el_malloc(EL_MAXMACRO * - sizeof(*ma->macro))) == NULL) { + if ((ma->macro = el_calloc(EL_MAXMACRO, sizeof(*ma->macro))) == NULL) { free(el->el_read); return -1; } diff --git a/src/readline.c b/src/readline.c index 778e6c2..72da61d 100644 --- a/src/readline.c +++ b/src/readline.c @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.151 2019/02/15 23:20:35 christos Exp $ */ +/* $NetBSD: readline.c,v 1.159 2019/10/09 14:31:07 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.151 2019/02/15 23:20:35 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.159 2019/10/09 14:31:07 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/types.h> @@ -111,7 +111,7 @@ int rl_inhibit_completion = 0; int rl_attempted_completion_over = 0; const char *rl_basic_word_break_characters = break_chars; char *rl_completer_word_break_characters = NULL; -char *rl_completer_quote_characters = NULL; +const char *rl_completer_quote_characters = NULL; rl_compentry_func_t *rl_completion_entry_function = NULL; char *(*rl_completion_word_break_hook)(void) = NULL; rl_completion_func_t *rl_attempted_completion_function = NULL; @@ -262,8 +262,14 @@ rl_set_prompt(const char *prompt) if (rl_prompt == NULL) return -1; - while ((p = strchr(rl_prompt, RL_PROMPT_END_IGNORE)) != NULL) - *p = RL_PROMPT_START_IGNORE; + while ((p = strchr(rl_prompt, RL_PROMPT_END_IGNORE)) != NULL) { + /* Remove adjacent end/start markers to avoid double-escapes. */ + if (p[1] == RL_PROMPT_START_IGNORE) { + memmove(p, p + 2, 1 + strlen(p + 2)); + } else { + *p = RL_PROMPT_START_IGNORE; + } + } return 0; } @@ -513,13 +519,13 @@ _rl_compat_sub(const char *str, const char *what, const char *with, } else s++; } - r = result = el_malloc((len + 1) * sizeof(*r)); + r = result = el_calloc(len + 1, sizeof(*r)); if (result == NULL) return NULL; s = str; while (*s) { if (*s == *what && !strncmp(s, what, what_len)) { - (void)strncpy(r, with, with_len); + memcpy(r, with, with_len); r += with_len; s += what_len; if (!globally) { @@ -603,10 +609,9 @@ get_history_event(const char *cmd, int *cindex, int qchar) else if (len == 0) return NULL; else { - if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL) + if ((pat = el_calloc(len + 1, sizeof(*pat))) == NULL) return NULL; - (void)strncpy(pat, cmd + begin, len); - pat[len] = '\0'; + (void)strlcpy(pat, cmd + begin, len + 1); } if (history(h, &ev, H_CURR) != 0) { @@ -697,11 +702,10 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen, } else { if (command[offs + 1] == '#') { /* use command so far */ - if ((aptr = el_malloc((offs + 1) * sizeof(*aptr))) + if ((aptr = el_calloc(offs + 1, sizeof(*aptr))) == NULL) return -1; - (void)strncpy(aptr, command, offs); - aptr[offs] = '\0'; + (void)strlcpy(aptr, command, offs + 1); idx = 1; } else { int qchar; @@ -931,7 +935,7 @@ history_expand(char *str, char **output) *output = NULL; if (str[0] == history_subst_char) { /* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */ - *output = el_malloc((strlen(str) + 4 + 1) * sizeof(**output)); + *output = el_calloc(strlen(str) + 4 + 1, sizeof(**output)); if (*output == NULL) return 0; (*output)[0] = (*output)[1] = history_expansion_char; @@ -958,9 +962,8 @@ history_expand(char *str, char **output) } \ result = nresult; \ } \ - (void)strncpy(&result[idx], what, len); \ + (void)strlcpy(&result[idx], what, len + 1); \ idx += len; \ - result[idx] = '\0'; \ } result = NULL; @@ -1079,7 +1082,7 @@ history_arg_extract(int start, int end, const char *str) for (i = (size_t)start, len = 0; i <= (size_t)end; i++) len += strlen(arr[i]) + 1; len++; - result = el_malloc(len * sizeof(*result)); + result = el_calloc(len, sizeof(*result)); if (result == NULL) goto out; @@ -1141,15 +1144,14 @@ history_tokenize(const char *str) result = nresult; } len = (size_t)i - (size_t)start; - temp = el_malloc((size_t)(len + 1) * sizeof(*temp)); + temp = el_calloc(len + 1, sizeof(*temp)); if (temp == NULL) { for (i = 0; i < idx; i++) el_free(result[i]); el_free(result); return NULL; } - (void)strncpy(temp, &str[start], len); - temp[len] = '\0'; + (void)strlcpy(temp, &str[start], len + 1); result[idx++] = temp; result[idx] = NULL; if (str[i]) @@ -1475,8 +1477,10 @@ add_history(const char *line) (void)history(h, &ev, H_GETSIZE); if (ev.num == history_length) history_base++; - else + else { + history_offset++; history_length = ev.num; + } return 0; } @@ -2227,15 +2231,16 @@ _rl_update_pos(void) rl_point = (int)(li->cursor - li->buffer); rl_end = (int)(li->lastchar - li->buffer); + rl_line_buffer[rl_end] = '\0'; } void rl_get_screen_size(int *rows, int *cols) { if (rows) - el_get(e, EL_GETTC, "li", rows, (void *)0); + el_get(e, EL_GETTC, "li", rows); if (cols) - el_get(e, EL_GETTC, "co", cols, (void *)0); + el_get(e, EL_GETTC, "co", cols); } void @@ -2256,7 +2261,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun) len = 1; max = 10; - if ((list = el_malloc(max * sizeof(*list))) == NULL) + if ((list = el_calloc(max, sizeof(*list))) == NULL) return NULL; while ((match = (*fun)(str, (int)(len - 1))) != NULL) { @@ -2291,7 +2296,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun) if ((list[0] = strdup(str)) == NULL) goto out; } else { - if ((list[0] = el_malloc((min + 1) * sizeof(*list[0]))) == NULL) + if ((list[0] = el_calloc(min + 1, sizeof(*list[0]))) == NULL) goto out; (void)memcpy(list[0], list[1], min); list[0][min] = '\0'; diff --git a/src/search.c b/src/search.c index aec87fe..38ddff6 100644 --- a/src/search.c +++ b/src/search.c @@ -1,4 +1,4 @@ -/* $NetBSD: search.c,v 1.48 2018/02/26 17:36:14 christos Exp $ */ +/* $NetBSD: search.c,v 1.49 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: search.c,v 1.48 2018/02/26 17:36:14 christos Exp $"); +__RCSID("$NetBSD: search.c,v 1.49 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -71,7 +71,7 @@ libedit_private int search_init(EditLine *el) { - el->el_search.patbuf = el_malloc(EL_BUFSIZ * + el->el_search.patbuf = el_calloc(EL_BUFSIZ, sizeof(*el->el_search.patbuf)); if (el->el_search.patbuf == NULL) return -1; diff --git a/src/terminal.c b/src/terminal.c index d8db3d1..1f734e5 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1,4 +1,4 @@ -/* $NetBSD: terminal.c,v 1.35 2019/02/15 23:20:35 christos Exp $ */ +/* $NetBSD: terminal.c,v 1.40 2019/09/15 21:09:11 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; #else -__RCSID("$NetBSD: terminal.c,v 1.35 2019/02/15 23:20:35 christos Exp $"); +__RCSID("$NetBSD: terminal.c,v 1.40 2019/09/15 21:09:11 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -269,31 +269,27 @@ libedit_private int terminal_init(EditLine *el) { - el->el_terminal.t_buf = el_malloc(TC_BUFSIZE * + el->el_terminal.t_buf = el_calloc(TC_BUFSIZE, sizeof(*el->el_terminal.t_buf)); if (el->el_terminal.t_buf == NULL) goto fail1; - el->el_terminal.t_cap = el_malloc(TC_BUFSIZE * + el->el_terminal.t_cap = el_calloc(TC_BUFSIZE, sizeof(*el->el_terminal.t_cap)); if (el->el_terminal.t_cap == NULL) goto fail2; - el->el_terminal.t_fkey = el_malloc(A_K_NKEYS * + el->el_terminal.t_fkey = el_calloc(A_K_NKEYS, sizeof(*el->el_terminal.t_fkey)); if (el->el_terminal.t_fkey == NULL) goto fail3; el->el_terminal.t_loc = 0; - el->el_terminal.t_str = el_malloc(T_str * + el->el_terminal.t_str = el_calloc(T_str, sizeof(*el->el_terminal.t_str)); if (el->el_terminal.t_str == NULL) goto fail4; - (void) memset(el->el_terminal.t_str, 0, T_str * - sizeof(*el->el_terminal.t_str)); - el->el_terminal.t_val = el_malloc(T_val * + el->el_terminal.t_val = el_calloc(T_val, sizeof(*el->el_terminal.t_val)); if (el->el_terminal.t_val == NULL) goto fail5; - (void) memset(el->el_terminal.t_val, 0, T_val * - sizeof(*el->el_terminal.t_val)); (void) terminal_set(el, NULL); terminal_init_arrow(el); return 0; @@ -426,11 +422,11 @@ terminal_alloc_buffer(EditLine *el) coord_t *c = &el->el_terminal.t_size; int i; - b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); + b = el_calloc((size_t)(c->v + 1), sizeof(*b)); if (b == NULL) return NULL; for (i = 0; i < c->v; i++) { - b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1)); + b[i] = el_calloc((size_t)(c->h + 1), sizeof(**b)); if (b[i] == NULL) { while (--i >= 0) el_free(b[i]); @@ -509,15 +505,14 @@ terminal_move_to_line(EditLine *el, int where) return; } if ((del = where - el->el_cursor.v) > 0) { - if ((del > 1) && GoodStr(T_DO)) { - terminal_tputs(el, tgoto(Str(T_DO), del, del), del); - del = 0; - } else { - for (; del > 0; del--) - terminal__putc(el, '\n'); - /* because the \n will become \r\n */ - el->el_cursor.h = 0; - } + /* + * We don't use DO here because some terminals are buggy + * if the destination is beyond bottom of the screen. + */ + for (; del > 0; del--) + terminal__putc(el, '\n'); + /* because the \n will become \r\n */ + el->el_cursor.h = 0; } else { /* del < 0 */ if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up))) terminal_tputs(el, tgoto(Str(T_UP), -del, -del), -del); @@ -966,9 +961,10 @@ terminal_get_size(EditLine *el, int *lins, int *cols) libedit_private int terminal_change_size(EditLine *el, int lins, int cols) { + coord_t cur = el->el_cursor; /* - * Just in case - */ + * Just in case + */ Val(T_co) = (cols < 2) ? 80 : cols; Val(T_li) = (lins < 1) ? 24 : lins; @@ -976,6 +972,7 @@ terminal_change_size(EditLine *el, int lins, int cols) if (terminal_rebuffer_display(el) == -1) return -1; re_clear_display(el); + el->el_cursor = cur; return 0; } @@ -1227,7 +1224,7 @@ terminal__putc(EditLine *el, wint_t c) { char buf[MB_LEN_MAX +1]; ssize_t i; - if (c == (wint_t)MB_FILL_CHAR) + if (c == MB_FILL_CHAR) return 0; if (c & EL_LITERAL) return fputs(literal_get(el, c), el->el_outfile); @@ -1,4 +1,4 @@ -/* $NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $ */ +/* $NetBSD: vi.c,v 1.63 2019/07/23 10:18:52 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $"); +__RCSID("$NetBSD: vi.c,v 1.63 2019/07/23 10:18:52 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -1019,10 +1019,10 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__))) return CC_ERROR; len = (size_t)(el->el_line.lastchar - el->el_line.buffer); #define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX) - cp = el_malloc(TMP_BUFSIZ * sizeof(*cp)); + cp = el_calloc(TMP_BUFSIZ, sizeof(*cp)); if (cp == NULL) goto error; - line = el_malloc(len * sizeof(*line) + 1); + line = el_calloc(len + 1, sizeof(*line)); if (line == NULL) goto error; wcsncpy(line, el->el_line.buffer, len); |