summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-10-26 12:42:53 +0000
committerVincent Sanders <vince@kyllikki.org>2014-10-26 12:42:53 +0000
commit14e282948996f75e87a14ab90f4b3ed54d9d6ad7 (patch)
tree7f78ad2cc5c9965f6a329c81c025d1c240eb4f87 /monkey
parenta913af5cf54400b441f3b1fbfc5d508cf85fea43 (diff)
downloadnetsurf-14e282948996f75e87a14ab90f4b3ed54d9d6ad7.tar.gz
netsurf-14e282948996f75e87a14ab90f4b3ed54d9d6ad7.tar.bz2
remove the die API from the core.
The die() API for abnormal termination does not belong within the core of netsurf and instead errors are propogated back to the callers. This is the final part of this change and the API is now only used within some parts of the frontends
Diffstat (limited to 'monkey')
-rw-r--r--monkey/dispatch.c9
-rw-r--r--monkey/dispatch.h2
-rw-r--r--monkey/main.c25
-rw-r--r--monkey/utils.c5
4 files changed, 30 insertions, 11 deletions
diff --git a/monkey/dispatch.c b/monkey/dispatch.c
index 9d022560c..c70070d4e 100644
--- a/monkey/dispatch.c
+++ b/monkey/dispatch.c
@@ -35,15 +35,18 @@ typedef struct cmdhandler {
static monkey_cmdhandler_t *handler_ring = NULL;
-void
+nserror
monkey_register_handler(const char *cmd, handle_command_fn fn)
{
monkey_cmdhandler_t *ret = calloc(sizeof(*ret), 1);
- if (ret == NULL)
- die("Unable to allocate handler");
+ if (ret == NULL) {
+ LOG(("Unable to allocate handler"));
+ return NSERROR_NOMEM;
+ }
ret->cmd = strdup(cmd);
ret->fn = fn;
RING_INSERT(handler_ring, ret);
+ return NSERROR_OK;
}
void
diff --git a/monkey/dispatch.h b/monkey/dispatch.h
index fe8f4e2f8..dc6e50a0b 100644
--- a/monkey/dispatch.h
+++ b/monkey/dispatch.h
@@ -21,7 +21,7 @@
typedef void (*handle_command_fn)(int argc, char **argv);
-void monkey_register_handler(const char *cmd, handle_command_fn fn);
+nserror monkey_register_handler(const char *cmd, handle_command_fn fn);
void monkey_process_command(void);
diff --git a/monkey/main.c b/monkey/main.c
index 77ef831b1..289017d94 100644
--- a/monkey/main.c
+++ b/monkey/main.c
@@ -42,6 +42,19 @@ char **respaths; /** resource search path vector */
static bool monkey_done = false;
+/**
+ * Cause an abnormal program termination.
+ *
+ * \note This never returns and is intended to terminate without any cleanup.
+ *
+ * \param error The message to display to the user.
+ */
+static void die(const char * const error)
+{
+ fprintf(stderr, "DIE %s\n", error);
+ exit(EXIT_FAILURE);
+}
+
/* Stolen from gtk/gui.c */
static char **
nsmonkey_init_resource(const char *resource_path)
@@ -174,8 +187,16 @@ main(int argc, char **argv)
urldb_load_cookies(nsoption_charp(cookie_file));
monkey_prepare_input();
- monkey_register_handler("QUIT", quit_handler);
- monkey_register_handler("WINDOW", monkey_window_handle_command);
+
+ ret = monkey_register_handler("QUIT", quit_handler);
+ if (ret != NSERROR_OK) {
+ die("quit handler failed to register");
+ }
+
+ ret = monkey_register_handler("WINDOW", monkey_window_handle_command);
+ if (ret != NSERROR_OK) {
+ die("window handler fialed to register");
+ }
fprintf(stdout, "GENERIC STARTED\n");
diff --git a/monkey/utils.c b/monkey/utils.c
index e1a702f2f..102f8ac01 100644
--- a/monkey/utils.c
+++ b/monkey/utils.c
@@ -28,8 +28,3 @@ void warn_user(const char *warning, const char *detail)
fprintf(stderr, "WARN %s %s\n", warning, detail);
}
-void die(const char * const error)
-{
- fprintf(stderr, "DIE %s\n", error);
- exit(EXIT_FAILURE);
-}