From: havoc Date: Fri, 6 Feb 2004 05:20:02 +0000 (+0000) Subject: rewrote PF_tokenize to not use memory allocations X-Git-Tag: xonotic-v0.1.0preview~6116 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d6a0f8b7536a7fd372fcd6cdb56b268d7bfb7785;p=xonotic%2Fdarkplaces.git rewrote PF_tokenize to not use memory allocations git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3872 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/pr_cmds.c b/pr_cmds.c index 7eaa915f..3a0c9d0f 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -2969,30 +2969,26 @@ void PF_clientcommand (void) //float(string s) tokenize = #441; // takes apart a string into individal words (access them with argv), returns how many //this function originally written by KrimZon, made shorter by LordHavoc -char **tokens = NULL; -int max_tokens, num_tokens = 0; +//20040203: rewritten by LordHavoc (no longer uses allocations) +int num_tokens = 0; +char *tokens[256], tokenbuf[4096]; void PF_tokenize (void) { + int pos; const char *p; - char *str; - str = G_STRING(OFS_PARM0); + p = G_STRING(OFS_PARM0); - if (tokens != NULL) + num_tokens = 0; + pos = 0; + while(COM_ParseToken(&p, false)) { - int i; - for (i=0;i= (int)(sizeof(tokens)/sizeof(tokens[0]))) + break; + if (pos + strlen(com_token) + 1 > sizeof(tokenbuf)) + break; + tokens[num_tokens++] = tokenbuf + pos; + strcpy(tokenbuf + pos, com_token); + pos += strlen(com_token) + 1; } G_FLOAT(OFS_RETURN) = num_tokens;