Subject: lib/14188: libedit should provide a client data pointer for callbacks
To: None <gnats-bugs@gnats.netbsd.org>
From: Anthony Mallet <anthony.mallet@ficus.yi.org>
List: netbsd-bugs
Date: 10/08/2001 12:26:51
>Number: 14188
>Category: lib
>Synopsis: libedit should provide a client data pointer for callbacks
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Mon Oct 08 03:28:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Anthony Mallet
>Release: NetBSD 1.5Y
>Organization:
>Environment:
System: NetBSD ficus 1.5Y NetBSD 1.5Y (FICUS) #7: Sun Sep 23 01:15:49 CEST 2001 toto@ficus:/home/src/netbsd-current/sys/arch/i386/compile/FICUS i386
Architecture: i386
Machine: i386
>Description:
The callback function of libedit (propmt, completion, ...) defined with
el_set(el, EL_PROMPT, ...) or el_set(el, EL_ADDFN, ....) do not provide a
mechanism for the definition of a 'context'.
It is therefore impossible to write callback function that do not rely on
global data.
I propose to add a request to el_set and el_get that let the user
associate a generic pointer to the EditLine structure. Callback function
can then retrieve their context.
>How-To-Repeat:
n/a
>Fix:
NOTE that the following patch is diff'ed against my previous PR (14067).
Since the changes here are quite trivial, I though it was not a problem.
If it is, I can still produce a patch against the current version of
libedit.
Index: editline.3
===================================================================
RCS file: /usr/local/cvs_hilare/lib/libedit/dist/editline.3,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- editline.3 26 Sep 2001 00:12:05 -0000 1.2
+++ editline.3 8 Oct 2001 09:55:24 -0000 1.3
@@ -379,6 +379,13 @@
.Fn el_getc .
The builtin function can be set or restored with the special function
name ``EL_BUILTIN_GETCFN''.
+.It Dv EL_CLIENTDATA , Fa "void *data"
+Register
+.Fa data
+to be associated with this EditLine structure. It can be retrieved with
+the corresponding
+.Fn el_get
+call.
.El
.It Fn el_get
Get
@@ -413,6 +420,12 @@
.It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)"
Return a pointer to the function that read characters, which is equal to
``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
+.It Dv EL_CLIENTDATA , Fa "void **data"
+Retrieve
+.Fa data
+previously registered with the corresponding
+.Fn el_set
+call.
.El
.It Fn el_source
Initialise
Index: el.c
===================================================================
RCS file: /usr/local/cvs_hilare/lib/libedit/dist/el.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- el.c 26 Sep 2001 00:12:05 -0000 1.3
+++ el.c 8 Oct 2001 09:55:24 -0000 1.4
@@ -93,7 +93,7 @@
(void) prompt_init(el);
(void) sig_init(el);
(void) read_init(el);
-
+
return (el);
}
@@ -252,6 +252,10 @@
break;
}
+ case EL_CLIENTDATA:
+ el->el_data = va_arg(va, void *);
+ break;
+
default:
rv = -1;
}
@@ -364,6 +368,11 @@
case EL_GETCFN:
*((el_rfunc_t *)ret) = el_read_getfn(el);
+ rv = 0;
+ break;
+
+ case EL_CLIENTDATA:
+ *((void **)ret) = el->el_data;
rv = 0;
break;
Index: el.h
===================================================================
RCS file: /usr/local/cvs_hilare/lib/libedit/dist/el.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- el.h 26 Sep 2001 00:12:05 -0000 1.2
+++ el.h 8 Oct 2001 09:55:24 -0000 1.3
@@ -131,6 +131,8 @@
el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling stuff */
el_read_t el_read; /* Character reading stuff */
+
+ void *el_data; /* Client data */
};
protected int el_editmode(EditLine *, int, char **);
Index: histedit.h
===================================================================
RCS file: /usr/local/cvs_hilare/lib/libedit/dist/histedit.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- histedit.h 26 Sep 2001 00:12:05 -0000 1.2
+++ histedit.h 8 Oct 2001 09:55:24 -0000 1.3
@@ -127,6 +127,7 @@
#define EL_EDITMODE 11 /* , int); */
#define EL_RPROMPT 12 /* , el_pfunc_t); */
#define EL_GETCFN 13 /* , el_rfunc_t); */
+#define EL_CLIENTDATA 14 /* , void *); */
#define EL_BUILTIN_GETCFN (NULL)
>Release-Note:
>Audit-Trail:
>Unformatted: