From: darkcoven Date: Fri, 27 Sep 2013 22:34:14 +0000 (+0200) Subject: Readline is now optional X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=67f00e10ceda8b690d2db1a227007d56b6074169;p=ngadmin Readline is now optional --- diff --git a/cli/src/admin.c b/cli/src/admin.c index bb4b310..dbd30bb 100644 --- a/cli/src/admin.c +++ b/cli/src/admin.c @@ -1,12 +1,18 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include #include #include +#ifdef HAVE_LIBREADLINE #include #include +#endif #include "common.h" #include "commands.h" @@ -15,7 +21,7 @@ #define MAXCOM 32 -int main_loop_continue = 1; +int main_loop_continue; static const struct TreeNode* getSubCom (char **com, int n, int *t) @@ -48,6 +54,7 @@ static const struct TreeNode* getSubCom (char **com, int n, int *t) } +#ifdef HAVE_LIBREADLINE static const struct TreeNode *compcur; @@ -105,6 +112,7 @@ static char** my_completion (const char *text, int start, int end UNUSED) return matches; } +#endif /* HAVE_LIBREADLINE */ static struct ngadmin *nga; @@ -212,7 +220,11 @@ int main (int argc, char **argv) tcgetattr(STDIN_FILENO, &orig_term); current_term = orig_term; +#ifdef HAVE_LIBREADLINE batch = false; +#else + batch = true; +#endif opterr = 0; @@ -317,28 +329,28 @@ int main (int argc, char **argv) if (mac != NULL && pre_login(mac, retries) != 0) goto end; - if (batch) { - /* in batch mode, we must be logged to continue */ - if (ngadmin_getCurrentSwitch(nga) == NULL) { - printf("must be logged\n"); - goto end; - } - } else { + if (!batch) { +#ifdef HAVE_LIBREADLINE /* initialize readline functions */ rl_attempted_completion_function = my_completion; rl_completion_entry_function = my_generator; sigsetjmp(jmpbuf, 1); +#endif } + main_loop_continue = 1; + while (main_loop_continue) { /* read user input */ line = NULL; n = 0; if (batch) n = getline(&line, (size_t*)&i, stdin); +#ifdef HAVE_LIBREADLINE else line = readline("> "); +#endif if (n < 0 || line == NULL) goto end; @@ -350,8 +362,10 @@ int main (int argc, char **argv) free(line); continue; } else { +#ifdef HAVE_LIBREADLINE if (!batch) add_history(line); +#endif free(line); } diff --git a/configure.ac b/configure.ac index d0dc40b..f57c78e 100644 --- a/configure.ac +++ b/configure.ac @@ -7,17 +7,33 @@ AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE -LT_PREREQ([2.4]) -LT_INIT - # Checks for programs AC_PROG_CC AM_PROG_CC_C_O +AC_PROG_LIBTOOL +AC_PROG_INSTALL + +LT_PREREQ([2.4]) +LT_INIT + + +AC_ARG_WITH([readline], + [AS_HELP_STRING([--with-readline], [support fancy command line editing @<:@default=check@:>@])], + [with_readline="$withval"], [with_readline=check]) CFLAGS="-Wall -Wextra -Os" # Checks for libraries -AC_CHECK_LIB([readline], [readline]) +if test "x${with_readline}" != xno; then + AC_CHECK_LIB([readline], [readline], [], [ + if test "x${with_readline}" = xyes; then + AC_MSG_ERROR([ +---------------------------------------- +Unable to find readline library +----------------------------------------]) + fi + ]) +fi # Checks for header files AC_CHECK_HEADERS([arpa/inet.h stdlib.h string.h sys/ioctl.h termios.h unistd.h]) @@ -47,3 +63,12 @@ AC_CONFIG_FILES([ AC_OUTPUT + +echo " +${PACKAGE_NAME} version ${PACKAGE_VERSION} +Prefix.............: ${prefix} +Debug..............: +Compiler...........: ${CC} ${CFLAGS} ${CPPFLAGS} +" + +