diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-27 02:48:53 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-27 02:48:53 +0200 |
| commit | db9c57eed1db2fd53bfd653efcf19210e5b14080 (patch) | |
| tree | 2ec2bccdd5186d8c27cf60fa659ca39ca7396ba8 /libbb | |
| parent | e74aaf93854b9453b9949954aec77710b257d8b6 (diff) | |
| download | busybox-w32-db9c57eed1db2fd53bfd653efcf19210e5b14080.tar.gz busybox-w32-db9c57eed1db2fd53bfd653efcf19210e5b14080.tar.bz2 busybox-w32-db9c57eed1db2fd53bfd653efcf19210e5b14080.zip | |
libbb/lineedit: fix the case when we configured history to have 0 lines
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/lineedit.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 38c69c602..3689b4b5d 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -1095,15 +1095,15 @@ static void save_command_ps_at_cur_history(void) | |||
| 1095 | int cur = state->cur_history; | 1095 | int cur = state->cur_history; |
| 1096 | free(state->history[cur]); | 1096 | free(state->history[cur]); |
| 1097 | 1097 | ||
| 1098 | #if ENABLE_FEATURE_ASSUME_UNICODE | 1098 | # if ENABLE_FEATURE_ASSUME_UNICODE |
| 1099 | { | 1099 | { |
| 1100 | char tbuf[MAX_LINELEN]; | 1100 | char tbuf[MAX_LINELEN]; |
| 1101 | save_string(tbuf, sizeof(tbuf)); | 1101 | save_string(tbuf, sizeof(tbuf)); |
| 1102 | state->history[cur] = xstrdup(tbuf); | 1102 | state->history[cur] = xstrdup(tbuf); |
| 1103 | } | 1103 | } |
| 1104 | #else | 1104 | # else |
| 1105 | state->history[cur] = xstrdup(command_ps); | 1105 | state->history[cur] = xstrdup(command_ps); |
| 1106 | #endif | 1106 | # endif |
| 1107 | } | 1107 | } |
| 1108 | } | 1108 | } |
| 1109 | 1109 | ||
| @@ -1131,7 +1131,7 @@ static int get_next_history(void) | |||
| 1131 | return 0; | 1131 | return 0; |
| 1132 | } | 1132 | } |
| 1133 | 1133 | ||
| 1134 | #if ENABLE_FEATURE_EDITING_SAVEHISTORY | 1134 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY |
| 1135 | /* We try to ensure that concurrent additions to the history | 1135 | /* We try to ensure that concurrent additions to the history |
| 1136 | * do not overwrite each other. | 1136 | * do not overwrite each other. |
| 1137 | * Otherwise shell users get unhappy. | 1137 | * Otherwise shell users get unhappy. |
| @@ -1256,10 +1256,10 @@ static void save_history(char *str) | |||
| 1256 | free_line_input_t(st_temp); | 1256 | free_line_input_t(st_temp); |
| 1257 | } | 1257 | } |
| 1258 | } | 1258 | } |
| 1259 | #else | 1259 | # else |
| 1260 | #define load_history(a) ((void)0) | 1260 | # define load_history(a) ((void)0) |
| 1261 | #define save_history(a) ((void)0) | 1261 | # define save_history(a) ((void)0) |
| 1262 | #endif /* FEATURE_COMMAND_SAVEHISTORY */ | 1262 | # endif /* FEATURE_COMMAND_SAVEHISTORY */ |
| 1263 | 1263 | ||
| 1264 | static void remember_in_history(char *str) | 1264 | static void remember_in_history(char *str) |
| 1265 | { | 1265 | { |
| @@ -1290,15 +1290,15 @@ static void remember_in_history(char *str) | |||
| 1290 | /* i <= MAX_HISTORY */ | 1290 | /* i <= MAX_HISTORY */ |
| 1291 | state->cur_history = i; | 1291 | state->cur_history = i; |
| 1292 | state->cnt_history = i; | 1292 | state->cnt_history = i; |
| 1293 | #if ENABLE_FEATURE_EDITING_SAVEHISTORY | 1293 | # if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY |
| 1294 | if ((state->flags & SAVE_HISTORY) && state->hist_file) | 1294 | if ((state->flags & SAVE_HISTORY) && state->hist_file) |
| 1295 | save_history(str); | 1295 | save_history(str); |
| 1296 | #endif | 1296 | # endif |
| 1297 | IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;) | 1297 | IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;) |
| 1298 | } | 1298 | } |
| 1299 | 1299 | ||
| 1300 | #else /* MAX_HISTORY == 0 */ | 1300 | #else /* MAX_HISTORY == 0 */ |
| 1301 | #define remember_in_history(a) ((void)0) | 1301 | # define remember_in_history(a) ((void)0) |
| 1302 | #endif /* MAX_HISTORY */ | 1302 | #endif /* MAX_HISTORY */ |
| 1303 | 1303 | ||
| 1304 | 1304 | ||
| @@ -1476,11 +1476,11 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
| 1476 | c = *prmt_ptr++; | 1476 | c = *prmt_ptr++; |
| 1477 | 1477 | ||
| 1478 | switch (c) { | 1478 | switch (c) { |
| 1479 | #if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR | 1479 | # if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR |
| 1480 | case 'u': | 1480 | case 'u': |
| 1481 | pbuf = user_buf ? user_buf : (char*)""; | 1481 | pbuf = user_buf ? user_buf : (char*)""; |
| 1482 | break; | 1482 | break; |
| 1483 | #endif | 1483 | # endif |
| 1484 | case 'h': | 1484 | case 'h': |
| 1485 | pbuf = free_me = safe_gethostname(); | 1485 | pbuf = free_me = safe_gethostname(); |
| 1486 | *strchrnul(pbuf, '.') = '\0'; | 1486 | *strchrnul(pbuf, '.') = '\0'; |
| @@ -1488,7 +1488,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
| 1488 | case '$': | 1488 | case '$': |
| 1489 | c = (geteuid() == 0 ? '#' : '$'); | 1489 | c = (geteuid() == 0 ? '#' : '$'); |
| 1490 | break; | 1490 | break; |
| 1491 | #if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR | 1491 | # if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR |
| 1492 | case 'w': | 1492 | case 'w': |
| 1493 | /* /home/user[/something] -> ~[/something] */ | 1493 | /* /home/user[/something] -> ~[/something] */ |
| 1494 | pbuf = cwd_buf; | 1494 | pbuf = cwd_buf; |
| @@ -1501,7 +1501,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
| 1501 | pbuf = free_me = xasprintf("~%s", cwd_buf + l); | 1501 | pbuf = free_me = xasprintf("~%s", cwd_buf + l); |
| 1502 | } | 1502 | } |
| 1503 | break; | 1503 | break; |
| 1504 | #endif | 1504 | # endif |
| 1505 | case 'W': | 1505 | case 'W': |
| 1506 | pbuf = cwd_buf; | 1506 | pbuf = cwd_buf; |
| 1507 | cp = strrchr(pbuf, '/'); | 1507 | cp = strrchr(pbuf, '/'); |
| @@ -1688,13 +1688,15 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li | |||
| 1688 | 1688 | ||
| 1689 | /* With null flags, no other fields are ever used */ | 1689 | /* With null flags, no other fields are ever used */ |
| 1690 | state = st ? st : (line_input_t*) &const_int_0; | 1690 | state = st ? st : (line_input_t*) &const_int_0; |
| 1691 | #if ENABLE_FEATURE_EDITING_SAVEHISTORY | 1691 | #if MAX_HISTORY > 0 |
| 1692 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY | ||
| 1692 | if ((state->flags & SAVE_HISTORY) && state->hist_file) | 1693 | if ((state->flags & SAVE_HISTORY) && state->hist_file) |
| 1693 | if (state->cnt_history == 0) | 1694 | if (state->cnt_history == 0) |
| 1694 | load_history(state); | 1695 | load_history(state); |
| 1695 | #endif | 1696 | # endif |
| 1696 | if (state->flags & DO_HISTORY) | 1697 | if (state->flags & DO_HISTORY) |
| 1697 | state->cur_history = state->cnt_history; | 1698 | state->cur_history = state->cnt_history; |
| 1699 | #endif | ||
| 1698 | 1700 | ||
| 1699 | /* prepare before init handlers */ | 1701 | /* prepare before init handlers */ |
| 1700 | cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */ | 1702 | 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 | |||
| 1716 | new_settings.c_cc[VTIME] = 0; | 1718 | new_settings.c_cc[VTIME] = 0; |
| 1717 | /* Turn off CTRL-C, so we can trap it */ | 1719 | /* Turn off CTRL-C, so we can trap it */ |
| 1718 | #ifndef _POSIX_VDISABLE | 1720 | #ifndef _POSIX_VDISABLE |
| 1719 | #define _POSIX_VDISABLE '\0' | 1721 | # define _POSIX_VDISABLE '\0' |
| 1720 | #endif | 1722 | #endif |
| 1721 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; | 1723 | new_settings.c_cc[VINTR] = _POSIX_VDISABLE; |
| 1722 | tcsetattr_stdin_TCSANOW(&new_settings); | 1724 | tcsetattr_stdin_TCSANOW(&new_settings); |
