2021-01-23 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	DJGPP support added.

	* configure: DJGPP specific prefix added.
	DJGPP specific EXEEXT added.
	DJGPP specific CFLAGS added.

	* doc/clzip.texi: DJGPP specific info added.

	* main.c: New macro NUMERIC_PATTERN replaces "00001".
	[O_BINARY, DJGPP]: unistd.h included to porovide pathconf prototype.
	Macro HAVE_LFN_SUPPORT defined according the OS used.
	(main): Added DJGPP to the systems that need to call setmode.
	(set_d_outname): SFN specific support implemented.
	(close_and_set_permissions) [MSDOS]: Do not set permissions, it does
	not really make sense on DOS/Windows inhibiting that the file can be
	deleted.
	(next_filename): SFN specific multi-file support implemented.
	(set_c_outname): SFN specific multi-file support implemented.
	(set_c_outname): SFN specific support implemented.

	* makefile.in: EXEEXT added.
	lzip will be created as link of clzip.
	doc will be created when installing.

	*testsuite/check.sh: Extension added to program name.






diff -aprNU5 clzip-1.12.orig/configure clzip-1.12/configure
--- clzip-1.12.orig/configure	2021-01-01 15:37:54 +0000
+++ clzip-1.12/configure	2021-01-23 22:42:38 +0000
@@ -12,22 +12,30 @@ srctrigger=doc/${pkgname}.texi
 
 # clear some things potentially inherited from environment.
 LC_ALL=C
 export LC_ALL
 srcdir=
-prefix=/usr/local
+prefix='/dev/env/DJDIR'
 exec_prefix='$(prefix)'
 bindir='$(exec_prefix)/bin'
 datarootdir='$(prefix)/share'
 infodir='$(datarootdir)/info'
 mandir='$(datarootdir)/man'
 CC=gcc
 CPPFLAGS=
-CFLAGS='-Wall -W -O2'
 LDFLAGS=
+EXEEXT=.exe
 
 # checking whether we are using GNU C.
+/bin/sh -c "${CC} --version" > /dev/null 2>&1 && { 
+	# Ensure that always old GNU extern inline semantics is used
+	# (aka -fgnu89-inline) even if ISO C99 semantics has been specified.
+	case $(${CC} --version 2>/dev/null | sed "/^.* \([1-9]\+\.[0-9]\+[.0-9]*\).*$/!d;s/^.* \([1-9]\+\.[0-9]\+[.0-9]*\).*$/\1/") in
+	[1-3].*|4.[0-1][.0-9]* )  CFLAGS=${CFLAGS='-g2 -O2 -march=i386 -mtune=i586 -Wall -pedantic -save-temps'};;
+	* )                       CFLAGS=${CFLAGS='-g2 -O2 -fgnu89-inline -march=i386 -mtune=i586 -Wall -pedantic -save-temps'};;
+	esac
+}
 /bin/sh -c "${CC} --version" > /dev/null 2>&1 || { CC=cc ; CFLAGS=-O2 ; }
 
 # Loop over all args
 args=
 no_create=
@@ -162,10 +170,11 @@ echo "infodir = ${infodir}"
 echo "mandir = ${mandir}"
 echo "CC = ${CC}"
 echo "CPPFLAGS = ${CPPFLAGS}"
 echo "CFLAGS = ${CFLAGS}"
 echo "LDFLAGS = ${LDFLAGS}"
+echo "EXEEXT = ${EXEEXT}"
 rm -f Makefile
 cat > Makefile << EOF
 # Makefile for Clzip - LZMA lossless data compressor
 # Copyright (C) 2010-2021 Antonio Diaz Diaz.
 # This file was generated automatically by configure. Don't edit.
@@ -185,9 +194,10 @@ infodir = ${infodir}
 mandir = ${mandir}
 CC = ${CC}
 CPPFLAGS = ${CPPFLAGS}
 CFLAGS = ${CFLAGS}
 LDFLAGS = ${LDFLAGS}
+EXEEXT = ${EXEEXT}
 EOF
 cat "${srcdir}/Makefile.in" >> Makefile
 
 echo "OK. Now you can run make."
diff -aprNU5 clzip-1.12.orig/doc/clzip.texi clzip-1.12/doc/clzip.texi
--- clzip-1.12.orig/doc/clzip.texi	2021-01-04 17:03:06 +0000
+++ clzip-1.12/doc/clzip.texi	2021-01-23 22:42:38 +0000
@@ -163,10 +163,44 @@ file from that of the compressed file as
 @item filename.lz  @tab becomes @tab filename
 @item filename.tlz @tab becomes @tab filename.tar
 @item anyothername @tab becomes @tab anyothername.out
 @end multitable
 
+The @acronym{DJGPP} port of clzip checks if the used file system supports LFNs
+or only SFNs.  If only SFN support is available, the file name and its extension
+must be truncated and modified to encode the compressor extension and the numbers
+to identify a multi volume archive.  The program does not store the original
+file name in the header of the archive thus there is no chance to regenerate
+them when uncompressiong the archive in a SFN environment.  Here the same
+naming schema is applied than the one used in the bzip2 and xz ports.  The
+archiver extension is ".lz".  On SFN systems, the ".lz" extension will consume
+one or two characters of the original file name extension.
+
+For SFN systems the following rules apply when decompressing:
+@multitable {anyothername.ext} {becomes} {anyothername.out}
+@item filename.exl  @tab becomes @tab filename.ex
+@item filename.elz  @tab becomes @tab filename.e
+@item filename.lz  @tab becomes @tab filename
+@item filename.tlz @tab becomes @tab filename.tar
+@item anyothername.ext @tab becomes @tab anyothername.out
+@end multitable
+
+For SFN systems the following rules apply when compressing:
+@multitable {anyothername.ext} {becomes} {anyothername.out}
+@item filename.ext  @tab becomes @tab filename.exl
+@item filename.ex  @tab becomes @tab filename.exl
+@item filename.e  @tab becomes @tab filename.elz
+@item filename  @tab becomes @tab filename.lz
+@item filename.tar @tab becomes @tab filename.tlz
+@end multitable
+
+If only SFN support is available, the @acronym{DJGPP} port of clzip will
+always consume the last 5 characters of the 8 possible name characters to
+encode the volume number.  E.g.: when compressing a file with the file name
+@samp{@var{filename.ext}} and splitting it into multiple volumes, the different
+volumes will become @samp{@var{fil}00001.exl}, @samp{@var{fil}00002.exl}, etc.
+
 (De)compressing a file is much like copying or moving it; therefore clzip
 preserves the access and modification dates, permissions, and, when
 possible, ownership of the file just as @samp{cp -p} does. (If the user ID or
 the group ID can't be duplicated, the file permission bits S_ISUID and
 S_ISGID are cleared).
diff -aprNU5 clzip-1.12.orig/main.c clzip-1.12/main.c
--- clzip-1.12.orig/main.c	2021-01-01 15:37:54 +0000
+++ clzip-1.12/main.c	2021-01-23 22:46:16 +0000
@@ -20,10 +20,11 @@
    corrupt or invalid input file, 3 for an internal consistency error
    (eg, bug) which caused clzip to panic.
 */
 
 #define _FILE_OFFSET_BITS 64
+#define NUMERIC_PATTERN "00001"
 
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -64,10 +65,21 @@
 #include "encoder.h"
 #include "fast_encoder.h"
 
 #ifndef O_BINARY
 #define O_BINARY 0
+#define HAVE_LFN_SUPPORT(name) (1)
+#else
+#ifdef __DJGPP__
+#include <unistd.h>
+#define HAVE_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
+#define IS_TAR(name)           (((name)[0] == 't' || (name)[0] == 'T') && \
+                                ((name)[1] == 'a' || (name)[1] == 'A') && \
+                                ((name)[2] == 'r' || (name)[2] == 'R'))
+#else
+#define HAVE_LFN_SUPPORT(name) (0)
+#endif
 #endif
 
 #if CHAR_BIT != 8
 #error "Environments where CHAR_BIT != 8 are not supported."
 #endif
