]> git.ipfire.org Git - thirdparty/bash.git/blame - lib/readline/bind.c
Imported from ../bash-2.05b.tar.gz.
[thirdparty/bash.git] / lib / readline / bind.c
CommitLineData
726f6388
JA
1/* bind.c -- key binding and startup file support for the readline library. */
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
bb70624e 10 as published by the Free Software Foundation; either version 2, or
726f6388
JA
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,
bb70624e 21 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
726f6388
JA
22#define READLINE_LIBRARY
23
ccc6cda3
JA
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
726f6388
JA
28#include <stdio.h>
29#include <sys/types.h>
30#include <fcntl.h>
ccc6cda3 31#if defined (HAVE_SYS_FILE_H)
726f6388 32# include <sys/file.h>
ccc6cda3 33#endif /* HAVE_SYS_FILE_H */
726f6388
JA
34
35#if defined (HAVE_UNISTD_H)
36# include <unistd.h>
37#endif /* HAVE_UNISTD_H */
38
39#if defined (HAVE_STDLIB_H)
40# include <stdlib.h>
41#else
42# include "ansi_stdlib.h"
43#endif /* HAVE_STDLIB_H */
44
45#include <errno.h>
ccc6cda3 46
726f6388
JA
47#if !defined (errno)
48extern int errno;
49#endif /* !errno */
50
51#include "posixstat.h"
52
53/* System-specific feature definitions and include files. */
54#include "rldefs.h"
55
56/* Some standard library routines. */
57#include "readline.h"
58#include "history.h"
59
bb70624e
JA
60#include "rlprivate.h"
61#include "rlshell.h"
62#include "xmalloc.h"
63
726f6388
JA
64#if !defined (strchr) && !defined (__STDC__)
65extern char *strchr (), *strrchr ();
66#endif /* !strchr && !__STDC__ */
67
ccc6cda3
JA
68/* Variables exported by this file. */
69Keymap rl_binding_keymap;
726f6388 70
7117c2d2
JA
71static char *_rl_read_file PARAMS((char *, size_t *));
72static void _rl_init_file_error PARAMS((const char *));
f73dda09
JA
73static int _rl_read_init_file PARAMS((const char *, int));
74static int glean_key_from_name PARAMS((char *));
75static int substring_member_of_array PARAMS((char *, const char **));
726f6388 76
bb70624e 77static int currently_reading_init_file;
726f6388 78
bb70624e
JA
79/* used only in this file */
80static int _rl_prefer_visible_bell = 1;
726f6388
JA
81
82/* **************************************************************** */
83/* */
84/* Binding keys */
85/* */
86/* **************************************************************** */
87
28ef6c31 88/* rl_add_defun (char *name, rl_command_func_t *function, int key)
726f6388
JA
89 Add NAME to the list of named functions. Make FUNCTION be the function
90 that gets called. If KEY is not -1, then bind it. */
ccc6cda3 91int
726f6388 92rl_add_defun (name, function, key)
28ef6c31
JA
93 const char *name;
94 rl_command_func_t *function;
726f6388
JA
95 int key;
96{
97 if (key != -1)
98 rl_bind_key (key, function);
99 rl_add_funmap_entry (name, function);
100 return 0;
101}
102
103/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */
104int
105rl_bind_key (key, function)
106 int key;
28ef6c31 107 rl_command_func_t *function;
726f6388
JA
108{
109 if (key < 0)
110 return (key);
111
112 if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii)
113 {
114 if (_rl_keymap[ESC].type == ISKMAP)
115 {
116 Keymap escmap;
117
118 escmap = FUNCTION_TO_KEYMAP (_rl_keymap, ESC);
119 key = UNMETA (key);
120 escmap[key].type = ISFUNC;
121 escmap[key].function = function;
122 return (0);
123 }
124 return (key);
125 }
126
127 _rl_keymap[key].type = ISFUNC;
128 _rl_keymap[key].function = function;
ccc6cda3 129 rl_binding_keymap = _rl_keymap;
726f6388
JA
130 return (0);
131}
132
133/* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid
134 KEY. */
135int
136rl_bind_key_in_map (key, function, map)
137 int key;
28ef6c31 138 rl_command_func_t *function;
726f6388
JA
139 Keymap map;
140{
141 int result;
ccc6cda3 142 Keymap oldmap;
726f6388 143
ccc6cda3 144 oldmap = _rl_keymap;
726f6388
JA
145 _rl_keymap = map;
146 result = rl_bind_key (key, function);
147 _rl_keymap = oldmap;
148 return (result);
149}
150
151/* Make KEY do nothing in the currently selected keymap.
152 Returns non-zero in case of error. */
153int
154rl_unbind_key (key)
155 int key;
156{
28ef6c31 157 return (rl_bind_key (key, (rl_command_func_t *)NULL));
726f6388
JA
158}
159
160/* Make KEY do nothing in MAP.
161 Returns non-zero in case of error. */
162int
163rl_unbind_key_in_map (key, map)
164 int key;
165 Keymap map;
166{
28ef6c31 167 return (rl_bind_key_in_map (key, (rl_command_func_t *)NULL, map));
726f6388
JA
168}
169
cce855bc
JA
170/* Unbind all keys bound to FUNCTION in MAP. */
171int
172rl_unbind_function_in_map (func, map)
28ef6c31 173 rl_command_func_t *func;
cce855bc
JA
174 Keymap map;
175{
b72432fd 176 register int i, rval;
cce855bc 177
b72432fd 178 for (i = rval = 0; i < KEYMAP_SIZE; i++)
cce855bc
JA
179 {
180 if (map[i].type == ISFUNC && map[i].function == func)
b72432fd 181 {
28ef6c31 182 map[i].function = (rl_command_func_t *)NULL;
b72432fd
JA
183 rval = 1;
184 }
cce855bc 185 }
b72432fd 186 return rval;
cce855bc
JA
187}
188
189int
190rl_unbind_command_in_map (command, map)
28ef6c31 191 const char *command;
cce855bc
JA
192 Keymap map;
193{
28ef6c31 194 rl_command_func_t *func;
cce855bc
JA
195
196 func = rl_named_function (command);
197 if (func == 0)
198 return 0;
199 return (rl_unbind_function_in_map (func, map));
200}
201
726f6388
JA
202/* Bind the key sequence represented by the string KEYSEQ to
203 FUNCTION. This makes new keymaps as necessary. The initial
204 place to do bindings is in MAP. */
ccc6cda3 205int
726f6388 206rl_set_key (keyseq, function, map)
28ef6c31
JA
207 const char *keyseq;
208 rl_command_func_t *function;
726f6388
JA
209 Keymap map;
210{
d166f048 211 return (rl_generic_bind (ISFUNC, keyseq, (char *)function, map));
726f6388
JA
212}
213
214/* Bind the key sequence represented by the string KEYSEQ to
215 the string of characters MACRO. This makes new keymaps as
216 necessary. The initial place to do bindings is in MAP. */
ccc6cda3 217int
726f6388 218rl_macro_bind (keyseq, macro, map)
28ef6c31 219 const char *keyseq, *macro;
726f6388
JA
220 Keymap map;
221{
222 char *macro_keys;
223 int macro_keys_len;
224
225 macro_keys = (char *)xmalloc ((2 * strlen (macro)) + 1);
226
227 if (rl_translate_keyseq (macro, macro_keys, &macro_keys_len))
228 {
229 free (macro_keys);
230 return -1;
231 }
232 rl_generic_bind (ISMACR, keyseq, macro_keys, map);
233 return 0;
234}
235
236/* Bind the key sequence represented by the string KEYSEQ to
237 the arbitrary pointer DATA. TYPE says what kind of data is
238 pointed to by DATA, right now this can be a function (ISFUNC),
239 a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps
240 as necessary. The initial place to do bindings is in MAP. */
ccc6cda3 241int
726f6388
JA
242rl_generic_bind (type, keyseq, data, map)
243 int type;
28ef6c31
JA
244 const char *keyseq;
245 char *data;
726f6388
JA
246 Keymap map;
247{
248 char *keys;
249 int keys_len;
250 register int i;
7117c2d2
JA
251 KEYMAP_ENTRY k;
252
253 k.function = 0;
726f6388
JA
254
255 /* If no keys to bind to, exit right away. */
256 if (!keyseq || !*keyseq)
257 {
258 if (type == ISMACR)
259 free (data);
260 return -1;
261 }
262
f73dda09 263 keys = (char *)xmalloc (1 + (2 * strlen (keyseq)));
726f6388
JA
264
265 /* Translate the ASCII representation of KEYSEQ into an array of
266 characters. Stuff the characters into KEYS, and the length of
267 KEYS into KEYS_LEN. */
268 if (rl_translate_keyseq (keyseq, keys, &keys_len))
269 {
270 free (keys);
271 return -1;
272 }
273
274 /* Bind keys, making new keymaps as necessary. */
275 for (i = 0; i < keys_len; i++)
276 {
7117c2d2
JA
277 unsigned char uc = keys[i];
278 int ic;
279
280 ic = uc;
281 if (ic < 0 || ic >= KEYMAP_SIZE)
282 return -1;
726f6388
JA
283
284 if (_rl_convert_meta_chars_to_ascii && META_CHAR (ic))
285 {
286 ic = UNMETA (ic);
287 if (map[ESC].type == ISKMAP)
288 map = FUNCTION_TO_KEYMAP (map, ESC);
289 }
290
291 if ((i + 1) < keys_len)
292 {
293 if (map[ic].type != ISKMAP)
294 {
7117c2d2
JA
295 /* We allow subsequences of keys. If a keymap is being
296 created that will `shadow' an existing function or macro
297 key binding, we save that keybinding into the ANYOTHERKEY
298 index in the new map. The dispatch code will look there
299 to find the function to execute if the subsequence is not
300 matched. ANYOTHERKEY was chosen to be greater than
301 UCHAR_MAX. */
302 k = map[ic];
726f6388
JA
303
304 map[ic].type = ISKMAP;
305 map[ic].function = KEYMAP_TO_FUNCTION (rl_make_bare_keymap());
306 }
307 map = FUNCTION_TO_KEYMAP (map, ic);
7117c2d2
JA
308 /* The dispatch code will return this function if no matching
309 key sequence is found in the keymap. This (with a little
310 help from the dispatch code in readline.c) allows `a' to be
311 mapped to something, `abc' to be mapped to something else,
312 and the function bound to `a' to be executed when the user
313 types `abx', leaving `bx' in the input queue. */
314 if (k.function /* && k.type == ISFUNC */)
315 {
316 map[ANYOTHERKEY] = k;
317 k.function = 0;
318 }
726f6388
JA
319 }
320 else
321 {
322 if (map[ic].type == ISMACR)
323 free ((char *)map[ic].function);
7117c2d2
JA
324 else if (map[ic].type == ISKMAP)
325 {
326 map = FUNCTION_TO_KEYMAP (map, ic);
327 ic = ANYOTHERKEY;
328 }
726f6388
JA
329
330 map[ic].function = KEYMAP_TO_FUNCTION (data);
331 map[ic].type = type;
332 }
ccc6cda3
JA
333
334 rl_binding_keymap = map;
726f6388
JA
335 }
336 free (keys);
337 return 0;
338}
339
340/* Translate the ASCII representation of SEQ, stuffing the values into ARRAY,
341 an array of characters. LEN gets the final length of ARRAY. Return
342 non-zero if there was an error parsing SEQ. */
ccc6cda3 343int
726f6388 344rl_translate_keyseq (seq, array, len)
28ef6c31
JA
345 const char *seq;
346 char *array;
726f6388
JA
347 int *len;
348{
cce855bc 349 register int i, c, l, temp;
726f6388 350
ccc6cda3 351 for (i = l = 0; c = seq[i]; i++)
726f6388
JA
352 {
353 if (c == '\\')
354 {
355 c = seq[++i];
356
ccc6cda3 357 if (c == 0)
726f6388
JA
358 break;
359
cce855bc
JA
360 /* Handle \C- and \M- prefixes. */
361 if ((c == 'C' || c == 'M') && seq[i + 1] == '-')
726f6388
JA
362 {
363 /* Handle special case of backwards define. */
364 if (strncmp (&seq[i], "C-\\M-", 5) == 0)
365 {
7117c2d2 366 array[l++] = ESC; /* ESC is meta-prefix */
726f6388 367 i += 5;
ccc6cda3 368 array[l++] = CTRL (_rl_to_upper (seq[i]));
cce855bc 369 if (seq[i] == '\0')
726f6388 370 i--;
726f6388 371 }
cce855bc 372 else if (c == 'M')
726f6388 373 {
726f6388 374 i++;
7117c2d2 375 array[l++] = ESC; /* ESC is meta-prefix */
cce855bc
JA
376 }
377 else if (c == 'C')
378 {
726f6388
JA
379 i += 2;
380 /* Special hack for C-?... */
ccc6cda3 381 array[l++] = (seq[i] == '?') ? RUBOUT : CTRL (_rl_to_upper (seq[i]));
726f6388 382 }
726f6388 383 continue;
cce855bc
JA
384 }
385
386 /* Translate other backslash-escaped characters. These are the
387 same escape sequences that bash's `echo' and `printf' builtins
388 handle, with the addition of \d -> RUBOUT. A backslash
389 preceding a character that is not special is stripped. */
390 switch (c)
391 {
392 case 'a':
393 array[l++] = '\007';
394 break;
395 case 'b':
396 array[l++] = '\b';
397 break;
398 case 'd':
399 array[l++] = RUBOUT; /* readline-specific */
400 break;
401 case 'e':
402 array[l++] = ESC;
403 break;
404 case 'f':
405 array[l++] = '\f';
406 break;
407 case 'n':
408 array[l++] = NEWLINE;
409 break;
410 case 'r':
411 array[l++] = RETURN;
412 break;
413 case 't':
414 array[l++] = TAB;
415 break;
416 case 'v':
417 array[l++] = 0x0B;
418 break;
419 case '\\':
420 array[l++] = '\\';
421 break;
422 case '0': case '1': case '2': case '3':
423 case '4': case '5': case '6': case '7':
424 i++;
425 for (temp = 2, c -= '0'; ISOCTAL (seq[i]) && temp--; i++)
426 c = (c * 8) + OCTVALUE (seq[i]);
427 i--; /* auto-increment in for loop */
f73dda09 428 array[l++] = c & largest_char;
cce855bc
JA
429 break;
430 case 'x':
431 i++;
f73dda09 432 for (temp = 2, c = 0; ISXDIGIT ((unsigned char)seq[i]) && temp--; i++)
cce855bc 433 c = (c * 16) + HEXVALUE (seq[i]);
f73dda09 434 if (temp == 2)
cce855bc
JA
435 c = 'x';
436 i--; /* auto-increment in for loop */
f73dda09 437 array[l++] = c & largest_char;
cce855bc
JA
438 break;
439 default: /* backslashes before non-special chars just add the char */
440 array[l++] = c;
441 break; /* the backslash is stripped */
726f6388 442 }
cce855bc 443 continue;
726f6388 444 }
cce855bc 445
726f6388
JA
446 array[l++] = c;
447 }
448
449 *len = l;
450 array[l] = '\0';
451 return (0);
452}
453
ccc6cda3
JA
454char *
455rl_untranslate_keyseq (seq)
456 int seq;
457{
458 static char kseq[16];
459 int i, c;
460
461 i = 0;
462 c = seq;
463 if (META_CHAR (c))
464 {
465 kseq[i++] = '\\';
466 kseq[i++] = 'M';
467 kseq[i++] = '-';
468 c = UNMETA (c);
469 }
470 else if (CTRL_CHAR (c))
471 {
472 kseq[i++] = '\\';
473 kseq[i++] = 'C';
474 kseq[i++] = '-';
d166f048 475 c = _rl_to_lower (UNCTRL (c));
ccc6cda3
JA
476 }
477 else if (c == RUBOUT)
478 {
479 kseq[i++] = '\\';
480 kseq[i++] = 'C';
481 kseq[i++] = '-';
482 c = '?';
483 }
484
485 if (c == ESC)
486 {
487 kseq[i++] = '\\';
d166f048 488 c = 'e';
ccc6cda3
JA
489 }
490 else if (c == '\\' || c == '"')
491 {
492 kseq[i++] = '\\';
493 }
494
495 kseq[i++] = (unsigned char) c;
496 kseq[i] = '\0';
497 return kseq;
498}
499
d166f048
JA
500static char *
501_rl_untranslate_macro_value (seq)
502 char *seq;
503{
504 char *ret, *r, *s;
505 int c;
506
f73dda09 507 r = ret = (char *)xmalloc (7 * strlen (seq) + 1);
d166f048
JA
508 for (s = seq; *s; s++)
509 {
510 c = *s;
511 if (META_CHAR (c))
512 {
513 *r++ = '\\';
514 *r++ = 'M';
515 *r++ = '-';
516 c = UNMETA (c);
517 }
518 else if (CTRL_CHAR (c) && c != ESC)
519 {
520 *r++ = '\\';
521 *r++ = 'C';
522 *r++ = '-';
523 c = _rl_to_lower (UNCTRL (c));
524 }
525 else if (c == RUBOUT)
526 {
527 *r++ = '\\';
528 *r++ = 'C';
529 *r++ = '-';
530 c = '?';
531 }
532
533 if (c == ESC)
534 {
535 *r++ = '\\';
536 c = 'e';
537 }
538 else if (c == '\\' || c == '"')
539 *r++ = '\\';
540
541 *r++ = (unsigned char)c;
542 }
543 *r = '\0';
544 return ret;
545}
546
726f6388
JA
547/* Return a pointer to the function that STRING represents.
548 If STRING doesn't have a matching function, then a NULL pointer
549 is returned. */
28ef6c31 550rl_command_func_t *
726f6388 551rl_named_function (string)
28ef6c31 552 const char *string;
726f6388
JA
553{
554 register int i;
555
556 rl_initialize_funmap ();
557
558 for (i = 0; funmap[i]; i++)
ccc6cda3 559 if (_rl_stricmp (funmap[i]->name, string) == 0)
726f6388 560 return (funmap[i]->function);
28ef6c31 561 return ((rl_command_func_t *)NULL);
726f6388
JA
562}
563
564/* Return the function (or macro) definition which would be invoked via
565 KEYSEQ if executed in MAP. If MAP is NULL, then the current keymap is
566 used. TYPE, if non-NULL, is a pointer to an int which will receive the
567 type of the object pointed to. One of ISFUNC (function), ISKMAP (keymap),
568 or ISMACR (macro). */
28ef6c31 569rl_command_func_t *
726f6388 570rl_function_of_keyseq (keyseq, map, type)
28ef6c31 571 const char *keyseq;
726f6388
JA
572 Keymap map;
573 int *type;
574{
575 register int i;
576
577 if (!map)
578 map = _rl_keymap;
579
580 for (i = 0; keyseq && keyseq[i]; i++)
581 {
f73dda09 582 unsigned char ic = keyseq[i];
726f6388
JA
583
584 if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii)
585 {
586 if (map[ESC].type != ISKMAP)
587 {
588 if (type)
589 *type = map[ESC].type;
590
591 return (map[ESC].function);
592 }
593 else
594 {
595 map = FUNCTION_TO_KEYMAP (map, ESC);
596 ic = UNMETA (ic);
597 }
598 }
599
600 if (map[ic].type == ISKMAP)
601 {
602 /* If this is the last key in the key sequence, return the
603 map. */
604 if (!keyseq[i + 1])
605 {
606 if (type)
607 *type = ISKMAP;
608
609 return (map[ic].function);
610 }
611 else
612 map = FUNCTION_TO_KEYMAP (map, ic);
613 }
614 else
615 {
616 if (type)
617 *type = map[ic].type;
618
619 return (map[ic].function);
620 }
621 }
28ef6c31 622 return ((rl_command_func_t *) NULL);
726f6388
JA
623}
624
625/* The last key bindings file read. */
626static char *last_readline_init_file = (char *)NULL;
627
ccc6cda3 628/* The file we're currently reading key bindings from. */
28ef6c31 629static const char *current_readline_init_file;
cce855bc 630static int current_readline_init_include_level;
ccc6cda3
JA
631static int current_readline_init_lineno;
632
cce855bc
JA
633/* Read FILENAME into a locally-allocated buffer and return the buffer.
634 The size of the buffer is returned in *SIZEP. Returns NULL if any
635 errors were encountered. */
636static char *
637_rl_read_file (filename, sizep)
638 char *filename;
639 size_t *sizep;
640{
641 struct stat finfo;
642 size_t file_size;
643 char *buffer;
644 int i, file;
645
646 if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY, 0666)) < 0)
647 return ((char *)NULL);
648
649 file_size = (size_t)finfo.st_size;
650
651 /* check for overflow on very large files */
652 if (file_size != finfo.st_size || file_size + 1 < file_size)
653 {
654 if (file >= 0)
655 close (file);
656#if defined (EFBIG)
657 errno = EFBIG;
658#endif
659 return ((char *)NULL);
660 }
661
662 /* Read the file into BUFFER. */
663 buffer = (char *)xmalloc (file_size + 1);
664 i = read (file, buffer, file_size);
665 close (file);
666
b72432fd 667 if (i < 0)
cce855bc
JA
668 {
669 free (buffer);
670 return ((char *)NULL);
671 }
672
bb70624e
JA
673 buffer[i] = '\0';
674 if (sizep)
675 *sizep = i;
bb70624e 676
cce855bc
JA
677 return (buffer);
678}
679
726f6388 680/* Re-read the current keybindings file. */
ccc6cda3 681int
726f6388
JA
682rl_re_read_init_file (count, ignore)
683 int count, ignore;
684{
685 int r;
28ef6c31 686 r = rl_read_init_file ((const char *)NULL);
726f6388
JA
687 rl_set_keymap_from_edit_mode ();
688 return r;
689}
690
691/* Do key bindings from a file. If FILENAME is NULL it defaults
692 to the first non-null filename from this list:
693 1. the filename used for the previous call
694 2. the value of the shell variable `INPUTRC'
695 3. ~/.inputrc
696 If the file existed and could be opened and read, 0 is returned,
697 otherwise errno is returned. */
698int
699rl_read_init_file (filename)
28ef6c31 700 const char *filename;
726f6388 701{
726f6388 702 /* Default the filename. */
ccc6cda3 703 if (filename == 0)
726f6388
JA
704 {
705 filename = last_readline_init_file;
ccc6cda3 706 if (filename == 0)
28ef6c31 707 filename = sh_get_env_value ("INPUTRC");
ccc6cda3 708 if (filename == 0)
726f6388
JA
709 filename = DEFAULT_INPUTRC;
710 }
711
ccc6cda3 712 if (*filename == 0)
726f6388
JA
713 filename = DEFAULT_INPUTRC;
714
bb70624e
JA
715#if defined (__MSDOS__)
716 if (_rl_read_init_file (filename, 0) == 0)
717 return 0;
718 filename = "~/_inputrc";
719#endif
cce855bc
JA
720 return (_rl_read_init_file (filename, 0));
721}
726f6388 722
cce855bc
JA
723static int
724_rl_read_init_file (filename, include_level)
28ef6c31 725 const char *filename;
cce855bc
JA
726 int include_level;
727{
728 register int i;
729 char *buffer, *openname, *line, *end;
730 size_t file_size;
726f6388 731
cce855bc
JA
732 current_readline_init_file = filename;
733 current_readline_init_include_level = include_level;
726f6388 734
cce855bc
JA
735 openname = tilde_expand (filename);
736 buffer = _rl_read_file (openname, &file_size);
b72432fd
JA
737 free (openname);
738
cce855bc
JA
739 if (buffer == 0)
740 return (errno);
741
742 if (include_level == 0 && filename != last_readline_init_file)
743 {
744 FREE (last_readline_init_file);
726f6388
JA
745 last_readline_init_file = savestring (filename);
746 }
747
bb70624e
JA
748 currently_reading_init_file = 1;
749
726f6388
JA
750 /* Loop over the lines in the file. Lines that start with `#' are
751 comments; all other lines are commands for readline initialization. */
ccc6cda3 752 current_readline_init_lineno = 1;
726f6388 753 line = buffer;
cce855bc 754 end = buffer + file_size;
726f6388
JA
755 while (line < end)
756 {
757 /* Find the end of this line. */
758 for (i = 0; line + i != end && line[i] != '\n'; i++);
759
28ef6c31 760#if defined (__CYGWIN__)
bb70624e
JA
761 /* ``Be liberal in what you accept.'' */
762 if (line[i] == '\n' && line[i-1] == '\r')
763 line[i - 1] = '\0';
764#endif
765
726f6388
JA
766 /* Mark end of line. */
767 line[i] = '\0';
768
769 /* Skip leading whitespace. */
770 while (*line && whitespace (*line))
771 {
772 line++;
773 i--;
774 }
775
776 /* If the line is not a comment, then parse it. */
777 if (*line && *line != '#')
778 rl_parse_and_bind (line);
779
780 /* Move to the next line. */
781 line += i + 1;
ccc6cda3 782 current_readline_init_lineno++;
726f6388 783 }
cce855bc 784
726f6388 785 free (buffer);
bb70624e 786 currently_reading_init_file = 0;
726f6388
JA
787 return (0);
788}
789
ccc6cda3
JA
790static void
791_rl_init_file_error (msg)
7117c2d2 792 const char *msg;
ccc6cda3 793{
bb70624e
JA
794 if (currently_reading_init_file)
795 fprintf (stderr, "readline: %s: line %d: %s\n", current_readline_init_file,
796 current_readline_init_lineno, msg);
797 else
798 fprintf (stderr, "readline: %s\n", msg);
ccc6cda3
JA
799}
800
726f6388
JA
801/* **************************************************************** */
802/* */
803/* Parser Directives */
804/* */
805/* **************************************************************** */
806
f73dda09 807typedef int _rl_parser_func_t PARAMS((char *));
28ef6c31
JA
808
809/* Things that mean `Control'. */
810const char *_rl_possible_control_prefixes[] = {
811 "Control-", "C-", "CTRL-", (const char *)NULL
812};
813
814const char *_rl_possible_meta_prefixes[] = {
815 "Meta", "M-", (const char *)NULL
816};
817
726f6388
JA
818/* Conditionals. */
819
820/* Calling programs set this to have their argv[0]. */
28ef6c31 821const char *rl_readline_name = "other";
726f6388
JA
822
823/* Stack of previous values of parsing_conditionalized_out. */
824static unsigned char *if_stack = (unsigned char *)NULL;
ccc6cda3
JA
825static int if_stack_depth;
826static int if_stack_size;
726f6388
JA
827
828/* Push _rl_parsing_conditionalized_out, and set parser state based
829 on ARGS. */
830static int
831parser_if (args)
832 char *args;
833{
834 register int i;
835
836 /* Push parser state. */
837 if (if_stack_depth + 1 >= if_stack_size)
838 {
839 if (!if_stack)
840 if_stack = (unsigned char *)xmalloc (if_stack_size = 20);
841 else
842 if_stack = (unsigned char *)xrealloc (if_stack, if_stack_size += 20);
843 }
844 if_stack[if_stack_depth++] = _rl_parsing_conditionalized_out;
845
846 /* If parsing is turned off, then nothing can turn it back on except
847 for finding the matching endif. In that case, return right now. */
848 if (_rl_parsing_conditionalized_out)
849 return 0;
850
851 /* Isolate first argument. */
852 for (i = 0; args[i] && !whitespace (args[i]); i++);
853
854 if (args[i])
855 args[i++] = '\0';
856
cce855bc 857 /* Handle "$if term=foo" and "$if mode=emacs" constructs. If this
726f6388
JA
858 isn't term=foo, or mode=emacs, then check to see if the first
859 word in ARGS is the same as the value stored in rl_readline_name. */
ccc6cda3 860 if (rl_terminal_name && _rl_strnicmp (args, "term=", 5) == 0)
726f6388
JA
861 {
862 char *tem, *tname;
863
864 /* Terminals like "aaa-60" are equivalent to "aaa". */
865 tname = savestring (rl_terminal_name);
866 tem = strchr (tname, '-');
867 if (tem)
868 *tem = '\0';
869
870 /* Test the `long' and `short' forms of the terminal name so that
871 if someone has a `sun-cmd' and does not want to have bindings
872 that will be executed if the terminal is a `sun', they can put
873 `$if term=sun-cmd' into their .inputrc. */
ccc6cda3
JA
874 _rl_parsing_conditionalized_out = _rl_stricmp (args + 5, tname) &&
875 _rl_stricmp (args + 5, rl_terminal_name);
726f6388
JA
876 free (tname);
877 }
878#if defined (VI_MODE)
ccc6cda3 879 else if (_rl_strnicmp (args, "mode=", 5) == 0)
726f6388
JA
880 {
881 int mode;
882
ccc6cda3 883 if (_rl_stricmp (args + 5, "emacs") == 0)
726f6388 884 mode = emacs_mode;
ccc6cda3 885 else if (_rl_stricmp (args + 5, "vi") == 0)
726f6388
JA
886 mode = vi_mode;
887 else
888 mode = no_mode;
889
ccc6cda3 890 _rl_parsing_conditionalized_out = mode != rl_editing_mode;
726f6388
JA
891 }
892#endif /* VI_MODE */
893 /* Check to see if the first word in ARGS is the same as the
894 value stored in rl_readline_name. */
ccc6cda3 895 else if (_rl_stricmp (args, rl_readline_name) == 0)
726f6388
JA
896 _rl_parsing_conditionalized_out = 0;
897 else
898 _rl_parsing_conditionalized_out = 1;
899 return 0;
900}
901
902/* Invert the current parser state if there is anything on the stack. */
903static int
904parser_else (args)
905 char *args;
906{
907 register int i;
908
cce855bc 909 if (if_stack_depth == 0)
726f6388 910 {
cce855bc 911 _rl_init_file_error ("$else found without matching $if");
726f6388
JA
912 return 0;
913 }
914
915 /* Check the previous (n - 1) levels of the stack to make sure that
916 we haven't previously turned off parsing. */
917 for (i = 0; i < if_stack_depth - 1; i++)
918 if (if_stack[i] == 1)
919 return 0;
920
921 /* Invert the state of parsing if at top level. */
922 _rl_parsing_conditionalized_out = !_rl_parsing_conditionalized_out;
923 return 0;
924}
925
926/* Terminate a conditional, popping the value of
927 _rl_parsing_conditionalized_out from the stack. */
928static int
929parser_endif (args)
930 char *args;
931{
932 if (if_stack_depth)
933 _rl_parsing_conditionalized_out = if_stack[--if_stack_depth];
934 else
cce855bc 935 _rl_init_file_error ("$endif without matching $if");
726f6388
JA
936 return 0;
937}
938
cce855bc
JA
939static int
940parser_include (args)
941 char *args;
942{
28ef6c31
JA
943 const char *old_init_file;
944 char *e;
cce855bc
JA
945 int old_line_number, old_include_level, r;
946
947 if (_rl_parsing_conditionalized_out)
948 return (0);
949
950 old_init_file = current_readline_init_file;
951 old_line_number = current_readline_init_lineno;
952 old_include_level = current_readline_init_include_level;
953
954 e = strchr (args, '\n');
955 if (e)
956 *e = '\0';
28ef6c31 957 r = _rl_read_init_file ((const char *)args, old_include_level + 1);
cce855bc
JA
958
959 current_readline_init_file = old_init_file;
960 current_readline_init_lineno = old_line_number;
961 current_readline_init_include_level = old_include_level;
962
963 return r;
964}
965
726f6388
JA
966/* Associate textual names with actual functions. */
967static struct {
28ef6c31
JA
968 const char *name;
969 _rl_parser_func_t *function;
726f6388
JA
970} parser_directives [] = {
971 { "if", parser_if },
972 { "endif", parser_endif },
973 { "else", parser_else },
cce855bc 974 { "include", parser_include },
28ef6c31 975 { (char *)0x0, (_rl_parser_func_t *)0x0 }
726f6388
JA
976};
977
978/* Handle a parser directive. STATEMENT is the line of the directive
979 without any leading `$'. */
980static int
981handle_parser_directive (statement)
982 char *statement;
983{
984 register int i;
985 char *directive, *args;
986
987 /* Isolate the actual directive. */
988
989 /* Skip whitespace. */
990 for (i = 0; whitespace (statement[i]); i++);
991
992 directive = &statement[i];
993
994 for (; statement[i] && !whitespace (statement[i]); i++);
995
996 if (statement[i])
997 statement[i++] = '\0';
998
999 for (; statement[i] && whitespace (statement[i]); i++);
1000
1001 args = &statement[i];
1002
1003 /* Lookup the command, and act on it. */
1004 for (i = 0; parser_directives[i].name; i++)
ccc6cda3 1005 if (_rl_stricmp (directive, parser_directives[i].name) == 0)
726f6388
JA
1006 {
1007 (*parser_directives[i].function) (args);
1008 return (0);
1009 }
1010
cce855bc
JA
1011 /* display an error message about the unknown parser directive */
1012 _rl_init_file_error ("unknown parser directive");
726f6388
JA
1013 return (1);
1014}
1015
726f6388
JA
1016/* Read the binding command from STRING and perform it.
1017 A key binding command looks like: Keyname: function-name\0,
1018 a variable binding command looks like: set variable value.
1019 A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */
ccc6cda3 1020int
726f6388
JA
1021rl_parse_and_bind (string)
1022 char *string;
1023{
1024 char *funname, *kname;
1025 register int c, i;
1026 int key, equivalency;
1027
1028 while (string && whitespace (*string))
1029 string++;
1030
1031 if (!string || !*string || *string == '#')
1032 return 0;
1033
1034 /* If this is a parser directive, act on it. */
1035 if (*string == '$')
1036 {
1037 handle_parser_directive (&string[1]);
1038 return 0;
1039 }
1040
1041 /* If we aren't supposed to be parsing right now, then we're done. */
1042 if (_rl_parsing_conditionalized_out)
1043 return 0;
1044
1045 i = 0;
1046 /* If this keyname is a complex key expression surrounded by quotes,
1047 advance to after the matching close quote. This code allows the
1048 backslash to quote characters in the key expression. */
1049 if (*string == '"')
1050 {
1051 int passc = 0;
1052
1053 for (i = 1; c = string[i]; i++)
1054 {
1055 if (passc)
1056 {
1057 passc = 0;
1058 continue;
1059 }
1060
1061 if (c == '\\')
1062 {
1063 passc++;
1064 continue;
1065 }
1066
1067 if (c == '"')
1068 break;
1069 }
ccc6cda3
JA
1070 /* If we didn't find a closing quote, abort the line. */
1071 if (string[i] == '\0')
1072 {
1073 _rl_init_file_error ("no closing `\"' in key binding");
1074 return 1;
1075 }
726f6388
JA
1076 }
1077
1078 /* Advance to the colon (:) or whitespace which separates the two objects. */
1079 for (; (c = string[i]) && c != ':' && c != ' ' && c != '\t'; i++ );
1080
1081 equivalency = (c == ':' && string[i + 1] == '=');
1082
1083 /* Mark the end of the command (or keyname). */
1084 if (string[i])
1085 string[i++] = '\0';
1086
1087 /* If doing assignment, skip the '=' sign as well. */
1088 if (equivalency)
1089 string[i++] = '\0';
1090
1091 /* If this is a command to set a variable, then do that. */
ccc6cda3 1092 if (_rl_stricmp (string, "set") == 0)
726f6388
JA
1093 {
1094 char *var = string + i;
1095 char *value;
1096
1097 /* Make VAR point to start of variable name. */
1098 while (*var && whitespace (*var)) var++;
1099
7117c2d2 1100 /* Make VALUE point to start of value string. */
726f6388
JA
1101 value = var;
1102 while (*value && !whitespace (*value)) value++;
1103 if (*value)
1104 *value++ = '\0';
1105 while (*value && whitespace (*value)) value++;
1106
1107 rl_variable_bind (var, value);
1108 return 0;
1109 }
1110
1111 /* Skip any whitespace between keyname and funname. */
1112 for (; string[i] && whitespace (string[i]); i++);
1113 funname = &string[i];
1114
1115 /* Now isolate funname.
1116 For straight function names just look for whitespace, since
1117 that will signify the end of the string. But this could be a
1118 macro definition. In that case, the string is quoted, so skip
1119 to the matching delimiter. We allow the backslash to quote the
1120 delimiter characters in the macro body. */
1121 /* This code exists to allow whitespace in macro expansions, which
1122 would otherwise be gobbled up by the next `for' loop.*/
1123 /* XXX - it may be desirable to allow backslash quoting only if " is
1124 the quoted string delimiter, like the shell. */
1125 if (*funname == '\'' || *funname == '"')
1126 {
cce855bc 1127 int delimiter = string[i++], passc;
726f6388 1128
cce855bc 1129 for (passc = 0; c = string[i]; i++)
726f6388
JA
1130 {
1131 if (passc)
1132 {
1133 passc = 0;
1134 continue;
1135 }
1136
1137 if (c == '\\')
1138 {
1139 passc = 1;
1140 continue;
1141 }
1142
1143 if (c == delimiter)
1144 break;
1145 }
1146 if (c)
1147 i++;
1148 }
1149
1150 /* Advance to the end of the string. */
1151 for (; string[i] && !whitespace (string[i]); i++);
1152
1153 /* No extra whitespace at the end of the string. */
1154 string[i] = '\0';
1155
1156 /* Handle equivalency bindings here. Make the left-hand side be exactly
1157 whatever the right-hand evaluates to, including keymaps. */
1158 if (equivalency)
1159 {
1160 return 0;
1161 }
1162
1163 /* If this is a new-style key-binding, then do the binding with
1164 rl_set_key (). Otherwise, let the older code deal with it. */
1165 if (*string == '"')
1166 {
cce855bc
JA
1167 char *seq;
1168 register int j, k, passc;
726f6388 1169
f73dda09 1170 seq = (char *)xmalloc (1 + strlen (string));
cce855bc 1171 for (j = 1, k = passc = 0; string[j]; j++)
726f6388
JA
1172 {
1173 /* Allow backslash to quote characters, but leave them in place.
1174 This allows a string to end with a backslash quoting another
1175 backslash, or with a backslash quoting a double quote. The
1176 backslashes are left in place for rl_translate_keyseq (). */
1177 if (passc || (string[j] == '\\'))
1178 {
1179 seq[k++] = string[j];
1180 passc = !passc;
1181 continue;
1182 }
1183
1184 if (string[j] == '"')
1185 break;
1186
1187 seq[k++] = string[j];
1188 }
1189 seq[k] = '\0';
1190
1191 /* Binding macro? */
1192 if (*funname == '\'' || *funname == '"')
1193 {
1194 j = strlen (funname);
1195
1196 /* Remove the delimiting quotes from each end of FUNNAME. */
1197 if (j && funname[j - 1] == *funname)
1198 funname[j - 1] = '\0';
1199
1200 rl_macro_bind (seq, &funname[1], _rl_keymap);
1201 }
1202 else
1203 rl_set_key (seq, rl_named_function (funname), _rl_keymap);
1204
1205 free (seq);
1206 return 0;
1207 }
1208
1209 /* Get the actual character we want to deal with. */
1210 kname = strrchr (string, '-');
1211 if (!kname)
1212 kname = string;
1213 else
1214 kname++;
1215
1216 key = glean_key_from_name (kname);
1217
1218 /* Add in control and meta bits. */
28ef6c31 1219 if (substring_member_of_array (string, _rl_possible_control_prefixes))
ccc6cda3 1220 key = CTRL (_rl_to_upper (key));
726f6388 1221
28ef6c31 1222 if (substring_member_of_array (string, _rl_possible_meta_prefixes))
726f6388
JA
1223 key = META (key);
1224
1225 /* Temporary. Handle old-style keyname with macro-binding. */
1226 if (*funname == '\'' || *funname == '"')
1227 {
f73dda09 1228 char useq[2];
726f6388
JA
1229 int fl = strlen (funname);
1230
d166f048 1231 useq[0] = key; useq[1] = '\0';
726f6388
JA
1232 if (fl && funname[fl - 1] == *funname)
1233 funname[fl - 1] = '\0';
1234
d166f048 1235 rl_macro_bind (useq, &funname[1], _rl_keymap);
726f6388
JA
1236 }
1237#if defined (PREFIX_META_HACK)
1238 /* Ugly, but working hack to keep prefix-meta around. */
ccc6cda3 1239 else if (_rl_stricmp (funname, "prefix-meta") == 0)
726f6388
JA
1240 {
1241 char seq[2];
1242
1243 seq[0] = key;
1244 seq[1] = '\0';
1245 rl_generic_bind (ISKMAP, seq, (char *)emacs_meta_keymap, _rl_keymap);
1246 }
1247#endif /* PREFIX_META_HACK */
1248 else
1249 rl_bind_key (key, rl_named_function (funname));
1250 return 0;
1251}
1252
1253/* Simple structure for boolean readline variables (i.e., those that can
1254 have one of two values; either "On" or 1 for truth, or "Off" or 0 for
1255 false. */
1256
bb70624e
JA
1257#define V_SPECIAL 0x1
1258
726f6388 1259static struct {
28ef6c31 1260 const char *name;
726f6388 1261 int *value;
bb70624e 1262 int flags;
726f6388 1263} boolean_varlist [] = {
bb70624e 1264 { "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL },
7117c2d2 1265 { "byte-oriented", &rl_byte_oriented, 0 },
bb70624e
JA
1266 { "completion-ignore-case", &_rl_completion_case_fold, 0 },
1267 { "convert-meta", &_rl_convert_meta_chars_to_ascii, 0 },
1268 { "disable-completion", &rl_inhibit_completion, 0 },
1269 { "enable-keypad", &_rl_enable_keypad, 0 },
1270 { "expand-tilde", &rl_complete_with_tilde_expansion, 0 },
f73dda09 1271 { "history-preserve-point", &_rl_history_preserve_point, 0 },
bb70624e
JA
1272 { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode, 0 },
1273 { "input-meta", &_rl_meta_flag, 0 },
1274 { "mark-directories", &_rl_complete_mark_directories, 0 },
1275 { "mark-modified-lines", &_rl_mark_modified_lines, 0 },
7117c2d2 1276 { "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs, 0 },
f73dda09 1277 { "match-hidden-files", &_rl_match_hidden_files, 0 },
bb70624e
JA
1278 { "meta-flag", &_rl_meta_flag, 0 },
1279 { "output-meta", &_rl_output_meta_chars, 0 },
7117c2d2 1280 { "page-completions", &_rl_page_completions, 0 },
bb70624e
JA
1281 { "prefer-visible-bell", &_rl_prefer_visible_bell, V_SPECIAL },
1282 { "print-completions-horizontally", &_rl_print_completions_horizontally, 0 },
1283 { "show-all-if-ambiguous", &_rl_complete_show_all, 0 },
726f6388 1284#if defined (VISIBLE_STATS)
bb70624e 1285 { "visible-stats", &rl_visible_stats, 0 },
726f6388 1286#endif /* VISIBLE_STATS */
726f6388
JA
1287 { (char *)NULL, (int *)NULL }
1288};
1289
bb70624e
JA
1290static int
1291find_boolean_var (name)
7117c2d2 1292 const char *name;
bb70624e
JA
1293{
1294 register int i;
1295
1296 for (i = 0; boolean_varlist[i].name; i++)
1297 if (_rl_stricmp (name, boolean_varlist[i].name) == 0)
1298 return i;
1299 return -1;
1300}
1301
1302/* Hooks for handling special boolean variables, where a
1303 function needs to be called or another variable needs
1304 to be changed when they're changed. */
1305static void
1306hack_special_boolean_var (i)
1307 int i;
1308{
28ef6c31 1309 const char *name;
bb70624e
JA
1310
1311 name = boolean_varlist[i].name;
1312
1313 if (_rl_stricmp (name, "blink-matching-paren") == 0)
1314 _rl_enable_paren_matching (rl_blink_matching_paren);
1315 else if (_rl_stricmp (name, "prefer-visible-bell") == 0)
1316 {
1317 if (_rl_prefer_visible_bell)
1318 _rl_bell_preference = VISIBLE_BELL;
1319 else
1320 _rl_bell_preference = AUDIBLE_BELL;
1321 }
1322}
1323
f73dda09 1324typedef int _rl_sv_func_t PARAMS((const char *));
28ef6c31 1325
bb70624e
JA
1326/* These *must* correspond to the array indices for the appropriate
1327 string variable. (Though they're not used right now.) */
1328#define V_BELLSTYLE 0
1329#define V_COMBEGIN 1
1330#define V_EDITMODE 2
1331#define V_ISRCHTERM 3
1332#define V_KEYMAP 4
1333
1334#define V_STRING 1
1335#define V_INT 2
1336
1337/* Forward declarations */
f73dda09
JA
1338static int sv_bell_style PARAMS((const char *));
1339static int sv_combegin PARAMS((const char *));
1340static int sv_compquery PARAMS((const char *));
1341static int sv_editmode PARAMS((const char *));
1342static int sv_isrchterm PARAMS((const char *));
1343static int sv_keymap PARAMS((const char *));
bb70624e
JA
1344
1345static struct {
28ef6c31 1346 const char *name;
bb70624e 1347 int flags;
28ef6c31 1348 _rl_sv_func_t *set_func;
bb70624e
JA
1349} string_varlist[] = {
1350 { "bell-style", V_STRING, sv_bell_style },
1351 { "comment-begin", V_STRING, sv_combegin },
1352 { "completion-query-items", V_INT, sv_compquery },
1353 { "editing-mode", V_STRING, sv_editmode },
1354 { "isearch-terminators", V_STRING, sv_isrchterm },
1355 { "keymap", V_STRING, sv_keymap },
1356 { (char *)NULL, 0 }
1357};
1358
1359static int
1360find_string_var (name)
7117c2d2 1361 const char *name;
bb70624e
JA
1362{
1363 register int i;
1364
1365 for (i = 0; string_varlist[i].name; i++)
1366 if (_rl_stricmp (name, string_varlist[i].name) == 0)
1367 return i;
1368 return -1;
1369}
1370
1371/* A boolean value that can appear in a `set variable' command is true if
1372 the value is null or empty, `on' (case-insenstive), or "1". Any other
1373 values result in 0 (false). */
1374static int
1375bool_to_int (value)
1376 char *value;
1377{
1378 return (value == 0 || *value == '\0' ||
1379 (_rl_stricmp (value, "on") == 0) ||
1380 (value[0] == '1' && value[1] == '\0'));
1381}
1382
ccc6cda3 1383int
726f6388 1384rl_variable_bind (name, value)
28ef6c31 1385 const char *name, *value;
726f6388
JA
1386{
1387 register int i;
bb70624e 1388 int v;
726f6388
JA
1389
1390 /* Check for simple variables first. */
bb70624e
JA
1391 i = find_boolean_var (name);
1392 if (i >= 0)
726f6388 1393 {
bb70624e
JA
1394 *boolean_varlist[i].value = bool_to_int (value);
1395 if (boolean_varlist[i].flags & V_SPECIAL)
1396 hack_special_boolean_var (i);
1397 return 0;
726f6388
JA
1398 }
1399
bb70624e 1400 i = find_string_var (name);
726f6388 1401
bb70624e
JA
1402 /* For the time being, unknown variable names or string names without a
1403 handler function are simply ignored. */
1404 if (i < 0 || string_varlist[i].set_func == 0)
1405 return 0;
1406
1407 v = (*string_varlist[i].set_func) (value);
1408 return v;
1409}
1410
1411static int
1412sv_editmode (value)
28ef6c31 1413 const char *value;
bb70624e
JA
1414{
1415 if (_rl_strnicmp (value, "vi", 2) == 0)
726f6388 1416 {
726f6388 1417#if defined (VI_MODE)
bb70624e
JA
1418 _rl_keymap = vi_insertion_keymap;
1419 rl_editing_mode = vi_mode;
726f6388 1420#endif /* VI_MODE */
bb70624e 1421 return 0;
726f6388 1422 }
bb70624e 1423 else if (_rl_strnicmp (value, "emacs", 5) == 0)
726f6388 1424 {
bb70624e
JA
1425 _rl_keymap = emacs_standard_keymap;
1426 rl_editing_mode = emacs_mode;
1427 return 0;
726f6388 1428 }
bb70624e
JA
1429 return 1;
1430}
1431
1432static int
1433sv_combegin (value)
28ef6c31 1434 const char *value;
bb70624e
JA
1435{
1436 if (value && *value)
726f6388 1437 {
bb70624e
JA
1438 FREE (_rl_comment_begin);
1439 _rl_comment_begin = savestring (value);
1440 return 0;
726f6388 1441 }
bb70624e
JA
1442 return 1;
1443}
1444
1445static int
1446sv_compquery (value)
28ef6c31 1447 const char *value;
bb70624e
JA
1448{
1449 int nval = 100;
1450
1451 if (value && *value)
726f6388 1452 {
bb70624e
JA
1453 nval = atoi (value);
1454 if (nval < 0)
1455 nval = 0;
726f6388 1456 }
bb70624e
JA
1457 rl_completion_query_items = nval;
1458 return 0;
1459}
1460
1461static int
1462sv_keymap (value)
28ef6c31 1463 const char *value;
bb70624e
JA
1464{
1465 Keymap kmap;
1466
1467 kmap = rl_get_keymap_by_name (value);
1468 if (kmap)
726f6388 1469 {
bb70624e
JA
1470 rl_set_keymap (kmap);
1471 return 0;
726f6388 1472 }
bb70624e
JA
1473 return 1;
1474}
1475
bb70624e
JA
1476static int
1477sv_bell_style (value)
28ef6c31 1478 const char *value;
bb70624e
JA
1479{
1480 if (value == 0 || *value == '\0')
f73dda09 1481 _rl_bell_preference = AUDIBLE_BELL;
bb70624e 1482 else if (_rl_stricmp (value, "none") == 0 || _rl_stricmp (value, "off") == 0)
f73dda09 1483 _rl_bell_preference = NO_BELL;
bb70624e 1484 else if (_rl_stricmp (value, "audible") == 0 || _rl_stricmp (value, "on") == 0)
f73dda09 1485 _rl_bell_preference = AUDIBLE_BELL;
bb70624e 1486 else if (_rl_stricmp (value, "visible") == 0)
f73dda09 1487 _rl_bell_preference = VISIBLE_BELL;
bb70624e
JA
1488 else
1489 return 1;
f73dda09 1490 return 0;
bb70624e 1491}
bb70624e
JA
1492
1493static int
1494sv_isrchterm (value)
28ef6c31 1495 const char *value;
bb70624e
JA
1496{
1497 int beg, end, delim;
1498 char *v;
1499
1500 if (value == 0)
1501 return 1;
1502
1503 /* Isolate the value and translate it into a character string. */
1504 v = savestring (value);
1505 FREE (_rl_isearch_terminators);
1506 if (v[0] == '"' || v[0] == '\'')
726f6388 1507 {
bb70624e
JA
1508 delim = v[0];
1509 for (beg = end = 1; v[end] && v[end] != delim; end++)
1510 ;
726f6388 1511 }
bb70624e 1512 else
b72432fd 1513 {
bb70624e
JA
1514 for (beg = end = 0; whitespace (v[end]) == 0; end++)
1515 ;
1516 }
726f6388 1517
bb70624e 1518 v[end] = '\0';
b72432fd 1519
bb70624e 1520 /* The value starts at v + beg. Translate it into a character string. */
f73dda09 1521 _rl_isearch_terminators = (char *)xmalloc (2 * strlen (v) + 1);
bb70624e
JA
1522 rl_translate_keyseq (v + beg, _rl_isearch_terminators, &end);
1523 _rl_isearch_terminators[end] = '\0';
1524
1525 free (v);
726f6388
JA
1526 return 0;
1527}
bb70624e 1528
726f6388
JA
1529/* Return the character which matches NAME.
1530 For example, `Space' returns ' '. */
1531
1532typedef struct {
28ef6c31 1533 const char *name;
726f6388
JA
1534 int value;
1535} assoc_list;
1536
1537static assoc_list name_key_alist[] = {
1538 { "DEL", 0x7f },
1539 { "ESC", '\033' },
1540 { "Escape", '\033' },
1541 { "LFD", '\n' },
1542 { "Newline", '\n' },
1543 { "RET", '\r' },
1544 { "Return", '\r' },
1545 { "Rubout", 0x7f },
1546 { "SPC", ' ' },
1547 { "Space", ' ' },
1548 { "Tab", 0x09 },
1549 { (char *)0x0, 0 }
1550};
1551
1552static int
1553glean_key_from_name (name)
1554 char *name;
1555{
1556 register int i;
1557
1558 for (i = 0; name_key_alist[i].name; i++)
ccc6cda3 1559 if (_rl_stricmp (name, name_key_alist[i].name) == 0)
726f6388
JA
1560 return (name_key_alist[i].value);
1561
1562 return (*(unsigned char *)name); /* XXX was return (*name) */
1563}
1564
1565/* Auxiliary functions to manage keymaps. */
1566static struct {
28ef6c31 1567 const char *name;
726f6388
JA
1568 Keymap map;
1569} keymap_names[] = {
1570 { "emacs", emacs_standard_keymap },
1571 { "emacs-standard", emacs_standard_keymap },
1572 { "emacs-meta", emacs_meta_keymap },
1573 { "emacs-ctlx", emacs_ctlx_keymap },
1574#if defined (VI_MODE)
1575 { "vi", vi_movement_keymap },
1576 { "vi-move", vi_movement_keymap },
1577 { "vi-command", vi_movement_keymap },
1578 { "vi-insert", vi_insertion_keymap },
1579#endif /* VI_MODE */
1580 { (char *)0x0, (Keymap)0x0 }
1581};
1582
1583Keymap
1584rl_get_keymap_by_name (name)
28ef6c31 1585 const char *name;
726f6388
JA
1586{
1587 register int i;
1588
1589 for (i = 0; keymap_names[i].name; i++)
28ef6c31 1590 if (_rl_stricmp (name, keymap_names[i].name) == 0)
726f6388
JA
1591 return (keymap_names[i].map);
1592 return ((Keymap) NULL);
1593}
1594
ccc6cda3
JA
1595char *
1596rl_get_keymap_name (map)
1597 Keymap map;
1598{
1599 register int i;
1600 for (i = 0; keymap_names[i].name; i++)
1601 if (map == keymap_names[i].map)
28ef6c31 1602 return ((char *)keymap_names[i].name);
ccc6cda3
JA
1603 return ((char *)NULL);
1604}
1605
726f6388
JA
1606void
1607rl_set_keymap (map)
1608 Keymap map;
1609{
1610 if (map)
1611 _rl_keymap = map;
1612}
1613
1614Keymap
1615rl_get_keymap ()
1616{
1617 return (_rl_keymap);
1618}
1619
1620void
1621rl_set_keymap_from_edit_mode ()
1622{
1623 if (rl_editing_mode == emacs_mode)
1624 _rl_keymap = emacs_standard_keymap;
1625#if defined (VI_MODE)
1626 else if (rl_editing_mode == vi_mode)
1627 _rl_keymap = vi_insertion_keymap;
1628#endif /* VI_MODE */
1629}
ccc6cda3
JA
1630
1631char *
1632rl_get_keymap_name_from_edit_mode ()
1633{
1634 if (rl_editing_mode == emacs_mode)
1635 return "emacs";
1636#if defined (VI_MODE)
1637 else if (rl_editing_mode == vi_mode)
1638 return "vi";
1639#endif /* VI_MODE */
1640 else
1641 return "none";
1642}
1643
726f6388
JA
1644/* **************************************************************** */
1645/* */
1646/* Key Binding and Function Information */
1647/* */
1648/* **************************************************************** */
1649
1650/* Each of the following functions produces information about the
1651 state of keybindings and functions known to Readline. The info
1652 is always printed to rl_outstream, and in such a way that it can
1653 be read back in (i.e., passed to rl_parse_and_bind (). */
1654
1655/* Print the names of functions known to Readline. */
1656void
ccc6cda3 1657rl_list_funmap_names ()
726f6388
JA
1658{
1659 register int i;
28ef6c31 1660 const char **funmap_names;
726f6388
JA
1661
1662 funmap_names = rl_funmap_names ();
1663
1664 if (!funmap_names)
1665 return;
1666
1667 for (i = 0; funmap_names[i]; i++)
1668 fprintf (rl_outstream, "%s\n", funmap_names[i]);
1669
1670 free (funmap_names);
1671}
1672
ccc6cda3
JA
1673static char *
1674_rl_get_keyname (key)
1675 int key;
1676{
1677 char *keyname;
b72432fd 1678 int i, c;
ccc6cda3
JA
1679
1680 keyname = (char *)xmalloc (8);
1681
1682 c = key;
1683 /* Since this is going to be used to write out keysequence-function
1684 pairs for possible inclusion in an inputrc file, we don't want to
1685 do any special meta processing on KEY. */
1686
7117c2d2
JA
1687#if 1
1688 /* XXX - Experimental */
ccc6cda3
JA
1689 /* We might want to do this, but the old version of the code did not. */
1690
1691 /* If this is an escape character, we don't want to do any more processing.
1692 Just add the special ESC key sequence and return. */
1693 if (c == ESC)
1694 {
7117c2d2
JA
1695 keyname[0] = '\\';
1696 keyname[1] = 'e';
1697 keyname[2] = '\0';
1698 return keyname;
ccc6cda3
JA
1699 }
1700#endif
1701
1702 /* RUBOUT is translated directly into \C-? */
1703 if (key == RUBOUT)
1704 {
1705 keyname[0] = '\\';
1706 keyname[1] = 'C';
1707 keyname[2] = '-';
1708 keyname[3] = '?';
1709 keyname[4] = '\0';
1710 return keyname;
1711 }
1712
1713 i = 0;
1714 /* Now add special prefixes needed for control characters. This can
1715 potentially change C. */
1716 if (CTRL_CHAR (c))
1717 {
1718 keyname[i++] = '\\';
1719 keyname[i++] = 'C';
1720 keyname[i++] = '-';
1721 c = _rl_to_lower (UNCTRL (c));
1722 }
1723
cce855bc
JA
1724 /* XXX experimental code. Turn the characters that are not ASCII or
1725 ISO Latin 1 (128 - 159) into octal escape sequences (\200 - \237).
1726 This changes C. */
1727 if (c >= 128 && c <= 159)
1728 {
1729 keyname[i++] = '\\';
1730 keyname[i++] = '2';
1731 c -= 128;
1732 keyname[i++] = (c / 8) + '0';
1733 c = (c % 8) + '0';
1734 }
1735
ccc6cda3
JA
1736 /* Now, if the character needs to be quoted with a backslash, do that. */
1737 if (c == '\\' || c == '"')
1738 keyname[i++] = '\\';
1739
1740 /* Now add the key, terminate the string, and return it. */
1741 keyname[i++] = (char) c;
1742 keyname[i] = '\0';
1743
1744 return keyname;
1745}
1746
726f6388
JA
1747/* Return a NULL terminated array of strings which represent the key
1748 sequences that are used to invoke FUNCTION in MAP. */
1749char **
1750rl_invoking_keyseqs_in_map (function, map)
28ef6c31 1751 rl_command_func_t *function;
726f6388
JA
1752 Keymap map;
1753{
1754 register int key;
1755 char **result;
1756 int result_index, result_size;
1757
1758 result = (char **)NULL;
1759 result_index = result_size = 0;
1760
ccc6cda3 1761 for (key = 0; key < KEYMAP_SIZE; key++)
726f6388
JA
1762 {
1763 switch (map[key].type)
1764 {
1765 case ISMACR:
1766 /* Macros match, if, and only if, the pointers are identical.
1767 Thus, they are treated exactly like functions in here. */
1768 case ISFUNC:
1769 /* If the function in the keymap is the one we are looking for,
1770 then add the current KEY to the list of invoking keys. */
1771 if (map[key].function == function)
1772 {
ccc6cda3 1773 char *keyname;
726f6388 1774
ccc6cda3 1775 keyname = _rl_get_keyname (key);
726f6388
JA
1776
1777 if (result_index + 2 > result_size)
ccc6cda3
JA
1778 {
1779 result_size += 10;
f73dda09 1780 result = (char **)xrealloc (result, result_size * sizeof (char *));
ccc6cda3 1781 }
726f6388
JA
1782
1783 result[result_index++] = keyname;
1784 result[result_index] = (char *)NULL;
1785 }
1786 break;
1787
1788 case ISKMAP:
1789 {
ccc6cda3
JA
1790 char **seqs;
1791 register int i;
726f6388
JA
1792
1793 /* Find the list of keyseqs in this map which have FUNCTION as
1794 their target. Add the key sequences found to RESULT. */
1795 if (map[key].function)
1796 seqs =
1797 rl_invoking_keyseqs_in_map (function, FUNCTION_TO_KEYMAP (map, key));
ccc6cda3
JA
1798 else
1799 break;
1800
1801 if (seqs == 0)
1802 break;
726f6388 1803
ccc6cda3 1804 for (i = 0; seqs[i]; i++)
726f6388 1805 {
ccc6cda3
JA
1806 char *keyname = (char *)xmalloc (6 + strlen (seqs[i]));
1807
1808 if (key == ESC)
7117c2d2 1809#if 0
ccc6cda3 1810 sprintf (keyname, "\\e");
7117c2d2
JA
1811#else
1812 /* XXX - experimental */
1813 sprintf (keyname, "\\M-");
1814#endif
ccc6cda3
JA
1815 else if (CTRL_CHAR (key))
1816 sprintf (keyname, "\\C-%c", _rl_to_lower (UNCTRL (key)));
1817 else if (key == RUBOUT)
1818 sprintf (keyname, "\\C-?");
1819 else if (key == '\\' || key == '"')
1820 {
1821 keyname[0] = '\\';
1822 keyname[1] = (char) key;
1823 keyname[2] = '\0';
1824 }
1825 else
1826 {
1827 keyname[0] = (char) key;
1828 keyname[1] = '\0';
1829 }
1830
1831 strcat (keyname, seqs[i]);
1832 free (seqs[i]);
726f6388 1833
ccc6cda3 1834 if (result_index + 2 > result_size)
726f6388 1835 {
ccc6cda3 1836 result_size += 10;
f73dda09 1837 result = (char **)xrealloc (result, result_size * sizeof (char *));
726f6388
JA
1838 }
1839
ccc6cda3
JA
1840 result[result_index++] = keyname;
1841 result[result_index] = (char *)NULL;
726f6388 1842 }
ccc6cda3
JA
1843
1844 free (seqs);
726f6388
JA
1845 }
1846 break;
1847 }
1848 }
1849 return (result);
1850}
1851
1852/* Return a NULL terminated array of strings which represent the key
1853 sequences that can be used to invoke FUNCTION using the current keymap. */
1854char **
1855rl_invoking_keyseqs (function)
28ef6c31 1856 rl_command_func_t *function;
726f6388
JA
1857{
1858 return (rl_invoking_keyseqs_in_map (function, _rl_keymap));
1859}
1860
726f6388
JA
1861/* Print all of the functions and their bindings to rl_outstream. If
1862 PRINT_READABLY is non-zero, then print the output in such a way
1863 that it can be read back in. */
1864void
1865rl_function_dumper (print_readably)
1866 int print_readably;
1867{
1868 register int i;
28ef6c31
JA
1869 const char **names;
1870 const char *name;
726f6388
JA
1871
1872 names = rl_funmap_names ();
1873
1874 fprintf (rl_outstream, "\n");
1875
1876 for (i = 0; name = names[i]; i++)
1877 {
28ef6c31 1878 rl_command_func_t *function;
726f6388
JA
1879 char **invokers;
1880
1881 function = rl_named_function (name);
1882 invokers = rl_invoking_keyseqs_in_map (function, _rl_keymap);
1883
1884 if (print_readably)
1885 {
1886 if (!invokers)
1887 fprintf (rl_outstream, "# %s (not bound)\n", name);
1888 else
1889 {
1890 register int j;
1891
1892 for (j = 0; invokers[j]; j++)
1893 {
1894 fprintf (rl_outstream, "\"%s\": %s\n",
1895 invokers[j], name);
1896 free (invokers[j]);
1897 }
1898
1899 free (invokers);
1900 }
1901 }
1902 else
1903 {
1904 if (!invokers)
1905 fprintf (rl_outstream, "%s is not bound to any keys\n",
1906 name);
1907 else
1908 {
1909 register int j;
1910
1911 fprintf (rl_outstream, "%s can be found on ", name);
1912
1913 for (j = 0; invokers[j] && j < 5; j++)
1914 {
1915 fprintf (rl_outstream, "\"%s\"%s", invokers[j],
1916 invokers[j + 1] ? ", " : ".\n");
1917 }
1918
1919 if (j == 5 && invokers[j])
1920 fprintf (rl_outstream, "...\n");
1921
1922 for (j = 0; invokers[j]; j++)
1923 free (invokers[j]);
1924
1925 free (invokers);
1926 }
1927 }
1928 }
1929}
1930
ccc6cda3
JA
1931/* Print all of the current functions and their bindings to
1932 rl_outstream. If an explicit argument is given, then print
1933 the output in such a way that it can be read back in. */
1934int
1935rl_dump_functions (count, key)
1936 int count, key;
1937{
d166f048
JA
1938 if (rl_dispatching)
1939 fprintf (rl_outstream, "\r\n");
ccc6cda3
JA
1940 rl_function_dumper (rl_explicit_arg);
1941 rl_on_new_line ();
1942 return (0);
1943}
1944
1945static void
1946_rl_macro_dumper_internal (print_readably, map, prefix)
1947 int print_readably;
1948 Keymap map;
1949 char *prefix;
1950{
1951 register int key;
1952 char *keyname, *out;
1953 int prefix_len;
1954
1955 for (key = 0; key < KEYMAP_SIZE; key++)
1956 {
1957 switch (map[key].type)
1958 {
1959 case ISMACR:
1960 keyname = _rl_get_keyname (key);
d166f048 1961 out = _rl_untranslate_macro_value ((char *)map[key].function);
7117c2d2 1962
ccc6cda3
JA
1963 if (print_readably)
1964 fprintf (rl_outstream, "\"%s%s\": \"%s\"\n", prefix ? prefix : "",
1965 keyname,
1966 out ? out : "");
1967 else
1968 fprintf (rl_outstream, "%s%s outputs %s\n", prefix ? prefix : "",
1969 keyname,
1970 out ? out : "");
1971 free (keyname);
d166f048 1972 free (out);
ccc6cda3
JA
1973 break;
1974 case ISFUNC:
1975 break;
1976 case ISKMAP:
1977 prefix_len = prefix ? strlen (prefix) : 0;
1978 if (key == ESC)
1979 {
f73dda09 1980 keyname = (char *)xmalloc (3 + prefix_len);
ccc6cda3
JA
1981 if (prefix)
1982 strcpy (keyname, prefix);
1983 keyname[prefix_len] = '\\';
1984 keyname[prefix_len + 1] = 'e';
1985 keyname[prefix_len + 2] = '\0';
1986 }
1987 else
1988 {
1989 keyname = _rl_get_keyname (key);
1990 if (prefix)
1991 {
f73dda09 1992 out = (char *)xmalloc (strlen (keyname) + prefix_len + 1);
ccc6cda3
JA
1993 strcpy (out, prefix);
1994 strcpy (out + prefix_len, keyname);
1995 free (keyname);
1996 keyname = out;
1997 }
1998 }
1999
2000 _rl_macro_dumper_internal (print_readably, FUNCTION_TO_KEYMAP (map, key), keyname);
2001 free (keyname);
2002 break;
2003 }
2004 }
2005}
2006
2007void
2008rl_macro_dumper (print_readably)
2009 int print_readably;
2010{
2011 _rl_macro_dumper_internal (print_readably, _rl_keymap, (char *)NULL);
2012}
2013
2014int
2015rl_dump_macros (count, key)
2016 int count, key;
2017{
d166f048
JA
2018 if (rl_dispatching)
2019 fprintf (rl_outstream, "\r\n");
ccc6cda3
JA
2020 rl_macro_dumper (rl_explicit_arg);
2021 rl_on_new_line ();
2022 return (0);
2023}
2024
2025void
2026rl_variable_dumper (print_readably)
2027 int print_readably;
2028{
2029 int i;
28ef6c31 2030 const char *kname;
ccc6cda3
JA
2031
2032 for (i = 0; boolean_varlist[i].name; i++)
2033 {
2034 if (print_readably)
2035 fprintf (rl_outstream, "set %s %s\n", boolean_varlist[i].name,
2036 *boolean_varlist[i].value ? "on" : "off");
2037 else
2038 fprintf (rl_outstream, "%s is set to `%s'\n", boolean_varlist[i].name,
2039 *boolean_varlist[i].value ? "on" : "off");
2040 }
2041
2042 /* bell-style */
2043 switch (_rl_bell_preference)
2044 {
cce855bc
JA
2045 case NO_BELL:
2046 kname = "none"; break;
2047 case VISIBLE_BELL:
2048 kname = "visible"; break;
ccc6cda3 2049 case AUDIBLE_BELL:
cce855bc
JA
2050 default:
2051 kname = "audible"; break;
ccc6cda3
JA
2052 }
2053 if (print_readably)
2054 fprintf (rl_outstream, "set bell-style %s\n", kname);
2055 else
2056 fprintf (rl_outstream, "bell-style is set to `%s'\n", kname);
2057
2058 /* comment-begin */
2059 if (print_readably)
2060 fprintf (rl_outstream, "set comment-begin %s\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
2061 else
7117c2d2 2062 fprintf (rl_outstream, "comment-begin is set to `%s'\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
ccc6cda3
JA
2063
2064 /* completion-query-items */
2065 if (print_readably)
2066 fprintf (rl_outstream, "set completion-query-items %d\n", rl_completion_query_items);
2067 else
2068 fprintf (rl_outstream, "completion-query-items is set to `%d'\n", rl_completion_query_items);
2069
2070 /* editing-mode */
2071 if (print_readably)
2072 fprintf (rl_outstream, "set editing-mode %s\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi");
2073 else
2074 fprintf (rl_outstream, "editing-mode is set to `%s'\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi");
2075
b72432fd
JA
2076 /* isearch-terminators */
2077 if (_rl_isearch_terminators)
2078 {
2079 char *disp;
2080
2081 disp = _rl_untranslate_macro_value (_rl_isearch_terminators);
2082
2083 if (print_readably)
2084 fprintf (rl_outstream, "set isearch-terminators \"%s\"\n", disp);
2085 else
2086 fprintf (rl_outstream, "isearch-terminators is set to \"%s\"\n", disp);
2087
2088 free (disp);
2089 }
7117c2d2
JA
2090
2091 /* keymap */
2092 kname = rl_get_keymap_name (_rl_keymap);
2093 if (kname == 0)
2094 kname = rl_get_keymap_name_from_edit_mode ();
2095 if (print_readably)
2096 fprintf (rl_outstream, "set keymap %s\n", kname ? kname : "none");
2097 else
2098 fprintf (rl_outstream, "keymap is set to `%s'\n", kname ? kname : "none");
ccc6cda3
JA
2099}
2100
2101/* Print all of the current variables and their values to
2102 rl_outstream. If an explicit argument is given, then print
2103 the output in such a way that it can be read back in. */
2104int
2105rl_dump_variables (count, key)
2106 int count, key;
2107{
d166f048
JA
2108 if (rl_dispatching)
2109 fprintf (rl_outstream, "\r\n");
ccc6cda3
JA
2110 rl_variable_dumper (rl_explicit_arg);
2111 rl_on_new_line ();
2112 return (0);
2113}
2114
7117c2d2
JA
2115/* Bind key sequence KEYSEQ to DEFAULT_FUNC if KEYSEQ is unbound. Right
2116 now, this is always used to attempt to bind the arrow keys, hence the
2117 check for rl_vi_movement_mode. */
726f6388
JA
2118void
2119_rl_bind_if_unbound (keyseq, default_func)
28ef6c31
JA
2120 const char *keyseq;
2121 rl_command_func_t *default_func;
726f6388 2122{
28ef6c31 2123 rl_command_func_t *func;
726f6388
JA
2124
2125 if (keyseq)
2126 {
2127 func = rl_function_of_keyseq (keyseq, _rl_keymap, (int *)NULL);
7117c2d2
JA
2128#if defined (VI_MODE)
2129 if (!func || func == rl_do_lowercase_version || func == rl_vi_movement_mode)
2130#else
726f6388 2131 if (!func || func == rl_do_lowercase_version)
7117c2d2 2132#endif
726f6388
JA
2133 rl_set_key (keyseq, default_func, _rl_keymap);
2134 }
2135}
2136
726f6388
JA
2137/* Return non-zero if any members of ARRAY are a substring in STRING. */
2138static int
2139substring_member_of_array (string, array)
28ef6c31
JA
2140 char *string;
2141 const char **array;
726f6388
JA
2142{
2143 while (*array)
2144 {
ccc6cda3 2145 if (_rl_strindex (string, *array))
726f6388
JA
2146 return (1);
2147 array++;
2148 }
2149 return (0);
2150}