mirror of
https://github.com/troglobit/editline.git
synced 2025-09-16 08:28:09 +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:
@@ -5,6 +5,3 @@ AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include
|
||||
|
||||
# TODO: Port "fileman" example from BSD editline
|
||||
noinst_PROGRAMS = testit cli
|
||||
|
||||
testit_SOURCES = testit.c
|
||||
#fileman_SOURCES = fileman.c
|
||||
|
@@ -45,8 +45,8 @@ cli_SOURCES = cli.c
|
||||
cli_OBJECTS = cli.$(OBJEXT)
|
||||
cli_LDADD = $(LDADD)
|
||||
cli_DEPENDENCIES = $(top_builddir)/src/libedit.a
|
||||
am_testit_OBJECTS = testit.$(OBJEXT)
|
||||
testit_OBJECTS = $(am_testit_OBJECTS)
|
||||
testit_SOURCES = testit.c
|
||||
testit_OBJECTS = testit.$(OBJEXT)
|
||||
testit_LDADD = $(LDADD)
|
||||
testit_DEPENDENCIES = $(top_builddir)/src/libedit.a
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
|
||||
@@ -56,8 +56,8 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = cli.c $(testit_SOURCES)
|
||||
DIST_SOURCES = cli.c $(testit_SOURCES)
|
||||
SOURCES = cli.c testit.c
|
||||
DIST_SOURCES = cli.c testit.c
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
@@ -149,7 +149,6 @@ top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
LDADD = $(top_builddir)/src/libedit.a
|
||||
AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include
|
||||
testit_SOURCES = testit.c
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
@@ -389,7 +388,6 @@ uninstall-am:
|
||||
mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \
|
||||
uninstall-am
|
||||
|
||||
#fileman_SOURCES = fileman.c
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
@@ -1,6 +1,4 @@
|
||||
/* The "testit" micro shell, now with command completion.
|
||||
* To be able to run, don't "--enable-default-complete".
|
||||
*/
|
||||
/* Custom CLI command completion. */
|
||||
#include "editline.h"
|
||||
#include <string.h>
|
||||
|
||||
@@ -12,7 +10,7 @@ char *list[] = {
|
||||
** Attempt to complete the pathname, returning an allocated copy.
|
||||
** Fill in *unique if we completed it, or set it to 0 if ambiguous.
|
||||
*/
|
||||
char *rl_complete(char *token, int *match)
|
||||
char *my_rl_complete(char *token, int *match)
|
||||
{
|
||||
int i;
|
||||
int index = -1;
|
||||
@@ -43,7 +41,7 @@ char *rl_complete(char *token, int *match)
|
||||
/*
|
||||
** Return all possible completions.
|
||||
*/
|
||||
int rl_list_possib(char *token, char ***av)
|
||||
int my_rl_list_possib(char *token, char ***av)
|
||||
{
|
||||
int i, num, total = 0;
|
||||
char **copy;
|
||||
@@ -69,6 +67,10 @@ int main(int ac, char *av[])
|
||||
char *line;
|
||||
char *prompt = "cli> ";
|
||||
|
||||
/* Setup callbacks */
|
||||
rl_complete = &my_rl_complete;
|
||||
rl_list_possib = &my_rl_list_possib;
|
||||
|
||||
while ((line = readline(prompt)) != NULL) {
|
||||
(void)printf("\t\t\t|%s|\n", line);
|
||||
free(line);
|
||||
|
Reference in New Issue
Block a user