diff -acprNC5 bzip2-1.0.2.orig/Makefile bzip2-1.0.2.djgpp/Makefile
*** bzip2-1.0.2.orig/Makefile	Fri Jan 25 23:34:52 2002
--- bzip2-1.0.2.djgpp/Makefile	Mon May 20 21:50:24 2002
*************** AR=ar
*** 7,56 ****
  RANLIB=ranlib
  LDFLAGS=
  
  # Suitably paranoid flags to avoid bugs in gcc-2.7
  BIGFILES=-D_FILE_OFFSET_BITS=64
! CFLAGS=-Wall -Winline -O2 -fomit-frame-pointer -fno-strength-reduce $(BIGFILES)
  
  # Where you want it installed when you do 'make install'
! PREFIX=/usr
  
  
  OBJS= blocksort.o  \
        huffman.o    \
        crctable.o   \
        randtable.o  \
        compress.o   \
        decompress.o \
        bzlib.o
  
! all: libbz2.a bzip2 bzip2recover test
  
  bzip2: libbz2.a bzip2.o
! 	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2
  
  bzip2recover: bzip2recover.o
! 	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover bzip2recover.o
  
  libbz2.a: $(OBJS)
  	rm -f libbz2.a
! 	$(AR) cq libbz2.a $(OBJS)
! 	@if ( test -f $(RANLIB) -o -f /usr/bin/ranlib -o \
! 		-f /bin/ranlib -o -f /usr/ccs/bin/ranlib ) ; then \
! 		echo $(RANLIB) libbz2.a ; \
! 		$(RANLIB) libbz2.a ; \
! 	fi
  
  check: test
  test: bzip2
  	@cat words1
! 	./bzip2 -1  < sample1.ref > sample1.rb2
! 	./bzip2 -2  < sample2.ref > sample2.rb2
! 	./bzip2 -3  < sample3.ref > sample3.rb2
! 	./bzip2 -d  < sample1.bz2 > sample1.tst
! 	./bzip2 -d  < sample2.bz2 > sample2.tst
! 	./bzip2 -ds < sample3.bz2 > sample3.tst
  	cmp sample1.bz2 sample1.rb2 
  	cmp sample2.bz2 sample2.rb2
  	cmp sample3.bz2 sample3.rb2
  	cmp sample1.tst sample1.ref
  	cmp sample2.tst sample2.ref
--- 7,58 ----
  RANLIB=ranlib
  LDFLAGS=
  
  # Suitably paranoid flags to avoid bugs in gcc-2.7
  BIGFILES=-D_FILE_OFFSET_BITS=64
! CFLAGS=-g -Wall -Winline -O2 -fomit-frame-pointer -fno-strength-reduce $(BIGFILES)
! 
! E=.exe
! MAKEINFO=makeinfo
! MAKEINFOFLAGS=--no-split
  
  # Where you want it installed when you do 'make install'
! PREFIX=/dev/env/DJDIR
  
  
  OBJS= blocksort.o  \
        huffman.o    \
        crctable.o   \
        randtable.o  \
        compress.o   \
        decompress.o \
        bzlib.o
  
! all: bzip2.info libbz2.a bzip2 bzip2recover test
! 
! bzip2.info: bzip2.texi
! 	$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@
  
  bzip2: libbz2.a bzip2.o
! 	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2$E bzip2.o -L. -lbz2
  
  bzip2recover: bzip2recover.o
! 	$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2recover$E bzip2recover.o
  
  libbz2.a: $(OBJS)
  	rm -f libbz2.a
! 	$(AR) cqs libbz2.a $(OBJS)
  
  check: test
  test: bzip2
  	@cat words1
! 	./bzip2$E -1  < sample1.ref > sample1.rb2
! 	./bzip2$E -2  < sample2.ref > sample2.rb2
! 	./bzip2$E -3  < sample3.ref > sample3.rb2
! 	./bzip2$E -d  < sample1.bz2 > sample1.tst
! 	./bzip2$E -d  < sample2.bz2 > sample2.tst
! 	./bzip2$E -ds < sample3.bz2 > sample3.tst
  	cmp sample1.bz2 sample1.rb2 
  	cmp sample2.bz2 sample2.rb2
  	cmp sample3.bz2 sample3.rb2
  	cmp sample1.tst sample1.ref
  	cmp sample2.tst sample2.ref
*************** test: bzip2
*** 58,78 ****
  	@cat words3
  
  install: bzip2 bzip2recover
  	if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
  	if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
  	if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi
  	if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi
  	if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
! 	cp -f bzip2 $(PREFIX)/bin/bzip2
! 	cp -f bzip2 $(PREFIX)/bin/bunzip2
! 	cp -f bzip2 $(PREFIX)/bin/bzcat
! 	cp -f bzip2recover $(PREFIX)/bin/bzip2recover
! 	chmod a+x $(PREFIX)/bin/bzip2
! 	chmod a+x $(PREFIX)/bin/bunzip2
! 	chmod a+x $(PREFIX)/bin/bzcat
! 	chmod a+x $(PREFIX)/bin/bzip2recover
  	cp -f bzip2.1 $(PREFIX)/man/man1
  	chmod a+r $(PREFIX)/man/man1/bzip2.1
  	cp -f bzlib.h $(PREFIX)/include
  	chmod a+r $(PREFIX)/include/bzlib.h
  	cp -f libbz2.a $(PREFIX)/lib
--- 60,81 ----
  	@cat words3
  
  install: bzip2 bzip2recover
  	if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
  	if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
+ 	if ( test ! -d $(PREFIX)/info ) ; then mkdir -p $(PREFIX)/info ; fi
  	if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi
  	if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi
  	if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi
! 	cp -f bzip2$E $(PREFIX)/bin/bzip2$E
! 	ln -s $(PREFIX)/bin/bzip2$E $(PREFIX)/bin/bunzip2$E
! 	ln -s $(PREFIX)/bin/bzip2$E $(PREFIX)/bin/bzcat$E
! 	cp -f bzip2recover$E $(PREFIX)/bin/bzip2recover$E
! 	chmod a+x $(PREFIX)/bin/bzip2$E
! 	chmod a+x $(PREFIX)/bin/bunzip2$E
! 	chmod a+x $(PREFIX)/bin/bzcat$E
! 	chmod a+x $(PREFIX)/bin/bzip2recover$E
  	cp -f bzip2.1 $(PREFIX)/man/man1
  	chmod a+r $(PREFIX)/man/man1/bzip2.1
  	cp -f bzlib.h $(PREFIX)/include
  	chmod a+r $(PREFIX)/include/bzlib.h
  	cp -f libbz2.a $(PREFIX)/lib
*************** install: bzip2 bzip2recover
*** 93,106 ****
  	chmod a+r $(PREFIX)/man/man1/bzdiff.1
  	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1
  	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzfgrep.1
  	echo ".so man1/bzmore.1" > $(PREFIX)/man/man1/bzless.1
  	echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
  
  distclean: clean
  clean: 
! 	rm -f *.o libbz2.a bzip2 bzip2recover \
  	sample1.rb2 sample2.rb2 sample3.rb2 \
  	sample1.tst sample2.tst sample3.tst
  
  blocksort.o: blocksort.c
  	@cat words0
--- 96,111 ----
  	chmod a+r $(PREFIX)/man/man1/bzdiff.1
  	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzegrep.1
  	echo ".so man1/bzgrep.1" > $(PREFIX)/man/man1/bzfgrep.1
  	echo ".so man1/bzmore.1" > $(PREFIX)/man/man1/bzless.1
  	echo ".so man1/bzdiff.1" > $(PREFIX)/man/man1/bzcmp.1
