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

Further special parameter changes



The patch below further reduces the number of special parameters. It makes
TTY, FCEDIT, HOST, MAIL, TIMEFMT, TMPPREFIX, WATCHFMT and signals non-special.
If zsh is invoked as sh/ksh, it removes the ARGC, status, prompt, PROMPT2,
PROMPT3, PROMPT4 and argv parameters. These parameters are not sh/ksh
compatible and all of them has an equivalent compatible pair.  Without this
patch sh scripts doing something like

foo ; status=$? ; if [ $status = ...

will fail because $status is a special parameter (I had such a script and this
idiom is quite common in sh scripts).

The patch depends on my previous patch which removed LOGNAME from the special
parameter list (art. 268).  Or you can apply it to my release as well which
already contains the LOGNAME patch.

Bye,
   Zoltan

*** 1.8	1995/07/06 12:28:04
--- Src/globals.h	1995/07/07 23:09:17
***************
*** 91,98 ****
   
  EXTERN int userdirsz, userdirct;
   
- EXTERN char *mailfile;
-  
  EXTERN char *yytext;
   
  /* error/break flag */
--- 91,96 ----
***************
*** 324,339 ****
  EXTERN char *rprompt;		/* $RPROMPT    */
  EXTERN char *sprompt;
  
- EXTERN char *timefmt;		/* $TIMEFMT    */
- EXTERN char *watchfmt;		/* $WATCHFMT   */
  EXTERN char *wordchars;
- EXTERN char *fceditparam;
- EXTERN char *tmpprefix;		/* $TMPPREFIX  */
  EXTERN char *rstring, *Rstring;
  EXTERN char *postedit;
  
  EXTERN char *hostnam;           /* from gethostname */
- EXTERN char *hostvar;           /* $HOST */
  EXTERN char *home;              /* $HOME */
  EXTERN char **pparams;          /* $argv */
  
--- 322,332 ----
***************
*** 541,552 ****
  EXTERN int noaliases;
  
  #ifdef GLOBALS
- /* signal names */
- char **sigptr = sigs;
  /* tokens */
  char *ztokens = "#$^*()$=|{}[]`<>?~`,'\"\\";
  #else
! extern char *ztokens, **sigptr;
  #endif
  
  /* $histchars */
--- 534,543 ----
  EXTERN int noaliases;
  
  #ifdef GLOBALS
  /* tokens */
  char *ztokens = "#$^*()$=|{}[]`<>?~`,'\"\\";
  #else
! extern char *ztokens;
  #endif
  
  /* $histchars */
*** 1.4	1995/07/04 14:23:18
--- Src/params.h	1995/07/07 23:09:17
***************
*** 51,57 ****
  #define IPDEF1(A,B,C,D) {NULL,A,NULL,IFN(C),IFN(B),10,\
  		PM_INTEGER|PM_SPECIAL|D,NULL,NULL,NULL,NULL,0}
  	IPDEF1("#", poundgetfn, IFN(nullsetfn), PM_READONLY),
- 	IPDEF1("ARGC", poundgetfn, IFN(nullsetfn), PM_READONLY),
  	IPDEF1("ERRNO", errnogetfn, IFN(nullsetfn), PM_READONLY),
  	IPDEF1("GID", gidgetfn, gidsetfn, 0),
  	IPDEF1("EGID", egidgetfn, egidsetfn, 0),
--- 51,56 ----
***************
*** 82,88 ****
  	IPDEF4("!", &lastpid),
  	IPDEF4("$", &mypid),
  	IPDEF4("?", &lastval),
- 	IPDEF4("status", &lastval),
  	IPDEF4("LINENO", &lineno),
  	IPDEF4("PPID", &ppid),
  
--- 81,86 ----
***************
*** 106,127 ****
  #define IPDEF6(A,B) {NULL,A,NULL,IFN(nullsetfn),IFN(strvargetfn),0,\
  		PM_SCALAR|PM_READONLY|PM_SPECIAL,(void *)B,NULL,NULL,NULL,0}
  	IPDEF6("PWD", &pwd),
- 	IPDEF6("TTY", &ttystrname),
  
  #define IPDEF7(A,B) {NULL,A,NULL,IFN(strvarsetfn),IFN(strvargetfn),0,\
  		PM_SCALAR|PM_SPECIAL,(void *)B,NULL,NULL,NULL,0}
