allow for a prompt argument.

This commit is contained in:
christos 2009-02-17 21:34:26 +00:00
parent d3f85b9eb7
commit 62dbbc55bc
4 changed files with 31 additions and 16 deletions

View File

@ -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:

View File

@ -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); */

View File

@ -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);
}

View File

@ -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 *);