From 2c9b79a6af5baa6623346e209c1e0c1fa0936ff9 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 13 Apr 2020 00:43:47 +0200 Subject: [PATCH] Warning() => GFX2_Log(GFX2_WARNING) --- src/errors.h | 10 ---------- src/fileformats.c | 18 +++++++++--------- src/gfx2surface.c | 2 +- src/loadrecoil.c | 12 ++++++------ src/loadsave.c | 2 +- src/main.c | 7 ------- src/readline.c | 2 +- src/sdlscreen.c | 4 ++-- src/text.c | 2 +- src/win32screen.c | 4 ++-- 10 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/errors.h b/src/errors.h index 79a2d88f..44ebc1dc 100644 --- a/src/errors.h +++ b/src/errors.h @@ -47,13 +47,3 @@ void Error_function(int error_code, const char *filename, int line_number, const /// - If the error code is 0, just do a red screen flash and resume. /// - If the error code is non-zero, abort the program. #define Error(n) Error_function(n, __FILE__,__LINE__,__func__) - -/// Helper function used by the macro ::Warning -void Warning_function(const char *message, const char *filename, int line_number, const char *function_name); - -/// -/// Report a run-time abnormal condition : It will print to standard output -/// some information about the calling function, and then resume silently. -/// This is most useful in debugger so you can put a breakpoint on -/// ::Warning_function and examine the stack trace. -#define Warning(msg) Warning_function(msg, __FILE__,__LINE__,__func__) diff --git a/src/fileformats.c b/src/fileformats.c index 3051bad5..06cb8133 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -367,7 +367,7 @@ static byte * Decode_NewIcons(const byte * p, int bits, unsigned int * len) value = value - 0x51; else { - Warning("Invalid value"); + GFX2_Log(GFX2_WARNING, "Decode_NewIcons(): Invalid value 0x%02x\n", value); break; } current_byte = (current_byte << 7) | value; @@ -571,7 +571,7 @@ void Load_INFO(T_IO_Context * context) palette_color_count++; } else - Warning("Too much colors in new icons"); + GFX2_Log(GFX2_WARNING, "Too much colors in new icons\n"); } palette_conv[i] = (byte)j; } @@ -629,7 +629,7 @@ void Load_INFO(T_IO_Context * context) palette_color_count++; } else - Warning("Too much colors in new icons"); + GFX2_Log(GFX2_WARNING, "Too much colors in new icons\n"); } palette_conv[i+palette_continues] = (byte)j; } @@ -1109,7 +1109,7 @@ static void Load_BMP_Pixels(T_IO_Context * context, FILE * file, unsigned int co if (0 == memcmp(png_header, "\x89PNG", 4)) { // NO PNG Support - Warning("PNG Signature : Compiled without libpng support"); + GFX2_Log(GFX2_WARNING, "PNG Signature : Compiled without libpng support\n"); File_error = 2; } #endif @@ -1122,7 +1122,7 @@ static void Load_BMP_Pixels(T_IO_Context * context, FILE * file, unsigned int co } break; default: - Warning("Unknown compression type"); + GFX2_Log(GFX2_WARNING, "BMP: Unknown compression type %d\n", compression); } } @@ -1227,7 +1227,7 @@ void Load_BMP(T_IO_Context * context) } else { - Warning("Unknown BMP type"); + GFX2_Log(GFX2_WARNING, "Unknown BMP type Size_2=%u\n", header.Size_2); File_error = 1; } } @@ -1629,7 +1629,7 @@ void Load_ICO(T_IO_Context * context) // check that real_height == entry->height if (real_height != entry->height) { - Warning("Load_ICO() : real_height != entry->height"); + GFX2_Log(GFX2_WARNING, "Load_ICO() : real_height(%hd) != entry->height(%hd)\n", real_height, entry->height); } // Image 16/24/32 bits @@ -1694,7 +1694,7 @@ void Save_ICO(T_IO_Context * context) if (context->Width > 256 || context->Height > 256) { File_error=1; - Warning(".ICO files can handle images up to 256x256"); + GFX2_Log(GFX2_WARNING, ".ICO files can handle images up to 256x256\n"); return; } @@ -2446,7 +2446,7 @@ void Load_SCx(T_IO_Context * context) { if (SCx_header.StorageType == 0x80) { - Warning("Compressed SCx files are not supported"); + GFX2_Log(GFX2_WARNING, "Compressed SCx files are not supported\n"); File_error = 2; } else diff --git a/src/gfx2surface.c b/src/gfx2surface.c index e4866dd9..1e5c0e1a 100644 --- a/src/gfx2surface.c +++ b/src/gfx2surface.c @@ -70,7 +70,7 @@ void Set_GFX2_Surface_pixel(T_GFX2_Surface * surface, int x, int y, byte value) if (surface == NULL) return; if (x<0 || x>=surface->w || y<0 || y>=surface->h) { - Warning("Set_GFX2_Surface_pixel() out of bound access"); + GFX2_Log(GFX2_WARNING, "Set_GFX2_Surface_pixel() out of bound access (%d,%d)\n", x, y); return; } surface->pixels[x + surface->w * y] = value; diff --git a/src/loadrecoil.c b/src/loadrecoil.c index e0c8d762..f6cdc9a3 100644 --- a/src/loadrecoil.c +++ b/src/loadrecoil.c @@ -34,6 +34,8 @@ #include "io.h" #include "errors.h" #include "unicode.h" +#include "gfx2mem.h" +#include "gfx2log.h" #include "recoil.h" @@ -82,17 +84,16 @@ void Load_Recoil_Image(T_IO_Context *context) File_error = 1; return; } - file_content = malloc(file_length); + file_content = GFX2_malloc(file_length); if (file_content == NULL) { - Warning("Memory allocation error"); fclose(f); File_error = 1; return; } if (!Read_bytes(f, file_content, file_length)) { - Warning("Read error"); + GFX2_Log(GFX2_WARNING, "Load_Recoil_Image(): Read error on file\n"); fclose(f); free(file_content); File_error = 1; @@ -116,7 +117,7 @@ void Load_Recoil_Image(T_IO_Context *context) // ie .DEE instead of .deep size_t i; size_t len = Unicode_strlen(context->File_name_unicode); - tempfilename = (char *)malloc(len + 1); + tempfilename = (char *)GFX2_malloc(len + 1); for (i = 0; i < len; i++) tempfilename[i] = (context->File_name_unicode[i] < 256) ? (char)context->File_name_unicode[i] : '_'; tempfilename[i] = '\0'; @@ -143,10 +144,9 @@ void Load_Recoil_Image(T_IO_Context *context) ratio = PIXEL_WIDE; else if(x_ratio == 1 && y_ratio > 1) ratio = PIXEL_TALL; - pixels = malloc(width * height); + pixels = GFX2_malloc(width * height); if (pixels == NULL) { - Warning("Memory allocation error"); File_error = 1; } else diff --git a/src/loadsave.c b/src/loadsave.c index e68af129..3c8c464e 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -615,7 +615,7 @@ void Load_image(T_IO_Context *context) f = Open_file_read(context); if (f == NULL) { - Warning("Cannot open file for reading"); + GFX2_Log(GFX2_WARNING, "Cannot open file for reading\n"); Error(0); return; } diff --git a/src/main.c b/src/main.c index 28c74e56..a0b3a9cb 100644 --- a/src/main.c +++ b/src/main.c @@ -204,13 +204,6 @@ void Display_syntax(void) #endif } -// ---------------------------- Sortie impromptue ---------------------------- -void Warning_function(const char *message, const char *filename, int line_number, const char *function_name) -{ - GFX2_Log(GFX2_WARNING, "Warning in file %s, line %d, function %s : %s\n", filename, line_number, function_name, message); -} - - // ---------------------------- Sortie impromptue ---------------------------- void Error_function(int error_code, const char *filename, int line_number, const char *function_name) { diff --git a/src/readline.c b/src/readline.c index 0a13402f..0e6646fd 100644 --- a/src/readline.c +++ b/src/readline.c @@ -705,7 +705,7 @@ byte Readline_ex_unicode(word x_pos, word y_pos, char * str, word * str_unicode, } else { - Warning("Unicode conversion of input text failed"); + GFX2_Log(GFX2_WARNING, "Unicode conversion of input text failed\n"); unicode_text[0] = 0; } #elif defined(WIN32) diff --git a/src/sdlscreen.c b/src/sdlscreen.c index d1727152..d2366e8e 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -83,7 +83,7 @@ byte Get_Screen_pixel(int x, int y) { if (y < 0 || x < 0 || y >= Screen_SDL->h || x >= Screen_SDL->w) { - Warning("Get_Screen_pixel() coordinates out of bound"); + GFX2_Log(GFX2_WARNING, "Get_Screen_pixel() coordinates out of bound\n"); return 0; } return ((byte *)Screen_SDL->pixels)[x + y*(Screen_SDL->pitch)]; @@ -93,7 +93,7 @@ void Set_Screen_pixel(int x, int y, byte value) { if (y < 0 || x < 0 || y >= Screen_SDL->h || x >= Screen_SDL->w) { - Warning("Set_Screen_pixel() coordinates out of bound"); + GFX2_Log(GFX2_WARNING, "Set_Screen_pixel() coordinates out of bound\n"); return; } ((byte *)Screen_SDL->pixels)[x + y*(Screen_SDL->pitch)] = value; diff --git a/src/text.c b/src/text.c index e1d59567..d230f3c9 100644 --- a/src/text.c +++ b/src/text.c @@ -748,7 +748,7 @@ byte *Render_text_SFont(const char *str, int font_number, int *width, int *heigh text_surface = New_GFX2_Surface(*width, *height); if (text_surface == NULL) { - Warning("Failed to allocate text surface"); + GFX2_Log(GFX2_WARNING, "Failed to allocate text surface\n"); SFont_FreeFont(font); return NULL; } diff --git a/src/win32screen.c b/src/win32screen.c index 2665ab3a..bc730d48 100644 --- a/src/win32screen.c +++ b/src/win32screen.c @@ -427,7 +427,7 @@ int Init_Win32(HINSTANCE hInstance, HINSTANCE hPrevInstance) wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("grafx2"); if (!RegisterClass(&wc)) { - Warning("RegisterClass failed\n"); + GFX2_Log(GFX2_WARNING, "RegisterClass failed\n"); Error(ERROR_INIT); return 0; } @@ -457,7 +457,7 @@ static int Video_AllocateDib(int width, int height) dc = GetDC(NULL); Windows_DIB = CreateDIBSection(dc, bi, DIB_RGB_COLORS, &Windows_Screen, NULL, 0); if (Windows_DIB == NULL) { - Warning("CreateDIBSection failed"); + GFX2_Log(GFX2_WARNING, "CreateDIBSection failed\n"); return -1; } ReleaseDC(NULL, dc);