2009-05-25 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	DJGPP support added.

	* Makefile.in: Variable exeext added. Use exeext for all produced
	binaries and in all targets where appropriate
	install-man added to install target.
	Use symlink instead of hard link to create red.  (Do not use "ln -s"
	command to generate the symlink with DJGPP 2.04 because the symlink
	will contain the path where the package has been compiled and not a
	generic one making the symlink useless for all others.  Use the
	command sequence: stubify stubedit instead.)

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

	* 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.

	* main.c (show_version): DJGPP port info added.
	(is_valid_filename): Use IS_DIR_SEPARATOR to check for backslash or
	slash as directory separator.
	(main): Use IS_RESTRICTED_ED to check for program name.

	* 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.

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





diff -aprNU5 ed-1.3.orig/Makefile.in ed-1.3/Makefile.in
--- ed-1.3.orig/Makefile.in	2009-05-18 12:05:36 +0000
+++ ed-1.3/Makefile.in	2009-05-25 18:28:54 +0000
@@ -3,24 +3,25 @@ DISTNAME = $(progname)-$(progversion)
 INSTALL = install
 INSTALL_PROGRAM = $(INSTALL) -p -m 755
 INSTALL_DATA = $(INSTALL) -p -m 644
 SHELL = /bin/sh
 
+exeext = .exe
 objs = buf.o carg_parser.o glbl.o io.o main.o main_loop.o re.o signal.o
 
 
 .PHONY : all install install-info install-man install-strip \
          uninstall uninstall-info uninstall-man \
          doc info man check dist clean distclean
 
-all : $(progname)
+all : $(progname)$(exeext) doc
 
-$(progname) : $(objs)
-	$(CC) $(LDFLAGS) -o $(progname) $(objs)
+$(progname)$(exeext) : $(objs)
+	$(CC) $(LDFLAGS) -o $(progname)$(exeext) $(objs)
 
-$(progname)_profiled : $(objs)
-	$(CC) $(LDFLAGS) -pg -o $(progname)_profiled $(objs)
+$(progname)_profiled$(exeext) : $(objs)
+	$(CC) $(LDFLAGS) -pg -o $(progname)_profiled$(exeext) $(objs)
 
 main.o : main.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) -DPROGVERSION=\"$(progversion)\" -c -o $@ $<
 
 %.o : %.c
@@ -39,36 +40,36 @@ $(VPATH)/doc/$(progname).info : $(VPATH)
 	cd $(VPATH)/doc && makeinfo $(progname).texinfo
 
 Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
 	./config.status
 
-check : all $(VPATH)/testsuite/check.sh
+check : all $(progname)$(exeext) $(VPATH)/testsuite/check.sh
 	@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite
 
 install : all install-info install-man
 	if test ! -d $(DESTDIR)$(bindir) ; then $(INSTALL) -d $(DESTDIR)$(bindir) ; fi
-	$(INSTALL_PROGRAM) ./$(progname) $(DESTDIR)$(bindir)/$(program_prefix)$(progname)
-	-rm -f $(DESTDIR)$(bindir)/$(program_prefix)r$(progname)
-	cd $(DESTDIR)$(bindir) && ln -s $(program_prefix)$(progname) $(program_prefix)r$(progname)
+	$(INSTALL_PROGRAM) ./$(progname)$(exeext) $(DESTDIR)$(bindir)/$(progname)$(exeext)
+	-rm -f $(DESTDIR)$(bindir)/r$(progname)$(exeext)
+	cd $(DESTDIR)$(bindir) ; stubify -g r$(progname)$(exeext) ; stubedit r$(progname)$(exeext) runfile=$(progname)
 
 install-info :
 	if test ! -d $(DESTDIR)$(infodir) ; then $(INSTALL) -d $(DESTDIR)$(infodir) ; fi
 	$(INSTALL_DATA) $(VPATH)/doc/$(progname).info $(DESTDIR)$(infodir)/$(program_prefix)$(progname).info
 	-install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$(program_prefix)$(progname).info
 
 install-man :
 	if test ! -d $(DESTDIR)$(mandir)/man1 ; then $(INSTALL) -d $(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-info uninstall-man
-	-rm -f $(DESTDIR)$(bindir)/$(program_prefix)$(progname)
-	-rm -f $(DESTDIR)$(bindir)/$(program_prefix)r$(progname)
+	-rm -f $(DESTDIR)$(bindir)/$(progname)$(exeext)
+	-rm -f $(DESTDIR)$(bindir)/r$(progname)$(exeext)
 
 uninstall-info :
 	-install-info --remove $(DESTDIR)$(infodir)/$(program_prefix)$(progname).info $(DESTDIR)$(infodir)/dir
 	-rm -f $(DESTDIR)$(infodir)/$(program_prefix)$(progname).info
 
@@ -103,9 +104,9 @@ dist :
 	  $(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)$(exeext) profiled_$(progname)$(exeext) $(objs)
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -aprNU5 ed-1.3.orig/buf.c ed-1.3/buf.c
--- ed-1.3.orig/buf.c	2009-04-24 11:30:40 +0000
+++ ed-1.3/buf.c	2009-05-25 18:32:52 +0000
@@ -402,12 +402,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.3.orig/ed.h ed-1.3/ed.h
--- ed-1.3.orig/ed.h	2009-04-23 19:02:28 +0000
+++ ed-1.3/ed.h	2009-05-25 18:34:38 +0000
@@ -50,10 +50,24 @@ 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), '\\'))
+/* We can have ed.exe and red.exe, and we are case-insensitive...  */
+# define IS_RESTRICTED_ED(n, file_name) \
+  (((n) > 3 && ((file_name)[n-3] == 'e' || (file_name)[n-3] == 'E')    \
+            && ((file_name)[n-2] == 'x' || (file_name)[n-2] == 'X')    \
+            && ((file_name)[n-1] == 'e' || (file_name)[n-1] == 'E')    \
+            && ((file_name)[n]   ==  0  || (file_name)[n]   ==  0 )) ? \
+   ((n) > 6 && ((file_name)[n-7] == 'r' || (file_name)[n-7] == 'R')) : 0)
+#else
+# define IS_DIR_SEPARATOR(path)  (strchr((path), '/'))
+# define IS_RESTRICTED_ED(n, file_name) ((n) > 2 && (file_name)[n-3] == 'r')
+#endif
+
 
 /* defined in buf.c */
 char append_lines( const char *ibufp2, const int addr, const char isglobal );
 char close_sbuf( void );
 char copy_lines( const int first_addr, const int second_addr, const int addr );
