diff -r -c bash-1_14_7/.distribution bash1147/.distribution
*** bash-1_14_7/.distribution	Wed Mar 10 09:43:44 1999
--- bash1147/.distribution	Wed Mar 10 09:44:50 1999
***************
*** 1 ****
! 1.14
--- 1 ----
! 1.15
diff -r -c bash-1_14_7/bashhist.c bash1147/bashhist.c
*** bash-1_14_7/bashhist.c	Wed Mar 10 09:43:45 1999
--- bash1147/bashhist.c	Fri Mar 19 17:36:13 1999
***************
*** 106,111 ****
--- 106,114 ----
    /* Read the history in HISTFILE into the history list. */
    hf = get_string_value ("HISTFILE");
  
+ #if defined (USE_VMS)
+   hf = vmsutil_expand_path (savestring (hf));
+ #endif
    if (hf && *hf)
      {
        struct stat buf;
***************
*** 117,122 ****
--- 120,129 ----
  	  history_lines_in_file = where_history ();
  	}
      }
+ #if defined (USE_VMS)
+   if (hf)
+     free (hf);
+ #endif
  }
  
  /* Write the existing history out to the history file. */
***************
*** 125,130 ****
--- 132,140 ----
  {
    char *hf = get_string_value ("HISTFILE");
  
+ #if defined (USE_VMS)
+   hf = vmsutil_expand_path (savestring (hf));
+ #endif
    if (hf && *hf)
      {
        struct stat buf;
***************
*** 141,146 ****
--- 151,160 ----
  	    write_history (hf);
  	}
      }
+ #if defined (USE_VMS)
+   if (hf)
+     free (hf);
+ #endif
  }
  
  /* If this is an interactive shell, then append the lines executed
***************
*** 154,159 ****
--- 168,176 ----
      {
        char *hf = get_string_value ("HISTFILE");
  
+ #if defined (USE_VMS)
+       hf = vmsutil_expand_path (savestring (hf));
+ #endif
        if (hf && *hf)
  	{
  	  struct stat buf;
***************
*** 182,187 ****
--- 199,208 ----
  	    }
  	  history_lines_this_session = 0;
  	}
+ #if defined (USE_VMS)
+       if (hf)
+ 	free (hf);
+ #endif
      }
    return (result);
  }
diff -r -c bash-1_14_7/builtins/cd.def bash1147/builtins/cd.def
*** bash-1_14_7/builtins/cd.def	Wed Mar 10 09:43:50 1999
--- bash1147/builtins/cd.def	Wed Mar 10 09:45:00 1999
***************
*** 22,28 ****
--- 22,30 ----
  $PRODUCES cd.c
  
  #include <stdio.h>
+ #ifndef VMS
  #include <sys/param.h>
+ #endif
  
  #if defined (HAVE_STRING_H)
  #  include <string.h>
diff -r -c bash-1_14_7/builtins/exit.def bash1147/builtins/exit.def
*** bash-1_14_7/builtins/exit.def	Wed Mar 10 09:43:51 1999
--- bash1147/builtins/exit.def	Fri Mar 19 15:18:18 1999
***************
*** 37,42 ****
--- 37,47 ----
  
  extern int interactive, login_shell;
  extern int last_command_exit_value;
+ #if defined (USE_VMS)
+ int subshell_exit_value = 0;
+ int subshell_exit_builtin = 0;
+ int subshell_skip_commands = 0;
+ #endif
  
  static int exit_or_logout ();
  static int sourced_logout = 0;
***************
*** 120,129 ****
--- 125,149 ----
  
    /* Run our `~/.bash_logout' file if it exists, and this is a login shell. */
    if (login_shell && sourced_logout++ == 0)
+ #if defined (USE_VMS)
+     if (maybe_execute_file ("sys$login:.bash_logout", 1) == 0)
+       if (maybe_execute_file ("sys$login:_bash_logout", 1) == 0)
+         maybe_execute_file ("sys$login:_blogout", 1);
+ #else
      maybe_execute_file ("~/.bash_logout", 1);
+ #endif
  
    last_command_exit_value = exit_value;
  
    /* Exit the program. */
+ #if defined (USE_VMS)
+   if (subshell_exit_builtin)
+     {
+       subshell_exit_value = exit_value;
+       subshell_exit_builtin = 0;
+       subshell_skip_commands = 1;
+       return (EXECUTION_SUCCESS);
+     }
+ #endif
    longjmp (top_level, EXITPROG);
  }
diff -r -c bash-1_14_7/builtins/fc.def bash1147/builtins/fc.def
*** bash-1_14_7/builtins/fc.def	Wed Mar 10 09:43:51 1999
--- bash1147/builtins/fc.def	Wed Mar 10 09:45:02 1999
***************
*** 50,59 ****
--- 50,65 ----
  #include "../bashansi.h"
  #include "../shell.h"
  #if defined (HISTORY)
+ #ifdef VMS
+ #include <types.h>
+ #include <stat.h>
+ #include <file.h>
+ #else
  #include <sys/param.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/file.h>
+ #endif
  #include <errno.h>
  #include "../builtins.h"
  #include "../flags.h"
diff -r -c bash-1_14_7/builtins/history.def bash1147/builtins/history.def
*** bash-1_14_7/builtins/history.def	Wed Mar 10 09:43:51 1999
--- bash1147/builtins/history.def	Wed Mar 10 09:45:03 1999
***************
*** 37,44 ****
--- 37,49 ----
  
  #include "../shell.h"
  #if defined (HISTORY)
+ #ifdef VMS
+ #include <types.h>
+ #include <file.h>
+ #else
  #include <sys/types.h>
  #include <sys/file.h>
+ #endif
  #include "../filecntl.h"
  #include "../posixstat.h"
  #include "../bashhist.h"
diff -r -c bash-1_14_7/builtins/mkbuiltins.c bash1147/builtins/mkbuiltins.c
*** bash-1_14_7/builtins/mkbuiltins.c	Wed Mar 10 09:43:52 1999
--- bash1147/builtins/mkbuiltins.c	Wed Mar 10 09:45:04 1999
***************
*** 231,240 ****
--- 231,247 ----
  
        if (structfile)
  	{
+ 	  char buff [256];
  	  write_longdocs (structfile, saved_builtins);
  	  fclose (structfile);
+ #if defined (VMS)
+ 	  sprintf (buff, "rename %s. %s",
+ 		   temp_struct_filename, struct_filename);
+ 	  system (buff);
+ #else
  	  link (temp_struct_filename, struct_filename);
  	  unlink (temp_struct_filename);
+ #endif
  	}
  
        if (externfile)
***************
*** 500,506 ****
  		  else
  		    fprintf (defs->output, "#line %d \"%s%s\"\n",
  			     defs->line_number + 1,
! 			     error_directory ? error_directory : "./",
  			     defs->filename);
  		  output_cpp_line_info = 0;
  		}
--- 507,513 ----
  		  else
  		    fprintf (defs->output, "#line %d \"%s%s\"\n",
  			     defs->line_number + 1,
! 			     error_directory ? error_directory : "",
  			     defs->filename);
  		  output_cpp_line_info = 0;
  		}
