libbb/lineedit: fix the case when we configured history to have 0 lines
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e74aaf9385
commit
db9c57eed1
@ -1095,15 +1095,15 @@ static void save_command_ps_at_cur_history(void)
|
|||||||
int cur = state->cur_history;
|
int cur = state->cur_history;
|
||||||
free(state->history[cur]);
|
free(state->history[cur]);
|
||||||
|
|
||||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
# if ENABLE_FEATURE_ASSUME_UNICODE
|
||||||
{
|
{
|
||||||
char tbuf[MAX_LINELEN];
|
char tbuf[MAX_LINELEN];
|
||||||
save_string(tbuf, sizeof(tbuf));
|
save_string(tbuf, sizeof(tbuf));
|
||||||
state->history[cur] = xstrdup(tbuf);
|
state->history[cur] = xstrdup(tbuf);
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
state->history[cur] = xstrdup(command_ps);
|
state->history[cur] = xstrdup(command_ps);
|
||||||
#endif
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1131,7 +1131,7 @@ static int get_next_history(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
|
# if ENABLE_FEATURE_EDITING_SAVEHISTORY
|
||||||
/* We try to ensure that concurrent additions to the history
|
/* We try to ensure that concurrent additions to the history
|
||||||
* do not overwrite each other.
|
* do not overwrite each other.
|
||||||
* Otherwise shell users get unhappy.
|
* Otherwise shell users get unhappy.
|
||||||
@ -1256,10 +1256,10 @@ static void save_history(char *str)
|
|||||||
free_line_input_t(st_temp);
|
free_line_input_t(st_temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
# else
|
||||||
#define load_history(a) ((void)0)
|
# define load_history(a) ((void)0)
|
||||||
#define save_history(a) ((void)0)
|
# define save_history(a) ((void)0)
|
||||||
#endif /* FEATURE_COMMAND_SAVEHISTORY */
|
# endif /* FEATURE_COMMAND_SAVEHISTORY */
|
||||||
|
|
||||||
static void remember_in_history(char *str)
|
static void remember_in_history(char *str)
|
||||||
{
|
{
|
||||||
@ -1290,15 +1290,15 @@ static void remember_in_history(char *str)
|
|||||||
/* i <= MAX_HISTORY */
|
/* i <= MAX_HISTORY */
|
||||||
state->cur_history = i;
|
state->cur_history = i;
|
||||||
state->cnt_history = i;
|
state->cnt_history = i;
|
||||||
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
|
# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
|
||||||
if ((state->flags & SAVE_HISTORY) && state->hist_file)
|
if ((state->flags & SAVE_HISTORY) && state->hist_file)
|
||||||
save_history(str);
|
save_history(str);
|
||||||
#endif
|
# endif
|
||||||
IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
|
IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* MAX_HISTORY == 0 */
|
#else /* MAX_HISTORY == 0 */
|
||||||
#define remember_in_history(a) ((void)0)
|
# define remember_in_history(a) ((void)0)
|
||||||
#endif /* MAX_HISTORY */
|
#endif /* MAX_HISTORY */
|
||||||
|
|
||||||
|
|
||||||
@ -1476,11 +1476,11 @@ static void parse_and_put_prompt(const char *prmt_ptr)
|
|||||||
c = *prmt_ptr++;
|
c = *prmt_ptr++;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||||
case 'u':
|
case 'u':
|
||||||
pbuf = user_buf ? user_buf : (char*)"";
|
pbuf = user_buf ? user_buf : (char*)"";
|
||||||
break;
|
break;
|
||||||
#endif
|
# endif
|
||||||
case 'h':
|
case 'h':
|
||||||
pbuf = free_me = safe_gethostname();
|
pbuf = free_me = safe_gethostname();
|
||||||
*strchrnul(pbuf, '.') = '\0';
|
*strchrnul(pbuf, '.') = '\0';
|
||||||
@ -1488,7 +1488,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
|
|||||||
case '$':
|
case '$':
|
||||||
c = (geteuid() == 0 ? '#' : '$');
|
c = (geteuid() == 0 ? '#' : '$');
|
||||||
break;
|
break;
|
||||||
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
|
||||||
case 'w':
|
case 'w':
|
||||||
/* /home/user[/something] -> ~[/something] */
|
/* /home/user[/something] -> ~[/something] */
|
||||||
pbuf = cwd_buf;
|
pbuf = cwd_buf;
|
||||||
@ -1501,7 +1501,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
|
|||||||
pbuf = free_me = xasprintf("~%s", cwd_buf + l);
|
pbuf = free_me = xasprintf("~%s", cwd_buf + l);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
# endif
|
||||||
case 'W':
|
case 'W':
|
||||||
pbuf = cwd_buf;
|
pbuf = cwd_buf;
|
||||||
cp = strrchr(pbuf, '/');
|
cp = strrchr(pbuf, '/');
|
||||||
@ -1688,13 +1688,15 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
|||||||
|
|
||||||
/* With null flags, no other fields are ever used */
|
/* With null flags, no other fields are ever used */
|
||||||
state = st ? st : (line_input_t*) &const_int_0;
|
state = st ? st : (line_input_t*) &const_int_0;
|
||||||
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
|
#if MAX_HISTORY > 0
|
||||||
|
# if ENABLE_FEATURE_EDITING_SAVEHISTORY
|
||||||
if ((state->flags & SAVE_HISTORY) && state->hist_file)
|
if ((state->flags & SAVE_HISTORY) && state->hist_file)
|
||||||
if (state->cnt_history == 0)
|
if (state->cnt_history == 0)
|
||||||
load_history(state);
|
load_history(state);
|
||||||
#endif
|
# endif
|
||||||
if (state->flags & DO_HISTORY)
|
if (state->flags & DO_HISTORY)
|
||||||
state->cur_history = state->cnt_history;
|
state->cur_history = state->cnt_history;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* prepare before init handlers */
|
/* prepare before init handlers */
|
||||||
cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */
|
cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */
|
||||||
@ -1716,7 +1718,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
|
|||||||
new_settings.c_cc[VTIME] = 0;
|
new_settings.c_cc[VTIME] = 0;
|
||||||
/* Turn off CTRL-C, so we can trap it */
|
/* Turn off CTRL-C, so we can trap it */
|
||||||
#ifndef _POSIX_VDISABLE
|
#ifndef _POSIX_VDISABLE
|
||||||
#define _POSIX_VDISABLE '\0'
|
# define _POSIX_VDISABLE '\0'
|
||||||
#endif
|
#endif
|
||||||
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
|
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
|
||||||
tcsetattr_stdin_TCSANOW(&new_settings);
|
tcsetattr_stdin_TCSANOW(&new_settings);
|
||||||
|
@ -13317,7 +13317,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sflag || minusc == NULL) {
|
if (sflag || minusc == NULL) {
|
||||||
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
|
#if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
|
||||||
if (iflag) {
|
if (iflag) {
|
||||||
const char *hp = lookupvar("HISTFILE");
|
const char *hp = lookupvar("HISTFILE");
|
||||||
if (hp)
|
if (hp)
|
||||||
|
Loading…
Reference in New Issue
Block a user