mirror of
https://github.com/troglobit/editline.git
synced 2025-11-02 01:38:10 +08:00
Change rl_complete() and rl_list_possib() to be function pointers instead.
This is a much cleaner design and also works with or without the configure --enable-default-complete option. See the examples for details.
This commit is contained in:
@@ -6,4 +6,5 @@ libedit_a_SOURCES = editline.c editline.h sysunix.c unix.h
|
||||
if COMPLETE
|
||||
# Built-in completion handler.
|
||||
libedit_a_SOURCES += complete.c
|
||||
AM_CPPFLAGS = -DCOMPLETE
|
||||
endif
|
||||
|
||||
@@ -161,6 +161,7 @@ AUTOMAKE_OPTIONS = foreign
|
||||
lib_LIBRARIES = libedit.a
|
||||
libedit_a_SOURCES = editline.c editline.h sysunix.c unix.h \
|
||||
$(am__append_1)
|
||||
@COMPLETE_TRUE@AM_CPPFLAGS = -DCOMPLETE
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
@@ -161,7 +161,7 @@ SplitPath(path, dirpart, filepart)
|
||||
** Fill in *unique if we completed it, or set it to 0 if ambiguous.
|
||||
*/
|
||||
char *
|
||||
rl_complete(pathname, unique)
|
||||
default_rl_complete(pathname, unique)
|
||||
char *pathname;
|
||||
int *unique;
|
||||
{
|
||||
@@ -233,7 +233,7 @@ rl_complete(pathname, unique)
|
||||
** Return all possible completions.
|
||||
*/
|
||||
int
|
||||
rl_list_possib(pathname, avp)
|
||||
default_rl_list_possib(pathname, avp)
|
||||
char *pathname;
|
||||
char ***avp;
|
||||
{
|
||||
|
||||
@@ -97,6 +97,11 @@ STATIC int TTYrows;
|
||||
/* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */
|
||||
int rl_meta_chars = 1;
|
||||
|
||||
/* User definable callbacks. */
|
||||
char *(*rl_complete)(char *token, int *match);
|
||||
int (*rl_list_possib)(char *token, char ***av);
|
||||
|
||||
|
||||
/*
|
||||
** Declarations.
|
||||
*/
|
||||
@@ -1033,6 +1038,20 @@ rl_reset_terminal(p)
|
||||
void
|
||||
rl_initialize(void)
|
||||
{
|
||||
#ifdef COMPLETE
|
||||
int done = 0;
|
||||
|
||||
if (!done)
|
||||
{
|
||||
if (!rl_complete)
|
||||
rl_complete = &default_rl_complete;
|
||||
|
||||
if (!rl_list_possib)
|
||||
rl_list_possib = &default_rl_list_possib;
|
||||
|
||||
done = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -1042,6 +1061,9 @@ readline(prompt)
|
||||
CHAR *line;
|
||||
int s;
|
||||
|
||||
/* Unless called by the user already. */
|
||||
rl_initialize ();
|
||||
|
||||
if (!isatty(0)) {
|
||||
TTYflush();
|
||||
return read_redirected();
|
||||
@@ -1177,6 +1199,10 @@ c_possible(void)
|
||||
CHAR *word;
|
||||
int ac;
|
||||
|
||||
if (!rl_list_possib) {
|
||||
return ring_bell();
|
||||
}
|
||||
|
||||
word = find_word();
|
||||
ac = rl_list_possib((char *)word, (char ***)&av);
|
||||
if (word)
|
||||
@@ -1200,6 +1226,10 @@ c_complete(void)
|
||||
int unique;
|
||||
STATUS s;
|
||||
|
||||
if (!rl_complete) {
|
||||
return ring_bell();
|
||||
}
|
||||
|
||||
word = find_word();
|
||||
p = (CHAR *)rl_complete((char *)word, &unique);
|
||||
if (word)
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
**
|
||||
** Internal header file for editline library.
|
||||
*/
|
||||
#ifndef __PRIVATE_EDITLINE_H__
|
||||
#define __PRIVATE_EDITLINE_H__
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_MALLOC_H
|
||||
@@ -70,8 +73,10 @@ extern int rl_quit;
|
||||
#if defined(DO_SIGTSTP)
|
||||
extern int rl_susp;
|
||||
#endif /* defined(DO_SIGTSTP) */
|
||||
extern char *rl_complete();
|
||||
extern int rl_list_possib(char *pathname, char ***avp);
|
||||
#ifdef COMPLETE
|
||||
extern char *default_rl_complete();
|
||||
extern int default_rl_list_possib(char *pathname, char ***avp);
|
||||
#endif
|
||||
extern void rl_ttyset();
|
||||
extern void rl_add_slash();
|
||||
|
||||
@@ -93,3 +98,6 @@ extern int strncmp();
|
||||
#if defined(NEED_STRDUP)
|
||||
extern char *strdup();
|
||||
#endif
|
||||
|
||||
#include "../include/editline.h"
|
||||
#endif /* __PRIVATE_EDITLINE_H__ */
|
||||
|
||||
Reference in New Issue
Block a user