Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit Don't depend on weak aliases to define the vi "a...



details:   https://anonhg.NetBSD.org/src/rev/68f9827ed697
branches:  trunk
changeset: 330042:68f9827ed697
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jun 18 18:12:28 2014 +0000

description:
Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.

diffstat:

 lib/libedit/chared.c   |  14 ++++++++++++--
 lib/libedit/chared.h   |   6 +++++-
 lib/libedit/el.c       |  11 +++++++++--
 lib/libedit/eln.c      |  11 +++++++++--
 lib/libedit/histedit.h |   3 ++-
 lib/libedit/vi.c       |  29 ++++++-----------------------
 6 files changed, 43 insertions(+), 31 deletions(-)

diffs (221 lines):

diff -r c7536d4c70b6 -r 68f9827ed697 lib/libedit/chared.c
--- a/lib/libedit/chared.c      Wed Jun 18 17:52:49 2014 +0000
+++ b/lib/libedit/chared.c      Wed Jun 18 18:12:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.c,v 1.39 2013/07/12 22:39:50 christos Exp $     */
+/*     $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 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.39 2013/07/12 22:39:50 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -434,6 +434,8 @@
        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;
 
@@ -757,3 +759,11 @@
        el->el_chared.c_resizearg = a;
        return 0;
 }
+
+protected int
+ch_aliasfun(EditLine *el, el_afunc_t f, void *a)
+{
+       el->el_chared.c_aliasfun = f;
+       el->el_chared.c_aliasarg = a;
+       return 0;
+}
diff -r c7536d4c70b6 -r 68f9827ed697 lib/libedit/chared.h
--- a/lib/libedit/chared.h      Wed Jun 18 17:52:49 2014 +0000
+++ b/lib/libedit/chared.h      Wed Jun 18 18:12:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chared.h,v 1.21 2010/08/28 15:44:59 christos Exp $     */
+/*     $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -104,6 +104,7 @@
 } c_kill_t;
 
 typedef void (*el_zfunc_t)(EditLine *, void *);
+typedef const char *(*el_afunc_t)(void *, const char *);
 
 /*
  * Note that we use both data structures because the user can bind
@@ -116,7 +117,9 @@
        c_vcmd_t        c_vcmd;
        c_macro_t       c_macro;
        el_zfunc_t      c_resizefun;
+       el_afunc_t      c_aliasfun;
        void *          c_resizearg;
+       void *          c_aliasarg;
 } el_chared_t;
 
 
@@ -165,6 +168,7 @@
 protected int   ch_init(EditLine *);
 protected void  ch_reset(EditLine *, int);
 protected int   ch_resizefun(EditLine *, el_zfunc_t, void *);
+protected int   ch_aliasfun(EditLine *, el_afunc_t, void *);
 protected int   ch_enlargebufs(EditLine *, size_t);
 protected void  ch_end(EditLine *);
 
diff -r c7536d4c70b6 -r 68f9827ed697 lib/libedit/el.c
--- a/lib/libedit/el.c  Wed Jun 18 17:52:49 2014 +0000
+++ b/lib/libedit/el.c  Wed Jun 18 18:12:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.c,v 1.72 2013/01/22 20:23:21 christos Exp $ */
+/*     $NetBSD: el.c,v 1.73 2014/06/18 18:12:28 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.72 2013/01/22 20:23:21 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.73 2014/06/18 18:12:28 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -194,6 +194,13 @@
                break;
        }
 
+       case EL_ALIAS_TEXT: {
+               el_afunc_t p = va_arg(ap, el_afunc_t);
+               void *arg = va_arg(ap, void *);
+               rv = ch_aliasfun(el, p, arg);
+               break;
+       }
+
        case EL_PROMPT_ESC:
        case EL_RPROMPT_ESC: {
                el_pfunc_t p = va_arg(ap, el_pfunc_t);
diff -r c7536d4c70b6 -r 68f9827ed697 lib/libedit/eln.c
--- a/lib/libedit/eln.c Wed Jun 18 17:52:49 2014 +0000
+++ b/lib/libedit/eln.c Wed Jun 18 18:12:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eln.c,v 1.16 2014/05/20 15:05:08 christos Exp $        */
+/*     $NetBSD: eln.c,v 1.17 2014/06/18 18:12:28 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.16 2014/05/20 15:05:08 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.17 2014/06/18 18:12:28 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include "histedit.h"
@@ -125,6 +125,13 @@
                break;
        }
 
+       case EL_ALIAS_TEXT: {
+               el_afunc_t p = va_arg(ap, el_afunc_t);
+               void *arg = va_arg(ap, void *);
+               ret = ch_aliasfun(el, p, arg);
+               break;
+       }
+
        case EL_PROMPT_ESC:
        case EL_RPROMPT_ESC: {
                el_pfunc_t p = va_arg(ap, el_pfunc_t);
diff -r c7536d4c70b6 -r 68f9827ed697 lib/libedit/histedit.h
--- a/lib/libedit/histedit.h    Wed Jun 18 17:52:49 2014 +0000
+++ b/lib/libedit/histedit.h    Wed Jun 18 18:12:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.h,v 1.52 2014/05/11 01:05:17 christos Exp $   */
+/*     $NetBSD: histedit.h,v 1.53 2014/06/18 18:12:28 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -156,6 +156,7 @@
 #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_ALIAS_TEXT   24      /* , el_afunc_t, void *);             set     */
 
 #define        EL_BUILTIN_GETCFN       (NULL)
 
diff -r c7536d4c70b6 -r 68f9827ed697 lib/libedit/vi.c
--- a/lib/libedit/vi.c  Wed Jun 18 17:52:49 2014 +0000
+++ b/lib/libedit/vi.c  Wed Jun 18 18:12:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vi.c,v 1.44 2014/06/18 13:03:08 christos Exp $ */
+/*     $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)vi.c       8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: vi.c,v 1.44 2014/06/18 13:03:08 christos Exp $");
+__RCSID("$NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -918,43 +918,26 @@
  * NB: posix implies that we should enter insert mode, however
  * this is against historical precedent...
  */
-#if defined(__weak_reference)
-# define libedit_weak(a) __weak_reference(a)
-# define libedit_weak_visible __weakref_visible
-#elif defined(__weak_extern)
-# define libedit_weak(a) __weak_extern(a)
-# define libedit_weak_visible
-#endif
-
-#ifdef libedit_weak
-libedit_weak_visible
-char *my_get_alias_text(const char *) libedit_weak(get_alias_text);
-#endif
-
 protected el_action_t
 /*ARGSUSED*/
 vi_alias(EditLine *el, Int c __attribute__((__unused__)))
 {
-#ifdef libedit_weak
        char alias_name[3];
-       char *alias_text;
+       const char *alias_text;
 
-       if (my_get_alias_text == 0) {
+       if (el->el_chared.c_aliasfun == NULL)
                return CC_ERROR;
-       }
 
        alias_name[0] = '_';
        alias_name[2] = 0;
        if (el_getc(el, &alias_name[1]) != 1)
                return CC_ERROR;
 
-       alias_text = my_get_alias_text(alias_name);
+       alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg,
+           alias_name);
        if (alias_text != NULL)
                FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch));
        return CC_NORM;
-#else
-       return CC_ERROR;
-#endif
 }
 
 /* vi_to_history_line():



Home | Main Index | Thread Index | Old Index