2015-11-20 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	DJGPP support added.

	* red.in: Check also for backslashes as directory separators.

	* testsuite/check.sh: Convert CR/LF to NL in all produced output files
	of the testsuite before comparing them with the reference files.

	* signal.c [__DJGPP__]: Include <pc.h> for OS specific ScreenRows and
	ScreenCols.  If SA_RESTART not defined on DJGPP then define to 0.
	(sigwinch_handler) [__DJGPP__]: On DJGPP if TIOCGWINSZ is not defined
	use ScreenRows and ScreenCols to initialize _window_lines and
	_window_columns.
	(set_signals) [MSDOS]: On MSDOS systems find out screen dimensions
	always.

	* main.c (may_access_filename): Use IS_DIR_SEPARATOR to check for
	backslash or slash as directory separator.

	* ed.h: Define new macros IS_DIR_SEPARATOR and IS_RESTRICTED_ED.
	The value of the macros depends if compiling on a MSDOS like OS or
	not.

	* buffer.c (path_max): [MSDOS] Do not make posix like assumptions
	when defining a default for max. path length.

	* Makefile.in: Variable exeext added. Use exeext for all produced
	binaries and in all targets where appropriate.
	install-man added to install target.
	Use cp instead of ln.






diff -aprNU5 ed-1.12.orig/buffer.c ed-1.12/buffer.c
--- ed-1.12.orig/buffer.c	2015-05-26 02:10:24 +0200
+++ ed-1.12/buffer.c	2015-11-20 23:26:26 +0100
@@ -397,12 +397,16 @@ int path_max( const char * filename )
   {
   long result;
   if( !filename ) filename = "/";
   errno = 0;
   result = pathconf( filename, _PC_PATH_MAX );
+#ifdef MSDOS
+  if( result < 0 ) if( errno ) result = 80;
+#else
   if( result < 0 ) { if( errno ) result = 256; else result = 1024; }
   else if( result < 256 ) result = 256;
+#endif
   return result;
   }
 
 
 /* append lines from the yank buffer */
diff -aprNU5 ed-1.12.orig/ed.h ed-1.12/ed.h
--- ed-1.12.orig/ed.h	2015-06-21 19:40:58 +0200
+++ ed-1.12/ed.h	2015-11-20 23:27:02 +0100
@@ -55,10 +55,16 @@ undo_t;
 #endif
 #ifndef min
 #define min( a,b ) ( (( a ) < ( b )) ? ( a ) : ( b ) )
 #endif
 
+#ifdef MSDOS
+# define IS_SLASH(path)  (strchr((path), '/') || strchr((path), '\\'))
+#else
+# define IS_SLASH(path)  (strchr((path), '/'))
+#endif
+
 
 /* defined in buffer.c */
 bool append_lines( const char ** const ibufpp, const int addr,
                    const bool isglobal );
 bool close_sbuf( void );
diff -aprNU5 ed-1.12.orig/main.c ed-1.12/main.c
--- ed-1.12.orig/main.c	2015-05-26 01:13:10 +0200
+++ ed-1.12/main.c	2015-11-20 23:28:20 +0100
@@ -126,11 +126,11 @@ bool is_regular_file( const int fd )
 
 
 bool may_access_filename( const char * const name )
   {
   if( restricted_ &&
-      ( *name == '!' || !strcmp( name, ".." ) || strchr( name, '/' ) ) )
+      ( *name == '!' || !strcmp( name, ".." ) || IS_SLASH( name ) ) )
     {
     set_error_msg( "Shell access restricted" );
     return false;
     }
   return true;
diff -aprNU5 ed-1.12.orig/Makefile.in ed-1.12/Makefile.in
--- ed-1.12.orig/Makefile.in	2015-04-09 05:43:12 +0200
+++ ed-1.12/Makefile.in	2015-11-20 23:25:26 +0100
@@ -5,23 +5,24 @@ INSTALL_PROGRAM = $(INSTALL) -m 755
 INSTALL_SCRIPT = $(INSTALL) -m 755
 INSTALL_DATA = $(INSTALL) -m 644
 INSTALL_DIR = $(INSTALL) -d -m 755
 SHELL = /bin/sh
 
