From f10cdeb1574274e9b5edeee57ca3c3082febe23c Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Thu, 26 Jul 2007 09:36:45 +0000 Subject: [PATCH] * Make debugprint.c a C++ file instead of C * Use std::ostream instead of FILE* for debug printing git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2198 4a71c877-e1ca-e34f-864e-861f7616d084 --- tools/editworld/src/EditWorld.dsp | 4 +- tools/editworld/src/bmphandler.cpp | 2 +- tools/editworld/src/brush.cpp | 2 +- tools/editworld/src/brushprop.cpp | 2 +- tools/editworld/src/bteditdoc.cpp | 2 +- tools/editworld/src/bteditview.cpp | 2 +- tools/editworld/src/chnkio.cpp | 2 +- tools/editworld/src/ddimage.cpp | 2 +- .../src/{debugprint.c => debugprint.cpp} | 45 +++++++------------ .../src/{debugprint.h => debugprint.hpp} | 38 +++++++--------- tools/editworld/src/dibdraw.cpp | 2 +- tools/editworld/src/directx.cpp | 2 +- tools/editworld/src/expandlimitsdlg.cpp | 2 +- tools/editworld/src/fileparse.cpp | 2 +- tools/editworld/src/gateway.cpp | 2 +- tools/editworld/src/gatewaysup.cpp | 2 +- tools/editworld/src/geometry.cpp | 2 +- tools/editworld/src/grdland.cpp | 2 +- tools/editworld/src/heightmap.cpp | 2 +- tools/editworld/src/initiallimitsdlg.cpp | 2 +- tools/editworld/src/keyhandler.cpp | 2 +- tools/editworld/src/limitsdialog.cpp | 2 +- tools/editworld/src/model.cpp | 2 +- tools/editworld/src/pcxhandler.cpp | 2 +- tools/editworld/src/textsel.cpp | 2 +- tools/editworld/src/textureview.cpp | 2 +- tools/editworld/src/tiletypes.cpp | 2 +- tools/editworld/src/wfview.cpp | 2 +- 28 files changed, 58 insertions(+), 79 deletions(-) rename tools/editworld/src/{debugprint.c => debugprint.cpp} (71%) rename tools/editworld/src/{debugprint.h => debugprint.hpp} (80%) diff --git a/tools/editworld/src/EditWorld.dsp b/tools/editworld/src/EditWorld.dsp index 645a521ec..505b56a02 100644 --- a/tools/editworld/src/EditWorld.dsp +++ b/tools/editworld/src/EditWorld.dsp @@ -126,7 +126,7 @@ SOURCE=.\ddimage.cpp # End Source File # Begin Source File -SOURCE=.\debugprint.c +SOURCE=.\debugprint.cpp # End Source File # Begin Source File @@ -294,7 +294,7 @@ SOURCE=.\debug.h # End Source File # Begin Source File -SOURCE=.\debugprint.h +SOURCE=.\debugprint.hpp # End Source File # Begin Source File diff --git a/tools/editworld/src/bmphandler.cpp b/tools/editworld/src/bmphandler.cpp index dff5904b7..aab34df60 100644 --- a/tools/editworld/src/bmphandler.cpp +++ b/tools/editworld/src/bmphandler.cpp @@ -25,7 +25,7 @@ #include "winstuff.h" #include "stdio.h" #include "assert.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "bmphandler.h" BMPHandler::BMPHandler() : diff --git a/tools/editworld/src/brush.cpp b/tools/editworld/src/brush.cpp index 7182eab3b..b5a032763 100644 --- a/tools/editworld/src/brush.cpp +++ b/tools/editworld/src/brush.cpp @@ -27,7 +27,7 @@ #include "bteditdoc.h" #include "brush.h" #include "tiletypes.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "assert.h" #ifdef _DEBUG diff --git a/tools/editworld/src/brushprop.cpp b/tools/editworld/src/brushprop.cpp index dc1e02cef..dd58a2e5a 100644 --- a/tools/editworld/src/brushprop.cpp +++ b/tools/editworld/src/brushprop.cpp @@ -28,7 +28,7 @@ #include "btedit.h" #include "bteditdoc.h" #include "wfview.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "brushprop.h" diff --git a/tools/editworld/src/bteditdoc.cpp b/tools/editworld/src/bteditdoc.cpp index b0ca64e48..5b39e1d3d 100644 --- a/tools/editworld/src/bteditdoc.cpp +++ b/tools/editworld/src/bteditdoc.cpp @@ -32,7 +32,7 @@ #include "mapprefs.h" #include "textureprefs.h" #include "dibdraw.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "wfview.h" #include "textureview.h" #include "bteditview.h" diff --git a/tools/editworld/src/bteditview.cpp b/tools/editworld/src/bteditview.cpp index 6ae3ee6ae..973a361b3 100644 --- a/tools/editworld/src/bteditview.cpp +++ b/tools/editworld/src/bteditview.cpp @@ -31,7 +31,7 @@ #include "bteditdoc.h" #include "bteditview.h" //#include "editstats.h" -#include "debugprint.h" +#include "debugprint.hpp" //#include "statsview.h" #include "tiletypes.h" #include "objectproperties.h" diff --git a/tools/editworld/src/chnkio.cpp b/tools/editworld/src/chnkio.cpp index d44b5d93e..9ea669114 100644 --- a/tools/editworld/src/chnkio.cpp +++ b/tools/editworld/src/chnkio.cpp @@ -26,7 +26,7 @@ #include "windowsx.h" #include "stdio.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "chnkio.h" diff --git a/tools/editworld/src/ddimage.cpp b/tools/editworld/src/ddimage.cpp index 137cf79ed..c331d6d27 100644 --- a/tools/editworld/src/ddimage.cpp +++ b/tools/editworld/src/ddimage.cpp @@ -27,7 +27,7 @@ #include "windowsx.h" #include "stdio.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "directx.h" diff --git a/tools/editworld/src/debugprint.c b/tools/editworld/src/debugprint.cpp similarity index 71% rename from tools/editworld/src/debugprint.c rename to tools/editworld/src/debugprint.cpp index 419d71cec..b4984b76f 100644 --- a/tools/editworld/src/debugprint.c +++ b/tools/editworld/src/debugprint.cpp @@ -24,33 +24,29 @@ #include "windows.h" #include "windowsx.h" -#include "stdio.h" +#include #include "tchar.h" +#include "debugprint.hpp" #ifdef _DEBUG extern void DebugWinPrint(char *String); -FILE* DebugStream=NULL; +static std::ostream* DebugStream = NULL; -void DebugOpen(char* LogName) +void DebugOpen(const char* LogName) { - if(DebugStream) { - fclose(DebugStream); - DebugStream = NULL; - } + DebugClose(); - DebugStream = fopen(LogName,"wb"); - - fprintf(DebugStream,"This build : %s %s\n\n",__DATE__,__TIME__); + DebugStream = new std::ofstream(LogName, std::ios_base::binary); + + *DebugStream << "This build : " << __DATE__ << " " << __TIME__ << "\n" << std::endl; } -void DebugClose(void) +void DebugClose() { - if(DebugStream) { - fclose(DebugStream); - } - DebugStream=NULL; + delete DebugStream; + DebugStream = NULL; } void DebugPrint(const TCHAR *format, ...) @@ -61,23 +57,12 @@ void DebugPrint(const TCHAR *format, ...) va_start(args,format); _vsntprintf(buf,4096,format,args); va_end(args); + + // Display the debug string in any debugger (WINAPI function) OutputDebugString(buf); - if(DebugStream!=NULL) { - fprintf(DebugStream,"%s",buf); - } -// DebugWinPrint(buf); + if(DebugStream) + *DebugStream << buf << std::endl; } -#else - -void DebugOpen(char* LogName) -{ -} - -void DebugClose(void) -{ -} - - #endif diff --git a/tools/editworld/src/debugprint.h b/tools/editworld/src/debugprint.hpp similarity index 80% rename from tools/editworld/src/debugprint.h rename to tools/editworld/src/debugprint.hpp index e7b9e78e7..d2e5f35d8 100644 --- a/tools/editworld/src/debugprint.h +++ b/tools/editworld/src/debugprint.hpp @@ -22,9 +22,8 @@ $HeadURL$ */ -#ifdef __cplusplus -extern "C" { -#endif +#ifndef __INCLUDE_DEBUGPRINT_HPP__ +#define __INCLUDE_DEBUGPRINT_HPP__ //#define DEBUG0 //#define DEBUG1 @@ -33,9 +32,6 @@ extern "C" { //#define DEBUG4 #define DEBUG5 -void DebugOpen(char* LogName); -void DebugClose(void); - #ifndef _TCHAR_DEFINED typedef char TCHAR, *PTCHAR; typedef unsigned char TBYTE , *PTBYTE ; @@ -44,26 +40,27 @@ typedef unsigned char TBYTE , *PTBYTE ; #ifdef _DEBUG +void DebugOpen(const char* LogName); +void DebugClose(); void DebugPrint(const TCHAR *format, ...); #else +#define DebugOpen +#define DebugClose #define DebugPrint #endif #ifdef __cplusplus - #ifndef ASSERT - - #define ASSERT - - #endif +# ifndef ASSERT +# define ASSERT +# endif #else - #ifndef ASSERT +# ifndef ASSERT +# define DBG_ASSERT(a,b) if(!(a)) { DebugPrint("Assertion Failure in %s, line : %d\n",__FILE__, __LINE__); \ + DebugPrint(b); \ + DebugPrint("\n"); } +# define ASSERT(a) DBG_ASSERT a - #define DBG_ASSERT(a,b) if(!(a)) { DebugPrint("Assertion Failure in %s, line : %d\n",__FILE__, __LINE__); \ - DebugPrint(b); \ - DebugPrint("\n"); } - #define ASSERT(a) DBG_ASSERT a - - #endif +# endif #endif #define DBERROR(a) DebugPrint a; @@ -106,7 +103,4 @@ void DebugPrint(const TCHAR *format, ...); #define DBP5 #endif -#ifdef __cplusplus -} -#endif - +#endif // __INCLUDE_DEBUGPRINT_HPP__ diff --git a/tools/editworld/src/dibdraw.cpp b/tools/editworld/src/dibdraw.cpp index e20ab4222..4ce3b1053 100644 --- a/tools/editworld/src/dibdraw.cpp +++ b/tools/editworld/src/dibdraw.cpp @@ -32,7 +32,7 @@ #include #include "dibdraw.h" -#include "debugprint.h" +#include "debugprint.hpp" // Create a DIBDraw class with user specified dimensions and colour depth. diff --git a/tools/editworld/src/directx.cpp b/tools/editworld/src/directx.cpp index d560ed4d5..df247553b 100644 --- a/tools/editworld/src/directx.cpp +++ b/tools/editworld/src/directx.cpp @@ -33,7 +33,7 @@ #include "directx.h" #include "geometry.h" -#include "debugprint.h" +#include "debugprint.hpp" //#define FOGGY #define FILTER diff --git a/tools/editworld/src/expandlimitsdlg.cpp b/tools/editworld/src/expandlimitsdlg.cpp index 084b98ba5..ac0dd5048 100644 --- a/tools/editworld/src/expandlimitsdlg.cpp +++ b/tools/editworld/src/expandlimitsdlg.cpp @@ -26,7 +26,7 @@ #include "stdafx.h" #include "btedit.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "expandlimitsdlg.h" #ifdef _DEBUG diff --git a/tools/editworld/src/fileparse.cpp b/tools/editworld/src/fileparse.cpp index f3972fff9..6fefa6c33 100644 --- a/tools/editworld/src/fileparse.cpp +++ b/tools/editworld/src/fileparse.cpp @@ -30,7 +30,7 @@ #include #include "fileparse.h" -#include "debugprint.h" +#include "debugprint.hpp" fileParser::fileParser(std::istream& file, short flags) : diff --git a/tools/editworld/src/gateway.cpp b/tools/editworld/src/gateway.cpp index 660931dd5..f6076cfec 100644 --- a/tools/editworld/src/gateway.cpp +++ b/tools/editworld/src/gateway.cpp @@ -41,7 +41,7 @@ #define MAP_MAXWIDTH 256 #define MAP_MAXHEIGHT 256 -#include "debugprint.h" +#include "debugprint.hpp" #include "gateway.hpp" diff --git a/tools/editworld/src/gatewaysup.cpp b/tools/editworld/src/gatewaysup.cpp index 4cd373451..66d243f24 100644 --- a/tools/editworld/src/gatewaysup.cpp +++ b/tools/editworld/src/gatewaysup.cpp @@ -49,7 +49,7 @@ #define MAP_MAXWIDTH 256 #define MAP_MAXHEIGHT 256 -#include "debugprint.h" +#include "debugprint.hpp" #include "assert.h" #include "gateway.hpp" diff --git a/tools/editworld/src/geometry.cpp b/tools/editworld/src/geometry.cpp index e936ed235..09ede3047 100644 --- a/tools/editworld/src/geometry.cpp +++ b/tools/editworld/src/geometry.cpp @@ -32,7 +32,7 @@ #include #include -#include "debugprint.h" +#include "debugprint.hpp" #include "geometry.h" #include "directx.h" diff --git a/tools/editworld/src/grdland.cpp b/tools/editworld/src/grdland.cpp index 84a4fde64..6cd33afe6 100644 --- a/tools/editworld/src/grdland.cpp +++ b/tools/editworld/src/grdland.cpp @@ -27,7 +27,7 @@ #include "windowsx.h" #include "stdio.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "grdland.h" diff --git a/tools/editworld/src/heightmap.cpp b/tools/editworld/src/heightmap.cpp index 594ef2212..ad5338879 100644 --- a/tools/editworld/src/heightmap.cpp +++ b/tools/editworld/src/heightmap.cpp @@ -28,7 +28,7 @@ #include "stdio.h" #include "math.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "directx.h" #include "geometry.h" diff --git a/tools/editworld/src/initiallimitsdlg.cpp b/tools/editworld/src/initiallimitsdlg.cpp index 631888332..19cc68cab 100644 --- a/tools/editworld/src/initiallimitsdlg.cpp +++ b/tools/editworld/src/initiallimitsdlg.cpp @@ -26,7 +26,7 @@ #include "stdafx.h" #include "btedit.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "initiallimitsdlg.h" #ifdef _DEBUG diff --git a/tools/editworld/src/keyhandler.cpp b/tools/editworld/src/keyhandler.cpp index a0808dcd7..f8bdb4582 100644 --- a/tools/editworld/src/keyhandler.cpp +++ b/tools/editworld/src/keyhandler.cpp @@ -26,7 +26,7 @@ #include "windowsx.h" #include "stdio.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "keyhandler.h" diff --git a/tools/editworld/src/limitsdialog.cpp b/tools/editworld/src/limitsdialog.cpp index 507ef70c2..713ce5889 100644 --- a/tools/editworld/src/limitsdialog.cpp +++ b/tools/editworld/src/limitsdialog.cpp @@ -26,7 +26,7 @@ #include "stdafx.h" #include "btedit.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "limitsdialog.h" #ifdef _DEBUG diff --git a/tools/editworld/src/model.cpp b/tools/editworld/src/model.cpp index c1e65942f..7f96b9f1b 100644 --- a/tools/editworld/src/model.cpp +++ b/tools/editworld/src/model.cpp @@ -28,7 +28,7 @@ #include "stdio.h" #include "math.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "directx.h" #include "geometry.h" diff --git a/tools/editworld/src/pcxhandler.cpp b/tools/editworld/src/pcxhandler.cpp index bcbd34c3d..94d49bf48 100644 --- a/tools/editworld/src/pcxhandler.cpp +++ b/tools/editworld/src/pcxhandler.cpp @@ -27,7 +27,7 @@ #include "windowsx.h" #include "stdio.h" #include "typedefs.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "pcxhandler.h" diff --git a/tools/editworld/src/textsel.cpp b/tools/editworld/src/textsel.cpp index a609dc7a6..ff85f4c77 100644 --- a/tools/editworld/src/textsel.cpp +++ b/tools/editworld/src/textsel.cpp @@ -25,7 +25,7 @@ // #include "stdafx.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "textsel.h" #include "heightmap.h" #include "tiletypes.h" diff --git a/tools/editworld/src/textureview.cpp b/tools/editworld/src/textureview.cpp index d8131cf56..08d12a98c 100644 --- a/tools/editworld/src/textureview.cpp +++ b/tools/editworld/src/textureview.cpp @@ -30,7 +30,7 @@ #include "textureview.h" #include "tiletypes.h" #include "autoflagdialog.h" -#include "debugprint.h" +#include "debugprint.hpp" #ifdef _DEBUG #define new DEBUG_NEW diff --git a/tools/editworld/src/tiletypes.cpp b/tools/editworld/src/tiletypes.cpp index 5de8f9ffd..acea4b61e 100644 --- a/tools/editworld/src/tiletypes.cpp +++ b/tools/editworld/src/tiletypes.cpp @@ -32,7 +32,7 @@ #include "directx.h" #include "geometry.h" -#include "debugprint.h" +#include "debugprint.hpp" #include "ddimage.h" #include "heightmap.h" diff --git a/tools/editworld/src/wfview.cpp b/tools/editworld/src/wfview.cpp index 8bdb907f7..ad16b3bcd 100644 --- a/tools/editworld/src/wfview.cpp +++ b/tools/editworld/src/wfview.cpp @@ -31,7 +31,7 @@ //#include "DBView.h" #include "tiletypes.h" //#include "EditStats.h" -#include "debugprint.h" +#include "debugprint.hpp" //#include "DebugWin.h" #include "objectproperties.h"