diff options
author | Flemming Madsen <busybox@themadsens.dk> | 2013-04-07 18:47:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-04-07 18:47:24 +0200 |
commit | d96ffda62e9f9c88a6e43dc1926c5b775a611166 (patch) | |
tree | f5c691e02aae158e04b797e267f3fa779d591728 | |
parent | 3beab83e4f7f4213c185737e95dc4895f0059dd6 (diff) | |
download | busybox-w32-d96ffda62e9f9c88a6e43dc1926c5b775a611166.tar.gz busybox-w32-d96ffda62e9f9c88a6e43dc1926c5b775a611166.tar.bz2 busybox-w32-d96ffda62e9f9c88a6e43dc1926c5b775a611166.zip |
ash,hush: history builtin
function old new delta
show_history - 39 +39
builtin_history - 16 +16
historycmd - 13 +13
bltins1 312 324 +12
builtintab 336 344 +8
popstring 134 140 +6
hush_main 1048 1046 -2
ash_main 1398 1396 -2
size_from_HISTFILESIZE 44 40 -4
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 3/3 up/down: 94/-8) Total: 86 bytes
Signed-off-by: Flemming Madsen <busybox@themadsens.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/lineedit.c | 16 | ||||
-rw-r--r-- | shell/ash.c | 15 | ||||
-rw-r--r-- | shell/hush.c | 14 |
4 files changed, 45 insertions, 3 deletions
diff --git a/include/libbb.h b/include/libbb.h index 6dd4d7cae..b5d1156ae 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1436,7 +1436,7 @@ void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; | |||
1436 | /* It's NOT just ENABLEd or disabled. It's a number: */ | 1436 | /* It's NOT just ENABLEd or disabled. It's a number: */ |
1437 | # if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0 | 1437 | # if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0 |
1438 | # define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) | 1438 | # define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) |
1439 | unsigned size_from_HISTFILESIZE(const char *hp); | 1439 | unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC; |
1440 | # else | 1440 | # else |
1441 | # define MAX_HISTORY 0 | 1441 | # define MAX_HISTORY 0 |
1442 | # endif | 1442 | # endif |
@@ -1478,6 +1478,7 @@ line_input_t *new_line_input_t(int flags) FAST_FUNC; | |||
1478 | * >0 length of input string, including terminating '\n' | 1478 | * >0 length of input string, including terminating '\n' |
1479 | */ | 1479 | */ |
1480 | int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC; | 1480 | int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC; |
1481 | void show_history(const line_input_t *st) FAST_FUNC; | ||
1481 | # if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT | 1482 | # if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT |
1482 | void save_history(line_input_t *st); | 1483 | void save_history(line_input_t *st); |
1483 | # endif | 1484 | # endif |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 93ab86426..1313dd5d9 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -1254,7 +1254,7 @@ line_input_t* FAST_FUNC new_line_input_t(int flags) | |||
1254 | 1254 | ||
1255 | #if MAX_HISTORY > 0 | 1255 | #if MAX_HISTORY > 0 |
1256 | 1256 | ||
1257 | unsigned size_from_HISTFILESIZE(const char *hp) | 1257 | unsigned FAST_FUNC size_from_HISTFILESIZE(const char *hp) |
1258 | { | 1258 | { |
1259 | int size = MAX_HISTORY; | 1259 | int size = MAX_HISTORY; |
1260 | if (hp) { | 1260 | if (hp) { |
@@ -1309,6 +1309,17 @@ static int get_next_history(void) | |||
1309 | return 0; | 1309 | return 0; |
1310 | } | 1310 | } |
1311 | 1311 | ||
1312 | /* Lists command history. Used by shell 'history' builtins */ | ||
1313 | void FAST_FUNC show_history(const line_input_t *st) | ||
1314 | { | ||
1315 | int i; | ||
1316 | |||
1317 | if (!st) | ||
1318 | return; | ||
1319 | for (i = 0; i < st->cnt_history; i++) | ||
1320 | printf("%4d %s\n", i, st->history[i]); | ||
1321 | } | ||
1322 | |||
1312 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY | 1323 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY |
1313 | /* We try to ensure that concurrent additions to the history | 1324 | /* We try to ensure that concurrent additions to the history |
1314 | * do not overwrite each other. | 1325 | * do not overwrite each other. |
@@ -2749,8 +2760,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2749 | free(command_ps); | 2760 | free(command_ps); |
2750 | #endif | 2761 | #endif |
2751 | 2762 | ||
2752 | if (command_len > 0) | 2763 | if (command_len > 0) { |
2753 | remember_in_history(command); | 2764 | remember_in_history(command); |
2765 | } | ||
2754 | 2766 | ||
2755 | if (break_out > 0) { | 2767 | if (break_out > 0) { |
2756 | command[command_len++] = '\n'; | 2768 | command[command_len++] = '\n'; |
diff --git a/shell/ash.c b/shell/ash.c index edcb7c028..6af14f551 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -9033,6 +9033,9 @@ static int getoptscmd(int, char **) FAST_FUNC; | |||
9033 | #if !ENABLE_FEATURE_SH_EXTRA_QUIET | 9033 | #if !ENABLE_FEATURE_SH_EXTRA_QUIET |
9034 | static int helpcmd(int, char **) FAST_FUNC; | 9034 | static int helpcmd(int, char **) FAST_FUNC; |
9035 | #endif | 9035 | #endif |
9036 | #if MAX_HISTORY | ||
9037 | static int historycmd(int, char **) FAST_FUNC; | ||
9038 | #endif | ||
9036 | #if ENABLE_SH_MATH_SUPPORT | 9039 | #if ENABLE_SH_MATH_SUPPORT |
9037 | static int letcmd(int, char **) FAST_FUNC; | 9040 | static int letcmd(int, char **) FAST_FUNC; |
9038 | #endif | 9041 | #endif |
@@ -9106,6 +9109,9 @@ static const struct builtincmd builtintab[] = { | |||
9106 | #if !ENABLE_FEATURE_SH_EXTRA_QUIET | 9109 | #if !ENABLE_FEATURE_SH_EXTRA_QUIET |
9107 | { BUILTIN_NOSPEC "help" , helpcmd }, | 9110 | { BUILTIN_NOSPEC "help" , helpcmd }, |
9108 | #endif | 9111 | #endif |
9112 | #if MAX_HISTORY | ||
9113 | { BUILTIN_NOSPEC "history" , historycmd }, | ||
9114 | #endif | ||
9109 | #if JOBS | 9115 | #if JOBS |
9110 | { BUILTIN_REGULAR "jobs" , jobscmd }, | 9116 | { BUILTIN_REGULAR "jobs" , jobscmd }, |
9111 | { BUILTIN_REGULAR "kill" , killcmd }, | 9117 | { BUILTIN_REGULAR "kill" , killcmd }, |
@@ -12621,6 +12627,15 @@ helpcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
12621 | } | 12627 | } |
12622 | #endif /* FEATURE_SH_EXTRA_QUIET */ | 12628 | #endif /* FEATURE_SH_EXTRA_QUIET */ |
12623 | 12629 | ||
12630 | #if MAX_HISTORY | ||
12631 | static int FAST_FUNC | ||
12632 | historycmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | ||
12633 | { | ||
12634 | show_history(line_input_state); | ||
12635 | return EXIT_SUCCESS; | ||
12636 | } | ||
12637 | #endif | ||
12638 | |||
12624 | /* | 12639 | /* |
12625 | * The export and readonly commands. | 12640 | * The export and readonly commands. |
12626 | */ | 12641 | */ |
diff --git a/shell/hush.c b/shell/hush.c index 1d421dc38..7cebe1784 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -850,6 +850,9 @@ static int builtin_jobs(char **argv) FAST_FUNC; | |||
850 | #if ENABLE_HUSH_HELP | 850 | #if ENABLE_HUSH_HELP |
851 | static int builtin_help(char **argv) FAST_FUNC; | 851 | static int builtin_help(char **argv) FAST_FUNC; |
852 | #endif | 852 | #endif |
853 | #if MAX_HISTORY | ||
854 | static int builtin_history(char **argv) FAST_FUNC; | ||
855 | #endif | ||
853 | #if ENABLE_HUSH_LOCAL | 856 | #if ENABLE_HUSH_LOCAL |
854 | static int builtin_local(char **argv) FAST_FUNC; | 857 | static int builtin_local(char **argv) FAST_FUNC; |
855 | #endif | 858 | #endif |
@@ -919,6 +922,9 @@ static const struct built_in_command bltins1[] = { | |||
919 | #if ENABLE_HUSH_HELP | 922 | #if ENABLE_HUSH_HELP |
920 | BLTIN("help" , builtin_help , NULL), | 923 | BLTIN("help" , builtin_help , NULL), |
921 | #endif | 924 | #endif |
925 | #if MAX_HISTORY | ||
926 | BLTIN("history" , builtin_history , "Show command history"), | ||
927 | #endif | ||
922 | #if ENABLE_HUSH_JOB | 928 | #if ENABLE_HUSH_JOB |
923 | BLTIN("jobs" , builtin_jobs , "List jobs"), | 929 | BLTIN("jobs" , builtin_jobs , "List jobs"), |
924 | #endif | 930 | #endif |
@@ -8627,6 +8633,14 @@ static int FAST_FUNC builtin_help(char **argv UNUSED_PARAM) | |||
8627 | } | 8633 | } |
8628 | #endif | 8634 | #endif |
8629 | 8635 | ||
8636 | #if MAX_HISTORY | ||
8637 | static int FAST_FUNC builtin_history(char **argv UNUSED_PARAM) | ||
8638 | { | ||
8639 | show_history(G.line_input_state); | ||
8640 | return EXIT_SUCCESS; | ||
8641 | } | ||
8642 | #endif | ||
8643 | |||
8630 | #if ENABLE_HUSH_JOB | 8644 | #if ENABLE_HUSH_JOB |
8631 | static int FAST_FUNC builtin_jobs(char **argv UNUSED_PARAM) | 8645 | static int FAST_FUNC builtin_jobs(char **argv UNUSED_PARAM) |
8632 | { | 8646 | { |