Author: bapt
Date: Fri Jan  9 07:40:56 2015
New Revision: 276881
URL: https://svnweb.freebsd.org/changeset/base/276881

Log:
  Synchronize libedit with NetBSD and activate UTF-8 support [1]
  
  Differences with NetBSD
  Reapply our local patches on top of it
  Fix Unicode environement detection
  Fix reading a line in unicode environment.
  It allows /bin/sh to works in UTF-8 envs
  
  Differential Revision:        https://reviews.freebsd.org/D1455
  Reviewed by:  jilles, pfg
  Obtained from:        NetBSD [1]
  MFC after:    1 month
  Relnotes:     yes

Added:
  head/lib/libedit/TEST/rl1.c   (contents, props changed)
  head/lib/libedit/TEST/wtc1.c   (contents, props changed)
  head/lib/libedit/chartype.c   (contents, props changed)
  head/lib/libedit/config.h   (contents, props changed)
  head/lib/libedit/eln.c   (contents, props changed)
  head/lib/libedit/keymacro.c
     - copied, changed from r276637, head/lib/libedit/key.c
  head/lib/libedit/keymacro.h
     - copied, changed from r276637, head/lib/libedit/key.h
  head/lib/libedit/terminal.c
     - copied, changed from r276637, head/lib/libedit/term.c
  head/lib/libedit/terminal.h
     - copied, changed from r276637, head/lib/libedit/term.h
Deleted:
  head/lib/libedit/key.c
  head/lib/libedit/key.h
  head/lib/libedit/term.c
  head/lib/libedit/term.h
Modified:
  head/lib/libedit/Makefile
  head/lib/libedit/TEST/tc1.c
  head/lib/libedit/chared.c
  head/lib/libedit/chared.h
  head/lib/libedit/chartype.h
  head/lib/libedit/common.c
  head/lib/libedit/edit/readline/readline.h
  head/lib/libedit/editline.3
  head/lib/libedit/editrc.5
  head/lib/libedit/el.c
  head/lib/libedit/el.h
  head/lib/libedit/emacs.c
  head/lib/libedit/filecomplete.c
  head/lib/libedit/filecomplete.h
  head/lib/libedit/hist.c
  head/lib/libedit/hist.h
  head/lib/libedit/histedit.h
  head/lib/libedit/history.c
  head/lib/libedit/makelist
  head/lib/libedit/map.c
  head/lib/libedit/map.h
  head/lib/libedit/parse.c
  head/lib/libedit/parse.h
  head/lib/libedit/prompt.c
  head/lib/libedit/prompt.h
  head/lib/libedit/read.c
  head/lib/libedit/read.h
  head/lib/libedit/readline.c
  head/lib/libedit/refresh.c
  head/lib/libedit/refresh.h
  head/lib/libedit/search.c
  head/lib/libedit/search.h
  head/lib/libedit/sig.c
  head/lib/libedit/sig.h
  head/lib/libedit/sys.h
  head/lib/libedit/tokenizer.c
  head/lib/libedit/tty.c
  head/lib/libedit/tty.h
  head/lib/libedit/vi.c

Modified: head/lib/libedit/Makefile
==============================================================================
--- head/lib/libedit/Makefile   Fri Jan  9 07:32:43 2015        (r276880)
+++ head/lib/libedit/Makefile   Fri Jan  9 07:40:56 2015        (r276881)
@@ -7,8 +7,8 @@ SHLIB_MAJOR=    7
 SHLIBDIR?= /lib
 
 OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c \
-       hist.c key.c map.c \
-       parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c
+       hist.c keymacro.c map.c chartype.c \
+       parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c
 
 LIBADD=        ncursesw
 
@@ -34,7 +34,10 @@ CLEANFILES+= common.h editline.c emacs.h
 
 INCS=  histedit.h
 
-CFLAGS+= -I. -I${.CURDIR} -I${.CURDIR}/edit
+OSRCS+=        eln.c
+SRCS+= tokenizern.c historyn.c
+CLEANFILES+=   tokenizern.c historyn.c
+CFLAGS+= -I. -I${.CURDIR} -I${.CURDIR}/edit -DWIDECHAR
 CFLAGS+= #-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
 CFLAGS+= #-DDEBUG_PASTE -DDEBUG_EDIT
 
