OSDN Git Service

(_rl_read_file): Use O_BINARY in open. Enable the test for incomplete
authoreliz <eliz>
Wed, 15 Mar 2000 11:32:18 +0000 (11:32 +0000)
committereliz <eliz>
Wed, 15 Mar 2000 11:32:18 +0000 (11:32 +0000)
read.  Strip the CR characters by hand after readin the file.
(rl_read_init_file): Allow for ~/_intputrc on 8+3 filesystems.

readline/bind.c

index 300530a..73cd827 100644 (file)
@@ -62,6 +62,10 @@ extern int errno;
 extern char *strchr (), *strrchr ();
 #endif /* !strchr && !__STDC__ */
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 extern int _rl_horizontal_scroll_mode;
 extern int _rl_mark_modified_lines;
 extern int _rl_bell_preference;
@@ -83,6 +87,7 @@ extern int rl_complete_with_tilde_expansion;
 extern int rl_completion_query_items;
 extern int rl_inhibit_completion;
 extern char *_rl_comment_begin;
+extern unsigned char *_rl_isearch_terminators;
 
 extern int rl_explicit_arg;
 extern int rl_editing_mode;
@@ -207,13 +212,17 @@ rl_unbind_function_in_map (func, map)
      Function *func;
      Keymap map;
 {
-  register int i;
+  register int i, rval;
 
-  for (i = 0; i < KEYMAP_SIZE; i++)
+  for (i = rval = 0; i < KEYMAP_SIZE; i++)
     {
       if (map[i].type == ISFUNC && map[i].function == func)
-       map[i].function = (Function *)NULL;
+       {
+         map[i].function = (Function *)NULL;
+         rval = 1;
+       }
     }
+  return rval;
 }
 
 int
@@ -222,7 +231,6 @@ rl_unbind_command_in_map (command, map)
      Keymap map;
 {
   Function *func;
-  register int i;
 
   func = rl_named_function (command);
   if (func == 0)
@@ -642,7 +650,7 @@ _rl_read_file (filename, sizep)
   char *buffer;
   int i, file;
 
-  if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY, 0666)) < 0)
+  if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY | O_BINARY, 0666)) < 0)
     return ((char *)NULL);
 
   file_size = (size_t)finfo.st_size;
@@ -663,13 +671,41 @@ _rl_read_file (filename, sizep)
   i = read (file, buffer, file_size);
   close (file);
 
+#if 1
   if (i < file_size)
+#else
+  if (i < 0)
+#endif
     {
       free (buffer);
       return ((char *)NULL);
     }
 
   buffer[file_size] = '\0';
+
+#if O_BINARY
+  {
+    /* Systems which distinguish between text and binary files need
+       to strip the CR characters before each Newline, otherwise the
+       parsing functions won't work.  */
+    char *s, *d;
+    size_t removed = 0;
+
+    for (s = buffer, d = buffer; s < buffer + file_size; s++)
+      {
+       if (removed)
+         *d = *s;
+       if (*s != '\r' || s[1] != '\n')
+         d++;
+       else
+         removed++;
+      }
+
+    file_size -= removed;
+    buffer[file_size] = '\0';
+  }
+#endif
+
   if (sizep)
     *sizep = file_size;
   return (buffer);
@@ -691,6 +727,7 @@ rl_re_read_init_file (count, ignore)
      1. the filename used for the previous call
      2. the value of the shell variable `INPUTRC'
      3. ~/.inputrc
+     4. (for __MSDOS__ only) ~/_inputrc
    If the file existed and could be opened and read, 0 is returned,
    otherwise errno is returned. */
 int
@@ -710,6 +747,20 @@ rl_read_init_file (filename)
   if (*filename == 0)
     filename = DEFAULT_INPUTRC;
 
+#ifdef __MSDOS__
+  {
+    /* DOS doesn't allow leading dots in file names.  If the original
+       name fails (it could work if we are on Windows), fall back to
+       ~/_inputrc.  */
+    int retval = _rl_read_init_file (filename, 0);
+
+    if (retval == 0)
+      return retval;
+    else if (strcmp (filename, "~/.inputrc") == 0)
+      filename = "~/_inputrc";
+  }
+#endif
+
   return (_rl_read_init_file (filename, 0));
 }
 
@@ -727,6 +778,8 @@ _rl_read_init_file (filename, include_level)
 
   openname = tilde_expand (filename);
   buffer = _rl_read_file (openname, &file_size);
+  free (openname);
+
   if (buffer == 0)
     return (errno);
   
@@ -1338,7 +1391,34 @@ rl_variable_bind (name, value)
       else
         _rl_bell_preference = AUDIBLE_BELL;
     }
+  else if (_rl_stricmp (name, "isearch-terminators") == 0)
+    {
+      /* Isolate the value and translate it into a character string. */
+      int beg, end;
+      char *v;
 
+      v = savestring (value);
+      FREE (_rl_isearch_terminators);
+      if (v[0] == '"' || v[0] == '\'')
+       {
+         int delim = v[0];
+         for (beg = end = 1; v[end] && v[end] != delim; end++)
+           ;
+       }
+      else
+       {
+         for (beg = end = 0; whitespace (v[end]) == 0; end++)
+           ;
+       }
+
+      v[end] = '\0';
+      /* The value starts at v + beg.  Translate it into a character string. */
+      _rl_isearch_terminators = (unsigned char *)xmalloc (2 * strlen (v) + 1);
+      rl_translate_keyseq (v + beg, _rl_isearch_terminators, &end);
+      _rl_isearch_terminators[end] = '\0';
+      free (v);
+    }
+      
   /* For the time being, unknown variable names are simply ignored. */
   return 0;
 }
@@ -1492,7 +1572,7 @@ _rl_get_keyname (key)
      int key;
 {
   char *keyname;
-  int i, c, v;
+  int i, c;
 
   keyname = (char *)xmalloc (8);
 
@@ -1897,6 +1977,21 @@ rl_variable_dumper (print_readably)
     fprintf (rl_outstream, "set keymap %s\n", kname ? kname : "none");
   else
     fprintf (rl_outstream, "keymap is set to `%s'\n", kname ? kname : "none");
+
+  /* isearch-terminators */
+  if (_rl_isearch_terminators)
+    {
+      char *disp;
+
+      disp = _rl_untranslate_macro_value (_rl_isearch_terminators);
+
+      if (print_readably)
+       fprintf (rl_outstream, "set isearch-terminators \"%s\"\n", disp);
+      else
+       fprintf (rl_outstream, "isearch-terminators is set to \"%s\"\n", disp);
+
+      free (disp);
+    }
 }
 
 /* Print all of the current variables and their values to