mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-05-30 08:40:39 +00:00
Okay, the big whitespace reformat. There is some silliness (case
statements, variable declarations), but all in all it's not bad.
This commit is contained in:
parent
b62d75a774
commit
54e2a4d9d3
172 changed files with 26949 additions and 26640 deletions
156
source/info.c
156
source/info.c
|
@ -27,7 +27,7 @@
|
|||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include "console.h"
|
||||
|
||||
|
@ -54,22 +54,22 @@ Searches the string for the given
|
|||
key and returns the associated value, or an empty string.
|
||||
===============
|
||||
*/
|
||||
char *Info_ValueForKey (char *s, char *key)
|
||||
char *
|
||||
Info_ValueForKey (char *s, char *key)
|
||||
{
|
||||
char pkey[512];
|
||||
static char value[4][512]; // use two buffers so compares
|
||||
// work without stomping on each other
|
||||
static int valueindex;
|
||||
char *o;
|
||||
|
||||
char pkey[512];
|
||||
static char value[4][512]; // use two buffers so compares
|
||||
|
||||
// work without stomping on each other
|
||||
static int valueindex;
|
||||
char *o;
|
||||
|
||||
valueindex = (valueindex + 1) % 4;
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
o = pkey;
|
||||
while (*s != '\\')
|
||||
{
|
||||
while (*s != '\\') {
|
||||
if (!*s)
|
||||
return "";
|
||||
*o++ = *s++;
|
||||
|
@ -79,15 +79,14 @@ char *Info_ValueForKey (char *s, char *key)
|
|||
|
||||
o = value[valueindex];
|
||||
|
||||
while (*s != '\\' && *s)
|
||||
{
|
||||
while (*s != '\\' && *s) {
|
||||
if (!*s)
|
||||
return "";
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
|
||||
if (!strcmp (key, pkey) )
|
||||
if (!strcmp (key, pkey))
|
||||
return value[valueindex];
|
||||
|
||||
if (!*s)
|
||||
|
@ -96,27 +95,25 @@ char *Info_ValueForKey (char *s, char *key)
|
|||
}
|
||||
}
|
||||
|
||||
void Info_RemoveKey (char *s, char *key)
|
||||
void
|
||||
Info_RemoveKey (char *s, char *key)
|
||||
{
|
||||
char *start;
|
||||
char pkey[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
char *start;
|
||||
char pkey[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
|
||||
if (strstr (key, "\\"))
|
||||
{
|
||||
if (strstr (key, "\\")) {
|
||||
Con_Printf ("Can't use a key with a \\\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
start = s;
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
o = pkey;
|
||||
while (*s != '\\')
|
||||
{
|
||||
while (*s != '\\') {
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
|
@ -125,17 +122,15 @@ void Info_RemoveKey (char *s, char *key)
|
|||
s++;
|
||||
|
||||
o = value;
|
||||
while (*s != '\\' && *s)
|
||||
{
|
||||
while (*s != '\\' && *s) {
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
|
||||
if (!strcmp (key, pkey) )
|
||||
{
|
||||
strcpy (start, s); // remove this part
|
||||
if (!strcmp (key, pkey)) {
|
||||
strcpy (start, s); // remove this part
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -145,22 +140,21 @@ void Info_RemoveKey (char *s, char *key)
|
|||
|
||||
}
|
||||
|
||||
void Info_RemovePrefixedKeys (char *start, char prefix)
|
||||
void
|
||||
Info_RemovePrefixedKeys (char *start, char prefix)
|
||||
{
|
||||
char *s;
|
||||
char pkey[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
char *s;
|
||||
char pkey[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
|
||||
s = start;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
o = pkey;
|
||||
while (*s != '\\')
|
||||
{
|
||||
while (*s != '\\') {
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
|
@ -169,16 +163,14 @@ void Info_RemovePrefixedKeys (char *start, char prefix)
|
|||
s++;
|
||||
|
||||
o = value;
|
||||
while (*s != '\\' && *s)
|
||||
{
|
||||
while (*s != '\\' && *s) {
|
||||
if (!*s)
|
||||
return;
|
||||
*o++ = *s++;
|
||||
}
|
||||
*o = 0;
|
||||
|
||||
if (pkey[0] == prefix)
|
||||
{
|
||||
if (pkey[0] == prefix) {
|
||||
Info_RemoveKey (start, pkey);
|
||||
s = start;
|
||||
}
|
||||
|
@ -190,58 +182,53 @@ void Info_RemovePrefixedKeys (char *start, char prefix)
|
|||
}
|
||||
|
||||
|
||||
void Info_SetValueForStarKey (char *s, char *key, char *value, size_t maxsize)
|
||||
void
|
||||
Info_SetValueForStarKey (char *s, char *key, char *value, size_t maxsize)
|
||||
{
|
||||
char newstr[1024], *v;
|
||||
int c, is_name, is_team;
|
||||
char newstr[1024], *v;
|
||||
int c, is_name, is_team;
|
||||
|
||||
if (strstr (key, "\\") || strstr (value, "\\") )
|
||||
{
|
||||
if (strstr (key, "\\") || strstr (value, "\\")) {
|
||||
Con_Printf ("Can't use keys or values with a \\\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strstr (key, "\"") || strstr (value, "\"") )
|
||||
{
|
||||
if (strstr (key, "\"") || strstr (value, "\"")) {
|
||||
Con_Printf ("Can't use keys or values with a \"\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen(key) > 63 || strlen(value) > 63)
|
||||
{
|
||||
if (strlen (key) > 63 || strlen (value) > 63) {
|
||||
Con_Printf ("Keys and values must be < 64 characters.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// this next line is kinda trippy
|
||||
if (*(v = Info_ValueForKey(s, key))) {
|
||||
// key exists, make sure we have enough room for new value, if we don't,
|
||||
if (*(v = Info_ValueForKey (s, key))) {
|
||||
// key exists, make sure we have enough room for new value, if we
|
||||
// don't,
|
||||
// don't change it!
|
||||
if (strlen(value) - strlen(v) + strlen(s) > maxsize) {
|
||||
if (strlen (value) - strlen (v) + strlen (s) > maxsize) {
|
||||
Con_Printf ("Info string length exceeded\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Info_RemoveKey (s, key);
|
||||
if (!value || !strlen(value))
|
||||
if (!value || !strlen (value))
|
||||
return;
|
||||
|
||||
snprintf (newstr, sizeof(newstr), "\\%s\\%s", key, value);
|
||||
snprintf (newstr, sizeof (newstr), "\\%s\\%s", key, value);
|
||||
|
||||
if ((int)(strlen(newstr) + strlen(s)) > maxsize)
|
||||
{
|
||||
if ((int) (strlen (newstr) + strlen (s)) > maxsize) {
|
||||
Con_Printf ("Info string length exceeded\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// only copy ascii values
|
||||
s += strlen(s);
|
||||
s += strlen (s);
|
||||
v = newstr;
|
||||
is_name = stricmp(key, "name") == 0;
|
||||
is_team = stricmp(key, "team") == 0;
|
||||
while (*v)
|
||||
{
|
||||
c = (unsigned char)*v++;
|
||||
is_name = stricmp (key, "name") == 0;
|
||||
is_team = stricmp (key, "team") == 0;
|
||||
while (*v) {
|
||||
c = (unsigned char) *v++;
|
||||
// client only allows highbits on name
|
||||
if (!is_name) {
|
||||
c &= 127;
|
||||
|
@ -249,7 +236,7 @@ void Info_SetValueForStarKey (char *s, char *key, char *value, size_t maxsize)
|
|||
continue;
|
||||
// auto lowercase team
|
||||
if (is_team)
|
||||
c = tolower(c);
|
||||
c = tolower (c);
|
||||
}
|
||||
if (c > 13)
|
||||
*s++ = c;
|
||||
|
@ -257,10 +244,10 @@ void Info_SetValueForStarKey (char *s, char *key, char *value, size_t maxsize)
|
|||
*s = 0;
|
||||
}
|
||||
|
||||
void Info_SetValueForKey (char *s, char *key, char *value, size_t maxsize)
|
||||
void
|
||||
Info_SetValueForKey (char *s, char *key, char *value, size_t maxsize)
|
||||
{
|
||||
if (key[0] == '*')
|
||||
{
|
||||
if (key[0] == '*') {
|
||||
Con_Printf ("Can't set * keys\n");
|
||||
return;
|
||||
}
|
||||
|
@ -268,33 +255,30 @@ void Info_SetValueForKey (char *s, char *key, char *value, size_t maxsize)
|
|||
Info_SetValueForStarKey (s, key, value, maxsize);
|
||||
}
|
||||
|
||||
void Info_Print (char *s)
|
||||
void
|
||||
Info_Print (char *s)
|
||||
{
|
||||
char key[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
int l;
|
||||
char key[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
int l;
|
||||
|
||||
if (*s == '\\')
|
||||
s++;
|
||||
while (*s)
|
||||
{
|
||||
while (*s) {
|
||||
o = key;
|
||||
while (*s && *s != '\\')
|
||||
*o++ = *s++;
|
||||
|
||||
l = o - key;
|
||||
if (l < 20)
|
||||
{
|
||||
memset (o, ' ', 20-l);
|
||||
if (l < 20) {
|
||||
memset (o, ' ', 20 - l);
|
||||
key[20] = 0;
|
||||
}
|
||||
else
|
||||
} else
|
||||
*o = 0;
|
||||
Con_Printf ("%s", key);
|
||||
|
||||
if (!*s)
|
||||
{
|
||||
if (!*s) {
|
||||
Con_Printf ("MISSING VALUE\n");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue