Skip to content

Commit

Permalink
From 0e42cdd9f0c62a345744c627482210fed76dd740 Mon Sep 17 00:00:00 2001
Browse files Browse the repository at this point in the history
From: Andrey Nazarov <[email protected]>
Date: Sat, 17 Nov 2018 17:22:33 +0300
Subject: [PATCH 287/396] Misc fixes to cmd code.
  • Loading branch information
Paril committed Dec 10, 2021
1 parent 4941a20 commit 37dff95
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions inc/common/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ char *Cmd_Args(void);
char *Cmd_RawArgs(void);
char *Cmd_ArgsFrom(int from);
char *Cmd_RawArgsFrom(int from);
char *Cmd_ArgsRange(int from, int to);
size_t Cmd_ArgsBuffer(char *buffer, size_t size);
size_t Cmd_ArgvBuffer(int arg, char *buffer, size_t size);
int Cmd_ArgOffset(int arg);
Expand Down
2 changes: 2 additions & 0 deletions src/client/ui/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ static menuSound_t Activate(menuCommon_t *self)
case MTYPE_ACTION:
if (strcmp(((menuAction_t *)self)->cmd, "_ignore")) {
Cbuf_AddText(&cmd_buffer, ((menuAction_t *)self)->cmd);
Cbuf_AddText(&cmd_buffer, "\n");
}
break;
case MTYPE_BITMAP:
Cbuf_AddText(&cmd_buffer, ((menuBitmap_t *)self)->cmd);
Cbuf_AddText(&cmd_buffer, "\n");
break;
case MTYPE_SAVEGAME:
Cbuf_AddText(&cmd_buffer, va("save \"%s\"; forcemenuoff\n", ((menuAction_t *)self)->cmd));
Expand Down
20 changes: 10 additions & 10 deletions src/common/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define Cmd_Malloc(size) Z_TagMalloc(size, TAG_CMD)
#define Cmd_CopyString(string) Z_TagCopyString(string, TAG_CMD)

static char *Cmd_ArgsRange(int from, int to);

/*
=============================================================================
Expand Down Expand Up @@ -928,7 +926,7 @@ char *Cmd_ArgsFrom(int from)
return Cmd_ArgsRange(from, cmd_argc - 1);
}

static char *Cmd_ArgsRange(int from, int to)
char *Cmd_ArgsRange(int from, int to)
{
int i;

Expand Down Expand Up @@ -1345,7 +1343,8 @@ void Cmd_TokenizeString(const char *text, bool macroExpand)
}

// copy off text
memcpy(cmd_string, text, len);
// use memmove because text may overlap with cmd_string
memmove(cmd_string, text, len);
cmd_string[len] = 0;
cmd_string_len = len;

Expand Down Expand Up @@ -1540,6 +1539,13 @@ void Cmd_ExecuteCommand(cmdbuf_t *buf)
cvar_t *v;
char *text;

// execute the command line
if (!cmd_argc) {
return; // no tokens
}

cmd_current = buf;

// check functions
cmd = Cmd_Find(cmd_argv[0]);
if (cmd) {
Expand Down Expand Up @@ -1589,12 +1595,6 @@ A complete command line has been parsed, so try to execute it
void Cmd_ExecuteString(cmdbuf_t *buf, const char *text)
{
Cmd_TokenizeString(text, true);

// execute the command line
if (!cmd_argc) {
return; // no tokens
}

Cmd_ExecuteCommand(buf);
}

Expand Down
8 changes: 3 additions & 5 deletions src/server/mvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ static char dummy_buffer_text[MAX_STRING_CHARS];
static void dummy_wait_f(void)
{
int count = atoi(Cmd_Argv(1));

if (count < 1) {
count = 1;
}
dummy_buffer.waitCount = count;
dummy_buffer.waitCount += max(count, 1);
}

static void dummy_command(void)
Expand Down Expand Up @@ -303,6 +299,7 @@ static void dummy_spawn(void)

if (sv_mvd_begincmd->string[0]) {
Cbuf_AddText(&dummy_buffer, sv_mvd_begincmd->string);
Cbuf_AddText(&dummy_buffer, "\n");
}

mvd.layout_time = svs.realtime;
Expand Down Expand Up @@ -443,6 +440,7 @@ static void dummy_run(void)
if (mvd.active && sv_mvd_scorecmd->string[0]) {
if (svs.realtime - mvd.layout_time > 9000) {
Cbuf_AddText(&dummy_buffer, sv_mvd_scorecmd->string);
Cbuf_AddText(&dummy_buffer, "\n");
mvd.layout_time = svs.realtime;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/unix/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static void tty_parse_input(const char *text)
}
Sys_Printf("]%s\n", s);
Cbuf_AddText(&cmd_buffer, s);
Cbuf_AddText(&cmd_buffer, "\n");
} else {
tty_stdout_write("]\n", 2);
}
Expand Down

0 comments on commit 37dff95

Please sign in to comment.