summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2014-06-18 18:12:28 +0000
committerchristos <christos@NetBSD.org>2014-06-18 18:12:28 +0000
commit4d25614bbe49402011fd1ce72ed3891902f25eef (patch)
treefd60df0675f2262678e75e06f40f6b47ce358d3d /lib
parent0817d1f00e9db3796857350532c57f25cafc9804 (diff)
Don't depend on weak aliases to define the vi "alias" expansion function,
provide an API instead to set it.
Diffstat (limited to 'lib')
-rw-r--r--lib/libedit/chared.c14
-rw-r--r--lib/libedit/chared.h6
-rw-r--r--lib/libedit/el.c11
-rw-r--r--lib/libedit/eln.c11
-rw-r--r--lib/libedit/histedit.h3
-rw-r--r--lib/libedit/vi.c29
6 files changed, 43 insertions, 31 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index 35ec4b4b597..3934a684f7c 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -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 @@ ch_init(EditLine *el)
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 @@ ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
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 --git a/lib/libedit/chared.h b/lib/libedit/chared.h
index 176475ac8f0..6d6ef2341f1 100644
--- a/lib/libedit/chared.h
+++ b/lib/libedit/chared.h
@@ -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 @@ typedef struct c_kill_t {
} 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 @@ typedef struct el_chared_t {
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 c_hpos(EditLine *);
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 --git a/lib/libedit/el.c b/lib/libedit/el.c
index c03ce6bacc4..864193d5971 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -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 @@ FUN(el,set)(EditLine *el, int op, ...)
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 --git a/lib/libedit/eln.c b/lib/libedit/eln.c
index cfb1fe5bf37..5bcfb4f2b3b 100644
--- a/lib/libedit/eln.c
+++ b/lib/libedit/eln.c
@@ -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 @@ el_set(EditLine *el, int op, ...)
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 --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h
index e1f5c060f54..94f33ed2a16 100644
--- a/lib/libedit/histedit.h
+++ b/lib/libedit/histedit.h
@@ -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 @@ unsigned char _el_fn_complete(EditLine *, int);
#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 --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index 86e7f0fb512..53c47817181 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -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 @@ vi_comment_out(EditLine *el, Int c __attribute__((__unused__)))
* 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():