diff -aprNU5 ed-1.3.orig/main.c ed-1.3/main.c
--- ed-1.3.orig/main.c	2009-05-21 17:15:36 +0000
+++ ed-1.3/main.c	2009-05-25 21:53:48 +0000
@@ -77,11 +77,11 @@ void show_help( void )
   }
 
 
 void show_version( void )
   {
-  printf( "%s %s\n", Program_name, PROGVERSION );
+  printf( "%s %s  (DJGPP port (r1))\n", Program_name, PROGVERSION );
   printf( "Copyright (C) 1994 Andrew L. Moore, %s Antonio Diaz Diaz.\n", program_year );
   printf( "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n" );
   printf( "This is free software: you are free to change and redistribute it.\n" );
   printf( "There is NO WARRANTY, to the extent permitted by law.\n" );
   }
@@ -119,11 +119,11 @@ char is_regular_file( int fd )
   }
 
 
 char is_valid_filename( const char *name )
   {
-  if( restricted_ && ( *name == '!' || !strcmp( name, ".." ) || strchr( name, '/' ) ) )
+  if( restricted_ && ( *name == '!' || !strcmp( name, ".." ) || IS_DIR_SEPARATOR( name ) ) )
     {
     set_error_msg( "Shell access restricted" );
     return 0;
     }
   return 1;
@@ -151,11 +151,11 @@ int main( const int argc, const char *ar
   if( !ap_init( &parser, argc, argv, options, 0 ) )
     { show_error( "Memory exhausted", 0, 0 ); return 1; }
   if( ap_error( &parser ) )				/* bad option */
     { show_error( ap_error( &parser ), 0, 1 ); return 1; }
   invocation_name = argv[0];
-  restricted_ = ( n > 2 && argv[0][n-3] == 'r' );
+  restricted_ = IS_RESTRICTED_ED( n, argv[0] );
 
   for( argind = 0; argind < ap_arguments( &parser ); ++argind )
     {
     const int code = ap_code( &parser, argind );
     const char * arg = ap_argument( &parser, argind );
diff -aprNU5 ed-1.3.orig/signal.c ed-1.3/signal.c
--- ed-1.3.orig/signal.c	2009-04-24 10:54:40 +0000
+++ ed-1.3/signal.c	2009-05-25 21:57:22 +0000
@@ -24,10 +24,17 @@
 #include <stdlib.h>
 #include <string.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 set, signals stay pending */
@@ -91,10 +98,15 @@ 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
   signum = 0;			/* keep compiler happy */
   }
 
 
@@ -131,10 +143,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.3.orig/testsuite/check.sh ed-1.3/testsuite/check.sh
--- ed-1.3.orig/testsuite/check.sh	2009-04-20 21:00:34 +0000
+++ ed-1.3/testsuite/check.sh	2009-05-25 21:59:48 +0000
@@ -71,10 +71,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
@@ -83,10 +84,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.o
 		if cmp -s ${base}.o "${testdir}"/${base}.r ; then
 			true
 		else
 			echo "*** Output ${base}.o of script $i is incorrect ***"
 		fi
