[BACK]Return to readline.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libedit

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libedit/readline.c between version 1.36 and 1.39

version 1.36, 2003/10/09 00:42:28 version 1.39, 2003/10/19 06:28:35
Line 51  __RCSID("$NetBSD$");
Line 51  __RCSID("$NetBSD$");
 #include <stdlib.h>  #include <stdlib.h>
 #include <unistd.h>  #include <unistd.h>
 #include <limits.h>  #include <limits.h>
   #include <errno.h>
   #include <fcntl.h>
   #ifdef HAVE_VIS_H
 #include <vis.h>  #include <vis.h>
   #else
   #include "np/vis.h"
   #endif
 #ifdef HAVE_ALLOCA_H  #ifdef HAVE_ALLOCA_H
 #include <alloca.h>  #include <alloca.h>
 #endif  #endif
 #include "histedit.h"  #include "histedit.h"
 #include "readline/readline.h"  #include "readline/readline.h"
 #include "el.h"  #include "el.h"
   #include "tokenizer.h"
 #include "fcns.h"               /* for EL_NUM_FCNS */  #include "fcns.h"               /* for EL_NUM_FCNS */
   
 /* for rl_complete() */  /* for rl_complete() */
Line 80  int rl_point = 0;
Line 87  int rl_point = 0;
 int rl_end = 0;  int rl_end = 0;
 char *rl_line_buffer = NULL;  char *rl_line_buffer = NULL;
 VFunction *rl_linefunc = NULL;  VFunction *rl_linefunc = NULL;
   int rl_done = 0;
   VFunction *rl_event_hook = NULL;
   
 int history_base = 1;           /* probably never subject to change */  int history_base = 1;           /* probably never subject to change */
 int history_length = 0;  int history_length = 0;
Line 103  char *rl_terminal_name = NULL;
Line 112  char *rl_terminal_name = NULL;
 int rl_already_prompted = 0;  int rl_already_prompted = 0;
 int rl_filename_completion_desired = 0;  int rl_filename_completion_desired = 0;
 int rl_ignore_completion_duplicates = 0;  int rl_ignore_completion_duplicates = 0;
   int rl_catch_signals = 1;
 VFunction *rl_redisplay_function = NULL;  VFunction *rl_redisplay_function = NULL;
 Function *rl_startup_hook = NULL;  Function *rl_startup_hook = NULL;
 VFunction *rl_completion_display_matches_hook = NULL;  VFunction *rl_completion_display_matches_hook = NULL;
Line 159  static char  *_rl_compat_sub(const char 
Line 169  static char  *_rl_compat_sub(const char 
                             const char *, int);                              const char *, int);
 static int               rl_complete_internal(int);  static int               rl_complete_internal(int);
 static int               _rl_qsort_string_compare(const void *, const void *);  static int               _rl_qsort_string_compare(const void *, const void *);
   static int               _rl_event_read_char(EditLine *, char *);
   
   
 /* ARGSUSED */  /* ARGSUSED */
Line 243  rl_initialize(void)
Line 254  rl_initialize(void)
                 return -1;                  return -1;
         }          }
         el_set(e, EL_PROMPT, _get_prompt);          el_set(e, EL_PROMPT, _get_prompt);
         el_set(e, EL_SIGNAL, 1);          el_set(e, EL_SIGNAL, rl_catch_signals);
   
         /* set default mode to "emacs"-style and read setting afterwards */          /* set default mode to "emacs"-style and read setting afterwards */
         /* so this can be overriden */          /* so this can be overriden */
Line 302  readline(const char *prompt)
Line 313  readline(const char *prompt)
         int count;          int count;
         const char *ret;          const char *ret;
         char *buf;          char *buf;
           static int used_event_hook;
   
         if (e == NULL || h == NULL)          if (e == NULL || h == NULL)
                 rl_initialize();                  rl_initialize();
   
           rl_done = 0;
   
         /* update prompt accordingly to what has been passed */          /* update prompt accordingly to what has been passed */
         if (!prompt)          if (!prompt)
                 prompt = "";                  prompt = "";
