summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2018-08-25 14:45:36 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2018-08-25 15:16:09 -0700
commit538ddd32790f0031357807b1b0c6c10879607209 (patch)
treeaa7820ef9187926b96d3b3e72d85a2293fa93fc8
parentfa1bb8ee9cc190416902a5929ac5cddfb6d6304b (diff)
Include more information in error messages
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--xcursorgen.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/xcursorgen.c b/xcursorgen.c
index a48b61b..ba9d85c 100644
--- a/xcursorgen.c
+++ b/xcursorgen.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <errno.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -35,6 +36,8 @@
#include <png.h>
+static const char *ProgramName;
+
struct flist
{
int size;
@@ -96,7 +99,9 @@ read_config_file (const char *config, struct flist **list)
break;
default:
{
- fprintf (stderr, "Bad config file data!\n");
+ fprintf (stderr, "%s: Bad config file data on line %d of %s\n",
+ ProgramName, count + 1,
+ strcmp(config, "-") ? config : "stdin");
fclose (fp);
return 0;
}
@@ -105,7 +110,8 @@ read_config_file (const char *config, struct flist **list)
curr = malloc (sizeof (struct flist));
if (curr == NULL)
{
- fprintf (stderr, "malloc() failed\n");
+ fprintf (stderr, "%s: malloc() failed: %s\n",
+ ProgramName, strerror(errno));
fclose (fp);
return 0;
}
@@ -119,7 +125,8 @@ read_config_file (const char *config, struct flist **list)
curr->pngfile = strdup (pngfile);
if (curr->pngfile == NULL)
{
- fprintf (stderr, "strdup() failed\n");
+ fprintf (stderr, "%s: strdup() failed: %s\n",
+ ProgramName, strerror(errno));
fclose (fp);
free(curr);
return 0;
@@ -206,7 +213,8 @@ load_image (struct flist *list, const char *prefix)
file = malloc (strlen (prefix) + 1 + strlen (list->pngfile) + 1);
if (file == NULL)
{
- fprintf (stderr, "malloc() failed\n");
+ fprintf (stderr, "%s: malloc() failed: %s\n",
+ ProgramName, strerror(errno));
png_destroy_read_struct (&png, &info, NULL);
return NULL;
}
@@ -264,6 +272,10 @@ load_image (struct flist *list, const char *prefix)
image = XcursorImageCreate (width, height);
if (image == NULL)
{
+ fprintf (stderr,
+ "%s: XcursorImageCreate() failed to create %u x %u image\n"
+ " for file %s\n",
+ ProgramName, width, height, list->pngfile);
fclose (fp);
png_destroy_read_struct (&png, &info, NULL);
return NULL;
@@ -323,7 +335,8 @@ write_cursors (int count, struct flist *list,
image = load_image (list, prefix);
if (image == NULL)
{
- fprintf (stderr, "PNG error while reading %s!\n", list->pngfile);
+ fprintf (stderr, "%s: PNG error while reading %s\n",
+ ProgramName, list->pngfile);
fclose(fp);
return 1;
}
@@ -349,7 +362,7 @@ check_image (char *image)
if (XReadBitmapFileData (image, &width, &height, &data, &x_hot, &y_hot) != BitmapSuccess)
{
- fprintf (stderr, "Can't open bitmap file \"%s\"\n", image);
+ fprintf (stderr, "%s: Can't open bitmap file \"%s\"\n", ProgramName, image);
return 1;
}
else {
@@ -385,6 +398,8 @@ main (int argc, char *argv[])
const char *prefix = NULL;
int i;
+ ProgramName = argv[0];
+
for (i = 1; i < argc; i++)
{
if (strcmp (argv[i], "-V") == 0 || strcmp (argv[i], "--version") == 0)
@@ -442,7 +457,8 @@ main (int argc, char *argv[])
count = read_config_file (in, &list);
if (count == 0)
{
- fprintf (stderr, "Error reading config file!\n");
+ fprintf (stderr, "%s: Error reading config file %s\n", argv[0],
+ strcmp(in, "-") ? in : "from stdin");
return 1;
}