diff --git a/Descent3/BriefingParse.h b/Descent3/BriefingParse.h index df74a2d2..5eae21c1 100644 --- a/Descent3/BriefingParse.h +++ b/Descent3/BriefingParse.h @@ -50,9 +50,7 @@ #ifndef __BRIEFPARSE_H_ #define __BRIEFPARSE_H_ -#if defined(POSIX) -#include "linux_fix.h" //for stricmp -#endif +#include "crossplat.h" //for stricmp #include "TelComEfxStructs.h" #include "grdefs.h" diff --git a/Descent3/credits.cpp b/Descent3/credits.cpp index 78936555..307e3aa4 100644 --- a/Descent3/credits.cpp +++ b/Descent3/credits.cpp @@ -77,8 +77,11 @@ * $NoKeywords: $ */ +#include + #include "mono.h" #include "pstypes.h" +#include "crossplat.h" #include "ddio.h" #include "grtext.h" #include "renderer.h" @@ -87,17 +90,10 @@ #include "bitmap.h" #include "descent.h" #include "mem.h" -#include "3d.h" #include "d3music.h" #include "hlsoundlib.h" -#include -#include #include "psrand.h" -#if defined(POSIX) -#include "linux_fix.h" -#endif - /* $$TABLE_GAMEFILE "GameCredits.txt" $$TABLE_GAMEFILE "credits.omf" diff --git a/Descent3/dedicated_server.cpp b/Descent3/dedicated_server.cpp index 664cfaa2..9b133ab6 100644 --- a/Descent3/dedicated_server.cpp +++ b/Descent3/dedicated_server.cpp @@ -112,31 +112,25 @@ typedef int socklen_t; #endif -#include "pstypes.h" +#include "crossplat.h" #include "pserror.h" #include "pstring.h" -#include "cfile.h" #include "inffile.h" #include "dedicated_server.h" #include "multi.h" #include "args.h" #include "AppConsole.h" #include "ddio.h" -#include "newui.h" -#include "ui.h" #include "multi_dll_mgr.h" #include "multi_ui.h" #include "Mission.h" #include "multi_server.h" -#include "Macros.h" -#include "game.h" #include "mem.h" #include "stringtable.h" #include "multi_save_settings.h" #include "objinfo.h" #include "rtperformance.h" #include "player.h" -#include "stringtable.h" #include "init.h" #include "ship.h" #include "hud.h" @@ -794,7 +788,6 @@ void PrintDedicatedMessage(const char *fmt, ...) { #include #include -#include "linux_fix.h" #include "errno.h" #define BOOL bool #ifndef SOCKET diff --git a/Descent3/descent.h b/Descent3/descent.h index 6b446f19..0e4ad4d8 100644 --- a/Descent3/descent.h +++ b/Descent3/descent.h @@ -132,10 +132,7 @@ #include #include "application.h" - -#if defined(POSIX) -#include "linux_fix.h" -#endif +#include "crossplat.h" // The name of this product #ifdef DEMO diff --git a/cfile/cfile.cpp b/cfile/cfile.cpp index 7f442f1c..7ad0478c 100644 --- a/cfile/cfile.cpp +++ b/cfile/cfile.cpp @@ -22,21 +22,13 @@ #include #include #include -#include #include #include #include #include -#if !defined(POSIX) -// Non-Linux Build Includes -#include -#else -// Linux Build Includes -#include "linux_fix.h" -#endif - #include "byteswap.h" +#include "crossplat.h" #include "pserror.h" #include "ddio.h" #include "psglob.h" diff --git a/cfile/inffile.h b/cfile/inffile.h index beaa40de..50c9d26b 100644 --- a/cfile/inffile.h +++ b/cfile/inffile.h @@ -30,7 +30,7 @@ #include #include "cfile.h" -#include "pstypes.h" +#include "crossplat.h" #include "psclass.h" enum InfFileError { diff --git a/ddio/lnxfile.cpp b/ddio/lnxfile.cpp index 08d34b51..74a48385 100644 --- a/ddio/lnxfile.cpp +++ b/ddio/lnxfile.cpp @@ -73,7 +73,7 @@ #endif #include "ddio.h" -#include "linux_fix.h" +#include "crossplat.h" #include "mem.h" #include "pserror.h" diff --git a/legacy/briefinglocalizer/briefinglocalizerDlg.cpp b/legacy/briefinglocalizer/briefinglocalizerDlg.cpp index 2447c9c3..2abe4daf 100644 --- a/legacy/briefinglocalizer/briefinglocalizerDlg.cpp +++ b/legacy/briefinglocalizer/briefinglocalizerDlg.cpp @@ -23,9 +23,7 @@ #include "briefinglocalizer.h" #include "briefinglocalizerDlg.h" -#if defined(POSIX) -#include "linux_fix.h" -#endif +#include "crossplat.h" #include #include diff --git a/legacy/renderer/opengl.cpp b/legacy/renderer/opengl.cpp index d8b0990a..569db09e 100644 --- a/legacy/renderer/opengl.cpp +++ b/legacy/renderer/opengl.cpp @@ -20,7 +20,7 @@ #include #include "ddraw.h" #elif defined(POSIX) -#include "linux_fix.h" +#include "crossplat.h" #include "lnxscreenmode.h" #else #endif diff --git a/lib/bitmap.h b/lib/bitmap.h index d2b71dc9..09c3632e 100644 --- a/lib/bitmap.h +++ b/lib/bitmap.h @@ -22,10 +22,7 @@ #include #include "cfile.h" - -#if defined(POSIX) -#include "linux_fix.h" //needed for stricmp's throughout bitmap lib -#endif +#include "crossplat.h" //needed for stricmp's throughout bitmap lib #define MAX_BITMAPS 5000 #define NUM_MIP_LEVELS 5 diff --git a/lib/crossplat.h b/lib/crossplat.h new file mode 100644 index 00000000..f153a503 --- /dev/null +++ b/lib/crossplat.h @@ -0,0 +1,65 @@ +/* + * Descent 3 + * Copyright (C) 2024 Parallax Software + * Copyright (C) 2024 Descent Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef CROSSPLAT_H_ +#define CROSSPLAT_H_ + +// Crossplatform stubs and replacements + +#if defined(WIN32) + +#include // strupr, stricmp, strnicmp +#include // _MAX_PATH, _MAX_FNAME, _MAX_EXT for WIN32 +#include // _chmod + +#elif defined(POSIX) + +#include // toupper +#include // strcasecmp, strncasecmp +#include // chmod + +inline char *strupr(char *string) { + while (string && *string) { + *string = toupper(*string); + string++; + } + return string; +} + +// Replace missing defines from stdlib.h +#define _MAX_PATH 260 /* max. length of full pathname*/ +#define _MAX_FNAME 256 /* max. length of path component*/ +#define _MAX_EXT 256 /* max. length of extension component*/ + +// _cdecl replacement +#define __cdecl __attribute__((cdecl)) +// __stdcall replacement +#define __stdcall __attribute__((stdcall)) + +#define stricmp(a, b) strcasecmp(a, b) +#define strnicmp(a, b, c) strncasecmp(a, b, c) +#define _chmod(a, b) chmod(a, b) + +#else + +#error "Unknown platform!" + +#endif + +#endif diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 9063cc6f..0efd06c3 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -1,5 +1,4 @@ set(HEADERS - linux_fix.h lnxapp.h lnxcontroller.h registry.h) diff --git a/linux/linux_fix.h b/linux/linux_fix.h deleted file mode 100644 index cb98046d..00000000 --- a/linux/linux_fix.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -* Descent 3 -* Copyright (C) 2024 Parallax Software -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -#ifndef __LINUX_FIX_H_ -#define __LINUX_FIX_H_ - -#include -#include - -#define LOKI_VERSION "" - -#define HGLOBAL void * - -char *strupr(char *string); - -#define _stat stat - -// Replace missing defines from stdlib.h -#define _MAX_PATH 260 /* max. length of full pathname*/ -#define _MAX_FNAME 256 /* max. length of path component*/ -#define _MAX_EXT 256 /* max. length of extension component*/ - -// _cdecl replacement -#define __cdecl __attribute__((cdecl)) -// __stdcall replacement -#define __stdcall __attribute__((stdcall)) - -#define stricmp(a, b) strcasecmp(a, b) -#define strnicmp(a, b, c) strncasecmp(a, b, c) -#define _chmod(a, b) chmod(a, b) -#endif diff --git a/linux/lnxapp.cpp b/linux/lnxapp.cpp index 2a03a526..bd6ceed8 100644 --- a/linux/lnxapp.cpp +++ b/linux/lnxapp.cpp @@ -69,7 +69,6 @@ */ #include -#include #if defined(POSIX) #include #else @@ -95,14 +94,6 @@ bool con_Create(int flags); void con_Destroy(); void con_Defer(); -char *strupr(char *string) { - while (string && *string) { - *string = toupper(*string); - string++; - } - return string; -} - static uint32_t LinuxAppFlags = 0; // static Display *LinuxAppDisplay=NULL; static bool LinuxAppSetAtExit = false; diff --git a/module/module.cpp b/module/module.cpp index 2477da28..c346444a 100644 --- a/module/module.cpp +++ b/module/module.cpp @@ -99,9 +99,9 @@ #if defined(POSIX) #include -#include "linux_fix.h" #endif +#include "crossplat.h" #include "module.h" #include "pserror.h" diff --git a/netcon/includes/con_dll.h b/netcon/includes/con_dll.h index 75eebf9e..fe4f73b9 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -270,14 +270,10 @@ #include #include +#include "crossplat.h" #include "ship.h" #include "pstypes.h" -#if defined(POSIX) -#include -#include "linux_fix.h" -#endif - // Uncomment out this line of code to build the demo version of the multiplayer connection dlls // #define DEMO 1 diff --git a/netcon/includes/inetgetfile.h b/netcon/includes/inetgetfile.h index af4f1474..f0c6ec01 100644 --- a/netcon/includes/inetgetfile.h +++ b/netcon/includes/inetgetfile.h @@ -97,7 +97,6 @@ #include #include -#include "linux_fix.h" // Linux includes/defines #if defined(__LINUX__) diff --git a/netcon/inetfile/CFtp.cpp b/netcon/inetfile/CFtp.cpp index 5ab9471f..dfeef42b 100644 --- a/netcon/inetfile/CFtp.cpp +++ b/netcon/inetfile/CFtp.cpp @@ -70,9 +70,9 @@ typedef int socklen_t; #endif -#include -#include -#include +#include +#include +#include #if defined(POSIX) // sorry, I'm lazy, I guess we could copy the defines @@ -82,6 +82,7 @@ typedef int socklen_t; #endif #include "CFtp.h" +#include "crossplat.h" // MTS: only used in this file? #if defined(POSIX) diff --git a/netcon/inetfile/Chttpget.cpp b/netcon/inetfile/Chttpget.cpp index 5cdf46ba..32731308 100644 --- a/netcon/inetfile/Chttpget.cpp +++ b/netcon/inetfile/Chttpget.cpp @@ -124,14 +124,15 @@ #include #endif -#include -#include -#include +#include +#include +#include #include "inetgetfile.h" #include "Chttpget.h" #include "chrono_timer.h" +#include "crossplat.h" #include "mem.h" #define NW_AGHBN_CANCEL 1 diff --git a/netcon/mtclient/chat_api.cpp b/netcon/mtclient/chat_api.cpp index 2da78170..658f107a 100644 --- a/netcon/mtclient/chat_api.cpp +++ b/netcon/mtclient/chat_api.cpp @@ -26,10 +26,10 @@ #if defined(POSIX) #include #include -#include "linux_fix.h" #endif #include "chat_api.h" +#include "crossplat.h" #include "grdefs.h" #include "mtstrings.h" #include "networking.h" diff --git a/netcon/mtclient/mtpilottracker.cpp b/netcon/mtclient/mtpilottracker.cpp index c355dc0f..25e7cf80 100644 --- a/netcon/mtclient/mtpilottracker.cpp +++ b/netcon/mtclient/mtpilottracker.cpp @@ -114,10 +114,7 @@ #include "networking.h" #include "mt_net.h" #include "byteswap.h" - -#if defined(POSIX) -#include "linux_fix.h" -#endif +#include "crossplat.h" #define LOGIN_LEN 33 #define REAL_NAME_LEN 66 diff --git a/scripts/linux_lib.h b/scripts/linux_lib.h index b8b3db50..def92648 100644 --- a/scripts/linux_lib.h +++ b/scripts/linux_lib.h @@ -22,7 +22,8 @@ #include #include #include -#include "linux_fix.h" + +#include "crossplat.h" // for stricmp void _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);