@@ -377,17 +389,110 @@ static int extension_index( const char *
 static void set_c_outname( const char * const name, const bool filenames_given,
                            const bool force_ext, const bool multifile )
   {
   /* zupdate < 1.9 depends on lzip adding the extension '.lz' to name when
      reading from standard input. */
-  output_filename = resize_buffer( output_filename, strlen( name ) + 5 +
-                                   strlen( known_extensions[0].from ) + 1 );
-  strcpy( output_filename, name );
-  if( multifile ) strcat( output_filename, "00001" );
-  if( force_ext || multifile ||
-      ( !filenames_given && extension_index( output_filename ) < 0 ) )
-    strcat( output_filename, known_extensions[0].from );
+  if( HAVE_LFN_SUPPORT(name) )
+    {
+    output_filename = resize_buffer( output_filename, strlen( name ) + 5 +
+                                     strlen( known_extensions[0].from ) + 1 );
+    strcpy( output_filename, name );
+    if( multifile ) strcat( output_filename, NUMERIC_PATTERN );
+    if( force_ext || multifile ||
+        ( !filenames_given && extension_index( output_filename ) < 0 ) )
+      strcat( output_filename, known_extensions[0].from );
+    }
+  else
+    {
+    // For plain DOS there are filename length limitations (8.3).
+    //
+    // uncompressed name     compressed name
+    //   filename.ext    -->   filename.exl
+    //   filename.ex     -->   filename.exl
+    //   filename.e      -->   filename.elz
+
+    size_t name_ext_len, name_len, str_len = strlen( name );
+    for( name_len = str_len; name_len && name[name_len] != '.'; name_len-- )
+      ;
+
+    {
+    const bool is_tar = IS_TAR( &(name[name_len + 1]) ) ? true : false;
+    const char* const suffix = is_tar ? known_extensions[1].from : known_extensions[0].from;
+    size_t ext_len = str_len - name_len;
+    if( ext_len == 1 || name_len == 0)
+      {
+      // File name has no extension so simply append the whole extension.
+      const size_t suffix_len = strlen(suffix);
+      name_len = ext_len == 1 && str_len > 1 ? --str_len : str_len;
+      name_ext_len = name_len + suffix_len;
+
+      str_len = multifile ? name_ext_len + sizeof NUMERIC_PATTERN - 1 : name_ext_len;
+      output_filename = resize_buffer( output_filename, str_len + 1);
+
+      memcpy( output_filename, name, name_len );
+      memcpy( output_filename + name_len, suffix, suffix_len);
+      output_filename[name_ext_len] = '\0';
+      }
+    else
+      {
+      // File name has an extension so only a part of the extension can be appended.
+      if( ext_len > 2 )
+        {
+        // Only one character left for extension.
+        name_ext_len = name_len + 1 + 2;                                 // Dot plus 2 extension chars
+
+        str_len = multifile ? name_ext_len + 1 + sizeof NUMERIC_PATTERN - 1 : name_ext_len + 1;
+        output_filename = resize_buffer( output_filename, str_len + 1);  // and 1 extension char.
+
+        if( is_tar )
+          {
+          memcpy( output_filename, name, name_len );
+          memcpy( output_filename + name_len, suffix, strlen( suffix ));
+          }
+        else
+          {
+          memcpy( output_filename, name, name_ext_len );
+          output_filename[name_ext_len] = suffix[1];
+          }
+        output_filename[++name_ext_len] = '\0';
+        }
+      else
+        {
+        // Two characters left for extension.
+        name_ext_len = name_len + 1 + 1;                                 // Dot plus 1 extension char
+
+        str_len = multifile ? name_ext_len + 2 + sizeof NUMERIC_PATTERN - 1: name_ext_len + 2;
+        output_filename = resize_buffer( output_filename, str_len + 1);  // and 2 extension chars.
+
+        memcpy( output_filename, name, name_ext_len);
+        output_filename[name_ext_len] = suffix[1];
+        output_filename[++name_ext_len] = suffix[2];
+        output_filename[++name_ext_len] = '\0';
+        }
+      }
+    }
+
+    if( multifile )
+      {
+      size_t i, k;
+
+      /*  Move extension.  */
+      size_t minor_index = 8 + name_ext_len - name_len;
+      size_t major_index = name_len < 4 ? str_len > 12 ? minor_index : str_len : minor_index;
+
+      if( major_index != name_ext_len )
+        for( name_len--, k = major_index, i = name_ext_len; i > name_len; i--, k-- )
+          output_filename[k] = output_filename[i];
+      else
+        k = --name_len;
+
+      /*  Insert numeric pattern.  */
+      minor_index = name_len < 3 ? i : 2;
+      for( output_filename[k--] = '1'; k > minor_index; k-- )
+        output_filename[k] = '0';
+      }
+    }
   }
 
 
 static void set_d_outname( const char * const name, const int eindex )
   {
@@ -405,11 +510,26 @@ static void set_d_outname( const char *
       return;
       }
     }
   output_filename = resize_buffer( output_filename, name_len + 4 + 1 );
   strcpy( output_filename, name );
-  strcat( output_filename, ".out" );
+  if( HAVE_LFN_SUPPORT(name) )
+    strcat( output_filename, ".out" );
+  else
+    {
+    if( name_len == 0 )
+      strcpy( output_filename, "_out" );  /* No leading dot allowed.  */
+    else
+      {
+      int n;
+      for( n = name_len - 1; n > -1 && output_filename[n] != '.'; n-- )
+        ;
+      if( n > 0 )
+        output_filename[n] = '\0';
+      strcat( output_filename, ".out" );
+      }
+    }
   if( verbosity >= 1 )
     fprintf( stderr, "%s: Can't guess original name for '%s' -- using '%s'\n",
              program_name, name, output_filename );
   }
 
