v16i079: MSDOS Shell (sh) Implementation 1.6.4, Patch02/02

Ian Stewartson istewart at datlog.co.uk
Thu Jan 17 06:53:07 AEST 1991


Submitted-by: istewart at datlog.co.uk (Ian Stewartson)
Posting-number: Volume 16, Issue 79
Archive-name: ms_sh-1.6/patch02
Patch-To: ms_sh-1.6: Volume 12, Issue 19-26

# this is SH.02 (part 2 of a multipart archive)
# do not concatenate these parts, unpack them in order with /bin/sh
# file Patch1.6.4 continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 2; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
	echo 'x - still skipping Patch1.6.4'
else
echo 'x - continuing file Patch1.6.4'
sed 's/^X//' << 'SHAR_EOF' >> 'Patch1.6.4' &&
X      {
! 	if ((cp = evalstr (*(wp++), DOSUB)) && gmatch (w, cp, FALSE))
X  	    return &t1->left;
X      }
X  
--- 861,868 ----
X  
X      for (wp = t1->words; *wp != (char *)NULL;)
X      {
! 	if ((cp = evalstr (*(wp++), DOSUB)) &&
! 	    gmatch (w, cp, FALSE, (char **)NULL, GM_ALL))
X  	    return &t1->left;
X      }
X  
***************
*** 922,928 ****
X  	    {
X  
X  /* No entry for the file - if the file exists, execute it as a shell
!  * script
X   */
X  		case ENOENT:
X  		    if ((res = O_for_execute (p_name, &params, &nargc)) >= 0)
--- 949,955 ----
X  	    {
X  
X  /* No entry for the file - if the file exists, execute it as a shell
!  * script.  If we never find the file, return the error
X   */
X  		case ENOENT:
X  		    if ((res = O_for_execute (p_name, &params, &nargc)) >= 0)
***************
*** 933,939 ****
X  
X  		    else if (!Check_for_bat_file (p_name))
X  		    {
! 			em = "not found";
X  			eloop = FALSE;
X  			break;
X  		    }
--- 960,966 ----
X  
X  		    else if (!Check_for_bat_file (p_name))
X  		    {
! 			errno = ENOENT;
X  			eloop = FALSE;
X  			break;
X  		    }
***************
*** 953,958 ****
--- 980,986 ----
X  			      == (char **)NULL)
X  		    {
X  			em = strerror (ENOMEM);
+ 			errno = ENOMEM;
X  			break;
X  		    }
X  
***************
*** 1017,1022 ****
--- 1045,1051 ----
X  
X  		    em = "no Shell";
X  		    eloop = FALSE;
+ 		    errno = ENOEXEC;
X  		    break;
X  
X  		case ENOEXEC:
***************
*** 1039,1048 ****
X  	} while ((sp != (char *)NULL) && !eloop);
X      }
X  
!     print_warn ("%s: %s\n", c, em);
X  
!     if (!d_flag)
! 	exit (-1);
X  
X      return -1;
X  }
--- 1068,1082 ----
X  	} while ((sp != (char *)NULL) && !eloop);
X      }
X  
! /* If we found the program - report the error */
X  
!     if (errno != ENOENT)
!     {
! 	print_warn (EF_msg, c, em);
! 
! 	if (!d_flag)
! 	    exit (-1);
!     }
X  
X      return -1;
X  }
Index: shell/sh4.c
Prereq: 1.9
*** ../sh16.3/shell/sh4.c	Fri Aug 17 21:34:51 1990
--- shell/sh4.c	Tue Nov  6 19:22:00 1990
***************
*** 13,21 ****
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh4.c 1.9 90/08/16 10:29:27 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh4.c $
X   * Revision 1.9  90/08/16  10:29:27  Ian_Stewartson
X   * Add support from String length option in ${}.
X   * Restore the memcpys
--- 13,27 ----
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh4.c 1.11 90/09/11 20:01:23 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh4.c $
+  * Revision 1.11  90/09/11  20:01:23  Ian_Stewartson
+  * Fix ${#*} functionality to match POSIX
+  * 
+  * Revision 1.10  90/08/24  21:56:18  Ian_Stewartson
+  * Add support for POSIX macro commands {x#y} and {x%y}
+  * 
X   * Revision 1.9  90/08/16  10:29:27  Ian_Stewartson
X   * Add support from String length option in ${}.
X   * Restore the memcpys
***************
*** 505,511 ****
X  
X      *e.linep = 0;
X  
! /* Scan for =-+? in string */
X  
X      if (*s)
X      {
--- 511,517 ----
X  
X      *e.linep = 0;
X  
! /* Scan for =-+?%# in string */
X  
X      if (*s)
X      {
***************
*** 514,526 ****
X  
X  /* Check for end character other than null (=-+?) */
X  
! 	    if (any (*cp, "=-+?"))
X  	    {
X  		c = *cp;
X  
! /* Check for case of :[=-+?].  If found - set flag */
! 
! 		if (*(cp - 1) == ':')
X  		{
X  		    colon_f = TRUE;
X  		    *(cp - 1) = 0;
--- 520,533 ----
X  
X  /* Check for end character other than null (=-+?) */
X  
! 	    if (any (*cp, "=-+?%#"))
X  	    {
X  		c = *cp;
X  
! /* Skip next section in case of % or #.  Check for case of :[=-+?]. 
!  * If found - set flag
!  */
! 		if ((c != '%') && (c != '#') && (*(cp - 1) == ':'))
X  		{
X  		    colon_f = TRUE;
X  		    *(cp - 1) = 0;
***************
*** 553,564 ****
X  
X  	    if (hash_f)
X  	    {
! 		int	slen, n;
! 
! 		for (n = 1, slen = 0; dolv[n] != (char *)NULL;
! 		     slen += (strlen (dolv[n++]) + 1));
! 
! 		dolp = strsave (putn (slen - 1), areanum);
X  		PUSHIO (aword, dolp, quoted ? qstrchar : strchar);
X  	    }
X  
--- 560,566 ----
X  
X  	    if (hash_f)
X  	    {
! 		dolp = strsave (putn (dolc - 1), areanum);
X  		PUSHIO (aword, dolp, quoted ? qstrchar : strchar);
X  	    }
X  
***************
*** 628,638 ****
X  	}
X      }
X  
!     else if (c == '+')
! 	dolp = strsave (cp, areanum);
X  
! /* Check for unset values */
X  
X      if (FL_TEST ('u') && dolp == null)
X      {
X  	print_error ("sh: unset variable %s\n", s);
--- 630,678 ----
X  	}
X      }
X  
! /* String exists - other processing */
X  
!     else
!     {
! 	char		*pos;		/* Position for substitute	*/
! 	char		*tsp;
! 	int		mode;		/* Mode for substitute		*/
X  
+ 	switch (c)
+ 	{
+ 	    case '+':
+ 		dolp = strsave (cp, areanum);
+ 		break;
+ 
+ 	    case '#':			/* Remove prefix */
+ 	    case '%':			/* Remove suffix */
+ 		mode = GM_SHORTEST;
+ 
+ 		if (*cp == c)
+ 		{
+ 		    mode = GM_LONGEST;
+ 		    ++cp;
+ 		}
+ 
+ 		if (c == '#')
+ 		{
+ 		    if (gmatch (dolp, cp, FALSE, &pos, mode))
+ 			dolp = strsave (pos, areanum);
+ 		}
+ 
+ 		else if (gmatch_suffix (dolp, cp, FALSE, &pos, mode))
+ 		{
+ 		    tsp = strsave (dolp, areanum);
+ 		    tsp[pos - dolp] = 0;
+ 		    dolp = tsp;
+ 		}
+ 
+ 		break;
+ 	}
+     }
+ 
+ /* Check for unset values */
+ 
X      if (FL_TEST ('u') && dolp == null)
X      {
X  	print_error ("sh: unset variable %s\n", s);
***************
*** 964,970 ****
X  
X  /* Check for a match */
X  
! 	if (gmatch (dname, gp, TRUE))
X  	{
X  
X  /* If there are no special characters in the new full name, the file must
--- 1004,1010 ----
X  
X  /* Check for a match */
X  
! 	if (gmatch (dname, gp, TRUE, (char **)NULL, GM_ALL))
X  	{
X  
X  /* If there are no special characters in the new full name, the file must
***************
*** 1191,1197 ****
X  
X  	    *t_drive = (char)(s_drive + 'a' - 1);
X  
! 	    if ((y_drive == s_drive) && gmatch (t_drive, pattern, TRUE))
X  	    {
X  		*new_pattern = *t_drive;
X  		globname (new_pattern, &new_pattern[2]);
--- 1231,1238 ----
X  
X  	    *t_drive = (char)(s_drive + 'a' - 1);
X  
! 	    if ((y_drive == s_drive) &&
! 		 gmatch (t_drive, pattern, TRUE, (char **)NULL, GM_ALL))
X  	    {
X  		*new_pattern = *t_drive;
X  		globname (new_pattern, &new_pattern[2]);
Index: shell/sh8.c
Prereq: 1.12
*** ../sh16.3/shell/sh8.c	Fri Aug 17 21:35:41 1990
--- shell/sh8.c	Tue Nov  6 19:22:21 1990
***************
*** 12,18 ****
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh8.c 1.12 90/08/14 23:31:08 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh8.c $
X   * Revision 1.12  90/08/14  23:31:08  Ian_Stewartson
--- 12,18 ----
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh8.c 1.12 90/08/14 23:31:08 Ian_Stewartson Exp Locker: Ian_Stewartson $
X   *
X   *    $Log:	sh8.c $
X   * Revision 1.12  90/08/14  23:31:08  Ian_Stewartson
Index: shell/sh6.c
Prereq: 1.14
*** ../sh16.3/shell/sh6.c	Fri Aug 17 21:35:10 1990
--- shell/sh6.c	Tue Nov  6 19:22:29 1990
***************
*** 13,21 ****
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh6.c 1.14 90/08/14 23:34:49 MS_user Exp $
X   *
X   *    $Log:	sh6.c $
X   * Revision 1.14  90/08/14  23:34:49  MS_user
X   * Changed for release 1.6.3
X   * 
--- 13,24 ----
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: D:/SRC/SHELL/RCS/sh6.c 1.15 90/09/11 19:42:15 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh6.c $
+  * Revision 1.15  90/09/11  19:42:15  Ian_Stewartson
+  * Version 1.6.4
+  * 
X   * Revision 1.14  90/08/14  23:34:49  MS_user
X   * Changed for release 1.6.3
X   * 
***************
*** 73,79 ****
X  #include <string.h>
X  #include "sh.h"
X  
! static char	*Copy_Right1 = "MS-DOS SH Version 1.6.3 - %s (DOS %d.%d)\n";
X  static char	*Copy_Right2 = "Copyright (c) Data Logic Ltd and Charles Forsyth 1990\n";
X  char		**dolv;		/* Parameter array			*/
X  int		dolc;		/* Number of entries in parameter array	*/
--- 76,82 ----
X  #include <string.h>
X  #include "sh.h"
X  
! static char	*Copy_Right1 = "MS-DOS SH Version 1.6.4 - %s (DOS %d.%d)\n";
X  static char	*Copy_Right2 = "Copyright (c) Data Logic Ltd and Charles Forsyth 1990\n";
X  char		**dolv;		/* Parameter array			*/
X  int		dolc;		/* Number of entries in parameter array	*/
Index: shell/sh2.c
Prereq: 1.6
*** ../sh16.3/shell/sh2.c	Fri Aug 17 21:34:11 1990
--- shell/sh2.c	Tue Nov  6 19:22:53 1990
***************
*** 13,21 ****
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh2.c 1.6 90/08/14 23:30:26 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh2.c $
X   * Revision 1.6  90/08/14  23:30:26  Ian_Stewartson
X   * Add support for read/write IO
X   * 
--- 13,24 ----
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh2.c 1.7 90/09/11 20:00:01 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh2.c $
+  * Revision 1.7  90/09/11  20:00:01  Ian_Stewartson
+  * Add support for $() POSIX functionality
+  * 
X   * Revision 1.6  90/08/14  23:30:26  Ian_Stewartson
X   * Add support for read/write IO
X   * 
***************
*** 733,744 ****
X  	case 0:
X  	    return c;
X  
X  	case '$':
X  	    *e.linep++ = (char)c;
X  
! 	    if ((c = Getc(0)) == '{') 
X  	    {
! 		if ((c = collect (c, '}')) != '\0')
X  		    return (c);
X  
X  		goto pack;
--- 736,749 ----
X  	case 0:
X  	    return c;
X  
+ /* Allow $name, ${name}, $(command) and support $[arthmetic functions] */
+ 
X  	case '$':
X  	    *e.linep++ = (char)c;
X  
! 	    if (((c = Getc(0)) == '{') || (c == '('))
X  	    {
! 		if ((c = collect (c, (c == '{') ? '}' : ')')) != '\0')
X  		    return (c);
X  
X  		goto pack;
***************
*** 823,829 ****
X  	return c;
X      }
X  
!     yylval.cp = strsave (e.cline, areanum);
X      return WORD;
X  }
X  
--- 828,857 ----
X  	return c;
X      }
X  
! /* Special processing for $(command) to convert it to `command` */
! 
!     if (strncmp (e.cline, "$(", 2) == 0)
!     {
! 	yylval.cp = strsave (e.cline + 1, areanum);
! 	*yylval.cp = '`';
! 	yylval.cp[strlen (yylval.cp) - 1] = '`';
!     }
! 
! /* Otherwise, handle words beginning with a ~ */
! 
!     else if (*e.cline == '~')
!     {
! 	char	*dir = lookup (home, FALSE)->value;
! 
! 	yylval.cp = tree (strlen (e.cline) + strlen (dir));
! 	strcat (strcpy (yylval.cp, dir), e.cline + 1);
!     }
! 
! /* Otherwise, just save it */
! 
!     else
! 	yylval.cp = strsave (e.cline, areanum);
! 
X      return WORD;
X  }
X  
Index: shell/sh7.c
Prereq: 1.18
*** ../sh16.3/shell/sh7.c	Fri Aug 17 21:35:57 1990
--- shell/sh7.c	Tue Nov  6 19:24:17 1990
***************
*** 15,81 ****
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh7.c 1.18 90/08/14 23:34:55 MS_user Exp $
X   *
X   *    $Log:	sh7.c $
X   * Revision 1.18  90/08/14  23:34:55  MS_user
X   * Fix directory display on change directory
X   * Fix spelling mistake.
!  * 
X   * Revision 1.17  90/05/31  09:50:05  MS_user
X   * Implement partial write when swapping to disk
!  * 
X   * Revision 1.16  90/04/30  19:50:44  MS_user
X   * Stop search path if second character of name is colon
!  * 
X   * Revision 1.15  90/04/25  22:35:53  MS_user
X   * Fix bug in doread to stop multi-line reads
!  * 
X   * Revision 1.14  90/04/25  09:21:11  MS_user
X   * Change version message processing
!  * 
X   * Revision 1.13  90/04/03  17:59:43  MS_user
X   * type didnot check for functions before searching PATH
!  * 
X   * Revision 1.12  90/03/27  20:33:58  MS_user
X   * Clear extended file name on interrupt
!  * 
X   * Revision 1.11  90/03/26  20:57:38  MS_user
X   * Change I/O restore so that "exec >filename" works
!  * 
X   * Revision 1.10  90/03/14  19:32:05  MS_user
X   * Change buffered output to be re-entrant and add it to getopt
!  * 
X   * Revision 1.9  90/03/14  16:45:52  MS_user
X   * New Open_buffer parameter
!  * 
X   * Revision 1.8  90/03/13  21:19:50  MS_user
X   * Use the new Buffered Output routines in doecho
!  * 
X   * Revision 1.7  90/03/12  20:43:52  MS_user
X   * Change bell test to check initialisation file
!  * 
X   * Revision 1.6  90/03/12  17:09:38  MS_user
X   * Add a missing cast
!  * 
X   * Revision 1.5  90/03/09  16:06:41  MS_user
X   * Add SH_BELL processing
!  * 
X   * Revision 1.4  90/03/06  16:50:10  MS_user
X   * Add disable history option
!  * 
X   * Revision 1.3  90/03/05  13:52:49  MS_user
X   * Changes to eval and dot functionality
X   * Fix bug in escape processing in doecho
X   * Add some array size checks
!  * 
X   * Revision 1.2  90/01/30  14:43:34  MS_user
X   * Add missing author note
!  * 
X   * Revision 1.1  90/01/29  17:46:25  MS_user
X   * Initial revision
!  * 
!  * 
X   */
X  
X  #include <sys/types.h>
--- 15,87 ----
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh7.c 1.20 90/09/19 15:33:07 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh7.c $
+  * Revision 1.20  90/09/19  15:33:07  Ian_Stewartson
+  * Allow builtin commands to selected/de-selected
+  * 
+  * Revision 1.19  90/09/11  19:42:59  Ian_Stewartson
+  * Implement builtin command
+  *
X   * Revision 1.18  90/08/14  23:34:55  MS_user
X   * Fix directory display on change directory
X   * Fix spelling mistake.
!  *
X   * Revision 1.17  90/05/31  09:50:05  MS_user
X   * Implement partial write when swapping to disk
!  *
X   * Revision 1.16  90/04/30  19:50:44  MS_user
X   * Stop search path if second character of name is colon
!  *
X   * Revision 1.15  90/04/25  22:35:53  MS_user
X   * Fix bug in doread to stop multi-line reads
!  *
X   * Revision 1.14  90/04/25  09:21:11  MS_user
X   * Change version message processing
!  *
X   * Revision 1.13  90/04/03  17:59:43  MS_user
X   * type didnot check for functions before searching PATH
!  *
X   * Revision 1.12  90/03/27  20:33:58  MS_user
X   * Clear extended file name on interrupt
!  *
X   * Revision 1.11  90/03/26  20:57:38  MS_user
X   * Change I/O restore so that "exec >filename" works
!  *
X   * Revision 1.10  90/03/14  19:32:05  MS_user
X   * Change buffered output to be re-entrant and add it to getopt
!  *
X   * Revision 1.9  90/03/14  16:45:52  MS_user
X   * New Open_buffer parameter
!  *
X   * Revision 1.8  90/03/13  21:19:50  MS_user
X   * Use the new Buffered Output routines in doecho
!  *
X   * Revision 1.7  90/03/12  20:43:52  MS_user
X   * Change bell test to check initialisation file
!  *
X   * Revision 1.6  90/03/12  17:09:38  MS_user
X   * Add a missing cast
!  *
X   * Revision 1.5  90/03/09  16:06:41  MS_user
X   * Add SH_BELL processing
!  *
X   * Revision 1.4  90/03/06  16:50:10  MS_user
X   * Add disable history option
!  *
X   * Revision 1.3  90/03/05  13:52:49  MS_user
X   * Changes to eval and dot functionality
X   * Fix bug in escape processing in doecho
X   * Add some array size checks
!  *
X   * Revision 1.2  90/01/30  14:43:34  MS_user
X   * Add missing author note
!  *
X   * Revision 1.1  90/01/29  17:46:25  MS_user
X   * Initial revision
!  *
!  *
X   */
X  
X  #include <sys/types.h>
***************
*** 210,215 ****
--- 216,222 ----
X  static int		doread (C_Op *);
X  static int		doeval (C_Op *);
X  static int		dotrap (C_Op *);
+ static int		dobuiltin (C_Op *);
X  static int		getsig (char *);
X  static int		dobreak (C_Op *);
X  static int		docontinue (C_Op *);
***************
*** 225,230 ****
--- 232,238 ----
X  static void		setsig (int, int (*)());
X  static int		rdexp (char **, int, char *);
X  
+ static char		*not_builtin = "%s: not a builtin\n";
X  static char		**test_alist;
X  static struct test_op	*test_op;
X  static jmp_buf		test_jmp;
***************
*** 1777,1784 ****
X      char		*xp;			/* In file name pointers */
X      char		*xp1;
X      int			n = 1;			/* Argument count	*/
!     int			i, fp;	
X      bool		found;			/* Found flag		*/
X      char		*l_path;
X      Fun_Ops		*fops;
X  
--- 1785,1793 ----
X      char		*xp;			/* In file name pointers */
X      char		*xp1;
X      int			n = 1;			/* Argument count	*/
!     int			i, fp;
X      bool		found;			/* Found flag		*/
+     bool		inb;			/* Inbuilt function	*/
X      char		*l_path;
X      Fun_Ops		*fops;
X  
***************
*** 1794,1800 ****
X  
X      while ((cp = t->words[n++]) != (char *)NULL)
X      {
! 	if (inbuilt (cp))
X  	{
X  	    v1_puts (cp);
X  	    v1a_puts (" is a shell internal command");
--- 1803,1812 ----
X  
X      while ((cp = t->words[n++]) != (char *)NULL)
X      {
! 
! /* Check for currently use inbuilt version */
! 
! 	if (inbuilt (cp, &inb) && inb)
X  	{
X  	    v1_puts (cp);
X  	    v1a_puts (" is a shell internal command");
***************
*** 1825,1831 ****
X  
X  	    if ((xp1 = strrchr (l_path, '/')) == (char *)NULL)
X  		xp1 = l_path;
! 	    
X  	    else
X  		++xp1;
X  
--- 1837,1843 ----
X  
X  	    if ((xp1 = strrchr (l_path, '/')) == (char *)NULL)
X  		xp1 = l_path;
! 
X  	    else
X  		++xp1;
X  
***************
*** 1862,1925 ****
X  	    }
X  	} while ((sp != (char *)NULL) && !found);
X  
! 	if (!found)
! 	    print_error ("%s not found\n", cp);
!     }
X  
X      return 0;
X  }
X  
X  /* Table of internal commands */
X  
X  static struct	builtin	builtin[] = {
! 	".",		dodot,
! 	":",		dolabel,
! 	"[",		dotest,
! 	"break",	dobreak,
! 	"cd",		dochdir,
! 	"continue",	docontinue,
! 	"echo",		doecho,
! 	"eval",		doeval,
! 	"exec",		doexec,
! 	"exit",		doexit,
! 	"export",	doexport,
! 	"getopt",	dogetopt,
X  #ifndef NO_HISTORY
! 	"history",	dohistory,
X  #endif
! 	"msdos",	domsdos,
! 	"pwd",		dopwd,
! 	"read",		doread,
! 	"readonly",	doreadonly,
! 	"return",	doreturn,
! 	"set",		doset,
! 	"shift",	doshift,
! 	"swap",		doswap,
! 	"test",		dotest,
! 	"trap",		dotrap,
! 	"type",		dotype,
! 	"umask",	doumask,
! 	"unset",	dounset,
! 	"ver",		dover,
! 	(char *)NULL,
X  };
X  
X  /*
X   * Look up a built in command
X   */
X  
! int		(*inbuilt (s))()
X  register char	*s;
X  {
X      register struct builtin	*bp;
X  
X      if ((strlen (s) == 2) && isalpha (*s) && (*s != '_') && (*(s + 1) == ':'))
X  	return dodrive;
X  
X      for (bp = builtin; bp->command != (char *)NULL; bp++)
X      {
X  	if (stricmp (bp->command, s) == 0)
X  	    return bp->fn;
X      }
X  
X      return (int (*)())NULL;
--- 1874,1959 ----
X  	    }
X  	} while ((sp != (char *)NULL) && !found);
X  
! /* If not found, check for inbuilt version */
X  
+ 	if (!found)
+ 	{
+ 	    if (inbuilt (cp, &inb))
+ 	    {
+ 		v1_puts (cp);
+ 		v1a_puts (" is a shell internal command");
+ 	    }
+ 
+ 	    else
+ 		print_error ("%s not found\n", cp);
+ 	}
+     }
+ 
X      return 0;
X  }
X  
X  /* Table of internal commands */
X  
X  static struct	builtin	builtin[] = {
! 	".",		dodot,		(BLT_ALWAYS | BLT_CURRENT),
! 	":",		dolabel,	(BLT_ALWAYS | BLT_CURRENT),
! 	"[",		dotest,		BLT_CURRENT,
! 	"break",	dobreak,	BLT_CURRENT,
! 	"builtin",	dobuiltin,	(BLT_ALWAYS | BLT_CURRENT),
! 	"cd",		dochdir,	BLT_CURRENT,
! 	"continue",	docontinue,	BLT_CURRENT,
! 	"echo",		doecho,		BLT_CURRENT,
! 	"eval",		doeval,		BLT_CURRENT,
! 	"exec",		doexec,		BLT_CURRENT,
! 	"exit",		doexit,		BLT_CURRENT,
! 	"export",	doexport,	BLT_CURRENT,
! 	"getopt",	dogetopt,	BLT_CURRENT,
X  #ifndef NO_HISTORY
! 	"history",	dohistory,	BLT_CURRENT,
X  #endif
! 	"msdos",	domsdos,	BLT_CURRENT,
! 	"pwd",		dopwd,		BLT_CURRENT,
! 	"read",		doread,		BLT_CURRENT,
! 	"readonly",	doreadonly,	BLT_CURRENT,
! 	"return",	doreturn,	BLT_CURRENT,
! 	"set",		doset,		BLT_CURRENT,
! 	"shift",	doshift,	BLT_CURRENT,
! 	"swap",		doswap,		BLT_CURRENT,
! 	"test",		dotest,		BLT_CURRENT,
! 	"trap",		dotrap,		BLT_CURRENT,
! 	"type",		dotype,		BLT_CURRENT,
! 	"umask",	doumask,	BLT_CURRENT,
! 	"unset",	dounset,	BLT_CURRENT,
! 	"ver",		dover,		BLT_CURRENT,
! 	(char *)NULL,	(int (*)())NULL,	0
X  };
X  
X  /*
X   * Look up a built in command
X   */
X  
! int		(*inbuilt (s, b))()
X  register char	*s;
+ bool		*b;
X  {
X      register struct builtin	*bp;
X  
+ /* Check for change drive */
+ 
+     *b = TRUE;
X      if ((strlen (s) == 2) && isalpha (*s) && (*s != '_') && (*(s + 1) == ':'))
X  	return dodrive;
X  
+ /* Search for command */
+ 
+     *b = FALSE;
X      for (bp = builtin; bp->command != (char *)NULL; bp++)
X      {
X  	if (stricmp (bp->command, s) == 0)
+ 	{
+ 	    *b = (bp->mode & BLT_CURRENT) ? TRUE : FALSE;
X  	    return bp->fn;
+ 	}
X      }
X  
X      return (int (*)())NULL;
***************
*** 1975,1978 ****
--- 2009,2114 ----
X  {
X      if ((c != 0x07) || Ring_Bell ())
X  	write (STDOUT_FILENO, &c, 1);
+ }
+ 
+ /*
+  * Builtin - either list builtins or execute it
+  */
+ 
+ static int	dobuiltin (t)
+ register C_Op	*t;
+ {
+     register struct builtin	*bp;
+     int				(*shcom)(C_Op *) = (int (*)())NULL;
+     int				rv = 0;
+     bool			mode;
+     int				action;
+     int				i;
+ 
+     if (t->words[1] == (char *)NULL)
+     {
+ 	for (bp = builtin; bp->command != (char *)NULL; bp++)
+ 	    v1printf ("builtin %s%s", bp->command,
+ 		      (bp->mode & BLT_CURRENT) ? " - preferred\n" : "\n");
+     }
+ 
+ /* Check for changing options */
+ 
+     else if (*t->words[1] == '-')
+     {
+ 	if (!strcmp (t->words[1], "-s"))
+ 	    action = 0;
+ 
+ 	else if (!strcmp (t->words[1], "-a"))
+ 	    action = 1;
+ 
+ 	else if (!strcmp (t->words[1], "-d"))
+ 	    action = 2;
+ 
+ 	else
+ 	{
+ 	    print_warn ("builtin: invalid flag %s\n", t->words[1]);
+ 	    return 1;
+ 	}
+ 
+ /* Process the commands */
+ 
+ 	for (i = 2; t->words[i] != (char *)NULL; ++i)
+ 	{
+ 	    for (bp = builtin; bp->command != (char *)NULL; bp++)
+ 	    {
+ 		if (stricmp (bp->command, t->words[i]) == 0)
+ 		{
+ 		    switch (action)
+ 		    {
+ 			case 0:
+ 			    print_warn ("%s: %s\n", t->words[i],
+ 					(bp->mode |= BLT_CURRENT)
+ 						? "builtin" : "external");
+ 			    break;
+ 
+ 			case 1:
+ 			    bp->mode |= BLT_CURRENT;
+ 			    break;
+ 
+ 			case 2:
+ 			    if (bp->mode & BLT_ALWAYS)
+ 				print_warn ("%s: always builtin\n",
+ 					    t->words[i]);
+ 			    else
+ 				bp->mode &= ~BLT_CURRENT;
+ 
+ 			    break;
+ 		    }
+ 
+ 		    break;
+ 		}
+ 	    }
+ 
+ 	    if (bp->command == (char *)NULL)
+ 	    {
+ 		print_warn (not_builtin, t->words[i]);
+ 		rv = 1;
+ 	    }
+ 	}
+     }
+ 
+ /* Check to see if we know about the builtin version */
+ 
+     else if ((shcom = inbuilt (t->words[1], &mode)) == (int (*)())NULL)
+     {
+ 	print_warn (not_builtin, t->words[i]);
+ 	rv = 1;
+     }
+ 
+ /* Set up the word list correctly */
+ 
+     else
+     {
+ 	t->words++;
+ 	rv = (*shcom)(t);
+ 	t->words--;
+     }
+ 
+     return rv;
X  }
Index: shell/sh10.c
Prereq: 1.4
*** ../sh16.3/shell/sh10.c	Fri Aug 17 21:32:51 1990
--- shell/sh10.c	Tue Nov  6 19:25:21 1990
***************
*** 12,20 ****
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh10.c 1.4 90/08/14 23:33:32 MS_user Exp $
X   *
X   *    $Log:	sh10.c $
X   * Revision 1.4  90/08/14  23:33:32  MS_user
X   * Fix memory bugs - Add Copy function code to code a function tree
X   * before it is executed.
--- 12,23 ----
X   * 2.  The sources (or parts thereof) or objects generated from the sources
X   *     (or parts of sources) cannot be sold under any circumstances.
X   *
!  *    $Header: C:/SRC/SHELL/RCS/sh10.c 1.5 90/09/11 19:40:46 Ian_Stewartson Exp $
X   *
X   *    $Log:	sh10.c $
+  * Revision 1.5  90/09/11  19:40:46  Ian_Stewartson
+  * Fix bug in case printing/deletion in functions
+  * 
X   * Revision 1.4  90/08/14  23:33:32  MS_user
X   * Fix memory bugs - Add Copy function code to code a function tree
X   * before it is executed.
***************
*** 186,192 ****
X  	case TCASE:			/* CASE function		*/
X  	    Print_IString ("case ", 1);
X  	    v1_puts (t->str);
! 	    v1a_puts (" do");
X  	    Print_Case (t->left);
X  	    Print_IString (" esac\n", -1);
X  	    return;
--- 189,195 ----
X  	case TCASE:			/* CASE function		*/
X  	    Print_IString ("case ", 1);
X  	    v1_puts (t->str);
! 	    v1a_puts (" in");
X  	    Print_Case (t->left);
X  	    Print_IString (" esac\n", -1);
X  	    return;
***************
*** 624,629 ****
--- 627,633 ----
X      if (t->type == TLIST) 
X      {
X  	Set_Free_Case (t->left, func);
+ 	(*func)((char *)t->left);
X  	t1 = t->right;
X      }
X      
***************
*** 638,643 ****
--- 642,650 ----
X      (*func)((char *)t1->words);
X  
X      Set_Free_ExTree (t1->left, func);
+     
+     if (t1 == t->right)
+ 	(*func)((char *)t->right);
X  }
X  
X  /*
SHAR_EOF
echo 'File Patch1.6.4 is complete' &&
chmod 0644 Patch1.6.4 ||
echo 'restore of Patch1.6.4 failed'
Wc_c="`wc -c < 'Patch1.6.4'`"
test 63614 -eq "$Wc_c" ||
	echo 'Patch1.6.4: original size 63614, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
rm -f _shar_seq_.tmp
echo You have unpacked the last part
exit 0

exit 0 # Just in case...
-- 
Kent Landfield                   INTERNET: kent at sparky.IMD.Sterling.COM
Sterling Software, IMD           UUCP:     uunet!sparky!kent
Phone:    (402) 291-8300         FAX:      (402) 291-4362
Please send comp.sources.misc-related mail to kent at uunet.uu.net.



More information about the Comp.sources.misc mailing list