aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core-commands.c9
-rw-r--r--src/main.c14
2 files changed, 18 insertions, 5 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index 141ce0a..337e8df 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1320,7 +1320,7 @@ teco_state_control_xor(teco_machine_main_t *ctx, GError **error)
}
/*$ ^C exit
- * ^C -- Exit program immediately
+ * [n]^C -- Exit program immediately
*
* Lets the top-level macro return immediately
* regardless of the current macro invocation frame.
@@ -1333,6 +1333,10 @@ teco_state_control_xor(teco_machine_main_t *ctx, GError **error)
* effectively just like \(lq-EX\fB$$\fP\(rq
* (when executed in the top-level macro at least).
*
+ * Any numeric parameter is returned by the process
+ * as its exit status.
+ * By default, the success code is returned.
+ *
* The \fBquit\fP hook is still executed.
*/
static void
@@ -1678,6 +1682,9 @@ teco_state_escape_input(teco_machine_main_t *ctx, gunichar chr, GError **error)
* Returning from the top-level macro in batch mode
* will exit the program or start up interactive mode depending
* on whether program exit has been requested.
+ * If \fB$$\fP exits the program, any remaining numeric parameter
+ * is returned by the process as its exit status.
+ * By default, the success code is returned.
* \(lqEX\fB$$\fP\(rq is thus a common idiom to exit
* prematurely.
*
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;
}