+exeext = .exe
 objs = buffer.o carg_parser.o global.o io.o main.o main_loop.o regex.o signal.o
 
 
 .PHONY : all install install-bin install-info install-man \
          install-strip install-compress install-strip-compress \
          install-bin-strip install-info-compress install-man-compress \
          uninstall uninstall-bin uninstall-info uninstall-man \
          doc info man check dist clean distclean
 
-all : $(progname) r$(progname)
+all : $(progname)$(exeext) r$(progname) doc
 
-$(progname) : $(objs)
-	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs)
+$(progname)$(exeext) : $(objs)
+	$(CC) $(LDFLAGS) -o $(progname)$(exeext) $(objs)
 
 r$(progname) : r$(progname).in
 	cat $(VPATH)/r$(progname).in > $@
 	chmod a+x $@
 
@@ -43,27 +44,27 @@ info : $(VPATH)/doc/$(pkgname).info
 $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
 	cd $(VPATH)/doc && makeinfo $(pkgname).texi
 
 man : $(VPATH)/doc/$(progname).1
 
-$(VPATH)/doc/$(progname).1 : $(progname)
+$(VPATH)/doc/$(progname).1 : $(progname)$(exeext)
 	help2man -n 'line-oriented text editor' -o $@ ./$(progname)
 
 Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
 	./config.status
 
-check : all
+check : all $(progname)$(exeext)
 	@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
 
 install : install-bin install-info install-man
 install-strip : install-bin-strip install-info install-man
 install-compress : install-bin install-info-compress install-man-compress
 install-strip-compress : install-bin-strip install-info-compress install-man-compress
 
 install-bin : all
 	if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
-	$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(program_prefix)$(progname)"
+	$(INSTALL_PROGRAM) ./$(progname)$(exeext) "$(DESTDIR)$(bindir)/$(program_prefix)$(progname)$(exeext)"
 	$(INSTALL_SCRIPT) ./r$(progname) "$(DESTDIR)$(bindir)/$(program_prefix)r$(progname)"
 
 install-bin-strip : all
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
 
@@ -79,22 +80,22 @@ install-info-compress : install-info
 install-man :
 	if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
 	-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"*
 	-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"*
 	$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"
-	cd "$(DESTDIR)$(mandir)/man1" && ln -s "$(program_prefix)$(progname).1" "$(program_prefix)r$(progname).1"
+	cd "$(DESTDIR)$(mandir)/man1" && cp -vf "$(program_prefix)$(progname).1" "$(program_prefix)r$(progname).1"
 
 install-man-compress : install-man
 	lzip -v -9 "$(DESTDIR)$(mandir)/man1/$(program_prefix)$(progname).1"
 	-rm -f "$(DESTDIR)$(mandir)/man1/$(program_prefix)r$(progname).1"*
 	cd "$(DESTDIR)$(mandir)/man1" && ln -s "$(program_prefix)$(progname).1.lz" "$(program_prefix)r$(progname).1.lz"
 
 uninstall : uninstall-man uninstall-info uninstall-bin
 
 uninstall-bin :
 	-rm -f "$(DESTDIR)$(bindir)/$(program_prefix)$(progname)"
-	-rm -f "$(DESTDIR)$(bindir)/$(program_prefix)r$(progname)"
+	-rm -f "$(DESTDIR)$(bindir)/$(program_prefix)$(progname)$(exeext)"
 
 uninstall-info :
 	-install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
 	-rm -f "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"*
 
