From 2de0eb982182c2a8000eb07d5370c061381d33fd Mon Sep 17 00:00:00 2001 From: rread Date: Fri, 26 Jul 2002 16:48:54 +0000 Subject: [PATCH] - add support for building without libreadline --- lustre/configure.in | 4 +++ lustre/include/config.h.in | 10 ++++++ lustre/utils/parser.c | 78 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 lustre/include/config.h.in diff --git a/lustre/configure.in b/lustre/configure.in index 21c0aaf..5312c92 100644 --- a/lustre/configure.in +++ b/lustre/configure.in @@ -24,6 +24,8 @@ XML2_LIBS=$($XML2_CONFIG --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' @@ -84,6 +86,8 @@ AC_SUBST(docdir) 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 \ diff --git a/lustre/include/config.h.in b/lustre/include/config.h.in new file mode 100644 index 0000000..14f0f3b --- /dev/null +++ b/lustre/include/config.h.in @@ -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 diff --git a/lustre/utils/parser.c b/lustre/utils/parser.c index 8e8fd04..88a18cf 100644 --- a/lustre/utils/parser.c +++ b/lustre/utils/parser.c @@ -24,9 +24,12 @@ #include #include #include +#include #include #include +#include +#ifdef HAVE_LIBREADLINE #define READLINE_LIBRARY #include @@ -34,6 +37,7 @@ extern void using_history(void); extern void stifle_history(int); extern void add_history(char *); +#endif #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, @@ -224,6 +229,7 @@ static char **command_completion(char * text, int start, int end) return(completion_matches(text, command_generator)); } +#endif /* 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; } -/* 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); + 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; +#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) { - line = readline(parser_prompt); + line = readline(interactive ? parser_prompt : NULL); 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) { - 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); } - 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); -- 1.8.3.1