[comp.binaries.ibm.pc.d] MS-SH 1.6.2 patches

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (08/09/90)

Some patches for the MS-DOS bourne shell 1.6.2:

- a fatal bug with commands in () ("sub-shell") was fixed
- #! in shell scripts works now correctly with, for example, gawk
- the internal commands of COMMAND.COM are recognized
- the type internal command of sh was changed to recognize
  the internal commands of sh as well as COMMAND.COM commands

You may have problems patching the sources with the patch program
because the patches were derived from my OS/2 version which has lots of
other changes. The line numbers in these patches are not correct, but
they should work, because they are context diffs.

My OS/2 version has these changes and some other nice features:
- background processes
- "jobs" command and key for list of bg processes
- reporting of exit status of ending bg processes
- increased length of expanded command line (2k, max. would be 32k)
- real pipes

May be I post it to comp.binaries.os2 sometimes.

Kai Uwe Rommel
rommel@lan.informatik.tu-muenchen.dbp.de


*** sh.org	Sat Aug 04 19:16:18 1990
--- sh.h	Sat Aug 04 17:41:46 1990
***************
*** 532,537 ****
--- 532,538 ----
  extern bool	eqname (char *, char *);
  extern bool	any (char, char *);
  extern int	(*inbuilt (char *))();
+ extern char     *cmd_internal(char *s);
  extern char	*path_append (char *, char *, char *);
  extern void	unset (char *, bool);
  extern int	S_open (bool, char *, int, ...);
diff -cbBwr shdos/src/sh3.c sh/src/sh3.c
*** shdos/src/sh3.c	Thu Jul 05 19:50:26 1990
--- sh/src/sh3.c	Sat Aug 04 18:29:58 1990
***************
*** 210,216 ****
  		Break_List  = (Break_C *)NULL;
  		bc.nextlev  = SShell_List;
  		SShell_List = &bc;
! 		rv = forkexec (t, pin, pout, act, wp);
  	    }
  
  /* Restore the original environment */
--- 210,217 ----
  		Break_List  = (Break_C *)NULL;
  		bc.nextlev  = SShell_List;
  		SShell_List = &bc;
! 		/* rv = forkexec (t, pin, pout, act, wp); wrong! */
! 		rv = execute (t->left, pin, pout, act);
  	    }
  
  /* Restore the original environment */
***************
*** 469,474 ****
--- 506,512 ----
      char	**owp = wp;
      bool	spawn = FALSE;
      Fun_Ops	*fop;
+     char        *cmdcom = NULL;
  
      if (t->type == TCOM)
      {
***************
*** 494,501 ****
  
  /* Check for built in commands */
  
! 	else if (cp != (char *)NULL)
! 	    shcom = inbuilt (cp);
      }
  
  /* Unix fork simulation? */
--- 532,541 ----
  
  /* Check for built in commands */
  
! 	else
!           if (cp != (char *)NULL)
! 	    if ( (shcom = inbuilt (cp)) == NULL )
!               cmdcom = cmd_internal(cp);
      }
  
  /* Unix fork simulation? */
***************
*** 634,639 ****
--- 674,682 ----
  
  /* Ok - execute the program */
  
+     if (cmdcom)
+       return restore_std (rexecve (NULL, wp, makenv (), spawn), TRUE);
+     else
        return restore_std (rexecve (wp[0], wp, makenv (), spawn), TRUE);
  }
  
***************
*** 860,867 ****
      int			nargc = 0;		/* # script args	*/
      char		*p_name;		/* Program name		*/
      int			i;
      union REGS		r;
  
  /* If the environment is null - It is too big - error */
  
      if (envp == (char **)NULL)
--- 903,918 ----
      int			nargc = 0;		/* # script args	*/
      char		*p_name;		/* Program name		*/
      int			i;
      union REGS		r;
  
+ /* Count the number of arguments to the program in case of shell script or
+  * bat file
+  */
+ 
+     while (v[argc++] != (char *)NULL);
+ 
+     ++argc;				/* Including the null		*/
+ 
  /* If the environment is null - It is too big - error */
  
      if (envp == (char **)NULL)
***************
*** 870,886 ****
      else if ((p_name = getcell (FFNAME_MAX)) == (char *)NULL)
  	em = strerror (ENOMEM);
  
