When libreadline isn't available try editline.

This commit is contained in:
Nikos Mavrogiannopoulos
2014-01-21 14:34:35 +01:00
parent 50656ef49f
commit 6a9600aa61
3 changed files with 39 additions and 11 deletions

View File

@@ -79,25 +79,38 @@ PKG_CHECK_MODULES([LIBPROTOBUF_C], [libprotobuf-c],,
AM_CONDITIONAL(LOCAL_PROTOBUF_C, test "x$with_local_protobuf_c" != xno)
PKG_CHECK_MODULES(LIBNL3, libnl-route-3.0 >= 3.1, [have_libnl3=yes], [have_libnl3=no])
if (test "${have_libnl3}" = "yes"); then
if test "${have_libnl3}" = "yes"; then
AC_DEFINE(HAVE_LIBNL, 1, [have libnl])
fi
if test "$dbus_enabled" = yes;then
occtl_enabled=yes
AC_LIB_HAVE_LINKFLAGS(readline,, [#include <readline/readline.h>], [readline(0);])
have_readline=no
AC_LIB_HAVE_LINKFLAGS(readline,, [
#include <stdio.h>
#include <readline/readline.h>], [readline(0);])
if test x$ac_cv_libreadline = xyes; then
AC_SUBST(LIBREADLINE_LIBS, [$LIBREADLINE]),
AC_SUBST(LIBREADLINE_LIBS, [$LIBREADLINE])
AC_DEFINE(HAVE_ORIG_READLINE, 1, [have original readline])
have_readline=yes
else
occtl_enabled=no
AC_MSG_WARN([[***
*** libreadline was not found. occtl will not be built.
PKG_CHECK_MODULES(LIBREADLINE, libedit, [have_libedit=yes], [have_libedit=no])
if test "${have_libedit}" = "no"; then
occtl_enabled=no
AC_MSG_WARN([[***
*** libreadline or editline was not found. occtl will not be built.
***]])
else
have_readline=editline
fi
fi
else
occtl_enabled=no
fi
AM_CONDITIONAL(ENABLE_OCCTL, test "x$occtl_enabled" = xyes)
pam_enabled=no
LIBS="$oldlibs -lpam"
AC_MSG_CHECKING([for pam library])
@@ -272,7 +285,7 @@ Summary of build options:
systemd: ${systemd_enabled}
(socket activation)
dbus: ${dbus_enabled}
readline: ${ac_cv_libreadline}
readline: ${have_readline}
libnl3: ${have_libnl3}
local protobuf-c: ${with_local_protobuf_c}
local PCL library: ${with_local_pcl}

View File

@@ -3,7 +3,7 @@ SUBDIRS =
AM_CPPFLAGS = -I$(srcdir)/../gl/ -I$(builddir)/../gl/ \
-I$(srcdir)/ -I$(builddir)/../ $(LIBOPTS_CFLAGS) \
$(LIBPROTOBUF_C_CFLAGS) $(LIBDBUS_CFLAGS) \
$(LIBNL3_CFLAGS)
$(LIBNL3_CFLAGS) $(LIBREADLINE_CFLAGS)
BUILT_SOURCES = ocpasswd-args.c ocpasswd-args.h \
ocserv-args.c ocserv-args.h ipc.pb-c.c ipc.pb-c.h
@@ -27,7 +27,7 @@ EXTRA_DIST = ccan/licenses/BSD-MIT version.inc.in \
occtl-args.def ipc.proto
bin_PROGRAMS = ocpasswd
if HAVE_DBUS
if ENABLE_OCCTL
bin_PROGRAMS += occtl
endif

View File

@@ -25,8 +25,13 @@
#include <string.h>
#include <time.h>
#include <signal.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <c-ctype.h>
#ifdef HAVE_ORIG_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#else
# include <readline.h>
#endif
#include <dbus/dbus.h>
#include <occtl.h>
#include <c-strcase.h>
@@ -114,6 +119,10 @@ static void print_commands(unsigned interactive)
}
}
#ifndef HAVE_ORIG_READLINE
# define whitespace(x) c_isspace(x)
#endif
static unsigned need_help(const char *arg)
{
while (whitespace(*arg))
@@ -1029,7 +1038,9 @@ static int handle_help_cmd(DBusConnection * conn, const char *arg)
static int handle_reset_cmd(DBusConnection * conn, const char *arg)
{
rl_reset_terminal(NULL);
#ifdef HAVE_ORIG_READLINE
rl_reset_screen_size();
#endif
return 0;
}
@@ -1268,9 +1279,11 @@ static char *occtl_completion(char *text, int start, int end)
void handle_sigint(int signo)
{
#ifdef HAVE_ORIG_READLINE
rl_reset_line_state();
rl_replace_line("", 0);
rl_crlf();
#endif
rl_redisplay();
return;
}
@@ -1281,7 +1294,9 @@ void initialize_readline(void)
rl_attempted_completion_function = (CPPFunction *) occtl_completion;
rl_completion_entry_function = command_generator;
rl_completion_query_items = 20;
#ifdef HAVE_ORIG_READLINE
rl_clear_signals();
#endif
signal(SIGINT, handle_sigint);
}