summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-02-15 00:14:59 +0100
committerAki <please@ignore.pl>2022-02-15 00:14:59 +0100
commit2ba78cf22f6f0f7c488d0d4cb606c05a841474f2 (patch)
tree16fa28469582c2fd5c9b0bde85f619336a2d4076
parent0ea71e86d0cf91718d3a9406060d7413f9c5aa01 (diff)
downloadstarshatter-2ba78cf22f6f0f7c488d0d4cb606c05a841474f2.zip
starshatter-2ba78cf22f6f0f7c488d0d4cb606c05a841474f2.tar.gz
starshatter-2ba78cf22f6f0f7c488d0d4cb606c05a841474f2.tar.bz2
Exported infamous Print to FoundationEx
-rw-r--r--FoundationEx/CMakeLists.txt1
-rw-r--r--FoundationEx/Utils.cpp39
-rw-r--r--FoundationEx/Utils.h17
-rw-r--r--Stars45/Archive.cpp3
-rw-r--r--Stars45/Bolt.cpp3
-rw-r--r--Stars45/CameraView.cpp5
-rw-r--r--Stars45/Color.cpp3
-rw-r--r--Stars45/ContentBundle.cpp3
-rw-r--r--Stars45/Encrypt.cpp3
-rw-r--r--Stars45/ExceptionHandler.cpp2
-rw-r--r--Stars45/Game.cpp16
-rw-r--r--Stars45/Game.h2
-rw-r--r--Stars45/Locale_ss.cpp3
-rw-r--r--Stars45/MCIWave.cpp5
-rw-r--r--Stars45/MachineInfo.cpp3
-rw-r--r--Stars45/Main.cpp8
-rw-r--r--Stars45/Parser.cpp3
-rw-r--r--Stars45/Projector.cpp3
-rw-r--r--Stars45/Reader.cpp4
-rw-r--r--Stars45/Scene.cpp3
-rw-r--r--Stars45/Skin.cpp3
-rw-r--r--Stars45/Sky.cpp3
-rw-r--r--Stars45/Solid.cpp3
-rw-r--r--Stars45/SoundD3D.cpp2
-rw-r--r--Stars45/Term.cpp3
-rw-r--r--Stars45/TexCubeDX9.cpp2
-rw-r--r--Stars45/TexDX9.cpp2
-rw-r--r--Stars45/VideoDX9.cpp2
-rw-r--r--Stars45/VideoDX9Enum.cpp2
29 files changed, 84 insertions, 67 deletions
diff --git a/FoundationEx/CMakeLists.txt b/FoundationEx/CMakeLists.txt
index 8672619..c2b546b 100644
--- a/FoundationEx/CMakeLists.txt
+++ b/FoundationEx/CMakeLists.txt
@@ -4,6 +4,7 @@ add_library(
STATIC
MemDebug.cpp
Text.cpp
+ Utils.cpp
)
target_include_directories(
FoundationEx
diff --git a/FoundationEx/Utils.cpp b/FoundationEx/Utils.cpp
new file mode 100644
index 0000000..8a9f157
--- /dev/null
+++ b/FoundationEx/Utils.cpp
@@ -0,0 +1,39 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#include <stdarg.h>
+#include <stdio.h>
+
+
+FILE* ErrLog = nullptr;
+
+
+void AssignErrLog(FILE * out)
+{
+ ErrLog = out;
+}
+
+
+int CloseErrLog()
+{
+ if (ErrLog)
+ return fclose(Errlog);
+ return 0;
+}
+
+
+void Print(const char* fmt, ...)
+{
+ if (!ErrLog) return;
+ va_list args;
+ va_start(args, fmt);
+ vfprintf_s(ErrLog, fmt, args);
+ fflush(ErrLog);
+ va_end(args);
+}
+
+
+#endif // Utils_h
diff --git a/FoundationEx/Utils.h b/FoundationEx/Utils.h
new file mode 100644
index 0000000..da7b66d
--- /dev/null
+++ b/FoundationEx/Utils.h
@@ -0,0 +1,17 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#ifndef Utils_h
+#define Utils_h
+
+#include <stdio.h>
+
+
+void AssignErrLog(FILE * out);
+void CloseErrLog();
+void Print(const char* fmt, ...);
+
+#endif // Utils_h
diff --git a/Stars45/Archive.cpp b/Stars45/Archive.cpp
index cf45331..258452d 100644
--- a/Stars45/Archive.cpp
+++ b/Stars45/Archive.cpp
@@ -10,6 +10,7 @@
#include "MemDebug.h"
#include "Types.h"
#include "Archive.h"
+#include "Utils.h"
#include <fcntl.h>
#include <sys/types.h>
@@ -22,8 +23,6 @@
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
-
int verbose = 1;
int err;
diff --git a/Stars45/Bolt.cpp b/Stars45/Bolt.cpp
index 3caed4f..be8792a 100644
--- a/Stars45/Bolt.cpp
+++ b/Stars45/Bolt.cpp
@@ -16,8 +16,7 @@
#include "Bitmap.h"
#include "Camera.h"
#include "Video.h"
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/CameraView.cpp b/Stars45/CameraView.cpp
index 3a4ea0d..ed39abd 100644
--- a/Stars45/CameraView.cpp
+++ b/Stars45/CameraView.cpp
@@ -25,10 +25,7 @@
#include "Bitmap.h"
#include "Screen.h"
#include "Game.h"
-
-// +--------------------------------------------------------------------+
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/Color.cpp b/Stars45/Color.cpp
index 6f6e7ae..aa01293 100644
--- a/Stars45/Color.cpp
+++ b/Stars45/Color.cpp
@@ -16,11 +16,10 @@
#include "Video.h"
#include "Pcx.h"
#include "Fix.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
-
Color Color::White = Color(255,255,255);
Color Color::Black = Color( 0, 0, 0);
Color Color::Gray = Color(128,128,128);
diff --git a/Stars45/ContentBundle.cpp b/Stars45/ContentBundle.cpp
index ad6a970..9f09833 100644
--- a/Stars45/ContentBundle.cpp
+++ b/Stars45/ContentBundle.cpp
@@ -14,8 +14,7 @@
#include "MemDebug.h"
#include "ContentBundle.h"
#include "DataLoader.h"
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/Encrypt.cpp b/Stars45/Encrypt.cpp
index 3f86fdb..ba07099 100644
--- a/Stars45/Encrypt.cpp
+++ b/Stars45/Encrypt.cpp
@@ -14,11 +14,10 @@
#include "MemDebug.h"
#include "Encrypt.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
-
static long k[4] = {
0x3B398E26,
0x40C29501,
diff --git a/Stars45/ExceptionHandler.cpp b/Stars45/ExceptionHandler.cpp
index b6d6bee..d93a88f 100644
--- a/Stars45/ExceptionHandler.cpp
+++ b/Stars45/ExceptionHandler.cpp
@@ -14,7 +14,7 @@
#include <windows.h>
#include <imagehlp.h>
-extern void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp
index ca66426..65c0e3f 100644
--- a/Stars45/Game.cpp
+++ b/Stars45/Game.cpp
@@ -27,10 +27,6 @@
// +--------------------------------------------------------------------+
-FILE* ErrLog = 0;
-int ErrLine = 0;
-char ErrBuf[1024];
-
Game* game = 0;
bool Game::active = false;
@@ -1377,18 +1373,6 @@ GetKeyPlus(int& key, int& shift)
// +====================================================================+
-void Print(const char* fmt, ...)
-{
- if (ErrLog) {
- vsprintf_s(ErrBuf, fmt, (char *)(&fmt+1));
-
- fprintf(ErrLog, ErrBuf);
- fflush(ErrLog);
- }
-}
-
-// +====================================================================+
-
DWORD GetRealTime()
{
if (game)
diff --git a/Stars45/Game.h b/Stars45/Game.h
index f450d10..557fc7c 100644
--- a/Stars45/Game.h
+++ b/Stars45/Game.h
@@ -16,8 +16,6 @@
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
-
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void FlushKeys();
diff --git a/Stars45/Locale_ss.cpp b/Stars45/Locale_ss.cpp
index d1b5cd8..334434a 100644
--- a/Stars45/Locale_ss.cpp
+++ b/Stars45/Locale_ss.cpp
@@ -13,8 +13,7 @@
#include "MemDebug.h"
#include "Locale_ss.h"
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/MCIWave.cpp b/Stars45/MCIWave.cpp
index 861894f..be72e27 100644
--- a/Stars45/MCIWave.cpp
+++ b/Stars45/MCIWave.cpp
@@ -14,10 +14,7 @@
#include "MemDebug.h"
#include "Types.h"
#include "Game.h"
-
-// +----------------------------------------------------------------------+
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +----------------------------------------------------------------------+
diff --git a/Stars45/MachineInfo.cpp b/Stars45/MachineInfo.cpp
index 59f3566..85d2bd6 100644
--- a/Stars45/MachineInfo.cpp
+++ b/Stars45/MachineInfo.cpp
@@ -15,6 +15,7 @@
#include "MemDebug.h"
#include "MachineInfo.h"
+#include "Utils.h"
#define DIRECTINPUT_VERSION 0x0700
@@ -26,8 +27,6 @@
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
-
static int cpu_class=-1;
static int cpu_speed=-1;
static int platform=-1;
diff --git a/Stars45/Main.cpp b/Stars45/Main.cpp
index f4f4943..bd79886 100644
--- a/Stars45/Main.cpp
+++ b/Stars45/Main.cpp
@@ -11,6 +11,7 @@
#include "Starshatter.h"
#include "StarServer.h"
#include "HUDView.h"
+#include "Utils.h"
#include "NetHost.h"
#include "NetAddr.h"
@@ -33,7 +34,6 @@
// WinMain
// +--------------------------------------------------------------------+
-extern FILE* ErrLog;
extern int VD3D_describe_things;
int dump_missions = 0;
@@ -57,9 +57,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
int do_server = 0;
if (strstr(lpCmdLine, "-server"))
- ErrLog = fopen("serverlog.txt", "wb");
+ AssignErrLog(fopen("serverlog.txt", "wb"));
else
- ErrLog = fopen("errlog.txt", "wb");
+ AssignErrLog(fopen("errlog.txt", "wb"));
PrintLogHeader();
@@ -148,7 +148,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
Print("+====================================================================+\n");
Print(" END OF LINE.\n");
- fclose(ErrLog);
+ CloseErrLog();
return result;
}
diff --git a/Stars45/Parser.cpp b/Stars45/Parser.cpp
index 103f7be..b1c9ef5 100644
--- a/Stars45/Parser.cpp
+++ b/Stars45/Parser.cpp
@@ -16,13 +16,12 @@
#include "Token.h"
#include "Parser.h"
#include "Term.h"
+#include "Utils.h"
#include <stdio.h>
#include <stdlib.h>
enum KEYS { KEY_TRUE, KEY_FALSE, KEY_DEF, KEY_MINUS };
-void Print(const char* fmt, ...);
-
static int dump_tokens = 0;
// +-------------------------------------------------------------------+
diff --git a/Stars45/Projector.cpp b/Stars45/Projector.cpp
index 3882178..8396d48 100644
--- a/Stars45/Projector.cpp
+++ b/Stars45/Projector.cpp
@@ -19,14 +19,13 @@
#include "MemDebug.h"
#include "Projector.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
static const float CLIP_PLANE_EPSILON = 0.0001f;
static const double Z_NEAR = 1.0;
-void Print(const char* fmt, ...);
-
// +--------------------------------------------------------------------+
static Camera emergency_cam;
diff --git a/Stars45/Reader.cpp b/Stars45/Reader.cpp
index efb1ce7..07f4e7a 100644
--- a/Stars45/Reader.cpp
+++ b/Stars45/Reader.cpp
@@ -16,9 +16,7 @@
#include <stdio.h>
#include <fstream>
#include <ctype.h>
-
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +-------------------------------------------------------------------+
diff --git a/Stars45/Scene.cpp b/Stars45/Scene.cpp
index e969440..5fc4f19 100644
--- a/Stars45/Scene.cpp
+++ b/Stars45/Scene.cpp
@@ -15,8 +15,7 @@
#include "Scene.h"
#include "Graphic.h"
#include "Light.h"
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/Skin.cpp b/Stars45/Skin.cpp
index d35c007..ff41494 100644
--- a/Stars45/Skin.cpp
+++ b/Stars45/Skin.cpp
@@ -14,8 +14,7 @@
#include "MemDebug.h"
#include "Skin.h"
#include "Solid.h"
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +--------------------------------------------------------------------+
diff --git a/Stars45/Sky.cpp b/Stars45/Sky.cpp
index b0e0078..6be9368 100644
--- a/Stars45/Sky.cpp
+++ b/Stars45/Sky.cpp
@@ -20,8 +20,7 @@
#include "DataLoader.h"
#include "Light.h"
#include "Random.h"
-
-void Print(const char* ftm, ...);
+#include "Utils.h"
// +====================================================================+
diff --git a/Stars45/Solid.cpp b/Stars45/Solid.cpp
index 833eee2..6ea1430 100644
--- a/Stars45/Solid.cpp
+++ b/Stars45/Solid.cpp
@@ -20,13 +20,12 @@
#include "Shadow.h"
#include "Projector.h"
#include "Opcode.h"
+#include "Utils.h"
#ifdef for
#undef for
#endif
-void Print(const char* fmt, ...);
-
// +--------------------------------------------------------------------+
static bool use_collision_detection = true;
diff --git a/Stars45/SoundD3D.cpp b/Stars45/SoundD3D.cpp
index d604d97..1fd4f1e 100644
--- a/Stars45/SoundD3D.cpp
+++ b/Stars45/SoundD3D.cpp
@@ -21,6 +21,7 @@
#include "MemDebug.h"
#include "SoundD3D.h"
#include "Game.h"
+#include "Utils.h"
#ifdef DIRECT_SOUND_3D
#include "ia3d.h"
@@ -28,7 +29,6 @@
// +--------------------------------------------------------------------+
-void Print(const char* msg, ...);
char* DSErrStr(HRESULT dserr);
void SoundD3DError(const char* msg, HRESULT dserr);
diff --git a/Stars45/Term.cpp b/Stars45/Term.cpp
index baa4368..4c9831c 100644
--- a/Stars45/Term.cpp
+++ b/Stars45/Term.cpp
@@ -14,8 +14,7 @@
#include "MemDebug.h"
#include "Term.h"
-
-void Print(const char* fmt, ...);
+#include "Utils.h"
// +-------------------------------------------------------------------+
diff --git a/Stars45/TexCubeDX9.cpp b/Stars45/TexCubeDX9.cpp
index 3c89af8..755a0b1 100644
--- a/Stars45/TexCubeDX9.cpp
+++ b/Stars45/TexCubeDX9.cpp
@@ -16,10 +16,10 @@
#include "VideoDX9.h"
#include "Bitmap.h"
#include "Color.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
void VideoDX9Error(const char* msg, HRESULT err);
#ifndef RELEASE
diff --git a/Stars45/TexDX9.cpp b/Stars45/TexDX9.cpp
index d86ae7d..75b5d0f 100644
--- a/Stars45/TexDX9.cpp
+++ b/Stars45/TexDX9.cpp
@@ -16,10 +16,10 @@
#include "VideoDX9.h"
#include "Bitmap.h"
#include "Color.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
-void Print(const char* fmt, ...);
void VideoDX9Error(const char* msg, HRESULT err);
#define TEXDX9_VERBOSE 0
diff --git a/Stars45/VideoDX9.cpp b/Stars45/VideoDX9.cpp
index 1d19151..2f2b356 100644
--- a/Stars45/VideoDX9.cpp
+++ b/Stars45/VideoDX9.cpp
@@ -23,10 +23,10 @@
#include "Polygon.h"
#include "Light.h"
#include "Solid.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
-void Print(const char* msg, ...);
char* D3DErrStr(HRESULT dderr);
void VideoDX9Error(const char* msg, HRESULT dderr);
static TexCacheDX9* texcache = 0;
diff --git a/Stars45/VideoDX9Enum.cpp b/Stars45/VideoDX9Enum.cpp
index c6df690..96f938a 100644
--- a/Stars45/VideoDX9Enum.cpp
+++ b/Stars45/VideoDX9Enum.cpp
@@ -15,10 +15,10 @@
#include "VideoDX9Enum.h"
#include "VideoSettings.h"
#include "Color.h"
+#include "Utils.h"
// +--------------------------------------------------------------------+
-void Print(const char* msg, ...);
char* DDErrStr(HRESULT dderr);
void VideoDX9Error(const char* msg, HRESULT dderr);
int VD3D_describe_things;