zsh-workers
 help / color / mirror / code / Atom feed
* Re: bodgy COLUMNS coredump
@ 1996-08-23  4:37 Geoff Wing
  0 siblings, 0 replies; 3+ messages in thread
From: Geoff Wing @ 1996-08-23  4:37 UTC (permalink / raw)
  To: zsh-workers

Heyla,
 re: my last patch
 There is another patch hidden in there, which is really a low priority
 optimisation.  It's in the zle_refresh.c part, but shouldn't cause any
 problems.
-- 
Geoff Wing [mason@primenet.com.au]   PrimeNet - Internet Consultancy
  Web: http://www.primenet.com.au/   Facsimile: +61-3-9819 3788


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bodgy COLUMNS coredump
  1996-08-23  4:32 Geoff Wing
@ 1996-08-23  6:27 ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1996-08-23  6:27 UTC (permalink / raw)
  To: Geoff Wing, zsh-workers

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"


^ permalink raw reply	[flat|nested] 3+ messages in thread

* bodgy COLUMNS coredump
@ 1996-08-23  4:32 Geoff Wing
  1996-08-23  6:27 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Geoff Wing @ 1996-08-23  4:32 UTC (permalink / raw)
  To: zsh-workers

Heyla,
  to get zsh to coredump on command.
% COLUMNS=1

Here's a patch, though I'm not very happy with it.  It provides more of a 
kludge than a clean fix.  Testing this also unveiled another bug (coredump) in
hist.c:620  hbegin->zsfree->zfree  which I haven't looked at yet.  I got this
by taking my xterm window down to 1 or 2 columns.
One interesting thing that happened to me was gdb coredumped while loading up
zsh & zsh.core :-)
I won't have much time in the next couple of weeks to look at this, but if
someone hasn't cleaned it up by then, I'll see what I can do then.



*** zsh.h	1996/08/15 16:41:25	2.44
--- zsh.h	1996/08/23 04:12:14
***************
*** 1246,1252 ****
  #define txtchangeisset(X)	(txtchange & (X))
  #define txtchangeset(X, Y)	(txtchange |= (X), txtchange &= ~(Y))
  
! #define COLUMNS      (columns < 1 ? 80 : columns)
  
  /****************************************/
  /* Definitions for the %_ prompt escape */
--- 1246,1252 ----
  #define txtchangeisset(X)	(txtchange & (X))
  #define txtchangeset(X, Y)	(txtchange |= (X), txtchange &= ~(Y))
  
! #define COLUMNS      (columns < 2 ? 80 : columns)
  
  /****************************************/
  /* Definitions for the %_ prompt escape */

*** init.c	1996/08/13 20:36:44	2.39
--- init.c	1996/08/23 03:59:53
***************
*** 541,546 ****
--- 541,547 ----
      columns = 80;
      lines = 24;
  #endif
+     columns = COLUMNS;		/* sanity */
  
      /* The following variable assignments cause zsh to behave more *
       * like Bourne and Korn shells when invoked as "sh" or "ksh".  *

*** utils.c	1996/08/14 16:21:47	2.51
--- utils.c	1996/08/23 04:00:09
***************
*** 841,846 ****
--- 841,847 ----
      ioctl(SHTTY, TIOCGWINSZ, (char *)&shttyinfo.winsize);
      if (shttyinfo.winsize.ws_col)
  	columns = shttyinfo.winsize.ws_col;
+     columns = COLUMNS;		/* sanity */
      if (shttyinfo.winsize.ws_row)
  	lines = shttyinfo.winsize.ws_row;
      if (oldcols != columns) {

*** zle_refresh.c	1996/08/12 01:39:05	2.13
--- zle_refresh.c	1996/08/23 04:17:41
***************
*** 66,72 ****
      int ln;
      static int lwinw = -1, lwinh = -1;	/* last window width & height */
   
!     winw = COLUMNS;  /* terminal width */
      if (isset(SINGLELINEZLE) || termok != TERM_OK)
  	winh = 1;
      else
--- 66,73 ----
      int ln;
      static int lwinw = -1, lwinh = -1;	/* last window width & height */
   
!     columns = COLUMNS;		/* sanity */
!     winw = COLUMNS; 		/* terminal width */
      if (isset(SINGLELINEZLE) || termok != TERM_OK)
  	winh = 1;
      else
***************
*** 247,253 ****
  	    moveto(0, pptw);
  	}
  	clearf = clearflag;
!     } else if (winw != COLUMNS)
  	resetvideo();
  
  /* now winw equals columns; now all width comparisons can be made to winw */
--- 248,254 ----
  	    moveto(0, pptw);
  	}
  	clearf = clearflag;
!     } else if (winw != columns)
  	resetvideo();
  
  /* now winw equals columns; now all width comparisons can be made to winw */
***************
*** 546,562 ****
      if (hasam && vcs == winw) {
  	vln++, vcs = 1;
  	putc(*nbuf[vln], shout);
! 	nl++;
! 	if (*ol)
! 	    ol++;
! 	ccs = 1;
      }
  
  /* 3: main display loop - write out the buffer using whatever tricks we can */
  
      for (;;) {
! 	if (*nl && nl[1] == ol[1])	/* skip only if second chars match */
! 	/* skip past all matching characters */
  	    for (; *nl && (*nl == *ol); nl++, ol++, ccs++) ;
  
  	if (!*nl) {
--- 547,565 ----
      if (hasam && vcs == winw) {
  	vln++, vcs = 1;
  	putc(*nbuf[vln], shout);
! 	if (!*ol) {
! 	    ol = halloc(2);
! 	    *ol = *nl;
! 	    ol[1] = '\0';
! 	}
      }
  
  /* 3: main display loop - write out the buffer using whatever tricks we can */
  
      for (;;) {
! 	if (*nl && *ol && (nl[1] == ol[1] || (ccs + 1 == vcs)))
! 	/* if second characters match or the cursor is on the second character
! 	   skip past all matching characters */
  	    for (; *nl && (*nl == *ol); nl++, ol++, ccs++) ;
  
  	if (!*nl) {

-- 
Geoff Wing [mason@primenet.com.au]   PrimeNet - Internet Consultancy
  Web: http://www.primenet.com.au/   Facsimile: +61-3-9819 3788


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-08-23  6:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-23  4:37 bodgy COLUMNS coredump Geoff Wing
  -- strict thread matches above, loose matches on Subject: below --
1996-08-23  4:32 Geoff Wing
1996-08-23  6:27 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).