diff options
author | Glenn L McGrath | 2002-12-09 11:10:40 +0000 |
---|---|---|
committer | Glenn L McGrath | 2002-12-09 11:10:40 +0000 |
commit | fdbbb048933389c5a2624aa77aa5af2dbea75b01 (patch) | |
tree | 41623dd3faac0290e7739fde7c7228f7fa47e18e /shell/cmdedit.c | |
parent | 6b5bd0e5abbfb6b3b925dfd8452c72589569981b (diff) | |
download | busybox-fdbbb048933389c5a2624aa77aa5af2dbea75b01.zip busybox-fdbbb048933389c5a2624aa77aa5af2dbea75b01.tar.gz |
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 73378e6..2e102e3 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c @@ -1131,40 +1131,44 @@ static int get_next_history(void) } } - -extern void load_history ( char *fromfile ) -{ #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY +extern void load_history ( const char *fromfile ) +{ FILE *fp; + int hi; - // cleanup old - while ( n_history ) { - if ( history [n_history - 1] ) - free ( history [n_history - 1] ); - n_history--; + /* cleanup old */ + + for(hi = n_history; hi > 0; ) { + hi--; + free ( history [hi] ); } if (( fp = fopen ( fromfile, "r" ))) { - char buffer [256]; - int i, l; - for ( i = 0; i < MAX_HISTORY; i++ ) { - if ( !fgets ( buffer, sizeof( buffer ) - 1, fp )) + for ( hi = 0; hi < MAX_HISTORY; ) { + char * hl = get_line_from_file(fp); + int l; + + if(!hl) break; - l = xstrlen ( buffer ); - if ( l && buffer [l - 1] == '\n' ) - buffer [l - 1] = 0; - history [n_history++] = xstrdup ( buffer ); + chomp(hl); + l = strlen(hl); + if(l >= BUFSIZ) + hl[BUFSIZ-1] = 0; + if(l == 0 || hl[0] == ' ') { + free(hl); + continue; + } + history [hi++] = hl; } fclose ( fp ); } - cur_history = n_history; -#endif + cur_history = n_history = hi; } -extern void save_history ( char *tofile ) +extern void save_history ( const char *tofile ) { -#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY FILE *fp = fopen ( tofile, "w" ); if ( fp ) { @@ -1176,8 +1180,8 @@ extern void save_history ( char *tofile ) } fclose ( fp ); } -#endif } +#endif #endif |