| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: readline.c,v 1.172 2022/02/08 15:05:10 christos Exp $ */ | | 1 | /* $NetBSD: readline.c,v 1.173 2022/02/19 17:45:02 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jaromir Dolecek. | | 8 | * by Jaromir Dolecek. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include "config.h" | | 32 | #include "config.h" |
33 | #if !defined(lint) && !defined(SCCSID) | | 33 | #if !defined(lint) && !defined(SCCSID) |
34 | __RCSID("$NetBSD: readline.c,v 1.172 2022/02/08 15:05:10 christos Exp $"); | | 34 | __RCSID("$NetBSD: readline.c,v 1.173 2022/02/19 17:45:02 christos Exp $"); |
35 | #endif /* not lint && not SCCSID */ | | 35 | #endif /* not lint && not SCCSID */ |
36 | | | 36 | |
37 | #include <sys/types.h> | | 37 | #include <sys/types.h> |
38 | #include <sys/stat.h> | | 38 | #include <sys/stat.h> |
39 | #include <ctype.h> | | 39 | #include <ctype.h> |
40 | #include <dirent.h> | | 40 | #include <dirent.h> |
41 | #include <errno.h> | | 41 | #include <errno.h> |
42 | #include <fcntl.h> | | 42 | #include <fcntl.h> |
43 | #include <limits.h> | | 43 | #include <limits.h> |
44 | #include <pwd.h> | | 44 | #include <pwd.h> |
45 | #include <setjmp.h> | | 45 | #include <setjmp.h> |
46 | #include <stdarg.h> | | 46 | #include <stdarg.h> |
47 | #include <stdint.h> | | 47 | #include <stdint.h> |
| @@ -103,37 +103,37 @@ char history_subst_char = '^'; | | | @@ -103,37 +103,37 @@ char history_subst_char = '^'; |
103 | char *history_no_expand_chars = expand_chars; | | 103 | char *history_no_expand_chars = expand_chars; |
104 | Function *history_inhibit_expansion_function = NULL; | | 104 | Function *history_inhibit_expansion_function = NULL; |
105 | char *history_arg_extract(int start, int end, const char *str); | | 105 | char *history_arg_extract(int start, int end, const char *str); |
106 | | | 106 | |
107 | int rl_inhibit_completion = 0; | | 107 | int rl_inhibit_completion = 0; |
108 | int rl_attempted_completion_over = 0; | | 108 | int rl_attempted_completion_over = 0; |
109 | const char *rl_basic_word_break_characters = break_chars; | | 109 | const char *rl_basic_word_break_characters = break_chars; |
110 | char *rl_completer_word_break_characters = NULL; | | 110 | char *rl_completer_word_break_characters = NULL; |
111 | const char *rl_completer_quote_characters = NULL; | | 111 | const char *rl_completer_quote_characters = NULL; |
112 | const char *rl_basic_quote_characters = "\"'"; | | 112 | const char *rl_basic_quote_characters = "\"'"; |
113 | rl_compentry_func_t *rl_completion_entry_function = NULL; | | 113 | rl_compentry_func_t *rl_completion_entry_function = NULL; |
114 | char *(*rl_completion_word_break_hook)(void) = NULL; | | 114 | char *(*rl_completion_word_break_hook)(void) = NULL; |
115 | rl_completion_func_t *rl_attempted_completion_function = NULL; | | 115 | rl_completion_func_t *rl_attempted_completion_function = NULL; |
116 | Function *rl_pre_input_hook = NULL; | | 116 | rl_hook_func_t *rl_pre_input_hook = NULL; |
117 | Function *rl_startup1_hook = NULL; | | 117 | rl_hook_func_t *rl_startup1_hook = NULL; |
118 | int (*rl_getc_function)(FILE *) = NULL; | | 118 | int (*rl_getc_function)(FILE *) = NULL; |
119 | char *rl_terminal_name = NULL; | | 119 | char *rl_terminal_name = NULL; |
120 | int rl_already_prompted = 0; | | 120 | int rl_already_prompted = 0; |
121 | int rl_filename_completion_desired = 0; | | 121 | int rl_filename_completion_desired = 0; |
122 | int rl_ignore_completion_duplicates = 0; | | 122 | int rl_ignore_completion_duplicates = 0; |
123 | int readline_echoing_p = 1; | | 123 | int readline_echoing_p = 1; |
124 | int _rl_print_completions_horizontally = 0; | | 124 | int _rl_print_completions_horizontally = 0; |
125 | VFunction *rl_redisplay_function = NULL; | | 125 | VFunction *rl_redisplay_function = NULL; |
126 | Function *rl_startup_hook = NULL; | | 126 | rl_hook_func_t *rl_startup_hook = NULL; |
127 | VFunction *rl_completion_display_matches_hook = NULL; | | 127 | VFunction *rl_completion_display_matches_hook = NULL; |
128 | VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal; | | 128 | VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal; |
129 | VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal; | | 129 | VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal; |
130 | KEYMAP_ENTRY_ARRAY emacs_meta_keymap; | | 130 | KEYMAP_ENTRY_ARRAY emacs_meta_keymap; |
131 | unsigned long rl_readline_state = RL_STATE_NONE; | | 131 | unsigned long rl_readline_state = RL_STATE_NONE; |
132 | int _rl_complete_mark_directories; | | 132 | int _rl_complete_mark_directories; |
133 | rl_icppfunc_t *rl_directory_completion_hook; | | 133 | rl_icppfunc_t *rl_directory_completion_hook; |
134 | int rl_completion_suppress_append; | | 134 | int rl_completion_suppress_append; |
135 | int rl_sort_completion_matches; | | 135 | int rl_sort_completion_matches; |
136 | int _rl_completion_prefix_display_length; | | 136 | int _rl_completion_prefix_display_length; |
137 | int _rl_echoing_p; | | 137 | int _rl_echoing_p; |
138 | int history_max_entries; | | 138 | int history_max_entries; |
139 | char *rl_display_prompt; | | 139 | char *rl_display_prompt; |
| @@ -435,42 +435,42 @@ rl_initialize(void) | | | @@ -435,42 +435,42 @@ rl_initialize(void) |
435 | char * | | 435 | char * |
436 | readline(const char *p) | | 436 | readline(const char *p) |
437 | { | | 437 | { |
438 | HistEvent ev; | | 438 | HistEvent ev; |
439 | const char * volatile prompt = p; | | 439 | const char * volatile prompt = p; |
440 | int count; | | 440 | int count; |
441 | const char *ret; | | 441 | const char *ret; |
442 | char *buf; | | 442 | char *buf; |
443 | static int used_event_hook; | | 443 | static int used_event_hook; |
444 | | | 444 | |
445 | if (e == NULL || h == NULL) | | 445 | if (e == NULL || h == NULL) |
446 | rl_initialize(); | | 446 | rl_initialize(); |
447 | if (rl_startup_hook) { | | 447 | if (rl_startup_hook) { |
448 | (*rl_startup_hook)(NULL, 0); | | 448 | (*rl_startup_hook)(); |
449 | } | | 449 | } |
450 | tty_init(e); | | 450 | tty_init(e); |
451 | | | 451 | |
452 | | | 452 | |
453 | rl_done = 0; | | 453 | rl_done = 0; |
454 | | | 454 | |
455 | (void)setjmp(topbuf); | | 455 | (void)setjmp(topbuf); |
456 | buf = NULL; | | 456 | buf = NULL; |
457 | | | 457 | |
458 | /* update prompt accordingly to what has been passed */ | | 458 | /* update prompt accordingly to what has been passed */ |
459 | if (rl_set_prompt(prompt) == -1) | | 459 | if (rl_set_prompt(prompt) == -1) |
460 | goto out; | | 460 | goto out; |
461 | | | 461 | |
462 | if (rl_pre_input_hook) | | 462 | if (rl_pre_input_hook) |
463 | (*rl_pre_input_hook)(NULL, 0); | | 463 | (*rl_pre_input_hook)(); |
464 | | | 464 | |
465 | if (rl_event_hook && !(e->el_flags & NO_TTY)) { | | 465 | if (rl_event_hook && !(e->el_flags & NO_TTY)) { |
466 | el_set(e, EL_GETCFN, _rl_event_read_char); | | 466 | el_set(e, EL_GETCFN, _rl_event_read_char); |
467 | used_event_hook = 1; | | 467 | used_event_hook = 1; |
468 | } | | 468 | } |
469 | | | 469 | |
470 | if (!rl_event_hook && used_event_hook) { | | 470 | if (!rl_event_hook && used_event_hook) { |
471 | el_set(e, EL_GETCFN, EL_BUILTIN_GETCFN); | | 471 | el_set(e, EL_GETCFN, EL_BUILTIN_GETCFN); |
472 | used_event_hook = 0; | | 472 | used_event_hook = 0; |
473 | } | | 473 | } |
474 | | | 474 | |
475 | rl_already_prompted = 0; | | 475 | rl_already_prompted = 0; |
476 | | | 476 | |