@@ -65,6 +68,12 @@ help.h: ${ASRC} makelist
 editline.c: ${OSRCS}
        sh ${.CURDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}
 
+tokenizern.c: makelist Makefile
+       sh ${.CURDIR}/makelist -n tokenizer.c > ${.TARGET}
+
+historyn.c: makelist Makefile
+       sh ${.CURDIR}/makelist -n history.c > ${.TARGET}
+
 # minimal dependency to make "make depend" optional
 editline.o editline.po editline.So editline.ln:        \
        common.h emacs.h fcns.c fcns.h help.c help.h vi.h

Added: head/lib/libedit/TEST/rl1.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libedit/TEST/rl1.c Fri Jan  9 07:40:56 2015        (r276881)
@@ -0,0 +1,53 @@
+/*     $NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $");
+#endif /* not lint  */
+__FBSDID("$FreeBSD$");
+
+/*
+ * test.c: A little test program
+ */
+#include <stdio.h>
+#include <readline/readline.h>
+
+int
+main(int argc, char *argv[])
+{
+       char *p;
+       while ((p = readline("hi$")) != NULL) {
+               add_history(p);
+               printf("%d %s\n", history_length, p);
+       }
+       return 0;
+}

Modified: head/lib/libedit/TEST/tc1.c
==============================================================================
--- head/lib/libedit/TEST/tc1.c Fri Jan  9 07:32:43 2015        (r276880)
+++ head/lib/libedit/TEST/tc1.c Fri Jan  9 07:40:56 2015        (r276881)
@@ -1,3 +1,5 @@
+/*     $NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $ */
+
 /*-
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -30,22 +32,24 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
+#include "config.h"
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
        The Regents of the University of California.  All rights reserved.\n");
 #endif /* not lint */
 
 #if !defined(lint) && !defined(SCCSID)
+#if 0
 static char sccsid[] = "@(#)test.c     8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $");
+#endif
 #endif /* not lint && not SCCSID */
-__RCSID("$NetBSD: test.c,v 1.3 2009/07/17 12:25:52 christos Exp $");
 __FBSDID("$FreeBSD$");
 
 /*
  * test.c: A little test program
  */
-#include "sys.h"
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
@@ -54,6 +58,7 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <unistd.h>
 #include <dirent.h>
+#include <locale.h>
 
 #include "histedit.h"
 
