Ilya Zakharevich on Tue, 21 Aug 2001 13:35:18 -0400


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

Runtime ReadLine switch-off


As I discovered, there are still some people who use cmdtool, and
GP/PARI loses point positioning with mouse when used in cmdtool with
readline support active.

This patch allows switching off the readline support at runtime with

  default(readline,0)

After this cmdtool allows mouse-positioning.  [Of course, no advanced
editing is possible after this - until default(readline,1).]

Enjoy,
Ilya

*** ./src/gp/gp.c-ini	Mon Aug  6 20:22:52 2001
--- ./src/gp/gp.c	Tue Aug 21 19:23:45 2001
***************
*** 33,38 ****
--- 33,40 ----
  
  #ifdef READLINE
    extern void init_readline();
+   long use_readline = 1;
+   int readline_init = 1;
  BEGINEXTERN
  #  if defined(__cplusplus) && defined(__SUNPRO_CC)
    /* readline.h gives a bad definition of readline() */
***************
*** 615,620 ****
--- 617,641 ----
  { return sd_numeric(v,flag,"debug",&DEBUGLEVEL, 0,20,NULL); }
  
  static GEN
+ sd_rl(char *v, int flag)
+ {
+ #ifdef READLINE
+ #  if 0			/* Works - even when init_readline() was called */
+     if (readline_init && *v == '0')
+ 	err(talker, "Too late to switch off readline mode");
+ #  endif
+     if (!readline_init && *v && *v != '0') {
+ 	init_readline();
+ 	readline_init = 1;
+     }
+     return sd_numeric(v,flag,"readline",&use_readline, 0,20,NULL);
+ #else	/* !( defined READLINE ) */
+     long dummy;
+     return sd_numeric(v,flag,"readline",&dummy, 0,20,NULL);
+ #endif
+ }
+ 
+ static GEN
  sd_debugfiles(char *v, int flag)
  { return sd_numeric(v,flag,"debugfiles",&DEBUGFILES, 0,20,NULL); }
  
***************
*** 898,903 ****
--- 919,925 ----
    {"prompt",(void*)sd_prompt},
    {"psfile",(void*)sd_psfile},
    {"realprecision",(void*)sd_realprecision},
+   {"readline",(void*)sd_rl},
    {"secure",(void*)sd_secure},
    {"seriesprecision",(void*)sd_seriesprecision},
    {"simplify",(void*)sd_simplify},
***************
*** 1532,1541 ****
  what_readline()
  {
  #ifdef READLINE
!  return "v"READLINE" enabled";
! #else
!   return "disabled";
  #endif
  }
  
  static void
--- 1554,1564 ----
  what_readline()
  {
  #ifdef READLINE
!   if (use_readline)
!     return "v"READLINE" enabled";
!   else
  #endif
+   return "disabled";
  }
  
  static void
***************
*** 1827,1836 ****
    if (!strncmp(s,"READL",5))
    {
  #ifdef READLINE
      return 1;
! #else
!     return 0;
  #endif
    }
    return -1;
  }
--- 1850,1860 ----
    if (!strncmp(s,"READL",5))
    {
  #ifdef READLINE
+   if (use_readline)
      return 1;
!   else
  #endif
+   return 0;
    }
    return -1;
  }
***************
*** 2229,2234 ****
--- 2253,2259 ----
    )
    {
  #ifdef READLINE
+    if (use_readline) {
      static char *previous_hist = NULL;
      char *rlbuffer = readline(promptbuf), *s = b->buf;
      int wait_for_brace, wait_for_input;
***************
*** 2291,2299 ****
        if (logfile) fprintf(logfile, "%s%s\n",promptbuf,s);
      }
      return 1;
! #else
!     pariputs(promptbuf);
  #endif /* defined(READLINE) */
    }
    else promptbuf = DFT_PROMPT;
    return get_line_from_file(infile, b, promptbuf);
--- 2316,2324 ----
        if (logfile) fprintf(logfile, "%s%s\n",promptbuf,s);
      }
      return 1;
!    } else
  #endif /* defined(READLINE) */
+     pariputs(promptbuf);
    }
    else promptbuf = DFT_PROMPT;
    return get_line_from_file(infile, b, promptbuf);
***************
*** 2665,2671 ****
    INIT_SIG_on;
    pari_sig_init(gp_sighandler);
  #ifdef READLINE
!   init_readline();
  #endif
    gp_history_fun = gp_history;
    whatnow_fun = whatnow;
--- 2690,2699 ----
    INIT_SIG_on;
    pari_sig_init(gp_sighandler);
  #ifdef READLINE
!   if (use_readline) {
!       init_readline();
!       readline_init = 1;
!   }
  #endif
    gp_history_fun = gp_history;
    whatnow_fun = whatnow;