mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-25 02:52:06 +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);
|
unsigned int pos);
|
||||||
void dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len);
|
void dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len);
|
||||||
void dstring_clear (dstring_t *dstr);
|
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
|
// String-specific functions
|
||||||
dstring_t *dstring_newstr (void);
|
dstring_t *dstring_newstr (void);
|
||||||
|
|
|
@ -1336,8 +1336,14 @@ Cmd_ProcessToken (cmd_token_t *token)
|
||||||
int
|
int
|
||||||
Cmd_Process (void)
|
Cmd_Process (void)
|
||||||
{
|
{
|
||||||
int arg, res, i;
|
int arg, res;
|
||||||
const char *str;
|
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++) {
|
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
||||||
if (cmd_activebuffer->argv[arg]->state == cmd_process) {
|
if (cmd_activebuffer->argv[arg]->state == cmd_process) {
|
||||||
|
@ -1347,26 +1353,22 @@ Cmd_Process (void)
|
||||||
cmd_activebuffer->argv[arg]->state = cmd_done;
|
cmd_activebuffer->argv[arg]->state = cmd_done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dstring_clearstr (cmd_activebuffer->line);
|
|
||||||
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
for (arg = 0; arg < cmd_activebuffer->argc; arg++) {
|
||||||
if (cmd_activebuffer->argv[arg]->state == cmd_done)
|
if (cmd_activebuffer->argv[arg]->state == cmd_original)
|
||||||
str = cmd_activebuffer->argv[arg]->processed->str;
|
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
|
else
|
||||||
str = cmd_activebuffer->argv[arg]->original->str;
|
quotes = 0;
|
||||||
for (i = 0; i < cmd_activebuffer->argv[arg]->space; i++)
|
cmd_activebuffer->args[arg] += adj;
|
||||||
dstring_appendstr (cmd_activebuffer->line, " ");
|
adj += (str->size - 1) - (org->size - 1);
|
||||||
cmd_activebuffer->args[arg] = strlen(cmd_activebuffer->line->str);
|
dstring_replace (cmd_activebuffer->line, str->str, str->size - 1,
|
||||||
if (cmd_activebuffer->argv[arg]->delim == '\'' ||
|
cmd_activebuffer->args[arg] + quotes, org->size - 1);
|
||||||
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, "}");
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1401,6 +1403,8 @@ Cmd_TokenizeString (const char *text, qboolean legacy)
|
||||||
i++;
|
i++;
|
||||||
space++;
|
space++;
|
||||||
}
|
}
|
||||||
|
if (space)
|
||||||
|
dstring_appendsubstr (cmd_activebuffer->line, str + i - space, space);
|
||||||
len = Cmd_GetToken (str + i, legacy);
|
len = Cmd_GetToken (str + i, legacy);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
Cmd_Error ("Parse error: Unmatched quotes, braces, or "
|
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 */
|
/* Remove surrounding quotes or double quotes or braces */
|
||||||
quotes = 0;
|
quotes = 0;
|
||||||
braces = 0;
|
braces = 0;
|
||||||
cmd_activebuffer->argv[cmd_argc-1]->delim = ' ';
|
cmd_activebuffer->args[cmd_argc - 1] = i;
|
||||||
if ((str[i] == '\'' && str[i + len] == '\'')
|
cmd_activebuffer->argv[cmd_argc - 1]->delim = ' ';
|
||||||
|
if ((!legacy && str[i] == '\'' && str[i + len] == '\'')
|
||||||
|| (str[i] == '"' && str[i + len] == '"')) {
|
|| (str[i] == '"' && str[i + len] == '"')) {
|
||||||
cmd_activebuffer->argv[cmd_argc-1]->delim = str[i];
|
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++;
|
i++;
|
||||||
len -= 1;
|
len -= 1;
|
||||||
quotes = 1;
|
quotes = 1;
|
||||||
}
|
}
|
||||||
|
dstring_appendsubstr (cmd_activebuffer->line,
|
||||||
|
str + i - quotes, len + quotes * 2);
|
||||||
if (str[i] == '{' && str[i + len] == '}') {
|
if (str[i] == '{' && str[i + len] == '}') {
|
||||||
i++;
|
i++;
|
||||||
len -= 1;
|
len -= 1;
|
||||||
|
|
|
@ -103,6 +103,24 @@ dstring_clear (dstring_t *dstr)
|
||||||
dstring_adjust (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_t *
|
||||||
dstring_newstr (void)
|
dstring_newstr (void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1044,7 +1044,7 @@ SV_ConnectionlessPacket (void)
|
||||||
s = MSG_ReadString (net_message);
|
s = MSG_ReadString (net_message);
|
||||||
|
|
||||||
Cmd_TokenizeString (s, true);
|
Cmd_TokenizeString (s, true);
|
||||||
Cmd_Process ();
|
//Cmd_Process ();
|
||||||
|
|
||||||
c = Cmd_Argv (0);
|
c = Cmd_Argv (0);
|
||||||
|
|
||||||
|
|
|
@ -1241,7 +1241,7 @@ SV_ExecuteUserCommand (const char *s)
|
||||||
ucmd_t cmd;
|
ucmd_t cmd;
|
||||||
|
|
||||||
Cmd_TokenizeString (s, true);
|
Cmd_TokenizeString (s, true);
|
||||||
Cmd_Process ();
|
//Cmd_Process ();
|
||||||
sv_player = host_client->edict;
|
sv_player = host_client->edict;
|
||||||
cmd.name = Cmd_Argv(0);
|
cmd.name = Cmd_Argv(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue