Module Name: src Committed By: christos Date: Wed Jun 18 18:12:28 UTC 2014
Modified Files: src/lib/libedit: chared.c chared.h el.c eln.c histedit.h vi.c Log Message: Don't depend on weak aliases to define the vi "alias" expansion function, provide an API instead to set it. To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/lib/libedit/chared.c cvs rdiff -u -r1.21 -r1.22 src/lib/libedit/chared.h cvs rdiff -u -r1.72 -r1.73 src/lib/libedit/el.c cvs rdiff -u -r1.16 -r1.17 src/lib/libedit/eln.c cvs rdiff -u -r1.52 -r1.53 src/lib/libedit/histedit.h cvs rdiff -u -r1.44 -r1.45 src/lib/libedit/vi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libedit/chared.c diff -u src/lib/libedit/chared.c:1.39 src/lib/libedit/chared.c:1.40 --- src/lib/libedit/chared.c:1.39 Fri Jul 12 18:39:50 2013 +++ src/lib/libedit/chared.c Wed Jun 18 14:12:28 2014 @@ -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, 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; +} Index: src/lib/libedit/chared.h diff -u src/lib/libedit/chared.h:1.21 src/lib/libedit/chared.h:1.22 --- src/lib/libedit/chared.h:1.21 Sat Aug 28 11:44:59 2010 +++ src/lib/libedit/chared.h Wed Jun 18 14:12:28 2014 @@ -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 *); Index: src/lib/libedit/el.c diff -u src/lib/libedit/el.c:1.72 src/lib/libedit/el.c:1.73 --- src/lib/libedit/el.c:1.72 Tue Jan 22 15:23:21 2013 +++ src/lib/libedit/el.c Wed Jun 18 14:12:28 2014 @@ -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); Index: src/lib/libedit/eln.c diff -u src/lib/libedit/eln.c:1.16 src/lib/libedit/eln.c:1.17 --- src/lib/libedit/eln.c:1.16 Tue May 20 11:05:08 2014 +++ src/lib/libedit/eln.c Wed Jun 18 14:12:28 2014 @@ -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); Index: src/lib/libedit/histedit.h diff -u src/lib/libedit/histedit.h:1.52 src/lib/libedit/histedit.h:1.53 --- src/lib/libedit/histedit.h:1.52 Sat May 10 21:05:17 2014 +++ src/lib/libedit/histedit.h Wed Jun 18 14:12:28 2014 @@ -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 * #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) Index: src/lib/libedit/vi.c diff -u src/lib/libedit/vi.c:1.44 src/lib/libedit/vi.c:1.45 --- src/lib/libedit/vi.c:1.44 Wed Jun 18 09:03:08 2014 +++ src/lib/libedit/vi.c Wed Jun 18 14:12:28 2014 @@ -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 __att * 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():