@@ -543,11 +663,15 @@ static void close_and_set_permissions( c
   if( in_statsp )
     {
     const mode_t mode = in_statsp->st_mode;
     /* fchown will in many cases return with EPERM, which can be safely ignored. */
     if( fchown( outfd, in_statsp->st_uid, in_statsp->st_gid ) == 0 )
+#ifdef MSDOS
+      warning = false;
+#else
       { if( fchmod( outfd, mode ) != 0 ) warning = true; }
+#endif
     else
       if( errno != EPERM ||
           fchmod( outfd, mode & ~( S_ISUID | S_ISGID | S_ISVTX ) ) != 0 )
         warning = true;
     }
@@ -570,19 +694,37 @@ static void close_and_set_permissions( c
   }
 
 
 static bool next_filename( void )
   {
-  const unsigned name_len = strlen( output_filename );
-  const unsigned ext_len = strlen( known_extensions[0].from );
-  int i, j;
-  if( name_len >= ext_len + 5 )				/* "*00001.lz" */
-    for( i = name_len - ext_len - 1, j = 0; j < 5; --i, ++j )
+  if( HAVE_LFN_SUPPORT(output_filename) )
+    {
+    const unsigned name_len = strlen( output_filename );
+    const unsigned ext_len = strlen( known_extensions[0].from );
+    int i, j;
+    if( name_len >= ext_len + 5 )				/* "*00001.lz" */
+      for( i = name_len - ext_len - 1, j = 0; j < 5; --i, ++j )
+        {
+        if( output_filename[i] < '9' ) { ++output_filename[i]; return true; }
+        else output_filename[i] = '0';
+        }
+    }
+  else
+    {
+    size_t name_len = strlen( output_filename );
+    for( ; name_len && output_filename[name_len] != '.'; name_len-- )
+      ;
+    if( --name_len > 3 )				/* "*00001" */
       {
-      if( output_filename[i] < '9' ) { ++output_filename[i]; return true; }
-      else output_filename[i] = '0';
+      int i;
+      for( i = name_len; name_len - i < 5; i-- )
+        {
+        if( output_filename[i] < '9' ) { ++output_filename[i]; return true; }
+        else output_filename[i] = '0';
+        }
       }
+    }
   return false;
   }
 
 
 struct Poly_encoder
diff -aprNU5 clzip-1.12.orig/Makefile.in clzip-1.12/Makefile.in
--- clzip-1.12.orig/Makefile.in	2020-05-01 22:20:54 +0000
+++ clzip-1.12/Makefile.in	2021-01-23 22:42:38 +0000
@@ -16,13 +16,13 @@ objs = carg_parser.o lzip_index.o list.o
          install-bin-strip install-info-compress install-man-compress \
          install-as-lzip \
          uninstall uninstall-bin uninstall-info uninstall-man \
          doc info man check dist clean distclean
 
-all : $(progname)
+all : $(progname)$(EXEEXT)
 
-$(progname) : $(objs)
+$(progname)$(EXEEXT) : $(objs)
 	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(objs)
 
 main.o : main.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
 
@@ -47,12 +47,12 @@ 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)
-	help2man -n 'reduces the size of files' -o $@ ./$(progname)
+$(VPATH)/doc/$(progname).1 : $(progname)$(EXEEXT)
+	help2man -n 'reduces the size of files' -o $@ ./$(progname)$(EXEEXT)
 
 Makefile : $(VPATH)/configure $(VPATH)/Makefile.in
 	./config.status
 
 check : all
