Bash  5.0-beta2
Bash - Bourne Again shell
misc.c File Reference
#include "ansi_stdlib.h"
#include <stdio.h>
#include "rldefs.h"
#include "rlmbutil.h"
#include "readline.h"
#include "history.h"
#include "rlprivate.h"
#include "rlshell.h"
#include "xmalloc.h"

Go to the source code of this file.

Macros

#define READLINE_LIBRARY
 

Functions

static int rl_digit_loop ()
 
static void _rl_history_set_point ()
 
void _rl_free_history_entry ()
 
int _rl_arg_overflow (void)
 
void _rl_arg_init (void)
 
int _rl_arg_getchar (void)
 
int _rl_arg_dispatch (_rl_arg_cxt cxt, int c)
 
void _rl_reset_argument (void)
 
int rl_digit_argument (int ignore, int key)
 
int rl_universal_argument (int count, int key)
 
int _rl_arg_callback (_rl_arg_cxt cxt)
 
int rl_discard_argument (void)
 
void _rl_start_using_history (void)
 
void _rl_free_history_entry (HIST_ENTRY *entry)
 
int rl_maybe_replace_line (void)
 
int rl_maybe_unsave_line (void)
 
int rl_maybe_save_line (void)
 
int _rl_free_saved_history_line (void)
 
void rl_replace_from_history (HIST_ENTRY *entry, int flags)
 
void _rl_revert_all_lines (void)
 
void rl_clear_history (void)
 
int rl_beginning_of_history (int count, int key)
 
int rl_end_of_history (int count, int key)
 
int rl_get_next_history (int count, int key)
 
int rl_get_previous_history (int count, int key)
 
int rl_vi_editing_mode (int count, int key)
 
int rl_emacs_editing_mode (int count, int key)
 
void _rl_set_insert_mode (int im, int force)
 
int rl_overwrite_mode (int count, int key)
 

Variables

int _rl_history_preserve_point = 0
 
_rl_arg_cxt _rl_argcxt
 
int _rl_history_saved_point = -1
 
HIST_ENTRY_rl_saved_line_for_history = (HIST_ENTRY *)NULL
 

Macro Definition Documentation

◆ READLINE_LIBRARY

#define READLINE_LIBRARY

Definition at line 22 of file misc.c.

Function Documentation

◆ rl_digit_loop()

static int rl_digit_loop ( void  )
static

Definition at line 194 of file misc.c.

References _rl_abort_internal(), _rl_arg_dispatch(), _rl_arg_getchar(), _rl_arg_overflow(), c, RL_ISSTATE, and RL_STATE_NUMERICARG.

Referenced by rl_digit_argument(), and rl_universal_argument().

195 {
196  int c, r;
197 
198  while (1)
199  {
200  if (_rl_arg_overflow ())
201  return 1;
202 
203  c = _rl_arg_getchar ();
204 
205  if (c < 0)
206  {
208  return -1;
209  }
210 
211  r = _rl_arg_dispatch (_rl_argcxt, c);
212  if (r <= 0 || (RL_ISSTATE (RL_STATE_NUMERICARG) == 0))
213  break;
214  }
215 
216  return r;
217 }
int _rl_arg_overflow(void)
Definition: misc.c:79
register GCHAR c
Definition: glob_loop.c:26
int _rl_arg_getchar(void)
Definition: misc.c:103
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
#define RL_ISSTATE(x)
Definition: readline.h:902
int _rl_abort_internal()
Definition: util.c:99
#define RL_STATE_NUMERICARG
Definition: readline.h:882
int _rl_arg_dispatch(_rl_arg_cxt cxt, int c)
Definition: misc.c:119
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_history_set_point()

static void _rl_history_set_point ( void  )
static

Definition at line 396 of file misc.c.

References _rl_keymap, emacs_mode, rl_editing_mode, rl_end, rl_mark, rl_point, vi_insertion_keymap, and vi_mode.

Referenced by rl_get_next_history(), and rl_get_previous_history().

