diff options
Diffstat (limited to 'readline/macro.c')
-rw-r--r-- | readline/macro.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/readline/macro.c b/readline/macro.c index c7017cc..92cc55c 100644 --- a/readline/macro.c +++ b/readline/macro.c @@ -1,6 +1,6 @@ /* macro.c -- keyboard macros for readline. */ -/* Copyright (C) 1994-2009 Free Software Foundation, Inc. +/* Copyright (C) 1994-2009,2017 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -49,6 +49,8 @@ #include "rlprivate.h" #include "xmalloc.h" +#define MAX_MACRO_LEVEL 16 + /* **************************************************************** */ /* */ /* Hacking Keyboard Macros */ @@ -83,13 +85,24 @@ struct saved_macro { /* The list of saved macros. */ static struct saved_macro *macro_list = (struct saved_macro *)NULL; +static int macro_level = 0; + /* Set up to read subsequent input from STRING. STRING is free ()'ed when we are done with it. */ void -_rl_with_macro_input (string) - char *string; +_rl_with_macro_input (char *string) { - _rl_push_executing_macro (); + if (macro_level > MAX_MACRO_LEVEL) + { + _rl_errmsg ("maximum macro execution nesting level exceeded"); + _rl_abort_internal (); + return; + } + +#if 0 + if (rl_executing_macro) /* XXX - later */ +#endif + _rl_push_executing_macro (); rl_executing_macro = string; executing_macro_index = 0; RL_SETSTATE(RL_STATE_MACROINPUT); @@ -98,7 +111,7 @@ _rl_with_macro_input (string) /* Return the next character available from a macro, or 0 if there are no macro characters. */ int -_rl_next_macro_key () +_rl_next_macro_key (void) { int c; @@ -117,12 +130,26 @@ _rl_next_macro_key () _rl_pop_executing_macro (); return c; #else + /* XXX - consider doing the same as the callback code, just not testing + whether we're running in callback mode */ return (rl_executing_macro[executing_macro_index++]); #endif } int -_rl_prev_macro_key () +_rl_peek_macro_key (void) +{ + if (rl_executing_macro == 0) + return (0); + if (rl_executing_macro[executing_macro_index] == 0 && (macro_list == 0 || macro_list->string == 0)) + return (0); + if (rl_executing_macro[executing_macro_index] == 0 && macro_list && macro_list->string) + return (macro_list->string[0]); + return (rl_executing_macro[executing_macro_index]); +} + +int +_rl_prev_macro_key (void) { if (rl_executing_macro == 0) return (0); @@ -136,7 +163,7 @@ _rl_prev_macro_key () /* Save the currently executing macro on a stack of saved macros. */ void -_rl_push_executing_macro () +_rl_push_executing_macro (void) { struct saved_macro *saver; @@ -146,12 +173,14 @@ _rl_push_executing_macro () saver->string = rl_executing_macro; macro_list = saver; + + macro_level++; } /* Discard the current macro, replacing it with the one on the top of the stack of saved macros. */ void -_rl_pop_executing_macro () +_rl_pop_executing_macro (void) { struct saved_macro *macro; @@ -168,14 +197,15 @@ _rl_pop_executing_macro () xfree (macro); } + macro_level--; + if (rl_executing_macro == 0) RL_UNSETSTATE(RL_STATE_MACROINPUT); } /* Add a character to the macro being built. */ void -_rl_add_macro_char (c) - int c; +_rl_add_macro_char (int c) { if (current_macro_index + 1 >= current_macro_size) { @@ -190,7 +220,7 @@ _rl_add_macro_char (c) } void -_rl_kill_kbd_macro () +_rl_kill_kbd_macro (void) { if (current_macro) { @@ -213,8 +243,7 @@ _rl_kill_kbd_macro () definition to the end of the existing macro, and start by re-executing the existing macro. */ int -rl_start_kbd_macro (ignore1, ignore2) - int ignore1, ignore2; +rl_start_kbd_macro (int ignore1, int ignore2) { if (RL_ISSTATE (RL_STATE_MACRODEF)) { @@ -238,8 +267,7 @@ rl_start_kbd_macro (ignore1, ignore2) A numeric argument says to execute the macro right now, that many times, counting the definition as the first time. */ int -rl_end_kbd_macro (count, ignore) - int count, ignore; +rl_end_kbd_macro (int count, int ignore) { if (RL_ISSTATE (RL_STATE_MACRODEF) == 0) { @@ -258,8 +286,7 @@ rl_end_kbd_macro (count, ignore) /* Execute the most recently defined keyboard macro. COUNT says how many times to execute it. */ int -rl_call_last_kbd_macro (count, ignore) - int count, ignore; +rl_call_last_kbd_macro (int count, int ignore) { if (current_macro == 0) _rl_abort_internal (); @@ -277,8 +304,7 @@ rl_call_last_kbd_macro (count, ignore) } int -rl_print_last_kbd_macro (count, ignore) - int count, ignore; +rl_print_last_kbd_macro (int count, int ignore) { char *m; @@ -300,8 +326,7 @@ rl_print_last_kbd_macro (count, ignore) } void -rl_push_macro_input (macro) - char *macro; +rl_push_macro_input (char *macro) { _rl_with_macro_input (macro); } |