aboutsummaryrefslogtreecommitdiff
path: root/shell/cmdedit.c
diff options
context:
space:
mode:
authorRobert Griebl <griebl@gmx.de>2002-12-03 22:45:46 +0000
committerRobert Griebl <griebl@gmx.de>2002-12-03 22:45:46 +0000
commit350d26bbbb127284cefb877b8380049e65665b15 (patch)
tree82f389342d1b840a6daf6a9b0e9ada9eba108693 /shell/cmdedit.c
parent3ba7ceebfc8035fa618c99b27f6995a5bc6997ac (diff)
downloadbusybox-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.
Diffstat (limited to 'shell/cmdedit.c')
-rw-r--r--shell/cmdedit.c56
1 files changed, 55 insertions, 1 deletions
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
1135extern 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
1165extern 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
1130enum { 1184enum {