2010-08-18 Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* Makefile: Add SHELL variable and install target.

	* libjbig/Makefile: Add SHELL, EXEEXT and prefix variables
	and install target.

	* pbmtools/Makefile: Add SHELL, EXEEXT and prefix variables
	and install target.

	* pbmtools/jbgtopbm.c:  New macro SET_STDIN_STDOUT_IN_BINARY_MODE
	defined.  Enables DJGPP/DOS specific binary mode read/write support.
	[__DJGPP__]: New macro STRIP_FULL_PATH_AND_EXTENSION defined.  For
	other systems these are no-ops.
	(diagnose_bie): Use %U instead of %d in fprintf.
	(main): Use %U instead of %d in fprintf.  Switch stdin and stdout
	into binary mode.  Use STRIP_FULL_PATH_AND_EXTENSION to strip path
	and extension from argv[0].

	* pbmtools/jbgtopbm85.c:  New macro SET_STDIN_STDOUT_IN_BINARY_MODE
	defined.  Enables DJGPP/DOS specific binary mode read/write support.
	[__DJGPP__]: New macro STRIP_FULL_PATH_AND_EXTENSION defined.  For
	other systems these are no-ops.
	(main): Use STRIP_FULL_PATH_AND_EXTENSION to strip path and extension
	from argv[0].  Switch stdin and stdout into binary mode.

	* pbmtools/pbmtojbg.c:  New macro SET_STDIN_STDOUT_IN_BINARY_MODE
	defined.  Enables DJGPP/DOS specific binary mode read/write support.
	[__DJGPP__]: New macro STRIP_FULL_PATH_AND_EXTENSION defined.  For
	other systems these are no-ops.
	(main): Use STRIP_FULL_PATH_AND_EXTENSION to strip path and extension
	from argv[0].  Switch stdin and stdout into binary mode.

	* pbmtools/pbmtojbg85.c:  New macro SET_STDIN_STDOUT_IN_BINARY_MODE
	defined.  Enables DJGPP/DOS specific binary mode read/write support.
	[__DJGPP__]: New macro STRIP_FULL_PATH_AND_EXTENSION defined.  For
	other systems these are no-ops.
	(main): Use STRIP_FULL_PATH_AND_EXTENSION to strip path and extension
	from argv[0].  Switch stdin and stdout into binary mode.








diff -aprNU5 jbigkit.orig/Makefile jbigkit/Makefile
--- jbigkit.orig/Makefile	2008-08-30 20:40:22 +0000
+++ jbigkit/Makefile	2010-08-19 23:44:58 +0000
@@ -1,7 +1,8 @@
 # Unix makefile for JBIG-KIT
 # $Id: Makefile 1303 2008-08-30 20:16:20Z mgk25 $
+SHELL = /bin/sh
 
 # Select an ANSI/ISO C compiler here, GNU gcc is recommended
 CC = gcc
 
 # Options for the compiler: A high optimization level is suggested
