*** buf.c~0	Sat Nov 19 12:37:58 1994
--- buf.c	Mon May  5 23:02:14 1997
*************** get_addressed_line_node (n)
*** 194,200 ****
  
  extern int newline_added;
  
! char sfn[15] = "";		/* scratch file name */
  
  /* open_sbuf: open scratch file */
  int
--- 194,200 ----
  
  extern int newline_added;
  
! char sfn[PATH_MAX] = "";		/* scratch file name */
  
  /* open_sbuf: open scratch file */
  int
*************** open_sbuf ()
*** 202,211 ****
  {
    char *mktemp ();
    int u;
  
    isbinary = newline_added = 0;
    u = umask(077);
-   strcpy (sfn, "/tmp/ed.XXXXXX");
    if (mktemp (sfn) == NULL || (sfp = fopen (sfn, "w+")) == NULL)
      {
        fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
--- 202,223 ----
  {
    char *mktemp ();
    int u;
+ #ifdef MSDOS
+   char *tempdir = getenv ("TMPDIR");
+ 
+   if (!tempdir)
+     tempdir = getenv ("TEMP");
+   if (!tempdir)
+     tempdir = getenv ("TMP");
+   if (!tempdir)
+     tempdir = "c:";
+   strcat (strcpy (sfn, tempdir), "/edXXXXXX");
+ #else
+   strcpy (sfn, "/tmp/ed.XXXXXX");
+ #endif
  
    isbinary = newline_added = 0;
    u = umask(077);
    if (mktemp (sfn) == NULL || (sfp = fopen (sfn, "w+")) == NULL)
      {
        fprintf (stderr, "%s: %s\n", sfn, strerror (errno));
*************** init_buffers ()
*** 279,284 ****
--- 291,297 ----
        fprintf (stderr, "%s\n", strerror (errno));
        quit (2);
      }
+   errmsg[0] = '\0';
    old_filename[0] = '\0';
    if (open_sbuf () < 0)
      quit (2);
*** configure	Sat Nov 19 12:56:24 1994
--- djgpp/configure	Mon May  5 22:18:32 1997
***************
*** 407,413 ****
  if ln -s X conftestdata 2>/dev/null
  then
    rm -f conftestdata
!   ac_cv_prog_LN_S="ln -s"
  else
    ac_cv_prog_LN_S=ln
  fi
--- 407,413 ----
  if ln -s X conftestdata 2>/dev/null
  then
    rm -f conftestdata
!   ac_cv_prog_LN_S=ln
  else
    ac_cv_prog_LN_S=ln
  fi
***************
*** 431,437 ****
    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
    for ac_dir in $PATH; do
      test -z "$ac_dir" && ac_dir=.
!     if test -f $ac_dir/$ac_word; then
        ac_cv_prog_RANLIB="ranlib"
        break
      fi
--- 431,437 ----
    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
    for ac_dir in $PATH; do
      test -z "$ac_dir" && ac_dir=.
!     if test -x $ac_dir/$ac_word; then
        ac_cv_prog_RANLIB="ranlib"
        break
      fi
***************
*** 449,459 ****
  
  ac_aux_dir=
  for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
!   if test -f $ac_dir/install-sh; then
      ac_aux_dir=$ac_dir
      ac_install_sh="$ac_aux_dir/install-sh -c"
      break
!   elif test -f $ac_dir/install.sh; then
      ac_aux_dir=$ac_dir
      ac_install_sh="$ac_aux_dir/install.sh -c"
      break
--- 449,459 ----
  
  ac_aux_dir=
  for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
!   if test -x $ac_dir/install-sh; then
      ac_aux_dir=$ac_dir
      ac_install_sh="$ac_aux_dir/install-sh -c"
      break
!   elif test -x $ac_dir/install.sh; then
      ac_aux_dir=$ac_dir
      ac_install_sh="$ac_aux_dir/install.sh -c"
      break
***************
*** 488,494 ****
      *)
        # OSF1 and SCO ODT 3.0 have their own names for install.
        for ac_prog in ginstall installbsd scoinst install; do
!         if test -f $ac_dir/$ac_prog; then
  	  if test $ac_prog = install &&
              grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
  	    # AIX install.  It has an incompatible calling convention.
--- 488,494 ----
      *)
        # OSF1 and SCO ODT 3.0 have their own names for install.
        for ac_prog in ginstall installbsd scoinst install; do
!         if test -x $ac_dir/$ac_prog; then
  	  if test $ac_prog = install &&
              grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
  	    # AIX install.  It has an incompatible calling convention.
***************
*** 549,555 ****
    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
    for ac_dir in $PATH; do
      test -z "$ac_dir" && ac_dir=.
!     if test -f $ac_dir/$ac_word; then
        ac_cv_prog_CC="gcc"
        break
      fi
--- 549,555 ----
    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
    for ac_dir in $PATH; do
      test -z "$ac_dir" && ac_dir=.
!     if test -x $ac_dir/$ac_word; then
        ac_cv_prog_CC="gcc"
        break
      fi
***************
*** 1413,1419 ****
  done
  
  ac_given_srcdir=$srcdir
! ac_given_INSTALL="$INSTALL"
  
  trap 'rm -fr Makefile config.h conftest*; exit 1' 1 2 15
  
--- 1413,1419 ----
  done
  
  ac_given_srcdir=$srcdir
! ac_given_INSTALL='$INSTALL'
  
  trap 'rm -fr Makefile config.h conftest*; exit 1' 1 2 15
  
***************
*** 1439,1444 ****
--- 1439,1445 ----
  s%@CPP@%$CPP%g
  s%@ALLOCA@%$ALLOCA%g
  s%@LIBOBJS@%$LIBOBJS%g
+ s,\.h\.in,.h-in,g
  
  CEOF
  EOF
***************
*** 1473,1486 ****
    .)  srcdir=.
        if test -z "$ac_dots"; then top_srcdir=.
        else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
!   /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
    *) # Relative path.
      srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
      top_srcdir="$ac_dots$ac_given_srcdir" ;;
    esac
  
    case "$ac_given_INSTALL" in
!   [/$]*) INSTALL="$ac_given_INSTALL" ;;
    *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
    esac
    echo creating "$ac_file"
--- 1474,1488 ----
    .)  srcdir=.
        if test -z "$ac_dots"; then top_srcdir=.
        else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
!   /* | [A-z]:/*) # Absolute path
!     srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
    *) # Relative path.
      srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
      top_srcdir="$ac_dots$ac_given_srcdir" ;;
    esac
  
    case "$ac_given_INSTALL" in
!   [/$]* | [A-z]:/*) INSTALL="$ac_given_INSTALL" ;;
    *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
    esac
    echo creating "$ac_file"
***************
*** 1519,1525 ****
  ac_eC=' '
  ac_eD='%g'
  
! CONFIG_HEADERS=${CONFIG_HEADERS-"config.h"}
  for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
    # Support "outfile[:infile]", defaulting infile="outfile.in".
    case "$ac_file" in
--- 1521,1527 ----
  ac_eC=' '
  ac_eD='%g'
  
! CONFIG_HEADERS=${CONFIG_HEADERS-"config.h:config.h-in"}
  for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then
    # Support "outfile[:infile]", defaulting infile="outfile.in".
    case "$ac_file" in
*** ed.h~0	Sat Nov 19 12:38:00 1994
--- ed.h	Mon May  5 22:34:46 1997
*************** undo_t;
*** 147,152 ****
--- 147,159 ----
  #define INC_MOD(l, k)	((l) + 1 > (k) ? 0 : (l) + 1)
  #define DEC_MOD(l, k)	((l) - 1 < 0 ? (k) : (l) - 1)
  
+ #ifndef HAVE_SIGACTION
+ #define sigemptyset(f,s) ((f) ? (*(f) = 0, 0) : -1)
+ #define sigaddset(f,s)	((f) ? ((*(f) |= (1 << ((s) - 1))), 0) : -1)
+ #define sigdelset(f,s)	((f) ? ((*(f) &= ~(1 << ((s) - 1))), 0) : -1)
+ #define sigismember(f,s) ((f) ? ((*(f) & (1 << ((s) - 1))) != 0) : -1)
+ #endif
+ 
  /* SPL1: disable some interrupts (requires reliable signals) */
  #define SPL1()		mutex++
  
*************** undo_t;
*** 156,163 ****
      {									\
        if (--mutex == 0)							\
  	{								\
! 	  if (sigflags & (1 << (SIGHUP - 1))) handle_hup (SIGHUP);	\
! 	  if (sigflags & (1 << (SIGINT - 1))) handle_int (SIGINT);	\
          }								\
      }									\
    while (0)
--- 163,170 ----
      {									\
        if (--mutex == 0)							\
  	{								\
! 	  if (sigismember (&sigflags, SIGHUP) == 1) handle_hup (SIGHUP);\
! 	  if (sigismember (&sigflags, SIGINT) == 1) handle_int (SIGINT);\
          }								\
      }									\
    while (0)
*************** extern int isbinary;
*** 337,343 ****
--- 344,354 ----
  extern int isglobal;
  extern int modified;
  extern int mutex;
+ #ifdef HAVE_SIGACTION
+ extern sigset_t sigflags;
+ #else
  extern int sigflags;
+ #endif
  extern int traditional;
  
  /* global vars */
*** main.c~0	Sat Nov 19 12:38:02 1994
--- main.c	Mon May  5 22:53:52 1997
*************** int mutex = 0;			/* if set, signals set 
*** 94,100 ****
  int red = 0;			/* if set, restrict shell/directory access */
  int scripted = 0;		/* if set, suppress diagnostics */
  int sigactive = 0;		/* if set, signal handlers are enabled */
! int sigflags = 0;		/* if set, signals received while mutex set */
  
  char *old_filename;		/* default filename */
  long current_addr;		/* current address in editor buffer */
--- 94,104 ----
  int red = 0;			/* if set, restrict shell/directory access */
  int scripted = 0;		/* if set, suppress diagnostics */
  int sigactive = 0;		/* if set, signal handlers are enabled */
! #ifdef HAVE_SIGACTION
! sigset_t sigflags;
! #else
! int sigflags;			/* if set, signals received while mutex set */
! #endif
  
  char *old_filename;		/* default filename */
  long current_addr;		/* current address in editor buffer */
*************** main (argc, argv)
*** 167,172 ****
--- 171,187 ----
  
    program_name = argv[0];
    red = (n = strlen (argv[0])) > 2 && argv[0][n - 3] == 'r';
+ #ifdef MSDOS
+   /* We can have ed.exe and red.exe, and we are case-insensitive...  */
+   if (!red)
+     {
+       if (n >= 4
+ 	  && (strcmp (argv[0] + n - 4, ".exe") == 0
+ 	      || strcmp (argv[0] + n - 4, ".EXE") == 0))
+ 	red = n > 6 && (argv[0][n - 7] == 'r' || argv[0][n - 7] == 'R');
+     }
+ #endif
+ 
  top:
    while ((c = getopt_long (argc, argv, "Gp:s", long_options, NULL)) != EOF)
      switch (c)
*************** top:
*** 210,220 ****
--- 225,239 ----
  #endif
    init_buffers ();
  
+   sigemptyset (&sigflags);
    /* assert: reliable signals! */
  #ifdef SIGWINCH
    handle_winch (SIGWINCH);
    if (isatty (0))
      reliable_signal (SIGWINCH, handle_winch);
+ #endif
+ #ifdef MSDOS
+   handle_winch (0);	/* find out screen dimensions anyway */
  #endif
    reliable_signal (SIGHUP, signal_hup);
    reliable_signal (SIGQUIT, SIG_IGN);
*** signal.c~0	Sat Nov 19 12:38:04 1994
--- signal.c	Mon May  5 22:03:34 1997
*************** static char *rcsid = "@(#)$Id: signal.c,
*** 26,31 ****
--- 26,35 ----
  #include <setjmp.h>
  #include <sys/ioctl.h>
  
+ #ifdef __DJGPP__
+ #include <pc.h>
+ #endif
+ 
  #include "ed.h"
  
  
*************** signal_hup (signo)
*** 59,65 ****
       int signo;
  {
    if (mutex)
!     sigflags |= (1 << (signo - 1));
    else
      handle_hup (signo);
  }
--- 63,69 ----
       int signo;
  {
    if (mutex)
!     sigaddset (&sigflags, signo);
    else
      handle_hup (signo);
  }
*************** signal_int (signo)
*** 70,76 ****
       int signo;
  {
    if (mutex)
!     sigflags |= (1 << (signo - 1));
    else
      handle_int (signo);
  }
--- 74,80 ----
       int signo;
  {
    if (mutex)
!     sigaddset (&sigflags, signo);
    else
      handle_int (signo);
  }
*************** handle_hup (signo)
*** 93,99 ****
  
    if (!sigactive)
      quit (1);
!   sigflags &= ~(1 << (signo - 1));
    if (addr_last && write_file ("ed.hup", "w", 1, addr_last) < 0 &&
        (s = getenv ("HOME")) != NULL &&
        (n = strlen (s)) + 7 <= PATH_MAX &&	/* "ed.hup" + '/' */
--- 97,103 ----
  
    if (!sigactive)
      quit (1);
!   sigdelset (&sigflags, signo);
    if (addr_last && write_file ("ed.hup", "w", 1, addr_last) < 0 &&
        (s = getenv ("HOME")) != NULL &&
        (n = strlen (s)) + 7 <= PATH_MAX &&	/* "ed.hup" + '/' */
*************** handle_int (signo)
*** 115,121 ****
  {
    if (!sigactive)
      quit (1);
!   sigflags &= ~(1 << (signo - 1));
  #ifdef HAVE_SIGSETJMP
    siglongjmp (env, -1);
  #else
--- 119,125 ----
  {
    if (!sigactive)
      quit (1);
!   sigdelset (&sigflags, signo);
  #ifdef HAVE_SIGSETJMP
    siglongjmp (env, -1);
  #else
*************** handle_winch (signo)
*** 135,141 ****
    struct winsize ws;		/* window size structure */
  #endif
  
!   sigflags &= ~(1 << (signo - 1));
  #ifdef TIOCGWINSZ
    if (ioctl (0, TIOCGWINSZ, (char *) &ws) >= 0)
      {
--- 139,145 ----
    struct winsize ws;		/* window size structure */
  #endif
  
!   sigdelset (&sigflags, signo);
  #ifdef TIOCGWINSZ
    if (ioctl (0, TIOCGWINSZ, (char *) &ws) >= 0)
      {
*************** handle_winch (signo)
*** 144,148 ****
--- 148,157 ----
        if (ws.ws_col > 8)
  	cols = ws.ws_col - 8;
      }
+ #else
+ #if defined (__DJGPP__)
+   rows = ScreenRows () - 2;
+   cols = ScreenCols () - 8;
+ #endif
  #endif
  }
*** testsuite/ckscripts.sh	Sat Nov 19 11:26:26 1994
--- djgpp/ckscripts.sh	Sat May 10 13:06:56 1997
***************
*** 3,9 ****
  # and compares their output against the .r files, which contain
  # the correct output.
  
! PATH="/bin:/usr/bin:/usr/local/bin/:."
  ED=$1
  TMP=$2
  
--- 3,9 ----
  # and compares their output against the .r files, which contain
  # the correct output.
  
! PATH="$PATH;."
  ED=$1
  TMP=$2
  
***************
*** 40,45 ****
--- 40,46 ----
  	if cat  $base.red | $ED -; then
  		echo "*** The piped script $i exited abnormally ***"
  	else
+ 		dtou $base.ro
  		if cmp -s $base.ro ${TESTDIR}/$base.rr; then :; else
  			echo "*** Output ${TMP}$base.ro of piped script ${TMP}$i is incorrect ***"
  		fi
***************
*** 54,59 ****
--- 55,61 ----
  #		s/\..*
  #	EOF`
  	if $base.ed; then
+ 		dtou $base.o
  		if cmp -s $base.o ${TESTDIR}/$base.r; then :; else
  			echo "*** Output ${TMP}$base.o of script ${TMP}$i is incorrect ***"
  		fi
*** testsuite/mkscripts.sh	Sat Nov 19 11:26:28 1994
--- djgpp/mkscripts.sh	Sat May 10 13:03:50 1997
***************
*** 2,8 ****
  # This script generates ed test scripts, with extensions .ed and .red, from 
  # .t and .err files, respectively.
  
! PATH="/bin:/usr/bin:/usr/local/bin/:."
  ED=$1
  TMP=$2
  TESTDIR=`pwd`
--- 2,8 ----
  # This script generates ed test scripts, with extensions .ed and .red, from 
  # .t and .err files, respectively.
  
! PATH="$PATH;."
  ED=$1
  TMP=$2
  TESTDIR=`pwd`
