Quake II RTX doxygen  1.0 dev
shared.c File Reference
#include "shared/shared.h"

Go to the source code of this file.

Functions

void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
 
vec_t VectorNormalize (vec3_t v)
 
vec_t VectorNormalize2 (vec3_t v, vec3_t out)
 
void ClearBounds (vec3_t mins, vec3_t maxs)
 
void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs)
 
void UnionBounds (vec3_t a[2], vec3_t b[2], vec3_t c[2])
 
vec_t RadiusFromBounds (const vec3_t mins, const vec3_t maxs)
 
char * COM_SkipPath (const char *pathname)
 
void COM_StripExtension (const char *in, char *out, size_t size)
 
char * COM_FileExtension (const char *in)
 
void COM_FileBase (char *in, char *out)
 
void COM_FilePath (const char *in, char *out, size_t size)
 
size_t COM_DefaultExtension (char *path, const char *ext, size_t size)
 
qboolean COM_IsFloat (const char *s)
 
qboolean COM_IsUint (const char *s)
 
qboolean COM_IsPath (const char *s)
 
qboolean COM_IsWhite (const char *s)
 
int SortStrcmp (const void *p1, const void *p2)
 
int SortStricmp (const void *p1, const void *p2)
 
size_t COM_strclr (char *s)
 
char * va (const char *format,...)
 
char * COM_Parse (const char **data_p)
 
size_t COM_Compress (char *data)
 
int Q_strncasecmp (const char *s1, const char *s2, size_t n)
 
int Q_strcasecmp (const char *s1, const char *s2)
 
char * Q_strcasestr (const char *s1, const char *s2)
 
size_t Q_strlcpy (char *dst, const char *src, size_t size)
 
size_t Q_strlcat (char *dst, const char *src, size_t size)
 
size_t Q_concat (char *dest, size_t size,...)
 
size_t Q_vsnprintf (char *dest, size_t size, const char *fmt, va_list argptr)
 
size_t Q_vscnprintf (char *dest, size_t size, const char *fmt, va_list argptr)
 
size_t Q_snprintf (char *dest, size_t size, const char *fmt,...)
 
size_t Q_scnprintf (char *dest, size_t size, const char *fmt,...)
 
char * Q_strchrnul (const char *s, int c)
 
voidQ_memccpy (void *dst, const void *src, int c, size_t size)
 
void Q_setenv (const char *name, const char *value)
 
char * Info_ValueForKey (const char *s, const char *key)
 
void Info_RemoveKey (char *s, const char *key)
 
qboolean Info_Validate (const char *s)
 
size_t Info_SubValidate (const char *s)
 
qboolean Info_SetValueForKey (char *s, const char *key, const char *value)
 
void Info_NextPair (const char **string, char *key, char *value)
 
void Info_Print (const char *infostring)
 

Variables

vec3_t vec3_origin = { 0, 0, 0 }
 
static char com_token [4][MAX_TOKEN_CHARS]
 
static int com_tokidx
 

Function Documentation

◆ AddPointToBounds()

void AddPointToBounds ( const vec3_t  v,
vec3_t  mins,
vec3_t  maxs 
)

Definition at line 97 of file shared.c.

98 {
99  int i;
100  vec_t val;
101 
102  for (i = 0; i < 3; i++) {
103  val = v[i];
104  if (val < mins[i])
105  mins[i] = val;
106  if (val > maxs[i])
107  maxs[i] = val;
108  }
109 }

Referenced by Think_SpawnDoorTrigger().

◆ AngleVectors()

void AngleVectors ( vec3_t  angles,
vec3_t  forward,
vec3_t  right,
vec3_t  up 
)

Definition at line 23 of file shared.c.

24 {
25  float angle;
26  float sr, sp, sy, cr, cp, cy;
27 
28  angle = angles[YAW] * (M_PI * 2 / 360);
29  sy = sin(angle);
30  cy = cos(angle);
31  angle = angles[PITCH] * (M_PI * 2 / 360);
32  sp = sin(angle);
33  cp = cos(angle);
34  angle = angles[ROLL] * (M_PI * 2 / 360);
35  sr = sin(angle);
36  cr = cos(angle);
37 
38  if (forward) {
39  forward[0] = cp * cy;
40  forward[1] = cp * sy;
41  forward[2] = -sp;
42  }
43  if (right) {
44  right[0] = (-1 * sr * sp * cy + -1 * cr * -sy);
45  right[1] = (-1 * sr * sp * sy + -1 * cr * cy);
46  right[2] = -1 * sr * cp;
47  }
48  if (up) {
49  up[0] = (cr * sp * cy + -sr * -sy);
50  up[1] = (cr * sp * sy + -sr * cy);
51  up[2] = cr * cp;
52  }
53 }

