Change up strcasecmp/strncasecmp to be more C++y
This commit is contained in:
+21
-94
@@ -2,6 +2,7 @@
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||
Copyright (C) 2026 iikorni
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@@ -20,8 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _Q_COMMON_H
|
||||
#define _Q_COMMON_H
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "convar.hpp"
|
||||
|
||||
// comndef.h -- general definitions
|
||||
@@ -40,64 +43,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#endif /* _MSC_VER */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L))
|
||||
#define GENERIC_TYPES(x, separator) \
|
||||
x(int, i) separator \
|
||||
x(unsigned int, u) separator \
|
||||
x(long, l) separator \
|
||||
x(unsigned long, ul) separator \
|
||||
x(long long, ll) separator \
|
||||
x(unsigned long long, ull) separator \
|
||||
x(float, f) separator \
|
||||
x(double, d)
|
||||
|
||||
#define COMMA ,
|
||||
#define NO_COMMA
|
||||
|
||||
#define IMPL_GENERIC_FUNCS(type, suffix) \
|
||||
static inline type std::min_##suffix (type a, type b) { \
|
||||
return (a < b) ? a : b; \
|
||||
} \
|
||||
static inline type std::max_##suffix (type a, type b) { \
|
||||
return (a > b) ? a : b; \
|
||||
} \
|
||||
static inline type clamp_##suffix (type minval, type val, type maxval) { \
|
||||
return (val < minval) ? minval : ((val > maxval) ? maxval : val); \
|
||||
}
|
||||
|
||||
GENERIC_TYPES (IMPL_GENERIC_FUNCS, NO_COMMA)
|
||||
|
||||
#define SELECT_std::min(type, suffix) type: std::min_##suffix
|
||||
#define std::min(a, b) _Generic((a) + (b), GENERIC_TYPES (SELECT_std::min, COMMA))(a, b)
|
||||
|
||||
#define SELECT_std::max(type, suffix) type: std::max_##suffix
|
||||
#define std::max(a, b) _Generic((a) + (b), GENERIC_TYPES (SELECT_std::max, COMMA))(a, b)
|
||||
|
||||
#define SELECT_CLAMP(type, suffix) type: clamp_##suffix
|
||||
#define CLAMP(minval, val, maxval) _Generic((minval) + (val) + (maxval), \
|
||||
GENERIC_TYPES (SELECT_CLAMP, COMMA))(minval, val, maxval)
|
||||
#endif
|
||||
|
||||
// TODO: Maybe some special casing on an std::vector?
|
||||
typedef struct sizebuf_s
|
||||
{
|
||||
bool allowoverflow; // if false, do a Sys_Error
|
||||
bool overflowed; // set to true if the buffer size failed
|
||||
byte *data;
|
||||
int maxsize;
|
||||
int cursize;
|
||||
} sizebuf_t;
|
||||
|
||||
void SZ_Alloc (sizebuf_t *buf, int startsize);
|
||||
void SZ_Free (sizebuf_t *buf);
|
||||
void SZ_Clear (sizebuf_t *buf);
|
||||
void *SZ_GetSpace (sizebuf_t *buf, int length);
|
||||
void SZ_Write (sizebuf_t *buf, const void *data, int length);
|
||||
void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf
|
||||
|
||||
//============================================================================
|
||||
|
||||
typedef struct link_s
|
||||
@@ -118,25 +63,6 @@ void InsertLinkAfter (link_t *l, link_t *after);
|
||||
|
||||
//============================================================================
|
||||
|
||||
typedef struct vec_header_t {
|
||||
size_t capacity;
|
||||
size_t size;
|
||||
} vec_header_t;
|
||||
|
||||
#define VEC_HEADER(v) (((vec_header_t*)(v))[-1])
|
||||
|
||||
#define VEC_PUSH(v,n) do { Vec_Grow((void**)&(v), sizeof((v)[0]), 1); (v)[VEC_HEADER(v).size++] = (n); } while (0)
|
||||
#define VEC_SIZE(v) ((v) ? VEC_HEADER(v).size : 0)
|
||||
#define VEC_FREE(v) Vec_Free((void**)&(v))
|
||||
#define VEC_CLEAR(v) Vec_Clear((void**)&(v))
|
||||
|
||||
void Vec_Grow (void **pvec, size_t element_size, size_t count);
|
||||
void Vec_Append (void **pvec, size_t element_size, const void *data, size_t count);
|
||||
void Vec_Clear (void **pvec);
|
||||
void Vec_Free (void **pvec);
|
||||
|
||||
//============================================================================
|
||||
|
||||
extern bool host_bigendian;
|
||||
|
||||
extern short (*BigShort) (short l);
|
||||
@@ -155,8 +81,8 @@ extern float (*LittleFloat) (float l);
|
||||
#include "strl_fn.hpp"
|
||||
|
||||
/* locale-insensitive strcasecmp replacement functions: */
|
||||
extern int q_strcasecmp (const char * s1, const char * s2);
|
||||
extern int q_strncasecmp (const char *s1, const char *s2, size_t n);
|
||||
// extern int common::strcasecmp (const char * s1, const char * s2);
|
||||
// extern int common::strncasecmp (const char *s1, const char *s2, size_t n);
|
||||
|
||||
/* locale-insensitive case-insensitive alternative to strstr */
|
||||
extern char *q_strcasestr(const char *haystack, const char *needle);
|
||||
@@ -175,8 +101,18 @@ extern bool com_eof;
|
||||
|
||||
|
||||
namespace common {
|
||||
extern std::vector<std::string> _argv;
|
||||
/**
|
||||
* When \c true, the engine will behave as if each of these arguments were applied to
|
||||
* the command line:
|
||||
* -nosound,-nocdaudio, -nomidi, -stdvid, -dibonly, -nomouse, -nojoy, -nolan
|
||||
*/
|
||||
extern bool safe_mode;
|
||||
|
||||
void init();
|
||||
|
||||
void init_argv(int argc, char **nargv);
|
||||
|
||||
std::optional<size_t> check_param(std::string_view parm);
|
||||
|
||||
std::optional<std::string> parse_token(std::istringstream &ss);
|
||||
@@ -184,20 +120,13 @@ namespace common {
|
||||
|
||||
int parse_int_newline(std::istringstream &ss);
|
||||
float parse_float_newline(std::istringstream &ss);
|
||||
|
||||
std::partial_ordering strcasecmp(std::string_view lhs, std::string_view rhs);
|
||||
|
||||
std::partial_ordering strncasecmp(std::string_view lhs, std::string_view rhs, size_t n);
|
||||
}
|
||||
|
||||
|
||||
extern int com_argc;
|
||||
extern char **com_argv;
|
||||
|
||||
extern int safemode;
|
||||
/* safe mode: in true, the engine will behave as if one
|
||||
of these arguments were actually on the command line:
|
||||
-nosound, -nocdaudio, -nomidi, -stdvid, -dibonly,
|
||||
-nomouse, -nojoy, -nolan
|
||||
*/
|
||||
|
||||
void COM_InitArgv (int argc, char **argv);
|
||||
void COM_InitFilesystem (void);
|
||||
|
||||
const char *COM_SkipPath (const char *pathname);
|
||||
@@ -329,5 +258,3 @@ extern bool standard_quake, rogue, hipnotic;
|
||||
extern bool fitzmode;
|
||||
/* if true, run in fitzquake mode disabling custom quakespasm hacks */
|
||||
|
||||
#endif /* _Q_COMMON_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user