!     else
      {
! 
! /* Count the number of arguments to the program in case of shell script or
!  * bat file
!  */
! 
! 	while (v[argc++] != (char *)NULL);
  
! 	++argc;				/* Including the null		*/
  
  /* Start off on the search path for the executable file */
  
  	sp = (any ('/', c) || (*(c + 1) == ':')) ? null : path->value;
--- 920,945 ----
      else if ((p_name = getcell (FFNAME_MAX)) == (char *)NULL)
  	em = strerror (ENOMEM);
  
!     else if ( c == NULL )
      {
! /* cmd.exe interal command */
  
!       if ((new_argv = (char **) getcell (sizeof(char *) * (argc + 2)))
!  	      == NULL)
!   	em = strerror (ENOMEM);
!       else
!       {
!         memcpy (&new_argv[2], &v[0], sizeof(char *) * argc);
!         new_argv[0] = lookup ("COMSPEC", FALSE)->value;
!         new_argv[1] = "/c";
!         res = rexecve (new_argv[0], new_argv, envp, d_flag);
!         DELETE (new_argv);
! 	return res;
!       }
!     }
  
+     else
+     {
  /* Start off on the search path for the executable file */
  
  	sp = (any ('/', c) || (*(c + 1) == ':')) ? null : path->value;
diff -cbBwr shdos/src/sh7.c sh/src/sh7.c
*** shdos/src/sh7.c	Thu Jul 05 19:50:32 1990
--- sh/src/sh7.c	Sat Aug 04 14:58:16 1990
***************
*** 1776,1781 ****
--- 1672,1678 ----
      bool		found;			/* Found flag		*/
      char		*l_path;
      Fun_Ops		*fops;
+     char                *mp;
  
  /* Get some memory for the buffer */
  
***************
*** 1789,1794 ****
--- 1686,1704 ----
  
      while ((cp = t->words[n++]) != (char *)NULL)
      {
+ 	if ( inbuilt (cp) )
+         {
+ 	    v1_puts (cp);
+ 	    v1a_puts (" is a shell internal command");
+ 	    continue;
+         }
+ 
+         if ( cmd_internal(cp) )
+         {
+ 	    v1_puts (cp);
+ 	    v1a_puts (" is a CMD.EXE internal command");
+ 	    continue;
+         }
  
  /* Check for a function */
  
***************
*** 1841,1849 ****
  
  		    else if ((stricmp (xp, ".exe") != 0) &&
  			     (stricmp (xp, ".com") != 0) &&
  			     (stricmp (xp, ".bat") != 0))
  			continue;
  
  		    print_error ("%s is %s\n", cp, l_path);
  		    found = TRUE;
  		}
--- 1751,1765 ----
  
  		    else if ((stricmp (xp, ".exe") != 0) &&
  			     (stricmp (xp, ".com") != 0) &&
  			     (stricmp (xp, ".bat") != 0))
  			continue;
  
+                     strlwr(l_path);
+ 
+                     for ( mp = l_path; *mp; mp++ )
+                       if ( *mp == '\\' )
+                         *mp = '/';
+ 
  		    print_error ("%s is %s\n", cp, l_path);
  		    found = TRUE;
  		}
***************
*** 1911,1916 ****
--- 1827,1861 ----
      }
  
      return (int (*)())NULL;
+ }
+ 
+ /* recognize CMD.EXE internal commands */
+ 
+ char *cmd_tab[] =
+ {
+   "chcp", "cls", "copy",
+   "date", "del", "detach", "dir",
+   "erase",
+   "md", "mkdir", "move",
+   "ren", "rename", "rd", "rmdir",
+   "start",
+   "time",
+   NULL
+ };
+ 
+ #define cmds (sizeof(cmd_tab) / sizeof(char *) - 1)
+ 
+ char *cmd_internal(char *s)
+ {
+     int cnt;
+ 
+     for ( cnt = 0; cnt < cmds; cnt++ )
+     {
+ 	if (stricmp (cmd_tab[cnt], s) == 0)
+ 	    return cmd_tab[cnt];
+     }
+ 
+     return NULL;
  }
  
  /* Write to stdout functions - printf, fputs, fputc, and a special */
*** sh8.org	Sat Aug 04 18:51:32 1990
--- sh8.c	Sat Aug 04 17:44:18 1990
***************
*** 595,601 ****
  /* Try the file name and then with a .sh appended */
  
      if ((i = Check_Script (strcpy (local_path, path), params, nargs)) < 0)
!         i = Check_Script (strcat (local_path, ".sh"), params, nargs);
  
      DELETE (local_path);
      return i;
--- 595,602 ----
  /* Try the file name and then with a .sh appended */
  
      if ((i = Check_Script (strcpy (local_path, path), params, nargs)) < 0)
!       if ((i = Check_Script (strcat (local_path, ".sh"), params, nargs)) == 0)
!         strcpy(path, local_path);
  
      DELETE (local_path);
      return i;

--
/* Kai Uwe Rommel
 * Munich
 * rommel@lan.informatik.tu-muenchen.dbp.de
 */

thakulin@hila.hut.fi (Timo T Hakulinen) (08/10/90)

In article <3860@tuminfo1.lan.informatik.tu-muenchen.dbp.de> rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) writes:

>   My OS/2 version has these changes and some other nice features:
>   - background processes
>   - "jobs" command and key for list of bg processes
>   - reporting of exit status of ending bg processes
>   - increased length of expanded command line (2k, max. would be 32k)
>   - real pipes
>
>   May be I post it to comp.binaries.os2 sometimes.

Sounds great.  Why not post diffs against the "official" 1.6.2 to, say,
comp.sources.misc now?  A proper bourne shell for OS/2 would be very welcome.

Timo

sasjaa@unx.sas.com (Jim Adams) (08/13/90)

In article <3860@tuminfo1.lan.informatik.tu-muenchen.dbp.de> rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) writes:
>Some patches for the MS-DOS bourne shell 1.6.2:
>
>- a fatal bug with commands in () ("sub-shell") was fixed
>- #! in shell scripts works now correctly with, for example, gawk
>- the internal commands of COMMAND.COM are recognized
>- the type internal command of sh was changed to recognize
>  the internal commands of sh as well as COMMAND.COM commands
>
>You may have problems patching the sources with the patch program
>because the patches were derived from my OS/2 version which has lots of
>other changes. The line numbers in these patches are not correct, but
>they should work, because they are context diffs.
>
>My OS/2 version has these changes and some other nice features:
>- background processes
>- "jobs" command and key for list of bg processes
>- reporting of exit status of ending bg processes
>- increased length of expanded command line (2k, max. would be 32k)
>- real pipes
>
>May be I post it to comp.binaries.os2 sometimes.
>
>Kai Uwe Rommel
>rommel@lan.informatik.tu-muenchen.dbp.de
>
 .... some SOURCE diffs deleted
>
>--
>/* Kai Uwe Rommel
> * Munich
> * rommel@lan.informatik.tu-muenchen.dbp.de
> */

I dare say that most of us will have some problems with this as the sources
have not been posted to this group. just the BINARIES. Kind of hard to apply
source diffs to binaries.....:-(

-- 
+---------------------------------------+-------------------------------------+
|James Adams                            |  Death by any other name would      |
|   ...!mcnc!rti!sas!sasjaa             |  be a character in a book.          |
+---------------------------------------+-------------------------------------+

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (08/14/90)

In article <THAKULIN.90Aug10002106@hila.hut.fi> thakulin@hila.hut.fi (Timo T Hakulinen) writes:
>Sounds great.  Why not post diffs against the "official" 1.6.2 to, say,
>comp.sources.misc now?  A proper bourne shell for OS/2 would be very welcome.
>
>Timo

I've sent it with sources & diffs to the moderator of comp.binaries.os2.
He will post it perhaps during the next time (I expect executable and
diffs to be posted).

Kai Uwe Rommel

--
/* Kai Uwe Rommel
 * Munich
 * rommel@lan.informatik.tu-muenchen.dbp.de
 */

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (08/16/90)

In article <1990Aug13.113901.25213@unx.sas.com> sasjaa@unx.sas.com (Jim Adams) writes:
>I dare say that most of us will have some problems with this as the sources
>have not been posted to this group. just the BINARIES. Kind of hard to apply
>source diffs to binaries.....:-(

The sources were posted some time ago to comp.sources.misc.

Kai Uwe Rommel

--
/* Kai Uwe Rommel
 * Munich
 * rommel@lan.informatik.tu-muenchen.dbp.de
 */