Referenced by actorMachineGun(), ai_run(), Blaster_Fire(), boss2_firebullet_left(), boss2_firebullet_right(), Boss2Rocket(), Chaingun_Fire(), CheckPowerArmor(), ChickRocket(), CL_AddExplosionLight(), CL_AddPacketEntities(), CL_AddPlayerBeams(), CL_AddViewWeapon(), CL_CalcViewValues(), CL_MuzzleFlash(), CL_MuzzleFlash2(), CL_SetupThirdPersionView(), CL_TrackerTrail(), ClientEndServerFrame(), CM_TransformedPointContents(), Drop_Item(), fire_flaregun(), fire_grenade(), fire_grenade2(), fire_hit(), fire_lead(), flare_sparks(), floater_fire_blaster(), floater_zap(), flyer_fire(), G_SetMovedir(), gib_touch(), GladiatorGun(), GunnerFire(), GunnerGrenade(), hover_fire_blaster(), InfantryMachineGun(), infront(), jorg_firebullet_left(), jorg_firebullet_right(), jorgBFG(), Machinegun_Fire(), makronBFG(), MakronHyperblaster(), MakronRailgun(), medic_cable_attack(), medic_fire_blaster(), mutant_jump_takeoff(), MVD_HitPlayer(), parasite_drain_attack(), PM_ClampAngles(), Pmove(), R_AliasSetUpLerpData(), R_AliasSetUpTransform(), R_SetupFrame(), RotatedBBox(), soldier_fire(), SP_func_door_secret(), supertankMachineGun(), supertankRocket(), SV_Push(), TankBlaster(), TankMachineGun(), TankRocket(), Touch_Multi(), turret_breach_fire(), UpdateChaseCam(), vkpt_freecam_update(), weapon_bfg_fire(), weapon_flaregun_fire(), weapon_grenade_fire(), weapon_grenadelauncher_fire(), weapon_railgun_fire(), Weapon_RocketLauncher_Fire(), weapon_shotgun_fire(), and weapon_supershotgun_fire().

◆ ClearBounds()

void ClearBounds ( vec3_t  mins,
vec3_t  maxs 
)

Definition at line 91 of file shared.c.

92 {
93  mins[0] = mins[1] = mins[2] = 99999;
94  maxs[0] = maxs[1] = maxs[2] = -99999;
95 }

Referenced by MOD_LoadMD2_GL(), and MOD_LoadMD2_RTX().

◆ COM_Compress()

size_t COM_Compress ( char *  data)

Definition at line 543 of file shared.c.

544 {
545  int c, n = 0;
546  char *s = data, *d = data;
547 
548  while (*s) {
549  // skip whitespace
550  if (*s <= ' ') {
551  if (n == 0) {
552  n = ' ';
553  }
554  do {
555  c = *s++;
556  if (c == '\n') {
557  n = '\n';
558  }
559  if (!c) {
560  goto finish;
561  }
562  } while (*s <= ' ');
563  }
564 
565  // skip // comments
566  if (s[0] == '/' && s[1] == '/') {
567  n = ' ';
568  s += 2;
569  while (*s && *s != '\n') {
570  s++;
571  }
572  continue;
573  }
574 
575  // skip /* */ comments
576  if (s[0] == '/' && s[1] == '*') {
577  n = ' ';
578  s += 2;
579  while (*s) {
580  if (s[0] == '*' && s[1] == '/') {
581  s += 2;
582  break;
583  }
584  if (*s == '\n') {
585  n = '\n';
586  }
587  s++;
588  }
589  continue;
590  }
591 
592  // add whitespace character
593  if (n) {
594  *d++ = n;
595  n = 0;
596  }
597 
598  // handle quoted strings specially
599  if (*s == '\"') {
600  s++;
601  *d++ = '\"';
602  do {
603  c = *s++;
604  if (!c) {
605  goto finish;
606  }
607  *d++ = c;
608  } while (c != '\"');
609  continue;
610  }
611 
612  // handle line feed escape
613  if (*s == '\\' && s[1] == '\n') {
614  s += 2;
615  continue;
616  }
617  if (*s == '\\' && s[1] == '\r' && s[2] == '\n') {
618  s += 3;
619  continue;
620  }
621 
622  // parse a regular word
623  do {
624  *d++ = *s++;
625  } while (*s > ' ');
626  }
627 
628 finish:
629  *d = 0;
630 
631  return d - data;
632 }

Referenced by Cmd_ExecuteFile(), and Parse_File().

◆ COM_DefaultExtension()

size_t COM_DefaultExtension ( char *  path,
const char *  ext,
size_t  size 
)

Definition at line 279 of file shared.c.

280 {
281  char *src;
282  size_t len;
283 
284  if (*path) {
285  len = strlen(path);
286  src = path + len - 1;
287 
288  while (*src != '/' && src != path) {
289  if (*src == '.')
290  return len; // it has an extension
291  src--;
292  }
293  }
294 
295  len = Q_strlcat(path, ext, size);
296  return len;
297 }

Referenced by CL_PlaySound_f(), and R_RegisterImage().

◆ COM_FileBase()

void COM_FileBase ( char *  in,
char *  out 
)

Definition at line 229 of file shared.c.

230 {
231  char *s, *s2;
232 
233  s = in + strlen(in) - 1;
234 
235  while (s != in && *s != '.')
236  s--;
237 
238  for (s2 = s; s2 != in && *s2 != '/'; s2--)
239  ;
240 
241  if (s - s2 < 2)
242  out[0] = 0;
243  else {
244  s--;
245  strncpy(out, s2 + 1, s - s2);
246  out[s - s2] = 0;
247  }
248 }

◆ COM_FileExtension()

char* COM_FileExtension ( const char *  in)

Definition at line 199 of file shared.c.

200 {
201  const char *s;
202  const char *last;
203 
204  if (!in) {
205  Com_Error(ERR_FATAL, "%s: NULL", __func__);
206  }
207 
208  s = in + strlen(in);
209  last = s;
210 
211  while (s != in) {
212  if (*s == '/') {
213  break;
214  }
215  if (*s == '.') {
216  return (char *)s;
217  }
218  s--;
219  }
220 
221  return (char *)last;
222 }