Line 319  readline(const char *prompt)
Line 333  readline(const char *prompt)
         if (rl_pre_input_hook)          if (rl_pre_input_hook)
                 (*rl_pre_input_hook)(NULL, 0);                  (*rl_pre_input_hook)(NULL, 0);
   
           if (rl_event_hook && !(e->el_flags&NO_TTY)) {
                   el_set(e, EL_GETCFN, _rl_event_read_char);
                   used_event_hook = 1;
           }
   
           if (!rl_event_hook && used_event_hook) {
                   el_set(e, EL_GETCFN, EL_BUILTIN_GETCFN);
                   used_event_hook = 0;
           }
   
         rl_already_prompted = 0;          rl_already_prompted = 0;
   
         /* get one line from input stream */          /* get one line from input stream */
Line 1827  rl_bind_wrapper(EditLine *el, unsigned c
Line 1851  rl_bind_wrapper(EditLine *el, unsigned c
         if (map[c] == NULL)          if (map[c] == NULL)
             return CC_ERROR;              return CC_ERROR;
         (*map[c])(NULL, c);          (*map[c])(NULL, c);
   
           /* If rl_done was set by the above call, deal with it here */
           if (rl_done)
                   return CC_EOF;
   
         return CC_NORM;          return CC_NORM;
 }  }
   
Line 1838  rl_add_defun(const char *name, Function 
Line 1867  rl_add_defun(const char *name, Function 
                 return -1;                  return -1;
         map[(unsigned char)c] = fun;          map[(unsigned char)c] = fun;
         el_set(e, EL_ADDFN, name, name, rl_bind_wrapper);          el_set(e, EL_ADDFN, name, name, rl_bind_wrapper);
         el_set(e, EL_BIND, vis(dest, c, VIS_WHITE, 0), name);          vis(dest, c, VIS_WHITE|VIS_NOSLASH, 0);
           el_set(e, EL_BIND, dest, name);
         return 0;          return 0;
 }  }
   
Line 1905  rl_get_previous_history(int count, int k
Line 1935  rl_get_previous_history(int count, int k
                 el_push(e, a);                  el_push(e, a);
         return 0;          return 0;
 }  }
   
   void
   /*ARGSUSED*/
   rl_prep_terminal(int meta_flag)
   {
           el_set(e, EL_PREP_TERM, 1);
   }
   
   void
   rl_deprep_terminal()
   {
           el_set(e, EL_PREP_TERM, 0);
   }
   
   int
   rl_read_init_file(const char *s)
   {
           return(el_source(e, s));
   }
   
   int
   rl_parse_and_bind(const char *line)
   {
           const char **argv;
           int argc;
           Tokenizer *tok;
   
           tok = tok_init(NULL);
           tok_line(tok, line, &argc, &argv);
           argc = el_parse(e, argc, argv);
           tok_end(tok);
           return (argc ? 1 : 0);
   }
   
   void
   rl_stuff_char(int c)
   {
           char buf[2];
   
           buf[0] = c;
           buf[1] = '\0';
           el_insertstr(e, buf);
   }
   
   static int
   _rl_event_read_char(EditLine *el, char *cp)
   {
           int     n, num_read;
   
           *cp = 0;
           while (rl_event_hook) {
   
                   (*rl_event_hook)();
   
   #if defined(FIONREAD)
                   if (ioctl(el->el_infd, FIONREAD, &n) < 0)
                           return(-1);
                   if (n)
                           num_read = read(el->el_infd, cp, 1);
                   else
                           num_read = 0;
   #elif defined(F_SETFL) && defined(O_NDELAY)
                   if ((n = fcntl(el->el_infd, F_GETFL, 0)) < 0)
                           return(-1);
                   if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0)
                           return(-1);
                   num_read = read(el->el_infd, cp, 1);
                   if (fcntl(el->el_infd, F_SETFL, n))
                           return(-1);
   #else
                   /* not non-blocking, but what you gonna do? */
                   num_read = read(el->el_infd, cp, 1);
                   return(-1);
   #endif
   
                   if (num_read < 0 && errno == EAGAIN)
                           continue;
                   if (num_read == 0)
                           continue;
                   break;
           }
           if (!rl_event_hook)
                   el_set(el, EL_GETCFN, EL_BUILTIN_GETCFN);
           return(num_read);
   }

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.39

CVSweb <webmaster@jp.NetBSD.org>