version 1.1.1.1, 2014/07/30 08:16:45
|
version 1.1.1.2, 2021/03/17 01:01:01
|
Line 1
|
Line 1
|
/* macro.c -- keyboard macros for readline. */ |
/* 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 |
This file is part of the GNU Readline Library (Readline), a library |
for reading lines of text with interactive input and history editing. |
for reading lines of text with interactive input and history editing. |
Line 49
|
Line 49
|
#include "rlprivate.h" |
#include "rlprivate.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
|
|
|
#define MAX_MACRO_LEVEL 16 |
|
|
/* **************************************************************** */ |
/* **************************************************************** */ |
/* */ |
/* */ |
/* Hacking Keyboard Macros */ |
/* Hacking Keyboard Macros */ |
Line 83 struct saved_macro {
|
Line 85 struct saved_macro {
|
/* The list of saved macros. */ |
/* The list of saved macros. */ |
static struct saved_macro *macro_list = (struct saved_macro *)NULL; |
static struct saved_macro *macro_list = (struct saved_macro *)NULL; |
|
|
|
static int macro_level = 0; |
|
|
/* Set up to read subsequent input from STRING. |
/* Set up to read subsequent input from STRING. |
STRING is free ()'ed when we are done with it. */ |
STRING is free ()'ed when we are done with it. */ |
void |
void |
_rl_with_macro_input (string) | _rl_with_macro_input (char *string) |
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; |
rl_executing_macro = string; |
executing_macro_index = 0; |
executing_macro_index = 0; |
RL_SETSTATE(RL_STATE_MACROINPUT); |
RL_SETSTATE(RL_STATE_MACROINPUT); |
Line 98 _rl_with_macro_input (string)
|
Line 111 _rl_with_macro_input (string)
|
/* Return the next character available from a macro, or 0 if |
/* Return the next character available from a macro, or 0 if |
there are no macro characters. */ |
there are no macro characters. */ |
int |
int |
_rl_next_macro_key () | _rl_next_macro_key (void) |
{ |
{ |
int c; |
int c; |
|
|
Line 117 _rl_next_macro_key ()
|
Line 130 _rl_next_macro_key ()
|
_rl_pop_executing_macro (); |
_rl_pop_executing_macro (); |
return c; |
return c; |
#else |
#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++]); |
return (rl_executing_macro[executing_macro_index++]); |
#endif |
#endif |
} |
} |
|
|
int |
int |
_rl_prev_macro_key () | _rl_peek_macro_key (void) |
{ |
{ |
if (rl_executing_macro == 0) |
if (rl_executing_macro == 0) |
return (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); |
|
|
if (executing_macro_index == 0) |
if (executing_macro_index == 0) |
return (0); |
return (0); |
|
|
Line 136 _rl_prev_macro_key ()
|
Line 163 _rl_prev_macro_key ()
|
|
|
/* Save the currently executing macro on a stack of saved macros. */ |
/* Save the currently executing macro on a stack of saved macros. */ |
void |
void |
_rl_push_executing_macro () | _rl_push_executing_macro (void) |
{ |
{ |
struct saved_macro *saver; |
struct saved_macro *saver; |
|
|
Line 146 _rl_push_executing_macro ()
|
Line 173 _rl_push_executing_macro ()
|
saver->string = rl_executing_macro; |
saver->string = rl_executing_macro; |
|
|
macro_list = saver; |
macro_list = saver; |
|
|
|
macro_level++; |
} |
} |
|
|
/* Discard the current macro, replacing it with the one |
/* Discard the current macro, replacing it with the one |
on the top of the stack of saved macros. */ |
on the top of the stack of saved macros. */ |
void |
void |
_rl_pop_executing_macro () | _rl_pop_executing_macro (void) |
{ |
{ |
struct saved_macro *macro; |
struct saved_macro *macro; |
|
|
Line 168 _rl_pop_executing_macro ()
|
Line 197 _rl_pop_executing_macro ()
|
xfree (macro); |
xfree (macro); |
} |
} |
|
|
|
macro_level--; |
|
|
if (rl_executing_macro == 0) |
if (rl_executing_macro == 0) |
RL_UNSETSTATE(RL_STATE_MACROINPUT); |
RL_UNSETSTATE(RL_STATE_MACROINPUT); |
} |
} |
|
|
/* Add a character to the macro being built. */ |
/* Add a character to the macro being built. */ |
void |
void |
_rl_add_macro_char (c) | _rl_add_macro_char (int c) |
int c; | |
{ |
{ |
if (current_macro_index + 1 >= current_macro_size) |
if (current_macro_index + 1 >= current_macro_size) |
{ |
{ |
Line 190 _rl_add_macro_char (c)
|
Line 220 _rl_add_macro_char (c)
|
} |
} |
|
|
void |
void |
_rl_kill_kbd_macro () | _rl_kill_kbd_macro (void) |
{ |
{ |
if (current_macro) |
if (current_macro) |
{ |
{ |
Line 213 _rl_kill_kbd_macro ()
|
Line 243 _rl_kill_kbd_macro ()
|
definition to the end of the existing macro, and start by |
definition to the end of the existing macro, and start by |
re-executing the existing macro. */ |
re-executing the existing macro. */ |
int |
int |
rl_start_kbd_macro (ignore1, ignore2) | rl_start_kbd_macro (int ignore1, int ignore2) |
int ignore1, ignore2; | |
{ |
{ |
if (RL_ISSTATE (RL_STATE_MACRODEF)) |
if (RL_ISSTATE (RL_STATE_MACRODEF)) |
{ |
{ |
_rl_abort_internal (); |
_rl_abort_internal (); |
return -1; | return 1; |
} |
} |
|
|
if (rl_explicit_arg) |
if (rl_explicit_arg) |
Line 238 rl_start_kbd_macro (ignore1, ignore2)
|
Line 267 rl_start_kbd_macro (ignore1, ignore2)
|
A numeric argument says to execute the macro right now, |
A numeric argument says to execute the macro right now, |
that many times, counting the definition as the first time. */ |
that many times, counting the definition as the first time. */ |
int |
int |
rl_end_kbd_macro (count, ignore) | rl_end_kbd_macro (int count, int ignore) |
int count, ignore; | |
{ |
{ |
if (RL_ISSTATE (RL_STATE_MACRODEF) == 0) |
if (RL_ISSTATE (RL_STATE_MACRODEF) == 0) |
{ |
{ |
_rl_abort_internal (); |
_rl_abort_internal (); |
return -1; | return 1; |
} |
} |
|
|
current_macro_index -= rl_key_sequence_length; |
current_macro_index -= rl_key_sequence_length; |
Line 258 rl_end_kbd_macro (count, ignore)
|
Line 286 rl_end_kbd_macro (count, ignore)
|
/* Execute the most recently defined keyboard macro. |
/* Execute the most recently defined keyboard macro. |
COUNT says how many times to execute it. */ |
COUNT says how many times to execute it. */ |
int |
int |
rl_call_last_kbd_macro (count, ignore) | rl_call_last_kbd_macro (int count, int ignore) |
int count, ignore; | |
{ |
{ |
if (current_macro == 0) |
if (current_macro == 0) |
_rl_abort_internal (); |
_rl_abort_internal (); |
Line 277 rl_call_last_kbd_macro (count, ignore)
|
Line 304 rl_call_last_kbd_macro (count, ignore)
|
} |
} |
|
|
int |
int |
rl_print_last_kbd_macro (count, ignore) | rl_print_last_kbd_macro (int count, int ignore) |
int count, ignore; | |
{ |
{ |
char *m; |
char *m; |
|
|
Line 300 rl_print_last_kbd_macro (count, ignore)
|
Line 326 rl_print_last_kbd_macro (count, ignore)
|
} |
} |
|
|
void |
void |
rl_push_macro_input (macro) | rl_push_macro_input (char *macro) |
char *macro; | |
{ |
{ |
_rl_with_macro_input (macro); |
_rl_with_macro_input (macro); |
} |
} |