aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-21 19:36:01 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-21 19:36:01 +0100
commit16a47e287f44f4ea154f9bfc1d3a6fa083a0f43e (patch)
tree6ceb4f16b271f85a00eb2e969ad9999e34369928 /src/main.cpp
parentefa646da494c659d24bc1f09936645eed1a10244 (diff)
downloadsciteco-16a47e287f44f4ea154f9bfc1d3a6fa083a0f43e.tar.gz
finally implemented the CLOSE and QUIT hooks
the QUIT hook is actually not that trivial and required some architectural changes. First, the QUIT hook execution and any error that might occurr cannot always be attached to an existing error stack frame. Thereforce, to give a stack frame for QUIT hooks and to improve the readability of error traces for ED hooks in general, a special EDHookFrame is added to every ED hook execution error. Secondly, since QUIT hooks can themselves throw errors, we cannot run it from an atexit() handler. Instead it's always called manually before __successful__ program termination. An error in a QUIT hook will result in a failure return code nevertheless. Thirdly, errors in QUIT hooks should not prevent program termination (in interactive mode), therefore they are only invoked from main() and always in batch mode. I.e. if the interactive mode is terminated (EX$$), SciTECO will switch back to batch mode and run the QUIT hook there. This is also symmetric to program startup, which is always in batch mode. This means that Interface::event_loop() no longer runs indefinitely. If it returns, this signals that the interface shut down and batch mode may be restored by SciTECO.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 5697063..e7cf62b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -308,6 +308,11 @@ main(int argc, char **argv)
/* add remaining arguments to unnamed buffer */
for (int i = 1; i < argc; i++) {
+ /*
+ * FIXME: arguments may contain line-feeds.
+ * Once SciTECO is 8-byte clear, we can add the
+ * command-line params null-terminated.
+ */
interface.ssm(SCI_APPENDTEXT, strlen(argv[i]), (sptr_t)argv[i]);
interface.ssm(SCI_APPENDTEXT, 1, (sptr_t)"\n");
}
@@ -323,6 +328,7 @@ main(int argc, char **argv)
error.add_frame(new Error::ToplevelFrame());
throw; /* forward */
}
+ QRegisters::hook(QRegisters::HOOK_QUIT);
exit(EXIT_SUCCESS);
}
@@ -331,7 +337,7 @@ main(int argc, char **argv)
/* FIXME: make quit immediate in batch/macro mode (non-UNDO)? */
if (quit_requested) {
- /* FIXME */
+ QRegisters::hook(QRegisters::HOOK_QUIT);
exit(EXIT_SUCCESS);
}
}
@@ -355,5 +361,21 @@ main(int argc, char **argv)
interface.event_loop();
+ /*
+ * Ordinary application termination:
+ * Interface is shut down, so we are
+ * in non-interactive mode again.
+ */
+ undo.enabled = false;
+ interface.ssm(SCI_EMPTYUNDOBUFFER);
+ undo.clear();
+
+ try {
+ QRegisters::hook(QRegisters::HOOK_QUIT);
+ } catch (Error &error) {
+ error.display_full();
+ exit(EXIT_FAILURE);
+ }
+
return 0;
}