summaryrefslogtreecommitdiff
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
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
-rw-r--r--amiga/misc.h9
-rwxr-xr-xatari/misc.h9
-rwxr-xr-xatari/plot/plot.c1
-rw-r--r--beos/gui.h9
-rw-r--r--cocoa/NetsurfApp.m12
-rw-r--r--cocoa/utils.m4
-rw-r--r--content/urldb.c27
-rw-r--r--content/urldb.h2
-rw-r--r--framebuffer/gui.c13
-rw-r--r--framebuffer/misc.c5
-rw-r--r--gtk/gui.c18
-rw-r--r--monkey/dispatch.c9
-rw-r--r--monkey/dispatch.h2
-rw-r--r--monkey/main.c25
-rw-r--r--monkey/utils.c5
-rw-r--r--riscos/gui.h9
-rw-r--r--utils/utils.h1
-rw-r--r--windows/main.c12
-rw-r--r--windows/misc.c4
19 files changed, 133 insertions, 43 deletions
diff --git a/amiga/misc.h b/amiga/misc.h
index db559f78a..ce2d94793 100644
--- a/amiga/misc.h
+++ b/amiga/misc.h
@@ -24,5 +24,14 @@ extern struct gui_file_table *amiga_file_table;
char *translate_escape_chars(const char *s);
int32 ami_warn_user_multi(const char *body, const char *opt1, const char *opt2, struct Window *win);
+/**
+ * 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.
+ */
+void die(const char * const error) __attribute__ ((noreturn));
+
#endif
diff --git a/atari/misc.h b/atari/misc.h
index 8d1719ce8..418f28308 100755
--- a/atari/misc.h
+++ b/atari/misc.h
@@ -66,4 +66,13 @@ const char * file_select(const char * title, const char * name);
*/
long nkc_to_input_key(short nkc, long * ucs4_out);
+/**
+ * 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.
+ */
+void die(const char * const error) __attribute__ ((noreturn));
+
#endif
diff --git a/atari/plot/plot.c b/atari/plot/plot.c
index a0b99e5ae..1b949d22a 100755
--- a/atari/plot/plot.c
+++ b/atari/plot/plot.c
@@ -32,6 +32,7 @@
#include "desktop/plotters.h"
#include "desktop/mouse.h"
+#include "atari/misc.h"
#include "atari/bitmap.h"
#include "utils/nsoption.h"
#include "atari/plot/plot.h"
diff --git a/beos/gui.h b/beos/gui.h
index 6689bd81a..215cda8b1 100644
--- a/beos/gui.h
+++ b/beos/gui.h
@@ -67,3 +67,12 @@ void nsbeos_gui_view_source(struct hlcache_handle *content);
image_id nsbeos_find_app_path(char *path);
void nsbeos_update_system_ui_colors(void);
+
+/**
+ * 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.
+ */
+void die(const char * const error) __attribute__ ((noreturn));
diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m
index 3bd5f43f8..d76aee10c 100644
--- a/cocoa/NetsurfApp.m
+++ b/cocoa/NetsurfApp.m
@@ -49,6 +49,18 @@
static bool cocoa_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)
+{
+ [NSException raise: @"NetsurfDie" format: @"Error: %s", error];
+}
+
- (void) loadOptions;
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
diff --git a/cocoa/utils.m b/cocoa/utils.m
index 61226ad2a..b49e503d0 100644
--- a/cocoa/utils.m
+++ b/cocoa/utils.m
@@ -22,10 +22,6 @@
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
-void die(const char * const error)
-{
- [NSException raise: @"NetsurfDie" format: @"Error: %s", error];
-}
void warn_user(const char *warning, const char *detail)
{
diff --git a/content/urldb.c b/content/urldb.c
index c74dae36d..650c7bc51 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -343,7 +343,7 @@ static struct bloom_filter *url_bloom;
*
* \param filename Name of file containing data
*/
-void urldb_load(const char *filename)
+nserror urldb_load(const char *filename)
{
#define MAXIMUM_URL_LENGTH 4096
char s[MAXIMUM_URL_LENGTH];
@@ -365,24 +365,24 @@ void urldb_load(const char *filename)
fp = fopen(filename, "r");
if (!fp) {
LOG(("Failed to open file '%s' for reading", filename));
- return;
+ return NSERROR_NOT_FOUND;
}
if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) {
fclose(fp);
- return;
+ return NSERROR_NEED_DATA;
}
version = atoi(s);
if (version < MIN_URL_FILE_VERSION) {
LOG(("Unsupported URL file version."));
fclose(fp);
- return;
+ return NSERROR_INVALID;
}
if (version > URL_FILE_VERSION) {
LOG(("Unknown URL file version."));
fclose(fp);
- return;
+ return NSERROR_INVALID;
}
while (fgets(host, sizeof host, fp)) {
@@ -417,7 +417,8 @@ void urldb_load(const char *filename)
h = urldb_add_host(host);
if (!h) {
LOG(("Failed adding host: '%s'", host));
- die("Memory exhausted whilst loading URL file");
+ fclose(fp);
+ return NSERROR_NOMEM;
}
/* load the non-corrupt data */
@@ -467,8 +468,8 @@ void urldb_load(const char *filename)
*/
if (nsurl_create(url, &nsurl) != NSERROR_OK) {
LOG(("Failed inserting '%s'", url));
- die("Memory exhausted whilst loading "
- "URL file");
+ fclose(fp);
+ return NSERROR_NOMEM;
}
if (url_bloom != NULL) {
@@ -480,8 +481,8 @@ void urldb_load(const char *filename)
if (nsurl_get(nsurl, NSURL_PATH | NSURL_QUERY,
&path_query, &len) != NSERROR_OK) {
LOG(("Failed inserting '%s'", url));
- die("Memory exhausted whilst loading "
- "URL file");
+ fclose(fp);
+ return NSERROR_NOMEM;
}
scheme_lwc = nsurl_get_component(nsurl, NSURL_SCHEME);
@@ -491,8 +492,8 @@ void urldb_load(const char *filename)
fragment_lwc, nsurl);
if (!p) {
LOG(("Failed inserting '%s'", url));
- die("Memory exhausted whilst loading "
- "URL file");
+ fclose(fp);
+ return NSERROR_NOMEM;
}
nsurl_unref(nsurl);
lwc_string_unref(scheme_lwc);
@@ -533,6 +534,8 @@ void urldb_load(const char *filename)
fclose(fp);
LOG(("Successfully loaded URL file"));
#undef MAXIMUM_URL_LENGTH
+
+ return NSERROR_OK;
}
/**
diff --git a/content/urldb.h b/content/urldb.h
index d60043089..c0fece24e 100644
--- a/content/urldb.h
+++ b/content/urldb.h
@@ -68,7 +68,7 @@ struct bitmap;
void urldb_destroy(void);
/* Persistence support */
-void urldb_load(const char *filename);
+nserror urldb_load(const char *filename);
void urldb_save(const char *filename);
void urldb_set_url_persistence(nsurl *url, bool persist);
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 992b19255..180c2614e 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -97,6 +97,19 @@ static struct gui_drag {
} gui_drag;
+/**
+ * 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 *error)
+{
+ LOG(("%s", error));
+ exit(1);
+}
+
/* queue a redraw operation, co-ordinates are relative to the window */
static void
fb_queue_redraw(struct fbtk_widget_s *widget, int x0, int y0, int x1, int y1)
diff --git a/framebuffer/misc.c b/framebuffer/misc.c
index 0a45b2842..406a959d3 100644
--- a/framebuffer/misc.c
+++ b/framebuffer/misc.c
@@ -30,9 +30,4 @@ void warn_user(const char *warning, const char *detail)
LOG(("%s %s", warning, detail));
}
-void die(const char *error)
-{
- LOG(("%s", error));
- exit(1);
-}
diff --git a/gtk/gui.c b/gtk/gui.c
index da993ac10..eeba46619 100644
--- a/gtk/gui.c
+++ b/gtk/gui.c
@@ -106,6 +106,19 @@ static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data);
char **respaths; /** resource search path vector */
+/**
+ * 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, "%s", error);
+ exit(EXIT_FAILURE);
+}
+
/** Create an array of valid paths to search for resources.
*
* The idea is that all the complex path computation to find resources
@@ -584,11 +597,6 @@ void warn_user(const char *warning, const char *detail)
gtk_widget_show_all(GTK_WIDGET(nsgtk_warning_window));
}
-void die(const char * const error)
-{
- fprintf(stderr, "%s", error);
- exit(EXIT_FAILURE);
-}
static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
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);
-}
diff --git a/riscos/gui.h b/riscos/gui.h
index 9077afeab..9e7704f39 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -120,6 +120,15 @@ void ro_gui_drag_box_start(wimp_pointer *pointer);
bool ro_gui_prequit(void);
const char *ro_gui_default_language(void);
+/**
+ * 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.
+ */
+void die(const char * const error) __attribute__ ((noreturn));
+
/* in download.c */
void ro_gui_download_init(void);
void ro_gui_download_datasave_ack(wimp_message *message);
diff --git a/utils/utils.h b/utils/utils.h
index 9be859e59..b90843271 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -257,7 +257,6 @@ nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...);
int dir_sort_alpha(const struct dirent **d1, const struct dirent **d2);
/* Platform specific functions */
-void die(const char * const error) __attribute__ ((noreturn));
void warn_user(const char *warning, const char *detail);
void PDF_Password(char **owner_pass, char **user_pass, char *path);
diff --git a/windows/main.c b/windows/main.c
index 09198d5d0..86e06b193 100644
--- a/windows/main.c
+++ b/windows/main.c
@@ -43,6 +43,18 @@ static char **respaths; /** resource search path vector. */
char *options_file_location;
+/**
+ * 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 *error)
+{
+ exit(1);
+}
+
static nsurl *gui_get_resource_url(const char *path)
{
char buf[PATH_MAX];
diff --git a/windows/misc.c b/windows/misc.c
index 3bf06f852..ad7ce0d84 100644
--- a/windows/misc.c
+++ b/windows/misc.c
@@ -37,8 +37,4 @@ void warn_user(const char *warning, const char *detail)
MessageBox(NULL, message, "Warning", MB_ICONWARNING);
}
-void die(const char *error)
-{
- exit(1);
-}