@@ -68,7 +73,7 @@ static        void    sig(int);
 static char *
 prompt(EditLine *el)
 {
-       static char a[] = "\1\e[7m\1Edit$\1\e[0m\1 ";
+       static char a[] = "\1\033[7m\1Edit$\1\033[0m\1 ";
        static char b[] = "Edit> ";
 
        return (continuation ? b : a);
@@ -88,6 +93,7 @@ complete(EditLine *el, int ch)
        const char* ptr;
        const LineInfo *lf = el_line(el);
        int len;
+       int res = CC_ERROR;
 
        /*
         * Find the last word
@@ -101,16 +107,16 @@ complete(EditLine *el, int ch)
                if (len > strlen(dp->d_name))
                        continue;
                if (strncmp(dp->d_name, ptr, len) == 0) {
-                       closedir(dd);
                        if (el_insertstr(el, &dp->d_name[len]) == -1)
-                               return (CC_ERROR);
+                               res = CC_ERROR;
                        else
-                               return (CC_REFRESH);
+                               res = CC_REFRESH;
+                       break;
                }
        }
 
        closedir(dd);
-       return (CC_ERROR);
+       return res;
 }
 
 int
@@ -127,6 +133,7 @@ main(int argc, char *argv[])
        History *hist;
        HistEvent ev;
 
+       (void) setlocale(LC_CTYPE, "");
        (void) signal(SIGINT, sig);
        (void) signal(SIGQUIT, sig);
        (void) signal(SIGHUP, sig);

Added: head/lib/libedit/TEST/wtc1.c
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libedit/TEST/wtc1.c        Fri Jan  9 07:40:56 2015        
(r276881)
@@ -0,0 +1,281 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <limits.h>
+#include <locale.h>
+
+#include "../histedit.h"
+
+
+static int continuation;
+volatile sig_atomic_t gotsig;
+static const char hfile[] = ".whistory";
+
+static wchar_t *
+prompt(EditLine *el)
+{
+       static wchar_t a[] = L"\1\033[7m\1Edit$\1\033[0m\1 ";
+       static wchar_t b[] = L"Edit> ";
+
+       return continuation ? b : a;
+}
+
+
+static void
+sig(int i)
+{
+       gotsig = i;
+}
+
+const char *
+my_wcstombs(const wchar_t *wstr)
+{
+       static struct {
+               char *str;
+               int len;
+       } buf;
+
+       int needed = wcstombs(0, wstr, 0) + 1;
+       if (needed > buf.len) {
+               buf.str = malloc(needed);
+               buf.len = needed;
+       }
+       wcstombs(buf.str, wstr, needed);
+       buf.str[needed - 1] = 0;
+
+       return buf.str;
+}
+
+
+static unsigned char
+complete(EditLine *el, int ch)
+{
+       DIR *dd = opendir(".");
+       struct dirent *dp;
+       const wchar_t *ptr;
+       char *buf, *bptr;
+       const LineInfoW *lf = el_wline(el);
+       int len, mblen, i;
+       unsigned char res = 0;
+       wchar_t dir[1024];
+
+       /* Find the last word */
+       for (ptr = lf->cursor -1; !iswspace(*ptr) && ptr > lf->buffer; --ptr)
+               continue;
+       len = lf->cursor - ++ptr;
+
+       /* Convert last word to multibyte encoding, so we can compare to it */
+       wctomb(NULL, 0); /* Reset shift state */
+       mblen = MB_LEN_MAX * len + 1;
+       buf = bptr = malloc(mblen);
+       if (buf == NULL)
+               err(1, "malloc");
+       for (i = 0; i < len; ++i) {
+               /* Note: really should test for -1 return from wctomb */
+               bptr += wctomb(bptr, ptr[i]);
+       }
+       *bptr = 0; /* Terminate multibyte string */
+       mblen = bptr - buf;
+
+       /* Scan directory for matching name */
+       for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
+               if (mblen > strlen(dp->d_name))
+                       continue;
+               if (strncmp(dp->d_name, buf, mblen) == 0) {
+                       mbstowcs(dir, &dp->d_name[mblen],
+                           sizeof(dir) / sizeof(*dir));
+                       if (el_winsertstr(el, dir) == -1)
+                               res = CC_ERROR;
+                       else
+                               res = CC_REFRESH;
+                       break;
+               }
+       }
+
+       closedir(dd);
+       free(buf);
+       return res;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+       EditLine *el = NULL;
+       int numc, ncontinuation;
+       const wchar_t *line;
+       TokenizerW *tok;
+       HistoryW *hist;
+       HistEventW ev;
+#ifdef DEBUG
+       int i;
+#endif
+
+       setlocale(LC_ALL, "");
+
+       (void)signal(SIGINT,  sig);
+       (void)signal(SIGQUIT, sig);
+       (void)signal(SIGHUP,  sig);
+       (void)signal(SIGTERM, sig);
+
+       hist = history_winit();         /* Init built-in history     */
+       history_w(hist, &ev, H_SETSIZE, 100);   /* Remember 100 events       */
+       history_w(hist, &ev, H_LOAD, hfile);
+
+       tok = tok_winit(NULL);                  /* Init the tokenizer        */
+
+       el = el_init(argv[0], stdin, stdout, stderr);
+
+       el_wset(el, EL_EDITOR, L"vi");          /* Default editor is vi      */
+       el_wset(el, EL_SIGNAL, 1);              /* Handle signals gracefully */
+       el_wset(el, EL_PROMPT_ESC, prompt, '\1'); /* Set the prompt function */
+
+       el_wset(el, EL_HIST, history_w, hist);  /* FIXME - history_w? */
+
+                                       /* Add a user-defined function  */
+       el_wset(el, EL_ADDFN, L"ed-complete", L"Complete argument", complete);
+
+                                       /* Bind <tab> to it */
+       el_wset(el, EL_BIND, L"^I", L"ed-complete", NULL);
+
+       /*
+       * Bind j, k in vi command mode to previous and next line, instead
+       * of previous and next history.
+       */
+       el_wset(el, EL_BIND, L"-a", L"k", L"ed-prev-line", NULL);
+       el_wset(el, EL_BIND, L"-a", L"j", L"ed-next-line", NULL);
+
+       /* Source the user's defaults file. */
+       el_source(el, NULL);
+
+       while((line = el_wgets(el, &numc)) != NULL && numc != 0) {
+               int ac, cc, co, rc;
+               const wchar_t **av;
+
+               const LineInfoW *li;
+               li = el_wline(el);
+
+#ifdef DEBUG
+               (void)fwprintf(stderr, L"==> got %d %ls", numc, line);
+               (void)fwprintf(stderr, L"  > li `%.*ls_%.*ls'\n",
+                   (li->cursor - li->buffer), li->buffer,
+                   (li->lastchar - 1 - li->cursor),
+                   (li->cursor >= li->lastchar) ? L"" : li->cursor);
+#endif
+
+               if (gotsig) {
+                       (void)fprintf(stderr, "Got signal %d.\n", (int)gotsig);
+                       gotsig = 0;
+                       el_reset(el);
+               }
+
+               if(!continuation && numc == 1)
+                       continue;       /* Only got a linefeed */
+
+               ac = cc = co = 0;
+               ncontinuation = tok_wline(tok, li, &ac, &av, &cc, &co);
+               if (ncontinuation < 0) {
+                       (void) fprintf(stderr, "Internal error\n");
+                       continuation = 0;
+                       continue;
+               }
+
+#ifdef DEBUG
+               (void)fprintf(stderr, "  > nc %d ac %d cc %d co %d\n",
+                       ncontinuation, ac, cc, co);
+#endif
+               history_w(hist, &ev, continuation ? H_APPEND : H_ENTER, line);
+
+               continuation = ncontinuation;
+               ncontinuation = 0;
+               if(continuation)
+                       continue;
+
+#ifdef DEBUG
+               for (i = 0; i < ac; ++i) {
+                       (void)fwprintf(stderr, L"  > arg# %2d ", i);
+                       if (i != cc)
+                               (void)fwprintf(stderr, L"`%ls'\n", av[i]);
+                       else
+                               (void)fwprintf(stderr, L"`%.*ls_%ls'\n",
+                                   co, av[i], av[i] + co);
+               }
+#endif
+
+               if (wcscmp (av[0], L"history") == 0) {
+                       switch(ac) {
+                       case 1:
+                               for(rc = history_w(hist, &ev, H_LAST);
+                                    rc != -1;
+                                    rc = history_w(hist, &ev, H_PREV))
+                                       (void)fwprintf(stdout, L"%4d %ls",
+                                            ev.num, ev.str);
+                               break;
+                       case 2:
+                               if (wcscmp(av[1], L"clear") == 0)
+                                       history_w(hist, &ev, H_CLEAR);
+                               else
+                                       goto badhist;
+                               break;
+                       case 3:
+                               if (wcscmp(av[1], L"load") == 0)
+                                       history_w(hist, &ev, H_LOAD,
+                                           my_wcstombs(av[2]));
+                               else if (wcscmp(av[1], L"save") == 0)
+                                       history_w(hist, &ev, H_SAVE,
+                                           my_wcstombs(av[2]));
+                               else
+                                       goto badhist;
+                               break;
+                       badhist:
+                       default:
+                               (void)fprintf(stderr,
+                                   "Bad history arguments\n");
+                               break;
+                       }
+               } else if (el_wparse(el, ac, av) == -1) {
+                       switch (fork()) {
+                       case 0: {
+                               Tokenizer *ntok = tok_init(NULL);
+                               int nargc;
+                               const char **nav;
+                               tok_str(ntok, my_wcstombs(line), &nargc, &nav);
+                               execvp(nav[0],(char **)nav);
+                               perror(nav[0]);
+                               _exit(1);
+                               /* NOTREACHED */
+                               break;
+                       }
+                       case -1:
+                               perror("fork");
+                               break;
+                       default:
+                               if (wait(&rc) == -1)
+                                       perror("wait");
+                               (void)fprintf(stderr, "Exit %x\n", rc);
+                               break;
+                       }
+               }
+
+               tok_wreset(tok);
+       }
+
+       el_end(el);
+       tok_wend(tok);
+       history_w(hist, &ev, H_SAVE, hfile);
+       history_wend(hist);
+
+       fprintf(stdout, "\n");
+       return 0;
+}
+
+

Modified: head/lib/libedit/chared.c
==============================================================================
--- head/lib/libedit/chared.c   Fri Jan  9 07:32:43 2015        (r276880)
+++ head/lib/libedit/chared.c   Fri Jan  9 07:40:56 2015        (r276881)
@@ -1,3 +1,5 @@
+/*     $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $     */
+
 /*-
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -28,12 +30,15 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- *
- *     $NetBSD: chared.c,v 1.27 2009/02/15 21:55:23 christos Exp $
  */
 
+#include "config.h"
 #if !defined(lint) && !defined(SCCSID)
+#if 0
 static char sccsid[] = "@(#)chared.c   8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $");
+#endif
 #endif /* not lint && not SCCSID */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -41,12 +46,10 @@ __FBSDID("$FreeBSD$");
 /*
  * chared.c: Character editor utilities
  */
-#include "sys.h"
-
 #include <stdlib.h>
 #include "el.h"
 
-private void ch__clearmacro(EditLine *);
+private void ch__clearmacro (EditLine *);
 
 /* value to leave unused in line buffer */
 #define        EL_LEAVE        2
@@ -62,10 +65,10 @@ cv_undo(EditLine *el)
        size_t size;
 
        /* Save entire line for undo */
-       size = el->el_line.lastchar - el->el_line.buffer;
-       vu->len = size;
+       size = (size_t)(el->el_line.lastchar - el->el_line.buffer);
+       vu->len = (ssize_t)size;
        vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