Referenced by check_file_len(), Com_MapList_m(), FS_ListFiles(), and Sys_ListFiles_r().

◆ COM_FilePath()

void COM_FilePath ( const char *  in,
char *  out,
size_t  size 
)

Definition at line 257 of file shared.c.

258 {
259  char *s;
260 
261  Q_strlcpy(out, in, size);
262  s = strrchr(out, '/');
263  if (s) {
264  *s = 0;
265  } else {
266  *out = 0;
267  }
268 }

◆ COM_IsFloat()

qboolean COM_IsFloat ( const char *  s)

Definition at line 307 of file shared.c.

308 {
309  int c, dot = '.';
310 
311  if (*s == '-') {
312  s++;
313  }
314  if (!*s) {
315  return qfalse;
316  }
317 
318  do {
319  c = *s++;
320  if (c == dot) {
321  dot = 0;
322  } else if (!Q_isdigit(c)) {
323  return qfalse;
324  }
325  } while (*s);
326 
327  return qtrue;
328 }

Referenced by Cmd_If_f(), and Cvar_Inc_f().

◆ COM_IsPath()

qboolean COM_IsPath ( const char *  s)

Definition at line 348 of file shared.c.

349 {
350  int c;
351 
352  if (!*s) {
353  return qfalse;
354  }
355 
356  do {
357  c = *s++;
358  if (!Q_ispath(c)) {
359  return qfalse;
360  }
361  } while (*s);
362 
363  return qtrue;
364 }

Referenced by CL_ParsePlayerSkin(), fs_game_changed(), SV_Loadgame_f(), and SV_Savegame_f().

◆ COM_IsUint()

qboolean COM_IsUint ( const char *  s)

Definition at line 330 of file shared.c.

331 {
332  int c;
333 
334  if (!*s) {
335  return qfalse;
336  }
337 
338  do {
339  c = *s++;
340  if (!Q_isdigit(c)) {
341  return qfalse;
342  }
343  } while (*s);
344 
345  return qtrue;
346 }

Referenced by AC_Info_f(), cl_chat_sound_changed(), Com_ParseColor(), gtv_set_conn(), MVD_SetChannel(), MVD_SetPlayer(), NET_StringPairToAdr(), SV_DelFilterCmd_f(), SV_DelMatch_f(), SV_GetPlayer(), and UI_StatusEvent().

◆ COM_IsWhite()

qboolean COM_IsWhite ( const char *  s)

Definition at line 366 of file shared.c.

367 {
368  int c;
369 
370  while (*s) {
371  c = *s++;
372  if (Q_isgraph(c)) {
373  return qfalse;
374  }
375  }
376 
377  return qtrue;
378 }

Referenced by parse_userinfo(), SV_UpdateUserinfo(), and UI_StatusEvent().

◆ COM_Parse()

char* COM_Parse ( const char **  data_p)

Definition at line 455 of file shared.c.

456 {
457  int c;
458  int len;
459  const char *data;
460  char *s = com_token[com_tokidx++ & 3];
461 
462  data = *data_p;
463  len = 0;
464  s[0] = 0;
465 
466  if (!data) {
467  *data_p = NULL;
468  return s;
469  }
470 
471 // skip whitespace
472 skipwhite:
473  while ((c = *data) <= ' ') {
474  if (c == 0) {
475  *data_p = NULL;
476  return s;
477  }
478  data++;
479  }
480 
481 // skip // comments
482  if (c == '/' && data[1] == '/') {
483  data += 2;
484  while (*data && *data != '\n')
485  data++;
486  goto skipwhite;
487  }
488 
489 // skip /* */ comments
490  if (c == '/' && data[1] == '*') {
491  data += 2;
492  while (*data) {
493  if (data[0] == '*' && data[1] == '/') {
494  data += 2;
495  break;
496  }
497  data++;
498  }
499  goto skipwhite;
500  }
501 
502 // handle quoted strings specially
503  if (c == '\"') {
504  data++;
505  while (1) {
506  c = *data++;
507  if (c == '\"' || !c) {
508  goto finish;
509  }
510 
511  if (len < MAX_TOKEN_CHARS - 1) {
512  s[len++] = c;
513  }
514  }
515  }
516 
517 // parse a regular word
518  do {
519  if (len < MAX_TOKEN_CHARS - 1) {
520  s[len++] = c;
521  }
522  data++;
523  c = *data;
524  } while (c > 32);
525 
526 finish:
527  s[len] = 0;
528 
529  *data_p = data;
530  return s;
531 }

Referenced by CL_ParseStatusResponse(), ED_ParseEdict(), MVD_ParseEntityString(), SCR_ExecuteLayoutString(), SpawnEntities(), and TH_DrawLayoutString().

◆ COM_SkipPath()

char* COM_SkipPath ( const char *  pathname)

Definition at line 152 of file shared.c.

153 {
154  char *last;
155 
156  if (!pathname) {
157  Com_Error(ERR_FATAL, "%s: NULL", __func__);
158  }
159 
160  last = (char *)pathname;
161  while (*pathname) {
162  if (*pathname == '/')
163  last = (char *)pathname + 1;
164  pathname++;
165  }
166  return last;
167 }

Referenced by CL_PlayDemo_f(), demo_play_next(), and FS_ListFiles().

◆ COM_strclr()

size_t COM_strclr ( char *  s)

Definition at line 398 of file shared.c.

