1 #include "cmd-io/macro-util.h"
3 /* Array of macro types [MACRO_MAX] */
6 /* Current macro action [1024] */
9 /* Array of macro patterns [MACRO_MAX] */
12 /* Array of macro actions [MACRO_MAX] */
15 /* Number of active macros */
18 /* Expand macros in "get_com" or not */
19 bool get_com_no_macros = FALSE;
21 /* Determine if any macros have ever started with a given character */
22 static bool macro__use[256];
24 /* Find the macro (if any) which exactly matches the given pattern */
25 int macro_find_exact(concptr pat)
27 if (!macro__use[(byte)(pat[0])]) {
31 for (int i = 0; i < macro__num; ++i) {
32 if (!streq(macro__pat[i], pat))
42 * Find the first macro (if any) which contains the given pattern
44 int macro_find_check(concptr pat)
46 if (!macro__use[(byte)(pat[0])]) {
50 for (int i = 0; i < macro__num; ++i) {
51 if (!prefix(macro__pat[i], pat))
61 * Find the first macro (if any) which contains the given pattern and more
63 int macro_find_maybe(concptr pat)
65 if (!macro__use[(byte)(pat[0])]) {
69 for (int i = 0; i < macro__num; ++i) {
70 if (!prefix(macro__pat[i], pat))
72 if (streq(macro__pat[i], pat))
82 * Find the longest macro (if any) which starts with the given pattern
84 int macro_find_ready(concptr pat)
86 int t, n = -1, s = -1;
88 if (!macro__use[(byte)(pat[0])]) {
92 for (int i = 0; i < macro__num; ++i) {
93 if (!prefix(pat, macro__pat[i]))
96 t = strlen(macro__pat[i]);
97 if ((n >= 0) && (s > t))
108 * Add a macro definition (or redefinition).
110 * We should use "act == NULL" to "remove" a macro, but this might make it
111 * impossible to save the "removal" of a macro definition.
113 * We should consider refusing to allow macros which contain existing macros,
114 * or which are contained in existing macros, because this would simplify the
115 * macro analysis code.
117 * We should consider removing the "command macro" crap, and replacing it
118 * with some kind of "powerful keymap" ability, but this might make it hard
119 * to change the "roguelike" option from inside the game.
121 errr macro_add(concptr pat, concptr act)
126 int n = macro_find_exact(pat);
128 string_free(macro__act[n]);
131 macro__pat[n] = string_make(pat);
134 macro__act[n] = string_make(act);
135 macro__use[(byte)(pat[0])] = TRUE;