Change up strcasecmp/strncasecmp to be more C++y
This commit is contained in:
+103
-505
@@ -31,11 +31,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "miniz.hpp"
|
||||
|
||||
static char *largv[MAX_NUM_ARGVS + 1];
|
||||
static char argvdummy[] = " ";
|
||||
|
||||
int safemode;
|
||||
|
||||
convar registered = {"registered", "1", {.rom = true}}; /* set to correct value in COM_CheckRegistered() */
|
||||
convar cmdline = {"cmdline", "", {.rom = true}/*|CVAR_SERVERINFO*/}; /* sending cmdline upon CCREQ_RULE_INFO is evil */
|
||||
|
||||
@@ -54,11 +51,6 @@ static void COM_Path_f(void);
|
||||
#define PAK0_COUNT_V091 308 /* id1/pak0.pak - v0.91/0.92, not supported */
|
||||
#define PAK0_CRC_V091 28804 /* id1/pak0.pak - v0.91/0.92, not supported */
|
||||
|
||||
int com_argc;
|
||||
char **com_argv;
|
||||
|
||||
#define CMDLINE_LENGTH 256 /* johnfitz -- mirrored in cmd.c */
|
||||
char com_cmdline[CMDLINE_LENGTH];
|
||||
|
||||
bool standard_quake = true, rogue, hipnotic;
|
||||
|
||||
@@ -142,62 +134,6 @@ void InsertLinkAfter(link_t *l, link_t *after) {
|
||||
l->next->prev = l;
|
||||
}
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
|
||||
DYNAMIC VECTORS
|
||||
|
||||
============================================================================
|
||||
*/
|
||||
|
||||
void Vec_Grow(void **pvec, size_t element_size, size_t count) {
|
||||
vec_header_t header;
|
||||
if (*pvec)
|
||||
header = VEC_HEADER(*pvec);
|
||||
else
|
||||
header.size = header.capacity = 0;
|
||||
|
||||
if (header.size + count > header.capacity) {
|
||||
void *new_buffer;
|
||||
size_t total_size;
|
||||
|
||||
header.capacity = header.size + count;
|
||||
header.capacity += header.capacity >> 1;
|
||||
if (header.capacity < 16)
|
||||
header.capacity = 16;
|
||||
total_size = sizeof(vec_header_t) + header.capacity * element_size;
|
||||
|
||||
if (*pvec)
|
||||
new_buffer = realloc(((vec_header_t *) *pvec) - 1, total_size);
|
||||
else
|
||||
new_buffer = malloc(total_size);
|
||||
if (!new_buffer)
|
||||
Sys_Error("Vec_Grow: failed to allocate %lu bytes\n", (unsigned long) total_size);
|
||||
|
||||
*pvec = 1 + (vec_header_t *) new_buffer;
|
||||
VEC_HEADER(*pvec) = header;
|
||||
}
|
||||
}
|
||||
|
||||
void Vec_Append(void **pvec, size_t element_size, const void *data, size_t count) {
|
||||
if (!count)
|
||||
return;
|
||||
Vec_Grow(pvec, element_size, count);
|
||||
memcpy((byte *) *pvec + VEC_HEADER(*pvec).size, data, count * element_size);
|
||||
VEC_HEADER(*pvec).size += count;
|
||||
}
|
||||
|
||||
void Vec_Clear(void **pvec) {
|
||||
if (*pvec)
|
||||
VEC_HEADER(*pvec).size = 0;
|
||||
}
|
||||
|
||||
void Vec_Free(void **pvec) {
|
||||
if (*pvec) {
|
||||
free(&VEC_HEADER(*pvec));
|
||||
*pvec = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============================================================================
|
||||
@@ -247,7 +183,7 @@ char *q_strcasestr(const char *haystack, const char *needle) {
|
||||
const size_t len = strlen(needle);
|
||||
|
||||
while (*haystack) {
|
||||
if (!q_strncasecmp(haystack, needle, len))
|
||||
if (std::is_eq(common::strncasecmp(haystack, needle, len)))
|
||||
return (char *) haystack;
|
||||
|
||||
++haystack;
|
||||
@@ -285,7 +221,7 @@ char *q_strupr(char *str) {
|
||||
#define vsnprintf_func vsnprintf
|
||||
#endif
|
||||
|
||||
int q_vsnprintf(char *str, size_t size, const char *format, va_list args) {
|
||||
int q_vsnprintf(char *str, const size_t size, const char *format, va_list args) {
|
||||
int ret;
|
||||
|
||||
ret = vsnprintf_func(str, size, format, args);
|
||||
@@ -300,7 +236,7 @@ int q_vsnprintf(char *str, size_t size, const char *format, va_list args) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int q_snprintf(char *str, size_t size, const char *format, ...) {
|
||||
int q_snprintf(char *str, const size_t size, const char *format, ...) {
|
||||
int ret;
|
||||
va_list argptr;
|
||||
|
||||
@@ -333,7 +269,7 @@ float (*BigFloat)(float l);
|
||||
|
||||
float (*LittleFloat)(float l);
|
||||
|
||||
short ShortSwap(short l) {
|
||||
short ShortSwap(const short l) {
|
||||
byte b1, b2;
|
||||
|
||||
b1 = l & 255;
|
||||
@@ -342,11 +278,11 @@ short ShortSwap(short l) {
|
||||
return (b1 << 8) + b2;
|
||||
}
|
||||
|
||||
short ShortNoSwap(short l) {
|
||||
short ShortNoSwap(const short l) {
|
||||
return l;
|
||||
}
|
||||
|
||||
int LongSwap(int l) {
|
||||
int LongSwap(const int l) {
|
||||
byte b1, b2, b3, b4;
|
||||
|
||||
b1 = l & 255;
|
||||
@@ -357,11 +293,11 @@ int LongSwap(int l) {
|
||||
return ((int) b1 << 24) + ((int) b2 << 16) + ((int) b3 << 8) + b4;
|
||||
}
|
||||
|
||||
int LongNoSwap(int l) {
|
||||
int LongNoSwap(const int l) {
|
||||
return l;
|
||||
}
|
||||
|
||||
float FloatSwap(float f) {
|
||||
float FloatSwap(const float f) {
|
||||
union {
|
||||
float f;
|
||||
byte b[4];
|
||||
@@ -376,346 +312,10 @@ float FloatSwap(float f) {
|
||||
return dat2.f;
|
||||
}
|
||||
|
||||
float FloatNoSwap(float f) {
|
||||
float FloatNoSwap(const float f) {
|
||||
return f;
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
MESSAGE IO FUNCTIONS
|
||||
|
||||
Handles byte ordering and avoids alignment errors
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
//
|
||||
// writing functions
|
||||
//
|
||||
|
||||
// void MSG_WriteChar(sizebuf_t *sb, int c) {
|
||||
// byte *buf;
|
||||
//
|
||||
// #ifdef PARANOID
|
||||
// if (c < -128 || c > 127)
|
||||
// Sys_Error("MSG_WriteChar: range error");
|
||||
// #endif
|
||||
//
|
||||
// buf = (byte *) SZ_GetSpace(sb, 1);
|
||||
// buf[0] = c;
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteByte(sizebuf_t *sb, int c) {
|
||||
// byte *buf;
|
||||
//
|
||||
// #ifdef PARANOID
|
||||
// if (c < 0 || c > 255)
|
||||
// Sys_Error("MSG_WriteByte: range error");
|
||||
// #endif
|
||||
//
|
||||
// buf = (byte *) SZ_GetSpace(sb, 1);
|
||||
// buf[0] = c;
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteShort(sizebuf_t *sb, int c) {
|
||||
// byte *buf;
|
||||
//
|
||||
// #ifdef PARANOID
|
||||
// if (c < ((short) 0x8000) || c > (short) 0x7fff)
|
||||
// Sys_Error("MSG_WriteShort: range error");
|
||||
// #endif
|
||||
//
|
||||
// buf = (byte *) SZ_GetSpace(sb, 2);
|
||||
// buf[0] = c & 0xff;
|
||||
// buf[1] = c >> 8;
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteLong(sizebuf_t *sb, int c) {
|
||||
// byte *buf;
|
||||
//
|
||||
// buf = (byte *) SZ_GetSpace(sb, 4);
|
||||
// buf[0] = c & 0xff;
|
||||
// buf[1] = (c >> 8) & 0xff;
|
||||
// buf[2] = (c >> 16) & 0xff;
|
||||
// buf[3] = c >> 24;
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteFloat(sizebuf_t *sb, float f) {
|
||||
// union {
|
||||
// float f;
|
||||
// int l;
|
||||
// } dat;
|
||||
//
|
||||
// dat.f = f;
|
||||
// dat.l = LittleLong(dat.l);
|
||||
//
|
||||
// SZ_Write(sb, &dat.l, 4);
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteString(sizebuf_t *sb, const char *s) {
|
||||
// if (!s)
|
||||
// SZ_Write(sb, "", 1);
|
||||
// else
|
||||
// SZ_Write(sb, s, std::strlen(s) + 1);
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096
|
||||
// void MSG_WriteCoord16(sizebuf_t *sb, float f) {
|
||||
// MSG_WriteShort(sb, Q_rint(f*8));
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- 16.8 fixed point coords, max range +-32768
|
||||
// void MSG_WriteCoord24(sizebuf_t *sb, float f) {
|
||||
// MSG_WriteShort(sb, f);
|
||||
// MSG_WriteByte(sb, (int) (f * 255) % 255);
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- 32-bit float coords
|
||||
// void MSG_WriteCoord32f(sizebuf_t *sb, float f) {
|
||||
// MSG_WriteFloat(sb, f);
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteCoord(sizebuf_t *sb, float f, unsigned int flags) {
|
||||
// if (flags & PRFL_FLOATCOORD)
|
||||
// MSG_WriteFloat(sb, f);
|
||||
// else if (flags & PRFL_INT32COORD)
|
||||
// MSG_WriteLong(sb, Q_rint(f * 16));
|
||||
// else if (flags & PRFL_24BITCOORD)
|
||||
// MSG_WriteCoord24(sb, f);
|
||||
// else MSG_WriteCoord16(sb, f);
|
||||
// }
|
||||
//
|
||||
// void MSG_WriteAngle(sizebuf_t *sb, float f, unsigned int flags) {
|
||||
// if (flags & PRFL_FLOATANGLE)
|
||||
// MSG_WriteFloat(sb, f);
|
||||
// else if (flags & PRFL_SHORTANGLE)
|
||||
// MSG_WriteShort(sb, Q_rint(f * 65536.0 / 360.0) & 65535);
|
||||
// else MSG_WriteByte(sb, Q_rint(f * 256.0 / 360.0) & 255); //johnfitz -- use Q_rint instead of (int) }
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- for PROTOCOL_FITZQUAKE
|
||||
// void MSG_WriteAngle16(sizebuf_t *sb, float f, unsigned int flags) {
|
||||
// if (flags & PRFL_FLOATANGLE)
|
||||
// MSG_WriteFloat(sb, f);
|
||||
// else MSG_WriteShort(sb, Q_rint(f * 65536.0 / 360.0) & 65535);
|
||||
// }
|
||||
//
|
||||
// //johnfitz
|
||||
//
|
||||
// //
|
||||
// // reading functions
|
||||
// //
|
||||
// int msg_readcount;
|
||||
// bool msg_badread;
|
||||
//
|
||||
// void MSG_BeginReading(void) {
|
||||
// msg_readcount = 0;
|
||||
// msg_badread = false;
|
||||
// }
|
||||
//
|
||||
// // returns -1 and sets msg_badread if no more characters are available
|
||||
// int MSG_ReadChar(void) {
|
||||
// int c;
|
||||
//
|
||||
// if (msg_readcount + 1 > net_message.cursize) {
|
||||
// msg_badread = true;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// c = (signed char) net_message.data[msg_readcount];
|
||||
// msg_readcount++;
|
||||
//
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// int MSG_ReadByte(void) {
|
||||
// int c;
|
||||
//
|
||||
// if (msg_readcount + 1 > net_message.cursize) {
|
||||
// msg_badread = true;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// c = (unsigned char) net_message.data[msg_readcount];
|
||||
// msg_readcount++;
|
||||
//
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// int MSG_ReadShort(void) {
|
||||
// int c;
|
||||
//
|
||||
// if (msg_readcount + 2 > net_message.cursize) {
|
||||
// msg_badread = true;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// c = (short) (net_message.data[msg_readcount]
|
||||
// + (net_message.data[msg_readcount + 1] << 8));
|
||||
//
|
||||
// msg_readcount += 2;
|
||||
//
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// int MSG_ReadLong(void) {
|
||||
// int c;
|
||||
//
|
||||
// if (msg_readcount + 4 > net_message.cursize) {
|
||||
// msg_badread = true;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// c = net_message.data[msg_readcount]
|
||||
// + (net_message.data[msg_readcount + 1] << 8)
|
||||
// + (net_message.data[msg_readcount + 2] << 16)
|
||||
// + (net_message.data[msg_readcount + 3] << 24);
|
||||
//
|
||||
// msg_readcount += 4;
|
||||
//
|
||||
// return c;
|
||||
// }
|
||||
//
|
||||
// float MSG_ReadFloat(void) {
|
||||
// union {
|
||||
// byte b[4];
|
||||
// float f;
|
||||
// int l;
|
||||
// } dat;
|
||||
//
|
||||
// dat.b[0] = net_message.data[msg_readcount];
|
||||
// dat.b[1] = net_message.data[msg_readcount + 1];
|
||||
// dat.b[2] = net_message.data[msg_readcount + 2];
|
||||
// dat.b[3] = net_message.data[msg_readcount + 3];
|
||||
// msg_readcount += 4;
|
||||
//
|
||||
// dat.l = LittleLong(dat.l);
|
||||
//
|
||||
// return dat.f;
|
||||
// }
|
||||
//
|
||||
// const char *MSG_ReadString(void) {
|
||||
// static char string[2048];
|
||||
// int c;
|
||||
// size_t l;
|
||||
//
|
||||
// l = 0;
|
||||
// do {
|
||||
// c = net_message.read_byte().value();
|
||||
// if (c == -1 || c == 0)
|
||||
// break;
|
||||
// string[l] = c;
|
||||
// l++;
|
||||
// } while (l < sizeof(string) - 1);
|
||||
//
|
||||
// string[l] = 0;
|
||||
//
|
||||
// return string;
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096
|
||||
// float MSG_ReadCoord16(void) {
|
||||
// return MSG_ReadShort() * (1.0 / 8);
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- 16.8 fixed point coords, max range +-32768
|
||||
// float MSG_ReadCoord24(void) {
|
||||
// return MSG_ReadShort() + net_message.read_byte().value() * (1.0 / 255);
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- 32-bit float coords
|
||||
// float MSG_ReadCoord32f(void) {
|
||||
// return MSG_ReadFloat();
|
||||
// }
|
||||
//
|
||||
// float MSG_ReadCoord(unsigned int flags) {
|
||||
// if (flags & PRFL_FLOATCOORD)
|
||||
// return MSG_ReadFloat();
|
||||
// else if (flags & PRFL_INT32COORD)
|
||||
// return MSG_ReadLong() * (1.0 / 16.0);
|
||||
// else if (flags & PRFL_24BITCOORD)
|
||||
// return MSG_ReadCoord24();
|
||||
// else return MSG_ReadCoord16();
|
||||
// }
|
||||
//
|
||||
// float MSG_ReadAngle(unsigned int flags) {
|
||||
// if (flags & PRFL_FLOATANGLE)
|
||||
// return MSG_ReadFloat();
|
||||
// else if (flags & PRFL_SHORTANGLE)
|
||||
// return MSG_ReadShort() * (360.0 / 65536);
|
||||
// else return MSG_ReadChar() * (360.0 / 256);
|
||||
// }
|
||||
//
|
||||
// //johnfitz -- for PROTOCOL_FITZQUAKE
|
||||
// float MSG_ReadAngle16(unsigned int flags) {
|
||||
// if (flags & PRFL_FLOATANGLE)
|
||||
// return MSG_ReadFloat(); // make sure
|
||||
// else return MSG_ReadShort() * (360.0 / 65536);
|
||||
// }
|
||||
//
|
||||
// //johnfitz
|
||||
|
||||
//===========================================================================
|
||||
|
||||
void SZ_Alloc(sizebuf_t *buf, int startsize) {
|
||||
if (startsize < 256)
|
||||
startsize = 256;
|
||||
buf->data = (byte *) Hunk_AllocName(startsize, "sizebuf");
|
||||
buf->maxsize = startsize;
|
||||
buf->cursize = 0;
|
||||
}
|
||||
|
||||
|
||||
void SZ_Free(sizebuf_t *buf) {
|
||||
// Z_Free (buf->data);
|
||||
// buf->data = NULL;
|
||||
// buf->maxsize = 0;
|
||||
buf->cursize = 0;
|
||||
}
|
||||
|
||||
void SZ_Clear(sizebuf_t *buf) {
|
||||
buf->cursize = 0;
|
||||
}
|
||||
|
||||
void *SZ_GetSpace(sizebuf_t *buf, int length) {
|
||||
void *data;
|
||||
|
||||
if (buf->cursize + length > buf->maxsize) {
|
||||
if (!buf->allowoverflow)
|
||||
Host_Error("SZ_GetSpace: overflow without allowoverflow set");
|
||||
// ericw -- made Host_Error to be less annoying
|
||||
|
||||
if (length > buf->maxsize)
|
||||
Sys_Error("SZ_GetSpace: %i is > full buffer size", length);
|
||||
|
||||
buf->overflowed = true;
|
||||
console::info("SZ_GetSpace: overflow\n");
|
||||
SZ_Clear(buf);
|
||||
}
|
||||
|
||||
data = buf->data + buf->cursize;
|
||||
buf->cursize += length;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void SZ_Write(sizebuf_t *buf, const void *data, int length) {
|
||||
std::memcpy(SZ_GetSpace(buf, length), data, length);
|
||||
}
|
||||
|
||||
void SZ_Print(sizebuf_t *buf, const char *data) {
|
||||
int len = std::strlen(data) + 1;
|
||||
|
||||
if (buf->data[buf->cursize - 1]) {
|
||||
/* no trailing 0 */
|
||||
std::memcpy(SZ_GetSpace(buf, len), data, len);
|
||||
} else {
|
||||
/* write over trailing 0 */
|
||||
std::memcpy(static_cast<byte *>(SZ_GetSpace(buf, len - 1)) - 1, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
|
||||
/*
|
||||
@@ -740,7 +340,7 @@ const char *COM_SkipPath(const char *pathname) {
|
||||
COM_StripExtension
|
||||
============
|
||||
*/
|
||||
void COM_StripExtension(const char *in, char *out, size_t outsize) {
|
||||
void COM_StripExtension(const char *in, char *out, const size_t outsize) {
|
||||
int length;
|
||||
|
||||
if (!*in) {
|
||||
@@ -786,7 +386,7 @@ const char *COM_FileGetExtension(const char *in) {
|
||||
COM_ExtractExtension
|
||||
============
|
||||
*/
|
||||
void COM_ExtractExtension(const char *in, char *out, size_t outsize) {
|
||||
void COM_ExtractExtension(const char *in, char *out, const size_t outsize) {
|
||||
const char *ext = COM_FileGetExtension(in);
|
||||
if (!*ext)
|
||||
*out = '\0';
|
||||
@@ -801,7 +401,7 @@ take 'somedir/otherdir/filename.ext',
|
||||
write only 'filename' to the output
|
||||
============
|
||||
*/
|
||||
void COM_FileBase(const char *in, char *out, size_t outsize) {
|
||||
void COM_FileBase(const char *in, char *out, const size_t outsize) {
|
||||
const char *dot, *slash, *s;
|
||||
|
||||
s = in;
|
||||
@@ -859,13 +459,16 @@ if path extension doesn't match .EXT, append it
|
||||
(extension should include the leading ".")
|
||||
==================
|
||||
*/
|
||||
void COM_AddExtension(char *path, const char *extension, size_t len) {
|
||||
void COM_AddExtension(char *path, const char *extension, const size_t len) {
|
||||
if (strcmp(COM_FileGetExtension(path), extension + 1) != 0)
|
||||
q_strlcat(path, extension, len);
|
||||
}
|
||||
|
||||
|
||||
namespace common {
|
||||
std::vector<std::string> _argv{};
|
||||
std::string cmdline{};
|
||||
bool safe_mode{false};
|
||||
|
||||
void init() {
|
||||
int i = 0x12345678;
|
||||
@@ -883,11 +486,9 @@ namespace common {
|
||||
*/
|
||||
if (*reinterpret_cast<char *>(&i) == 0x12) {
|
||||
host_bigendian = true;
|
||||
}
|
||||
else if (*reinterpret_cast<char *>(&i) == 0x78) {
|
||||
} else if (*reinterpret_cast<char *>(&i) == 0x78) {
|
||||
host_bigendian = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Sys_Error("Unsupported endianism.");
|
||||
}
|
||||
|
||||
@@ -913,12 +514,43 @@ namespace common {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<size_t> check_param(std::string_view parm) {
|
||||
for (auto i = 1; i < com_argc; i++) {
|
||||
if (!com_argv[i]) {
|
||||
void init_argv(const int nargc, char **nargv) {
|
||||
for (auto j = 0; (j < MAX_NUM_ARGVS) && (j < nargc); j++) {
|
||||
cmdline += nargv[j];
|
||||
cmdline += " ";
|
||||
}
|
||||
|
||||
if (!cmdline.empty() && cmdline.back() == ' ')
|
||||
cmdline.pop_back();
|
||||
|
||||
console::info("Command line: %s\n", cmdline.c_str());
|
||||
|
||||
for (auto i = 0; (i < MAX_NUM_ARGVS) && (i < nargc); i++) {
|
||||
_argv.emplace_back(nargv[i]);
|
||||
if (_argv.back() == "-safe")
|
||||
safe_mode = true;
|
||||
}
|
||||
|
||||
_argv.push_back(" ");
|
||||
|
||||
if (check_param("-rogue").has_value()) {
|
||||
rogue = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
|
||||
if (check_param("-hipnotic").has_value() || check_param("-quoth").has_value()) //johnfitz -- "-quoth" support
|
||||
{
|
||||
hipnotic = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<size_t> check_param(const std::string_view parm) {
|
||||
for (auto i = 1; i < _argv.size(); i++) {
|
||||
if (_argv[i].empty()) {
|
||||
continue; // NEXTSTEP sometimes clears appkit vars.
|
||||
}
|
||||
if (parm == com_argv[i]) {
|
||||
if (parm == _argv[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1047,6 +679,21 @@ namespace common {
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::partial_ordering strcasecmp(const std::string_view lhs, const std::string_view rhs) {
|
||||
return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
|
||||
[](const char c, const char d) {
|
||||
return q_tolower(c) <=> q_tolower(d);
|
||||
});
|
||||
}
|
||||
|
||||
std::partial_ordering strncasecmp(const std::string_view lhs, const std::string_view rhs, const size_t n) {
|
||||
return std::lexicographical_compare_three_way(lhs.begin(), lhs.begin() + std::min(lhs.size(), n), rhs.begin(),
|
||||
rhs.begin() + std::min(rhs.size(), n),
|
||||
[](const char c, const char d) {
|
||||
return q_tolower(c) <=> q_tolower(d);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1091,67 +738,17 @@ static void COM_CheckRegistered(void) {
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; com_cmdline[i]; i++) {
|
||||
if (com_cmdline[i] != ' ')
|
||||
for (i = 0; common::cmdline[i]; i++) {
|
||||
if (common::cmdline[i] != ' ')
|
||||
break;
|
||||
}
|
||||
|
||||
convar::set_rom("cmdline", &com_cmdline[i]);
|
||||
convar::set_rom("cmdline", &common::cmdline[i]);
|
||||
convar::set_rom("registered", "1");
|
||||
console::info("Playing registered version.\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
COM_InitArgv
|
||||
================
|
||||
*/
|
||||
void COM_InitArgv(int argc, char **argv) {
|
||||
int i, j, n;
|
||||
|
||||
// reconstitute the command line for the cmdline externally visible cvar
|
||||
n = 0;
|
||||
|
||||
for (j = 0; (j < MAX_NUM_ARGVS) && (j < argc); j++) {
|
||||
i = 0;
|
||||
|
||||
while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i]) {
|
||||
com_cmdline[n++] = argv[j][i++];
|
||||
}
|
||||
|
||||
if (n < (CMDLINE_LENGTH - 1))
|
||||
com_cmdline[n++] = ' ';
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (n > 0 && com_cmdline[n - 1] == ' ')
|
||||
com_cmdline[n - 1] = 0; //johnfitz -- kill the trailing space
|
||||
|
||||
console::info("Command line: %s\n", com_cmdline);
|
||||
|
||||
for (com_argc = 0; (com_argc < MAX_NUM_ARGVS) && (com_argc < argc); com_argc++) {
|
||||
largv[com_argc] = argv[com_argc];
|
||||
if (!std::strcmp("-safe", argv[com_argc]))
|
||||
safemode = 1;
|
||||
}
|
||||
|
||||
largv[com_argc] = argvdummy;
|
||||
com_argv = largv;
|
||||
|
||||
if (common::check_param("-rogue").has_value()) {
|
||||
rogue = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
|
||||
if (common::check_param("-hipnotic").has_value() || common::check_param("-quoth").has_value()) //johnfitz -- "-quoth" support
|
||||
{
|
||||
hipnotic = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
va
|
||||
@@ -1242,7 +839,7 @@ COM_WriteFile
|
||||
The filename will be prefixed by the current game directory
|
||||
============
|
||||
*/
|
||||
void COM_WriteFile(const char *filename, const void *data, int len) {
|
||||
void COM_WriteFile(const char *filename, const void *data, const int len) {
|
||||
int handle;
|
||||
char name[MAX_OSPATH];
|
||||
|
||||
@@ -1436,7 +1033,7 @@ COM_CloseFile
|
||||
If it is a pak file handle, don't really close it
|
||||
============
|
||||
*/
|
||||
void COM_CloseFile(int h) {
|
||||
void COM_CloseFile(const int h) {
|
||||
searchpath_t *s;
|
||||
|
||||
for (s = com_searchpaths; s; s = s->next)
|
||||
@@ -1466,7 +1063,7 @@ static byte *loadbuf;
|
||||
static cache_user_t *loadcache;
|
||||
static int loadsize;
|
||||
|
||||
byte *COM_LoadFile(const char *path, int usehunk, unsigned int *path_id) {
|
||||
byte *COM_LoadFile(const char *path, const int usehunk, unsigned int *path_id) {
|
||||
int h;
|
||||
byte *buf;
|
||||
char base[32];
|
||||
@@ -1539,7 +1136,7 @@ void COM_LoadCacheFile(const char *path, struct cache_user_s *cu, unsigned int *
|
||||
}
|
||||
|
||||
// uses temp hunk if larger than bufsize
|
||||
byte *COM_LoadStackFile(const char *path, void *buffer, int bufsize, unsigned int *path_id) {
|
||||
byte *COM_LoadStackFile(const char *path, void *buffer, const int bufsize, unsigned int *path_id) {
|
||||
byte *buf;
|
||||
|
||||
loadbuf = (byte *) buffer;
|
||||
@@ -1774,7 +1371,7 @@ static void COM_Game_f(void) {
|
||||
console::info("invalid mission pack argument to \"game\"\n");
|
||||
return;
|
||||
}
|
||||
if (!q_strcasecmp(p, GAMENAME)) {
|
||||
if (std::is_eq(common::strcasecmp(p, GAMENAME))) {
|
||||
console::info("no mission pack arguments to %s game\n", GAMENAME);
|
||||
return;
|
||||
}
|
||||
@@ -1788,14 +1385,14 @@ static void COM_Game_f(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!q_strcasecmp(p, COM_SkipPath(com_gamedir))) //no change
|
||||
if (std::is_eq(common::strcasecmp(p, COM_SkipPath(com_gamedir)))) //no change
|
||||
{
|
||||
if (com_searchpaths->path_id > 1) {
|
||||
//current game not id1
|
||||
if (*p2 && com_searchpaths->path_id == 2) {
|
||||
// rely on QuakeSpasm extension treating '-game missionpack'
|
||||
// as '-missionpack', otherwise would be a mess
|
||||
if (!q_strcasecmp(p, &p2[1]))
|
||||
if (std::is_eq(common::strcasecmp(p, &p2[1])))
|
||||
goto _same;
|
||||
console::info("reloading game \"%s\" with \"%s\" support\n", p, &p2[1]);
|
||||
} else if (!*p2 && com_searchpaths->path_id > 2)
|
||||
@@ -1832,7 +1429,7 @@ static void COM_Game_f(void) {
|
||||
rogue = false;
|
||||
standard_quake = true;
|
||||
|
||||
if (q_strcasecmp(p, GAMENAME)) //game is not id1
|
||||
if (is_neq(common::strcasecmp(p, GAMENAME))) //game is not id1
|
||||
{
|
||||
if (*p2) {
|
||||
COM_AddGameDirectory(com_basedir, &p2[1]);
|
||||
@@ -1841,15 +1438,15 @@ static void COM_Game_f(void) {
|
||||
hipnotic = true;
|
||||
else if (!strcmp(p2, "-rogue"))
|
||||
rogue = true;
|
||||
if (q_strcasecmp(p, &p2[1])) //don't load twice
|
||||
if (is_neq(common::strcasecmp(p, &p2[1]))) //don't load twice
|
||||
COM_AddGameDirectory(com_basedir, p);
|
||||
} else {
|
||||
COM_AddGameDirectory(com_basedir, p);
|
||||
// QuakeSpasm extension: treat '-game missionpack' as '-missionpack'
|
||||
if (!q_strcasecmp(p, "hipnotic") || !q_strcasecmp(p, "quoth")) {
|
||||
if (std::is_eq(common::strcasecmp(p, "hipnotic")) || std::is_eq(common::strcasecmp(p, "quoth"))) {
|
||||
hipnotic = true;
|
||||
standard_quake = false;
|
||||
} else if (!q_strcasecmp(p, "rogue")) {
|
||||
} else if (std::is_eq(common::strcasecmp(p, "rogue"))) {
|
||||
rogue = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
@@ -1896,10 +1493,9 @@ void COM_InitFilesystem(void) //johnfitz -- modified based on topaz's tutorial
|
||||
command::add("game", COM_Game_f); //johnfitz
|
||||
|
||||
auto i = common::check_param("-basedir");
|
||||
if (i.has_value() && i.value() < com_argc - 1) {
|
||||
q_strlcpy(com_basedir, com_argv[i.value() + 1], sizeof(com_basedir));
|
||||
}
|
||||
else {
|
||||
if (i.has_value() && i.value() < common::_argv.size() - 1) {
|
||||
q_strlcpy(com_basedir, common::_argv[i.value() + 1].c_str(), sizeof(com_basedir));
|
||||
} else {
|
||||
q_strlcpy(com_basedir, host_parms->basedir, sizeof(com_basedir));
|
||||
}
|
||||
|
||||
@@ -1930,30 +1526,32 @@ void COM_InitFilesystem(void) //johnfitz -- modified based on topaz's tutorial
|
||||
}
|
||||
|
||||
i = common::check_param("-game");
|
||||
if (i.has_value() && i.value() < com_argc - 1) {
|
||||
const char *p = com_argv[i.value() + 1];
|
||||
if (!*p || !strcmp(p, ".") || strstr(p, "..") || strstr(p, "/") || strstr(p, "\\") || strstr(p, ":")) {
|
||||
if (i.has_value() && i.value() < common::_argv.size() - 1) {
|
||||
std::optional<std::string> p = common::_argv[i.value() + 1];
|
||||
if (p.value().empty() || p == "." || p->contains("..") || p->contains("/") || p->contains("\\") || p->
|
||||
contains(":")) {
|
||||
Sys_Error("gamedir should be a single directory name, not a path\n");
|
||||
}
|
||||
com_modified = true;
|
||||
// don't load mission packs twice
|
||||
if (common::check_param("-rogue").has_value() && !q_strcasecmp(p, "rogue")) {
|
||||
p = nullptr;
|
||||
if (common::check_param("-rogue").has_value() && std::is_eq(common::strcasecmp(p->c_str(), "rogue"))) {
|
||||
p = std::nullopt;
|
||||
}
|
||||
if (p && common::check_param("-hipnotic").has_value() && !q_strcasecmp(p, "hipnotic")) {
|
||||
p = nullptr;
|
||||
if (p.has_value() && common::check_param("-hipnotic").has_value() &&
|
||||
std::is_eq(common::strcasecmp(*p, "hipnotic"))) {
|
||||
p = std::nullopt;
|
||||
}
|
||||
if (p && common::check_param("-quoth").has_value() && !q_strcasecmp(p, "quoth")) {
|
||||
p = nullptr;
|
||||
if (p.has_value() && common::check_param("-quoth").has_value() && std::is_eq(common::strcasecmp(*p, "quoth"))) {
|
||||
p = std::nullopt;
|
||||
}
|
||||
if (p != nullptr) {
|
||||
COM_AddGameDirectory(com_basedir, p);
|
||||
if (p.has_value()) {
|
||||
COM_AddGameDirectory(com_basedir, p->c_str());
|
||||
// QuakeSpasm extension: treat '-game missionpack' as '-missionpack'
|
||||
if (!q_strcasecmp(p, "rogue")) {
|
||||
if (std::is_eq(common::strcasecmp(*p, "rogue"))) {
|
||||
rogue = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
if (!q_strcasecmp(p, "hipnotic") || !q_strcasecmp(p, "quoth")) {
|
||||
if (std::is_eq(common::strcasecmp(*p, "hipnotic")) || std::is_eq(common::strcasecmp(*p, "quoth"))) {
|
||||
hipnotic = true;
|
||||
standard_quake = false;
|
||||
}
|
||||
@@ -1970,7 +1568,7 @@ void COM_InitFilesystem(void) //johnfitz -- modified based on topaz's tutorial
|
||||
* Allocating and filling in the fshandle_t structure is the users'
|
||||
* responsibility when the file is initially opened. */
|
||||
|
||||
size_t FS_fread(void *ptr, size_t size, size_t nmemb, fshandle_t *fh) {
|
||||
size_t FS_fread(void *ptr, const size_t size, const size_t nmemb, fshandle_t *fh) {
|
||||
long byte_size;
|
||||
long bytes_read;
|
||||
size_t nmemb_read;
|
||||
@@ -2006,7 +1604,7 @@ size_t FS_fread(void *ptr, size_t size, size_t nmemb, fshandle_t *fh) {
|
||||
return nmemb_read;
|
||||
}
|
||||
|
||||
int FS_fseek(fshandle_t *fh, long offset, int whence) {
|
||||
int FS_fseek(fshandle_t *fh, long offset, const int whence) {
|
||||
/* I don't care about 64 bit off_t or fseeko() here.
|
||||
* the quake/hexen2 file system is 32 bits, anyway. */
|
||||
int ret;
|
||||
@@ -2159,7 +1757,7 @@ unsigned COM_HashString(const char *str) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
static size_t mz_zip_file_read_func(void *opaque, mz_uint64 ofs, void *buf, size_t n) {
|
||||
static size_t mz_zip_file_read_func(void *opaque, const mz_uint64 ofs, void *buf, const size_t n) {
|
||||
if (SDL_RWseek((SDL_RWops*)opaque, (Sint64)ofs, RW_SEEK_SET) < 0)
|
||||
return 0;
|
||||
#ifdef USE_SDL2
|
||||
|
||||
Reference in New Issue
Block a user