399 {
400  char *p;
401  int c;
402  size_t len;
403 
404  p = s;
405  len = 0;
406  while (*s) {
407  c = *s++;
408  c &= 127;
409  if (Q_isprint(c)) {
410  *p++ = c;
411  len++;
412  }
413  }
414 
415  *p = 0;
416 
417  return len;
418 }

Referenced by CL_CheckForIgnore(), CL_Name_g(), CL_ParseCenterPrint(), and CL_ParsePrint().

◆ COM_StripExtension()

void COM_StripExtension ( const char *  in,
char *  out,
size_t  size 
)

Definition at line 174 of file shared.c.

175 {
176  char *s;
177 
178  Q_strlcpy(out, in, size);
179 
180  s = out + strlen(out);
181 
182  while (s != out) {
183  if (*s == '/') {
184  break;
185  }
186  if (*s == '.') {
187  *s = 0;
188  break;
189  }
190  s--;
191  }
192 }

Referenced by IconOfSkinExists(), and PlayerModel_Load().

◆ Info_NextPair()

void Info_NextPair ( const char **  string,
char *  key,
char *  value 
)

Definition at line 1189 of file shared.c.

1190 {
1191  char *o;
1192  const char *s;
1193 
1194  *value = *key = 0;
1195 
1196  s = *string;
1197  if (!s) {
1198  return;
1199  }
1200 
1201  if (*s == '\\')
1202  s++;
1203 
1204  if (!*s) {
1205  *string = NULL;
1206  return;
1207  }
1208 
1209  o = key;
1210  while (*s && *s != '\\') {
1211  *o++ = *s++;
1212  }
1213  *o = 0;
1214 
1215  if (!*s) {
1216  *string = NULL;
1217  return;
1218  }
1219 
1220  o = value;
1221  s++;
1222  while (*s && *s != '\\') {
1223  *o++ = *s++;
1224  }
1225  *o = 0;
1226 
1227  *string = s;
1228 }

Referenced by Info_Print(), and UI_StatusEvent().

◆ Info_Print()

void Info_Print ( const char *  infostring)

Definition at line 1235 of file shared.c.

1236 {
1237  char key[MAX_INFO_STRING];
1238  char value[MAX_INFO_STRING];
1239 
1240  while (1) {
1241  Info_NextPair(&infostring, key, value);
1242  if (!infostring)
1243  break;
1244 
1245  if (!key[0])
1246  strcpy(key, "<MISSING KEY>");
1247 
1248  if (!value[0])
1249  strcpy(value, "<MISSING VALUE>");
1250 
1251  Com_Printf("%-20s %s\n", key, value);
1252  }
1253 }

Referenced by CL_DumpStatusResponse(), CL_Userinfo_f(), SV_DumpUser_f(), SV_Serverinfo_f(), and SV_ShowServerInfo_f().

◆ Info_RemoveKey()

void Info_RemoveKey ( char *  s,
const char *  key 
)

Definition at line 991 of file shared.c.

992 {
993  char *start;
994  char pkey[MAX_INFO_STRING];
995  char *o;
996 
997  while (1) {
998  start = s;
999  if (*s == '\\')
1000  s++;
1001  o = pkey;
1002  while (*s != '\\') {
1003  if (!*s)
1004  return;
1005  *o++ = *s++;
1006  }
1007  *o = 0;
1008  s++;
1009 
1010  while (*s != '\\' && *s) {
1011  s++;
1012  }
1013 
1014  if (!strcmp(key, pkey)) {
1015  o = start; // remove this part
1016  while (*s) {
1017  *o++ = *s++;
1018  }
1019  *o = 0;
1020  s = start;
1021  continue; // search for duplicates
1022  }
1023 
1024  if (!*s)
1025  return;
1026  }
1027 
1028 }

Referenced by Com_TestInfo_f(), Info_SetValueForKey(), and parse_userinfo().

◆ Info_SetValueForKey()

qboolean Info_SetValueForKey ( char *  s,
const char *  key,
const char *  value 
)

Definition at line 1137 of file shared.c.

1138 {
1139  char newi[MAX_INFO_STRING], *v;
1140  size_t l, kl, vl;
1141  int c;
1142 
1143  // validate key
1144  kl = Info_SubValidate(key);
1145  if (kl >= MAX_QPATH) {
1146  return qfalse;
1147  }
1148 
1149  // validate value
1150  vl = Info_SubValidate(value);
1151  if (vl >= MAX_QPATH) {
1152  return qfalse;
1153  }
1154 
1155  Info_RemoveKey(s, key);
1156  if (!vl) {
1157  return qtrue;
1158  }
1159 
1160  l = strlen(s);
1161  if (l + kl + vl + 2 >= MAX_INFO_STRING) {
1162  return qfalse;
1163  }
1164 
1165  newi[0] = '\\';
1166  memcpy(newi + 1, key, kl);
1167  newi[kl + 1] = '\\';
1168  memcpy(newi + kl + 2, value, vl + 1);
1169 
1170  // only copy ascii values
1171  s += l;
1172  v = newi;
1173  while (*v) {
1174  c = *v++;
1175  c &= 127; // strip high bits
1176  if (Q_isprint(c))
1177  *s++ = c;
1178  }
1179  *s = 0;
1180 
1181  return qtrue;
1182 }

Referenced by ClientConnect(), Com_TestInfo_f(), parse_userinfo(), SV_ParseDeltaUserinfo(), and SV_UpdateUserinfo().

