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