Commit 95b463d9 authored by Dom Lachowicz's avatar Dom Lachowicz Committed by Dom Lachowicz

Use rsvg_return_if_fail where appropriate, to make life easier for

2006-04-19 Dom Lachowicz <cinamod@hotmail.com>

	* *.[ch]: Use rsvg_return_if_fail where appropriate, to make life
	easier for language bindings and to report errors more consistently
	(bug #338881)
parent 775b4043
2006-04-19 Dom Lachowicz <cinamod@hotmail.com>
* *.[ch]: Use rsvg_return_if_fail where appropriate, to make life
easier for language bindings and to report errors more consistently
(bug #338881)
2006-04-17 Sebastian Rittau <srittau@jroger.in-berlin.de>
* Update API documentation to match deprecated symbol list
......
......@@ -33,8 +33,8 @@ rsvg_handle_fill_with_data (RsvgHandle * handle,
gsize data_len,
GError **error)
{
g_return_val_if_fail(data != NULL, FALSE);
g_return_val_if_fail(data_len != 0, FALSE);
rsvg_return_val_if_fail(data != NULL, FALSE, error);
rsvg_return_val_if_fail(data_len != 0, FALSE, error);
if(!rsvg_handle_write (handle, data, data_len, error))
return FALSE;
......@@ -90,7 +90,7 @@ RsvgHandle * rsvg_handle_new_from_file (const gchar *file_name,
GByteArray *f;
RsvgHandle * handle = NULL;
g_return_val_if_fail(file_name != NULL, NULL);
rsvg_return_val_if_fail(file_name != NULL, NULL, error);
base_uri = rsvg_get_base_uri_from_filename(file_name);
f = _rsvg_acquire_xlink_href_resource (file_name, base_uri, error);
......
......@@ -785,7 +785,7 @@ rsvg_handle_write_impl (RsvgHandle *handle,
GError *real_error = NULL;
int result;
g_return_val_if_fail (handle != NULL, FALSE);
rsvg_return_val_if_fail (handle != NULL, FALSE, error);
handle->priv->error = &real_error;
if (handle->priv->ctxt == NULL)
......@@ -1082,9 +1082,10 @@ rsvg_handle_get_dimensions(RsvgHandle * handle, RsvgDimensionData * dimension_da
RsvgNodeSvg * sself;
RsvgBbox bbox;
g_return_if_fail(handle);
g_return_if_fail(dimension_data);
memset(dimension_data, 0, sizeof(RsvgDimensionData));
g_return_if_fail(handle);
sself = (RsvgNodeSvg *)handle->priv->treebase;
if(!sself)
......@@ -1253,7 +1254,7 @@ rsvg_handle_write (RsvgHandle *handle,
gsize count,
GError **error)
{
g_return_val_if_fail(handle, FALSE);
rsvg_return_val_if_fail(handle, FALSE, error);
if (handle->priv->first_write) {
handle->priv->first_write = FALSE;
......@@ -1296,7 +1297,7 @@ gboolean
rsvg_handle_close (RsvgHandle *handle,
GError **error)
{
g_return_val_if_fail(handle, FALSE);
rsvg_return_val_if_fail(handle, FALSE, error);
#if HAVE_SVGZ
if (handle->priv->is_gzipped) {
......@@ -1563,3 +1564,15 @@ void _rsvg_pop_view_box(RsvgDrawingCtx *ctx)
g_free(ctx->vb_stack->data);
ctx->vb_stack = g_slist_delete_link(ctx->vb_stack, ctx->vb_stack);
}
void rsvg_return_if_fail_warning (const char *pretty_function,
const char *expression,
GError **error)
{
g_set_error (error,
RSVG_ERROR,
0,
_("%s: assertion `%s' failed"),
pretty_function,
expression);
}
......@@ -48,6 +48,16 @@
#include <cairo-svg.h>
#endif
static void
display_error(GError *err)
{
if (err)
{
g_print ("%s", err->message);
g_error_free (err);
}
}
static RsvgHandle *
rsvg_handle_new_from_stdio_file (FILE * f,
GError **error)
......@@ -125,6 +135,7 @@ main (int argc, char **argv)
int keep_aspect_ratio = FALSE;
char * base_uri = NULL;
gboolean using_stdin = FALSE;
GError *error = NULL;
int i;
char **args;
......@@ -155,7 +166,8 @@ main (int argc, char **argv)
g_option_context = g_option_context_new (_("- SVG Converter"));
g_option_context_add_main_entries (g_option_context, options_table, NULL);
g_option_context_set_help_enabled (g_option_context, TRUE);
if(!g_option_context_parse (g_option_context, &argc, &argv, NULL)) {
if(!g_option_context_parse (g_option_context, &argc, &argv, &error)) {
display_error (error);
exit(1);
}
......@@ -172,7 +184,7 @@ main (int argc, char **argv)
output_file = fopen (output, "wb");
if (!output_file)
{
fprintf (stderr, _("Error saving to file %s\n"), output);
fprintf (stderr, _("Error saving to file: %s\n"), output);
exit (1);
}
}
......@@ -186,9 +198,9 @@ main (int argc, char **argv)
n_args = 1;
using_stdin = TRUE;
}
else if (n_args > 1 && (!format || !strcmp (format, "png")))
else if (n_args > 1 && (!format || !(!strcmp (format, "ps") || !strcmp (format, "pdf"))))
{
fprintf (stderr, _("Multiple SVG files are only allowed for PDF, PS and SVG output.\n"));
fprintf (stderr, _("Multiple SVG files are only allowed for PDF and PS output.\n"));
exit (1);
}
......@@ -201,12 +213,14 @@ main (int argc, char **argv)
for(i = 0; i < n_args; i++)
{
if (using_stdin)
rsvg = rsvg_handle_new_from_stdio_file (stdin, NULL);
rsvg = rsvg_handle_new_from_stdio_file (stdin, &error);
else
rsvg = rsvg_handle_new_from_file (args[i], NULL);
rsvg = rsvg_handle_new_from_file (args[i], &error);
if(!rsvg) {
fprintf (stderr, _("Error reading SVG.\n"));
fprintf (stderr, _("Error reading SVG:"));
display_error (error);
fprintf (stderr, "\n");
exit (1);
}
......
......@@ -205,7 +205,7 @@ rsvg_acquire_base64_resource (const char *data,
guchar *bufptr;
size_t buffer_len, buffer_max_len, data_len;
g_return_val_if_fail (data != NULL, NULL);
rsvg_return_val_if_fail (data != NULL, NULL, error);
while (*data) if (*data++ == ',') break;
......@@ -261,7 +261,7 @@ rsvg_acquire_file_resource (const char *filename,
int length;
FILE *f;
g_return_val_if_fail (filename != NULL, NULL);
rsvg_return_val_if_fail (filename != NULL, NULL, error);
path = rsvg_get_file_path (filename, base_uri);
f = fopen (path, "rb");
......@@ -315,8 +315,8 @@ rsvg_acquire_vfs_resource (const char *filename,
GnomeVFSHandle *f = NULL;
GnomeVFSResult res;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (gnome_vfs_initialized (), NULL);
rsvg_return_val_if_fail (filename != NULL, NULL, error);
rsvg_return_val_if_fail (gnome_vfs_initialized (), NULL, error);
res = gnome_vfs_open (&f, filename, GNOME_VFS_OPEN_READ);
......
......@@ -342,6 +342,26 @@ void _rsvg_pop_view_box(RsvgDrawingCtx *ctx);
void rsvg_SAX_handler_struct_init (void);
void rsvg_return_if_fail_warning (const char *pretty_function,
const char *expression,
GError **error);
#define rsvg_return_if_fail(expr, error) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
rsvg_return_if_fail_warning (__PRETTY_FUNCTION__, \
#expr, error); \
return; \
}; }G_STMT_END
#define rsvg_return_val_if_fail(expr,val,error) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
rsvg_return_if_fail_warning (__PRETTY_FUNCTION__, \
#expr, error); \
return (val); \
}; }G_STMT_END
G_END_DECLS
#endif
......@@ -820,14 +820,16 @@ main (int argc, char **argv)
if (!info.pixbuf)
{
g_print (_("Error displaying pixbuf!\n"));
g_print (_("Error displaying image: "));
if (err)
{
g_print ("%s\n", err->message);
g_print ("%s", err->message);
g_error_free (err);
}
g_print ("\n");
return 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment