summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 19:22:41 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-18 19:22:41 (EDT)
commit8225911a9c19f5c738397488ccebf510490536f3 (patch)
treee3c42fab0df409aeae0ab600ef3a7ad2d3ed8731
parentfa13692468790adab90c43f8b5bcce4b201f479f (diff)
image_*(), text_*(), sgr(): Add error() output
-rw-r--r--src/image.c4
-rw-r--r--src/sgr.c4
-rw-r--r--src/text.c8
3 files changed, 16 insertions, 0 deletions
diff --git a/src/image.c b/src/image.c
index 59716da..47bc94c 100644
--- a/src/image.c
+++ b/src/image.c
@@ -28,6 +28,7 @@
#include "font.h"
#include "i18n.h"
+#include "output.h"
#include "text.h"
struct image {
@@ -43,6 +44,7 @@ image_new(const char *file_name)
image = calloc(1, sizeof(*image));
if (!image) {
+ error(_("Cannot allocate memory for image object"));
return NULL;
}
@@ -57,11 +59,13 @@ image_new(const char *file_name)
image->png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (!image->png_ptr) {
+ error(_("Failed to create PNG structure"));
return image_destroy(&image);
}
image->info_ptr = png_create_info_struct(image->png_ptr);
if (!image->info_ptr) {
+ error(_("Failed to create PNG info structure"));
return image_destroy(&image);
}
diff --git a/src/sgr.c b/src/sgr.c
index 9faa117..4017b72 100644
--- a/src/sgr.c
+++ b/src/sgr.c
@@ -26,6 +26,9 @@
#include <png.h>
+#include "i18n.h"
+#include "output.h"
+
static png_color _4bit[] = {
{ 0, 0, 0}, /* Black */
{170, 0, 0}, /* Red */
@@ -87,6 +90,7 @@ sgr(unsigned char *param, png_colorp fg, png_colorp bg)
}
p = param + 1;
} else if (*param < '0' || *param > '9') {
+ error(_("Invalid SGR parameter \"%s\""), p);
break;
}
}
diff --git a/src/text.c b/src/text.c
index 995d10e..f5ddaba 100644
--- a/src/text.c
+++ b/src/text.c
@@ -28,6 +28,8 @@
#include <png.h>
#include "font.h"
+#include "i18n.h"
+#include "output.h"
#include "sgr.h"
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -70,6 +72,7 @@ text_new(FILE *stream)
}
text = calloc(1, sizeof(*text));
if (!text) {
+ error(_("Cannot allocate memory for text object"));
return NULL;
}
@@ -83,6 +86,10 @@ text_new(FILE *stream)
for (; c >= 0x20 && c <= 0x2F; _getc(text, stream, &c));
if (c >= 0x40 && c <= 0x7E) {
_getc(text, stream, &c);
+ } else {
+ error(_("Invalid control sequence at line %lu "
+ "column %lu"),
+ text->height + 1, width + 1);
}
eol = 0;
} else if (c == '\n') {
@@ -142,6 +149,7 @@ text_render(const struct text *text, const struct font *font, png_bytepp rows)
string_start = calloc(strlen((char *) text->string) + 1,
sizeof(*text->string));
if (!string_start) {
+ error(_("Cannot allocate memory for text rendering"));
return;
}
memcpy(string_start, text->string, strlen((char *) text->string) + 1);