diff options
author | Robert Griebl <griebl@gmx.de> | 2002-12-03 22:45:46 +0000 |
---|---|---|
committer | Robert Griebl <griebl@gmx.de> | 2002-12-03 22:45:46 +0000 |
commit | 350d26bbbb127284cefb877b8380049e65665b15 (patch) | |
tree | 82f389342d1b840a6daf6a9b0e9ada9eba108693 | |
parent | 3ba7ceebfc8035fa618c99b27f6995a5bc6997ac (diff) | |
download | busybox-w32-350d26bbbb127284cefb877b8380049e65665b15.tar.gz busybox-w32-350d26bbbb127284cefb877b8380049e65665b15.tar.bz2 busybox-w32-350d26bbbb127284cefb877b8380049e65665b15.zip |
- the number of commands in the history list is now configureable via the
config system
- added a new config option to allow persistant history lists. This is
currently only used by ash, but the calls ({load,save}_history) could
be added to the other shells as well.
-rw-r--r-- | shell/ash.c | 9 | ||||
-rw-r--r-- | shell/cmdedit.c | 56 | ||||
-rw-r--r-- | shell/cmdedit.h | 3 | ||||
-rw-r--r-- | shell/config.in | 2 |
4 files changed, 69 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index d20618d3c..bec37cfcc 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -7356,6 +7356,10 @@ int ash_main(int argc, char **argv) | |||
7356 | 7356 | ||
7357 | if (sflag || minusc == NULL) { | 7357 | if (sflag || minusc == NULL) { |
7358 | state4: /* XXX ??? - why isn't this before the "if" statement */ | 7358 | state4: /* XXX ??? - why isn't this before the "if" statement */ |
7359 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
7360 | if ( iflag ) | ||
7361 | load_history ( ".ash_history" ); | ||
7362 | #endif | ||
7359 | cmdloop(1); | 7363 | cmdloop(1); |
7360 | } | 7364 | } |
7361 | #if PROFILE | 7365 | #if PROFILE |
@@ -7546,6 +7550,11 @@ static int exitcmd(int argc, char **argv) | |||
7546 | { | 7550 | { |
7547 | if (stoppedjobs()) | 7551 | if (stoppedjobs()) |
7548 | return 0; | 7552 | return 0; |
7553 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
7554 | if ( iflag ) | ||
7555 | save_history ( ".ash_history" ); | ||
7556 | #endif | ||
7557 | |||
7549 | if (argc > 1) | 7558 | if (argc > 1) |
7550 | exitstatus = number(argv[1]); | 7559 | exitstatus = number(argv[1]); |
7551 | else | 7560 | else |
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index b6e743eb4..73378e659 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -90,7 +90,12 @@ | |||
90 | 90 | ||
91 | 91 | ||
92 | /* Maximum length of the linked list for the command line history */ | 92 | /* Maximum length of the linked list for the command line history */ |
93 | #define MAX_HISTORY 15 | 93 | #ifndef CONFIG_FEATURE_COMMAND_HISTORY |
94 | #define MAX_HISTORY 15 | ||
95 | #else | ||
96 | #define MAX_HISTORY CONFIG_FEATURE_COMMAND_HISTORY | ||
97 | #endif | ||
98 | |||
94 | #if MAX_HISTORY < 1 | 99 | #if MAX_HISTORY < 1 |
95 | #warning cmdedit: You set MAX_HISTORY < 1. The history algorithm switched off. | 100 | #warning cmdedit: You set MAX_HISTORY < 1. The history algorithm switched off. |
96 | #else | 101 | #else |
@@ -1125,6 +1130,55 @@ static int get_next_history(void) | |||
1125 | return 0; | 1130 | return 0; |
1126 | } | 1131 | } |
1127 | } | 1132 | } |
1133 | |||
1134 | |||
1135 | extern void load_history ( char *fromfile ) | ||
1136 | { | ||
1137 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
1138 | FILE *fp; | ||
1139 | |||
1140 | // cleanup old | ||
1141 | while ( n_history ) { | ||
1142 | if ( history [n_history - 1] ) | ||
1143 | free ( history [n_history - 1] ); | ||
1144 | n_history--; | ||
1145 | } | ||
1146 | |||
1147 | if (( fp = fopen ( fromfile, "r" ))) { | ||
1148 | char buffer [256]; | ||
1149 | int i, l; | ||
1150 | |||
1151 | for ( i = 0; i < MAX_HISTORY; i++ ) { | ||
1152 | if ( !fgets ( buffer, sizeof( buffer ) - 1, fp )) | ||
1153 | break; | ||
1154 | l = xstrlen ( buffer ); | ||
1155 | if ( l && buffer [l - 1] == '\n' ) | ||
1156 | buffer [l - 1] = 0; | ||
1157 | history [n_history++] = xstrdup ( buffer ); | ||
1158 | } | ||
1159 | fclose ( fp ); | ||
1160 | } | ||
1161 | cur_history = n_history; | ||
1162 | #endif | ||
1163 | } | ||
1164 | |||
1165 | extern void save_history ( char *tofile ) | ||
1166 | { | ||
1167 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
1168 | FILE *fp = fopen ( tofile, "w" ); | ||
1169 | |||
1170 | if ( fp ) { | ||
1171 | int i; | ||
1172 | |||
1173 | for ( i = 0; i < n_history; i++ ) { | ||
1174 | fputs ( history [i], fp ); | ||
1175 | fputc ( '\n', fp ); | ||
1176 | } | ||
1177 | fclose ( fp ); | ||
1178 | } | ||
1179 | #endif | ||
1180 | } | ||
1181 | |||
1128 | #endif | 1182 | #endif |
1129 | 1183 | ||
1130 | enum { | 1184 | enum { |
diff --git a/shell/cmdedit.h b/shell/cmdedit.h index 83893572a..045588dc1 100644 --- a/shell/cmdedit.h +++ b/shell/cmdedit.h | |||
@@ -3,4 +3,7 @@ | |||
3 | 3 | ||
4 | int cmdedit_read_input(char* promptStr, char* command); | 4 | int cmdedit_read_input(char* promptStr, char* command); |
5 | 5 | ||
6 | void load_history ( char *fromfile ); | ||
7 | void save_history ( char *tofile ); | ||
8 | |||
6 | #endif /* CMDEDIT_H */ | 9 | #endif /* CMDEDIT_H */ |
diff --git a/shell/config.in b/shell/config.in index b34c23845..cb1365b9d 100644 --- a/shell/config.in +++ b/shell/config.in | |||
@@ -52,6 +52,8 @@ comment 'Bourne Shell Options' | |||
52 | bool 'command line editing' CONFIG_FEATURE_COMMAND_EDITING | 52 | bool 'command line editing' CONFIG_FEATURE_COMMAND_EDITING |
53 | bool 'tab completion' CONFIG_FEATURE_COMMAND_TAB_COMPLETION | 53 | bool 'tab completion' CONFIG_FEATURE_COMMAND_TAB_COMPLETION |
54 | bool 'username completion' CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION | 54 | bool 'username completion' CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION |
55 | int 'history size' CONFIG_FEATURE_COMMAND_HISTORY 15 | ||
56 | bool 'history saving (currently only ash)' CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
55 | bool 'Standalone shell' CONFIG_FEATURE_SH_STANDALONE_SHELL | 57 | bool 'Standalone shell' CONFIG_FEATURE_SH_STANDALONE_SHELL |
56 | bool 'Standalone shell -- applets always win' CONFIG_FEATURE_SH_APPLETS_ALWAYS_WIN | 58 | bool 'Standalone shell -- applets always win' CONFIG_FEATURE_SH_APPLETS_ALWAYS_WIN |
57 | bool 'Fancy shell prompts' CONFIG_FEATURE_SH_FANCY_PROMPT | 59 | bool 'Fancy shell prompts' CONFIG_FEATURE_SH_FANCY_PROMPT |