397 {
400  : rl_end;
401  if (rl_point > rl_end)
402  rl_point = rl_end;
403 
404 #if defined (VI_MODE)
406  rl_point = 0;
407 #endif /* VI_MODE */
408 
410  rl_mark = (rl_point == rl_end ? 0 : rl_end);
411 }
int _rl_history_saved_point
Definition: misc.c:70
int rl_mark
Definition: readline.c:160
int rl_editing_mode
Definition: readline.c:123
KEYMAP_ENTRY_ARRAY vi_insertion_keymap
Definition: vi_keymap.c:312
int _rl_history_preserve_point
Definition: misc.c:64
int rl_point
Definition: readline.c:157
Keymap _rl_keymap
Definition: readline.c:120
int rl_end
Definition: readline.c:163
#define vi_mode
Definition: rldefs.h:94
#define emacs_mode
Definition: rldefs.h:95
Here is the caller graph for this function:

◆ _rl_free_history_entry() [1/2]

void _rl_free_history_entry ( )

Referenced by _rl_free_saved_history_line(), _rl_start_using_history(), rl_clear_history(), and rl_maybe_unsave_line().

Here is the caller graph for this function:

◆ _rl_arg_overflow()

int _rl_arg_overflow ( void  )

Definition at line 79 of file misc.c.

References rl_clear_message(), rl_ding(), rl_explicit_arg, rl_numeric_arg, rl_restore_prompt(), RL_STATE_NUMERICARG, and RL_UNSETSTATE.

Referenced by rl_digit_loop(), and rl_digit_loop1().

80 {
81  if (rl_numeric_arg > 1000000)
82  {
83  _rl_argcxt = 0;
85  rl_ding ();
89  return 1;
90  }
91  return 0;
92 }
void rl_restore_prompt(void)
Definition: display.c:2768
#define RL_UNSETSTATE(x)
Definition: readline.h:901
int rl_numeric_arg
Definition: readline.c:137
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
int rl_clear_message(void)
Definition: display.c:2720
#define RL_STATE_NUMERICARG
Definition: readline.h:882
int rl_ding()
Definition: terminal.c:681
int rl_explicit_arg
Definition: readline.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_arg_init()

void _rl_arg_init ( void  )

Definition at line 95 of file misc.c.

References rl_save_prompt(), RL_SETSTATE, and RL_STATE_NUMERICARG.

Referenced by rl_digit_argument(), and rl_universal_argument().

96 {
97  rl_save_prompt ();
98  _rl_argcxt = 0;
100 }
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
#define RL_STATE_NUMERICARG
Definition: readline.h:882
void rl_save_prompt(void)
Definition: display.c:2747
#define RL_SETSTATE(x)
Definition: readline.h:900
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_arg_getchar()

int _rl_arg_getchar ( void  )

Definition at line 103 of file misc.c.

References c, rl_arg_sign, rl_message(), rl_numeric_arg, rl_read_key(), RL_SETSTATE, RL_STATE_MOREINPUT, and RL_UNSETSTATE.

Referenced by _rl_arg_callback(), rl_digit_loop(), and rl_digit_loop1().

104 {
105  int c;
106 
107  rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
109  c = rl_read_key ();
111 
112  return c;
113 }
int rl_message(char *format, arg1, arg2)
Definition: display.c:2685
#define RL_UNSETSTATE(x)
Definition: readline.h:901
register GCHAR c
Definition: glob_loop.c:26
int rl_numeric_arg
Definition: readline.c:137
int rl_arg_sign
Definition: readline.c:143
#define RL_STATE_MOREINPUT
Definition: readline.h:878
int rl_read_key(void)
Definition: input.c:455
#define RL_SETSTATE(x)
Definition: readline.h:900
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_arg_dispatch()

int _rl_arg_dispatch ( _rl_arg_cxt  cxt,
int  c 
)

Definition at line 119 of file misc.c.

References _rl_digit_p, _rl_digit_value, _rl_dispatch(), _rl_keymap, c, ISFUNC, NUM_READONE, NUM_SAWDIGITS, NUM_SAWMINUS, rl_arg_sign, rl_clear_message(), rl_done, rl_explicit_arg, RL_ISSTATE, rl_numeric_arg, rl_read_key(), rl_restore_prompt(), RL_SETSTATE, RL_STATE_CALLBACK, RL_STATE_MOREINPUT, RL_STATE_NUMERICARG, rl_universal_argument(), RL_UNSETSTATE, and UNMETA.

