zsh-workers
 help / color / mirror / code / Atom feed
* Zsh 3.1.{6,9} patches
@ 2000-07-13  9:59 Fr. Br. George
  2000-07-13 11:12 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Fr. Br. George @ 2000-07-13  9:59 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1180 bytes --]

	Hello!

	This is some upgrades i've made for zsh-3.1.6, but it also
useable for zsh-3.1.9

	The first one is code to meke zsh truncate PS1 string backwards.
Just use zro-started argument with %~ command to drop out the REST of
path instead ofte HEAD. See the example (note %01~ entry):
	user@host:/usr..zsh/3.1.9/zsh> pwd; echo $PS1 
	/usr/local/lib/zsh/3.1.9/zsh
	%U%n%u@%B%m%b:%5(~:%01~..%3~:%~)> 
This is useful for keeping starting part of path, so I'll always be
prompted the root of pwd. Who knows how many */bin's a system may have :)
It also possible to use backward flag with another numeric-argumented
commands in the future.

	The second one is Solaris 2.7+ configure patch to make it compile zsh
with libcurses.so by default instead of termcap, which is unnative. If
this is incorrect, and Solaris curses are bugged, please inform me...
I never got a problem using zsh compiled with libcurses.so from Solaris
2.7 (so it was even possible to copy the library to Solaris 2.6 and 2.5.1!).
This is useful for delicate terminal configuring.

	The patchfiles are all for zsh-3.1.9 sources.

			George V Kouryachy (aka Fr. Br. George)
			email: frbrgeorge@intelligencia.com

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1311 bytes --]

--- zsh-3.1.9/Src/prompt.c	Fri Mar 24 13:43:21 2000
+++ zsh-3.1.9.new/Src/prompt.c	Fri Jul  7 17:36:54 2000
@@ -93,6 +93,10 @@
 
 static int dontcount;
 
+/* Backward truncating flag */
+
+static int bw;
+
 /* Strings to use for %r and %R (for the spelling prompt). */
 
 static char *rstring, *Rstring;
@@ -112,7 +116,8 @@
 	modp = tricat("~", nd->nam, p + strlen(nd->dir));
 
     if (npath) {
-	char *sptr;
+      char *sptr;
+      if (!bw) {
 	for (sptr = modp + strlen(modp); sptr > modp; sptr--) {
 	    if (*sptr == '/' && !--npath) {
 		sptr++;
@@ -122,6 +127,15 @@
 	if (*sptr == '/' && sptr[1] && sptr != modp)
 	    sptr++;
 	stradd(sptr);
+      } else {
+        char cbu;
+        for (sptr = modp+1; *sptr; sptr++ )
+	    if (*sptr == '/' && !--npath) break;
+	cbu=*sptr;
+	*sptr=0;
+	stradd(modp);
+	*sptr=cbu;
+      }
     } else
 	stradd(modp);
 
@@ -197,14 +211,16 @@
     Nameddir nd;
 
     for (; *fm && *fm != endchar; fm++) {
-	arg = 0;
+	arg = bw = 0;
 	if (*fm == '%' && isset(PROMPTPERCENT)) {
+	    if (fm[1]=='0') bw=1;
 	    if (idigit(*++fm)) {
 		arg = zstrtol(fm, &fm, 10);
 	    }
 	    if (*fm == '(') {
 		int tc, otrunclen;
 
+		if (fm[1]=='0') bw=1;
 		if (idigit(*++fm)) {
 		    arg = zstrtol(fm, &fm, 10);
 		}

[-- Attachment #3: Type: TEXT/PLAIN, Size: 1129 bytes --]

--- zsh-3.1.9/configure	Tue May 30 13:15:39 2000
+++ zsh-3.1.9.new/configure	Fri Jul  7 17:37:54 2000
@@ -2967,7 +2967,7 @@
 
 
 case "$host_os" in
-  aix*|hpux10.*|hpux11.*) termcap_curses_order="curses ncurses termcap" ;;
+  solaris*|aix*|hpux10.*|hpux11.*) termcap_curses_order="curses ncurses termcap" ;;
   *)             termcap_curses_order="termcap curses ncurses" ;;
 esac
 
@@ -5969,12 +5969,12 @@
   fi
   case "$host_os" in
     hpux*)        DLLDFLAGS="${DLLDFLAGS=-b}" ;;
-    freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
+    solaris*|freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
     sunos*)       DLLDFLAGS="${DLLDFLAGS=-assert nodefinitions}" ;;
     sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G $ldflags}" ;;
     netbsd*)      DLLDFLAGS="${DLLDFLAGS=${DLLDARG}-x -shared --whole-archive}" ;;
     aix*)         DLLDFLAGS="${DLLDFLAGS=-G -bexpall -lc}" ;;
-    solaris*|sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;
+    sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;
     openbsd*)     DLLDFLAGS="${DLLDFLAGS=-Bshareable}" ;;
   esac
   case "$host" in

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

* Re: Zsh 3.1.{6,9} patches
  2000-07-13  9:59 Zsh 3.1.{6,9} patches Fr. Br. George
@ 2000-07-13 11:12 ` Peter Stephenson
  2000-07-13 14:56   ` Clint Adams
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Peter Stephenson @ 2000-07-13 11:12 UTC (permalink / raw)
  To: Zsh hackers list, Fr. Br. George

> 	The first one is code to meke zsh truncate PS1 string backwards.
> Just use zro-started argument with %~ command to drop out the REST of
> path instead ofte HEAD. See the example (note %01~ entry):
> 	user@host:/usr..zsh/3.1.9/zsh> pwd; echo $PS1 
> 	/usr/local/lib/zsh/3.1.9/zsh
> 	%U%n%u@%B%m%b:%5(~:%01~..%3~:%~)> 

This is a good idea, but I'd prefer if it used negative integers instead of
integers beginning with zero, as in the following patch.

I've used minuses in other places where it seems appropriate.  I couldn't
try it for trailing hostname components, however, because this is
initialised from gethostname(), and although it sets $HOST it continues to
use the internal variable hostnam.  In fact, the only use of that seems to
be for printing a prompt.  Would anyone object if I got rid of hostnam and
made the prompt code read $HOST?  The only user-visible change would be
that the prompt reflects changes in $HOST, as it already does with $HOME.

> 	The second one is Solaris 2.7+ configure patch to make it compile zsh
> with libcurses.so by default instead of termcap, which is unnative.

This is perfectly believable, though I never tried.

> -    freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
> +    solaris*|freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
...
> -    solaris*|sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;
> +    sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;

Are you sure this is right?  ld and cc on this solaris system definitely
use -G, not -shared.

