aboutsummaryrefslogtreecommitdiff
path: root/src/transform.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-09-03 23:54:12 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-09-04 00:13:34 +0200
commit695f71d9462ce3fe0bdcbe7fae9015ce254512fd (patch)
tree88ca5eebc13f3868c6c9c850c6eb00a8aa085e58 /src/transform.c
parent8d19acd91af9592d862ef2a7aa8e95eea4160152 (diff)
downloadtdv-695f71d9462ce3fe0bdcbe7fae9015ce254512fd.tar.gz
tdv-695f71d9462ce3fe0bdcbe7fae9015ce254512fd.tar.xz
tdv-695f71d9462ce3fe0bdcbe7fae9015ce254512fd.zip
tools: clean up error message printing
Diffstat (limited to 'src/transform.c')
-rw-r--r--src/transform.c44
1 files changed, 13 insertions, 31 deletions
diff --git a/src/transform.c b/src/transform.c
index 2d5c2f2..f9909b7 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -34,6 +34,7 @@
#include "stardict.h"
#include "stardict-private.h"
#include "generator.h"
+#include "utils.h"
enum { PIPE_READ, PIPE_WRITE };
@@ -177,18 +178,10 @@ main (int argc, char *argv[])
(ctx, "Transform dictionaries using a filter program.");
g_option_context_set_description (ctx, "Test?");
if (!g_option_context_parse (ctx, &argc, &argv, &error))
- {
- g_printerr ("Error: option parsing failed: %s\n", error->message);
- exit (EXIT_FAILURE);
- }
+ fatal ("Error: option parsing failed: %s\n", error->message);
if (argc < 3)
- {
- gchar *help = g_option_context_get_help (ctx, TRUE, FALSE);
- g_printerr ("%s", help);
- g_free (help);
- exit (EXIT_FAILURE);
- }
+ fatal ("%s", g_option_context_get_help (ctx, TRUE, FALSE));
// GLib is bullshit, getopt_long() always correctly removes this
gint program_argv_start = 3;
@@ -200,20 +193,16 @@ main (int argc, char *argv[])
printf ("Loading the original dictionary...\n");
StardictDict *dict = stardict_dict_new (argv[1], &error);
if (!dict)
- {
- g_printerr ("Error: opening the dictionary failed: %s\n",
- error->message);
- exit (EXIT_FAILURE);
- }
+ fatal ("Error: opening the dictionary failed: %s\n", error->message);
printf ("Filtering entries...\n");
gint child_in[2];
if (!g_unix_open_pipe (child_in, 0, &error))
- g_error ("g_unix_open_pipe: %s", error->message);
+ fatal ("g_unix_open_pipe: %s\n", error->message);
FILE *child_out = tmpfile ();
if (!child_out)
- g_error ("tmpfile: %s", strerror (errno));
+ fatal ("tmpfile: %s\n", strerror (errno));
GPid pid = -1;
if (!g_spawn_async_with_fds (NULL /* working_directory */,
@@ -221,32 +210,29 @@ main (int argc, char *argv[])
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
NULL /* child_setup */, NULL /* user_data */,
&pid, child_in[PIPE_READ], fileno (child_out), STDERR_FILENO, &error))
- g_error ("g_spawn: %s", error->message);
+ fatal ("g_spawn: %s\n", error->message);
if (!write_to_filter (dict, child_in[PIPE_WRITE], &error))
- g_error ("write_to_filter: %s", error->message);
+ fatal ("write_to_filter: %s\n", error->message);
if (!g_close (child_in[PIPE_READ], &error)
|| !g_close (child_in[PIPE_WRITE], &error))
- g_error ("g_close: %s", error->message);
+ fatal ("g_close: %s\n", error->message);
printf ("Waiting for the filter to finish...\n");
int wstatus = errno = 0;
if (waitpid (pid, &wstatus, 0) < 1
|| !WIFEXITED (wstatus) || WEXITSTATUS (wstatus) > 0)
- g_error ("Filter failed (%s, status %d)", strerror (errno), wstatus);
+ fatal ("Filter failed (%s, status %d)\n", strerror (errno), wstatus);
GMappedFile *filtered = g_mapped_file_new_from_fd (fileno (child_out),
FALSE /* writable */, &error);
if (!filtered)
- g_error ("g_mapped_file_new_from_fd: %s", error->message);
+ fatal ("g_mapped_file_new_from_fd: %s\n", error->message);
printf ("Writing the new dictionary...\n");
Generator *generator = generator_new (argv[2], &error);
if (!generator)
- {
- g_printerr ("Error: failed to create the output dictionary: %s\n",
+ fatal ("Error: failed to create the output dictionary: %s\n",
error->message);
- exit (EXIT_FAILURE);
- }
StardictInfo *info = generator->info;
stardict_info_copy (info, stardict_dict_get_info (dict));
@@ -256,11 +242,7 @@ main (int argc, char *argv[])
if (!update_from_filter (dict, generator, filtered, &error)
|| !generator_finish (generator, &error))
- {
- g_printerr ("Error: failed to write the dictionary: %s\n",
- error->message);
- exit (EXIT_FAILURE);
- }
+ fatal ("Error: failed to write the dictionary: %s\n", error->message);
g_mapped_file_unref (filtered);
fclose (child_out);