Referenced by _rl_arg_callback(), rl_digit_argument(), and rl_digit_loop().

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)
128  {
129  if ((cxt & NUM_SAWDIGITS) == 0)
130  {
131  rl_numeric_arg *= 4;
132  return 1;
133  }
134  else if (RL_ISSTATE (RL_STATE_CALLBACK))
135  {
137  return 0; /* XXX */
138  }
139  else
140  {
142  key = rl_read_key ();
145  rl_clear_message ();
147  if (key < 0)
148  return -1;
149  return (_rl_dispatch (key, _rl_keymap));
150  }
151  }
152 
153  c = UNMETA (c);
154 
155  if (_rl_digit_p (c))
156  {
157  r = _rl_digit_value (c);
158  rl_numeric_arg = rl_explicit_arg ? (rl_numeric_arg * 10) + r : r;
159  rl_explicit_arg = 1;
161  }
162  else if (c == '-' && rl_explicit_arg == 0)
163  {
164  rl_numeric_arg = 1;
166  rl_arg_sign = -1;
167  }
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)
172  rl_explicit_arg = 1;
174  rl_clear_message ();
176 
177  r = _rl_dispatch (key, _rl_keymap);
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)
183  (*rl_redisplay_function) ();
184  r = 0;
185  }
186  return r;
187  }
188 
189  return 1;
190 }
void rl_restore_prompt(void)
Definition: display.c:2768
#define ISFUNC
Definition: keymaps.h:59
#define RL_UNSETSTATE(x)
Definition: readline.h:901
int rl_universal_argument(int count, int key)
Definition: misc.c:250
register GCHAR c
Definition: glob_loop.c:26
#define NUM_SAWDIGITS
Definition: rlprivate.h:114
#define RL_STATE_CALLBACK
Definition: readline.h:891
int rl_numeric_arg
Definition: readline.c:137
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
#define NUM_SAWMINUS
Definition: rlprivate.h:113
int rl_arg_sign
Definition: readline.c:143
int rl_clear_message(void)
Definition: display.c:2720
#define RL_ISSTATE(x)
Definition: readline.h:902
int rl_done
Definition: readline.c:166
#define _rl_digit_p(c)
Definition: chardefs.h:100
#define RL_STATE_NUMERICARG
Definition: readline.h:882
#define _rl_digit_value(x)
Definition: chardefs.h:111
#define UNMETA(c)
Definition: chardefs.h:66
#define RL_STATE_MOREINPUT
Definition: readline.h:878
#define NUM_READONE
Definition: rlprivate.h:115
Keymap _rl_keymap
Definition: readline.c:120
int rl_read_key(void)
Definition: input.c:455
#define RL_SETSTATE(x)
Definition: readline.h:900
int _rl_dispatch(register int key, Keymap map)
Definition: readline.c:795
int rl_explicit_arg
Definition: readline.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_reset_argument()

void _rl_reset_argument ( void  )

Definition at line 221 of file misc.c.

References rl_arg_sign, rl_explicit_arg, and rl_numeric_arg.

Referenced by _rl_abort_internal(), readline_internal_char(), rl_discard_argument(), rl_free_line_state(), and rl_insert().

222 {
224  rl_explicit_arg = 0;
225  _rl_argcxt = 0;
226 }
int rl_numeric_arg
Definition: readline.c:137
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
int rl_arg_sign
Definition: readline.c:143
int rl_explicit_arg
Definition: readline.c:140
Here is the caller graph for this function:

◆ rl_digit_argument()

int rl_digit_argument ( int  ignore,
int  key 
)

Definition at line 230 of file misc.c.

References _rl_arg_dispatch(), _rl_arg_init(), rl_arg_sign, rl_digit_loop(), rl_execute_next(), RL_ISSTATE, rl_message(), rl_numeric_arg, and RL_STATE_CALLBACK.

Referenced by _rl_dispatch_subseq(), and rl_vi_arg_digit().

231 {
232  _rl_arg_init ();
234  {
236  rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
237  return 0;
238  }
239  else
240  {
241  rl_execute_next (key);
242  return (rl_digit_loop ());
243  }
244 }
int rl_message(char *format, arg1, arg2)
Definition: display.c:2685
#define RL_STATE_CALLBACK
Definition: readline.h:891
int rl_numeric_arg
Definition: readline.c:137
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
int rl_arg_sign
Definition: readline.c:143
#define RL_ISSTATE(x)
Definition: readline.h:902
static int rl_digit_loop()
Definition: misc.c:194
int _rl_arg_dispatch(_rl_arg_cxt cxt, int c)
Definition: misc.c:119
void _rl_arg_init(void)
Definition: misc.c:95
int rl_execute_next(int c)
Definition: input.c:431
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_universal_argument()

int rl_universal_argument ( int  count,
int  key 
)

Definition at line 250 of file misc.c.

References _rl_arg_init(), rl_digit_loop(), RL_ISSTATE, rl_numeric_arg, and RL_STATE_CALLBACK.

Referenced by _rl_arg_dispatch(), and _rl_vi_arg_dispatch().

251 {
252  _rl_arg_init ();
253  rl_numeric_arg *= 4;
254 
255  return (RL_ISSTATE (RL_STATE_CALLBACK) ? 0 : rl_digit_loop ());
256 }
#define RL_STATE_CALLBACK
Definition: readline.h:891
int rl_numeric_arg
Definition: readline.c:137
#define RL_ISSTATE(x)
Definition: readline.h:902
static int rl_digit_loop()
Definition: misc.c:194
void _rl_arg_init(void)
Definition: misc.c:95
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_arg_callback()

int _rl_arg_callback ( _rl_arg_cxt  cxt)

Definition at line 259 of file misc.c.

References _rl_arg_dispatch(), _rl_arg_getchar(), c, NUM_READONE, rl_arg_sign, rl_clear_message(), rl_execute_next(), rl_message(), rl_numeric_arg, rl_restore_prompt(), RL_STATE_NUMERICARG, and RL_UNSETSTATE.

Referenced by rl_callback_read_char().

260 {
261  int c, r;
262 
263  c = _rl_arg_getchar ();
264  if (c < 0)
265  return (1); /* EOF */
266 
267  if (_rl_argcxt & NUM_READONE)
268  {
269  _rl_argcxt &= ~NUM_READONE;
271  rl_clear_message ();
273  rl_execute_next (c);
274  return 0;
275  }
276 
277  r = _rl_arg_dispatch (cxt, c);
278  if (r > 0)
279  rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
280  return (r != 1);
281 }
void rl_restore_prompt(void)
Definition: display.c:2768
int rl_message(char *format, arg1, arg2)
Definition: display.c:2685
#define RL_UNSETSTATE(x)
Definition: readline.h:901
register GCHAR c
Definition: glob_loop.c:26
int rl_numeric_arg
Definition: readline.c:137
int _rl_arg_getchar(void)
Definition: misc.c:103
_rl_arg_cxt _rl_argcxt
Definition: misc.c:66
int rl_arg_sign
Definition: readline.c:143
int rl_clear_message(void)
Definition: display.c:2720
#define RL_STATE_NUMERICARG
Definition: readline.h:882
#define NUM_READONE
Definition: rlprivate.h:115
int _rl_arg_dispatch(_rl_arg_cxt cxt, int c)
Definition: misc.c:119
int rl_execute_next(int c)
Definition: input.c:431
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_discard_argument()

int rl_discard_argument ( void  )

Definition at line 285 of file misc.c.

References _rl_reset_argument(), rl_clear_message(), and rl_ding().

286 {
287  rl_ding ();
288  rl_clear_message ();
290 
291  return 0;
292 }
int rl_clear_message(void)
Definition: display.c:2720
void _rl_reset_argument(void)
Definition: misc.c:221
int rl_ding()
Definition: terminal.c:681
Here is the call graph for this function:

◆ _rl_start_using_history()

void _rl_start_using_history ( void  )

Definition at line 310 of file misc.c.

References _rl_free_history_entry(), NULL, and using_history().

Referenced by rl_initialize().

311 {
312  using_history ();
315 
317 }
void _rl_free_history_entry()
void using_history(void)
Definition: history.c:131
HIST_ENTRY * _rl_saved_line_for_history
Definition: misc.c:306
#define NULL
Definition: general.h:53
Definition: history.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_free_history_entry() [2/2]

void _rl_free_history_entry ( HIST_ENTRY entry)

Definition at line 321 of file misc.c.

References FREE, _hist_entry::line, _hist_entry::timestamp, and xfree().

322 {
323  if (entry == 0)
324  return;
325 
326  FREE (entry->line);
327  FREE (entry->timestamp);
328 
329  xfree (entry);
330 }
char * timestamp
Definition: history.h:48
#define FREE(s)
Definition: general.h:172
void xfree(char *string)
Definition: xmalloc.c:89
char * line
Definition: history.h:47
Here is the call graph for this function:

◆ rl_maybe_replace_line()

int rl_maybe_replace_line ( void  )

Definition at line 334 of file misc.c.

References current_history(), _hist_entry::data, FREE, _hist_entry::line, replace_history_entry(), rl_line_buffer, rl_undo_list, temp, _hist_entry::timestamp, where_history(), and xfree().

Referenced by _rl_isearch_init(), maybe_replace_line(), rl_end_of_history(), rl_get_next_history(), and rl_get_previous_history().

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))
341  {
343  xfree (temp->line);
344  FREE (temp->timestamp);
345  xfree (temp);
346  }
347  return 0;
348 }
int where_history(void)
Definition: history.c:153
char * timestamp
Definition: history.h:48
char * rl_line_buffer
Definition: readline.c:251
HIST_ENTRY * replace_history_entry(int which, const char *line, histdata_t data)
Definition: history.c:381
UNDO_LIST * rl_undo_list
Definition: undo.c:64
histdata_t data
Definition: history.h:49
Definition: history.h:46
#define FREE(s)
Definition: general.h:172
HIST_ENTRY * current_history(void)
Definition: history.c:181
void xfree(char *string)
Definition: xmalloc.c:89
char * histdata_t
Definition: history.h:42
char * line
Definition: history.h:47
temp
Definition: subst.c:10040
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_maybe_unsave_line()

int rl_maybe_unsave_line ( void  )

Definition at line 352 of file misc.c.

References _rl_free_history_entry(), _hist_entry::data, _hist_entry::line, NULL, rl_ding(), rl_end, rl_point, rl_replace_line(), and rl_undo_list.

Referenced by _rl_nsearch_abort(), maybe_unsave_line(), noninc_dosearch(), rl_end_of_history(), rl_get_next_history(), rl_get_previous_history(), and rl_history_search_internal().

353 {
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. */
362  rl_point = rl_end; /* rl_replace_line sets rl_end */
363  }
364  else
365  rl_ding ();
366  return 0;
367 }
void _rl_free_history_entry()
void rl_replace_line(const char *text, int clear_undo)
Definition: text.c:204
UNDO_LIST * rl_undo_list
Definition: undo.c:64
histdata_t data
Definition: history.h:49
HIST_ENTRY * _rl_saved_line_for_history
Definition: misc.c:306
int rl_point
Definition: readline.c:157
#define NULL
Definition: general.h:53
Definition: history.h:46
int rl_end
Definition: readline.c:163
int rl_ding()
Definition: terminal.c:681
char * line
Definition: history.h:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_maybe_save_line()

int rl_maybe_save_line ( void  )

Definition at line 371 of file misc.c.

References _hist_entry::data, _hist_entry::line, NULL, rl_line_buffer, rl_undo_list, savestring(), _hist_entry::timestamp, and xmalloc().

Referenced by _rl_nsearch_init(), maybe_save_line(), rl_get_previous_history(), and rl_history_search_internal().

372 {
374  {
379  }
380 
381  return 0;
382 }
char * timestamp
Definition: history.h:48
char * rl_line_buffer
Definition: readline.c:251
UNDO_LIST * rl_undo_list
Definition: undo.c:64
char * savestring(const char *s)
Definition: savestring.c:33
histdata_t data
Definition: history.h:49
HIST_ENTRY * _rl_saved_line_for_history
Definition: misc.c:306
#define NULL
Definition: general.h:53
Definition: history.h:46
char * line
Definition: history.h:47
static char * xmalloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_free_saved_history_line()

int _rl_free_saved_history_line ( void  )

Definition at line 385 of file misc.c.

References _rl_free_history_entry(), and NULL.

Referenced by rl_history_search_reinit(), and rl_vi_search().

386 {
388  {
391  }
392  return 0;
393 }
void _rl_free_history_entry()
HIST_ENTRY * _rl_saved_line_for_history
Definition: misc.c:306
#define NULL
Definition: general.h:53
Definition: history.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_replace_from_history()

void rl_replace_from_history ( HIST_ENTRY entry,
int  flags 
)

Definition at line 414 of file misc.c.

References _hist_entry::data, _hist_entry::line, rl_editing_mode, rl_end, rl_mark, rl_point, rl_replace_line(), rl_undo_list, VI_MODE, and vi_mode.

Referenced by _rl_revert_all_lines(), rl_get_next_history(), and rl_get_previous_history().

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)
425  {
426  rl_point = 0;
427  rl_mark = rl_end;
428  }
429 #endif
430 }
#define VI_MODE
Definition: rlconf.h:26
void rl_replace_line(const char *text, int clear_undo)
Definition: text.c:204
int rl_mark
Definition: readline.c:160
int rl_editing_mode
Definition: readline.c:123
UNDO_LIST * rl_undo_list
Definition: undo.c:64
histdata_t data
Definition: history.h:49
int rl_point
Definition: readline.c:157
int rl_end
Definition: readline.c:163
#define vi_mode
Definition: rldefs.h:94
char * line
Definition: history.h:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rl_revert_all_lines()

void _rl_revert_all_lines ( void  )

Definition at line 438 of file misc.c.

References _rl_set_the_line(), current_history(), _hist_entry::data, FREE, history_length, history_set_pos(), lbuf, _hist_entry::line, previous_history(), rl_do_undo(), rl_line_buffer, rl_replace_from_history(), rl_replace_line(), rl_undo_list, savestring(), where_history(), and xfree().

Referenced by readline_internal_teardown().

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 ();
450  while (entry)
451  {
452  if (ul = (UNDO_LIST *)entry->data)
453  {
454  if (ul == saved_undo_list)
455  saved_undo_list = 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)
461  rl_do_undo ();
462  /* And copy the reverted line back to the history entry, preserving
463  the timestamp. */
464  FREE (entry->line);
465  entry->line = savestring (rl_line_buffer);
466  }
467  entry = previous_history ();
468  }
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 }
int history_length
Definition: history.c:93
HIST_ENTRY * previous_history(void)
Definition: history.c:192
int where_history(void)
Definition: history.c:153
void rl_replace_line(const char *text, int clear_undo)
Definition: text.c:204
static char lbuf[128]
Definition: zread.c:115
int history_set_pos(int pos)
Definition: history.c:161
char * rl_line_buffer
Definition: readline.c:251
UNDO_LIST * rl_undo_list
Definition: undo.c:64
char * savestring(const char *s)
Definition: savestring.c:33
histdata_t data
Definition: history.h:49
void rl_replace_from_history(HIST_ENTRY *entry, int flags)
Definition: misc.c:414
Definition: history.h:46
#define FREE(s)
Definition: general.h:172
int rl_do_undo(void)
Definition: undo.c:169
HIST_ENTRY * current_history(void)
Definition: history.c:181
void _rl_set_the_line(void)
Definition: readline.c:684
void xfree(char *string)
Definition: xmalloc.c:89
char * line
Definition: history.h:47
Here is the caller graph for this function:

◆ rl_clear_history()

void rl_clear_history ( void  )

Definition at line 487 of file misc.c.

References _rl_free_history_entry(), _rl_free_undo_list(), _hist_entry::data, history_length, history_list(), history_offset, i, and rl_undo_list.

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++)
497  {
498  hent = hlist[i];
499  if (ul = (UNDO_LIST *)hent->data)
500  {
501  if (ul == saved_undo_list)
502  saved_undo_list = 0;
503  _rl_free_undo_list (ul);
504  hent->data = 0;
505  }
506  _rl_free_history_entry (hent);
507  }
508 
509  history_offset = history_length = 0;
510  rl_undo_list = saved_undo_list; /* should be NULL */
511 }
int history_length
Definition: history.c:93
void _rl_free_history_entry()
void _rl_free_undo_list()
static nls_uint32 nls_uint32 i
Definition: gettextP.h:74
UNDO_LIST * rl_undo_list
Definition: undo.c:64
int history_offset
Definition: history.c:90
histdata_t data
Definition: history.h:49
Definition: history.h:46
HIST_ENTRY ** history_list()
Definition: history.c:173
Here is the call graph for this function:

◆ rl_beginning_of_history()

int rl_beginning_of_history ( int  count,
int  key 
)

Definition at line 521 of file misc.c.

References rl_get_previous_history(), and where_history().

Referenced by rl_vi_fetch_history().

522 {
523  return (rl_get_previous_history (1 + where_history (), key));
524 }
int where_history(void)
Definition: history.c:153
int rl_get_previous_history(int count, int key)
Definition: misc.c:576
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_end_of_history()

int rl_end_of_history ( int  count,
int  key 
)

Definition at line 528 of file misc.c.

