about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2010-01-13 12:05:22 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2010-01-13 12:05:22 +0000
commit036cb0ce95580efa03dff169bb3dba457a48cfdc (patch)
treec1e611cf935047a626af55ef9e50c82acc4fc5cf /Src
parenta7ea114f965abfea376293f9e56d1d790c1ca1d2 (diff)
downloadzsh-036cb0ce95580efa03dff169bb3dba457a48cfdc.tar.gz
zsh-036cb0ce95580efa03dff169bb3dba457a48cfdc.tar.xz
zsh-036cb0ce95580efa03dff169bb3dba457a48cfdc.zip
Joakim Rosqvist: 27591 as modified in 27594:
KEYBOARD_HACK variable
Diffstat (limited to 'Src')
-rw-r--r--Src/input.c40
-rw-r--r--Src/options.c3
-rw-r--r--Src/params.c46
3 files changed, 75 insertions, 14 deletions
diff --git a/Src/input.c b/Src/input.c
index 80f8ec8d5..248d2ae71 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -291,20 +291,32 @@ inputline(void)
 	zputs(ingetcline, stderr);
 	fflush(stderr);
     }
-    if (*ingetcline && ingetcline[strlen(ingetcline) - 1] == '\n' &&
-	interact && isset(SUNKEYBOARDHACK) && isset(SHINSTDIN) &&
-	SHTTY != -1 && *ingetcline && ingetcline[1] &&
-	ingetcline[strlen(ingetcline) - 2] == '`') {
-	/* Junk an unmatched "`" at the end of the line. */
-	int ct;
-	char *ptr;
-
-	for (ct = 0, ptr = ingetcline; *ptr; ptr++)
-	    if (*ptr == '`')
-		ct++;
-	if (ct & 1) {
-	    ptr[-2] = '\n';
-	    ptr[-1] = '\0';
+    if (keyboardhackchar && *ingetcline &&
+	ingetcline[strlen(ingetcline) - 1] == '\n' &&
+	interact && isset(SHINSTDIN) &&
+	SHTTY != -1 && ingetcline[1])
+    {
+	char *stripptr = ingetcline + strlen(ingetcline) - 2;
+	if (*stripptr == keyboardhackchar) {
+	    /* Junk an unwanted character at the end of the line.
+	       (key too close to return key) */
+	    int ct = 1;  /* force odd */
+	    char *ptr;
+
+	    if (keyboardhackchar == '\'' || keyboardhackchar == '"' ||
+		keyboardhackchar == '`') {
+		/*
+		 * for the chars above, also require an odd count before
+		 * junking
+		 */
+		for (ct = 0, ptr = ingetcline; *ptr; ptr++)
+		    if (*ptr == keyboardhackchar)
+			ct++;
+	    }
+	    if (ct & 1) {
+		stripptr[0] = '\n';
+		stripptr[1] = '\0';
+	    }
 	}
     }
     isfirstch = 1;
diff --git a/Src/options.c b/Src/options.c
index c5b7c3b8f..a5f299e49 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -748,6 +748,9 @@ dosetopt(int optno, int value, int force)
     } else if ((optno == EMACSMODE || optno == VIMODE) && value) {
 	zleentry(ZLE_CMD_SET_KEYMAP, optno);
 	opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] = 0;
+    } else if (optno == SUNKEYBOARDHACK) {
+	/* for backward compatibility */
+	keyboardhackchar = (value ? '`' : '\0');
     }
     opts[optno] = value;
     if (optno == BANGHIST || optno == SHINSTDIN)
diff --git a/Src/params.c b/Src/params.c
index 0425e0700..abc4c0002 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -108,6 +108,9 @@ zlong lineno,		/* $LINENO      */
 mod_export unsigned char bangchar;
 /**/
 unsigned char hatchar, hashchar;
+
+/**/
+unsigned char keyboardhackchar = '\0';
  
 /* $SECONDS = now.tv_sec - shtimer.tv_sec
  *          + (now.tv_usec - shtimer.tv_usec) / 1000000.0
@@ -204,6 +207,8 @@ static const struct gsu_scalar ifs_gsu =
 { ifsgetfn, ifssetfn, stdunsetfn };
 static const struct gsu_scalar underscore_gsu =
 { underscoregetfn, nullstrsetfn, stdunsetfn };
+static const struct gsu_scalar keyboard_hack_gsu =
+{ keyboardhackgetfn, keyboardhacksetfn, stdunsetfn };
 #ifdef USE_LOCALE
 static const struct gsu_scalar lc_blah_gsu =
 { strgetfn, lcsetfn, stdunsetfn };
@@ -273,6 +278,7 @@ IPDEF2("TERM", term_gsu, 0),
 IPDEF2("WORDCHARS", wordchars_gsu, 0),
 IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT),
 IPDEF2("_", underscore_gsu, PM_READONLY),
+IPDEF2("KEYBOARD_HACK", keyboard_hack_gsu, PM_DONTIMPORT),
 
 #ifdef USE_LOCALE
 # define LCIPDEF(name) IPDEF2(name, lc_blah_gsu, PM_UNSET)
@@ -3834,6 +3840,46 @@ errnogetfn(UNUSED(Param pm))
     return errno;
 }
 
+/* Function to get value for special parameter `KEYBOARD_HACK' */
+
+/**/
+char *
+keyboardhackgetfn(UNUSED(Param pm))
+{
+    static char buf[2];
+
+    buf[0] = keyboardhackchar;
+    buf[1] = '\0';
+    return buf;
+}
+
+
+/* Function to set value of special parameter `KEYBOARD_HACK' */
+
+/**/
+void
+keyboardhacksetfn(UNUSED(Param pm), char *x)
+{
+    if (x) {
+	int len, i;
+
+	unmetafy(x, &len);
+	if (len > 1) {
+	    len = 1;
+	    zwarn("Only one KEYBOARD_HACK character can be defined");  /* could be changed if needed */
+	}
+	for (i = 0; i < len; i++) {
+	    if (!isascii(STOUC(x[i]))) {
+		zwarn("KEYBOARD_HACK can only contain ASCII characters");
+		return;
+	    }
+	}
+	keyboardhackchar = len ? STOUC(x[0]) : '\0';
+	free(x);
+    } else
+	keyboardhackchar = '\0';
+}
+
 /* Function to get value for special parameter `histchar' */
 
 /**/