◆ Info_SubValidate()

size_t Info_SubValidate ( const char *  s)

Definition at line 1112 of file shared.c.

1113 {
1114  size_t len;
1115  int c;
1116 
1117  len = 0;
1118  while (*s) {
1119  c = *s++;
1120  c &= 127; // strip high bits
1121  if (c == '\\' || c == '\"' || c == ';') {
1122  return SIZE_MAX; // illegal characters
1123  }
1124  if (++len == MAX_QPATH) {
1125  return MAX_QPATH; // oversize value
1126  }
1127  }
1128 
1129  return len;
1130 }

Referenced by Info_SetValueForKey(), and validate_info_cvar().

◆ Info_Validate()

qboolean Info_Validate ( const char *  s)

Definition at line 1040 of file shared.c.

1041 {
1042  size_t len, total;
1043  int c;
1044 
1045  total = 0;
1046  while (1) {
1047  //
1048  // validate key
1049  //
1050  if (*s == '\\') {
1051  s++;
1052  if (++total == MAX_INFO_STRING) {
1053  return qfalse; // oversize infostring
1054  }
1055  }
1056  if (!*s) {
1057  return qfalse; // missing key
1058  }
1059  len = 0;
1060  while (*s != '\\') {
1061  c = *s++;
1062  if (!Q_isprint(c) || c == '\"' || c == ';') {
1063  return qfalse; // illegal characters
1064  }
1065  if (++len == MAX_INFO_KEY) {
1066  return qfalse; // oversize key
1067  }
1068  if (++total == MAX_INFO_STRING) {
1069  return qfalse; // oversize infostring
1070  }
1071  if (!*s) {
1072  return qfalse; // missing value
1073  }
1074  }
1075 
1076  //
1077  // validate value
1078  //
1079  s++;
1080  if (++total == MAX_INFO_STRING) {
1081  return qfalse; // oversize infostring
1082  }
1083  if (!*s) {
1084  return qfalse; // missing value
1085  }
1086  len = 0;
1087  while (*s != '\\') {
1088  c = *s++;
1089  if (!Q_isprint(c) || c == '\"' || c == ';') {
1090  return qfalse; // illegal characters
1091  }
1092  if (++len == MAX_INFO_VALUE) {
1093  return qfalse; // oversize value
1094  }
1095  if (++total == MAX_INFO_STRING) {
1096  return qfalse; // oversize infostring
1097  }
1098  if (!*s) {
1099  return qtrue; // end of string
1100  }
1101  }
1102  }
1103 
1104  return qfalse; // quiet compiler warning
1105 }

Referenced by CL_ParseStatusResponse(), ClientUserinfoChanged(), Com_TestInfo_f(), parse_userinfo(), and SV_UpdateUserinfo().

◆ Info_ValueForKey()

char* Info_ValueForKey ( const char *  s,
const char *  key 
)

Definition at line 945 of file shared.c.

946 {
947  // use 4 buffers so compares work without stomping on each other
948  static char value[4][MAX_INFO_STRING];
949  static int valueindex;
950  char pkey[MAX_INFO_STRING];
951  char *o;
952 
953  valueindex++;
954  if (*s == '\\')
955  s++;
956  while (1) {
957  o = pkey;
958  while (*s != '\\') {
959  if (!*s)
960  goto fail;
961  *o++ = *s++;
962  }
963  *o = 0;
964  s++;
965 
966  o = value[valueindex & 3];
967  while (*s != '\\' && *s) {
968  *o++ = *s++;
969  }
970  *o = 0;
971 
972  if (!strcmp(key, pkey))
973  return value[valueindex & 3];
974 
975  if (!*s)
976  goto fail;
977  s++;
978  }
979 
980 fail:
981  o = value[valueindex & 3];
982  *o = 0;
983  return o;
984 }

Referenced by ClientConnect(), ClientTeam(), ClientUserinfoChanged(), ColorForStatus(), dummy_create(), IsFemale(), IsNeutral(), MVD_GameClientUserinfoChanged(), parse_userinfo(), PutClientInServer(), spectator_respawn(), SV_UpdateUserinfo(), SV_UserinfoChanged(), SVC_DirectConnect(), and UI_StatusEvent().

◆ Q_concat()

size_t Q_concat ( char *  dest,
size_t  size,
  ... 
)

Definition at line 758 of file shared.c.

759 {
760  va_list argptr;
761  const char *s;
762  size_t len, total = 0;
763 
764  va_start(argptr, size);
765  while ((s = va_arg(argptr, const char *)) != NULL) {
766  len = strlen(s);
767  if (total + len < size) {
768  memcpy(dest, s, len);
769  dest += len;
770  }
771  total += len;
772  }
773  va_end(argptr);
774 
775  if (size) {
776  *dest = 0;
777  }
778 
779  return total;
780 }

Referenced by bsp_mesh_register_textures(), BuildName(), check_player(), CL_AddPacketEntities(), CL_LoadClientinfo(), CL_RequestNextDownload(), Cmd_PrintHelp(), Cvar_BitInfo(), easy_open_read(), easy_open_write(), FS_LastModified(), FS_WhereIs_f(), GL_LoadWorld(), Keybind_Draw(), LoadCache(), LOC_LoadLocations(), MOD_LoadMD2_RTX(), open_file_read(), open_file_write(), override_entity_string(), parseMaterialsTable(), PlayerModel_Load(), Pop(), ProcessTexinfo(), Prompt_CompleteCommand(), q_printf(), R_BeginRegistration(), R_BeginRegistration_GL(), R_BeginRegistration_RTX(), R_RegisterImage(), R_SetSky(), R_SetSky_GL(), R_SetSky_RTX(), ReloadMedia(), S_RegisterSexedSound(), S_RegisterSound(), SCR_DrawInventory(), SV_LoadGameLibrary(), SV_ParseMapCmd(), SV_SpawnServer(), Sys_ListFiles_r(), V_Gun_Model_f(), vkpt_textures_prefetch(), and WriteCache().