References rl_maybe_replace_line(), rl_maybe_unsave_line(), and using_history().

529 {
531  using_history ();
533  return 0;
534 }
void using_history(void)
Definition: history.c:131
int rl_maybe_unsave_line(void)
Definition: misc.c:352
int rl_maybe_replace_line(void)
Definition: misc.c:334
Here is the call graph for this function:

◆ rl_get_next_history()

int rl_get_next_history ( int  count,
int  key 
)

Definition at line 538 of file misc.c.

References _rl_history_set_point(), next_history(), NULL, rl_end, rl_get_previous_history(), rl_maybe_replace_line(), rl_maybe_unsave_line(), rl_point, rl_replace_from_history(), and temp.

Referenced by _rl_isearch_fini(), bind_arrow_keys_internal(), bind_termcap_arrow_keys(), rl_arrow_keys(), rl_get_previous_history(), rl_history_search_forward(), and rl_history_substr_search_forward().

539 {
540  HIST_ENTRY *temp;
541 
542  if (count < 0)
543  return (rl_get_previous_history (-count, key));
544 
545  if (count == 0)
546  return 0;
547 
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))
553 
554  temp = (HIST_ENTRY *)NULL;
555  while (count)
556  {
557  temp = next_history ();
558  if (!temp)
559  break;
560  --count;
561  }
562 
563  if (temp == 0)
565  else
566  {
567  rl_replace_from_history (temp, 0);
569  }
570  return 0;
571 }
int _rl_history_saved_point
Definition: misc.c:70
int rl_get_previous_history(int count, int key)
Definition: misc.c:576
int rl_maybe_unsave_line(void)
Definition: misc.c:352
static void _rl_history_set_point()
Definition: misc.c:396
void rl_replace_from_history(HIST_ENTRY *entry, int flags)
Definition: misc.c:414
int rl_point
Definition: readline.c:157
#define NULL
Definition: general.h:53
Definition: history.h:46
int rl_maybe_replace_line(void)
Definition: misc.c:334
int rl_end
Definition: readline.c:163
HIST_ENTRY * next_history(void)
Definition: history.c:201
temp
Definition: subst.c:10040
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_get_previous_history()

int rl_get_previous_history ( int  count,
int  key 
)

Definition at line 576 of file misc.c.

References _rl_history_set_point(), history_list(), NULL, previous_history(), rl_ding(), rl_end, rl_get_next_history(), rl_maybe_replace_line(), rl_maybe_save_line(), rl_maybe_unsave_line(), rl_point, rl_replace_from_history(), and temp.

Referenced by _rl_isearch_fini(), bind_arrow_keys_internal(), bind_termcap_arrow_keys(), rl_arrow_keys(), rl_beginning_of_history(), rl_get_next_history(), rl_history_search_backward(), rl_history_substr_search_backward(), and rl_vi_fetch_history().

577 {
578  HIST_ENTRY *old_temp, *temp;
579 
580  if (count < 0)
581  return (rl_get_next_history (-count, key));
582 
583  if (count == 0 || history_list () == 0)
584  return 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))
589 
590  /* If we don't have a line saved, then save this one. */
592 
593  /* If the current line has changed, save the changes. */
595 
596  temp = old_temp = (HIST_ENTRY *)NULL;
597  while (count)
598  {
599  temp = previous_history ();
600  if (temp == 0)
601  break;
602 
603  old_temp = temp;
604  --count;
605  }
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)
610  temp = old_temp;
611 
612  if (temp == 0)
613  {
615  rl_ding ();
616  }
617  else
618  {
619  rl_replace_from_history (temp, 0);
621  }
622 
623  return 0;
624 }
HIST_ENTRY * previous_history(void)
Definition: history.c:192
int _rl_history_saved_point
Definition: misc.c:70
int rl_maybe_unsave_line(void)
Definition: misc.c:352
static void _rl_history_set_point()
Definition: misc.c:396
int rl_maybe_save_line(void)
Definition: misc.c:371
void rl_replace_from_history(HIST_ENTRY *entry, int flags)
Definition: misc.c:414
int rl_point
Definition: readline.c:157
#define NULL
Definition: general.h:53
Definition: history.h:46
int rl_maybe_replace_line(void)
Definition: misc.c:334
HIST_ENTRY ** history_list()
Definition: history.c:173
int rl_end
Definition: readline.c:163
int rl_ding()
Definition: terminal.c:681
int rl_get_next_history(int count, int key)
Definition: misc.c:538
temp
Definition: subst.c:10040
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_vi_editing_mode()

