Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit setup a callback to be invoked on resize buffers...



details:   https://anonhg.NetBSD.org/src/rev/94bca2ebc405
branches:  trunk
changeset: 757421:94bca2ebc405
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Aug 28 15:44:59 2010 +0000

description:
setup a callback to be invoked on resize buffers so that readline can
reset rl_line_buffer which unfortunately some applications use it directly.

diffstat:

 lib/libedit/chared.c   |  16 ++++++++++++++--
 lib/libedit/chared.h   |   7 ++++++-
 lib/libedit/el.c       |  11 +++++++++--
 lib/libedit/eln.c      |  11 +++++++++--
 lib/libedit/histedit.h |   3 ++-
 lib/libedit/readline.c |  23 +++++++++++++++++------
 6 files changed, 57 insertions(+), 14 deletions(-)

diffs (229 lines):

diff -r 9b08558b996f -r 94bca2ebc405 lib/libedit/chared.c
--- a/lib/libedit/chared.c      Sat Aug 28 15:42:45 2010 +0000
+++ b/lib/libedit/chared.c      Sat Aug 28 15:44:59 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $     */
+/*     $NetBSD: chared.c,v 1.29 2010/08/28 15:44:59 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.28 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.29 2010/08/28 15:44:59 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -489,6 +489,8 @@
            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_map.current              = el->el_map.key;
 
@@ -629,6 +631,8 @@
 
        /* 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;
 }
 
@@ -782,3 +786,11 @@
                return (int)(el->el_line.cursor - ptr - 1);
        }
 }
+
+protected int
+ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
+{
+       el->el_chared.c_resizefun = f;
+       el->el_chared.c_resizearg = a;
+       return 0;
+}
diff -r 9b08558b996f -r 94bca2ebc405 lib/libedit/chared.h
--- a/lib/libedit/chared.h      Sat Aug 28 15:42:45 2010 +0000
+++ b/lib/libedit/chared.h      Sat Aug 28 15:44:59 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.h,v 1.20 2010/04/15 00:57:33 christos Exp $     */
+/*     $NetBSD: chared.h,v 1.21 2010/08/28 15:44:59 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -103,6 +103,8 @@
        Char    *mark;
 } c_kill_t;
 
+typedef void (*el_zfunc_t)(EditLine *, void *);
+
 /*
  * Note that we use both data structures because the user can bind
  * commands from both editors!
@@ -113,6 +115,8 @@
        c_redo_t        c_redo;
        c_vcmd_t        c_vcmd;
        c_macro_t       c_macro;
+       el_zfunc_t      c_resizefun;
+       void *          c_resizearg;
 } el_chared_t;
 
 
@@ -160,6 +164,7 @@
 
 protected int   ch_init(EditLine *);
 protected void  ch_reset(EditLine *, int);
+protected int   ch_resizefun(EditLine *, el_zfunc_t, void *);
 protected int   ch_enlargebufs(EditLine *, size_t);
 protected void  ch_end(EditLine *);
 
diff -r 9b08558b996f -r 94bca2ebc405 lib/libedit/el.c
--- a/lib/libedit/el.c  Sat Aug 28 15:42:45 2010 +0000
+++ b/lib/libedit/el.c  Sat Aug 28 15:44:59 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.c,v 1.59 2010/04/15 00:56:40 christos Exp $ */
+/*     $NetBSD: el.c,v 1.60 2010/08/28 15:44:59 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.59 2010/04/15 00:56:40 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.60 2010/08/28 15:44:59 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -177,6 +177,13 @@
                break;
        }
 
+       case EL_RESIZE: {
+               el_zfunc_t p = va_arg(ap, el_zfunc_t);
+               void *arg = va_arg(ap, void *);
+               rv = ch_resizefun(el, p, arg);
+               break;
+       }
+
        case EL_PROMPT_ESC:
        case EL_RPROMPT_ESC: {
                el_pfunc_t p = va_arg(ap, el_pfunc_t);
diff -r 9b08558b996f -r 94bca2ebc405 lib/libedit/eln.c
--- a/lib/libedit/eln.c Sat Aug 28 15:42:45 2010 +0000
+++ b/lib/libedit/eln.c Sat Aug 28 15:44:59 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eln.c,v 1.7 2010/04/15 00:52:48 christos Exp $ */
+/*     $NetBSD: eln.c,v 1.8 2010/08/28 15:44:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: eln.c,v 1.7 2010/04/15 00:52:48 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.8 2010/08/28 15:44:59 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include "histedit.h"
@@ -118,6 +118,13 @@
                break;
        }
 
+       case EL_RESIZE: {
+               el_zfunc_t p = va_arg(ap, el_zfunc_t);
+               void *arg = va_arg(ap, void *);
+               ret = ch_resizefun(el, p, arg);
+               break;
+       }
+
        case EL_TERMINAL:       /* const char * */
                ret = el_wset(el, op, va_arg(ap, char *));
                break;
diff -r 9b08558b996f -r 94bca2ebc405 lib/libedit/histedit.h
--- a/lib/libedit/histedit.h    Sat Aug 28 15:42:45 2010 +0000
+++ b/lib/libedit/histedit.h    Sat Aug 28 15:44:59 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.h,v 1.46 2010/04/15 00:50:03 christos Exp $   */
+/*     $NetBSD: histedit.h,v 1.47 2010/08/28 15:44:59 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -155,6 +155,7 @@
 #define        EL_REFRESH      20      /* , void);                           set     */
 #define        EL_PROMPT_ESC   21      /* , prompt_func, Char);              set/get */
 #define        EL_RPROMPT_ESC  22      /* , prompt_func, Char);              set/get */
+#define        EL_RESIZE       23      /* , el_zfunc_t, void *);             set     */
 
 #define        EL_BUILTIN_GETCFN       (NULL)
 
diff -r 9b08558b996f -r 94bca2ebc405 lib/libedit/readline.c
--- a/lib/libedit/readline.c    Sat Aug 28 15:42:45 2010 +0000
+++ b/lib/libedit/readline.c    Sat Aug 28 15:44:59 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $   */
+/*     $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 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.90 2010/08/04 20:29:18 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -220,6 +220,17 @@
        return 1;
 }
 
+static void
+_resize_fun(EditLine *el, void *a)
+{
+       const LineInfo *li;
+       char **ap = a;
+
+       li = el_line(el);
+       /* a cheesy way to get rid of const cast. */
+       *ap = memchr(li->buffer, *li->buffer, 1);
+}
+
 static const char _dothistory[] = "/.history";
 
 static const char *
@@ -272,7 +283,6 @@
 rl_initialize(void)
 {
        TYPE(HistEvent) ev;
-       const LineInfo *li;
        int editmode = 1;
        struct termios t;
 
@@ -306,6 +316,9 @@
        max_input_history = INT_MAX;
        el_set(e, EL_HIST, history, h);
 
+       /* Setup resize function */
+       el_set(e, EL_RESIZE, _resize_fun, &rl_line_buffer);
+
        /* setup getc function if valid */
        if (rl_getc_function)
                el_set(e, EL_GETCFN, _getc_function);
@@ -351,9 +364,7 @@
         * Unfortunately, some applications really do use rl_point
         * and rl_line_buffer directly.
         */
-       li = el_line(e);
-       /* a cheesy way to get rid of const cast. */
-       rl_line_buffer = memchr(li->buffer, *li->buffer, 1);
+       _resize_fun(e, &rl_line_buffer);
        _rl_update_pos();
 
        if (rl_startup_hook)



Home | Main Index | Thread Index | Old Index