This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix RedBoot history recall


BZ #1000714 - history recall via !nn was incorrect.  This
change fixes it.  Checked into trunk & 3.0 branches

n.b. I'm not even sure why this is in here, probably historical.
It came with the original line editing stuff, but is of very
limited usefulness IMO

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
Index: redboot/current/ChangeLog
===================================================================
RCS file: /srv/misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.267
diff -u -5 -p -r1.267 ChangeLog
--- redboot/current/ChangeLog	4 Mar 2009 17:22:32 -0000	1.267
+++ redboot/current/ChangeLog	9 Mar 2009 23:41:56 -0000
@@ -1,5 +1,11 @@
+2009-03-09  Gary Thomas  <gary@mlbassoc.com>
+
+	* src/io.c: Better handling of history - commands now have
+	a [fixed] virtual number over time.  This makes !nn work correctly.
+	Fixes BZ#1000714
+
 2009-03-04  Gary Thomas  <gary@mlbassoc.com>
 
 	* src/fconfig.c (get_config): Simplify memcpy() call to
 	work around GCC 4.3 code generation error.  BZ#1000672
 
Index: redboot/current/src/io.c
===================================================================
RCS file: /srv/misc/cvsfiles/ecos/packages/redboot/current/src/io.c,v
retrieving revision 1.35
diff -u -5 -p -r1.35 io.c
--- redboot/current/src/io.c	29 Jan 2009 17:50:04 -0000	1.35
+++ redboot/current/src/io.c	9 Mar 2009 23:38:51 -0000
@@ -313,10 +313,11 @@ getc_script(char *cp)
 #if CYGNUM_REDBOOT_CMD_LINE_EDITING != 0
 #define _CL_NUM_LINES CYGNUM_REDBOOT_CMD_LINE_EDITING       // Number of lines to keep
 static char _cl_lines[_CL_NUM_LINES][CYGPKG_REDBOOT_MAX_CMD_LINE];
 static int  _cl_index = -1;      // Last known command line
 static int  _cl_max_index = -1;  // Last command in buffers
+static int  _cl_real_index = 0;  // Virtual command index (0..N)
 
 #ifdef CYGBLD_REDBOOT_CMD_LINE_HISTORY
 static void expand_history(char *);
 #endif
 #endif
@@ -606,13 +607,16 @@ _rb_gets_preloaded(char *buf, int buflen
                 // History handling - only when enabled
 #ifdef CYGBLD_REDBOOT_CMD_LINE_HISTORY
 		expand_history(buf);
 #endif
 		if (*buf != '\0') {
-		    if (++_cl_index == _CL_NUM_LINES) _cl_index = 0;
+		    if (++_cl_index == _CL_NUM_LINES) {
+                        _cl_index = 0;
+                    }
 		    if (_cl_index > _cl_max_index) _cl_max_index = _cl_index;
 		    strcpy(_cl_lines[_cl_index], buf);
+                    _cl_real_index++;
 		}
             }
 #endif
             return _GETS_OK;
         case '\b':
@@ -800,24 +804,28 @@ expand_history(char *buf)
 	if (!strcmp(buf, "!!")) {
 	    strcpy(buf, _cl_lines[_cl_index]);
 	    return;
 	}
 	if ((index = parse_history_index(buf + 1)) >= 0) {
-	    if (index <= _cl_max_index) {
-		strcpy(buf, _cl_lines[index]);
-		return;
-	    }
-	}
-	len = strlen(buf + 1);
-	for (i = 0, index = _cl_index; i < ncmds; i++) {
-	    if (!strncmp(_cl_lines[index], buf+1, len)) {
-		strcpy(buf, _cl_lines[index]);
-		return;
-	    }
-	    if (--index < 0)
-		index = _cl_max_index;
-	}
+            if (index <= _cl_real_index) {
+                while (index >= _CL_NUM_LINES) {
+                    index -= _CL_NUM_LINES;
+                }
+                strcpy(buf, _cl_lines[index]);
+                return;
+            }
+	} else {
+            len = strlen(buf + 1);
+            for (i = 0, index = _cl_index; i < ncmds; i++) {
+                if (!strncmp(_cl_lines[index], buf+1, len)) {
+                    strcpy(buf, _cl_lines[index]);
+                    return;
+                }
+                if (--index < 0)
+                    index = _cl_max_index;
+            }
+        }
     }
 
     diag_printf("%s: event not found\n", buf);
     *buf = '\0';
 }
@@ -831,12 +839,13 @@ do_history(int argc, char *argv[])
     if (_cl_index == _cl_max_index) {
 	// history has not wrapped around
 	for (i = 0; i < ncmds; i++)
 	    diag_printf("%3d %s\n", i, _cl_lines[i]);
     } else {
+        diag_printf("_cl_index = %d\n", _cl_index);
 	for (i = 0, index = _cl_index + 1; i < ncmds; i++) {
-	    diag_printf("%3d %s\n", i, _cl_lines[index++]);
+	    diag_printf("%3d %s\n", i+_cl_real_index-_CL_NUM_LINES, _cl_lines[index++]);
 	    if (index > _cl_max_index)
 		index = 0;
 	}
     }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]