2014-05-11 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-2.1.orig/Makefile jbigkit-2.1/Makefile
--- jbigkit-2.1.orig/Makefile	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/Makefile	2014-05-11 15:57:44 +0200
@@ -1,12 +1,13 @@
 # Unix makefile for JBIG-KIT
+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
-CFLAGS = -O2 -W -Wno-unused-result
+CFLAGS = -O2 -W -Wall -Wno-unused-result
 # CFLAGS = -O -g -W -Wall -Wno-unused-result -ansi -pedantic # -DDEBUG
 
 export CC CFLAGS
 
 VERSION=2.1
@@ -22,10 +23,14 @@ pbm: lib
 
 test: lib pbm
 	cd libjbig  && $(MAKE) test
 	cd pbmtools && $(MAKE) test
 
+install: lib pbm
+	(cd libjbig;  make "CC=$(CC)" "CFLAGS=$(CFLAGS)" install)
+	(cd pbmtools; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" install)
+
 analyze:
 	cd libjbig  && $(MAKE) analyze
 	cd pbmtools && $(MAKE) analyze
 
 clean:
diff -aprNU5 jbigkit-2.1.orig/libjbig/Makefile jbigkit-2.1/libjbig/Makefile
--- jbigkit-2.1.orig/libjbig/Makefile	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/libjbig/Makefile	2014-05-11 15:57:16 +0200
@@ -1,20 +1,35 @@
 # Unix makefile for the JBIG-KIT library
+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 -W -Wall -ansi -pedantic # --coverage
+#CFLAGS = -g -O -W -Wall -ansi -pedantic # --coverage
+CFLAGS = -O2 -Wall -pedantic
+
+all: libjbig.a tstcodec$(EXEEXT) tstcodec85$(EXEEXT)
 
-all: libjbig.a libjbig85.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.o jbig.o jbig_ar.o
+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.o jbig85.o jbig_ar.o
+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
@@ -40,16 +55,16 @@ update-po: jbig.c jbig85.c Makefile
 	  msgmerge --update $$po ../jbig.pot ; done
 
 analyze:
 	clang --analyze *.c
 
-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 *.plist *~ core gmon.out dbg_d\=??.pbm
 	rm -f t82test.pbm
 	rm -f tstcodec tstcodec85
diff -aprNU5 jbigkit-2.1.orig/pbmtools/Makefile jbigkit-2.1/pbmtools/Makefile
--- jbigkit-2.1.orig/pbmtools/Makefile	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/pbmtools/Makefile	2014-05-11 15:57:16 +0200
@@ -1,32 +1,50 @@
 # Unix makefile for the JBIG-KIT PBM tools
+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 -O -W -Wall -Wno-unused-result -ansi -pedantic # --coverage
+#CFLAGS = -g -O -W -Wall -Wno-unused-result -ansi -pedantic # --coverage
+CFLAGS = -O2 -Wall -pedantic -I../libjbig
 CPPFLAGS = -I../libjbig 
 
 .SUFFIXES: .1 .5 .txt $(SUFFIXES)
 .PHONY: txt test test82 test85 clean
 
-all: pbmtojbg jbgtopbm pbmtojbg85 jbgtopbm85 txt
+all: pbmtojbg$(EXEEXT) jbgtopbm$(EXEEXT) pbmtojbg85$(EXEEXT) jbgtopbm85$(EXEEXT) txt
 
 txt: 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
@@ -42,11 +60,11 @@ pbmtojbg85.o: pbmtojbg85.c ../libjbig/jb
 analyze:
 	clang $(CPPFLAGS) --analyze *.c
 
 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
@@ -60,44 +78,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
@@ -118,49 +136,49 @@ 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) $@
 
 FOPT=-c 1000 -p 300000 -m 3
 fuzz: test-t82.pbm
 	while \
-	  ./pbmtojbg -f test-t82.pbm | ./jbgfuzz.pl $(FOPT) && \
-	  ./pbmtojbg test-t82.pbm | ./jbgfuzz.pl $(FOPT) -d jbgtopbm ; \
+	  ./pbmtojbg$(EXEEXT) -f test-t82.pbm | ./jbgfuzz.pl $(FOPT) && \
+	  ./pbmtojbg$(EXEEXT) test-t82.pbm | ./jbgfuzz.pl $(FOPT) -d jbgtopbm ; \
 	do true; done
 
 .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 *.plist
diff -aprNU5 jbigkit-2.1.orig/pbmtools/jbgtopbm.c jbigkit-2.1/pbmtools/jbgtopbm.c
--- jbigkit-2.1.orig/pbmtools/jbgtopbm.c	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/pbmtools/jbgtopbm.c	2014-05-11 15:57:16 +0200
@@ -8,10 +8,65 @@
 #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) == ':')
+
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define __gnuc_extension__  __extension__
+# else
+#  define __gnuc_extension__
+# endif
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)    \
+  (__gnuc_extension__                                \
+    ({                                               \
+        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
@@ -292,11 +347,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
@@ -346,12 +401,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) {
@@ -359,12 +419,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
+  }
 
   /* send input file to decoder */
   jbg_dec_init(&s);
   jbg_dec_maxsize(&s, xmax, ymax);
   /* read BIH first to check VLENGTH */
diff -aprNU5 jbigkit-2.1.orig/pbmtools/jbgtopbm85.c jbigkit-2.1/pbmtools/jbgtopbm85.c
--- jbigkit-2.1.orig/pbmtools/jbgtopbm85.c	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/pbmtools/jbgtopbm85.c	2014-05-11 15:57:16 +0200
@@ -8,10 +8,65 @@
 #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>
+
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define __gnuc_extension__  __extension__
+# else
+#  define __gnuc_extension__
+# endif
+
+# undef  IS_SLASH
+# define IS_SLASH(c)   ((c) == '/' || (c) == '\\' || (c) == ':')
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)    \
+  (__gnuc_extension__                                \
+    ({                                               \
+        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;
@@ -64,11 +119,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
@@ -118,21 +173,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-2.1.orig/pbmtools/pbmtojbg.c jbigkit-2.1/pbmtools/pbmtojbg.c
--- jbigkit-2.1.orig/pbmtools/pbmtojbg.c	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/pbmtools/pbmtojbg.c	2014-05-11 15:57:16 +0200
@@ -8,10 +8,64 @@
 #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) == ':')
+
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define __gnuc_extension__  __extension__
+# else
+#  define __gnuc_extension__
+# endif
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)    \
+  (__gnuc_extension__                                \
+    ({                                               \
+        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 */
 
 
@@ -126,11 +180,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
@@ -242,21 +296,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-2.1.orig/pbmtools/pbmtojbg85.c jbigkit-2.1/pbmtools/pbmtojbg85.c
--- jbigkit-2.1.orig/pbmtools/pbmtojbg85.c	2014-03-27 18:47:14 +0100
+++ jbigkit-2.1/pbmtools/pbmtojbg85.c	2014-05-11 15:57:16 +0200
@@ -8,10 +8,64 @@
 #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) == ':')
+
+# if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define __gnuc_extension__  __extension__
+# else
+#  define __gnuc_extension__
+# endif
+
+# define STRIP_FULL_PATH_AND_EXTENSION(file_name)    \
+  (__gnuc_extension__                                \
+    ({                                               \
+        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] */
 
 
 /*
@@ -105,11 +159,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
@@ -165,12 +219,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)) ;
@@ -199,12 +258,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) */
