Whamcloud - gitweb
- add support for building without libreadline
authorrread <rread>
Fri, 26 Jul 2002 16:48:54 +0000 (16:48 +0000)
committerrread <rread>
Fri, 26 Jul 2002 16:48:54 +0000 (16:48 +0000)
lustre/configure.in
lustre/include/config.h.in [new file with mode: 0644]
lustre/utils/parser.c

index 21c0aaf..5312c92 100644 (file)
@@ -24,6 +24,8 @@ XML2_LIBS=$($XML2_CONFIG --libs)
 AC_SUBST(XML2_CFLAGS)
 AC_SUBST(XML2_LIBS)
 
 AC_SUBST(XML2_CFLAGS)
 AC_SUBST(XML2_LIBS)
 
+AC_CHECK_LIB(readline, readline)
+
 # Kernel build environment.
 ac_default_prefix=
 bindir='${exec_prefix}/usr/bin'
 # Kernel build environment.
 ac_default_prefix=
 bindir='${exec_prefix}/usr/bin'
@@ -84,6 +86,8 @@ AC_SUBST(docdir)
 demodir='$(docdir)/demo'
 AC_SUBST(demodir)
 
 demodir='$(docdir)/demo'
 AC_SUBST(demodir)
 
+AM_CONFIG_HEADER(include/config.h)
+
 AC_OUTPUT(Makefile lib/Makefile ldlm/Makefile \
          obdecho/Makefile ptlrpc/Makefile \
        lov/Makefile osc/Makefile mdc/Makefile mds/Makefile ost/Makefile utils/Makefile \
 AC_OUTPUT(Makefile lib/Makefile ldlm/Makefile \
          obdecho/Makefile ptlrpc/Makefile \
        lov/Makefile osc/Makefile mdc/Makefile mds/Makefile ost/Makefile utils/Makefile \
diff --git a/lustre/include/config.h.in b/lustre/include/config.h.in
new file mode 100644 (file)
index 0000000..14f0f3b
--- /dev/null
@@ -0,0 +1,10 @@
+/* include/config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+/* Define if you have the `readline' library (-lreadline). */
+#undef HAVE_LIBREADLINE
+
+/* Name of package */
+#undef PACKAGE
+
+/* Version number of package */
+#undef VERSION
index 8e8fd04..88a18cf 100644 (file)
 #include <ctype.h>
 #include <string.h>
 #include <stddef.h>
 #include <ctype.h>
 #include <string.h>
 #include <stddef.h>
+#include <unistd.h>
 #include <sys/param.h>
 #include <assert.h>
 
 #include <sys/param.h>
 #include <assert.h>
 
+#include <config.h>
+#ifdef HAVE_LIBREADLINE
 #define READLINE_LIBRARY
 #include <readline/readline.h>
 
 #define READLINE_LIBRARY
 #include <readline/readline.h>
 
@@ -34,6 +37,7 @@
 extern void using_history(void);
 extern void stifle_history(int);
 extern void add_history(char *);
 extern void using_history(void);
 extern void stifle_history(int);
 extern void add_history(char *);
+#endif
 
 #include "parser.h"
 
 
 #include "parser.h"
 
@@ -179,6 +183,7 @@ static int process(char *s, char ** next, command_t *lookup,
         }
 }
 
         }
 }
 
+#ifdef HAVE_LIBREADLINE
 static char * command_generator(const char * text, int state) 
 {
         static int index,
 static char * command_generator(const char * text, int state) 
 {
         static int index,
@@ -224,6 +229,7 @@ static char **command_completion(char * text, int start, int end)
 
         return(completion_matches(text, command_generator));
 }
 
         return(completion_matches(text, command_generator));
 }
+#endif
 
 /* take a string and execute the function or print help */
 int execute_line(char * line)
 
 /* take a string and execute the function or print help */
 int execute_line(char * line)
@@ -270,20 +276,66 @@ int execute_line(char * line)
         return rc;
 }
 
         return rc;
 }
 
-/* this is the command execution machine */
-int Parser_commands(void)
+int
+noop_fn ()
 {
 {
-        char *line, *s;
-        int rc = 0;
+        return (0);
+}
 
 
+/* just in case you're ever in an airplane and discover you 
+   forgot to install readline-dev. :) */
+int init_input() 
+{
+        int   interactive = isatty (fileno (stdin));
+
+#ifdef HAVE_LIBREADLINE
         using_history();
         stifle_history(HISTORY);
 
         using_history();
         stifle_history(HISTORY);
 
+        if (!interactive)
+        {
+                rl_prep_term_function = (rl_vintfunc_t *)noop_fn;
+                rl_deprep_term_function = (rl_voidfunc_t *)noop_fn;
+        }
+
         rl_attempted_completion_function = (CPPFunction *)command_completion;
         rl_completion_entry_function = (void *)command_generator;
         rl_attempted_completion_function = (CPPFunction *)command_completion;
         rl_completion_entry_function = (void *)command_generator;
+#endif 
+        return interactive;
+}
+
+#ifndef HAVE_LIBREADLINE
+#define add_history(s)
+char * readline(char * prompt) 
+{
+        char line[2048];
+        int n;
+        char * ret = NULL;
+        if (prompt)
+                printf ("%s", prompt);
+        fgets(line, sizeof(line), stdin);
+        n = strlen(line);
+        if (n && line[n-1] == '\n')
+                line[--n] = '\0';
+        if (n == 0 && feof(stdin)) {
+                ret = NULL;
+        } else
+                ret =  strdup(line);
+        return ret;
+}
+#endif
+
+/* this is the command execution machine */
+int Parser_commands(void)
+{
+        char *line, *s;
+        int rc = 0;
+        int interactive;
+        
+        interactive = init_input();
 
         while(!done) {
 
         while(!done) {
-                line = readline(parser_prompt);
+                line = readline(interactive ? parser_prompt : NULL);
 
                 if (!line) break;
 
 
                 if (!line) break;
 
@@ -628,19 +680,19 @@ int Parser_size (int *sizep, char *str) {
 
 /* Convert a string boolean to an int; "enable" -> 1 */
 int Parser_bool (int *b, char *str) {
 
 /* Convert a string boolean to an int; "enable" -> 1 */
 int Parser_bool (int *b, char *str) {
-        if (strcasecmp (str, "no") ||
-            strcasecmp (str, "n") ||
-            strcasecmp (str, "off") ||
-            strcasecmp (str, "disable"))
+        if (!strcasecmp (str, "no") ||
+            !strcasecmp (str, "n") ||
+            !strcasecmp (str, "off") ||
+            !strcasecmp (str, "disable"))
         {
                 *b = 0;
                 return (0);
         }
         
         {
                 *b = 0;
                 return (0);
         }
         
-        if (strcasecmp (str, "yes") ||
-            strcasecmp (str, "y") ||
-            strcasecmp (str, "on") ||
-            strcasecmp (str, "enable"))
+        if (!strcasecmp (str, "yes") ||
+            !strcasecmp (str, "y") ||
+            !strcasecmp (str, "on") ||
+            !strcasecmp (str, "enable"))
         {
                 *b = 1;
                 return (0);
         {
                 *b = 1;
                 return (0);