@@ -63,42 +63,42 @@ install-strip : install-bin-strip instal
 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)/$(progname)"
+	$(INSTALL_PROGRAM) ./$(progname)$(EXEEXT) "$(DESTDIR)$(bindir)/$(progname)$(EXEEXT)"
 
 install-bin-strip : all
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
 
-install-info :
+install-info : info
 	if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
 	-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*
 	$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(pkgname).info"
 	-if $(CAN_RUN_INSTALLINFO) ; then \
 	  install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info" ; \
 	fi
 
 install-info-compress : install-info
 	lzip -v -9 "$(DESTDIR)$(infodir)/$(pkgname).info"
 
-install-man :
+install-man : man
 	if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
 	-rm -f "$(DESTDIR)$(mandir)/man1/$(progname).1"*
 	$(INSTALL_DATA) $(VPATH)/doc/$(progname).1 "$(DESTDIR)$(mandir)/man1/$(progname).1"
 
 install-man-compress : install-man
 	lzip -v -9 "$(DESTDIR)$(mandir)/man1/$(progname).1"
 
 install-as-lzip : install
 	-rm -f "$(DESTDIR)$(bindir)/lzip"
-	cd "$(DESTDIR)$(bindir)" && ln -s $(progname) lzip
+	cd "$(DESTDIR)$(bindir)" && stubify -g lzip.exe | stubedit lzip.exe runfile=$(progname)$(EXEEXT)
 
 uninstall : uninstall-man uninstall-info uninstall-bin
 
 uninstall-bin :
-	-rm -f "$(DESTDIR)$(bindir)/$(progname)"
+	-rm -f "$(DESTDIR)$(bindir)/$(progname)$(EXEEXT)"
 
 uninstall-info :
 	-if $(CAN_RUN_INSTALLINFO) ; then \
 	  install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info" ; \
 	fi
@@ -131,9 +131,9 @@ dist : doc
 	  $(DISTNAME)/testsuite/test_em.txt.lz
 	rm -f $(DISTNAME)
 	lzip -v -9 $(DISTNAME).tar
 
 clean :
-	-rm -f $(progname) $(objs)
+	-rm -f $(progname)$(EXEEXT) $(objs)
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -aprNU5 clzip-1.12.orig/testsuite/check.sh clzip-1.12/testsuite/check.sh
--- clzip-1.12.orig/testsuite/check.sh	2021-01-02 23:20:56 +0000
+++ clzip-1.12/testsuite/check.sh	2021-01-23 22:42:38 +0000
@@ -7,11 +7,11 @@
 
 LC_ALL=C
 export LC_ALL
 objdir=`pwd`
 testdir=`cd "$1" ; pwd`
-LZIP="${objdir}"/clzip
+LZIP="${objdir}"/clzip.exe
 framework_failure() { echo "failure in testing framework" ; exit 1 ; }
 
 if [ ! -f "${LZIP}" ] || [ ! -x "${LZIP}" ] ; then
 	echo "${LZIP}: cannot execute"
 	exit 1