◆ Q_memccpy()

void* Q_memccpy ( void dst,
const void src,
int  c,
size_t  size 
)

Definition at line 895 of file shared.c.

896 {
897  byte *d = dst;
898  const byte *s = src;
899 
900  while (size--) {
901  if ((*d++ = *s++) == c) {
902  return d;
903  }
904  }
905 
906  return NULL;
907 }

Referenced by check_skins(), MOD_LoadMD2(), MOD_LoadMD2_GL(), MOD_LoadMD2_RTX(), and MOD_LoadSP2().

◆ Q_scnprintf()

◆ Q_setenv()

void Q_setenv ( const char *  name,
const char *  value 
)

Definition at line 909 of file shared.c.

910 {
911 #ifdef _WIN32
912  if (!value) {
913  value = "";
914  }
915 #if (_MSC_VER >= 1400)
916  _putenv_s(name, value);
917 #else
918  _putenv(va("%s=%s", name, value));
919 #endif
920 #else // _WIN32
921  if (value) {
922  setenv(name, value, 1);
923  } else {
924  unsetenv(name);
925  }
926 #endif // !_WIN32
927 }

◆ Q_snprintf()

size_t Q_snprintf ( char *  dest,
size_t  size,
const char *  fmt,
  ... 
)

Definition at line 846 of file shared.c.

847 {
848  va_list argptr;
849  size_t ret;
850 
851  va_start(argptr, fmt);
852  ret = Q_vsnprintf(dest, size, fmt, argptr);
853  va_end(argptr);
854 
855  return ret;
856 }

Referenced by AC_LoadChecks(), AC_ParseViolation(), append_extra_userinfo(), bsp_mesh_create_from_bsp(), bsp_mesh_load_custom_sky(), CL_CheckForResend(), CL_IgnoreNick_f(), CL_InitLocal(), CL_MuzzleFlash(), CL_MuzzleFlash2(), CL_RegisterTEntSounds(), CL_UnIgnoreNick_f(), Cmd_PlayerList_f(), Cmd_Players_f(), Cmd_Say_f(), Com_Quit(), Com_TestSnprintf_f(), Con_DrawSolidConsole(), copy_file(), create_screenshot(), CreateTargetChangeLevel(), Cvar_ClampInteger(), Cvar_ClampValue(), Cvar_Inc_f(), Cvar_SetInteger(), Cvar_SetValue(), DeathmatchScoreboardMessage(), evaluate_reference_mode(), ExitLevel(), finish_download(), format_mask(), FS_Restart(), func_clock_format_countdown(), func_clock_think(), HelpComputer(), HTTP_QueueDownload(), HTTP_SetServer(), http_strerror(), inet_ntop4(), Key_Event(), load_sky_and_lava_clusters(), MVD_Connect_f(), MVD_GameInit(), MVD_LayoutChannels(), MVD_LayoutClients(), MVD_Play_f(), MVD_Say_f(), NET_AdrToString(), PlayDemo(), qvk_result_to_string(), read_level_file(), read_server_file(), remove_file(), scr_crosshair_changed(), SCR_DrawFPS(), SCR_DrawInventory(), SCR_ExecuteLayoutString(), SCR_PlayCinematic(), SCR_ScoreShot_f(), SkyLoadScatterParameters(), SP_target_speaker(), start_download(), SV_GetSaveInfo(), SV_ListMasters_f(), SV_StatusString(), SVCmd_WriteIP_f(), TCP_OpenSocket(), UDP_OpenSocket(), UI_Init(), UpdateStatus(), userinfo_ip_string(), VID_SetGeometry(), vtos(), write_level_file(), and write_server_file().

◆ Q_strcasecmp()

int Q_strcasecmp ( const char *  s1,
const char *  s2 
)

Definition at line 666 of file shared.c.

667 {
668  int c1, c2;
669 
670  do {
671  c1 = *s1++;
672  c2 = *s2++;
673 
674  if (c1 != c2) {
675  c1 = Q_tolower(c1);
676  c2 = Q_tolower(c2);
677  if (c1 < c2)
678  return -1;
679  if (c1 > c2)
680  return 1; /* strings not equal */
681  }
682  } while (c1);
683 
684  return 0; /* strings are equal */
685 }

Referenced by CL_AddPacketEntities(), CL_InitLocal(), find_dup(), MAT_FindPBRMaterial(), and validateMaterialsTable().

◆ Q_strcasestr()

char* Q_strcasestr ( const char *  s1,
const char *  s2 
)

Definition at line 687 of file shared.c.

688 {
689  size_t l1, l2;
690 
691  l2 = strlen(s2);
692  if (!l2) {
693  return (char *)s1;
694  }
695 
696  l1 = strlen(s1);
697  while (l1 >= l2) {
698  l1--;
699  if (!Q_strncasecmp(s1, s2, l2)) {
700  return (char *)s1;
701  }
702  s1++;
703  }
704 
705  return NULL;
706 }

