Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/readline/misc.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* misc.c -- miscellaneous bindable readline functions. */ | - | ||||||||||||||||||
2 | - | |||||||||||||||||||
3 | /* Copyright (C) 1987-2017 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 (HAVE_CONFIG_H) | - | ||||||||||||||||||
25 | # include <config.h> | - | ||||||||||||||||||
26 | #endif | - | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||
29 | # include <unistd.h> | - | ||||||||||||||||||
30 | #endif /* HAVE_UNISTD_H */ | - | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | #if defined (HAVE_STDLIB_H) | - | ||||||||||||||||||
33 | # include <stdlib.h> | - | ||||||||||||||||||
34 | #else | - | ||||||||||||||||||
35 | # include "ansi_stdlib.h" | - | ||||||||||||||||||
36 | #endif /* HAVE_STDLIB_H */ | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | #if defined (HAVE_LOCALE_H) | - | ||||||||||||||||||
39 | # include <locale.h> | - | ||||||||||||||||||
40 | #endif | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #include <stdio.h> | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | /* System-specific feature definitions and include files. */ | - | ||||||||||||||||||
45 | #include "rldefs.h" | - | ||||||||||||||||||
46 | #include "rlmbutil.h" | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | /* Some standard library routines. */ | - | ||||||||||||||||||
49 | #include "readline.h" | - | ||||||||||||||||||
50 | #include "history.h" | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | #include "rlprivate.h" | - | ||||||||||||||||||
53 | #include "rlshell.h" | - | ||||||||||||||||||
54 | #include "xmalloc.h" | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | static int rl_digit_loop PARAMS((void)); | - | ||||||||||||||||||
57 | static void _rl_history_set_point PARAMS((void)); | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | /* Forward declarations used in this file */ | - | ||||||||||||||||||
60 | void _rl_free_history_entry PARAMS((HIST_ENTRY *)); | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | /* If non-zero, rl_get_previous_history and rl_get_next_history attempt | - | ||||||||||||||||||
63 | to preserve the value of rl_point from line to line. */ | - | ||||||||||||||||||
64 | int _rl_history_preserve_point = 0; | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | _rl_arg_cxt _rl_argcxt; | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | /* Saved target point for when _rl_history_preserve_point is set. Special | - | ||||||||||||||||||
69 | value of -1 means that point is at the end of the line. */ | - | ||||||||||||||||||
70 | int _rl_history_saved_point = -1; | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | /* **************************************************************** */ | - | ||||||||||||||||||
73 | /* */ | - | ||||||||||||||||||
74 | /* Numeric Arguments */ | - | ||||||||||||||||||
75 | /* */ | - | ||||||||||||||||||
76 | /* **************************************************************** */ | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | int | - | ||||||||||||||||||
79 | _rl_arg_overflow (void) | - | ||||||||||||||||||
80 | { | - | ||||||||||||||||||
81 | if (rl_numeric_arg > 1000000)
| 0 | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | _rl_argcxt = 0; | - | ||||||||||||||||||
84 | rl_explicit_arg = rl_numeric_arg = 0; | - | ||||||||||||||||||
85 | rl_ding (); | - | ||||||||||||||||||
86 | rl_restore_prompt (); | - | ||||||||||||||||||
87 | rl_clear_message (); | - | ||||||||||||||||||
88 | RL_UNSETSTATE(RL_STATE_NUMERICARG); | - | ||||||||||||||||||
89 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
90 | } | - | ||||||||||||||||||
91 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
92 | } | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | void | - | ||||||||||||||||||
95 | _rl_arg_init (void) | - | ||||||||||||||||||
96 | { | - | ||||||||||||||||||
97 | rl_save_prompt (); | - | ||||||||||||||||||
98 | _rl_argcxt = 0; | - | ||||||||||||||||||
99 | RL_SETSTATE(RL_STATE_NUMERICARG); | - | ||||||||||||||||||
100 | } never executed: end of block | 0 | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | int | - | ||||||||||||||||||
103 | _rl_arg_getchar (void) | - | ||||||||||||||||||
104 | { | - | ||||||||||||||||||
105 | int c; | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); | - | ||||||||||||||||||
108 | RL_SETSTATE(RL_STATE_MOREINPUT); | - | ||||||||||||||||||
109 | c = rl_read_key (); | - | ||||||||||||||||||
110 | RL_UNSETSTATE(RL_STATE_MOREINPUT); | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | return c; never executed: return c; | 0 | ||||||||||||||||||
113 | } | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | /* Process C as part of the current numeric argument. Return -1 if the | - | ||||||||||||||||||
116 | argument should be aborted, 0 if we should not read any more chars, and | - | ||||||||||||||||||
117 | 1 if we should continue to read chars. */ | - | ||||||||||||||||||
118 | int | - | ||||||||||||||||||
119 | _rl_arg_dispatch (_rl_arg_cxt cxt, int c) | - | ||||||||||||||||||
120 | { | - | ||||||||||||||||||
121 | int key, r; | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | key = c; | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | /* If we see a key bound to `universal-argument' after seeing digits, | - | ||||||||||||||||||
126 | it ends the argument but is otherwise ignored. */ | - | ||||||||||||||||||
127 | if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument)
| 0 | ||||||||||||||||||
128 | { | - | ||||||||||||||||||
129 | if ((cxt & NUM_SAWDIGITS) == 0)
| 0 | ||||||||||||||||||
130 | { | - | ||||||||||||||||||
131 | rl_numeric_arg *= 4; | - | ||||||||||||||||||
132 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
133 | } | - | ||||||||||||||||||
134 | else if (RL_ISSTATE (RL_STATE_CALLBACK))
| 0 | ||||||||||||||||||
135 | { | - | ||||||||||||||||||
136 | _rl_argcxt |= NUM_READONE; | - | ||||||||||||||||||
137 | return 0; /* XXX */ never executed: return 0; | 0 | ||||||||||||||||||
138 | } | - | ||||||||||||||||||
139 | else | - | ||||||||||||||||||
140 | { | - | ||||||||||||||||||
141 | RL_SETSTATE(RL_STATE_MOREINPUT); | - | ||||||||||||||||||
142 | key = rl_read_key (); | - | ||||||||||||||||||
143 | RL_UNSETSTATE(RL_STATE_MOREINPUT); | - | ||||||||||||||||||
144 | rl_restore_prompt (); | - | ||||||||||||||||||
145 | rl_clear_message (); | - | ||||||||||||||||||
146 | RL_UNSETSTATE(RL_STATE_NUMERICARG); | - | ||||||||||||||||||
147 | if (key < 0)
| 0 | ||||||||||||||||||
148 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
149 | return (_rl_dispatch (key, _rl_keymap)); never executed: return (_rl_dispatch (key, _rl_keymap)); | 0 | ||||||||||||||||||
150 | } | - | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | c = UNMETA (c); | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | if (_rl_digit_p (c))
| 0 | ||||||||||||||||||
156 | { | - | ||||||||||||||||||
157 | r = _rl_digit_value (c); | - | ||||||||||||||||||
158 | rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + r : r;
| 0 | ||||||||||||||||||
159 | rl_explicit_arg = 1; | - | ||||||||||||||||||
160 | _rl_argcxt |= NUM_SAWDIGITS; | - | ||||||||||||||||||
161 | } never executed: end of block | 0 | ||||||||||||||||||
162 | else if (c == '-' && rl_explicit_arg == 0)
| 0 | ||||||||||||||||||
163 | { | - | ||||||||||||||||||
164 | rl_numeric_arg = 1; | - | ||||||||||||||||||
165 | _rl_argcxt |= NUM_SAWMINUS; | - | ||||||||||||||||||
166 | rl_arg_sign = -1; | - | ||||||||||||||||||
167 | } never executed: end of block | 0 | ||||||||||||||||||
168 | else | - | ||||||||||||||||||
169 | { | - | ||||||||||||||||||
170 | /* Make M-- command equivalent to M--1 command. */ | - | ||||||||||||||||||
171 | if ((_rl_argcxt & NUM_SAWMINUS) && rl_numeric_arg == 1 && rl_explicit_arg == 0)
| 0 | ||||||||||||||||||
172 | rl_explicit_arg = 1; never executed: rl_explicit_arg = 1; | 0 | ||||||||||||||||||
173 | rl_restore_prompt (); | - | ||||||||||||||||||
174 | rl_clear_message (); | - | ||||||||||||||||||
175 | RL_UNSETSTATE(RL_STATE_NUMERICARG); | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | r = _rl_dispatch (key, _rl_keymap); | - | ||||||||||||||||||
178 | if (RL_ISSTATE (RL_STATE_CALLBACK))
| 0 | ||||||||||||||||||
179 | { | - | ||||||||||||||||||
180 | /* At worst, this will cause an extra redisplay. Otherwise, | - | ||||||||||||||||||
181 | we have to wait until the next character comes in. */ | - | ||||||||||||||||||
182 | if (rl_done == 0)
| 0 | ||||||||||||||||||
183 | (*rl_redisplay_function) (); never executed: (*rl_redisplay_function) (); | 0 | ||||||||||||||||||
184 | r = 0; | - | ||||||||||||||||||
185 | } never executed: end of block | 0 | ||||||||||||||||||
186 | return r; never executed: return r; | 0 | ||||||||||||||||||
187 | } | - | ||||||||||||||||||
188 | - | |||||||||||||||||||
189 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
190 | } | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | /* Handle C-u style numeric args, as well as M--, and M-digits. */ | - | ||||||||||||||||||
193 | static int | - | ||||||||||||||||||
194 | rl_digit_loop (void) | - | ||||||||||||||||||
195 | { | - | ||||||||||||||||||
196 | int c, r; | - | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | while (1) | - | ||||||||||||||||||
199 | { | - | ||||||||||||||||||
200 | if (_rl_arg_overflow ())
| 0 | ||||||||||||||||||
201 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | c = _rl_arg_getchar (); | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | if (c < 0)
| 0 | ||||||||||||||||||
206 | { | - | ||||||||||||||||||
207 | _rl_abort_internal (); | - | ||||||||||||||||||
208 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
209 | } | - | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | r = _rl_arg_dispatch (_rl_argcxt, c); | - | ||||||||||||||||||
212 | if (r <= 0 || (RL_ISSTATE (RL_STATE_NUMERICARG) == 0))
| 0 | ||||||||||||||||||
213 | break; never executed: break; | 0 | ||||||||||||||||||
214 | } never executed: end of block | 0 | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | return r; never executed: return r; | 0 | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | /* Create a default argument. */ | - | ||||||||||||||||||
220 | void | - | ||||||||||||||||||
221 | _rl_reset_argument (void) | - | ||||||||||||||||||
222 | { | - | ||||||||||||||||||
223 | rl_numeric_arg = rl_arg_sign = 1; | - | ||||||||||||||||||
224 | rl_explicit_arg = 0; | - | ||||||||||||||||||
225 | _rl_argcxt = 0; | - | ||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | /* Start a numeric argument with initial value KEY */ | - | ||||||||||||||||||
229 | int | - | ||||||||||||||||||
230 | rl_digit_argument (int ignore, int key) | - | ||||||||||||||||||
231 | { | - | ||||||||||||||||||
232 | _rl_arg_init (); | - | ||||||||||||||||||
233 | if (RL_ISSTATE (RL_STATE_CALLBACK))
| 0 | ||||||||||||||||||
234 | { | - | ||||||||||||||||||
235 | _rl_arg_dispatch (_rl_argcxt, key); | - | ||||||||||||||||||
236 | rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); | - | ||||||||||||||||||
237 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | else | - | ||||||||||||||||||
240 | { | - | ||||||||||||||||||
241 | rl_execute_next (key); | - | ||||||||||||||||||
242 | return (rl_digit_loop ()); never executed: return (rl_digit_loop ()); | 0 | ||||||||||||||||||
243 | } | - | ||||||||||||||||||
244 | } | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | /* C-u, universal argument. Multiply the current argument by 4. | - | ||||||||||||||||||
247 | Read a key. If the key has nothing to do with arguments, then | - | ||||||||||||||||||
248 | dispatch on it. If the key is the abort character then abort. */ | - | ||||||||||||||||||
249 | int | - | ||||||||||||||||||
250 | rl_universal_argument (int count, int key) | - | ||||||||||||||||||
251 | { | - | ||||||||||||||||||
252 | _rl_arg_init (); | - | ||||||||||||||||||
253 | rl_numeric_arg *= 4; | - | ||||||||||||||||||
254 | - | |||||||||||||||||||
255 | return (RL_ISSTATE (RL_STATE_CALLBACK) ? 0 : rl_digit_loop ()); never executed: return ((rl_readline_state & (0x0080000)) ? 0 : rl_digit_loop ()); | 0 | ||||||||||||||||||
256 | } | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | int | - | ||||||||||||||||||
259 | _rl_arg_callback (_rl_arg_cxt cxt) | - | ||||||||||||||||||
260 | { | - | ||||||||||||||||||
261 | int c, r; | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | c = _rl_arg_getchar (); | - | ||||||||||||||||||
264 | if (c < 0)
| 0 | ||||||||||||||||||
265 | return (1); /* EOF */ never executed: return (1); | 0 | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | if (_rl_argcxt & NUM_READONE)
| 0 | ||||||||||||||||||
268 | { | - | ||||||||||||||||||
269 | _rl_argcxt &= ~NUM_READONE; | - | ||||||||||||||||||
270 | rl_restore_prompt (); | - | ||||||||||||||||||
271 | rl_clear_message (); | - | ||||||||||||||||||
272 | RL_UNSETSTATE(RL_STATE_NUMERICARG); | - | ||||||||||||||||||
273 | rl_execute_next (c); | - | ||||||||||||||||||
274 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
275 | } | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | r = _rl_arg_dispatch (cxt, c); | - | ||||||||||||||||||
278 | if (r > 0)
| 0 | ||||||||||||||||||
279 | rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); never executed: rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg); | 0 | ||||||||||||||||||
280 | return (r != 1); never executed: return (r != 1); | 0 | ||||||||||||||||||
281 | } | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | /* What to do when you abort reading an argument. */ | - | ||||||||||||||||||
284 | int | - | ||||||||||||||||||
285 | rl_discard_argument (void) | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | rl_ding (); | - | ||||||||||||||||||
288 | rl_clear_message (); | - | ||||||||||||||||||
289 | _rl_reset_argument (); | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
292 | } | - | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | /* **************************************************************** */ | - | ||||||||||||||||||
295 | /* */ | - | ||||||||||||||||||
296 | /* History Utilities */ | - | ||||||||||||||||||
297 | /* */ | - | ||||||||||||||||||
298 | /* **************************************************************** */ | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | /* We already have a history library, and that is what we use to control | - | ||||||||||||||||||
301 | the history features of readline. This is our local interface to | - | ||||||||||||||||||
302 | the history mechanism. */ | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | /* While we are editing the history, this is the saved | - | ||||||||||||||||||
305 | version of the original line. */ | - | ||||||||||||||||||
306 | HIST_ENTRY *_rl_saved_line_for_history = (HIST_ENTRY *)NULL; | - | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | /* Set the history pointer back to the last entry in the history. */ | - | ||||||||||||||||||
309 | void | - | ||||||||||||||||||
310 | _rl_start_using_history (void) | - | ||||||||||||||||||
311 | { | - | ||||||||||||||||||
312 | using_history (); | - | ||||||||||||||||||
313 | if (_rl_saved_line_for_history)
| 0 | ||||||||||||||||||
314 | _rl_free_history_entry (_rl_saved_line_for_history); never executed: _rl_free_history_entry (_rl_saved_line_for_history); | 0 | ||||||||||||||||||
315 | - | |||||||||||||||||||
316 | _rl_saved_line_for_history = (HIST_ENTRY *)NULL; | - | ||||||||||||||||||
317 | } never executed: end of block | 0 | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | /* Free the contents (and containing structure) of a HIST_ENTRY. */ | - | ||||||||||||||||||
320 | void | - | ||||||||||||||||||
321 | _rl_free_history_entry (HIST_ENTRY *entry) | - | ||||||||||||||||||
322 | { | - | ||||||||||||||||||
323 | if (entry == 0)
| 0 | ||||||||||||||||||
324 | return; never executed: return; | 0 | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | FREE (entry->line); never executed: free (entry->line);
| 0 | ||||||||||||||||||
327 | FREE (entry->timestamp); never executed: free (entry->timestamp);
| 0 | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | xfree (entry); | - | ||||||||||||||||||
330 | } never executed: end of block | 0 | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | /* Perhaps put back the current line if it has changed. */ | - | ||||||||||||||||||
333 | int | - | ||||||||||||||||||
334 | rl_maybe_replace_line (void) | - | ||||||||||||||||||
335 | { | - | ||||||||||||||||||
336 | HIST_ENTRY *temp; | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | temp = current_history (); | - | ||||||||||||||||||
339 | /* If the current line has changed, save the changes. */ | - | ||||||||||||||||||
340 | if (temp && ((UNDO_LIST *)(temp->data) != rl_undo_list))
| 0 | ||||||||||||||||||
341 | { | - | ||||||||||||||||||
342 | temp = replace_history_entry (where_history (), rl_line_buffer, (histdata_t)rl_undo_list); | - | ||||||||||||||||||
343 | xfree (temp->line); | - | ||||||||||||||||||
344 | FREE (temp->timestamp); never executed: free (temp->timestamp);
| 0 | ||||||||||||||||||
345 | xfree (temp); | - | ||||||||||||||||||
346 | } never executed: end of block | 0 | ||||||||||||||||||
347 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
348 | } | - | ||||||||||||||||||
349 | - | |||||||||||||||||||
350 | /* Restore the _rl_saved_line_for_history if there is one. */ | - | ||||||||||||||||||
351 | int | - | ||||||||||||||||||
352 | rl_maybe_unsave_line (void) | - | ||||||||||||||||||
353 | { | - | ||||||||||||||||||
354 | if (_rl_saved_line_for_history)
| 0 | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | /* Can't call with `1' because rl_undo_list might point to an undo | - | ||||||||||||||||||
357 | list from a history entry, as in rl_replace_from_history() below. */ | - | ||||||||||||||||||
358 | rl_replace_line (_rl_saved_line_for_history->line, 0); | - | ||||||||||||||||||
359 | rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data; | - | ||||||||||||||||||
360 | _rl_free_history_entry (_rl_saved_line_for_history); | - | ||||||||||||||||||
361 | _rl_saved_line_for_history = (HIST_ENTRY *)NULL; | - | ||||||||||||||||||
362 | rl_point = rl_end; /* rl_replace_line sets rl_end */ | - | ||||||||||||||||||
363 | } never executed: end of block | 0 | ||||||||||||||||||
364 | else | - | ||||||||||||||||||
365 | rl_ding (); never executed: rl_ding (); | 0 | ||||||||||||||||||
366 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
367 | } | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | /* Save the current line in _rl_saved_line_for_history. */ | - | ||||||||||||||||||
370 | int | - | ||||||||||||||||||
371 | rl_maybe_save_line (void) | - | ||||||||||||||||||
372 | { | - | ||||||||||||||||||
373 | if (_rl_saved_line_for_history == 0)
| 0 | ||||||||||||||||||
374 | { | - | ||||||||||||||||||
375 | _rl_saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); | - | ||||||||||||||||||
376 | _rl_saved_line_for_history->line = savestring (rl_line_buffer); | - | ||||||||||||||||||
377 | _rl_saved_line_for_history->timestamp = (char *)NULL; | - | ||||||||||||||||||
378 | _rl_saved_line_for_history->data = (char *)rl_undo_list; | - | ||||||||||||||||||
379 | } never executed: end of block | 0 | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
382 | } | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | int | - | ||||||||||||||||||
385 | _rl_free_saved_history_line (void) | - | ||||||||||||||||||
386 | { | - | ||||||||||||||||||
387 | if (_rl_saved_line_for_history)
| 0 | ||||||||||||||||||
388 | { | - | ||||||||||||||||||
389 | _rl_free_history_entry (_rl_saved_line_for_history); | - | ||||||||||||||||||
390 | _rl_saved_line_for_history = (HIST_ENTRY *)NULL; | - | ||||||||||||||||||
391 | } never executed: end of block | 0 | ||||||||||||||||||
392 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
393 | } | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | static void | - | ||||||||||||||||||
396 | _rl_history_set_point (void) | - | ||||||||||||||||||
397 | { | - | ||||||||||||||||||
398 | rl_point = (_rl_history_preserve_point && _rl_history_saved_point != -1)
| 0 | ||||||||||||||||||
399 | ? _rl_history_saved_point | - | ||||||||||||||||||
400 | : rl_end; | - | ||||||||||||||||||
401 | if (rl_point > rl_end)
| 0 | ||||||||||||||||||
402 | rl_point = rl_end; never executed: rl_point = rl_end; | 0 | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | #if defined (VI_MODE) | - | ||||||||||||||||||
405 | if (rl_editing_mode == vi_mode && _rl_keymap != vi_insertion_keymap)
| 0 | ||||||||||||||||||
406 | rl_point = 0; never executed: rl_point = 0; | 0 | ||||||||||||||||||
407 | #endif /* VI_MODE */ | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | if (rl_editing_mode == emacs_mode)
| 0 | ||||||||||||||||||
410 | rl_mark = (rl_point == rl_end ? 0 : rl_end); never executed: rl_mark = (rl_point == rl_end ? 0 : rl_end);
| 0 | ||||||||||||||||||
411 | } never executed: end of block | 0 | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | void | - | ||||||||||||||||||
414 | rl_replace_from_history (HIST_ENTRY *entry, int flags) | - | ||||||||||||||||||
415 | { | - | ||||||||||||||||||
416 | /* Can't call with `1' because rl_undo_list might point to an undo list | - | ||||||||||||||||||
417 | from a history entry, just like we're setting up here. */ | - | ||||||||||||||||||
418 | rl_replace_line (entry->line, 0); | - | ||||||||||||||||||
419 | rl_undo_list = (UNDO_LIST *)entry->data; | - | ||||||||||||||||||
420 | rl_point = rl_end; | - | ||||||||||||||||||
421 | rl_mark = 0; | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | #if defined (VI_MODE) | - | ||||||||||||||||||
424 | if (rl_editing_mode == vi_mode)
| 0 | ||||||||||||||||||
425 | { | - | ||||||||||||||||||
426 | rl_point = 0; | - | ||||||||||||||||||
427 | rl_mark = rl_end; | - | ||||||||||||||||||
428 | } never executed: end of block | 0 | ||||||||||||||||||
429 | #endif | - | ||||||||||||||||||
430 | } never executed: end of block | 0 | ||||||||||||||||||
431 | - | |||||||||||||||||||
432 | /* Process and free undo lists attached to each history entry prior to the | - | ||||||||||||||||||
433 | current entry, inclusive, reverting each line to its saved state. This | - | ||||||||||||||||||
434 | is destructive, and state about the current line is lost. This is not | - | ||||||||||||||||||
435 | intended to be called while actively editing, and the current line is | - | ||||||||||||||||||
436 | not assumed to have been added to the history list. */ | - | ||||||||||||||||||
437 | void | - | ||||||||||||||||||
438 | _rl_revert_all_lines (void) | - | ||||||||||||||||||
439 | { | - | ||||||||||||||||||
440 | int hpos; | - | ||||||||||||||||||
441 | HIST_ENTRY *entry; | - | ||||||||||||||||||
442 | UNDO_LIST *ul, *saved_undo_list; | - | ||||||||||||||||||
443 | char *lbuf; | - | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | lbuf = savestring (rl_line_buffer); | - | ||||||||||||||||||
446 | saved_undo_list = rl_undo_list; | - | ||||||||||||||||||
447 | hpos = where_history (); | - | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | entry = (hpos == history_length) ? previous_history () : current_history ();
| 0 | ||||||||||||||||||
450 | while (entry)
| 0 | ||||||||||||||||||
451 | { | - | ||||||||||||||||||
452 | if (ul = (UNDO_LIST *)entry->data)
| 0 | ||||||||||||||||||
453 | { | - | ||||||||||||||||||
454 | if (ul == saved_undo_list)
| 0 | ||||||||||||||||||
455 | saved_undo_list = 0; never executed: saved_undo_list = 0; | 0 | ||||||||||||||||||
456 | /* Set up rl_line_buffer and other variables from history entry */ | - | ||||||||||||||||||
457 | rl_replace_from_history (entry, 0); /* entry->line is now current */ | - | ||||||||||||||||||
458 | entry->data = 0; /* entry->data is now current undo list */ | - | ||||||||||||||||||
459 | /* Undo all changes to this history entry */ | - | ||||||||||||||||||
460 | while (rl_undo_list)
| 0 | ||||||||||||||||||
461 | rl_do_undo (); never executed: rl_do_undo (); | 0 | ||||||||||||||||||
462 | /* And copy the reverted line back to the history entry, preserving | - | ||||||||||||||||||
463 | the timestamp. */ | - | ||||||||||||||||||
464 | FREE (entry->line); never executed: free (entry->line);
| 0 | ||||||||||||||||||
465 | entry->line = savestring (rl_line_buffer); | - | ||||||||||||||||||
466 | } never executed: end of block | 0 | ||||||||||||||||||
467 | entry = previous_history (); | - | ||||||||||||||||||
468 | } never executed: end of block | 0 | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | /* Restore history state */ | - | ||||||||||||||||||
471 | rl_undo_list = saved_undo_list; /* may have been set to null */ | - | ||||||||||||||||||
472 | history_set_pos (hpos); | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | /* reset the line buffer */ | - | ||||||||||||||||||
475 | rl_replace_line (lbuf, 0); | - | ||||||||||||||||||
476 | _rl_set_the_line (); | - | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | /* and clean up */ | - | ||||||||||||||||||
479 | xfree (lbuf); | - | ||||||||||||||||||
480 | } never executed: end of block never executed: end of block | 0 | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | /* Free the history list, including private readline data and take care | - | ||||||||||||||||||
483 | of pointer aliases to history data. Resets rl_undo_list if it points | - | ||||||||||||||||||
484 | to an UNDO_LIST * saved as some history entry's data member. This | - | ||||||||||||||||||
485 | should not be called while editing is active. */ | - | ||||||||||||||||||
486 | void | - | ||||||||||||||||||
487 | rl_clear_history (void) | - | ||||||||||||||||||
488 | { | - | ||||||||||||||||||
489 | HIST_ENTRY **hlist, *hent; | - | ||||||||||||||||||
490 | register int i; | - | ||||||||||||||||||
491 | UNDO_LIST *ul, *saved_undo_list; | - | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | saved_undo_list = rl_undo_list; | - | ||||||||||||||||||
494 | hlist = history_list (); /* direct pointer, not copy */ | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | for (i = 0; i < history_length; i++)
| 0 | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | hent = hlist[i]; | - | ||||||||||||||||||
499 | if (ul = (UNDO_LIST *)hent->data)
| 0 | ||||||||||||||||||
500 | { | - | ||||||||||||||||||
501 | if (ul == saved_undo_list)
| 0 | ||||||||||||||||||
502 | saved_undo_list = 0; never executed: saved_undo_list = 0; | 0 | ||||||||||||||||||
503 | _rl_free_undo_list (ul); | - | ||||||||||||||||||
504 | hent->data = 0; | - | ||||||||||||||||||
505 | } never executed: end of block | 0 | ||||||||||||||||||
506 | _rl_free_history_entry (hent); | - | ||||||||||||||||||
507 | } never executed: end of block | 0 | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | history_offset = history_length = 0; | - | ||||||||||||||||||
510 | rl_undo_list = saved_undo_list; /* should be NULL */ | - | ||||||||||||||||||
511 | } never executed: end of block | 0 | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | /* **************************************************************** */ | - | ||||||||||||||||||
514 | /* */ | - | ||||||||||||||||||
515 | /* History Commands */ | - | ||||||||||||||||||
516 | /* */ | - | ||||||||||||||||||
517 | /* **************************************************************** */ | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | /* Meta-< goes to the start of the history. */ | - | ||||||||||||||||||
520 | int | - | ||||||||||||||||||
521 | rl_beginning_of_history (int count, int key) | - | ||||||||||||||||||
522 | { | - | ||||||||||||||||||
523 | return (rl_get_previous_history (1 + where_history (), key)); never executed: return (rl_get_previous_history (1 + where_history (), key)); | 0 | ||||||||||||||||||
524 | } | - | ||||||||||||||||||
525 | - | |||||||||||||||||||
526 | /* Meta-> goes to the end of the history. (The current line). */ | - | ||||||||||||||||||
527 | int | - | ||||||||||||||||||
528 | rl_end_of_history (int count, int key) | - | ||||||||||||||||||
529 | { | - | ||||||||||||||||||
530 | rl_maybe_replace_line (); | - | ||||||||||||||||||
531 | using_history (); | - | ||||||||||||||||||
532 | rl_maybe_unsave_line (); | - | ||||||||||||||||||
533 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
534 | } | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | /* Move down to the next history line. */ | - | ||||||||||||||||||
537 | int | - | ||||||||||||||||||
538 | rl_get_next_history (int count, int key) | - | ||||||||||||||||||
539 | { | - | ||||||||||||||||||
540 | HIST_ENTRY *temp; | - | ||||||||||||||||||
541 | - | |||||||||||||||||||
542 | if (count < 0)
| 0 | ||||||||||||||||||
543 | return (rl_get_previous_history (-count, key)); never executed: return (rl_get_previous_history (-count, key)); | 0 | ||||||||||||||||||
544 | - | |||||||||||||||||||
545 | if (count == 0)
| 0 | ||||||||||||||||||
546 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
547 | - | |||||||||||||||||||
548 | rl_maybe_replace_line (); | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | /* either not saved by rl_newline or at end of line, so set appropriately. */ | - | ||||||||||||||||||
551 | if (_rl_history_saved_point == -1 && (rl_point || rl_end))
| 0 | ||||||||||||||||||
552 | _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point; never executed: _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point;
| 0 | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | temp = (HIST_ENTRY *)NULL; | - | ||||||||||||||||||
555 | while (count)
| 0 | ||||||||||||||||||
556 | { | - | ||||||||||||||||||
557 | temp = next_history (); | - | ||||||||||||||||||
558 | if (!temp)
| 0 | ||||||||||||||||||
559 | break; never executed: break; | 0 | ||||||||||||||||||
560 | --count; | - | ||||||||||||||||||
561 | } never executed: end of block | 0 | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | if (temp == 0)
| 0 | ||||||||||||||||||
564 | rl_maybe_unsave_line (); never executed: rl_maybe_unsave_line (); | 0 | ||||||||||||||||||
565 | else | - | ||||||||||||||||||
566 | { | - | ||||||||||||||||||
567 | rl_replace_from_history (temp, 0); | - | ||||||||||||||||||
568 | _rl_history_set_point (); | - | ||||||||||||||||||
569 | } never executed: end of block | 0 | ||||||||||||||||||
570 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
571 | } | - | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | /* Get the previous item out of our interactive history, making it the current | - | ||||||||||||||||||
574 | line. If there is no previous history, just ding. */ | - | ||||||||||||||||||
575 | int | - | ||||||||||||||||||
576 | rl_get_previous_history (int count, int key) | - | ||||||||||||||||||
577 | { | - | ||||||||||||||||||
578 | HIST_ENTRY *old_temp, *temp; | - | ||||||||||||||||||
579 | - | |||||||||||||||||||
580 | if (count < 0)
| 0 | ||||||||||||||||||
581 | return (rl_get_next_history (-count, key)); never executed: return (rl_get_next_history (-count, key)); | 0 | ||||||||||||||||||
582 | - | |||||||||||||||||||
583 | if (count == 0 || history_list () == 0)
| 0 | ||||||||||||||||||
584 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | /* either not saved by rl_newline or at end of line, so set appropriately. */ | - | ||||||||||||||||||
587 | if (_rl_history_saved_point == -1 && (rl_point || rl_end))
| 0 | ||||||||||||||||||
588 | _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point; never executed: _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point;
| 0 | ||||||||||||||||||
589 | - | |||||||||||||||||||
590 | /* If we don't have a line saved, then save this one. */ | - | ||||||||||||||||||
591 | rl_maybe_save_line (); | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | /* If the current line has changed, save the changes. */ | - | ||||||||||||||||||
594 | rl_maybe_replace_line (); | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | temp = old_temp = (HIST_ENTRY *)NULL; | - | ||||||||||||||||||
597 | while (count)
| 0 | ||||||||||||||||||
598 | { | - | ||||||||||||||||||
599 | temp = previous_history (); | - | ||||||||||||||||||
600 | if (temp == 0)
| 0 | ||||||||||||||||||
601 | break; never executed: break; | 0 | ||||||||||||||||||
602 | - | |||||||||||||||||||
603 | old_temp = temp; | - | ||||||||||||||||||
604 | --count; | - | ||||||||||||||||||
605 | } never executed: end of block | 0 | ||||||||||||||||||
606 | - | |||||||||||||||||||
607 | /* If there was a large argument, and we moved back to the start of the | - | ||||||||||||||||||
608 | history, that is not an error. So use the last value found. */ | - | ||||||||||||||||||
609 | if (!temp && old_temp)
| 0 | ||||||||||||||||||
610 | temp = old_temp; never executed: temp = old_temp; | 0 | ||||||||||||||||||
611 | - | |||||||||||||||||||
612 | if (temp == 0)
| 0 | ||||||||||||||||||
613 | { | - | ||||||||||||||||||
614 | rl_maybe_unsave_line (); | - | ||||||||||||||||||
615 | rl_ding (); | - | ||||||||||||||||||
616 | } never executed: end of block | 0 | ||||||||||||||||||
617 | else | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | rl_replace_from_history (temp, 0); | - | ||||||||||||||||||
620 | _rl_history_set_point (); | - | ||||||||||||||||||
621 | } never executed: end of block | 0 | ||||||||||||||||||
622 | - | |||||||||||||||||||
623 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | /* **************************************************************** */ | - | ||||||||||||||||||
627 | /* */ | - | ||||||||||||||||||
628 | /* Editing Modes */ | - | ||||||||||||||||||
629 | /* */ | - | ||||||||||||||||||
630 | /* **************************************************************** */ | - | ||||||||||||||||||
631 | /* How to toggle back and forth between editing modes. */ | - | ||||||||||||||||||
632 | int | - | ||||||||||||||||||
633 | rl_vi_editing_mode (int count, int key) | - | ||||||||||||||||||
634 | { | - | ||||||||||||||||||
635 | #if defined (VI_MODE) | - | ||||||||||||||||||
636 | _rl_set_insert_mode (RL_IM_INSERT, 1); /* vi mode ignores insert mode */ | - | ||||||||||||||||||
637 | rl_editing_mode = vi_mode; | - | ||||||||||||||||||
638 | rl_vi_insert_mode (1, key); | - | ||||||||||||||||||
639 | #endif /* VI_MODE */ | - | ||||||||||||||||||
640 | - | |||||||||||||||||||
641 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | int | - | ||||||||||||||||||
645 | rl_emacs_editing_mode (int count, int key) | - | ||||||||||||||||||
646 | { | - | ||||||||||||||||||
647 | rl_editing_mode = emacs_mode; | - | ||||||||||||||||||
648 | _rl_set_insert_mode (RL_IM_INSERT, 1); /* emacs mode default is insert mode */ | - | ||||||||||||||||||
649 | _rl_keymap = emacs_standard_keymap; | - | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | if (_rl_show_mode_in_prompt)
| 0 | ||||||||||||||||||
652 | _rl_reset_prompt (); never executed: _rl_reset_prompt (); | 0 | ||||||||||||||||||
653 | - | |||||||||||||||||||
654 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
655 | } | - | ||||||||||||||||||
656 | - | |||||||||||||||||||
657 | /* Function for the rest of the library to use to set insert/overwrite mode. */ | - | ||||||||||||||||||
658 | void | - | ||||||||||||||||||
659 | _rl_set_insert_mode (int im, int force) | - | ||||||||||||||||||
660 | { | - | ||||||||||||||||||
661 | #ifdef CURSOR_MODE | - | ||||||||||||||||||
662 | _rl_set_cursor (im, force); | - | ||||||||||||||||||
663 | #endif | - | ||||||||||||||||||
664 | - | |||||||||||||||||||
665 | rl_insert_mode = im; | - | ||||||||||||||||||
666 | } never executed: end of block | 0 | ||||||||||||||||||
667 | - | |||||||||||||||||||
668 | /* Toggle overwrite mode. A positive explicit argument selects overwrite | - | ||||||||||||||||||
669 | mode. A negative or zero explicit argument selects insert mode. */ | - | ||||||||||||||||||
670 | int | - | ||||||||||||||||||
671 | rl_overwrite_mode (int count, int key) | - | ||||||||||||||||||
672 | { | - | ||||||||||||||||||
673 | if (rl_explicit_arg == 0)
| 0 | ||||||||||||||||||
674 | _rl_set_insert_mode (rl_insert_mode ^ 1, 0); never executed: _rl_set_insert_mode (rl_insert_mode ^ 1, 0); | 0 | ||||||||||||||||||
675 | else if (count > 0)
| 0 | ||||||||||||||||||
676 | _rl_set_insert_mode (RL_IM_OVERWRITE, 0); never executed: _rl_set_insert_mode (0, 0); | 0 | ||||||||||||||||||
677 | else | - | ||||||||||||||||||
678 | _rl_set_insert_mode (RL_IM_INSERT, 0); never executed: _rl_set_insert_mode (1, 0); | 0 | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
681 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |