From 62dbbc55bc7793439cdc7067072d821a8db2f57e Mon Sep 17 00:00:00 2001 From: christos Date: Tue, 17 Feb 2009 21:34:26 +0000 Subject: [PATCH] allow for a prompt argument. --- lib/libedit/el.c | 10 ++++++---- lib/libedit/histedit.h | 4 ++-- lib/libedit/prompt.c | 26 +++++++++++++++++++------- lib/libedit/prompt.h | 7 ++++--- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 0acc2bbb21c3..f8ce6a0ed17a 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.47 2009/01/18 12:17:24 lukem Exp $ */ +/* $NetBSD: el.c,v 1.48 2009/02/17 21:34:26 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.47 2009/01/18 12:17:24 lukem Exp $"); +__RCSID("$NetBSD: el.c,v 1.48 2009/02/17 21:34:26 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -156,7 +156,8 @@ el_set(EditLine *el, int op, ...) switch (op) { case EL_PROMPT: case EL_RPROMPT: - rv = prompt_set(el, va_arg(ap, el_pfunc_t), op); + rv = prompt_set(el, va_arg(ap, el_pfunc_t), + va_arg(ap, void *), op); break; case EL_TERMINAL: @@ -341,7 +342,8 @@ el_get(EditLine *el, int op, ...) switch (op) { case EL_PROMPT: case EL_RPROMPT: - rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op); + rv = prompt_get(el, va_arg(ap, el_pfunc_t *), + va_arg(ap, void **), op); break; case EL_EDITOR: diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h index 37823141c064..1557968ec8c3 100644 --- a/lib/libedit/histedit.h +++ b/lib/libedit/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.35 2009/02/05 19:15:44 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.36 2009/02/17 21:34:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -115,7 +115,7 @@ unsigned char _el_fn_complete(EditLine *, int); /* * el_set/el_get parameters */ -#define EL_PROMPT 0 /* , el_pfunc_t); */ +#define EL_PROMPT 0 /* , el_pfunc_t, void *); */ #define EL_TERMINAL 1 /* , const char *); */ #define EL_EDITOR 2 /* , const char *); */ #define EL_SIGNAL 3 /* , int); */ diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c index ec8855570f50..b85ec43f90b5 100644 --- a/lib/libedit/prompt.c +++ b/lib/libedit/prompt.c @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.c,v 1.11 2003/08/07 16:44:32 agc Exp $ */ +/* $NetBSD: prompt.c,v 1.12 2009/02/17 21:34:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: prompt.c,v 1.11 2003/08/07 16:44:32 agc Exp $"); +__RCSID("$NetBSD: prompt.c,v 1.12 2009/02/17 21:34:26 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -132,7 +132,7 @@ prompt_end(EditLine *el __attribute__((__unused__))) * Install a prompt printing function */ protected int -prompt_set(EditLine *el, el_pfunc_t prf, int op) +prompt_set(EditLine *el, el_pfunc_t prf, void *arg, int op) { el_prompt_t *p; @@ -140,13 +140,18 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op) p = &el->el_prompt; else p = &el->el_rprompt; + if (prf == NULL) { if (op == EL_PROMPT) p->p_func = prompt_default; else p->p_func = prompt_default_r; - } else + p->p_arg = NULL; + } else { p->p_func = prf; + p->p_arg = arg; + } + p->p_pos.v = 0; p->p_pos.h = 0; return (0); @@ -157,14 +162,21 @@ prompt_set(EditLine *el, el_pfunc_t prf, int op) * Retrieve the prompt printing function */ protected int -prompt_get(EditLine *el, el_pfunc_t *prf, int op) +prompt_get(EditLine *el, el_pfunc_t *prf, void **arg, int op) { + el_prompt_t *p; if (prf == NULL) return (-1); + if (op == EL_PROMPT) - *prf = el->el_prompt.p_func; + p = &el->el_prompt; else - *prf = el->el_rprompt.p_func; + p = &el->el_rprompt; + + *prf = p->p_func; + + if (arg) + *arg = p->p_arg; return (0); } diff --git a/lib/libedit/prompt.h b/lib/libedit/prompt.h index d18110861f8d..9b9a7692d8a3 100644 --- a/lib/libedit/prompt.h +++ b/lib/libedit/prompt.h @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.h,v 1.6 2003/08/07 16:44:32 agc Exp $ */ +/* $NetBSD: prompt.h,v 1.7 2009/02/17 21:34:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -47,11 +47,12 @@ typedef char * (*el_pfunc_t)(EditLine*); typedef struct el_prompt_t { el_pfunc_t p_func; /* Function to return the prompt */ coord_t p_pos; /* position in the line after prompt */ + void *p_arg; /* Argument to prompt function */ } el_prompt_t; protected void prompt_print(EditLine *, int); -protected int prompt_set(EditLine *, el_pfunc_t, int); -protected int prompt_get(EditLine *, el_pfunc_t *, int); +protected int prompt_set(EditLine *, el_pfunc_t, void *, int); +protected int prompt_get(EditLine *, el_pfunc_t *, void **, int); protected int prompt_init(EditLine *); protected void prompt_end(EditLine *);