From 9bfb31fcbee028eaecce75a743f2a0bd50b5807c Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Tue, 28 May 2024 07:54:34 -0600 Subject: remove the vis->initialized member I already fixed the reason that this even existed (vis_event_emit getting called at random times when the editor wasn't ready). The option checking in main() was moved up because I noticed it was in the wrong place while thinking about where to emit the INIT event. There is no reason to do a bunch of useless work just to print the version. --- main.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 85330cb..3e9d9ab 100644 --- a/main.c +++ b/main.c @@ -2214,10 +2214,34 @@ static void signal_handler(int signum, siginfo_t *siginfo, void *context) { } int main(int argc, char *argv[]) { + for (int i = 1; i < argc; i++) { + if (argv[i][0] != '-') { + continue; + } else if (strcmp(argv[i], "-") == 0) { + continue; + } else if (strcmp(argv[i], "--") == 0) { + break; + } else if (strcmp(argv[i], "-v") == 0) { + printf("vis %s%s%s%s%s%s%s\n", VERSION, + CONFIG_CURSES ? " +curses" : "", + CONFIG_LUA ? " +lua" : "", + CONFIG_LPEG ? " +lpeg" : "", + CONFIG_TRE ? " +tre" : "", + CONFIG_ACL ? " +acl" : "", + CONFIG_SELINUX ? " +selinux" : ""); + return 0; + } else { + fprintf(stderr, "Unknown command option: %s\n", argv[i]); + return 1; + } + } + vis = vis_new(); if (!vis) return EXIT_FAILURE; + vis_event_emit(vis, VIS_EVENT_INIT); + for (int i = 0; i < LENGTH(vis_action); i++) { const KeyAction *action = &vis_action[i]; if (!vis_action_register(vis, action)) @@ -2264,28 +2288,6 @@ int main(int argc, char *argv[]) { if (sigprocmask(SIG_BLOCK, &blockset, NULL) == -1) vis_die(vis, "Failed to block signals\n"); - for (int i = 1; i < argc; i++) { - if (argv[i][0] != '-') { - continue; - } else if (strcmp(argv[i], "-") == 0) { - continue; - } else if (strcmp(argv[i], "--") == 0) { - break; - } else if (strcmp(argv[i], "-v") == 0) { - printf("vis %s%s%s%s%s%s%s\n", VERSION, - CONFIG_CURSES ? " +curses" : "", - CONFIG_LUA ? " +lua" : "", - CONFIG_LPEG ? " +lpeg" : "", - CONFIG_TRE ? " +tre" : "", - CONFIG_ACL ? " +acl" : "", - CONFIG_SELINUX ? " +selinux" : ""); - return 0; - } else { - fprintf(stderr, "Unknown command option: %s\n", argv[i]); - return 1; - } - } - char *cmd = NULL; bool end_of_options = false, win_created = false; -- cgit v1.2.3