2017-02-25 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.
	Dor DJGPP add extension to the program.

	* 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.14.2.orig/buffer.c ed-1.14.2/buffer.c
--- ed-1.14.2.orig/buffer.c	2017-01-06 01:06:00 +0000
+++ ed-1.14.2/buffer.c	2017-02-25 23:08:34 +0000
@@ -394,12 +394,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.14.2.orig/ed.h ed-1.14.2/ed.h
--- ed-1.14.2.orig/ed.h	2017-02-22 16:25:30 +0000
+++ ed-1.14.2/ed.h	2017-02-25 23:08:34 +0000
@@ -53,10 +53,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,
                    bool insert, const bool isglobal );
 bool close_sbuf( void );
diff -aprNU5 ed-1.14.2.orig/main.c ed-1.14.2/main.c
--- ed-1.14.2.orig/main.c	2017-02-22 16:29:42 +0000
+++ ed-1.14.2/main.c	2017-02-25 23:08:34 +0000
@@ -127,11 +127,11 @@ bool is_regular_file( const int fd )
 
 
 bool may_access_filename( const char * const name )
   {
   if( restricted_ &&
-      ( *name == '!' || strcmp( name, ".." ) == 0 || strchr( name, '/' ) ) )
+      ( *name == '!' || strcmp( name, ".." ) == 0 || IS_SLASH( name ) ) )
     {
     set_error_msg( "Shell access restricted" );
     return false;
     }
   return true;
diff -aprNU5 ed-1.14.2.orig/Makefile.in ed-1.14.2/Makefile.in
--- ed-1.14.2.orig/Makefile.in	2016-09-26 22:21:00 +0000
+++ ed-1.14.2/Makefile.in	2017-02-25 23:08:34 +0000
@@ -6,23 +6,24 @@ INSTALL_SCRIPT = $(INSTALL) -m 755
 INSTALL_DATA = $(INSTALL) -m 644
 INSTALL_DIR = $(INSTALL) -d -m 755
 SHELL = /bin/sh
 CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1
 
+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 $@
 
@@ -44,27 +45,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
 
@@ -82,21 +83,21 @@ 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"
+	cd "$(DESTDIR)$(mandir)/man1" && cp -vf "$(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)$(progname)$(exeext)"
 	-rm -f "$(DESTDIR)$(bindir)/$(program_prefix)r$(progname)"
 
 uninstall-info :
 	-if $(CAN_RUN_INSTALLINFO) ; then \
 		install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info" ; \
@@ -134,9 +135,9 @@ dist : doc
 	  $(DISTNAME)/testsuite/*.err
 	rm -f $(DISTNAME)
 	lzip -v -9 $(DISTNAME).tar
 
 clean :
-	-rm -f $(progname) r$(progname) $(objs)
+	-rm -f $(progname)$(exeext) r$(progname) $(objs)
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -aprNU5 ed-1.14.2.orig/red.in ed-1.14.2/red.in
--- ed-1.14.2.orig/red.in	2010-05-14 11:49:26 +0000
+++ ed-1.14.2/red.in	2017-02-25 23:08:34 +0000
@@ -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.14.2.orig/signal.c ed-1.14.2/signal.c
--- ed-1.14.2.orig/signal.c	2017-01-06 01:06:00 +0000
+++ ed-1.14.2/signal.c	2017-02-25 23:08:34 +0000
@@ -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.14.2.orig/testsuite/check.sh ed-1.14.2/testsuite/check.sh
--- ed-1.14.2.orig/testsuite/check.sh	2017-01-06 01:13:24 +0000
+++ ed-1.14.2/testsuite/check.sh	2017-02-25 23:08:34 +0000
@@ -7,11 +7,15 @@
 
 LC_ALL=C
 export LC_ALL
 objdir=`pwd`
 testdir=`cd "$1" ; pwd`
-ED="${objdir}"/ed
+if [ "x${DJDIR}" != "x" ]; then
+	ED="${objdir}"/ed.exe
+else
+	ED="${objdir}"/ed
+fi
 framework_failure() { echo "failure in testing framework" ; exit 1 ; }
 
 if [ ! -f "${ED}" ] || [ ! -x "${ED}" ] ; then
 	echo "${ED}: cannot execute"
 	exit 1
@@ -55,10 +59,11 @@ for i in "${testdir}"/*.err ; do
 	base=`echo "$i" | sed 's,^.*/,,;s,\.err$,,'`	# remove dir and ext
 	if cat "$i" | "${ED}" -s test.txt > /dev/null 2>&1 ; then
 		echo "*** The piped script $i exited abnormally ***"
 		fail=127
 	else
+		dtou $base.ro
 		if cmp -s out.ro test.txt ; then
 			true
 		else
 			mv -f out.ro ${base}.ro
 			echo "*** Output ${base}.ro of piped script $i is incorrect ***"
@@ -72,10 +77,11 @@ done
 # which contain the correct output.
 # The .ed scripts should exit with zero status.
 for i in "${testdir}"/*.ed ; do
 	base=`echo "$i" | sed 's,^.*/,,;s,\.ed$,,'`	# remove dir and ext
 	if "${ED}" -s test.txt < "$i" > /dev/null 2> out.log ; then
+		dtou $base.ro
 		if cmp -s out.o "${testdir}"/${base}.r ; then
 			true
 		else
 			mv -f out.o ${base}.o
 			echo "*** Output ${base}.o of script $i is incorrect ***"