-       memcpy(vu->buf, el->el_line.buffer, size);
+       (void)memcpy(vu->buf, el->el_line.buffer, size * sizeof(*vu->buf));
 
        /* save command info for redo */
        r->count = el->el_state.doingarg ? el->el_state.argument : 0;
@@ -79,11 +82,11 @@ cv_undo(EditLine *el)
  *     Save yank/delete data for paste
  */
 protected void
-cv_yank(EditLine *el, const char *ptr, int size)
+cv_yank(EditLine *el, const Char *ptr, int size)
 {
        c_kill_t *k = &el->el_chared.c_kill;
 
-       memcpy(k->buf, ptr, (size_t)size);
+       (void)memcpy(k->buf, ptr, (size_t)size * sizeof(*k->buf));
        k->last = k->buf + size;
 }
 
@@ -94,7 +97,7 @@ cv_yank(EditLine *el, const char *ptr, i
 protected void
 c_insert(EditLine *el, int num)
 {
-       char *cp;
+       Char *cp;
 
        if (el->el_line.lastchar + num >= el->el_line.limit) {
                if (!ch_enlargebufs(el, (size_t)num))
@@ -126,7 +129,7 @@ c_delafter(EditLine *el, int num)
        }
 
        if (num > 0) {
-               char *cp;
+               Char *cp;
 
                for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
                        *cp = cp[num];
@@ -142,7 +145,7 @@ c_delafter(EditLine *el, int num)
 protected void
 c_delafter1(EditLine *el)
 {
-       char *cp;
+       Char *cp;
 
        for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
                *cp = cp[1];
@@ -167,7 +170,7 @@ c_delbefore(EditLine *el, int num)
        }
 
        if (num > 0) {
-               char *cp;
+               Char *cp;
 
                for (cp = el->el_line.cursor - num;
                    cp <= el->el_line.lastchar;
@@ -185,7 +188,7 @@ c_delbefore(EditLine *el, int num)
 protected void
 c_delbefore1(EditLine *el)
 {
-       char *cp;
+       Char *cp;
 
        for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
                *cp = cp[1];
@@ -198,9 +201,9 @@ c_delbefore1(EditLine *el)
  *     Return if p is part of a word according to emacs
  */
 protected int
-ce__isword(int p)
+ce__isword(Int p)
 {
-       return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL);
+       return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
 }
 
 
@@ -208,11 +211,11 @@ ce__isword(int p)
  *     Return if p is part of a word according to vi
  */
 protected int
-cv__isword(int p)
+cv__isword(Int p)
 {
-       if (isalnum(p) || p == '_')
+       if (Isalnum(p) || p == '_')
                return 1;
-       if (isgraph(p))
+       if (Isgraph(p))
                return 2;
        return 0;
 }
@@ -222,24 +225,24 @@ cv__isword(int p)
  *     Return if p is part of a big word according to vi
  */
 protected int
-cv__isWord(int p)
+cv__isWord(Int p)
 {
-       return (!isspace(p));
+       return !Isspace(p);
 }
 
 
 /* c__prev_word():
  *     Find the previous word
  */
-protected char *
-c__prev_word(char *p, char *low, int n, int (*wtest)(int))
+protected Char *
+c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
 {
        p--;
 
        while (n--) {
-               while ((p >= low) && !(*wtest)((unsigned char) *p))
+               while ((p >= low) && !(*wtest)(*p))
                        p--;
-               while ((p >= low) && (*wtest)((unsigned char) *p))
+               while ((p >= low) && (*wtest)(*p))
                        p--;
        }
 
@@ -248,117 +251,83 @@ c__prev_word(char *p, char *low, int n, 
        if (p < low)
                p = low;
        /* cp now points where we want it */
-       return (p);
+       return p;
 }
 
 
 /* c__next_word():
  *     Find the next word
  */
-protected char *
-c__next_word(char *p, char *high, int n, int (*wtest)(int))
+protected Char *
+c__next_word(Char *p, Char *high, int n, int (*wtest)(Int))
 {
        while (n--) {
-               while ((p < high) && !(*wtest)((unsigned char) *p))
+               while ((p < high) && !(*wtest)(*p))
                        p++;
-               while ((p < high) && (*wtest)((unsigned char) *p))
+               while ((p < high) && (*wtest)(*p))
                        p++;
        }
        if (p > high)
                p = high;
        /* p now points where we want it */
-       return (p);
+       return p;
 }
 
 /* cv_next_word():
  *     Find the next word vi style
  */
-protected char *
-cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
+protected Char *
+cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int))
 {
        int test;
 
        while (n--) {
-               test = (*wtest)((unsigned char) *p);
-               while ((p < high) && (*wtest)((unsigned char) *p) == test)
+               test = (*wtest)(*p);
+               while ((p < high) && (*wtest)(*p) == test)
                        p++;
                /*
                 * vi historically deletes with cw only the word preserving the
                 * trailing whitespace! This is not what 'w' does..
                 */
                if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
-                       while ((p < high) && isspace((unsigned char) *p))
+                       while ((p < high) && Isspace(*p))
                                p++;
        }
 
        /* p now points where we want it */
        if (p > high)
-               return (high);
+               return high;
        else
-               return (p);
+               return p;
 }
 
 
 /* cv_prev_word():
  *     Find the previous word vi style
  */
-protected char *
-cv_prev_word(char *p, char *low, int n, int (*wtest)(int))
+protected Char *
+cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
 {
        int test;
 
        p--;
        while (n--) {
-               while ((p > low) && isspace((unsigned char) *p))
+               while ((p > low) && Isspace(*p))
                        p--;
-               test = (*wtest)((unsigned char) *p);
-               while ((p >= low) && (*wtest)((unsigned char) *p) == test)
+               test = (*wtest)(*p);
+               while ((p >= low) && (*wtest)(*p) == test)
                        p--;
        }
        p++;
 
        /* p now points where we want it */
        if (p < low)
-               return (low);
+               return low;
        else
-               return (p);
+               return p;
 }
 
 
-#ifdef notdef
-/* c__number():
- *     Ignore character p points to, return number appearing after that.
- *     A '$' by itself means a big number; "$-" is for negative; '^' means 1.
- *     Return p pointing to last char used.
- */
-protected char *
-c__number(
-    char *p,   /* character position */
-    int *num,  /* Return value */
-    int dval)  /* dval is the number to subtract from like $-3 */
-{
-       int i;
-       int sign = 1;
-
-       if (*++p == '^') {
-               *num = 1;
-               return (p);
-       }
-       if (*p == '$') {
-               if (*++p != '-') {
-                       *num = 0x7fffffff;      /* Handle $ */
-                       return (--p);
-               }
-               sign = -1;                      /* Handle $- */
-               ++p;
-       }
-       for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
-               continue;
-       *num = (sign < 0 ? dval - i : i);
-       return (--p);
-}
-#endif
-
 /* cv_delfini():
  *     Finish vi delete action
  */
@@ -397,48 +366,26 @@ cv_delfini(EditLine *el)
 }
 
 
-#ifdef notdef
-/* ce__endword():
- *     Go to the end of this word according to emacs
- */
-protected char *
-ce__endword(char *p, char *high, int n)
-{
-       p++;
-
-       while (n--) {
-               while ((p < high) && isspace((unsigned char) *p))
-                       p++;
-               while ((p < high) && !isspace((unsigned char) *p))
-                       p++;
-       }
-
-       p--;
-       return (p);
-}
-#endif
-
-
 /* cv__endword():
  *     Go to the end of this word according to vi
  */
-protected char *
-cv__endword(char *p, char *high, int n, int (*wtest)(int))
+protected Char *
+cv__endword(Char *p, Char *high, int n, int (*wtest)(Int))
 {
        int test;
 
        p++;
 
        while (n--) {
-               while ((p < high) && isspace((unsigned char) *p))
+               while ((p < high) && Isspace(*p))
                        p++;
 
-               test = (*wtest)((unsigned char) *p);
-               while ((p < high) && (*wtest)((unsigned char) *p) == test)
+               test = (*wtest)(*p);
+               while ((p < high) && (*wtest)(*p) == test)
                        p++;
        }
        p--;
-       return (p);
+       return p;
 }
 
 /* ch_init():
@@ -449,24 +396,29 @@ ch_init(EditLine *el)
 {
        c_macro_t *ma = &el->el_chared.c_macro;
 
-       el->el_line.buffer              = (char *) el_malloc(EL_BUFSIZ);
+       el->el_line.buffer              = el_malloc(EL_BUFSIZ *
+           sizeof(*el->el_line.buffer));
        if (el->el_line.buffer == NULL)
-               return (-1);
+               return -1;
 
-       (void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
+       (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        = (char *) el_malloc(EL_BUFSIZ);
+       el->el_chared.c_undo.buf        = el_malloc(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);
+               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        = (char *) el_malloc(EL_BUFSIZ);
+       el->el_chared.c_redo.buf        = el_malloc(EL_BUFSIZ *
+           sizeof(*el->el_chared.c_redo.buf));
        if (el->el_chared.c_redo.buf == NULL)
-               return (-1);
+               return -1;
        el->el_chared.c_redo.pos        = el->el_chared.c_redo.buf;
        el->el_chared.c_redo.lim        = el->el_chared.c_redo.buf + EL_BUFSIZ;
        el->el_chared.c_redo.cmd        = ED_UNASSIGNED;
@@ -474,12 +426,18 @@ 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        = (char *) el_malloc(EL_BUFSIZ);
+       el->el_chared.c_kill.buf        = el_malloc(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);
+               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;
+       el->el_chared.c_resizearg       = NULL;
+       el->el_chared.c_aliasfun        = NULL;
+       el->el_chared.c_aliasarg        = NULL;
 
        el->el_map.current              = el->el_map.key;
 
@@ -491,10 +449,10 @@ ch_init(EditLine *el)
 
        ma->level       = -1;
        ma->offset      = 0;
-       ma->macro       = (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
+       ma->macro       = el_malloc(EL_MAXMACRO * sizeof(*ma->macro));
        if (ma->macro == NULL)
-               return (-1);
-       return (0);
+               return -1;
+       return 0;
 }
 
 /* ch_reset():
@@ -533,7 +491,7 @@ ch__clearmacro(EditLine *el)
 {
        c_macro_t *ma = &el->el_chared.c_macro;
        while (ma->level >= 0)
-               el_free((ptr_t)ma->macro[ma->level--]);
+               el_free(ma->macro[ma->level--]);
 }
 
 /* ch_enlargebufs():
@@ -544,9 +502,9 @@ protected int
 ch_enlargebufs(EditLine *el, size_t addlen)
 {
        size_t sz, newsz;
-       char *newbuffer, *oldbuf, *oldkbuf;
+       Char *newbuffer, *oldbuf, *oldkbuf;
 
-       sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
+       sz = (size_t)(el->el_line.limit - el->el_line.buffer + EL_LEAVE);
        newsz = sz * 2;
        /*
         * If newly required length is longer than current buffer, we need
@@ -560,12 +518,12 @@ ch_enlargebufs(EditLine *el, size_t addl
        /*
         * Reallocate line buffer.
         */
-       newbuffer = el_realloc(el->el_line.buffer, newsz);
+       newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer));
        if (!newbuffer)
                return 0;
 
        /* zero the newly added memory, leave old data in */
-       (void) memset(&newbuffer[sz], 0, newsz - sz);
+       (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
            
        oldbuf = el->el_line.buffer;
 
@@ -578,12 +536,13 @@ ch_enlargebufs(EditLine *el, size_t addl
        /*
         * Reallocate kill buffer.
         */
-       newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
+       newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
+           sizeof(*newbuffer));
        if (!newbuffer)
                return 0;
 
        /* zero the newly added memory, leave old data in */
-       (void) memset(&newbuffer[sz], 0, newsz - sz);
+       (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
 
        oldkbuf = el->el_chared.c_kill.buf;
 
@@ -596,15 +555,17 @@ ch_enlargebufs(EditLine *el, size_t addl
        /*
         * Reallocate undo buffer.
         */
-       newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
+       newbuffer = el_realloc(el->el_chared.c_undo.buf,
+           newsz * sizeof(*newbuffer));
        if (!newbuffer)
                return 0;
 
        /* zero the newly added memory, leave old data in */
-       (void) memset(&newbuffer[sz], 0, newsz - sz);
+       (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
        el->el_chared.c_undo.buf = newbuffer;
 
-       newbuffer = el_realloc(el->el_chared.c_redo.buf, newsz);
+       newbuffer = el_realloc(el->el_chared.c_redo.buf,
+           newsz * sizeof(*newbuffer));
        if (!newbuffer)
                return 0;
        el->el_chared.c_redo.pos = newbuffer +
@@ -618,6 +579,8 @@ ch_enlargebufs(EditLine *el, size_t addl
 
        /* Safe to set enlarged buffer size */
        el->el_line.limit  = &el->el_line.buffer[newsz - EL_LEAVE];
+       if (el->el_chared.c_resizefun)
+               (*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
        return 1;
 }
 
@@ -627,20 +590,20 @@ ch_enlargebufs(EditLine *el, size_t addl
 protected void
 ch_end(EditLine *el)
 {
-       el_free((ptr_t) el->el_line.buffer);
+       el_free(el->el_line.buffer);
        el->el_line.buffer = NULL;
        el->el_line.limit = NULL;
-       el_free((ptr_t) el->el_chared.c_undo.buf);
+       el_free(el->el_chared.c_undo.buf);
        el->el_chared.c_undo.buf = NULL;
-       el_free((ptr_t) el->el_chared.c_redo.buf);

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to