diff -c -r -N -x*.dsk sh-util1.12-orig/config.bat sh-util1.12/config.bat
*** sh-util1.12-orig/config.bat	Thu Jan  1 02:00:00 1970
--- sh-util1.12/config.bat	Mon Sep 30 18:49:00 1996
***************
*** 0 ****
--- 1,17 ----
+ @echo off
+ echo Configuring the Top directory...
+ if exist config.status del config.status
+ update config.dj config.h
+ redir -e cfg.tmp -o Makefile sed -f configdj.sed Makefile.in
+ echo Configuring `lib' directory...
+ redir -ea cfg.tmp -o lib/Makefile sed -f configdj.sed lib/Makefile.in
+ echo Configuring `src' directory...
+ redir -ea cfg.tmp -o src/Makefile sed -f configdj.sed src/Makefile.in
+ echo Configuring `doc' directory...
+ redir -ea cfg.tmp -o doc/Makefile sed -f configdj.sed doc/Makefile.in
+ echo Configuring `man' directory...
+ redir -ea cfg.tmp -o Makefile.tmp sed -f configdj.sed man/Makefile.in
+ redir -ea cfg.tmp -o man/Makefile sed -e '/^[^#]/s/ 1/ 1n/g' Makefile.tmp
+ if exist Makefile.tmp del Makefile.tmp
+ update cfg.tmp config.status
+ echo timestamp > stamp-h
diff -c -r -N -x*.dsk sh-util1.12-orig/config.dj sh-util1.12/config.dj
*** sh-util1.12-orig/config.dj	Thu Jan  1 02:00:00 1970
--- sh-util1.12/config.dj	Wed Oct  2 13:07:04 1996
***************
*** 0 ****
--- 1,9 ----
+ #include <sys/config.h>
+ 
+ #undef  HAVE_UNAME
+ #define HAVE_UNAME 1
+ 
+ #undef  NICE_PRIORITY
+ #define NICE_PRIORITY 1
+ 
+ #define SHELLS_FILE  "c:/etc/shells"
diff -c -r -N -x*.dsk sh-util1.12-orig/configdj.sed sh-util1.12/configdj.sed
*** sh-util1.12-orig/configdj.sed	Thu Jan  1 02:00:00 1970
--- sh-util1.12/configdj.sed	Wed Oct  2 16:18:20 1996
***************
*** 0 ****
--- 1,86 ----
+ 1i\
+ # Generated automatically from Makefile.in by configdj.sed.\
+ top_builddir = ..
+ 
+ s%@CFLAGS@%-DHAVE_CONFIG_H -O2 -g%g
+ s%@CPPFLAGS@%%g
+ s%@CXXFLAGS@%%g
+ s%@DEFS@%%g
+ s%@LDFLAGS@%%g
+ s%@LIBS@%%g
+ s%@PROGS@%%g
+ s%@exec_prefix@%$(DJDIR)%g
+ s%@prefix@%$(DJDIR)%g
+ s%@program_transform_name@%s,x,x,%g
+ s%@CC@%gcc%g
+ s%@INSTALL_PROGRAM@%ginstall -c%g
+ s%@INSTALL_DATA@%ginstall -m 644%g
+ s%@SET_MAKE@%MAKE=make%g
+ s%@CPP@%cpp%g
+ s%@RANLIB@%ranlib%g
+ s%@YACC@%bison -y%g
+ s%@ALLOCA@%%g
+ s%@LIBOBJS@% getusershell.o stime.o%g
+ s%@srcdir@%.%g
+ s%@top_srcdir@%..%g
+ s%@INSTALL@%ginstall -c%g
+ /^NROFF *=/s/nroff/cawf -man/
+ s/@MAN@/nice.1 su.1 uname.1/
+ s/\.1/.1n/g
+ s/^all:$/all: $(MANFILES)/
+ /^all: $(MANFILES)/a\
+ \
+ NROFF = cawf -man\
+ \
+ %.1n: %.1\
+ 	$(NROFF) $< > $@\
+ 
+ /^Makefile:.*/,/^	/c\
+ Makefile: $(top_builddir)/configdj.sed $(srcdir)/Makefile.in\
+ 	redir -o $@ sed -f $^\
+ 
+ /^config.status:.*/,/^	/c\
+ config.status: config.bat configdj.sed\
+ 	config.bat\
+ 
+ /^	CONFIG_FILES=.*/d
+ /^all install uninstall:/,/^[ 	]*$/c\
+ all install uninstall:\
+ 	@redir -o submk.bat echo '@echo off'\
+ 	@redir -oa submk.bat echo 'echo making %2 in %1'\
+ 	@redir -oa submk.bat echo '$(subst /,\\,$(MAKE)) -C %1 %2'\
+ 	@redir -o mk.bat echo '@echo off'\
+ 	@redir -oa mk.bat echo 'for %%d in ($(SUBDIRS)) do call submk %%d $@'\
+ 	@mk.bat\
+ 
+ /^	    mostlyclean-recursive realclean-recursive:/,/^[ 	]*$/c\
+ 	    mostlyclean-recursive realclean-recursive:\
+ 	@redir -o submk.bat echo @echo off\
+ 	@redir -oa submk.bat echo echo making %2 in %1\
+ 	@redir -oa submk.bat echo $(subst /,\\,$(MAKE)) -C %1 %2\
+ 	@redir -o mk.bat echo @echo off\
+ 	@redir -oa mk.bat echo for %%d in ($(SUBDIRS)) do call submk %%d $(subst -recursive,,$@)\
+ 	@mk.bat\
+ 
+ /^DISTFILES *=/i\
+ CLEANFILES = *.1n *.exe *.tmp mk.bat submk.bat\
+ 
+ /^OBJECTS *=/s/strftime.o //
+ /^[^#]/s/ who / /
+ /^[^#]/s/ users / /
+ /^[^#]/s/ putenv\.o//
+ s/\.tab\.c/_tab.c/g
+ /^SUBDIRS *=/a\
+ top_builddir = .
+ s/^LIBPROGS *=/& uname nice /
+ s/\.version/_versi/g
+ /^	sed -e /s/\$(bindir)/./
+ /^\$(PROGS) su \$(LIBPROGS):/s/\$(PROGS)/$(filter-out false groups true, &)/
+ /^	\$(link_command) date.o/a\
+ 	stubify -g gdate.exe\
+ 	stubedit gdate.exe runfile=date argv0=date
+ /^	\$(link_command) echo.o/a\
+ 	stubify -g gecho.exe\
+ 	stubedit gecho.exe runfile=echo argv0=echo
+ /^	\$(RM) -f \$(PROGS)/s/\*.o/& *.exe _versi/
+ s|`cat _versi`|$(shell sed -n -e p _versi)|g
diff -c -r -N -x*.dsk sh-util1.12-orig/lib/basename.c sh-util1.12/lib/basename.c
*** sh-util1.12-orig/lib/basename.c	Mon Sep 26 23:46:14 1994
--- sh-util1.12/lib/basename.c	Mon Sep 30 17:00:36 1996
***************
*** 37,41 ****
--- 37,50 ----
    char *base;
  
    base = rindex (name, '/');
+ #ifdef MSDOS
+   {
+     char *p = rindex (name, '\\');
+     if (!base || (p && p > base))
+       base = p;
+     if (!base && name[0] && name[1] == ':')
+       base = name + 1;
+   }
+ #endif
    return base ? base + 1 : name;
  }
diff -c -r -N -x*.dsk sh-util1.12-orig/lib/getusers.c sh-util1.12/lib/getusers.c
*** sh-util1.12-orig/lib/getusers.c	Mon Sep 26 23:55:54 1994
--- sh-util1.12/lib/getusers.c	Wed Oct  2 13:10:08 1996
***************
*** 43,48 ****
--- 43,51 ----
  /* List of shells to use if the shells file is missing. */
  static char const* const default_shells[] =
  {
+ #ifdef MSDOS
+   "c:/dos/command.com", "c:/windows/command.com", "c:/command.com",
+ #endif
    "/bin/sh", "/bin/csh", "/usr/bin/sh", "/usr/bin/csh", NULL
  };
  
***************
*** 78,83 ****
--- 81,91 ----
    if (shellstream == NULL)
      {
        shellstream = fopen (SHELLS_FILE, "r");
+ #ifdef MSDOS
+       /* No standard place for "/etc/shells"...  */
+       if (shellstream == NULL && getenv ("SHELLS_FILE"))
+ 	shellstream = fopen (getenv ("SHELLS_FILE"), "r");
+ #endif
        if (shellstream == NULL)
  	{
  	  /* No shells file.  Use the default list.  */
diff -c -r -N -x*.dsk sh-util1.12-orig/lib/stripsla.c sh-util1.12/lib/stripsla.c
*** sh-util1.12-orig/lib/stripsla.c	Mon Sep 26 23:42:18 1994
--- sh-util1.12/lib/stripsla.c	Mon Sep 30 16:50:46 1996
***************
*** 38,43 ****
    int last;
  
    last = strlen (path) - 1;
!   while (last > 0 && path[last] == '/')
      path[last--] = '\0';
  }
--- 38,56 ----
    int last;
  
    last = strlen (path) - 1;
! #ifdef MSDOS
!   /* Leave alone a single slash in "d:/".  "d:" means something
!      VERY different on MSDOS.  */
!   if (path[1] == ':')
!     {
!       path += 2;
!       last -= 2;
!     }
! #endif
!   while (last > 0 && (path[last] == '/'
! #ifdef MSDOS
! 		      || path[last] == '\\'
! #endif
! 		      ))
      path[last--] = '\0';
  }
diff -c -r -N -x*.dsk sh-util1.12-orig/src/date.c sh-util1.12/src/date.c
*** sh-util1.12-orig/src/date.c	Sat Oct  1 20:06:08 1994
--- sh-util1.12/src/date.c	Mon Sep 30 19:12:12 1996
***************
*** 87,93 ****
    FILE *in_stream;
    char *line;
    int line_length;
!   int buflen;
    time_t when;
  
    if (strcmp (input_filename, "-") == 0)
--- 87,93 ----
    FILE *in_stream;
    char *line;
    int line_length;
!   size_t buflen;
    time_t when;
  
    if (strcmp (input_filename, "-") == 0)
diff -c -r -N -x*.dsk sh-util1.12-orig/src/dirname.c sh-util1.12/src/dirname.c
*** sh-util1.12-orig/src/dirname.c	Fri Oct 21 06:59:42 1994
--- sh-util1.12/src/dirname.c	Tue Oct  1 14:58:38 1996
***************
*** 60,65 ****
--- 60,66 ----
       char **argv;
  {
    register char *path;
+   register char *path_start;
    register char *slash;
  
    program_name = argv[0];
***************
*** 72,87 ****
        usage (1);
      }
  
!   path = argv[1];
    strip_trailing_slashes (path);
  
    slash = rindex (path, '/');
    if (slash == NULL)
      path = (char *) ".";
    else
      {
        /* Remove any trailing slashes and final element. */
!       while (slash > path && *slash == '/')
  	--slash;
        slash[1] = 0;
      }
--- 73,107 ----
        usage (1);
      }
  
!   path_start = path = argv[1];
    strip_trailing_slashes (path);
  
    slash = rindex (path, '/');
+ #ifdef MSDOS
+   {
+     /* We might get mixed forward- and backslashes.  Find the rightmost.  */
+     char *bs = rindex (path, '\\');
+ 
+     if (!slash || bs && bs > slash)
+       slash = bs;
+     if (!slash && path[0] && path[1] == ':')
+       slash = path + 1;
+ 
+     /* Make sure the first slash after the d: is left alone.  */
+     if (path[1] == ':')
+       path_start += 2;
+   }
+ #endif
    if (slash == NULL)
      path = (char *) ".";
    else
      {
        /* Remove any trailing slashes and final element. */
!       while (slash > path_start && (*slash == '/'
! #ifdef MSDOS
! 				    || *slash == '\\'
! #endif
! 				    ))
  	--slash;
        slash[1] = 0;
      }
diff -c -r -N -x*.dsk sh-util1.12-orig/src/pathchk.c sh-util1.12/src/pathchk.c
*** sh-util1.12-orig/src/pathchk.c	Fri Oct 21 06:59:44 1994
--- sh-util1.12/src/pathchk.c	Tue Oct  1 16:50:26 1996
***************
*** 275,282 ****
  
    /* Figure out the parent of the first element in PATH.  */
    parent = xstrdup (*path == '/' ? "/" : ".");
- 
    slash = path;
    last_elem = 0;
    while (1)
      {
--- 275,299 ----
  
    /* Figure out the parent of the first element in PATH.  */
    parent = xstrdup (*path == '/' ? "/" : ".");
    slash = path;
+ #ifdef MSDOS
+   if (path [0] && path[1] == ':')
+     {
+       /* If we have a pathname with a drive, make sure it's explicit
+ 	 (i.e. instead of "d:foo/bar" get "d:/curdir/foo/bar").  */
+       char *normalized_path = alloca(PATH_MAX + 1);
+       int c;
+ 
+       _fixpath (path, normalized_path);
+       c = normalized_path[3];
+       normalized_path[3] = 0;
+       parent = xstrdup (normalized_path);
+       normalized_path[3] = c;
+       path = normalized_path;
+       slash = path + 2;		/* point to the leftmost slash */
+     }
+ #endif
+ 
    last_elem = 0;
    while (1)
      {
diff -c -r -N -x*.dsk sh-util1.12-orig/src/su.c sh-util1.12/src/su.c
*** sh-util1.12-orig/src/su.c	Tue Oct 11 03:47:02 1994
--- sh-util1.12/src/su.c	Wed Oct  2 13:35:54 1996
***************
*** 123,135 ****
--- 123,143 ----
  #include "version.h"
  
  /* The default PATH for simulated logins to non-superuser accounts.  */
+ #ifdef MSDOS
+ #define DEFAULT_LOGIN_PATH "c:/windows;c:/dos;c:/"
+ #else
  #define DEFAULT_LOGIN_PATH ":/usr/ucb:/bin:/usr/bin"
+ #endif
  
  /* The default PATH for simulated logins to superuser accounts.  */
  #define DEFAULT_ROOT_LOGIN_PATH "/usr/ucb:/bin:/usr/bin:/etc"
  
  /* The shell to run if none is given in the user's passwd entry.  */
+ #ifdef MSDOS
+ #define DEFAULT_SHELL "command.com"
+ #else
  #define DEFAULT_SHELL "/bin/sh"
+ #endif
  
  /* The user to become if none is specified.  */
  #define DEFAULT_USER "root"
***************
*** 194,200 ****
--- 202,212 ----
       char **argv;
  {
    int optc;
+ #ifdef MSDOS
+   char *new_user = getlogin ();
+ #else
    const char *new_user = DEFAULT_USER;
+ #endif
    char *command = 0;
    char **additional_args = 0;
    char *shell = 0;
***************
*** 261,267 ****
--- 273,294 ----
  
    pw = getpwnam (new_user);
    if (pw == 0)
+ #ifdef MSDOS
+     {
+       /* On MSDOS, allow them to become anyone.  */
+       extern char * __dosexec_find_on_path (const char *, char **, char *);
+       char found_at[PATH_MAX];
+ 
+       pw = (struct passwd *)alloca (sizeof (struct passwd));
+       pw->pw_name = new_user;
+       pw->pw_dir = "c:/";
+       pw->pw_shell = __dosexec_find_on_path ("command.com", environ, found_at);
+       pw->pw_uid = getuid ();
+       pw->pw_gid = getgid ();
+     }
+ #else  /* not MSDOS */
      error (1, 0, "user %s does not exist", new_user);
+ #endif /* not MSDOS */
    endpwent ();
  
    /* Make a copy of the password information and point pw at the local
***************
*** 291,296 ****
--- 318,328 ----
      pw->pw_shell = (char *) DEFAULT_SHELL;
    if (shell == 0 && change_environment == 0)
      shell = getenv ("SHELL");
+ #ifdef MSDOS
+   /* $SHELL is not guaranteed to be defined on MSDOS.  */
+   if (shell == 0 && change_environment == 0)
+     shell = getenv ("COMSPEC");
+ #endif
    if (shell != 0 && getuid () && restricted_shell (pw->pw_shell))
      {
        /* The user being su'd to has a nonstandard shell, and so is
***************
*** 332,337 ****
--- 364,374 ----
      correct = sp->sp_pwdp;
    else
  #endif
+ 
+ #ifdef MSDOS
+   /* Everybody is a root on MSDOS, so don't bother.  */
+   return 1;
+ #else
    correct = pw->pw_passwd;
  
    if (getuid () == 0 || correct == 0 || correct[0] == '\0')
***************
*** 346,351 ****
--- 383,389 ----
    encrypted = crypt (unencrypted, correct);
    bzero (unencrypted, strlen (unencrypted));
    return strcmp (encrypted, correct) == 0;
+ #endif /* MSDOS */
  }
  
  /* Update `environ' for the new shell based on PW, with SHELL being
***************
*** 445,450 ****
--- 483,495 ----
      args[argno++] = "-f";
    if (command)
      {
+ #ifdef MSDOS
+       extern int _is_dos_shell (const char *);
+ 
+       if (_is_dos_shell (shell))
+ 	args[argno++] = "/c";
+       else
+ #endif
        args[argno++] = "-c";
        args[argno++] = command;
      }
***************
*** 509,514 ****
--- 554,567 ----
       char *shell;
  {
    char *line;
+ #ifdef MSDOS
+   /* Convert all slashes to forward style, make sure the
+      letter case in both SHELL and LINE is consistent.  */
+   char shellbuf[PATH_MAX];
+ 
+   _fixpath (shell, shellbuf);
+   shell = shellbuf;
+ #endif
  
    setusershell ();
    while ((line = getusershell ()) != NULL)
diff -c -r -N -x*.dsk sh-util1.12-orig/src/tee.c sh-util1.12/src/tee.c
*** sh-util1.12-orig/src/tee.c	Sat Oct  1 04:41:24 1994
--- sh-util1.12/src/tee.c	Mon Sep 30 18:11:50 1996
***************
*** 162,167 ****
--- 162,179 ----
    else
      mode |= O_TRUNC;
  
+ #ifdef MSDOS
+   /* When reading from a pipe, do it in binary mode so file
+      contents are copied verbatim.  */
+   if (!isatty (0))
+     {
+       setmode (0, O_BINARY);
+       if (!isatty (1))
+ 	setmode (1, O_BINARY);
+       mode |= O_BINARY;
+     }
+ #endif
+ 
    /* Move all the names `up' one in the argv array to make room for
       the entry for standard output.  This writes into argv[argc].  */
    for (i = nfiles; i >= 1; i--)
diff -c -r -N -x*.dsk sh-util1.12-orig/src/test.c sh-util1.12/src/test.c
*** sh-util1.12-orig/src/test.c	Sat Oct  1 05:27:38 1994
--- sh-util1.12/src/test.c	Tue Nov  5 15:11:18 1996
***************
*** 164,169 ****
--- 164,174 ----
       char *path;
       int mode;
  {
+ #ifdef MSDOS
+   /* The bits in MODE are different for `access' and `stat'.
+      Besides, MSDOS doesn't care about uid/euid issues.  */
+   return access (path, mode);
+ #else /* not MSDOS */
    struct stat st;
    static int euid = -1;
  
***************
*** 194,199 ****
--- 199,205 ----
      return (0);
  
    return (-1);
+ #endif /* not MSDOS */
  }
  
  /* Increment our position in the argument list.  Check that we're not
***************
*** 670,675 ****
--- 676,693 ----
      case 'x':			/* File is executable? */
        unary_advance ();
        value = -1 != eaccess (argv[pos - 1], X_OK);
+ #ifdef __DJGPP__
+       /* Shell scripts say ``test -x prog'', but DOS executables are
+ 	 called `prog.exe', `prog.com' etc.  Make so they are found.  */
+       {
+ 	extern char * __dosexec_find_on_path (const char *, char *[], char *);
+ 	char arg_path[PATH_MAX];
+ 
+ 	if (value == FALSE
+ 	    && __dosexec_find_on_path (argv[pos -1], (char **)0, arg_path))
+ 	  value = -1 != eaccess (arg_path, X_OK);
+       }
+ #endif
        return (TRUE == value);
  
      case 'O':			/* File is owned by you? */