+ 	cp -f bzip2.info $(PREFIX)/info/bzip2.info
+ 	install-info --info-dir=$(PREFIX)/info $(PREFIX)/info/bzip2.info
  
  distclean: clean
  clean: 
! 	rm -f *.o libbz2.a bzip2$E bzip2recover$E \
  	sample1.rb2 sample2.rb2 sample3.rb2 \
  	sample1.tst sample2.tst sample3.tst
  
  blocksort.o: blocksort.c
  	@cat words0
*************** tarfile:
*** 177,192 ****
  	   $(DISTNAME)/bzgrep.1 \
  	   $(DISTNAME)/Makefile-libbz2_so
  	gzip -v $(DISTNAME).tar
  
  # For rebuilding the manual from sources on my RedHat 7.2 box
! manual: manual.ps manual.pdf manual.html
  
! manual.ps: manual.texi
! 	tex manual.texi
! 	dvips -o manual.ps manual.dvi
  
! manual.pdf: manual.ps
! 	ps2pdf manual.ps
  
! manual.html: manual.texi
! 	texi2html -split_chapter manual.texi
--- 182,197 ----
  	   $(DISTNAME)/bzgrep.1 \
  	   $(DISTNAME)/Makefile-libbz2_so
  	gzip -v $(DISTNAME).tar
  
  # For rebuilding the manual from sources on my RedHat 7.2 box
! manual: bzip2.ps bzip2.html bzip2.pdf
  
! bzip2.ps: bzip2.texi
! 	tex bzip2.texi
! 	dvips -o bzip2.ps bzip2.dvi
  
! bzip2.pdf: bzip2.ps
! 	ps2pdf bzip2.ps
  
! bzip2.html: bzip2.texi
! 	perl ./djgpp/texi2html -expandinfo -verbose -monolithic bzip2.texi
diff -acprNC5 bzip2-1.0.2.orig/bzdiff bzip2-1.0.2.djgpp/bzdiff
*** bzip2-1.0.2.orig/bzdiff	Sun Dec 30 02:12:34 2001
--- bzip2-1.0.2.djgpp/bzdiff	Fri May 17 22:08:02 2002
***************
*** 10,20 ****
  # the  files  compared  are file1 and an uncompressed file1.gz.
  # If two files are specified, then they are  uncompressed  (if
  # necessary) and fed to cmp or diff.  The exit status from cmp
  # or diff is preserved.
  
! PATH="/usr/bin:$PATH"; export PATH
  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
    *cmp) comp=${CMP-cmp}   ;;
    *)    comp=${DIFF-diff} ;;
  esac
--- 10,31 ----
  # the  files  compared  are file1 and an uncompressed file1.gz.
  # If two files are specified, then they are  uncompressed  (if
  # necessary) and fed to cmp or diff.  The exit status from cmp
  # or diff is preserved.
  
! tmpdir=${TMPDIR-/tmp}
! if test ! -d "$tmpdir"; then
!   tmpdir=.
! fi
! 
! remove=/bin/rm
! pathsep=:
! if test -n "$DJGPP$djgpp"; then
!   remove=/dev/env/DJDIR/rm
!   pathsep=";"
! fi
! PATH="/dev/env/DJDIR/bin$pathsep$PATH"; export PATH
  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
    *cmp) comp=${CMP-cmp}   ;;
    *)    comp=${DIFF-diff} ;;
  esac
*************** do
*** 35,48 ****
  done
  if test -z "$FILES"; then
  	echo "Usage: $prog [${comp}_options] file [file]"
  	exit 1
  fi
! tmp=`tempfile -d /tmp -p bz` || {
!       echo 'cannot create a temporary file' >&2
!       exit 1
! }
  set $FILES
  if test $# -eq 1; then
  	FILE=`echo "$1" | sed 's/.bz2$//'`
  	bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
  	STAT="$?"
--- 46,56 ----
  done
  if test -z "$FILES"; then
  	echo "Usage: $prog [${comp}_options] file [file]"
  	exit 1
  fi
! tmp="$tmpdir/bz$$"
  set $FILES
  if test $# -eq 1; then
  	FILE=`echo "$1" | sed 's/.bz2$//'`
  	bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
  	STAT="$?"
*************** elif test $# -eq 2; then
*** 54,64 ****
  	        *.bz2)
  			F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
                          bzip2 -cdfq "$2" > $tmp
                          bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
                          STAT="$?"
! 			/bin/rm -f $tmp;;
  
                  *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
                          STAT="$?";;
                  esac;;
          *)      case "$2" in
--- 62,72 ----
  	        *.bz2)
  			F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
                          bzip2 -cdfq "$2" > $tmp
                          bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
                          STAT="$?"
! 			$remove -f $tmp;;
  
                  *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
                          STAT="$?";;
                  esac;;
          *)      case "$2" in
diff -acprNC5 bzip2-1.0.2.orig/bzgrep bzip2-1.0.2.djgpp/bzgrep
*** bzip2-1.0.2.orig/bzgrep	Sun Dec 30 02:12:34 2001
--- bzip2-1.0.2.djgpp/bzgrep	Fri May 17 22:08:02 2002
***************
*** 4,14 ****
  # adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
  ## zgrep notice:
  ## zgrep -- a wrapper around a grep program that decompresses files as needed
  ## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
  
! PATH="/usr/bin:$PATH"; export PATH
  
  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
  	*egrep)	grep=${EGREP-egrep}	;;
  	*fgrep)	grep=${FGREP-fgrep}	;;
--- 4,18 ----
  # adapted from zgrep by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
  ## zgrep notice:
  ## zgrep -- a wrapper around a grep program that decompresses files as needed
  ## Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
  
! pathsep=:
! if test -n "$DJGPP$djgpp"; then
!   pathsep=";"
! fi
! PATH="/dev/env/DJDIR/bin$pathsep$PATH"; export PATH
  
  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
  	*egrep)	grep=${EGREP-egrep}	;;
  	*fgrep)	grep=${FGREP-fgrep}	;;
diff -acprNC5 bzip2-1.0.2.orig/bzip2.1 bzip2-1.0.2.djgpp/bzip2.1
*** bzip2-1.0.2.orig/bzip2.1	Wed Jan  2 23:14:36 2002
--- bzip2-1.0.2.djgpp/bzip2.1	Mon May 20 22:40:50 2002
*************** bzcat \- decompresses files to stdout
*** 8,25 ****
  bzip2recover \- recovers data from damaged bzip2 files
  
  .SH SYNOPSIS
  .ll +8
  .B bzip2
! .RB [ " \-cdfkqstvzVL123456789 " ]
  [
  .I "filenames \&..."
  ]
  .ll -8
  .br
  .B bunzip2
! .RB [ " \-fkvsVL " ]
  [ 
  .I "filenames \&..."
  ]
  .br
  .B bzcat
--- 8,25 ----
  bzip2recover \- recovers data from damaged bzip2 files
  
  .SH SYNOPSIS
  .ll +8
  .B bzip2
! .RB [ " \-cdfknqstvzVL123456789 " ]
  [
  .I "filenames \&..."
  ]
  .ll -8
  .br
  .B bunzip2
! .RB [ " \-fknvsVL " ]
  [ 
  .I "filenames \&..."
  ]
  .br
  .B bzcat
*************** complains that it cannot
*** 100,109 ****
--- 100,171 ----
  guess the name of the original file, and uses the original name
  with
  .I .out
  appended.
  
+ The above applies also to the DJGPP port of
+ .I bzip2
+ when LFN support is avaliable.
+ If LFN support is not available (plain DOS and WIN9X with LFN=n) the file name
+ and the extension will not be properly preserved at the same time.
+ This port offers the user the choice between two rules to create the name of the
+ compressed file. The first rule (default) will preserve the file name at the cost
+ of truncating the extension. The second rule will preserve the extension and truncate
+ the file name. The different rules are selected by omitting or setting the
+ .I \-n
+ flag.
+ 
+ Rule 1: file name preserving and extension truncating.
+ This is the default rule. If the
+ .I \-n
+ flag is omitted then this rule will be used.
+ With this rule the following types of file names will be created:
+ 
+ When compressing:
+        filename       becomes   filename.bz2
+        filename.e     becomes   filename.ebz
+        filename.ex    becomes   filename.exb
+        filename.ext   becomes   filename.exb
+        filename.tar   becomes   filename.tbz
+ 
+ When decompressing:
+        filename.bz2   becomes   filename
+        filename.b     becomes   filename
+        filename.ebz   becomes   filename.e
+        filename.exb   becomes   filename.ex
+        filename.tbz   becomes   filename.tar
+        anyothername   becomes   anyothername.out
+ 
+ Rule 2: file name truncating and extension preserving.
+ This rule must be explicity enabled by setting the
+ .I \-n
+ flag.
+ With this rule backward compatibility with other MSDOS ports of
+ .I bzip2
+ is achieved.
+ With this rule the following types of file names will be created:
+ 
+ When compressing:
+        filename       becomes   filename.bz2
+        filename.e     becomes   filena_e.bz2
+        filename.ex    becomes   filen_ex.bz2
+        filename.ext   becomes   file_ext.bz2
+        filename.tar   becomes   filename.tbz
+ 
+ When decompressing:
+        filename.bz2   becomes   filename
+        filena_e.bz2   becomes   filena.e
+        filen_ex.bz2   becomes   filen.ex
+        file_ext.bz2   becomes   file.ext
+        filename.tbz   becomes   filename.tar
+        anyothername   becomes   anyothername.out
+ 
+ The same rule must be used for compression and decompression.
+ The
+ .I \-n
+ flag is ignored on WIN9X with LFN=y.
+ 
  As with compression, supplying no
  filenames causes decompression from 
  standard input to standard output.
  
  .I bunzip2 
*************** with a dash, for example: bzip2 \-- \-my
*** 259,268 ****
--- 321,349 ----
  .B \--repetitive-fast --repetitive-best
  These flags are redundant in versions 0.9.5 and above.  They provided
  some coarse control over the behaviour of the sorting algorithm in
  earlier versions, which was sometimes useful.  0.9.5 and above have an
  improved algorithm which renders these flags irrelevant.
+ .TP
+ .B \-n
+ This flag is only available for DJGPP ports of
+ .I bzip2
+ on plain DOS and WIN9X with LFN=n and is ignored on WIN9X with LFN=y.
+ This flag selects one of two rules to create the name of the compressed
+ file. If this flag is omitted then rule 1 will be used. Rule 1 preserves
+ the original file name and truncates the extension. If the extension has
+ the length of one character a 
+ .I bz
+ will be added to the extension. If the extension has two characters a
+ .I b
+ character will be added to the extension else the third character of
+ the extension will be overwritten with a
+ .I b
+ character.
+ If the flag is set then rule 2 will be used. Rule 2 stores
+ the extension truncating the original file name.
+ The same rule must be used for compression and decompression.
  
  .SH MEMORY MANAGEMENT
  .I bzip2 
  compresses large files in blocks.  The block size affects
  both the compression ratio achieved, and the amount of memory needed for
*************** futile to use it on damaged single-block
*** 374,383 ****
--- 455,472 ----
  damaged  block  cannot  be recovered.  If you wish to minimise 
  any potential data loss through media  or  transmission errors, 
  you might consider compressing with a smaller
  block size.
  
+ For the DJGPP port of
+ .I bzip2recover
+ the following applies:
+ If LFN support is available the output file names will be of the same form
+ as above described. If LFN support is not available then "rec0001file" will
+ become "r0001file", etc. If the file has no extension then an ".bz2" extension
+ will be added, else the original extension will be retained.
+ 
  .SH PERFORMANCE NOTES
  The sorting phase of compression gathers together similar strings in the
  file.  Because of this, files containing very long runs of repeated
  symbols, like "aabaabaabaab ..."  (repeated several hundred times) may
  compress more slowly than normal.  Versions 0.9.5 and above fare much
diff -acprNC5 bzip2-1.0.2.orig/bzip2.c bzip2-1.0.2.djgpp/bzip2.c
*** bzip2-1.0.2.orig/bzip2.c	Fri Jan 25 01:38:36 2002
--- bzip2-1.0.2.djgpp/bzip2.c	Mon May 20 22:23:50 2002
***************
*** 116,125 ****
--- 116,136 ----
    This is the default.
  --*/
  #define BZ_UNIX      1
  
  /*--
+   DJGPP supports DOS and Win32 environments.
+   The actual OS is determinated at run time.
+ --*/
+ #define BZ_DOS       0
+ 
+ #if defined(__DJGPP__)
+ #undef  BZ_DOS
+ #define BZ_DOS 1
+ #endif
+ 
+ /*--
    Win32, as seen by Jacob Navia's excellent
    port of (Chris Fraser & David Hanson)'s excellent
    lcc compiler.  Or with MS Visual C.
    This is selected automatically if compiled by a compiler which
    defines _WIN32, not including the Cygwin GCC.
***************
*** 164,178 ****
  #   include <utime.h>
  #   include <unistd.h>
  #   include <sys/stat.h>
  #   include <sys/times.h>
  
! #   define PATH_SEP    '/'
! #   define MY_LSTAT    lstat
! #   define MY_STAT     stat
! #   define MY_S_ISREG  S_ISREG
! #   define MY_S_ISDIR  S_ISDIR
  
  #   define APPEND_FILESPEC(root, name) \
        root=snocString((root), (name))
  
  #   define APPEND_FLAG(root, name) \
--- 175,191 ----
  #   include <utime.h>
  #   include <unistd.h>
  #   include <sys/stat.h>
  #   include <sys/times.h>
  
! #   define HAVE_SIGBUS    1
! #   define IS_PATH_SEP(c) ((c) == '/')
! #   define MY_LSTAT       lstat
! #   define MY_STAT        stat
! #   define MY_S_ISREG     S_ISREG
! #   define MY_S_ISDIR     S_ISDIR
! #   define MY_STDOUT      stderr
  
  #   define APPEND_FILESPEC(root, name) \
        root=snocString((root), (name))
  
  #   define APPEND_FLAG(root, name) \
***************
*** 187,212 ****
  #   endif
  
  #   ifdef __DJGPP__
  #     include <io.h>
  #     include <fcntl.h>
! #     undef MY_LSTAT
  #     undef MY_STAT
- #     define MY_LSTAT stat
  #     define MY_STAT stat
! #     undef SET_BINARY_MODE
! #     define SET_BINARY_MODE(fd)                        \
          do {                                            \
!            int retVal = setmode ( fileno ( fd ),        \
!                                   O_BINARY );           \
!            ERROR_IF_MINUS_ONE ( retVal );               \
          } while ( 0 )
  #   endif
  
  #   ifdef __CYGWIN__
  #     include <io.h>
  #     include <fcntl.h>
  #     undef SET_BINARY_MODE
  #     define SET_BINARY_MODE(fd)                        \
          do {                                            \
             int retVal = setmode ( fileno ( fd ),        \
                                    O_BINARY );           \
--- 200,243 ----
  #   endif
  
  #   ifdef __DJGPP__
  #     include <io.h>
  #     include <fcntl.h>
! #     undef  HAVE_SIGBUS
! #     define HAVE_SIGBUS            0
! #     undef  IS_PATH_SEP
! #     define IS_PATH_SEP(c)         ((c) == '/' || (c) == '\\' || (c) == ':')
! #     define IS_EXTENSION(name)     (strchr ((name), '.') != NULL)
! #     define IS_TAR_EXTENSION(name) (strstr ((name), ".tar") != NULL)
! #     define NO_LFN_SUPPORT(name)   (pathconf ((name), _PC_NAME_MAX) <= 12)
! #     ifndef S_ISLNK
! #       undef  MY_LSTAT
! #       define MY_LSTAT     stat
! #     endif
  #     undef MY_STAT
  #     define MY_STAT stat
! #     undef MY_STDOUT
! #     define MY_STDOUT stdout
! #     if (defined(O_BINARY) != 0)
! #       undef  SET_BINARY_MODE
! #       define SET_BINARY_MODE(fd)                      \
          do {                                            \
!            if ( !isatty ( fileno ( fd ) ) )             \
!            {                                            \
!              int retVal = setmode ( fileno ( fd ),      \
!                                    O_BINARY );          \
!              ERROR_IF_MINUS_ONE ( retVal );             \
!            }                                            \
          } while ( 0 )
+ #     endif
  #   endif
  
  #   ifdef __CYGWIN__
  #     include <io.h>
  #     include <fcntl.h>
+ #     undef MY_STDOUT
+ #     define MY_STDOUT stdout
  #     undef SET_BINARY_MODE
  #     define SET_BINARY_MODE(fd)                        \
          do {                                            \
             int retVal = setmode ( fileno ( fd ),        \
                                    O_BINARY );           \
***************
*** 221,235 ****
  #   include <io.h>
  #   include <fcntl.h>
  #   include <sys\stat.h>
  
  #   define NORETURN       /**/