- 	IPDEF7("FCEDIT", &fceditparam),
- 	IPDEF7("HOST", &hostvar),
  	IPDEF7("OLDPWD", &oldpwd),
  	IPDEF7("OPTARG", &zoptarg),
- 	IPDEF7("MAIL", &mailfile),
  	IPDEF7("NULLCMD", &nullcmd),
  	IPDEF7("POSTEDIT", &postedit),
- 	IPDEF7("prompt", &prompt),
- 	IPDEF7("PROMPT", &prompt),
- 	IPDEF7("PROMPT2", &prompt2),
- 	IPDEF7("PROMPT3", &prompt3),
- 	IPDEF7("PROMPT4", &prompt4),
  	IPDEF7("READNULLCMD", &readnullcmd),
  	IPDEF7("RPROMPT", &rprompt),
  	IPDEF7("PS1", &prompt),
--- 104,116 ----
***************
*** 130,138 ****
  	IPDEF7("PS4", &prompt4),
  	IPDEF7("RPS1", &rprompt),
  	IPDEF7("SPROMPT", &sprompt),
- 	IPDEF7("TIMEFMT", &timefmt),
- 	IPDEF7("TMPPREFIX", &tmpprefix),
- 	IPDEF7("WATCHFMT", &watchfmt),
  	IPDEF7("0", &argzero),
  
  #define IPDEF8(A,B,C) {NULL,A,NULL,IFN(colonarrsetfn),IFN(colonarrgetfn),0,\
--- 119,124 ----
***************
*** 157,169 ****
  	IPDEF9("manpath", 0, &manpath, "MANPATH"),
  	IPDEF9("watch", 0, &watch, "WATCH"),
  	IPDEF9("psvar", 0, &psvar, "PSVAR"),
- 	IPDEF9("signals", PM_READONLY, &sigptr, NULL),
- 	IPDEF9("argv", 0, &pparams, NULL),
  	IPDEF9("*", 0, &pparams, NULL),
  	IPDEF9("@", 0, &pparams, NULL),
  
  	{NULL, "path", NULL, IFN(pathsetfn), IFN(pathgetfn), 0,
  	 PM_ARRAY | PM_SPECIAL | PM_UNIQUE, NULL, NULL, "PATH", NULL, 0},
  
  	{NULL,}
      };
--- 143,166 ----
  	IPDEF9("manpath", 0, &manpath, "MANPATH"),
  	IPDEF9("watch", 0, &watch, "WATCH"),
  	IPDEF9("psvar", 0, &psvar, "PSVAR"),
  	IPDEF9("*", 0, &pparams, NULL),
  	IPDEF9("@", 0, &pparams, NULL),
  
  	{NULL, "path", NULL, IFN(pathsetfn), IFN(pathgetfn), 0,
  	 PM_ARRAY | PM_SPECIAL | PM_UNIQUE, NULL, NULL, "PATH", NULL, 0},
+ 
+ 	{NULL,},
+ 
+ 	/* The following parameters are not avaible in sh/ksh compatibility *
+ 	 * mode. All of these has sh compatible equivalents.                */
+ 	IPDEF1("ARGC", poundgetfn, IFN(nullsetfn), PM_READONLY),
+ 	IPDEF4("status", &lastval),
+ 	IPDEF7("prompt", &prompt),
+ 	IPDEF7("PROMPT", &prompt),
+ 	IPDEF7("PROMPT2", &prompt2),
+ 	IPDEF7("PROMPT3", &prompt3),
+ 	IPDEF7("PROMPT4", &prompt4),
+ 	IPDEF9("argv", 0, &pparams, NULL),
  
  	{NULL,}
      };
