From 8225911a9c19f5c738397488ccebf510490536f3 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 18 Jul 2019 19:22:41 -0400 Subject: image_*(), text_*(), sgr(): Add error() output --- 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 +#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 #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); -- cgit v0.9.1