! #   define PATH_SEP       '\\'
  #   define MY_LSTAT       _stat
  #   define MY_STAT        _stat
  #   define MY_S_ISREG(x)  ((x) & _S_IFREG)
  #   define MY_S_ISDIR(x)  ((x) & _S_IFDIR)
  
  #   define APPEND_FLAG(root, name) \
        root=snocString((root), (name))
  
  #   define APPEND_FILESPEC(root, name)                \
--- 252,268 ----
  #   include <io.h>
  #   include <fcntl.h>
  #   include <sys\stat.h>
  
  #   define NORETURN       /**/
! #   define HAVE_SIGBUS    1
! #   define IS_PATH_SEP(c) ((c) == '\\')
  #   define MY_LSTAT       _stat
  #   define MY_STAT        _stat
  #   define MY_S_ISREG(x)  ((x) & _S_IFREG)
  #   define MY_S_ISDIR(x)  ((x) & _S_IFDIR)
+ #   define MY_STDOUT      stdout
  
  #   define APPEND_FLAG(root, name) \
        root=snocString((root), (name))
  
  #   define APPEND_FILESPEC(root, name)                \
*************** Char    outName[FILE_NAME_LEN];
*** 299,317 ****
--- 332,354 ----
  Char    tmpName[FILE_NAME_LEN];
  Char    *progName;
  Char    progNameReally[FILE_NAME_LEN];
  FILE    *outputHandleJustInCase;
  Int32   workFactor;
+ #ifdef BZ_DOS
+ Bool    dosFileNameRule1;
+ #endif
  
  static void    panic                 ( Char* )   NORETURN;
  static void    ioError               ( void )    NORETURN;
  static void    outOfMemory           ( void )    NORETURN;
  static void    configError           ( void )    NORETURN;
  static void    crcError              ( void )    NORETURN;
  static void    cleanUpAndFail        ( Int32 )   NORETURN;
  static void    compressedStreamEOF   ( void )    NORETURN;
  
+ static void    addBZ2Suffix ( Char* );
  static void    copyFileName ( Char*, Char* );
  static void*   myMalloc     ( Int32 );
  
  
  
*************** void copyFileName ( Char* to, Char* from
*** 1014,1023 ****
--- 1051,1124 ----
  }
  
  
  /*---------------------------------------------*/
  static 
