19 #include "shared/shared.h"
20 #include "common/utils.h"
30 static qboolean
match_raw(
int c1,
int c2, qboolean ignorecase)
38 c1 = c1 ==
'\\' ?
'/' : Q_tolower(c1);
39 c2 = c2 ==
'\\' ?
'/' : Q_tolower(c2);
52 static qboolean
match_char(
int c1,
int c2, qboolean ignorecase)
61 static qboolean
match_part(
const char *filter,
const char *
string,
62 size_t len, qboolean ignorecase)
68 if (*filter ==
'\\') {
70 match =
match_raw(*filter, *
string, ignorecase);
72 match =
match_char(*filter, *
string, ignorecase);
87 static const char *
match_filter(
const char *filter,
const char *
string,
88 size_t len, qboolean ignorecase)
90 const char *ret = NULL;
91 size_t remaining = strlen(
string);
93 while (remaining >= len) {
94 if (
match_part(filter,
string, len, ignorecase)) {
123 int term, qboolean ignorecase)
129 while (*filter && *filter != term) {
130 if (*filter ==
'*') {
134 }
while (*filter ==
'*');
137 for (sub = filter, len = 0; *filter && *filter != term && *filter !=
'*'; filter++, len++) {
139 if (*filter ==
'\\') {
158 if (*filter ==
'\\') {
163 match =
match_raw(*filter, *
string, ignorecase);
165 match =
match_char(*filter, *
string, ignorecase);
191 "black",
"red",
"green",
"yellow",
192 "blue",
"cyan",
"magenta",
"white",
209 i = strtoul(s, NULL, 10);
210 return i > last ? COLOR_NONE : i;
213 for (i = 0; i <= last; i++) {
230 unsigned Com_ParseExtensionString(
const char *s,
const char *
const extnames[])
245 for (i = 0; extnames[i]; i++) {
246 l2 = strlen(extnames[i]);
247 if (l1 == l2 && !memcmp(s, extnames[i], l1)) {
273 VectorScale(ps->pmove.origin, 0.125f, es->origin);
275 pitch = ps->viewangles[PITCH];
279 es->angles[PITCH] = pitch / 3;
280 es->angles[YAW] = ps->viewangles[YAW];
281 es->angles[ROLL] = 0;
284 #if USE_CLIENT || USE_MVD_CLIENT
293 qboolean Com_ParseTimespec(
const char *s,
int *frames)
295 unsigned long c1, c2, c3;
298 c1 = strtoul(s, &p, 10);
305 c2 = strtoul(p + 1, &p, 10);
308 *frames = c1 * 10 + c2;
313 c2 = strtoul(p + 1, &p, 10);
315 *frames = c1 * 600 + c2 * 10;
320 c3 = strtoul(p + 1, &p, 10);
323 *frames = c1 * 600 + c2 * 10 + c3;
346 hash = 127 * hash +
c;
349 hash = (hash >> 20) ^(hash >> 10) ^ hash;
350 return hash & (size - 1);
366 while (*s && len--) {
368 hash = 127 * hash +
c;
371 hash = (hash >> 20) ^(hash >> 10) ^ hash;
372 return hash & (size - 1);
387 for (i = size - 1; i > 0; i -= 4096)
393 int sec, min, hour, day;
395 min = t / 60; sec = t % 60;
396 hour = min / 60; min %= 60;
397 day = hour / 24; hour %= 24;
400 return Q_scnprintf(buffer, size,
"%d+%d:%02d.%02d", day, hour, min, sec);
403 return Q_scnprintf(buffer, size,
"%d:%02d.%02d", hour, min, sec);
405 return Q_scnprintf(buffer, size,
"%02d.%02d", min, sec);
410 int sec, min, hour, day;
417 min = t / 60; sec = t % 60;
418 hour = min / 60; min %= 60;
419 day = hour / 24; hour %= 24;
425 "%d day%s%s", day, day == 1 ?
"" :
"s", (hour || min || sec) ?
", " :
"");
429 "%d hour%s%s", hour, hour == 1 ?
"" :
"s", (min || sec) ?
", " :
"");
433 "%d min%s%s", min, min == 1 ?
"" :
"s", sec ?
", " :
"");
437 "%d sec%s", sec, sec == 1 ?
"" :
"s");
467 if (bytes >= 10000000) {
468 return Q_scnprintf(dest, destsize,
"%dM", (
int)(bytes / 1000000));
470 if (bytes >= 1000000) {
471 return Q_scnprintf(dest, destsize,
"%.1fM", (
float)bytes / 1000000);
474 return Q_scnprintf(dest, destsize,
"%dK", (
int)(bytes / 1000));
477 return Q_scnprintf(dest, destsize,
"%d", (
int)bytes);
484 if (bytes >= 10000000) {
485 return Q_scnprintf(dest, destsize,
"%d MB", (
int)(bytes / 1000000));
487 if (bytes >= 1000000) {
488 return Q_scnprintf(dest, destsize,
"%.1f MB", (
float)bytes / 1000000);
491 return Q_scnprintf(dest, destsize,
"%d kB", (
int)(bytes / 1000));
495 (
int)bytes, bytes == 1 ?
"" :
"s");
497 return Q_scnprintf(dest, destsize,
"unknown size");