From 0023db327bc1db00068284b70e1db45857aeee35 Mon Sep 17 00:00:00 2001 From: Travis Bradshaw Date: Tue, 31 Jan 2012 14:32:09 -0600 Subject: The Quake sources as originally release under the GPL license on December 21, 1999 --- QW/qwfwd/misc.c | 452 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 452 insertions(+) create mode 100644 QW/qwfwd/misc.c (limited to 'QW/qwfwd/misc.c') diff --git a/QW/qwfwd/misc.c b/QW/qwfwd/misc.c new file mode 100644 index 0000000..0359a39 --- /dev/null +++ b/QW/qwfwd/misc.c @@ -0,0 +1,452 @@ +#include "master.h" + +int com_argc; +char **com_argv; + +/* +================ +COM_CheckParm + +Returns the position (1 to argc-1) in the program's argument list +where the given parameter apears, or 0 if not present +================ +*/ +int COM_CheckParm (char *parm) +{ + int i; + + for (i=1 ; i32); + + com_token[len] = 0; + return data; +} + +/* +============ +Cmd_Argc +============ +*/ +int Cmd_Argc (void) +{ + return cmd_argc; +} + +/* +============ +Cmd_Argv +============ +*/ +char *Cmd_Argv (int arg) +{ + if ( (unsigned)arg >= cmd_argc ) + return ""; + return cmd_argv[arg]; +} + +/* +============ +Cmd_TokenizeString + +Parses the given string into command line tokens. +============ +*/ +void Cmd_TokenizeString (char *text) +{ + cmd_argc = 0; + + while (1) + { +// skip whitespace up to a /n + while (*text && *text <= ' ') + { + text++; + } + + if (!*text) + return; + + text = COM_Parse (text); + if (!text) + return; + + if (cmd_argc < MAX_ARGS) + { + strcpy (cmd_argv[cmd_argc], com_token); + cmd_argc++; + } + } + +} + + +/* +===================================================================== + + INFO STRINGS + +===================================================================== +*/ + +/* +=============== +Info_ValueForKey + +Searches the string (userinfo or masterinfo) for the given +key and returns the associated value, or an empty string. +=============== +*/ +char *Info_ValueForKey (char *s, char *key) +{ + char pkey[512]; + static char value[512]; + char *o; + + if (*s == '\\') + s++; + while (1) + { + o = pkey; + while (*s != '\\') + { + if (!*s) + return ""; + *o++ = *s++; + } + *o = 0; + s++; + + o = value; + while (*s != '\\' && *s) + { + if (!*s) + return ""; + *o++ = *s++; + } + *o = 0; + + if (!strcmp (key, pkey) ) + return value; + + if (!*s) + return ""; + s++; + } +} + +void Info_RemoveKey (char *s, char *key) +{ + char *start; + char pkey[512]; + char value[512]; + char *o; + + if (strstr (key, "\\")) + { + printf ("Can't use a key with a \\\n"); + return; + } + + while (1) + { + start = s; + if (*s == '\\') + s++; + o = pkey; + while (*s != '\\') + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + s++; + + o = value; + while (*s != '\\' && *s) + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + + if (!strcmp (key, pkey) ) + { + strcpy (start, s); // remove this part + return; + } + + if (!*s) + return; + } + +} + +void Info_RemovePrefixedKeys (char *start, char prefix) +{ + char *s; + char pkey[512]; + char value[512]; + char *o; + + s = start; + while (1) + { + if (*s == '\\') + s++; + o = pkey; + while (*s != '\\') + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + s++; + + o = value; + while (*s != '\\' && *s) + { + if (!*s) + return; + *o++ = *s++; + } + *o = 0; + + if (pkey[0] == prefix) + { + Info_RemoveKey (start, pkey); + s = start; + } + + if (!*s) + return; + } + +} + +void Info_SetValueForKey (char *s, char *key, char *value) +{ + char new[512]; + + if (strstr (key, "\\") || strstr (value, "\\") ) + { + printf ("Can't use keys or values with a \\\n"); + return; + } + if (strstr (key, "\"") || strstr (value, "\"") ) + { + printf ("Can't use keys or values with a \\\n"); + return; + } + + Info_RemoveKey (s, key); + if (!value || !strlen(value)) + return; + + sprintf (new, "\\%s\\%s", key, value); + + if (strlen(new) + strlen(s) > MAX_INFO_STRING) + { + printf ("Info string length exceeded\n"); + return; + } + strcat (s, new); +} + +void Info_Print (char *s) +{ + char key[512]; + char value[512]; + char *o; + int l; + + if (*s == '\\') + s++; + while (*s) + { + o = key; + while (*s && *s != '\\') + *o++ = *s++; + + l = o - key; + if (l < 20) + { + memset (o, ' ', 20-l); + key[20] = 0; + } + else + *o = 0; + printf ("%s", key); + + if (!*s) + { + printf ("MISSING VALUE\n"); + return; + } + + o = value; + s++; + while (*s && *s != '\\') + *o++ = *s++; + *o = 0; + + if (*s) + s++; + printf ("%s\n", value); + } +} -- cgit v1.2.3