@@ -129,9 +130,9 @@ dist : doc
 	  $(DISTNAME)/*.c
 	rm -f $(DISTNAME)
 	lzip -v -9 $(DISTNAME).tar
 
 clean :
-	-rm -f $(progname) r$(progname) $(objs)
+	-rm -f $(progname)$(exeext) r$(progname) $(progname)_profiled$(progname)$(exeext) $(objs)
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -aprNU5 ed-1.12.orig/red.in ed-1.12/red.in
--- ed-1.12.orig/red.in	2010-05-01 20:49:30 +0200
+++ ed-1.12/red.in	2015-11-20 23:28:12 +0100
@@ -1,3 +1,3 @@
 #! /bin/sh
-bindir=`echo "$0" | sed -e 's,[^/]*$,,'`
+bindir=`echo "$0" | sed -e 's,[^/\\]*$,,'`
 exec "${bindir}"ed --restricted "$@"
diff -aprNU5 ed-1.12.orig/signal.c ed-1.12/signal.c
--- ed-1.12.orig/signal.c	2014-12-31 21:47:40 +0100
+++ ed-1.12/signal.c	2015-11-21 21:31:48 +0100
@@ -26,10 +26,18 @@
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 
+#ifdef __DJGPP__
+# include <pc.h>
+# ifndef SA_RESTART
+#  define SA_RESTART 0
+# endif
+#endif
+
+
 #include "ed.h"
 
 
 jmp_buf jmp_state;
 static int mutex = 0;			/* If > 0, signals stay pending */
@@ -93,10 +101,15 @@ static void sigwinch_handler( int signum
     {
     /* Sanity check values of environment vars */
     if( ws.ws_row > 2 && ws.ws_row < 600 ) window_lines_ = ws.ws_row - 2;
     if( ws.ws_col > 8 && ws.ws_col < 1800 ) window_columns_ = ws.ws_col - 8;
     }
+#else
+# if defined (__DJGPP__)
+  window_lines_ = ScreenRows () - 2;
+  window_columns_ = ScreenCols () - 8;
+# endif
 #endif
   if( signum ) {}			/* keep compiler happy */
   }
 
 
@@ -133,10 +146,13 @@ void set_signals( void )
   {
 #ifdef SIGWINCH
   sigwinch_handler( SIGWINCH );
   if( isatty( 0 ) ) set_signal( SIGWINCH, sigwinch_handler );
 #endif
+#ifdef MSDOS
+  sigwinch_handler ( 0 );	/* find out screen dimensions anyway */
+#endif
   set_signal( SIGHUP, sighup_handler );
   set_signal( SIGQUIT, SIG_IGN );
   set_signal( SIGINT, sigint_handler );
   }
 
diff -aprNU5 ed-1.12.orig/testsuite/check.sh ed-1.12/testsuite/check.sh
--- ed-1.12.orig/testsuite/check.sh	2014-12-30 03:43:16 +0100
+++ ed-1.12/testsuite/check.sh	2015-11-21 21:32:54 +0100
@@ -69,10 +69,11 @@ for i in *.red ; do
 	base=`echo "$i" | sed 's/\.red$//'`
 	if cat ${base}.red | "${ED}" -s > /dev/null 2>&1 ; then
 		echo "*** The piped script $i exited abnormally ***"
 		fail=127
 	else
+		dtou $base.ro
 		if cmp -s ${base}.ro "${testdir}"/${base}.pr ; then
 			true
 		else
 			echo "*** Output ${base}.ro of piped script $i is incorrect ***"
 			fail=127
@@ -82,10 +83,11 @@ done
 
 # Run the remaining scripts; they exit with zero status
 for i in *.ed ; do
 	base=`echo "$i" | sed 's/\.ed$//'`
 	if "${ED}" -s < ${base}.ed > /dev/null 2>&1 ; then
+		dtou $base.ro
 		if cmp -s ${base}.o "${testdir}"/${base}.r ; then
 			true
 		else
 			echo "*** Output ${base}.o of script $i is incorrect ***"
 			fail=127