***************
*** 840,846 ****
       char *format, *arg1, *arg2;
  {
    if (defs->filename[0] != '/')
!     fprintf (stderr, "%s", error_directory ? error_directory : "./");
    fprintf (stderr, "%s:%d:", defs->filename, defs->line_number + 1);
    fprintf (stderr, format, arg1, arg2);
    fprintf (stderr, "\n");
--- 847,853 ----
       char *format, *arg1, *arg2;
  {
    if (defs->filename[0] != '/')
!     fprintf (stderr, "%s", error_directory ? error_directory : "");
    fprintf (stderr, "%s:%d:", defs->filename, defs->line_number + 1);
    fprintf (stderr, format, arg1, arg2);
    fprintf (stderr, "\n");
diff -r -c bash-1_14_7/builtins/psize.sh bash1147/builtins/psize.sh
*** bash-1_14_7/builtins/psize.sh	Wed Mar 10 09:43:52 1999
--- bash1147/builtins/psize.sh	Wed Mar 10 09:45:04 1999
***************
*** 11,17 ****
  echo " */"
  echo ""
  
! ./psize.aux 2>/tmp/pipesize | sleep 3
  
  if [ -s /tmp/pipesize ]; then
  	echo "#define PIPESIZE `cat /tmp/pipesize`"
--- 11,17 ----
  echo " */"
  echo ""
  
! ./psize.exe 2>/tmp/pipesize | sleep 3
  
  if [ -s /tmp/pipesize ]; then
  	echo "#define PIPESIZE `cat /tmp/pipesize`"
diff -r -c bash-1_14_7/builtins/source.def bash1147/builtins/source.def
*** bash-1_14_7/builtins/source.def	Wed Mar 10 09:43:52 1999
--- bash1147/builtins/source.def	Wed Mar 10 09:45:05 1999
***************
*** 98,104 ****
      {
        char *string, *filename;
        struct stat finfo;
!       int fd, tt;
  
        filename = find_path_file (list->word->word);
        if (!filename)
--- 98,104 ----
      {
        char *string, *filename;
        struct stat finfo;
!       int fd, tt, pos;
  
        filename = find_path_file (list->word->word);
        if (!filename)
***************
*** 108,120 ****
  	goto file_error_exit;
  
        string = (char *)xmalloc (1 + (int)finfo.st_size);
!       tt = read (fd, string, finfo.st_size);
!       string[finfo.st_size] = '\0';
  
        /* Close the open file, preserving the state of errno. */
        { int temp = errno; close (fd); errno = temp; }
  
        if (tt != finfo.st_size)
  	{
  	  free (string);
  
--- 108,127 ----
  	goto file_error_exit;
  
        string = (char *)xmalloc (1 + (int)finfo.st_size);
!       pos = 0;
!       while ((tt = read (fd, &string [pos], finfo.st_size)) > 0)
! 	pos += tt;
!       string [pos] = '\0';
!       tt = pos;
  
        /* Close the open file, preserving the state of errno. */
        { int temp = errno; close (fd); errno = temp; }
  
+ #if defined (USE_VMS)
+       if (tt < 0)
+ #else
        if (tt != finfo.st_size)
+ #endif
  	{
  	  free (string);
  
diff -r -c bash-1_14_7/builtins/ulimit.def bash1147/builtins/ulimit.def
*** bash-1_14_7/builtins/ulimit.def	Wed Mar 10 09:43:53 1999
--- bash1147/builtins/ulimit.def	Wed Mar 10 09:45:06 1999
***************
*** 52,59 ****
--- 52,63 ----
  $END
  
  #include <stdio.h>
+ #ifdef VMS
+ #include <types.h>
+ #else
  #include <sys/types.h>
  #include <sys/param.h>
+ #endif
  #include <errno.h>
  #include "../shell.h"
  #include "pipesize.h"
***************
*** 138,143 ****
--- 142,151 ----
  static void print_all_limits ();
  
  static char t[2];
+ 
+ #if defined (USE_VMS)
+ static RLIMTYPE ulimit () {return 0;}
+ #endif
  
  /* Return 1 if the limit associated with CMD can be raised from CURRENT
     to NEW.  This is for USG systems without HAVE_RESOURCE, most of which
diff -r -c bash-1_14_7/command.h bash1147/command.h
*** bash-1_14_7/command.h	Wed Mar 10 09:43:45 1999
--- bash1147/command.h	Wed Mar 10 09:44:52 1999
***************
*** 45,50 ****
--- 45,53 ----
  			   or backslash is present. */
    int assignment;	/* Non-zero means that this word contains an
  			   assignment. */
+ #if defined (USE_VMS)
+   int expansion;	/* path expansion for "/" and "//x/" */
+ #endif
  } WORD_DESC;
  
  /* A linked list of words. */
diff -r -c bash-1_14_7/config.h bash1147/config.h
*** bash-1_14_7/config.h	Wed Mar 10 09:43:45 1999
--- bash1147/config.h	Wed Mar 10 09:44:52 1999
***************
*** 47,52 ****
--- 47,56 ----
  #  endif /* !_POSIX_JOB_CONTROL */
  #endif /* USG || Minix || MINIX */
  
+ #if defined (USE_VMS)
+ #  undef JOB_CONTROL
+ #endif
+ 
  /* Define ALIAS if you want the alias features. */
  #define ALIAS
  
***************
*** 89,96 ****
--- 93,105 ----
  #endif
  
  /* The default value of the PATH variable. */
+ #if defined (USE_VMS)
+ #define DEFAULT_PATH_VALUE \
+   "/gnu/bin:/bin:."
+ #else
  #define DEFAULT_PATH_VALUE \
    "/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:."
+ #endif
  
  /* The value for PATH when invoking `command -p'.  This is only used when
     the Posix.2 confstr () function, or CS_PATH define are not present. */
diff -r -c bash-1_14_7/execute_cmd.c bash1147/execute_cmd.c
*** bash-1_14_7/execute_cmd.c	Wed Mar 10 09:43:46 1999
--- bash1147/execute_cmd.c	Fri Mar 19 17:49:29 1999
***************
*** 33,39 ****
--- 33,41 ----
  #define SIGABRT SIGIOT
  #endif
  
+ #if !defined (VMS)
  #include <sys/param.h>
+ #endif
  #include <errno.h>
  
  #if !defined (errno)
***************
*** 46,53 ****
--- 48,64 ----
  #  include <strings.h>
  #endif /* !HAVE_STRING_H */
  
+ #ifdef VMS
+ #include <wait.h>
+ #include <climsgdef>
+ #endif
+ 
  #include "shell.h"
+ #if defined (VMS)
+ #include "y_tab.h"
+ #else
  #include "y.tab.h"
+ #endif
  #include "flags.h"
  #include "hash.h"
  #include "jobs.h"
***************
*** 92,97 ****
--- 103,124 ----
  static int execute_builtin_or_function (), add_undo_redirect ();
  static char *find_user_command_internal (), *find_user_command_in_path ();
  
+ #if defined (USE_VMS)
+ #include <stdlib.h>
+ #include "vmsutil.h"
+ #include "trap.h"
+ static int check_batch_file (char *filename);
+ static void expand_words_for_internal_command (WORD_LIST *words);
+ static void expand_arguments_for_external_command (WORD_LIST *words, char **args,
+ 						   char **except);
+ static void maybe_expand_arguments (WORD_LIST *words, char *command, char **args);
+ extern char *extract_unit (char *string, int *p_index, int separator);
+ extern int subshell_exit_value;
+ extern int subshell_exit_builtin;
+ extern int subshell_skip_commands;
+ extern int startup_state;
+ #endif
+ 
  /* The line number that the currently executing function starts on. */
  static int function_line_number = 0;
  
***************
*** 129,134 ****
--- 156,169 ----
  
  struct fd_bitmap *current_fds_to_close = (struct fd_bitmap *)NULL;
  
+ int
+ debug_getname (fd)
+      int fd;
+ {
+   char buffer[256];
+   fprintf (stderr, "fd - %d: %s\n", fd, getname (fd, buffer));
+ }
+ 
  #define FD_BITMAP_DEFAULT_SIZE 32
  /* Functions to allocate and deallocate the structures used to pass
     information from the shell to its children about file descriptors
***************
*** 178,183 ****
--- 213,291 ----
      }
  }
  
+ #if defined (USE_VMS)
+ static int delay_remove_size = 0;
+ static int delay_remove_counts = 0;
+ static char **delay_remove_filenames = NULL;
+ #define DELAY_REMOVE_DEFAULT_SIZE 5 /* at least size */
+ 
+ static void
+ add_delay_remove (const char *filename)
+ {
+   int i;
+ 
+   if (delay_remove_filenames == NULL)
+     {
+       delay_remove_size = DELAY_REMOVE_DEFAULT_SIZE;
+       delay_remove_counts = 0;
+       delay_remove_filenames = (char **) xmalloc (sizeof (char *)
+ 						  * delay_remove_size);
+       for (i = 0; i < delay_remove_size; i++)
+ 	delay_remove_filenames[i] = NULL;
+     }
+   else if (delay_remove_size >= delay_remove_counts)
+     {
+       delay_remove_size *= 2;
+       delay_remove_filenames = (char **) xrealloc (delay_remove_filenames,
+ 						   sizeof (char *)
+ 						   * delay_remove_size);
+       for (i = delay_remove_counts; i < delay_remove_size; i++)
+ 	delay_remove_filenames[i] = NULL;
+     }
+ 
+   for (i = 0; i < delay_remove_size; i++)
+     if (delay_remove_filenames[i] == NULL)
+       {
+ 	delay_remove_filenames[i] = savestring (filename);
+ 	delay_remove_counts++;
+ 	break;
+       }
+ }
+ 
+ static void
+ try_delay_remove (void)
+ {
+   int i;
+ 
+   if (delay_remove_counts == 0)
+     return;
+ 
+   /* search and delete if found */
+   for (i = 0; i < delay_remove_size; i++)
+     {
+       if (delay_remove_filenames[i] == NULL)
+ 	continue;
+ 
+       if (remove (delay_remove_filenames[i]) == 0)
+ 	{
+ 	  free (delay_remove_filenames[i]);
+ 	  delay_remove_filenames[i] = NULL;
+ 	  delay_remove_counts--;
+ 	}
+     }
+ 
+   if (delay_remove_counts == 0
+       && delay_remove_size != DELAY_REMOVE_DEFAULT_SIZE)
+     {
+       /* shrink array size */
+       delay_remove_size = DELAY_REMOVE_DEFAULT_SIZE;
+       delay_remove_filenames = (char **) xrealloc (delay_remove_filenames,
+ 						   sizeof (char *)
+ 						   * delay_remove_size);
+     }
+ }
+ #endif
+ 
  /* Execute the command passed in COMMAND.  COMMAND is exactly what
     read_command () places into GLOBAL_COMMAND.  See "command.h" for the
     details of the command structure.
***************
*** 190,195 ****
--- 298,306 ----
  {
    struct fd_bitmap *bitmap;
    int result;
+ #if defined (USE_VMS)
+   int pipes = vmsutil_pipe_no ();
+ #endif
  
    current_fds_to_close = (struct fd_bitmap *)NULL;
    bitmap = new_fd_bitmap (FD_BITMAP_DEFAULT_SIZE);
***************
*** 205,210 ****
--- 316,325 ----
  #if defined (PROCESS_SUBSTITUTION)
    unlink_fifo_list ();
  #endif /* PROCESS_SUBSTITUTION */
+ #if defined (USE_VMS)
+   vmsutil_pipe_clean (pipes);
+   try_delay_remove ();
+ #endif
  
    return (result);
  }
***************
*** 283,289 ****
--- 398,408 ----
    fprintf (stderr, "pid %d open files:", getpid ());
    for (i = 3; i < fd_table_size; i++)
      {
+ #if defined (USE_VMS)
+       if ((f = vmsfcntl (i, F_GETFD, 0)) != -1)
+ #else
        if ((f = fcntl (i, F_GETFD, 0)) != -1)
+ #endif
  	fprintf (stderr, " %d (%s)", i, f ? "close" : "open");
      }
    fprintf (stderr, "\n");
***************
*** 314,319 ****
--- 433,442 ----
    int invert, ignore_return;
    REDIRECT *my_undo_list, *exec_undo_list;
  
+ #if defined (USE_VMS)
+   if (subshell_skip_commands)
+     return (EXECUTION_SUCCESS);
+ #endif
    if (!command || breaking || continuing)
      return (EXECUTION_SUCCESS);
  
***************
*** 331,349 ****
--- 454,502 ----
         (pipe_out != NO_PIPE || pipe_in != NO_PIPE || asynchronous)))
      {
        pid_t paren_pid;
+ #if defined (USE_VMS)
+       COMMAND *old_command;
+       OLDENVBUF oldenvbuf;
+ #endif
+ 
+ #if defined (USE_VMS)
+ 	/* save arg list */
+ 	old_command = command;
+ 	command = copy_command (old_command);
  
+ 	/* save fd, jmp_buf, current directory, global variables */
+ 	vmsutil_save_all_environment (&oldenvbuf);
+ #endif
        /* Fork a subshell, turn off the subshell bit, turn off job
  	 control and call execute_command () on the command again. */
        paren_pid = make_child (savestring (make_command_string (command)),
  			      asynchronous);
+ #if defined (USE_VMS)
+       /* force execute in parent shell */
+       if (paren_pid != 0)
+ #else
        if (paren_pid == 0)
+ #endif
  	{
  	  int user_subshell, return_code, function_value;
+ #if defined (USE_VMS)
+ 	  char *old_trap_list[1];
+ 	  int old_sigmodes[1];
+ #endif
+ 
+ #if defined (USE_VMS)
+ 	  /* save signal */
+ 	  old_trap_list[0] = trap_list[0] ? savestring (trap_list[0]) : NULL;
+ 	  old_sigmodes[0] = vmsutil_get_signal_modes (0);
  
+ 	  /* Cancel exit trap */
+ 	  restore_default_signal (0);
+ #else
  	  /* Cancel traps, in trap.c. */
  	  restore_original_signals ();
  	  if (asynchronous)
  	    setup_async_signals ();
+ #endif
  
  #if defined (JOB_CONTROL)
  	  set_sigchld_handler ();
***************
*** 427,433 ****
--- 580,593 ----
  	  if (command->redirects)
  	    {
  	      if (do_redirections (command->redirects, 1, 0, 0) != 0)
+ #if defined (USE_VMS)
+ 		{
+ 		  vmsutil_wait_status = (EXECUTION_FAILURE);
+ 		  goto _exec1_return;
+ 		}
+ #else
  		exit (EXECUTION_FAILURE);
+ #endif
  
  	      dispose_redirects (command->redirects);
  	      command->redirects = (REDIRECT *)NULL;
***************
*** 448,458 ****
--- 608,636 ----
  	  if (return_catch_flag)
  	    function_value =  setjmp (return_catch);
  
+ #if defined (USE_VMS)
+ 	  begin_unwind_frame ("subshell-execute-command");
+ 	  unwind_protect_int (subshell_exit_value);
+ 	  unwind_protect_int (subshell_exit_builtin);
+ 	  unwind_protect_int (subshell_skip_commands);
+ 
+ 	  subshell_exit_value = 0;
+ 	  subshell_exit_builtin = 1;
+ 	  subshell_skip_commands = 0;
+ #endif
  	  if (function_value)
  	    return_code = return_catch_value;
  	  else
  	    return_code = execute_command_internal
  	      (command, asynchronous, NO_PIPE, NO_PIPE, fds_to_close);
+ #if defined (USE_VMS)
+ 	  if (subshell_skip_commands)
+ 	    {
+ 	      return_code = subshell_exit_value;
+ 	      last_command_exit_value = return_code;
+ 	    }
+ 	  run_unwind_frame ("subshell-execute-command");
+ #endif
  
  	  /* If we were explicitly placed in a subshell with (), we need
  	     to do the `shell cleanup' things, such as running traps[0]. */
***************
*** 462,471 ****
--- 640,672 ----
  	      return_code = run_exit_trap ();
  	    }
  
+ #if defined (USE_VMS)
+ 	  vmsutil_wait_status = return_code << 8;
+ 
+ _exec1_return:
+ 	  /* restore signal */
+ 	  restore_default_signal (0);
+ 	  trap_list[0] = old_trap_list[0];
+ 	  vmsutil_set_signal_modes (0, old_sigmodes[0]);
+ 
+ 	  /* restore fd, jmp_buf, current directory, global variables */
+ 	  vmsutil_restore_all_environment (&oldenvbuf);
+ 
+ 	  /* restore arg list */
+ 	  dispose_command (command);
+ 	  command = old_command;
+ 
+ 	  goto _subshell_parent;
+ #else
  	  exit (return_code);
+ #endif
  	}
        else
  	{
+ #if defined (USE_VMS)
+ 	  /* parent side */
+ _subshell_parent:
+ #endif
  	  close_pipes (pipe_in, pipe_out);
  
  #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
***************
*** 504,509 ****
--- 705,714 ----
  
  	      return (EXECUTION_SUCCESS);
  	    }
+ #if defined (USE_VMS)
+ 	/* return in parent */
+ 	return (0);
+ #endif
  	}
      }
  
***************
*** 668,673 ****
--- 873,884 ----
  	    if (asynchronous)
  	      {
  		DESCRIBE_PID (last_made_pid);
+ #if defined (USE_VMS)
+ 		last_made_pid = NO_PID;
+ #if 0
+ 		last_asynchronous_pid = NO_PID;
+ #endif /* 0 */
+ #endif
  	      }
  	    else
  #if !defined (JOB_CONTROL)
***************
*** 700,705 ****
--- 911,919 ----
  	  {
  	    COMMAND *tc = command->value.Connection->first;
  	    REDIRECT *rp;
+ #if defined (USE_VMS)
+ 	    int ofd = -1;
+ #endif
  
  	    if (!tc)
  	      break;
***************
*** 723,728 ****
--- 937,950 ----
  	    {
  	      REDIRECT *tr;
  
+ #if defined (USE_VMS)
+ #if 0
+ 	      /* save stdin */
+ 	      if ((ofd = dup (0)) < 0)
+ 		internal_error ("cannot duplicate fd 0: %s",
+ 			strerror (errno));
+ #endif /* 0 */
+ #endif
  	      rd.filename = make_word ("/dev/null");
  	      tr = make_redirection (0, r_inputa_direction, rd);
  	      tr->next = tc->redirects;
***************
*** 744,749 ****
--- 966,985 ----
  		 multiple times with the same command. */
  	      REDIRECT *tr, *tl;
  
+ #if defined (USE_VMS)
+ #if 0
+ 	      /* restore stdin */
+ 	      if (ofd >= 0)
+ 		{
+ 		  if (dup2 (ofd, 0) < 0)
+ 		    internal_error ("cannot duplicate fd %d to fd 0: %s",
+ 					ofd, strerror (errno));
+ 		  close (ofd);
+ 		  ofd = -1;
+ 		}
+ #endif 
+ #endif
+ 
  	      tr = tc->redirects;
  	      do
  		{
***************
*** 811,817 ****
--- 1047,1057 ----
  		   cmd->value.Connection->connector == '|')
  	      {
  		/* Make a pipeline between the two commands. */
+ #if defined (USE_VMS)
+ 		if (vmsutil_pipe (fildes) < 0)
+ #else
  		if (pipe (fildes) < 0)
+ #endif
  		  {
  		    report_error ("pipe error: %s", strerror (errno));
  #if defined (JOB_CONTROL)
***************
*** 852,858 ****
--- 1092,1105 ----
  			    (char *)fd_bitmap->bitmap, fds_to_close->size);
  
  		    /* And mark the pipe file descriptors to be closed. */
+ #if defined (USE_VMS)
+ #if 0
+ 		    /* close pipe in */
  		    fd_bitmap->bitmap[fildes[0]] = 1;
+ #endif /* 0 */
+ #else
+ 		    fd_bitmap->bitmap[fildes[0]] = 1;
+ #endif
  
  		    /* In case there are pipe or out-of-processes errors, we
  		       want all these file descriptors to be closed when
***************
*** 1053,1058 ****
--- 1300,1309 ----
        REAP ();
        QUIT;
  
+ #if defined (USE_VMS)
+       if (subshell_skip_commands)
+ 	break;
+ #endif
        if (breaking)
  	{
  	  breaking--; 
***************
*** 1335,1340 ****
--- 1586,1595 ----
        REAP ();
        QUIT;
  
+ #if defined (USE_VMS)
+       if (subshell_skip_commands)
+ 	break;
+ #endif
        if (breaking)
  	{
  	  breaking--;
***************
*** 1496,1501 ****
--- 1751,1760 ----
        return_value = execute_command (while_command->test);
        REAP ();
  
+ #if defined (USE_VMS)
+       if (subshell_skip_commands)
+ 	break;
+ #endif
        if (type == CMD_WHILE && return_value != EXECUTION_SUCCESS)
  	break;
        if (type == CMD_UNTIL && return_value == EXECUTION_SUCCESS)
***************
*** 1505,1510 ****
--- 1764,1773 ----
        body_status = execute_command (while_command->action);
        QUIT;
  
+ #if defined (USE_VMS)
+       if (subshell_skip_commands)
+ 	break;
+ #endif
        if (breaking)
  	{
  	  breaking--;
***************
*** 1534,1539 ****
--- 1797,1806 ----
    if_command->test->flags |= CMD_IGNORE_RETURN;
    return_value = execute_command (if_command->test);
  
+ #if defined (USE_VMS)
+   if (subshell_skip_commands)
+      return (EXECUTION_SUCCESS);
+ #endif
    if (return_value == EXECUTION_SUCCESS)
      {
        QUIT;
***************
*** 1576,1581 ****
--- 1843,1853 ----
    char *command_line, *lastarg;
    int first_word_quoted, result;
    pid_t old_last_command_subst_pid;
+ #if defined (USE_VMS)
+ #if 0
+   int ofds[3] = { -1, -1, -1 };
+ #endif /* 0 */
+ #endif
  
    result = EXECUTION_SUCCESS;
  
***************
*** 1586,1593 ****
--- 1858,1870 ----
    /* Remember what this command line looks like at invocation. */
    command_string_index = 0;
    print_simple_command (simple_command);
+ #if defined (USE_VMS)
+   /* Expect to call function 'savestring' */
+   command_line = the_printed_command;
+ #else
    command_line = (char *)alloca (1 + strlen (the_printed_command));
    strcpy (command_line, the_printed_command);
+ #endif
  
    first_word_quoted =
      simple_command->words ? simple_command->words->word->quoted : 0;
***************
*** 1730,1735 ****
--- 2007,2018 ----
  	 If so, and we have pipes, then fork a subshell in here.  Else, just
  	 do the command. */
  
+ #if defined (USE_VMS)
+ #if 0
+       save_std_fds (ofds);
+ #endif /* 0 */
+ #endif
+ 
        if (func)
  	builtin = (Function *)NULL;
        else
***************
*** 1742,1748 ****
--- 2025,2035 ----
  	{
  	  if ((pipe_in != NO_PIPE) || (pipe_out != NO_PIPE) || async)
  	    {
+ #if defined (USE_VMS)
+ 	      if (make_child (savestring (command_line), async) != 0)
+ #else
  	      if (make_child (savestring (command_line), async) == 0)
+ #endif
  		{
  		  /* Cancel traps, in trap.c. */
  		  restore_original_signals ();
***************
*** 1750,1759 ****
--- 2037,2057 ----
  		  if (async)
  		    setup_async_signals ();
  
+ #if defined (USE_VMS)
+ 		  expand_words_for_internal_command (words);
+ #endif
  		  execute_subshell_builtin_or_function
  		    (words, simple_command->redirects, builtin, func,
  		     pipe_in, pipe_out, async, fds_to_close,
  		     simple_command->flags);
+ #if defined (USE_VMS)
+ 		  /* execute parent side */
+ 		  close_pipes (pipe_in, pipe_out);
+ #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
+ 		  unlink_fifo_list ();
+ #endif
+ 		  goto return_result;
+ #endif
  		}
  	      else
  		{
***************
*** 1766,1782 ****
--- 2064,2112 ----
  	    }
  	  else
  	    {
+ #if defined (USE_VMS)
+ #if 0
+ 	      if (subshell_environment || builtin != exec_builtin)
+ 		save_std_fds (ofds);
+ #endif /* 0 */
+ #endif
+ #if defined (USE_VMS)
+ 	      expand_words_for_internal_command (words);
+ #endif
  	      result = execute_builtin_or_function
  		(words, builtin, func, simple_command->redirects, fds_to_close,
  		 simple_command->flags);
+ #if defined (USE_VMS)
+ #if 0
+ 	      restore_std_fds (ofds);
+ #endif /* 0 */
+ #endif
  
  	      goto return_result;
  	    }
  	}
  
+ #if defined (USE_VMS)
+ #if 0
+       save_std_fds (ofds);
+ #endif /* 0 */
+ #endif
        execute_disk_command (words, simple_command->redirects, command_line,
  			    pipe_in, pipe_out, async, fds_to_close,
  			    (simple_command->flags & CMD_NO_FORK));
+ #if defined (USE_VMS)
+ #if 0
+       restore_std_fds (ofds);
+ #endif /* 0 */
+ 
+       /* sh -c "foo": Return result code */
+       if (startup_state == 2)
+ 	{
+ 	  result = vmsutil_wait_status;
+ 	  if ((result & 0x0000ff00) == 0x0000ff00)
+ 	    result &= 0x000000ff;
+ 	}
+ #endif
  
        goto return_result;
      }
***************
*** 1786,1805 ****
--- 2116,2154 ----
  	 care of it.  Just fork, do piping and redirections, and exit. */
        if (make_child (savestring (""), async) == 0)
  	{
+ #if !(defined (USE_VMS))
  	  /* Cancel traps, in trap.c. */
  	  restore_original_signals ();
+ #endif
  
  	  do_piping (pipe_in, pipe_out);
  
  	  subshell_environment = 1;
  
  	  if (do_redirections (simple_command->redirects, 1, 0, 0) == 0)
+ #if defined (USE_VMS)
+ 	    {
+ 	      vmsutil_wait_status = (EXECUTION_SUCCESS);
+ 	      goto null_return_exit;
+ 	    }
+ #else
  	    exit (EXECUTION_SUCCESS);
+ #endif
  	  else
+ #if defined (USE_VMS)
+ 	    {
+ 	      vmsutil_wait_status = (EXECUTION_FAILURE);
+ 	      goto null_return_exit;
+ 	    }
+ #else
  	    exit (EXECUTION_FAILURE);
+ #endif
  	}
        else
  	{
+ #if defined (USE_VMS)
+ null_return_exit:
+ #endif
  	  close_pipes (pipe_in, pipe_out);
  #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
  	  unlink_fifo_list ();
***************
*** 1826,1831 ****
--- 2175,2186 ----
      }
  
   return_result:
+ #if defined (USE_VMS)
+ #if 0
+   restore_std_fds (ofds);
+ #endif /* 0 */
+ #endif
+ 
    bind_lastarg (lastarg);
    /* The unwind-protect frame is set up only if WORDS is not empty. */
    if (words)
***************
*** 1878,1883 ****
--- 2233,2244 ----
  
    result = ((*builtin) (words->next));
  
+ #if defined (USE_VMS)
+   /* check subshell return */
+   if (builtin == exit_builtin && result == EXECUTION_SUCCESS)
+     result = last_command_exit_value;
+ #endif
+ 
    if (subshell == 0 && builtin == source_builtin)
      {
        dispose_builtin_env ();
***************
*** 1999,2004 ****
--- 2360,2373 ----
       struct fd_bitmap *fds_to_close;
       int flags;
  {
+ #if defined (USE_VMS)
+       OLDENVBUF oldenvbuf;
+ #endif
+ 
+ #if defined (USE_VMS)
+   /* save fd, jmp_buf, current directory, global variables */
+   vmsutil_save_all_environment (&oldenvbuf);
+ #endif
    /* A subshell is neither a login shell nor interactive. */
    login_shell = interactive = 0;
  
***************
*** 2029,2035 ****
--- 2398,2411 ----
      close_fd_bitmap (fds_to_close);
  
    if (do_redirections (redirects, 1, 0, 0) != 0)
+ #if defined (USE_VMS)
+     {
+       vmsutil_wait_status = (EXECUTION_FAILURE);
+       goto return_exit;
+     }
+ #else
      exit (EXECUTION_FAILURE);
+ #endif
  
    if (builtin)
      {
***************
*** 2039,2044 ****
--- 2415,2433 ----
  	 so we don't go back up to main(). */
        result = setjmp (top_level);
  
+ #if defined (USE_VMS)
+       if (result == EXITPROG)
+ 	vmsutil_wait_status = (last_command_exit_value);
+       else if (result)
+ 	vmsutil_wait_status = (EXECUTION_FAILURE);
+       else
+ 	vmsutil_wait_status = (execute_builtin (builtin, words, flags, 1));
+     }
+   else
+     {
+       vmsutil_wait_status = (execute_function (var, words, flags, fds_to_close, async, 1));
+     }
+ #else
        if (result == EXITPROG)
  	exit (last_command_exit_value);
        else if (result)
***************
*** 2050,2055 ****
--- 2439,2453 ----
      {
        exit (execute_function (var, words, flags, fds_to_close, async, 1));
      }
+ #endif
+ #if defined (USE_VMS)
+ return_exit:
+   /* restore fd, jmp_buf, current directory, global variables */
+   vmsutil_restore_all_environment (&oldenvbuf);
+ 
+   /* return in subshell */
+   return;
+ #endif
  }
  
  /* Execute a builtin or function in the current shell context.  If BUILTIN
***************
*** 2167,2172 ****
--- 2565,2574 ----
    char *hashed_file, *command, **args;
    int pid, temp_path;
    SHELL_VAR *path;
+ #if defined (USE_VMS)
+   int ofds[3] = { -1, -1, -1 };
+   char *fixp;
+ #endif
  
    pathname = words->word->word;
  #if defined (RESTRICTED_SHELL)
***************
*** 2203,2209 ****
--- 2605,2619 ----
      {
        int st;
  
+ #if defined (USE_VMS)
+       /* for adding extention (dot + 3ext) */
+       fixp = xmalloc (1 + strlen (hashed_file) + 1 + 3);
+       strcpy (fixp, hashed_file);
+       st = file_status (fixp);
+       free (fixp);
+ #else
        st = file_status (hashed_file);
+ #endif
        if ((st ^ (FS_EXISTS | FS_EXECABLE)) != 0)
  	{
  	  remove_hashed_filename (pathname);
***************
*** 2216,2222 ****
--- 2626,2644 ----
    else if (absolute_program (pathname))
      /* A command containing a slash is not looked up in PATH or saved in
         the hash table. */
+ #if defined (USE_VMS)
+     {
+       /* search suffix */
+       fixp = vmsutil_expand_path (savestring (pathname));
+       command = find_user_command_internal (fixp, FS_EXEC_ONLY);
+       if (command == NULL)
+ 	command = fixp;
+       else
+ 	free (fixp);
+     }
+ #else
      command = savestring (pathname);
+ #endif
    else
      {
        command = find_user_command (pathname);
***************
*** 2234,2247 ****
--- 2656,2688 ----
    /* If we can get away without forking and there are no pipes to deal with,
       don't bother to fork, just directly exec the command. */
    if (nofork && pipe_in == NO_PIPE && pipe_out == NO_PIPE)
+ #if defined (USE_VMS)
+     pid = vmsutil_current_pid;
+ #else
      pid = 0;
+ #endif
    else
+ #if defined (USE_VMS)
+     {
+       vmsutil_save_std_fds (ofds);
+       pid = make_child (savestring (command_line), async);
+     }
+ #else
      pid = make_child (savestring (command_line), async);
+ #endif
  
+ #if defined (USE_VMS)
+   if (pid != 0)
+ #else
    if (pid == 0)
+ #endif
      {
        int old_interactive;
+ #if defined (USE_VMS)
+       int old_subshell_environment = subshell_environment;
+ #endif
  
+ #if !(defined (USE_VMS))
        /* Cancel traps, in trap.c. */
        restore_original_signals ();
  
***************
*** 2250,2255 ****
--- 2691,2697 ----
           in asynchronous children. */
        if (async)
  	setup_async_signals ();
+ #endif
  
        do_piping (pipe_in, pipe_out);
  
***************
*** 2281,2307 ****
--- 2723,2796 ----
  	     result of redirections. */
  	  unlink_fifo_list ();
  #endif /* PROCESS_SUBSTITUTION */
+ #if defined (USE_VMS)
+ 	  vmsutil_wait_status = (EXECUTION_FAILURE);
+ 	  goto _exec_return;
+ #else
  	  exit (EXECUTION_FAILURE);
+ #endif
  	}
  
        if (async)
  	interactive = old_interactive;
  
+ #if defined (USE_VMS)
+       if (!command)
+ 	{
+ 	  vmsutil_wait_status = vms_spawn (words, pathname, args);
+ 	  if (vmsutil_wait_status == EXECUTION_SUCCESS)
+ 	    goto _exec_return;
+ 	  if (vmsutil_wait_status != CLI$_IVVERB)
+ 	    {
+ 	      vmsutil_wait_status = (EX_USAGE << 8);
+ 	      goto _exec_return;
+ 	    }
+ 	}
+ #endif
+ 
        if (!command)
  	{
  	  report_error ("%s: command not found", args[0]);
+ #if defined (USE_VMS)
+ 	  vmsutil_wait_status = (EX_NOTFOUND << 8);
+ 	  goto _exec_return;
+ #else
  	  exit (EX_NOTFOUND);	/* Posix.2 says the exit status is 127 */
+ #endif
  	}
  
+ #if defined (USE_VMS)
+       vmsutil_wait_status = shell_execve_dos (words, command, args, export_env, 1);
+ _exec_return:
+       dispose_word_array (args);
+ 
+       vmsutil_restore_std_fds (ofds);
+ 
+       /* for parent shell */
+       if (pid == vmsutil_current_pid)
+ 	goto disk_command_nofork;
+ 
+       /* restore parent environment */
+       subshell_environment = old_subshell_environment;
+ 
+       goto disk_command_parent;
+ #else
        exit (shell_execve (command, args, export_env));
+ #endif
      }
    else
      {
+ #if defined (USE_VMS)
+ disk_command_parent:
+ #endif
        /* Make sure that the pipes are closed in the parent. */
        close_pipes (pipe_in, pipe_out);
  #if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
        unlink_fifo_list ();
  #endif
+ #if defined (USE_VMS)
+ disk_command_nofork:
+ #endif
        FREE (command);
      }
  }
***************
*** 2315,2359 ****
--- 2804,2914 ----
  
     The word immediately following the #! is the interpreter to execute.
     A single argument to the interpreter is allowed. */
+ #if defined (USE_VMS)
+ static int
+ execute_shell_script (sample, sample_len, words, command, args, env)
+      unsigned char *sample;
+      int sample_len;
+      WORD_LIST *words;
+      char *command;
+      char **args, **env;
+ #else
  static int
  execute_shell_script (sample, sample_len, command, args, env)
       unsigned char *sample;
       int sample_len;
       char *command;
       char **args, **env;
+ #endif
  {
    register int i;
    char *execname, *firstarg;
    int start, size_increment, larry;
+ #if defined (USE_VMS)
+   WORD_LIST *newwords;
+   char *fixp;
+   char **newargs;
+   int status;
+ #endif
  
    /* Find the name of the interpreter to exec. */
    for (i = 2; whitespace (sample[i]) && i < sample_len; i++)
      ;
  
+ #if defined (USE_VMS)
+   /* support CR/LF */
+   for (start = i;
+        !whitespace (sample[i]) && sample[i] != '\r'
+        && sample[i] != '\n' && i < sample_len;
+        i++)
+ #else
    for (start = i;
         !whitespace (sample[i]) && sample[i] != '\n' && i < sample_len;
         i++)
+ #endif
      ;
  
    execname = xmalloc (1 + (i - start));
    strncpy (execname, (char *) (sample + start), i - start);
    execname[i - start] = '\0';
+ #if defined (USE_VMS)
+   /* search suffix */
+   fixp = vmsutil_expand_path (execname);
+   execname = find_user_command_internal (fixp, FS_EXEC_ONLY);
+   if (execname == NULL)
+     execname = fixp;
+   else
+     free (fixp);
+ 
+   /* research without absolute pathname? */
+   if (access (execname, X_OK) != 0 && (fixp = strrchr (execname, '/')) != NULL)
+     {
+       fixp++;
+       strcpy (execname, fixp);
+       fixp = xmalloc (strlen (execname) + 5);
+       strcpy (fixp, execname);
+       free (execname);
+       execname = find_user_command_internal (fixp, FS_EXEC_ONLY);
+     }
+ #endif
    size_increment = 1;
  
    /* Now the argument, if any. */
    firstarg = (char *)NULL;
+ #if defined (USE_VMS)
+   /* support CR/LF */
+   for (start = i;
+        whitespace (sample[i]) && sample[i] != '\r'
+        && sample[i] != '\n' && i < sample_len;
+        i++)
+ #else
    for (start = i;
         whitespace (sample[i]) && sample[i] != '\n' && i < sample_len;
         i++)
+ #endif
      ;
  
    /* If there is more text on the line, then it is an argument for the
       interpreter. */
+ #if defined (USE_VMS)
+   /* support CR/LF */
+   if (i < sample_len && sample[i] != '\r'
+       && sample[i] != '\n' && !whitespace (sample[i]))
+ #else
    if (i < sample_len && sample[i] != '\n' && !whitespace (sample[i]))
+ #endif
      {
+ #if defined (USE_VMS)
+       /* support CR/LF */
+       for (start = i;
+ 	   !whitespace (sample[i]) && sample[i] != '\r'
+ 	   && sample[i] != '\n' && i < sample_len;
+ 	   i++)
+ #else
        for (start = i;
  	   !whitespace (sample[i]) && sample[i] != '\n' && i < sample_len;
  	   i++)
+ #endif
  	;
        firstarg = xmalloc (1 + (i - start));
        strncpy (firstarg, (char *)(sample + start), i - start);
***************
*** 2364,2373 ****
--- 2919,2941 ----
  
    larry = array_len (args) + size_increment;
  
+ #if defined (USE_VMS)
+   newargs = (char **)xmalloc ((1 + larry) * sizeof (char *));
+   newwords = copy_word_list (words);
+   if (firstarg)
+     newwords = make_word_list (make_word (firstarg), newwords);
+   newwords = make_word_list (make_word (execname), newwords);
+ 
+   for (i = larry - 1; i >= size_increment; i--)
+     newargs[i] = args[i - size_increment];
+ 
+   args = newargs;
+ #else
    args = (char **)xrealloc ((char *)args, (1 + larry) * sizeof (char *));
  
    for (i = larry - 1; i; i--)
      args[i] = args[i - size_increment];
+ #endif
  
    args[0] = execname;
    if (firstarg)
***************
*** 2380,2401 ****
  
    args[larry] = (char *)NULL;
  
    return (shell_execve (execname, args, env));
  }
  
  /* Call execve (), handling interpreting shell scripts, and handling
     exec failures. */
  int
  shell_execve (command, args, env)
       char *command;
       char **args, **env;
  {
  #if defined (isc386) && defined (_POSIX_SOURCE)
    __setostype (0);		/* Turn on USGr3 semantics. */
    execve (command, args, env);
    __setostype (1);		/* Turn the POSIX semantics back on. */
  #else
!   execve (command, args, env);
  #endif /* !(isc386 && _POSIX_SOURCE) */
  
    /* If we get to this point, then start checking out the file.
--- 2948,3081 ----
  
    args[larry] = (char *)NULL;
  
+ #if defined (USE_VMS)
+   status = shell_execve_dos (newwords, execname, args, env, 1);
+   dispose_words (newwords);
+   free (execname);
+   free (newargs);
+   return status;
+ #else
    return (shell_execve (execname, args, env));
+ #endif
  }
  
+ #if defined (USE_VMS)
+ typedef struct dsc {unsigned short len, mbz; char *adr; } Descr;
+ 
+ int
+ vms_spawn (words, command, args)
+      WORD_LIST *words;
+      char *command;
+      char **args;
+ {
+   Descr cmd;
+   int status, vms_status;
+   int i;
+   int len = 1;
+ 
+   for (i=0; args[i]; i++)
+     len = len + strlen (args[i]) + 1;
+ 
+   {
+     char *allargs = (char*) xmalloc (len);
+ 
+     strcpy (allargs, args [0]);
+     strcat (allargs, " ");
+ 
+     for (i=1; args[i]; i++)
+       {
+         strcat (allargs, args[i]);
+         strcat (allargs, " ");
+       }
+     cmd.adr = allargs;
+     cmd.len = len;
+     cmd.mbz = 0;
+ 
+     vms_status = lib$spawn (&cmd,0,0,0,0,0,&status);
+     xfree (allargs);
+ 
+     if ((vms_status & 1) != 1)
+       return (vms_status);
+ 
+     vms_status = status;
+     if ((vms_status & 1) != 1)
+       return (vms_status);
+ 
+     return (EXECUTION_SUCCESS);
+   }
+ }
+ #endif
+ 
  /* Call execve (), handling interpreting shell scripts, and handling
     exec failures. */
+ #if defined (USE_VMS)
+ int
+ shell_execve (command, args, env)
+      char *command;
+      char **args, **env;
+ {
+   return shell_execve_dos ((WORD_LIST *)NULL, command, args, env, 0);
+ }
+ 
+ /*
+  * flag: 0 = execve, 1 = spawnve, 2 = spawnve from exec builtin,
+  */
+ int
+ shell_execve_dos (words, command, args, env, flag)
+      WORD_LIST *words;
+      char *command;
+      char **args, **env;
+      int flag;
+ #else
  int
  shell_execve (command, args, env)
       char *command;
       char **args, **env;
+ #endif
  {
  #if defined (isc386) && defined (_POSIX_SOURCE)
    __setostype (0);		/* Turn on USGr3 semantics. */
    execve (command, args, env);
    __setostype (1);		/* Turn the POSIX semantics back on. */
  #else
! #if defined (USE_VMS)
!   int status = -1;
!   char **newargs;
! #if defined (USE_VMS)
!   int real_pid;
! #endif
! 
!   if (flag)
!     {
! #if defined (USE_VMS)
! #if 0
!       {
! 	char buffer[256];
! 	fprintf (stderr, "stdin: %s\n", getname (0, buffer));
! 	fprintf (stderr, "stdout: %s\n", getname (1, buffer));
! 	fprintf (stderr, "stderr: %s\n", getname (2, buffer));
!       }
! #endif
!       if ((real_pid = vfork ()) < 0)
! 	return (real_pid);
!       else if (real_pid == 0)
! 	{
! 	  if ((status = execve (command, args, env)) >= 0)
! 	    exit (status);
! 	}
!       else
! 	{
! 	  waitpid (real_pid, &status, 0);
! 	  return (status);
! 	}
! #else
!       if ((status = spawnve (P_WAIT, command, args, env)) >= 0)
! 	return status;
! #endif
!     }
!   else
! #endif
!     execve (command, args, env);
  #endif /* !(isc386 && _POSIX_SOURCE) */
  
    /* If we get to this point, then start checking out the file.
***************
*** 2421,2427 ****
--- 3101,3111 ----
  	   if the first line (or up to 30 characters) are in the ASCII set.
  	   Execute the contents as shell commands. */
  	int larray = array_len (args) + 1;
+ #if defined (USE_VMS)
+ 	int i, should_exec = 1;
+ #else
  	int i, should_exec = 0;
+ #endif
  
  	{
  	  int fd = open (command, O_RDONLY);
***************
*** 2443,2450 ****
--- 3127,3139 ----
  		 characters. */
  
  	      if (sample_len > 0 && sample[0] == '#' && sample[1] == '!')
+ #if defined (USE_VMS)
+ 		return (execute_shell_script
+ 			(sample, sample_len, words, command, args, env));
+ #else
  		return (execute_shell_script
  			(sample, sample_len, command, args, env));
+ #endif
  	      else if ((sample_len != -1) &&
  		       check_binary_file (sample, sample_len))
  		{
***************
*** 2453,2458 ****
--- 3142,3149 ----
  		}
  	    }
  	}
+ 
+ #if !(defined (USE_VMS))
  #if defined (JOB_CONTROL)
  	/* Forget about the way that job control was working. We are
  	   in a subshell. */
***************
*** 2467,2478 ****
--- 3158,3179 ----
  	set_sigchld_handler ();
  #endif /* JOB_CONTROL */
  	set_sigint_handler ();
+ #endif
  
  	/* Insert the name of this shell into the argument list. */
+ #if defined (USE_VMS)
+ 	newargs = (char **)xmalloc ((1 + larray) * sizeof (char *));
+ 
+ 	for (i = larray - 1; i; i--)
+ 	  newargs[i] = args[i - 1];
+ 
+ 	args = newargs;
+ #else
  	args = (char **)xrealloc ((char *)args, (1 + larray) * sizeof (char *));
  
  	for (i = larray - 1; i; i--)
  	  args[i] = args[i - 1];
+ #endif
  
  	args[0] = shell_name;
  	args[1] = command;
***************
*** 2490,2504 ****
--- 3191,3242 ----
  	    execve (shell_name, args, env);
  	    __setostype (1);	/* Turn the POSIX semantics back on. */
  #else
+ #if defined (USE_VMS)
+ 	    if (flag)
+ 	      {
+ #if defined (USE_VMS)
+ #if 0
+ 		{
+ 		  char buffer[256];
+ 		  fprintf (stderr, "stdin: %s\n", getname (0, buffer));
+ 		  fprintf (stderr, "stdout: %s\n", getname (1, buffer));
+ 		  fprintf (stderr, "stderr: %s\n", getname (2, buffer));
+ 		}
+ #endif
+ 		if ((real_pid = vfork ()) < 0)
+ 		  return (real_pid);
+ 		else if (real_pid == 0)
+ 		  {
+ 		    if ((status = execve (shell_name, args, env)) >= 0)
+ 		      exit (status);
+ 		  }
+ 		else
+ 		  {
+ 		    waitpid (real_pid, &status, 0);
+ 		    return (status);
+ 		  }
+ #endif
+ 	      }
+ 	    else
+ #endif
  	    execve (shell_name, args, env);
  #endif /* isc386 && _POSIX_SOURCE */
  
+ #if 0 /* defined (USE_VMS) */
+ 	    /* ??? Copy stuff from Gnu make to execute command file */
+ #endif
+ 
  	    /* Oh, no!  We couldn't even exec this! */
  	    if ((stat (args[0], &finfo) == 0) && (S_ISDIR (finfo.st_mode)))
  	      report_error ("%s: is a directory", args[0]);
  	    else
  	      file_error (args[0]);
  
+ #if defined (USE_VMS)
+ 	    free (newargs);
+ 	    if (flag == 2)
+ 	      return -1;
+ #endif
  	    return (EXECUTION_FAILURE);
  	  }
  	else
***************
*** 2551,2556 ****
--- 3289,3298 ----
  			pipe_in, strerror (errno));
        if (pipe_in > 0)
          close (pipe_in);
+ #if defined (USE_VMS)
+       /* reset file pointer */
+       lseek (0, 0, SEEK_SET);
+ #endif
      }
    if (pipe_out != NO_PIPE)
      {
***************
*** 2831,2836 ****
--- 3573,3581 ----
  	  struct stat finfo;
  	  int stat_result;
  
+ #if defined (USE_VMS)
+ 	  redirectee_word = vmsutil_expand_path (redirectee_word);
+ #endif
  	  stat_result = stat (redirectee_word, &finfo);
  
  	  if ((stat_result == 0) && (S_ISREG (finfo.st_mode)))
***************
*** 2844,2850 ****
--- 3589,3600 ----
  	  if (stat_result != 0)
  	    redirect->flags |= O_EXCL;
  
+ #if defined (USE_VMS)
+ 	  fd = open (redirectee_word, redirect->flags | O_APPEND, 0666,
+ 		     "rfm=stmlf", "ctx=rec", "rat=none", "shr=del,get,put,upd");
+ #else
  	  fd = open (redirectee_word, redirect->flags, 0666);
+ #endif
  
  	  if ((fd < 0) && (errno == EEXIST))
  	    {
***************
*** 2854,2860 ****
  	}
        else
  	{
! 	  fd = open (redirectee_word, redirect->flags, 0666);
  #if defined (AFS_CREATE_BUG)
  	  if ((fd < 0) && (errno == EACCES))
  	    fd = open (redirectee_word, (redirect->flags & ~O_CREAT), 0666);
--- 3604,3618 ----
  	}
        else
  	{
! #if defined (USE_VMS)
! 	  redirectee_word = vmsutil_expand_path (redirectee_word);
! #endif
! #if defined (USE_VMS)
! 	  fd = open (redirectee_word, redirect->flags, 0666,
! 		     "rfm=stmlf", "ctx=rec", "rat=none", "shr=del,get,put,upd");
! #else
! 	  fd = open (redirectee_word, redirect->flags, 0666); 
! #endif
  #if defined (AFS_CREATE_BUG)
  	  if ((fd < 0) && (errno == EACCES))
  	    fd = open (redirectee_word, (redirect->flags & ~O_CREAT), 0666);
***************
*** 2869,2875 ****
--- 3627,3637 ----
  	{
  	  if (remembering)
  	    /* Only setup to undo it if the thing to undo is active. */
+ #if defined (USE_VMS)
+ 	    if ((fd != redirector) && (vmsfcntl (redirector, F_GETFD, 0) != -1))
+ #else
  	    if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
+ #endif
  	      add_undo_redirect (redirector);
  	    else
  	      add_undo_close_redirect (redirector);
***************
*** 2934,2944 ****
--- 3696,3725 ----
  	 the new input.  Place it in a temporary file. */
        if (redirectee)
  	{
+ #if defined (USE_VMS)
+ 	  char *filename;
+ 	  char *tname;
+ 	  char *tmpdir;
+ #else
  	  char filename[40];
+ #endif
  	  pid_t pid = getpid ();
  
  	  /* Make the filename for the temp file. */
+ #if defined (USE_VMS)
+ 	  tmpdir = getenv ("TMPDIR");
+ 	  if (tmpdir == NULL)
+ 	    tmpdir = "/tmp";
+ 
+ 	  tname = xmalloc (strlen (tmpdir) + sizeof ("/shXXXXXX"));
+ 	  sprintf (tname, "%s/sh%6.6d", tmpdir, pid % 1000000);
+ 	  tname = vmsutil_expand_path (tname);
+ 	  filename = alloca (strlen (tname) + 1);
+ 	  strcpy (filename, tname);
+ 	  free (tname);
+ #else
  	  sprintf (filename, "/tmp/t%d-sh", pid);
+ #endif
  
  	  fd = open (filename, O_TRUNC | O_WRONLY | O_CREAT, 0666);
  	  if (fd < 0)
***************
*** 3014,3029 ****
--- 3795,3824 ----
  	    }	  
  
  	  close (fd);
+ #if 0 /* ??? defined (USE_VMS) */
+ 	  if (errno && errno != ENOTTY)
+ 	    return (errno);
+ 	  else
+ 	    errno = 0;
+ #else
  	  if (errno)
  	    return (errno);
+ #endif
  
  	  /* Make the document really temporary.  Also make it the input. */
  	  fd = open (filename, O_RDONLY, 0666);
  
+ #if defined (USE_VMS) /* otherwise file is unlinked */
+ 	  if (fd < 0)
+ #else
  	  if (unlink (filename) < 0 || fd < 0)
+ #endif
  	    {
  	      if (fd >= 0)
  	        close (fd);
+ #if defined (USE_VMS)
+ 	      remove (filename);
+ #endif
  	      return (errno);
  	    }
  
***************
*** 3031,3037 ****
--- 3826,3836 ----
  	    {
  	      if (remembering)
  		/* Only setup to undo it if the thing to undo is active. */
+ #if defined (USE_VMS)
+ 		if ((fd != redirector) && (vmsfcntl (redirector, F_GETFD, 0) != -1))
+ #else
  		if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
+ #endif
  		  add_undo_redirect (redirector);
  		else
  		  add_undo_close_redirect (redirector);
***************
*** 3042,3047 ****
--- 3841,3849 ----
  	      if (dup2 (fd, redirector) < 0)
  		{
  		  close (fd);
+ #if defined (USE_VMS)
+ 		  remove (filename);
+ #endif
  		  return (errno);
  		}
  
***************
*** 3058,3063 ****
--- 3860,3871 ----
  #else
  	  close (fd);
  #endif
+ #if defined (USE_VMS)
+ #if 0
+ 	  if (remove (filename) != 0)
+ #endif
+ 	    add_delay_remove (filename);
+ #endif
  	}
        break;
  
***************
*** 3067,3073 ****
--- 3875,3885 ----
  	{
  	  if (remembering)
  	    /* Only setup to undo it if the thing to undo is active. */
+ #if defined (USE_VMS)
+ 	    if (vmsfcntl (redirector, F_GETFD, 0) != -1)
+ #else
  	    if (fcntl (redirector, F_GETFD, 0) != -1)
+ #endif
  	      add_undo_redirect (redirector);
  	    else
  	      add_undo_close_redirect (redirector);
***************
*** 3091,3097 ****
--- 3903,3913 ----
  	     unless closed by something like `exec 2<&-'. */
  	  /* if ((already_set || set_unconditionally) && (ok_to_set))
  		set_it () */
+ #if defined (USE_VMS)
+ 	  if (((vmsfcntl (redir_fd, F_GETFD, 0) == 1) || set_clexec) &&
+ #else
  	  if (((fcntl (redir_fd, F_GETFD, 0) == 1) || set_clexec) &&
+ #endif
  	       (redirector > 2))
  	    SET_CLOSE_ON_EXEC (redirector);
  	}
***************
*** 3100,3106 ****
--- 3916,3927 ----
      case r_close_this:
        if (for_real)
  	{
+ 	  char buffer[256];
+ #if defined (USE_VMS)
+ 	  if (remembering && (vmsfcntl (redirector, F_GETFD, 0) != -1))
+ #else
  	  if (remembering && (fcntl (redirector, F_GETFD, 0) != -1))
+ #endif
  	    add_undo_redirect (redirector);
  
  #if defined (BUFFERED_INPUT)
***************
*** 3129,3135 ****
--- 3950,3960 ----
    int new_fd, clexec_flag;
    REDIRECT *new_redirect, *closer;
  
+ #if defined (USE_VMS)
+   new_fd = dup (fd);
+ #else
    new_fd = fcntl (fd, F_DUPFD, SHELL_FD_BASE);
+ #endif
  
    if (new_fd < 0)
      {
***************
*** 3139,3146 ****
--- 3964,3976 ----
    else
      {
        REDIRECT *dummy_redirect;
+       char buffer[256];
  
+ #if defined (USE_VMS)
+       clexec_flag = vmsfcntl (fd, F_GETFD, 0);
+ #else
        clexec_flag = fcntl (fd, F_GETFD, 0);
+ #endif
  
        rd.dest = 0L;
        closer = make_redirection (new_fd, r_close_this, rd);
***************
*** 3228,3237 ****
--- 4058,4095 ----
  {
    struct stat finfo;
    static int user_id = -1;
+ #if defined (USE_VMS)
+   char *ext, *newname;
+   int len;
+ #endif
  
    /* Determine whether this file exists or not. */
+ #if defined (USE_VMS)
+   len = strlen (name);
+   if (len + 5 > PATH_MAX)
+     return 0;
+ 
+   newname = xmalloc (len + 5);
+   strcpy (newname, name);
+   
+   ext = newname + len;
+ 
+   /* skip a directory */
+   while (stat (newname, &finfo) < 0 || S_ISDIR (finfo.st_mode))
+     {
+ #if defined (USE_VMS)
+       if (!vmsutil_add_executable_suffix (newname, ext))
+ #endif
+ 	{
+ 	  free (newname);
+ 	  return 0; /* failure */
+ 	}
+     }
+   free (newname);
+ #else
    if (stat (name, &finfo) < 0)
      return (0);
+ #endif
  
    /* If the file is a directory, then it is not "executable" in the
       sense of the shell. */
***************
*** 3478,3484 ****
--- 4336,4347 ----
    int path_len;
  
    path_len = strlen (path);
+ #if defined (USE_VMS)
+   /* for adding extention (dot + 3ext) */
+   full_path = xmalloc (2 + path_len + name_len + 1 + 3);
+ #else
    full_path = xmalloc (2 + path_len + name_len);
+ #endif
    strcpy (full_path, path);
    full_path[path_len] = '/';
    strcpy (full_path + path_len + 1, name);
***************
*** 3520,3526 ****
--- 4383,4394 ----
  
    if (absolute_program (name))
      {
+ #if defined (USE_VMS)
+       /* for adding extention (dot + 3ext) */
+       full_path = xmalloc (1 + name_len + 1 + 3);
+ #else
        full_path = xmalloc (1 + name_len);
+ #endif
        strcpy (full_path, name);
  
        status = file_status (full_path);
***************
*** 3661,3666 ****
--- 4529,4537 ----
        value = xmalloc (1 + i - start);
        strncpy (value, string + start, i - start);
        value [i - start] = '\0';
+ #if defined (USE_VMS)
+       value = vmsutil_expand_path (value);
+ #endif
  
        return (value);
      }
***************
*** 3696,3698 ****
--- 4567,4724 ----
      }
    return (0);
  }
+ 
+ #if defined (USE_VMS)
+ static int
+ check_batch_file (char *filename)
+ {
+   int len;
+ 
+   if ((len = strlen (filename)) > 4)
+     if ((filename[len - 4] == '.')
+ 	&& (filename[len - 3] == 'C' || filename[len - 3] == 'c')
+ 	&& (filename[len - 2] == 'O' || filename[len - 2] == 'o')
+ 	&& (filename[len - 1] == 'M' || filename[len - 1] == 'm'))
+       return 1;
+ 
+   return 0;
+ }
+ 
+ static void
+ expand_words_for_internal_command (WORD_LIST *words)
+ {
+   char *p;
+ 
+   if (!vmsutil_path_expand || words == NULL)
+     return;
+ 
+   words = words->next; /* skip command name */
+   while (words)
+     {
+       p = words->word->word;
+       if (words->word->expansion)
+ 	{
+ 	  /* nothing */
+ 	}
+       words->word->word = p;
+       words = words->next;
+     }
+ }
+ 
+ static void
+ expand_arguments_for_external_command (WORD_LIST *words, char **args, char **except)
+ {
+   char *p, *sysroot = NULL;
+   int i, sysroot_len = -1;
+ 
+   if (!vmsutil_path_expand || words == NULL || args == NULL || *args == NULL)
+     return;
+ 
+   if (vmsutil_sysroot_len > 0)
+     {
+       sysroot = get_string_value ("SYSROOT");
+       sysroot_len = strlen (sysroot);
+     }
+ 
+   args++; /* skip command name */
+   words = words->next;
+   while ((p = *args) != NULL)
+     {
+       /* may skip argument */
+       if (except != NULL)
+ 	{
+ 	  if (strnicmp (p, "--", sizeof ("--") - 1) == 0)
+ 	    {
+ 	      except = NULL; /* terminate switch */
+ 	      args++;
+ 	      goto done;
+ 	    }
+ 
+ 	  for (i = 1; except[i] != NULL; i++)
+ 	    {
+ 	      if (strnicmp (p, except[i], strlen (except[i])) == 0)
+ 		{
+ 		skip_args:
+ 		  args++;
+ 		  if (*args != NULL) /* skip only complete argument */
+ 		    {
+ 		      words = words->next;
+ 		      args++;
+ 		    }
+ 		  goto done;
+ 		}
+ 	    }
+ 	}
+ 
+       /* expands only non-quoted string */
+       if (words->word->expansion)
+ 	{
+ 	  /* insterts SYSROOT(may have double-slashed drive name) */
+ 	  if (sysroot_len > 0 && p[0] == '/'
+ 	      && (p[1] == '\0' || (p[1] != '/' && p[2] != '\0')))
+ 	    {
+ 	      p = xrealloc (p, strlen (p) + sysroot_len + 1);
+ 	      memmove (p + sysroot_len, p, strlen (p) + 1);
+ 	      memcpy (p, sysroot, sysroot_len);
+ 	    }
+ 
+ 	  /* expands double-slashed drive name */
+ 	  if (p[0] == '/' && p[1] == '/' && isalpha(p[2])
+ 	      && (p[3] == '/' || p[3] == '\0'))
+ 	    {
+ 	      p[0] = p[2];
+ 	      p[1] = ':';
+ 	      strcpy (p + 2, p + 3);
+ 	      p = xrealloc (p, strlen(p) + 1);
+ 	    }
+ 	}
+ 
+       /* stores and increses */
+       *args++ = p;
+     done:
+       words = words->next;
+     }
+ }
+ 
+ static void
+ maybe_expand_arguments (WORD_LIST *words, char *command, char **args)
+ {
+   static char *except_sed[] = { "sed", "-e", NULL };
+   static char *except_gsed[] = { "gsed", "-e", NULL };
+   static char **except_array[] =
+     {
+       except_sed,
+       except_gsed,
+       NULL
+     };
+   static char *shells[] = { "bash", "sh", NULL };
+   char **except = NULL, *fixp, *p;
+   int i, need_expand = 1;
+ 
+   if (!vmsutil_path_expand || words == NULL || command == NULL
+       || args == NULL || *args == NULL)
+     return;
+ 
+   fixp = savestring (command);
+   vmsutil_toslash (fixp);
+   if ((p = strrchr (fixp, '/')) == NULL)
+     p = fixp - 1;
+   p++;
+   for (i = 0; shells[i] != NULL; i++)
+     if (strnicmp (p, shells[i], strlen (shells[i])) == 0)
+       {
+ 	need_expand = 0;
+ 	break;
+       }
+   if (need_expand)
+     {
+       for (i = 0; except_array[i] != NULL; i++)
+ 	if (strnicmp (p, except_array[i][0], strlen (except_array[i][0])) == 0)
+ 	  except = except_array[i];
+     }
+   free (fixp);
+ 
+   if (need_expand)
+     expand_arguments_for_external_command (words, args, except);
+ }
+ #endif
diff -r -c bash-1_14_7/execute_cmd.h bash1147/execute_cmd.h
*** bash-1_14_7/execute_cmd.h	Wed Mar 10 09:43:46 1999
--- bash1147/execute_cmd.h	Wed Mar 10 09:44:54 1999
***************
*** 44,47 ****
--- 44,53 ----
  extern void close_all_files __P((void));
  #endif
  
+ #if defined (USE_VMS)
+ extern int shell_execve_dos (WORD_LIST *words, char *command, char **args,
+ 			     char **env, int flag);
+ extern char *extract_unit (char *string, int *p_index, int separator);
+ #endif
+ 
  #endif /* _EXECUTE_CMD_H_ */
diff -r -c bash-1_14_7/filecntl.h bash1147/filecntl.h
*** bash-1_14_7/filecntl.h	Wed Mar 10 09:43:46 1999
--- bash1147/filecntl.h	Wed Mar 10 09:44:54 1999
***************
*** 30,36 ****
--- 30,61 ----
  
  #define FD_NCLOEXEC    0
  
+ #if defined (USE_VMS)
+ #define F_DUPFD 0
+ #define F_GETFD 1
+ #define F_SETFD 2
+ #define F_GETFL 3
+ #define F_SETFL 4
+ #define F_GETLK 7
+ #define F_SETLK 8
+ #define F_SETLKW 9
+ #define SET_CLOSE_ON_EXEC(fd)                  \
+   do {                                         \
+ 	fcntl ((fd), F_SETFD, FD_CLOEXEC);     \
+ 	vmsfcntl ((fd), F_SETFD, FD_CLOEXEC);  \
+   } while (0)
+ #define SET_OPEN_ON_EXEC(fd)                   \
+   do {                                         \
+ 	fcntl ((fd), F_SETFD, FD_NCLOEXEC);    \
+ 	vmsfcntl ((fd), F_SETFD, FD_NCLOEXEC); \
+   } while (0)
+ #else
  #define SET_CLOSE_ON_EXEC(fd)  (fcntl ((fd), F_SETFD, FD_CLOEXEC))
  #define SET_OPEN_ON_EXEC(fd)   (fcntl ((fd), F_SETFD, FD_NCLOEXEC))
+ #endif
+ 
+ #if 0 /* VMS */
+ #define O_TEXT 0
+ #endif
  
  #endif /* ! _FILECNTL_H_ */
diff -r -c bash-1_14_7/general.c bash1147/general.c
*** bash-1_14_7/general.c	Wed Mar 10 09:43:47 1999
--- bash1147/general.c	Fri Mar 19 17:49:15 1999
***************
*** 24,30 ****
--- 24,32 ----
  #include <ctype.h>
  #include <errno.h>
  #include "bashtypes.h"
+ #if !defined (VMS)
  #include <sys/param.h>
+ #endif
  #if defined (_POSIX_VERSION)
  #  if defined (amiga) && defined (USGr4)
  #    define _POSIX_SOURCE
***************
*** 45,50 ****
--- 47,55 ----
  
  #include <sys/times.h>
  #include "maxpath.h"
+ #if defined (USE_VMS)
+ #include "vmsutil.h"
+ #endif
  
  #if !defined (errno)
  extern int errno;
***************
*** 318,324 ****
--- 323,333 ----
  {
    int flags, set = 0;
  
+ #if defined (USE_VMS)
+   if ((flags = vmsfcntl (fd, F_GETFL, 0)) < 0)
+ #else
    if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
+ #endif
      return;
  
  #if defined (O_NONBLOCK)
***************
*** 338,344 ****
--- 347,357 ----
  #endif /* O_NDELAY */
  
    if (set)
+ #if defined (USE_VMS)
+     vmsfcntl (fd, F_SETFL, flags);
+ #else
      fcntl (fd, F_SETFL, flags);
+ #endif
  }
  
  
***************
*** 658,664 ****
  	      i = (start < 0) ? 0 : start;
  	      continue;
  	    }
! 	}
      }
  
    if (!*result)
--- 671,677 ----
  	      i = (start < 0) ? 0 : start;
  	      continue;
  	    }
!  	}
      }
  
    if (!*result)
***************
*** 666,671 ****
--- 679,685 ----
        *result = stub_char;
        result[1] = '\0';
      }
+ 
    return (result);
  }
  
***************
*** 680,686 ****
--- 694,705 ----
    char *result;
    int result_len;
    
+ #if defined (USE_VMS) /* ??? handled concealed logical names
+ 			   e.g. /disk$axpvmssys -> /disk$axpvmssys/000000 */
    if (!dot_path || *string == '/')
+ #else
+   if (!dot_path || *string == '/')
+ #endif
      result = savestring (string);
    else
      {
***************
*** 716,722 ****
--- 735,746 ----
    if (!string || !*string)
      return (0);
  
+ #if defined (USE_VMS) /* ??? handled concealed logical names
+ 			   e.g. /disk$axpvmssys -> /disk$axpvmssys/000000 */
    if (*string == '/')
+ #else
+   if (*string == '/')
+ #endif
      return (1);
  
    if (*string++ == '.')
***************
*** 773,779 ****
--- 797,807 ----
    else
      file = savestring (file);
  
+ #if defined (USE_VMS)
+   if (absolute_pathname (file))
+ #else
    if ((*file == '/') && absolute_pathname (file))
+ #endif
      return (file);
  
    disposer = file;
***************
*** 781,787 ****
--- 809,819 ----
    {
      char *current_dir = xmalloc (2 + MAXPATHLEN + strlen (file));
      int dlen;
+ #if defined (USE_VMS)
+     if (vmsutil_getwd (current_dir) == 0)
+ #else
      if (getwd (current_dir) == 0)
+ #endif
        {
  	report_error (current_dir);
  	free (current_dir);
***************
*** 1093,1099 ****
--- 1125,1135 ----
    extern char *getcwd ();
    char *result;
  
+ #if defined (USE_VMS)
+   result = vmsutil_getcwd (string, MAXPATHLEN);
+ #else
    result = getcwd (string, MAXPATHLEN);
+ #endif
    if (result == NULL)
      strcpy (string, "getwd: cannot access parent directories");
    return (result);
***************
*** 1165,1171 ****
  
  #endif /* NO_READ_RESTART_ON_SIGNAL */
  
! #if defined (USG) || defined (AIX) || (defined (_POSIX_VERSION) && defined (Ultrix))
  /* USG and strict POSIX systems do not have killpg ().  But we use it in
     jobs.c, nojobs.c and some of the builtins.  This can also be redefined
     as a macro if necessary. */
--- 1201,1207 ----
  
  #endif /* NO_READ_RESTART_ON_SIGNAL */
  
! #if defined (USG) || defined (AIX) || (defined (_POSIX_VERSION) && defined (Ultrix)) || defined (VMS)
  /* USG and strict POSIX systems do not have killpg ().  But we use it in
     jobs.c, nojobs.c and some of the builtins.  This can also be redefined
     as a macro if necessary. */
***************
*** 1271,1273 ****
--- 1307,1313 ----
    return (oact.sa_handler);
  }
  #endif /* _POSIX_VERSION */
+ 
+ #if defined (USE_VMS)
+ #include "vmsutil.c"
+ #endif
diff -r -c bash-1_14_7/general.h bash1147/general.h
*** bash-1_14_7/general.h	Wed Mar 10 09:43:47 1999
--- bash1147/general.h	Fri Mar 19 17:49:02 1999
***************
*** 220,227 ****
--- 220,229 ----
  extern void tilde_initialize __P((void));
  
  #if !defined (strerror)
+ #ifndef VMS
  extern char *strerror __P((int));
  #endif
+ #endif
  
  #if defined (RLIMTYPE)
  extern RLIMTYPE string_to_rlimtype __P((char *));
***************
*** 243,247 ****
--- 245,253 ----
  #if defined (USG) && !defined (HAVE_GETHOSTNAME)
  extern int gethostname __P((char *, int));
  #endif /* USG && !HAVE_GETHOSTNAME */
+ 
+ #if defined (USE_VMS)
+ #include "vmsutil.h"
+ #endif
  
  #endif	/* _GENERAL_H */
diff -r -c bash-1_14_7/input.c bash1147/input.c
*** bash-1_14_7/input.c	Wed Mar 10 09:43:47 1999
--- bash1147/input.c	Fri Mar 19 17:36:15 1999
***************
*** 137,150 ****
--- 137,162 ----
  	 might be able to avoid this by copying the buffered stream verbatim
  	 to the new file descriptor. */
        if (buffers[fd])
+ #if defined (USE_VMS)
+ 	sync_buffered_stream_crlf (fd);
+ #else
  	sync_buffered_stream (fd);
+ #endif
  
        /* Now take care of duplicating the file descriptor that bash is
  	 using for input, so we can reinitialize it later. */
+ #if defined (USE_VMS)
+       nfd = vmsfcntl (fd, F_DUPFD, 10);
+ #else
        nfd = fcntl (fd, F_DUPFD, 10);
+ #endif
        if (nfd == -1)
  	{
+ #if defined (USE_VMS)
+ 	  if (vmsfcntl (fd, F_GETFD, 0) == 0)
+ #else
  	  if (fcntl (fd, F_GETFD, 0) == 0)
+ #endif
  	    report_error
  	      ("cannot allocate new file descriptor for bash input from fd %d: %s",
  		fd, strerror (errno));
***************
*** 306,320 ****
--- 318,350 ----
  }
  
  /* Read a buffer full of characters from BP, a buffered stream. */
+ #if defined (USE_VMS) /* ??? */
+ #define B_USECR 0x100
+ #endif
  static int
  b_fill_buffer (bp)
       BUFFERED_STREAM *bp;
  {
+ #if defined (USE_VMS)
+   long plpos = lseek (bp->b_fd, 0, SEEK_CUR);
+   long nlpos;
+ #endif
+ 
    do
      {
        bp->b_used = read (bp->b_fd, bp->b_buffer, bp->b_size);
      }
    while (bp->b_used < 0 && errno == EINTR);
+ 
+ #if defined (USE_VMS)
+   nlpos = lseek (bp->b_fd, 0, SEEK_CUR);
+   if ((plpos >= 0) && (nlpos >= 0) && (bp->b_used >= 0))
+     {
+       if ((plpos + bp->b_used) != nlpos)
+ 	bp->b_flag |= B_USECR;
+     }
+ #endif
+ 
    if (bp->b_used <= 0)
      {
        bp->b_buffer[0] = 0;
***************
*** 365,370 ****
--- 395,435 ----
    bp->b_used = bp->b_inputp = 0;
    return (0);
  }
+ 
+ #if defined (USE_VMS)
+ int
+ sync_buffered_stream_crlf (bfd)
+      int bfd;
+ {
+   BUFFERED_STREAM *bp;
+   int chars_left;
+ 
+   bp = buffers[bfd];
+   if (!bp)
+     return (-1);
+   chars_left = bp->b_used - bp->b_inputp;
+ 
+   if (chars_left)
+     {
+       lseek (bp->b_fd, -chars_left, SEEK_CUR);
+       if (bp->b_flag & B_USECR)
+ 	{
+ 	  int i = bp->b_inputp;
+ 	  int crlf = 0;
+ 	  char *p = bp->b_buffer + bp->b_inputp;
+ 
+ 	  while (i++ < bp->b_used)
+ 	    if (*p++ == '\n')
+ 	      crlf++;
+ 
+ 	  lseek (bp->b_fd, -crlf, SEEK_CUR);
+ 	}
+     }
+ 
+   bp->b_used = bp->b_inputp = 0;
+   return (0);
+ }
+ #endif
  
  int
  buffered_getchar ()
diff -r -c bash-1_14_7/jobs.c bash1147/jobs.c
*** bash-1_14_7/jobs.c	Wed Mar 10 09:43:47 1999
--- bash1147/jobs.c	Fri Mar 19 17:36:15 1999
***************
*** 48,54 ****
--- 48,56 ----
  #include <sys/file.h>
  #include "filecntl.h"
  #include <sys/ioctl.h>
+ #if !defined (VMS)
  #include <sys/param.h>
+ #endif
  
  #if defined (BUFFERED_INPUT)
  #  include "input.h"
***************
*** 74,79 ****
--- 76,85 ----
  #  endif /* USG | hpux | Xenix | sgi */
  #endif /* !_POSIX_VERSION */
  
+ #if defined (VMS)
+ #undef NEW_TTY_DRIVER
+ #endif
+ 
  /* Include the right header file for the specific type of terminal
     handler installed on this system. */
  #if defined (NEW_TTY_DRIVER)
***************
*** 200,205 ****
--- 206,218 ----
     commands. */
  static int freeze_jobs_list;
  
+ #if defined (VMS)
+ #  define getpgid(p) 0
+ #  define getpgrp(p) 0
+ #  define tcgetpgrp(p) 0
+ #  define setpgid(t,p) 0
+ #  define tcsetpgrp(t,p) 0
+ #else
  #if !defined (_POSIX_VERSION)
  
  /* These are definitions to map POSIX 1003.1 functions onto existing BSD
***************
*** 248,253 ****
--- 261,267 ----
      *oldset = old;
  }
  #endif /* !_POSIX_VERSION */
+ #endif
  
  /* Return the working directory for the current process.  Unlike
     job_working_directory, this does not call malloc (), nor do any
***************
*** 991,996 ****
--- 1005,1013 ----
        (!async_p || default_buffered_input > 0))
      sync_buffered_stream (default_buffered_input);
  #endif /* BUFFERED_INPUT */
+ #if defined (VMS)
+ #define fork vfork
+ #endif
  
    /* Create the child, handle severe errors. */
    if ((pid = fork ()) < 0)
***************
*** 1158,1163 ****
--- 1175,1184 ----
  static struct termios shell_tty_info;
  #endif /* TERMIOS_TTY_DRIVER */
  
+ #if !(defined (NEW_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER) || defined (TERMIOS_TTY_DRIVER))
+ static int shell_tty_info;
+ #endif
+ 
  #if defined (NEW_TTY_DRIVER) && defined (DRAIN_OUTPUT)
  /* Since the BSD tty driver does not allow us to change the tty modes
     while simultaneously waiting for output to drain and preserving
***************
*** 1800,1805 ****
--- 1821,1830 ----
    static struct termios save_stty;
  #endif
  
+ #if !(defined (NEW_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER) || defined (TERMIOS_TTY_DRIVER))
+   static int save_stty;
+ #endif
+ 
    BLOCK_CHILD (set, oset);
    already_running = (JOBSTATE (job) == JRUNNING);
  
***************
*** 2475,2480 ****
--- 2500,2509 ----
  #  endif /* TERMIOS_LDISC */
    return (0);
  #endif /* TERMIOS_TTY_DRIVER */
+ 
+ #if defined (VMS)
+   return (0);
+ #endif
  
  #if !defined (NEW_TTY_DRIVER) && !defined (TERMIO_TTY_DRIVER) && !defined (TERMIOS_TTY_DRIVER)
    return (-1);
diff -r -c bash-1_14_7/jobs.h bash1147/jobs.h
*** bash-1_14_7/jobs.h	Wed Mar 10 09:43:47 1999
--- bash1147/jobs.h	Wed Mar 10 09:44:55 1999
***************
*** 282,288 ****
  #endif /* !_POSIX_VERSION */
  
  /* System calls. */
! #if !defined (SunOS5) && !defined (USGr4_2) && !defined (__BSD_4_4__)
  extern pid_t fork (), getpid (), getpgrp ();
  #endif /* !SunOS5 && !USGr4_2 && !__BSD_4_4__ */
  
--- 282,288 ----
  #endif /* !_POSIX_VERSION */
  
  /* System calls. */
! #if !defined (SunOS5) && !defined (USGr4_2) && !defined (__BSD_4_4__) && !defined(VMS)
  extern pid_t fork (), getpid (), getpgrp ();
  #endif /* !SunOS5 && !USGr4_2 && !__BSD_4_4__ */
  
diff -r -c bash-1_14_7/lib/readline/complete.c bash1147/lib/readline/complete.c
*** bash-1_14_7/lib/readline/complete.c	Wed Mar 10 09:44:01 1999
--- bash1147/lib/readline/complete.c	Fri Mar 19 15:37:37 1999
***************
*** 963,970 ****
  {
    struct stat finfo;
    int character, r;
! 
! #if defined (S_ISLNK)
    r = lstat (filename, &finfo);
  #else
    r = stat (filename, &finfo);
--- 963,969 ----
  {
    struct stat finfo;
    int character, r;
! #if defined (S_ISLNK) && !defined (VMS)
    r = lstat (filename, &finfo);
  #else
    r = stat (filename, &finfo);
***************
*** 1015,1021 ****
       int state;
       char *text;
  {
! #if defined (__GO32__)
    return (char *)NULL;
  #else /* !__GO32__ */
    static char *username = (char *)NULL;
--- 1014,1020 ----
       int state;
       char *text;
  {
! #if defined (__GO32__) || defined (USE_VMS)
    return (char *)NULL;
  #else /* !__GO32__ */
    static char *username = (char *)NULL;
diff -r -c bash-1_14_7/lib/readline/display.c bash1147/lib/readline/display.c
*** bash-1_14_7/lib/readline/display.c	Wed Mar 10 09:44:01 1999
--- bash1147/lib/readline/display.c	Wed Mar 10 09:45:18 1999
***************
*** 62,68 ****
--- 62,72 ----
  extern int terminal_can_insert, term_xn;
  
  extern void _rl_output_some_chars ();
+ #ifdef _BSD44_CURSES
+ extern void _rl_output_character_function ();
+ #else
  extern int _rl_output_character_function ();
+ #endif
  
  extern int _rl_output_meta_chars;
  extern int _rl_horizontal_scroll_mode;
***************
*** 1132,1138 ****
    /* If IC is defined, then we do not have to "enter" insert mode. */
    if (term_IC)
      {
!       char *tgoto (), *buffer;
        buffer = tgoto (term_IC, 0, count);
        tputs (buffer, 1, _rl_output_character_function);
        _rl_output_some_chars (string, count);
--- 1136,1145 ----
    /* If IC is defined, then we do not have to "enter" insert mode. */
    if (term_IC)
      {
! #ifndef VMS
!       char *tgoto ();
! #endif
!       char *buffer;
        buffer = tgoto (term_IC, 0, count);
        tputs (buffer, 1, _rl_output_character_function);
        _rl_output_some_chars (string, count);
***************
*** 1186,1192 ****
  
    if (term_DC && *term_DC)
      {
!       char *tgoto (), *buffer;
        buffer = tgoto (term_DC, count, count);
        tputs (buffer, count, _rl_output_character_function);
      }
--- 1193,1202 ----
  
    if (term_DC && *term_DC)
      {
! #ifndef VMS
!       char *tgoto ();
! #endif
!       char *buffer;
        buffer = tgoto (term_DC, count, count);
        tputs (buffer, count, _rl_output_character_function);
      }
diff -r -c bash-1_14_7/lib/readline/history.c bash1147/lib/readline/history.c
*** bash-1_14_7/lib/readline/history.c	Wed Mar 10 09:44:01 1999
--- bash1147/lib/readline/history.c	Fri Mar 19 15:23:18 1999
***************
*** 25,30 ****
--- 25,34 ----
     you can call.  I think I have done that. */
  #define READLINE_LIBRARY
  
+ #ifdef HAVE_CONFIG_H
+ #include "config.h"
+ #endif
+ 
  #include <stdio.h>
  #include <sys/types.h>
  #include <sys/file.h>
diff -r -c bash-1_14_7/lib/readline/readline.c bash1147/lib/readline/readline.c
*** bash-1_14_7/lib/readline/readline.c	Wed Mar 10 09:44:02 1999
--- bash1147/lib/readline/readline.c	Fri Mar 19 15:40:04 1999
***************
*** 67,73 ****
--- 67,75 ----
     to be visible to readline callers. */
  
  /* Functions imported from other files in the library. */
+ #ifndef VMS
  extern char *tgetstr ();
+ #endif
  extern void rl_prep_terminal (), rl_deprep_terminal ();
  
  extern void _rl_bind_if_unbound ();
***************
*** 102,108 ****
--- 104,114 ----
  
  int _rl_dispatch ();
  void _rl_set_screen_size ();
+ #ifdef _BSD44_CURSES
+ void _rl_output_character_function ();
+ #else
  int _rl_output_character_function ();
+ #endif
  
  static char *readline_internal ();
  static void readline_initialize_everything ();
***************
*** 526,531 ****
--- 532,538 ----
    result = ioctl (tty, FIONREAD, &chars_avail);
  #endif
  
+ #ifndef VMS
  #if defined (O_NDELAY)
    if (result == -1)
      {
***************
*** 541,546 ****
--- 548,554 ----
  	return;
      }
  #endif /* O_NDELAY */
+ #endif
  
    /* If there's nothing available, don't waste time trying to read
       something. */
***************
*** 982,991 ****
    /* Initialize the terminal interface. */
    init_terminal_io ((char *)NULL);
  
! #if !defined (__GO32__)
    /* Bind tty characters to readline functions. */
    readline_default_bindings ();
  #endif /* !__GO32__ */
  
    /* Initialize the function names. */
    rl_initialize_funmap ();
--- 990,1002 ----
    /* Initialize the terminal interface. */
    init_terminal_io ((char *)NULL);
  
! #if !defined (__GO32__) && !defined (_BSD44_CURSES)
    /* Bind tty characters to readline functions. */
    readline_default_bindings ();
  #endif /* !__GO32__ */
+ #ifdef _BSD44_CURSES
+   initscr ();
+ #endif
  
    /* Initialize the function names. */
    rl_initialize_funmap ();
***************
*** 1027,1037 ****
--- 1038,1050 ----
  /* If this system allows us to look at the values of the regular
     input editing characters, then bind them to their readline
     equivalents, iff the characters are not bound to keymaps. */
+ #if !defined(_BSD44_CURSES)
  static void
  readline_default_bindings ()
  {
    rltty_set_default_bindings (_rl_keymap);
  }
+ #endif
  
  static void
  bind_arrow_keys_internal ()
***************
*** 1373,1378 ****
--- 1386,1394 ----
  #else /* !__GO32__ */
  
    char *term, *buffer;
+ #ifdef VMS
+   char *termcap;
+ #endif
    int tty;
    Keymap xkeymap;
  
***************
*** 1486,1498 ****
  }
  
  /* A function for the use of tputs () */
! int
  _rl_output_character_function (c)
       int c;
  {
    return putc (c, out_stream);
  }
! 
  /* Write COUNT characters from STRING to the output stream. */
  void
  _rl_output_some_chars (string, count)
--- 1502,1520 ----
  }
  
  /* A function for the use of tputs () */
! #ifdef _BSD44_CURSES
! void
  _rl_output_character_function (c)
+ {
+   putc (c, out_stream);
+ }
+ #else
+ int _rl_output_character_function (c)
       int c;
  {
    return putc (c, out_stream);
  }
! #endif
  /* Write COUNT characters from STRING to the output stream. */
  void
  _rl_output_some_chars (string, count)
***************
*** 3302,3307 ****
--- 3324,3333 ----
    if (isatty (0))
      return (getkey () & 0x7F);
  #endif /* __GO32__ */
+ #ifdef _BSD44_CURSES
+   if (isatty (0))
+     return getch ();
+ #endif
  
    while (1)
      {
***************
*** 3315,3320 ****
--- 3341,3347 ----
        if (result == 0)
  	return (EOF);
  
+ #ifndef VMS
  #if defined (EWOULDBLOCK)
        if (errno == EWOULDBLOCK)
  	{
***************
*** 3347,3352 ****
--- 3374,3380 ----
  	    }
  	}
  #endif /* _POSIX_VERSION && EAGAIN && O_NONBLOCK */
+ #endif
  
  #if !defined (__GO32__)
        /* If the error that we received was SIGINT, then try again,
diff -r -c bash-1_14_7/lib/readline/rldefs.h bash1147/lib/readline/rldefs.h
*** bash-1_14_7/lib/readline/rldefs.h	Wed Mar 10 09:44:02 1999
--- bash1147/lib/readline/rldefs.h	Wed Mar 10 09:45:19 1999
***************
*** 47,52 ****
--- 47,58 ----
  #  undef HAVE_BSD_SIGNALS
  #endif
  
+ #ifdef VMS
+ #undef NEW_TTY_DRIVER
+ #define _BSD44_CURSES 1
+ #include <curses.h>
+ #endif
+ 
  /* System V machines use termio. */
  #if !defined (_POSIX_VERSION)
  #  if defined (USG) || defined (hpux) || defined (Xenix) || defined (sgi) || \
***************
*** 87,92 ****
--- 93,102 ----
  #  include <sgtty.h>
  #endif
  
+ #if 1
+ #  define D_NAMLEN(d) strlen ((d)->d_name)
+ #else
+ 
  #if !defined (SHELL) && (defined (_POSIX_VERSION) || defined (USGr3))
  #  if !defined (HAVE_DIRENT_H)
  #    define HAVE_DIRENT_H
***************
*** 111,116 ****
--- 121,127 ----
  #    define dirent direct
  #  endif /* !dirent */
  #endif /* !HAVE_DIRENT_H */
+ #endif
  
  #if defined (USG) && defined (TIOCGWINSZ) && !defined (Linux)
  #  if defined (HAVE_SYS_STREAM_H)
diff -r -c bash-1_14_7/lib/readline/rltty.c bash1147/lib/readline/rltty.c
*** bash-1_14_7/lib/readline/rltty.c	Wed Mar 10 09:44:02 1999
--- bash1147/lib/readline/rltty.c	Fri Mar 19 15:40:32 1999
***************
*** 126,137 ****
--- 126,146 ----
  extern char *term_ks;
  extern char *term_ke;
  
+ #ifdef _BSD44_CURSES
+ static void
+ outchar (c)
+      int c;
+ {
+   putc (c, rl_outstream);
+ }
+ #else
  static int
  outchar (c)
       int c;
  {
    return putc (c, rl_outstream);
  }
+ #endif
  
  /* Turn on/off the meta key depending on ON. */
  static void
***************
*** 347,352 ****
--- 356,362 ----
  }
  
  #else  /* !defined (NEW_TTY_DRIVER) */
+ #ifndef _BSD44_CURSES
  
  #if !defined (VMIN)
  #  define VMIN VEOF
***************
*** 495,500 ****
--- 505,511 ----
  
  #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
  }
+ #endif /* _BSD44_CURSES */
  #endif  /* NEW_TTY_DRIVER */
  
  /* Put the terminal in CBREAK mode so that we can detect key presses. */
***************
*** 504,510 ****
  {
  #if !defined (__GO32__)
    int tty = fileno (rl_instream);
!   TIOTYPE tio;
  
    if (terminal_prepped)
      return;
--- 515,523 ----
  {
  #if !defined (__GO32__)
    int tty = fileno (rl_instream);
! #ifndef _BSD44_CURSES
!     TIOTYPE tio;
! #endif
  
    if (terminal_prepped)
      return;
***************
*** 512,517 ****
--- 525,536 ----
    /* Try to keep this function from being INTerrupted. */
    block_sigint ();
  
+ #ifdef _BSD44_CURSES
+   crmode ();
+   noecho ();
+   nodelay (stdscr, 0);
+ #else
+ 
    if (get_tty_settings (tty, &tio) < 0)
      {
        release_sigint ();
***************
*** 527,532 ****
--- 546,552 ----
        release_sigint ();
        return;
      }
+ #endif
  
    control_meta_key (1);
  #if 0
***************
*** 552,557 ****
--- 572,581 ----
    /* Try to keep this function from being INTerrupted. */
    block_sigint ();
  
+ #ifdef _BSD44_CURSES
+   nocrmode ();
+   echo ();
+ #else
    control_meta_key (0);
  #if 0
    control_keypad (0);
***************
*** 563,569 ****
        release_sigint ();
        return;
      }
! 
    terminal_prepped = 0;
  
    release_sigint ();
--- 587,593 ----
        release_sigint ();
        return;
      }
! #endif
    terminal_prepped = 0;
  
    release_sigint ();
***************
*** 640,645 ****
--- 664,670 ----
  /*			Default Key Bindings			    */
  /*								    */
  /* **************************************************************** */
+ #if !defined(_BSD44_CURSES)
  void
  rltty_set_default_bindings (kmap)
       Keymap kmap;
***************
*** 703,705 ****
--- 728,731 ----
      }
  #endif /* !NEW_TTY_DRIVER */
  }
+ #endif
diff -r -c bash-1_14_7/lib/readline/tilde.c bash1147/lib/readline/tilde.c
*** bash-1_14_7/lib/readline/tilde.c	Wed Mar 10 09:44:03 1999
--- bash1147/lib/readline/tilde.c	Fri Mar 19 15:24:08 1999
***************
*** 292,298 ****
--- 292,300 ----
  	      free (dirname);
  	      dirname = temp_name;
  	    }
+ #ifndef VMS
  	  endpwent ();
+ #endif
  	  free (username);
  	}
      }
diff -r -c bash-1_14_7/lib/readline/vi_mode.c bash1147/lib/readline/vi_mode.c
*** bash-1_14_7/lib/readline/vi_mode.c	Wed Mar 10 09:44:03 1999
--- bash1147/lib/readline/vi_mode.c	Wed Mar 10 09:45:20 1999
***************
*** 349,355 ****
--- 349,359 ----
  }
  
  /* Move forward a word the way that 'W' does. */
+ #ifdef VMS
+ rl_vi_fwword (count)
+ #else
  rl_vi_fWord (count)
+ #endif
       int count;
  {
    while (count-- && rl_point < (rl_end - 1))
***************
*** 365,371 ****
--- 369,379 ----
    return (0);
  }
  
+ #ifdef VMS
+ rl_vi_bwword (count)
+ #else
  rl_vi_bWord (count)
+ #endif
       int count;
  {
    while (count-- && rl_point > 0)
***************
*** 388,394 ****
--- 396,406 ----
    return (0);
  }
  
+ #ifdef VMS
+ rl_vi_ewword (count)
+ #else
  rl_vi_eWord (count)
+ #endif
       int count;
  {
    while (count-- && rl_point < (rl_end - 1))
diff -r -c bash-1_14_7/machines.h bash1147/machines.h
*** bash-1_14_7/machines.h	Wed Mar 10 09:43:47 1999
--- bash1147/machines.h	Wed Mar 10 09:44:55 1999
***************
*** 586,591 ****
--- 586,623 ----
  
  #if defined (i386)
  
+ /* MS-DOS(DJGPP) */
+ #  if !defined (done386) && defined (__DJGPP__)
+ #    define done386
+ #    define M_MACHINE "PCAT"
+ #    define M_OS "MSDOS"
+ #    define USE_DOS
+ #    define REQUIRED_LIBRARIES
+ #    undef HAVE_SYS_SIGLIST
+ #    undef USE_GNU_MALLOC
+ #    define USE_GNU_TERMCAP
+ #  define HAVE_SETLINEBUF
+ #    define HAVE_VFPRINTF
+ /*#  define HAVE_GETGROUPS*/
+ #    define SYSDEP_CFLAGS -DUSE_DOS -DHAVE_BCOPY -DHAVE_UID_T -DHAVE_GETDTABLESIZE \
+ 			  -DHAVE_GETHOSTNAME
+ #    define HAVE_STRERROR
+ #    define HAVE_STRCASECMP
+ #    define HAVE_DIRENT
+ #    define VOID_SIGHANDLER
+ /* following comes from sysdefs.h */
+ #    define HAVE_WAIT_H
+ #    define HAVE_RESOURCE
+ #    define HAVE_SYS_PARAM
+ #    define HAVE_UNISTD_H
+ #    define HAVE_STDLIB_H
+ #    define HAVE_LIMITS_H
+ #    define HAVE_DIRENT_H
+ #    define HAVE_STRING_H
+ #    define HAVE_VARARGS_H
+ #    define HAVE_BISON
+ #  endif
+ 
  /* Sequent Symmetry running Dynix/ptx 2.x */
  #  if !defined (done386) && defined (_SEQUENT_)
  #    define done386
***************
*** 2229,2234 ****
--- 2261,2283 ----
  #  undef HAVE_ALLOCA
  #  undef HAVE_WAIT_H
  #endif /* cadmus */
+ 
+ /* X68000 */
+ #if defined (HUMAN68K)
+ #  define M_MACHINE "x68000"
+ #  define M_OS "Human68k"
+ #  define REQUIRED_LIBRARIES
+ #  define HAVE_SYS_SIGLIST
+ #  undef USE_GNU_MALLOC
+ #  define USE_GNU_TERMCAP
+ #  define HAVE_VFPRINTF
+ #  define SYSDEP_CFLAGS -DUSE_DOS -DHAVE_BCOPY -DHAVE_RESOURCE -DHAVE_UID_T \
+ 		-D__NO_SIGNAL_INLINE__
+ #  define HAVE_STRERROR
+ #  define HAVE_STRCASECMP
+ #  define HAVE_DIRENT
+ #  define VOID_SIGHANDLER
+ #endif
  
  /* **************************************************************** */
  /*								    */
diff -r -c bash-1_14_7/mailcheck.c bash1147/mailcheck.c
*** bash-1_14_7/mailcheck.c	Wed Mar 10 09:43:47 1999
--- bash1147/mailcheck.c	Fri Mar 19 17:36:15 1999
***************
*** 21,32 ****
--- 21,38 ----
  #include <stdio.h>
  #include "bashtypes.h"
  #include "posixstat.h"
+ #if !defined (VMS)
  #include <sys/param.h>
+ #endif
  #include "bashansi.h"
  #include "shell.h"
  #include "maxpath.h"
  #include "execute_cmd.h"
  #include <tilde/tilde.h>
+ 
+ #if defined (USE_VMS)
+ extern char *extract_unit (char *string, int *p_index, int separator);
+ #endif
  
  #ifndef NOW
  #define NOW ((time_t)time ((time_t *)0))
diff -r -c bash-1_14_7/make_cmd.c bash1147/make_cmd.c
*** bash-1_14_7/make_cmd.c	Wed Mar 10 09:43:47 1999
--- bash1147/make_cmd.c	Fri Mar 19 17:36:15 1999
***************
*** 50,55 ****
--- 50,58 ----
    temp = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
    temp->word = savestring (string);
    temp->quoted = temp->dollar_present = temp->assignment = 0;
+ #if defined (USE_VMS)
+   temp->expansion = 0;
+ #endif
  
    while (*string)
      {
***************
*** 423,430 ****
--- 426,438 ----
  	      len = strlen (line);
  	      if (len + document_index >= document_size)
  		{
+ #if 0
  		  document_size = document_size ? 2 * (document_size + len)
  						: 1000;	/* XXX */
+ #else
+ 		  document_size = document_size ? 2 * (document_size + len)
+ 						: len + document_index + 1;
+ #endif
  		  document = xrealloc (document, document_size);
  		}
  
diff -r -c bash-1_14_7/makefile. bash1147/makefile.
*** bash-1_14_7/makefile.	Wed Mar 10 09:43:47 1999
--- bash1147/makefile.	Wed Mar 10 09:44:55 1999
***************
*** 19,26 ****
  # MAKE    = make
  RM      = rm -f
  SHELL   = /bin/sh
! GAWK     = awk
! # GAWK     = gawk
  
  # Force CPPNAME to be the name of your C preprocesor if Bash can't
  # find it.  For instance, `CPPNAME=/usr/libexec/cpp' on 4.4 BSD.
--- 19,26 ----
  # MAKE    = make
  RM      = rm -f
  SHELL   = /bin/sh
! # GAWK     = awk
! GAWK     = gawk
  
  # Force CPPNAME to be the name of your C preprocesor if Bash can't
  # find it.  For instance, `CPPNAME=/usr/libexec/cpp' on 4.4 BSD.
***************
*** 74,80 ****
  	@test -s bash-Makefile || { rm -f bash-Makefile ; exit 1; }
  
  sysdefs.h: $(MKSYSDEFS)
! 	$(SHELL) $(MKSYSDEFS) -s $(srcdir)
  
  # This is also performed by support/mksysdefs, but there's no way to change
  # it if cpp-Makefile is changed without changing anything else, since there
--- 74,80 ----
  	@test -s bash-Makefile || { rm -f bash-Makefile ; exit 1; }
  
  sysdefs.h: $(MKSYSDEFS)
! 	$(SHELL) $(MKSYSDEFS) -s $(srcdir) -i $(DJDIR)/include
  
  # This is also performed by support/mksysdefs, but there's no way to change
  # it if cpp-Makefile is changed without changing anything else, since there
diff -r -c bash-1_14_7/news. bash1147/news.
*** bash-1_14_7/news.	Wed Mar 10 09:43:48 1999
--- bash1147/news.	Wed Mar 10 09:44:56 1999
***************
*** 1,10 ****
! This file documents the bugs fixed between this release, bash-1.14.7,
! and the last public bash release, 1.14.6.
  
  1.  Bugs fixed in Bash
  
! a.  A memory leak that caused long-running scripts to eventually consume
!     all available memory was fixed.
  
! b.  A sign-extension bug that caused a security hole for non-interactive
!     shells was fixed.
--- 1,55 ----
! This file documents the bugs fixed between this release, bash-1.14.6,
! and the last public bash release, 1.14.5.
  
  1.  Bugs fixed in Bash
  
! a.  Fix to the `fc' builtin to prevent core dumps when the history list
!     is empty.
  
! b.  Fix to `getopts' to keep it from running off the end of the array of
!     positional parameters.
! 
! c.  FIFOs are now created with mode 600 for security reasons.
! 
! d.  The list of active file descriptors connected to files in /dev/fd is
!     now properly zeroed when allocated or extended.
! 
! e.  Fix to trap so that the exit status is preserved around the command
!     executed via `trap 0', unless that command contains a call to exit.
!     If a call to exit appears, that will set the exit value for the shell.
! 
! f.  Fixed an off-by-one error that caused words to be split incorrectly
!     when IFS was set to "'".
! 
! g.  Fixed an off-by-one error that caused completion to sometimes fail
!     when escaped single quotes appeared in the command line.
! 
! h.  Fixed a parser error that occasionally resulted in close braces (`}')
!     causing syntax errors.
! 
! i.  There is now a machine description for HPUX version 10.x.
! 
! j.  Fixed an obscure bug that caused machines without restartable syscalls
!     to drop backslash-escaped characters when reading here documents in an
!     interactive shell.
! 
! k.  Fixed a bug that caused FIGNORE to occasionally allow some completions
!     that should be ignored.
! 
! l.  New machine descriptions: NetBSD/pmax, Linux/m68k, BSD/OS/sparc.
! 
! m.  Fixed a bug that caused the `vi' mode `v' command to execute the
!     original command after it was changed in the editor.
! 
! n.  Fixed some substitution bugs that left occasional stray CTLNUL characters
!     in the results of variable expansion.
! 
! o.  Updated machine descriptions: SCOv5.
! 
! 2.  Bugs fixed in Readline
! 
! a.  Fix to the history searching functions so a null search string does
!     not cause readline to seg fault.
! 
! b.  Fixed a bug in the completion code which caused words appearing on a
!     line after a quoted string to not be completed correctly.
diff -r -c bash-1_14_7/nojobs.c bash1147/nojobs.c
*** bash-1_14_7/nojobs.c	Wed Mar 10 09:43:48 1999
--- bash1147/nojobs.c	Fri Mar 19 17:36:15 1999
***************
*** 26,31 ****
--- 26,35 ----
  #include <setjmp.h>
  #include <errno.h>
  
+ #ifdef VMS
+ #include <wait.h>
+ #endif
+ 
  #include "config.h"
  #include "command.h"
  #include "general.h"
***************
*** 38,44 ****
  #  include "input.h"
  #endif
  
! #if !defined (USG) && !defined (_POSIX_VERSION)
  #  include <sgtty.h>
  #else
  #  if defined (_POSIX_VERSION)
--- 42,50 ----
  #  include "input.h"
  #endif
  
! #if defined (USE_VMS)
! #  include "vmstermios.h"
! #elif !defined (USG) && !defined (_POSIX_VERSION)
  #  include <sgtty.h>
  #else
  #  if defined (_POSIX_VERSION)
***************
*** 59,65 ****
  #  define killpg(pg, sig)		kill(-(pg),(sig))
  #endif /* USG || _POSIX_VERSION */
  
! #if defined (USG)
  #  define siginterrupt(sig, code)
  #endif /* USG */
  
--- 65,71 ----
  #  define killpg(pg, sig)		kill(-(pg),(sig))
  #endif /* USG || _POSIX_VERSION */
  
! #if defined (USG) || defined (USE_VMS)
  #  define siginterrupt(sig, code)
  #endif /* USG */
  
***************
*** 302,308 ****
--- 308,318 ----
    retry_fork:
  #endif /* _POSIX_VERSION */
  
+ #if defined (USE_VMS)
+   if ((pid = vmsutil_make_child_pid ()) < 0)
+ #else
    if ((pid = fork ()) < 0)
+ #endif
      {
  #if defined (_POSIX_VERSION)
        /* Posix systems with a non-blocking waitpid () system call available
***************
*** 319,325 ****
  
        throw_to_top_level ();
      }
!  
    if (pid == 0)
      {
  #if defined (BUFFERED_INPUT)
--- 329,335 ----
  
        throw_to_top_level ();
      }
! 
    if (pid == 0)
      {
  #if defined (BUFFERED_INPUT)
***************
*** 362,367 ****
--- 372,380 ----
  	last_asynchronous_pid = pid;
  
        add_pid (pid);
+ #if defined (USE_VMS)
+       vmsutil_current_pid = pid;
+ #endif
      }
    return (pid);
  }
***************
*** 477,482 ****
--- 490,506 ----
    if (!interactive_shell)
      old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
  
+ #if defined (USE_VMS)
+   {
+     status = vmsutil_wait_status;
+     if ((status & 0x0000ff00) == 0x0000ff00)
+       status &= 0x000000ff;
+     errno = 0;
+     got_pid = pid;
+ 
+     last_made_pid = NO_PID;
+   }
+ #else
    while ((got_pid = WAITPID (-1, &status, 0)) != pid) /* XXX was pid now -1 */
      {
        if (got_pid < 0 && errno == ECHILD)
***************
*** 493,498 ****
--- 517,523 ----
        else if (got_pid > 0)
  	set_pid_status (got_pid, status);
      }
+ #endif /* !USE_VMS */
  
    set_pid_status (got_pid, status);
  
diff -r -c bash-1_14_7/parse.y bash1147/parse.y
*** bash-1_14_7/parse.y	Wed Mar 10 09:43:48 1999
--- bash1147/parse.y	Fri Mar 19 17:48:13 1999
***************
*** 27,32 ****
--- 27,36 ----
  #include "flags.h"
  #include "input.h"
  
+ #if defined (USE_VMS)
+ #include "vmsutil.h"
+ #endif
+ 
  #if defined (READLINE)
  #  include <readline/readline.h>
  #endif /* READLINE */
***************
*** 2406,2411 ****
--- 2410,2418 ----
      the_word->dollar_present = dollar_present;
      the_word->quoted = quoted;
      the_word->assignment = assignment (token);
+ #if defined (USE_VMS)
+     the_word->expansion = 0;
+ #endif
  
      yylval.word = the_word;
      result = WORD;
***************
*** 2614,2619 ****
--- 2621,2627 ----
  
    while (c = *string++)
      {
+ 
        if (posixly_correct && c == '!')
  	{
  	  if (*string == '!')
***************
*** 2723,2733 ****
--- 2731,2749 ----
  		temp = get_string_value ("PWD");
  
  		if (!temp)
+ #if defined (USE_VMS)
+ 		  vmsutil_getwd (t_string);
+ #else
  		  getwd (t_string);
+ #endif
  		else
  		  strcpy (t_string, temp);
  #else
+ #if defined (USE_VMS)
+ 		vmsutil_getwd (t_string);
+ #else
  		getwd (t_string);
+ #endif
  #endif	/* EFFICIENT */
  
  		if (c == 'W')
diff -r -c bash-1_14_7/print_cmd.c bash1147/print_cmd.c
*** bash-1_14_7/print_cmd.c	Wed Mar 10 09:43:48 1999
--- bash1147/print_cmd.c	Fri Mar 19 17:36:15 1999
***************
*** 30,36 ****
--- 30,40 ----
  #endif /* !HAVE_STRING_H */
  
  #include "shell.h"
+ #if defined (VMS)
+ #include "y_tab.h"
+ #else
  #include "y.tab.h"
+ #endif
  #include "stdc.h"
  #include "builtins/common.h"
  
diff -r -c bash-1_14_7/shell.c bash1147/shell.c
*** bash-1_14_7/shell.c	Wed Mar 10 09:43:48 1999
--- bash1147/shell.c	Fri Mar 19 17:47:48 1999
***************
*** 63,68 ****
--- 63,73 ----
  
  #include <tilde/tilde.h>
  
+ #if defined (USE_VMS)
+ #include "vmsutil.h"
+ #include <locale.h>
+ #endif
+ 
  #if defined (USG) && !defined (HAVE_GETPW_DECLS)
  extern struct passwd *getpwuid ();
  #endif /* USG && !HAVE_GETPW_DECLS */
***************
*** 174,180 ****
--- 179,189 ----
  time_t shell_start_time;
  
  /* The name of the .(shell)rc file. */
+ #if defined (VMS)
+ static char *bashrc_file = "sys$login:.bashrc";
+ #else
  static char *bashrc_file = "~/.bashrc";
+ #endif
  
  /* Non-zero means to act more like the Bourne shell on startup. */
  static int act_like_sh = 0;
***************
*** 248,253 ****
--- 257,271 ----
    int top_level_arg_index, read_from_stdin;
    FILE *default_input;
  
+ #if defined (USE_VMS)
+   setlocale (LC_CTYPE, "");
+   vmsutil_import_envvar ();
+   argv [0] = savestring (TO_CANONICAL_FILE_SPEC (argv[0]));
+   vmsutil_delsysroot (argv[0]);
+   vmsutil_reserve_fds ();
+   vmsutil_save_cwd ();
+ #endif /* !USE_VMS */
+ 
    /* There is a bug in the NeXT 2.1 rlogind that causes opens
       of /dev/tty to fail. */
  #if defined (RLOGIN_PGRP_BUG)
***************
*** 507,512 ****
--- 525,531 ----
  #endif /* JOB_CONTROL */
      }
  
+ #if !defined (USE_VMS)
  #define CLOSE_FDS_AT_LOGIN
  #if defined (CLOSE_FDS_AT_LOGIN)
    /*
***************
*** 522,527 ****
--- 541,547 ----
  	close (i);
      }
  #endif /* CLOSE_FDS_AT_LOGIN */
+ #endif /* USE_VMS */
  
    /* From here on in, the shell must be a normal functioning shell.
       Variables from the environment are expected to be set, etc. */
***************
*** 632,637 ****
--- 652,658 ----
      {
        int fd;
        char *filename;
+       struct stat statbuff;
  
        free (dollar_vars[0]);
        dollar_vars[0] = savestring (argv[arg_index]);
***************
*** 748,759 ****
    else if (!interactive)
      /* In this mode, bash is reading a script from stdin, which is a
         pipe or redirected file. */
  #if defined (BUFFERED_INPUT)
!     default_buffered_input = fileno (stdin);	/* == 0 */
  #else      
!     setbuf (default_input, (char *)NULL);
  #endif /* !BUFFERED_INPUT */
! 
    /* Bind remaining args to $1 ... $n */
    {
      WORD_LIST *args = (WORD_LIST *)NULL;
--- 769,784 ----
    else if (!interactive)
      /* In this mode, bash is reading a script from stdin, which is a
         pipe or redirected file. */
+     {
+ #if defined (USE_VMS)
+       fflush (stdin);
+ #endif
  #if defined (BUFFERED_INPUT)
!       default_buffered_input = fileno (stdin);	/* == 0 */
  #else      
!       setbuf (default_input, (char *)NULL);
  #endif /* !BUFFERED_INPUT */
!     }
    /* Bind remaining args to $1 ... $n */
    {
      WORD_LIST *args = (WORD_LIST *)NULL;
***************
*** 773,778 ****
--- 798,811 ----
    unset_nodelay_mode (fileno (stdin));
  #endif /* !BUFFERED_INPUT */
  
+ #if 0 /* def VMS Bug in DEC C RTL, fixed in VMS 7.2 */
+ #if defined (BUFFERED_INPUT)
+   lseek (default_buffered_input, 0, SEEK_SET);
+ #else
+   lseek (fileno (stdin), 0, SEEK_SET);
+ #endif
+ #endif
+ 
    /* with_input_from_stdin really means `with_input_from_readline' */
    if (interactive && !no_line_editing)
      with_input_from_stdin ();
***************
*** 845,856 ****
        if (login_shell && !no_profile)
          {
            if (act_like_sh)
              maybe_execute_file ("~/.profile", 1);
            else
              {
!               if (maybe_execute_file ("~/.bash_profile", 1) == 0)
  	        if (maybe_execute_file ("~/.bash_login", 1) == 0)
  	          maybe_execute_file ("~/.profile", 1);
              }
          }
  
--- 878,908 ----
        if (login_shell && !no_profile)
          {
            if (act_like_sh)
+ #if defined (USE_VMS)
+ 	    {
+ 	      if (maybe_execute_file ("sys$login:.profile", 1) == 0)
+ 		maybe_execute_file ("sys$login:_profile", 1);
+ 	    }
+ #else
              maybe_execute_file ("~/.profile", 1);
+ #endif
            else
              {
! #if defined (USE_VMS)
!               if (maybe_execute_file ("sys$login:.bash_profile", 1) == 0)
! 		if (maybe_execute_file ("sys$login:_bash_profile", 1) == 0)
! 		  if (maybe_execute_file ("sys$login:_bprof", 1) == 0)
! 		    if (maybe_execute_file ("sys$login:.bash_login", 1) == 0)
! 		      if (maybe_execute_file ("sys$login:_bash_login", 1) == 0)
! 			if (maybe_execute_file ("sys$login:_blogin", 1) == 0)
! 			  if (maybe_execute_file ("sys$login:.profile", 1)
! 			      == 0)
! 			    maybe_execute_file ("sys$login:_profile", 1);
! #else
! 	      if (maybe_execute_file ("~/.bash_profile", 1) == 0)
  	        if (maybe_execute_file ("~/.bash_login", 1) == 0)
  	          maybe_execute_file ("~/.profile", 1);
+ #endif
              }
          }
  
***************
*** 878,884 ****
--- 930,942 ----
        if (!act_like_sh && !no_rc &&
            (interactive_shell || (isnetconn (fileno (stdin)) &&
  			         local_pending_command)))
+ #if defined (USE_VMS)
+ 	if (maybe_execute_file (bashrc_file, 1) == 0
+ 	    && strcmp (bashrc_file, "sys$login:.bashrc") == 0)
+ 	  maybe_execute_file ("sys$login:_bashrc", 1);
+ #else
          maybe_execute_file (bashrc_file, 1);
+ #endif
      }
  
     /* Try a TMB suggestion.  If running a script, then execute the
***************
*** 948,959 ****
       int force_noninteractive;
  {
    jmp_buf old_return_catch;
!   int return_val, fd, tresult, old_interactive;
    char *filename, *string;
    struct stat file_info;
  
    filename = tilde_expand (fname);
    fd = open (filename, O_RDONLY);
  
    if (fd < 0)
      {
--- 1006,1023 ----
       int force_noninteractive;
  {
    jmp_buf old_return_catch;
!   int return_val, fd, tresult, old_interactive, tnext;
    char *filename, *string;
    struct stat file_info;
  
    filename = tilde_expand (fname);
+ #if defined (USE_VMS)
+   errno = 0;
+   filename = vmsutil_expand_path (filename);
+   fd = open (filename, O_RDONLY);
+ #else
    fd = open (filename, O_RDONLY);
+ #endif
  
    if (fd < 0)
      {
***************
*** 975,981 ****
      }
  
    string = (char *)xmalloc (1 + (int)file_info.st_size);
!   tresult = read (fd, string, file_info.st_size);
  
    {
      int tt = errno;
--- 1039,1051 ----
      }
  
    string = (char *)xmalloc (1 + (int)file_info.st_size);
!   tnext = 0;
!   do 
!     {
!       tresult = read (fd, &string [tnext], file_info.st_size);
!       tnext += tresult;
!     } while (tresult > 0);
!   tresult = tnext;
  
    {
      int tt = errno;
***************
*** 983,994 ****
--- 1053,1072 ----
      errno = tt;
    }
  
+ #if defined (USE_VMS)
+   if (tresult < 0)
+ #else
    if (tresult != file_info.st_size)
+ #endif
      {
        free (string);
        goto file_error_and_exit;
      }
+ #if defined (USE_VMS)
+   string[tresult] = '\0';
+ #else
    string[file_info.st_size] = '\0';
+ #endif
  
    return_catch_flag++;
    xbcopy ((char *)return_catch, (char *)old_return_catch, sizeof (jmp_buf));
***************
*** 1123,1128 ****
--- 1201,1209 ----
  		{
  		  executing = 1;
  		  execute_command (current_command);
+ #if defined (USE_VMS)
+ 		  vmsutil_pipe_clean (0);
+ #endif
  		}
  
  	    exec_done:
***************
*** 1310,1315 ****
--- 1391,1401 ----
  	else
  	  current_user.shell = savestring ("/bin/sh");
  	current_user.home_dir = savestring (entry->pw_dir);
+ #if defined (USE_VMS)
+ 	current_user.shell = savestring ("bash");
+ 	current_user.home_dir = savestring
+ 	  (to_canonical_dir_spec (current_user.home_dir, 0));
+ #endif
        }
      else
        {
***************
*** 1318,1324 ****
--- 1404,1412 ----
  	current_user.home_dir = savestring ("/");
        }
  
+ #if !defined (VMS)
      endpwent ();
+ #endif
    }
  
    /* Initialize our interface to the tilde expander. */
***************
*** 1374,1380 ****
--- 1462,1472 ----
  
    /* Ensure that the default startup file is used.  (Except that we don't
       execute this file for reinitialized shells). */
+ #if defined (VMS)
+   bashrc_file = "sys$login:.bashrc";
+ #else
    bashrc_file = "~/.bashrc";
+ #endif
  
    /* Delete all variables and functions.  They will be reinitialized when
       the environment is parsed. */
***************
*** 1589,1594 ****
--- 1681,1687 ----
  
  #endif /* !_POSIX_VERSION */
  
+ #if !defined (USE_VMS)
  #if defined (JOB_CONTROL) || defined (_POSIX_VERSION)
    /* All shells use the signal mask they inherit, and pass it along
       to child processes.  Children will never block SIGCHLD, though. */
***************
*** 1596,1601 ****
--- 1689,1695 ----
    sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &top_level_mask);
    sigdelset (&top_level_mask, SIGCHLD);
  #endif /* JOB_CONTROL || _POSIX_VERSION */
+ #endif /* USE_VMS */
  
    /* And, some signals that are specifically ignored by the shell. */
    set_signal_handler (SIGQUIT, SIG_IGN);
***************
*** 1714,1719 ****
--- 1808,1828 ----
    set_signal_handler (sig, sigint_sighandler);
  #endif
  
+ #if defined (USE_VMS) /* ??? */
+ #define SIG_TRAPPED     0x1	/* Currently trapped. */
+ #define SIG_INPROGRESS  0x10	/* Signal handler currently executing. */
+   {
+     extern int vmsutil_get_signal_modes (int);
+     extern int vmsutil_set_signal_modes (int, int);
+     int modes;
+ 
+     modes = vmsutil_get_signal_modes (SIGINT);
+     if (interrupt_state == 0 && interrupt_immediately == 0
+         && (modes & (SIG_INPROGRESS | SIG_TRAPPED)) == (SIG_INPROGRESS | SIG_TRAPPED))
+       vmsutil_set_signal_modes (SIGINT, modes & ~SIG_INPROGRESS);
+   }
+ #endif
+ 
    /* interrupt_state needs to be set for the stack of interrupts to work
       right.  Should it be set unconditionally? */
    if (!interrupt_state)
***************
*** 1743,1750 ****
--- 1852,1873 ----
  void
  show_shell_version ()
  {
+ #if defined (USE_VMS) /* ??? fix version numbers */
+   {
+     char *p = savestring (base_pathname (shell_name));
+ 
+     if (strlen (p) >= sizeof (".exe"))
+       if (stricmp (p + strlen (p) - (sizeof (".exe") - 1), ".exe") == 0)
+ 	p[strlen (p) - (sizeof (".exe") - 1)] = '\0';
+     printf ("GNU %s, version %s%s\n", p, shell_version_string (),
+ 	    vmsutil_version_string ());
+ 
+     free (p);
+   }
+ #else
    printf ("GNU %s, version %s\n", base_pathname (shell_name),
      shell_version_string ());
+ #endif
  }
  
  #if !defined (USG) && defined (ENOTSOCK)
***************
*** 1771,1776 ****
--- 1894,1902 ----
    return (S_ISCHR (sb.st_mode));
  #else /* !USGr4 && !USGr4_2 */
  #  if defined (HAVE_SOCKETS)
+ #if defined (VMS)
+   unsigned
+ #endif
    int rv, l;
    struct sockaddr sa;
  
diff -r -c bash-1_14_7/subst.c bash1147/subst.c
*** bash-1_14_7/subst.c	Wed Mar 10 09:43:49 1999
--- bash1147/subst.c	Fri Mar 19 17:47:40 1999
***************
*** 24,29 ****
--- 24,32 ----
  #include <pwd.h>
  #include <signal.h>
  #include <errno.h>
+ #ifdef VMS
+ #include <wait.h>
+ #endif
  /* Not all systems declare ERRNO in errno.h... and some systems #define it! */
  #if !defined (errno)
  extern int errno;
***************
*** 52,57 ****
--- 55,64 ----
  #include <glob/fnmatch.h>
  #include "builtins/getopt.h"
  
+ #if defined (USE_VMS)
+ #include "vmsutil.h"
+ #endif
+ 
  /* The size that strings change by. */
  #define DEFAULT_ARRAY_SIZE 512
  
***************
*** 1036,1041 ****
--- 1043,1054 ----
  	     perform quoted null character removal on the current word. */
  	  remove_quoted_nulls (current_word);
  	  result = make_word_list (make_word (current_word), result);
+ #if defined (USE_VMS)
+ 	  /* expand each word */
+ 	  if ((!quoted && current_word[0] == '/')
+ 	      || (quoted && current_word[0] == CTLESC && current_word[1] == '/'))
+ 	    result->word->expansion = 1;
+ #endif
  	  if (quoted)
  	    result->word->quoted = 1;
  	}
***************
*** 1845,1850 ****
--- 1858,1890 ----
    nfifo = 0;
  }
  
+ #if defined (USE_VMS)
+ static char *
+ make_named_pipe ()
+ {
+   char *tmpdir;
+   char *tname;
+   int fd;
+ 
+   tmpdir = getenv ("TMPDIR");
+   if (tmpdir == NULL)
+     tmpdir = "/tmp";
+ 
+   tname = xmalloc (strlen (tmpdir) + sizeof ("/npXXXXXX"));
+   sprintf (tname, "%s/npXXXXXX", tmpdir);
+   tname = mktemp (vmsutil_expand_path (tname));
+   if ((fd = creat (tname, 0600)) < 0)
+     {
+       free (tname);
+       return ((char *)NULL);
+     }
+   else
+     close (fd);
+ 
+   add_fifo_list (tname);
+   return (tname);
+ }
+ #else /* !USE_VMS */
  static char *
  make_named_pipe ()
  {
***************
*** 1860,1865 ****
--- 1900,1906 ----
    add_fifo_list (tname);
    return (tname);
  }
+ #endif /* !USE_VMS */
  
  #if !defined (_POSIX_VERSION)
  int
***************
*** 1875,1880 ****
--- 1916,1931 ----
  }
  #endif /* !_POSIX_VERSION */
  
+ #if defined (VMS)
+ int
+ mkfifo (path, mode)
+      char *path;
+      int mode;
+ {
+   return (-1);
+ }
+ #endif
+ 
  #else /* HAVE_DEV_FD */
  
  /* DEV_FD_LIST is a bitmap of file descriptors attached to pipes the shell
***************
*** 1985,1990 ****
--- 2036,2044 ----
  #if defined (JOB_CONTROL)
    pid_t old_pipeline_pgrp;
  #endif  
+ #if defined (USE_VMS)
+   OLDENVBUF oldenvbuf;
+ #endif
  
    if (!string || !*string)
      return ((char *)NULL);
***************
*** 1992,1998 ****
--- 2046,2056 ----
  #if !defined (HAVE_DEV_FD)
    pathname = make_named_pipe ();
  #else /* HAVE_DEV_FD */
+ #if defined (USE_VMS)
+   if (vmsutil_pipe (fildes) < 0)
+ #else
    if (pipe (fildes) < 0)
+ #endif
      {
        internal_error ("can't make pipes for process substitution: %s",
  	strerror (errno));
***************
*** 2030,2041 ****
--- 2088,2108 ----
    stop_making_children ();
    pipeline_pgrp = old_pipeline_pgrp;
  #else /* !JOB_CONTROL */
+ #if defined (USE_VMS)
+   vmsutil_save_all_environment (&oldenvbuf);
+ #endif
    pid = make_child ((char *)NULL, 1);
+ #if defined (USE_VMS)
+   if (pid > 0)
+ #else
    if (pid == 0)
+ #endif
      {
+ #if !defined (USE_VMS)
        /* Cancel traps, in trap.c. */
        restore_original_signals ();
        setup_async_signals ();
+ #endif
        subshell_environment++;
      }
  #endif /* !JOB_CONTROL */
***************
*** 2049,2059 ****
--- 2116,2136 ----
        close (parent_pipe_fd);
        close (child_pipe_fd);
  #endif /* HAVE_DEV_FD */
+ #if defined (USE_VMS)
+       vmsutil_restore_all_environment (&oldenvbuf);
+ #endif
        return ((char *)NULL);
      }
  
+ #if defined (USE_VMS)
+   if (pid == 0)
+     {
+       /* parent side */
+       process_substitute_parent:
+ #else
    if (pid > 0)
      {
+ #endif
        last_made_pid = old_pid;
  
  #if defined (JOB_CONTROL) && defined (PGRP_PIPE)
***************
*** 2080,2086 ****
--- 2157,2168 ----
      {
        internal_error ("cannot open named pipe %s for %s: %s", pathname,
  	open_for_read_in_child ? "reading" : "writing", strerror (errno));
+ #if defined (USE_VMS)
+       vmsutil_wait_status = 127;
+       goto process_substitute_exit;
+ #else
        exit (127);
+ #endif
      }
  #else /* HAVE_DEV_FD */
    fd = child_pipe_fd;
***************
*** 2090,2096 ****
--- 2172,2183 ----
      {
        internal_error ("cannot duplicate named pipe %s as fd %d: %s",
  	pathname, open_for_read_in_child ? 0 : 1, strerror (errno));
+ #if defined (USE_VMS)
+       vmsutil_wait_status = 127;
+       goto process_substitute_exit;
+ #else
        exit (127);
+ #endif
      }
  
    close (fd);
***************
*** 2118,2125 ****
--- 2205,2222 ----
    close (open_for_read_in_child ? 0 : 1);
  #endif /* !HAVE_DEV_FD */
  
+ #if defined (USE_VMS)
+   vmsutil_wait_status = result;
+ 
+ process_substitute_exit:
+   vmsutil_restore_all_environment (&oldenvbuf);
+ 
+   /* run parent side */
+   goto process_substitute_parent;
+ #else
    exit (result);
    /*NOTREACHED*/
+ #endif
  }
  #endif /* PROCESS_SUBSTITUTION */
  
***************
*** 2135,2140 ****
--- 2232,2241 ----
    char *istring = (char *)NULL;
    int istring_index, istring_size, c = 1;
    int result;
+ #if defined (USE_VMS)
+   int pipes = vmsutil_pipe_no ();
+   OLDENVBUF oldenvbuf;
+ #endif
  
    istring_index = istring_size = 0;
  
***************
*** 2144,2151 ****
--- 2245,2260 ----
      return ((char *)NULL);
  
    /* Pipe the output of executing STRING into the current shell. */
+ #if defined (USE_VMS)
+   if (vmsutil_pipe (fildes) < 0)
+ #else
    if (pipe (fildes) < 0)
+ #endif
      {
+ #if defined (USE_VMS)
+       fildes[0] = -1;
+       fildes[1] = -1;
+ #endif
        internal_error ("Can't make pipes for command substitution!");
        goto error_exit;
      }
***************
*** 2167,2178 ****
--- 2276,2292 ----
      pipeline_pgrp = old_pipeline_pgrp;
    }
  #else /* !JOB_CONTROL */
+ #if defined (USE_VMS)
+   vmsutil_save_all_environment (&oldenvbuf);
+ #endif
    pid = make_child ((char *)NULL, 0);
  
+ #if !defined (USE_VMS)
    if (pid == 0)
      /* Reset the signal handlers in the child, but don't free the
         trap strings. */
      reset_signal_handlers ();
+ #endif
  #endif /* !JOB_CONTROL */
  
    if (pid < 0)
***************
*** 2180,2193 ****
--- 2294,2329 ----
        internal_error ("Can't make a child for command substitution: %s",
  	strerror (errno));
      error_exit:
+ #if defined (USE_VMS)
+       vmsutil_restore_all_environment (&oldenvbuf);
+     error_exit_without_restore:
+ #endif
  
        FREE (istring);
+ #if defined (USE_VMS)
+       if (fildes[0] >= 0)
+ 	{
+ 	  close (fildes[0]);
+ 	  fildes[0] = -1;
+ 	}
+       if (fildes[1] >= 0)
+ 	{
+ 	  close (fildes[1]);
+ 	  fildes[1] = -1;
+ 	}
+       vmsutil_pipe_clean (pipes);
+ #else
        close (fildes[0]);
        close (fildes[1]);
+ #endif
        return ((char *)NULL);
      }
  
+ #if defined (USE_VMS)
+   if (pid > 0)
+ #else
    if (pid == 0)
+ #endif
      {
        set_sigint_handler ();	/* XXX */
  #if defined (JOB_CONTROL)
***************
*** 2198,2206 ****
--- 2334,2348 ----
  	  internal_error
  	    ("command_substitute: cannot duplicate pipe as fd 1: %s",
  	     strerror (errno));
+ #if defined (USE_VMS)
+ 	  vmsutil_wait_status = (EXECUTION_FAILURE);
+ 	  goto error_exit;
+ #else
  	  exit (EXECUTION_FAILURE);
+ #endif
  	}
  
+ #if !defined (USE_VMS)
        /* If standard output is closed in the parent shell
  	 (such as after `exec >&-'), file descriptor 1 will be
  	 the lowest available file descriptor, and end up in
***************
*** 2216,2221 ****
--- 2358,2364 ----
  	  (fildes[0] != fileno (stdout)) &&
  	  (fildes[0] != fileno (stderr)))
  	close (fildes[0]);
+ #endif
  
        /* The currently executing shell is not interactive. */
        interactive = 0;
***************
*** 2229,2258 ****
--- 2372,2435 ----
  	 so we don't go back up to main (). */
        result = setjmp (top_level);
  
+ #if defined (USE_VMS)
+       if (result == EXITPROG)
+ 	{
+ 	  vmsutil_wait_status = (last_command_exit_value) << 8;
+ 	  goto error_exit;
+ 	}
+       else if (result)
+ 	{
+ 	  vmsutil_wait_status = (EXECUTION_FAILURE);
+ 	  goto error_exit;
+ 	}
+       else
+ 	vmsutil_wait_status = (parse_and_execute (string, "command substitution", -1)) << 8;
+ 
+       vmsutil_restore_all_environment (&oldenvbuf);
+ 
+       /* run parent side */
+       goto command_substitute_parent;
+ #else /* !USE_VMS */
        if (result == EXITPROG)
  	exit (last_command_exit_value);
        else if (result)
  	exit (EXECUTION_FAILURE);
        else
  	exit (parse_and_execute (string, "command substitution", -1));
+ #endif /* !USE_VMS */
      }
    else
      {
        FILE *istream;
  
+ #if defined (USE_VMS)
+ command_substitute_parent:
+       /* reset file pointer */
+       lseek (fildes[0], 0, SEEK_SET);
+       istream = fdopen (fildes[0], "r");
+ #else
        istream = fdopen (fildes[0], "r");
+ #endif
  
  #if defined (JOB_CONTROL) && defined (PGRP_PIPE)
        close_pgrp_pipe ();
  #endif /* JOB_CONTROL && PGRP_PIPE */
  
        close (fildes[1]);
+ #if defined (USE_VMS)
+       fildes[1] = -1;
+ #endif
  
        if (!istream)
  	{
  	  internal_error ("Can't reopen pipe to command substitution (fd %d): %s",
  			fildes[0], strerror (errno));
+ #if defined (USE_VMS)
+ 	  goto error_exit_without_restore;
+ #else
  	  goto error_exit;
+ #endif
  	}
  
        /* Read the output of the command through the pipe. */
***************
*** 2283,2289 ****
--- 2460,2472 ----
  	}
  
        fclose (istream);
+ #if defined (USE_VMS)
+       /* fildes[0] closed by fclose */
+       fildes[0] = -1;
+       vmsutil_pipe_clean (pipes);
+ #else
        close (fildes[0]);
+ #endif
  
        last_command_exit_value = wait_for (pid);
        last_command_subst_pid = pid;
***************
*** 2305,2311 ****
--- 2488,2498 ----
        /* If we read no output, just return now and save ourselves some
  	 trouble. */
        if (istring_index == 0)
+ #if defined (USE_VMS)
+ 	goto error_exit_without_restore;
+ #else
  	goto error_exit;
+ #endif
  
        /* Strip trailing newlines from the output of the command. */
        if (quoted)
***************
*** 2684,2689 ****
--- 2871,2879 ----
    int number;			/* Temporary number value. */
    int t_index;			/* For calls to string_extract_xxx. */
    char *command_subst_result;	/* For calls to command_substitute (). */
+ #if defined (USE_VMS)
+   int need_expand_path = 0;
+ #endif
  
    istring[0] = '\0';
  
***************
*** 2797,2802 ****
--- 2987,2997 ----
  	      temp = itos (number);
  	    dollar_add_string:
  	      if (string[sindex]) sindex++;
+ #if defined (USE_VMS)
+ 	      if (temp && istring_index == 0
+ 		  && (temp[0] == '/' || (temp[0] == CTLESC && temp[1] == '/')))
+ 		need_expand_path = 1;
+ #endif
  
  	      /* Add TEMP to ISTRING. */
  	    add_string:
***************
*** 3270,3275 ****
--- 3465,3474 ----
  		if (var && !invisible_p (var) && value_cell (var))
  		  {
  		    temp = value_cell (var);
+ #if defined (USE_VMS)
+ 		    if (temp[0] == '/')
+ 		      need_expand_path = 1;
+ #endif
  		    temp = quoted && temp && *temp ? quote_string (temp)
  						   : quote_escapes (temp);
  		    free (name);
***************
*** 3308,3316 ****
--- 3507,3522 ----
  	  handle_command_substitution:
  	    command_subst_result = command_substitute (temp, quoted);
  
+ #if 0 /* unwind_frame_run_internal may have already freed temp. DBR. */
  	    FREE (temp);
+ #endif
  
  	    temp = command_subst_result;
+ #if defined (USE_VMS)
+ 	    if (temp && istring_index == 0
+ 		&& (temp[0] == '/' || (temp[0] == CTLESC && temp[1] == '/')))
+ 	      need_expand_path = 1;
+ #endif
  
  	    if (string[sindex])
  	      sindex++;
***************
*** 3362,3367 ****
--- 3568,3577 ----
  
  	    t_index = sindex;
  	    temp = string_extract_double_quoted (string, &sindex);
+ #if defined (USE_VMS)
+ 	    if (temp && istring_index == 0 && temp[0] == '/')
+ 	      need_expand_path = 1;
+ #endif
  
  	    /* If the quotes surrounded the entire string, then the
  	       whole word was quoted. */
***************
*** 3437,3442 ****
--- 3647,3656 ----
  	       as well), so we go directly to add_string. */
  	    if (tresult)
  	      {
+ #if defined (USE_VMS)
+ 		if (tresult->word->expansion)
+ 		  need_expand_path = 1;
+ #endif
  		if (tresult->next)
  		  {
  		    quote_list (tresult);
***************
*** 3527,3532 ****
--- 3741,3750 ----
  	    }
  
  	add_character:
+ #if defined (USE_VMS)
+ 	  if (istring_index == 0 && c == '/')
+ 	    need_expand_path = 1;
+ #endif
  	  if (istring_index + 1 >= istring_size)
  	    {
  	      while (istring_index + 1 >= istring_size)
***************
*** 3543,3548 ****
--- 3761,3792 ----
  
  finished_with_string:
  final_exit:
+ #if defined (USE_VMS)
+   if (need_expand_path != 0 && istring && strpbrk (istring, ":;") == NULL)
+     {
+       char tbuf[4] = { 0, 0, 0, 0, };
+       char *p = istring, *q = tbuf;
+       int i;
+ 
+       /* dequote 4 chars */
+       for (i = 0; i < 4; i++)
+ 	{
+ 	  if (*p == CTLESC)
+ 	    p++;
+ 	  if (*p == '\0')
+ 	    break;
+ 	  *q++ = *p++;
+ 	}
+ 
+       /* check whether it's option switch */
+       if (tbuf[0] != '/' || (tbuf[1] != '\0' && (tbuf[1] == '/' || tbuf[2] == '\0')
+ 			     && (tbuf[1] != '/' || !isalpha (tbuf[2])
+ 				 || (tbuf[3] != '/' && tbuf[3] != '\0'))))
+ 	need_expand_path = 0;
+     }
+   else
+     need_expand_path = 0;
+ #endif
    /* OK, we're ready to return.  If we have a quoted string, and
       quoted_dollar_at is not set, we do no splitting at all; otherwise
       we split on ' '.  The routines that call this will handle what to
***************
*** 3625,3630 ****
--- 3869,3877 ----
  	      temp_list = make_word_list (tword, (WORD_LIST *)NULL);
  	      tword->quoted = quoted || (quoted_state == WHOLLY_QUOTED);
  	      tword->assignment = word->assignment;
+ #if defined (USE_VMS)
+ 	      tword->expansion = need_expand_path;
+ #endif
  	    }
  	}
  
***************
*** 4497,4502 ****
--- 4744,4756 ----
  void sv_notify ();
  #endif
  
+ #if defined (USE_VMS)
+ void sv_path_expand (char *name);
+ void sv_path_separator (char *name);
+ void sv_path_slash (char *name);
+ void sv_sysroot (char *name);
+ #endif
+ 
  #define SET_INT_VAR(name, intvar)  intvar = find_variable (name) != 0
  
  struct name_and_function {
***************
*** 4549,4554 ****
--- 4803,4816 ----
    { "allow_null_glob_expansion", sv_allow_null_glob_expansion },
    { "noclobber", sv_noclobber },
    { "nolinks", sv_nolinks },
+ 
+ #if defined (USE_VMS)
+   { "PATH_EXPAND", sv_path_expand },
+   { "PATH_SEPARATOR", sv_path_separator },
+   { "PATH_SLASH", sv_path_slash },
+   { "SYSROOT", sv_sysroot },
+ #endif
+ 
    { (char *)0x00, (VFunction *)0x00 }
  };
  
***************
*** 4865,4867 ****
--- 5127,5209 ----
    posix_readline_initialize (posixly_correct);
  #endif /* READLINE */
  }
+ 
+ #if defined (USE_VMS)
+ void
+ sv_path_expand (char *name)
+ {
+   char *p;
+ 
+   p = get_string_value (name);
+   vmsutil_path_expand = 0;
+   if (p != NULL)
+     {
+       if (*p == 'y' || *p == 'Y')
+ 	vmsutil_path_expand = 1;
+     }
+ }
+ 
+ void
+ sv_path_separator (char *name)
+ {
+   char **vp, *p;
+ 
+   vp = vmsutil_get_import_variables ();
+   p = get_string_value (name);
+   vmsutil_path_separator = ';';
+   if (p != NULL)
+     {
+       if (*p != '\0' && *p != '/' && *p != '\\' && *p < 0x7f)
+ 	vmsutil_path_separator = (int) *(unsigned char *) p;
+     }
+   vmsutil_put_export_variables (vp);
+ }
+ 
+ void
+ sv_path_slash (char *name)
+ {
+   char **vp, *p;
+ 
+   vp = vmsutil_get_import_variables ();
+   p = get_string_value (name);
+   vmsutil_path_slash = '/';
+   if (p != NULL)
+     {
+       if (*p != '\0' && (*p == '/' || *p == '\\') && *p < 0x7f)
+ 	vmsutil_path_slash = (int) *(unsigned char *) p;
+     }
+   vmsutil_put_export_variables (vp);
+ }
+ 
+ void
+ sv_sysroot (char *name)
+ {
+   char **vp, *p;
+ 
+   vp = vmsutil_get_import_variables ();
+   p = get_string_value (name);
+   if (p != NULL)
+     {
+       if (p[0] == '/' && p[1] == '/' && isalpha (p[2]) && (p[3] == '\0' || p[3] == '/'))
+ 	{
+ 	  vmsutil_sysroot[0] = p[2];
+ 	  vmsutil_sysroot[1] = ':';
+ 	  strcpy (vmsutil_sysroot + 2, p + 3);
+ 	}
+       else
+ 	strcpy (vmsutil_sysroot, p);
+       vmsutil_toslash (vmsutil_sysroot);
+       if (vmsutil_sysroot[0] != '/' || vmsutil_sysroot[1] != '\0')
+ 	vmsutil_delslash (vmsutil_sysroot);
+       if (isalpha (vmsutil_sysroot[0]) && vmsutil_sysroot[1] == ':')
+ 	vmsutil_sysroot[0] = tolower (vmsutil_sysroot[0]);
+       vmsutil_sysroot_len = strlen (vmsutil_sysroot);
+     }
+   else
+     {
+       vmsutil_sysroot[0] = '\0';
+       vmsutil_sysroot_len = -1;
+     }
+   vmsutil_put_export_variables (vp);
+ }
+ #endif
diff -r -c bash-1_14_7/support/getcppsyms.c bash1147/support/getcppsyms.c
*** bash-1_14_7/support/getcppsyms.c	Wed Mar 10 09:44:07 1999
--- bash1147/support/getcppsyms.c	Wed Mar 10 09:45:24 1999
***************
*** 422,427 ****
--- 422,430 ----
  #if defined (vax)
    printf (" -Dvax");
  #endif /* vax */
+ #if defined (vms)
+   printf (" -Dvms");
+ #endif /* vms */
  
    printf ("\n");
    exit (0);
diff -r -c bash-1_14_7/support/inpath. bash1147/support/inpath.
*** bash-1_14_7/support/inpath.	Wed Mar 10 09:44:07 1999
--- bash1147/support/inpath.	Wed Mar 10 09:45:24 1999
***************
*** 3,18 ****
  # Search $PATH for a file the same name as $1; return TRUE if found.
  #
  
  command=$1
  [ -n "$command" ] || exit 1
  
! set `echo $PATH | sed 's/^:/.:/
! 			s/::/:.:/g
! 			s/:$/:./
! 			s/:/ /g'`
  	
  while [ $# -ne 0 ] ; do
  	[ -f $1/$command ] && exit 0	# test -x not universal
  	shift
  done
  
--- 3,23 ----
  # Search $PATH for a file the same name as $1; return TRUE if found.
  #
  
+ PSC=$PATH_SEPARATOR
+ if [ -z "$PSC" ]; then
+   PSC=";"
+ fi
  command=$1
  [ -n "$command" ] || exit 1
  
! set `echo $PATH | sed -e "s/^$PSC/.$PSC/
! 			s/$PSC$PSC/$PSC.$PSC/g
! 			s/$PSC\\$/$PSC./
! 			s/$PSC/ /g" -e 's,\\\\,/,g'`
  	
  while [ $# -ne 0 ] ; do
  	[ -f $1/$command ] && exit 0	# test -x not universal
+ 	[ -f $1/${command}.exe ] && exit 0	# test -x not universal
  	shift
  done
  
diff -r -c bash-1_14_7/test.c bash1147/test.c
*** bash-1_14_7/test.c	Wed Mar 10 09:43:49 1999
--- bash1147/test.c	Fri Mar 19 17:36:16 1999
***************
*** 27,32 ****
--- 27,36 ----
  #include <stdio.h>
  #include "bashtypes.h"
  
+ #if defined (VMS)
+ #define lstat stat
+ #endif
+ 
  #if !defined (STANDALONE)
  #  if !defined (_POSIX_VERSION)
  #    include <sys/file.h>
***************
*** 47,52 ****
--- 51,60 ----
  #  define digit_value(c) ((c) - '0')
  #endif /* STANDALONE */
  
+ #if defined (USE_VMS)
+ #include <stdlib.h>
+ #endif
+ 
  #if !defined (STRLEN)
  #  define STRLEN(s) ((s)[0] ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
  #endif
***************
*** 191,197 ****
--- 199,217 ----
  	}
      }
  #endif /* !HAVE_DEV_FD */
+ #if defined (USE_VMS)
+   {
+     int rc;
+     char *fixp;
+ 
+     fixp = vmsutil_expand_path (savestring (path));
+     rc = stat (fixp, finfo);
+     free (fixp);
+     return rc;
+   }
+ #else
    return (stat (path, finfo));
+ #endif
  }
  
  /* Do the same thing access(2) does, but use the effective uid and gid,
***************
*** 773,778 ****
--- 793,822 ----
      case 'x':			/* File is executable? */
        unary_advance ();
        value = -1 != EACCESS (argv[pos - 1], X_OK);
+ #if defined (USE_VMS)
+       if (value != TRUE)
+ 	{
+ 	  char *name, *ext;
+ 	  int len;
+ 
+ 	  len = strlen (argv[pos - 1]);
+ 	  name = malloc (len + 5);
+ 	  if (name != NULL)
+ 	    {
+ 	      strcpy (name, argv[pos - 1]);
+ 	      ext = name + len;
+ #if defined (USE_VMS)
+ 	      while (vmsutil_add_executable_suffix (name, ext))
+ #endif
+ 		{
+ 		  value = -1 != EACCESS (name, X_OK);
+ 		  if (value == TRUE)
+ 		    break;
+ 		}
+ 	      free (name);
+ 	    }
+ 	}
+ #endif
        return (TRUE == value);
  
      case 'O':			/* File is owned by you? */
diff -r -c bash-1_14_7/tests/exp-tests. bash1147/tests/exp-tests.
*** bash-1_14_7/tests/exp-tests.	Wed Mar 10 09:44:08 1999
--- bash1147/tests/exp-tests.	Wed Mar 10 09:45:26 1999
***************
*** 18,35 ****
  # Test the substitution quoting characters (CTLESC and CTLNUL) in different
  # combinations
  
! expect "<^A>"
! recho `echo ''`
! expect "<^A>"
! recho `echo ""`
! expect "<^B>"
! recho `echo ''`
! expect "<^B>"
! recho `echo ""`
! expect "<^A>"
! recho `echo `
! expect "<^B>"
! recho `echo `
  
  # Test null strings without variable expansion
  expect "<abcdefgh>"
--- 18,35 ----
  # Test the substitution quoting characters (CTLESC and CTLNUL) in different
  # combinations
  
! #expect "<^A>"
! #recho `echo ''`
! #expect "<^A>"
! #recho `echo ""`
! #expect "<^B>"
! #recho `echo ''`
! #expect "<^B>"
! #recho `echo ""`
! #expect "<^A>"
! #recho `echo `
! #expect "<^B>"
! #recho `echo `
  
  # Test null strings without variable expansion
  expect "<abcdefgh>"
***************
*** 227,237 ****
  expect '<\$x>'
  recho '\$x'
  
! expect '<$x>'
! recho `echo '\$x'`
  
! expect '<\$x>'
! recho $(echo '\$x')
  
  # The difference between $* "$*" and "$@"
  
--- 227,237 ----
  expect '<\$x>'
  recho '\$x'
  
! #expect '<$x>'
! #recho `echo '\$x'`
  
! #expect '<\$x>'
! #recho $(echo '\$x')
  
  # The difference between $* "$*" and "$@"
  
***************
*** 316,323 ****
  expect '<26>'
  recho $[ 13 * 2 ]
  
! expect '<\>'
! recho `echo \\\\`
  
  expect '<~>'
  recho '~'
--- 316,323 ----
  expect '<26>'
  recho $[ 13 * 2 ]
  
! #expect '<\>'
! #recho `echo \\\\`
  
  expect '<~>'
  recho '~'
diff -r -c bash-1_14_7/tests/run-ifs-tests. bash1147/tests/run-ifs-tests.
*** bash-1_14_7/tests/run-ifs-tests.	Wed Mar 10 09:44:10 1999
--- bash1147/tests/run-ifs-tests.	Wed Mar 10 09:45:28 1999
***************
*** 2,13 ****
  # show that IFS is only applied to the result of expansions
  #
  ../bash ifs-test-1.sh > xx
! diff xx ./ifs.1.right
  
  ../bash ifs-test-2.sh > xx
! diff xx ./ifs.2.right
  
  ../bash ifs-test-3.sh > xx
! diff xx ./ifs.3.right
  
  rm -f xx
--- 2,13 ----
  # show that IFS is only applied to the result of expansions
  #
  ../bash ifs-test-1.sh > xx
! diff xx ./ifs_1.right
  
  ../bash ifs-test-2.sh > xx
! diff xx ./ifs_2.right
  
  ../bash ifs-test-3.sh > xx
! diff xx ./ifs_3.right
  
  rm -f xx
diff -r -c bash-1_14_7/tests/varenv.sh bash1147/tests/varenv.sh
*** bash-1_14_7/tests/varenv.sh	Wed Mar 10 09:44:11 1999
--- bash1147/tests/varenv.sh	Wed Mar 10 09:45:29 1999
***************
*** 45,51 ****
  echo $HOME
  
  expect $HOME
! HOME=/a/b/c /bin/echo $HOME
  
  expect $HOME
  echo $HOME
--- 45,51 ----
  echo $HOME
  
  expect $HOME
! HOME=/a/b/c /gnu/bin/echo $HOME
  
  expect $HOME
  echo $HOME
***************
*** 59,65 ****
  # This should echo $HOME 9, NOT /a/b/c 9
  
  expect "$HOME"
! HOME=/a/b/c /bin/echo $HOME c=9
  expect "$HOME 7"
  echo $HOME $c
  
--- 59,65 ----
  # This should echo $HOME 9, NOT /a/b/c 9
  
  expect "$HOME"
! HOME=/a/b/c /gnu/bin/echo $HOME c=9
  expect "$HOME 7"
  echo $HOME $c
  
diff -r -c bash-1_14_7/trap.c bash1147/trap.c
*** bash-1_14_7/trap.c	Wed Mar 10 09:43:49 1999
--- bash1147/trap.c	Fri Mar 19 17:36:16 1999
***************
*** 86,97 ****
--- 86,99 ----
        original_signals[i] = IMPOSSIBLE_TRAP_HANDLER;
      }
  
+ #if !defined (USE_VMS)
    /* Show which signals are treated specially by the shell. */
  #if defined (SIGCHLD)
    original_signals[SIGCHLD] = (SigHandler *) set_signal_handler (SIGCHLD, SIG_DFL);
    set_signal_handler (SIGCHLD, original_signals[SIGCHLD]);
    sigmodes[SIGCHLD] |= (SIG_SPECIAL | SIG_NO_TRAP);
  #endif /* SIGCHLD */
+ #endif /* !USE_VMS */
  
    original_signals[SIGINT] =
      (SigHandler *) set_signal_handler (SIGINT, SIG_DFL);
***************
*** 454,459 ****
--- 456,483 ----
  /* Handle the calling of "trap 0".  The only sticky situation is when
     the command to be executed includes an "exit".  This is why we have
     to provide our own place for top_level to jump to. */
+ #if defined (USE_VMS)
+ /* static variables wrapper */
+ int
+ vmsutil_get_signal_modes (int sig)
+ {
+   if (sig < 0 || sig >= NSIG)
+     return -1;
+   return sigmodes[sig];
+ }
+ 
+ int
+ vmsutil_set_signal_modes (int sig, int modes)
+ {
+   int oldmodes;
+   if (sig < 0 || sig >= NSIG)
+     return -1;
+   oldmodes = sigmodes[sig];
+   sigmodes[sig] = modes;
+   return oldmodes;
+ }
+ #endif
+ 
  int
  run_exit_trap ()
  {
***************
*** 586,591 ****
--- 610,619 ----
  {
    char *command, *saved_command;
    int old_exit_value;
+ #if defined (USE_VMS)
+   int old_subshell_exit_builtin;
+   extern int subshell_exit_builtin;
+ #endif
  
    /* Run the interrupt trap if SIGINT is trapped and not ignored, and if
       we are not currently running in the interrupt trap handler. */
***************
*** 601,608 ****
--- 629,643 ----
        command = savestring (saved_command);
  
        old_exit_value = last_command_exit_value;
+ #if defined (USE_VMS)
+       old_subshell_exit_builtin = subshell_exit_builtin; 
+       subshell_exit_builtin = 0;
+ #endif
        parse_and_execute (command, "interrupt trap", 0);
        last_command_exit_value = old_exit_value;
+ #if defined (USE_VMS)
+       subshell_exit_builtin = old_subshell_exit_builtin;
+ #endif
  
        sigmodes[SIGINT] &= ~SIG_INPROGRESS;
  
diff -r -c bash-1_14_7/trap.h bash1147/trap.h
*** bash-1_14_7/trap.h	Wed Mar 10 09:43:49 1999
--- bash1147/trap.h	Wed Mar 10 09:44:58 1999
***************
*** 29,35 ****
--- 29,39 ----
  #endif /* SIG_DFL */
  
  #if !defined (NSIG)
+ #if defined (SIGMAX)
+ #define NSIG SIGMAX
+ #else
  #define NSIG 64
+ #endif /* !SIGMAX */
  #endif /* !NSIG */
  
  #define NO_SIG -1
diff -r -c bash-1_14_7/variables.c bash1147/variables.c
*** bash-1_14_7/variables.c	Wed Mar 10 09:43:49 1999
--- bash1147/variables.c	Fri Mar 19 17:36:16 1999
***************
*** 195,201 ****
--- 195,211 ----
    temp_var = set_if_not ("PATH", DEFAULT_PATH_VALUE);
    set_auto_export (temp_var);
  
+ #if defined (USE_VMS)
+   temp_var = find_variable ("TERM");
+   if (!temp_var)
+     {
+       /* makes empty invisible variable */
+       temp_var = bind_variable ("TERM", (char *) NULL);
+       temp_var->attributes |= att_invisible;
+     }
+ #else
    temp_var = set_if_not ("TERM", "dumb");
+ #endif
    set_auto_export (temp_var);
  
    if (interactive_shell)
***************
*** 537,544 ****
--- 547,562 ----
    register SHELL_VAR *var;
  
    for (i = 0; list && (var = list[i]); i++)
+ #if defined (USE_VMS)
+     {
+       QUIT;
+       if (!invisible_p (var))
+         print_assignment (var);
+     }
+ #else
      if (!invisible_p (var))
        print_assignment (var);
+ #endif
  }
  
  #if defined (NOTDEF)
***************
*** 1666,1676 ****
--- 1684,1700 ----
  	{
  	  free (array[i]);
  	  array[i] = savestring (assign);
+ #if defined (USE_VMS)
+ 	  array[i] = vmsutil_fix_variable (array[i]);
+ #endif
  	  return (array);
  	}
      }
    array = (char **)xrealloc (array, ((2 + i) * sizeof (char *)));
    array[i++] = savestring (assign);
+ #if defined (USE_VMS)
+   array[i-1] = vmsutil_fix_variable (array[i-1]);
+ #endif
    array[i] = (char *)NULL;
    return (array);
  }
