Ilya Zakharevich on Fri, 29 Nov 2002 17:57:22 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PATCH oldish CVS] readline 1.0


This patch

 a) restores compatibility with readline 1.0 (at least headers);

 b) detects when history.h is missing (and corrects for it, sigh...);

 c) detects a (typical?) case mismatch between readline headers and
    library (when headers are old, but the library is newer - somebody
    installed "user-visible" update, but not developer-visible?); we do
    not do anything drastic in this case; only enable rl_save_prompt
    if the library version is 4.1 or more (do not know the exact
    transition time, should be after 2.1)

 d) Report both version of readline at compile time and now (if possible);

Enjoy,
Ilya

--- ./Configure-ppre	Fri Nov 29 16:07:39 2002
+++ ./Configure	Fri Nov 29 17:52:17 2002
@@ -1033,6 +1033,12 @@ if test "$optimization" != profiling; th
     case $x in
      ?:/*|/*) rl_include=`echo $x | sed 's,/readline.h,,'`
          echo ..."Found readline header in $rl_include"
+	 if (test -r "$rl_include/history.h"); then
+           echo ..."Found history header in $rl_include"
+	   rl_history=yes
+	 else
+           echo ..."No history header in $rl_include"
+	 fi
          if (grep CPPFunction $x > /dev/null 2>&1); then CPPF_defined=yes; fi
          if (grep rl_message  $x > /dev/null 2>&1); then rl_message=yes; fi
          if (grep rl_completion_matches $x > /dev/null 2>&1); then
@@ -1050,6 +1056,19 @@ if test "$optimization" != profiling; th
          if (grep rl_generic_bind $x > /dev/null 2>&1); then
            rl_genericbind=yes
          fi
+         if (grep rl_attempted_completion_over $x > /dev/null 2>&1); then
+           rl_attempted_completion_over=yes;
+         fi
+         if (grep rl_completion_query_items $x > /dev/null 2>&1); then
+           rl_completion_query_items=yes;
+         fi
+         if (grep rl_bind_key_in_map $x > /dev/null 2>&1); then
+           rl_bind_key_in_map=yes;
+         fi
+         if (grep rl_library_version $x > /dev/null 2>&1); then
+           rl_library_version=yes;
+	   rl_extra_flags="-DHAS_RL_LIBRARY_VERSION"
+         fi
          if (grep rl_save_prompt $x > /dev/null 2>&1); then
            rl_save_prompt=yes;
          else # might be defined but not declared (old readline)
@@ -1123,8 +1142,18 @@ if test "$optimization" != profiling; th
   else
     if test "$fastread" = yes; then
       exe=$osname-$arch-rlv$$
-      $CC $extraflag $RLINCLUDE -o $exe rl_version.c $RLLIBS 2> /dev/null
-      if test -r $exe; then readline=`$exe`; else readline=1.0; fi
+      $CC $extraflag $rl_extra_flags $RLINCLUDE -o $exe rl_version.c $RLLIBS 2> /dev/null
+      if test -r $exe; then readline=`$exe`; else readline="?.?"; fi
+      if test -z "$rl_library_version" -a "X$readline" != "X?.?"; then
+	  echo "!!! Possible mismatch between readline headers and library:"
+	  echo "!!!  header is apparently for v1.0, library reports $readline!"
+	  case "$readline" in
+	    # rl_save_prompt was not in 2.1, is in 4.1; do not know more...
+	    4.[1-9]*|[5-9]*) rl_fake_save_prompt=yes;;
+	  esac
+	  readline="1.0=Header/$readline=Lib"
+	  rl_fake_library_version=yes
+      fi
       rm -f $exe $exe$exe_suff
       echo "Using GNU readline, version $readline"
     fi
@@ -1134,10 +1163,23 @@ if test "$optimization" != profiling; th
     if test -z "$rl_genericbind"; then
       echo ..."Library readline does not have rl_generic_bind"
     fi
+    if test -z "$rl_completion_query_items"; then
+      echo ..."Library readline does not have rl_completion_query_items"
+    fi
+    if test -z "$rl_bind_key_in_map"; then
+      echo ..."Library readline does not have rl_bind_key_in_map"
+    fi
+    if test -z "$rl_attempted_completion_over"; then
+      echo ..."Library readline does not have rl_attempted_completion_over"
+    fi
     if test -z "$rl_save_prompt"; then
       echo ..."Library readline does not have rl_save_prompt"
       if test -n "$_rl_save_prompt"; then
         echo ......"but it has _rl_save_prompt"
+	if test -n "$rl_fake_save_prompt"; then
+	    echo ........."but due to library mismatch we fake rl_save_prompt"
+	    rl_save_prompt=yes
+	fi
       fi
     fi
 
@@ -1393,8 +1435,9 @@ for variable in\
   ranlib gzip zcat emacs perl ln_s make_sh exe_suff\
   readline readline_enabledp CPPF_defined rl_refresh_line_oldproto\
   rl_appendchar rl_genericbind rl_save_prompt _rl_save_prompt rl_message\
-  rl_completion_matches rl_completion_func_t\
-  RLINCLUDE RLLIBS\
+  rl_completion_matches rl_completion_func_t rl_history rl_bind_key_in_map\
+  rl_attempted_completion_over rl_completion_query_items rl_library_version\
+  rl_fake_library_version RLINCLUDE RLLIBS\
   sizeof_long doubleformat\
   gnuplot extralib X11 Xincroot which_graphic_lib gnuplot_libs graphic_lib_dll\
   $_has_list; do
--- ./config/rl_version.c-pre	Fri Nov 29 16:57:47 2002
+++ ./config/rl_version.c	Fri Nov 29 17:12:13 2002
@@ -4,4 +4,9 @@
 #   else
 #     include <readline/readline.h>
 #   endif
-main(){ printf(rl_library_version); }
+
+#ifndef HAS_RL_LIBRARY_VERSION
+extern char *rl_library_version; /* Might be mismatched header, try anyway! */
+#endif
+
+main(){ printf("%s", rl_library_version); }
--- ./config/paricfg.h.SH-pre	Fri Nov 29 16:42:16 2002
+++ ./config/paricfg.h.SH	Fri Nov 29 17:15:09 2002
@@ -107,6 +107,24 @@ EOT
   if test -n "$rl_completion_func_t"; then
     echo '#define HAS_RL_COMPLETION_FUNC_T' >> $file
   fi