◆ Q_strchrnul()

char* Q_strchrnul ( const char *  s,
int  c 
)

Definition at line 879 of file shared.c.

880 {
881  while (*s && *s != c) {
882  s++;
883  }
884  return (char *)s;
885 }

Referenced by AC_SimpleParse(), and CL_ParseStatusResponse().

◆ Q_strlcat()

size_t Q_strlcat ( char *  dst,
const char *  src,
size_t  size 
)

Definition at line 735 of file shared.c.

736 {
737  size_t ret, len = strlen(dst);
738 
739  if (len >= size) {
740  Com_Error(ERR_FATAL, "%s: already overflowed", __func__);
741  }
742 
743  ret = Q_strlcpy(dst + len, src, size - len);
744  ret += len;
745 
746  return ret;
747 }

Referenced by Cmd_Exec_f(), COM_DefaultExtension(), easy_open_read(), and IconOfSkinExists().

◆ Q_strlcpy()

◆ Q_strncasecmp()

int Q_strncasecmp ( const char *  s1,
const char *  s2,
size_t  n 
)

Definition at line 642 of file shared.c.

643 {
644  int c1, c2;
645 
646  do {
647  c1 = *s1++;
648  c2 = *s2++;
649 
650  if (!n--)
651  return 0; /* strings are equal until end point */
652 
653  if (c1 != c2) {
654  c1 = Q_tolower(c1);
655  c2 = Q_tolower(c2);
656  if (c1 < c2)
657  return -1;
658  if (c1 > c2)
659  return 1; /* strings not equal */
660  }
661  } while (c1);
662 
663  return 0; /* strings are equal */
664 }

Referenced by CL_Connect_f(), Prompt_AddMatch(), and Q_strcasestr().

◆ Q_vscnprintf()

size_t Q_vscnprintf ( char *  dest,
size_t  size,
const char *  fmt,
va_list  argptr 
)

Definition at line 823 of file shared.c.

824 {
825  size_t ret;
826 
827  if (!size)
828  return 0;
829 
830  ret = Q_vsnprintf(dest, size, fmt, argptr);
831  if (ret < size)
832  return ret;
833 
834  return size - 1;
835 }

Referenced by Com_Error(), Com_LPrintf(), and Q_scnprintf().

◆ Q_vsnprintf()

size_t Q_vsnprintf ( char *  dest,
size_t  size,
const char *  fmt,
va_list  argptr 
)

Definition at line 791 of file shared.c.

792 {
793  int ret;
794 
795  if (size > INT_MAX)
796  Com_Error(ERR_FATAL, "%s: bad buffer size", __func__);
797 
798 #ifdef _WIN32
799  if (size) {
800  ret = _vsnprintf(dest, size - 1, fmt, argptr);
801  if (ret < 0 || ret >= size - 1)
802  dest[size - 1] = 0;
803  } else {
804  ret = _vscprintf(fmt, argptr);
805  }
806 #else
807  ret = vsnprintf(dest, size, fmt, argptr);
808 #endif
809 
810  // exploit the fact -1 becomes SIZE_MAX > size
811  return (size_t)ret;
812 }

Referenced by AC_Announce(), Com_Error(), Com_LPrintf(), Con_Printf(), FS_FPrintf(), MVD_BroadcastPrintf(), MVD_Destroyf(), Netchan_OutOfBand(), PF_bprintf(), PF_centerprintf(), PF_cprintf(), PF_dprintf(), PF_error(), q_printf(), Q_snprintf(), Q_vscnprintf(), SV_BroadcastCommand(), SV_BroadcastPrintf(), SV_ClientCommand(), SV_ClientPrintf(), Sys_Error(), and va().

◆ RadiusFromBounds()

vec_t RadiusFromBounds ( const vec3_t  mins,
const vec3_t  maxs 
)

Definition at line 127 of file shared.c.

128 {
129  int i;
130  vec3_t corner;
131  vec_t a, b;
132 
133  for (i = 0; i < 3; i++) {
134  a = Q_fabs(mins[i]);
135  b = Q_fabs(maxs[i]);
136  corner[i] = a > b ? a : b;
137  }
138 
139  return VectorLength(corner);
140 }

Referenced by LOAD(), MOD_LoadMD2_GL(), and MOD_LoadMD2_RTX().

◆ SortStrcmp()

int SortStrcmp ( const void p1,
const void p2 
)

Definition at line 380 of file shared.c.

381 {
382  return strcmp(*(const char **)p1, *(const char **)p2);
383 }

Referenced by Prompt_CompleteCommand(), and Prompt_ShowIndividualMatches().

◆ SortStricmp()

int SortStricmp ( const void p1,
const void p2 
)

Definition at line 385 of file shared.c.

386 {
387  return Q_stricmp(*(const char **)p1, *(const char **)p2);
388 }

Referenced by Prompt_CompleteCommand().

◆ UnionBounds()

void UnionBounds ( vec3_t  a[2],
vec3_t  b[2],
vec3_t  c[2] 
)

Definition at line 111 of file shared.c.

112 {
113  c[0][0] = b[0][0] < a[0][0] ? b[0][0] : a[0][0];
114  c[0][1] = b[0][1] < a[0][1] ? b[0][1] : a[0][1];
115  c[0][2] = b[0][2] < a[0][2] ? b[0][2] : a[0][2];
116 
117  c[1][0] = b[1][0] > a[1][0] ? b[1][0] : a[1][0];
118  c[1][1] = b[1][1] > a[1][1] ? b[1][1] : a[1][1];
119  c[1][2] = b[1][2] > a[1][2] ? b[1][2] : a[1][2];
120 }

