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

Re: bodgy COLUMNS coredump



On Aug 23,  2:32pm, Geoff Wing wrote:
} Subject: bodgy COLUMNS coredump
}
} +     columns = COLUMNS;		/* sanity */

If you're going to do this, all the references to COLUMNS in other places
can probably be backed out.  Really, sanity of `columns' should be forced
wherever it is initialized or reset, and the COLUMNS macro could go away.
To do that right requires a special *setfn for COLUMNS and LINES, rather
than using intvarsetfn.

The following also fixes PSVAR and FIGNORE so they can be set to empty,
rather than having an empty assignment set them to "." (dot).  I don't
know whether MANPATH should have this behavior or not, so I left it
alone.

Note that this simply disables ZLE if COLUMNS is set to less than 2;
it probably ought to disable it at 10 columns or so, but ....  Also,
SINGLELINEZLE is enabled when LINES is set to 1.

Index: Src/builtin.c
--- zsh-3.0.0/Src/builtin.c	Wed Aug 14 08:06:54 1996
+++ zsh-3.0.0-build/Src/builtin.c	Thu Aug 22 22:57:18 1996
@@ -4314,7 +4314,7 @@
 		l = t;
 
 	sc = l + 2;
-	nc = (COLUMNS + 1) / sc;
+	nc = (columns + 1) / sc;
 	if (!nc)
 	    nc = 1;
 	nr = (n + nc - 1) / nc;
Index: Src/hashtable.h
--- zsh-3.0.0/Src/hashtable.h	Tue Aug 13 18:13:18 1996
+++ zsh-3.0.0-build/Src/hashtable.h	Thu Aug 22 23:08:23 1996
@@ -134,11 +134,11 @@
 IPDEF4("LINENO", &lineno),
 IPDEF4("PPID", &ppid),
 
-#define IPDEF5(A,B) {NULL,A,PM_INTEGER|PM_SPECIAL,NULL,IFN(intvarsetfn),IFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
-IPDEF5("COLUMNS", &columns),
-IPDEF5("LINES", &lines),
-IPDEF5("OPTIND", &zoptind),
-IPDEF5("SHLVL", &shlvl),
+#define IPDEF5(A,B,F) {NULL,A,PM_INTEGER|PM_SPECIAL,NULL,IFN(F),IFN(intvargetfn),10,(void *)B,NULL,NULL,NULL,0}
+IPDEF5("COLUMNS", &columns, zlevarsetfn),
+IPDEF5("LINES", &lines, zlevarsetfn),
+IPDEF5("OPTIND", &zoptind, intvarsetfn),
+IPDEF5("SHLVL", &shlvl, intvarsetfn),
 
 #define IPDEF6(A,B) {NULL,A,PM_SCALAR|PM_READONLY|PM_SPECIAL,NULL,IFN(nullsetfn),IFN(strvargetfn),0,(void *)B,NULL,NULL,NULL,0}
 IPDEF6("PWD", &pwd),
@@ -158,13 +158,13 @@
 IPDEF7("SPROMPT", &sprompt),
 IPDEF7("0", &argzero),
 
-#define IPDEF8(A,B,C) {NULL,A,PM_SCALAR|PM_SPECIAL,NULL,IFN(colonarrsetfn),IFN(colonarrgetfn),0,(void *)B,NULL,C,NULL,0}
-IPDEF8("CDPATH", &cdpath, "cdpath"),
-IPDEF8("FIGNORE", &fignore, "fignore"),
-IPDEF8("FPATH", &fpath, "fpath"),
-IPDEF8("MAILPATH", &mailpath, "mailpath"),
-IPDEF8("WATCH", &watch, "watch"),
-IPDEF8("PSVAR", &psvar, "psvar"),
+#define IPDEF8(A,B,C,F) {NULL,A,PM_SCALAR|PM_SPECIAL,NULL,IFN(F),IFN(colonarrgetfn),0,(void *)B,NULL,C,NULL,0}
+IPDEF8("CDPATH", &cdpath, "cdpath", colonarrsetfn),
+IPDEF8("FIGNORE", &fignore, "fignore", colonarr2setfn),
+IPDEF8("FPATH", &fpath, "fpath", colonarrsetfn),
+IPDEF8("MAILPATH", &mailpath, "mailpath", colonarr2setfn),
+IPDEF8("WATCH", &watch, "watch", colonarrsetfn),
+IPDEF8("PSVAR", &psvar, "psvar", colonarr2setfn),
 
 {NULL, "PATH", PM_SPECIAL,NULL, IFN(colonpathsetfn), IFN(colonpathgetfn), 0, (void *) NULL, NULL, "path", NULL, 0},
 
@@ -183,7 +183,7 @@
 IPDEF7("PROMPT2", &prompt2),
 IPDEF7("PROMPT3", &prompt3),
 IPDEF7("PROMPT4", &prompt4),
-IPDEF8("MANPATH", &manpath, "manpath"),
+IPDEF8("MANPATH", &manpath, "manpath", colonarrsetfn),
 IPDEF9("argv", 0, &pparams, NULL),
 IPDEF9("fignore", 0, &fignore, "FIGNORE"),
 IPDEF9("cdpath", 0, &cdpath, "CDPATH"),
Index: Src/init.c
--- zsh-3.0.0/Src/init.c	Thu Aug 15 09:42:16 1996
+++ zsh-3.0.0-build/Src/init.c	Thu Aug 22 22:28:59 1996
@@ -535,8 +535,12 @@
 #ifdef TIOCGWINSZ
     if (!(columns = shttyinfo.winsize.ws_col))
 	columns = 80;
+    if (columns < 2)
+	opts[USEZLE] = 0;
     if (!(lines = shttyinfo.winsize.ws_row))
 	lines = 24;
+    if (lines < 2)
+	opts[SINGLELINEZLE] = 1;
 #else
     columns = 80;
     lines = 24;
Index: Src/jobs.c
--- zsh-3.0.0/Src/jobs.c	Wed Jul 31 11:13:17 1996
+++ zsh-3.0.0-build/Src/jobs.c	Thu Aug 22 22:59:42 1996
@@ -221,7 +221,7 @@
 {
     Process pn;
     int job = jn - jobtab, len = 9, sig, sflag = 0, llen;
-    int conted = 0, lineleng = COLUMNS, skip = 0, doputnl = 0;
+    int conted = 0, lineleng = columns, skip = 0, doputnl = 0;
     FILE *fout = (synch == 2) ? stdout : shout;
 
     if (jn->stat & STAT_NOPRINT)
Index: Src/params.c
--- zsh-3.0.0/Src/params.c	Sun Aug  4 05:52:33 1996
+++ zsh-3.0.0-build/Src/params.c	Thu Aug 22 23:13:08 1996
@@ -1223,6 +1223,31 @@
     *((long *)pm->data) = x;
 }
 
+/* Function to set value of any ZLE-related integer *
+ * parameter.  data is pointer to global variable   *
+ * where the value is to be stored.                 */
+
+/**/
+void
+zlevarsetfn(Param pm, long x)
+{
+    if (x < 2) {
+	if ((long *)pm->data == & columns) {
+	    if (x <= 0)
+		x = 80;		/* Arbitary, but same as init.c */
+	    else
+		x = 2;
+	    opts[USEZLE] = 0;
+	} else if ((long *)pm->data == & lines) {
+	    if (x <= 0)
+		x = 24;		/* Arbitrary, but same as init.c */
+	    else
+		opts[SINGLELINEZLE] = 1;
+	}
+    }
+    *((long *)pm->data) = x;
+}
+
 /* Function to set value of generic special scalar    *
  * parameter.  data is pointer to a character pointer *
  * representing the scalar (string).                  */
@@ -1317,11 +1342,21 @@
     char ***dptr = (char ***)pm->data;
 
     freearray(*dptr);
-    if (pm->data == (void *) & mailpath && x && !*x) {
+    *dptr = x ? colonfix(x, pm->ename ? pm->nam : NULL, pm->flags & PM_UNIQUE) : mkarray(NULL);
+}
+
+/**/
+void
+colonarr2setfn(Param pm, char *x)
+{
+    char ***dptr = (char ***)pm->data;
+
+    if (x && !*x) {
+	freearray(*dptr);
 	zsfree(x);
 	*dptr = mkarray(NULL);
     } else
-	*dptr = x ? colonfix(x, pm->ename ? pm->nam : NULL, pm->flags & PM_UNIQUE) : mkarray(NULL);
+	colonarrsetfn(pm, x);
 }
 
 /* Function to get the value of special (scalar)        *
Index: Src/utils.c
--- zsh-3.0.0/Src/utils.c	Wed Aug 14 09:18:34 1996
+++ zsh-3.0.0-build/Src/utils.c	Thu Aug 22 22:31:24 1996
@@ -844,6 +844,10 @@
     if (shttyinfo.winsize.ws_row)
 	lines = shttyinfo.winsize.ws_row;
     if (oldcols != columns) {
+	if (columns < 2)
+	    opts[USEZLE] = 0;
+	if (lines < 2)
+	    opts[SINGLELINEZLE] = 1;
 	if (zleactive) {
 	    resetneeded = winchanged = 1;
 	    refresh();
Index: Src/zle_misc.c
--- zsh-3.0.0/Src/zle_misc.c	Tue Aug 13 13:24:14 1996
+++ zsh-3.0.0-build/Src/zle_misc.c	Thu Aug 22 22:59:51 1996
@@ -835,8 +835,8 @@
     if (wp) {
 	*wp = bp - bl0 - lensb;
 	if (pmpt != rpmpt) {
-	    *wp %= COLUMNS;
-	    if (*wp == COLUMNS - 1) {
+	    *wp %= columns;
+	    if (*wp == columns - 1) {
 		addbufspc(1);
 		*wp = 0;
 		*bp++ = ' ';
Index: Src/zle_refresh.c
--- zsh-3.0.0/Src/zle_refresh.c	Sun Aug 11 18:39:05 1996
+++ zsh-3.0.0-build/Src/zle_refresh.c	Thu Aug 22 23:00:07 1996
@@ -66,7 +66,7 @@
     int ln;
     static int lwinw = -1, lwinh = -1;	/* last window width & height */
  
-    winw = COLUMNS;  /* terminal width */
+    winw = columns;  /* terminal width */
     if (isset(SINGLELINEZLE) || termok != TERM_OK)
 	winh = 1;
     else
@@ -247,7 +247,7 @@
 	    moveto(0, pptw);
 	}
 	clearf = clearflag;
-    } else if (winw != COLUMNS)
+    } else if (winw != columns)
 	resetvideo();
 
 /* now winw equals columns; now all width comparisons can be made to winw */
Index: Src/zle_tricky.c
--- zsh-3.0.0/Src/zle_tricky.c	Sun Aug 11 12:15:35 1996
+++ zsh-3.0.0-build/Src/zle_tricky.c	Thu Aug 22 23:00:39 1996
@@ -3469,7 +3469,7 @@
 	} else {
 	    cc++;
 	    if (*p == '\n') {
-		l += 1 + (cc / COLUMNS);
+		l += 1 + (cc / columns);
 		cc = 0;
 	    }
 	    if (dopr)
@@ -3477,7 +3477,7 @@
 	}
     }
 
-    return l + (cc / COLUMNS);
+    return l + (cc / columns);
 }
 
 /* List the matches.  Note that the list entries are metafied. */
@@ -3551,7 +3551,7 @@
 	longest++;
 
     fw = longest + 2;
-    fct = (COLUMNS + 1) / fw;
+    fct = (columns + 1) / fw;
     if (fct == 0) {
 	fct = 1;
 	colsz = ct;
@@ -3559,7 +3559,7 @@
 	for (ap = arr; *ap; ap++)
 	    up += (niceztrlen(*ap + off) - nboff + of +
 		(ispattern ? 0 :
-		(!(haswhat & HAS_MISC) ? nfpl + nfsl : nlpl + nlsl))) / COLUMNS;
+		(!(haswhat & HAS_MISC) ? nfpl + nfsl : nlpl + nlsl))) / columns;
     } else {
 	colsz = (ct + fct - 1) / fct;
 	up = colsz + nlnct - clearflag;
@@ -3739,11 +3739,11 @@
     while (t0)
 	t0 /= 10, longest++;
     /* to compensate for added ')' */
-    fct = (COLUMNS - 1) / (longest + 3);
+    fct = (columns - 1) / (longest + 3);
     if (fct == 0)
 	fct = 1;
     else
-	fw = (COLUMNS - 1) / fct;
+	fw = (columns - 1) / fct;
     colsz = (ct + fct - 1) / fct;
     for (t1 = 0; t1 != colsz; t1++) {
 	ap = arr + t1;
Index: Src/zsh.h
--- zsh-3.0.0/Src/zsh.h	Mon Aug 12 10:57:32 1996
+++ zsh-3.0.0-build/Src/zsh.h	Thu Aug 22 22:56:55 1996
@@ -1246,8 +1246,6 @@
 #define txtchangeisset(X)	(txtchange & (X))
 #define txtchangeset(X, Y)	(txtchange |= (X), txtchange &= ~(Y))
 
-#define COLUMNS      (columns < 1 ? 80 : columns)
-
 /****************************************/
 /* Definitions for the %_ prompt escape */
 /****************************************/

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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