[BusyBox-cvs] busybox/shell ash.c,1.62,1.63 cmdedit.c,1.73,1.74 cmdedit.h,1.12,1.13 config.in,1.5,1.6

Robert Griebl sandman at busybox.net
Tue Dec 3 22:45:51 UTC 2002


Update of /var/cvs/busybox/shell
In directory winder:/tmp/cvs-serv10117

Modified Files:
	ash.c cmdedit.c cmdedit.h config.in 
Log Message:
 - 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.


Index: ash.c
===================================================================
RCS file: /var/cvs/busybox/shell/ash.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- ash.c	22 Oct 2002 22:15:33 -0000	1.62
+++ ash.c	3 Dec 2002 22:45:46 -0000	1.63
@@ -7356,6 +7356,10 @@
 
 	if (sflag || minusc == NULL) {
 	  state4:			/* XXX ??? - why isn't this before the "if" statement */
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+	    if ( iflag )
+	    	load_history ( ".ash_history" );
+#endif
 		cmdloop(1);
 	}
 #if PROFILE
@@ -7546,6 +7550,11 @@
 {
 	if (stoppedjobs())
 		return 0;
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+	if ( iflag )
+		save_history ( ".ash_history" );
+#endif			
+		
 	if (argc > 1)
 		exitstatus = number(argv[1]);
 	else

Index: cmdedit.c
===================================================================
RCS file: /var/cvs/busybox/shell/cmdedit.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- cmdedit.c	27 Nov 2002 09:29:48 -0000	1.73
+++ cmdedit.c	3 Dec 2002 22:45:46 -0000	1.74
@@ -90,7 +90,12 @@
 
 
 /* Maximum length of the linked list for the command line history */
-#define MAX_HISTORY 15
+#ifndef CONFIG_FEATURE_COMMAND_HISTORY
+#define MAX_HISTORY   15
+#else
+#define MAX_HISTORY   CONFIG_FEATURE_COMMAND_HISTORY
+#endif
+
 #if MAX_HISTORY < 1
 #warning cmdedit: You set MAX_HISTORY < 1. The history algorithm switched off.
 #else
@@ -1125,6 +1130,55 @@
 		return 0;
 	}
 }
+
+
+extern void load_history ( char *fromfile )
+{
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+	FILE *fp;
+
+	// cleanup old
+	while ( n_history ) {
+		if ( history [n_history - 1] )
+			free ( history [n_history - 1] );
+		n_history--;
+	}
+
+	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 ))
+				break;
+			l = xstrlen	( buffer );
+			if ( l && buffer [l - 1] == '\n' )
+				buffer [l - 1] = 0;
+			history [n_history++] = xstrdup ( buffer );
+		}
+		fclose ( fp );
+	}
+	cur_history = n_history;
+#endif
+}
+
+extern void save_history ( char *tofile )
+{
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+	FILE *fp = fopen ( tofile, "w" );
+	
+	if ( fp ) {
+		int i;
+		
+		for ( i = 0; i < n_history; i++ ) {
+			fputs ( history [i], fp );
+			fputc ( '\n', fp );
+		}
+		fclose ( fp );
+	}
+#endif
+}
+
 #endif
 
 enum {

Index: cmdedit.h
===================================================================
RCS file: /var/cvs/busybox/shell/cmdedit.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cmdedit.h	17 Jul 2001 01:12:36 -0000	1.12
+++ cmdedit.h	3 Dec 2002 22:45:46 -0000	1.13
@@ -3,4 +3,7 @@
 
 int     cmdedit_read_input(char* promptStr, char* command);
 
+void    load_history ( char *fromfile );
+void    save_history ( char *tofile );
+
 #endif /* CMDEDIT_H */

Index: config.in
===================================================================
RCS file: /var/cvs/busybox/shell/config.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- config.in	1 Sep 2002 06:45:54 -0000	1.5
+++ config.in	3 Dec 2002 22:45:46 -0000	1.6
@@ -52,6 +52,8 @@
 bool 'command line editing'		CONFIG_FEATURE_COMMAND_EDITING
 bool 'tab completion'			CONFIG_FEATURE_COMMAND_TAB_COMPLETION
 bool 'username completion'		CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION
+int  'history size'             CONFIG_FEATURE_COMMAND_HISTORY  15
+bool 'history saving (currently only ash)'         CONFIG_FEATURE_COMMAND_SAVEHISTORY
 bool 'Standalone shell'			CONFIG_FEATURE_SH_STANDALONE_SHELL
 bool 'Standalone shell -- applets always win'	CONFIG_FEATURE_SH_APPLETS_ALWAYS_WIN
 bool 'Fancy shell prompts'	CONFIG_FEATURE_SH_FANCY_PROMPT




More information about the busybox-cvs mailing list