Index: Doc/Zsh/prompt.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/prompt.yo,v
retrieving revision 1.2
diff -u -r1.2 prompt.yo
--- Doc/Zsh/prompt.yo	2000/05/22 15:01:35	1.2
+++ Doc/Zsh/prompt.yo	2000/07/13 11:04:40
@@ -44,7 +44,8 @@
 item(tt(%/))(
 Present working directory (tt($PWD)).  If an integer follows the `tt(%)',
 it specifies a number of trailing components of tt($PWD) to show; zero
-means the whole path.
+means the whole path.  A negative integer specifies leading components,
+i.e. tt(%-1d) specifies the first component.
 )
 item(tt(%~))(
 As tt(%d) and tt(%/), but if tt($PWD) has a named directory as its prefix,
@@ -64,7 +65,8 @@
 item(tt(%m))(
 The hostname up to the first `tt(.)'.
 An integer may follow the `tt(%)' to specify
-how many components of the hostname are desired.
+how many components of the hostname are desired.  With a negative integer,
+trailing components of the hostname are shown.
 )
 item(tt(%S) LPAR()tt(%s)RPAR())(
 Start (stop) standout mode.
@@ -93,7 +95,7 @@
 currently executing, whichever was started most recently.  If there is
 none, this is equivalent to the parameter tt($0).  An integer may follow
 the `tt(%)' to specify a number of trailing path components to show; zero
-means the full path.
+means the full path.  A negative integer specifies leading components.
 )
 item(tt(%i))(
 The line number currently being executed in the script, sourced file, or
@@ -126,7 +128,7 @@
 item(tt(%_))(
 The status of the parser, i.e. the shell constructs (like `tt(if)' and
 `tt(for)') that have been started on the command line. If given an integer
-number that many strings will be printed; zero or no integer means
+number that many strings will be printed; zero or negative or no integer means
 print as many as there are.  This is most useful in prompts tt(PS2) for
 continuation lines and tt(PS4) for debugging with the tt(XTRACE) option; in
 the latter case it will also work non-interactively.
@@ -145,7 +147,8 @@
 item(tt(%v))(
 vindex(psvar, use of)
 The value of the first element of the tt(psvar) array parameter.  Following
-the `tt(%)' with an integer gives that element of the array.
+the `tt(%)' with an integer gives that element of the array.  Negative
+integers count from the end of the array.
 )
 item(tt(%{)...tt(%}))(
 Include a string as a literal escape sequence.
@@ -163,10 +166,9 @@
 and var(false-text) may both contain arbitrarily-nested escape
 sequences, including further ternary expressions.
 
-The left
-parenthesis may be preceded or followed by a positive integer var(n),
-which defaults to zero.  The test character var(x) may be any of the
-following:
+The left parenthesis may be preceded or followed by a positive integer var(n),
+which defaults to zero.  A negative integer will be multiplied by -1.
+The test character var(x) may be any of the following:
 
 startsitem()
 sxitem(tt(c))
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.1.1.13
diff -u -r1.1.1.13 prompt.c
--- Src/prompt.c	2000/03/24 10:43:21	1.1.1.13
+++ Src/prompt.c	2000/07/13 11:04:41
@@ -113,15 +113,26 @@
 
     if (npath) {
 	char *sptr;
-	for (sptr = modp + strlen(modp); sptr > modp; sptr--) {
-	    if (*sptr == '/' && !--npath) {
-		sptr++;
-		break;
+	if (npath > 0) {
+	    for (sptr = modp + strlen(modp); sptr > modp; sptr--) {
+		if (*sptr == '/' && !--npath) {
+		    sptr++;
+		    break;
+		}
 	    }
+	    if (*sptr == '/' && sptr[1] && sptr != modp)
+		sptr++;
+	    stradd(sptr);
+	} else {
+	    char cbu;
+	    for (sptr = modp+1; *sptr; sptr++)
+		if (*sptr == '/' && !++npath)
+		    break;
+	    cbu = *sptr;
+	    *sptr = 0;
+	    stradd(modp);
+	    *sptr = cbu;
 	}
-	if (*sptr == '/' && sptr[1] && sptr != modp)
-	    sptr++;
-	stradd(sptr);
     } else
 	stradd(modp);
 
@@ -199,14 +210,26 @@
     for (; *fm && *fm != endchar; fm++) {
 	arg = 0;
 	if (*fm == '%' && isset(PROMPTPERCENT)) {
-	    if (idigit(*++fm)) {
-		arg = zstrtol(fm, &fm, 10);
+	    int minus = 0;
+	    fm++;
+	    if (*fm == '-') {
+		minus = 1;
+		fm++;
 	    }
+	    if (idigit(*fm)) {
+		arg = zstrtol(fm, &fm, 10);
+		if (minus)
+		    arg *= -1;
+	    } else if (minus)
+		arg = -1;
 	    if (*fm == '(') {
 		int tc, otrunclen;
 
 		if (idigit(*++fm)) {
 		    arg = zstrtol(fm, &fm, 10);
+		} else if (arg < 0) {
+		    /* negative numbers don't make sense here */
+		    arg *= -1;
 		}
 		test = 0;
 		ss = pwd;
@@ -354,13 +377,20 @@
 	    case 'm':
 		if (!arg)
 		    arg++;
-		for (ss = hostnam; *ss; ss++)
-		    if (*ss == '.' && !--arg)
-			break;
-		t0 = *ss;
-		*ss = '\0';
-		stradd(hostnam);
-		*ss = t0;
+		if (arg < 0) {
+		    for (ss = hostnam + strlen(hostnam); ss > hostnam; ss--)
+			if (ss[-1] == '.' && !++arg)
+			    break;
+		    stradd(ss);
+		} else {
+		    for (ss = hostnam; *ss; ss++)
+			if (*ss == '.' && !--arg)
+			    break;
+		    t0 = *ss;
+		    *ss = '\0';
+		    stradd(hostnam);
+		    *ss = t0;
+		}
 		break;
 	    case 'S':
 		txtchangeset(TXTSTANDOUT, TXTNOSTANDOUT);
@@ -509,6 +539,8 @@
 	    case 'v':
 		if (!arg)
 		    arg = 1;
+		else if (arg < 0)
+		    arg += arrlen(psvar) + 1;
 		if (arrlen(psvar) >= arg)
 		    stradd(psvar[arg - 1]);
 		break;
@@ -732,7 +764,7 @@
 static int
 prompttrunc(int arg, int truncchar, int doprint, int endchar)
 {
-    if (arg) {
+    if (arg > 0) {
 	char ch = *fm, *ptr, *truncstr;
 	int truncatleft = ch == '<';
 	int w = bp - buf;
-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


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

* Re: Zsh 3.1.{6,9} patches
  2000-07-13 11:12 ` Peter Stephenson
@ 2000-07-13 14:56   ` Clint Adams
  2000-07-13 15:16     ` Peter Stephenson
  2000-07-13 15:53   ` Bart Schaefer
  2000-07-14 11:32   ` Fr. Br. George
  2 siblings, 1 reply; 7+ messages in thread
From: Clint Adams @ 2000-07-13 14:56 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list, Fr. Br. George

> Are you sure this is right?  ld and cc on this solaris system definitely
> use -G, not -shared.

He's probably got GNU binutils installed somewhere in his PATH before
/usr/ccs/bin.  We should probably make configure check for GNU ld.


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

* Re: Zsh 3.1.{6,9} patches
  2000-07-13 14:56   ` Clint Adams
@ 2000-07-13 15:16     ` Peter Stephenson
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2000-07-13 15:16 UTC (permalink / raw)
  To: Zsh hackers list

> > Are you sure this is right?  ld and cc on this solaris system definitely
> > use -G, not -shared.
> 
> He's probably got GNU binutils installed somewhere in his PATH before
> /usr/ccs/bin.  We should probably make configure check for GNU ld.

Presumably this also implies gcc, which we've already tested for.  I think
-shared is a standard option to gcc, so maybe it's enough always to used
-shared instead of -G in this case only.  I had a vague feeling there were
more gcc-specific tests in configure than there seem to be now, however, so
I'm a little disquieted.

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


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

* Re: Zsh 3.1.{6,9} patches
  2000-07-13 11:12 ` Peter Stephenson
  2000-07-13 14:56   ` Clint Adams
@ 2000-07-13 15:53   ` Bart Schaefer
  2000-07-13 16:32     ` Peter Stephenson
  2000-07-14 11:32   ` Fr. Br. George
  2 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2000-07-13 15:53 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 13, 12:12pm, Peter Stephenson wrote:
} Subject: Re: Zsh 3.1.{6,9} patches
}
} Would anyone object if I got rid of hostnam and made the prompt code
} read $HOST? The only user-visible change would be that the prompt
} reflects changes in $HOST, as it already does with $HOME.

I think that would be fine.


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: Zsh 3.1.{6,9} patches
  2000-07-13 15:53   ` Bart Schaefer
@ 2000-07-13 16:32     ` Peter Stephenson
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2000-07-13 16:32 UTC (permalink / raw)
  To: Zsh hackers list

Bart wrote:
> On Jul 13, 12:12pm, Peter Stephenson wrote:
> } Subject: Re: Zsh 3.1.{6,9} patches
> }
> } Would anyone object if I got rid of hostnam and made the prompt code
> } read $HOST? The only user-visible change would be that the prompt
> } reflects changes in $HOST, as it already does with $HOME.
> 
> I think that would be fine.

Here it is.  We save almost a quarter of a kilobyte, since hostnam was
always initialised to 256 bytes which were never freed.  (And I checked out
this morning's %-1m, which allows you to display your .com address in the
prompt.)

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.5
diff -u -r1.5 init.c
--- Src/init.c	2000/05/27 08:32:58	1.5
+++ Src/init.c	2000/07/13 16:26:23
@@ -595,9 +595,6 @@
     gettimeofday(&shtimer, &dummy_tz);	/* init $SECONDS */
     srand((unsigned int)(shtimer.tv_sec + shtimer.tv_usec)); /* seed $RANDOM */
 
-    hostnam     = (char *) zalloc(256);
-    gethostname(hostnam, 256);
-
     /* Set default path */
     path    = (char **) zalloc(sizeof(*path) * 5);
     path[0] = ztrdup("/bin");
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.22
diff -u -r1.22 params.c
--- Src/params.c	2000/07/04 15:04:17	1.22
+++ Src/params.c	2000/07/13 16:26:27
@@ -56,7 +56,6 @@
 /**/
 char *argzero,		/* $0           */
      *home,		/* $HOME        */
-     *hostnam,		/* $HOST        */
      *nullcmd,		/* $NULLCMD     */
      *oldpwd,		/* $OLDPWD      */
      *zoptarg,		/* $OPTARG      */
@@ -458,7 +457,7 @@
     Param ip, pm;
     char **new_environ, **envp, **envp2, **sigptr, **t;
     char **old_environ = environ;
-    char buf[50], *str, *iname;
+    char buf[50], *str, *iname, *hostnam;
     int num_env, oae = opts[ALLEXPORT];
 #ifdef HAVE_UNAME
     struct utsname unamebuf;
@@ -494,7 +493,12 @@
     setsparam("TMPPREFIX", ztrdup(DEFAULT_TMPPREFIX));
     setsparam("TIMEFMT", ztrdup(DEFAULT_TIMEFMT));
     setsparam("WATCHFMT", ztrdup(default_watchfmt));
+
+    hostnam = (char *)zalloc(256);
+    gethostname(hostnam, 256);
     setsparam("HOST", ztrdup(hostnam));
+    zfree(hostnam, 256);
+
     setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username));
 
     /* Copy the environment variables we are inheriting to dynamic *
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.2
diff -u -r1.2 prompt.c
--- Src/prompt.c	2000/07/13 11:20:46	1.2
+++ Src/prompt.c	2000/07/13 16:26:30
@@ -201,7 +201,7 @@
 static int
 putpromptchar(int doprint, int endchar)
 {
-    char *ss, *tmbuf = NULL;
+    char *ss, *tmbuf = NULL, *hostnam;
     int t0, arg, test, sep;
     struct tm *tm;
     time_t timet;
@@ -372,11 +372,14 @@
 		bp += strlen(bp);
 		break;
 	    case 'M':
-		stradd(hostnam);
+		if ((hostnam = getsparam("HOST")))
+		    stradd(hostnam);
 		break;
 	    case 'm':
 		if (!arg)
 		    arg++;
+		if (!(hostnam = getsparam("HOST")))
+		    break;
 		if (arg < 0) {
 		    for (ss = hostnam + strlen(hostnam); ss > hostnam; ss--)
 			if (ss[-1] == '.' && !++arg)

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


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

* Re: Zsh 3.1.{6,9} patches
  2000-07-13 11:12 ` Peter Stephenson
  2000-07-13 14:56   ` Clint Adams
  2000-07-13 15:53   ` Bart Schaefer
@ 2000-07-14 11:32   ` Fr. Br. George
  2 siblings, 0 replies; 7+ messages in thread
From: Fr. Br. George @ 2000-07-14 11:32 UTC (permalink / raw)
  To: Peter Stephenson

On Thu, 13 Jul 2000, Peter Stephenson wrote:
> > -    freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
> > +    solaris*|freebsd*|linux*|irix*|osf*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
> ...
> > -    solaris*|sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;
> > +    sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;
> 
> Are you sure this is right?  ld and cc on this solaris system definitely
> use -G, not -shared.
	The Configure thinks GCC is better. So do I. The script needs
more complex patch to recognize where it uses CC or GCC.

			George V Kouryachy (aka Fr. Br. George)
			email: frbrgeorge@intelligencia.com



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

end of thread, other threads:[~2000-07-14 11:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-13  9:59 Zsh 3.1.{6,9} patches Fr. Br. George
2000-07-13 11:12 ` Peter Stephenson
2000-07-13 14:56   ` Clint Adams
2000-07-13 15:16     ` Peter Stephenson
2000-07-13 15:53   ` Bart Schaefer
2000-07-13 16:32     ` Peter Stephenson
2000-07-14 11:32   ` Fr. Br. George

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).