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
This commit is contained in:
Vincent Sanders 2014-10-26 12:42:53 +00:00
parent a913af5cf5
commit 14e2829489
19 changed files with 133 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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));

View File

@ -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];

View File

@ -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)
{

View File

@ -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;
}
/**

View File

@ -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);

View File

@ -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)

View File

@ -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);
}

View File

@ -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,

View File

@ -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

View File

@ -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);

View File

@ -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");

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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];

View File

@ -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);
}