From c066a043f79860daf37234db3509156a3fc9205f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 11 Mar 1999 11:12:07 +0000 Subject: [PATCH] Added GNU readline support. HTML display in client. --- CHANGELOG | 4 ++ client/client.c | 54 +++++++++++++------ configure | 154 +++++++++++++++++++++++++++++++++++++++++++++++++------ configure.in | 9 +++- 4 files changed, 188 insertions(+), 33 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 020d6cd..2643508 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ Possible compatibility problems with earlier versions marked with '*'. +Added support for GNU readline in client. Thanks to Jacob Poulsen +. GNU configure attempts to detect if readline +is available. + * CHANGED DEFINITION OF ES: UPDATE (INCLUDING THE OID) to reflect the new definition from the ZIG. NOTE THIS IF YOU HAVE AN UPDATE IMPLEMENTATION! This change was made to the development version before diff --git a/client/client.c b/client/client.c index cf0de26..1016778 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.75 1999-02-01 15:37:32 adam + * Revision 1.76 1999-03-11 11:12:07 adam + * Added GNU readline support. HTML display in client. + * + * Revision 1.75 1999/02/01 15:37:32 adam * Fixed minor bug introduced by previous commit. * * Revision 1.74 1999/02/01 15:35:21 adam @@ -272,6 +275,13 @@ #include #endif +#if HAVE_READLINE_READLINE_H +#include +#endif +#if HAVE_READLINE_HISTORY_H +#include +#endif + #define C_PROMPT "Z> " static ODR out, in, print; /* encoding and decoding streams */ @@ -666,9 +676,15 @@ static void display_record(Z_DatabaseRecord *p) else if (r->which == Z_External_octet && p->u.octet_aligned->len) { const char *octet_buf = (char*)p->u.octet_aligned->buf; - if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML) + if (ent->value == VAL_TEXT_XML || ent->value == VAL_APPLICATION_XML || + ent->value == VAL_HTML) { - fwrite (octet_buf, 1, p->u.octet_aligned->len, stdout); + int i; + for (i = 0; iu.octet_aligned->len; i++) + if (octet_buf[i] > 126 || octet_buf[i] < 7) + printf ("<%02X>", octet_buf[i]); + else + fputc (octet_buf[i], stdout); printf ("\n"); } else @@ -1883,13 +1899,25 @@ static int client(int wait) #else if (!wait) #endif - { - /* quick & dirty way to get a command line. */ - char *end_p; - if (!fgets(line, 1023, stdin)) - break; - if ((end_p = strchr (line, '\n'))) - *end_p = '\0'; + { +#if HAVE_READLINE_READLINE_H + char* line_in; + line_in=readline(C_PROMPT); +#if HAVE_READLINE_HISTORY_H + if (*line_in) + add_history(line_in); +#endif + strcpy(line,line_in); + free (line_in); +#else + char *end_p; + printf (C_PROMPT); + fflush(stdout); + if (!fgets(line, 1023, stdin)) + break; + if ((end_p = strchr (line, '\n'))) + *end_p = '\0'; +#endif if ((res = sscanf(line, "%s %[^;]", word, arg)) <= 0) { strcpy(word, last_cmd); @@ -1914,7 +1942,6 @@ static int client(int wait) } if (res < 2) { - printf(C_PROMPT); continue; } } @@ -2003,8 +2030,6 @@ static int client(int wait) } } while (conn && cs_more(conn)); - printf(C_PROMPT); - fflush(stdout); } } return 0; @@ -2046,10 +2071,7 @@ int main(int argc, char **argv) } } if (!opened) - { initialize (); - printf (C_PROMPT); - } return client (opened); } diff --git a/configure b/configure index 662f93c..5466d78 100755 --- a/configure +++ b/configure @@ -1111,13 +1111,135 @@ fi fi +echo $ac_n "checking for readline in -lreadline""... $ac_c" 1>&6 +echo "configure:1116: checking for readline in -lreadline" >&5 +ac_lib_var=`echo readline'_'readline | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lreadline $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + LIBS="$LIBS -lreadline" +else + echo "$ac_t""no" 1>&6 +fi + +echo $ac_n "checking for add_history in -lhistory""... $ac_c" 1>&6 +echo "configure:1156: checking for add_history in -lhistory" >&5 +ac_lib_var=`echo history'_'add_history | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lhistory $LIBS" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + LIBS="$LIBS -lhistory" +else + echo "$ac_t""no" 1>&6 +fi + +if test "$ac_cv_lib_readline_readline" = "yes"; then + for ac_hdr in readline/readline.h readline/history.h +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:1200: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1210: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out` +if test -z "$ac_err"; then + rm -rf conftest* + eval "ac_cv_header_$ac_safe=yes" +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_header_$ac_safe=no" +fi +rm -f conftest* +fi +if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` + cat >> confdefs.h <&6 +fi +done + +fi echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1116: checking for ANSI C header files" >&5 +echo "configure:1238: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1125,7 +1247,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1129: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1251: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1142,7 +1264,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1160,7 +1282,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1181,7 +1303,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1192,7 +1314,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1196: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1318: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null then : else @@ -1231,17 +1353,17 @@ if test "$threads_ok" = "yes"; then do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1235: checking for $ac_hdr" >&5 +echo "configure:1357: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1245: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1367: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* @@ -1268,12 +1390,12 @@ fi done echo $ac_n "checking for pthread_mutex_lock""... $ac_c" 1>&6 -echo "configure:1272: checking for pthread_mutex_lock" >&5 +echo "configure:1394: checking for pthread_mutex_lock" >&5 if eval "test \"`echo '$''{'ac_cv_func_pthread_mutex_lock'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1422: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_pthread_mutex_lock=yes" else @@ -1317,7 +1439,7 @@ fi if test "$ac_cv_func_pthread_mutex_lock" = "no"; then echo $ac_n "checking for main in -lpthread""... $ac_c" 1>&6 -echo "configure:1321: checking for main in -lpthread" >&5 +echo "configure:1443: checking for main in -lpthread" >&5 ac_lib_var=`echo pthread'_'main | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1325,14 +1447,14 @@ else ac_save_LIBS="$LIBS" LIBS="-lpthread $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:1458: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else diff --git a/configure.in b/configure.in index c9d3385..342eb41 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ dnl YAZ Toolkit dnl (c) Index Data 1994-1998 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.5 1998-11-09 13:39:46 adam Exp $ +dnl $Id: configure.in,v 1.6 1999-03-11 11:12:07 adam Exp $ AC_INIT(include/yaz-version.h) dnl dnl ------ Checking programs @@ -43,6 +43,13 @@ if test "$checkBoth" = "1"; then fi AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"])) dnl +dnl ------ GNU Readline +AC_CHECK_LIB(readline, readline, [LIBS="$LIBS -lreadline"]) +AC_CHECK_LIB(history, add_history, [LIBS="$LIBS -lhistory"]) +if test "$ac_cv_lib_readline_readline" = "yes"; then + AC_CHECK_HEADERS(readline/readline.h readline/history.h) +fi +dnl dnl ------ Headers AC_STDC_HEADERS if test "$ac_cv_header_stdc" = "no"; then -- 1.7.10.4