mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
dstring.c dstring.h:
add dstring_replace. this replaces a string of lenth rlen at position pos with data of lenth len, growing, shrinking and shuffling data as appropriate. At this rate, the dstring `class' will get buffer gap editing capabilities :) cmd.c: Cmd_TokenizeString builds cmd_active_buffer->line again. Cmd_Process bails out instantly if cmd_active_buffer is a legacy buffer and uses dstring_replace to modify the parameters in cmd_active_buffer->line. This last change results in drastic simplification (and accuracy) of the commandline reconstruction code, both in Cmd_TokenizeString and Cmd_Process.
This commit is contained in:
parent
1ff8c715b9
commit
4ccc9d6322
5 changed files with 51 additions and 26 deletions
|
@ -48,6 +48,8 @@ void dstring_insert(dstring_t *dstr, const char *data, unsigned int len,
|
|||
unsigned int pos);
|
||||
void dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len);
|
||||
void dstring_clear (dstring_t *dstr);
|
||||
void dstring_replace (dstring_t *dstr, const char *data, unsigned int len,
|
||||
unsigned int pos, unsigned int rlen);
|
||||
|
||||
// String-specific functions
|
||||
dstring_t *dstring_newstr (void);
|
||||
|
|
|
@ -1336,9 +1336,15 @@ Cmd_ProcessToken (cmd_token_t *token)
|
|||
int
|
||||
Cmd_Process (void)
|
||||
{
|
||||
int arg, res, i;
|
||||
const char *str;
|
||||
int arg, res;
|
||||
dstring_t *str;
|
||||
dstring_t *org;
|
||||
int quotes;
|
||||
unsigned int adj = 0;
|
||||
|
||||
if (cmd_activebuffer->legacy)
|
||||
return 0;
|
||||
|
||||
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
||||
if (cmd_activebuffer->argv[arg]->state == cmd_process) {
|
||||
res = Cmd_ProcessToken (cmd_activebuffer->argv[arg]);
|
||||
|
@ -1347,26 +1353,22 @@ Cmd_Process (void)
|
|||
cmd_activebuffer->argv[arg]->state = cmd_done;
|
||||
}
|
||||
}
|
||||
dstring_clearstr (cmd_activebuffer->line);
|
||||
|
||||
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
||||
if (cmd_activebuffer->argv[arg]->state == cmd_done)
|
||||
str = cmd_activebuffer->argv[arg]->processed->str;
|
||||
if (cmd_activebuffer->argv[arg]->state == cmd_original)
|
||||
continue;
|
||||
|
||||
str = cmd_activebuffer->argv[arg]->processed;
|
||||
org = cmd_activebuffer->argv[arg]->original;
|
||||
if (cmd_activebuffer->argv[arg]->delim == '\'' ||
|
||||
cmd_activebuffer->argv[arg]->delim == '\"')
|
||||
quotes = 1;
|
||||
else
|
||||
str = cmd_activebuffer->argv[arg]->original->str;
|
||||
for (i = 0; i < cmd_activebuffer->argv[arg]->space; i++)
|
||||
dstring_appendstr (cmd_activebuffer->line, " ");
|
||||
cmd_activebuffer->args[arg] = strlen(cmd_activebuffer->line->str);
|
||||
if (cmd_activebuffer->argv[arg]->delim == '\'' ||
|
||||
cmd_activebuffer->argv[arg]->delim == '\"')
|
||||
dstring_appendstr (cmd_activebuffer->line, va("%c", cmd_activebuffer->argv[arg]->delim));
|
||||
if (cmd_activebuffer->argv[arg]->delim == '{')
|
||||
dstring_appendstr (cmd_activebuffer->line, "{");
|
||||
dstring_appendstr (cmd_activebuffer->line, str);
|
||||
if (cmd_activebuffer->argv[arg]->delim == '\'' ||
|
||||
cmd_activebuffer->argv[arg]->delim == '\"')
|
||||
dstring_appendstr (cmd_activebuffer->line, va("%c", cmd_activebuffer->argv[arg]->delim));
|
||||
if (cmd_activebuffer->argv[arg]->delim == '{')
|
||||
dstring_appendstr (cmd_activebuffer->line, "}");
|
||||
quotes = 0;
|
||||
cmd_activebuffer->args[arg] += adj;
|
||||
adj += (str->size - 1) - (org->size - 1);
|
||||
dstring_replace (cmd_activebuffer->line, str->str, str->size - 1,
|
||||
cmd_activebuffer->args[arg] + quotes, org->size - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1401,6 +1403,8 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
|||
i++;
|
||||
space++;
|
||||
}
|
||||
if (space)
|
||||
dstring_appendsubstr (cmd_activebuffer->line, str + i - space, space);
|
||||
len = Cmd_GetToken (str + i, legacy);
|
||||
if (len < 0) {
|
||||
Cmd_Error ("Parse error: Unmatched quotes, braces, or "
|
||||
|
@ -1427,16 +1431,17 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
|||
/* Remove surrounding quotes or double quotes or braces */
|
||||
quotes = 0;
|
||||
braces = 0;
|
||||
cmd_activebuffer->argv[cmd_argc-1]->delim = ' ';
|
||||
if ((str[i] == '\'' && str[i + len] == '\'')
|
||||
cmd_activebuffer->args[cmd_argc - 1] = i;
|
||||
cmd_activebuffer->argv[cmd_argc - 1]->delim = ' ';
|
||||
if ((!legacy && str[i] == '\'' && str[i + len] == '\'')
|
||||
|| (str[i] == '"' && str[i + len] == '"')) {
|
||||
cmd_activebuffer->argv[cmd_argc-1]->delim = str[i];
|
||||
dstring_appendsubstr (cmd_activebuffer->line, str + i, 1);
|
||||
dstring_appendsubstr (cmd_activebuffer->line, str + i, 1);
|
||||
i++;
|
||||
len -= 1;
|
||||
quotes = 1;
|
||||
}
|
||||
dstring_appendsubstr (cmd_activebuffer->line,
|
||||
str + i - quotes, len + quotes * 2);
|
||||
if (str[i] == '{' && str[i + len] == '}') {
|
||||
i++;
|
||||
len -= 1;
|
||||
|
|
|
@ -103,6 +103,24 @@ dstring_clear (dstring_t *dstr)
|
|||
dstring_adjust (dstr);
|
||||
}
|
||||
|
||||
void
|
||||
dstring_replace (dstring_t *dstr, const char *data, unsigned int len,
|
||||
unsigned int pos, unsigned int rlen)
|
||||
{
|
||||
if (rlen < len) {
|
||||
dstr->size += len - rlen;
|
||||
dstring_adjust (dstr);
|
||||
memmove (dstr->str + pos + len, dstr->str + pos + rlen,
|
||||
dstr->size - (pos + rlen));
|
||||
} else if (rlen > len) {
|
||||
memmove (dstr->str + pos + len, dstr->str + pos + rlen,
|
||||
dstr->size - (pos + rlen));
|
||||
dstr->size -= rlen - len;
|
||||
dstring_adjust (dstr);
|
||||
}
|
||||
memcpy (dstr->str + pos, data, len);
|
||||
}
|
||||
|
||||
dstring_t *
|
||||
dstring_newstr (void)
|
||||
{
|
||||
|
|
|
@ -1044,7 +1044,7 @@ SV_ConnectionlessPacket (void)
|
|||
s = MSG_ReadString (net_message);
|
||||
|
||||
Cmd_TokenizeString (s, true);
|
||||
Cmd_Process ();
|
||||
//Cmd_Process ();
|
||||
|
||||
c = Cmd_Argv (0);
|
||||
|
||||
|
|
|
@ -1241,7 +1241,7 @@ SV_ExecuteUserCommand (const char *s)
|
|||
ucmd_t cmd;
|
||||
|
||||
Cmd_TokenizeString (s, true);
|
||||
Cmd_Process ();
|
||||
//Cmd_Process ();
|
||||
sv_player = host_client->edict;
|
||||
cmd.name = Cmd_Argv(0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue