diff options
author | pommicket <pommicket@gmail.com> | 2023-08-12 10:41:22 -0300 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-08-12 10:41:22 -0300 |
commit | dbf441cdc74245c5a5f567ae0165146cd74c3b92 (patch) | |
tree | f1ca3bdf3102445a000bbc6e2695333150d0c0a2 /macro.c | |
parent | a974b6192479e5f7f6d6fcc328313c76290f486d (diff) |
more internralization
Diffstat (limited to 'macro.c')
-rw-r--r-- | macro.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -1,7 +1,17 @@ #include "ted-internal.h" +typedef struct MacroAction { + Command command; + CommandArgument argument; +} MacroAction; + +struct Macro { + // dynamic array + MacroAction *actions; +}; + static void macro_clear(Macro *macro) { - arr_foreach_ptr(macro->actions, Action, act) { + arr_foreach_ptr(macro->actions, MacroAction, act) { free((char *)act->argument.string); } arr_free(macro->actions); @@ -34,7 +44,7 @@ void macro_add(Ted *ted, Command command, const CommandArgument *argument) { CommandArgument arg = *argument; if (arg.string) arg.string = str_dup(arg.string); - Action action = { + MacroAction action = { .command = command, .argument = arg }; @@ -51,15 +61,21 @@ void macro_execute(Ted *ted, u32 index) { ted->executing_macro = true; const CommandContext context = {.running_macro = true}; - arr_foreach_ptr(macro->actions, Action, act) { + arr_foreach_ptr(macro->actions, MacroAction, act) { command_execute_ex(ted, act->command, &act->argument, &context); } ted->executing_macro = false; } +void macros_init(Ted *ted) { + ted->macros = calloc(TED_MACRO_MAX, sizeof *ted->macros); +} + void macros_free(Ted *ted) { for (int i = 0; i < TED_MACRO_MAX; ++i) { Macro *macro = &ted->macros[i]; macro_clear(macro); } + free(ted->macros); + ted->macros = NULL; } |