*** 1.12	1995/07/04 18:21:23
--- Src/params.c	1995/07/23 00:43:13
***************
*** 44,50 ****
  {
      struct iparam *ip;
      Param pm;
!     char **old_environ, **envp, **envp2;
      char buf[50], *str, *iname;
      int num_env;
  
--- 44,50 ----
  {
      struct iparam *ip;
      Param pm;
!     char **old_environ, **envp, **envp2, **sigptr, **t;
      char buf[50], *str, *iname;
      int num_env;
  
***************
*** 63,72 ****
      /* Add the special parameter to the hash table */
      for (ip = special_param; ip->nam; ip++)
  	paramtab->addnode(paramtab, ztrdup(ip->nam), ip);
! 
!     argvparam = (Param) paramtab->getnode(paramtab, "argv");
! 
      setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username));
      noerrs = 1;
  
      /* Copy the environment variables we are inheriting to dynamic *
--- 63,83 ----
      /* Add the special parameter to the hash table */
      for (ip = special_param; ip->nam; ip++)
  	paramtab->addnode(paramtab, ztrdup(ip->nam), ip);
!     if (strcmp(zsh_name, "sh") && strcmp(zsh_name, "ksh"))
! 	while ((++ip)->nam)
! 	    paramtab->addnode(paramtab, ztrdup(ip->nam), ip);
! 
!     argvparam = (Param) paramtab->getnode(paramtab, "*");
! 
!     /* Add standard non-special parameters which have to be       *
!      * initialized before we copy the environment variables since *
!      * zsh mustn't override their values in the environment.      */
      setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username));
+     setsparam("FCEDIT", ztrdup(DEFAULT_FCEDIT));
+     setsparam("HOST", ztrdup(hostnam));
+     setsparam("TIMEFMT", ztrdup(DEFAULT_TIMEFMT));
+     setsparam("WATCHFMT", ztrdup(DEFAULT_WATCHFMT));
+     setsparam("TMPPREFIX", ztrdup(DEFAULT_TMPPREFIX));
      noerrs = 1;
  
      /* Copy the environment variables we are inheriting to dynamic *
***************
*** 123,131 ****
--- 134,145 ----
      setsparam("HOSTTYPE", ztrdup(HOSTTYPE));
      setsparam("MACHTYPE", ztrdup(MACHTYPE));
      setsparam("OSTYPE", ztrdup(OSTYPE));
+     setsparam("TTY", ztrdup(ttystrname));
      setsparam("VENDOR", ztrdup(VENDOR));
      setsparam("ZSH_NAME", ztrdup(zsh_name));
      setsparam("ZSH_VERSION", ztrdup(ZSH_VERSION));
+     setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));
+     for (t = sigs; (*sigptr++ = ztrdup(*t++)); );
  
      noerrs = 0;
  }
*** 1.10	1995/07/07 18:32:30
--- Src/init.c	1995/07/23 00:18:56
***************
*** 513,523 ****
      if (!(ttystrname = ztrdup(ttyname(SHTTY))))
  	ttystrname = ztrdup("");
      ifs         = ztrdup(" \t\n");
-     timefmt     = ztrdup(DEFAULT_TIMEFMT);
-     watchfmt    = ztrdup(DEFAULT_WATCHFMT);
      wordchars   = ztrdup(DEFAULT_WORDCHARS);
-     fceditparam = ztrdup(DEFAULT_FCEDIT);
-     tmpprefix   = ztrdup(DEFAULT_TMPPREFIX);
      postedit    = ztrdup("");
      underscore  = ztrdup("");
  
--- 513,519 ----
***************
*** 533,539 ****
  
      hostnam     = (char *) zalloc(256);
      gethostname(hostnam, 256);
-     hostvar     = ztrdup(hostnam);
  
      compctlsetup();
      namdirs     = (Nameddirs) zcalloc(sizeof(*namdirs) * 2);
--- 529,534 ----
*** 1.1	1995/06/23 07:48:00
--- Src/watch.c	1995/07/23 00:26:00
***************
*** 377,388 ****
  dowatch(void)
  {
      char **s = watch;
!     char *fmt = (watchfmt) ? watchfmt : DEFAULT_WATCHFMT;
      FILE *in;
      int utabsz = 0, utabmax = wtabsz + 4, uct, wct;
      STRUCT_UTMP *utab, *uptr, *wptr;
      struct stat st;
  
      holdintr();
      if (!fmt)
  	fmt = "%n has %a %l from %m.";
--- 377,390 ----
  dowatch(void)
  {
      char **s = watch;
!     char *fmt = getsparam("WATCHFMT");
      FILE *in;
      int utabsz = 0, utabmax = wtabsz + 4, uct, wct;
      STRUCT_UTMP *utab, *uptr, *wptr;
      struct stat st;
  
+     if (!fmt)
+ 	fmt = DEFAULT_WATCHFMT;
      holdintr();
      if (!fmt)
  	fmt = "%n has %a %l from %m.";
*** 1.1	1995/06/18 06:44:03
--- Src/jobs.c	1995/07/23 00:22:45
***************
*** 696,702 ****
      if (percent > 100)
          percent = 100;   /* just to make it look right */
  
!     for (s = (timefmt ? timefmt : DEFAULT_TIMEFMT); *s; s++)
  	if (*s == '%')
  	    switch (*++s) {
  	    case 'E':
--- 696,704 ----
      if (percent > 100)
          percent = 100;   /* just to make it look right */
  
!     if (!(s = getsparam("TIMEFMT")))
! 	s = DEFAULT_TIMEFMT;
!     for (; *s; s++)
  	if (*s == '%')
  	    switch (*++s) {
  	    case 'E':
*** 1.25	1995/07/17 20:57:39
--- Src/builtin.c	1995/07/23 00:31:06
***************
*** 2703,2715 ****
  		((out = fdopen(tempfd, "w")) == NULL)) {
  	    zwarnnam("fc", "can't open temp file: %e", NULL, errno);
  	} else {
! 	    if (!fclist(out, 0, ops['r'], 0, 0, first, last, asgf, com))
! 		if (fcedit(auxdata ? auxdata :
! 			   (fceditparam ? fceditparam : DEFAULT_FCEDIT), fil))
  		    if (stuff(fil))
  			zwarnnam("fc", "%e: %s", s, errno);
  		    else
  			retval = 0;
  	}
  	unlink(fil);
      }
--- 2703,2717 ----
  		((out = fdopen(tempfd, "w")) == NULL)) {
  	    zwarnnam("fc", "can't open temp file: %e", NULL, errno);
  	} else {
! 	    if (!fclist(out, 0, ops['r'], 0, 0, first, last, asgf, com)) {
! 		char *editor = auxdata ? auxdata : getsparam("FCEDIT");
! 
! 		if (fcedit(editor ? editor : DEFAULT_FCEDIT, fil))
  		    if (stuff(fil))
  			zwarnnam("fc", "%e: %s", s, errno);
  		    else
  			retval = 0;
+ 	    }
  	}
  	unlink(fil);
      }
*** 1.12	1995/07/14 14:24:06
--- Src/exec.c	1995/07/23 00:27:07
***************
*** 2055,2060 ****
--- 2055,2062 ----
  char *
  gettemp(void)
  {
+     char *tmpprefix = getsparam("TMPPREFIX");
+ 
      return ((char *) mktemp(dyncat((tmpprefix ? tmpprefix : DEFAULT_TMPPREFIX), "XXXXXX")));
  }
  
*** 1.13	1995/07/14 14:18:35
--- Src/utils.c	1995/07/23 00:03:39
***************
*** 589,597 ****
  	return;
      diff = (int)difftime(time(NULL), lastmailcheck);
      if (diff > mailcheck) {
  	if (mailpath && *mailpath && **mailpath)
  	    checkmailpath(mailpath);
! 	else if (mailfile && *mailfile) {
  	    char *x[2];
  
  	    x[0] = mailfile;
--- 589,599 ----
  	return;
      diff = (int)difftime(time(NULL), lastmailcheck);
      if (diff > mailcheck) {
+ 	char *mailfile;
+ 
  	if (mailpath && *mailpath && **mailpath)
  	    checkmailpath(mailpath);
! 	else if ((mailfile = getsparam("MAIL")) && *mailfile) {
  	    char *x[2];
  
  	    x[0] = mailfile;
*** 1.8	1995/07/11 15:09:08
--- Doc/zshparam.1	1995/07/22 23:58:07
***************
*** 127,133 ****
  The number of positional parameters in decimal.
  .TP
  .B ARGC
! Same as \fB#\fP.
  .TP
  .B $
  The process id of this shell.
--- 127,133 ----
  The number of positional parameters in decimal.
  .TP
  .B ARGC
! Same as \fB#\fP. It has no special meaning in sh/ksh compatibility mode.
  .TP
  .B $
  The process id of this shell.
***************
*** 140,155 ****
  An array containing the positional parameters.
  .TP
  .B argv
! Same as \fB*\fP.
  .TP
  .B @
! Same as \fBargv[@]\fP.
  .TP
  .B ?
  The exit value returned by the last command.
  .TP
  .B status
! Same as \fB?\fP.
  .TP
  .B _
  The last argument of the previous command.
--- 140,155 ----
  An array containing the positional parameters.
  .TP
  .B argv
! Same as \fB*\fP. It has no special meaning in sh/ksh compatibility mode.
  .TP
  .B @
! Same as \fBargv[@]\fP but it can be used in sh/ksh compatibility mode.
  .TP
  .B ?
  The exit value returned by the last command.
  .TP
  .B status
! Same as \fB?\fP. It has no special meaning in sh/ksh compatibility mode.
  .TP
  .B _
  The last argument of the previous command.
***************
*** 393,400 ****
  .TP
  .B MAIL
  If this parameter is set and \fBmailpath\fP is not set,
! the shell looks for mail in the specified file.  By default it is set to
! the user's system mailbox.
  .TP
  .B MAILCHECK
  The interval in seconds between checks for new mail. 
--- 393,399 ----
  .TP
  .B MAIL
  If this parameter is set and \fBmailpath\fP is not set,
! the shell looks for mail in the specified file.
  .TP
  .B MAILCHECK
  The interval in seconds between checks for new mail. 
***************
*** 432,438 ****
  This string is output whenever the line editor exits.
  It usually contains termcap strings to reset the terminal.
  .TP
! .B PROMPT
  The primary prompt string, printed before a command is read;
  the default is "%m%# ".  If the escape sequence takes an optional
  integer, it should appear between the '%' and the next character of the
--- 431,437 ----
  This string is output whenever the line editor exits.
  It usually contains termcap strings to reset the terminal.
  .TP
! .B PS1
  The primary prompt string, printed before a command is read;
  the default is "%m%# ".  If the escape sequence takes an optional
  integer, it should appear between the '%' and the next character of the
***************
*** 621,649 ****
  .PP
  .PD 0
  .TP
! .B PROMPT2
  The secondary prompt, printed when the shell needs more information
  to complete a command.
! Recognizes the same escape sequences as \fB$PROMPT\fP.
  The default is "> ".
  .TP
! .B PROMPT3
  Selection prompt used within a \fBselect\fP loop.
! Recognizes the same escape sequences as \fB$PROMPT\fP.
  The default is "?# ".
  .TP
! .B PROMPT4
  The execution trace prompt.  Default is "+ ".
  .TP
! .B PS1
  .TP
! .B PS2
  .TP
! .B PS3
  .TP
! .B PS4
! Same as \fBPROMPT\fP, \fBPROMPT2\fP, \fBPROMPT3\fP, and \fBPROMPT4\fP,
! respectively.
  .TP
  .B psvar (PSVAR)
  An array (colon-separated list) whose first nine values can be used in
--- 620,649 ----
  .PP
  .PD 0
  .TP
! .B PS2
  The secondary prompt, printed when the shell needs more information
  to complete a command.
! Recognizes the same escape sequences as \fB$PS1\fP.
  The default is "> ".
  .TP
! .B PS3
  Selection prompt used within a \fBselect\fP loop.
! Recognizes the same escape sequences as \fB$PS1\fP.
  The default is "?# ".
  .TP
! .B PS4
  The execution trace prompt.  Default is "+ ".
  .TP
! .B PROMPT
  .TP
! .B PROMPT2
  .TP
! .B PROMPT3
  .TP
! .B PROMPT4
! Same as \fBPS1\fP, \fBPS2\fP, \fBPS3\fP, and \fBPS4\fP,
! respectively.  These parameters do not have any special
! meaning in sh/ksh compatibility mode.
  .TP
  .B psvar (PSVAR)
  An array (colon-separated list) whose first nine values can be used in
***************
*** 651,657 ****
  vice versa.
  .TP
  .B prompt
! Same as \fBPROMPT\fP.
  .TP
  .B READNULLCMD
  The command name to assume if a single input redirection
--- 651,657 ----
  vice versa.
  .TP
  .B prompt
! Same as \fBPS1\fP. It has no special meaning in sh/ksh compatibility mode.
  .TP
  .B READNULLCMD
  The command name to assume if a single input redirection



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