Move platform-specific defines and macros to own file crossplat.h

This commit is contained in:
Azamat H. Hackimov 2024-08-11 19:29:35 +03:00
parent 22829e5e43
commit 79db9aa3e2
22 changed files with 91 additions and 116 deletions

View File

@ -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"

View File

@ -77,8 +77,11 @@
* $NoKeywords: $
*/
#include <cstring>
#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 <string.h>
#include <math.h>
#include "psrand.h"
#if defined(POSIX)
#include "linux_fix.h"
#endif
/*
$$TABLE_GAMEFILE "GameCredits.txt"
$$TABLE_GAMEFILE "credits.omf"

View File

@ -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 <sys/socket.h>
#include <unistd.h>
#include "linux_fix.h"
#include "errno.h"
#define BOOL bool
#ifndef SOCKET

View File

@ -132,10 +132,7 @@
#include <filesystem>
#include "application.h"
#if defined(POSIX)
#include "linux_fix.h"
#endif
#include "crossplat.h"
// The name of this product
#ifdef DEMO

View File

@ -22,21 +22,13 @@
#include <cstring>
#include <cstdarg>
#include <cerrno>
#include <cctype>
#include <filesystem>
#include <map>
#include <memory>
#include <vector>
#if !defined(POSIX)
// Non-Linux Build Includes
#include <io.h>
#else
// Linux Build Includes
#include "linux_fix.h"
#endif
#include "byteswap.h"
#include "crossplat.h"
#include "pserror.h"
#include "ddio.h"
#include "psglob.h"

View File

@ -30,7 +30,7 @@
#include <filesystem>
#include "cfile.h"
#include "pstypes.h"
#include "crossplat.h"
#include "psclass.h"
enum InfFileError {

View File

@ -73,7 +73,7 @@
#endif
#include "ddio.h"
#include "linux_fix.h"
#include "crossplat.h"
#include "mem.h"
#include "pserror.h"

View File

@ -23,9 +23,7 @@
#include "briefinglocalizer.h"
#include "briefinglocalizerDlg.h"
#if defined(POSIX)
#include "linux_fix.h"
#endif
#include "crossplat.h"
#include <sys/types.h>
#include <sys/stat.h>

View File

@ -20,7 +20,7 @@
#include <windows.h>
#include "ddraw.h"
#elif defined(POSIX)
#include "linux_fix.h"
#include "crossplat.h"
#include "lnxscreenmode.h"
#else
#endif

View File

@ -22,10 +22,7 @@
#include <filesystem>
#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

65
lib/crossplat.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef CROSSPLAT_H_
#define CROSSPLAT_H_
// Crossplatform stubs and replacements
#if defined(WIN32)
#include <cstring> // strupr, stricmp, strnicmp
#include <cstdlib> // _MAX_PATH, _MAX_FNAME, _MAX_EXT for WIN32
#include <io.h> // _chmod
#elif defined(POSIX)
#include <cctype> // toupper
#include <cstring> // strcasecmp, strncasecmp
#include <sys/stat.h> // 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

View File

@ -1,5 +1,4 @@
set(HEADERS
linux_fix.h
lnxapp.h
lnxcontroller.h
registry.h)

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef __LINUX_FIX_H_
#define __LINUX_FIX_H_
#include <cstring>
#include <sys/stat.h>
#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

View File

@ -69,7 +69,6 @@
*/
#include <cstdlib>
#include <cctype>
#if defined(POSIX)
#include <termios.h>
#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;

View File

@ -99,9 +99,9 @@
#if defined(POSIX)
#include <dlfcn.h>
#include "linux_fix.h"
#endif
#include "crossplat.h"
#include "module.h"
#include "pserror.h"

View File

@ -270,14 +270,10 @@
#include <regex>
#include <string>
#include "crossplat.h"
#include "ship.h"
#include "pstypes.h"
#if defined(POSIX)
#include <cstring>
#include "linux_fix.h"
#endif
// Uncomment out this line of code to build the demo version of the multiplayer connection dlls
// #define DEMO 1

View File

@ -97,7 +97,6 @@
#include <sys/time.h>
#include <unistd.h>
#include "linux_fix.h"
// Linux includes/defines
#if defined(__LINUX__)

View File

@ -70,9 +70,9 @@
typedef int socklen_t;
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#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)

View File

@ -124,14 +124,15 @@
#include <process.h>
#endif
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include "inetgetfile.h"
#include "Chttpget.h"
#include "chrono_timer.h"
#include "crossplat.h"
#include "mem.h"
#define NW_AGHBN_CANCEL 1

View File

@ -26,10 +26,10 @@
#if defined(POSIX)
#include <sys/time.h>
#include <unistd.h>
#include "linux_fix.h"
#endif
#include "chat_api.h"
#include "crossplat.h"
#include "grdefs.h"
#include "mtstrings.h"
#include "networking.h"

View File

@ -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

View File

@ -22,7 +22,8 @@
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include "linux_fix.h"
#include "crossplat.h" // for stricmp
void _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);