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:
@@ -236,7 +236,7 @@ struct instance_globals_c {
|
||||
coord clicklook_cc;
|
||||
/* decl.c */
|
||||
char chosen_windowtype[WINTYPELEN];
|
||||
char command_line[COLNO];
|
||||
int cmd_key; /* parse() / rhack() */
|
||||
cmdcount_nht command_count;
|
||||
/* some objects need special handling during destruction or placement */
|
||||
struct obj *current_wand; /* wand currently zapped/applied */
|
||||
|
||||
@@ -350,7 +350,7 @@ extern void parseautocomplete(char *, boolean);
|
||||
extern void lock_mouse_buttons(boolean);
|
||||
extern void reset_commands(boolean);
|
||||
extern void update_rest_on_space(void);
|
||||
extern void rhack(char *);
|
||||
extern void rhack(int);
|
||||
extern int doextlist(void);
|
||||
extern int extcmd_via_menu(void);
|
||||
extern int enter_explore_mode(void);
|
||||
|
||||
@@ -485,13 +485,13 @@ moveloop_core(void)
|
||||
} else {
|
||||
--gm.multi;
|
||||
nhassert(gc.command_count != 0);
|
||||
rhack(gc.command_line);
|
||||
rhack(gc.cmd_key);
|
||||
}
|
||||
} else if (gm.multi == 0) {
|
||||
#ifdef MAIL
|
||||
ckmailstatus();
|
||||
#endif
|
||||
rhack((char *) 0);
|
||||
rhack(0);
|
||||
}
|
||||
if (u.utotype) /* change dungeon level */
|
||||
deferred_goto(); /* after rhack() */
|
||||
|
||||
57
src/cmd.c
57
src/cmd.c
@@ -167,7 +167,7 @@ static char there_cmd_menu(coordxy, coordxy, int);
|
||||
static char here_cmd_menu(void);
|
||||
|
||||
static char readchar_core(coordxy *, coordxy *, int *);
|
||||
static char *parse(void);
|
||||
static int parse(void);
|
||||
static void show_direction_keys(winid, char, boolean);
|
||||
static boolean help_dir(char, uchar, const char *);
|
||||
static int QSORTCALLBACK migrsort_cmp(const genericptr, const genericptr);
|
||||
@@ -2513,7 +2513,7 @@ do_repeat(void)
|
||||
}
|
||||
repeat_copy = cmdq_copy(CQ_REPEAT);
|
||||
gi.in_doagain = TRUE;
|
||||
rhack((char *) 0); /* read and execute command */
|
||||
rhack(0); /* read and execute command */
|
||||
gi.in_doagain = FALSE;
|
||||
cmdq_clear(CQ_REPEAT);
|
||||
gc.command_queue[CQ_REPEAT] = repeat_copy;
|
||||
@@ -4881,10 +4881,9 @@ reset_cmd_vars(boolean reset_cmdq)
|
||||
}
|
||||
|
||||
void
|
||||
rhack(char *cmd)
|
||||
rhack(int key)
|
||||
{
|
||||
char queuedkeystroke[2];
|
||||
boolean bad_command, firsttime = (cmd == 0);
|
||||
boolean bad_command, firsttime = (key == 0);
|
||||
struct _cmd_queue cq, *cmdq = NULL;
|
||||
const struct ext_func_tab *cmdq_ec = 0, *prefix_seen = 0;
|
||||
boolean was_m_prefix = FALSE;
|
||||
@@ -4902,23 +4901,21 @@ rhack(char *cmd)
|
||||
free(cmdq);
|
||||
if (cq.typ == CMDQ_EXTCMD && (cmdq_ec = cq.ec_entry) != 0)
|
||||
goto do_cmdq_extcmd;
|
||||
cmd = queuedkeystroke;
|
||||
/* already handled a queued command (goto do_cmdq_extcmd);
|
||||
if something other than a key is queued, we'll drop down
|
||||
to the !*cmd handling which clears out the command-queue */
|
||||
cmd[0] = (cq.typ == CMDQ_KEY) ? cq.key : '\0';
|
||||
cmd[1] = '\0';
|
||||
key = (cq.typ == CMDQ_KEY) ? cq.key : 0;
|
||||
} else if (firsttime) {
|
||||
cmd = parse();
|
||||
key = parse();
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* if there's no command, there's nothing to do except reset */
|
||||
if (!cmd || !*cmd || *cmd == (char) 0377
|
||||
|| *cmd == gc.Cmd.spkeys[NHKF_ESC]) {
|
||||
if (!cmd || *cmd != gc.Cmd.spkeys[NHKF_ESC])
|
||||
if (!key || key == (char) 0377
|
||||
|| key == gc.Cmd.spkeys[NHKF_ESC]) {
|
||||
if (!key || key != gc.Cmd.spkeys[NHKF_ESC])
|
||||
nhbell();
|
||||
reset_cmd_vars(TRUE);
|
||||
return;
|
||||
@@ -4934,9 +4931,9 @@ rhack(char *cmd)
|
||||
if (cmdq_ec)
|
||||
tlist = cmdq_ec;
|
||||
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 (!can_do_extcmd(tlist)) {
|
||||
/* can_do_extcmd() already gave a message */
|
||||
@@ -4961,9 +4958,9 @@ rhack(char *cmd)
|
||||
pline("The %s command does not accept '%s' prefix.",
|
||||
tlist->ef_txt, which);
|
||||
} else {
|
||||
uchar key = tlist->key;
|
||||
boolean up = (key == '<' || tlist->ef_funct == doup),
|
||||
down = (key == '>' || tlist->ef_funct == dodown);
|
||||
uchar ch = tlist->key;
|
||||
boolean up = (ch == '<' || tlist->ef_funct == doup),
|
||||
down = (ch == '>' || tlist->ef_funct == dodown);
|
||||
|
||||
pline(
|
||||
"The '%s' prefix should be followed by a movement command%s.",
|
||||
@@ -5078,22 +5075,7 @@ rhack(char *cmd)
|
||||
}
|
||||
|
||||
if (bad_command) {
|
||||
char expcmd[20]; /* we expect 'cmd' to point to 1 or 2 chars */
|
||||
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);
|
||||
Norep("Unknown command '%s'.", visctrl(key));
|
||||
cmdq_clear(CQ_CANNED);
|
||||
cmdq_clear(CQ_REPEAT);
|
||||
}
|
||||
@@ -6323,7 +6305,7 @@ get_count(
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
static int
|
||||
parse(void)
|
||||
{
|
||||
register int foo;
|
||||
@@ -6364,12 +6346,11 @@ parse(void)
|
||||
if (gm.multi)
|
||||
gm.multi--;
|
||||
|
||||
gc.command_line[0] = foo;
|
||||
gc.command_line[1] = '\0';
|
||||
gc.cmd_key = foo;
|
||||
clear_nhwindow(WIN_MESSAGE);
|
||||
|
||||
iflags.in_parse = FALSE;
|
||||
return gc.command_line;
|
||||
return gc.cmd_key;
|
||||
}
|
||||
|
||||
#ifdef HANGUPHANDLING
|
||||
|
||||
@@ -269,7 +269,7 @@ const struct instance_globals_c g_init_c = {
|
||||
{ 0, 0 }, /* clicklook_cc */
|
||||
/* decl.c */
|
||||
UNDEFINED_VALUES, /* chosen_windowtype */
|
||||
UNDEFINED_VALUES, /* command_line */
|
||||
0, /* cmd_key */
|
||||
0L, /* command_count */
|
||||
UNDEFINED_PTR, /* current_wand */
|
||||
#ifdef DEF_PAGER
|
||||
|
||||
Reference in New Issue
Block a user