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
+20 -7
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) 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]) 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]) AC_DEFINE(HAVE_LIBNL, 1, [have libnl])
fi fi
if test "$dbus_enabled" = yes;then if test "$dbus_enabled" = yes;then
occtl_enabled=yes 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 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 else
occtl_enabled=no PKG_CHECK_MODULES(LIBREADLINE, libedit, [have_libedit=yes], [have_libedit=no])
AC_MSG_WARN([[*** if test "${have_libedit}" = "no"; then
*** libreadline was not found. occtl will not be built. occtl_enabled=no
AC_MSG_WARN([[***
*** libreadline or editline was not found. occtl will not be built.
***]]) ***]])
else
have_readline=editline
fi
fi fi
else else
occtl_enabled=no occtl_enabled=no
fi fi
AM_CONDITIONAL(ENABLE_OCCTL, test "x$occtl_enabled" = xyes)
pam_enabled=no pam_enabled=no
LIBS="$oldlibs -lpam" LIBS="$oldlibs -lpam"
AC_MSG_CHECKING([for pam library]) AC_MSG_CHECKING([for pam library])
@@ -272,7 +285,7 @@ Summary of build options:
systemd: ${systemd_enabled} systemd: ${systemd_enabled}
(socket activation) (socket activation)
dbus: ${dbus_enabled} dbus: ${dbus_enabled}
readline: ${ac_cv_libreadline} readline: ${have_readline}
libnl3: ${have_libnl3} libnl3: ${have_libnl3}
local protobuf-c: ${with_local_protobuf_c} local protobuf-c: ${with_local_protobuf_c}
local PCL library: ${with_local_pcl} local PCL library: ${with_local_pcl}
+2 -2
View File
@@ -3,7 +3,7 @@ SUBDIRS =
AM_CPPFLAGS = -I$(srcdir)/../gl/ -I$(builddir)/../gl/ \ AM_CPPFLAGS = -I$(srcdir)/../gl/ -I$(builddir)/../gl/ \
-I$(srcdir)/ -I$(builddir)/../ $(LIBOPTS_CFLAGS) \ -I$(srcdir)/ -I$(builddir)/../ $(LIBOPTS_CFLAGS) \
$(LIBPROTOBUF_C_CFLAGS) $(LIBDBUS_CFLAGS) \ $(LIBPROTOBUF_C_CFLAGS) $(LIBDBUS_CFLAGS) \
$(LIBNL3_CFLAGS) $(LIBNL3_CFLAGS) $(LIBREADLINE_CFLAGS)
BUILT_SOURCES = ocpasswd-args.c ocpasswd-args.h \ BUILT_SOURCES = ocpasswd-args.c ocpasswd-args.h \
ocserv-args.c ocserv-args.h ipc.pb-c.c ipc.pb-c.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 occtl-args.def ipc.proto
bin_PROGRAMS = ocpasswd bin_PROGRAMS = ocpasswd
if HAVE_DBUS if ENABLE_OCCTL
bin_PROGRAMS += occtl bin_PROGRAMS += occtl
endif endif
+17 -2
View File
@@ -25,8 +25,13 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <signal.h> #include <signal.h>
#include <readline/readline.h> #include <c-ctype.h>
#include <readline/history.h> #ifdef HAVE_ORIG_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#else
# include <readline.h>
#endif
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <occtl.h> #include <occtl.h>
#include <c-strcase.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) static unsigned need_help(const char *arg)
{ {
while (whitespace(*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) static int handle_reset_cmd(DBusConnection * conn, const char *arg)
{ {
rl_reset_terminal(NULL); rl_reset_terminal(NULL);
#ifdef HAVE_ORIG_READLINE
rl_reset_screen_size(); rl_reset_screen_size();
#endif
return 0; return 0;
} }
@@ -1268,9 +1279,11 @@ static char *occtl_completion(char *text, int start, int end)
void handle_sigint(int signo) void handle_sigint(int signo)
{ {
#ifdef HAVE_ORIG_READLINE
rl_reset_line_state(); rl_reset_line_state();
rl_replace_line("", 0); rl_replace_line("", 0);
rl_crlf(); rl_crlf();
#endif
rl_redisplay(); rl_redisplay();
return; return;
} }
@@ -1281,7 +1294,9 @@ void initialize_readline(void)
rl_attempted_completion_function = (CPPFunction *) occtl_completion; rl_attempted_completion_function = (CPPFunction *) occtl_completion;
rl_completion_entry_function = command_generator; rl_completion_entry_function = command_generator;
rl_completion_query_items = 20; rl_completion_query_items = 20;
#ifdef HAVE_ORIG_READLINE
rl_clear_signals(); rl_clear_signals();
#endif
signal(SIGINT, handle_sigint); signal(SIGINT, handle_sigint);
} }