home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / TERMNET / READLINE.0 / COMPLETE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-20  |  37.4 KB  |  1,418 lines

  1. /* complete.c -- filename completion for readline. */
  2.  
  3. /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
  4.  
  5.    This file is part of the GNU Readline Library, a library for
  6.    reading lines of text with interactive input and history editing.
  7.  
  8.    The GNU Readline Library is free software; you can redistribute it
  9.    and/or modify it under the terms of the GNU General Public License
  10.    as published by the Free Software Foundation; either version 1, or
  11.    (at your option) any later version.
  12.  
  13.    The GNU Readline Library is distributed in the hope that it will be
  14.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  15.    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    The GNU General Public License is often shipped with GNU software, and
  19.    is generally kept in a file called COPYING or LICENSE.  If you do not
  20.    have a copy of the license, write to the Free Software Foundation,
  21.    675 Mass Ave, Cambridge, MA 02139, USA. */
  22. #define READLINE_LIBRARY
  23.  
  24. #include <stdio.h>
  25. #include <sys/types.h>
  26. #include <fcntl.h>
  27. #if !defined (NO_SYS_FILE)
  28. #  include <sys/file.h>
  29. #endif /* !NO_SYS_FILE */
  30.  
  31. #if defined (HAVE_UNISTD_H)
  32. #  include <unistd.h>
  33. #endif /* HAVE_UNISTD_H */
  34.  
  35. #if defined (HAVE_STDLIB_H)
  36. #  include <stdlib.h>
  37. #else
  38. #  include "ansi_stdlib.h"
  39. #endif /* HAVE_STDLIB_H */
  40.  
  41. #include <errno.h>
  42. /* Not all systems declare ERRNO in errno.h... and some systems #define it! */
  43. #if !defined (errno)
  44. extern int errno;
  45. #endif /* !errno */
  46.  
  47. #include <pwd.h>
  48. #if defined (USG) && !defined (HAVE_GETPW_DECLS)
  49. extern struct passwd *getpwent ();
  50. #endif /* USG && !HAVE_GETPW_DECLS */
  51.  
  52. /* ISC systems don't define getpwent() if _POSIX_SOURCE is defined. */
  53. #if defined (isc386) && defined (_POSIX_SOURCE)
  54. #  if defined (__STDC__)
  55. extern struct passwd *getpwent (void);
  56. #  else
  57. extern struct passwd *getpwent ();
  58. #  endif /* !__STDC__ */
  59. #endif /* isc386 && _POSIX_SOURCE */
  60.  
  61. #include "posixstat.h"
  62.  
  63. /* System-specific feature definitions and include files. */
  64. #include "rldefs.h"
  65.  
  66. /* Some standard library routines. */
  67. #include "readline.h"
  68.  
  69. /* Possible values for do_replace in rl_complete_internal. */
  70. #define NO_MATCH    0
  71. #define SINGLE_MATCH    1
  72. #define MULT_MATCH    2
  73.  
  74. #if !defined (strchr) && !defined (__STDC__)
  75. extern char *strchr (), *strrchr ();
  76. #endif /* !strchr && !__STDC__ */
  77.  
  78. extern char *tilde_expand ();
  79. extern char *rl_copy_text ();
  80.  
  81. extern Function *rl_last_func;
  82. extern int rl_editing_mode;
  83. extern int screenwidth;
  84.  
  85. /* Forward declarations for functions defined and used in this file. */
  86. char *filename_completion_function ();
  87. char **completion_matches ();
  88.  
  89. static int compare_strings ();
  90. static char *rl_strpbrk ();
  91.  
  92. #if defined (STATIC_MALLOC)
  93. static char *xmalloc (), *xrealloc ();
  94. #else
  95. extern char *xmalloc (), *xrealloc ();
  96. #endif /* STATIC_MALLOC */
  97.  
  98. /* If non-zero, then this is the address of a function to call when
  99.    completing on a directory name.  The function is called with
  100.    the address of a string (the current directory name) as an arg. */
  101. Function *rl_directory_completion_hook = (Function *)NULL;
  102.  
  103. /* Non-zero means readline completion functions perform tilde expansion. */
  104. int rl_complete_with_tilde_expansion = 0;
  105.  
  106. /* If non-zero, non-unique completions always show the list of matches. */
  107. int _rl_complete_show_all = 0;
  108.  
  109. #if defined (VISIBLE_STATS)
  110. #  if !defined (X_OK)
  111. #    define X_OK 1
  112. #  endif
  113.  
  114. static int stat_char ();
  115.  
  116. /* Non-zero means add an additional character to each filename displayed
  117.    during listing completion iff rl_filename_completion_desired which helps
  118.    to indicate the type of file being listed. */
  119. int rl_visible_stats = 0;
  120. #endif /* VISIBLE_STATS */
  121.  
  122. /* **************************************************************** */
  123. /*                                    */
  124. /*    Completion matching, from readline's point of view.        */
  125. /*                                    */
  126. /* **************************************************************** */
  127.  
  128. /* Pointer to the generator function for completion_matches ().
  129.    NULL means to use filename_entry_function (), the default filename
  130.    completer. */
  131. Function *rl_completion_entry_function = (Function *)NULL;
  132.  
  133. /* Pointer to alternative function to create matches.
  134.    Function is called with TEXT, START, and END.
  135.    START and END are indices in RL_LINE_BUFFER saying what the boundaries
  136.    of TEXT are.
  137.    If this function exists and returns NULL then call the value of
  138.    rl_completion_entry_function to try to match, otherwise use the
  139.    array of strings returned. */
  140. CPPFunction *rl_attempted_completion_function = (CPPFunction *)NULL;
  141.  
  142. /* Non-zero means to suppress normal filename completion after the
  143.    user-specified completion function has been called. */
  144. int rl_attempted_completion_over = 0;
  145.  
  146. /* Local variable states what happened during the last completion attempt. */
  147. static int completion_changed_buffer = 0;
  148.  
  149. /* Complete the word at or before point.  You have supplied the function
  150.    that does the initial simple matching selection algorithm (see
  151.    completion_matches ()).  The default is to do filename completion. */
  152.  
  153. rl_complete (ignore, invoking_key)
  154.      int ignore, invoking_key;
  155. {
  156.   if (rl_last_func == rl_complete && !completion_changed_buffer)
  157.     return (rl_complete_internal ('?'));
  158.   else if (_rl_complete_show_all)
  159.     return (rl_complete_internal ('!'));
  160.   else
  161.     return (rl_complete_internal (TAB));
  162. }
  163.  
  164. /* List the possible completions.  See description of rl_complete (). */
  165. rl_possible_completions (ignore, invoking_key)
  166.      int ignore, invoking_key;
  167. {
  168.   return (rl_complete_internal ('?'));
  169. }
  170.  
  171. rl_insert_completions (ignore, invoking_key)
  172.      int ignore, invoking_key;
  173. {
  174.   return (rl_complete_internal ('*'));
  175. }
  176.  
  177. /* The user must press "y" or "n". Non-zero return means "y" pressed. */
  178. get_y_or_n ()
  179. {
  180.   int c;
  181.  
  182.   for (;;)
  183.     {
  184.       c = rl_read_key ();
  185.       if (c == 'y' || c == 'Y' || c == ' ')
  186.     return (1);
  187.       if (c == 'n' || c == 'N' || c == RUBOUT)
  188.     return (0);
  189.       if (c == ABORT_CHAR)
  190.     rl_abort ();
  191.       ding ();
  192.     }
  193. }
  194.  
  195. /* Up to this many items will be displayed in response to a
  196.    possible-completions call.  After that, we ask the user if
  197.    she is sure she wants to see them all. */
  198. int rl_completion_query_items = 100;
  199.  
  200. /* The basic list of characters that signal a break between words for the
  201.    completer routine.  The contents of this variable is what breaks words
  202.    in the shell, i.e. " \t\n\"\\'`@$><=" */
  203. char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(";
  204.  
  205. /* The list of characters that signal a break between words for
  206.    rl_complete_internal.  The default list is the contents of
  207.    rl_basic_word_break_characters.  */
  208. char *rl_completer_word_break_characters = (char *)NULL;
  209.  
  210. /* List of characters which can be used to quote a substring of the line.
  211.    Completion occurs on the entire substring, and within the substring
  212.    rl_completer_word_break_characters are treated as any other character,
  213.    unless they also appear within this list. */
  214. char *rl_completer_quote_characters = (char *)NULL;
  215.  
  216. /* List of characters that are word break characters, but should be left
  217.    in TEXT when it is passed to the completion function.  The shell uses
  218.    this to help determine what kind of completing to do. */
  219. char *rl_special_prefixes = (char *)NULL;
  220.  
  221. /* If non-zero, then disallow duplicates in the matches. */
  222. int rl_ignore_completion_duplicates = 1;
  223.  
  224. /* Non-zero means that the results of the matches are to be treated
  225.    as filenames.  This is ALWAYS zero on entry, and can only be changed
  226.    within a completion entry finder function. */
  227. int rl_filename_completion_desired = 0;
  228.  
  229. /* Non-zero means that the results of the matches are to be quoted using
  230.    double quotes (or an application-specific quoting mechanism) if the
  231.    filename contains any characters in rl_word_break_chars.  This is
  232.    ALWAYS non-zero on entry, and can only be changed within a completion
  233.    entry finder function. */
  234. int rl_filename_quoting_desired = 1;
  235.  
  236. /* This function, if defined, is called by the completer when real
  237.    filename completion is done, after all the matching names have been
  238.    generated. It is passed a (char**) known as matches in the code below.
  239.    It consists of a NULL-terminated array of pointers to potential
  240.    matching strings.  The 1st element (matches[0]) is the maximal
  241.    substring that is common to all matches. This function can re-arrange
  242.    the list of matches as required, but all elements of the array must be
  243.    free()'d if they are deleted. The main intent of this function is
  244.    to implement FIGNORE a la SunOS csh. */
  245. Function *rl_ignore_some_completions_function = (Function *)NULL;
  246.  
  247. #if defined (SHELL)
  248. /* A function to strip quotes that are not protected by backquotes.  It
  249.    allows single quotes to appear within double quotes, and vice versa.
  250.    It should be smarter.  It's fairly shell-specific, hence the SHELL
  251.    definition wrapper. */
  252. static char *
  253. _delete_quotes (text)
  254.      char *text;
  255. {
  256.   char *ret, *p, *r;
  257.   int l, quoted;
  258.  
  259.   l = strlen (text);
  260.   ret = xmalloc (l + 1);
  261.   for (quoted = 0, p = text, r = ret; p && *p; p++)
  262.     {
  263.       /* Allow backslash-quoted characters to pass through unscathed. */
  264.       if (*p == '\\')
  265.         continue;
  266.       /* Close quote. */
  267.       if (quoted && *p == quoted)
  268.     {
  269.       quoted = 0;
  270.       continue;
  271.     }
  272.       /* Open quote. */
  273.       if (quoted == 0 && (*p == '\'' || *p == '"'))
  274.     {
  275.       quoted = *p;
  276.       continue;
  277.     }
  278.       *r++ = *p;
  279.     }
  280.   *r = '\0';
  281.   return ret;
  282. }
  283. #endif /* SHELL */
  284.  
  285. /* Return the portion of PATHNAME that should be output when listing
  286.    possible completions.  If we are hacking filename completion, we
  287.    are only interested in the basename, the portion following the
  288.    final slash.  Otherwise, we return what we were passed. */
  289. static char *
  290. printable_part (pathname)
  291.       char *pathname;
  292. {
  293.   char *temp = (char *)NULL;
  294.  
  295.   if (rl_filename_completion_desired)
  296.     temp = strrchr (pathname, '/');
  297.  
  298.   if (!temp)
  299.     return (pathname);
  300.   else
  301.     return (++temp);
  302. }
  303.  
  304. /* Output TO_PRINT to rl_outstream.  If VISIBLE_STATS is defined and we
  305.    are using it, check for and output a single character for `special'
  306.    filenames.  Return 1 if we printed an extension character, 0 if not. */
  307. static int
  308. print_filename (to_print, full_pathname)
  309.      char *to_print, *full_pathname;
  310. {
  311. #if !defined (VISIBLE_STATS)
  312.   fputs (to_print, rl_outstream);
  313.   return 0;
  314. #else  
  315.   char *s, c, *new_full_pathname;
  316.   int extension_char = 0, slen, tlen;
  317.  
  318.   fputs (to_print, rl_outstream);
  319.   if (rl_filename_completion_desired && rl_visible_stats)
  320.     {
  321.       /* If to_print != full_pathname, to_print is the basename of the
  322.      path passed.  In this case, we try to expand the directory
  323.      name before checking for the stat character. */
  324.       if (to_print != full_pathname)
  325.     {
  326.       /* Terminate the directory name. */
  327.       c = to_print[-1];
  328.       to_print[-1] = '\0';
  329.  
  330.       s = tilde_expand (full_pathname);
  331.       if (rl_directory_completion_hook)
  332.         (*rl_directory_completion_hook) (&s);
  333.  
  334.       slen = strlen (s);
  335.       tlen = strlen (to_print);
  336.       new_full_pathname = xmalloc (slen + tlen + 2);
  337.       strcpy (new_full_pathname, s);
  338.       new_full_pathname[slen] = '/';
  339.       strcpy (new_full_pathname + slen + 1, to_print);
  340.  
  341.       extension_char = stat_char (new_full_pathname);
  342.  
  343.       free (new_full_pathname);
  344.       to_print[-1] = c;
  345.     }
  346.       else
  347.     {
  348.       s = tilde_expand (full_pathname);
  349.       extension_char = stat_char (s);
  350.     }
  351.  
  352.       free (s);
  353.       if (extension_char)
  354.     putc (extension_char, rl_outstream);
  355.       return (extension_char != 0);
  356.     }
  357.   else
  358.     return 0;
  359. #endif /* VISIBLE_STATS */
  360. }
  361.  
  362. /* Complete the word at or before point.
  363.    WHAT_TO_DO says what to do with the completion.
  364.    `?' means list the possible completions.
  365.    TAB means do standard completion.
  366.    `*' means insert all of the possible completions.
  367.    `!' means to do standard completion, and list all possible completions if
  368.    there is more than one. */
  369. rl_complete_internal (what_to_do)
  370.      int what_to_do;
  371. {
  372.   char **matches;
  373.   Function *our_func;
  374.   int start, scan, end, delimiter = 0, pass_next;
  375.   char *text, *saved_line_buffer;
  376.   char *replacement;
  377.   char quote_char = '\0';
  378.   int found_quote = 0;
  379.  
  380.   if (rl_line_buffer)
  381.     saved_line_buffer = savestring (rl_line_buffer);
  382.   else
  383.     saved_line_buffer = (char *)NULL;
  384.  
  385.   if (rl_completion_entry_function)
  386.     our_func = rl_completion_entry_function;
  387.   else
  388.     our_func = (Function *)filename_completion_function;
  389.  
  390.   /* Only the completion entry function can change these. */
  391.   rl_filename_completion_desired = 0;
  392.   rl_filename_quoting_desired = 1;
  393.  
  394.   /* We now look backwards for the start of a filename/variable word. */
  395.   end = rl_point;
  396.  
  397.   if (rl_point)
  398.     {
  399.       if (rl_completer_quote_characters)
  400.     {
  401.       /* We have a list of characters which can be used in pairs to
  402.          quote substrings for the completer.  Try to find the start
  403.          of an unclosed quoted substring. */
  404.       /* FOUND_QUOTE is set so we know what kind of quotes we found. */
  405.       for (scan = pass_next = 0; scan < end; scan++)
  406.         {
  407.           if (pass_next)
  408.         {
  409.           pass_next = 0;
  410.           continue;
  411.         }
  412.  
  413.           if (rl_line_buffer[scan] == '\\')
  414.         {
  415.           pass_next = 1;
  416.           found_quote |= 4;
  417.           continue;
  418.         }
  419.  
  420.           if (quote_char != '\0')
  421.         {
  422.           /* Ignore everything until the matching close quote char. */
  423.           if (rl_line_buffer[scan] == quote_char)
  424.             {
  425.               /* Found matching close.  Abandon this substring. */
  426.               quote_char = '\0';
  427.               rl_point = end;
  428.             }
  429.         }
  430.           else if (strchr (rl_completer_quote_characters, rl_line_buffer[scan]))
  431.         {
  432.           /* Found start of a quoted substring. */
  433.           quote_char = rl_line_buffer[scan];
  434.           rl_point = scan + 1;
  435.           /* Shell-like quoting conventions. */
  436.           if (quote_char == '\'')
  437.             found_quote |= 1;
  438.           else if (quote_char == '"')
  439.             found_quote |= 2;
  440.         }
  441.         }
  442.     }
  443.  
  444.       if (rl_point == end)
  445.     {
  446.       int quoted = 0;
  447.       /* We didn't find an unclosed quoted substring upon which to do
  448.          completion, so use the word break characters to find the
  449.          substring on which to complete. */
  450.       while (--rl_point)
  451.         {
  452.           scan = rl_line_buffer[rl_point];
  453.  
  454.           if (strchr (rl_completer_word_break_characters, scan) == 0)
  455.         continue;
  456.  
  457. #if defined (SHELL)
  458.           /* Don't let word break characters in quoted substrings break
  459.          words for the completer. */
  460.           if (found_quote && char_is_quoted (rl_line_buffer, rl_point))
  461.         continue;
  462. #endif /* SHELL */
  463.  
  464.           /* Convoluted code, but it avoids an n^2 algorithm with calls
  465.                to char_is_quoted. */
  466.           break;
  467.         }
  468.     }
  469.  
  470.       /* If we are at an unquoted word break, then advance past it. */
  471.       scan = rl_line_buffer[rl_point];
  472. #if defined (SHELL)
  473.       if ((found_quote == 0 || char_is_quoted (rl_line_buffer, rl_point) == 0) &&
  474.           strchr (rl_completer_word_break_characters, scan))
  475. #else
  476.       if (strchr (rl_completer_word_break_characters, scan))
  477. #endif
  478.     {
  479.       /* If the character that caused the word break was a quoting
  480.          character, then remember it as the delimiter. */
  481.       if (strchr ("\"'", scan) && (end - rl_point) > 1)
  482.         delimiter = scan;
  483.  
  484.       /* If the character isn't needed to determine something special
  485.          about what kind of completion to perform, then advance past it. */
  486.       if (!rl_special_prefixes || strchr (rl_special_prefixes, scan) == 0)
  487.         rl_point++;
  488.     }
  489.     }
  490.  
  491.   /* At this point, we know we have an open quote if quote_char != '\0'. */
  492.   start = rl_point;
  493.   rl_point = end;
  494.   text = rl_copy_text (start, end);
  495.  
  496.   /* If the user wants to TRY to complete, but then wants to give
  497.      up and use the default completion function, they set the
  498.      variable rl_attempted_completion_function. */
  499.   if (rl_attempted_completion_function)
  500.     {
  501.       matches = (*rl_attempted_completion_function) (text, start, end);
  502.  
  503.       if (matches || rl_attempted_completion_over)
  504.     {
  505.       rl_attempted_completion_over = 0;
  506.       our_func = (Function *)NULL;
  507.       goto after_usual_completion;
  508.     }
  509.     }
  510.  
  511. #if defined (SHELL)
  512.   /* Beware -- we're stripping the quotes here.  Do this only if we know
  513.      we are doing filename completion. */
  514.   if (found_quote && our_func == (Function *)filename_completion_function)
  515.     {
  516.       /* delete single and double quotes */
  517.       replacement = _delete_quotes (text);
  518.       free (text);
  519.       text = replacement;
  520.       replacement = (char *)0;
  521.     }
  522. #endif /* SHELL */
  523.  
  524.   matches = completion_matches (text, our_func);
  525.  
  526.  after_usual_completion:
  527.   free (text);
  528.  
  529.   if (!matches)
  530.     ding ();
  531.   else
  532.     {
  533.       register int i;
  534.       int should_quote;
  535.  
  536.       /* It seems to me that in all the cases we handle we would like
  537.      to ignore duplicate possiblilities.  Scan for the text to
  538.      insert being identical to the other completions. */
  539.       if (rl_ignore_completion_duplicates)
  540.     {
  541.       char *lowest_common;
  542.       int j, newlen = 0;
  543.       char dead_slot;
  544.       char **temp_array;
  545.  
  546.       /* Sort the items. */
  547.       /* It is safe to sort this array, because the lowest common
  548.          denominator found in matches[0] will remain in place. */
  549.       for (i = 0; matches[i]; i++);
  550.       qsort (matches, i, sizeof (char *), compare_strings);
  551.  
  552.       /* Remember the lowest common denominator for it may be unique. */
  553.       lowest_common = savestring (matches[0]);
  554.  
  555.       for (i = 0; matches[i + 1]; i++)
  556.         {
  557.           if (strcmp (matches[i], matches[i + 1]) == 0)
  558.         {
  559.           free (matches[i]);
  560.           matches[i] = (char *)&dead_slot;
  561.         }
  562.           else
  563.         newlen++;
  564.         }
  565.  
  566.       /* We have marked all the dead slots with (char *)&dead_slot.
  567.          Copy all the non-dead entries into a new array. */
  568.       temp_array = (char **)xmalloc ((3 + newlen) * sizeof (char *));
  569.       for (i = j = 1; matches[i]; i++)
  570.         {
  571.           if (matches[i] != (char *)&dead_slot)
  572.         temp_array[j++] = matches[i];
  573.         }
  574.       temp_array[j] = (char *)NULL;
  575.  
  576.       if (matches[0] != (char *)&dead_slot)
  577.         free (matches[0]);
  578.       free (matches);
  579.  
  580.       matches = temp_array;
  581.  
  582.       /* Place the lowest common denominator back in [0]. */
  583.       matches[0] = lowest_common;
  584.  
  585.       /* If there is one string left, and it is identical to the
  586.          lowest common denominator, then the LCD is the string to
  587.          insert. */
  588.       if (j == 2 && strcmp (matches[0], matches[1]) == 0)
  589.         {
  590.           free (matches[1]);
  591.           matches[1] = (char *)NULL;
  592.         }
  593.     }
  594.  
  595.       switch (what_to_do)
  596.     {
  597.     case TAB:
  598.     case '!':
  599.       /* If we are matching filenames, then here is our chance to
  600.          do clever processing by re-examining the list.  Call the
  601.          ignore function with the array as a parameter.  It can
  602.          munge the array, deleting matches as it desires. */
  603.       if (rl_ignore_some_completions_function &&
  604.           our_func == (Function *)filename_completion_function)
  605.         (void)(*rl_ignore_some_completions_function)(matches);
  606.  
  607.       /* If we are doing completion on quoted substrings, and any matches
  608.          contain any of the completer_word_break_characters, then auto-
  609.          matically prepend the substring with a quote character (just pick
  610.          the first one from the list of such) if it does not already begin
  611.          with a quote string.  FIXME: Need to remove any such automatically
  612.          inserted quote character when it no longer is necessary, such as
  613.          if we change the string we are completing on and the new set of
  614.          matches don't require a quoted substring. */
  615.       replacement = matches[0];
  616.  
  617.       should_quote = matches[0] && rl_completer_quote_characters &&
  618.              rl_filename_completion_desired &&
  619.              rl_filename_quoting_desired;
  620.  
  621.       if (should_quote)
  622. #if defined (SHELL)
  623.         should_quote = should_quote && (!quote_char || quote_char == '"');
  624. #else
  625.         should_quote = should_quote && !quote_char;
  626. #endif
  627.  
  628.       if (should_quote)
  629.         {
  630.           int do_replace;
  631.  
  632.           do_replace = NO_MATCH;
  633.  
  634.           /* If there is a single match, see if we need to quote it.
  635.          This also checks whether the common prefix of several
  636.          matches needs to be quoted.  If the common prefix should
  637.          not be checked, add !matches[1] to the if clause. */
  638.           should_quote = rl_strpbrk (matches[0], rl_completer_word_break_characters) != 0;
  639. #if defined (SHELL)
  640.           should_quote = should_quote || rl_strpbrk (matches[0], "#$`") != 0;
  641. #endif
  642.  
  643.           if (should_quote)
  644.         do_replace = matches[1] ? MULT_MATCH : SINGLE_MATCH;
  645.  
  646.           if (do_replace != NO_MATCH)
  647.         {
  648. #if defined (SHELL)
  649.           /* Quote the replacement, since we found an
  650.              embedded word break character in a potential
  651.              match. */
  652.           char *rtext, *mtext;
  653.           int rlen;
  654.           extern char *double_quote ();    /* in builtins/common.c */
  655.  
  656.           /* If DO_REPLACE == MULT_MATCH, it means that there is
  657.              more than one match.  In this case, we do not add
  658.              the closing quote or attempt to perform tilde
  659.              expansion.  If DO_REPLACE == SINGLE_MATCH, we try
  660.              to perform tilde expansion, because double quotes
  661.              inhibit tilde expansion by the shell. */
  662.  
  663.           mtext = matches[0];
  664.           if (mtext[0] == '~' && do_replace == SINGLE_MATCH)
  665.             mtext = tilde_expand (matches[0]);
  666.           rtext = double_quote (mtext);
  667.           if (mtext != matches[0])
  668.             free (mtext);
  669.  
  670.           rlen = strlen (rtext);
  671.           replacement = xmalloc (rlen + 1);
  672.           /* If we're completing on a quoted string where the user
  673.              has already supplied the opening quote, we don't want
  674.              the quote in the replacement text, and we reset
  675.              QUOTE_CHAR to 0 to avoid an extra closing quote. */
  676.           if (quote_char == '"')
  677.             {
  678.               strcpy (replacement, rtext + 1);
  679.               rlen--;
  680.               quote_char = 0;
  681.             }
  682.           else
  683.             strcpy (replacement, rtext);
  684.           if (do_replace == MULT_MATCH)
  685.             replacement[rlen - 1] = '\0';
  686.           free (rtext);
  687. #else /* !SHELL */
  688.           /* Found an embedded word break character in a potential
  689.              match, so we need to prepend a quote character if we
  690.              are replacing the completion string. */
  691.           replacement = xmalloc (strlen (matches[0]) + 2);
  692.           quote_char = *rl_completer_quote_characters;
  693.           *replacement = quote_char;
  694.           strcpy (replacement + 1, matches[0]);
  695. #endif /* SHELL */
  696.         }
  697.         }
  698.  
  699.       if (replacement)
  700.         {
  701.           rl_begin_undo_group ();
  702.           rl_delete_text (start, rl_point);
  703.           rl_point = start;
  704.           rl_insert_text (replacement);
  705.           rl_end_undo_group ();
  706.           if (replacement != matches[0])
  707.         free (replacement);
  708.         }
  709.  
  710.       /* If there are more matches, ring the bell to indicate.
  711.          If this was the only match, and we are hacking files,
  712.          check the file to see if it was a directory.  If so,
  713.          add a '/' to the name.  If not, and we are at the end
  714.          of the line, then add a space. */
  715.       if (matches[1])
  716.         {
  717.           if (what_to_do == '!')
  718.         goto display_matches;        /* XXX */
  719.           else if (rl_editing_mode != vi_mode)
  720.         ding ();    /* There are other matches remaining. */
  721.         }
  722.       else
  723.         {
  724.           char temp_string[4];
  725.           int temp_string_index = 0;
  726.  
  727.           if (quote_char)
  728.         temp_string[temp_string_index++] = quote_char;
  729.  
  730.           temp_string[temp_string_index++] = delimiter ? delimiter : ' ';
  731.           temp_string[temp_string_index++] = '\0';
  732.  
  733.           if (rl_filename_completion_desired)
  734.         {
  735.           struct stat finfo;
  736.           char *filename = tilde_expand (matches[0]);
  737.  
  738.           if ((stat (filename, &finfo) == 0) && S_ISDIR (finfo.st_mode))
  739.             {
  740.               if (rl_line_buffer[rl_point] != '/')
  741.             rl_insert_text ("/");
  742.             }
  743.           else
  744.             {
  745.               if (rl_point == rl_end)
  746.             rl_insert_text (temp_string);
  747.             }
  748.           free (filename);
  749.         }
  750.           else
  751.         {
  752.           if (rl_point == rl_end)
  753.             rl_insert_text (temp_string);
  754.         }
  755.         }
  756.       break;
  757.  
  758.     case '*':
  759.       {
  760.         int i = 1;
  761.  
  762.         rl_begin_undo_group ();
  763.         rl_delete_text (start, rl_point);
  764.         rl_point = start;
  765.         if (matches[1])
  766.           {
  767.         while (matches[i])
  768.           {
  769.             rl_insert_text (matches[i++]);
  770.             rl_insert_text (" ");
  771.           }
  772.           }
  773.         else
  774.           {
  775.         rl_insert_text (matches[0]);
  776.         rl_insert_text (" ");
  777.           }
  778.         rl_end_undo_group ();
  779.       }
  780.       break;
  781.  
  782.     case '?':
  783.       {
  784.         int len, count, limit, max;
  785.         int j, k, l;
  786.  
  787.         /* Handle simple case first.  What if there is only one answer? */
  788.         if (!matches[1])
  789.           {
  790.         char *temp;
  791.  
  792.         temp = printable_part (matches[0]);
  793.         crlf ();
  794.         print_filename (temp, matches[0]);
  795.         crlf ();
  796.         goto restart;
  797.           }
  798.  
  799.         /* There is more than one answer.  Find out how many there are,
  800.            and find out what the maximum printed length of a single entry
  801.            is. */
  802.       display_matches:
  803.         for (max = 0, i = 1; matches[i]; i++)
  804.           {
  805.         char *temp;
  806.         int name_length;
  807.  
  808.         temp = printable_part (matches[i]);
  809.         name_length = strlen (temp);
  810.  
  811.         if (name_length > max)
  812.           max = name_length;
  813.           }
  814.  
  815.         len = i - 1;
  816.  
  817.         /* If there are many items, then ask the user if she
  818.            really wants to see them all. */
  819.         if (len >= rl_completion_query_items)
  820.           {
  821.         crlf ();
  822.         fprintf (rl_outstream,
  823.              "There are %d possibilities.  Do you really", len);
  824.         crlf ();
  825.         fprintf (rl_outstream, "wish to see them all? (y or n)");
  826.         fflush (rl_outstream);
  827.         if (!get_y_or_n ())
  828.           {
  829.             crlf ();
  830.             goto restart;
  831.           }
  832.           }
  833.  
  834.         /* How many items of MAX length can we fit in the screen window? */
  835.         max += 2;
  836.         limit = screenwidth / max;
  837.         if (limit != 1 && (limit * max == screenwidth))
  838.           limit--;
  839.  
  840.         /* Avoid a possible floating exception.  If max > screenwidth,
  841.            limit will be 0 and a divide-by-zero fault will result. */
  842.         if (limit == 0)
  843.           limit = 1;
  844.  
  845.         /* How many iterations of the printing loop? */
  846.         count = (len + (limit - 1)) / limit;
  847.  
  848.         /* Watch out for special case.  If LEN is less than LIMIT, then
  849.            just do the inner printing loop. */
  850.         if (len < limit)
  851.           count = 1;
  852.  
  853.         /* Sort the items if they are not already sorted. */
  854.         if (!rl_ignore_completion_duplicates)
  855.           qsort (matches, len, sizeof (char *), compare_strings);
  856.  
  857.         /* Print the sorted items, up-and-down alphabetically, like
  858.            ls might. */
  859.         crlf ();
  860.  
  861.         for (i = 1; i < count + 1; i++)
  862.           {
  863.         for (j = 0, l = i; j < limit; j++)
  864.           {
  865.             if (l > len || !matches[l])
  866.               break;
  867.             else
  868.               {
  869.             char *temp;
  870.             int printed_length;
  871.  
  872.             temp = printable_part (matches[l]);
  873.             printed_length = strlen (temp);
  874.             printed_length += print_filename (temp, matches[l]);
  875.  
  876.             if (j + 1 < limit)
  877.               {
  878.                 for (k = 0; k < max - printed_length; k++)
  879.                   putc (' ', rl_outstream);
  880.               }
  881.               }
  882.             l += count;
  883.           }
  884.         crlf ();
  885.           }
  886.       restart:
  887.  
  888.         rl_on_new_line ();
  889.       }
  890.       break;
  891.  
  892.     default:
  893.       fprintf (stderr, "\r\nreadline: bad value for what_to_do in rl_complete\n");
  894.       abort ();
  895.     }
  896.  
  897.       for (i = 0; matches[i]; i++)
  898.     free (matches[i]);
  899.       free (matches);
  900.     }
  901.  
  902.   /* Check to see if the line has changed through all of this manipulation. */
  903.   if (saved_line_buffer)
  904.     {
  905.       if (strcmp (rl_line_buffer, saved_line_buffer) != 0)
  906.     completion_changed_buffer = 1;
  907.       else
  908.     completion_changed_buffer = 0;
  909.  
  910.       free (saved_line_buffer);
  911.     }
  912.   return 0;
  913. }
  914.  
  915. #if defined (VISIBLE_STATS)
  916. /* Return the character which best describes FILENAME.
  917.      `@' for symbolic links
  918.      `/' for directories
  919.      `*' for executables
  920.      `=' for sockets */
  921. static int
  922. stat_char (filename)
  923.      char *filename;
  924. {
  925.   struct stat finfo;
  926.   int character, r;
  927.  
  928. #if defined (S_ISLNK)
  929.   r = lstat (filename, &finfo);
  930. #else
  931.   r = stat (filename, &finfo);
  932. #endif
  933.  
  934.   if (r == -1)
  935.     return (0);
  936.  
  937.   character = 0;
  938.   if (S_ISDIR (finfo.st_mode))
  939.     character = '/';
  940. #if defined (S_ISLNK)
  941.   else if (S_ISLNK (finfo.st_mode))
  942.     character = '@';
  943. #endif /* S_ISLNK */
  944. #if defined (S_ISSOCK)
  945.   else if (S_ISSOCK (finfo.st_mode))
  946.     character = '=';
  947. #endif /* S_ISSOCK */
  948.   else if (S_ISREG (finfo.st_mode))
  949.     {
  950.       if (access (filename, X_OK) == 0)
  951.     character = '*';
  952.     }
  953.   return (character);
  954. }
  955. #endif /* VISIBLE_STATS */
  956.  
  957. /* Stupid comparison routine for qsort () ing strings. */
  958. static int
  959. compare_strings (s1, s2)
  960.   char **s1, **s2;
  961. {
  962.   int result;
  963.  
  964.   result = **s1 - **s2;
  965.   if (result == 0)
  966.     result = strcmp (*s1, *s2);
  967.  
  968.   return result;
  969. }
  970.  
  971. /* A completion function for usernames.
  972.    TEXT contains a partial username preceded by a random
  973.    character (usually `~').  */
  974. char *
  975. username_completion_function (text, state)
  976.      int state;
  977.      char *text;
  978. {
  979. #if defined (__GO32__)
  980.   return (char *)NULL;
  981. #else /* !__GO32__ */
  982.   static char *username = (char *)NULL;
  983.   static struct passwd *entry;
  984.   static int namelen, first_char, first_char_loc;
  985.  
  986.   if (!state)
  987.     {
  988.       if (username)
  989.     free (username);
  990.  
  991.       first_char = *text;
  992.  
  993.       if (first_char == '~')
  994.     first_char_loc = 1;
  995.       else
  996.     first_char_loc = 0;
  997.  
  998.       username = savestring (&text[first_char_loc]);
  999.       namelen = strlen (username);
  1000.       setpwent ();
  1001.     }
  1002.  
  1003.   while (entry = getpwent ())
  1004.     {
  1005.       if ((username[0] == entry->pw_name[0]) &&
  1006.       (strncmp (username, entry->pw_name, namelen) == 0))
  1007.     break;
  1008.     }
  1009.  
  1010.   if (!entry)
  1011.     {
  1012.       endpwent ();
  1013.       return ((char *)NULL);
  1014.     }
  1015.   else
  1016.     {
  1017.       char *value = xmalloc (2 + strlen (entry->pw_name));
  1018.  
  1019.       *value = *text;
  1020.  
  1021.       strcpy (value + first_char_loc, entry->pw_name);
  1022.  
  1023.       if (first_char == '~')
  1024.     rl_filename_completion_desired = 1;
  1025.  
  1026.       return (value);
  1027.     }
  1028. #endif /* !__GO32__ */
  1029. }
  1030.  
  1031. /* **************************************************************** */
  1032. /*                                    */
  1033. /*                 Completion                    */
  1034. /*                                    */
  1035. /* **************************************************************** */
  1036.  
  1037. /* Non-zero means that case is not significant in completion. */
  1038. int completion_case_fold = 0;
  1039.  
  1040. /* Return an array of (char *) which is a list of completions for TEXT.
  1041.    If there are no completions, return a NULL pointer.
  1042.    The first entry in the returned array is the substitution for TEXT.
  1043.    The remaining entries are the possible completions.
  1044.    The array is terminated with a NULL pointer.
  1045.  
  1046.    ENTRY_FUNCTION is a function of two args, and returns a (char *).
  1047.      The first argument is TEXT.
  1048.      The second is a state argument; it should be zero on the first call, and
  1049.      non-zero on subsequent calls.  It returns a NULL pointer to the caller
  1050.      when there are no more matches.
  1051.  */
  1052. char **
  1053. completion_matches (text, entry_function)
  1054.      char *text;
  1055.      CPFunction *entry_function;
  1056. {
  1057.   /* Number of slots in match_list. */
  1058.   int match_list_size;
  1059.  
  1060.   /* The list of matches. */
  1061.   char **match_list =
  1062.     (char **)xmalloc (((match_list_size = 10) + 1) * sizeof (char *));
  1063.  
  1064.   /* Number of matches actually found. */
  1065.   int matches = 0;
  1066.  
  1067.   /* Temporary string binder. */
  1068.   char *string;
  1069.  
  1070.   match_list[1] = (char *)NULL;
  1071.  
  1072.   while (string = (*entry_function) (text, matches))
  1073.     {
  1074.       if (matches + 1 == match_list_size)
  1075.     match_list = (char **)xrealloc
  1076.       (match_list, ((match_list_size += 10) + 1) * sizeof (char *));
  1077.  
  1078.       match_list[++matches] = string;
  1079.       match_list[matches + 1] = (char *)NULL;
  1080.     }
  1081.  
  1082.   /* If there were any matches, then look through them finding out the
  1083.      lowest common denominator.  That then becomes match_list[0]. */
  1084.   if (matches)
  1085.     {
  1086.       register int i = 1;
  1087.       int low = 100000;        /* Count of max-matched characters. */
  1088.  
  1089.       /* If only one match, just use that. */
  1090.       if (matches == 1)
  1091.     {
  1092.       match_list[0] = match_list[1];
  1093.       match_list[1] = (char *)NULL;
  1094.     }
  1095.       else
  1096.     {
  1097.       /* Otherwise, compare each member of the list with
  1098.          the next, finding out where they stop matching. */
  1099.  
  1100.       while (i < matches)
  1101.         {
  1102.           register int c1, c2, si;
  1103.  
  1104.           if (completion_case_fold)
  1105.         {
  1106.           for (si = 0;
  1107.                (c1 = to_lower(match_list[i][si])) &&
  1108.                (c2 = to_lower(match_list[i + 1][si]));
  1109.                si++)
  1110.             if (c1 != c2) break;
  1111.         }
  1112.           else
  1113.         {
  1114.           for (si = 0;
  1115.                (c1 = match_list[i][si]) &&
  1116.                (c2 = match_list[i + 1][si]);
  1117.                si++)
  1118.             if (c1 != c2) break;
  1119.         }
  1120.  
  1121.           if (low > si) low = si;
  1122.           i++;
  1123.         }
  1124.       match_list[0] = xmalloc (low + 1);
  1125.       strncpy (match_list[0], match_list[1], low);
  1126.       match_list[0][low] = '\0';
  1127.     }
  1128.     }
  1129.   else                /* There were no matches. */
  1130.     {
  1131.       free (match_list);
  1132.       match_list = (char **)NULL;
  1133.     }
  1134.   return (match_list);
  1135. }
  1136.  
  1137. /* Okay, now we write the entry_function for filename completion.  In the
  1138.    general case.  Note that completion in the shell is a little different
  1139.    because of all the pathnames that must be followed when looking up the
  1140.    completion for a command. */
  1141. char *
  1142. filename_completion_function (text, state)
  1143.      int state;
  1144.      char *text;
  1145. {
  1146.   static DIR *directory;
  1147.   static char *filename = (char *)NULL;
  1148.   static char *dirname = (char *)NULL;
  1149.   static char *users_dirname = (char *)NULL;
  1150.   static int filename_len;
  1151.  
  1152.   struct dirent *entry = (struct dirent *)NULL;
  1153.  
  1154.   /* If we don't have any state, then do some initialization. */
  1155.   if (!state)
  1156.     {
  1157.       char *temp;
  1158.  
  1159.       if (dirname) free (dirname);
  1160.       if (filename) free (filename);
  1161.       if (users_dirname) free (users_dirname);
  1162.  
  1163.       filename = savestring (text);
  1164.       if (!*text) text = ".";
  1165.       dirname = savestring (text);
  1166.  
  1167.       temp = strrchr (dirname, '/');
  1168.  
  1169.       if (temp)
  1170.     {
  1171.       strcpy (filename, ++temp);
  1172.       *temp = '\0';
  1173.     }
  1174.       else
  1175.     strcpy (dirname, ".");
  1176.  
  1177.       /* We aren't done yet.  We also support the "~user" syntax. */
  1178.  
  1179.       /* Save the version of the directory that the user typed. */
  1180.       users_dirname = savestring (dirname);
  1181.       {
  1182.     char *temp_dirname;
  1183.     int replace_dirname;
  1184.  
  1185.     temp_dirname = tilde_expand (dirname);
  1186.     free (dirname);
  1187.     dirname = temp_dirname;
  1188.  
  1189.     replace_dirname = 0;
  1190.     if (rl_directory_completion_hook)
  1191.       replace_dirname = (*rl_directory_completion_hook) (&dirname);
  1192.     if (replace_dirname)
  1193.       {
  1194.         free (users_dirname);
  1195.         users_dirname = savestring (dirname);
  1196.       }
  1197.       }
  1198.       directory = opendir (dirname);
  1199.       filename_len = strlen (filename);
  1200.  
  1201.       rl_filename_completion_desired = 1;
  1202.     }
  1203.  
  1204.   /* At this point we should entertain the possibility of hacking wildcarded
  1205.      filenames, like /usr/man/man<WILD>/te<TAB>.  If the directory name
  1206.      contains globbing characters, then build an array of directories, and
  1207.      then map over that list while completing. */
  1208.   /* *** UNIMPLEMENTED *** */
  1209.  
  1210.   /* Now that we have some state, we can read the directory. */
  1211.  
  1212.   while (directory && (entry = readdir (directory)))
  1213.     {
  1214.       /* Special case for no filename.
  1215.      All entries except "." and ".." match. */
  1216.       if (!filename_len)
  1217.     {
  1218.       if ((strcmp (entry->d_name, ".") != 0) &&
  1219.           (strcmp (entry->d_name, "..") != 0))
  1220.         break;
  1221.     }
  1222.       else
  1223.     {
  1224.       /* Otherwise, if these match up to the length of filename, then
  1225.          it is a match. */
  1226.         if ((entry->d_name[0] == filename[0]) &&
  1227.         (((int)D_NAMLEN (entry)) >= filename_len) &&
  1228.         (strncmp (filename, entry->d_name, filename_len) == 0))
  1229.           break;
  1230.     }
  1231.     }
  1232.  
  1233.   if (!entry)
  1234.     {
  1235.       if (directory)
  1236.     {
  1237.       closedir (directory);
  1238.       directory = (DIR *)NULL;
  1239.     }
  1240.       if (dirname)
  1241.     {
  1242.       free (dirname);
  1243.       dirname = (char *)NULL;
  1244.     }
  1245.       if (filename)
  1246.     {
  1247.       free (filename);
  1248.       filename = (char *)NULL;
  1249.     }
  1250.       if (users_dirname)
  1251.     {
  1252.       free (users_dirname);
  1253.       users_dirname = (char *)NULL;
  1254.     }
  1255.  
  1256.       return (char *)NULL;
  1257.     }
  1258.   else
  1259.     {
  1260.       char *temp;
  1261.  
  1262.       /* dirname && (strcmp (dirname, ".") != 0) */
  1263.       if (dirname && (dirname[0] != '.' || dirname[1]))
  1264.     {
  1265.       if (rl_complete_with_tilde_expansion && *users_dirname == '~')
  1266.         {
  1267.           int dirlen = strlen (dirname);
  1268.           temp = xmalloc (2 + dirlen + D_NAMLEN (entry));
  1269.           strcpy (temp, dirname);
  1270.           /* Canonicalization cuts off any final slash present.  We need
  1271.          to add it back. */
  1272.           if (dirname[dirlen - 1] != '/')
  1273.             {
  1274.               temp[dirlen] = '/';
  1275.               temp[dirlen + 1] = '\0';
  1276.             }
  1277.         }
  1278.       else
  1279.         {
  1280.           temp = xmalloc (1 + strlen (users_dirname) + D_NAMLEN (entry));
  1281.           strcpy (temp, users_dirname);
  1282.         }
  1283.  
  1284.       strcat (temp, entry->d_name);
  1285.     }
  1286.       else
  1287.     temp = (savestring (entry->d_name));
  1288.  
  1289.       return (temp);
  1290.     }
  1291. }
  1292.  
  1293. /* A function for simple tilde expansion. */
  1294. int
  1295. rl_tilde_expand (ignore, key)
  1296.      int ignore, key;
  1297. {
  1298.   register int start, end;
  1299.   char *homedir;
  1300.  
  1301.   end = rl_point;
  1302.   start = end - 1;
  1303.  
  1304.   if (rl_point == rl_end && rl_line_buffer[rl_point] == '~')
  1305.     {
  1306.       homedir = tilde_expand ("~");
  1307.       goto insert;
  1308.     }
  1309.   else if (rl_line_buffer[start] != '~')
  1310.     {
  1311.       for (; !whitespace (rl_line_buffer[start]) && start >= 0; start--);
  1312.       start++;
  1313.     }
  1314.  
  1315.   end = start;
  1316.   do
  1317.     {
  1318.       end++;
  1319.     }
  1320.   while (!whitespace (rl_line_buffer[end]) && end < rl_end);
  1321.  
  1322.   if (whitespace (rl_line_buffer[end]) || end >= rl_end)
  1323.     end--;
  1324.  
  1325.   /* If the first character of the current word is a tilde, perform
  1326.      tilde expansion and insert the result.  If not a tilde, do
  1327.      nothing. */
  1328.   if (rl_line_buffer[start] == '~')
  1329.     {
  1330.       char *temp;
  1331.       int len;
  1332.  
  1333.       len = end - start + 1;
  1334.       temp = xmalloc (len + 1);
  1335.       strncpy (temp, rl_line_buffer + start, len);
  1336.       temp[len] = '\0';
  1337.       homedir = tilde_expand (temp);
  1338.       free (temp);
  1339.  
  1340.     insert:
  1341.       rl_begin_undo_group ();
  1342.       rl_delete_text (start, end + 1);
  1343.       rl_point = start;
  1344.       rl_insert_text (homedir);
  1345.       rl_end_undo_group ();
  1346.     }
  1347.  
  1348.   return (0);
  1349. }
  1350.  
  1351. /* Find the first occurrence in STRING1 of any character from STRING2.
  1352.    Return a pointer to the character in STRING1. */
  1353. static char *
  1354. rl_strpbrk (string1, string2)
  1355.      char *string1, *string2;
  1356. {
  1357.   register char *scan;
  1358.  
  1359.   for (; *string1; string1++)
  1360.     {
  1361.       for (scan = string2; *scan; scan++)
  1362.     {
  1363.       if (*string1 == *scan)
  1364.         {
  1365.           return (string1);
  1366.         }
  1367.     }
  1368.     }
  1369.   return ((char *)NULL);
  1370. }
  1371.  
  1372. #if defined (STATIC_MALLOC)
  1373.  
  1374. /* **************************************************************** */
  1375. /*                                    */
  1376. /*            xmalloc and xrealloc ()                     */
  1377. /*                                    */
  1378. /* **************************************************************** */
  1379.  
  1380. static void memory_error_and_abort ();
  1381.  
  1382. static char *
  1383. xmalloc (bytes)
  1384.      int bytes;
  1385. {
  1386.   char *temp = (char *)malloc (bytes);
  1387.  
  1388.   if (!temp)
  1389.     memory_error_and_abort ();
  1390.   return (temp);
  1391. }
  1392.  
  1393. static char *
  1394. xrealloc (pointer, bytes)
  1395.      char *pointer;
  1396.      int bytes;
  1397. {
  1398.   char *temp;
  1399.  
  1400.   if (!pointer)
  1401.     temp = (char *)malloc (bytes);
  1402.   else
  1403.     temp = (char *)realloc (pointer, bytes);
  1404.  
  1405.   if (!temp)
  1406.     memory_error_and_abort ();
  1407.  
  1408.   return (temp);
  1409. }
  1410.  
  1411. static void
  1412. memory_error_and_abort ()
  1413. {
  1414.   fprintf (stderr, "readline: Out of virtual memory!\n");
  1415.   abort ();
  1416. }
  1417. #endif /* STATIC_MALLOC */
  1418.