aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-05-18 18:23:25 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-05-18 18:23:25 +0300
commitfe3535dbeec8f3f0fca9e6b895c993e59846e103 (patch)
tree10a20d25edf32adb45739ce6f2cc626b98a7391d /src/main.c
parent394fe39825cf4fc2f12ad511d8fea2bb61ee4837 (diff)
downloadsciteco-fe3535dbeec8f3f0fca9e6b895c993e59846e103.tar.gz
allow process exit status to be determined by macros
* Any value left on the numeric stack now determines the exit code. This ensures you can call n^C as the SciTECO version of exit(n). It will also work with n$$ in the top level macro. But you don't necessarily need any of these commands. * Could be useful in shell scripting as in `sciteco -e "@EB/file/ :@S/foo/\"F1'"` to fail `foo` is not found.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 05f8c41..e57ab6f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,6 +35,7 @@
#endif
#include "sciteco.h"
+#include "expressions.h"
#include "file-utils.h"
#include "cmdline.h"
#include "interface.h"
@@ -337,6 +338,7 @@ main(int argc, char **argv)
#endif
{
g_autoptr(GError) error = NULL;
+ teco_int_t ret = EXIT_SUCCESS;
#ifdef DEBUG_PAUSE
/* Windows debugging hack (see above) */
@@ -461,7 +463,8 @@ main(int argc, char **argv)
}
g_clear_error(&error);
- if (!teco_ed_hook(TECO_ED_HOOK_QUIT, &error))
+ if (!teco_expressions_pop_num_calc(&ret, EXIT_SUCCESS, &error) ||
+ !teco_ed_hook(TECO_ED_HOOK_QUIT, &error))
goto cleanup;
goto cleanup;
}
@@ -499,7 +502,8 @@ main(int argc, char **argv)
g_clear_error(&error);
if (teco_quit_requested) {
- if (!teco_ed_hook(TECO_ED_HOOK_QUIT, &error))
+ if (!teco_expressions_pop_num_calc(&ret, EXIT_SUCCESS, &error) ||
+ !teco_ed_hook(TECO_ED_HOOK_QUIT, &error))
goto cleanup;
goto cleanup;
}
@@ -553,8 +557,10 @@ main(int argc, char **argv)
goto cleanup;
cleanup:
- if (error != NULL)
+ if (error != NULL) {
teco_error_display_full(error);
+ ret = EXIT_FAILURE;
+ }
#ifndef NDEBUG
teco_ring_cleanup();
@@ -565,5 +571,5 @@ cleanup:
#endif
teco_interface_cleanup();
- return error ? EXIT_FAILURE : EXIT_SUCCESS;
+ return ret;
}