2013-04-27 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.8.orig/Makefile.in ed-1.8/Makefile.in
--- ed-1.8.orig/Makefile.in	2012-10-09 15:17:26 +0000
+++ ed-1.8/Makefile.in	2013-04-27 13:30:24 +0000
@@ -5,25 +5,26 @@ INSTALL_PROGRAM = $(INSTALL) -p -m 755
 INSTALL_SCRIPT = $(INSTALL) -p -m 755
 INSTALL_DATA = $(INSTALL) -p -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 \
          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) -o $@ $(objs)
+$(progname)$(exeext) : $(objs)
+	$(CC) $(LDFLAGS) -o $(progname)$(exeext) $(objs)
 
-$(progname)_profiled : $(objs)
-	$(CC) $(LDFLAGS) -pg -o $@ $(objs)
+$(progname)_profiled$(exeext) : $(objs)
+	$(CC) $(LDFLAGS) -pg -o $(progname)_profiled$(exeext) $(objs)
 
 r$(progname) : r$(progname).in
 	cat $(VPATH)/r$(progname).in > $@
 	chmod a+x $@
 
@@ -45,25 +46,25 @@ info : $(VPATH)/doc/$(pkgname).info
 $(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texinfo
 	cd $(VPATH)/doc && makeinfo $(pkgname).texinfo
 
 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-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-info :
 	if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
 	$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
@@ -71,19 +72,19 @@ install-info :
 
 install-man :
 	if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
 	$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(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" "$(program_prefix)r$(progname).1"
+	cd "$(DESTDIR)$(mandir)/man1" && cp -vf "$(program_prefix)$(progname).1" "$(program_prefix)r$(progname).1"
 
 install-strip : all
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
 
 uninstall : uninstall-bin uninstall-info uninstall-man
 
 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 :
 	-install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
 	-rm -f "$(DESTDIR)$(infodir)/$(program_prefix)$(pkgname).info"
@@ -119,9 +120,9 @@ dist : doc
 	  $(DISTNAME)/*.c
 	rm -f $(DISTNAME)
 	lzip -v -9 $(DISTNAME).tar
 
 clean :
-	-rm -f $(progname) r$(progname) $(progname)_profiled $(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.8.orig/buffer.c ed-1.8/buffer.c
--- ed-1.8.orig/buffer.c	2013-02-08 23:22:56 +0000
+++ ed-1.8/buffer.c	2013-04-27 13:30:24 +0000
@@ -398,12 +398,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.8.orig/ed.h ed-1.8/ed.h
--- ed-1.8.orig/ed.h	2013-02-08 23:22:56 +0000
+++ ed-1.8/ed.h	2013-04-27 13:30:24 +0000
@@ -56,10 +56,16 @@ undo_t;
 #endif
 #ifndef min
 #define min( a,b ) ( (( a ) < ( b )) ? ( a ) : ( b ) )
 #endif
 
+#ifdef MSDOS
+# define IS_DIR_SEPARATOR(path)  (strchr((path), '/') || strchr((path), '\\'))
+#else
+# define IS_DIR_SEPARATOR(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.8.orig/main.c ed-1.8/main.c
--- ed-1.8.orig/main.c	2013-02-08 23:29:00 +0000
+++ ed-1.8/main.c	2013-04-27 13:30:24 +0000
@@ -124,11 +124,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_DIR_SEPARATOR( name ) ) )
     {
     set_error_msg( "Shell access restricted" );
     return false;
     }
   return true;
diff -aprNU5 ed-1.8.orig/red.in ed-1.8/red.in
--- ed-1.8.orig/red.in	2010-05-14 11:49:30 +0000
+++ ed-1.8/red.in	2013-04-27 13:30:24 +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.8.orig/signal.c ed-1.8/signal.c
--- ed-1.8.orig/signal.c	2013-02-08 23:22:56 +0000
+++ ed-1.8/signal.c	2013-04-27 13:30:24 +0000
@@ -27,10 +27,17 @@
 #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 */
@@ -94,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 */
   }
 
 
@@ -134,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.8.orig/testsuite/check.sh ed-1.8/testsuite/check.sh
--- ed-1.8.orig/testsuite/check.sh	2013-02-08 23:22:56 +0000
+++ ed-1.8/testsuite/check.sh	2013-04-27 13:30:24 +0000
@@ -77,10 +77,11 @@ done > errs.ck 2>&1
 for i in *.red ; do
 	base=`echo "$i" | sed 's/\.red$//'`
 	if cat ${base}.red | "${ED}" -s ; then
 		echo "*** The piped script $i exited abnormally ***"
 	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 ***"
 		fi
@@ -89,10 +90,11 @@ done > pipes.ck 2>&1
 
 # Run the remainding scripts; they exit with zero status
 for i in *.ed ; do
 	base=`echo "$i" | sed 's/\.ed$//'`
 	if ./${base}.ed ; then
+		dtou $base.ro
 		if cmp -s ${base}.o "${testdir}"/${base}.r ; then
 			true
 		else
 			echo "*** Output ${base}.o of script $i is incorrect ***"
 		fi