+  if test -n "$rl_history"; then
+    echo '#define HAS_HISTORY_H' >> $file
+  fi
+  if test -n "$rl_attempted_completion_over"; then
+    echo '#define HAS_RL_ATTEMPTED_COMPLETION_OVER' >> $file
+  fi
+  if test -n "$rl_completion_query_items"; then
+    echo '#define HAS_RL_COMPLETION_QUERY_ITEMS' >> $file
+  fi
+  if test -n "$rl_bind_key_in_map"; then
+    echo '#define HAS_RL_BIND_KEY_IN_MAP' >> $file
+  fi
+  if test -n "$rl_library_version"; then
+    echo '#define HAS_RL_LIBRARY_VERSION' >> $file
+  fi
+  if test -n "$rl_fake_library_version"; then
+    echo '#define FAKE_RL_LIBRARY_VERSION' >> $file
+  fi
   echo >> $file
 fi
 
--- ./src/gp/gp.c-pre	Tue Oct 22 14:41:38 2002
+++ ./src/gp/gp.c	Fri Nov 29 17:24:44 2002
@@ -1641,11 +1641,21 @@ print_shortversion(void)
 static void
 print_version(void)
 {
-  char buf[64];
+  char buf[256];
+#if defined(HAS_RL_LIBRARY_VERSION) || defined(FAKE_RL_LIBRARY_VERSION)
+  char RL_nowver[64];
+#  ifdef FAKE_RL_LIBRARY_VERSION
+  extern char *rl_library_version;
+#  endif
+
+  sprintf(RL_nowver, " (now v%s)", rl_library_version);
+#else
+#  define RL_nowver ""
+#endif
 
   center(PARIVERSION); center(PARIINFO);
-  sprintf(buf,"(readline %s, extended help%s available)", what_readline(),
-          has_ext_help()? "": " not");
+  sprintf(buf,"(readline %s%s, extended help%s available)", what_readline(),
+          RL_nowver, has_ext_help()? "": " not");
   center(buf);
 }
 
--- ./src/gp/gp_rl.c-pre	Wed Nov 13 03:08:56 2002
+++ ./src/gp/gp_rl.c	Fri Nov 29 16:36:06 2002
@@ -34,10 +34,14 @@ BEGINEXTERN
 #endif
 #ifdef READLINE_LIBRARY
 #  include <readline.h>
-#  include <history.h>
+#  ifdef HAS_HISTORY_H
+#    include <history.h>
+#  endif
 #else
 #  include <readline/readline.h>
-#  include <readline/history.h>
+#  ifdef HAS_HISTORY_H
+#    include <readline/history.h>
+#  endif
 #endif
 #ifndef HAS_RL_MESSAGE
 extern int rl_message (const char *, ...);
@@ -546,7 +550,9 @@ pari_completion(char *text, int START, i
 	 && (ep = is_entry(buf)) && ep->help)
      {
       rl_print_aide(buf,h_RL);
+#ifdef HAS_RL_ATTEMPTED_COMPLETION_OVER
       rl_attempted_completion_over = 1;
+#endif
       return NULL;
     }
   }
@@ -620,10 +626,16 @@ init_readline(void)
   rl_attempted_completion_function = (rl_completion_func_t*) pari_completion;
 
   /* we always want the whole list of completions under emacs */
+#ifdef HAS_RL_COMPLETION_QUERY_ITEMS
   if (GP_DATA->flags & EMACS) rl_completion_query_items = 0x8fff;
-
-#define Bind(a,b,c) (((void(*)(int,Function*,Keymap)) rl_bind_key_in_map)\
+#endif
+#ifdef HAS_RL_BIND_KEY_IN_MAP
+#  define Bind(a,b,c) (((void(*)(int,Function*,Keymap)) rl_bind_key_in_map)\
   ((a), (Function*)(b), (c)))
+#else
+#  define Bind(a,b,c)
+#endif
+
 #define Defun(a,b,c) (((void(*)(const char*,Function*,int)) rl_add_defun)\
   ((a), (Function*)(b), (c)))
 
@@ -744,6 +756,12 @@ texmacs_completion(char *s, long pos)
   printf(")%c", DATA_END);
   fflush(stdout);
 }
+
+#ifndef HAS_HISTORY_H
+extern int history_length;
+typedef struct HIST_ENTRY__ {char *line; void *data;} HIST_ENTRY;
+extern HIST_ENTRY *history_get(int);
+#endif
 
 static int
 history_is_new(char *s)