diff --git a/src/Makefile.dep b/src/Makefile.dep index d35b21b2..22f13e76 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -1,46 +1,49 @@ $(OBJDIR)/SFont.o: SFont.c SFont.h gfx2surface.h struct.h const.h $(OBJDIR)/brush.o: brush.c global.h struct.h const.h graph.h misc.h errors.h \ - windows.h screen.h brush.h tiles.h + gfx2log.h windows.h screen.h brush.h tiles.h $(OBJDIR)/brush_ops.o: brush_ops.c brush.h struct.h const.h buttons.h loadsave.h \ gfx2surface.h engine.h global.h graph.h misc.h operatio.h pages.h \ screen.h windows.h keyboard.h $(OBJDIR)/buttons.o: buttons.c const.h struct.h global.h misc.h graph.h engine.h \ readline.h filesel.h loadsave.h gfx2surface.h init.h buttons.h \ - operatio.h pages.h palette.h errors.h readini.h saveini.h shade.h io.h \ - help.h text.h screen.h windows.h brush.h input.h keycodes.h special.h \ - tiles.h setup.h unicode.h + operatio.h pages.h palette.h errors.h gfx2log.h readini.h saveini.h \ + shade.h io.h help.h text.h screen.h windows.h brush.h input.h keycodes.h \ + special.h tiles.h setup.h unicode.h $(OBJDIR)/buttons_effects.o: buttons_effects.c brush.h struct.h const.h buttons.h \ loadsave.h gfx2surface.h engine.h global.h graph.h help.h input.h \ keycodes.h misc.h pages.h readline.h screen.h windows.h tiles.h $(OBJDIR)/colorred.o: colorred.c colorred.h struct.h const.h $(OBJDIR)/engine.o: engine.c const.h struct.h global.h graph.h misc.h special.h \ - buttons.h loadsave.h gfx2surface.h operatio.h shade.h errors.h screen.h \ - windows.h brush.h input.h keycodes.h engine.h pages.h layers.h factory.h \ - io.h pxsimple.h oldies.h + buttons.h loadsave.h gfx2surface.h operatio.h shade.h errors.h gfx2log.h \ + screen.h windows.h brush.h input.h keycodes.h engine.h pages.h layers.h \ + factory.h io.h pxsimple.h oldies.h $(OBJDIR)/factory.o: factory.c brush.h struct.h const.h buttons.h loadsave.h \ - gfx2surface.h engine.h errors.h filesel.h global.h graph.h io.h misc.h \ - pages.h readline.h screen.h windows.h palette.h input.h keycodes.h \ - help.h realpath.h setup.h tiles.h -$(OBJDIR)/fileformats.o: fileformats.c errors.h global.h struct.h const.h \ + gfx2surface.h engine.h errors.h gfx2log.h filesel.h global.h graph.h \ + io.h misc.h pages.h readline.h screen.h windows.h palette.h input.h \ + keycodes.h help.h realpath.h setup.h tiles.h +$(OBJDIR)/fileformats.o: fileformats.c gfx2log.h errors.h global.h struct.h const.h \ loadsave.h gfx2surface.h misc.h io.h pages.h windows.h fileformats.h -$(OBJDIR)/filesel.o: filesel.c const.h struct.h global.h misc.h errors.h io.h \ - windows.h screen.h loadsave.h gfx2surface.h mountlist.h engine.h \ +$(OBJDIR)/filesel.o: filesel.c const.h struct.h global.h misc.h errors.h gfx2log.h \ + io.h windows.h screen.h loadsave.h gfx2surface.h mountlist.h engine.h \ readline.h input.h keycodes.h help.h unicode.h filesel.h -$(OBJDIR)/gfx2surface.o: gfx2surface.c gfx2surface.h struct.h const.h errors.h +$(OBJDIR)/gfx2log.o: gfx2log.c gfx2log.h +$(OBJDIR)/gfx2surface.o: gfx2surface.c gfx2surface.h struct.h const.h errors.h \ + gfx2log.h $(OBJDIR)/graph.o: graph.c global.h struct.h const.h engine.h buttons.h loadsave.h \ - gfx2surface.h pages.h errors.h screen.h graph.h misc.h pxsimple.h \ - pxtall.h pxwide.h pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxtall3.h \ - pxquad.h windows.h input.h keycodes.h brush.h tiles.h + gfx2surface.h pages.h errors.h gfx2log.h screen.h graph.h misc.h \ + pxsimple.h pxtall.h pxwide.h pxdouble.h pxtriple.h pxwide2.h pxtall2.h \ + pxtall3.h pxquad.h windows.h input.h keycodes.h brush.h tiles.h $(OBJDIR)/help.o: help.c const.h struct.h global.h misc.h engine.h helpfile.h \ help.h screen.h text.h keyboard.h windows.h input.h keycodes.h hotkeys.h \ - errors.h pages.h factory.h + errors.h gfx2log.h pages.h factory.h $(OBJDIR)/hotkeys.o: hotkeys.c struct.h const.h global.h hotkeys.h keycodes.h $(OBJDIR)/init.o: init.c buttons.h struct.h const.h loadsave.h gfx2surface.h \ - errors.h global.h graph.h init.h io.h factory.h help.h hotkeys.h \ - keyboard.h misc.h mountlist.h operatio.h palette.h screen.h setup.h \ - transform.h windows.h layers.h special.h -$(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h screen.h windows.h \ - errors.h misc.h buttons.h loadsave.h gfx2surface.h input.h keycodes.h + errors.h gfx2log.h global.h graph.h init.h io.h factory.h help.h \ + hotkeys.h keyboard.h misc.h mountlist.h operatio.h palette.h screen.h \ + setup.h transform.h windows.h layers.h special.h +$(OBJDIR)/input.o: input.c gfx2log.h global.h struct.h const.h keyboard.h screen.h \ + windows.h errors.h misc.h buttons.h loadsave.h gfx2surface.h input.h \ + keycodes.h $(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.h unicode.h global.h $(OBJDIR)/keyboard.o: keyboard.c global.h struct.h const.h keyboard.h keycodes.h $(OBJDIR)/layers.o: layers.c const.h struct.h global.h windows.h engine.h pages.h \ @@ -48,34 +51,36 @@ $(OBJDIR)/layers.o: layers.c const.h struct.h global.h windows.h engine.h pages. $(OBJDIR)/libraw2crtc.o: libraw2crtc.c const.h global.h struct.h loadsave.h \ gfx2surface.h $(OBJDIR)/loadrecoil.o: loadrecoil.c struct.h const.h global.h loadsave.h \ - gfx2surface.h io.h errors.h recoil.h -$(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h loadsave.h \ - gfx2surface.h errors.h global.h io.h misc.h graph.h op_c.h colorred.h \ - pages.h palette.h screen.h windows.h engine.h brush.h setup.h filesel.h \ - unicode.h fileformats.h -$(OBJDIR)/main.o: main.c const.h struct.h global.h graph.h misc.h init.h buttons.h \ - loadsave.h gfx2surface.h engine.h pages.h screen.h errors.h readini.h \ - saveini.h io.h text.h setup.h windows.h brush.h palette.h realpath.h \ - input.h keycodes.h help.h filesel.h -$(OBJDIR)/misc.o: misc.c struct.h const.h global.h errors.h buttons.h loadsave.h \ - gfx2surface.h engine.h misc.h keyboard.h screen.h windows.h palette.h \ - input.h keycodes.h graph.h pages.h + gfx2surface.h io.h errors.h gfx2log.h recoil.h +$(OBJDIR)/loadsave.o: loadsave.c gfx2log.h buttons.h struct.h const.h loadsave.h \ + gfx2surface.h errors.h global.h keycodes.h io.h misc.h graph.h op_c.h \ + colorred.h pages.h palette.h screen.h windows.h engine.h brush.h setup.h \ + filesel.h unicode.h fileformats.h +$(OBJDIR)/main.o: main.c gfx2log.h const.h struct.h global.h graph.h misc.h init.h \ + buttons.h loadsave.h gfx2surface.h engine.h pages.h screen.h errors.h \ + readini.h saveini.h io.h text.h setup.h windows.h brush.h palette.h \ + realpath.h input.h keycodes.h help.h filesel.h +$(OBJDIR)/misc.o: misc.c struct.h const.h global.h errors.h gfx2log.h buttons.h \ + loadsave.h gfx2surface.h engine.h misc.h keyboard.h screen.h windows.h \ + palette.h input.h keycodes.h graph.h pages.h $(OBJDIR)/miscfileformats.o: miscfileformats.c engine.h struct.h const.h errors.h \ - global.h io.h libraw2crtc.h loadsave.h gfx2surface.h misc.h screen.h \ - windows.h oldies.h pages.h keycodes.h fileformats.h + gfx2log.h global.h io.h libraw2crtc.h loadsave.h gfx2surface.h misc.h \ + screen.h windows.h oldies.h pages.h keycodes.h fileformats.h $(OBJDIR)/mountlist.o: mountlist.c mountlist.h -$(OBJDIR)/oldies.o: oldies.c struct.h const.h global.h errors.h misc.h palette.h \ - pages.h windows.h layers.h -$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h colorred.h errors.h global.h \ - engine.h windows.h +$(OBJDIR)/oldies.o: oldies.c struct.h const.h global.h errors.h gfx2log.h misc.h \ + palette.h pages.h windows.h layers.h +$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h colorred.h errors.h gfx2log.h \ + global.h engine.h windows.h $(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h misc.h engine.h graph.h \ - operatio.h buttons.h loadsave.h gfx2surface.h pages.h errors.h screen.h \ - brush.h windows.h input.h keycodes.h special.h tiles.h keyboard.h -$(OBJDIR)/pages.o: pages.c global.h struct.h const.h pages.h errors.h loadsave.h \ - gfx2surface.h misc.h windows.h tiles.h graph.h + operatio.h buttons.h loadsave.h gfx2surface.h pages.h errors.h gfx2log.h \ + screen.h brush.h windows.h input.h keycodes.h special.h tiles.h \ + keyboard.h +$(OBJDIR)/pages.o: pages.c global.h struct.h const.h pages.h errors.h gfx2log.h \ + loadsave.h gfx2surface.h misc.h windows.h tiles.h graph.h $(OBJDIR)/palette.o: palette.c const.h struct.h global.h misc.h engine.h readline.h \ buttons.h loadsave.h gfx2surface.h pages.h help.h screen.h errors.h \ - op_c.h colorred.h windows.h input.h keycodes.h palette.h shade.h + gfx2log.h op_c.h colorred.h windows.h input.h keycodes.h palette.h \ + shade.h $(OBJDIR)/pversion.o: pversion.c $(OBJDIR)/pxdouble.o: pxdouble.c global.h struct.h const.h screen.h misc.h graph.h \ pxdouble.h pxwide.h @@ -95,23 +100,25 @@ $(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h screen.h misc.h graph.h \ pxwide.h $(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h screen.h misc.h graph.h \ pxwide2.h -$(OBJDIR)/readini.o: readini.c const.h errors.h global.h struct.h misc.h readini.h \ - setup.h realpath.h io.h windows.h -$(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h screen.h \ - readline.h windows.h input.h keycodes.h engine.h unicode.h +$(OBJDIR)/readini.o: readini.c const.h errors.h gfx2log.h global.h struct.h misc.h \ + readini.h setup.h realpath.h io.h windows.h +$(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \ + gfx2log.h screen.h readline.h windows.h input.h keycodes.h engine.h \ + unicode.h $(OBJDIR)/realpath.o: realpath.c $(OBJDIR)/recoil.o: recoil.c recoil.h $(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h readini.h io.h errors.h \ - misc.h saveini.h setup.h windows.h + gfx2log.h misc.h saveini.h setup.h windows.h $(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h sdlscreen.h errors.h \ - misc.h + gfx2log.h misc.h $(OBJDIR)/setup.o: setup.c struct.h const.h io.h setup.h $(OBJDIR)/shade.o: shade.c global.h struct.h const.h graph.h engine.h errors.h \ - misc.h readline.h help.h screen.h windows.h input.h keycodes.h shade.h + gfx2log.h misc.h readline.h help.h screen.h windows.h input.h keycodes.h \ + shade.h $(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h \ special.h pages.h misc.h buttons.h loadsave.h gfx2surface.h -$(OBJDIR)/text.o: text.c struct.h const.h global.h io.h errors.h windows.h misc.h \ - setup.h loadsave.h gfx2surface.h SFont.h +$(OBJDIR)/text.o: text.c struct.h const.h global.h io.h errors.h gfx2log.h \ + windows.h misc.h setup.h loadsave.h gfx2surface.h SFont.h $(OBJDIR)/tiles.o: tiles.c struct.h const.h global.h graph.h screen.h engine.h \ windows.h input.h keycodes.h misc.h tiles.h $(OBJDIR)/transform.o: transform.c global.h struct.h const.h transform.h engine.h \ @@ -120,6 +127,7 @@ $(OBJDIR)/transform.o: transform.c global.h struct.h const.h transform.h engine. $(OBJDIR)/unicode.o: unicode.c unicode.h struct.h const.h $(OBJDIR)/version.o: version.c $(OBJDIR)/windows.o: windows.c windows.h struct.h const.h engine.h errors.h \ - global.h graph.h input.h keycodes.h misc.h op_c.h colorred.h readline.h \ - screen.h palette.h unicode.h keyboard.h -$(OBJDIR)/x11screen.o: x11screen.c screen.h struct.h const.h global.h gfx2surface.h + gfx2log.h global.h graph.h input.h keycodes.h misc.h op_c.h colorred.h \ + readline.h screen.h palette.h unicode.h keyboard.h +$(OBJDIR)/x11screen.o: x11screen.c screen.h struct.h const.h global.h gfx2surface.h \ + loadsave.h gfx2log.h diff --git a/src/engine.c b/src/engine.c index 6d1d5346..12b983bc 100644 --- a/src/engine.c +++ b/src/engine.c @@ -71,9 +71,17 @@ static byte* Window_background[8]; static void Save_background(byte **buffer, int x_pos, int y_pos, int width, int height) { int index; - if(*buffer != NULL) DEBUG("WARNING : buffer already allocated !!!",0); + if(*buffer != NULL) + { + GFX2_Log(GFX2_WARNING, "%s() WARNING : buffer already allocated !!!\n", __func__); + free(*buffer); + } *buffer=(byte *) malloc(width*Menu_factor_X*height*Menu_factor_Y*Pixel_width); - if(*buffer==NULL) Error(0); + if(*buffer==NULL) + { + Error(0); + return; + } for (index=0; index<(height*Menu_factor_Y); index++) Read_line(x_pos,y_pos+index,width*Menu_factor_X,(*buffer)+((int)index*width*Menu_factor_X*Pixel_width)); } diff --git a/src/errors.h b/src/errors.h index 7d9e20d4..79a2d88f 100644 --- a/src/errors.h +++ b/src/errors.h @@ -23,6 +23,8 @@ /// Functions and macros for tracing and error reporting. ////////////////////////////////////////////////////////////////////////////// +#include "gfx2log.h" + #ifdef __VBCC__ #define __func__ "stupid compiler !" #endif @@ -31,10 +33,10 @@ #endif /// Prints the source filename, line number, function name, a string and an integer. -#define DEBUG(y,z) printf("%s %d %s | %s : %d###\n",__FILE__,__LINE__,__func__,y,(unsigned int)z) +#define DEBUG(y,z) GFX2_Log(GFX2_DEBUG, "%s %d %s | %s : %d###\n",__FILE__,__LINE__,__func__,y,(unsigned int)z) /// Same as ::DEBUG but in hexadecimal -#define DEBUGX(y,z) printf("%s %d %s | %s : %X###\n",__FILE__,__LINE__,__func__,y,(unsigned int)z) +#define DEBUGX(y,z) GFX2_Log(GFX2_DEBUG, "%s %d %s | %s : %X###\n",__FILE__,__LINE__,__func__,y,(unsigned int)z) /// Helper function used by the macro ::Error void Error_function(int error_code, const char *filename, int line_number, const char *function_name); diff --git a/src/fileformats.c b/src/fileformats.c index e0707844..c69eb373 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -5318,7 +5318,7 @@ void Load_PCX(T_IO_Context * context) || ! Read_byte(file,&(context->Palette[index].B)) ) { File_error=2; - DEBUG("ERROR READING PCX PALETTE !",index); + GFX2_Log(GFX2_ERROR, "ERROR READING PCX PALETTE ! index=%d\n", index); break; } } diff --git a/src/gfx2log.c b/src/gfx2log.c index f2af27c7..a95221d6 100644 --- a/src/gfx2log.c +++ b/src/gfx2log.c @@ -34,12 +34,23 @@ extern void GFX2_Log(GFX2_Log_priority_T priority, const char * fmt, ...) va_start(ap, fmt); GFX2_LogV(priority, fmt, ap); va_end(ap); +#if defined(_MSC_VER) && defined(DEBUG) + { + char message[1024]; + va_start(ap, fmt); + vsnprintf(message, sizeof(message), fmt, ap); + va_end(ap); + OutputDebugStringA(message); + } +#endif } extern void GFX2_LogV(GFX2_Log_priority_T priority, const char * fmt, va_list ap) { +#if !defined(DEBUG) if ((unsigned)GFX2_verbosity_level < (unsigned)priority) return; +#endif #if defined(USE_SDL2) { int sdl_priority; @@ -62,6 +73,7 @@ extern void GFX2_LogV(GFX2_Log_priority_T priority, const char * fmt, va_list ap } SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, sdl_priority, fmt, ap); } -#endif +#else vfprintf((unsigned)priority >= GFX2_INFO ? stdout : stderr, fmt, ap); +#endif } diff --git a/src/init.c b/src/init.c index 8ebfc2c4..d2b912da 100644 --- a/src/init.c +++ b/src/init.c @@ -1930,7 +1930,7 @@ static void Set_video_mode(short width, if (Nb_video_modes >= MAX_VIDEO_MODES-1) { - DEBUG("Error! Attempt to create too many videomodes. Maximum is:", MAX_VIDEO_MODES); + GFX2_Log(GFX2_ERROR, "Attempt to create too many videomodes. Maximum is: %d\n", MAX_VIDEO_MODES); return; } if (!fullscreen) diff --git a/src/input.c b/src/input.c index 88df701d..f3e70bec 100644 --- a/src/input.c +++ b/src/input.c @@ -1093,11 +1093,13 @@ int Get_input(int sleep_time) // Drop of zero files. Thanks for the information, Bill. } } +#else + GFX2_Log(GFX2_DEBUG, "Unhandled SDL_SYSWMEVENT\n"); #endif break; default: - //DEBUG("Unhandled SDL event number : ",event.type); + GFX2_Log(GFX2_DEBUG, "Unhandled SDL event number : %d\n",event.type); break; } } diff --git a/src/main.c b/src/main.c index 629aba7b..26203531 100644 --- a/src/main.c +++ b/src/main.c @@ -164,11 +164,7 @@ void Display_syntax(void) // ---------------------------- Sortie impromptue ---------------------------- void Warning_function(const char *message, const char *filename, int line_number, const char *function_name) { - printf("Warning in file %s, line %d, function %s : %s\n", filename, line_number, function_name, message); -#if defined(_MSC_VER) && defined(DEBUG) - OutputDebugStringA(message); - OutputDebugStringA("\n"); -#endif + GFX2_Log(GFX2_WARNING, "Warning in file %s, line %d, function %s : %s\n", filename, line_number, function_name, message); } @@ -678,6 +674,9 @@ int Init_program(int argc,char * argv[]) Spare.time_of_safety_backup = 0; + // analyse commande line as soon as possible + file_in_command_line=Analyze_command_line(argc, argv, main_filename, main_directory, spare_filename, spare_directory); + #if defined(USE_SDL) || defined(USE_SDL2) // SDL if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) @@ -687,6 +686,9 @@ int Init_program(int argc,char * argv[]) return(0); } +#if defined(USE_SDL2) + SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE); +#endif Joystick = SDL_JoystickOpen(0); #endif #if defined(USE_SDL) @@ -803,10 +805,10 @@ int Init_program(int argc,char * argv[]) // Pas un problème, on a les valeurs par défaut. break; case ERROR_CFG_CORRUPTED: - DEBUG("Corrupted CFG file.",0); + GFX2_Log(GFX2_ERROR, "Corrupted CFG file.\n"); break; case ERROR_CFG_OLD: - DEBUG("Unknown CFG file version, not loaded.",0); + GFX2_Log(GFX2_WARNING, "Unknown CFG file version, not loaded.\n"); break; } // Charger la configuration du .INI @@ -821,8 +823,6 @@ int Init_program(int argc,char * argv[]) Compute_menu_offsets(); - file_in_command_line=Analyze_command_line(argc, argv, main_filename, main_directory, spare_filename, spare_directory); - Current_help_section=0; Help_position=0; diff --git a/src/saveini.c b/src/saveini.c index 7ae07545..72114ebf 100644 --- a/src/saveini.c +++ b/src/saveini.c @@ -338,7 +338,7 @@ int Save_INI_set_values(FILE * old_file,FILE * new_file,char * buffer,char * opt free(result_buffer); free(upper_buffer); free(option_upper); - DEBUG("END OF FILE",0); + GFX2_Log(GFX2_WARNING, "%s(): END OF FILE\n", __func__); return ERROR_INI_CORRUPTED; } diff --git a/src/sdlscreen.c b/src/sdlscreen.c index 889cda01..06dcca1d 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -132,7 +132,7 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen) // Check the mode we got, in case it was different from the one we requested. if (Screen_SDL->w != *width || Screen_SDL->h != *height) { - DEBUG("Error: Got a different video mode than the requested one!",0); + GFX2_Log(GFX2_WARNING, "Got a different video mode than the requested one! %dx%d => %dx%d\n", *width, *height, Screen_SDL->w, Screen_SDL->h); *width = Screen_SDL->w; *height = Screen_SDL->h; } @@ -140,7 +140,7 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen) } else { - DEBUG("Error: Unable to change video mode!",0); + GFX2_Log(GFX2_ERROR, "Unable to change video mode!\n"); } #else // SDL2 diff --git a/src/text.c b/src/text.c index 04fe7342..2d1e8539 100644 --- a/src/text.c +++ b/src/text.c @@ -712,7 +712,7 @@ byte *Render_text_SFont(const char *str, int font_number, int *width, int *heigh font=SFont_InitFont(font_surface); if (!font) { - DEBUG("Font init failed",1); + GFX2_Log(GFX2_ERROR, "Font init failed : %s\n", Font_name(font_number)); Free_GFX2_Surface(font_surface); return NULL; }