+ void addBZ2Suffix ( Char* name )
+ {
+ #if BZ_DOS
+    if (NO_LFN_SUPPORT ( name ))
+    {
+      /* DJGPP detects at run time if a LFN-API (win32) is available or not (plain dos).
+         MSDOS 8.3 filename restriction.
+      */
+ 
+      Char* fileName = basename ( name );
+      if (IS_EXTENSION ( fileName ))
+      {
+        IntNative extStart = (IntNative)( strchr ( fileName, '.' ) - fileName );
+        if (IS_TAR_EXTENSION ( &fileName[extStart] ))
+          strcpy ( &fileName[extStart], ".tbz" );
+        else
+        {
+          /* File has extension but not tar extension. */
+ 
+          IntNative extLen = strlen ( &fileName[extStart] );
+          if (dosFileNameRule1 == True)
+          {
+            /*----------------------------------------------*/
+            /*---   Output file name rule 1 (default):   ---*/
+            /*---   filename.ext -> filename.exb         ---*/
+            /*----------------------------------------------*/
+            extLen--;
+            switch (extLen) {
+               case 1:
+                  strcat ( fileName, "bz" ); break;
+               case 2:
+                  strcat ( fileName, "b" );  break;
+               default:
+                  fileName[extStart + 3] = 'b'; break;
+            }
+          }
+          else
+          {
+            /*-------------------------------------------------------------*/
+            /*---   Output file name rule 2 (selected with flag: -n):   ---*/
+            /*---   filename.ext -> file_ext.bz2                        ---*/
+            /*-------------------------------------------------------------*/
+ 
+            IntNative fileNameLen = extStart;
+            fileName[extStart] = '_';
+            if (fileNameLen + extLen > 8)
+              strcpy ( &fileName[8 - extLen], &fileName[extStart] );
+            strcat ( fileName, ".bz2" );
+          }
+        }
+      }
+      else
+        /* no extension at all. */
+        strcat ( fileName, ".bz2" );
+    }
+    else
+      /* no filename restriction. */
+ #endif  /* ! BZ_DOS */
+      strcat ( name, ".bz2" ); 
+ }
+ 
+ 
+ /*---------------------------------------------*/
+ static 
  Bool fileExists ( Char* name )
  {
     FILE *tmp   = fopen ( name, "rb" );
     Bool exists = (tmp != NULL);
     if (tmp != NULL) fclose ( tmp );
*************** void applySavedMetaInfoToOutputFile ( Ch
*** 1150,1160 ****
  
  /*---------------------------------------------*/
  static 
  Bool containsDubiousChars ( Char* name )
  {
! #  if BZ_UNIX
     /* On unix, files can contain any characters and the file expansion
      * is performed by the shell.
      */
     return False;
  #  else /* ! BZ_UNIX */
--- 1251,1261 ----
  
  /*---------------------------------------------*/
  static 
  Bool containsDubiousChars ( Char* name )
  {
! #  if defined(BZ_UNIX) && !defined(BZ_DOS)
     /* On unix, files can contain any characters and the file expansion
      * is performed by the shell.
      */
     return False;
  #  else /* ! BZ_UNIX */
*************** void compress ( Char *name )
*** 1217,1227 ****
           copyFileName ( outName, "(stdout)" ); 
           break;
        case SM_F2F: 
           copyFileName ( inName, name );
           copyFileName ( outName, name );
!          strcat ( outName, ".bz2" ); 
           break;
        case SM_F2O: 
           copyFileName ( inName, name );
           copyFileName ( outName, "(stdout)" ); 
           break;
--- 1318,1328 ----
           copyFileName ( outName, "(stdout)" ); 
           break;
        case SM_F2F: 
           copyFileName ( inName, name );
           copyFileName ( outName, name );
!          addBZ2Suffix ( outName ); 
           break;
        case SM_F2O: 
           copyFileName ( inName, name );
           copyFileName ( outName, "(stdout)" ); 
           break;
*************** void uncompress ( Char *name )
*** 1402,1413 ****
           break;
        case SM_F2F: 
           copyFileName ( inName, name );
           copyFileName ( outName, name );
           for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
!             if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
!                goto zzz; 
           cantGuess = True;
           strcat ( outName, ".out" );
           break;
        case SM_F2O: 
           copyFileName ( inName, name );
--- 1503,1561 ----
           break;
        case SM_F2F: 
           copyFileName ( inName, name );
           copyFileName ( outName, name );
           for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
!          {
!            if (mapSuffix ( outName,zSuffix[i], unzSuffix[i] )) /* Test for extensions: .bz2, .tbz2, .bz, .tbz */
!            {
!              if (NO_LFN_SUPPORT ( outName ))  /* MSDOS 8.3 filename restriction */
!              {
!                if (dosFileNameRule1 == False)
!                {
!                  /*-------------------------------------------------------------*/
!                  /*---   Output file name rule 2 (selected with flag: -n):   ---*/
!                  /*---   file_ext.bz2 -> file.ext                            ---*/
!                  /*-------------------------------------------------------------*/
! 
!                  Char* fileName = basename ( outName );
!                  if (!IS_TAR_EXTENSION ( fileName ))
!                  {
!                    Char* dot = strrchr ( fileName, '_' );
!                    if (dot && strlen ( dot ) <= 4)
!                      *dot = '.';
!                  }
!                }
!              }
!              goto zzz;
!            }
!            else /* If and only if DOS or WIN9X(LFN=n) is used, test for extensions: .xbz, .xxb. x= any character. */
!            {
!              if (NO_LFN_SUPPORT ( outName ))  /* MSDOS 8.3 filename restriction */
!              {
!                if (dosFileNameRule1 == True)
!                {
!                  /*----------------------------------------------*/
!                  /*---   Output file name rule 1 (default):   ---*/
!                  /*---   filename.exb -> filename.ex          ---*/
!                  /*----------------------------------------------*/
! 
!                  Char* fileName = basename ( outName );
!                  if (IS_EXTENSION ( fileName ))
!                  {
!                    register IntNative extEnd = strlen ( fileName );
!                    for (; extEnd; --extEnd)
!                      if (fileName[extEnd] == 'b')
!                      {
!                        fileName[extEnd] = '\0';
!                        goto zzz;
!                      }
!                  }
!                }
!              }
!            }
!          }
           cantGuess = True;
           strcat ( outName, ".out" );
           break;
        case SM_F2O: 
           copyFileName ( inName, name );
*************** void testf ( Char *name )
*** 1667,1677 ****
  
  /*---------------------------------------------*/
  static 
  void license ( void )
  {
!    fprintf ( stderr,
  
      "bzip2, a block-sorting file compressor.  "
      "Version %s.\n"
      "   \n"
      "   Copyright (C) 1996-2002 by Julian Seward.\n"
--- 1815,1825 ----
  
  /*---------------------------------------------*/
  static 
  void license ( void )
  {
!    fprintf ( MY_STDOUT,
  
      "bzip2, a block-sorting file compressor.  "
      "Version %s.\n"
      "   \n"
      "   Copyright (C) 1996-2002 by Julian Seward.\n"
*************** void license ( void )
*** 1693,1703 ****
  /*---------------------------------------------*/
  static 
  void usage ( Char *fullProgName )
  {
     fprintf (
!       stderr,
        "bzip2, a block-sorting file compressor.  "
        "Version %s.\n"
        "\n   usage: %s [flags and input files in any order]\n"
        "\n"
        "   -h --help           print this message\n"
--- 1841,1851 ----
  /*---------------------------------------------*/
  static 
  void usage ( Char *fullProgName )
  {
     fprintf (
!       MY_STDOUT,
        "bzip2, a block-sorting file compressor.  "
        "Version %s.\n"
        "\n   usage: %s [flags and input files in any order]\n"
        "\n"
        "   -h --help           print this message\n"
*************** void usage ( Char *fullProgName )
*** 1708,1717 ****
--- 1856,1873 ----
        "   -t --test           test compressed file integrity\n"
        "   -c --stdout         output to standard out\n"
        "   -q --quiet          suppress noncritical error messages\n"
        "   -v --verbose        be verbose (a 2nd -v gives more)\n"
        "   -L --license        display software version & license\n"
+ #ifdef BZ_DOS
+       "   -n                  select output file name rule 2.\n"
+       "                       rule 1: filename preserved, extension truncated.\n"
+       "                       default is output file name rule 1.\n"
+       "                       rule 2: filename truncated, extension preserved.\n"
+       "                       This flag is only available on plain DOS\n"
+       "                       and WIN9X with LFN=n.\n"
+ #endif
        "   -V --version        display software version & license\n"
        "   -s --small          use less memory (at most 2500k)\n"
        "   -1 .. -9            set block size to 100k .. 900k\n"
        "   --fast              alias for -1\n"
        "   --best              alias for -9\n"
*************** IntNative main ( IntNative argc, Char *a
*** 1869,1895 ****
     numFileNames            = 0;
     numFilesProcessed       = 0;
     workFactor              = 30;
     deleteOutputOnInterrupt = False;
     exitValue               = 0;
     i = j = 0; /* avoid bogus warning from egcs-1.1.X */
  
     /*-- Set up signal handlers for mem access errors --*/
     signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
  #  if BZ_UNIX
! #  ifndef __DJGPP__
     signal (SIGBUS,  mySIGSEGVorSIGBUScatcher);
  #  endif
  #  endif
  
     copyFileName ( inName,  "(none)" );
     copyFileName ( outName, "(none)" );
  
     copyFileName ( progNameReally, argv[0] );
     progName = &progNameReally[0];
     for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
!       if (*tmp == PATH_SEP) progName = tmp + 1;
  
  
     /*-- Copy flags from env var BZIP2, and 
          expand filename wildcards in arg list.
     --*/
--- 2025,2054 ----
     numFileNames            = 0;
     numFilesProcessed       = 0;
     workFactor              = 30;
     deleteOutputOnInterrupt = False;
     exitValue               = 0;
+ #ifdef BZ_DOS
+    dosFileNameRule1        = True; /* On MSDOS default to output file name rule 1. */
+ #endif
     i = j = 0; /* avoid bogus warning from egcs-1.1.X */
  
     /*-- Set up signal handlers for mem access errors --*/
     signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
  #  if BZ_UNIX
! #  if HAVE_SIGBUS
     signal (SIGBUS,  mySIGSEGVorSIGBUScatcher);
  #  endif
  #  endif
  
     copyFileName ( inName,  "(none)" );
     copyFileName ( outName, "(none)" );
  
     copyFileName ( progNameReally, argv[0] );
     progName = &progNameReally[0];
     for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
!       if (IS_PATH_SEP ( *tmp )) progName = tmp + 1;
  
  
     /*-- Copy flags from env var BZIP2, and 
          expand filename wildcards in arg list.
     --*/
*************** IntNative main ( IntNative argc, Char *a
*** 1956,1965 ****
--- 2115,2127 ----
                 case '5': blockSize100k    = 5; break;
                 case '6': blockSize100k    = 6; break;
                 case '7': blockSize100k    = 7; break;
                 case '8': blockSize100k    = 8; break;
                 case '9': blockSize100k    = 9; break;
+ #ifdef BZ_DOS
+                case 'n': dosFileNameRule1 = False; break;
+ #endif
                 case 'V':
                 case 'L': license();            break;
                 case 'v': verbosity++; break;
                 case 'h': usage ( progName );
                           exit ( 0 );
diff -acprNC5 bzip2-1.0.2.orig/bzip2.texi bzip2-1.0.2.djgpp/bzip2.texi
*** bzip2-1.0.2.orig/bzip2.texi	Sat Jan  5 00:52:50 2002
--- bzip2-1.0.2.djgpp/bzip2.texi	Mon May 20 22:40:48 2002
*************** END-INFO-DIR-ENTRY
*** 44,54 ****
  
  The following text is the License for this software.  You should
  find it identical to that contained in the file LICENSE in the 
  source distribution.
  
! @bf{------------------ START OF THE LICENSE ------------------}
  
  This program, @code{bzip2}, 
  and associated library @code{libbzip2}, are
  Copyright (C) 1996-2002 Julian R Seward.  All rights reserved.
  
--- 44,54 ----
  
  The following text is the License for this software.  You should
  find it identical to that contained in the file LICENSE in the 
  source distribution.
  
! @c @bf{------------------ START OF THE LICENSE ------------------}
  
  This program, @code{bzip2}, 
  and associated library @code{libbzip2}, are
  Copyright (C) 1996-2002 Julian R Seward.  All rights reserved.
  
*************** Julian Seward, Cambridge, UK.
*** 88,98 ****
  
  @code{jseward@@acm.org}
  
  @code{bzip2}/@code{libbzip2} version 1.0.2 of 30 December 2001.
  
! @bf{------------------ END OF THE LICENSE ------------------}
  
  Web sites:
  
  @code{http://sources.redhat.com/bzip2}
  
--- 88,98 ----
  
  @code{jseward@@acm.org}
  
  @code{bzip2}/@code{libbzip2} version 1.0.2 of 30 December 2001.
  
! @c @bf{------------------ END OF THE LICENSE ------------------}
  
  Web sites:
  
  @code{http://sources.redhat.com/bzip2}
  
*************** This chapter contains a copy of the @cod
*** 137,159 ****
  and nothing else.
  
  @quotation
  
  @unnumberedsubsubsec NAME
! @itemize
  @item @code{bzip2}, @code{bunzip2}
! - a block-sorting file compressor, v1.0.2
  @item @code{bzcat} 
! - decompresses files to stdout
  @item @code{bzip2recover}
! - recovers data from damaged bzip2 files
  @end itemize
  
  @unnumberedsubsubsec SYNOPSIS
! @itemize
! @item @code{bzip2} [ -cdfkqstvzVL123456789 ] [ filenames ...  ]
! @item @code{bunzip2} [ -fkvsVL ] [ filenames ...  ]
  @item @code{bzcat} [ -s ] [ filenames ...  ]
  @item @code{bzip2recover} filename
  @end itemize
  
  @unnumberedsubsubsec DESCRIPTION
--- 137,159 ----
  and nothing else.
  
  @quotation
  
  @unnumberedsubsubsec NAME
! @itemize @minus
  @item @code{bzip2}, @code{bunzip2}
! a block-sorting file compressor, v1.0.2
  @item @code{bzcat} 
! decompresses files to stdout
  @item @code{bzip2recover}
! recovers data from damaged bzip2 files
  @end itemize
  
  @unnumberedsubsubsec SYNOPSIS
! @itemize @minus
! @item @code{bzip2} [ -cdfknqstvzVL123456789 ] [ filenames ...  ]
! @item @code{bunzip2} [ -fknvsVL ] [ filenames ...  ]
  @item @code{bzcat} [ -s ] [ filenames ...  ]
  @item @code{bzip2recover} filename
  @end itemize
  
  @unnumberedsubsubsec DESCRIPTION
*************** incomprehensible and therefore pointless
*** 188,210 ****
  @code{bunzip2} (or @code{bzip2 -d}) decompresses all
  specified files.  Files which were not created by @code{bzip2}
  will be detected and ignored, and a warning issued.  
  @code{bzip2} attempts to guess the filename for the decompressed file 
  from that of the compressed file as follows:
! @itemize
  @item @code{filename.bz2 } becomes @code{filename}
  @item @code{filename.bz  } becomes @code{filename}
  @item @code{filename.tbz2} becomes @code{filename.tar}
  @item @code{filename.tbz } becomes @code{filename.tar}
  @item @code{anyothername } becomes @code{anyothername.out}
  @end itemize
  If the file does not end in one of the recognised endings, 
  @code{.bz2}, @code{.bz}, 
  @code{.tbz2} or @code{.tbz}, @code{bzip2} complains that it cannot
  guess the name of the original file, and uses the original name
  with @code{.out} appended.
  
  As with compression, supplying no
  filenames causes decompression from standard input to standard output.
  
  @code{bunzip2} will correctly decompress a file which is the
  concatenation of two or more compressed files.  The result is the
--- 188,269 ----
  @code{bunzip2} (or @code{bzip2 -d}) decompresses all
  specified files.  Files which were not created by @code{bzip2}
  will be detected and ignored, and a warning issued.  
  @code{bzip2} attempts to guess the filename for the decompressed file 
  from that of the compressed file as follows:
! @itemize @bullet
  @item @code{filename.bz2 } becomes @code{filename}
  @item @code{filename.bz  } becomes @code{filename}
  @item @code{filename.tbz2} becomes @code{filename.tar}
  @item @code{filename.tbz } becomes @code{filename.tar}
  @item @code{anyothername } becomes @code{anyothername.out}
  @end itemize
+ 
  If the file does not end in one of the recognised endings, 
  @code{.bz2}, @code{.bz}, 
  @code{.tbz2} or @code{.tbz}, @code{bzip2} complains that it cannot
  guess the name of the original file, and uses the original name
  with @code{.out} appended.
  
+ The above applies also to the DJGPP port of @code{bzip2} when LFN support is avaliable.
+ If LFN support is not available (plain DOS and WIN9X with @code{LFN=n}) the file name
+ and the extension will not be properly preserved at the same time.
+ This port offers the user the choice between two rules to create the name of the
+ compressed file. The first rule (default) will preserve the filename at the cost
+ of truncating the extension. The second rule will preserve the extension and truncate
+ the file name. The different rules are selected by omitting or setting the @code{-n} flag.
+ 
+ Rule 1: file name preserving and extension truncating.
+ This is the default rule. If the @code{-n} flag is omitted then this rule will be used.
+ With this rule the following types of file names will be created:
+ 
+ When compressing:
+ @itemize @bullet
+ @item @code{filename    } becomes @code{filename.bz2}
+ @item @code{filename.e  } becomes @code{filename.ebz}
+ @item @code{filename.ex } becomes @code{filename.exb}
+ @item @code{filename.ext} becomes @code{filename.exb}
+ @item @code{filename.tar} becomes @code{filename.tbz}
+ @end itemize
+ 
+ When decompressing:
+ @itemize @bullet
+ @item @code{filename.bz2} becomes @code{filename}
+ @item @code{filename.b  } becomes @code{filename}
+ @item @code{filename.ebz} becomes @code{filename.e}
+ @item @code{filename.exb} becomes @code{filename.ex}
+ @item @code{filename.tbz} becomes @code{filename.tar}
+ @item @code{anyothername} becomes @code{anyothername.out}
+ @end itemize
+ 
+ Rule 2: file name truncating and extension preserving.
+ This rule must be explicity enabled by setting the @code{-n} flag.
+ With this rule backward compatibility with other MSDOS ports of
+ @code{bzip2} is achieved.
+ With this rule the following types of file names will be created:
+ When compressing:
+ @itemize @bullet
+ @item @code{filename    } becomes @code{filename.bz2}
+ @item @code{filename.e  } becomes @code{filena_e.bz2}
+ @item @code{filename.ex } becomes @code{filen_ex.bz2}
+ @item @code{filename.ext} becomes @code{file_ext.bz2}
+ @item @code{filename.tar} becomes @code{filename.tbz}
+ @end itemize
+ 
+ When decompressing:
+ @itemize @bullet
+ @item @code{filename.bz2} becomes @code{filename}
+ @item @code{filena_e.bz2} becomes @code{filena.e}
+ @item @code{filen_ex.bz2} becomes @code{filen.ex}
+ @item @code{file_ext.bz2} becomes @code{file.ext}
+ @item @code{filename.tbz} becomes @code{filename.tar}
+ @item @code{anyothername} becomes @code{anyothername.out}
+ @end itemize
+ 
+ The same rule must be used for compression and decompression.
+ The @code{-n} flag is ignored on WIN9X with @code{LFN=y}.
+ 
  As with compression, supplying no
  filenames causes decompression from standard input to standard output.
  
  @code{bunzip2} will correctly decompress a file which is the
  concatenation of two or more compressed files.  The result is the
*************** with a dash, for example: @code{bzip2 --
*** 313,322 ****
--- 372,394 ----
  @item --repetitive-best
  These flags are redundant in versions 0.9.5 and above.  They provided
  some coarse control over the behaviour of the sorting algorithm in
  earlier versions, which was sometimes useful.  0.9.5 and above have an
  improved algorithm which renders these flags irrelevant.
+ @item -n
+ This flag is only available for DJGPP ports of @code{bzip2} on plain
+ DOS and WIN9X with @code{LFN=n} and is ignored on WIN9X with @code{LFN=y}.
+ This flag selects one of two rules to create the name of the compressed
+ file.  If this flag is omitted then rule 1 will be used.  Rule 1 preserves
+ the original file name and truncates the extension.  If the extension has
+ the length of one character a @code{bz} will be added to the extension.
+ If the extension has two characters a @code{b} character will be added
+ to the extension else the third character of the extension will be
+ overwritten with a @code{b} character.
+ If the flag is set then rule 2 will be used. Rule 2 stores the extension
+ truncating the original file name.
+ The same rule must be used for compression and decompression.
  @end table
  
  
  @unnumberedsubsubsec MEMORY MANAGEMENT
  
*************** files, as these will contain many blocks
*** 417,426 ****
--- 489,505 ----
  it on damaged single-block files, since a damaged block cannot be
  recovered.  If you wish to minimise any potential data loss through
  media or transmission errors, you might consider compressing with a
  smaller block size.
  
+ For the DJGPP port of @code{bzip2recover} the following applies:
+ 
+ If LFN support is available the output file names will be of the same form as
+ above described. If LFN support is not available then @file{rec0001file} will
+ become @file{r0001file}, etc. If the file has no extension then an @code{.bz2} extension
+ will be added, else the original extension will be preserved.
+ 
  
  @unnumberedsubsubsec PERFORMANCE NOTES
  
  The sorting phase of compression gathers together similar strings in the
  file.  Because of this, files containing very long runs of repeated
*************** This interface provides functions for re
*** 1195,1205 ****
  @subsection @code{BZ2_bzReadOpen}
  @example
     typedef void BZFILE;
  
     BZFILE *BZ2_bzReadOpen ( int *bzerror, FILE *f, 
!                             int small, int verbosity,
                              void *unused, int nUnused );
  @end example
  Prepare to read compressed data from file handle @code{f}.  @code{f}
  should refer to a file which has been opened for reading, and for which
  the error indicator (@code{ferror(f)})is not set.  If @code{small} is 1,
--- 1274,1284 ----
  @subsection @code{BZ2_bzReadOpen}
  @example
     typedef void BZFILE;
  
     BZFILE *BZ2_bzReadOpen ( int *bzerror, FILE *f, 
!                             int verbosity, int small,
                              void *unused, int nUnused );
  @end example
  Prepare to read compressed data from file handle @code{f}.  @code{f}
  should refer to a file which has been opened for reading, and for which
  the error indicator (@code{ferror(f)})is not set.  If @code{small} is 1,
*************** int     nWritten;
*** 1591,1601 ****
  
  f = fopen ( "myfile.bz2", "r" );
  if (!f) @{
     /* handle error */
  @}
! b = BZ2_bzReadOpen ( &bzerror, f, 0, NULL, 0 );
  if (bzerror != BZ_OK) @{
     BZ2_bzReadClose ( &bzerror, b );
     /* handle error */
  @}
  
--- 1670,1680 ----
  
  f = fopen ( "myfile.bz2", "r" );
  if (!f) @{
     /* handle error */
  @}
! b = BZ2_bzReadOpen ( &bzerror, f, 0, 0,NULL, 0 );
  if (bzerror != BZ_OK) @{
     BZ2_bzReadClose ( &bzerror, b );
     /* handle error */
  @}
  
*************** if (bzerror != BZ_STREAM_END) @{
*** 1611,1620 ****
--- 1690,1701 ----
     /* handle error */
  @} else @{
     BZ2_bzReadClose ( &bzerror );
  @}
  @end example
+ On MS-DOS/WIN9X systems all fopen calls must be done in binary mode,
+ so substitute the "r" and "w" parameter in the examples above by "rb" and "wb" accordingly.
  
  
  
  @section Utility functions
  @subsection @code{BZ2_bzBuffToBuffCompress}
diff -acprNC5 bzip2-1.0.2.orig/bzip2recover.c bzip2-1.0.2.djgpp/bzip2recover.c
*** bzip2-1.0.2.orig/bzip2recover.c	Sat Jan  5 12:40:38 2002
--- bzip2-1.0.2.djgpp/bzip2recover.c	Mon May 20 22:39:44 2002
***************
*** 54,63 ****
--- 54,66 ----
  
  #include <stdio.h>
  #include <errno.h>
  #include <stdlib.h>
  #include <string.h>
+ #ifdef __DJGPP__
+ #  include <unistd.h>
+ #endif
  
  
  /* This program records bit locations in the file to be recovered.
     That means that if 64-bit ints are not supported, we will not
     be able to recover .bz2 files over 512MB (2^32 bits) long.
*************** Char outFileName[BZ_MAX_FILENAME];
*** 96,105 ****
--- 99,116 ----
  Char progName[BZ_MAX_FILENAME];
  
  MaybeUInt64 bytesOut = 0;
  MaybeUInt64 bytesIn  = 0;
  
+ #define IS_DIR_SEPARATOR(c) ((c) == '/')
+ #ifdef __DJGPP__
+ #  undef  IS_DIR_SEPARATOR
+ #  define IS_DIR_SEPARATOR(c)    ((c) == '/' || (c) == '\\' || (c) == ':')
+ #  define NO_LFN_SUPPORT(name)   (pathconf ((name), _PC_NAME_MAX) <= 12)
+ #  define HAS_NO_EXTENSION(name) (strrchr ((name), '.') == NULL)
+ #endif
+ 
  
  /*---------------------------------------------------*/
  /*--- Header bytes                                ---*/
  /*---------------------------------------------------*/
  
*************** Int32 bsGetBit ( BitStream* bs )
*** 232,242 ****
  {
     if (bs->buffLive > 0) {
        bs->buffLive --;
        return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
     } else {
!       Int32 retVal = getc ( bs->handle );
        if ( retVal == EOF ) {
           if (errno != 0) readError();
           return 2;
        }
        bs->buffLive = 7;
--- 243,255 ----
  {
     if (bs->buffLive > 0) {
        bs->buffLive --;
        return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
     } else {
!       Int32 retVal;
!       errno = 0; /* to avoid program abort with ENOENT set by fopen in main. */
!       retVal = getc ( bs->handle );
        if ( retVal == EOF ) {
           if (errno != 0) readError();
           return 2;
        }
        bs->buffLive = 7;
*************** Bool endsInBz2 ( Char* name )
*** 305,319 ****
--- 318,335 ----
  /*---------------------------------------------------*/
  /*---                                             ---*/
  /*---------------------------------------------------*/
  
  /* This logic isn't really right when it comes to Cygwin. */
+ /* This logic isn't right at all when it comes to DJGPP. */
+ #ifndef __DJGPP__
  #ifdef _WIN32
  #  define  BZ_SPLIT_SYM  '\\'  /* path splitter on Windows platform */
  #else
  #  define  BZ_SPLIT_SYM  '/'   /* path splitter on Unix platform */
  #endif
+ #endif
  
  #define BLOCK_HEADER_HI  0x00003141UL
  #define BLOCK_HEADER_LO  0x59265359UL
  
  #define BLOCK_ENDMARK_HI 0x00001772UL
*************** Int32 main ( Int32 argc, Char** argv )
*** 339,348 ****
--- 355,367 ----
     MaybeUInt64 bitsRead;
  
     UInt32      buffHi, buffLo, blockCRC;
     Char*       p;
  
+    Int32       pathLen;    /* Path length in inFileName including last slash. */
+    Char*       fileName;   /* Pointer to file name (basename) in inFileName. */
+ 
     strcpy ( progName, argv[0] );
     inFileName[0] = outFileName[0] = 0;
  
     fprintf ( stderr, 
               "bzip2recover 1.0.2: extracts blocks from damaged .bz2 files.\n" );
*************** Int32 main ( Int32 argc, Char** argv )
*** 378,387 ****
--- 397,420 ----
        exit(1);
     }
  
     strcpy ( inFileName, argv[1] );
  
+    /*--
+      Make a pointer to the file name in inFileName
+      and compute the length of the path string without
+      the file name part but including the last slash.
+    --*/
+    fileName = inFileName;
+    for (fileName += strlen ( inFileName ); fileName > inFileName; --fileName)
+      if (IS_DIR_SEPARATOR ( *fileName ))
+      {
+        fileName++;
+        break;
+      }
+    pathLen = fileName - inFileName;
+ 
     inFile = fopen ( inFileName, "rb" );
     if (inFile == NULL) {
        fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
        exit(1);
     }
*************** Int32 main ( Int32 argc, Char** argv )
*** 492,501 ****
--- 525,535 ----
           }
           if (wrBlock >= rbCtr) break;
           wrBlock++;
        } else
        if (bitsRead == rbStart[wrBlock]) {
+ #ifdef BZ_SPLIT_SYM
           /* Create the output file name, correctly handling leading paths. 
              (31.10.2001 by Sergey E. Kusikov) */
           Char* split;
           Int32 ofs, k;
           for (k = 0; k < BZ_MAX_FILENAME; k++) 
*************** Int32 main ( Int32 argc, Char** argv )
*** 507,521 ****
           } else {
              ++split;
  	 }
  	 /* Now split points to the start of the basename. */
           ofs  = split - outFileName;
!          sprintf (split, "rec%5d", wrBlock+1);
!          for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
!          strcat (outFileName, inFileName + ofs);
! 
!          if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
  
           fprintf ( stderr, "   writing block %d to `%s' ...\n",
                             wrBlock+1, outFileName );
  
           outFile = fopen ( outFileName, "wb" );
--- 541,570 ----
           } else {
              ++split;
  	 }
  	 /* Now split points to the start of the basename. */
           ofs  = split - outFileName;
! #endif
!          if (pathLen > 0) /* Account for a possible path in inFileName. */
!            strncpy ( outFileName, inFileName, pathLen );
!          else
!            outFileName[0] = 0;
! 
!          if (NO_LFN_SUPPORT ( inFileName )) /* There are only 8 characters available. */
!            sprintf ( &outFileName[pathLen], "r%4d", wrBlock+1 );
!          else
!            sprintf ( &outFileName[pathLen], "rec%4d", wrBlock+1 );
! 
!          for (p = outFileName; *p != 0; p++) if (*p == ' ') *p = '0';
!          strcat (outFileName, fileName);
! 
!          /* MSDOS 8.3 file name restriction. */
!          if (NO_LFN_SUPPORT ( outFileName ) && HAS_NO_EXTENSION ( fileName ))
!            strcat ( outFileName, ".bz2" );
!          else
!            /* Only if LFN support is available, append an extra extension. */
!            if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
  
           fprintf ( stderr, "   writing block %d to `%s' ...\n",
                             wrBlock+1, outFileName );
  
           outFile = fopen ( outFileName, "wb" );
diff -acprNC5 bzip2-1.0.2.orig/bzmore bzip2-1.0.2.djgpp/bzmore
*** bzip2-1.0.2.orig/bzmore	Sun Dec 30 02:12:34 2001
--- bzip2-1.0.2.djgpp/bzmore	Fri May 17 22:08:02 2002
***************
*** 1,11 ****
  #!/bin/sh
  
  # Bzmore wrapped for bzip2, 
  # adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
  
! PATH="/usr/bin:$PATH"; export PATH
  
  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
  	*less)	more=less	;;
  	*)	more=more       ;;
--- 1,15 ----
  #!/bin/sh
  
  # Bzmore wrapped for bzip2, 
  # adapted from zmore by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
  
! pathsep=:
! if test -n "$DJGPP$djgpp"; then
!   pathsep=";"
! fi
! PATH="/dev/env/DJDIR/bin$pathsep$PATH"; export PATH
  
  prog=`echo $0 | sed 's|.*/||'`
  case "$prog" in
  	*less)	more=less	;;
  	*)	more=more       ;;
diff -acprNC5 bzip2-1.0.2.orig/words3 bzip2-1.0.2.djgpp/words3
*** bzip2-1.0.2.orig/words3	Sat Jan  5 01:04:54 2002
--- bzip2-1.0.2.djgpp/words3	Sun May 19 20:46:28 2002
*************** is going to do, you can first do
*** 13,23 ****
  The -n instructs make to show the commands it would execute, but
  not actually execute them.
  
  Instructions for use are in the preformatted manual page, in the file
  bzip2.txt.  For more detailed documentation, read the full manual.  
! It is available in Postscript form (manual.ps), PDF form (manual.pdf),
! and HTML form (manual_toc.html).
  
  You can also do "bzip2 --help" to see some helpful information. 
  "bzip2 -L" displays the software license.
  
--- 13,23 ----
  The -n instructs make to show the commands it would execute, but
  not actually execute them.
  
  Instructions for use are in the preformatted manual page, in the file
  bzip2.txt.  For more detailed documentation, read the full manual.  
! It is available in Postscript form (bzip2.ps), PDF form (bzip2.pdf),
! and HTML form (bzip2.html).
  
  You can also do "bzip2 --help" to see some helpful information. 
  "bzip2 -L" displays the software license.
  
