+ else if (!strcmp(com_token, "sv.bufstr"))
+ {
+ COM_ParseToken_Simple(&t, false, false, true);
+ i = atoi(com_token);
+ COM_ParseToken_Simple(&t, false, false, true);
+ k = atoi(com_token);
+ COM_ParseToken_Simple(&t, false, false, true);
+ stringbuffer = (prvm_stringbuffer_t*) Mem_ExpandableArray_RecordAtIndex(&prog->stringbuffersarray, i);
+ // VorteX: nasty code, cleanup required
+ // create buffer at this index
+ if(!stringbuffer)
+ stringbuffer = (prvm_stringbuffer_t *) Mem_ExpandableArray_AllocRecordAtIndex(&prog->stringbuffersarray, i);
+ if (!stringbuffer)
+ Con_Printf("cant write string %i into buffer %i\n", k, i);
+ else
+ {
+ // code copied from VM_bufstr_set
+ // expand buffer
+ if (stringbuffer->max_strings <= i)
+ {
+ char **oldstrings = stringbuffer->strings;
+ stringbuffer->max_strings = max(stringbuffer->max_strings * 2, 128);
+ while (stringbuffer->max_strings <= i)
+ stringbuffer->max_strings *= 2;
+ stringbuffer->strings = (char **) Mem_Alloc(prog->progs_mempool, stringbuffer->max_strings * sizeof(stringbuffer->strings[0]));
+ if (stringbuffer->num_strings > 0)
+ memcpy(stringbuffer->strings, oldstrings, stringbuffer->num_strings * sizeof(stringbuffer->strings[0]));
+ if (oldstrings)
+ Mem_Free(oldstrings);
+ }
+ // allocate string
+ stringbuffer->num_strings = max(stringbuffer->num_strings, k + 1);
+ if(stringbuffer->strings[k])
+ Mem_Free(stringbuffer->strings[k]);
+ stringbuffer->strings[k] = NULL;
+ alloclen = strlen(com_token) + 1;
+ stringbuffer->strings[k] = (char *)Mem_Alloc(prog->progs_mempool, alloclen);
+ memcpy(stringbuffer->strings[k], com_token, alloclen);
+ }
+ }