1 /* complete.c -- filename completion for readline. */
3 /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
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.
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.
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. */
25 #include <sys/types.h>
27 #if !defined (NO_SYS_FILE)
28 # include <sys/file.h>
29 #endif /* !NO_SYS_FILE */
32 /* Not all systems declare ERRNO in errno.h... and some systems #define it! */
37 /* These next are for filename completion. Perhaps this belongs
38 in a different place. */
41 #endif /* __MSDOS__ */
42 #if defined (USG) && !defined (isc386) && !defined (sgi)
43 extern struct passwd *getpwuid (), *getpwent ();
45 #if defined (isc386) && !defined (__STDC__) && defined (_POSIX_SOURCE)
46 extern struct passwd *getpwent ();
49 /* System-specific feature definitions and include files. */
52 /* Some standard library routines. */
56 extern char *strchr ();
58 #if !defined (strrchr)
59 extern char *strrchr ();
62 extern char *tilde_expand ();
63 extern char *rl_copy_text ();
65 extern Function *rl_last_func;
66 extern int rl_editing_mode;
67 extern int screenwidth;
69 static int compare_strings ();
70 static char *rl_strpbrk ();
72 #if defined (STATIC_MALLOC)
73 static char *xmalloc (), *xrealloc ();
75 extern char *xmalloc (), *xrealloc ();
76 #endif /* STATIC_MALLOC */
78 /* If non-zero, then this is the address of a function to call when
79 completing on a directory name. The function is called with
80 the address of a string (the current directory name) as an arg. */
81 Function *rl_symbolic_link_hook = (Function *)NULL;
83 /* Non-zero means readline completion functions perform tilde expansion. */
84 int rl_complete_with_tilde_expansion = 0;
88 #if defined (VISIBLE_STATS)
89 static int stat_char ();
91 /* Non-zero means add an additional character to each filename displayed
92 during listing completion iff rl_filename_completion_desired which helps
93 to indicate the type of file being listed. */
94 int rl_visible_stats = 0;
95 #endif /* VISIBLE_STATS */
97 /* **************************************************************** */
99 /* Completion matching, from readline's point of view. */
101 /* **************************************************************** */
103 /* Pointer to the generator function for completion_matches ().
104 NULL means to use filename_entry_function (), the default filename
106 Function *rl_completion_entry_function = (Function *)NULL;
108 /* Pointer to alternative function to create matches.
109 Function is called with TEXT, START, and END.
110 START and END are indices in RL_LINE_BUFFER saying what the boundaries
112 If this function exists and returns NULL then call the value of
113 rl_completion_entry_function to try to match, otherwise use the
114 array of strings returned. */
115 Function *rl_attempted_completion_function = (Function *)NULL;
117 /* Local variable states what happened during the last completion attempt. */
118 static int completion_changed_buffer = 0;
120 /* Complete the word at or before point. You have supplied the function
121 that does the initial simple matching selection algorithm (see
122 completion_matches ()). The default is to do filename completion. */
124 rl_complete (ignore, invoking_key)
125 int ignore, invoking_key;
127 if (rl_last_func == rl_complete && !completion_changed_buffer)
128 rl_complete_internal ('?');
130 rl_complete_internal (TAB);
133 /* List the possible completions. See description of rl_complete (). */
134 rl_possible_completions (ignore, invoking_key)
136 rl_complete_internal ('?');
139 rl_insert_completions (ignore, invoking_key)
140 int ignore, invoking_key;
142 rl_complete_internal ('*');
145 /* The user must press "y" or "n". Non-zero return means "y" pressed. */
153 if (c == 'y' || c == 'Y')
155 if (c == 'n' || c == 'N')
163 /* Up to this many items will be displayed in response to a
164 possible-completions call. After that, we ask the user if
165 she is sure she wants to see them all. */
166 int rl_completion_query_items = 100;
168 /* The basic list of characters that signal a break between words for the
169 completer routine. The contents of this variable is what breaks words
170 in the shell, i.e. " \t\n\"\\'`@$><=" */
171 char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(";
173 /* The list of characters that signal a break between words for
174 rl_complete_internal. The default list is the contents of
175 rl_basic_word_break_characters. */
176 char *rl_completer_word_break_characters = (char *)NULL;
178 /* List of characters which can be used to quote a substring of the line.
179 Completion occurs on the entire substring, and within the substring
180 rl_completer_word_break_characters are treated as any other character,
181 unless they also appear within this list. */
182 char *rl_completer_quote_characters = (char *)NULL;
184 /* List of characters that are word break characters, but should be left
185 in TEXT when it is passed to the completion function. The shell uses
186 this to help determine what kind of completing to do. */
187 char *rl_special_prefixes = (char *)NULL;
189 /* If non-zero, then disallow duplicates in the matches. */
190 int rl_ignore_completion_duplicates = 1;
192 /* Non-zero means that the results of the matches are to be treated
193 as filenames. This is ALWAYS zero on entry, and can only be changed
194 within a completion entry finder function. */
195 int rl_filename_completion_desired = 0;
197 /* This function, if defined, is called by the completer when real
198 filename completion is done, after all the matching names have been
199 generated. It is passed a (char**) known as matches in the code below.
200 It consists of a NULL-terminated array of pointers to potential
201 matching strings. The 1st element (matches[0]) is the maximal
202 substring that is common to all matches. This function can re-arrange
203 the list of matches as required, but all elements of the array must be
204 free()'d if they are deleted. The main intent of this function is
205 to implement FIGNORE a la SunOS csh. */
206 Function *rl_ignore_some_completions_function = (Function *)NULL;
208 /* Complete the word at or before point.
209 WHAT_TO_DO says what to do with the completion.
210 `?' means list the possible completions.
211 TAB means do standard completion.
212 `*' means insert all of the possible completions. */
213 rl_complete_internal (what_to_do)
216 char *filename_completion_function ();
217 char **completion_matches (), **matches;
219 int start, scan, end, delimiter = 0;
220 char *text, *saved_line_buffer;
221 char quote_char = '\0';
225 saved_line_buffer = savestring (rl_line_buffer);
227 saved_line_buffer = (char *)NULL;
229 if (rl_completion_entry_function)
230 our_func = rl_completion_entry_function;
232 our_func = (int (*)())filename_completion_function;
234 /* Only the completion entry function can change this. */
235 rl_filename_completion_desired = 0;
237 /* We now look backwards for the start of a filename/variable word. */
242 if (rl_completer_quote_characters)
244 /* We have a list of characters which can be used in pairs to
245 quote substrings for the completer. Try to find the start
246 of an unclosed quoted substring.
247 [FIXME: Doesn't yet handle '\' escapes to quote quotes. */
248 for (scan = 0; scan < end; scan++)
250 if (quote_char != '\0')
252 /* Ignore everything until the matching close quote char. */
253 if (rl_line_buffer[scan] == quote_char)
255 /* Found matching close quote. Abandon this substring. */
260 else if (strchr (rl_completer_quote_characters, rl_line_buffer[scan]))
262 /* Found start of a quoted substring. */
263 quote_char = rl_line_buffer[scan];
270 /* We didn't find an unclosed quoted substring upon which to do
271 completion, so use the word break characters to find the
272 substring on which to do completion. */
274 !strchr (rl_completer_word_break_characters,
275 rl_line_buffer[rl_point])) {;}
278 /* If we are at a word break, then advance past it. */
279 if (strchr (rl_completer_word_break_characters, rl_line_buffer[rl_point]))
281 /* If the character that caused the word break was a quoting
282 character, then remember it as the delimiter. */
283 if (strchr ("\"'", rl_line_buffer[rl_point]) && (end - rl_point) > 1)
284 delimiter = rl_line_buffer[rl_point];
286 /* If the character isn't needed to determine something special
287 about what kind of completion to perform, then advance past it. */
289 if (!rl_special_prefixes ||
290 !strchr (rl_special_prefixes, rl_line_buffer[rl_point]))
297 text = rl_copy_text (start, end);
299 /* If the user wants to TRY to complete, but then wants to give
300 up and use the default completion function, they set the
301 variable rl_attempted_completion_function. */
302 if (rl_attempted_completion_function)
305 (char **)(*rl_attempted_completion_function) (text, start, end);
309 if (matches == (char **)-1)
310 matches = (char **)NULL;
311 our_func = (Function *)NULL;
312 goto after_usual_completion;
316 matches = completion_matches (text, our_func);
318 after_usual_completion:
329 /* It seems to me that in all the cases we handle we would like
330 to ignore duplicate possibilities. Scan for the text to
331 insert being identical to the other completions. */
332 if (rl_ignore_completion_duplicates)
337 /* Sort the items. */
338 /* It is safe to sort this array, because the lowest common
339 denominator found in matches[0] will remain in place. */
340 for (i = 0; matches[i]; i++);
341 qsort (matches, i, sizeof (char *), compare_strings);
343 /* Remember the lowest common denominator for it may be unique. */
344 lowest_common = savestring (matches[0]);
346 for (i = 0; matches[i + 1]; i++)
348 if (strcmp (matches[i], matches[i + 1]) == 0)
351 matches[i] = (char *)-1;
357 /* We have marked all the dead slots with (char *)-1.
358 Copy all the non-dead entries into a new array. */
361 (char **)xmalloc ((3 + newlen) * sizeof (char *));
363 for (i = 1, j = 1; matches[i]; i++)
365 if (matches[i] != (char *)-1)
366 temp_array[j++] = matches[i];
369 temp_array[j] = (char *)NULL;
371 if (matches[0] != (char *)-1)
376 matches = temp_array;
379 /* Place the lowest common denominator back in [0]. */
380 matches[0] = lowest_common;
382 /* If there is one string left, and it is identical to the
383 lowest common denominator, then the LCD is the string to
385 if (j == 2 && strcmp (matches[0], matches[1]) == 0)
388 matches[1] = (char *)NULL;
395 /* If we are matching filenames, then here is our chance to
396 do clever processing by re-examining the list. Call the
397 ignore function with the array as a parameter. It can
398 munge the array, deleting matches as it desires. */
399 if (rl_ignore_some_completions_function &&
400 our_func == (int (*)())filename_completion_function)
401 (void)(*rl_ignore_some_completions_function)(matches);
403 /* If we are doing completion on quoted substrings, and any matches
404 contain any of the completer_word_break_characters, then auto-
405 matically prepend the substring with a quote character (just pick
406 the first one from the list of such) if it does not already begin
407 with a quote string. FIXME: Need to remove any such automatically
408 inserted quote character when it no longer is necessary, such as
409 if we change the string we are completing on and the new set of
410 matches don't require a quoted substring. */
411 replacement = matches[0];
413 if (matches[0] && rl_completer_quote_characters && !quote_char &&
414 rl_filename_completion_desired)
420 /* If there is only a single match, see if we need to
423 rl_strpbrk (matches[0], rl_completer_word_break_characters))
426 /* If there are multiple matches, check to see if any of them
427 require that the substring be quoted. */
428 for (i = 1; matches[i] != NULL; i++)
429 if (rl_strpbrk (matches[i], rl_completer_word_break_characters))
437 /* XXX - experimental */
438 /* Single-quote the replacement, since we found an
439 embedded word break character in a potential match. */
441 extern char *single_quote (); /* in builtins/common.c */
443 rtext = single_quote (matches[0]);
444 replacement = (char *)alloca (strlen (rtext) + 1);
445 strcpy (replacement, rtext);
448 /* Found an embedded word break character in a potential
449 match, so we need to prepend a quote character if we
450 are replacing the completion string. */
451 replacement = (char *)alloca (strlen (matches[0]) + 2);
452 quote_char = *rl_completer_quote_characters;
453 *replacement = quote_char;
454 strcpy (replacement + 1, matches[0]);
460 rl_delete_text (start, rl_point);
462 rl_insert_text (replacement);
465 /* If there are more matches, ring the bell to indicate.
466 If this was the only match, and we are hacking files,
467 check the file to see if it was a directory. If so,
468 add a '/' to the name. If not, and we are at the end
469 of the line, then add a space. */
472 if (rl_editing_mode != vi_mode)
473 ding (); /* There are other matches remaining. */
478 int temp_string_index = 0;
481 temp_string[temp_string_index++] = quote_char;
483 temp_string[temp_string_index++] = delimiter ? delimiter : ' ';
484 temp_string[temp_string_index++] = '\0';
486 if (rl_filename_completion_desired)
489 char *filename = tilde_expand (matches[0]);
491 if ((stat (filename, &finfo) == 0) &&
492 S_ISDIR (finfo.st_mode))
494 if (rl_line_buffer[rl_point] != '/')
495 rl_insert_text ("/");
499 if (rl_point == rl_end)
500 rl_insert_text (temp_string);
506 if (rl_point == rl_end)
507 rl_insert_text (temp_string);
516 rl_delete_text (start, rl_point);
518 rl_begin_undo_group ();
523 rl_insert_text (matches[i++]);
524 rl_insert_text (" ");
529 rl_insert_text (matches[0]);
530 rl_insert_text (" ");
532 rl_end_undo_group ();
538 int len, count, limit, max = 0;
541 /* Handle simple case first. What if there is only one answer? */
546 if (rl_filename_completion_desired)
547 temp = strrchr (matches[0], '/');
557 fprintf (rl_outstream, "%s", temp);
558 #if defined (VISIBLE_STATS)
559 if (rl_filename_completion_desired && rl_visible_stats)
563 extension_char = stat_char (matches[0]);
565 putc (extension_char, rl_outstream);
567 #endif /* VISIBLE_STATS */
572 /* There is more than one answer. Find out how many there are,
573 and find out what the maximum printed length of a single entry
575 for (i = 1; matches[i]; i++)
580 /* If we are hacking filenames, then only count the characters
581 after the last slash in the pathname. */
582 if (rl_filename_completion_desired)
583 temp = strrchr (matches[i], '/');
592 name_length = strlen (temp);
594 if (name_length > max)
600 /* If there are many items, then ask the user if she
601 really wants to see them all. */
602 if (len >= rl_completion_query_items)
605 fprintf (rl_outstream,
606 "There are %d possibilities. Do you really", len);
608 fprintf (rl_outstream, "wish to see them all? (y or n)");
609 fflush (rl_outstream);
616 /* How many items of MAX length can we fit in the screen window? */
618 limit = screenwidth / max;
619 if (limit != 1 && (limit * max == screenwidth))
622 /* Avoid a possible floating exception. If max > screenwidth,
623 limit will be 0 and a divide-by-zero fault will result. */
627 /* How many iterations of the printing loop? */
628 count = (len + (limit - 1)) / limit;
630 /* Watch out for special case. If LEN is less than LIMIT, then
631 just do the inner printing loop. */
635 /* Sort the items if they are not already sorted. */
636 if (!rl_ignore_completion_duplicates)
637 qsort (matches, len, sizeof (char *), compare_strings);
639 /* Print the sorted items, up-and-down alphabetically, like
643 for (i = 1; i < count + 1; i++)
645 for (j = 0, l = i; j < limit; j++)
647 if (l > len || !matches[l])
653 char *temp = (char *)NULL;
656 if (rl_filename_completion_desired)
657 temp = strrchr (matches[l], '/');
664 printed_length = strlen (temp);
665 fprintf (rl_outstream, "%s", temp);
667 #if defined (VISIBLE_STATS)
668 if (rl_filename_completion_desired &&
673 extension_char = stat_char (matches[l]);
677 putc (extension_char, rl_outstream);
681 #endif /* VISIBLE_STATS */
685 for (k = 0; k < max - printed_length; k++)
686 putc (' ', rl_outstream);
703 for (i = 0; matches[i]; i++)
708 /* Check to see if the line has changed through all of this manipulation. */
709 if (saved_line_buffer)
711 if (strcmp (rl_line_buffer, saved_line_buffer) != 0)
712 completion_changed_buffer = 1;
714 completion_changed_buffer = 0;
716 free (saved_line_buffer);
720 #if defined (VISIBLE_STATS)
721 /* Return the character which best describes FILENAME.
722 `@' for symbolic links
733 if (stat (filename, &finfo) == -1)
736 if (S_ISDIR (finfo.st_mode))
738 #if defined (S_ISLNK)
739 else if (S_ISLNK (finfo.st_mode))
742 #if defined (S_ISSOCK)
743 else if (S_ISSOCK (finfo.st_mode))
745 #endif /* S_ISSOCK */
746 else if (S_ISREG (finfo.st_mode))
748 if (access (filename, X_OK) == 0)
753 #endif /* VISIBLE_STATS */
755 /* Stupid comparison routine for qsort () ing strings. */
757 compare_strings (s1, s2)
760 return (strcmp (*s1, *s2));
763 /* A completion function for usernames.
764 TEXT contains a partial username preceded by a random
765 character (usually `~'). */
767 username_completion_function (text, state)
773 #else /* !__GO32__ */
774 static char *username = (char *)NULL;
775 static struct passwd *entry;
776 static int namelen, first_char, first_char_loc;
785 if (first_char == '~')
790 username = savestring (&text[first_char_loc]);
791 namelen = strlen (username);
795 while (entry = getpwent ())
797 if (strncmp (username, entry->pw_name, namelen) == 0)
804 return ((char *)NULL);
808 char *value = (char *)xmalloc (2 + strlen (entry->pw_name));
812 strcpy (value + first_char_loc, entry->pw_name);
814 if (first_char == '~')
815 rl_filename_completion_desired = 1;
819 #endif /* !__GO32__ */
823 /* **************************************************************** */
827 /* **************************************************************** */
829 /* Non-zero means that case is not significant in completion. */
830 int completion_case_fold = 0;
832 /* Return an array of (char *) which is a list of completions for TEXT.
833 If there are no completions, return a NULL pointer.
834 The first entry in the returned array is the substitution for TEXT.
835 The remaining entries are the possible completions.
836 The array is terminated with a NULL pointer.
838 ENTRY_FUNCTION is a function of two args, and returns a (char *).
839 The first argument is TEXT.
840 The second is a state argument; it should be zero on the first call, and
841 non-zero on subsequent calls. It returns a NULL pointer to the caller
842 when there are no more matches.
845 completion_matches (text, entry_function)
847 char *(*entry_function) ();
849 /* Number of slots in match_list. */
852 /* The list of matches. */
854 (char **)xmalloc (((match_list_size = 10) + 1) * sizeof (char *));
856 /* Number of matches actually found. */
859 /* Temporary string binder. */
862 match_list[1] = (char *)NULL;
864 while (string = (*entry_function) (text, matches))
866 if (matches + 1 == match_list_size)
867 match_list = (char **)xrealloc
868 (match_list, ((match_list_size += 10) + 1) * sizeof (char *));
870 match_list[++matches] = string;
871 match_list[matches + 1] = (char *)NULL;
874 /* If there were any matches, then look through them finding out the
875 lowest common denominator. That then becomes match_list[0]. */
879 int low = 100000; /* Count of max-matched characters. */
881 /* If only one match, just use that. */
884 match_list[0] = match_list[1];
885 match_list[1] = (char *)NULL;
889 /* Otherwise, compare each member of the list with
890 the next, finding out where they stop matching. */
894 register int c1, c2, si;
896 if (completion_case_fold)
899 (c1 = to_lower(match_list[i][si])) &&
900 (c2 = to_lower(match_list[i + 1][si]));
907 (c1 = match_list[i][si]) &&
908 (c2 = match_list[i + 1][si]);
913 if (low > si) low = si;
916 match_list[0] = (char *)xmalloc (low + 1);
917 strncpy (match_list[0], match_list[1], low);
918 match_list[0][low] = '\0';
921 else /* There were no matches. */
924 match_list = (char **)NULL;
929 /* Okay, now we write the entry_function for filename completion. In the
930 general case. Note that completion in the shell is a little different
931 because of all the pathnames that must be followed when looking up the
932 completion for a command. */
934 filename_completion_function (text, state)
938 static DIR *directory;
939 static char *filename = (char *)NULL;
940 static char *dirname = (char *)NULL;
941 static char *users_dirname = (char *)NULL;
942 static int filename_len;
944 dirent *entry = (dirent *)NULL;
946 /* If we don't have any state, then do some initialization. */
951 if (dirname) free (dirname);
952 if (filename) free (filename);
953 if (users_dirname) free (users_dirname);
955 filename = savestring (text);
956 if (!*text) text = ".";
957 dirname = savestring (text);
959 temp = strrchr (dirname, '/');
963 strcpy (filename, ++temp);
967 strcpy (dirname, ".");
969 /* We aren't done yet. We also support the "~user" syntax. */
971 /* Save the version of the directory that the user typed. */
972 users_dirname = savestring (dirname);
976 temp_dirname = tilde_expand (dirname);
978 dirname = temp_dirname;
980 if (rl_symbolic_link_hook)
981 (*rl_symbolic_link_hook) (&dirname);
983 directory = opendir (dirname);
984 filename_len = strlen (filename);
986 rl_filename_completion_desired = 1;
989 /* At this point we should entertain the possibility of hacking wildcarded
990 filenames, like /usr/man/man<WILD>/te<TAB>. If the directory name
991 contains globbing characters, then build an array of directories, and
992 then map over that list while completing. */
993 /* *** UNIMPLEMENTED *** */
995 /* Now that we have some state, we can read the directory. */
997 while (directory && (entry = readdir (directory)))
999 /* Special case for no filename.
1000 All entries except "." and ".." match. */
1003 if ((strcmp (entry->d_name, ".") != 0) &&
1004 (strcmp (entry->d_name, "..") != 0))
1009 /* Otherwise, if these match upto the length of filename, then
1011 if (((int)D_NAMLEN (entry)) >= filename_len &&
1012 (entry->d_name[0] == filename[0]) &&
1013 (strncmp (filename, entry->d_name, filename_len) == 0))
1024 closedir (directory);
1025 directory = (DIR *)NULL;
1031 dirname = (char *)NULL;
1036 filename = (char *)NULL;
1040 free (users_dirname);
1041 users_dirname = (char *)NULL;
1044 return (char *)NULL;
1050 if (dirname && (strcmp (dirname, ".") != 0))
1052 if (rl_complete_with_tilde_expansion && *users_dirname == '~')
1054 int dirlen = strlen (dirname);
1055 temp = (char *)xmalloc (2 + dirlen + D_NAMLEN (entry));
1056 strcpy (temp, dirname);
1057 /* Canonicalization cuts off any final slash present. We need
1059 if (dirname[dirlen - 1] != '/')
1062 temp[dirlen + 1] = '\0';
1068 xmalloc (1 + strlen (users_dirname) + D_NAMLEN (entry));
1069 strcpy (temp, users_dirname);
1072 strcat (temp, entry->d_name);
1076 temp = (savestring (entry->d_name));
1082 /* A function for simple tilde expansion. */
1084 rl_tilde_expand (ignore, key)
1087 register int start, end;
1093 if (rl_point == rl_end && rl_line_buffer[rl_point] == '~')
1095 homedir = tilde_expand ("~");
1098 else if (rl_line_buffer[start] != '~')
1100 for (; !whitespace (rl_line_buffer[start]) && start >= 0; start--);
1109 while (!whitespace (rl_line_buffer[end]) && end < rl_end);
1111 if (whitespace (rl_line_buffer[end]) || end >= rl_end)
1114 /* If the first character of the current word is a tilde, perform
1115 tilde expansion and insert the result. If not a tilde, do
1117 if (rl_line_buffer[start] == '~')
1122 len = end - start + 1;
1123 temp = (char *)alloca (len + 1);
1124 strncpy (temp, rl_line_buffer + start, len);
1126 homedir = tilde_expand (temp);
1129 rl_begin_undo_group ();
1130 rl_delete_text (start, end + 1);
1132 rl_insert_text (homedir);
1133 rl_end_undo_group ();
1139 /* Find the first occurrence in STRING1 of any character from STRING2.
1140 Return a pointer to the character in STRING1. */
1142 rl_strpbrk (string1, string2)
1143 char *string1, *string2;
1145 register char *scan;
1147 for (; *string1; string1++)
1149 for (scan = string2; *scan; scan++)
1151 if (*string1 == *scan)
1157 return ((char *)NULL);
1160 #if defined (STATIC_MALLOC)
1162 /* **************************************************************** */
1164 /* xmalloc and xrealloc () */
1166 /* **************************************************************** */
1168 static void memory_error_and_abort ();
1174 char *temp = (char *)malloc (bytes);
1177 memory_error_and_abort ();
1182 xrealloc (pointer, bytes)
1189 temp = (char *)malloc (bytes);
1191 temp = (char *)realloc (pointer, bytes);
1194 memory_error_and_abort ();
1200 memory_error_and_abort ()
1202 fprintf (stderr, "readline: Out of virtual memory!\n");
1205 #endif /* STATIC_MALLOC */