Re: Mangled prompt in xterm under XFree86 4.x



Hello, Dmitry!

>     In xterm under XFree86 4.x the prompt is "prefixed" with a "^O", so that
> instead of e.g. "goofy:~ " one sees "^Ogoofy:~" (shell is zsh with
> PS1='%m:%~%# ').

Finally I have fixed this problem.  Actually, there were two problems:

strip_ctrl_codes() wasn't using is_printable().  There are still many
places where is_printable() should be used, but let's fix your problem
first.

strip_ctrl_codes() didn't work are advertized.  Stripping of the sequences
beginning with '\e[' was buggy.  Unfortunately, this function was the
finest example of "primadonna style coding", so I just rewrote it using
pointers instead of indices - it was easier than to understand the
existing code :-/

The patch:

------------------------------------
--- ChangeLog
+++ ChangeLog
@@ -2,2 +2,5 @@

+	* util.c (strip_ctrl_codes): Rewrite using pointers.  Fix
+	stripping sequences beginning with "\e[".  Check is_printable().
+
 	* man2hlp.c: Remove HTML support.  Remove old link support.
--- util.c
+++ util.c
@@ -841,28 +841,28 @@ char *skip_numbers (char *s)
  * terminfo databases, except the Hewlett-Packard 70092 and some Wyse
  * terminals.  If I hear from a single person who uses such a terminal
  * with MC, I'll be glad to add support for it.  (Dugan)
+ * Non-printable characters are also removed.
  */

 char *strip_ctrl_codes (char *s)
 {
-    int i;  /* Current length of the string's correct (stripped) prefix */
-    int j;  /* Number of control characters we have skipped so far */
+    char *w; /* Current position where the stripped data is written */
+    char *r; /* Current position where the original data is read */

     if (!s)
 	return 0;
-
-    for (i = 0, j = 0; s [i+j]; ++i)
-	if (s [i+j] != ESC_CHAR){
-	    if (j)
-		s [i] = s [i+j];
+
+    for (w = s, r = s; *r; ++r)
+	if (*r != ESC_CHAR){
+	    if (is_printable(*r))
+		*w++ = *r;
 	} else {
-	    ++j;
-	    if (s [i+j++] == '[')
-		while (strchr ("0123456789;?", s [i+j++]))
+	    if (*(++r) == '[') {
+		while (strchr ("0123456789;?", *(++r)))
 		    /* Skip the control sequence's arguments */ ;
-	    --i;
+	    }
 	}
-    s[i] = 0;
+    *w = 0;
     return s;
 }

------------------------------------

The fixed snapshot is at http://www.red-bean.com/~proski/mc/

Thank you for reporting the problem!

-- 
Regards,
Pavel Roskin





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]