55 if (!
buf->allowoverflow)
56 Host_Error (
"SZ_GetSpace: overflow without allowoverflow set");
61 buf->overflowed =
true;
81static const char *
hexchar =
"0123456789ABCDEF";
86 char *cur, *flushpointer;
87 const unsigned char *d;
89 flushpointer = text + 512;
103 for (j = 0;j < 16;j++)
107 *cur++ =
hexchar[(d[j] >> 4) & 15];
108 *cur++ =
hexchar[(d[j] >> 0) & 15];
119 for (j = 0;j < 16;j++)
129 else if (d[j] >= (
unsigned char)
' ')
139 if (cur >= flushpointer ||
i >=
size)
185 qbool isContinuation =
false;
187 const char *startOfLine =
string;
188 const char *cursor =
string;
189 const char *end =
string +
length;
190 float spaceUsedInLine = 0;
191 float spaceUsedForWord;
197 wordWidth(passthroughCW,
NULL, &dummy, -1);
199 spaceWidth = wordWidth(passthroughCW,
" ", &dummy, -1);
203 char ch = (cursor < end) ? *cursor : 0;
207 result += processLine(passthroughPL, startOfLine, cursor - startOfLine, spaceUsedInLine, isContinuation);
210 result += processLine(passthroughPL, startOfLine, cursor - startOfLine, spaceUsedInLine, isContinuation);
211 isContinuation =
false;
213 startOfLine = cursor;
217 spaceUsedInLine += spaceWidth;
221 while(cursor + wordLen < end)
223 switch(cursor[wordLen])
235 spaceUsedForWord = wordWidth(passthroughCW, cursor, &wordLen, maxWidth - continuationWidth);
239 spaceUsedForWord = maxWidth + 1;
241 if(spaceUsedInLine + spaceUsedForWord <= maxWidth || cursor == startOfLine)
245 spaceUsedInLine += spaceUsedForWord;
250 result += processLine(passthroughPL, startOfLine, cursor - startOfLine, spaceUsedInLine, isContinuation);
251 isContinuation =
true;
252 startOfLine = cursor;
254 spaceUsedInLine = continuationWidth + spaceUsedForWord;
467 const char *
data = *datapointer;
495 if (
data[0] ==
'\r' &&
data[1] ==
'\n')
498 if (parsecomments &&
data[0] ==
'/' &&
data[1] ==
'/')
505 else if (parsecomments &&
data[0] ==
'/' &&
data[1] ==
'*')
517 else if (*
data ==
'\"')
523 if (*
data ==
'\\' && parsebackslash)
542 else if (*
data ==
'\r')
551 else if (*
data ==
'\n')
585 const char *
data = *datapointer;
613 if (
data[0] ==
'\r' &&
data[1] ==
'\n')
616 if (
data[0] ==
'/' &&
data[1] ==
'/')
623 else if (
data[0] ==
'/' &&
data[1] ==
'*')
635 else if (*
data ==
'\"' || *
data ==
'\'')
661 else if (*
data ==
'\r')
704 const char *
data = *datapointer;
732 if (
data[0] ==
'\r' &&
data[1] ==
'\n')
735 if (
data[0] ==
'/' &&
data[1] ==
'/')
742 else if (
data[0] ==
'/' &&
data[1] ==
'*')
754 else if (*
data ==
'\"' || *
data ==
'\'')
780 else if (*
data ==
'\r')
822 const char *
data = *datapointer;
852 else if (*
data ==
'\"')
858 if (*
data ==
'\\' && (
data[1] ==
'\"' ||
data[1] ==
'\\'))
898 sign = side < 0 ? -1 : 1;
901 if (side < velocityval)
902 side = side * angleval / velocityval;
939 if (
n >= ((
int)
sizeof(com_cmdline) - 2))
941 com_cmdline[
n++] =
'\"';
944 while ((
n < ((
int)
sizeof(com_cmdline) - 2)) &&
sys.
argv[j][
i])
947 com_cmdline[
n++] =
'\"';
953 while ((
n < ((
int)
sizeof(com_cmdline) - 1)) &&
sys.
argv[j][
i])
956 if (
n < ((
int)
sizeof(com_cmdline) - 1))
957 com_cmdline[
n++] =
' ';
976 va_start (argptr,
format);
992# define snprintf _snprintf
993# define vsnprintf _vsnprintf
1015 result = _vsnprintf_s (
buffer, buffersize, _TRUNCATE,
format, args);
1019 if (result < 0 || (
size_t)result >= buffersize)
1023 buffer[buffersize - 1] =
'\0';
1027 Sys_Print(
"dpvsnprintf: output error!\n", 27);
1032 result = _snprintf_s(msg,
sizeof(msg), _TRUNCATE,
"dpvsnprintf: truncated to %lu bytes: \"%s\"\n", (
unsigned long)buffersize - 1,
buffer);
1034 result =
snprintf(msg,
sizeof(msg),
"dpvsnprintf: truncated to %lu bytes: \"%s\"\n", (
unsigned long)buffersize - 1,
buffer);
1038 msg[
sizeof(msg) - 1] =
'\n';
1053 const char *out_start = out;
1061 while(*in && size_out > 1)
1072 return out - out_start;
1075 while (*in && size_out > 1)
1077 if (*in >=
'A' && *in <=
'Z')
1078 *out++ = *in++ +
'a' -
'A';
1084 return out - out_start;
1089 const char *out_start = out;
1097 while(*in && size_out > 1)
1108 return out - out_start;
1111 while (*in && size_out > 1)
1113 if (*in >=
'a' && *in <=
'z')
1114 *out++ = *in++ +
'A' -
'a';
1120 return out - out_start;
1125 for (;*s && *match;s++, match++)
1133 int argc, commentprefixlength;
1137 tokenbufend = tokenbuf + tokenbufsize;
1139 commentprefixlength = 0;
1141 commentprefixlength = (
int)
strlen(commentprefix);
1142 while (*l && *l !=
'\n' && *l !=
'\r')
1146 if (commentprefixlength && !strncmp(l, commentprefix, commentprefixlength))
1148 while (*l && *l !=
'\n' && *l !=
'\r')
1152 if (argc >= maxargc)
1154 argv[argc++] = tokenbuf;
1158 while (*l && *l !=
'"')
1160 if (tokenbuf >= tokenbufend)
1171 if (tokenbuf >= tokenbufend)
1176 if (tokenbuf >= tokenbufend)
1214 const char *end = size_s ? (s + size_s) :
NULL;
1218 switch((s == end) ? 0 : *s)
1226 switch((s == end) ? 0 : *s)
1229 if (s+1 != end && isxdigit(s[1]) &&
1230 s+2 != end && isxdigit(s[2]) &&
1231 s+3 != end && isxdigit(s[3]) )
1247 case '0':
case '1':
case '2':
case '3':
case '4':
1248 case '5':
case '6':
case '7':
case '8':
case '9':
1288#define APPEND(ch) do { if(--size_out) { *out++ = (ch); } else { *out++ = 0; return 0; } } while(0)
1290 const char *out_start = out;
1291 const char *end = size_in ? (in + size_in) :
NULL;
1297 switch((in == end) ? 0 : *in)
1301 return out - out_start;
1304 switch((in == end) ? 0 : *in)
1307 if (in+1 != end && isxdigit(in[1]) &&
1308 in+2 != end && isxdigit(in[2]) &&
1309 in+3 != end && isxdigit(in[3]) )
1325 return out - out_start;
1332 case '0':
case '1':
case '2':
case '3':
case '4':
1333 case '5':
case '6':
case '7':
case '8':
case '9':
1364 #define memccpy _memccpy
1375 char *p = (
char *)memccpy(dst,
src,
'\0', end - dst);
1380 Con_Printf(
CON_WARN "%s: src string unterminated or truncated to %lu bytes: \"%s\"\n", __func__, (
unsigned long)(dst == end ? 0 : (end - dst) - 1), dst);
1393 Con_Printf(
CON_WARN "%s: src string truncated to %lu bytes: \"%.*s\"\n", __func__, (
unsigned long)slen, (
int)slen,
src);
1395 memcpy(dst,
src, slen);
1406size_t dp__strlcpy(
char *dst,
const char *
src,
size_t dsize,
const char *func,
unsigned line)
1408 char *p = (
char *)memccpy(dst,
src,
'\0', dsize);
1411 return (p - 1) - dst;
1412 dst[dsize - 1] =
'\0';
1413 Con_Printf(
CON_WARN "%s:%u: src string unterminated or truncated to %lu bytes: \"%s\"\n", func, line, (
unsigned long)dsize - 1, dst);
1423size_t dp__strlcat(
char *dst,
const char *
src,
size_t dsize,
const char *func,
unsigned line)
1426 char *p = (
char *)memchr(dst,
'\0', dsize);
1441 bestdiff =
fabs(val);
1445 for(
i = 1;
i <= denomMax; ++
i)
1448 double diff =
fabs(val - inum / (
double)
i);
1461 static char *
tokens[257];
1462 static char lines[257][512];
1471 tokens[line] = lines[line];
1486static const char base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1487static void base64_3to4(
const unsigned char *in,
unsigned char *out,
int bytes)
1489 unsigned char i0 = (bytes > 0) ? in[0] : 0;
1490 unsigned char i1 = (bytes > 1) ? in[1] : 0;
1491 unsigned char i2 = (bytes > 2) ? in[2] : 0;
1492 unsigned char o0 =
base64[i0 >> 2];
1493 unsigned char o1 =
base64[((i0 << 4) | (i1 >> 4)) & 077];
1494 unsigned char o2 =
base64[((i1 << 2) | (i2 >> 6)) & 077];
1495 unsigned char o3 =
base64[i2 & 077];
1496 out[0] = (bytes > 0) ? o0 :
'?';
1497 out[1] = (bytes > 0) ? o1 :
'?';
1498 out[2] = (bytes > 1) ? o2 :
'=';
1499 out[3] = (bytes > 2) ? o3 :
'=';
1506 blocks = (buflen + 2) / 3;
1507 if(blocks*4 > outbuflen)
1509 for(
i = blocks;
i > 0; )
#define CF_READONLY
cvar cannot be changed from the console or the command buffer, and is considered CF_PERSISTENT
#define CF_USERINFO
command or cvar used to communicate userinfo to the server
#define CF_SERVER
cvar/command that only the server can change/execute
#define CF_CLIENT
cvar/command that only the client can change/execute
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
void SZ_Clear(sizebuf_t *buf)
int dpvsnprintf(char *buffer, size_t buffersize, const char *format, va_list args)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
char * dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t slen)
Copies a measured byte sequence (unterminated string) to a null-terminated string.
size_t dp__strlcpy(char *dst, const char *src, size_t dsize, const char *func, unsigned line)
Copies a string, like strlcpy() but with a better return: the number of bytes copied excluding the \0...
int COM_StringBeginsWith(const char *s, const char *match)
unsigned char * SZ_GetSpace(sizebuf_t *buf, int length)
int COM_Wordwrap(const char *string, size_t length, float continuationWidth, float maxWidth, COM_WordWidthFunc_t wordWidth, void *passthroughCW, COM_LineProcessorFunc processLine, void *passthroughPL)
char com_token[MAX_INPUTLINE]
char * va(char *buf, size_t buflen, const char *format,...)
qbool COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline)
char * dp_stpecpy(char *dst, char *end, const char *src)
Chain-copies a string with truncation and efficiency (compared to strlcat()).
char ** XPM_DecodeString(const char *in)
size_t COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qbool escape_carets)
qbool COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline)
qbool COM_ParseToken_Console(const char **datapointer)
float Com_CalcRoll(const vec3_t angles, const vec3_t velocity, const vec_t angleval, const vec_t velocityval)
size_t COM_ToUpperString(const char *in, char *out, size_t size_out)
Returns the number of bytes written to *out excluding the \0 terminator.
void Com_HexDumpToConsole(const unsigned char *data, int size)
void SZ_HexDumpToConsole(const sizebuf_t *buf)
void FindFraction(double val, int *num, int *denom, int denomMax)
static const char base64[]
static const char * hexchar
static void base64_3to4(const unsigned char *in, unsigned char *out, int bytes)
size_t COM_StringLengthNoColors(const char *s, size_t size_s, qbool *valid)
qbool COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments)
void COM_Init_Commands(void)
int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix)
void SZ_Write(sizebuf_t *buf, const unsigned char *data, int length)
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen)
size_t COM_ToLowerString(const char *in, char *out, size_t size_out)
Returns the number of bytes written to *out excluding the \0 terminator.
size_t dp__strlcat(char *dst, const char *src, size_t dsize, const char *func, unsigned line)
Catenates a string, like strlcat() but with a better return: the number of bytes copied excluding the...
int(* COM_LineProcessorFunc)(void *passthrough, const char *line, size_t length, float width, qbool isContination)
float(* COM_WordWidthFunc_t)(void *passthrough, const char *w, size_t *length, float maxWidth)
#define dp_strlcpy(dst, src, dsize)
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
void Cvar_SetQuick(cvar_t *var, const char *value)
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
void Cvar_RegisterVirtual(cvar_t *variable, const char *name)
#define STRING_COLOR_RGB_TAG_CHAR
static int(ZEXPORT *qz_inflate)(z_stream *strm
GLsizei const GLchar ** string
GLenum GLuint GLenum GLsizei length
GLint GLint GLint GLsizei GLsizei GLenum format
GLsizeiptr const GLvoid * data
GLuint GLuint GLintptr offset
GLenum GLuint GLenum GLsizei const GLchar * buf
void Host_Error(const char *error,...)
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
static int tokens[VM_TEMPSTRING_MAXSIZE/2]
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
void Sys_Print(const char *text, size_t textlen)
(may) output text to terminal which launched program is POSIX async-signal-safe textlen excludes any ...
Uchar u8_tolower(Uchar ch)
Uchar u8_toupper(Uchar ch)
int u8_fromchar(Uchar w, char *to, size_t maxlen)
Encode a wide-character into utf-8.
Uchar u8_getchar_utf8_enabled(const char *_s, const char **_end)
Fetch a character from an utf-8 encoded string.