int rl_vi_editing_mode ( int  count,
int  key 
)

Definition at line 633 of file misc.c.

References _rl_set_insert_mode(), rl_editing_mode, RL_IM_INSERT, rl_vi_insert_mode(), and vi_mode.

634 {
635 #if defined (VI_MODE)
636  _rl_set_insert_mode (RL_IM_INSERT, 1); /* vi mode ignores insert mode */
638  rl_vi_insert_mode (1, key);
639 #endif /* VI_MODE */
640 
641  return 0;
642 }
#define RL_IM_INSERT
Definition: rldefs.h:99
void _rl_set_insert_mode(int im, int force)
Definition: misc.c:659
int rl_editing_mode
Definition: readline.c:123
int rl_vi_insert_mode(int count, int key)
Definition: vi_mode.c:801
#define vi_mode
Definition: rldefs.h:94
Here is the call graph for this function:

◆ rl_emacs_editing_mode()

int rl_emacs_editing_mode ( int  count,
int  key 
)

Definition at line 645 of file misc.c.

References _rl_keymap, _rl_reset_prompt(), _rl_set_insert_mode(), _rl_show_mode_in_prompt, emacs_mode, emacs_standard_keymap, rl_editing_mode, and RL_IM_INSERT.

646 {
648  _rl_set_insert_mode (RL_IM_INSERT, 1); /* emacs mode default is insert mode */
650 
652  _rl_reset_prompt ();
653 
654  return 0;
655 }
#define RL_IM_INSERT
Definition: rldefs.h:99
void _rl_set_insert_mode(int im, int force)
Definition: misc.c:659
KEYMAP_ENTRY_ARRAY emacs_standard_keymap
Definition: emacs_keymap.c:32
void _rl_reset_prompt(void)
Definition: display.c:515
int rl_editing_mode
Definition: readline.c:123
int _rl_show_mode_in_prompt
Definition: readline.c:312
Keymap _rl_keymap
Definition: readline.c:120
#define emacs_mode
Definition: rldefs.h:95
Here is the call graph for this function:

◆ _rl_set_insert_mode()

void _rl_set_insert_mode ( int  im,
int  force 
)

Definition at line 659 of file misc.c.

References _rl_set_cursor(), and rl_insert_mode.

Referenced by readline_internal_teardown(), rl_emacs_editing_mode(), rl_initialize(), rl_overwrite_mode(), and rl_vi_editing_mode().

660 {
661 #ifdef CURSOR_MODE
662  _rl_set_cursor (im, force);
663 #endif
664 
665  rl_insert_mode = im;
666 }
static int force
Definition: rm.c:39
int rl_insert_mode
Definition: readline.c:126
void _rl_set_cursor()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rl_overwrite_mode()

int rl_overwrite_mode ( int  count,
int  key 
)

Definition at line 671 of file misc.c.

References _rl_set_insert_mode(), rl_explicit_arg, RL_IM_INSERT, RL_IM_OVERWRITE, and rl_insert_mode.

Referenced by bind_arrow_keys_internal(), and bind_termcap_arrow_keys().

672 {
673  if (rl_explicit_arg == 0)
675  else if (count > 0)
677  else
679 
680  return 0;
681 }
#define RL_IM_INSERT
Definition: rldefs.h:99
void _rl_set_insert_mode(int im, int force)
Definition: misc.c:659
#define RL_IM_OVERWRITE
Definition: rldefs.h:100
int rl_insert_mode
Definition: readline.c:126
int rl_explicit_arg
Definition: readline.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _rl_history_preserve_point

int _rl_history_preserve_point = 0

Definition at line 64 of file misc.c.

Referenced by rl_newline().

◆ _rl_argcxt

_rl_arg_cxt _rl_argcxt

Definition at line 66 of file misc.c.

Referenced by rl_callback_read_char(), and rl_callback_sigcleanup().

◆ _rl_history_saved_point

int _rl_history_saved_point = -1

Definition at line 70 of file misc.c.

Referenced by rl_newline().

◆ _rl_saved_line_for_history

HIST_ENTRY* _rl_saved_line_for_history = (HIST_ENTRY *)NULL

Definition at line 306 of file misc.c.