@@ -23,10 +24,14 @@ pbm: lib
 
 test: lib pbm
 	(cd libjbig;  make "CC=$(CC)" "CFLAGS=$(CFLAGS)" test)
 	(cd pbmtools; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" test)
 
+install: lib pbm
+	(cd libjbig;  make "CC=$(CC)" "CFLAGS=$(CFLAGS)" install)
+	(cd pbmtools; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" install)
+
 clean:
 	rm -f *~ core
 	(cd libjbig; make clean)
 	(cd pbmtools; make clean)
 
diff -aprNU5 jbigkit.orig/libjbig/Makefile jbigkit/libjbig/Makefile
--- jbigkit.orig/libjbig/Makefile	2008-08-30 17:20:52 +0000
+++ jbigkit/libjbig/Makefile	2010-08-19 23:45:46 +0000
@@ -1,21 +1,36 @@
 # Unix makefile for the JBIG-KIT library
 # $Id: Makefile 1285 2008-08-18 13:36:45Z mgk25 $
+SHELL = /bin/sh
+
+prefix=/dev/env/DJDIR
+
+EXEEXT = .exe
 
 # Select an ANSI/ISO C compiler here, GNU gcc is recommended
 CC = gcc
 
 # Options for the compiler: A high optimization level is suggested
-CFLAGS = -g -O -Wall -ansi -pedantic # --coverage
+#CFLAGS = -g -O -Wall -ansi -pedantic # --coverage
+CFLAGS = -O2 -Wall -pedantic
+
+all: libjbig.a tstcodec$(EXEEXT) tstcodec85$(EXEEXT)
 
-all: libjbig.a tstcodec tstcodec85
+install: libjbig.a libjbig85.a
+	mkdir -p $(prefix)/include
+	mkdir -p $(prefix)/lib
+	/dev/env/DJDIR/bin/ginstall -c jbig_ar.h $(prefix)/include/jbig_ar.h
+	/dev/env/DJDIR/bin/ginstall -c jbig.h $(prefix)/include/jbig.h
+	/dev/env/DJDIR/bin/ginstall -c jbig85.h $(prefix)/include/jbig85.h
+	/dev/env/DJDIR/bin/ginstall -c libjbig.a $(prefix)/lib/libjbig.a
+	/dev/env/DJDIR/bin/ginstall -c libjbig85.a $(prefix)/lib/libjb85.a
 
-tstcodec: tstcodec.o jbig.o jbig_ar.o
-	$(CC) $(CFLAGS) -o tstcodec $+
+tstcodec$(EXEEXT): tstcodec.o jbig.o jbig_ar.o
+	$(CC) $(CFLAGS) -o tstcodec$(EXEEXT) $+
 
-tstcodec85: tstcodec85.o jbig85.o jbig_ar.o
-	$(CC) $(CFLAGS) -o tstcodec85 $+
+tstcodec85$(EXEEXT): tstcodec85.o jbig85.o jbig_ar.o
+	$(CC) $(CFLAGS) -o tstcodec85$(EXEEXT) $+
 
 libjbig.a: jbig.o jbig_ar.o
 	rm -f libjbig.a
 	ar rc libjbig.a jbig.o jbig_ar.o
 	-ranlib libjbig.a
@@ -34,15 +49,15 @@ tstcodec85.o: tstcodec85.c jbig85.h
 jbig.pot: jbig.c
 	xgettext -o$@ -k_ \
 	  --copyright-holder='Markus Kuhn' \
 	  --msgid-bugs-address='http://www.cl.cam.ac.uk/~mgk25/jbigkit/' $+
 
-test: tstcodec tstcodec85
-	./tstcodec
-	./tstcodec85
+test: tstcodec$(EXEEXT) tstcodec85$(EXEEXT)
+	./tstcodec$(EXEEXT)
+	./tstcodec85$(EXEEXT)
 
-t82test.pbm: tstcodec
-	./tstcodec $@
+t82test.pbm: tstcodec$(EXEEXT)
+	./tstcodec$(EXEEXT) $@
 
 clean:
 	rm -f *.{o,gcda,gcno,gcov} *~ core gmon.out dbg_d\=??.pbm t82test.pbm
-	rm -f tstcodec tstcodec85
+	rm -f tstcodec$(EXEEXT) tstcodec85$(EXEEXT)
diff -aprNU5 jbigkit.orig/pbmtools/Makefile jbigkit/pbmtools/Makefile
--- jbigkit.orig/pbmtools/Makefile	2008-08-25 22:26:38 +0000
+++ jbigkit/pbmtools/Makefile	2010-08-19 23:44:58 +0000
@@ -1,30 +1,48 @@
 # Unix makefile for the JBIG-KIT PBM tools
 # $Id: Makefile 1293 2008-08-25 22:26:39Z mgk25 $
+SHELL = /bin/sh
+
+prefix=/dev/env/DJDIR
+
+EXEEXT = .exe
 
 # Select an ANSI/ISO C compiler here, e.g. GNU gcc is recommended
 CC = gcc
 
 # Options for the compiler
-CFLAGS = -g -Wall -ansi -pedantic -I../libjbig # --coverage
+#CFLAGS = -g -Wall -ansi -pedantic -I../libjbig # --coverage
+CFLAGS = -O2 -Wall -pedantic -I../libjbig
 
 .SUFFIXES: .1 .5 .txt $(SUFFIXES)
 
-all: pbmtojbg jbgtopbm pbmtojbg85 jbgtopbm85 \
+all: pbmtojbg$(EXEEXT) jbgtopbm$(EXEEXT) pbmtojbg85$(EXEEXT) jbgtopbm85$(EXEEXT) \
 	pbmtojbg.txt jbgtopbm.txt pbm.txt pgm.txt
 
-pbmtojbg: pbmtojbg.o ../libjbig/libjbig.a
-	$(CC) $(CFLAGS) -o pbmtojbg pbmtojbg.o -L../libjbig -ljbig
+install: pbmtojbg$(EXEEXT) jbgtopbm$(EXEEXT)
+	mkdir -p $(prefix)/bin
+	mkdir -p $(prefix)/share/man/man1
+	mkdir -p $(prefix)/share/man/man5
+	/dev/env/DJDIR/bin/ginstall -c pbmtojbg$(EXEEXT) $(prefix)/bin/pbmtojbg$(EXEEXT)
+	/dev/env/DJDIR/bin/ginstall -c jbgtopbm$(EXEEXT) $(prefix)/bin/jbgtopbm$(EXEEXT)
+	/dev/env/DJDIR/bin/ginstall -c pbmtojbg85$(EXEEXT) $(prefix)/bin/85pbmtojbg$(EXEEXT)
+	/dev/env/DJDIR/bin/ginstall -c jbgtopbm85$(EXEEXT) $(prefix)/bin/85jbgtopbm$(EXEEXT)
+	/dev/env/DJDIR/bin/ginstall -c jbgtopbm.1 $(prefix)/share/man/man1/jbgtopbm.1
+	/dev/env/DJDIR/bin/ginstall -c pbmtojbg.1 $(prefix)/share/man/man1/pbmtojbg.1
+	/dev/env/DJDIR/bin/ginstall -c pbm.5 $(prefix)/share/man/man5/pbm.5
+
+pbmtojbg$(EXEEXT): pbmtojbg.o ../libjbig/libjbig.a
+	$(CC) $(CFLAGS) -o pbmtojbg$(EXEEXT) pbmtojbg.o -L../libjbig -ljbig
 
-jbgtopbm: jbgtopbm.o ../libjbig/libjbig.a
-	$(CC) $(CFLAGS) -o jbgtopbm jbgtopbm.o -L../libjbig -ljbig
+jbgtopbm$(EXEEXT): jbgtopbm.o ../libjbig/libjbig.a
+	$(CC) $(CFLAGS) -o jbgtopbm$(EXEEXT) jbgtopbm.o -L../libjbig -ljbig
 
-pbmtojbg85: pbmtojbg85.o ../libjbig/libjbig85.a
-	$(CC) $(CFLAGS) -o pbmtojbg85 pbmtojbg85.o -L../libjbig -ljbig85
+pbmtojbg85$(EXEEXT): pbmtojbg85.o ../libjbig/libjbig85.a
+	$(CC) $(CFLAGS) -o pbmtojbg85$(EXEEXT) pbmtojbg85.o -L../libjbig -ljbig85
 
-jbgtopbm85: jbgtopbm85.o ../libjbig/libjbig85.a
-	$(CC) $(CFLAGS) -o jbgtopbm85 jbgtopbm85.o -L../libjbig -ljbig85
+jbgtopbm85$(EXEEXT): jbgtopbm85.o ../libjbig/libjbig85.a
+	$(CC) $(CFLAGS) -o jbgtopbm85$(EXEEXT) jbgtopbm85.o -L../libjbig -ljbig85
 
 jbgtopbm.o: jbgtopbm.c ../libjbig/jbig.h
 pbmtojbg.o: pbmtojbg.c ../libjbig/jbig.h
 jbgtopbm85.o: jbgtopbm85.c ../libjbig/jbig85.h
 pbmtojbg85.o: pbmtojbg85.c ../libjbig/jbig85.h
@@ -37,11 +55,11 @@ pbmtojbg85.o: pbmtojbg85.c ../libjbig/jb
 	../libjbig/jbig_ar.c ../libjbig/jbig_ar.h
 	make -C ../libjbig libjbig85.a
 
 test: test82 test85
 
-test82: pbmtojbg jbgtopbm
+test82: pbmtojbg$(EXEEXT) jbgtopbm$(EXEEXT)
 	make IMG=ccitt1     OPTIONSP=                      dotest1
 	make IMG=ccitt2     OPTIONSP=                      dotest1
 	make IMG=ccitt3     OPTIONSP=                      dotest1
 	make IMG=xvlogo    "OPTIONSP=-d 3"                 dotest1
 	make IMG=sandra     OPTIONSP=      OPTIONSJ=       dotest2g
@@ -55,44 +73,44 @@ test82: pbmtojbg jbgtopbm
 	make IMG=mx        "OPTIONSP=-q -s 3 -m 128"       dotest2b
 	make IMG=mx        "OPTIONSP=-q -s 3 -m 128 -p 92" dotest2b
 	make IMG=mx        "OPTIONSP=-q -Y -1"             dotest2b
 	make IMG=mx        "OPTIONSP=-Y -1"                dotest2b
 	rm -f test-*.jbg test-*.pbm test-*.pgm
-	./jbgtopbm ../examples/ccitt1.jbg | ./pbmtojbg > test-ccitt1.jbg
+	./jbgtopbm$(EXEEXT) ../examples/ccitt1.jbg | ./pbmtojbg > test-ccitt1.jbg
 	cmp ../examples/ccitt1.jbg test-ccitt1.jbg
 	rm -f test-*.jbg test-*.pbm test-*.pgm
-	./jbgtopbm < ../examples/ccitt1.jbg | ./pbmtojbg - test-ccitt1.jbg
+	./jbgtopbm$(EXEEXT) < ../examples/ccitt1.jbg | ./pbmtojbg - test-ccitt1.jbg
 	cmp ../examples/ccitt1.jbg test-ccitt1.jbg
 	rm -f test-*.jbg test-*.pbm test-*.pgm
-	./jbgtopbm < ../examples/ccitt1.jbg - test-ccitt1.pbm ; \
-	  ./pbmtojbg test-ccitt1.pbm test-ccitt1.jbg
+	./jbgtopbm$(EXEEXT) < ../examples/ccitt1.jbg - test-ccitt1.pbm ; \
+	  ./pbmtojbg$(EXEEXT) test-ccitt1.pbm test-ccitt1.jbg
 	cmp ../examples/ccitt1.jbg test-ccitt1.jbg
 	rm -f test-*.jbg test-*.pbm test-*.pgm
-	./jbgtopbm ../examples/ccitt1.jbg test-ccitt1.pbm ; \
-	  ./pbmtojbg test-ccitt1.pbm >test-ccitt1.jbg
+	./jbgtopbm$(EXEEXT) ../examples/ccitt1.jbg test-ccitt1.pbm ; \
+	  ./pbmtojbg$(EXEEXT) test-ccitt1.pbm >test-ccitt1.jbg
 	cmp ../examples/ccitt1.jbg test-ccitt1.jbg
 	rm -f test-*.jbg test-*.pbm test-*.pgm
 	@echo
 	@echo "The pbmtools have PASSED the functional tests. Good!"
 	@echo
 
 dotest1:
-	./jbgtopbm ../examples/$(IMG).jbg test-$(IMG).pbm
-	./pbmtojbg $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg
+	./jbgtopbm$(EXEEXT) ../examples/$(IMG).jbg test-$(IMG).pbm
+	./pbmtojbg$(EXEEXT) $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg
 	cmp test-$(IMG).jbg ../examples/$(IMG).jbg
 
 dotest2b:
-	./pbmtojbg $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg
-	./jbgtopbm $(OPTIONSJ) test-$(IMG).jbg test-$(IMG)-2.pbm
+	./pbmtojbg$(EXEEXT) $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg
+	./jbgtopbm$(EXEEXT) $(OPTIONSJ) test-$(IMG).jbg test-$(IMG)-2.pbm
 	cmp test-$(IMG).pbm test-$(IMG)-2.pbm
 
 dotest2g:
-	./pbmtojbg $(OPTIONSP) ../examples/$(IMG).pgm test-$(IMG).jbg
-	./jbgtopbm $(OPTIONSJ) test-$(IMG).jbg test-$(IMG).pgm
+	./pbmtojbg$(EXEEXT) $(OPTIONSP) ../examples/$(IMG).pgm test-$(IMG).jbg
+	./jbgtopbm$(EXEEXT) $(OPTIONSJ) test-$(IMG).jbg test-$(IMG).pgm
 	cmp test-$(IMG).pgm ../examples/$(IMG).pgm
 
-test85: pbmtojbg jbgtopbm pbmtojbg85 jbgtopbm85 test-t82.pbm
+test85: pbmtojbg$(EXEEXT) jbgtopbm$(EXEEXT) pbmtojbg85$(EXEEXT) jbgtopbm85$(EXEEXT) test-t82.pbm
 	make IMG=t82 "OPTIONSP=-p 0"      dotest85
 	make IMG=t82 "OPTIONSP=-p 8"      dotest85
 	make IMG=t82 "OPTIONSP=-p 8 -r"   dotest85b
 	make IMG=t82 "OPTIONSP=-p 64"     dotest85
 	make IMG=t82 "OPTIONSP=-p 72"     dotest85
@@ -113,42 +131,42 @@ test85: pbmtojbg jbgtopbm pbmtojbg85 jbg
 	@echo
 	@echo "The T.85 pbmtools have PASSED the functional tests. Good!"
 	@echo
 
 dotest85: test-$(IMG).pbm
-	./pbmtojbg85  $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg85
+	./pbmtojbg85$(EXEEXT)  $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg85
 	ls -l test-$(IMG).jbg85
-	./jbgtopbm test-$(IMG).jbg85 test-$(IMG).pbm85
+	./jbgtopbm$(EXEEXT) test-$(IMG).jbg85 test-$(IMG).pbm85
 	cmp test-$(IMG).pbm test-$(IMG).pbm85
 	rm test-$(IMG).pbm85
-	./jbgtopbm85 test-$(IMG).jbg85 test-$(IMG).pbm85
+	./jbgtopbm85$(EXEEXT) test-$(IMG).jbg85 test-$(IMG).pbm85
 	cmp test-$(IMG).pbm test-$(IMG).pbm85
 	rm test-$(IMG).pbm85
-	./jbgtopbm85 -B 1 test-$(IMG).jbg85 test-$(IMG).pbm85
+	./jbgtopbm85$(EXEEXT) -B 1 test-$(IMG).jbg85 test-$(IMG).pbm85
 	cmp test-$(IMG).pbm test-$(IMG).pbm85
 
 dotest85b: test-$(IMG).pbm
-	./pbmtojbg -f $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg85
+	./pbmtojbg$(EXEEXT) -f $(OPTIONSP) test-$(IMG).pbm test-$(IMG).jbg85
 	ls -l test-$(IMG).jbg85
-	./jbgtopbm test-$(IMG).jbg85 test-$(IMG).pbm85
+	./jbgtopbm$(EXEEXT) test-$(IMG).jbg85 test-$(IMG).pbm85
 	cmp test-$(IMG).pbm test-$(IMG).pbm85
 	rm test-$(IMG).pbm85
-	./jbgtopbm85 test-$(IMG).jbg85 test-$(IMG).pbm85
+	./jbgtopbm85$(EXEEXT) test-$(IMG).jbg85 test-$(IMG).pbm85
 	cmp test-$(IMG).pbm test-$(IMG).pbm85
 	rm test-$(IMG).pbm85
-	./jbgtopbm85 -B 1 test-$(IMG).jbg85 test-$(IMG).pbm85
+	./jbgtopbm85$(EXEEXT) -B 1 test-$(IMG).jbg85 test-$(IMG).pbm85
 	cmp test-$(IMG).pbm test-$(IMG).pbm85
 
 test-%.pbm: ../examples/%.jbg
-	./jbgtopbm $< $@
+	./jbgtopbm$(EXEEXT) $< $@
 
 test-t82.pbm:
-	make -C ../libjbig tstcodec
-	../libjbig/tstcodec $@
+	make -C ../libjbig tstcodec$(EXEEXT)
+	../libjbig/tstcodec$(EXEEXT) $@
 
 .1.txt .5.txt:
-	groff -man -Tascii -P -c -P -b -P -u $< >$@
+	groff -man -Tascii -P -b -P -u $< >$@
 
 clean:
-	rm -f *.o *~ core pbmtojbg jbgtopbm pbmtojbg85 jbgtopbm85
+	rm -f *.o *~ core pbmtojbg$(EXEEXT) jbgtopbm$(EXEEXT) pbmtojbg85$(EXEEXT) jbgtopbm85$(EXEEXT)
 	rm -f test-*.jbg test-*.pbm test-*.pgm test-*.jbg85 test-*.pbm85
 	rm -f *.gcda *.gcno
diff -aprNU5 jbigkit.orig/pbmtools/jbgtopbm.c jbigkit/pbmtools/jbgtopbm.c
--- jbigkit.orig/pbmtools/jbgtopbm.c	2008-08-27 21:37:44 +0000
+++ jbigkit/pbmtools/jbgtopbm.c	2010-08-19 23:44:58 +0000
@@ -10,10 +10,57 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <limits.h>
 #include "jbig.h"
 
+/*
+ *  For systems that distinguish between binary and text mode,
+ *  define this macro to 1 to set stdin and stdout into O_BINARY mode
+ *  or define it to 0 to set stdin and stdout into O_TEXT mode.
+ *  If stdio/stdout has been set to binary mode the program **can not**
+ *  be interrupted with cntl-c nor cntl-break. This means that you will
+ *  have to reset your machine to gain control again but you will be able
+ *  process image files from and to a pipe.
+ *  If stdin/stdout has been set to text mode the program **can not**
+ *  process images receive from stdin nor send images to stdout, but
+ *  you will be able to interrupt the program under any circumstances.
+ */
+#define SET_STDIN_STDOUT_IN_BINARY_MODE 1
+
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+# include <fcntl.h>
+# include <io.h>
+# include <sys/exceptn.h>
+#endif
+
+#ifdef __DJGPP__
+# include <libc/unconst.h>
+
+# undef  IS_SLASH
+# define IS_SLASH(c)   ((c) == '/' || (c) == '\\' || (c) == ':')
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  \
+  ({                                               \
+      char *_dst, *_src;                           \
+      _dst = _src = unconst((file_name), char *);  \
+      while (*_src++)                              \
+        ;                                          \
+      while ((_src - _dst) && (*--_src != '.'))    \
+        ;                                          \
+      for (*_src = '\0'; (_src - _dst); _src--)    \
+        if (IS_SLASH(*_src))                       \
+          break;                                   \
+      if (_src - _dst)                             \
+        while ((*_dst++ = *++_src))                \
+          ;                                        \
+      (file_name);                                 \
+  })
+#else
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)
+#endif
+
+
 char *progname;                  /* global pointer to argv[0] */
 
 
 /*
  * Print usage message and abort
@@ -132,11 +179,11 @@ void diagnose_bie(FILE *fin)
   unsigned long sdes, sde = 0;
   
   /* read BIH */
   read_file(&bie, &buflen, &len, fin);
   if (len < 20) {
-    fprintf(f, "Error: Input file is %d < 20 bytes long and therefore "
+    fprintf(f, "Error: Input file is %U < 20 bytes long and therefore "
 	    "does not contain an intact BIE header!\n", len);
     return;
   }
 
   /* parse BIH */
@@ -186,11 +233,11 @@ void diagnose_bie(FILE *fin)
   p = bie + 20; /* skip BIH */
   if ((bie[19] & (JBG_DPON | JBG_DPPRIV | JBG_DPLAST))
       == (JBG_DPON | JBG_DPPRIV))
     p += 1728;  /* skip DPTABLE */
   if (p > bie + len) {
-    fprintf(f, "Error: Input file is %d < 20+1728 bytes long and therefore "
+    fprintf(f, "Error: Input file is %U < 20+1728 bytes long and therefore "
 	    "does not contain an intact BIE header with DPTABLE!\n", len);
     return;
   }
   while (p != bie + len) {
     if (p > bie + len - 2) {
@@ -294,11 +341,11 @@ int main (int argc, char **argv)
     printf("Sorry, not enough memory available!\n");
     exit(1);
   }
 
   /* parse command line arguments */
-  progname = argv[0];
+  progname =  STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
   for (i = 1; i < argc; i++) {
     if (!all_args && argv[i][0] == '-')
       if (argv[i][1] == 0) {
 	if (files++) usage();
       } else
@@ -348,12 +395,17 @@ int main (int argc, char **argv)
     if (!fin) {
       fprintf(stderr, "Can't open input file '%s", fnin);
       perror("'");
       exit(1);
     }
-  } else
-    fnin  = "<stdin>";
+  } else {
+     fnin  = "<stdin>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fin), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
   if (diagnose) {
     diagnose_bie(fin);
     exit(0);
   }
   if (fnout) {
@@ -361,20 +413,25 @@ int main (int argc, char **argv)
     if (!fout) {
       fprintf(stderr, "Can't open input file '%s", fnout);
       perror("'");
       exit(1);
     }
-  } else
-    fnout = "<stdout>";
+  } else {
+     fnout = "<stdout>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fout), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
 
   /* send input file to decoder */
   jbg_dec_init(&s);
   jbg_dec_maxsize(&s, xmax, ymax);
   /* read BIH first to check VLENGTH */
   len = fread(buffer, 1, 20, fin);
   if (len < 20) {
-    fprintf(stderr, "Input file '%s' (%d bytes) must be at least "
+    fprintf(stderr, "Input file '%s' (%U bytes) must be at least "
 	    "20 bytes long\n", fnin, len);
     if (fout != stdout) {
       fclose(fout);
       remove(fnout);
     }
diff -aprNU5 jbigkit.orig/pbmtools/jbgtopbm85.c jbigkit/pbmtools/jbgtopbm85.c
--- jbigkit.orig/pbmtools/jbgtopbm85.c	2008-08-27 08:50:40 +0000
+++ jbigkit/pbmtools/jbgtopbm85.c	2010-08-19 23:44:58 +0000
@@ -10,10 +10,57 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <limits.h>
 #include "jbig85.h"
 
+/*
+ *  For systems that distinguish between binary and text mode,
+ *  define this macro to 1 to set stdin and stdout into O_BINARY mode
+ *  or define it to 0 to set stdin and stdout into O_TEXT mode.
+ *  If stdio/stdout has been set to binary mode the program **can not**
+ *  be interrupted with cntl-c nor cntl-break. This means that you will
+ *  have to reset your machine to gain control again but you will be able
+ *  process image files from and to a pipe.
+ *  If stdin/stdout has been set to text mode the program **can not**
+ *  process images receive from stdin nor send images to stdout, but
+ *  you will be able to interrupt the program under any circumstances.
+ */
+#define SET_STDIN_STDOUT_IN_BINARY_MODE 1
+
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+# include <fcntl.h>
+# include <io.h>
+# include <sys/exceptn.h>
+#endif
+
+#ifdef __DJGPP__
+# include <libc/unconst.h>
+
+# undef  IS_SLASH
+# define IS_SLASH(c)   ((c) == '/' || (c) == '\\' || (c) == ':')
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  \
+  ({                                               \
+      char *_dst, *_src;                           \
+      _dst = _src = unconst((file_name), char *);  \
+      while (*_src++)                              \
+        ;                                          \
+      while ((_src - _dst) && (*--_src != '.'))    \
+        ;                                          \
+      for (*_src = '\0'; (_src - _dst); _src--)    \
+        if (IS_SLASH(*_src))                       \
+          break;                                   \
+      if (_src - _dst)                             \
+        while ((*_dst++ = *++_src))                \
+          ;                                        \
+      (file_name);                                 \
+  })
+#else
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)
+#endif
+
+
 char *progname;                  /* global pointer to argv[0] */
 unsigned long y_0;
 fpos_t ypos;
 int ypos_error = 1;
 unsigned long ymax = 0;
@@ -66,11 +113,11 @@ int main (int argc, char **argv)
   size_t inbuflen = 8192, outbuflen, len, cnt, cnt2;
   unsigned long xmax = 8192;
   size_t bytes_read = 0;
 
   /* parse command line arguments */
-  progname = argv[0];
+  progname = STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
   for (i = 1; i < argc; i++) {
     if (!all_args && argv[i][0] == '-')
       if (argv[i][1] == 0) {
 	if (files++) usage();
       } else
@@ -120,21 +167,31 @@ int main (int argc, char **argv)
     if (!fin) {
       fprintf(stderr, "Can't open input file '%s", fnin);
       perror("'");
       exit(1);
     }
-  } else
-    fnin  = "<stdin>";
+  } else {
+     fnin  = "<stdin>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fin), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
   if (fnout) {
     fout = fopen(fnout, "wb");
     if (!fout) {
       fprintf(stderr, "Can't open input file '%s", fnout);
       perror("'");
       exit(1);
     }
-  } else
-    fnout = "<stdout>";
+  } else {
+     fnout = "<stdout>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fout), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
 
   /* send input file to decoder */
   jbg85_dec_init(&s, outbuf, outbuflen, line_out, fout);
   result = JBG_EAGAIN;
   while ((len = fread(inbuf, 1, inbuflen, fin))) {
diff -aprNU5 jbigkit.orig/pbmtools/pbmtojbg.c jbigkit/pbmtools/pbmtojbg.c
--- jbigkit.orig/pbmtools/pbmtojbg.c	2008-07-16 20:59:40 +0000
+++ jbigkit/pbmtools/pbmtojbg.c	2010-08-19 23:44:58 +0000
@@ -10,10 +10,56 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include "jbig.h"
 
+/*
+ *  For systems that distinguish between binary and text mode,
+ *  define this macro to 1 to set stdin and stdout into O_BINARY mode
+ *  or define it to 0 to set stdin and stdout into O_TEXT mode.
+ *  If stdio/stdout has been set to binary mode the program **can not**
+ *  be interrupted with cntl-c nor cntl-break. This means that you will
+ *  have to reset your machine to gain control again but you will be able
+ *  process image files from and to a pipe.
+ *  If stdin/stdout has been set to text mode the program **can not**
+ *  process images receive from stdin nor send images to stdout, but
+ *  you will be able to interrupt the program under any circumstances.
+ */
+#define SET_STDIN_STDOUT_IN_BINARY_MODE 1
+
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+# include <fcntl.h>
+# include <io.h>
+# include <sys/exceptn.h>
+#endif
+
+#ifdef __DJGPP__
+# include <libc/unconst.h>
+
+# undef  IS_SLASH
+# define IS_SLASH(c)   ((c) == '/' || (c) == '\\' || (c) == ':')
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  \
+  ({                                               \
+      char *_dst, *_src;                           \
+      _dst = _src = unconst((file_name), char *);  \
+      while (*_src++)                              \
+        ;                                          \
+      while ((_src - _dst) && (*--_src != '.'))    \
+        ;                                          \
+      for (*_src = '\0'; (_src - _dst); _src--)    \
+        if (IS_SLASH(*_src))                       \
+          break;                                   \
+      if (_src - _dst)                             \
+        while ((*_dst++ = *++_src))                \
+          ;                                        \
+      (file_name);                                 \
+  })
+#else
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)
+#endif
+
 
 char *progname;                  /* global pointer to argv[0] */
 unsigned long total_length = 0;  /* used for determining output file length */
 
 
@@ -128,11 +174,11 @@ int main (int argc, char **argv)
   char *comment = NULL;
   int options = JBG_TPDON | JBG_TPBON | JBG_DPON;
   int order = JBG_ILEAVE | JBG_SMID;
 
   /* parse command line arguments */
-  progname = argv[0];
+  progname = STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
   for (i = 1; i < argc; i++) {
     if (!all_args && argv[i][0] == '-')
       if (argv[i][1] == 0) {
 	if (files++) usage();
       } else
@@ -244,21 +290,31 @@ int main (int argc, char **argv)
     if (!fin) {
       fprintf(stderr, "Can't open input file '%s", fnin);
       perror("'");
       exit(1);
     }
-  } else
-    fnin  = "<stdin>";
+  } else {
+     fnin  = "<stdin>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fin), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
   if (fnout) {
     fout = fopen(fnout, "wb");
     if (!fout) {
       fprintf(stderr, "Can't open input file '%s", fnout);
       perror("'");
       exit(1);
     }
-  } else
-    fnout = "<stdout>";
+  } else {
+     fnout = "<stdout>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fout), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
 
   /* read PBM header */
   while ((c = getc(fin)) != EOF && (isspace(c) || c == '#'))
     if (c == '#')
       while ((c = getc(fin)) != EOF && !(c == 13 || c == 10)) ;
diff -aprNU5 jbigkit.orig/pbmtools/pbmtojbg85.c jbigkit/pbmtools/pbmtojbg85.c
--- jbigkit.orig/pbmtools/pbmtojbg85.c	2008-08-25 22:26:38 +0000
+++ jbigkit/pbmtools/pbmtojbg85.c	2010-08-19 23:44:58 +0000
@@ -10,10 +10,56 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include "jbig85.h"
 
+/*
+ *  For systems that distinguish between binary and text mode,
+ *  define this macro to 1 to set stdin and stdout into O_BINARY mode
+ *  or define it to 0 to set stdin and stdout into O_TEXT mode.
+ *  If stdio/stdout has been set to binary mode the program **can not**
+ *  be interrupted with cntl-c nor cntl-break. This means that you will
+ *  have to reset your machine to gain control again but you will be able
+ *  process image files from and to a pipe.
+ *  If stdin/stdout has been set to text mode the program **can not**
+ *  process images receive from stdin nor send images to stdout, but
+ *  you will be able to interrupt the program under any circumstances.
+ */
+#define SET_STDIN_STDOUT_IN_BINARY_MODE 1
+
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+# include <fcntl.h>
+# include <io.h>
+# include <sys/exceptn.h>
+#endif
+
+#ifdef __DJGPP__
+# include <libc/unconst.h>
+
+# undef  IS_SLASH
+# define IS_SLASH(c)   ((c) == '/' || (c) == '\\' || (c) == ':')
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  \
+  ({                                               \
+      char *_dst, *_src;                           \
+      _dst = _src = unconst((file_name), char *);  \
+      while (*_src++)                              \
+        ;                                          \
+      while ((_src - _dst) && (*--_src != '.'))    \
+        ;                                          \
+      for (*_src = '\0'; (_src - _dst); _src--)    \
+        if (IS_SLASH(*_src))                       \
+          break;                                   \
+      if (_src - _dst)                             \
+        while ((*_dst++ = *++_src))                \
+          ;                                        \
+      (file_name);                                 \
+  })
+#else
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)  (file_name)
+#endif
+
 
 char *progname;                  /* global pointer to argv[0] */
 
 
 /*
@@ -107,11 +153,11 @@ int main (int argc, char **argv)
   unsigned long l0 = 0, yi = 0, yr = 0;
   char *comment = NULL;
   int options = JBG_TPBON;
 
   /* parse command line arguments */
-  progname = argv[0];
+  progname = STRIP_FULL_PATH_AND_EXTENSION(argv[0]);
   for (i = 1; i < argc; i++) {
     if (!all_args && argv[i][0] == '-')
       if (argv[i][1] == 0) {
 	if (files++) usage();
       } else
@@ -167,12 +213,17 @@ int main (int argc, char **argv)
     if (!fin) {
       fprintf(stderr, "Can't open input file '%s", fnin);
       perror("'");
       exit(1);
     }
-  } else
-    fnin  = "<stdin>";
+  } else {
+     fnin  = "<stdin>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fin), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
 
   /* read PBM header */
   while ((c = getc(fin)) != EOF && (isspace(c) || c == '#'))
     if (c == '#')
       while ((c = getc(fin)) != EOF && !(c == 13 || c == 10)) ;
@@ -201,12 +252,17 @@ int main (int argc, char **argv)
     if (!fout) {
       fprintf(stderr, "Can't open input file '%s", fnout);
       perror("'");
       exit(1);
     }
-  } else
-    fnout = "<stdout>";
+  } else {
+     fnout = "<stdout>";
+#if SET_STDIN_STDOUT_IN_BINARY_MODE
+    setmode(fileno(fout), O_BINARY);
+    __djgpp_set_ctrl_c(1);
+#endif
+  }
 
   /* initialize parameter struct for JBIG encoder*/
   jbg85_enc_init(&s, width, yi ? yi : height, data_out, fout);
 
   /* Specify a few other options (each is ignored if negative) */
