libcaesium/caesium/error.c

56 lines
1.3 KiB
C
Raw Normal View History

2016-11-04 11:00:04 +01:00
#include <stdio.h>
#include "error.h"
2016-11-13 14:43:54 +01:00
void display_error(error_level level, int code)
2016-11-04 11:00:04 +01:00
{
2017-02-21 23:15:31 +01:00
char *error_level = ((level) ? "[WARNING]" : "[ERROR]");
2016-11-04 11:00:04 +01:00
fprintf(stderr, "%s %d: %s\n",
error_level,
code,
get_error_message(code));
}
const char *get_error_message(int code)
{
switch (code) {
2016-11-13 14:43:54 +01:00
//Generic errors
2017-02-21 23:15:31 +01:00
case 101:
2016-11-04 11:00:04 +01:00
return "NULL file pointer while checking type.";
2017-02-21 23:15:31 +01:00
case 103:
2016-11-04 11:00:04 +01:00
return "File type not supported.";
2017-02-21 23:15:31 +01:00
case 104:
2016-11-04 11:00:04 +01:00
return "Could not open input file.";
2016-11-13 14:43:54 +01:00
2016-11-14 18:56:24 +01:00
//JPEG related errors
2017-02-21 23:15:31 +01:00
case 200:
2016-11-14 18:56:24 +01:00
return "Failed to open JPEG file while trying to get markers";
2017-02-21 23:15:31 +01:00
case 201:
2016-11-14 18:56:24 +01:00
return "Failed to open input JPEG file while optimizing";
2017-02-21 23:15:31 +01:00
case 202:
2016-11-14 18:56:24 +01:00
return "Failed to open output JPEG file while optimizing";
2017-02-21 23:15:31 +01:00
case 203:
2016-11-14 18:56:24 +01:00
return "Failed to open JPEG file while compressing";
2017-02-21 23:15:31 +01:00
case 204:
2016-11-14 18:56:24 +01:00
return "Failed to open JPEG file while decompressing";
2017-06-03 12:22:23 +02:00
case 205:
return "Failed to retrieve input JPEG file size";
case 206:
return "Input JPEG file is too big";
case 207:
return "Compressor failed";
case 208:
return "Compressor failed";
2016-11-14 18:56:24 +01:00
2016-11-13 14:43:54 +01:00
//PNG related errors
2017-02-21 23:15:31 +01:00
case 300:
2016-11-13 14:43:54 +01:00
return "Failed to load PNG file.";
2017-02-21 23:15:31 +01:00
case 301:
2016-11-13 14:43:54 +01:00
return "Error while optimizing PNG.";
2017-02-21 23:15:31 +01:00
case 303:
2016-11-13 14:43:54 +01:00
return "Error while writing output PNG file.";
2016-11-04 11:00:04 +01:00
default:
return "Unrecognized error.";
}
}