Unsetting CMDCHARS sets it back to the default

Previously you could unset CMDCHARS and the effect would be to treat it like it was set to DEFAULT_CMDCHARS,
except that some code was missing the fallback (eg. ignore_last_nick()) which would make it crash.

Instead of having the fallback everywhere, just make it so that you can't unset the variable - if you try, it
sets it to DEFAULT_CMDCHARS.  This reflects what the behaviour has always been, it just makes it explicit to
the user and the bonus is we don't have the test it for NULL everywhere.
This commit is contained in:
Kevin Easton
2017-02-16 23:42:52 +11:00
parent debfebf3a7
commit 686344314f
5 changed files with 44 additions and 54 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2.2]
* Unsetting CMDCHARS sets it back to the default. (caf)
* Fix a double-free bug when a window on an alternate screen queries an exec
process. (caf)

View File

@@ -4111,21 +4111,18 @@ void command_completion(char unused, char *not_used)
char *line = NULL,
*com,
*cmdchars,
*rest,
firstcmdchar[2] = "/";
const char *cmdchars = get_string_var(CMDCHARS_VAR);
const IrcCommand *command;
#ifdef WANT_DLL
IrcCommandDll *dll = NULL;
#endif
char buffer[BIG_BUFFER_SIZE];
malloc_strcpy(&line, get_input());
if ((com = next_arg(line, &rest)) != NULL)
{
if (!(cmdchars = get_string_var(CMDCHARS_VAR)))
cmdchars = DEFAULT_CMDCHARS;
if (*com == '/' || strchr(cmdchars, *com))
{
*firstcmdchar = *cmdchars;
@@ -4439,12 +4436,12 @@ void BX_parse_line (const char *name, char *org_line, const char *args, int hist
* characters or anything (beyond those specific for a given command being
* executed).
*/
int BX_parse_command(register char *line, int hist_flag, char *sub_args)
int BX_parse_command(char *line, int hist_flag, char *sub_args)
{
static unsigned int level = 0;
static unsigned int level = 0;
unsigned int display,
old_display_var;
char *cmdchars;
const char *cmdchars = get_string_var(CMDCHARS_VAR);
const char *com;
char *this_cmd = NULL;
int args_flag = 0,
@@ -4461,10 +4458,6 @@ static unsigned int level = 0;
debugyell("Executing [%d] %s", level, line);
level++;
if (!(cmdchars = get_string_var(CMDCHARS_VAR)))
cmdchars = DEFAULT_CMDCHARS;
this_cmd = LOCAL_COPY(line);
set_current_command(this_cmd);
add_to_hist = 1;

View File

@@ -1183,12 +1183,9 @@ static char *alias_target (void)
static char *alias_cmdchar (void)
{
char *cmdchars, tmp[2];
const char *cmdchars = get_string_var(CMDCHARS_VAR);
char tmp[2] = { cmdchars[0], 0 };
if ((cmdchars = get_string_var(CMDCHARS_VAR)) == NULL)
cmdchars = DEFAULT_CMDCHARS;
tmp[0] = cmdchars[0];
tmp[1] = 0;
return m_strdup(tmp);
}

View File

@@ -983,14 +983,11 @@ BUILT_IN_KEYBINDING(toggle_insert_mode)
BUILT_IN_KEYBINDING(input_msgreply)
{
char *cmdchar;
char *line, *cmd, *t;
char *snick;
NickTab *nick = NULL;
int got_space = 0;
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = DEFAULT_CMDCHARS;
const char *cmdchar = get_string_var(CMDCHARS_VAR);
char *line, *cmd, *t;
char *snick;
NickTab *nick = NULL;
int got_space = 0;
t = line = m_strdup(get_input());
if (t)
@@ -1172,14 +1169,10 @@ BUILT_IN_KEYBINDING(send_line)
}
else
{
char *line,
*cmdchar,
*tmp = NULL;
const char *cmdchar = get_string_var(CMDCHARS_VAR);
char *line = get_input();
char *tmp = m_strdup(line);
line = get_input();
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = "/";
malloc_strcpy(&tmp, line);
if (line && (*line != *cmdchar) && get_int_var(NICK_COMPLETION_VAR) && !current_window->query_nick)
{
char auto_comp_char;
@@ -2523,16 +2516,16 @@ char buffer[BIG_BUFFER_SIZE+1];
BUILT_IN_KEYBINDING(tab_completion)
{
int count = 0,
int count = 0,
wcount = 0;
enum completion type = NO_COMPLETION;
char *inp = NULL;
char *possible = NULL, *old_pos = NULL;
char *cmdchar;
char *suggested = NULL;
int got_space = 0;
char *get = NULL;
Ext_Name_Type *extcomp = ext_completion;
enum completion type = NO_COMPLETION;
char *inp = NULL;
char *possible = NULL, *old_pos = NULL;
const char *cmdchar = get_string_var(CMDCHARS_VAR);
char *suggested = NULL;
int got_space = 0;
char *get = NULL;
Ext_Name_Type *extcomp = ext_completion;
/*
* is this the != second word, then just complete from the
@@ -2546,8 +2539,7 @@ Ext_Name_Type *extcomp = ext_completion;
if (*inp && inp[strlen(inp)-1] == ' ')
got_space = 1;
wcount = word_count(inp);
if (!(cmdchar = get_string_var(CMDCHARS_VAR)))
cmdchar = "/";
switch(wcount)
{
case 0:

View File

@@ -90,6 +90,7 @@ static void set_clock_format (Window *, char *, int);
static void set_dcc_timeout(Window *, char *, int);
void BX_set_scrollback_size (Window *, char *, int);
static void set_use_socks(Window *, char *, int);
static void set_cmdchars(Window *, char *, int);
static void set_mangle_inbound (Window *, char *, int);
static void set_mangle_outbound (Window *, char *, int);
@@ -166,7 +167,7 @@ static IrcVariable irc_variable[] =
{ "CLOCK_FORMAT",0, STR_TYPE_VAR, 0, NULL, set_clock_format, 0, 0 },
{ "CLONE_CHECK",0, INT_TYPE_VAR, 0, NULL, NULL, 0, 0 },
{ "CLONE_COUNT",0, INT_TYPE_VAR, 0, NULL, NULL, 0, 0 },
{ "CMDCHARS",0, STR_TYPE_VAR, 0, NULL, NULL, 0, 0 },
{ "CMDCHARS",0, STR_TYPE_VAR, 0, NULL, set_cmdchars, 0, 0 },
{ "COLOR",0, BOOL_TYPE_VAR, 1, NULL, NULL, 0, 0 },
{ "COMMAND_MODE",0, BOOL_TYPE_VAR, DEFAULT_COMMAND_MODE, NULL, NULL, 0, 0 },
{ "COMMENT_BREAKAGE",0, BOOL_TYPE_VAR, 0, NULL, NULL, 0, 0 },
@@ -1561,6 +1562,11 @@ extern int use_socks;
use_socks = 0;
}
/* CMDCHARS cannot be unset - unsetting it just sets it back to the default. */
static void set_cmdchars(Window *win, char *value, int unused)
{
set_string_var(CMDCHARS_VAR, value ? value : DEFAULT_CMDCHARS);
}
int parse_mangle (char *value, int nvalue, char **rv)
{