1 #include "cmd-io/macro-util.h"
3 /* Current macro action [1024] */
4 std::vector<char> macro__buf;
6 /* Array of macro patterns [MACRO_MAX] */
7 std::vector<std::string> macro__pat;
9 /* Array of macro actions [MACRO_MAX] */
10 std::vector<std::string> macro__act;
12 /* Number of active macros */
15 /* Expand macros in "get_com" or not */
16 bool get_com_no_macros = false;
18 /* Determine if any macros have ever started with a given character */
19 static bool macro__use[256];
21 /* Find the macro (if any) which exactly matches the given pattern */
22 int macro_find_exact(concptr pat)
24 if (!macro__use[(byte)(pat[0])]) {
28 for (int i = 0; i < macro__num; ++i) {
29 if (!streq(macro__pat[i], pat)) {
40 * Find the first macro (if any) which contains the given pattern
42 int macro_find_check(concptr pat)
44 if (!macro__use[(byte)(pat[0])]) {
48 for (int i = 0; i < macro__num; ++i) {
49 if (!prefix(macro__pat[i], pat)) {
60 * Find the first macro (if any) which contains the given pattern and more
62 int macro_find_maybe(concptr pat)
64 if (!macro__use[(byte)(pat[0])]) {
68 for (int i = 0; i < macro__num; ++i) {
69 if (!prefix(macro__pat[i], pat)) {
72 if (streq(macro__pat[i], pat)) {
83 * Find the longest macro (if any) which starts with the given pattern
85 int macro_find_ready(concptr pat)
87 int t, n = -1, s = -1;
89 if (!macro__use[(byte)(pat[0])]) {
93 for (int i = 0; i < macro__num; ++i) {
94 if (!prefix(pat, macro__pat[i])) {
98 t = macro__pat[i].size();
99 if ((n >= 0) && (s > t)) {
111 * Add a macro definition (or redefinition).
113 * We should use "act == nullptr" to "remove" a macro, but this might make it
114 * impossible to save the "removal" of a macro definition.
116 * We should consider refusing to allow macros which contain existing macros,
117 * or which are contained in existing macros, because this would simplify the
118 * macro analysis code.
120 * We should consider removing the "command macro" crap, and replacing it
121 * with some kind of "powerful keymap" ability, but this might make it hard
122 * to change the "roguelike" option from inside the game.
124 errr macro_add(concptr pat, concptr act)
129 if (strlen(pat) == 0 || strlen(act) == 0) {
133 int n = macro_find_exact(pat);
140 macro__use[(byte)(pat[0])] = true;