Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: multibyte odds and ends



Bart Schaefer wrote:
> On Aug 1,  9:44pm, Peter Stephenson wrote:
> } Does anybody have any preferences?  Does anybody ever redefine HISTCHARS?
> 
> I've been redefining HISTCHARS/histchars to replace ^ with = for longer
> than I've been using zsh (dating from using csh way back when some tty
> terminals did not have | and the Bourne shell interpreted ^ as a pipe).
> 
> I'd be fine with restricting HISTCHARS to ASCII, or even to non-alpha-
> numeric ASCII.

I presume this is the only response I'm likely to get.

The shell will now issue a warning and refuse to set histchars/HISTCHARS
if either contains non-ASCII characters.  I thought about an error, but
the most likely place to set HISTCHARS is in .zshrc, and aborting all
processing if setting the variable fails is not likely to be the right
thing to do.

It also fixes a hard-to-find bug with metafication.

By the way, I've no intention of removing HISTCHARS so the note that
it's "deprecated" isn't really true, particularly since upper case is
the natural form for scalars in zsh.

Index: README
===================================================================
RCS file: /cvsroot/zsh/zsh/README,v
retrieving revision 1.34
diff -u -r1.34 README
--- README	10 Jul 2006 13:08:22 -0000	1.34
+++ README	2 Aug 2006 17:05:51 -0000
@@ -81,6 +81,11 @@
 on some fairly common PC configurations.  This change is only likely to
 affect some highly specialised uses of the shell.
 
+The variables HISTCHARS and histchars now reject any attempt to
+set non-ASCII characters for history or comments.  Multibyte characters
+have never worked and the most consistent change was to restrict the
+set to portable characters only.
+
 Documentation
 -------------
 
Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.32
diff -u -r1.32 params.yo
--- Doc/Zsh/params.yo	2 Aug 2006 09:59:23 -0000	1.32
+++ Doc/Zsh/params.yo	2 Aug 2006 17:05:51 -0000
@@ -803,6 +803,10 @@
 expansion (default `tt(!)').  The second character signals the
 start of a quick history substitution (default `tt(^)').  The third
 character is the comment character (default `tt(#)').
+
+The characters must be in the ASCII character set; any attempt to set
+tt(histchars) to characters with a locale-dependent meaning will be
+rejected with an error message.
 )
 vindex(HISTCHARS)
 item(tt(HISTCHARS) <S> <Z>)(
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.117
diff -u -r1.117 params.c
--- Src/params.c	10 Jul 2006 13:08:23 -0000	1.117
+++ Src/params.c	2 Aug 2006 17:05:52 -0000
@@ -3548,10 +3548,21 @@
 histcharssetfn(UNUSED(Param pm), char *x)
 {
     if (x) {
-	bangchar = x[0];
-	hatchar = (bangchar) ? x[1] : '\0';
-	hashchar = (hatchar) ? x[2] : '\0';
-	zsfree(x);
+	int len, i;
+
+	unmetafy(x, &len);
+	if (len > 3)
+	    len = 3;
+	for (i = 0; i < len; i++) {
+	    if (!isascii(STOUC(x[i]))) {
+		zwarn("HISTCHARS can only contain ASCII characters");
+		return;
+	    }
+	}
+	bangchar = len ? STOUC(x[0]) : '\0';
+	hatchar =  len > 1 ? STOUC(x[1]) : '\0';
+	hashchar = len > 2 ? STOUC(x[2]) : '\0';
+	free(x);
     } else {
 	bangchar = '!';
 	hashchar = '#';

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



Messages sorted by: Reverse Date, Date, Thread, Author