diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-12-09 11:10:40 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-12-09 11:10:40 +0000 |
| commit | fdbbb048933389c5a2624aa77aa5af2dbea75b01 (patch) | |
| tree | 41623dd3faac0290e7739fde7c7228f7fa47e18e /shell | |
| parent | 6b5bd0e5abbfb6b3b925dfd8452c72589569981b (diff) | |
| download | busybox-w32-fdbbb048933389c5a2624aa77aa5af2dbea75b01.tar.gz busybox-w32-fdbbb048933389c5a2624aa77aa5af2dbea75b01.tar.bz2 busybox-w32-fdbbb048933389c5a2624aa77aa5af2dbea75b01.zip | |
Command line history changes, lastpatch_71 from Vladimir N. Oleynik
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/Config.in | 15 | ||||
| -rw-r--r-- | shell/ash.c | 48 | ||||
| -rw-r--r-- | shell/cmdedit.c | 46 | ||||
| -rw-r--r-- | shell/cmdedit.h | 6 |
4 files changed, 77 insertions, 38 deletions
diff --git a/shell/Config.in b/shell/Config.in index 69f848272..b643c8f3d 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | # see scripts/kbuild/config-language.txt. | 3 | # see scripts/kbuild/config-language.txt. |
| 4 | # | 4 | # |
| 5 | 5 | ||
| 6 | menu "Bourne Shell" | 6 | menu "Another Bourne-like Shell" |
| 7 | 7 | ||
| 8 | choice | 8 | choice |
| 9 | prompt "Choose your default shell" | 9 | prompt "Choose your default shell" |
| @@ -95,12 +95,6 @@ config CONFIG_ASH_OPTIMIZE_FOR_SIZE | |||
| 95 | help | 95 | help |
| 96 | Please submit a patch to add help text for this item. | 96 | Please submit a patch to add help text for this item. |
| 97 | 97 | ||
| 98 | config CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 99 | bool " history saving" | ||
| 100 | default n | ||
| 101 | depends on CONFIG_ASH | ||
| 102 | help | ||
| 103 | Please submit a patch to add help text for this item. | ||
| 104 | 98 | ||
| 105 | if CONFIG_FEATURE_SH_IS_HUSH | 99 | if CONFIG_FEATURE_SH_IS_HUSH |
| 106 | config CONFIG_HUSH | 100 | config CONFIG_HUSH |
| @@ -158,6 +152,13 @@ config CONFIG_FEATURE_COMMAND_EDITING | |||
| 158 | help | 152 | help |
| 159 | Please submit a patch to add help text for this item. | 153 | Please submit a patch to add help text for this item. |
| 160 | 154 | ||
| 155 | config CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 156 | bool " history saving" | ||
| 157 | default n | ||
| 158 | depends on CONFIG_ASH | ||
| 159 | help | ||
| 160 | Please submit a patch to add help text for this item. | ||
| 161 | |||
| 161 | config CONFIG_FEATURE_COMMAND_TAB_COMPLETION | 162 | config CONFIG_FEATURE_COMMAND_TAB_COMPLETION |
| 162 | bool "tab completion" | 163 | bool "tab completion" |
| 163 | default n | 164 | default n |
diff --git a/shell/ash.c b/shell/ash.c index bec37cfcc..715169053 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -1196,6 +1196,10 @@ static struct var vlc_all; | |||
| 1196 | static struct var vlc_ctype; | 1196 | static struct var vlc_ctype; |
| 1197 | #endif | 1197 | #endif |
| 1198 | 1198 | ||
| 1199 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 1200 | static struct var vhistfile; | ||
| 1201 | #endif | ||
| 1202 | |||
| 1199 | struct varinit { | 1203 | struct varinit { |
| 1200 | struct var *var; | 1204 | struct var *var; |
| 1201 | int flags; | 1205 | int flags; |
| @@ -1242,6 +1246,10 @@ static const struct varinit varinit[] = { | |||
| 1242 | {&vlc_ctype, VSTRFIXED | VTEXTFIXED | VUNSET, "LC_CTYPE=", | 1246 | {&vlc_ctype, VSTRFIXED | VTEXTFIXED | VUNSET, "LC_CTYPE=", |
| 1243 | change_lc_ctype}, | 1247 | change_lc_ctype}, |
| 1244 | #endif | 1248 | #endif |
| 1249 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 1250 | {&vhistfile, VSTRFIXED | VTEXTFIXED | VUNSET, "HISTFILE=", | ||
| 1251 | NULL}, | ||
| 1252 | #endif | ||
| 1245 | {NULL, 0, NULL, | 1253 | {NULL, 0, NULL, |
| 1246 | NULL} | 1254 | NULL} |
| 1247 | }; | 1255 | }; |
| @@ -7312,6 +7320,20 @@ int ash_main(int argc, char **argv) | |||
| 7312 | init(); | 7320 | init(); |
| 7313 | setstackmark(&smark); | 7321 | setstackmark(&smark); |
| 7314 | procargs(argc, argv); | 7322 | procargs(argc, argv); |
| 7323 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 7324 | if ( iflag ) { | ||
| 7325 | const char *hp = lookupvar("HISTFILE"); | ||
| 7326 | |||
| 7327 | if(hp == NULL ) { | ||
| 7328 | hp = lookupvar("HOME"); | ||
| 7329 | if(hp != NULL) { | ||
| 7330 | char *defhp = concat_path_file(hp, ".ash_history"); | ||
| 7331 | setvar("HISTFILE", defhp, 0); | ||
| 7332 | free(defhp); | ||
| 7333 | } | ||
| 7334 | } | ||
| 7335 | } | ||
| 7336 | #endif | ||
| 7315 | if (argv[0] && argv[0][0] == '-') | 7337 | if (argv[0] && argv[0][0] == '-') |
| 7316 | isloginsh = 1; | 7338 | isloginsh = 1; |
| 7317 | if (isloginsh) { | 7339 | if (isloginsh) { |
| @@ -7357,8 +7379,12 @@ int ash_main(int argc, char **argv) | |||
| 7357 | if (sflag || minusc == NULL) { | 7379 | if (sflag || minusc == NULL) { |
| 7358 | state4: /* XXX ??? - why isn't this before the "if" statement */ | 7380 | state4: /* XXX ??? - why isn't this before the "if" statement */ |
| 7359 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | 7381 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY |
| 7360 | if ( iflag ) | 7382 | if ( iflag ) { |
| 7361 | load_history ( ".ash_history" ); | 7383 | const char *hp = lookupvar("HISTFILE"); |
| 7384 | |||
| 7385 | if(hp != NULL ) | ||
| 7386 | load_history ( hp ); | ||
| 7387 | } | ||
| 7362 | #endif | 7388 | #endif |
| 7363 | cmdloop(1); | 7389 | cmdloop(1); |
| 7364 | } | 7390 | } |
| @@ -7550,10 +7576,6 @@ static int exitcmd(int argc, char **argv) | |||
| 7550 | { | 7576 | { |
| 7551 | if (stoppedjobs()) | 7577 | if (stoppedjobs()) |
| 7552 | return 0; | 7578 | return 0; |
| 7553 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 7554 | if ( iflag ) | ||
| 7555 | save_history ( ".ash_history" ); | ||
| 7556 | #endif | ||
| 7557 | 7579 | ||
| 7558 | if (argc > 1) | 7580 | if (argc > 1) |
| 7559 | exitstatus = number(argv[1]); | 7581 | exitstatus = number(argv[1]); |
| @@ -11615,12 +11637,22 @@ static void exitshell(int status) | |||
| 11615 | trap[0] = NULL; | 11637 | trap[0] = NULL; |
| 11616 | evalstring(p, 0); | 11638 | evalstring(p, 0); |
| 11617 | } | 11639 | } |
| 11618 | l1:handler = &loc2; /* probably unnecessary */ | 11640 | l1: |
| 11641 | handler = &loc2; /* probably unnecessary */ | ||
| 11619 | flushall(); | 11642 | flushall(); |
| 11620 | #ifdef CONFIG_ASH_JOB_CONTROL | 11643 | #ifdef CONFIG_ASH_JOB_CONTROL |
| 11621 | setjobctl(0); | 11644 | setjobctl(0); |
| 11622 | #endif | 11645 | #endif |
| 11623 | l2:_exit(status); | 11646 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY |
| 11647 | if (iflag && rootshell) { | ||
| 11648 | const char *hp = lookupvar("HISTFILE"); | ||
| 11649 | |||
| 11650 | if(hp != NULL ) | ||
| 11651 | save_history ( hp ); | ||
| 11652 | } | ||
| 11653 | #endif | ||
| 11654 | l2: | ||
| 11655 | _exit(status); | ||
| 11624 | /* NOTREACHED */ | 11656 | /* NOTREACHED */ |
| 11625 | } | 11657 | } |
| 11626 | 11658 | ||
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 73378e659..2e102e351 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
| @@ -1131,40 +1131,44 @@ static int get_next_history(void) | |||
| 1131 | } | 1131 | } |
| 1132 | } | 1132 | } |
| 1133 | 1133 | ||
| 1134 | |||
| 1135 | extern void load_history ( char *fromfile ) | ||
| 1136 | { | ||
| 1137 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | 1134 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY |
| 1135 | extern void load_history ( const char *fromfile ) | ||
| 1136 | { | ||
| 1138 | FILE *fp; | 1137 | FILE *fp; |
| 1138 | int hi; | ||
| 1139 | 1139 | ||
| 1140 | // cleanup old | 1140 | /* cleanup old */ |
| 1141 | while ( n_history ) { | 1141 | |
| 1142 | if ( history [n_history - 1] ) | 1142 | for(hi = n_history; hi > 0; ) { |
| 1143 | free ( history [n_history - 1] ); | 1143 | hi--; |
| 1144 | n_history--; | 1144 | free ( history [hi] ); |
| 1145 | } | 1145 | } |
| 1146 | 1146 | ||
| 1147 | if (( fp = fopen ( fromfile, "r" ))) { | 1147 | if (( fp = fopen ( fromfile, "r" ))) { |
| 1148 | char buffer [256]; | ||
| 1149 | int i, l; | ||
| 1150 | 1148 | ||
| 1151 | for ( i = 0; i < MAX_HISTORY; i++ ) { | 1149 | for ( hi = 0; hi < MAX_HISTORY; ) { |
| 1152 | if ( !fgets ( buffer, sizeof( buffer ) - 1, fp )) | 1150 | char * hl = get_line_from_file(fp); |
| 1151 | int l; | ||
| 1152 | |||
| 1153 | if(!hl) | ||
| 1153 | break; | 1154 | break; |
| 1154 | l = xstrlen ( buffer ); | 1155 | chomp(hl); |
| 1155 | if ( l && buffer [l - 1] == '\n' ) | 1156 | l = strlen(hl); |
| 1156 | buffer [l - 1] = 0; | 1157 | if(l >= BUFSIZ) |
| 1157 | history [n_history++] = xstrdup ( buffer ); | 1158 | hl[BUFSIZ-1] = 0; |
| 1159 | if(l == 0 || hl[0] == ' ') { | ||
| 1160 | free(hl); | ||
| 1161 | continue; | ||
| 1162 | } | ||
| 1163 | history [hi++] = hl; | ||
| 1158 | } | 1164 | } |
| 1159 | fclose ( fp ); | 1165 | fclose ( fp ); |
| 1160 | } | 1166 | } |
| 1161 | cur_history = n_history; | 1167 | cur_history = n_history = hi; |
| 1162 | #endif | ||
| 1163 | } | 1168 | } |
| 1164 | 1169 | ||
| 1165 | extern void save_history ( char *tofile ) | 1170 | extern void save_history ( const char *tofile ) |
| 1166 | { | 1171 | { |
| 1167 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | ||
| 1168 | FILE *fp = fopen ( tofile, "w" ); | 1172 | FILE *fp = fopen ( tofile, "w" ); |
| 1169 | 1173 | ||
| 1170 | if ( fp ) { | 1174 | if ( fp ) { |
| @@ -1176,8 +1180,8 @@ extern void save_history ( char *tofile ) | |||
| 1176 | } | 1180 | } |
| 1177 | fclose ( fp ); | 1181 | fclose ( fp ); |
| 1178 | } | 1182 | } |
| 1179 | #endif | ||
| 1180 | } | 1183 | } |
| 1184 | #endif | ||
| 1181 | 1185 | ||
| 1182 | #endif | 1186 | #endif |
| 1183 | 1187 | ||
diff --git a/shell/cmdedit.h b/shell/cmdedit.h index 045588dc1..991dafcd1 100644 --- a/shell/cmdedit.h +++ b/shell/cmdedit.h | |||
| @@ -3,7 +3,9 @@ | |||
| 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 ); | 6 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY |
| 7 | void save_history ( char *tofile ); | 7 | void load_history ( const char *fromfile ); |
| 8 | void save_history ( const char *tofile ); | ||
| 9 | #endif | ||
| 8 | 10 | ||
| 9 | #endif /* CMDEDIT_H */ | 11 | #endif /* CMDEDIT_H */ |