Referenced by cull_lerped_model().

◆ va()

◆ VectorNormalize()

vec_t VectorNormalize ( vec3_t  v)

Definition at line 55 of file shared.c.

56 {
57  float length, ilength;
58 
59  length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
60  length = sqrtf(length); // FIXME
61 
62  if (length) {
63  ilength = 1 / length;
64  v[0] *= ilength;
65  v[1] *= ilength;
66  v[2] *= ilength;
67  }
68 
69  return length;
70 
71 }

Referenced by actorMachineGun(), AL_AddLoopSounds(), bfg_think(), boss2_firebullet_left(), boss2_firebullet_right(), Boss2Rocket(), CheckPowerArmor(), ChickRocket(), CL_AddBeams(), CL_AddPlayerBeams(), CL_BlasterTrail(), CL_BlasterTrail2(), CL_BubbleTrail(), CL_BubbleTrail2(), CL_DebugTrail(), CL_DiminishingTrail(), CL_FlagTrail(), CL_ForceWall(), CL_Heatbeam(), CL_IonripperTrail(), CL_MonsterPlasma_Shell(), CL_Nukeblast(), CL_OldRailTrail(), CL_ParticleEffect(), CL_ParticleEffectWaterSplash(), CL_QuadTrail(), CL_RailLights(), CL_RailSpiral(), CL_RocketTrail(), CL_SmokeTrail(), CL_TagTrail(), CL_TeleportParticles(), CL_Tracker_Explode(), CL_Tracker_Shell(), CL_TrackerTrail(), CL_TrapParticles(), CL_Widowbeamout(), CL_WidowSplash(), collect_ligth_polys(), compute_world_tangents(), fire_blaster(), fire_hit(), fire_lead(), func_explosive_explode(), get_triangle_off_center(), GladiatorGun(), GunnerFire(), InfantryMachineGun(), infront(), jorg_firebullet_left(), jorg_firebullet_right(), jorgBFG(), light_affects_cluster(), makronBFG(), MakronRailgun(), MakronSpawn(), MOD_LoadMD2_RTX(), Move_Calc(), mutant_jump_touch(), P_DamageFeedback(), PM_AirMove(), PM_CheckSpecialMovement(), PM_DeadMove(), PM_FlyMove(), PM_WaterMove(), prepare_camera(), R_DrawBeam(), R_IMFlatShadedQuad(), R_ViewChanged(), soldier_fire(), supertankMachineGun(), supertankRocket(), T_Damage(), TankRocket(), target_laser_think(), UpdateChaseCam(), vkpt_build_beam_lights(), vkpt_build_cylinder_light(), vkpt_normalize_normal_map(), vkpt_physical_sky_update_ubo(), vkpt_shadow_map_setup(), write_beam_geometry(), write_particle_geometry(), and write_sprite_geometry().

◆ VectorNormalize2()

vec_t VectorNormalize2 ( vec3_t  v,
vec3_t  out 
)

Definition at line 73 of file shared.c.

74 {
75  float length, ilength;
76 
77  length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
78  length = sqrtf(length); // FIXME
79 
80  if (length) {
81  ilength = 1 / length;
82  out[0] = v[0] * ilength;
83  out[1] = v[1] * ilength;
84  out[2] = v[2] * ilength;
85  }
86 
87  return length;
88 
89 }

Referenced by compute_world_tangents(), computeTangents(), create_look_at_matrix(), R_SetSky_GL(), and R_SetSky_RTX().

Variable Documentation

◆ com_token

char com_token[4][MAX_TOKEN_CHARS]
static

Definition at line 444 of file shared.c.

Referenced by COM_Parse(), and SpawnEntities().

◆ com_tokidx

int com_tokidx
static

Definition at line 445 of file shared.c.

Referenced by COM_Parse().

◆ vec3_origin

Q_strlcat
size_t Q_strlcat(char *dst, const char *src, size_t size)
Definition: shared.c:735
Q_strncasecmp
int Q_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: shared.c:642
com_token
static char com_token[4][MAX_TOKEN_CHARS]
Definition: shared.c:444
data_p
static byte * data_p
Definition: mem.c:100
Q_vsnprintf
size_t Q_vsnprintf(char *dest, size_t size, const char *fmt, va_list argptr)
Definition: shared.c:791
ext
char ext[4]
Definition: images.c:657
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
forward
static vec3_t forward
Definition: p_view.c:27
va
char * va(const char *format,...)
Definition: shared.c:429
Q_strlcpy
size_t Q_strlcpy(char *dst, const char *src, size_t size)
Definition: shared.c:715
c
statCounters_t c
Definition: main.c:30
up
static vec3_t up
Definition: p_view.c:27
right
static vec3_t right
Definition: p_view.c:27
com_tokidx
static int com_tokidx
Definition: shared.c:445
Q_vscnprintf
size_t Q_vscnprintf(char *dest, size_t size, const char *fmt, va_list argptr)
Definition: shared.c:823
Info_NextPair
void Info_NextPair(const char **string, char *key, char *value)
Definition: shared.c:1189
Info_RemoveKey
void Info_RemoveKey(char *s, const char *key)
Definition: shared.c:991
Info_SubValidate
size_t Info_SubValidate(const char *s)
Definition: shared.c:1112