ansilove

ANSI and ASCII art to PNG converter in C
Log | Files | Refs | README | LICENSE

commit a8e1ba9e5b3df09d6ab3ff0451c640a92b1f4a8c
parent 7e3a77603882554d0dd55191e3413d5600daf60c
Author: Frederic Cambus <fred@statdns.com>
Date:   Sat, 15 Apr 2017 22:43:49 +0200

Use perror when printing errors

Diffstat:
Msrc/loaders/ansi.c | 3++-
Msrc/loaders/artworx.c | 6++++--
Msrc/loaders/binary.c | 3++-
Msrc/loaders/icedraw.c | 12++++++++----
Msrc/loaders/tundra.c | 3++-
Msrc/loaders/xbin.c | 6++++--
Msrc/main.c | 9++++++---
7 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -421,7 +421,8 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c im_ANSi = gdImageCreate(columns * bits,(position_y_max)*fontData.font_size_y); if (!im_ANSi) { - fputs ("\nCan't allocate ANSi buffer image memory.\n\n", stderr); exit (6); + perror("Can't allocate ANSi buffer image memory"); + exit(6); } int32_t colors[16]; diff --git a/src/loaders/artworx.c b/src/loaders/artworx.c @@ -24,7 +24,8 @@ void artworx(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output // error output if (!im_ADF) { - fputs ("\nCan't allocate buffer image memory.\n\n", stderr); exit (7); + perror("Can't allocate buffer image memory"); + exit (7); } // ADF color palette array @@ -36,7 +37,8 @@ void artworx(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output // process ADF font font_data_adf = (unsigned char *) malloc(sizeof(unsigned char)*4096); if (font_data_adf == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (7); + perror("Memory error"); + exit (7); } memcpy(font_data_adf,inputFileBuffer+193,4096); diff --git a/src/loaders/binary.c b/src/loaders/binary.c @@ -27,7 +27,8 @@ void binary(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, ((inputFileSize / 2) / columns * fontData.font_size_y)); if (!im_Binary) { - fputs ("\nError, can't allocate buffer image memory.\n\n", stderr); exit (6); + perror("Error, can't allocate buffer image memory"); + exit (6); } // allocate black color diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c @@ -29,7 +29,8 @@ void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output // process IDF font font_data_idf = (unsigned char *) malloc(sizeof(unsigned char)*4096); if (font_data_idf == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (7); + perror("Memory error"); + exit (7); } memcpy(font_data_idf,inputFileBuffer+(inputFileSize - 48 - 4096),4096); @@ -64,7 +65,8 @@ void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output idf_buffer = temp; } else { - fputs ("\nError allocating IDF buffer memory.\n\n", stderr); exit (7); + perror("Error allocating IDF buffer memory"); + exit (7); } idf_buffer[i] = inputFileBuffer[loop + 4]; @@ -80,7 +82,8 @@ void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output idf_buffer = temp; } else { - fputs ("\nError allocating IDF buffer memory.\n\n", stderr); exit (8); + perror("Error allocating IDF buffer memory"); + exit (8); } // normal character @@ -96,7 +99,8 @@ void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output // error output if (!im_IDF) { - fputs ("\nCan't allocate buffer image memory.\n\n", stderr); exit (9); + perror("Can't allocate buffer image memory"); + exit (9); } gdImageColorAllocate(im_IDF, 0, 0, 0); diff --git a/src/loaders/tundra.c b/src/loaders/tundra.c @@ -98,7 +98,8 @@ void tundra(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, im_Tundra = gdImageCreateTrueColor(columns * bits , (position_y) * fontData.font_size_y); if (!im_Tundra) { - fputs ("\nError, can't allocate buffer image memory.\n\n", stderr); exit (6); + perror("Error, can't allocate buffer image memory"); + exit (6); } // process tundra diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c @@ -30,7 +30,8 @@ void xbin(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c im_XBIN = gdImageCreate(8 * xbin_width, xbin_fontsize * xbin_height); if (!im_XBIN) { - fputs ("\nError, can't allocate buffer image memory.\n\n", stderr); exit (6); + perror("Error, can't allocate buffer image memory"); + exit (6); } // allocate black color @@ -81,7 +82,8 @@ void xbin(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c // allocate memory to contain the XBin font font_data_xbin = (unsigned char *) malloc(sizeof(unsigned char)*(xbin_fontsize * numchars)); if (font_data_xbin == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (5); + perror("Memory error"); + exit (5); } memcpy(font_data_xbin,inputFileBuffer+offset,(xbin_fontsize * numchars)); diff --git a/src/main.c b/src/main.c @@ -277,7 +277,8 @@ int main(int argc, char *argv[]) { // load input file FILE *input_file = fopen(input, "r"); if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); + perror("File error"); + exit (1); } // get the file size (bytes) @@ -291,12 +292,14 @@ int main(int argc, char *argv[]) { // allocate memory to contain the whole file inputFileBuffer = (unsigned char *) malloc(sizeof(unsigned char)*inputFileSize + 1); if (inputFileBuffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); + perror("Memory error"); + exit (2); } // copy the file into the buffer if (fread(inputFileBuffer, 1, inputFileSize, input_file) != inputFileSize) { - fputs ("\nReading error.\n\n", stderr); exit (3); + perror("Reading error"); + exit (3); } // whole file is now loaded into inputFileBuffer inputFileBuffer[inputFileSize] = '\0';