From f3011b4a496b44a7634f039ce573ec4722edc454 Mon Sep 17 00:00:00 2001 From: Matteo Paonessa Date: Tue, 21 Feb 2017 23:15:31 +0100 Subject: [PATCH] New error enumeration --- caesium/caesium.c | 4 ++-- caesium/error.c | 24 ++++++++++++------------ caesium/jpeg.c | 10 +++++----- caesium/png.c | 6 +++--- caesium/utils.c | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/caesium/caesium.c b/caesium/caesium.c index 44693f1..e8d0c1b 100644 --- a/caesium/caesium.c +++ b/caesium/caesium.c @@ -13,7 +13,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars bool result = false; if ((pInputFile = fopen(input_path, "rb")) == NULL) { - display_error(ERROR, 4); + display_error(ERROR, 104); return result; } @@ -22,7 +22,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars fclose(pInputFile); if (type == UNKN) { - display_error(WARNING, 3); + display_error(WARNING, 103); } else if (type == JPEG) { if (options->jpeg.quality != 0) { cs_jpeg_compress(output_path, cs_jpeg_decompress(input_path, &options->jpeg), &options->jpeg); diff --git a/caesium/error.c b/caesium/error.c index 6f4c129..35b0683 100644 --- a/caesium/error.c +++ b/caesium/error.c @@ -4,7 +4,7 @@ void display_error(error_level level, int code) { - char *error_level = ((level) ? "WARNING" : "ERROR"); + char *error_level = ((level) ? "[WARNING]" : "[ERROR]"); fprintf(stderr, "%s %d: %s\n", error_level, code, @@ -15,31 +15,31 @@ const char *get_error_message(int code) { switch (code) { //Generic errors - case 1: + case 101: return "NULL file pointer while checking type."; - case 3: + case 103: return "File type not supported."; - case 4: + case 104: return "Could not open input file."; //JPEG related errors - case 100: + case 200: return "Failed to open JPEG file while trying to get markers"; - case 101: + case 201: return "Failed to open input JPEG file while optimizing"; - case 102: + case 202: return "Failed to open output JPEG file while optimizing"; - case 103: + case 203: return "Failed to open JPEG file while compressing"; - case 104: + case 204: return "Failed to open JPEG file while decompressing"; //PNG related errors - case 200: + case 300: return "Failed to load PNG file."; - case 201: + case 301: return "Error while optimizing PNG."; - case 203: + case 303: return "Error while writing output PNG file."; default: diff --git a/caesium/jpeg.c b/caesium/jpeg.c index 12df191..c97381c 100644 --- a/caesium/jpeg.c +++ b/caesium/jpeg.c @@ -17,7 +17,7 @@ struct jpeg_decompress_struct cs_get_markers(const char *input) //Check for errors if ((fp = fopen(input, "r")) == NULL) { - display_error(ERROR, 100); + display_error(ERROR, 200); } //Create the IO instance for the input file @@ -59,7 +59,7 @@ bool cs_jpeg_optimize(const char *input_file, const char *output_file, bool exif //Check for errors if ((fp = fopen(input_file, "r")) == NULL) { - display_error(ERROR, 101); + display_error(ERROR, 201); } //Create the IO instance for the input file @@ -90,7 +90,7 @@ bool cs_jpeg_optimize(const char *input_file, const char *output_file, bool exif //Check for errors if ((fp = fopen(output_file, "wb")) == NULL) { - display_error(ERROR, 102); + display_error(ERROR, 202); } //CRITICAL - This is the optimization step @@ -138,7 +138,7 @@ void cs_jpeg_compress(const char *output_file, unsigned char *image_buffer, cs_j //Check for errors if ((fp = fopen(output_file, "wb")) == NULL) { - display_error(ERROR, 103); + display_error(ERROR, 203); } output_buffer = NULL; @@ -175,7 +175,7 @@ unsigned char *cs_jpeg_decompress(const char *fileName, cs_jpeg_pars *options) int fileWidth = 0, fileHeight = 0, jpegSubsamp = 0, colorSpace = 0; if ((fp = fopen(fileName, "rb")) == NULL) { - display_error(ERROR, 104); + display_error(ERROR, 204); } fseek(fp, 0, SEEK_END); sourceJpegBufferSize = ftell(fp); diff --git a/caesium/png.c b/caesium/png.c index ef7b572..32df8d5 100644 --- a/caesium/png.c +++ b/caesium/png.c @@ -32,7 +32,7 @@ bool cs_png_optimize(const char *input, const char *output, cs_png_pars *options png_options.auto_filter_strategy = options->auto_filter_strategy; if (lodepng_load_file(&orig_buffer, &orig_buffer_size, input) != 0) { - display_error(ERROR, 200); + display_error(ERROR, 300); goto cleanup; } @@ -42,12 +42,12 @@ bool cs_png_optimize(const char *input, const char *output, cs_png_pars *options 0, &resultpng, &resultpng_size) != 0) { - display_error(ERROR, 201); + display_error(ERROR, 301); goto cleanup; } if (lodepng_save_file(resultpng, resultpng_size, output) != 0) { - display_error(ERROR, 202); + display_error(ERROR, 302); goto cleanup; } diff --git a/caesium/utils.c b/caesium/utils.c index 83cec2e..2c288cc 100644 --- a/caesium/utils.c +++ b/caesium/utils.c @@ -9,7 +9,7 @@ image_type detect_image_type(FILE *pFile) unsigned char buffer[2]; if (pFile == NULL) { - display_error(ERROR, 1); + display_error(WARNING, 101); return UNKN; }