Fix /HISTORY *pattern* and /HISTORY -CLEAR

This code contained a bug where any argument to /HISTORY that _didn't_ start with "-CL" would clear history,
so no number or pattern argument could successfully be passed.

With this fix only an argument that case-insensitively matches "-clear" will clear history, so a pattern
argument will also work correctly.
This commit is contained in:
Kevin Easton
2018-11-05 23:25:01 +11:00
parent a3e8364bc9
commit d897a3b753
2 changed files with 13 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2.2] [Changes 1.2.2]
* Fix /HISTORY *pattern* and /HISTORY -CLEAR. (caf)
* Fix /SET TAB OFF. (caf) * Fix /SET TAB OFF. (caf)
* Count columns used by ND_SPACE character when splitting lines. (caf) * Count columns used by ND_SPACE character when splitting lines. (caf)

View File

@@ -269,17 +269,16 @@ char *get_from_history(int which)
/* history: the /HISTORY command, shows the command history buffer. */ /* history: the /HISTORY command, shows the command history buffer. */
BUILT_IN_COMMAND(history) BUILT_IN_COMMAND(history)
{ {
int cnt, int cnt;
max = 0; int max = get_int_var(HISTORY_VAR);
char *value; char *value;
char *match = NULL; char *match = NULL;
if (get_int_var(HISTORY_VAR)) if (max)
{ {
say("Command History:");
if ((value = next_arg(args, &args)) != NULL) if ((value = next_arg(args, &args)) != NULL)
{ {
if (my_strnicmp(value, "-CLEAR", 3)) if (!my_stricmp(value, "-CLEAR"))
{ {
for (tmp = command_history_head; command_history_head; tmp = command_history_head) for (tmp = command_history_head; command_history_head; tmp = command_history_head)
{ {
@@ -295,15 +294,15 @@ BUILT_IN_COMMAND(history)
} }
if (isdigit((unsigned char)*value)) if (isdigit((unsigned char)*value))
{ {
max = my_atol(value); int limit = my_atol(value);
if (max > get_int_var(HISTORY_VAR)) if (limit < max)
max = get_int_var(HISTORY_VAR); max = limit;
} }
else else
match = value; match = value;
} }
else
max = get_int_var(HISTORY_VAR); say("Command History:");
for (tmp = command_history_tail, cnt = 0; tmp && (match || (cnt < max)); for (tmp = command_history_tail, cnt = 0; tmp && (match || (cnt < max));
tmp = tmp->prev, cnt++) tmp = tmp->prev, cnt++)
{ {