Simplify rhack and parse

AFAICT, we only used the first char of the "command_line" string.
Just turn it into int to hold the key the main input loop parse() got.

Shouldn't have any functional difference.
This commit is contained in:
Pasi Kallinen
2024-01-26 15:19:21 +02:00
parent 17414c500a
commit 39fb072a92
5 changed files with 24 additions and 43 deletions

View File

@@ -236,7 +236,7 @@ struct instance_globals_c {
coord clicklook_cc; coord clicklook_cc;
/* decl.c */ /* decl.c */
char chosen_windowtype[WINTYPELEN]; char chosen_windowtype[WINTYPELEN];
char command_line[COLNO]; int cmd_key; /* parse() / rhack() */
cmdcount_nht command_count; cmdcount_nht command_count;
/* some objects need special handling during destruction or placement */ /* some objects need special handling during destruction or placement */
struct obj *current_wand; /* wand currently zapped/applied */ struct obj *current_wand; /* wand currently zapped/applied */

View File

@@ -350,7 +350,7 @@ extern void parseautocomplete(char *, boolean);
extern void lock_mouse_buttons(boolean); extern void lock_mouse_buttons(boolean);
extern void reset_commands(boolean); extern void reset_commands(boolean);
extern void update_rest_on_space(void); extern void update_rest_on_space(void);
extern void rhack(char *); extern void rhack(int);
extern int doextlist(void); extern int doextlist(void);
extern int extcmd_via_menu(void); extern int extcmd_via_menu(void);
extern int enter_explore_mode(void); extern int enter_explore_mode(void);

View File

@@ -485,13 +485,13 @@ moveloop_core(void)
} else { } else {
--gm.multi; --gm.multi;
nhassert(gc.command_count != 0); nhassert(gc.command_count != 0);
rhack(gc.command_line); rhack(gc.cmd_key);
} }
} else if (gm.multi == 0) { } else if (gm.multi == 0) {
#ifdef MAIL #ifdef MAIL
ckmailstatus(); ckmailstatus();
#endif #endif
rhack((char *) 0); rhack(0);
} }
if (u.utotype) /* change dungeon level */ if (u.utotype) /* change dungeon level */
deferred_goto(); /* after rhack() */ deferred_goto(); /* after rhack() */

View File

@@ -167,7 +167,7 @@ static char there_cmd_menu(coordxy, coordxy, int);
static char here_cmd_menu(void); static char here_cmd_menu(void);
static char readchar_core(coordxy *, coordxy *, int *); static char readchar_core(coordxy *, coordxy *, int *);
static char *parse(void); static int parse(void);
static void show_direction_keys(winid, char, boolean); static void show_direction_keys(winid, char, boolean);
static boolean help_dir(char, uchar, const char *); static boolean help_dir(char, uchar, const char *);
static int QSORTCALLBACK migrsort_cmp(const genericptr, const genericptr); static int QSORTCALLBACK migrsort_cmp(const genericptr, const genericptr);
@@ -2513,7 +2513,7 @@ do_repeat(void)
} }
repeat_copy = cmdq_copy(CQ_REPEAT); repeat_copy = cmdq_copy(CQ_REPEAT);
gi.in_doagain = TRUE; gi.in_doagain = TRUE;
rhack((char *) 0); /* read and execute command */ rhack(0); /* read and execute command */
gi.in_doagain = FALSE; gi.in_doagain = FALSE;
cmdq_clear(CQ_REPEAT); cmdq_clear(CQ_REPEAT);
gc.command_queue[CQ_REPEAT] = repeat_copy; gc.command_queue[CQ_REPEAT] = repeat_copy;
@@ -4881,10 +4881,9 @@ reset_cmd_vars(boolean reset_cmdq)
} }
void void
rhack(char *cmd) rhack(int key)
{ {
char queuedkeystroke[2]; boolean bad_command, firsttime = (key == 0);
boolean bad_command, firsttime = (cmd == 0);
struct _cmd_queue cq, *cmdq = NULL; struct _cmd_queue cq, *cmdq = NULL;
const struct ext_func_tab *cmdq_ec = 0, *prefix_seen = 0; const struct ext_func_tab *cmdq_ec = 0, *prefix_seen = 0;
boolean was_m_prefix = FALSE; boolean was_m_prefix = FALSE;
@@ -4902,23 +4901,21 @@ rhack(char *cmd)
free(cmdq); free(cmdq);
if (cq.typ == CMDQ_EXTCMD && (cmdq_ec = cq.ec_entry) != 0) if (cq.typ == CMDQ_EXTCMD && (cmdq_ec = cq.ec_entry) != 0)
goto do_cmdq_extcmd; goto do_cmdq_extcmd;
cmd = queuedkeystroke;
/* already handled a queued command (goto do_cmdq_extcmd); /* already handled a queued command (goto do_cmdq_extcmd);
if something other than a key is queued, we'll drop down if something other than a key is queued, we'll drop down
to the !*cmd handling which clears out the command-queue */ to the !*cmd handling which clears out the command-queue */
cmd[0] = (cq.typ == CMDQ_KEY) ? cq.key : '\0'; key = (cq.typ == CMDQ_KEY) ? cq.key : 0;
cmd[1] = '\0';
} else if (firsttime) { } else if (firsttime) {
cmd = parse(); key = parse();
/* parse() pushed a cmd but didn't return any key */ /* parse() pushed a cmd but didn't return any key */
if (!*cmd && cmdq_peek(CQ_CANNED)) if (!key && cmdq_peek(CQ_CANNED))
goto got_prefix_input; goto got_prefix_input;
} }
/* if there's no command, there's nothing to do except reset */ /* if there's no command, there's nothing to do except reset */
if (!cmd || !*cmd || *cmd == (char) 0377 if (!key || key == (char) 0377
|| *cmd == gc.Cmd.spkeys[NHKF_ESC]) { || key == gc.Cmd.spkeys[NHKF_ESC]) {
if (!cmd || *cmd != gc.Cmd.spkeys[NHKF_ESC]) if (!key || key != gc.Cmd.spkeys[NHKF_ESC])
nhbell(); nhbell();
reset_cmd_vars(TRUE); reset_cmd_vars(TRUE);
return; return;
@@ -4934,9 +4931,9 @@ rhack(char *cmd)
if (cmdq_ec) if (cmdq_ec)
tlist = cmdq_ec; tlist = cmdq_ec;
else else
tlist = gc.Cmd.commands[*cmd & 0xff]; tlist = gc.Cmd.commands[key & 0xff];
/* current - use *cmd to directly index cmdlist array */ /* current - use key to directly index cmdlist array */
if (tlist != 0) { if (tlist != 0) {
if (!can_do_extcmd(tlist)) { if (!can_do_extcmd(tlist)) {
/* can_do_extcmd() already gave a message */ /* can_do_extcmd() already gave a message */
@@ -4961,9 +4958,9 @@ rhack(char *cmd)
pline("The %s command does not accept '%s' prefix.", pline("The %s command does not accept '%s' prefix.",
tlist->ef_txt, which); tlist->ef_txt, which);
} else { } else {
uchar key = tlist->key; uchar ch = tlist->key;
boolean up = (key == '<' || tlist->ef_funct == doup), boolean up = (ch == '<' || tlist->ef_funct == doup),
down = (key == '>' || tlist->ef_funct == dodown); down = (ch == '>' || tlist->ef_funct == dodown);
pline( pline(
"The '%s' prefix should be followed by a movement command%s.", "The '%s' prefix should be followed by a movement command%s.",
@@ -5078,22 +5075,7 @@ rhack(char *cmd)
} }
if (bad_command) { if (bad_command) {
char expcmd[20]; /* we expect 'cmd' to point to 1 or 2 chars */ Norep("Unknown command '%s'.", visctrl(key));
char c, c1 = cmd[1];
expcmd[0] = '\0';
while ((c = *cmd++) != '\0')
Strcat(expcmd, visctrl(c)); /* add 1..4 chars plus terminator */
#if 1
nhUse(c1);
#else
/* note: since prefix keys became actual commnads, we can no longer
get here with 'prefix_seen' set so this never calls help_dir()
anymore */
if (!prefix_seen
|| !help_dir(c1, prefix_seen->key, "Invalid direction key!"))
#endif
Norep("Unknown command '%s'.", expcmd);
cmdq_clear(CQ_CANNED); cmdq_clear(CQ_CANNED);
cmdq_clear(CQ_REPEAT); cmdq_clear(CQ_REPEAT);
} }
@@ -6323,7 +6305,7 @@ get_count(
} }
static char * static int
parse(void) parse(void)
{ {
register int foo; register int foo;
@@ -6364,12 +6346,11 @@ parse(void)
if (gm.multi) if (gm.multi)
gm.multi--; gm.multi--;
gc.command_line[0] = foo; gc.cmd_key = foo;
gc.command_line[1] = '\0';
clear_nhwindow(WIN_MESSAGE); clear_nhwindow(WIN_MESSAGE);
iflags.in_parse = FALSE; iflags.in_parse = FALSE;
return gc.command_line; return gc.cmd_key;
} }
#ifdef HANGUPHANDLING #ifdef HANGUPHANDLING

View File

@@ -269,7 +269,7 @@ const struct instance_globals_c g_init_c = {
{ 0, 0 }, /* clicklook_cc */ { 0, 0 }, /* clicklook_cc */
/* decl.c */ /* decl.c */
UNDEFINED_VALUES, /* chosen_windowtype */ UNDEFINED_VALUES, /* chosen_windowtype */
UNDEFINED_VALUES, /* command_line */ 0, /* cmd_key */
0L, /* command_count */ 0L, /* command_count */
UNDEFINED_PTR, /* current_wand */ UNDEFINED_PTR, /* current_wand */
#ifdef DEF_PAGER #ifdef DEF_PAGER