]> git.sur5r.net Git - ngadmin/commitdiff
Readline is now optional
authordarkcoven <admin@darkcoven.tk>
Fri, 27 Sep 2013 22:34:14 +0000 (00:34 +0200)
committerdarkcoven <admin@darkcoven.tk>
Fri, 27 Sep 2013 22:34:14 +0000 (00:34 +0200)
cli/src/admin.c
configure.ac

index bb4b310fd721afb234fe10a1cc647bf82c7d61b7..dbd30bbaeaf260fca48659de9cdf1fec1e376473 100644 (file)
@@ -1,12 +1,18 @@
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include <signal.h>
 #include <unistd.h>
 #include <setjmp.h>
 
 #include <getopt.h>
+#ifdef HAVE_LIBREADLINE
 #include <readline/readline.h>
 #include <readline/history.h>
+#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);
                }
                
index d0dc40be84b750c96fa400447d7ac85a5eebc7ac..f57c78ecb6078b87a1d3f3631eadda9e65c18685 100644 (file)
@@ -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}
+"
+
+