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/cmdedit.c | |
| 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/cmdedit.c')
| -rw-r--r-- | shell/cmdedit.c | 46 |
1 files changed, 25 insertions, 21 deletions
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 | ||
