about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2022-03-27 23:20:22 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2022-03-27 23:20:22 +0000
commit772c4792d998deb70f1719c1a2ad82f2defde5f0 (patch)
treef512ff95f5e767aa5bb1655caa0aaf87063a624a
parentf336dfc59346a26a045f7e0df0ecba32d904c55e (diff)
downloadnetpbm-mirror-772c4792d998deb70f1719c1a2ad82f2defde5f0.tar.gz
netpbm-mirror-772c4792d998deb70f1719c1a2ad82f2defde5f0.tar.xz
netpbm-mirror-772c4792d998deb70f1719c1a2ad82f2defde5f0.zip
Promote Development release to Advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@4318 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--analyzer/pgmtexture.c9
-rw-r--r--analyzer/pnmpsnr.c2
-rw-r--r--common.mk2
-rw-r--r--converter/other/ipdb.c222
-rw-r--r--converter/other/ipdb.h23
-rw-r--r--converter/other/pamtopdbimg.c76
-rw-r--r--converter/other/pamtoxvmini.c77
-rw-r--r--converter/other/pdbimgtopam.c127
-rw-r--r--converter/other/pnmtorle.c276
-rw-r--r--converter/other/pnmtosir.c35
-rw-r--r--converter/ppm/picttoppm.c1682
-rw-r--r--converter/ppm/ppmtoapplevol.c2
-rw-r--r--converter/ppm/ppmtoilbm.c210
-rw-r--r--doc/COPYRIGHT.PATENT7
-rw-r--r--doc/HISTORY53
-rw-r--r--doc/copyright_summary2
-rw-r--r--editor/pamsistoaglyph.c3
-rw-r--r--editor/pgmmedian.c287
-rwxr-xr-xeditor/pnmmargin2
-rwxr-xr-xeditor/pnmquant5
-rwxr-xr-xeditor/pnmquantall5
-rwxr-xr-xeditor/ppmfade146
-rwxr-xr-xeditor/ppmshadow2
-rw-r--r--generator/pbmnoise.c1
-rw-r--r--lib/Makefile3
-rw-r--r--lib/libpbmfont2.c51
-rw-r--r--lib/libppmfloyd.c312
-rw-r--r--lib/ppmfloyd.h69
-rw-r--r--lib/util/shhopt.README18
-rw-r--r--other/pambayer.c229
-rw-r--r--other/pamendian.c51
-rw-r--r--other/pamx/window.c85
-rwxr-xr-xtest/411toppm.test2
-rwxr-xr-xtest/Execute-Tests4
-rw-r--r--test/Test-Order22
-rwxr-xr-xtest/atari-roundtrip.test2
-rwxr-xr-xtest/atk-roundtrip.test2
-rwxr-xr-xtest/avs-roundtrip.test2
-rwxr-xr-xtest/bmp-roundtrip.test2
-rwxr-xr-xtest/channel-stack-roundtrip.test2
-rwxr-xr-xtest/cis-roundtrip.test2
-rwxr-xr-xtest/cmuw-roundtrip.test2
-rwxr-xr-xtest/cut-cat-roundtrip.test57
-rwxr-xr-xtest/cut-paste-roundtrip.test2
-rwxr-xr-xtest/enlarge-reduce-roundtrip.test2
-rwxr-xr-xtest/eyuvtoppm.test2
-rwxr-xr-xtest/facesaver-roundtrip.test2
-rwxr-xr-xtest/fiasco-roundtrip.test2
-rwxr-xr-xtest/fits-roundtrip.test2
-rwxr-xr-xtest/g3-roundtrip.test2
-rwxr-xr-xtest/gem-roundtrip.test2
-rwxr-xr-xtest/gif-transparent1.test2
-rwxr-xr-xtest/hdiff-roundtrip.test2
-rw-r--r--test/ilbm-roundtrip.ok6
-rwxr-xr-xtest/ilbm-roundtrip.test27
-rwxr-xr-xtest/jbig-roundtrip.test2
-rwxr-xr-xtest/jpeg-roundtrip.test2
-rwxr-xr-xtest/jpeg2k-roundtrip.test2
-rwxr-xr-xtest/leaf-roundtrip.test2
-rwxr-xr-xtest/lookup-roundtrip.test2
-rw-r--r--test/lps-roundtrip.ok4
-rwxr-xr-xtest/lps-roundtrip.test16
-rwxr-xr-xtest/macp-roundtrip.test2
-rwxr-xr-xtest/mda-roundtrip.test2
-rwxr-xr-xtest/mgr-roundtrip.test2
-rwxr-xr-xtest/mrf-roundtrip.test2
-rwxr-xr-xtest/pad-crop-roundtrip.test2
-rwxr-xr-xtest/palm-roundtrip2.test2
-rwxr-xr-xtest/pamarith-compare-equal.test2
-rwxr-xr-xtest/pamarith-multiple-input.test6
-rwxr-xr-xtest/pamarith.test2
-rwxr-xr-xtest/pambackground.test2
-rwxr-xr-xtest/pambrighten.test2
-rwxr-xr-xtest/pamchannel.test2
-rwxr-xr-xtest/pamcrater.test2
-rwxr-xr-xtest/pamcut.test7
-rwxr-xr-xtest/pamdepth-roundtrip.test2
-rwxr-xr-xtest/pamdice-roundtrip.test6
-rwxr-xr-xtest/pamdice.test2
-rwxr-xr-xtest/pamditherbw-random.test2
-rwxr-xr-xtest/pamditherbw.test2
-rwxr-xr-xtest/pamedge.test2
-rw-r--r--test/pamendian-roundtrip.ok5
-rwxr-xr-xtest/pamendian-roundtrip.test8
-rwxr-xr-xtest/pamenlarge-pbm.test28
-rwxr-xr-xtest/pamenlarge.test2
-rwxr-xr-xtest/pamexec.test9
-rwxr-xr-xtest/pamfile.test2
-rwxr-xr-xtest/pamfind.test2
-rwxr-xr-xtest/pamfix.test28
-rw-r--r--test/pamflip-pbm-roundtrip.ok122
-rwxr-xr-xtest/pamflip-pbm-roundtrip.test74
-rw-r--r--test/pamflip-roundtrip.ok16
-rwxr-xr-xtest/pamflip-roundtrip.test23
-rwxr-xr-xtest/pamflip1.test2
-rwxr-xr-xtest/pamflip2.test2
-rwxr-xr-xtest/pamfunc.test2
-rwxr-xr-xtest/pamgauss.test16
-rwxr-xr-xtest/pamhue-roundtrip.test2
-rwxr-xr-xtest/pammixmulti-identity.test2
-rwxr-xr-xtest/pamrecolor.test2
-rwxr-xr-xtest/pamscale-filters1.test4
-rwxr-xr-xtest/pamscale-filters2.test4
-rwxr-xr-xtest/pamscale-filters3.test4
-rwxr-xr-xtest/pamscale-reportonly.test2
-rwxr-xr-xtest/pamseq.test2
-rwxr-xr-xtest/pamslice-roundtrip.test22
-rwxr-xr-xtest/pamstretch.test2
-rwxr-xr-xtest/pamsumm.test2
-rwxr-xr-xtest/pamtable.test19
-rwxr-xr-xtest/pamtopam.test2
-rwxr-xr-xtest/pamundice.test42
-rwxr-xr-xtest/pamvalidate.test12
-rw-r--r--test/pbm-misc-converters.ok83
-rwxr-xr-xtest/pbm-misc-converters.test120
-rwxr-xr-xtest/pbm-ppm-roundtrip.test2
-rwxr-xr-xtest/pbmclean.test2
-rwxr-xr-xtest/pbmlife.test2
-rwxr-xr-xtest/pbmmake.test29
-rwxr-xr-xtest/pbmminkowski.test2
-rwxr-xr-xtest/pbmnoise-parameters.test2
-rwxr-xr-xtest/pbmnoise1.test6
-rwxr-xr-xtest/pbmnoise2.test2
-rwxr-xr-xtest/pbmpage.test2
-rwxr-xr-xtest/pbmpscale.test2
-rwxr-xr-xtest/pbmtext-bdf.test2
-rwxr-xr-xtest/pbmtext-iso88591.test2
-rwxr-xr-xtest/pbmtext.test4
-rwxr-xr-xtest/pbmtog3.test2
-rwxr-xr-xtest/pbmtopgm.test2
-rwxr-xr-xtest/pbmupc.test2
-rw-r--r--test/pcx-roundtrip.ok6
-rwxr-xr-xtest/pcx-roundtrip.test13
-rw-r--r--test/pdb-roundtrip.ok8
-rwxr-xr-xtest/pdb-roundtrip.test28
-rwxr-xr-xtest/pfm-roundtrip.test2
-rwxr-xr-xtest/pgmbentley.test2
-rwxr-xr-xtest/pgmhist.test2
-rwxr-xr-xtest/pgmmake.test2
-rwxr-xr-xtest/pgmminkowski.test2
-rwxr-xr-xtest/pgmnoise-parameters.test2
-rw-r--r--test/pgmnoise.ok5
-rwxr-xr-xtest/pgmnoise.test34
-rwxr-xr-xtest/pgmramp.test2
-rw-r--r--test/pgmtopgm.ok12
-rwxr-xr-xtest/pgmtopgm.test12
-rwxr-xr-xtest/pgmtoppm.test2
-rwxr-xr-xtest/pi3-roundtrip.test2
-rwxr-xr-xtest/pict-roundtrip.test2
-rwxr-xr-xtest/png-roundtrip.test2
-rwxr-xr-xtest/png-roundtrip2.test2
-rwxr-xr-xtest/pnm-pam-roundtrip.test2
-rwxr-xr-xtest/pnm-plain-roundtrip.test2
-rwxr-xr-xtest/pnmcat.test2
-rwxr-xr-xtest/pnmcolormap.test2
-rwxr-xr-xtest/pnmcrop-blank.test2
-rw-r--r--test/pnmcrop1.ok131
-rwxr-xr-xtest/pnmcrop1.test30
-rwxr-xr-xtest/pnmcrop2.test4
-rw-r--r--test/pnmcrop3.ok4
-rwxr-xr-xtest/pnmcrop3.test23
-rwxr-xr-xtest/pnminvert-roundtrip.test2
-rwxr-xr-xtest/pnminvert.test2
-rw-r--r--test/pnmpad-reportonly.ok67
-rwxr-xr-xtest/pnmpad-reportonly.test129
-rwxr-xr-xtest/pnmpaste-pbm.test2
-rwxr-xr-xtest/pnmpsnr.test2
-rwxr-xr-xtest/pnmquant.test2
-rwxr-xr-xtest/pnmquantall.test2
-rwxr-xr-xtest/pnmremap1.test2
-rwxr-xr-xtest/pnmremap2.test2
-rwxr-xr-xtest/pnmshear.test2
-rw-r--r--test/pnmtopnm-plain.ok89
-rwxr-xr-xtest/pnmtopnm-plain.test16
-rwxr-xr-xtest/ppmbrighten.test2
-rwxr-xr-xtest/ppmchange-roundtrip.test2
-rwxr-xr-xtest/ppmchange.test2
-rwxr-xr-xtest/ppmcie.test2
-rwxr-xr-xtest/ppmdfont.test2
-rwxr-xr-xtest/ppmdim.test2
-rwxr-xr-xtest/ppmdither.test2
-rwxr-xr-xtest/ppmforge-parameters.test2
-rwxr-xr-xtest/ppmforge.test2
-rwxr-xr-xtest/ppmhist.test2
-rwxr-xr-xtest/ppmmake.test2
-rwxr-xr-xtest/ppmmix.test2
-rwxr-xr-xtest/ppmpat-random.test2
-rwxr-xr-xtest/ppmpat.test2
-rwxr-xr-xtest/ppmrelief.test2
-rwxr-xr-xtest/ppmrough.test2
-rwxr-xr-xtest/ppmshift.ok29
-rwxr-xr-xtest/ppmshift.test35
-rwxr-xr-xtest/ppmspread.ok14
-rwxr-xr-xtest/ppmspread.test28
-rw-r--r--test/ppmtoapplevol.ok6
-rwxr-xr-xtest/ppmtoapplevol.test30
-rwxr-xr-xtest/ppmtoarbtxt-roundtrip.test2
-rwxr-xr-xtest/ppmtopgm.test2
-rwxr-xr-xtest/ppmtoppm.test2
-rwxr-xr-xtest/ppmwheel.test2
-rwxr-xr-xtest/ps-alt-roundtrip.test2
-rwxr-xr-xtest/ps-flate-roundtrip.test2
-rwxr-xr-xtest/ps-roundtrip.test2
-rwxr-xr-xtest/random-generator.test2
-rwxr-xr-xtest/sbig-roundtrip.test2
-rwxr-xr-xtest/sgi-roundtrip.test2
-rwxr-xr-xtest/st4-roundtrip.test2
-rw-r--r--test/stdin-pam1.ok41
-rwxr-xr-xtest/stdin-pam1.test72
-rw-r--r--test/stdin-pam2.ok5
-rwxr-xr-xtest/stdin-pam2.test70
-rw-r--r--test/stdin-pam3.ok32
-rwxr-xr-xtest/stdin-pam3.test73
-rw-r--r--test/stdin-pbm1.ok9
-rwxr-xr-xtest/stdin-pbm1.test45
-rw-r--r--test/stdin-pbm2.ok28
-rwxr-xr-xtest/stdin-pbm2.test78
-rw-r--r--test/stdin-pgm1.ok11
-rwxr-xr-xtest/stdin-pgm1.test47
-rw-r--r--test/stdin-pgm2.ok6
-rwxr-xr-xtest/stdin-pgm2.test49
-rw-r--r--test/stdin-pnm1.ok23
-rwxr-xr-xtest/stdin-pnm1.test60
-rw-r--r--test/stdin-pnm2.ok28
-rwxr-xr-xtest/stdin-pnm2.test91
-rw-r--r--test/stdin-ppm1.ok15
-rwxr-xr-xtest/stdin-ppm1.test58
-rw-r--r--test/stdin-ppm2.ok11
-rwxr-xr-xtest/stdin-ppm2.test68
-rw-r--r--test/stdin-ppm3.ok20
-rwxr-xr-xtest/stdin-ppm3.test77
-rwxr-xr-xtest/sunicon-roundtrip.test37
-rwxr-xr-xtest/sunrast-roundtrip.test2
-rw-r--r--test/symmetry.ok6
-rwxr-xr-xtest/symmetry.test25
-rwxr-xr-xtest/tiff-flate-lzw-roundtrip.test2
-rwxr-xr-xtest/tiff-roundtrip.test2
-rwxr-xr-xtest/tiffcmyk-roundtrip.test2
-rwxr-xr-xtest/utahrle-roundtrip.test2
-rwxr-xr-xtest/wbmp-roundtrip.test2
-rwxr-xr-xtest/winicon-roundtrip.test2
-rwxr-xr-xtest/winicon-roundtrip2.test2
-rwxr-xr-xtest/xbm-roundtrip.test4
-rwxr-xr-xtest/xpm-roundtrip.test2
-rwxr-xr-xtest/xv-roundtrip.test2
-rwxr-xr-xtest/xwd-roundtrip.test2
-rwxr-xr-xtest/yuv-roundtrip.test2
-rw-r--r--urt/Makefile6
-rw-r--r--urt/README5
-rw-r--r--urt/Runput.c300
-rw-r--r--urt/Runput.h2
-rw-r--r--urt/cmd_name.c30
-rw-r--r--urt/rle.h147
-rw-r--r--urt/rle_addhist.c20
-rw-r--r--urt/rle_code.h57
-rw-r--r--urt/rle_config.h10
-rw-r--r--urt/rle_error.c89
-rw-r--r--urt/rle_getcom.c44
-rw-r--r--urt/rle_getrow.c89
-rw-r--r--urt/rle_getskip.c198
-rw-r--r--urt/rle_global.c78
-rw-r--r--urt/rle_hdr.c2
-rw-r--r--urt/rle_open_f.c28
-rw-r--r--urt/rle_put.h64
-rw-r--r--urt/rle_putcom.c57
-rw-r--r--urt/rle_putrow.c753
-rw-r--r--urt/rle_row_alc.c100
-rw-r--r--urt/scanargs.c918
-rw-r--r--urt/vaxshort.c32
-rw-r--r--version.mk4
270 files changed, 5223 insertions, 4823 deletions
diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c
index ea0b6210..5af51bf5 100644
--- a/analyzer/pgmtexture.c
+++ b/analyzer/pgmtexture.c
@@ -49,7 +49,16 @@ static bool const sortit = FALSE;
 static float *
 vector(unsigned int const nl,
        unsigned int const nh) {
+/*----------------------------------------------------------------------------
+  Allocate a float vector with range [nl..nh]
+
+  We do some seedy C here, subtracting an arbitrary integer from a pointer and
+  calling the result a pointer.  It normally works because the only way we'll
+  use that pointer is by adding that same integer or something greater to it.
 
+  The point of this is not to allocate memory for vector elements that will
+  never be referenced (component < nl).
+-----------------------------------------------------------------------------*/
     float * v;
     unsigned int i;
 
diff --git a/analyzer/pnmpsnr.c b/analyzer/pnmpsnr.c
index 2363e8c3..6543c542 100644
--- a/analyzer/pnmpsnr.c
+++ b/analyzer/pnmpsnr.c
@@ -179,7 +179,7 @@ validateInput(struct pam const pam1,
                  pam1.height, pam2.height);
 
     if (pam1.maxval != pam2.maxval)
-        pm_error("images do not have the same maxval.  This programs works "
+        pm_error("images do not have the same maxval.  This program works "
                  "only on like maxvals.  "
                  "The first image has maxval %u, "
                  "while the second has %u.  Use Pamdepth to change the "
diff --git a/common.mk b/common.mk
index 91b476b9..c86ef910 100644
--- a/common.mk
+++ b/common.mk
@@ -144,7 +144,7 @@ IMPORTINC_ROOT_HEADERS := pm_config.h inttypes_netpbm.h version.h
 
 IMPORTINC_LIB_HEADERS := \
   pm.h pbm.h pgm.h ppm.h pnm.h pam.h pbmfont.h ppmcmap.h \
-  pammap.h colorname.h ppmfloyd.h ppmdraw.h pm_system.h ppmdfont.h \
+  pammap.h colorname.h ppmdraw.h pm_system.h ppmdfont.h \
   pm_gamma.h lum.h dithers.h pamdraw.h
 
 IMPORTINC_LIB_UTIL_HEADERS := \
diff --git a/converter/other/ipdb.c b/converter/other/ipdb.c
index 5e4dc82e..d524c7e9 100644
--- a/converter/other/ipdb.c
+++ b/converter/other/ipdb.c
@@ -23,15 +23,12 @@
 #define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 #define _BSD_SOURCE   /* Ensure strdup() is in <string.h> */
 #include <assert.h>
-#include <time.h>
 #include <string.h>
 
 #include "mallocvar.h"
 #include "nstring.h"
-#include "ipdb.h"
-
-typedef uint32_t pilot_time_t;
 
+#include "ipdb.h"
 
 
 
@@ -49,7 +46,7 @@ imgPpb(IMAGE * const imgP) {
 
 
 unsigned int
-ipdb_img_ppb(IMAGE * const imgP) {
+ipdb_imgPpb(IMAGE * const imgP) {
 /*----------------------------------------------------------------------------
    Pixels per byte
 -----------------------------------------------------------------------------*/
@@ -59,7 +56,7 @@ ipdb_img_ppb(IMAGE * const imgP) {
 
 
 size_t
-ipdb_img_size(IMAGE * const imgP) {
+ipdb_imgSize(IMAGE * const imgP) {
 /*----------------------------------------------------------------------------
   Size (in bytes) of an image's data.
 -----------------------------------------------------------------------------*/
@@ -71,115 +68,97 @@ ipdb_img_size(IMAGE * const imgP) {
 /*
  * Return the start of row `r'.
  */
- uint8_t *
- ipdb_img_row(IMAGE *      const imgP,
-              unsigned int const row) {
-
-     return &imgP->data[(row) * imgP->width / imgPpb(imgP)];
- }
-
-
+uint8_t *
+ipdb_imgRow(IMAGE *      const imgP,
+            unsigned int const row) {
 
- #define img_row(i, r)   
-
- static pilot_time_t const unixepoch = (66*365+17)*24*3600;
-     /* The unix epoch in Mac time (the Mac epoch is 00:00 UTC 1904.01.01).
-        The 17 is the number of leap years.
-     */
-
- static const char * const errorDesc[] = {
-     /* E_BADCOLORS      */
-     "Invalid palette, only {0x00, 0x55, 0xAA, 0xFF} allowed.",
+    return &imgP->data[(row) * imgP->width / imgPpb(imgP)];
+}
 
-     /* E_NOTIMAGE       */
-     "Not an image file.",
 
-     /* E_IMAGETHERE     */
-     "Image record already present, logic error.",
 
-     /* E_IMAGENOTTHERE  */
-     "Image record required before text record, logic error.",
+static const char * const errorDesc[] = {
+    /* E_BADCOLORS      */
+    "Invalid palette, only {0x00, 0x55, 0xAA, 0xFF} allowed.",
 
-     /* E_TEXTTHERE      */
-     "Text record already present, logic error.",
+    /* E_NOTIMAGE       */
+    "Not an image file.",
 
-     /* E_NOTRECHDR      */
-     "Invalid record header encountered.",
+    /* E_IMAGETHERE     */
+    "Image record already present, logic error.",
 
-     /* E_UNKNOWNRECHDR  */
-     "Unknown record header.",
+    /* E_IMAGENOTTHERE  */
+    "Image record required before text record, logic error.",
 
-     /* E_TOOBIGG        */
-     "Image too big, maximum size approx. 640*400 gray pixels.",
+    /* E_TEXTTHERE      */
+    "Text record already present, logic error.",
 
-     /* E_TOOBIGM        */
-     "Image too big, maximum size approx. 640*800 monochrome pixels.",
- };
+    /* E_NOTRECHDR      */
+    "Invalid record header encountered.",
 
+    /* E_UNKNOWNRECHDR  */
+    "Unknown record header.",
 
+    /* E_TOOBIGG        */
+    "Image too big, maximum size approx. 640*400 gray pixels.",
 
- const char *
- ipdb_err(int const e) {
+    /* E_TOOBIGM        */
+    "Image too big, maximum size approx. 640*800 monochrome pixels.",
+};
 
-     if (e < 0)
-         return e >= E_LAST ? errorDesc[-e - 1] : "unknown error";
-     else
-         return strerror(e);
- }
 
 
+const char *
+ipdb_err(int const e) {
 
- static void
- rechdr_free(RECHDR * const recP) {
+    if (e < 0)
+        return e >= E_LAST ? errorDesc[-e - 1] : "unknown error";
+    else
+        return strerror(e);
+}
 
-     if (recP) {
-         free(recP->extra);
-         free(recP);
-     }
- }
 
 
+static void
+rechdr_free(RECHDR * const recP) {
 
- void
- ipdb_image_free(IMAGE * const imgP) {
+    if (recP) {
+        free(recP->extra);
+        free(recP);
+    }
+}
 
-     if (imgP) {
-         rechdr_free(imgP->r);
-         free(imgP->data);
-         free(imgP);
-     }
- }
 
 
+void
+ipdb_imageFree(IMAGE * const imgP) {
 
- void
- ipdb_text_free(TEXT * const textP) {
+    if (imgP) {
+        rechdr_free(imgP->r);
+        free(imgP->data);
+        free(imgP);
+    }
+}
 
-     if (textP) {
-         rechdr_free(textP->r);
-         free(textP->data);
-         free(textP);
-     }
- }
 
 
+void
+ipdb_textFree(TEXT * const textP) {
 
- void
- ipdb_pdbhead_free(PDBHEAD * const headP) {
+    if (textP) {
+        rechdr_free(textP->r);
+        if (textP->data)
+            free(textP->data);
+        free(textP);
+    }
+}
 
-     free(headP);
- }
 
 
+void
+ipdb_pdbheadFree(PDBHEAD * const headP) {
 
- void
- ipdb_clear(IPDB * const pdbP) {
-     
-     if (pdbP) {
-         ipdb_image_free(pdbP->i);
-         ipdb_text_free(pdbP->t);
-         ipdb_pdbhead_free(pdbP->p);
-    }
+    free(headP);
 }
 
 
@@ -187,14 +166,22 @@ ipdb_img_size(IMAGE * const imgP) {
 void
 ipdb_free(IPDB * const pdbP) {
 
-    ipdb_clear(pdbP);
+    if (pdbP->i)
+        ipdb_imageFree(pdbP->i);
+
+    if (pdbP->t)
+        ipdb_textFree(pdbP->t);
+
+    if (pdbP->p)
+        ipdb_pdbheadFree(pdbP->p);
+
     free(pdbP);
 }
 
 
 
 PDBHEAD *
-ipdb_pdbhead_alloc(const char * const name) {
+ipdb_pdbheadAlloc() {
 
     PDBHEAD * pdbHeadP;
 
@@ -202,20 +189,6 @@ ipdb_pdbhead_alloc(const char * const name) {
 
     if (pdbHeadP) {
         MEMSZERO(pdbHeadP);
-
-        STRSCPY(pdbHeadP->name, name == NULL ? "unnamed" : name);
-
-        /*
-         * All of the Image Viewer pdb files that I've come across have
-         * 3510939142U (1997.08.16 14:38:22 UTC) here.  I don't know where
-         * this bizarre date comes from but the real date works fine so
-         * I'm using it.
-         */
-        pdbHeadP->ctime =
-            pdbHeadP->mtime = (pilot_time_t)time(NULL) + unixepoch;
-        
-        MEMSCPY(&pdbHeadP->type, IPDB_vIMG);
-        MEMSCPY(&pdbHeadP->id,   IPDB_View);
     }
     return pdbHeadP;
 }
@@ -223,7 +196,7 @@ ipdb_pdbhead_alloc(const char * const name) {
 
 
 static RECHDR *
-rechdr_alloc(int      const type,
+rechdrCreate(int      const type,
              uint32_t const offset) {
 
     /*
@@ -234,7 +207,7 @@ rechdr_alloc(int      const type,
     RECHDR  * recHdrP;
 
     MALLOCVAR(recHdrP);
-    
+
     if (recHdrP) {
         MEMSSET(recHdrP, 0);
 
@@ -255,10 +228,10 @@ rechdr_alloc(int      const type,
 
 
 IMAGE *
-ipdb_image_alloc(const char * const name,
-            int          const type,
-            int          const w,
-            int          const h) {
+ipdb_imageCreate(const char * const name,
+                 int          const type,
+                 int          const w,
+                 int          const h) {
 
     bool failed;
     IMAGE * imgP;
@@ -277,7 +250,7 @@ ipdb_image_alloc(const char * const name,
         imgP->width    = w;
         imgP->height   = h;
 
-        imgP->r = rechdr_alloc(IMG_REC, IMGOFFSET);
+        imgP->r = rechdrCreate(IMG_REC, IMGOFFSET);
 
         if (imgP->r) {
             if (w != 0 && h != 0) {
@@ -292,10 +265,10 @@ ipdb_image_alloc(const char * const name,
                 rechdr_free(imgP->r);
         } else
             failed = true;
-        
+
         if (failed)
-            ipdb_image_free(imgP);
-    } else 
+            ipdb_imageFree(imgP);
+    } else
         failed = true;
 
     return failed ? NULL : imgP;
@@ -304,7 +277,7 @@ ipdb_image_alloc(const char * const name,
 
 
 TEXT *
-ipdb_text_alloc(const char * const content) {
+ipdb_textAlloc(void) {
 
     TEXT * textP;
     bool failed;
@@ -320,22 +293,13 @@ ipdb_text_alloc(const char * const content) {
     if (textP) {
         MEMSZERO(textP);
 
-        textP->r = rechdr_alloc(TEXT_REC, 0);
+        textP->r = rechdrCreate(TEXT_REC, 0);
 
-        if (textP->r) {
-            if (content) {
-                textP->data = strdup(content);
-
-                if (!textP->data)
-                    failed = true;
-            }
-            if (failed)
-                rechdr_free(textP->r);
-        } else
+        if (textP->r == NULL)
             failed = true;
 
         if (failed)
-            ipdb_text_free(textP);
+            free(textP);
     } else
         failed = true;
 
@@ -345,7 +309,7 @@ ipdb_text_alloc(const char * const content) {
 
 
 IPDB *
-ipdb_alloc(const char * const name) {
+ipdb_alloc(void) {
 
     IPDB * pdbP;
     bool failed;
@@ -357,12 +321,11 @@ ipdb_alloc(const char * const name) {
     if (pdbP) {
         MEMSZERO(pdbP);
 
-        if (name) {
-            pdbP->p = ipdb_pdbhead_alloc(name);
+        pdbP->p = ipdb_pdbheadAlloc();
+
+        if (!pdbP->p)
+            failed = true;
 
-            if (!pdbP->p)
-                failed = true;
-        }
         if (failed)
             ipdb_free(pdbP);
     } else
@@ -383,3 +346,6 @@ ipdb_typeName(uint8_t const type) {
     default: return "???";
     }
 }
+
+
+
diff --git a/converter/other/ipdb.h b/converter/other/ipdb.h
index 6af5fc44..59e5d266 100644
--- a/converter/other/ipdb.h
+++ b/converter/other/ipdb.h
@@ -201,43 +201,40 @@ const char *
 ipdb_err(int error);
 
 size_t
-ipdb_img_size(IMAGE * const imgP);
+ipdb_imgSize(IMAGE * const imgP);
 
 unsigned int
-ipdb_img_ppb(IMAGE * const imgP);
+ipdb_imgPpb(IMAGE * const imgP);
 
 uint8_t *
-ipdb_img_row(IMAGE *      const imgP,
+ipdb_imgRow(IMAGE *      const imgP,
              unsigned int const row);
 
 void
 ipdb_free(IPDB *);
 
 IPDB *
-ipdb_alloc(const char *);
-
-void
-ipdb_clear(IPDB * const pdbP);
+ipdb_alloc(void);
 
 PDBHEAD *
-ipdb_pdbhead_alloc(const char * const name);
+ipdb_pdbheadAlloc(void);
 
 void
-ipdb_pdbhead_free(PDBHEAD * const headP);
+ipdb_pdbheadFree(PDBHEAD * const headP);
 
 IMAGE *
-ipdb_image_alloc(const char * const name,
+ipdb_imageCreate(const char * const name,
                  int          const type,
                  int          const w,
                  int          const h);
 
 void
-ipdb_image_free(IMAGE * const imgP);
+ipdb_imageFree(IMAGE * const imgP);
 
 void
-ipdb_text_free(TEXT * const textP);
+ipdb_textFree(TEXT * const textP);
 
 TEXT *
-ipdb_text_alloc(const char * const content);
+ipdb_textAlloc(void);
 
 #endif
diff --git a/converter/other/pamtopdbimg.c b/converter/other/pamtopdbimg.c
index 4823686f..da0f5064 100644
--- a/converter/other/pamtopdbimg.c
+++ b/converter/other/pamtopdbimg.c
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <string.h>
+#include <time.h>
 #include <sys/stat.h>
 
 #include "pm_c_util.h"
@@ -45,7 +46,7 @@
 
 enum CompMode {COMPRESSED, MAYBE, UNCOMPRESSED};
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
@@ -54,13 +55,14 @@ struct cmdlineInfo {
     const char * notefile;  /* NULL if not specified */
     enum CompMode compMode;
     unsigned int depth4;
+    unsigned int fixedtime;
 };
 
 
 
 static void
 parseCommandLine(int argc, const char ** argv,
-                 struct cmdlineInfo * const cmdlineP) {
+                 struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    parse program command line described in Unix standard form by argc
    and argv.  Return the information in the options as *cmdlineP.
@@ -96,6 +98,8 @@ parseCommandLine(int argc, const char ** argv,
             &uncompressed,            0);
     OPTENT3(0, "4depth",              OPT_FLAG,      NULL,
             &cmdlineP->depth4,        0);
+    OPTENT3(0, "fixedtime",           OPT_FLAG,      NULL,
+            &cmdlineP->fixedtime,     0);
 
     opt.opt_table = option_def;
     opt.short_allowed = false;  /* We have no short (old-fashioned) options */
@@ -144,6 +148,42 @@ parseCommandLine(int argc, const char ** argv,
 
 
 
+static uint32_t const unixepoch = (66*365+17)*24*3600;
+    /* The unix epoch in Mac time (the Mac epoch is 00:00 UTC 1904.01.01).
+       The 17 is the number of leap years.
+    */
+
+
+
+static void
+setPdbHeader(PDBHEAD *    const pdbHeadP,
+             const char * const name,
+             bool         const wantFixedTime) {
+
+    STRSCPY(pdbHeadP->name, name);
+
+    {
+        /*
+         * All of the Image Viewer pdb files that I've come across have
+         * 3510939142U (1997.08.16 14:38:22 UTC) here.  I don't know where
+         * this bizarre datetime comes from but the real date works fine so
+         * I'm using it unless user asked for a fixed time (probably just so he
+         * gets repeatable output).
+         */
+
+        uint32_t const stdTime = 3510939142U;
+
+        uint32_t const hdrDt =
+            wantFixedTime ? stdTime : (uint32_t)time(NULL) + unixepoch;
+
+        pdbHeadP->ctime = pdbHeadP->mtime = hdrDt;
+    }
+    MEMSCPY(&pdbHeadP->type, IPDB_vIMG);
+    MEMSCPY(&pdbHeadP->id,   IPDB_View);
+}
+
+
+
 static int
 pdbheadWrite(PDBHEAD * const pdbheadP,
              FILE *    const fileP) {
@@ -249,9 +289,9 @@ compressIfRequired(IPDB *     const pdbP,
 
     if (comp == IPDB_NOCOMPRESS) {
         *compressedDataP = pdbP->i->data;
-        *compressedSizeP = ipdb_img_size(pdbP->i);
+        *compressedSizeP = ipdb_imgSize(pdbP->i);
     } else {
-        int const uncompressedSz = ipdb_img_size(pdbP->i);
+        int const uncompressedSz = ipdb_imgSize(pdbP->i);
 
         unsigned char * outbuf;
         size_t          compressedSz;
@@ -475,7 +515,7 @@ imageInsertInit(IPDB * const pdbP,
                      ipdb_typeName(type), MAX_SIZE(type));
         else {
             pdbP->i =
-                ipdb_image_alloc(name, type, adjustedWidth, adjustedHeight);
+                ipdb_imageCreate(name, type, adjustedWidth, adjustedHeight);
             if (pdbP->i == NULL)
                 pm_message("Could not get memory for %u x %u image",
                            adjustedWidth, adjustedHeight);
@@ -582,7 +622,7 @@ insertMimage(IPDB *          const pdbP,
 
 static int
 insertText(IPDB *       const pdbP,
-           const char * const s) {
+           const char * const content) {
 
     int retval;
 
@@ -591,17 +631,23 @@ insertText(IPDB *       const pdbP,
     else if (pdbP->p->num_recs == 2)
         retval = E_TEXTTHERE;
     else {
-        pdbP->t = ipdb_text_alloc(s);
+        pdbP->t = ipdb_textAlloc();
         if (pdbP->t == NULL)
             retval = ENOMEM;
         else {
-            pdbP->p->num_recs = 2;
+            pdbP->t->data = strdup(content);
 
-            pdbP->i->r->offset += 8;
-            pdbP->t->r->offset =
-                pdbP->i->r->offset + IMAGESIZE + ipdb_img_size(pdbP->i);
+            if (pdbP->t->data == NULL)
+                retval = ENOMEM;
+            else {
+                pdbP->p->num_recs = 2;
 
-            retval = 0;
+                pdbP->i->r->offset += 8;
+                pdbP->t->r->offset =
+                    pdbP->i->r->offset + IMAGESIZE + ipdb_imgSize(pdbP->i);
+
+                retval = 0;
+            }
         }
     }
     return retval;
@@ -689,7 +735,7 @@ readtxt(IPDB *       const pdbP,
 int
 main(int argc, const char **argv) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     IPDB * pdbP;
     FILE * ifP;
     int comp;
@@ -709,11 +755,13 @@ main(int argc, const char **argv) {
     if (strlen(cmdline.title) > 31)
         pm_error("Title too long.  Max length is 31 characters.");
 
-    pdbP = ipdb_alloc(cmdline.title);
+    pdbP = ipdb_alloc();
 
     if (pdbP == NULL)
         pm_error("Failed to allocate IPDB structure");
 
+    setPdbHeader(pdbP->p, cmdline.title, cmdline.fixedtime);
+
     readimg(pdbP, ifP, cmdline.depth4);
 
     if (cmdline.notefile)
diff --git a/converter/other/pamtoxvmini.c b/converter/other/pamtoxvmini.c
index b57bcc74..047de75a 100644
--- a/converter/other/pamtoxvmini.c
+++ b/converter/other/pamtoxvmini.c
@@ -23,16 +23,16 @@ typedef struct xvPalette {
 } xvPalette;
 
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     const char * inputFileName;
 };
 
 
 
 static void
-parseCommandLine(int const argc,
-                 char *    argv[],
-                 struct cmdlineInfo * const cmdlineP) {
+parseCommandLine(int const                  argc,
+                 const char *               argv[],
+                 struct CmdlineInfo * const cmdlineP) {
 
     if (argc-1 < 1)
         cmdlineP->inputFileName = "-";
@@ -75,7 +75,7 @@ static void
 writeXvHeader(FILE *       const ofP,
               unsigned int const cols,
               unsigned int const rows) {
-           
+
     fprintf(ofP, "P7 332\n");
 
     fprintf(ofP, "# Created by Pamtoxvmini\n");
@@ -94,12 +94,14 @@ writeXvHeader(FILE *       const ofP,
 
 static void
 findClosestColor(struct pam *      const pamP,
-                 tuple             const tuple, 
+                 tuple             const tuple,
                  const xvPalette * const xvPaletteP,
                  unsigned int *    const paletteIndexP) {
 /*----------------------------------------------------------------------------
    Find the color in the palette *xvPaletteP that is closest to the color
    'tuple' and return its index in the palette.
+
+   *pamP gives the format of 'tuple', which must be RGB with maxval 255.
 -----------------------------------------------------------------------------*/
     unsigned int paletteIndex;
     unsigned int bestPaletteIndex;
@@ -118,12 +120,12 @@ findClosestColor(struct pam *      const pamP,
         unsigned int const tupleRed = tuple[PAM_RED_PLANE];
         unsigned int const tupleGrn = tuple[PAM_GRN_PLANE];
         unsigned int const tupleBlu = tuple[PAM_BLU_PLANE];
-        
+
         unsigned int const paletteRed = xvPaletteP->red[paletteIndex];
         unsigned int const paletteGrn = xvPaletteP->grn[paletteIndex];
         unsigned int const paletteBlu = xvPaletteP->blu[paletteIndex];
 
-        unsigned int const distance = 
+        unsigned int const distance =
             SQR((int)tupleRed - (int)paletteRed) +
             SQR((int)tupleGrn - (int)paletteGrn) +
             SQR((int)tupleBlu - (int)paletteBlu);
@@ -155,24 +157,29 @@ getPaletteIndexThroughCache(struct pam *      const pamP,
     int found;
     int paletteIndex;
 
+    /* As required by findClosestColor(): */
+    assert(pamP->depth >= 3);
+    assert(pamP->maxval == 255);
+
     pnm_lookuptuple(pamP, paletteHash, tuple, &found, &paletteIndex);
     if (found)
         *paletteIndexP = paletteIndex;
     else {
         int fits;
+
         findClosestColor(pamP, tuple, xvPaletteP, paletteIndexP);
-        
+
         pnm_addtotuplehash(pamP, paletteHash, tuple, *paletteIndexP, &fits);
-        
+
         if (!fits)
             pm_error("Can't get memory for palette hash.");
     }
 }
 
-    
+
 
 static void
-writeXvRaster(struct pam * const pamP,
+writeXvRaster(struct pam * const inpamP,
               xvPalette *  const xvPaletteP,
               FILE *       const ofP) {
 /*----------------------------------------------------------------------------
@@ -190,33 +197,40 @@ writeXvRaster(struct pam * const pamP,
     unsigned int row;
     unsigned char * xvrow;
     struct pam scaledPam;
+    struct pam scaledRgbPam;
+
+    pnm_setminallocationdepth(inpamP, 3);
 
     paletteHash = pnm_createtuplehash();
 
-    tuplerow = pnm_allocpamrow(pamP);
-    xvrow = (unsigned char*)pm_allocrow(pamP->width, 1);
+    tuplerow = pnm_allocpamrow(inpamP);
+    xvrow = (unsigned char*)pm_allocrow(inpamP->width, 1);
 
-    scaledPam = *pamP;
+    scaledPam = *inpamP;  /* initial value */
     scaledPam.maxval = 255;
 
-    for (row = 0; row < pamP->height; ++row) {
+    scaledRgbPam = scaledPam;  /* initial value */
+    scaledRgbPam.depth = MAX(3, scaledPam.depth);
+
+    for (row = 0; row < inpamP->height; ++row) {
         unsigned int col;
 
-        pnm_readpamrow(pamP, tuplerow);
-        pnm_scaletuplerow(pamP, tuplerow, tuplerow, scaledPam.maxval);
+        pnm_readpamrow(inpamP, tuplerow);
+        pnm_scaletuplerow(inpamP, tuplerow, tuplerow, scaledPam.maxval);
         pnm_makerowrgb(&scaledPam, tuplerow);
 
-        for (col = 0; col < scaledPam.width; ++col) {
+        for (col = 0; col < scaledRgbPam.width; ++col) {
             unsigned int paletteIndex;
 
-            getPaletteIndexThroughCache(&scaledPam, tuplerow[col], xvPaletteP,
-                                        paletteHash, &paletteIndex);
+            getPaletteIndexThroughCache(&scaledRgbPam, tuplerow[col],
+                                        xvPaletteP, paletteHash,
+                                        &paletteIndex);
 
             assert(paletteIndex < 256);
 
             xvrow[col] = paletteIndex;
         }
-        fwrite(xvrow, 1, scaledPam.width, ofP);
+        fwrite(xvrow, 1, scaledRgbPam.width, ofP);
     }
 
     pm_freerow((char*)xvrow);
@@ -227,16 +241,16 @@ writeXvRaster(struct pam * const pamP,
 
 
 
-int 
-main(int    argc,
-     char * argv[]) {
+int
+main(int          argc,
+     const char * argv[]) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     FILE * ifP;
     struct pam pam;
     xvPalette xvPalette;
- 
-    pnm_init(&argc, argv);
+
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
@@ -246,13 +260,14 @@ main(int    argc,
 
     pnm_readpaminit(ifP, &pam, PAM_STRUCT_SIZE(allocation_depth));
 
-    pnm_setminallocationdepth(&pam, 3);
-
     writeXvHeader(stdout, pam.width, pam.height);
-    
+
     writeXvRaster(&pam, &xvPalette, stdout);
 
     pm_close(ifP);
 
     return 0;
 }
+
+
+
diff --git a/converter/other/pdbimgtopam.c b/converter/other/pdbimgtopam.c
index 67044109..b191644f 100644
--- a/converter/other/pdbimgtopam.c
+++ b/converter/other/pdbimgtopam.c
@@ -56,7 +56,7 @@ parseCommandLine(int argc, const char ** argv,
                  struct cmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    parse program command line described in Unix standard form by argc
-   and argv.  Return the information in the options as *cmdlineP.  
+   and argv.  Return the information in the options as *cmdlineP.
 
    If command line is internally inconsistent (invalid options, etc.),
    issue error message to stderr and abort program.
@@ -90,7 +90,7 @@ parseCommandLine(int argc, const char ** argv,
 
     if (!notefileSpec)
         cmdlineP->notefile = NULL;
-    
+
     if (argc-1 < 1)
         cmdlineP->inputFileName = "-";
     else if (argc-1 == 1)
@@ -152,7 +152,7 @@ decompress(const uint8_t * const compressed,
         const uint8_t * inP;
         uint8_t *       outP;
         size_t          bytesLeft;
-        
+
         for (bytesLeft = imageSize,
                  inP  = &compressed[0], outP = &uncompressed[0];
              bytesLeft > 0;
@@ -224,7 +224,7 @@ readCompressed(IMAGE *    const imgP,
          * this extra byte and ignore it by paying attention to
          * the image dimensions.
          */
-       size_t const maxCompressedSizeWithBloat = ipdb_img_size(imgP) * 2;
+       size_t const maxCompressedSizeWithBloat = ipdb_imgSize(imgP) * 2;
          /*
           * Provide a buffer large enough for the worst case.
           * See note in lib/util/runlength.c .
@@ -251,7 +251,7 @@ readCompressed(IMAGE *    const imgP,
          * Read to the indicated offset.
          */
         dataSize = end_offset - ftell(fP) + 1;
-        
+
         MALLOCARRAY(buffer, dataSize);
 
         if (buffer == NULL)
@@ -306,9 +306,9 @@ imageReadHeader(FILE *  const fileP,
         pm_message("  Y_anchor: %u", imgP->y_anchor);
         pm_message("  Width: %u", imgP->width);
         pm_message("  Height: %u", imgP->height);
-        pm_message("Pixels per byte: %u", ipdb_img_ppb(imgP));
+        pm_message("Pixels per byte: %u", ipdb_imgPpb(imgP));
         pm_message("Image size: %lu bytes",
-                   (unsigned long)ipdb_img_size(imgP));
+                   (unsigned long)ipdb_imgSize(imgP));
     }
 }
 
@@ -318,7 +318,7 @@ imageReadData(FILE *   const fileP,
               IMAGE *  const imgP,
               uint32_t const end_offset) {
 
-    size_t const imageSize = ipdb_img_size(imgP);  
+    size_t const imageSize = ipdb_imgSize(imgP);
 
     int retval;
     size_t dataSize;
@@ -390,7 +390,7 @@ textRead(TEXT * const textP,
         return 0;
 
     textP->r->offset = (uint32_t)ftell(fileP);
-    
+
     /*
      * What a pain in the ass!  Why the hell isn't there a length
      * attached to the text record?  I suppose the designer wasn't
@@ -453,7 +453,7 @@ pdbheadRead(PDBHEAD * const pdbHeadP,
     pm_readbiglongu2(fileP, &pdbHeadP->next_rec);
     pm_readbigshortu(fileP, &pdbHeadP->num_recs);
 
-    if (!memeq(pdbHeadP->type, IPDB_vIMG, 4) 
+    if (!memeq(pdbHeadP->type, IPDB_vIMG, 4)
         || !memeq(pdbHeadP->id, IPDB_View, 4))
         retval = E_NOTIMAGE;
     else
@@ -531,62 +531,54 @@ ipdbRead(IPDB * const pdbP,
 
     int retval;
 
-    ipdb_clear(pdbP);
+    int status;
 
-    pdbP->p = ipdb_pdbhead_alloc(NULL);
+    status = pdbheadRead(pdbP->p, fileP);
 
-    if (pdbP->p == NULL)
-        retval = ENOMEM;
+    if (status != 0)
+        retval = status;
     else {
-        int status;
-
-        status = pdbheadRead(pdbP->p, fileP);
-
-        if (status != 0)
-            retval = status;
+        pdbP->i = ipdb_imageCreate(pdbP->p->name, IMG_GRAY, 0, 0);
+        if (pdbP->i == NULL)
+            retval = ENOMEM;
         else {
-            pdbP->i = ipdb_image_alloc(pdbP->p->name, IMG_GRAY, 0, 0);
-            if (pdbP->i == NULL)
-                retval = ENOMEM;
+            int status;
+            status = rechdrRead(pdbP->i->r, fileP);
+            if (status != 0)
+                retval = status;
             else {
-                int status;
-                status = rechdrRead(pdbP->i->r, fileP);
-                if (status != 0)
-                    retval = status;
-                else {
-                    if (pdbP->p->num_recs > 1) {
-                        pdbP->t = ipdb_text_alloc(NULL);
-                        if (pdbP->t == NULL)
-                            retval = ENOMEM;
-                        else {
-                            int status;
-                            status = rechdrRead(pdbP->t->r, fileP);
-                            if (status != 0)
-                                retval = status;
-                            else
-                                retval = 0;
-                        }
-                    } else
-                        retval = 0;
-                    
-                    if (retval == 0) {
-                        uint32_t const offset =
-                            pdbP->t == NULL ?
-                            UNKNOWN_OFFSET : pdbP->t->r->offset - 1;
-
+                if (pdbP->p->num_recs > 1) {
+                    pdbP->t = ipdb_textAlloc();
+                    if (pdbP->t == NULL)
+                        retval = ENOMEM;
+                    else {
                         int status;
-
-                        status = imageRead(pdbP->i, offset, fileP, verbose);
+                        status = rechdrRead(pdbP->t->r, fileP);
                         if (status != 0)
                             retval = status;
-                        else {
-                            if (pdbP->t != NULL) {
-                                int status;
-                                
-                                status = textRead(pdbP->t, fileP);
-                                if (status != 0)
-                                    retval = status;
-                            }
+                        else
+                            retval = 0;
+                    }
+                } else
+                    retval = 0;
+
+                if (retval == 0) {
+                    uint32_t const offset =
+                        pdbP->t == NULL ?
+                        UNKNOWN_OFFSET : pdbP->t->r->offset - 1;
+
+                    int status;
+
+                    status = imageRead(pdbP->i, offset, fileP, verbose);
+                    if (status != 0)
+                        retval = status;
+                    else {
+                        if (pdbP->t != NULL) {
+                            int status;
+
+                            status = textRead(pdbP->t, fileP);
+                            if (status != 0)
+                                retval = status;
                         }
                     }
                 }
@@ -663,8 +655,8 @@ static void
 g16row(IPDB *       const pdbP,
        unsigned int const row,
        uint8_t *    const buffer) {
-    
-    g16unpack(ipdb_img_row(pdbP->i, row), buffer, ipdb_width(pdbP));
+
+    g16unpack(ipdb_imgRow(pdbP->i, row), buffer, ipdb_width(pdbP));
 }
 
 
@@ -674,7 +666,7 @@ grow(IPDB *       const pdbP,
      unsigned int const row,
      uint8_t *    const buffer) {
 
-    gunpack(ipdb_img_row(pdbP->i, row), buffer, ipdb_width(pdbP));
+    gunpack(ipdb_imgRow(pdbP->i, row), buffer, ipdb_width(pdbP));
 }
 
 
@@ -684,7 +676,7 @@ mrow(IPDB *       const pdbP,
      unsigned int const row,
      uint8_t *    const buffer) {
 
-    munpack(ipdb_img_row(pdbP->i, row), buffer, ipdb_width(pdbP));
+    munpack(ipdb_imgRow(pdbP->i, row), buffer, ipdb_width(pdbP));
 }
 
 
@@ -715,7 +707,7 @@ writeImgPam(IPDB * const pdbP,
            PAM_PBM_TUPLETYPE : PAM_PGM_TUPLETYPE);
 
     pnm_writepaminit(&pam);
-    
+
     tupleRow = pnm_allocpamrow(&pam);
 
     for (row = 0; row < pam.height; ++row) {
@@ -731,7 +723,7 @@ writeImgPam(IPDB * const pdbP,
 
         for (col = 0; col < pam.width; ++col)
             tupleRow[col][0] = imgRow[col];
-        
+
         pnm_writepamrow(&pam, tupleRow);
     }
     pnm_freepamrow(tupleRow);
@@ -754,7 +746,7 @@ writeText(IPDB *       const pdbP,
         fP = pm_openw(name);
         if (fP == NULL)
             pm_error("Could not open note file '%s' for output", name);
-        
+
         fprintf(fP, "%s\n", note);
 
         pm_close(fP);
@@ -777,7 +769,7 @@ main(int argc, const char ** argv) {
 
     ifP = pm_openr(cmdline.inputFileName);
 
-    pdbP = ipdb_alloc(NULL);
+    pdbP = ipdb_alloc();
     if (pdbP == NULL)
         pm_error("Could not allocate IPDB structure.");
 
@@ -795,3 +787,6 @@ main(int argc, const char ** argv) {
 
     return EXIT_SUCCESS;
 }
+
+
+
diff --git a/converter/other/pnmtorle.c b/converter/other/pnmtorle.c
index d61884dd..17c9cfbc 100644
--- a/converter/other/pnmtorle.c
+++ b/converter/other/pnmtorle.c
@@ -33,71 +33,157 @@
  * 2000.04.13 adapted for Netpbm by Bryan Henderson.  Quieted compiler
  *            warnings.
  *
+ * 2022.03.06 revision by Akira F Urushibata
+ *            use shhopt instead of scanargs
+ *            proper handling of multiple image files with -h
+ *
  */
 /*-----------------------------------------------------
  * System includes.
  */
 #include <string.h>
 #include <stdio.h>
+#include <assert.h>
 #include "pnm.h"
 #include "mallocvar.h"
 #include "rle.h"
+#include "shhopt.h"
+#include "pm_c_util.h"
+
+
+struct CmdlineInfo {
+    /* All the information the user supplied in the command line,
+       in a form easy for the program to use.
+    */
+    const char * inFileName;
+    const char * outfile;
+    unsigned int verbose;
+    unsigned int header;
+    unsigned int alpha;
+};
+
+
+
+static void
+parseCommandLine(int argc, const char ** argv,
+                 struct CmdlineInfo * const cmdlineP) {
+/*----------------------------------------------------------------------------
+   Note that the file spec array we return is stored in the storage that
+   was passed to us as the argv array.
+-----------------------------------------------------------------------------*/
+    optEntry * option_def;
+    /* Instructions to pm_optParseOptions3 on how to parse our options. */
+
+    optStruct3 opt;
+
+    unsigned int option_def_index;
+    unsigned int outfileSpec;
+
+    MALLOCARRAY_NOFAIL(option_def, 100);
+
+    option_def_index = 0;   /* incremented by OPTENTRY */
+    OPTENT3(0, "alpha",    OPT_FLAG,   NULL,  &cmdlineP->alpha,     0);
+    OPTENT3(0, "header",   OPT_FLAG,   NULL,  &cmdlineP->header,    0);
+    OPTENT3(0, "verbose",  OPT_FLAG,   NULL,  &cmdlineP->verbose,   0);
+    OPTENT3(0, "outfile",  OPT_STRING, &cmdlineP->outfile,
+                                              &outfileSpec,         0);
+
+    opt.opt_table = option_def;
+    opt.short_allowed = false;  /* We have no short (old-fashioned) options */
+    opt.allowNegNum = false;  /* We have no parms that are negative numbers */
+
+    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
+        /* Uses and sets argc, argv, and some of *cmdlineP and others. */
+
+    free(option_def);
+
+    if (argc-1 == 0)
+        cmdlineP->inFileName = "-";
+    else if (argc-1 != 1) {
+        pm_error("Program takes zero or one argument (filename).  You "
+                 "specified %d", argc-1);
+    }
+    else
+        cmdlineP->inFileName = argv[1];
+
+    if (!outfileSpec)
+        cmdlineP->outfile = "-";
+}
+
 
-#define VPRINTF if (verbose || header) fprintf
 
-typedef unsigned char U_CHAR;
-/*
- * Global variables.
- */
-static FILE    *fp;
-static rle_hdr hdr;
-static int  format;
-static int width, height;
-static int verbose = 0, header = 0, do_alpha = 0;
-static gray    maxval;
-/*-----------------------------------------------------------------------------
- *                                        Read the pnm image file header.
- */
 static void
-read_pnm_header(void) {
+readPnmHeader(bool      const verbose,
+              bool      const wantAlpha,
+              FILE    * const ifP,
+              int     * const widthP,
+              int     * const heightP,
+              gray    * const maxvalP,
+              int     * const formatP) {
+/*-----------------------------------------------------------------------------
+  Read the pnm image file header.
+---------------------------------------------------------------------------- */
+    int   width;
+    int   height;
+    gray  maxval;
+    int   format;
+    const char * type;
+
+    pnm_readpnminit(ifP, &width, &height, &maxval, &format);
 
-    pnm_readpnminit(fp, &width, &height, &maxval, &format);
     switch (format) {
     case PBM_FORMAT:
-        VPRINTF(stderr, "Image type: plain pbm format\n");
+        type="plain pbm";
         break;
     case RPBM_FORMAT:
-        VPRINTF(stderr, "Image type: raw pbm format\n");
+        type="raw pbm";
         break;
     case PGM_FORMAT:
-        VPRINTF(stderr, "Image type: plain pgm format\n");
+        type="plain pgm";
         break;
     case RPGM_FORMAT:
-        VPRINTF(stderr, "Image type: raw pgm format\n");
+        type="raw pgm";
         break;
     case PPM_FORMAT:
-        VPRINTF(stderr, "Image type: plain ppm format\n");
+        type="plain ppm";
         break;
     case RPPM_FORMAT:
-        VPRINTF(stderr, "Image type: raw ppm format\n");
+        type="raw ppm";
         break;
     }
-    VPRINTF(stderr, "Full image: %dx%d\n", width, height);
-    VPRINTF(stderr, "Maxval:     %d\n", maxval);
-    if (do_alpha)
-        VPRINTF(stderr, "Computing alpha channel...\n");
+    if (verbose) {
+        pm_message("Image type: %s format", type);
+        pm_message("Full image: %dx%d", width, height);
+        pm_message("Maxval:     %d", maxval);
+
+        if (wantAlpha)
+            pm_message("Computing alpha channel...");
+    }
+    *widthP  = width;
+    *heightP = height;
+    *maxvalP = maxval;
+    *formatP = format;
 }
 
 
 
 static void
-write_rle_header(void) {
+writeRleHeader(bool         const wantAlpha,
+               int          const format,
+               unsigned int const width,
+               unsigned int const height,
+               rle_hdr *    const hdrP) {
+
+    rle_hdr hdr;
+
+    hdr = *hdrP;  /* initial value */
 
     hdr.xmin    = 0;
     hdr.xmax    = width-1;
     hdr.ymin    = 0;
     hdr.ymax    = height-1;
     hdr.background = 0;
+
     switch (format) {
     case PBM_FORMAT:
     case RPBM_FORMAT:
@@ -114,31 +200,42 @@ write_rle_header(void) {
         RLE_SET_BIT(hdr, RLE_BLUE);
         break;
     }
-    if (do_alpha) {
+    if (wantAlpha) {
         hdr.alpha = 1;
         RLE_SET_BIT(hdr, RLE_ALPHA);
     }
     rle_put_setup(&hdr);
+
+    *hdrP = hdr;
 }
 
 
 
 static void
-write_rle_data(void) {
+writeRleData(bool         const verbose,
+             bool         const wantAlpha,
+             FILE      *  const ifP,
+             rle_hdr   *  const hdrP,
+             unsigned int const width,
+             unsigned int const height,
+             gray         const maxval,
+             int          const format) {
 
     unsigned int scan;
     xel * xelrow;
     rle_pixel *** scanlines;
 
     MALLOCARRAY(xelrow, width);
-    MALLOCARRAY(scanlines, height);
+    if (xelrow == NULL)
+        pm_error("Failed to allocate memory for row of %u pixels", width);
 
-    if (!scanlines)
+    MALLOCARRAY(scanlines, height);
+    if (scanlines == NULL)
         pm_error("Failed to allocate memory for %u scanline pointers", height);
 
     for (scan = 0; scan < height; ++scan) {
         int rc;
-        rc = rle_row_alloc(&hdr, &scanlines[scan]);
+        rc = rle_row_alloc(hdrP, &scanlines[scan]);
         if (rc < 0)
             pm_error("Failed to allocate memory for a scanline");
     }
@@ -151,10 +248,10 @@ write_rle_data(void) {
         for (scan = 0; scan < height; ++scan) {
             rle_pixel ** const scanline = scanlines[height - scan - 1];
             unsigned int col;
-            pnm_readpnmrow(fp, xelrow, width, maxval, format);
+            pnm_readpnmrow(ifP, xelrow, width, maxval, format);
             for (col = 0; col < width; ++col) {
                 scanline[RLE_RED][col] = PNM_GET1(xelrow[col]) ? 255 : 0;
-                if (do_alpha)
+                if (wantAlpha)
                     scanline[RLE_ALPHA][col] = scanline[RLE_RED][col];
             }
         }
@@ -165,10 +262,10 @@ write_rle_data(void) {
         for (scan = 0; scan < height; ++scan) {
             rle_pixel ** const scanline = scanlines[height - scan - 1];
             unsigned int col;
-            pnm_readpnmrow(fp, xelrow, width, maxval, format);
+            pnm_readpnmrow(ifP, xelrow, width, maxval, format);
             for (col = 0; col < width; ++col) {
                 scanline[RLE_RED][col] = PNM_GET1(xelrow[col]);
-                if (do_alpha)
+                if (wantAlpha)
                     scanline[RLE_ALPHA][col] =
                         scanline[RLE_RED][col] ? 255 : 0;
             }
@@ -179,13 +276,16 @@ write_rle_data(void) {
         unsigned int scan;
         for (scan = 0; scan < height; scan++) {
             rle_pixel ** const scanline = scanlines[height - scan - 1];
+
             unsigned int col;
-            pnm_readpnmrow(fp, xelrow, width, maxval, format);
+
+            pnm_readpnmrow(ifP, xelrow, width, maxval, format);
+
             for (col = 0; col < width; ++col) {
                 scanline[RLE_RED][col]   = PPM_GETR(xelrow[col]);
                 scanline[RLE_GREEN][col] = PPM_GETG(xelrow[col]);
                 scanline[RLE_BLUE][col]  = PPM_GETB(xelrow[col]);
-                if (do_alpha)
+                if (wantAlpha)
                     scanline[RLE_ALPHA][col] =
                         (scanline[RLE_RED][col] ||
                          scanline[RLE_GREEN][col] ||
@@ -196,25 +296,27 @@ write_rle_data(void) {
     }
     /* Write out data in URT order (bottom to top). */
     for (scan = 0; scan < height; ++scan)
-        rle_putrow(scanlines[scan], width, &hdr);
+        rle_putrow(scanlines[scan], width, hdrP);
 
     for (scan = 0; scan < height; ++scan)
-        rle_row_free(&hdr, scanlines[scan]);
+        rle_row_free(hdrP, scanlines[scan]);
     free(scanlines);
     free(xelrow);
 
-    VPRINTF(stderr, "Done -- write eof to RLE data.\n");
-    rle_puteof(&hdr);
+    if (verbose)
+        pm_message("Done -- write eof to RLE data.");
+
+    rle_puteof(hdrP);
 }
 
 
 
 static void
-skip_data(FILE      * const fp,
-          int         const width,
-          int         const height,
-          gray        const maxval,
-          int         const format) {
+skipData(FILE      *  const ifP,
+         unsigned int const width,
+         unsigned int const height,
+         gray         const maxval,
+         int          const format) {
 
     xel * xelrow;
     unsigned int scan;
@@ -223,8 +325,8 @@ skip_data(FILE      * const fp,
     if (xelrow == NULL)
         pm_error("Failed to allocate memory for row of %u pixels", width);
 
-    for(scan=0; scan < height; ++scan)
-        pnm_readpnmrow(fp, xelrow, width, maxval, format);
+    for (scan=0; scan < height; ++scan)
+        pnm_readpnmrow(ifP, xelrow, width, maxval, format);
 
     free(xelrow);
 }
@@ -232,57 +334,57 @@ skip_data(FILE      * const fp,
 
 
 int
-main(int argc, char **  argv) {
-
-    const char * pnmname;
-    const char * outname;
-    int oflag;
+main(int argc, char ** argv) {
+
+    struct CmdlineInfo cmdline;
+
+    FILE   * ifP;
+    rle_hdr hdr;
+    int  format;
+    int  width, height;
+    gray maxval;
+    bool verbose;
+    const char ** argvWork;
+    unsigned int i;
     int eof;
 
-    pnm_init(&argc, argv);
-
-    pnmname = NULL;  /* initial value */
-    outname = NULL;  /* initial value */
-
-    /* Get those options. */
-    if (!scanargs(argc,argv,
-                  "% v%- h%- a%- o%-outfile!s pnmfile%s\n(\
-\tConvert a PNM file to URT RLE format.\n\
-\t-a\tFake an alpha channel.  Alpha=0 when input=0, 255 otherwise.\n\
-\t-h\tPrint header of PNM file and exit.\n\
-\t-v\tVerbose mode.)",
-                  &verbose,
-                  &header,
-                  &do_alpha,
-                  &oflag, &outname,
-                  &pnmname))
-        exit(-1);
+    MALLOCARRAY_NOFAIL(argvWork, argc + 1);
+
+    for (i = 0; i < argc; ++i)  /* Make a copy of argv */
+        argvWork[i] = argv[i];
+
+    pm_proginit(&argc, argvWork);
+
+    parseCommandLine(argc, argvWork, &cmdline);
+
+    verbose = cmdline.verbose || cmdline.header;
 
     hdr = *rle_hdr_init(NULL);
-    rle_names(&hdr, cmd_name(argv), outname, 0);
+
+    rle_names(&hdr, "pnmtorle", cmdline.outfile, 0);
 
     /* Open the file. */
-    if (pnmname == NULL) {
-        fp = pm_openr("-");
-    } else {
-        fp = pm_openr(pnmname);
-    }
+    assert(cmdline.inFileName != NULL);
+    ifP = pm_openr(cmdline.inFileName);
 
-    hdr.rle_file = rle_open_f( hdr.cmd, outname, "wb" );
+    hdr.rle_file = rle_open_f(hdr.cmd, cmdline.outfile, "wb");
 
     for (eof = 0; !eof; ) {
-        read_pnm_header();
+        readPnmHeader(verbose, cmdline.alpha, ifP,
+                      &width, &height, &maxval, &format);
 
-        if (header)
-            skip_data(fp, width, height, maxval, format);
-        else {
+        if (cmdline.header) {
+            skipData(ifP, width, height, maxval, format);
+        } else {
             rle_addhist(argv, NULL, &hdr);
-            write_rle_header();
-            write_rle_data();
+            writeRleHeader(cmdline.alpha, format, width, height, &hdr);
+            writeRleData(verbose, cmdline.alpha, ifP, &hdr,
+                         width, height, maxval, format);
         }
-        pnm_nextimage(fp, &eof);
+        pnm_nextimage(ifP, &eof);
     }
-    pm_close(fp);
+
+    pm_close(ifP);
 
     return 0;
 }
diff --git a/converter/other/pnmtosir.c b/converter/other/pnmtosir.c
index 20bb6178..7b7650fe 100644
--- a/converter/other/pnmtosir.c
+++ b/converter/other/pnmtosir.c
@@ -20,16 +20,16 @@
 
 int
 main(int argc, const char * argv[]) {
-    
+
     FILE * ifP;
     xel ** xels;
     int rows, cols, format;
     unsigned int n;
     bool isGrayscale;
     xelval maxval;
-    unsigned short Header[16];
-    unsigned short LutHeader[16];
-    unsigned short Lut[2048];
+    unsigned short Header[10];
+    unsigned short LutHeader[5];
+    unsigned short Lut[1024];
 
     pm_proginit(&argc, argv);
 
@@ -43,9 +43,9 @@ main(int argc, const char * argv[]) {
     }  else {
         ifP = stdin;
     }
-    
+
     xels = pnm_readpnm(ifP, &cols, &rows, &maxval, &format);
-    
+
     /* Figure out the colormap. */
     switch (PNM_FORMAT_TYPE(format) ) {
     case PPM_TYPE:
@@ -93,15 +93,19 @@ main(int argc, const char * argv[]) {
         pm_writelittleshort(stdout,LutHeader[n]);
     for (n = 5; n < 256; ++n)
         pm_writelittleshort(stdout,0);
- 
-    for (n = 0; n < 3; ++n) {
+
+    for (n = 0; n < 256; ++n) {
         unsigned int m;
-        for (m = 0; m < 256; ++m)
-            Lut[m * 4 + n] = m << 8;
+        for (m = 0; m < 3; ++m)
+            Lut[n * 4 + m] = n << 8;
+
+        Lut[n * 4 + 3] = 0;
+            /* Clear to ensure repeatable output, suppress Valgrind error */
     }
+
     for (n = 0; n < 1024; ++n)
         pm_writelittleshort(stdout,Lut[n]);
- 
+
     /* Finally, write out the data. */
     switch (PNM_FORMAT_TYPE(format)) {
     case PPM_TYPE: {
@@ -110,13 +114,13 @@ main(int argc, const char * argv[]) {
             unsigned int col;
             for (col = 0; col < cols; ++col) {
                 unsigned char const ub =
-                    (char) (PPM_GETR(xels[row][col]) * (255 / maxval)); 
+                    (char) (PPM_GETR(xels[row][col]) * (255 / maxval));
                 fputc(ub, stdout);
             }
         }
         for (row = 0; row < rows; ++row) {
             unsigned int col;
-            for (col = 0; col < cols; ++col) {  
+            for (col = 0; col < cols; ++col) {
                 unsigned const char ub =
                     (char) (PPM_GETG(xels[row][col]) * (255 / maxval));
                 fputc(ub, stdout);
@@ -124,7 +128,7 @@ main(int argc, const char * argv[]) {
         }
         for (row = 0; row < rows; ++row) {
             unsigned int col;
-            for (col = 0; col < cols; ++col) {  
+            for (col = 0; col < cols; ++col) {
                 unsigned const char ub =
                     (char) (PPM_GETB(xels[row][col]) * (255 / maxval));
                 fputc(ub, stdout);
@@ -144,10 +148,11 @@ main(int argc, const char * argv[]) {
         }
     } break;
     }
-    
+
     pm_close(ifP);
 
     return 0;
 }
 
 
+
diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c
index bf60748f..ec701cfc 100644
--- a/converter/ppm/picttoppm.c
+++ b/converter/ppm/picttoppm.c
@@ -35,6 +35,7 @@
 #include "pbmfont.h"
 #include "mallocvar.h"
 #include "nstring.h"
+#include "shhopt.h"
 
 
 /*
@@ -46,6 +47,82 @@ typedef unsigned short Word;
 typedef unsigned long Longword;
 
 
+struct CmdlineInfo {
+    /* All the information the user supplied in the command line,
+       in a form easy for the program to use.
+    */
+    const char * inputFileName;  /* File name of input file */
+
+    unsigned int fullres;
+    unsigned int noheader;
+    unsigned int quickdraw;
+    const char * fontdir;  /* Null if not specified */
+    unsigned int verbose;
+};
+
+
+
+static void
+parseCommandLine(int argc,
+                 const char ** argv,
+                 struct CmdlineInfo  * const cmdlineP) {
+/* --------------------------------------------------------------------------
+   Parse program command line described in Unix standard form by argc
+   and argv.  Return the information in the options as *cmdlineP.
+
+   If command line is internally inconsistent (invalid options, etc.),
+   issue error message to stderr and abort program.
+
+   Note that the strings we return are stored in the storage that
+   was passed to us as the argv array.  We also trash *argv.
+--------------------------------------------------------------------------*/
+    optEntry * option_def;
+    optStruct3 opt;
+        /* Instructions to pm_optParseOptions3 on how to parse our options. */
+
+    unsigned int option_def_index;
+
+    unsigned int fontdirSpec, verboseSpec;
+
+    MALLOCARRAY_NOFAIL(option_def, 100);
+
+    option_def_index = 0;   /* incremented by OPTENT3 */
+    OPTENT3(0, "fontdir",     OPT_STRING,    &cmdlineP->fontdir,
+            &fontdirSpec,                     0);
+    OPTENT3(0, "fullres",     OPT_FLAG,      NULL,
+            &cmdlineP->fullres,               0);
+    OPTENT3(0, "noheader",    OPT_FLAG,      NULL,
+            &cmdlineP->noheader,              0);
+    OPTENT3(0, "quickdraw",   OPT_FLAG,      NULL,
+            &cmdlineP->quickdraw,             0);
+    OPTENT3(0, "verbose",     OPT_UINT,      &cmdlineP->verbose,
+            &verboseSpec,               0);
+
+    opt.opt_table = option_def;
+    opt.short_allowed = false;  /* We have no short (old-fashioned) options */
+    opt.allowNegNum = false;   /* We have no parms that are negative numbers */
+
+    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
+        /* Uses and sets argc, argv, and some of *cmdlineP and others. */
+
+    if (!fontdirSpec)
+        cmdlineP->fontdir = NULL;
+
+    if (!verboseSpec)
+        cmdlineP->verbose = 0;
+
+    if (argc-1 < 1)
+        cmdlineP->inputFileName = "-";
+    else {
+        cmdlineP->inputFileName = argv[1];
+        if (argc-1 > 1)
+            pm_error("Too many arguments: %u.  The only possible non-option "
+                     "argument is the input file name", argc-1);
+    }
+}
+
+
+
 /*
  * Data structures for QuickDraw (and hence PICT) stuff.
  */
@@ -65,20 +142,20 @@ struct Rect {
     /* "End" means last plus one */
 };
 
-struct pixMap {
+struct PixMap {
     struct Rect Bounds;
-    Word version;
-    Word packType;
-    Longword packSize;
-    Longword hRes;
-    Longword vRes;
-    Word pixelType;
-    Word pixelSize;
-    Word cmpCount;
-    Word cmpSize;
-    Longword planeBytes;
-    Longword pmTable;
-    Longword pmReserved;
+    Word        version;
+    Word        packType;
+    Longword    packSize;
+    Longword    hRes;
+    Longword    vRes;
+    Word        pixelType;
+    Word        pixelSize;
+    Word        cmpCount;
+    Word        cmpSize;
+    Longword    planeBytes;
+    Longword    pmTable;
+    Longword    pmReserved;
 };
 
 struct RGBColor {
@@ -109,7 +186,7 @@ struct RgbPlanes {
     Word * blu;
 };
 
-struct canvas {
+struct Canvas {
     struct RgbPlanes planes;
 };
 
@@ -120,7 +197,6 @@ static struct Rect picFrame;
 static Word rowlen;
 static Word collen;
 static int verbose;
-static int fullres;
 static int recognize_comment;
 
 static struct RGBColor black = { 0, 0, 0 };
@@ -157,7 +233,7 @@ static int ps_cent_x;
 static int ps_cent_y;
 static int ps_cent_set;
 
-struct raster {
+struct Raster {
 /*----------------------------------------------------------------------------
    An image raster.  May be either truecolor or paletted.
 
@@ -188,7 +264,7 @@ struct raster {
 
 
 static void
-allocateRaster(struct raster * const rasterP,
+allocateRaster(struct Raster * const rasterP,
                unsigned int    const width,
                unsigned int    const height,
                unsigned int    const bitsPerPixel) {
@@ -217,19 +293,24 @@ allocateRaster(struct raster * const rasterP,
         /* TODO: I'm still trying to figure out this format.
 
            My theory today:
-           The row data is in plane order (a row consists of red
-           plane, then, green, then blue, then some 4th plane).
 
-           The old hack code said 3 bytes per pixel here, and could get
-           away with it because it never got to decoding the 4th plane.
+           The row data is in plane order (a row consists of red plane, then,
+           green, then blue, then some 4th plane).
+
+           If the image is compressed, each row is compressed separately, with
+           the planes opaque to the compressor.
 
-           But the new clean code needs to tell it like it is and allocate
-           4 bytes per pixel.  If we say 3 bytes per pixel here, we get an
-           "invalid PICT" error because the image actually contains 4
-           bytes per pixel and as we decompress it, we run out of place
-           to put the data.
+           The old hack code said 3 bytes per pixel here, and could get away
+           with it because it never got to decoding the 4th plane.
 
-           We have yet to see if we can properly interpret the data.
+           But the new clean code needs to tell it like it is and allocate 4
+           bytes per pixel.  If we say 3 bytes per pixel here, we get an
+           "invalid PICT" error on one image because the image actually
+           contains 4 bytes per pixel and as we decompress it, we run out of
+           place to put the data.
+
+           On another image we've seen, the decompressor generates 3 bytes per
+           pixel.
         */
 
         rasterP->rowSize = allocWidth * 4;
@@ -259,37 +340,37 @@ allocateRaster(struct raster * const rasterP,
 
 
 static void
-freeRaster(struct raster const raster) {
+freeRaster(struct Raster const raster) {
 
     free(raster.bytes);
 }
 
 
-struct blit_info {
-    struct Rect        srcRect;
-    struct Rect        srcBounds;
-    struct raster      srcplane;
-    int                pixSize;
-    struct Rect        dstRect;
-    struct RGBColor *  colorMap;
-    int                mode;
-    struct blit_info * next;
+struct BlitInfo {
+    struct Rect       srcRect;
+    struct Rect       srcBounds;
+    struct Raster     srcplane;
+    int               pixSize;
+    struct Rect       dstRect;
+    struct RGBColor * colorMap;
+    int               mode;
+    struct BlitInfo * next;
 };
 
 typedef struct {
-    struct blit_info * firstP;
-    struct blit_info ** connectorP;
+    struct BlitInfo * firstP;
+    struct BlitInfo ** connectorP;
     bool unblittableText;
         /* The image contains text opcodes, and we don't know how to put that
            in a blit list (I really don't even know what a blit _is_), so
            the image information here is incomplete.
         */
-} blitList;
+} BlitList;
 
 
-typedef void (drawFn)(struct canvas *, blitList *, int);
+typedef void (drawFn)(FILE *, struct Canvas *, BlitList *, int);
 
-struct opdef {
+struct Opdef {
     const char* name;
     int len;
         /* If non-negative, this is the length of the argument of the
@@ -322,16 +403,15 @@ struct opdef {
 #define RGB_LEN (6)
 
 
-static FILE* ifp;
 static int align = 0;
 
 
 
 static Byte
-readByte(void) {
+readByte(FILE * const ifP) {
     int c;
 
-    if ((c = fgetc(ifp)) == EOF)
+    if ((c = fgetc(ifP)) == EOF)
         pm_error("EOF / read error while %s", stage);
 
     ++align;
@@ -341,27 +421,29 @@ readByte(void) {
 
 
 static Word
-readWord(void) {
+readWord(FILE * const ifP) {
 
-    Byte const hi = readByte();
-    Byte const lo = readByte();
+    Byte const hi = readByte(ifP);
+    Byte const lo = readByte(ifP);
 
     return (hi << 8) | (lo << 0);
 }
 
 
 
-static void readPoint(struct Point * const p) {
-    p->y = readWord();
-    p->x = readWord();
+static void readPoint(FILE *         const ifP,
+                      struct Point * const p) {
+    p->y = readWord(ifP);
+    p->x = readWord(ifP);
 }
 
 
 
 static Longword
-readLong(void) {
-    Word const hi = readWord();
-    Word const lo = readWord();
+readLong(FILE * const ifP) {
+
+    Word const hi = readWord(ifP);
+    Word const lo = readWord(ifP);
 
     return (hi << 16) | (lo << 0);
 }
@@ -369,40 +451,45 @@ readLong(void) {
 
 
 static SignedByte
-readSignedByte(void) {
-    return (SignedByte)readByte();
+readSignedByte(FILE * const ifP) {
+    return (SignedByte)readByte(ifP);
 }
 
 
 
 static void
-readShortPoint(struct Point * const p) {
-    p->x = readSignedByte();
-    p->y = readSignedByte();
+readShortPoint(FILE *         const ifP,
+               struct Point * const p) {
+
+    p->x = readSignedByte(ifP);
+    p->y = readSignedByte(ifP);
 }
 
 
 
 static void
-skip(int const byteCount) {
-    static Byte buf[1024];
+skip(FILE *       const ifP,
+     unsigned int const byteCount) {
+
+    Byte buf[1024];
     int n;
 
     align += byteCount;
 
-    for (n = byteCount; n > 0; n -= 1024)
-        if (fread(buf, n > 1024 ? 1024 : n, 1, ifp) != 1)
+    for (n = byteCount; n > 0; n -= 1024) {
+        if (fread(buf, n > 1024 ? 1024 : n, 1, ifP) != 1)
             pm_error("EOF / read error while %s", stage);
+    }
 }
 
 
 
-struct const_name {
+struct ConstName {
     int value;
     const char * name;
 };
 
-struct const_name const transfer_name[] = {
+struct ConstName const transfer_name[] = {
     { 0,    "srcCopy" },
     { 1,    "srcOr" },
     { 2,    "srcXor" },
@@ -422,7 +509,7 @@ struct const_name const transfer_name[] = {
     { -1,   0 }
 };
 
-struct const_name font_name[] = {
+struct ConstName font_name[] = {
     { 0,    "systemFont" },
     { 1,    "applFont" },
     { 2,    "newYork" },
@@ -443,7 +530,7 @@ struct const_name font_name[] = {
     { -1,   0 }
 };
 
-struct const_name ps_just_name[] = {
+struct ConstName ps_just_name[] = {
     { 0,    "no" },
     { 1,    "left" },
     { 2,    "center" },
@@ -452,7 +539,7 @@ struct const_name ps_just_name[] = {
     { -1,   0 }
 };
 
-struct const_name ps_flip_name[] = {
+struct ConstName ps_flip_name[] = {
     { 0,    "no" },
     { 1,    "horizontal" },
     { 2,    "vertical" },
@@ -462,8 +549,8 @@ struct const_name ps_flip_name[] = {
 
 
 static const char*
-const_name(const struct const_name * const table,
-           unsigned int              const ct) {
+constName(const struct ConstName * const table,
+          unsigned int             const ct) {
 
     static char numbuf[32];
 
@@ -480,8 +567,9 @@ const_name(const struct const_name * const table,
 
 
 static void
-picComment(Word const type,
-           int const length) {
+picComment(FILE * const ifP,
+           Word   const type,
+           int    const length) {
 
     unsigned int remainingLength;
 
@@ -489,10 +577,10 @@ picComment(Word const type,
     case 150:
         if (verbose) pm_message("TextBegin");
         if (length >= 6) {
-            ps_just = readByte();
-            ps_flip = readByte();
-            ps_rotation = readWord();
-            ps_linespace = readByte();
+            ps_just = readByte(ifP);
+            ps_flip = readByte(ifP);
+            ps_rotation = readWord(ifP);
+            ps_linespace = readByte(ifP);
             remainingLength = length - 5;
             if (recognize_comment)
                 ps_text = 1;
@@ -500,8 +588,8 @@ picComment(Word const type,
             if (verbose) {
                 pm_message("%s justification, %s flip, %d degree rotation, "
                            "%d/2 linespacing",
-                           const_name(ps_just_name, ps_just),
-                           const_name(ps_flip_name, ps_flip),
+                           constName(ps_just_name, ps_just),
+                           constName(ps_flip_name, ps_flip),
                            ps_rotation, ps_linespace);
             }
         } else
@@ -525,14 +613,14 @@ picComment(Word const type,
         if (length < 8)
             remainingLength = length;
         else {
-            ps_cent_y = readWord();
+            ps_cent_y = readWord(ifP);
             if (ps_cent_y > 32767)
                 ps_cent_y -= 65536;
-            skip(2); /* ignore fractional part */
-            ps_cent_x = readWord();
+            skip(ifP, 2); /* ignore fractional part */
+            ps_cent_x = readWord(ifP);
             if (ps_cent_x > 32767)
                 ps_cent_x -= 65536;
-            skip(2); /* ignore fractional part */
+            skip(ifP, 2); /* ignore fractional part */
             remainingLength = length - 8;
             if (verbose)
                 pm_message("offset %d %d", ps_cent_x, ps_cent_y);
@@ -628,7 +716,7 @@ picComment(Word const type,
         break;
     }
     if (remainingLength > 0)
-        skip(remainingLength);
+        skip(ifP, remainingLength);
 }
 
 
@@ -636,11 +724,12 @@ picComment(Word const type,
 static drawFn ShortComment;
 
 static void
-ShortComment(struct canvas * const canvasP,
-             blitList *      const blitListP,
+ShortComment(FILE *          const ifP,
+             struct Canvas * const canvasP,
+             BlitList *      const blitListP,
              int             const version) {
 
-    picComment(readWord(), 0);
+    picComment(ifP, readWord(ifP), 0);
 }
 
 
@@ -648,27 +737,29 @@ ShortComment(struct canvas * const canvasP,
 static drawFn LongComment;
 
 static void
-LongComment(struct canvas * const canvasP,
-            blitList *      const blitListP,
+LongComment(FILE *          const ifP,
+            struct Canvas * const canvasP,
+            BlitList *      const blitListP,
             int             const version) {
 
     Word type;
 
-    type = readWord();
-    picComment(type, readWord());
+    type = readWord(ifP);
+    picComment(ifP, type, readWord(ifP));
 }
 
 
 
-static drawFn skip_poly_or_region;
+static drawFn skipPolyOrRegion;
 
 static void
-skip_poly_or_region(struct canvas * const canvasP,
-                    blitList *      const blitListP,
-                    int             const version) {
+skipPolyOrRegion(FILE *          const ifP,
+                 struct Canvas * const canvasP,
+                 BlitList *      const blitListP,
+                 int             const version) {
 
     stage = "skipping polygon or region";
-    skip(readWord() - 2);
+    skip(ifP, readWord(ifP) - 2);
 }
 
 
@@ -684,17 +775,17 @@ skip_poly_or_region(struct canvas * const canvasP,
 
 /* Some font searching routines */
 
-struct fontinfo {
+struct FontInfo {
     int font;
     int size;
     int style;
     char* filename;
     struct font* loaded;
-    struct fontinfo* next;
+    struct FontInfo* next;
 };
 
-static struct fontinfo* fontlist = 0;
-static struct fontinfo** fontlist_ins = &fontlist;
+static struct FontInfo* fontlist = 0;
+static struct FontInfo** fontlist_ins = &fontlist;
 
 
 
@@ -729,9 +820,9 @@ tokenize(char *         const s,
 
 static void
 parseFontLine(const char **      const token,
-              struct fontinfo ** const fontinfoPP) {
+              struct FontInfo ** const fontinfoPP) {
 
-    struct fontinfo * fontinfoP;
+    struct FontInfo * fontinfoP;
 
     MALLOCVAR(fontinfoP);
     if (fontinfoP == NULL)
@@ -752,7 +843,7 @@ parseFontLine(const char **      const token,
 
 
 static int
-load_fontdir(const char * const dirfile) {
+loadFontdir(const char * const dirfile) {
 /*----------------------------------------------------------------------------
    Load the font directory from file named 'dirfile'.  Add its contents
    to the global list of fonts 'fontlist'.
@@ -777,7 +868,7 @@ load_fontdir(const char * const dirfile) {
         } else if (nToken != 4) {
             /* Unrecognized format - ignore */
         } else {
-            struct fontinfo * fontinfoP;
+            struct FontInfo * fontinfoP;
 
             parseFontLine(token, &fontinfoP);
 
@@ -795,6 +886,23 @@ load_fontdir(const char * const dirfile) {
 
 
 static void
+loadDefaultFontDir(void) {
+/*----------------------------------------------------------------------------
+   Load the fonts from the font directory file "fontdir" (in the current
+   directory), if it exists.
+-----------------------------------------------------------------------------*/
+    struct stat statbuf;
+    int rc;
+
+    rc = stat("fontdir", &statbuf);
+
+    if (rc == 0)
+        loadFontdir("fontdir");
+}
+
+
+
+static void
 dumpRect(const char * const label,
          struct Rect  const rectangle) {
 
@@ -807,7 +915,8 @@ dumpRect(const char * const label,
 
 
 static void
-readRect(struct Rect * const r) {
+readRect(FILE *        const ifP,
+         struct Rect * const r) {
 
     /* We don't have a formal specification for the Pict format, but we have
        seen samples that have the rectangle corners either in top left, bottom
@@ -819,10 +928,10 @@ readRect(struct Rect * const r) {
        So now we accept all 4 possibilities.
     */
 
-    Word const y1 = readWord();
-    Word const x1 = readWord();
-    Word const y2 = readWord();
-    Word const x2 = readWord();
+    Word const y1 = readWord(ifP);
+    Word const x1 = readWord(ifP);
+    Word const y2 = readWord(ifP);
+    Word const x2 = readWord(ifP);
 
     r->top    = MIN(y1, y2);
     r->left   = MIN(x1, x2);
@@ -909,7 +1018,7 @@ rectscale(struct Rect * const r,
 
 
 static void
-initBlitList(blitList * const blitListP) {
+initBlitList(BlitList * const blitListP) {
 
     blitListP->firstP          = NULL;
     blitListP->connectorP      = &blitListP->firstP;
@@ -919,16 +1028,16 @@ initBlitList(blitList * const blitListP) {
 
 
 static void
-addBlitList(blitList *        const blitListP,
+addBlitList(BlitList *        const blitListP,
             struct Rect       const srcRect,
             struct Rect       const srcBounds,
-            struct raster     const srcplane,
+            struct Raster     const srcplane,
             int               const pixSize,
             struct Rect       const dstRect,
             struct RGBColor * const colorMap,
             int               const mode) {
 
-    struct blit_info * biP;
+    struct BlitInfo * biP;
 
     MALLOCVAR(biP);
     if (biP == NULL)
@@ -945,7 +1054,7 @@ addBlitList(blitList *        const blitListP,
         biP->next = NULL;
 
         *blitListP->connectorP = biP;
-        blitListP->connectorP = &biP->next;
+        blitListP->connectorP  = &biP->next;
     }
 }
 
@@ -970,12 +1079,15 @@ rgbAllSame(const struct RGBColor * const colorP,
 }
 
 
+
 static bool
 rgbIsWhite(const struct RGBColor * const colorP) {
 
     return rgbAllSame(colorP, 0xffff);
 }
 
+
+
 static bool
 rgbIsBlack(const struct RGBColor * const colorP) {
 
@@ -983,122 +1095,133 @@ rgbIsBlack(const struct RGBColor * const colorP) {
 }
 
 
+
 static void
-srcCopy(struct RGBColor * const src,
-        struct RGBColor * const dst) {
+srcCopy(struct RGBColor * const srcP,
+        struct RGBColor * const dstP) {
 
-    if (rgbIsBlack(src))
-        *dst = foreground;
+    if (rgbIsBlack(srcP))
+        *dstP = foreground;
     else
-        *dst = background;
+        *dstP = background;
 }
 
 
 
 static void
-srcOr(struct RGBColor * const src,
-      struct RGBColor * const dst) {
-    if (rgbIsBlack(src))
-        *dst = foreground;
+srcOr(struct RGBColor * const srcP,
+      struct RGBColor * const dstP) {
+
+    if (rgbIsBlack(srcP))
+        *dstP = foreground;
 }
 
 
 
 static void
-srcXor(struct RGBColor * const src,
-       struct RGBColor * const dst) {
-    dst->red ^= ~src->red;
-    dst->grn ^= ~src->grn;
-    dst->blu ^= ~src->blu;
+srcXor(struct RGBColor * const srcP,
+       struct RGBColor * const dstP) {
+
+    dstP->red ^= ~srcP->red;
+    dstP->grn ^= ~srcP->grn;
+    dstP->blu ^= ~srcP->blu;
 }
 
 
 
 static void
-srcBic(struct RGBColor * const src,
-       struct RGBColor * const dst) {
-    if (rgbIsBlack(src))
-        *dst = background;
+srcBic(struct RGBColor * const srcP,
+       struct RGBColor * const dstP) {
+
+    if (rgbIsBlack(srcP))
+        *dstP = background;
 }
 
 
 
 static void
-notSrcCopy(struct RGBColor * const src,
-           struct RGBColor * const dst) {
-    if (rgbIsWhite(src))
-        *dst = foreground;
-    else if (rgbIsBlack(src))
-        *dst = background;
+notSrcCopy(struct RGBColor * const srcP,
+           struct RGBColor * const dstP) {
+
+    if (rgbIsWhite(srcP))
+        *dstP = foreground;
+    else if (rgbIsBlack(srcP))
+        *dstP = background;
 }
 
 
 
 static void
-notSrcOr(struct RGBColor * const src,
-         struct RGBColor * const dst) {
-    if (rgbIsWhite(src))
-        *dst = foreground;
+notSrcOr(struct RGBColor * const srcP,
+         struct RGBColor * const dstP) {
+
+    if (rgbIsWhite(srcP))
+        *dstP = foreground;
 }
 
 
 
 static void
-notSrcBic(struct RGBColor * const src,
-          struct RGBColor * const dst) {
-    if (rgbIsWhite(src))
-        *dst = background;
+notSrcBic(struct RGBColor * const srcP,
+          struct RGBColor * const dstP) {
+
+    if (rgbIsWhite(srcP))
+        *dstP = background;
 }
 
 
 
 static void
-notSrcXor(struct RGBColor * const src,
-          struct RGBColor * const dst) {
-    dst->red ^= src->red;
-    dst->grn ^= src->grn;
-    dst->blu ^= src->blu;
+notSrcXor(struct RGBColor * const srcP,
+          struct RGBColor * const dstP) {
+
+    dstP->red ^= srcP->red;
+    dstP->grn ^= srcP->grn;
+    dstP->blu ^= srcP->blu;
 }
 
 
 
 static void
-addOver(struct RGBColor * const src,
-        struct RGBColor * const dst) {
-    dst->red += src->red;
-    dst->grn += src->grn;
-    dst->blu += src->blu;
+addOver(struct RGBColor * const srcP,
+        struct RGBColor * const dstP) {
+
+    dstP->red += srcP->red;
+    dstP->grn += srcP->grn;
+    dstP->blu += srcP->blu;
 }
 
 
 
 static void
-addPin(struct RGBColor * const src,
-       struct RGBColor * const dst) {
-    if ((long)dst->red + (long)src->red > (long)op_color.red)
-        dst->red = op_color.red;
+addPin(struct RGBColor * const srcP,
+       struct RGBColor * const dstP) {
+
+    if ((long)dstP->red + (long)srcP->red > (long)op_color.red)
+        dstP->red = op_color.red;
     else
-        dst->red = dst->red + src->red;
+        dstP->red = dstP->red + srcP->red;
 
-    if ((long)dst->grn + (long)src->grn > (long)op_color.grn)
-        dst->grn = op_color.grn;
+    if ((long)dstP->grn + (long)srcP->grn > (long)op_color.grn)
+        dstP->grn = op_color.grn;
     else
-        dst->grn = dst->grn + src->grn;
+        dstP->grn = dstP->grn + srcP->grn;
 
-    if ((long)dst->blu + (long)src->blu > (long)op_color.blu)
-        dst->blu = op_color.blu;
+    if ((long)dstP->blu + (long)srcP->blu > (long)op_color.blu)
+        dstP->blu = op_color.blu;
     else
-        dst->blu = dst->blu + src->blu;
+        dstP->blu = dstP->blu + srcP->blu;
 }
 
 
 
 static void
-subOver(struct RGBColor * const src,
-        struct RGBColor * const dst) {
-    dst->red -= src->red;
-    dst->grn -= src->grn;
-    dst->blu -= src->blu;
+subOver(struct RGBColor * const srcP,
+        struct RGBColor * const dstP) {
+
+    dstP->red -= srcP->red;
+    dstP->grn -= srcP->grn;
+    dstP->blu -= srcP->blu;
 }
 
 
@@ -1107,74 +1230,81 @@ subOver(struct RGBColor * const src,
 
 
 static void
-subPin(struct RGBColor * const src,
-       struct RGBColor * const dst) {
-    if ((long)dst->red - (long)src->red < (long)op_color.red)
-        dst->red = op_color.red;
+subPin(struct RGBColor * const srcP,
+       struct RGBColor * const dstP) {
+
+    if ((long)dstP->red - (long)srcP->red < (long)op_color.red)
+        dstP->red = op_color.red;
     else
-        dst->red = dst->red - src->red;
+        dstP->red = dstP->red - srcP->red;
 
-    if ((long)dst->grn - (long)src->grn < (long)op_color.grn)
-        dst->grn = op_color.grn;
+    if ((long)dstP->grn - (long)srcP->grn < (long)op_color.grn)
+        dstP->grn = op_color.grn;
     else
-        dst->grn = dst->grn - src->grn;
+        dstP->grn = dstP->grn - srcP->grn;
 
-    if ((long)dst->blu - (long)src->blu < (long)op_color.blu)
-        dst->blu = op_color.blu;
+    if ((long)dstP->blu - (long)srcP->blu < (long)op_color.blu)
+        dstP->blu = op_color.blu;
     else
-        dst->blu = dst->blu - src->blu;
+        dstP->blu = dstP->blu - srcP->blu;
 }
 
 
 
 static void
-adMax(struct RGBColor * const src,
-      struct RGBColor * const dst) {
-    if (src->red > dst->red) dst->red = src->red;
-    if (src->grn > dst->grn) dst->grn = src->grn;
-    if (src->blu > dst->blu) dst->blu = src->blu;
+adMax(struct RGBColor * const srcP,
+      struct RGBColor * const dstP) {
+
+    if (srcP->red > dstP->red) dstP->red = srcP->red;
+    if (srcP->grn > dstP->grn) dstP->grn = srcP->grn;
+    if (srcP->blu > dstP->blu) dstP->blu = srcP->blu;
 }
 
 
 
 static void
-adMin(struct RGBColor * const src,
-      struct RGBColor * const dst) {
-    if (src->red < dst->red) dst->red = src->red;
-    if (src->grn < dst->grn) dst->grn = src->grn;
-    if (src->blu < dst->blu) dst->blu = src->blu;
+adMin(struct RGBColor * const srcP,
+      struct RGBColor * const dstP) {
+
+    if (srcP->red < dstP->red) dstP->red = srcP->red;
+    if (srcP->grn < dstP->grn) dstP->grn = srcP->grn;
+    if (srcP->blu < dstP->blu) dstP->blu = srcP->blu;
 }
 
 
 
 static void
-blend(struct RGBColor * const src,
-      struct RGBColor * const dst) {
+blend(struct RGBColor * const srcP,
+      struct RGBColor * const dstP) {
+
 #define blend_component(cmp)    \
-    ((long)src->cmp * (long)op_color.cmp) / 65536 +    \
-    ((long)dst->cmp * (long)(65536 - op_color.cmp) / 65536)
+    ((long)srcP->cmp * (long)op_color.cmp) / 65536 +    \
+    ((long)dstP->cmp * (long)(65536 - op_color.cmp) / 65536)
 
-    dst->red = blend_component(red);
-    dst->grn = blend_component(grn);
-    dst->blu = blend_component(blu);
+    dstP->red = blend_component(red);
+    dstP->grn = blend_component(grn);
+    dstP->blu = blend_component(blu);
 }
 
 
 
 static void
-transparent(struct RGBColor * const src,
-            struct RGBColor * const dst) {
-    if (src->red != background.red ||
-        src->grn != background.grn ||
-        src->blu != background.blu) {
-        *dst = *src;
+transparent(struct RGBColor * const srcP,
+            struct RGBColor * const dstP) {
+
+    if (srcP->red != background.red ||
+        srcP->grn != background.grn ||
+        srcP->blu != background.blu) {
+
+        *dstP = *srcP;
     }
 }
 
 
 
 static transfer_func
-transfer(int const mode) {
+transferFunctionForMode(unsigned int const mode) {
+
     switch (mode) {
     case  0: return srcCopy;
     case  1: return srcOr;
@@ -1193,9 +1323,8 @@ transfer(int const mode) {
     case 38: return subOver;
     case 39: return adMin;
     default:
-        if (mode != 0)
-            pm_message("no transfer function for code %s, using srcCopy",
-                const_name(transfer_name, mode));
+        pm_message("no transfer function for code %s, using srcCopy",
+                   constName(transfer_name, mode));
         return srcCopy;
     }
 }
@@ -1447,186 +1576,171 @@ putRgb(struct RGBColor  const rgb,
 
 
 static void
-doSameSize(transfer_func           trf,
-           int               const pixSize,
-           struct Rect       const srcRect,
-           unsigned char *   const src,
-           unsigned int      const srcwid,
-           struct RGBColor * const color_map,
-           struct RgbPlanes  const dst,
-           unsigned int      const dstwid) {
-/*----------------------------------------------------------------------------
-   Transfer pixels from 'src' to 'dst', applying the transfer function
-   'trf'.
+doSameSize8bpp(transfer_func           trf,
+               unsigned int      const xsize,
+               unsigned int      const ysize,
+               unsigned char *   const src,
+               unsigned int      const srcwid,
+               struct RGBColor * const colorMap,
+               struct RgbPlanes  const dst,
+               unsigned int      const dstwid) {
+
+    unsigned int rowNumber;
+
+    for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
+        unsigned char * const srcrow = &src[rowNumber * srcwid];
+        unsigned int const dstRowCurs = rowNumber * dstwid;
+
+        unsigned int colNumber;
+        for (colNumber = 0; colNumber < xsize; ++colNumber) {
+            unsigned int const dstCursor = dstRowCurs + colNumber;
+            unsigned int const colorIndex = srcrow[colNumber];
+
+            if (trf) {
+                struct RGBColor dstColor;
 
-   'src' has the same format as the 'bytes' member of struct raster.
-   'srcwid' is the size in bytes of each row, like raster.rowSize.
+                getRgb(dst, dstCursor, &dstColor);
+                (*trf)(&colorMap[colorIndex], &dstColor);
+                putRgb(dstColor, dstCursor, dst);
+            } else
+                putRgb(colorMap[colorIndex], dstCursor, dst);
+        }
+    }
+}
 
-   We use only the first 'ysize' rows and only the first 'xsize'
-   pixels of each row.
 
-   We really should clean this up so that we can take pixels out of
-   the middle of a row and rows out of the middle of the raster.  As
-   it stands, Caller achieves the same result by passing as 'src'
-   a pointer into the middle of a raster -- the upper left corner of
-   the rectangle he wants.  But that is messy and nonobvious.
 
-   Each plane of 'dst' is one word per pixel and contains actual
-   colors, never a palette index.  It is an array in row-major order
-   with 'dstwid' words per row.
------------------------------------------------------------------------------*/
-    unsigned int const xsize = rectwidth(&srcRect);
-    unsigned int const ysize = rectheight(&srcRect);
+static void
+doSameSize16bpp(transfer_func           trf,
+                unsigned int      const xsize,
+                unsigned int      const ysize,
+                unsigned char *   const src,
+                unsigned int      const srcwid,
+                struct RgbPlanes  const dst,
+                unsigned int      const dstwid) {
 
-    switch (pixSize) {
-    case 8: {
-        unsigned int rowNumber;
+    unsigned int rowNumber;
 
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const srcrow = &src[rowNumber * srcwid];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
+    for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
+        unsigned char * const row = &src[rowNumber * srcwid];
+        unsigned int const dstRowCurs = rowNumber * dstwid;
 
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const dstCursor = dstRowCurs + colNumber;
-                unsigned int const colorIndex = srcrow[colNumber];
-                struct RGBColor dstColor;
-                getRgb(dst, dstCursor, &dstColor);
-                (*trf)(&color_map[colorIndex], &dstColor);
-                putRgb(dstColor, dstCursor, dst);
-            }
-        }
-    } break;
-    case 16: {
-        unsigned int rowNumber;
+        unsigned int colNumber;
+        for (colNumber = 0; colNumber < xsize; ++colNumber) {
+            unsigned int const dstCursor = dstRowCurs + colNumber;
+            struct RGBColor const srcColor = decode16(&row[colNumber*2]);
+
+            struct RGBColor scaledSrcColor;
 
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const row = &src[rowNumber * srcwid];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
+            scaledSrcColor.red = srcColor.red << 11;
+            scaledSrcColor.grn = srcColor.grn << 11;
+            scaledSrcColor.blu = srcColor.blu << 11;
 
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const dstCursor = dstRowCurs + colNumber;
-                struct RGBColor const srcColor = decode16(&row[colNumber*2]);
+            if (trf) {
                 struct RGBColor dstColor;
-                struct RGBColor scaledSrcColor;
-                scaledSrcColor.red = srcColor.red << 11;
-                scaledSrcColor.grn = srcColor.grn << 11;
-                scaledSrcColor.blu = srcColor.blu << 11;
+
                 getRgb(dst, dstCursor, &dstColor);
                 (*trf)(&scaledSrcColor, &dstColor);
                 putRgb(dstColor, dstCursor, dst);
-            }
+            } else
+                putRgb(scaledSrcColor, dstCursor, dst);
         }
-    } break;
-    case 32: {
-        unsigned int const planeSize = xsize;
-        unsigned int rowNumber;
+    }
+}
+
+
+
+static void
+doSameSize32bpp(transfer_func           trf,
+                unsigned int      const xsize,
+                unsigned int      const ysize,
+                unsigned char *   const src,
+                unsigned int      const srcwid,
+                struct RgbPlanes  const dst,
+                unsigned int      const dstwid) {
+
+    unsigned int const planeSize = xsize;
+
+    unsigned int rowNumber;
+
+    for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
+        unsigned char * const row = &src[rowNumber * srcwid];
+        unsigned char * const redPlane = &row[planeSize * 0];
+        unsigned char * const grnPlane = &row[planeSize * 1];
+        unsigned char * const bluPlane = &row[planeSize * 2];
+        unsigned int const dstRowCurs = rowNumber * dstwid;
 
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const row = &src[rowNumber * srcwid];
-            unsigned char * const redPlane = &row[planeSize * 0];
-            unsigned char * const grnPlane = &row[planeSize * 1];
-            unsigned char * const bluPlane = &row[planeSize * 2];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
+        unsigned int colNumber;
 
-            unsigned int colNumber;
+        for (colNumber = 0; colNumber < xsize; ++colNumber) {
+            unsigned int const dstCursor = dstRowCurs + colNumber;
+
+            struct RGBColor srcColor;
+
+            srcColor.red = redPlane[colNumber] << 8;
+            srcColor.grn = grnPlane[colNumber] << 8;
+            srcColor.blu = bluPlane[colNumber] << 8;
+
+            if (trf) {
+                struct RGBColor dstColor;
 
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const dstCursor = dstRowCurs + colNumber;
-                struct RGBColor srcColor, dstColor;
                 getRgb(dst, dstCursor, &dstColor);
-                srcColor.red = redPlane[colNumber] << 8;
-                srcColor.grn = grnPlane[colNumber] << 8;
-                srcColor.blu = bluPlane[colNumber] << 8;
                 (*trf)(&srcColor, &dstColor);
                 putRgb(dstColor, dstCursor, dst);
-            }
+            } else
+                putRgb(srcColor, dstCursor, dst);
         }
-    } break;
-    default:
-        pm_error("Impossible value of pixSize: %u", pixSize);
     }
 }
 
 
 
 static void
-blitIdempotent(unsigned int          const pixSize,
-               struct Rect           const srcRect,
-               unsigned char *       const src,
-               unsigned int          const srcwid,
-               struct RGBColor *     const colorMap,
-               struct RgbPlanes      const dst,
-               unsigned int          const dstwid) {
+doSameSize(transfer_func           trf,
+           int               const pixSize,
+           struct Rect       const srcRect,
+           unsigned char *   const src,
+           unsigned int      const srcwid,
+           struct RGBColor * const colorMap,
+           struct RgbPlanes  const dst,
+           unsigned int      const dstwid) {
 /*----------------------------------------------------------------------------
-  This is the same as doSameSize(), except optimized for the case that
-  the transfer function is idempotent (i.e. it's just a straight copy).
-  The original author's comments suggest that this optimization isn't
-  all that important -- that he just wrote this first and instead of
-  expanding it to handle arbitrary transfer functions, added functions
-  for that.
+   Transfer pixels from 'src' to 'dst', applying the transfer function
+   'trf'.
+
+   'src' has the same format as the 'bytes' member of struct Raster.
+   'srcwid' is the size in bytes of each row, like raster.rowSize.
+   Note that there may be padding in there; there isn't necessarily
+   'srcwid' bytes of information in a row.
+
+   We use only the first 'ysize' rows and only the first 'xsize'
+   pixels of each row.
+
+   We really should clean this up so that we can take pixels out of
+   the middle of a row and rows out of the middle of the raster.  As
+   it stands, Caller achieves the same result by passing as 'src'
+   a pointer into the middle of a raster -- the upper left corner of
+   the rectangle he wants.  But that is messy and nonobvious.
+
+   Each plane of 'dst' is one word per pixel and contains actual
+   colors, never a palette index.  It is an array in row-major order
+   with 'dstwid' words per row.
 -----------------------------------------------------------------------------*/
     unsigned int const xsize = rectwidth(&srcRect);
     unsigned int const ysize = rectheight(&srcRect);
 
     switch (pixSize) {
-    case 8: {
-        unsigned int rowNumber;
-
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const srcrow = &src[rowNumber * srcwid];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const dstCursor = dstRowCurs + colNumber;
-                struct RGBColor * const ct = colorMap + srcrow[colNumber];
-                dst.red[dstCursor] = ct->red;
-                dst.grn[dstCursor] = ct->grn;
-                dst.blu[dstCursor] = ct->blu;
-            }
-        }
-    } break;
-    case 16: {
-        unsigned int rowNumber;
-
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const srcrow = &src[rowNumber * srcwid];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const dstCursor = dstRowCurs + colNumber;
-                struct RGBColor const srcColor =
-                    decode16(&srcrow[colNumber * 2]);
-                dst.red[dstCursor] = srcColor.red << 11;
-                dst.grn[dstCursor] = srcColor.grn << 11;
-                dst.blu[dstCursor] = srcColor.blu << 11;
-            }
-        }
-    } break;
-    case 32: {
-        unsigned int const planeSize = xsize;
-        unsigned int rowNumber;
-
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const srcrow = &src[rowNumber * srcwid];
-            unsigned char * const redPlane = &srcrow[planeSize * 0];
-            unsigned char * const grnPlane = &srcrow[planeSize * 1];
-            unsigned char * const bluPlane = &srcrow[planeSize * 2];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
-
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const dstCursor = dstRowCurs + colNumber;
-                dst.red[dstCursor] = redPlane[colNumber] << 8;
-                dst.grn[dstCursor] = grnPlane[colNumber] << 8;
-                dst.blu[dstCursor] = bluPlane[colNumber] << 8;
-            }
-        }
-    } break;
+    case 8:
+        doSameSize8bpp(trf, xsize, ysize, src, srcwid, colorMap, dst, dstwid);
+        break;
+    case 16:
+        doSameSize16bpp(trf, xsize, ysize, src, srcwid, dst, dstwid);
+        break;
+    case 32:
+        doSameSize32bpp(trf, xsize, ysize, src, srcwid, dst, dstwid);
+        break;
     default:
-        pm_error("INTERNAL ERROR: invalid bits per pixel (%u) in "
-                 "blitIdempotent()", pixSize);
+        pm_error("Impossible value of pixSize: %u", pixSize);
     }
 }
 
@@ -1636,16 +1750,15 @@ static void
 doBlit(struct Rect       const srcRect,
        struct Rect       const dstRect,
        struct Rect       const srcBounds,
-       struct raster     const srcplane,
+       struct Raster     const srcplane,
        struct Rect       const dstBounds,
        struct RgbPlanes  const canvasPlanes,
        int               const pixSize,
        int               const dstwid,
-       struct RGBColor * const color_map,
-       int               const mode) {
+       struct RGBColor * const colorMap,
+       unsigned int      const mode) {
 /*----------------------------------------------------------------------------
-   Transfer some pixels from 'srcplane' to 'canvasPlanes', applying the
-   transfer function 'trf'.
+   Transfer some pixels from 'srcplane' to 'canvasPlanes'.
 
    'srcplane' contains the rectangle 'srcBounds' of the image.
    'canvasPlanes' contains the rectangle 'dstRect' of the image.
@@ -1661,6 +1774,9 @@ doBlit(struct Rect       const srcRect,
     struct RgbPlanes dst;
     int dstoff;
     transfer_func trf;
+        /* A transfer function to use as we transfer the pixels.
+           NULL for none.
+        */
 
     if (verbose) {
         dumpRect("copying from:", srcRect);
@@ -1697,35 +1813,31 @@ doBlit(struct Rect       const srcRect,
     if ((mode & ~64) == 0)
         trf = NULL;    /* optimized srcCopy */
     else
-        trf = transfer(mode & ~64);
+        trf = transferFunctionForMode(mode & ~64);
 
     if (!rectsamesize(srcRect, dstRect))
         doDiffSize(srcRect, dstRect, pixSize,
-                   trf, color_map, src, srcplane.rowSize, dst);
+                   trf, colorMap, src, srcplane.rowSize, dst);
     else {
-        if (trf == NULL)
-            blitIdempotent(pixSize, srcRect, src, srcplane.rowSize,
-                           color_map, dst, dstwid);
-        else
-            doSameSize(trf, pixSize, srcRect, src, srcplane.rowSize,
-                       color_map, dst, dstwid);
+        doSameSize(trf, pixSize, srcRect, src, srcplane.rowSize,
+                   colorMap, dst, dstwid);
     }
 }
 
 
 
-static int
+static void
 blit(struct Rect       const srcRect,
      struct Rect       const srcBounds,
-     struct raster     const srcplane,
-     struct canvas *   const canvasP,
-     blitList *        const blitListP,
+     struct Raster     const srcplane,
+     struct Canvas *   const canvasP,
+     BlitList *        const blitListP,
      int               const pixSize,
      struct Rect       const dstRect,
      struct Rect       const dstBounds,
      int               const dstwid,
      struct RGBColor * const color_map,
-     int               const mode) {
+     unsigned int      const mode) {
 /*----------------------------------------------------------------------------
    'srcplane' contains the rectangle 'srcBounds' of the image.
 
@@ -1734,19 +1846,8 @@ blit(struct Rect       const srcRect,
    if 'blitListP' is non-null, we don't draw anything on 'canvasP'; instead,
    we add to the list *blitlistP a description of what needs to be drawn.
 -----------------------------------------------------------------------------*/
-
-    /* I can't tell what the result value of this function is supposed to mean,
-       but I found several return statements that did not set it to anything,
-       and several calls that examine it.  I'm guessing that "1" is the
-       appropriate thing to return in those cases, so I made it so.
-       -Bryan 00.03.02
-    */
-
-    int retval;
-
-    if (ps_text)
-        retval = 1;
-    else {
+    if (ps_text) {
+    } else {
         /* Almost got it.  Clip source rect with source bounds.
            clip dest rect with dest bounds.
         */
@@ -1760,17 +1861,12 @@ blit(struct Rect       const srcRect,
             addBlitList(blitListP,
                         clipsrc, srcBounds, srcplane, pixSize,
                         clipdst, color_map, mode);
-
-            retval = 0;
         } else {
             doBlit(clipsrc, clipdst,
                    srcBounds, srcplane, dstBounds, canvasP->planes,
                    pixSize, dstwid, color_map, mode);
-
-            retval = 1;
         }
     }
-    return retval;
 }
 
 
@@ -1828,11 +1924,11 @@ compact(Word const input) {
 
 
 static void
-reportBlitList(blitList * const blitListP) {
+reportBlitList(BlitList * const blitListP) {
 
     if (verbose) {
         unsigned int count;
-        struct blit_info * biP;
+        struct BlitInfo * biP;
 
         for (count = 0, biP = blitListP->firstP; biP; biP = biP->next)
             ++count;
@@ -1844,15 +1940,15 @@ reportBlitList(blitList * const blitListP) {
 
 
 static void
-doBlitList(struct canvas * const canvasP,
-           blitList *      const blitListP) {
+doBlitList(struct Canvas * const canvasP,
+           BlitList *      const blitListP) {
 /*----------------------------------------------------------------------------
    Do the list of blits *blitListP, drawing on canvas *canvasP.
 
    We allocate new plane data structures in *canvasP.  We assume it doesn't
    have them already.
 -----------------------------------------------------------------------------*/
-    struct blit_info * bi;
+    struct BlitInfo * bi;
     int srcwidth, dstwidth, srcheight, dstheight;
     double  scale, scalelow, scalehigh;
     double  xscale = 1.0;
@@ -1862,8 +1958,6 @@ doBlitList(struct canvas * const canvasP,
 
     reportBlitList(blitListP);
 
-    fullres = 0;
-
     for (bi = blitListP->firstP; bi; bi = bi->next) {
         srcwidth = rectwidth(&bi->srcRect);
         dstwidth = rectwidth(&bi->dstRect);
@@ -1940,7 +2034,7 @@ doBlitList(struct canvas * const canvasP,
     }
 
     if (xscale != 1.0 || yscale != 1.0) {
-        struct blit_info * biP;
+        struct BlitInfo * biP;
 
         for (biP = blitListP->firstP; biP; biP = biP->next)
             rectscale(&biP->dstRect, xscale, yscale);
@@ -2007,19 +2101,20 @@ outputPpm(FILE *           const ofP,
  * is padded with a null.
  */
 static Word
-nextOp(int const version) {
+nextOp(FILE *       const ifP,
+       unsigned int const version) {
 
     if ((align & 0x1) && version == 2) {
         stage = "aligning for opcode";
-        readByte();
+        readByte(ifP);
     }
 
     stage = "reading opcode";
 
     if (version == 1)
-        return readByte();
+        return readByte(ifP);
     else
-        return readWord();
+        return readWord(ifP);
 }
 
 
@@ -2027,11 +2122,12 @@ nextOp(int const version) {
 static drawFn ClipRgn;
 
 static void
-ClipRgn(struct canvas * const canvasP,
-        blitList *      const blitListP,
+ClipRgn(FILE *          const ifP,
+        struct Canvas * const canvasP,
+        BlitList *      const blitListP,
         int             const version) {
 
-    Word const len = readWord();
+    Word const len = readWord(ifP);
         /* Length in bytes of the parameter (including this word) */
 
     if (len == 10) {    /* null rgn */
@@ -2046,7 +2142,7 @@ ClipRgn(struct canvas * const canvasP,
         */
         struct Rect clipRgnParm;
 
-        readRect(&clipRgnParm);
+        readRect(ifP, &clipRgnParm);
 
         rectintersect(&clipRgnParm, &picFrame, &clip_rect);
 
@@ -2060,7 +2156,7 @@ ClipRgn(struct canvas * const canvasP,
         if (verbose)
             dumpRect("clipping to", clip_rect);
     } else
-        skip(len - 2);
+        skip(ifP, len - 2);
 }
 
 
@@ -2068,35 +2164,37 @@ ClipRgn(struct canvas * const canvasP,
 static drawFn OpColor;
 
 static void
-OpColor(struct canvas * const canvasP,
-        blitList *      const blitListP,
+OpColor(FILE *          const ifP,
+        struct Canvas * const canvasP,
+        BlitList *      const blitListP,
         int             const version) {
 
-    op_color.red = readWord();
-    op_color.grn = readWord();
-    op_color.blu = readWord();
+    op_color.red = readWord(ifP);
+    op_color.grn = readWord(ifP);
+    op_color.blu = readWord(ifP);
 }
 
 
 
 static void
-readPixmap(struct pixMap * const p) {
+readPixmap(FILE *          const ifP,
+           struct PixMap * const p) {
 
     stage = "getting pixMap header";
 
-    readRect(&p->Bounds);
-    p->version    = readWord();
-    p->packType   = readWord();
-    p->packSize   = readLong();
-    p->hRes       = readLong();
-    p->vRes       = readLong();
-    p->pixelType  = readWord();
-    p->pixelSize  = readWord();
-    p->cmpCount   = readWord();
-    p->cmpSize    = readWord();
-    p->planeBytes = readLong();
-    p->pmTable    = readLong();
-    p->pmReserved = readLong();
+    readRect(ifP, &p->Bounds);
+    p->version    = readWord(ifP);
+    p->packType   = readWord(ifP);
+    p->packSize   = readLong(ifP);
+    p->hRes       = readLong(ifP);
+    p->vRes       = readLong(ifP);
+    p->pixelType  = readWord(ifP);
+    p->pixelSize  = readWord(ifP);
+    p->cmpCount   = readWord(ifP);
+    p->cmpSize    = readWord(ifP);
+    p->planeBytes = readLong(ifP);
+    p->pmTable    = readLong(ifP);
+    p->pmReserved = readLong(ifP);
 
     if (verbose) {
         pm_message("pixelType: %d", p->pixelType);
@@ -2119,19 +2217,20 @@ readPixmap(struct pixMap * const p) {
 
 
 static struct RGBColor*
-readColorTable(void) {
+readColorTable(FILE * const ifP) {
+
     Longword ctSeed;
     Word ctFlags;
     Word ctSize;
     Word val;
     int i;
-    struct RGBColor* color_table;
+    struct RGBColor* colorTable;
 
     stage = "getting color table info";
 
-    ctSeed = readLong();
-    ctFlags = readWord();
-    ctSize = readWord();
+    ctSeed  = readLong(ifP);
+    ctFlags = readWord(ifP);
+    ctSize  = readWord(ifP);
 
     if (verbose) {
         pm_message("ctSeed:  %ld", ctSeed);
@@ -2141,12 +2240,12 @@ readColorTable(void) {
 
     stage = "reading color table";
 
-    MALLOCARRAY(color_table, ctSize + 1);
-    if (color_table == NULL)
+    MALLOCARRAY(colorTable, ctSize + 1);
+    if (!colorTable)
         pm_error("no memory for color table");
 
-    for (i = 0; i <= ctSize; i++) {
-        val = readWord();
+    for (i = 0; i <= ctSize; ++i) {
+        val = readWord(ifP);
         /* The indices in a device color table are bogus and usually == 0.
          * so I assume we allocate up the list of colors in order.
          */
@@ -2154,18 +2253,19 @@ readColorTable(void) {
             val = i;
         if (val > ctSize)
             pm_error("pixel value greater than color table size");
-        color_table[val].red = readWord();
-        color_table[val].grn = readWord();
-        color_table[val].blu = readWord();
+
+        colorTable[val].red = readWord(ifP);
+        colorTable[val].grn = readWord(ifP);
+        colorTable[val].blu = readWord(ifP);
 
         if (verbose > 1)
             pm_message("Color %3u: [%u,%u,%u]", val,
-                color_table[val].red,
-                color_table[val].grn,
-                color_table[val].blu);
+                colorTable[val].red,
+                colorTable[val].grn,
+                colorTable[val].blu);
     }
 
-    return color_table;
+    return colorTable;
 }
 
 
@@ -2261,7 +2361,7 @@ expand1Bit(unsigned char * const packed,
 static void
 unpackBuf(unsigned char *  const packed,
           unsigned int     const packedLen,
-          int              const bitsPerPixel,
+          unsigned int     const bitsPerPixel,
           unsigned char ** const expandedP,
           unsigned int *   const expandedLenP) {
 /*----------------------------------------------------------------------------
@@ -2317,7 +2417,7 @@ unpackBuf(unsigned char *  const packed,
 
 static void
 unpackUncompressedBits(FILE *          const ifP,
-                       struct raster   const raster,
+                       struct Raster   const raster,
                        unsigned int    const rowBytes,
                        unsigned int    const bitsPerPixel) {
 /*----------------------------------------------------------------------------
@@ -2332,6 +2432,9 @@ unpackUncompressedBits(FILE *          const ifP,
     unsigned int rowOfRect;
     unsigned char * linebuf;
 
+    if (verbose)
+        pm_message("Bits are not packed");
+
     MALLOCARRAY(linebuf, rowBytes + 100);
     if (linebuf == NULL)
         pm_error("can't allocate memory for line buffer");
@@ -2364,13 +2467,15 @@ reportValidateCompressedLineLen(unsigned int const row,
                                 unsigned int const linelen,
                                 unsigned int const rowSize) {
 /*----------------------------------------------------------------------------
-   'row' is a row number in the raster.
+  Report the line length and fail the program if it is obviously wrong.
 
-   'linelen' is the number of bytes of PICT that the PICT says hold the
-   compressed version of that row.
+ 'row' is a row number in the raster.
 
-   'rowSize' is the number of bytes we expect the uncompressed line to
-   be (includes pad pixels on the right).
+ 'linelen' is the number of bytes of PICT that the PICT says hold the
+ compressed version of that row.
+
+ 'rowSize' is the number of bytes we expect the uncompressed line to
+ be (includes pad pixels on the right).
 -----------------------------------------------------------------------------*/
     if (verbose > 1)
         pm_message("Row %u: %u-byte compressed line", row, linelen);
@@ -2428,7 +2533,7 @@ expandRun(unsigned char * const block,
 
         assert(block[0] & 0x80);  /* It's a run */
 
-        if (verbose > 1)
+        if (verbose > 2)
             pm_message("Block: run of %u packed %u-byte units",
                        runLength, pkpixsize);
 
@@ -2507,7 +2612,7 @@ copyPixelGroup(unsigned char * const block,
         assert(blockLimit >= 1);  /* block[0] exists */
         assert((block[0] & 0x80) == 0);  /* It's not a run */
 
-        if (verbose > 1)
+        if (verbose > 2)
             pm_message("Block: %u explicit packed %u-byte units",
                        groupLen, pkpixsize);
 
@@ -2576,13 +2681,13 @@ interpretCompressedLine(unsigned char * const linebuf,
                         unsigned int    const rowSize,
                         unsigned int    const bitsPerPixel) {
 /*----------------------------------------------------------------------------
-   linebuf[] contains 'linelen' bytes from the PICT image that represents
-   one row of the image, in compressed format.  Return the
-   uncompressed pixels of that row as rowRaster[].
+   linebuf[] contains 'linelen' bytes from the PICT image that represents one
+   row of the image, in compressed format.  Return the uncompressed pixels of
+   that row as rowRaster[].
 
-   rowRaster[] has 'rowSize' bytes of space.  Caller ensures that
-   linebuf[] does not contain more pixels than that, unless the PICT
-   image from which it comes is corrupt.
+   rowRaster[] has 'rowSize' bytes of space.  Caller ensures that linebuf[]
+   does not contain more pixels than that, unless the PICT image from which it
+   comes is corrupt.
 -----------------------------------------------------------------------------*/
     unsigned int lineCursor;
         /* Cursor into linebuf[] -- the compressed data */
@@ -2609,7 +2714,8 @@ interpretCompressedLine(unsigned char * const linebuf,
         assert(rasterCursor <= rowSize);
     }
     if (verbose > 1)
-        pm_message("Got %u pixels for row", rasterCursor);
+        pm_message("Decompressed %u bytes into %u bytes for row",
+                   lineCursor, rasterCursor);
 }
 
 
@@ -2642,11 +2748,11 @@ interpretCompressedLine(unsigned char * const linebuf,
 
 static void
 unpackCompressedBits(FILE *          const ifP,
-                     struct raster   const raster,
+                     struct Raster   const raster,
                      unsigned int    const rowBytes,
                      unsigned int    const bitsPerPixel) {
 /*----------------------------------------------------------------------------
-   Read the raster on file *ifP and place it in 'raster'.
+   Set the raster bytes of 'raster' with bytes read from *ifP.
 
    The data in the file is compressed with run length encoding and
    possibly packed multiple pixels per byte as well.
@@ -2665,6 +2771,9 @@ unpackCompressedBits(FILE *          const ifP,
     unsigned char * linebuf;
     unsigned int linebufSize;
 
+    if (verbose)
+        pm_message("Bits are packed");
+
     linebufSize = rowBytes;
     MALLOCARRAY(linebuf, linebufSize);
     if (linebuf == NULL)
@@ -2676,9 +2785,9 @@ unpackCompressedBits(FILE *          const ifP,
         unsigned int linelen;
 
         if (llsize == 2)
-            linelen = readWord();
+            linelen = readWord(ifP);
         else
-            linelen = readByte();
+            linelen = readByte(ifP);
 
         reportValidateCompressedLineLen(row, linelen, raster.rowSize);
 
@@ -2702,19 +2811,19 @@ static void
 unpackbits(FILE *           const ifP,
            struct Rect *    const boundsP,
            Word             const rowBytesArg,
-           int              const bitsPerPixel,
-           struct raster *  const rasterP) {
+           unsigned int     const bitsPerPixel,
+           struct Raster *  const rasterP) {
 
     unsigned int const rectHeight = boundsP->bottom - boundsP->top;
     unsigned int const rectWidth  = boundsP->right  - boundsP->left;
 
-    struct raster raster;
+    struct Raster raster;
     unsigned int rowBytes;
 
     stage = "unpacking packbits";
 
     if (verbose)
-        pm_message("rowBytes = %u, bitsPerPixel = %d",
+        pm_message("rowBytes = %u, bitsPerPixel = %u",
                    rowBytesArg, bitsPerPixel);
 
     allocateRaster(&raster, rectWidth, rectHeight, bitsPerPixel);
@@ -2754,33 +2863,33 @@ interpretRowBytesWord(Word           const rowBytesWord,
  * a pattern in the fabled complete version.
  */
 static void
-readPattern(void) {
+readPattern(FILE * const ifP) {
 
     Word PatType;
 
     stage = "Reading a pattern";
 
-    PatType = readWord();
+    PatType = readWord(ifP);
 
     switch (PatType) {
     case 2:
-        skip(8); /* old pattern data */
-        skip(5); /* RGB for pattern */
+        skip(ifP, 8); /* old pattern data */
+        skip(ifP, 5); /* RGB for pattern */
         break;
     case 1: {
         Word rowBytesWord;
         bool pixMap;
         unsigned int rowBytes;
-        struct pixMap p;
-        struct raster raster;
+        struct PixMap p;
+        struct Raster raster;
         struct RGBColor * ct;
 
-        skip(8); /* old pattern data */
-        rowBytesWord = readWord();
+        skip(ifP, 8); /* old pattern data */
+        rowBytesWord = readWord(ifP);
         interpretRowBytesWord(rowBytesWord, &pixMap, &rowBytes);
-        readPixmap(&p);
-        ct = readColorTable();
-        unpackbits(ifp, &p.Bounds, rowBytes, p.pixelSize, &raster);
+        readPixmap(ifP, &p);
+        ct = readColorTable(ifP);
+        unpackbits(ifP, &p.Bounds, rowBytes, p.pixelSize, &raster);
         freeRaster(raster);
         free(ct);
     } break;
@@ -2791,16 +2900,17 @@ readPattern(void) {
 
 
 
-/* these 3 do nothing but skip over their data! */
+/* These three do nothing but skip over their data! */
 
 static drawFn BkPixPat;
 
 static void
-BkPixPat(struct canvas * const canvasP,
-         blitList *      const blitListP,
+BkPixPat(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
-    readPattern();
+    readPattern(ifP);
 }
 
 
@@ -2808,11 +2918,12 @@ BkPixPat(struct canvas * const canvasP,
 static drawFn PnPixPat;
 
 static void
-PnPixPat(struct canvas * const canvasP,
-         blitList *      const blitListP,
+PnPixPat(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
-    readPattern();
+    readPattern(ifP);
 }
 
 
@@ -2820,17 +2931,20 @@ PnPixPat(struct canvas * const canvasP,
 static drawFn FillPixPat;
 
 static void
-FillPixPat(struct canvas * const canvasP,
-           blitList *      const blitListP,
+FillPixPat(FILE *          const ifP,
+           struct Canvas * const canvasP,
+           BlitList *      const blitListP,
            int             const version) {
 
-    readPattern();
+    readPattern(ifP);
 }
 
 
 
 static void
-read8x8Pattern(struct Pattern * const pat) {
+read8x8Pattern(FILE *           const ifP,
+               struct Pattern * const pat) {
+
     unsigned char buf[8];
     unsigned char * exp;
     unsigned int len;
@@ -2838,7 +2952,7 @@ read8x8Pattern(struct Pattern * const pat) {
     unsigned int i;
 
     len = 8;  /* initial value */
-    readBytes(ifp, len, buf);
+    readBytes(ifP, len, buf);
     if (verbose) {
         pm_message("pattern: %02x%02x%02x%02x",
                    buf[0], buf[1], buf[2], buf[3]);
@@ -2855,11 +2969,12 @@ read8x8Pattern(struct Pattern * const pat) {
 static drawFn BkPat;
 
 static void
-BkPat(struct canvas * const canvasP,
-      blitList *      const blitListP,
+BkPat(FILE *          const ifP,
+      struct Canvas * const canvasP,
+      BlitList *      const blitListP,
       int             const version) {
 
-    read8x8Pattern(&bkpat);
+    read8x8Pattern(ifP, &bkpat);
 }
 
 
@@ -2867,11 +2982,12 @@ BkPat(struct canvas * const canvasP,
 static drawFn PnPat;
 
 static void
-PnPat(struct canvas * const canvasP,
-      blitList *      const blitListP,
+PnPat(FILE *          const ifP,
+      struct Canvas * const canvasP,
+      BlitList *      const blitListP,
       int             const version) {
 
-    read8x8Pattern(&pen_pat);
+    read8x8Pattern(ifP, &pen_pat);
 }
 
 
@@ -2879,11 +2995,12 @@ PnPat(struct canvas * const canvasP,
 static drawFn FillPat;
 
 static void
-FillPat(struct canvas * const canvasP,
-        blitList *      const blitListP,
+FillPat(FILE *          const ifP,
+        struct Canvas * const canvasP,
+        BlitList *      const blitListP,
         int             const version) {
 
-    read8x8Pattern(&fillpat);
+    read8x8Pattern(ifP, &fillpat);
 }
 
 
@@ -2891,12 +3008,14 @@ FillPat(struct canvas * const canvasP,
 static drawFn PnSize;
 
 static void
-PnSize(struct canvas * const canvasP,
-       blitList *      const blitListP,
+PnSize(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    pen_height = readWord();
-    pen_width = readWord();
+    pen_height = readWord(ifP);
+    pen_width  = readWord(ifP);
+
     if (verbose)
         pm_message("pen size %d x %d", pen_width, pen_height);
 }
@@ -2906,28 +3025,31 @@ PnSize(struct canvas * const canvasP,
 static drawFn PnSize;
 
 static void
-PnMode(struct canvas * const canvasP,
-       blitList *      const blitListP,
+PnMode(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    pen_mode = readWord();
+    pen_mode = readWord(ifP);
 
     if (pen_mode >= 8 && pen_mode < 15)
         pen_mode -= 8;
     if (verbose)
         pm_message("pen transfer mode = %s",
-            const_name(transfer_name, pen_mode));
+            constName(transfer_name, pen_mode));
 
-    pen_trf = transfer(pen_mode);
+    pen_trf = transferFunctionForMode(pen_mode);
 }
 
 
 
 static void
-readRgb(struct RGBColor * const rgb) {
-    rgb->red = readWord();
-    rgb->grn = readWord();
-    rgb->blu = readWord();
+readRgb(FILE *            const ifP,
+        struct RGBColor * const rgb) {
+
+    rgb->red = readWord(ifP);
+    rgb->grn = readWord(ifP);
+    rgb->blu = readWord(ifP);
 }
 
 
@@ -2935,11 +3057,13 @@ readRgb(struct RGBColor * const rgb) {
 static drawFn RGBFgCol;
 
 static void
-RGBFgCol(struct canvas * const canvasP,
-         blitList *      const blitListP,
+RGBFgCol(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
-    readRgb(&foreground);
+    readRgb(ifP, &foreground);
+
     if (verbose)
         pm_message("foreground now [%d,%d,%d]",
             foreground.red, foreground.grn, foreground.blu);
@@ -2950,11 +3074,13 @@ RGBFgCol(struct canvas * const canvasP,
 static drawFn RGBBkCol;
 
 static void
-RGBBkCol(struct canvas * const canvasP,
-         blitList *      const blitListP,
+RGBBkCol(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
-    readRgb(&background);
+    readRgb(ifP, &background);
+
     if (verbose)
         pm_message("background now [%d,%d,%d]",
             background.red, background.grn, background.blu);
@@ -2978,7 +3104,7 @@ pixelIndex(struct Rect  const picFrame,
 
 
 static void
-drawPixel(struct canvas *   const canvasP,
+drawPixel(struct Canvas *   const canvasP,
           int               const x,
           int               const y,
           struct RGBColor * const clr,
@@ -3006,7 +3132,7 @@ drawPixel(struct canvas *   const canvasP,
 
 
 static void
-drawPenRect(struct canvas * const canvasP,
+drawPenRect(struct Canvas * const canvasP,
             struct Rect *   const rP) {
 
     if (!rectisnull(rP)) {
@@ -3051,7 +3177,7 @@ drawPenRect(struct canvas * const canvasP,
 
 
 static void
-drawPen(struct canvas * const canvasP,
+drawPen(struct Canvas * const canvasP,
         int             const x,
         int             const y) {
 
@@ -3082,7 +3208,7 @@ drawPen(struct canvas * const canvasP,
  * Paul Heckbert    3 Sep 85
  */
 static void
-scanLine(struct canvas * const canvasP,
+scanLine(struct Canvas * const canvasP,
          short           const x1,
          short           const y1,
          short           const x2,
@@ -3133,16 +3259,19 @@ scanLine(struct canvas * const canvasP,
 static drawFn Line;
 
 static void
-Line(struct canvas * const canvasP,
-     blitList *      const blitListP,
+Line(FILE *          const ifP,
+     struct Canvas * const canvasP,
+     BlitList *      const blitListP,
      int             const version) {
 
   struct Point p1;
-  readPoint(&p1);
-  readPoint(&current);
+  readPoint(ifP, &p1);
+  readPoint(ifP, &current);
+
   if (verbose)
     pm_message("(%d,%d) to (%d, %d)",
            p1.x,p1.y,current.x,current.y);
+
   scanLine(canvasP, p1.x,p1.y,current.x,current.y);
 }
 
@@ -3151,12 +3280,15 @@ Line(struct canvas * const canvasP,
 static drawFn LineFrom;
 
 static void
-LineFrom(struct canvas * const canvasP,
-         blitList *      const blitListP,
+LineFrom(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
     struct Point p1;
-    readPoint(&p1);
+
+    readPoint(ifP, &p1);
+
     if (verbose)
         pm_message("(%d,%d) to (%d, %d)", current.x, current.y, p1.x, p1.y);
 
@@ -3172,15 +3304,19 @@ LineFrom(struct canvas * const canvasP,
 static drawFn ShortLine;
 
 static void
-ShortLine(struct canvas * const canvasP,
-          blitList *      const blitListP,
+ShortLine(FILE *          const ifP,
+          struct Canvas * const canvasP,
+          BlitList *      const blitListP,
           int             const version) {
 
     struct Point p1;
-    readPoint(&p1);
-    readShortPoint(&current);
+
+    readPoint(ifP,&p1);
+    readShortPoint(ifP, &current);
+
     if (verbose)
         pm_message("(%d,%d) delta (%d, %d)", p1.x, p1.y, current.x, current.y);
+
     current.x += p1.x;
     current.y += p1.y;
 
@@ -3193,19 +3329,25 @@ ShortLine(struct canvas * const canvasP,
 static drawFn ShortLineFrom;
 
 static void
-ShortLineFrom(struct canvas * const canvasP,
-              blitList *      const blitListP,
+ShortLineFrom(FILE *          const ifP,
+              struct Canvas * const canvasP,
+              BlitList *      const blitListP,
               int             const version) {
 
     struct Point p1;
-    readShortPoint(&p1);
+
+    readShortPoint(ifP, &p1);
+
     if (verbose)
         pm_message("(%d,%d) delta (%d, %d)",
                    current.x,current.y,p1.x,p1.y);
+
     p1.x += current.x;
     p1.y += current.y;
+
     if (!blitListP)
         scanLine(canvasP, current.x, current.y, p1.x, p1.y);
+
     current.x = p1.x;
     current.y = p1.y;
 }
@@ -3213,7 +3355,7 @@ ShortLineFrom(struct canvas * const canvasP,
 
 
 static void
-doPaintRect(struct canvas * const canvasP,
+doPaintRect(struct Canvas * const canvasP,
             struct Rect     const prect) {
 
     struct Rect rect;
@@ -3231,11 +3373,13 @@ doPaintRect(struct canvas * const canvasP,
 static drawFn paintRect;
 
 static void
-paintRect(struct canvas * const canvasP,
-          blitList *      const blitListP,
+paintRect(FILE *          const ifP,
+          struct Canvas * const canvasP,
+          BlitList *      const blitListP,
           int             const version) {
 
-    readRect(&cur_rect);
+    readRect(ifP, &cur_rect);
+
     if (!blitListP)
         doPaintRect(canvasP, cur_rect);
 }
@@ -3245,8 +3389,9 @@ paintRect(struct canvas * const canvasP,
 static drawFn paintSameRect;
 
 static void
-paintSameRect(struct canvas * const canvasP,
-              blitList *      const blitListP,
+paintSameRect(FILE *          const ifP,
+              struct Canvas * const canvasP,
+              BlitList *      const blitListP,
               int             const version) {
 
     if (!blitListP)
@@ -3256,7 +3401,7 @@ paintSameRect(struct canvas * const canvasP,
 
 
 static void
-doFrameRect(struct canvas * const canvasP,
+doFrameRect(struct Canvas * const canvasP,
             struct Rect     const rect) {
 
     if (verbose)
@@ -3282,11 +3427,12 @@ doFrameRect(struct canvas * const canvasP,
 static drawFn frameRect;
 
 static void
-frameRect(struct canvas * const canvasP,
-          blitList *      const blitListP,
+frameRect(FILE *          const ifP,
+          struct Canvas * const canvasP,
+          BlitList *      const blitListP,
           int             const version) {
 
-    readRect(&cur_rect);
+    readRect(ifP, &cur_rect);
 
     if (!blitListP)
         doFrameRect(canvasP, cur_rect);
@@ -3297,8 +3443,9 @@ frameRect(struct canvas * const canvasP,
 static drawFn frameSameRect;
 
 static void
-frameSameRect(struct canvas * const canvasP,
-              blitList *      const blitListP,
+frameSameRect(FILE *          const ifP,
+              struct Canvas * const canvasP,
+              BlitList *      const blitListP,
               int             const version) {
 
     if (!blitListP)
@@ -3343,7 +3490,7 @@ polySort(int const sort_index, struct Point points[]) {
 /* Watch out for the lack of error checking in the next two functions ... */
 
 static void
-scanPoly(struct canvas * const canvasP,
+scanPoly(struct Canvas * const canvasP,
          int             const np,
          struct Point          pts[]) {
 
@@ -3448,17 +3595,22 @@ scanPoly(struct canvas * const canvasP,
 static drawFn paintPoly;
 
 static void
-paintPoly(struct canvas * const canvasP,
-          blitList *      const blitListP,
+paintPoly(FILE *          const ifP,
+          struct Canvas * const canvasP,
+          BlitList *      const blitListP,
           int             const version) {
 
   struct Rect bb;
   struct Point pts[100];
-  int i, np = (readWord() - 10) >> 2;
+  int i;
+  int np;
+
+  np = (readWord(ifP) - 10) >> 2;
 
-  readRect(&bb);
-  for (i=0; i<np; ++i)
-    readPoint(&pts[i]);
+  readRect(ifP, &bb);
+
+  for (i = 0; i < np; ++i)
+      readPoint(ifP, &pts[i]);
 
   /* scan convert poly ... */
   if (!blitListP)
@@ -3470,11 +3622,14 @@ paintPoly(struct canvas * const canvasP,
 static drawFn PnLocHFrac;
 
 static void
-PnLocHFrac(struct canvas * const canvasP,
-           blitList *      const blitListP,
+PnLocHFrac(FILE *          const ifP,
+           struct Canvas * const canvasP,
+           BlitList *      const blitListP,
            int             const version) {
 
-    Word frac = readWord();
+    Word frac;
+
+    frac = readWord(ifP);
 
     if (verbose)
         pm_message("PnLocHFrac = %d", frac);
@@ -3485,20 +3640,21 @@ PnLocHFrac(struct canvas * const canvasP,
 static drawFn TxMode;
 
 static void
-TxMode(struct canvas * const canvasP,
-       blitList *      const blitListP,
+TxMode(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    text_mode = readWord();
+    text_mode = readWord(ifP);
 
     if (text_mode >= 8 && text_mode < 15)
         text_mode -= 8;
     if (verbose)
         pm_message("text transfer mode = %s",
-            const_name(transfer_name, text_mode));
+            constName(transfer_name, text_mode));
 
     /* ignore the text mask bit 'cause we don't handle it yet */
-    text_trf = transfer(text_mode & ~64);
+    text_trf = transferFunctionForMode(text_mode & ~64);
 }
 
 
@@ -3506,13 +3662,15 @@ TxMode(struct canvas * const canvasP,
 static drawFn TxFont;
 
 static void
-TxFont(struct canvas * const canvasP,
-       blitList *      const blitListP,
+TxFont(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    text_font = readWord();
+    text_font = readWord(ifP);
+
     if (verbose)
-        pm_message("text font %s", const_name(font_name, text_font));
+        pm_message("text font %s", constName(font_name, text_font));
 }
 
 
@@ -3520,11 +3678,13 @@ TxFont(struct canvas * const canvasP,
 static drawFn TxFace;
 
 static void
-TxFace(struct canvas * const canvasP,
-       blitList *      const blitListP,
+TxFace(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    text_face = readByte();
+    text_face = readByte(ifP);
+
     if (verbose)
         pm_message("text face %d", text_face);
 }
@@ -3534,11 +3694,13 @@ TxFace(struct canvas * const canvasP,
 static drawFn TxSize;
 
 static void
-TxSize(struct canvas * const canvasP,
-       blitList *      const blitListP,
+TxSize(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    text_size = readWord();
+    text_size = readWord(ifP);
+
     if (verbose)
         pm_message("text size %d", text_size);
 }
@@ -3546,9 +3708,10 @@ TxSize(struct canvas * const canvasP,
 
 
 static void
-skipText(blitList * const blitListP) {
+skipText(FILE *     const ifP,
+         BlitList * const blitListP) {
 
-    skip(readByte());
+    skip(ifP, readByte(ifP));
 
     blitListP->unblittableText = true;
 }
@@ -3571,7 +3734,7 @@ getFont(int const font,
         int const style) {
 
     int closeness, bestcloseness;
-    struct fontinfo* fi, *best;
+    struct FontInfo* fi, *best;
 
     best = 0;
     for (fi = fontlist; fi; fi = fi->next) {
@@ -3631,7 +3794,8 @@ rotate(int * const x,
 
 
 static void
-doPsText(struct canvas * const canvasP,
+doPsText(FILE *          const ifP,
+         struct Canvas * const canvasP,
          Word            const tx,
          Word            const ty) {
 
@@ -3648,12 +3812,12 @@ doPsText(struct canvas * const canvasP,
         ps_cent_set = 1;
     }
 
-    len = readByte();
+    len = readByte(ifP);
 
     /* XXX this width calculation is not completely correct */
     width = 0;
     for (i = 0; i < len; i++) {
-        ch = str[i] = readByte();
+        ch = str[i] = readByte(ifP);
         if (tfont->glyph[ch])
             width += tfont->glyph[ch]->xadd;
     }
@@ -3700,27 +3864,28 @@ doPsText(struct canvas * const canvasP,
 
 
 static void
-doText(struct canvas *  const canvasP,
-       blitList *       const blitListP,
+doText(FILE *           const ifP,
+       struct Canvas *  const canvasP,
+       BlitList *       const blitListP,
        Word             const startx,
        Word             const starty) {
 
     if (blitListP)
-        skipText(blitListP);
+        skipText(ifP, blitListP);
     else {
         if (!(tfont = getFont(text_font, text_size, text_face)))
             tfont = pbm_defaultfont("bdf");
 
         if (ps_text)
-            doPsText(canvasP, startx, starty);
+            doPsText(ifP, canvasP, startx, starty);
         else {
             int len;
             Word x, y;
 
             x = startx;
             y = starty;
-            for (len = readByte(); len > 0; --len) {
-                struct glyph* const glyph = tfont->glyph[readByte()];
+            for (len = readByte(ifP); len > 0; --len) {
+                struct glyph* const glyph = tfont->glyph[readByte(ifP)];
                 if (glyph) {
                     int dy;
                     int h;
@@ -3750,15 +3915,16 @@ doText(struct canvas *  const canvasP,
 static drawFn LongText;
 
 static void
-LongText(struct canvas * const canvasP,
-         blitList *      const blitListP,
+LongText(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
     struct Point p;
 
-    readPoint(&p);
+    readPoint(ifP, &p);
 
-    doText(canvasP, blitListP, p.x, p.y);
+    doText(ifP, canvasP, blitListP, p.x, p.y);
 }
 
 
@@ -3766,13 +3932,14 @@ LongText(struct canvas * const canvasP,
 static drawFn DHText;
 
 static void
-DHText(struct canvas * const canvasP,
-       blitList *      const blitListP,
+DHText(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    current.x += readByte();
+    current.x += readByte(ifP);
 
-    doText(canvasP, blitListP, current.x, current.y);
+    doText(ifP, canvasP, blitListP, current.x, current.y);
 }
 
 
@@ -3780,13 +3947,14 @@ DHText(struct canvas * const canvasP,
 static drawFn DVText;
 
 static void
-DVText(struct canvas * const canvasP,
-       blitList *      const blitListP,
+DVText(FILE *          const ifP,
+       struct Canvas * const canvasP,
+       BlitList *      const blitListP,
        int             const version) {
 
-    current.y += readByte();
+    current.y += readByte(ifP);
 
-    doText(canvasP, blitListP, current.x, current.y);
+    doText(ifP, canvasP, blitListP, current.x, current.y);
 }
 
 
@@ -3794,13 +3962,15 @@ DVText(struct canvas * const canvasP,
 static drawFn DHDVText;
 
 static void
-DHDVText(struct canvas * const canvasP,
-         blitList *      const blitListP,
+DHDVText(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
+
     Byte dh, dv;
 
-    dh = readByte();
-    dv = readByte();
+    dh = readByte(ifP);
+    dv = readByte(ifP);
 
     if (verbose)
         pm_message("dh, dv = %d, %d", dh, dv);
@@ -3808,7 +3978,7 @@ DHDVText(struct canvas * const canvasP,
     current.x += dh;
     current.y += dv;
 
-    doText(canvasP, blitListP, current.x, current.y);
+    doText(ifP, canvasP, blitListP, current.x, current.y);
 }
 
 
@@ -3818,50 +3988,51 @@ DHDVText(struct canvas * const canvasP,
  */
 
 static void
-directBits(struct canvas * const canvasP,
-           blitList *      const blitListP,
+directBits(FILE *          const ifP,
+           struct Canvas * const canvasP,
+           BlitList *      const blitListP,
            unsigned int    const pictVersion,
            bool            const skipRegion) {
 
-    struct pixMap   p;
+    struct PixMap   p;
     struct Rect     srcRect;
     struct Rect     dstRect;
-    struct raster   raster;
+    struct Raster   raster;
     Word            mode;
 
     /* skip fake len, and fake EOF */
-    skip(4);    /* Ptr baseAddr == 0x000000ff */
-    readWord();    /* version */
-    readRect(&p.Bounds);
-    p.packType = readWord();
-    p.packSize = readLong();
-    p.hRes = readLong();
-    p.vRes = readLong();
-    p.pixelType = readWord();
-    p.pixelSize = readWord();
-    p.pixelSize = readWord();    /* XXX twice??? */
-    p.cmpCount = readWord();
-    p.cmpSize = readWord();
-    p.planeBytes = readLong();
-    p.pmTable = readLong();
-    p.pmReserved = readLong();
-
-    readRect(&srcRect);
+    skip(ifP, 4);    /* Ptr baseAddr == 0x000000ff */
+    readWord(ifP);    /* version */
+    readRect(ifP, &p.Bounds);
+    p.packType   = readWord(ifP);
+    p.packSize   = readLong(ifP);
+    p.hRes       = readLong(ifP);
+    p.vRes       = readLong(ifP);
+    p.pixelType  = readWord(ifP);
+    p.pixelSize  = readWord(ifP);
+    p.pixelSize  = readWord(ifP);    /* XXX twice??? */
+    p.cmpCount   = readWord(ifP);
+    p.cmpSize    = readWord(ifP);
+    p.planeBytes = readLong(ifP);
+    p.pmTable    = readLong(ifP);
+    p.pmReserved = readLong(ifP);
+
+    readRect(ifP, &srcRect);
     if (verbose)
         dumpRect("source rectangle:", srcRect);
 
-    readRect(&dstRect);
+    readRect(ifP, &dstRect);
     if (verbose)
         dumpRect("destination rectangle:", dstRect);
 
-    mode = readWord();
+    mode = readWord(ifP);
     if (verbose)
-        pm_message("transfer mode = %s", const_name(transfer_name, mode));
+        pm_message("transfer mode = %s", constName(transfer_name, mode));
 
     if (skipRegion)
-        skip_poly_or_region(canvasP, blitListP, pictVersion);
+        skipPolyOrRegion(ifP, canvasP, blitListP, pictVersion);
 
-    unpackbits(ifp, &p.Bounds, 0, p.pixelSize, &raster);
+    unpackbits(ifP, &p.Bounds, 0, p.pixelSize, &raster);
 
     blit(srcRect, p.Bounds, raster, canvasP, blitListP, p.pixelSize,
          dstRect, picFrame, rowlen, NULL, mode);
@@ -3877,11 +4048,12 @@ directBits(struct canvas * const canvasP,
 static drawFn DirectBitsRect;
 
 static void
-DirectBitsRect(struct canvas * const canvasP,
-               blitList *      const blitListP,
+DirectBitsRect(FILE *          const ifP,
+               struct Canvas * const canvasP,
+               BlitList *      const blitListP,
                int             const version) {
 
-    directBits(canvasP, blitListP, version, SKIP_REGION_FALSE);
+    directBits(ifP, canvasP, blitListP, version, SKIP_REGION_FALSE);
 }
 
 
@@ -3889,18 +4061,20 @@ DirectBitsRect(struct canvas * const canvasP,
 static drawFn DirectBitsRgn;
 
 static void
-DirectBitsRgn(struct canvas * const canvasP,
-              blitList *      const blitListP,
+DirectBitsRgn(FILE *          const ifP,
+              struct Canvas * const canvasP,
+              BlitList *      const blitListP,
               int             const version) {
 
-    directBits(canvasP, blitListP, version, SKIP_REGION_TRUE);
+    directBits(ifP, canvasP, blitListP, version, SKIP_REGION_TRUE);
 }
 
 
 
 static void
-doPixmap(struct canvas * const canvasP,
-         blitList *      const blitListP,
+doPixmap(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version,
          Word            const rowBytes,
          int             const is_region) {
@@ -3908,47 +4082,47 @@ doPixmap(struct canvas * const canvasP,
    Do a paletted image.
 -----------------------------------------------------------------------------*/
     Word mode;
-    struct pixMap p;
-    struct raster raster;
-    struct RGBColor * color_table;
+    struct PixMap p;
+    struct Raster raster;
+    struct RGBColor * colorTable;
     struct Rect srcRect;
     struct Rect dstRect;
 
-    readPixmap(&p);
+    readPixmap(ifP, &p);
 
     if (verbose)
         pm_message("%u x %u paletted image",
                    p.Bounds.right - p.Bounds.left,
                    p.Bounds.bottom - p.Bounds.top);
 
-    color_table = readColorTable();
+    colorTable = readColorTable(ifP);
 
-    readRect(&srcRect);
+    readRect(ifP, &srcRect);
 
     if (verbose)
         dumpRect("source rectangle:", srcRect);
 
-    readRect(&dstRect);
+    readRect(ifP, &dstRect);
 
     if (verbose)
         dumpRect("destination rectangle:", dstRect);
 
-    mode = readWord();
+    mode = readWord(ifP);
 
     if (verbose)
-        pm_message("transfer mode = %s", const_name(transfer_name, mode));
+        pm_message("transfer mode = %s", constName(transfer_name, mode));
 
     if (is_region)
-        skip_poly_or_region(canvasP, blitListP, version);
+        skipPolyOrRegion(ifP, canvasP, blitListP, version);
 
     stage = "unpacking rectangle";
 
-    unpackbits(ifp, &p.Bounds, rowBytes, p.pixelSize, &raster);
+    unpackbits(ifP, &p.Bounds, rowBytes, p.pixelSize, &raster);
 
     blit(srcRect, p.Bounds, raster, canvasP, blitListP, 8,
-         dstRect, picFrame, rowlen, color_table, mode);
+         dstRect, picFrame, rowlen, colorTable, mode);
 
-    free(color_table);
+    free(colorTable);
     freeRaster(raster);
 }
 
@@ -3956,8 +4130,8 @@ doPixmap(struct canvas * const canvasP,
 
 static void
 doBitmap(FILE *          const ifP,
-         struct canvas * const canvasP,
-         blitList *      const blitListP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version,
          int             const rowBytes,
          int             const is_region) {
@@ -3970,22 +4144,22 @@ doBitmap(FILE *          const ifP,
     struct Rect srcRect;
     struct Rect dstRect;
     Word mode;
-    struct raster raster;
+    struct Raster raster;
         /* This raster contains padding on the right to make a multiple
            of 16 pixels per row.
         */
     static struct RGBColor color_table[] = {
         {65535L, 65535L, 65535L}, {0, 0, 0} };
 
-    readRect(&Bounds);
-    readRect(&srcRect);
-    readRect(&dstRect);
-    mode = readWord();
+    readRect(ifP, &Bounds);
+    readRect(ifP, &srcRect);
+    readRect(ifP, &dstRect);
+    mode = readWord(ifP);
     if (verbose)
-        pm_message("transfer mode = %s", const_name(transfer_name, mode));
+        pm_message("transfer mode = %s", constName(transfer_name, mode));
 
     if (is_region)
-        skip_poly_or_region(canvasP, blitListP, version);
+        skipPolyOrRegion(ifP, canvasP, blitListP, version);
 
     stage = "unpacking rectangle";
 
@@ -4002,8 +4176,9 @@ doBitmap(FILE *          const ifP,
 static drawFn BitsRect;
 
 static void
-BitsRect(struct canvas * const canvasP,
-         blitList *      const blitListP,
+BitsRect(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
          int             const version) {
 
     Word rowBytesWord;
@@ -4011,14 +4186,14 @@ BitsRect(struct canvas * const canvasP,
     unsigned int rowBytes;
 
     stage = "Reading rowBytes word for bitsrect";
-    rowBytesWord = readWord();
+    rowBytesWord = readWord(ifP);
 
     interpretRowBytesWord(rowBytesWord, &pixMap, &rowBytes);
 
     if (pixMap)
-        doPixmap(canvasP, blitListP, version, rowBytes, 0);
+        doPixmap(ifP, canvasP, blitListP, version, rowBytes, 0);
     else
-        doBitmap(ifp, canvasP, blitListP, version, rowBytes, 0);
+        doBitmap(ifP, canvasP, blitListP, version, rowBytes, 0);
 }
 
 
@@ -4026,8 +4201,9 @@ BitsRect(struct canvas * const canvasP,
 static drawFn BitsRegion;
 
 static void
-BitsRegion(struct canvas * const canvasP,
-           blitList *      const blitListP,
+BitsRegion(FILE *          const ifP,
+           struct Canvas * const canvasP,
+           BlitList *      const blitListP,
            int             const version) {
 
     Word rowBytesWord;
@@ -4035,14 +4211,14 @@ BitsRegion(struct canvas * const canvasP,
     unsigned int rowBytes;
 
     stage = "Reading rowBytes for bitsregion";
-    rowBytesWord = readWord();
+    rowBytesWord = readWord(ifP);
 
     interpretRowBytesWord(rowBytesWord, &pixMap, &rowBytes);
 
     if (pixMap)
-        doPixmap(canvasP, blitListP, version, rowBytes, 1);
+        doPixmap(ifP, canvasP, blitListP, version, rowBytes, 1);
     else
-        doBitmap(ifp, canvasP, blitListP, version, rowBytes, 1);
+        doBitmap(ifP, canvasP, blitListP, version, rowBytes, 1);
 }
 
 
@@ -4051,7 +4227,7 @@ BitsRegion(struct canvas * const canvasP,
   * See http://developer.apple.com/techpubs/mac/QuickDraw/QuickDraw-461.html
   * for opcode description
   */
-static struct opdef const optable[] = {
+static struct Opdef const optable[] = {
 /* 0x00 */  { "NOP", 0, NULL, "nop" },
 /* 0x01 */  { "ClipRgn", NA, ClipRgn, "clip region" },
 /* 0x02 */  { "BkPat", 8, BkPat, "background pattern" },
@@ -4167,14 +4343,14 @@ static struct opdef const optable[] = {
 /* 0x6d */  RESERVED_OP(4),
 /* 0x6e */  RESERVED_OP(4),
 /* 0x6f */  RESERVED_OP(4),
-/* 0x70 */  { "framePoly", NA, skip_poly_or_region, "poly" },
+/* 0x70 */  { "framePoly", NA, skipPolyOrRegion, "poly" },
 /* 0x71 */  { "paintPoly", NA, paintPoly, "poly" },
-/* 0x72 */  { "erasePoly", NA, skip_poly_or_region, "poly" },
-/* 0x73 */  { "invertPoly", NA, skip_poly_or_region, "poly" },
-/* 0x74 */  { "fillPoly", NA, skip_poly_or_region, "poly" },
-/* 0x75 */  RESERVED_OP_F(skip_poly_or_region),
-/* 0x76 */  RESERVED_OP_F(skip_poly_or_region),
-/* 0x77 */  RESERVED_OP_F(skip_poly_or_region),
+/* 0x72 */  { "erasePoly", NA, skipPolyOrRegion, "poly" },
+/* 0x73 */  { "invertPoly", NA, skipPolyOrRegion, "poly" },
+/* 0x74 */  { "fillPoly", NA, skipPolyOrRegion, "poly" },
+/* 0x75 */  RESERVED_OP_F(skipPolyOrRegion),
+/* 0x76 */  RESERVED_OP_F(skipPolyOrRegion),
+/* 0x77 */  RESERVED_OP_F(skipPolyOrRegion),
 /* 0x78 */  { "frameSamePoly", 0, NULL, "poly (NYI)" },
 /* 0x79 */  { "paintSamePoly", 0, NULL, "poly (NYI)" },
 /* 0x7a */  { "eraseSamePoly", 0, NULL, "poly (NYI)" },
@@ -4183,14 +4359,14 @@ static struct opdef const optable[] = {
 /* 0x7d */  RESERVED_OP(0),
 /* 0x7e */  RESERVED_OP(0),
 /* 0x7f */  RESERVED_OP(0),
-/* 0x80 */  { "frameRgn", NA, skip_poly_or_region, "region" },
-/* 0x81 */  { "paintRgn", NA, skip_poly_or_region, "region" },
-/* 0x82 */  { "eraseRgn", NA, skip_poly_or_region, "region" },
-/* 0x83 */  { "invertRgn", NA, skip_poly_or_region, "region" },
-/* 0x84 */  { "fillRgn", NA, skip_poly_or_region, "region" },
-/* 0x85 */  RESERVED_OP_F(skip_poly_or_region),
-/* 0x86 */  RESERVED_OP_F(skip_poly_or_region),
-/* 0x87 */  RESERVED_OP_F(skip_poly_or_region),
+/* 0x80 */  { "frameRgn", NA, skipPolyOrRegion, "region" },
+/* 0x81 */  { "paintRgn", NA, skipPolyOrRegion, "region" },
+/* 0x82 */  { "eraseRgn", NA, skipPolyOrRegion, "region" },
+/* 0x83 */  { "invertRgn", NA, skipPolyOrRegion, "region" },
+/* 0x84 */  { "fillRgn", NA, skipPolyOrRegion, "region" },
+/* 0x85 */  RESERVED_OP_F(skipPolyOrRegion),
+/* 0x86 */  RESERVED_OP_F(skipPolyOrRegion),
+/* 0x87 */  RESERVED_OP_F(skipPolyOrRegion),
 /* 0x88 */  { "frameSameRgn", 0, NULL, "region (NYI)" },
 /* 0x89 */  { "paintSameRgn", 0, NULL, "region (NYI)" },
 /* 0x8a */  { "eraseSameRgn", 0, NULL, "region (NYI)" },
@@ -4225,9 +4401,10 @@ static struct opdef const optable[] = {
 
 
 static void
-processOpcode(Word            const opcode,
-              struct canvas * const canvasP,
-              blitList *      const blitListP,
+processOpcode(FILE *          const ifP,
+              Word            const opcode,
+              struct Canvas * const canvasP,
+              BlitList *      const blitListP,
               unsigned int    const version) {
 
     if (opcode < 0xa2) {
@@ -4240,15 +4417,15 @@ processOpcode(Word            const opcode,
         }
 
         if (optable[opcode].impl != NULL)
-            (*optable[opcode].impl)(canvasP, blitListP, version);
+            (*optable[opcode].impl)(ifP, canvasP, blitListP, version);
         else if (optable[opcode].len >= 0)
-            skip(optable[opcode].len);
+            skip(ifP, optable[opcode].len);
         else {
             /* It's a special length code */
             switch (optable[opcode].len) {
             case WORD_LEN: {
-                Word const len = readWord();
-                skip(len);
+                Word const len = readWord(ifP);
+                skip(ifP, len);
             } break;
             default:
                 pm_error("can't do length %d", optable[opcode].len);
@@ -4258,12 +4435,12 @@ processOpcode(Word            const opcode,
         if (verbose)
             pm_message("HeaderOp");
         stage = "HeaderOp";
-        skip(24);
+        skip(ifP, 24);
     } else if (opcode >= 0xa2 && opcode <= 0xaf) {
         stage = "skipping reserved";
         if (verbose)
             pm_message("%s 0x%x", stage, opcode);
-        skip(readWord());
+        skip(ifP, readWord(ifP));
     } else if (opcode >= 0xb0 && opcode <= 0xcf) {
         /* just a reserved opcode, no data */
         if (verbose)
@@ -4272,12 +4449,12 @@ processOpcode(Word            const opcode,
         stage = "skipping reserved";
         if (verbose)
             pm_message("%s 0x%x", stage, opcode);
-        skip(readLong());
+        skip(ifP, readLong(ifP));
     } else if (opcode >= 0x100 && opcode <= 0x7fff) {
         stage = "skipping reserved";
         if (verbose)
             pm_message("%s 0x%x", stage, opcode);
-        skip((opcode >> 7) & 255);
+        skip(ifP, (opcode >> 7) & 255);
     } else if (opcode >= 0x8000 && opcode <= 0x80ff) {
         /* just a reserved opcode, no data */
         if (verbose)
@@ -4286,7 +4463,7 @@ processOpcode(Word            const opcode,
         stage = "skipping reserved";
         if (verbose)
             pm_message("%s 0x%x", stage, opcode);
-        skip(readLong());
+        skip(ifP, readLong(ifP));
     } else
         pm_error("This program does not understand opcode 0x%04x", opcode);
 }
@@ -4294,15 +4471,23 @@ processOpcode(Word            const opcode,
 
 
 static void
-interpretPict(FILE * const ofP) {
+interpretPict(FILE *       const ifP,
+              FILE *       const ofP,
+              bool         const noheader,
+              bool         const fullres,
+              bool         const quickdraw,
+              unsigned int const verboseArg) {
 
     Byte ch;
     Word picSize;
     Word opcode;
     unsigned int version;
     unsigned int i;
-    struct canvas canvas;
-    blitList blitList;
+    struct Canvas canvas;
+    BlitList blitList;
+
+    verbose = verboseArg;
+    recognize_comment = !quickdraw;
 
     initBlitList(&blitList);
 
@@ -4310,18 +4495,24 @@ interpretPict(FILE * const ofP) {
         pen_pat.pix[i] = bkpat.pix[i] = fillpat.pix[i] = 1;
     pen_width = pen_height = 1;
     pen_mode = 0; /* srcCopy */
-    pen_trf = transfer(pen_mode);
+    pen_trf = transferFunctionForMode(pen_mode);
     text_mode = 0; /* srcCopy */
-    text_trf = transfer(text_mode);
+    text_trf = transferFunctionForMode(text_mode);
+
+    if (!noheader) {
+        stage = "Reading 512 byte header";
+        /* Note that the "header" in PICT is entirely comment! */
+        skip(ifP, 512);
+    }
 
     stage = "Reading picture size";
-    picSize = readWord();
+    picSize = readWord(ifP);
 
     if (verbose)
         pm_message("picture size = %u (0x%x)", picSize, picSize);
 
     stage = "reading picture frame";
-    readRect(&picFrame);
+    readRect(ifP, &picFrame);
 
     if (verbose) {
         dumpRect("Picture frame:", picFrame);
@@ -4339,18 +4530,18 @@ interpretPict(FILE * const ofP) {
         clip_rect = picFrame;
     }
 
-    while ((ch = readByte()) == 0)
+    while ((ch = readByte(ifP)) == 0)
         ;
     if (ch != 0x11)
         pm_error("No version number");
 
-    version = readByte();
+    version = readByte(ifP);
 
     switch (version) {
     case 1:
         break;
     case 2: {
-        unsigned char const subcode = readByte();
+        unsigned char const subcode = readByte(ifP);
         if (subcode != 0xff)
             pm_error("The only Version 2 PICT images this program "
                      "undertands are subcode 0xff.  This image has "
@@ -4363,8 +4554,9 @@ interpretPict(FILE * const ofP) {
     if (verbose)
         pm_message("PICT version %u", version);
 
-    while((opcode = nextOp(version)) != 0xff)
-        processOpcode(opcode, &canvas, fullres ? &blitList : NULL, version);
+    while((opcode = nextOp(ifP, version)) != 0xff)
+        processOpcode(ifP, opcode, &canvas, fullres ? &blitList : NULL,
+                      version);
 
     if (fullres) {
         if (blitList.unblittableText)
@@ -4379,77 +4571,25 @@ interpretPict(FILE * const ofP) {
 
 
 
-static void
-loadDefaultFontDir(void) {
-/*----------------------------------------------------------------------------
-   Load the fonts from the font directory file "fontdir" (in the current
-   directory), if it exists.
------------------------------------------------------------------------------*/
-    struct stat statbuf;
-    int rc;
-
-    rc = stat("fontdir", &statbuf);
-
-    if (rc == 0)
-        load_fontdir("fontdir");
-}
+int
+main(int argc, const char *argv[]) {
 
+    struct CmdlineInfo cmdline;
+    FILE * ifP;
 
+    pm_proginit(&argc, argv);
 
-int
-main(int argc, char * argv[]) {
-    int argn;
-    int header;
-    const char* const usage =
-"[-verbose] [-fullres] [-noheader] [-quickdraw] [-fontdir file] [pictfile]";
-
-    ppm_init( &argc, argv );
-
-    argn = 1;
-    verbose = 0;
-    fullres = 0;
-    header = 1;
-    recognize_comment = 1;
-
-    while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
-        if (pm_keymatch(argv[argn], "-verbose", 2))
-            verbose++;
-        else if (pm_keymatch(argv[argn], "-fullres", 3))
-            fullres = 1;
-        else if (pm_keymatch(argv[argn], "-noheader", 2))
-            header = 0;
-        else if (pm_keymatch(argv[argn], "-quickdraw", 2))
-            recognize_comment = 0;
-        else if (pm_keymatch(argv[argn], "-fontdir", 3)) {
-            argn++;
-            if (!argv[argn])
-                pm_usage(usage);
-            else
-                load_fontdir(argv[argn]);
-        }
-        else
-            pm_usage(usage);
-        ++argn;
-    }
+    parseCommandLine(argc, argv, &cmdline);
 
-    if (argn < argc) {
-        ifp = pm_openr(argv[argn]);
-        ++argn;
-    } else
-        ifp = stdin;
+    ifP = pm_openr(cmdline.inputFileName);
 
-    if (argn != argc)
-        pm_usage(usage);
+    if (cmdline.fontdir)
+        loadFontdir(cmdline.fontdir);
 
     loadDefaultFontDir();
 
-    if (header) {
-        stage = "Reading 512 byte header";
-        /* Note that the "header" in PICT is entirely comment! */
-        skip(512);
-    }
-
-    interpretPict(stdout);
+    interpretPict(ifP, stdout, cmdline.noheader,
+                  cmdline.fullres, cmdline.quickdraw, cmdline.verbose);
 
     pm_close(stdout);
 
diff --git a/converter/ppm/ppmtoapplevol.c b/converter/ppm/ppmtoapplevol.c
index eb4b6b2a..1e979de9 100644
--- a/converter/ppm/ppmtoapplevol.c
+++ b/converter/ppm/ppmtoapplevol.c
@@ -78,7 +78,7 @@ main (int argc, const char * argv[]) {
 
     for (row = 0; row < rows; row++) {
         unsigned int col;
-        
+
         ppm_readppmrow(ifP, pixelrow, cols, maxval, format);
 
         for (col = 0; col < cols; ++col) {
diff --git a/converter/ppm/ppmtoilbm.c b/converter/ppm/ppmtoilbm.c
index c5fa4d00..ad07f9fb 100644
--- a/converter/ppm/ppmtoilbm.c
+++ b/converter/ppm/ppmtoilbm.c
@@ -73,7 +73,6 @@
 #include "pm_c_util.h"
 #include "mallocvar.h"
 #include "ppm.h"
-#include "ppmfloyd.h"
 #include "pbm.h"
 #include "runlength.h"
 #include "ilbm.h"
@@ -118,13 +117,13 @@
 static unsigned char *coded_rowbuf; /* buffer for uncompressed scanline */
 static unsigned char *compr_rowbuf; /* buffer for compressed scanline */
 static pixel **pixels;  /* PPM image (NULL for row-by-row operation) */
-static pixel *pixrow;   
+static pixel *pixrow;
     /* current row in PPM image (pointer into pixels array, or buffer
-       for row-by-row operation) 
+       for row-by-row operation)
     */
 
 static long viewportmodes = 0;
-static int slicesize = 1; 
+static int slicesize = 1;
     /* rows per slice for multipalette images - NOT USED */
 
 static unsigned char compmethod = DEF_COMPRESSION;   /* default compression */
@@ -155,9 +154,8 @@ static bodyblock *cur_block = &firstblock;
 static char *anno_chunk, *auth_chunk, *name_chunk, *text_chunk, *copyr_chunk;
 
 /* flags */
-static short compr_force = 0;   
+static short compr_force = 0;
     /* force compressed output, even if the image got larger  - NOT USED */
-static short floyd = 0;         /* apply floyd-steinberg error diffusion */
 static short gen_camg = 0;      /* write CAMG chunk */
 
 #define WORSTCOMPR(bytes)       ((bytes) + (bytes)/128 + 1)
@@ -360,7 +358,7 @@ writeCmap(pixel * const colormap,
     pm_writebiglong(stdout, cmapsize);
     if( maxval != MAXCOLVAL ) {
         int *table;
-        pm_message("maxval is not %d - automatically rescaling colors", 
+        pm_message("maxval is not %d - automatically rescaling colors",
                    MAXCOLVAL);
         table = makeValTable(maxval, MAXCOLVAL);
         for( i = 0; i < colors; i++ ) {
@@ -457,7 +455,7 @@ compressRow(unsigned int const bytes) {
                 &compressedByteCt);
             break;
         default:
-            pm_error("compressRow(): unknown compression method %d", 
+            pm_error("compressRow(): unknown compression method %d",
                      compmethod);
     }
     storeBodyrow(compr_rowbuf, compressedByteCt);
@@ -551,35 +549,35 @@ reportTooManyColors(int         const ifmode,
                     int         const hamplanes,
                     DirectColor const dcol,
                     int         const deepbits) {
-    
+
     int const maxcolors = 1 << maxplanes;
 
     switch( ifmode ) {
     case MODE_HAM:
         pm_message("too many colors for %d planes - "
-                   "proceeding to write a HAM%d file", 
+                   "proceeding to write a HAM%d file",
                    maxplanes, hamplanes);
-        pm_message("if you want a non-HAM file, try doing a 'pnmquant %d'", 
+        pm_message("if you want a non-HAM file, try doing a 'pnmquant %d'",
                    maxcolors);
         break;
     case MODE_DCOL:
         pm_message("too many colors for %d planes - "
-                   "proceeding to write a %d:%d:%d direct color ILBM", 
+                   "proceeding to write a %d:%d:%d direct color ILBM",
                    maxplanes, dcol.r, dcol.g, dcol.b);
         pm_message("if you want a non-direct color file, "
                    "try doing a 'pnmquant %d'", maxcolors);
         break;
     case MODE_DEEP:
         pm_message("too many colors for %d planes - "
-                   "proceeding to write a %d-bit \'deep\' ILBM", 
+                   "proceeding to write a %d-bit \'deep\' ILBM",
                    maxplanes, deepbits*3);
         pm_message("if you want a non-deep file, "
-                   "try doing a 'pnmquant %d'", 
+                   "try doing a 'pnmquant %d'",
                    maxcolors);
         break;
     default:
         pm_error("too many colors for %d planes - "
-                 "try doing a 'pnmquant %d'", 
+                 "try doing a 'pnmquant %d'",
                  maxplanes, maxcolors);
         break;
     }
@@ -599,7 +597,7 @@ getIntVal(const char * const string,
         pm_error("option \"%s\" needs integer argument", option);
 
     if (val < bot || val > top)
-        pm_error("option \"%s\" argument value out of range (%d..%d)", 
+        pm_error("option \"%s\" argument value out of range (%d..%d)",
                  option, bot, top);
 
     return val;
@@ -613,10 +611,10 @@ getComprMethod(const char * const string) {
     int retval;
     if( pm_keymatch(string, "none", 1) || pm_keymatch(string, "0", 1) )
         retval = cmpNone;
-    else if( pm_keymatch(string, "byterun1", 1) || 
+    else if( pm_keymatch(string, "byterun1", 1) ||
              pm_keymatch(string, "1", 1) )
         retval = cmpByteRun1;
-    else 
+    else
         pm_error("unknown compression method: %s", string);
     return retval;
 }
@@ -631,12 +629,12 @@ getMaskType(const char * const string) {
     if( pm_keymatch(string, "none", 1) || pm_keymatch(string, "0", 1) )
         retval = mskNone;
     else
-    if( pm_keymatch(string, "plane", 1) || 
+    if( pm_keymatch(string, "plane", 1) ||
         pm_keymatch(string, "maskplane", 1) ||
         pm_keymatch(string, "1", 1) )
         retval = mskHasMask;
     else
-    if( pm_keymatch(string, "transparentcolor", 1) || 
+    if( pm_keymatch(string, "transparentcolor", 1) ||
         pm_keymatch(string, "2", 1) )
         retval = mskHasTransparentColor;
     else
@@ -665,7 +663,7 @@ getHammapMode(const char * const string) {
     else
     if( pm_keymatch(string, "rgb5", 4) )
         retval = HAMMODE_RGB5;
-    else 
+    else
         pm_error("unknown HAM colormap selection mode: %s", string);
     return retval;
 }
@@ -726,7 +724,7 @@ hcmp(const void * const a,
     const hentry * const vaP = a;
     const hentry * const vbP = b;
 
-    return(vbP->count - vaP->count);  
+    return(vbP->count - vaP->count);
 }
 
 
@@ -801,17 +799,17 @@ computeHamCmap(int   const cols,
                     if( dist <= maxdist ) {
                         unsigned int sum = hmap[i].count + hmap[col].count;
 
-                        hmap[i].r = ROUNDDIV(hmap[i].r * hmap[i].count + 
+                        hmap[i].r = ROUNDDIV(hmap[i].r * hmap[i].count +
                                              r * hmap[col].count, sum);
-                        hmap[i].g = ROUNDDIV(hmap[i].g * hmap[i].count + 
+                        hmap[i].g = ROUNDDIV(hmap[i].g * hmap[i].count +
                                              g * hmap[col].count, sum);
-                        hmap[i].b = ROUNDDIV(hmap[i].b * hmap[i].count + 
+                        hmap[i].b = ROUNDDIV(hmap[i].b * hmap[i].count +
                                              b * hmap[col].count, sum);
                         hmap[i].count = sum;
 
                         hmap[col] = hmap[i];    /* temp store */
-                        for( tmp = i-1; 
-                             tmp >= 0 && hmap[tmp].count < hmap[col].count; 
+                        for( tmp = i-1;
+                             tmp >= 0 && hmap[tmp].count < hmap[col].count;
                              tmp-- )
                             hmap[tmp+1] = hmap[tmp];
                         hmap[tmp+1] = hmap[col];
@@ -878,7 +876,6 @@ doHamBody(FILE *  const ifP,
 
     int col, row, i;
     rawtype *raw_rowbuf;
-    ppm_fs_info *fi = NULL;
     colorhash_table cht, cht2;
     long bodysize = 0;
     int *itoh;      /* table image -> ham */
@@ -898,9 +895,6 @@ doHamBody(FILE *  const ifP,
 
     itoh = makeValTable(maxval, hammaxval);
 
-    if( floyd )
-        fi = ppm_fs_init(cols, maxval, 0);
-
     for( row = 0; row < rows; row++ ) {
         int noprev;
         int spr, spg, spb;   /* scaled values of previous pixel */
@@ -909,9 +903,7 @@ doHamBody(FILE *  const ifP,
 
         noprev = 1;
         prow = nextPixrow(ifP, row);
-        for( col = ppm_fs_startrow(fi, prow); 
-             col < cols; 
-             col = ppm_fs_next(fi, col) ) {
+        for( col = 0; col < cols; ++col ) {
 
             pixel const p = prow[col];
 
@@ -930,15 +922,15 @@ doHamBody(FILE *  const ifP,
                 int ucr, ucg, ucb;  /* unscaled values of colormap entry */
 
                 if(  hammapmode == HAMMODE_GRAY ) {
-                    if( maxval <= 255 ) 
-                        /* Use fast approximation to 
+                    if( maxval <= 255 )
+                        /* Use fast approximation to
                            0.299 r + 0.587 g + 0.114 b. */
                         i = (int)ppm_fastlumin(p);
-                    else 
-                        /* Can't use fast approximation, 
-                           so fall back on floats. 
+                    else
+                        /* Can't use fast approximation,
+                           so fall back on floats.
                         */
-                        i = (int)(PPM_LUMIN(p) + 0.5); 
+                        i = (int)(PPM_LUMIN(p) + 0.5);
                             /* -IUW added '+ 0.5' */
                     i = itoh[i];
                 }
@@ -956,8 +948,8 @@ doHamBody(FILE *  const ifP,
                         }
                     }
                 }
-                ucr = PPM_GETR(colormap[i]); 
-                ucg = PPM_GETG(colormap[i]); 
+                ucr = PPM_GETR(colormap[i]);
+                ucg = PPM_GETG(colormap[i]);
                 ucb = PPM_GETB(colormap[i]);
 
                 if( noprev ) {  /* no previous pixel, must use colormap */
@@ -985,21 +977,21 @@ doHamBody(FILE *  const ifP,
                         (sb - scb)*(sb - scb);
 #endif
 
-                    if( di <= dr && di <= dg && di <= db ) {    
+                    if( di <= dr && di <= dg && di <= db ) {
                         /* prefer colormap lookup */
-                        raw_rowbuf[col] = i; 
+                        raw_rowbuf[col] = i;
                         upr = ucr;  upg = ucg;  upb = ucb;
                         spr = scr;  spg = scg;  spb = scb;
                     }
                     else
                     if( db <= dr && db <= dg ) {
-                        raw_rowbuf[col] = sb + hamcode_blue; 
+                        raw_rowbuf[col] = sb + hamcode_blue;
                         spb = sb;
                         upb = ub;
                     }
                     else
                     if( dr <= dg ) {
-                        raw_rowbuf[col] = sr + hamcode_red;  
+                        raw_rowbuf[col] = sr + hamcode_red;
                         spr = sr;
                         upr = ur;
                     }
@@ -1012,19 +1004,17 @@ doHamBody(FILE *  const ifP,
             }
             else {  /* prefect match in cmap */
                 raw_rowbuf[col] = i;    /* + (HAMCODE_CMAP << colbits) */
-                upr = PPM_GETR(colormap[i]); 
-                upg = PPM_GETG(colormap[i]); 
+                upr = PPM_GETR(colormap[i]);
+                upg = PPM_GETG(colormap[i]);
                 upb = PPM_GETB(colormap[i]);
-                spr = itoh[upr];            
-                spg = itoh[upg];            
+                spr = itoh[upr];
+                spg = itoh[upg];
                 spb = itoh[upb];
             }
-            ppm_fs_update3(fi, col, upr, upg, upb);
         }
         bodysize += encodeRow(ofP, raw_rowbuf, cols, nPlanes);
         if( maskmethod == mskHasMask )
             bodysize += encodeMaskrow(ofP, raw_rowbuf, cols);
-        ppm_fs_endrow(fi);
     }
     if( ofP && ODD(bodysize) )
         putByte(0);
@@ -1033,7 +1023,6 @@ doHamBody(FILE *  const ifP,
 
     /* clean up */
     free(raw_rowbuf);
-    ppm_fs_free(fi);
 
     return bodysize;
 }
@@ -1113,12 +1102,12 @@ ppmToHam(FILE *  const ifP,
             }
             break;
             case HAMMODE_RGB4:
-                colormap = computeHamCmap(cols, rows, maxval, hamcolors, 
+                colormap = computeHamCmap(cols, rows, maxval, hamcolors,
                                           &colors, 4);
                 cmapmaxval = 15;
                 break;
             case HAMMODE_RGB5:
-                colormap = computeHamCmap(cols, rows, maxval, 
+                colormap = computeHamCmap(cols, rows, maxval,
                                           hamcolors, &colors, 5);
                 cmapmaxval = 31;
                 break;
@@ -1129,7 +1118,7 @@ ppmToHam(FILE *  const ifP,
     else {
         hammapmode = HAMMODE_MAPFILE;
         if( colors > hamcolors ) {
-            pm_message("colormap too large - using first %d colors", 
+            pm_message("colormap too large - using first %d colors",
                        hamcolors);
             colors = hamcolors;
         }
@@ -1142,9 +1131,9 @@ ppmToHam(FILE *  const ifP,
         newcmap = ppm_allocrow(colors);
         table = makeValTable(cmapmaxval, maxval);
         for( i = 0; i < colors; i++ )
-            PPM_ASSIGN(newcmap[i], 
-                       table[PPM_GETR(colormap[i])], 
-                       table[PPM_GETG(colormap[i])], 
+            PPM_ASSIGN(newcmap[i],
+                       table[PPM_GETR(colormap[i])],
+                       table[PPM_GETG(colormap[i])],
                        table[PPM_GETB(colormap[i])]);
         free(table);
         ppm_freerow(colormap);
@@ -1158,16 +1147,16 @@ ppmToHam(FILE *  const ifP,
 
     bodysize = oldsize = rows * TOTALPLANES(nPlanes) * RowBytes(cols);
     if( DO_COMPRESS ) {
-        bodysize = doHamBody(ifP, NULL, cols, rows, maxval, 
+        bodysize = doHamBody(ifP, NULL, cols, rows, maxval,
                                hammaxval, nPlanes, colormap, colors);
-        /*bodysize = doHamBody(ifP, NULL, cols, 
+        /*bodysize = doHamBody(ifP, NULL, cols,
           rows, maxval, hammaxval, nPlanes, colbits, nocolor);*/
         if( bodysize > oldsize )
             pm_message("warning - %s compression increases BODY size "
-                       "by %ld%%", 
+                       "by %ld%%",
                        cmpNAME[compmethod], 100*(bodysize-oldsize)/oldsize);
         else
-            pm_message("BODY compression (%s): %ld%%", 
+            pm_message("BODY compression (%s): %ld%%",
                        cmpNAME[compmethod], 100*(oldsize-bodysize)/oldsize);
     }
 
@@ -1195,7 +1184,7 @@ ppmToHam(FILE *  const ifP,
     if( DO_COMPRESS )
         writeBodyRows();
     else
-        doHamBody(ifP, stdout, cols, rows, maxval, hammaxval, 
+        doHamBody(ifP, stdout, cols, rows, maxval, hammaxval,
                   nPlanes, colormap, colors);
 }
 
@@ -1210,7 +1199,7 @@ doDeepBody(FILE * const ifP,
            FILE * const ofP,
            int    const cols,
            int    const rows,
-           pixval const maxval, 
+           pixval const maxval,
            int    const bitspercolor) {
 
     int row, col;
@@ -1226,7 +1215,7 @@ doDeepBody(FILE * const ifP,
 
     newmaxval = pm_bitstomaxval(bitspercolor);
     if( maxval != newmaxval ) {
-        pm_message("maxval is not %d - automatically rescaling colors", 
+        pm_message("maxval is not %d - automatically rescaling colors",
                    newmaxval);
         table = makeValTable(maxval, newmaxval);
     }
@@ -1294,7 +1283,7 @@ ppmToDeep(FILE * const ifP,
             pm_message("warning - %s compression increases BODY size by %ld%%",
                        cmpNAME[compmethod], 100*(bodysize-oldsize)/oldsize);
         else
-            pm_message("BODY compression (%s): %ld%%", 
+            pm_message("BODY compression (%s): %ld%%",
                        cmpNAME[compmethod], 100*(oldsize-bodysize)/oldsize);
     }
 
@@ -1335,7 +1324,7 @@ doDcolBody(FILE *        const ifP,
            FILE *        const ofP,
            int           const cols,
            int           const rows,
-           pixval        const maxval, 
+           pixval        const maxval,
            DirectColor * const dcol) {
 
     int row, col;
@@ -1405,10 +1394,10 @@ ppmToDcol(FILE *        const ifP,
         bodysize = doDcolBody(ifP, NULL, cols, rows, maxval, dcol);
         if( bodysize > oldsize )
             pm_message("warning - %s compression increases BODY size by %ld%%",
-                       cmpNAME[compmethod], 
+                       cmpNAME[compmethod],
                        100*(bodysize-oldsize)/oldsize);
         else
-            pm_message("BODY compression (%s): %ld%%", cmpNAME[compmethod], 
+            pm_message("BODY compression (%s): %ld%%", cmpNAME[compmethod],
                        100*(oldsize-bodysize)/oldsize);
     }
 
@@ -1467,35 +1456,30 @@ doStdBody(FILE *  const ifP,
     int row, col, i;
     pixel *pP;
     rawtype *raw_rowbuf;
-    ppm_fs_info *fi = NULL;
     long bodysize = 0;
     int usehash = 1;
     colorhash_table cht;
 
     MALLOCARRAY_NOFAIL(raw_rowbuf, cols);
     cht = ppm_colorrowtocolorhash(colormap, colors);
-    if( floyd )
-        fi = ppm_fs_init(cols, maxval, FS_ALTERNATE);
 
     for( row = 0; row < rows; row++ ) {
         pixel *prow;
         prow = nextPixrow(ifP, row);
 
-        for( col = ppm_fs_startrow(fi, prow); 
-             col < cols; 
-             col = ppm_fs_next(fi, col) ) {
+        for( col = 0; col < cols; ++col ) {
             pP = &prow[col];
 
-            if( maskmethod == mskHasTransparentColor && 
+            if( maskmethod == mskHasTransparentColor &&
                 maskrow[col] == PBM_WHITE )
                 i = transpIndex;
             else {
                 /* Check hash table to see if we have already matched
-                   this color. 
+                   this color.
                 */
                 i = ppm_lookupcolor(cht, pP);
                 if( i == -1 ) {
-                    i = ppm_findclosestcolor(colormap, colors, pP);    
+                    i = ppm_findclosestcolor(colormap, colors, pP);
                         /* No; search colormap for closest match. */
                     if( usehash ) {
                         if( ppm_addtocolorhash(cht, pP, i) < 0 ) {
@@ -1507,12 +1491,10 @@ doStdBody(FILE *  const ifP,
                 }
             }
             raw_rowbuf[col] = i;
-            ppm_fs_update(fi, col, &colormap[i]);
         }
         bodysize += encodeRow(ofP, raw_rowbuf, cols, nPlanes);
         if( maskmethod == mskHasMask )
             bodysize += encodeMaskrow(ofP, raw_rowbuf, cols);
-        ppm_fs_endrow(fi);
     }
     if( ofP && ODD(bodysize) )
         putByte(0);
@@ -1520,7 +1502,6 @@ doStdBody(FILE *  const ifP,
     /* clean up */
     ppm_freecolorhash(cht);
     free(raw_rowbuf);
-    ppm_fs_free(fi);
 
     return bodysize;
 }
@@ -1534,7 +1515,7 @@ ppmToStd(FILE *  const ifP,
          int     const maxval,
          pixel * const colormapArg,
          int     const colorsArg,
-         int     const cmapmaxvalArg, 
+         int     const cmapmaxvalArg,
          int     const maxcolors,
          int     const nPlanes) {
 
@@ -1550,7 +1531,7 @@ ppmToStd(FILE *  const ifP,
 
     if( maskmethod == mskHasTransparentColor ) {
         if( transpColor ) {
-            transpIndex = 
+            transpIndex =
                 ppm_addtocolorrow(colormap, &colors, maxcolors, transpColor);
         }
         else
@@ -1572,9 +1553,9 @@ ppmToStd(FILE *  const ifP,
         newcmap = ppm_allocrow(colors);
         table = makeValTable(cmapmaxval, maxval);
         for (i = 0; i < colors; ++i)
-            PPM_ASSIGN(newcmap[i], 
-                       table[PPM_GETR(colormap[i])], 
-                       table[PPM_GETG(colormap[i])], 
+            PPM_ASSIGN(newcmap[i],
+                       table[PPM_GETR(colormap[i])],
+                       table[PPM_GETG(colormap[i])],
                        table[PPM_GETB(colormap[i])]);
         free(table);
         colormap = newcmap;
@@ -1584,13 +1565,13 @@ ppmToStd(FILE *  const ifP,
 
     bodysize = oldsize = rows * TOTALPLANES(nPlanes) * RowBytes(cols);
     if( DO_COMPRESS ) {
-        bodysize = doStdBody(ifP, NULL, cols, rows, maxval, colormap, 
+        bodysize = doStdBody(ifP, NULL, cols, rows, maxval, colormap,
                              colors, nPlanes);
         if( bodysize > oldsize )
             pm_message("warning - %s compression increases BODY size by %ld%%",
                        cmpNAME[compmethod], 100*(bodysize-oldsize)/oldsize);
         else
-            pm_message("BODY compression (%s): %ld%%", 
+            pm_message("BODY compression (%s): %ld%%",
                        cmpNAME[compmethod], 100*(oldsize-bodysize)/oldsize);
     }
 
@@ -1659,7 +1640,7 @@ ppmToRgb8(FILE * const ifP,
         for( col1 = 0; col1 < cols; col1 = col2 ) {
             col2 = col1 + 1;
             if( maskrow ) {
-                while( col2 < cols && PPM_EQUAL(pP[col1], pP[col2]) && 
+                while( col2 < cols && PPM_EQUAL(pP[col1], pP[col2]) &&
                        maskrow[col1] == maskrow[col2] )
                     col2++;
             }
@@ -1750,7 +1731,7 @@ ppmToRgbn(FILE * const ifP,
         for( col1 = 0; col1 < cols; col1 = col2 ) {
             col2 = col1 + 1;
             if( maskrow ) {
-                while( col2 < cols && PPM_EQUAL(pP[col1], pP[col2]) && 
+                while( col2 < cols && PPM_EQUAL(pP[col1], pP[col2]) &&
                        maskrow[col1] == maskrow[col2] )
                     col2++;
             }
@@ -1782,14 +1763,14 @@ ppmToRgbn(FILE * const ifP,
                 else {
                     ++compr_len;                  /* 3 bit repeat count = 0 */
                     if( count <= 255 )
-                        compr_row[compr_len++] = (unsigned char)count;  
+                        compr_row[compr_len++] = (unsigned char)count;
                             /* byte repeat count */
                     else {
-                        compr_row[compr_len++] = (unsigned char)0;   
+                        compr_row[compr_len++] = (unsigned char)0;
                             /* byte repeat count = 0 */
-                        compr_row[compr_len++] = (count >> 8) & 0xff; 
+                        compr_row[compr_len++] = (count >> 8) & 0xff;
                             /* word repeat count MSB */
-                        compr_row[compr_len++] = count & 0xff;    
+                        compr_row[compr_len++] = count & 0xff;
                             /* word repeat count LSB */
                     }
                 }
@@ -1878,6 +1859,7 @@ main(int argc, char ** argv) {
     pixval cmapmaxval;      /* maxval of colors in cmap */
     const char * mapfile;
     const char * transpname;
+    unsigned int defunctArgs = 0;
 
     ppm_init(&argc, argv);
 
@@ -1902,7 +1884,7 @@ main(int argc, char ** argv) {
         if( pm_keymatch(argv[argn], "-rgbn", 5) )
             forcemode = MODE_RGBN;
         else
-        if( pm_keymatch(argv[argn], "-maxplanes", 4) || 
+        if( pm_keymatch(argv[argn], "-maxplanes", 4) ||
             pm_keymatch(argv[argn], "-mp", 3) ) {
             if( ++argn >= argc )
                 pm_error("-maxplanes requires a value");
@@ -1910,7 +1892,7 @@ main(int argc, char ** argv) {
             fixplanes = 0;
         }
         else
-        if( pm_keymatch(argv[argn], "-fixplanes", 4) || 
+        if( pm_keymatch(argv[argn], "-fixplanes", 4) ||
             pm_keymatch(argv[argn], "-fp", 3) ) {
             if( ++argn >= argc )
                 pm_error("-fixplanes requires a value");
@@ -1935,7 +1917,7 @@ main(int argc, char ** argv) {
                     break;
                 default:
                     pm_error("This program does not know how to handle "
-                             "masking method '%s'", 
+                             "masking method '%s'",
                              mskNAME[maskmethod]);
             }
         }
@@ -2014,7 +1996,7 @@ main(int argc, char ** argv) {
         if( pm_keymatch(argv[argn], "-hambits", 5) ) {
             if( ++argn >= argc )
                 pm_usage("-hambits requires a value");
-            hamplanes = 
+            hamplanes =
                 getIntVal(argv[argn], argv[argn-1], 3, HAMMAXPLANES-2) +2;
         }
         else
@@ -2118,7 +2100,7 @@ main(int argc, char ** argv) {
                 forcemode = MODE_NONE;
         }
         else
-        if( pm_keymatch(argv[argn], "-dcbits", 4) || 
+        if( pm_keymatch(argv[argn], "-dcbits", 4) ||
             pm_keymatch(argv[argn], "-dcplanes", 4) ) {
             if( argc - argn < 4 )
                 pm_error("-dcbits requires 4 arguments");
@@ -2154,13 +2136,9 @@ main(int argc, char ** argv) {
             compmethod = getComprMethod(argv[argn]);
         }
         else
-        if( pm_keymatch(argv[argn], "-floyd", 3) || 
-            pm_keymatch(argv[argn], "-fs", 3) )
-            floyd = 1;
-        else
-        if( pm_keymatch(argv[argn], "-nofloyd", 5) || 
+        if( pm_keymatch(argv[argn], "-nofloyd", 5) ||
             pm_keymatch(argv[argn], "-nofs", 5) )
-            floyd = 0;
+	    defunctArgs++;
         else
         if( pm_keymatch(argv[argn], "-annotation", 3) ) {
             if( ++argn >= argc )
@@ -2230,10 +2208,10 @@ main(int argc, char ** argv) {
         case MODE_CMAP:
             /* Figure out the colormap. */
             pm_message("computing colormap...");
-            colormap = ppm_mapfiletocolorrow(ifP, MAXCOLORS, &colors, 
+            colormap = ppm_mapfiletocolorrow(ifP, MAXCOLORS, &colors,
                                              &cmapmaxval);
             if (colormap == NULL)
-                pm_error("too many colors - try doing a 'pnmquant %d'", 
+                pm_error("too many colors - try doing a 'pnmquant %d'",
                          MAXCOLORS);
             pm_message("%d colors found", colors);
             break;
@@ -2241,11 +2219,11 @@ main(int argc, char ** argv) {
             if (mapfile)
                 initRead(ifP, &cols, &rows, &maxval, &format, 0);
             else {
-                initRead(ifP, &cols, &rows, &maxval, &format, 1);  
+                initRead(ifP, &cols, &rows, &maxval, &format, 1);
                     /* read file into memory */
                 pm_message("computing colormap...");
-                colormap = 
-                    ppm_computecolorrow(pixels, cols, rows, MAXCOLORS, 
+                colormap =
+                    ppm_computecolorrow(pixels, cols, rows, MAXCOLORS,
                                         &colors);
                 if (colormap) {
                     cmapmaxval = maxval;
@@ -2266,7 +2244,7 @@ main(int argc, char ** argv) {
 
         pm_message("reading colormap file...");
         mapfp = pm_openr(mapfile);
-        colormap = ppm_mapfiletocolorrow(mapfp, MAXCOLORS, &colors, 
+        colormap = ppm_mapfiletocolorrow(mapfp, MAXCOLORS, &colors,
                                          &cmapmaxval);
         pm_close(mapfp);
         if (colormap == NULL)
@@ -2302,11 +2280,11 @@ main(int argc, char ** argv) {
         if (DO_COMPRESS)
             pm_rlenc_allocoutbuf(&compr_rowbuf, RowBytes(cols), PM_RLE_PACKBITS);
     }
-    
+
     switch (mode) {
         case MODE_HAM:
             viewportmodes |= vmHAM;
-            ppmToHam(ifP, cols, rows, maxval, 
+            ppmToHam(ifP, cols, rows, maxval,
                      colormap, colors, cmapmaxval, hamplanes);
             break;
         case MODE_DEEP:
@@ -2325,9 +2303,7 @@ main(int argc, char ** argv) {
             ppmToCmap(colormap, colors, cmapmaxval);
             break;
         default:
-            if (mapfile == NULL)
-                floyd = 0;          /* would only slow down conversion */
-            ppmToStd(ifP, cols, rows, maxval, colormap, colors, 
+            ppmToStd(ifP, cols, rows, maxval, colormap, colors,
                      cmapmaxval, MAXCOLORS, nPlanes);
             break;
     }
diff --git a/doc/COPYRIGHT.PATENT b/doc/COPYRIGHT.PATENT
index dd1d91e6..5e4db7d7 100644
--- a/doc/COPYRIGHT.PATENT
+++ b/doc/COPYRIGHT.PATENT
@@ -25,6 +25,13 @@ at appropriate places within the package.  A slightly out of date
 summary of all the copyrights is in the file 'doc/copyright_summary'
 in the Netpbm source tree.
 
+Each component is a package of code and documentation; e.g. the 'pamcomp'
+program and the pamcomp user manual go together and are licensed to the public
+as a package.  The Netpbm manual is just a hyperlinked collection of such
+component manuals.  Parts of the manual that are not tied to a particular
+component of code and do not carry a copyright notice are in the public
+domain.
+
 As with most public open source software, no one really knows for sure
 where the code came from.  It is possible that a contributor copied it
 without license to do so.  That might mean any user of the code owes
diff --git a/doc/HISTORY b/doc/HISTORY
index 51440fe7..6e0ca9c9 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -4,7 +4,14 @@ Netpbm.
 CHANGE HISTORY 
 --------------
 
-22.03.20 BJH  Release 10.97.06
+22.03.27 BJH  Release 10.98.00
+
+              pamtopdbimg: Add -fixedtime.
+
+              ppmfade: Use temporary files securely.
+              
+              pnmtosir: Set some possibly meaningless bits in output to zero
+              so output is repeatable.
 
               pamx: Fix bug: top-justifies image in all cases where it should
               bottom-justify.  Always broken.  (pamx was new in Netpbm 10.34
@@ -12,22 +19,24 @@ CHANGE HISTORY
 
               pnmtorle: Fix bug: -h works only on first image.
 
-22.02.27 BJH  Release 10.97.05
-
               pamsistoaglyph: Fix invalid memory reference and incorrect
               output on depth 1 input.  Always broken.  (pamsistoaglyph was
               new in Netpbm 10.47 (June 2009).  Thanks Scott Pakin.
 
-              pambayer: Fix bogus colors at edges.  Always broken (pambayer
+              pambayer: Fix bogus colors at edges.  Always Broken (pambayer
               was new in Release 10.30 (October 2005)).
 
-22.02.13 BJH  Release 10.97.04
-
               libnetpbm, various programs: fix bug: bogus warning that a color
               specified on command line cannot be represented exactly with the
               maxval being used.  Introduced in Netpbm 10.83 (June 2018).
 
-22.01.27 BJH  Release 10.97.03
+              pnmtopsnr: Fix typo in error message.  Always broken (pnmpsnr
+              was new in Netpbm 9.6 (July 2000).
+
+              ppmtoilbm: Remove -floyd (aka -fs) option, which hasn't worked
+              in a long time if ever and is inappropriate function for this
+              program.  And the broken code is inconsistent with new random
+              number logic elsewhere in the package.
 
               ppmtoapplevol: Fix bug: reads from Standard Input even when you
               specify the input file argument.  Always broken.  (ppmtoapplevol
@@ -37,25 +46,29 @@ CHANGE HISTORY
               than 255.  Always broken.  (ppmtoapplevol was new in Netpbm
               10.54 (March 2011).
 
-              pgmtexture: Fix incorrect output.  Always broken.  (Program was
-              added in primordial Netpbm in 1991).
-              
-              pgmabel: Fix incorrect output.  Always broken.  (Program was
-              new in Netpbm 10.3 (July 2002).
-
-22.01.11 BJH  Release 10.97.02
-
-              ppmtoilbm: Fix wild memory references and hangs with -map .
-              Introduced in Netpbm 9.12 (March 2001).
+              pgmmedian: fix crash when median matrix is wider or higher than
+              the input image.
 
-22.01.09 BJH  Release 10.97.01
- 
               picttoppm: Fix incorrect output for 32 bit per pixel images
               that have only 3 planes.  Broken in Netpbm 10.34 (June 2006).
 
               pamendian: fix bogus "sample exceeds maxval" failure.
               Introduced in Netpbm 10.66 (March 2014).
 
+              ppmtoilbm: Fix wild memory references and hangs with -map .
+              Introduced in Netpbm 9.12 (March 2001).
+
+              pgmtexture: Fix incorrect output.  Always broken.  (Program was
+              added in primordial Netpbm in 1991).
+              
+              pgmabel: Fix incorrect output.  Always broken.  (Program was
+              new in Netpbm 10.3 (July 2002).
+
+              Remove Floyd-Steinberg dithering functions (ppm_fs_*) from
+              libnetpbm (libppmfloyd).  No longer used.  Floyd-Steinberg
+              dithering logic can be found in pnmremap.  libppmfloyd
+              was previously used by ppmtoilbm.
+
 21.12.27 BJH  Release 10.97.00
 
               Add pbnnoise.
@@ -5798,7 +5811,7 @@ CHANGE HISTORY
 
 00.07.12 BJH  Release 9.6
 
-              Add pnmtofiasco, fiascotopnm, psnpsnr.  Thanks to Ullrich
+              Add pnmtofiasco, fiascotopnm, pnmpnsr.  Thanks to Ullrich
               Hafner.
 
               Make Pnmcrop use a temporary file instead of huge amounts
diff --git a/doc/copyright_summary b/doc/copyright_summary
index 9ab3a784..84fa9397 100644
--- a/doc/copyright_summary
+++ b/doc/copyright_summary
@@ -1,4 +1,4 @@
-Here is an analysys of Netpbm copyrights done by Steve McIntyre
+Here is an analysis of Netpbm copyrights done by Steve McIntyre
 <stevem@chiark.greenend.org.uk> finishing on October 7, 2001.
 
 It is based on Netpbm 9.20, so it doesn't cover material added since
diff --git a/editor/pamsistoaglyph.c b/editor/pamsistoaglyph.c
index f9e25518..cac1f99f 100644
--- a/editor/pamsistoaglyph.c
+++ b/editor/pamsistoaglyph.c
@@ -151,7 +151,7 @@ bestEyeSepWeEncountered(int const bestSeparation[3],
     for (i = 2; i >= 0; --i) {
         if (bestSeparation[i] != 0)
             return bestSeparation[i];
-    }    
+    }
     return altBestSeparation;
 }
 
@@ -429,3 +429,4 @@ main(int argc, const char *argv[]) {
     return 0;
 }
 
+
diff --git a/editor/pgmmedian.c b/editor/pgmmedian.c
index cdd94629..9cebeac8 100644
--- a/editor/pgmmedian.c
+++ b/editor/pgmmedian.c
@@ -25,6 +25,7 @@
 ** Image Processing Algorithms" by Ioannis Pitas.
 */
 
+#include <assert.h>
 
 #include "pm_c_util.h"
 #include "pgm.h"
@@ -32,10 +33,10 @@
 #include "mallocvar.h"
 #include "nstring.h"
 
-enum medianMethod {MEDIAN_UNSPECIFIED, SELECT_MEDIAN, HISTOGRAM_SORT_MEDIAN};
+enum MedianMethod {MEDIAN_UNSPECIFIED, SELECT_MEDIAN, HISTOGRAM_SORT_MEDIAN};
 #define MAX_MEDIAN_TYPES      2
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
@@ -43,24 +44,28 @@ struct cmdlineInfo {
     unsigned int width;
     unsigned int height;
     unsigned int cutoff;
-    enum medianMethod type;
+    enum MedianMethod type;
 };
 
 
-/* Global variables common to each median sort routine. */
 static int const forceplain = 0;
-static int format;
-static gray maxval;
-static gray **grays;
-static gray *grayrow;
-static int ccolso2, crowso2;
-static int row;
+
+
+
+/* Global variables common to each median sort routine. */
+static gray ** grays;
+    /* The convolution buffer.  This is a circular buffer that contains the
+       rows of the input image that are being convolved into the current 
+       output row.
+    */
+static gray * grayrow;
+    /* A buffer for building the current output row */
 
 
 
 static void
-parseCommandLine(int argc, char ** argv,
-                 struct cmdlineInfo * const cmdlineP) {
+parseCommandLine(int argc, const char ** argv,
+                 struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that the file spec array we return is stored in the storage that
    was passed to us as the argv array.
@@ -91,13 +96,21 @@ parseCommandLine(int argc, char ** argv,
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
     opt.allowNegNum = FALSE;  /* We may have parms that are negative numbers */
 
-    pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
+    pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
-    if (!widthSpec)
+    if (widthSpec) {
+        if (cmdlineP->width < 1)
+            pm_error("-width must be at least 1");
+    } else
         cmdlineP->width = 3;
-    if (!heightSpec)
+
+    if (heightSpec) {
+        if (cmdlineP->height < 1)
+            pm_error("-height must be at least 1");
+    } else
         cmdlineP->height = 3;
+
     if (!cutoffSpec)
         cmdlineP->cutoff = 250;
 
@@ -125,6 +138,32 @@ parseCommandLine(int argc, char ** argv,
 
 
 static void
+setWindow(gray **      const convBuffer,
+          unsigned int const crows,
+          gray **      const cgrayrow,
+          unsigned int const lastRow) {
+/*----------------------------------------------------------------------------
+   Set 'cgrayrow' so it points into the circular buffer 'convBuffer' such
+   that cgrayrow[0] is the topmost row in the buffer, given that the
+   bottommost row in the buffer is row number 'lastRow'.
+-----------------------------------------------------------------------------*/
+    unsigned int const windowTopRow = (lastRow + 1) % crows;
+
+    unsigned int bufferRow;
+    unsigned int wrow;
+
+    wrow = 0;
+
+    for (bufferRow = windowTopRow; bufferRow < crows; ++wrow, ++bufferRow)
+        cgrayrow[wrow] = grays[bufferRow];
+
+    for (bufferRow = 0; bufferRow < windowTopRow; ++wrow, ++bufferRow)
+        cgrayrow[wrow] = grays[bufferRow];
+}
+
+
+
+static void
 select489(gray * const a,
           int *  const parray,
           int    const n,
@@ -184,7 +223,13 @@ selectMedian(FILE *       const ifP,
              unsigned int const crows,
              unsigned int const cols,
              unsigned int const rows,
-             unsigned int const median) {
+             int          const format,
+             gray         const maxval,
+             unsigned int const median,
+             unsigned int const firstRow) {
+
+    unsigned int const ccolso2 = ccols / 2;
+    unsigned int const crowso2 = crows / 2;
 
     unsigned int const numValues = crows * ccols;
 
@@ -192,45 +237,39 @@ selectMedian(FILE *       const ifP,
     gray * garray;  /* Array of the currently gray values */
     int * parray;
     int * subcol;
-    gray ** rowptr;
+    gray ** cgrayrow;
+    unsigned int row;
 
     garray = pgm_allocrow(numValues);
 
-    MALLOCARRAY(rowptr, crows);
+    MALLOCARRAY(cgrayrow, crows);
     MALLOCARRAY(parray, numValues);
     MALLOCARRAY(subcol, cols);
 
-    if (rowptr == NULL || parray == NULL || subcol == NULL)
+    if (cgrayrow == NULL || parray == NULL || subcol == NULL)
         pm_error("Unable to allocate memory");
 
     for (col = 0; col < cols; ++col)
         subcol[col] = (col - (ccolso2 + 1)) % ccols;
 
     /* Apply median to main part of image. */
-    for ( ; row < rows; ++row) {
-        int crow;
-        int rownum, irow, temprow;
+    for (row = firstRow; row < rows; ++row) {
+        unsigned int crow;
         unsigned int col;
 
         pgm_readpgmrow(ifP, grays[row % crows], cols, maxval, format);
 
-        /* Rotate pointers to rows, so rows can be accessed in order. */
-        temprow = (row + 1) % crows;
-        rownum = 0;
-        for (irow = temprow; irow < crows; ++rownum, ++irow)
-            rowptr[rownum] = grays[irow];
-        for (irow = 0; irow < temprow; ++rownum, ++irow)
-            rowptr[rownum] = grays[irow];
+        setWindow(grays, crows, cgrayrow, row);
 
         for (col = 0; col < cols; ++col) {
             if (col < ccolso2 || col >= cols - ccolso2) {
-                grayrow[col] = rowptr[crowso2][col];
+                grayrow[col] = cgrayrow[crowso2][col];
             } else if (col == ccolso2) {
                 unsigned int const leftcol = col - ccolso2;
                 unsigned int i;
                 i = 0;
                 for (crow = 0; crow < crows; ++crow) {
-                    gray * const temprptr = rowptr[crow] + leftcol;
+                    gray * const temprptr = cgrayrow[crow] + leftcol;
                     unsigned int ccol;
                     for (ccol = 0; ccol < ccols; ++ccol) {
                         garray[i] = *(temprptr + ccol);
@@ -245,23 +284,16 @@ selectMedian(FILE *       const ifP,
                 unsigned int crow;
                 unsigned int tsum;
                 for (crow = 0, tsum = 0; crow < crows; ++crow, tsum += ccols)
-                    garray[tsum + subcol[col]] = *(rowptr[crow] + addcol );
+                    garray[tsum + subcol[col]] = *(cgrayrow[crow] + addcol );
                 select489( garray, parray, numValues, median );
                 grayrow[col] = garray[parray[median]];
             }
         }
         pgm_writepgmrow( stdout, grayrow, cols, maxval, forceplain );
     }
-
-    {
-        unsigned int irow;
-        /* Write out remaining unchanged rows. */
-        for (irow = crowso2 + 1; irow < crows; ++irow)
-            pgm_writepgmrow(stdout, rowptr[irow], cols, maxval, forceplain);
-    }
     free(subcol);
     free(parray);
-    free(rowptr);
+    free(cgrayrow);
     pgm_freerow(garray);
 }
 
@@ -273,31 +305,40 @@ histogramSortMedian(FILE *       const ifP,
                     unsigned int const crows,
                     unsigned int const cols,
                     unsigned int const rows,
-                    unsigned int const median) {
+                    int          const format,
+                    gray         const maxval,
+                    unsigned int const median,
+                    unsigned int const firstRow) {
 
+    unsigned int const ccolso2 = ccols / 2;
+    unsigned int const crowso2 = crows / 2;
     unsigned int const histmax = maxval + 1;
 
     unsigned int * hist;
     unsigned int mdn, ltmdn;
     gray * leftCol;
     gray * rghtCol;
-    gray ** rowptr;
-
-    MALLOCARRAY(rowptr, crows);
+    gray ** cgrayrow;
+        /* The window of the image currently being convolved, with
+           cgrayrow[0] being the top row of the window.  Pointers into grays[]
+        */
+    unsigned int row;
+        /* Row number in input -- bottommost row in the window we're currently
+           convolving
+        */
+
+    MALLOCARRAY(cgrayrow, crows);
     MALLOCARRAY(hist, histmax);
 
-    if (rowptr == NULL || hist == NULL)
+    if (cgrayrow == NULL || hist == NULL)
         pm_error("Unable to allocate memory");
 
     leftCol = pgm_allocrow(crows);
     rghtCol = pgm_allocrow(crows);
 
     /* Apply median to main part of image. */
-    for ( ; row < rows; ++row) {
+    for (row = firstRow; row < rows; ++row) {
         unsigned int col;
-        unsigned int temprow;
-        unsigned int rownum;
-        unsigned int irow;
         unsigned int i;
         /* initialize hist[] */
         for (i = 0; i < histmax; ++i)
@@ -305,24 +346,18 @@ histogramSortMedian(FILE *       const ifP,
 
         pgm_readpgmrow(ifP, grays[row % crows], cols, maxval, format);
 
-        /* Rotate pointers to rows, so rows can be accessed in order. */
-        temprow = (row + 1) % crows;
-        rownum = 0;
-        for (irow = temprow; irow < crows; ++rownum, ++irow)
-            rowptr[rownum] = grays[irow];
-        for (irow = 0; irow < temprow; ++rownum, ++irow)
-            rowptr[rownum] = grays[irow];
+        setWindow(grays, crows, cgrayrow, row);
 
         for (col = 0; col < cols; ++col) {
             if (col < ccolso2 || col >= cols - ccolso2)
-                grayrow[col] = rowptr[crowso2][col];
+                grayrow[col] = cgrayrow[crowso2][col];
             else if (col == ccolso2) {
-                unsigned int crow;
                 unsigned int const leftcol = col - ccolso2;
+                unsigned int crow;
                 i = 0;
                 for (crow = 0; crow < crows; ++crow) {
                     unsigned int ccol;
-                    gray * const temprptr = rowptr[crow] + leftcol;
+                    gray * const temprptr = cgrayrow[crow] + leftcol;
                     for (ccol = 0; ccol < ccols; ++ccol) {
                         gray const g = *(temprptr + ccol);
                         ++hist[g];
@@ -338,12 +373,12 @@ histogramSortMedian(FILE *       const ifP,
 
                 grayrow[col] = mdn;
             } else {
-                unsigned int crow;
                 unsigned int const subcol = col - (ccolso2 + 1);
                 unsigned int const addcol = col + ccolso2;
+                unsigned int crow;
                 for (crow = 0; crow < crows; ++crow) {
-                    leftCol[crow] = *(rowptr[crow] + subcol);
-                    rghtCol[crow] = *(rowptr[crow] + addcol);
+                    leftCol[crow] = *(cgrayrow[crow] + subcol);
+                    rghtCol[crow] = *(cgrayrow[crow] + addcol);
                 }
                 for (crow = 0; crow < crows; ++crow) {
                     {
@@ -381,87 +416,127 @@ histogramSortMedian(FILE *       const ifP,
         }
         pgm_writepgmrow(stdout, grayrow, cols, maxval, forceplain);
     }
-
-    {
-        /* Write out remaining unchanged rows. */
-        unsigned int irow;
-        for (irow = crowso2 + 1; irow < crows; ++irow)
-            pgm_writepgmrow(stdout, rowptr[irow], cols, maxval, forceplain);
-    }
     pgm_freerow(leftCol);
     pgm_freerow(rghtCol);
     free(hist);
-    free(rowptr);
+    free(cgrayrow);
+}
+
+
+
+static void
+convolve(FILE *            const ifP,
+         unsigned int      const cols,
+         unsigned int      const rows,
+         gray              const maxval,
+         int               const format,
+         unsigned int      const ccols,
+         unsigned int      const crows,
+         enum MedianMethod const medianMethod,
+         unsigned int      const median) {
+
+    unsigned int const crowso2 = crows / 2;
+
+    unsigned int row;
+
+    /* An even-size convolution window is biased toward the top and left.  So
+       if it is 8 rows, the window covers 4 rows above the target row and 3
+       rows below it, plus the target row itself.  'crowso2' is the number of
+       the target row within the window.  There are always 'crowso2' rows
+       above it and either crowso2 or crowso2-1 rows below it.
+    */
+
+    /* Allocate space for number of rows in mask size. */
+    grays = pgm_allocarray(cols, crows);
+    grayrow = pgm_allocrow(cols);
+
+    /* Prime the convolution window -- fill it except the last row */
+    for (row = 0; row < crows - 1; ++row)
+        pgm_readpgmrow(ifP, grays[row], cols, maxval, format);
+
+    /* Copy the top half out verbatim, since convolution kernel for these rows
+       runs off the top of the image.
+    */
+    for (row = 0; row < crowso2; ++row)
+        pgm_writepgmrow(stdout, grays[row], cols, maxval, forceplain);
+
+    switch (medianMethod) {
+    case SELECT_MEDIAN:
+        selectMedian(ifP, ccols, crows, cols, rows, format, maxval,
+                     median, crows-1);
+        break;
+
+    case HISTOGRAM_SORT_MEDIAN:
+        histogramSortMedian(ifP, ccols, crows, cols, rows, format, maxval,
+                            median, crows-1);
+        break;
+    case MEDIAN_UNSPECIFIED:
+        pm_error("INTERNAL ERROR: median unspecified");
+    }
+
+    /* Copy the bottom half of the remaining convolution window verbatim,
+       since convolution kernel for these rows runs off the bottom of the
+       image.
+    */
+    assert(crows >= crowso2 + 1);
+
+    for (row = rows - (crows-crowso2-1); row < rows; ++row)
+        pgm_writepgmrow(stdout, grays[row % crows], cols, maxval,
+                        forceplain);
+
+    pgm_freearray(grays, crows);
+    pgm_freerow(grayrow);
 }
 
 
 
 int
-main(int    argc,
-     char * argv[]) {
+main(int          argc,
+     const char * argv[]) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     FILE * ifP;
     int cols, rows;
-    int median;
-    enum medianMethod medianMethod;
+    int format;
+    gray maxval;
+    unsigned int ccols, crows;
+    unsigned int median;
+    enum MedianMethod medianMethod;
 
-    pgm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
     ifP = pm_openr(cmdline.inputFileName);
 
-    ccolso2 = cmdline.width / 2;
-    crowso2 = cmdline.height / 2;
+    assert(cmdline.height > 0 && cmdline.width > 0);
 
     pgm_readpgminit(ifP, &cols, &rows, &maxval, &format);
-    pgm_writepgminit(stdout, cols, rows, maxval, forceplain);
 
-    /* Allocate space for number of rows in mask size. */
-    grays = pgm_allocarray(cols, cmdline.height);
-    grayrow = pgm_allocrow(cols);
+    ccols = MIN(cmdline.width,  cols+1);
+    crows = MIN(cmdline.height, rows+1);
 
-    /* Read in and write out initial rows that won't get changed. */
-    for (row = 0; row < cmdline.height - 1; ++row) {
-        pgm_readpgmrow(ifP, grays[row], cols, maxval, format);
-        /* Write out the unchanged row. */
-        if (row < crowso2)
-            pgm_writepgmrow(stdout, grays[row], cols, maxval, forceplain);
-    }
+    pgm_writepgminit(stdout, cols, rows, maxval, forceplain);
 
-    median = (cmdline.height * cmdline.width) / 2;
+    median = (crows * ccols) / 2;
 
     /* Choose which sort to run. */
     if (cmdline.type == MEDIAN_UNSPECIFIED) {
-        if ((maxval / ((cmdline.width * cmdline.height) - 1)) < cmdline.cutoff)
+        if ((maxval / ((ccols * crows) - 1)) < cmdline.cutoff)
             medianMethod = HISTOGRAM_SORT_MEDIAN;
         else
             medianMethod = SELECT_MEDIAN;
     } else
         medianMethod = cmdline.type;
 
-    switch (medianMethod) {
-    case SELECT_MEDIAN:
-        selectMedian(ifP, cmdline.width, cmdline.height, cols, rows, median);
-        break;
 
-    case HISTOGRAM_SORT_MEDIAN:
-        histogramSortMedian(ifP, cmdline.width, cmdline.height,
-                            cols, rows, median);
-        break;
-    case MEDIAN_UNSPECIFIED:
-        pm_error("INTERNAL ERROR: median unspecified");
-    }
+    convolve(ifP, cols, rows, maxval, format, ccols, crows, medianMethod,
+             median);
 
     pm_close(ifP);
     pm_close(stdout);
 
-    pgm_freearray(grays, cmdline.height);
-    pgm_freerow(grayrow);
-
     return 0;
 }
 
 
-
diff --git a/editor/pnmmargin b/editor/pnmmargin
index 1b5370be..e8851bda 100755
--- a/editor/pnmmargin
+++ b/editor/pnmmargin
@@ -87,7 +87,7 @@ else
 
     case "$color" in
         -gofigure )
-        pnmcut 0 0 1 1 $tmp1 | pnmtile $size 1 > $tmp2
+        pamcut 0 0 1 1 $tmp1 | pnmtile $size 1 > $tmp2
         ;;
         -white | -black )
         pnmpad $plainopt $color \
diff --git a/editor/pnmquant b/editor/pnmquant
index 0bebce69..4dd133f1 100755
--- a/editor/pnmquant
+++ b/editor/pnmquant
@@ -66,16 +66,17 @@ sub doVersionHack($) {
 
 sub tempFile($) {
 
+    my ($suffix) = @_;
+
     # We trust Perl's File::Temp to do a better job of creating the temp
     # file, but it doesn't exist before Perl 5.6.1.
 
     if (eval { require File::Temp; 1 }) {
         return File::Temp::tempfile("pnmquant_XXXX", 
-                                    SUFFIX=>".pnm", 
+                                    SUFFIX=>$suffix, 
                                     DIR=>File::Spec->tmpdir(),
                                     UNLINK=>$TRUE);
     } else {
-        my ($suffix) = @_;
         my $fileName;
         local *file;  # For some inexplicable reason, must be local, not my
         my $i;
diff --git a/editor/pnmquantall b/editor/pnmquantall
index 80d00fce..5f434fc2 100755
--- a/editor/pnmquantall
+++ b/editor/pnmquantall
@@ -117,16 +117,17 @@ sub parseArgs($$$$) {
 
 sub tempFile($) {
 
+    my ($suffix) = @_;
+
     # We trust Perl's File::Temp to do a better job of creating the temp
     # file, but it doesn't exist before Perl 5.6.1.
 
     if (eval { require File::Temp; 1 }) {
         return File::Temp::tempfile("pnmquant_XXXX", 
-                                    SUFFIX=>".pnm", 
+                                    SUFFIX=>$suffix, 
                                     DIR=>File::Spec->tmpdir(),
                                     UNLINK=>$TRUE);
     } else {
-        my ($suffix) = @_;
         my $fileName;
         local *file;  # For some inexplicable reason, must be local, not my
         my $i;
diff --git a/editor/ppmfade b/editor/ppmfade
index dcd7bf26..7dc533a1 100755
--- a/editor/ppmfade
+++ b/editor/ppmfade
@@ -41,6 +41,8 @@ exec perl -w -x -S -- "$0" "$@"
 ##############################################################################
 use strict;
 
+use File::Temp;
+
 sub doVersionHack($) {
     my ($argvR) = @_;
 
@@ -52,7 +54,9 @@ sub doVersionHack($) {
     }
 }
 
+my $tmpdir;
 
+$tmpdir = File::Temp::tempdir("ppmfade.XXXXXX", CLEANUP => 1);
 
 my $SPREAD =  1;
 my $SHIFT =   2;
@@ -151,18 +155,18 @@ print("Frames are " . $width . "W x " . $height . "H\n");
 
 if ($first_file eq "undefined") {
     print "Fading from black to ";
-    system("ppmmake \\#000 $width $height >junk1$$.ppm");
+    system("ppmmake \\#000 $width $height >$tmpdir/junk1.ppm");
 } else {
     print "Fading from $first_file to ";
-    system("cp", $first_file, "junk1$$.ppm");
+    system("cp", $first_file, "$tmpdir/junk1.ppm");
 }
 
 if ($last_file eq "undefined") {
     print "black.\n";
-    system("ppmmake \\#000 $width $height >junk2$$.ppm");
+    system("ppmmake \\#000 $width $height >$tmpdir/junk2.ppm");
 } else {
     print "$last_file\n";
-    system("cp", $last_file, "junk2$$.ppm");
+    system("cp", $last_file, "$tmpdir/junk2.ppm");
 }
 
 #
@@ -170,14 +174,14 @@ if ($last_file eq "undefined") {
 #
 
 # Here's what our temporary files are:
-#   junk1$$.ppm: The original (fade-from) image
-#   junk2$$.ppm: The target (fade-from) image
-#   junk3$$.ppm: The frame of the fade for the current iteration of the 
-#                the for loop.
-#   junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate
-#                 image to another, this is the first frame of that 
-#                 sequence.
-#   junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence
+#   junk1.ppm: The original (fade-from) image
+#   junk2.ppm: The target (fade-from) image
+#   junk3.ppm: The frame of the fade for the current iteration of the 
+#              the for loop.
+#   junk1a.ppm: If the fade involves a ppmmix sequence from one intermediate
+#               image to another, this is the first frame of that 
+#               sequence.
+#   junk2a.ppm: This is the last frame of the above-mentioned ppmmix sequence
 
 my $i;    # Frame number
 for ($i = 1; $i <= $nframes; $i++) {
@@ -185,147 +189,151 @@ for ($i = 1; $i <= $nframes; $i++) {
     if ($mode eq $SPREAD) {
         if ($i <= 10) {
             my $n = $spline20[$i] * 100;
-            system("ppmspread $n junk1$$.ppm >junk3$$.ppm");
+            system("ppmspread $n $tmpdir/junk1.ppm >$tmpdir/junk3.ppm");
         } elsif ($i <= 20) {
             my $n;
             $n = $spline20[$i] * 100;
-            system("ppmspread $n junk1$$.ppm >junk1a$$.ppm");
+            system("ppmspread $n $tmpdir/junk1.ppm >$tmpdir/junk1a.ppm");
             $n = (1-$spline20[$i-10]) * 100;
-            system("ppmspread $n junk2$$.ppm >junk2a$$.ppm");
+            system("ppmspread $n $tmpdir/junk2.ppm >$tmpdir/junk2a.ppm");
             $n = $spline10[$i-10];
-            system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
+            system("ppmmix $n $tmpdir/junk1a.ppm $tmpdir/junk2a.ppm " .
+                   ">$tmpdir/junk3.ppm");
         } else {
             my $n = (1-$spline20[$i-10])*100;
-            system("ppmspread $n junk2$$.ppm >junk3$$.ppm");
+            system("ppmspread $n $tmpdir/junk2.ppm >$tmpdir/junk3.ppm");
         }
     } elsif ($mode eq $SHIFT) {
         if ($i <= 10) {
             my $n = $spline20[$i] * 100;
-            system("ppmshift $n junk1$$.ppm >junk3$$.ppm");
+            system("ppmshift $n $tmpdir/junk1.ppm >$tmpdir/junk3.ppm");
         } elsif ($i <= 20) {
             my $n;
             $n = $spline20[$i] * 100;
-            system("ppmshift $n junk1$$.ppm >junk1a$$.ppm");
+            system("ppmshift $n $tmpdir/junk1.ppm >$tmpdir/junk1a.ppm");
             $n = (1-$spline20[$i-10])*100;
-            system("ppmshift $n junk2$$.ppm >junk2a$$.ppm");
+            system("ppmshift $n junk2.ppm >junk2a.ppm");
             $n = $spline10[$i-10];
-            system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1a.ppm junk2a.ppm >junk3.ppm");
         } else {
             my $n = (1-$spline20[$i-10]) * 100;
-            system("ppmshift $n junk2$$.ppm >junk3$$.ppm");
+            system("ppmshift $n junk2.ppm >junk3.ppm");
         }
     } elsif ($mode eq $RELIEF) {
         if ($i == 1) {
-            system("ppmrelief junk1$$.ppm >junk1r$$.ppm");
+            system("ppmrelief junk1.ppm >junk1r.ppm");
         }
         if ($i <= 10) {
             my $n = $spline10[$i];
-            system("ppmmix $n junk1$$.ppm junk1r$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1.ppm junk1r.ppm >junk3.ppm");
         } elsif ($i <= 20) {
             my $n = $spline10[$i-10];
-            system("ppmmix $n junk1r$$.ppm junk2r$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1r.ppm junk2r.ppm >junk3.ppm");
         } else {
             my $n = $spline10[$i-20];
-            system("ppmmix $n junk2r$$.ppm junk2$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk2r.ppm junk2.ppm >junk3.ppm");
         }
         if ($i == 10) {
-            system("ppmrelief junk2$$.ppm >junk2r$$.ppm");
+            system("ppmrelief junk2.ppm >junk2r.ppm");
         }
     } elsif ($mode eq $OIL) {
         if ($i == 1) {
-            system("ppmtopgm junk1$$.ppm | pgmoil >junko$$.ppm");
-            system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
-                   ">junk1o$$.ppm");
+            system("ppmtopgm junk1.ppm | pgmoil >junko.ppm");
+            system("rgb3toppm junko.ppm junko.ppm junko.ppm " .
+                   ">junk1o.ppm");
         }
         if ($i <= 10) {
             my $n = $spline10[$i];
-            system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1.ppm junk1o.ppm >junk3.ppm");
         } elsif ($i <= 20) {
             my $n = $spline10[$i-10];
-            system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1o.ppm junk2o.ppm >junk3.ppm");
         } else {
             my $n = $spline10[$i-20];
-            system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk2o.ppm junk2.ppm >junk3.ppm");
         }
         if ($i == 10) {
-            system("ppmtopgm junk2$$.ppm | pgmoil >junko$$.ppm");
-            system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
-                   ">junk2o$$.ppm");
+            system("ppmtopgm junk2.ppm | pgmoil >junko.ppm");
+            system("rgb3toppm junko.ppm junko.ppm junko.ppm " .
+                   ">junk2o.ppm");
         }
     } elsif ($mode eq $EDGE) {
         if ($i == 1) {
-            system("ppmtopgm junk1$$.ppm | pgmedge >junko$$.ppm");
-            system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
-                   ">junk1o$$.ppm");
+            system("ppmtopgm junk1.ppm | pgmedge >junko.ppm");
+            system("rgb3toppm junko.ppm junko.ppm junko.ppm " .
+                   ">junk1o.ppm");
         }
         if ($i <= 10) {
             my $n = $spline10[$i];
-            system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1.ppm junk1o.ppm >junk3.ppm");
         } elsif ($i <= 20) {
             my $n = $spline10[$i-10];
-            system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1o.ppm junk2o.ppm >junk3.ppm");
         } else {
             my $n = $spline10[$i-20];
-            system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk2o.ppm junk2.ppm >junk3.ppm");
         }
         if ($i == 10) {
-            system("ppmtopgm junk2$$.ppm | pgmedge >junko$$.ppm");
-            system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
-                   ">junk2o$$.ppm");
+            system("ppmtopgm junk2.ppm | pgmedge >junko.ppm");
+            system("rgb3toppm junko.ppm junko.ppm junko.ppm " .
+                   ">junk2o.ppm");
         } 
     } elsif ($mode eq $BENTLEY) {
         if ($i == 1) {
-            system("ppmtopgm junk1$$.ppm | pgmbentley >junko$$.ppm");
-            system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
-                   ">junk1o$$.ppm");
+            system("ppmtopgm junk1.ppm | pgmbentley >junko.ppm");
+            system("rgb3toppm junko.ppm junko.ppm junko.ppm " .
+                   ">junk1o.ppm");
         }
         if ($i <= 10) {
             my $n = $spline10[$i];
-            system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1.ppm junk1o.ppm >junk3.ppm");
         } elsif ($i <= 20) {
             my $n = $spline10[$i-10];
-            system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
+            system("ppmmix $n junk1o.ppm junk2o.ppm >junk3.ppm");
         } else {
             my $n = $spline10[$i-20];
-            system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
+            system("ppmmix $n $tmpdir/junk2o.ppm $tmpdir/junk2.ppm " .
+                   ">$tmpdir/junk3.ppm");
         }
         if ($i == 10) {
-            system("ppmtopgm junk2$$.ppm | pgmbentley >junko$$.ppm");
-            system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
-                   ">junk2o$$.ppm");
+               system("ppmtopgm $tmpdir/junk2.ppm | pgmbentley " .
+                      ">$tmpdir/junko.ppm");
+            system("rgb3toppm $tmpdir/junko.ppm $tmpdir/junko.ppm " .
+                   "$tmpdir/junko.ppm " .
+                   ">$tmpdir/junk2o.ppm");
         }
     } elsif ($mode eq $BLOCK) {
         if ($i <= 10) {
             my $n = 1 - 1.9*$spline20[$i];
-            system("pamscale $n junk1$$.ppm | " .
-                   "pamscale -width $width -height $height >junk3$$.ppm");
+            system("pamscale $n $tmpdir/junk1.ppm | " .
+                   "pamscale -width $width -height $height " .
+                   ">$tmpdir/junk3.ppm");
         } elsif ($i <= 20) {
             my $n = $spline10[$i-10];
-            system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
+            system("ppmmix $n $tmpdir/junk1a.ppm $tmpdir/junk2a.ppm " .
+                   ">$tmpdir/junk3.ppm");
         } else {
             my $n = 1 - 1.9*$spline20[31-$i];
-            system("pamscale $n junk2$$.ppm | " .
-                   "pamscale -width $width -height $height >junk3$$.ppm");
+            system("pamscale $n $tmpdir/junk2.ppm | " .
+                   "pamscale -width $width -height $height " .
+                   ">$tmpdir/junk3.ppm");
         }
         if ($i == 10) {
-            system("cp", "junk3$$.ppm", "junk1a$$.ppm");
-            system("pamscale $n junk2$$.ppm | " .
-                   "pamscale -width $width -height $height >junk2a$$.ppm");
+            system("cp", "$tmpdir/junk3.ppm", "$tmpdir/junk1a.ppm");
+            system("pamscale $n $tmpdir/junk2.ppm | " .
+                   "pamscale -width $width -height $height " .
+                   ">$tmpdir/junk2a.ppm");
         }    
     } elsif ($mode eq $MIX) {
         my $fade_factor = sqrt(1/($nframes-$i+1));
-        system("ppmmix $fade_factor junk1$$.ppm junk2$$.ppm >junk3$$.ppm");
+        system("ppmmix $fade_factor $tmpdir/junk1.ppm $tmpdir/junk2.ppm " .
+               ">$tmpdir/junk3.ppm");
     } else {
         print("Internal error: impossible mode value '$mode'\n");
     }
 
     my $outfile = sprintf("%s.%04d.ppm", $base_name, $i);
-    system("cp", "junk3$$.ppm", $outfile);
+    system("cp", "$tmpdir/junk3.ppm", $outfile);
 }
 
-#
-#  Clean up shop.
-#
-system("rm junk*$$.ppm");
-
 exit(0);
diff --git a/editor/ppmshadow b/editor/ppmshadow
index c07c03b0..438d4fa9 100755
--- a/editor/ppmshadow
+++ b/editor/ppmshadow
@@ -198,7 +198,7 @@ if ($keeptemp) {
     mkdir($ourtmp, 0777) or
         die("Unable to create directory for temporary files '$ourtmp");
 } else {
-    $ourtmp = File::Temp::tempdir("$tmpdir/ppmshadowXXXX", UNLINK=>1);
+    $ourtmp = File::Temp::tempdir("$tmpdir/ppmshadowXXXX", CLEANUP=>1);
 }
 
 #   Apply defaults for arguments not specified
diff --git a/generator/pbmnoise.c b/generator/pbmnoise.c
index 9a537d5c..e316dafc 100644
--- a/generator/pbmnoise.c
+++ b/generator/pbmnoise.c
@@ -405,6 +405,7 @@ pbmnoise_packed(FILE *             const ofP,
 
             wordSave = bitrowByWord[words - 1];
 
+            pbm_cleanrowend_packed(bitrow0, cols);
             pbm_writepbmrow_packed(ofP, bitrow0, cols, 0);
             offset = cols % 32;
         } else {
diff --git a/lib/Makefile b/lib/Makefile
index d42658a2..d7dfc993 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -33,7 +33,6 @@ LIBOBJECTS = libpm.o pmfileio.o fileio.o colorname.o \
 	libpgm1.o libpgm2.o \
 	libppm1.o libppm2.o libppmcmap.o libppmcolor.o libppmfuzzy.o \
 	libppmd.o ppmdfont.o standardppmdfont.o path.o \
-	libppmfloyd.o \
 	libpnm1.o libpnm2.o libpnm3.o \
 	libpam.o libpamread.o libpamwrite.o \
 	libpamn.o libpammap.o libpamcolor.o \
@@ -63,7 +62,7 @@ MANUALS5 = pbm pgm ppm pnm pam
 INTERFACE_HEADERS = colorname.h \
 	pam.h pamdraw.h pammap.h pbm.h pbmfont.h pbmfontdata.h \
 	pgm.h pm.h pm_gamma.h pm_system.h pnm.h \
-	ppm.h ppmcmap.h ppmdfont.h ppmdraw.h ppmfloyd.h \
+	ppm.h ppmcmap.h ppmdfont.h ppmdraw.h \
 	util/mallocvar.h util/runlength.h util/shhopt.h \
 
 DATAFILES = rgb.txt
diff --git a/lib/libpbmfont2.c b/lib/libpbmfont2.c
index 6007d7f6..7c0415c1 100644
--- a/lib/libpbmfont2.c
+++ b/lib/libpbmfont2.c
@@ -193,9 +193,12 @@ pm_selector_mark(struct pm_selector * const selectorP,
     }
 }
 
+
+
 /* There is no function for erasing a marked bit */
 
 
+
 int  /* boolean */
 pm_selector_is_marked(const struct pm_selector * const selectorP,
                       unsigned int               const index) {
@@ -312,14 +315,13 @@ tokenize(char *         const s,
 
     while (*p) {
         if (!ISGRAPH(*p)) {
-            if(!ISSPACE(*p)) {
-              /* Control chars excluding 09 - 0d (space), 80-ff */
-            pm_message("Warning: non-ASCII character '%x' in "
-                       "BDF font file", *p);
+            if (!ISSPACE(*p)) {
+                /* Control chars excluding 09 - 0d (space), 80-ff */
+                pm_message("Warning: non-ASCII character '%x' in "
+                           "BDF font file", *p);
             }
             *p++ = '\0';
-        }
-        else {
+        } else {
             words[n++] = p;
             if (n >= wordsSz - 1)
                 break;
@@ -395,6 +397,7 @@ parseBitmapRow(const char *    const hex,
                         glyphWidth, hex);
         else {
             char const hdig = *p++;
+
             unsigned int hdigValue;
 
             if (hdig >= '0' && hdig <= '9')
@@ -517,7 +520,7 @@ static void
 validateWordCount(Readline *    const readlineP,
                   unsigned int  const nWords) {
 
-    if( readlineP->wordCt != nWords )
+    if (readlineP->wordCt != nWords)
         pm_error("Wrong number of arguments in '%s' line in BDF font file",
                  readlineP->arg[0]);
 
@@ -536,7 +539,6 @@ readExpectedStatement(Readline *    const readlineP,
   beginning of the line is that, e.g. "STARTFONT").  Check for the number
   of words: 'nWords'.  If either condition is not met, fail the program.
 -----------------------------------------------------------------------------*/
-
     bool eof;
 
     readline_read(readlineP, &eof);
@@ -561,7 +563,6 @@ skipCharacter(Readline * const readlineP) {
 
   At entry the stream must be positioned at the end of the ENCODING line.
 -----------------------------------------------------------------------------*/
-
     char * rc;
     do {
         rc = fgets(readlineP->line, MAXBDFLINE+1, readlineP->ifP);
@@ -625,10 +626,12 @@ interpEncoding(const char **  const arg,
 
    'maxmaxglyph' is the maximum codepoint in the font.
 -----------------------------------------------------------------------------*/
-    bool gotCodepoint = false;   /* initial value */
+    bool gotCodepoint;
     bool badCodepoint;
     unsigned int codepoint;
 
+    gotCodepoint = false;  /* initial value */
+
     if (wordToInt(arg[1]) >= 0) {
         codepoint = wordToInt(arg[1]);
         gotCodepoint = true;
@@ -662,8 +665,9 @@ readEncoding(Readline *     const readlineP,
              bool *         const badCodepointP,
              PM_WCHAR       const maxmaxglyph) {
 
+    const char * const expected = "ENCODING";
+
     bool eof;
-    const char * expected = "ENCODING";
 
     readline_read(readlineP, &eof);
 
@@ -672,7 +676,7 @@ readEncoding(Readline *     const readlineP,
     else if (!streq(readlineP->arg[0], expected))
         pm_error("Statement of type '%s' where '%s' expected in BDF font file",
                  readlineP->arg[0], expected);
-    else if(readlineP->wordCt != 2 &&  readlineP->wordCt != 3)
+    else if (readlineP->wordCt != 2 &&  readlineP->wordCt != 3)
         pm_error("Wrong number of arguments in '%s' line in BDF font file",
                  readlineP->arg[0]);
 
@@ -747,7 +751,7 @@ validateGlyphLimits(const struct font2 * const font2P,
 static void
 readStartchar(Readline * const readlineP,
               const char ** charNameP) {
-        
+
         const char * charName;
         bool eof;
 
@@ -786,6 +790,7 @@ readGlyph(Readline * const readlineP,
           struct glyph ** const glyphPP) {
 
     struct glyph * glyphP;
+
     MALLOCVAR(glyphP);
     if (glyphP == NULL)
         pm_error("no memory for font glyph for '%s' character",
@@ -959,8 +964,11 @@ loadCharsetString(const char *  const registry,
 }
 
 
+
 static unsigned int const maxTokenLen = 60;
 
+
+
 static void
 doCharsetRegistry(Readline *    const readlineP,
                   bool *        const gotRegistryP,
@@ -1178,7 +1186,6 @@ initializeGlyphArray(struct font2 * const font2P,
            It may not be defined in the font, but the program may try
            to use space as a substitute char
         */
-
 }
 
 
@@ -1220,7 +1227,7 @@ pbm_loadbdffont2select(const char *               const filename,
     if (font2P->selectorP == NULL) {
         PM_WCHAR i;
 
-        for(i = 0; i <= maxmaxglyph; ++i)
+        for (i = 0; i <= maxmaxglyph; ++i)
             font2P->glyph[i] = NULL;
             /* Initial value.  Overwrite later if codepoint i is defined. */
     }
@@ -1252,10 +1259,10 @@ pbm_loadbdffont2select(const char *               const filename,
     }
     fclose(ifP);
 
-    if(font2P->total_chars == 0)
+    if (font2P->total_chars == 0)
         pm_error("No glyphs found in BDF font file "
                  "in codepoint range 0 - %u", (unsigned int) maxmaxglyph);
-    if(font2P->chars == 0)
+    if (font2P->chars == 0)
         pm_error("Not any requested glyphs found in BDF font file "
                  "in codepoint range 0 - %u", (unsigned int) maxmaxglyph);
 
@@ -1272,23 +1279,21 @@ pbm_loadbdffont2select(const char *               const filename,
 }
 
 
+
 struct font2 *
 pbm_loadbdffont2(const char * const filename,
                  PM_WCHAR     const maxmaxglyph) {
 
-  return (pbm_loadbdffont2select(filename, maxmaxglyph, NULL));
-
-  return(0);
+    return pbm_loadbdffont2select(filename, maxmaxglyph, NULL);
 }
 
 
 
-
 static struct font *
 font2ToFont(const struct font2 * const font2P) {
 
-            struct font  * fontP;
-            unsigned int   codePoint;
+    struct font  * fontP;
+    unsigned int   codePoint;
 
     MALLOCVAR(fontP);
     if (fontP == NULL)
diff --git a/lib/libppmfloyd.c b/lib/libppmfloyd.c
deleted file mode 100644
index a7117c8e..00000000
--- a/lib/libppmfloyd.c
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
-These functions were taken from Ingo Wilken's ilbm package by Bryan
-Henderson on 01.03.10.  Because ppmtoilbm and ilbmtoppm are the only
-programs that will use these in the foreseeable future, they remain
-lightly documented and tested.
-
-But they look like they would be useful in other Netpbm programs that
-do Floyd-Steinberg.
-*/
-
-
-
-/* libfloyd.c - generic Floyd-Steinberg error distribution routines for PBMPlus
-**
-** Copyright (C) 1994 Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
-**
-** Permission to use, copy, modify, and distribute this software and its
-** documentation for any purpose and without fee is hereby granted, provided
-** that the above copyright notice appear in all copies and that both that
-** copyright notice and this permission notice appear in supporting
-** documentation.  This software is provided "as is" without express or
-** implied warranty.
-*/
-
-#include "netpbm/mallocvar.h"
-#include "ppm.h"
-#include "ppmfloyd.h"
-
-
-
-static void
-fs_adjust(ppm_fs_info * const fi,
-          int           const col) {
-
-    int     const errcol = col+1;
-    pixel * const pP     = &(fi->pixrow[col]);
-    pixval  const maxval = fi->maxval;
-
-    long r, g, b;
-
-    /* Use Floyd-Steinberg errors to adjust actual color. */
-    r = fi->thisrederr  [errcol]; if( r < 0 ) r -= 8; else r += 8; r /= 16;
-    g = fi->thisgreenerr[errcol]; if( g < 0 ) g -= 8; else g += 8; g /= 16;
-    b = fi->thisblueerr [errcol]; if( b < 0 ) b -= 8; else b += 8; b /= 16;
-
-    r += PPM_GETR(*pP); if ( r < 0 ) r = 0; else if ( r > maxval ) r = maxval;
-    g += PPM_GETG(*pP); if ( g < 0 ) g = 0; else if ( g > maxval ) g = maxval;
-    b += PPM_GETB(*pP); if ( b < 0 ) b = 0; else if ( b > maxval ) b = maxval;
-
-    PPM_ASSIGN(*pP, r, g, b);
-    fi->red = r; fi->green = g; fi->blue = b;
-}
-
-
-
-static ppm_fs_info *
-allocateFi(int const cols) {
-
-    ppm_fs_info * fi;
-
-    MALLOCVAR(fi);
-
-    if (fi != NULL) {
-        MALLOCARRAY(fi->thisrederr  , cols + 2);
-        MALLOCARRAY(fi->thisgreenerr, cols + 2);
-        MALLOCARRAY(fi->thisblueerr , cols + 2);
-        MALLOCARRAY(fi->nextrederr  , cols + 2);
-        MALLOCARRAY(fi->nextgreenerr, cols + 2);
-        MALLOCARRAY(fi->nextblueerr , cols + 2);
-
-        if (fi->thisrederr   == NULL ||
-            fi->thisgreenerr == NULL ||
-            fi->thisblueerr  == NULL ||
-            fi->nextrederr   == NULL ||
-            fi->nextgreenerr == NULL ||
-            fi->nextblueerr  == NULL)
-            pm_error("out of memory allocating "
-                     "Floyd-Steinberg control structure");
-    } else
-        pm_error("out of memory allocating Floyd-Steinberg control structure");
-
-    return(fi);
-}
-
-
-
-ppm_fs_info *
-ppm_fs_init(unsigned int const cols,
-            pixval       const maxval,
-            unsigned int const flags) {
-
-    ppm_fs_info * fiP;
-
-    fiP = allocateFi(cols);
-
-    fiP->lefttoright = 1;
-    fiP->cols        = cols;
-    fiP->maxval      = maxval;
-    fiP->flags       = flags;
-
-    if (flags & FS_RANDOMINIT) {
-        unsigned int i;
-        srand(pm_randseed());
-        for (i = 0; i < cols +2; ++i) {
-            /* random errors in [-1..+1] */
-            fiP->thisrederr[i]   = rand() % 32 - 16;
-            fiP->thisgreenerr[i] = rand() % 32 - 16;
-            fiP->thisblueerr[i]  = rand() % 32 - 16;
-        }
-    } else {
-        unsigned int i;
-
-        for (i = 0; i < cols + 2; ++i)
-            fiP->thisrederr[i] = fiP->thisgreenerr[i] =
-                fiP->thisblueerr[i] = 0;
-    }
-    return fiP;
-}
-
-
-
-void
-ppm_fs_free(ppm_fs_info * const fiP) {
-
-    if (fiP) {
-        free(fiP->thisrederr); free(fiP->thisgreenerr); free(fiP->thisblueerr);
-        free(fiP->nextrederr); free(fiP->nextgreenerr); free(fiP->nextblueerr);
-        free(fiP);
-    }
-}
-
-
-
-int
-ppm_fs_startrow(ppm_fs_info * const fiP,
-                pixel *       const pixrow) {
-
-    int retval;
-
-    if (!fiP)
-        retval = 0;
-    else {
-        unsigned int col;
-
-        fiP->pixrow = pixrow;
-
-        for (col = 0; col < fiP->cols + 2; ++col) {
-            fiP->nextrederr  [col] = 0;
-            fiP->nextgreenerr[col] = 0;
-            fiP->nextblueerr [col] = 0;
-        }
-
-        if(fiP->lefttoright) {
-            fiP->col_end = fiP->cols;
-            col = 0;
-        } else {
-            fiP->col_end = -1;
-            col = fiP->cols - 1;
-        }
-        fs_adjust(fiP, col);
-
-        retval = col;
-    }
-    return retval;
-}
-
-
-
-int
-ppm_fs_next(ppm_fs_info * const fiP,
-            int           const startCol) {
-
-    int col;
-
-    col = startCol;  /* initial value */
-
-    if (!fiP)
-        ++col;
-    else {
-        if (fiP->lefttoright)
-            ++col;
-        else
-            --col;
-        if (col == fiP->col_end)
-            col = fiP->cols;
-        else
-            fs_adjust(fiP, col);
-    }
-    return col;
-}
-
-
-
-void
-ppm_fs_endrow(ppm_fs_info * const fiP) {
-
-    if (fiP) {
-        {
-            long * const tmp = fiP->thisrederr;
-            fiP->thisrederr = fiP->nextrederr;
-            fiP->nextrederr = tmp;
-        }
-        {
-            long * const tmp = fiP->thisgreenerr;
-            fiP->thisgreenerr = fiP->nextgreenerr;
-            fiP->nextgreenerr = tmp;
-        }
-        {
-            long * const tmp = fiP->thisblueerr;
-            fiP->thisblueerr = fiP->nextblueerr;
-            fiP->nextblueerr = tmp;
-        }
-        if (fiP->flags & FS_ALTERNATE)
-            fiP->lefttoright = !fiP->lefttoright;
-    }
-}
-
-
-
-void
-ppm_fs_update(ppm_fs_info * const fiP,
-              int           const col,
-              pixel *       const pP) {
-
-    if (fiP)
-        ppm_fs_update3(fiP, col, PPM_GETR(*pP), PPM_GETG(*pP), PPM_GETB(*pP));
-}
-
-
-
-void
-ppm_fs_update3(ppm_fs_info * const fiP,
-               int           const col,
-               pixval        const r,
-               pixval        const g,
-               pixval        const b) {
-
-    int const errcol = col + 1;
-
-    if (fiP) {
-        long const rerr = (long)(fiP->red)   - (long)r;
-        long const gerr = (long)(fiP->green) - (long)g;
-        long const berr = (long)(fiP->blue)  - (long)b;
-
-        if ( fiP->lefttoright ) {
-            {
-                long const two_err = 2*rerr;
-
-                long err;
-
-                err = rerr;     fiP->nextrederr[errcol+1] += err;    /* 1/16 */
-                err += two_err; fiP->nextrederr[errcol-1] += err;    /* 3/16 */
-                err += two_err; fiP->nextrederr[errcol  ] += err;    /* 5/16 */
-                err += two_err; fiP->thisrederr[errcol+1] += err;    /* 7/16 */
-            }
-            {
-                long const two_err = 2*gerr;
-
-                long err;
-
-                err = gerr;     fiP->nextgreenerr[errcol+1] += err;  /* 1/16 */
-                err += two_err; fiP->nextgreenerr[errcol-1] += err;  /* 3/16 */
-                err += two_err; fiP->nextgreenerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisgreenerr[errcol+1] += err;  /* 7/16 */
-            }
-            {
-                long const two_err = 2*berr;
-
-                long err;
-
-                err = berr;     fiP->nextblueerr[errcol+1] += err;  /* 1/16 */
-                err += two_err; fiP->nextblueerr[errcol-1] += err;  /* 3/16 */
-                err += two_err; fiP->nextblueerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisblueerr[errcol+1] += err;  /* 7/16 */
-            }
-        } else {
-            {
-                long const two_err = 2*rerr;
-
-                long err;
-
-                err = rerr;     fiP->nextrederr[errcol-1] += err;    /* 1/16 */
-                err += two_err; fiP->nextrederr[errcol+1] += err;    /* 3/16 */
-                err += two_err; fiP->nextrederr[errcol  ] += err;    /* 5/16 */
-                err += two_err; fiP->thisrederr[errcol-1] += err;    /* 7/16 */
-            }
-            {
-                long const two_err = 2*gerr;
-
-                long err;
-
-                err = gerr;     fiP->nextgreenerr[errcol-1] += err;  /* 1/16 */
-                err += two_err; fiP->nextgreenerr[errcol+1] += err;  /* 3/16 */
-                err += two_err; fiP->nextgreenerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisgreenerr[errcol-1] += err;  /* 7/16 */
-            }
-            {
-                long const two_err = 2*berr;
-
-                long err;
-
-                err = berr;     fiP->nextblueerr[errcol-1] += err;  /* 1/16 */
-                err += two_err; fiP->nextblueerr[errcol+1] += err;  /* 3/16 */
-                err += two_err; fiP->nextblueerr[errcol  ] += err;  /* 5/16 */
-                err += two_err; fiP->thisblueerr[errcol-1] += err;  /* 7/16 */
-            }
-        }
-    }
-}
-
-
-
diff --git a/lib/ppmfloyd.h b/lib/ppmfloyd.h
deleted file mode 100644
index 264fc0b6..00000000
--- a/lib/ppmfloyd.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* These declarations were supposed to be in the libfloyd.h file in the ilbm
-   package, but that file was missing, so I made them up myself.  
-   - Bryan 01.03.10.
-*/
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-} /* to fake out automatic code indenters */
-#endif
-
-struct ppm_fs_info {
-    /* thisXerr and nextXerr are dynamically allocated arrays each of whose
-       dimension is the width of the image plus 2
-       */
-    long * thisrederr;
-    long * thisgreenerr;
-    long * thisblueerr;
-    long * nextrederr;
-    long * nextgreenerr;
-    long * nextblueerr;
-    int lefttoright;
-    int cols;
-    pixval maxval;
-    int flags;
-    pixel * pixrow;
-    int col_end;
-    pixval red, green, blue;
-};
-
-typedef struct ppm_fs_info ppm_fs_info;
-
-/* Bitmasks for ppm_fs_info.flags */
-#define FS_RANDOMINIT 0x01
-#define FS_ALTERNATE  0x02
-
-ppm_fs_info *
-ppm_fs_init(unsigned int const cols,
-            pixval       const maxval,
-            unsigned int const flags);
-
-void
-ppm_fs_free(ppm_fs_info *fi);
-
-int
-ppm_fs_startrow(ppm_fs_info *fi, pixel *pixrow);
-
-int
-ppm_fs_next(ppm_fs_info *fi, int col);
-
-void
-ppm_fs_endrow(ppm_fs_info *fi);
-
-void
-ppm_fs_update(    ppm_fs_info *fi, int col, pixel *pP);
-
-
-void
-ppm_fs_update3(ppm_fs_info * const fi, 
-               int           const col, 
-               pixval        const r, 
-               pixval        const g, 
-               pixval        const b);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/lib/util/shhopt.README b/lib/util/shhopt.README
index 2d241edf..f34f9a39 100644
--- a/lib/util/shhopt.README
+++ b/lib/util/shhopt.README
@@ -7,19 +7,20 @@ The file LICENSE.TXT in this directory contains the license (the
 Artistic License) under which Bryan took and redistributed Shhopt and
 the license under which Bryan offers the modified Shhopt to others.
 
-Bryan made the following changes to shhopt for Netpbm.  It is fully
-backward compatible with the original.
+Bryan made the following changes to shhopt for Netpbm.  
 
 - OPT_FLOAT (floating point number) data type added
 
-- optParseOptions2() added.  Advantages over optParseOptions(): You
+- symbols prefixed with "pm_".
+
+- pm_optParseOptions2() added.  Advantages over pm_optParseOptions(): You
   can have a syntax where there is no such thing as a short option
   (e.g. -a.  Maybe stacked like -tanp).  Then the long options can
   have either 1 or 2 dashes (e.g. -width or --width).  Of course, -w
   could be an abbreviation of -width; that's not the same thing as a
   short option.
 
-- optParseOptions3() added.  Advantages over optParseOptions2(): 
+- pm_optParseOptions3() added.  Advantages over pm_optParseOptions2(): 
   Tells you whether (how many times, actually) an option was
   specified - no need to play games with defaults.  Also, no need
   to initialize an option value variable.
@@ -34,6 +35,15 @@ backward compatible with the original.
 - replace isdigit() with ISDIGIT() from Netpbm nstring.h so weird 
   8-bit characters don't cause incorrect results.
 
+- OPT_NAMELIST and OPT_STRINGLIST added.
+
+WARNING: pm_optParseOptionsX modify their argv argument (the array of
+pointers, not the the things to which they point).
+
+WARNING: The option values returned by pm_optParseOptionsX for options of type
+OPT_STRING reside in the program's argument space (the memory addressed by the
+program's argv array).
+
 ------------------------------------------------------------------------------
 
 
diff --git a/other/pambayer.c b/other/pambayer.c
index 9cffc8f0..599dc11e 100644
--- a/other/pambayer.c
+++ b/other/pambayer.c
@@ -18,7 +18,7 @@
   USA
 
   Copyright Alexandre Becoulet <diaxen AT free DOT fr>
-  
+
   Completely rewritten for Netpbm by Bryan Henderson August 2005.
 */
 
@@ -32,24 +32,24 @@
 #include "nstring.h"
 
 
-enum bayerType {
+enum BayerType {
     BAYER1,
     BAYER2,
     BAYER3,
     BAYER4
 };
 
-struct cmdlineInfo {
-    const char * inputFilespec;
-    enum bayerType bayerType;
-    unsigned int nointerpolate;
+struct CmdlineInfo {
+    const char *   inputFilespec;
+    enum BayerType bayerType;
+    unsigned int   nointerpolate;
 };
 
 
 
 static void
 parseCommandLine(int argc, const char ** argv,
-                 struct cmdlineInfo * const cmdlineP) {
+                 struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that the file spec array we return is stored in the storage that
    was passed to us as the argv array.
@@ -66,10 +66,10 @@ parseCommandLine(int argc, const char ** argv,
     MALLOCARRAY_NOFAIL(option_def, 100);
 
     option_def_index = 0;   /* incremented by OPTENT3 */
-    OPTENT3(0, "type",     OPT_UINT, &type,
-            &typeSpec, 0);
+    OPTENT3(0, "type",          OPT_UINT, &type,
+            &typeSpec,                      0);
     OPTENT3(0, "nointerpolate", OPT_FLAG, NULL,
-            &cmdlineP->nointerpolate, 0);
+            &cmdlineP->nointerpolate,       0);
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
@@ -104,47 +104,60 @@ parseCommandLine(int argc, const char ** argv,
 
 static void
 clearTuples(const struct pam * const pamP,
-	    tuple **           const outtuples) {
+            tuple **           const outtuples) {
+/*----------------------------------------------------------------------------
+  Make tuples at the edge that may not get set to anything by the normal
+  computation of the bayer pattern black.
+-----------------------------------------------------------------------------*/
+    if (pamP->height <= 4 || pamP->width <= 4) {
+        unsigned int row;
+
+        for (row = 0; row < pamP->height; ++row) {
+            unsigned int col;
+            for (col = 0; col < pamP->width; ++col) {
+                unsigned int plane;
+                for (plane = 0; plane < pamP->depth; ++plane)
+                    outtuples[row][col][plane] = 0;
+            }
+        }
+    } else {
+        unsigned int col;
+        unsigned int row;
 
-    unsigned int row;
-    unsigned int col;
-    unsigned int plane;
+        for (col = 0; col < pamP->width; ++col) {
+            unsigned int plane;
 
-    if(pamP->height <= 4 || pamP->width <= 4) {
-        for(row=0; row < pamP->height; ++row)
-          for(col=0; col < pamP->width; ++col)
-            for (plane=0; plane < pamP->depth; ++plane)
-              outtuples[row][col][plane] = 0;
-    }
-    else {
-        for(col = 0; col < pamP->width; ++col)
             for (plane = 0; plane < pamP->depth; ++plane) {
                 outtuples[0][col][plane] = 0;
                 outtuples[1][col][plane] = 0;
                 outtuples[pamP->height-2][col][plane] = 0;
                 outtuples[pamP->height-1][col][plane] = 0;
-          }
+            }
 
-        for(row = 2; row < pamP->height - 2; ++row)
-            for (plane = 0; plane < pamP->depth; ++plane) {
-                outtuples[row][0][plane] = 0;
-                outtuples[row][1][plane] = 0;
-                outtuples[row][pamP->width-2][plane] = 0;
-                outtuples[row][pamP->width-1][plane] = 0;
+            for (row = 2; row < pamP->height - 2; ++row) {
+                unsigned int plane;
+
+                for (plane = 0; plane < pamP->depth; ++plane) {
+                    outtuples[row][0][plane] = 0;
+                    outtuples[row][1][plane] = 0;
+                    outtuples[row][pamP->width-2][plane] = 0;
+                    outtuples[row][pamP->width-1][plane] = 0;
+                }
             }
+        }
     }
 }
 
 
 
 static void
-calc_4(const struct pam * const pamP,
-       tuple **           const intuples,
-       tuple **           const outtuples,
-       unsigned int       const plane,
-       bool               const noInterpolation,
-       unsigned int       const xoffset,
-       unsigned int       const yoffset) {
+calc4(const struct pam * const pamP,
+      tuple **           const intuples,
+      tuple **           const outtuples,
+      unsigned int       const plane,
+      bool               const noInterpolation,
+      unsigned int       const xoffset,
+      unsigned int       const yoffset) {
 /*----------------------------------------------------------------------------
     X . X
     . . .
@@ -158,7 +171,7 @@ calc_4(const struct pam * const pamP,
   (even/odd is with respect to ('xoffset', 'yoffset')).
 -----------------------------------------------------------------------------*/
     unsigned int row;
-    
+
     /* Do the even rows -- the even column pixels get copied from the input,
        while the odd column pixels get the mean of adjacent even ones
     */
@@ -177,7 +190,7 @@ calc_4(const struct pam * const pamP,
     for (row = yoffset; row + 2 < pamP->height; row += 2) {
         unsigned int col;
         for (col = xoffset; col < pamP->width; ++col) {
-            outtuples[row + 1][col][plane] = 
+            outtuples[row + 1][col][plane] =
                 noInterpolation ?
                 0 :
                 (outtuples[row][col][plane] +
@@ -189,13 +202,13 @@ calc_4(const struct pam * const pamP,
 
 
 static void
-calc_5(const struct pam * const pamP,
-       tuple **           const intuples,
-       tuple **           const outtuples,
-       unsigned int       const plane,
-       bool               const noInterpolation,
-       unsigned int       const xoffset,
-       unsigned int       const yoffset) {
+calc5(const struct pam * const pamP,
+      tuple **           const intuples,
+      tuple **           const outtuples,
+      unsigned int       const plane,
+      bool               const noInterpolation,
+      unsigned int       const xoffset,
+      unsigned int       const yoffset) {
 /*----------------------------------------------------------------------------
    . X .
    X . X
@@ -231,7 +244,7 @@ calc_5(const struct pam * const pamP,
 
 
 
-struct compAction {
+struct CompAction {
     unsigned int xoffset;
     unsigned int yoffset;
     void (*calc)(const struct pam * const pamP,
@@ -244,54 +257,68 @@ struct compAction {
 };
 
 
+struct BayerPattern {
+
+    struct CompAction compAction[3];
+        /* compAction[n] tells how to compute Plane 'n' */
+};
+
 
-static struct compAction const comp_1[3] = {
+
+static struct BayerPattern const bayer1 = {
 /*----------------------------------------------------------------------------
   G B G B
   R G R G
   G B G B
   R G R G
 -----------------------------------------------------------------------------*/
-
-    { 0, 1, calc_4 },
-    { 0, 1, calc_5 },
-    { 1, 0, calc_4 }
+    {  /* compAction */
+        { 0, 1, calc4 },
+        { 0, 1, calc5 },
+        { 1, 0, calc4 }
+    }
 };
 
-static struct compAction const comp_2[3] = {
+static struct BayerPattern const bayer2 = {
 /*----------------------------------------------------------------------------
   R G R G
   G B G B
   R G R G
   G B G B
 -----------------------------------------------------------------------------*/
-    { 0, 0, calc_4 },
-    { 0, 0, calc_5 },
-    { 1, 1, calc_4 }
+    {  /* compAction */
+        { 0, 0, calc4 },
+        { 0, 0, calc5 },
+        { 1, 1, calc4 }
+    }
 };
 
-static struct compAction const comp_3[3] = {
+static struct BayerPattern const bayer3 = {
 /*----------------------------------------------------------------------------
   B G B G
   G R G R
   B G B G
   G R G R
 -----------------------------------------------------------------------------*/
-    { 1, 1, calc_4 },
-    { 0, 0, calc_5 },
-    { 0, 0, calc_4 }
+    {  /* compAction */
+        { 1, 1, calc4 },
+        { 0, 0, calc5 },
+        { 0, 0, calc4 }
+    }
 };
 
-static struct compAction const comp_4[3] = {
+static struct BayerPattern const bayer4 = {
 /*----------------------------------------------------------------------------
   G R G R
   B G B G
   G R G R
   B G B G
 -----------------------------------------------------------------------------*/
-    { 1, 0, calc_4 },
-    { 0, 1, calc_5 },
-    { 0, 1, calc_4 }
+    {  /* compAction */
+        { 1, 0, calc4 },
+        { 0, 1, calc5 },
+        { 0, 1, calc4 }
+    }
 };
 
 
@@ -315,56 +342,83 @@ makeOutputPam(const struct pam * const inpamP,
 
 
 
-static const struct compAction *
-actionTableForType(enum bayerType const bayerType) {
+struct XyOffset {
+/*----------------------------------------------------------------------------
+   A two-dimensional offset within a matrix.
+-----------------------------------------------------------------------------*/
+    unsigned int row;
+    unsigned int col;
+};
+
+
+
+static const struct CompAction *
+actionTableForType(enum BayerType const bayerType) {
 
-    const struct compAction * retval;
+    const struct CompAction * retval;
 
     switch (bayerType) {
-    case BAYER1: retval = comp_1; break;
-    case BAYER2: retval = comp_2; break;
-    case BAYER3: retval = comp_3; break;
-    case BAYER4: retval = comp_4; break;
+    case BAYER1: retval = bayer1.compAction; break;
+    case BAYER2: retval = bayer2.compAction; break;
+    case BAYER3: retval = bayer3.compAction; break;
+    case BAYER4: retval = bayer4.compAction; break;
     }
     return retval;
 }
 
 
 
-int
+static void
+calcImage(struct pam *   const inpamP,
+          tuple **       const intuples,
+          struct pam *   const outpamP,
+          tuple **       const outtuples,
+          enum BayerType const bayerType,
+          bool           const wantNoInterpolate) {
+
+    const struct CompAction * const compActionTable =
+        actionTableForType(bayerType);
+
+    unsigned int plane;
+
+    clearTuples(outpamP, outtuples);
+
+    for (plane = 0; plane < 3; ++plane) {
+
+        struct CompAction const compAction = compActionTable[plane];
+
+        compAction.calc(inpamP, intuples, outtuples, plane,
+                        wantNoInterpolate,
+                        compAction.xoffset, compAction.yoffset);
+    }
+}
+
+
+            int
 main(int argc, const char **argv) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     FILE * ifP;
     struct pam inpam;
     struct pam outpam;
     tuple ** intuples;
     tuple ** outtuples;
-    const struct compAction * compActionTable;
-    unsigned int plane;
 
     pm_proginit(&argc, argv);
-    
+
     parseCommandLine(argc, argv, &cmdline);
-    
+
     ifP = pm_openr(cmdline.inputFilespec);
-    
-    intuples = pnm_readpam(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));
 
-    compActionTable = actionTableForType(cmdline.bayerType);
+    intuples = pnm_readpam(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));
 
     makeOutputPam(&inpam, &outpam);
 
     outtuples = pnm_allocpamarray(&outpam);
-    clearTuples(&outpam, outtuples);
 
-    for (plane = 0; plane < 3; ++plane) {
-        struct compAction const compAction = compActionTable[plane];
+    calcImage(&inpam, intuples, &outpam, outtuples,cmdline.bayerType,
+              !!cmdline.nointerpolate);
 
-        compAction.calc(&inpam, intuples, outtuples, plane,
-                        cmdline.nointerpolate,
-                        compAction.xoffset, compAction.yoffset);
-    }
     pnm_writepam(&outpam, outtuples);
 
     pnm_freepamarray(outtuples, &outpam);
@@ -372,3 +426,6 @@ main(int argc, const char **argv) {
 
     return 0;
 }
+
+
+
diff --git a/other/pamendian.c b/other/pamendian.c
index c24d9629..8826b06f 100644
--- a/other/pamendian.c
+++ b/other/pamendian.c
@@ -1,20 +1,21 @@
-/******************************************************************************
+/*=============================================================================
                               pamendian
-*******************************************************************************
+===============================================================================
 
   Reverse the endianness of multi-byte samples in a Netpbm stream.
   I.e. convert between the true format and the little endian variation of
   it.
-******************************************************************************/
-  
+=============================================================================*/
+
 #include "pam.h"
 
 
 static sample
-reverseSample(sample const insample, unsigned int const bytesPerSample) {
+reverseSample(sample       const insample,
+              unsigned int const bytesPerSample) {
 /*----------------------------------------------------------------------------
   Return a sample whose value is the least significant
-  'bytes_per_sample' bytes, in reverse order.
+  'bytesPerSample' bytes, in reverse order.
 -----------------------------------------------------------------------------*/
     unsigned int bytePos;
     sample shiftedInsample;
@@ -30,14 +31,14 @@ reverseSample(sample const insample, unsigned int const bytesPerSample) {
 
 
 
-int main(int argc, char *argv[]) {
+int main(int argc, const char ** argv) {
 
     struct pam inpam, outpam;
     tuple * intuplerow;
     tuple * outtuplerow;
     unsigned int row;
 
-    pnm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     pnm_readpaminit(stdin, &inpam, PAM_STRUCT_SIZE(tuple_type));
 
@@ -46,27 +47,39 @@ int main(int argc, char *argv[]) {
 
     pnm_writepaminit(&outpam);
 
-    intuplerow = pnm_allocpamrow(&inpam);      
-    outtuplerow = pnm_allocpamrow(&outpam);
-
+    /* We read the samples as if the maxval is 65535 so pnm_readpamrow, which
+       assumes big-endian samples, doesn't choke on a little-endian sample,
+       finding it to exceed the maxval.  (The pure way to do this would be not
+       to use libnetpbm row reading and writing facilities on little-endian
+       pseudo-Netpbm images, but this program isn't important enough to
+       justify that effort).
+    */
     inpam.maxval = 65535;
 
-    for (row = 0; row < inpam.height; row++) {
+    intuplerow  = pnm_allocpamrow(&inpam);
+    outtuplerow = pnm_allocpamrow(&outpam);
+
+    for (row = 0; row < inpam.height; ++row) {
         unsigned int col;
+
         pnm_readpamrow(&inpam, intuplerow);
-        for (col = 0; col < inpam.width; col++) {
+        for (col = 0; col < inpam.width; ++col) {
             unsigned int plane;
-            for (plane = 0; plane < inpam.depth; plane++) 
-                outtuplerow[col][plane] = 
-                    reverseSample(intuplerow[col][plane], 
+
+            for (plane = 0; plane < inpam.depth; ++plane) {
+                outtuplerow[col][plane] =
+                    reverseSample(intuplerow[col][plane],
                                   inpam.bytes_per_sample);
+            }
         }
         pnm_writepamrow(&outpam, outtuplerow);
     }
 
-    pnm_freepamrow(outtuplerow);        
-    pnm_freepamrow(intuplerow);        
+    pnm_freepamrow(outtuplerow);
+    pnm_freepamrow(intuplerow);
 
-    exit(0);
+    return 0;
 }
 
+
+
diff --git a/other/pamx/window.c b/other/pamx/window.c
index d44008c9..61089ea5 100644
--- a/other/pamx/window.c
+++ b/other/pamx/window.c
@@ -1,8 +1,8 @@
 /*
    Functions to allocate and deallocate structures and structure data
- 
+
    By Jim Frost 1989.10.03, Bryan Henderson 2006.03.25.
- 
+
    See COPYRIGHT file for copyright information.
 */
 
@@ -80,10 +80,10 @@ static void
 setDeleteWindow(viewer * const viewerP) {
 
     Atom const protoAtom = XInternAtom(viewerP->dispP, "WM_PROTOCOLS", False);
-    
+
     viewerP->deleteAtom = XInternAtom(viewerP->dispP,
                                       "WM_DELETE_WINDOW", False);
-    
+
     if ((protoAtom != None) && (viewerP->deleteAtom != None))
         XChangeProperty(viewerP->dispP, viewerP->viewportWin,
                         protoAtom, XA_ATOM, 32, PropModeReplace,
@@ -139,7 +139,7 @@ createViewer(viewer **     const viewerPP,
              bool          const fullscreen) {
 
     viewer * viewerP;
-    
+
     XSetWindowAttributes  swa_view;
 
     MALLOCVAR_NOFAIL(viewerP);
@@ -164,7 +164,7 @@ createViewer(viewer **     const viewerPP,
         ButtonPressMask | Button1MotionMask | KeyPressMask |
         StructureNotifyMask | EnterWindowMask | LeaveWindowMask;
     swa_view.save_under       = FALSE;
-    
+
     viewerP->viewportWin =
         XCreateWindow(dispP, RootWindow(dispP, scrn),
                       viewerP->xpos, viewerP->ypos,
@@ -176,7 +176,7 @@ createViewer(viewer **     const viewerPP,
                       &swa_view);
 
     setXloadimageClassHint(viewerP->dispP, viewerP->viewportWin);
-    
+
     setDeleteWindow(viewerP);
 
     viewerP->blank = TRUE;
@@ -192,7 +192,7 @@ determineRepaintStrategy(viewer  *    const viewerP,
                          bool         const verbose,
                          XImageInfo * const ximageinfoP,
                          Pixmap *     const pixmapP) {
-                        
+
     /* Decide how we're going to handle repaints.  We have three modes:
        use backing-store, use background pixmap, and use exposures.
        If the server allows backing-store, we enable it and use it.
@@ -200,7 +200,7 @@ determineRepaintStrategy(viewer  *    const viewerP,
        server does not have backing-store, we try to send the image to
        a pixmap and use that as backing-store.  If that fails, we use
        exposures to blit the image (which is ugly but it works).
-       
+
        'use_pixmap' forces background pixmap mode, which may improve
        performance.
     */
@@ -303,7 +303,7 @@ createImageWindow(viewer *      const viewerP,
 
 static void
 destroyImageWindow(viewer * const viewerP) {
-    
+
     if (viewerP->imageWin) {
         if (viewerP->imageColormap &&
             (viewerP->imageColormap != DefaultColormap(viewerP->dispP, viewerP->scrn)))
@@ -311,7 +311,7 @@ destroyImageWindow(viewer * const viewerP) {
         XDestroyWindow(viewerP->dispP, viewerP->imageWin);
     }
 }
-                       
+
 
 
 static void
@@ -348,12 +348,32 @@ placeImage(viewer * const viewerP,
            int      const height,
            int *    const rxP,     /* input and output */
            int *    const ryP) {   /* input and output */
+/*----------------------------------------------------------------------------
+   Move the X window of *viewerP on the right place on the display to contain
+   an image whose dimensions are 'width' by 'height'.
+
+   As input *rxP and *ryP are the current location of the window (offset from
+   the top left corner of the display of the top left corner of the window).
+   We update them with the new location.
+
+   If the image is narrower than the display, center it.
+
+   Otherwise, either left-justify it or right-justify it depending upon the
+   current position of the window:
+
+      If in the current position, the right edge of the image is within the
+      display, right-justify.
 
+      Otherwise left-justify.
+
+
+   Do the analogous thing for vertical placement.
+-----------------------------------------------------------------------------*/
     int pixx, pixy;
-    
+
     pixx = *rxP;
     pixy = *ryP;
-    
+
     if (viewerP->width > width)
         pixx = (viewerP->width - width) / 2;
     else {
@@ -434,10 +454,10 @@ destroyViewer(viewer * const viewerP) {
     if (viewerP->imageWin)
         XDestroyWindow(viewerP->dispP, viewerP->imageWin);
     viewerP->imageWin = 0;
-    
+
     if (viewerP->viewportWin)
         XDestroyWindow(viewerP->dispP, viewerP->viewportWin);
-    
+
     viewerP->viewportWin = 0;
 
     XFreeCursor(viewerP->dispP, viewerP->cursor);
@@ -459,12 +479,12 @@ setViewportColormap(viewer *  const viewerP,
 
     if (cmap_atom == None)
         cmap_atom = XInternAtom(viewerP->dispP, "WM_COLORMAP_WINDOWS", False);
-    
+
     /* If the visual we're using is the same as the default visual (used by
        the viewport window) then we can set the viewport window to use the
        image's colormap.  This keeps most window managers happy.
     */
-    
+
     if (visualP == DefaultVisual(viewerP->dispP, viewerP->scrn)) {
         swa.colormap = viewerP->imageColormap;
         XChangeWindowAttributes(viewerP->dispP, viewerP->viewportWin,
@@ -507,11 +527,11 @@ iconName(const char * const s) {
         t = strchr(buf, ' ');
         if (t)
             *t = '\0';
-    
+
         /* Strip off leading path.  if you don't use unix-style paths,
            You might want to change this.
         */
-    
+
         t= strrchr(buf, '/');
         if (t) {
             char * p;
@@ -557,7 +577,7 @@ visualClassFromName(const char * const name) {
     unsigned int a;
     int class;
     bool found;
-    
+
     for (a = 0, found = FALSE; VisualClassName[a].name; ++a) {
         if (strcaseeq(VisualClassName[a].name, name)) {
             /* Check for uniqueness.  We special-case StaticGray
@@ -674,10 +694,10 @@ bestVisual(Display *      const disp,
         pm_message("bestVisual: didn't find any depths?!?");
         depth = DefaultDepth(disp, scrn);
     }
-    
+
     /* given this depth, find the best possible visual
      */
-    
+
     default_visualP = DefaultVisual(disp, scrn);
     switch (imageP->type) {
     case ITRUE: {
@@ -697,7 +717,7 @@ bestVisual(Display *      const disp,
                 visualP = bestVisualOfClassAndDepth(disp, scrn, TrueColor,
                                                     depth);
         }
-        
+
         if (!visualP || ((depth <= 8) &&
                          bestVisualOfClassAndDepth(disp, scrn, PseudoColor,
                                                    depth)))
@@ -711,7 +731,7 @@ bestVisual(Display *      const disp,
         if (!visualP)
             visualP = bestVisualOfClassAndDepth(disp, scrn, StaticGray, depth);
     } break;
-        
+
     case IRGB: {
         /* if it's an RGB image, we want PseudoColor if we can get it */
 
@@ -814,7 +834,7 @@ getImageDispDimensions(viewer *       const viewerP,
         *widthP  = viewerP->width;
         *heightP = viewerP->height;
     } else {
-        unsigned int const displayWidth = 
+        unsigned int const displayWidth =
             DisplayWidth(viewerP->dispP, viewerP->scrn);
         unsigned int const displayHeight =
             DisplayHeight(viewerP->dispP, viewerP->scrn);
@@ -878,9 +898,9 @@ getVisualAndDepth(Image *        const imageP,
 static void
 setNormalSizeHints(viewer *     const viewerP,
                    Image *      const imageP) {
-    
+
     XSizeHints sh;
-    
+
     sh.width  = viewerP->width;
     sh.height = viewerP->height;
     if (viewerP->fullscreen) {
@@ -984,7 +1004,7 @@ run(viewer *     const viewerP,
             KeySym ks;
             XComposeStatus status;
             Status rc;
-            
+
             rc = XLookupString(&event.key, buf, 128, &ks, &status);
             if (rc == 1) {
                 char const ret = buf[0];
@@ -1093,7 +1113,7 @@ static void
 resizeViewer(viewer *     const viewerP,
              unsigned int const newWidth,
              unsigned int const newHeight) {
-    
+
     if (viewerP->width != newWidth || viewerP->height != newHeight) {
         XResizeWindow(viewerP->dispP, viewerP->viewportWin,
                       newWidth, newHeight);
@@ -1116,7 +1136,7 @@ displayInViewer(viewer *       const viewerP,
                 const char *   const title,
                 bool           const verbose,
                 int *          const retvalP) {
-    
+
     XImageInfo *     ximageInfoP;
     Visual *         visual;
     unsigned int     depth;
@@ -1134,7 +1154,7 @@ displayInViewer(viewer *       const viewerP,
     getVisualAndDepth(imageP, viewerP->dispP, viewerP->scrn,
                       fit, visualSpec, visualClass,
                       &visual, &depth);
-    
+
     if (verbose && (visual != DefaultVisual(viewerP->dispP, viewerP->scrn)))
         pm_message("Using %s visual", nameOfVisualClass(visual->class));
 
@@ -1211,3 +1231,6 @@ displayInViewer(viewer *       const viewerP,
 
     *retvalP = retvalueFromExitReason(exitReason);
 }
+
+
+
diff --git a/test/411toppm.test b/test/411toppm.test
index 98170c67..7a9e533c 100755
--- a/test/411toppm.test
+++ b/test/411toppm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: 411toppm
 # Also requires:
 
diff --git a/test/Execute-Tests b/test/Execute-Tests
index da4504a4..9b51cfd5 100755
--- a/test/Execute-Tests
+++ b/test/Execute-Tests
@@ -185,8 +185,8 @@ elif [ $VALGRIND_TESTS = "on" ]
   # You may want to add --track-origins=yes to the above.
 
   for i in awk basename cat cksum cmp comm cp cut date dirname \
-           egrep fgrep file grep gs head iconv ls mkdir mktemp perl rm \
-           sed seq sh sort tee tr uniq wc \
+           egrep fgrep file grep gs head iconv ls mkdir mktemp perl \
+           printf rm sed seq sh sort tee tr uniq wc \
            testrandom Available-Testprog
 
     # Tell valgrind not to probe execution of the above programs.
diff --git a/test/Test-Order b/test/Test-Order
index c21f892d..dd89a91c 100644
--- a/test/Test-Order
+++ b/test/Test-Order
@@ -80,6 +80,7 @@ pnminvert.test
 pamchannel.test
 ppmchange.test
 pambackground.test
+pnmpad-reportonly.test
 pnmpaste-pbm.test
 
 ppmshift.test
@@ -129,16 +130,32 @@ pammixmulti-identity.test
 
 symmetry.test
 
+# Standard input tests
+
+stdin-pbm1.test
+stdin-pbm2.test
+stdin-pgm1.test
+stdin-pgm2.test
+stdin-ppm1.test
+stdin-ppm2.test
+stdin-ppm3.test
+stdin-pnm1.test
+stdin-pnm2.test
+stdin-pam1.test
+stdin-pam2.test
+stdin-pam3.test
+
+pbm-misc-converters.test
+
 # Format converter tests
 
 pamtopdbimg.test
 pbmtog3.test
+ppmtoapplevol.test
 411toppm.test
 eyuvtoppm.test
 rawtoppm.test
 
-pbm-misc-converters.test
-
 gif-transparent1.test
 
 # Miscellaneous utility tests
@@ -155,6 +172,7 @@ pnm-plain-roundtrip.test
 pnm-pam-roundtrip.test
 pnminvert-roundtrip.test
 pamflip-roundtrip.test
+pamflip-pbm-roundtrip.test
 pamdepth-roundtrip.test
 pad-crop-roundtrip.test
 pbm-ppm-roundtrip.test
diff --git a/test/atari-roundtrip.test b/test/atari-roundtrip.test
index 413438a1..809cbdb2 100755
--- a/test/atari-roundtrip.test
+++ b/test/atari-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtopi1 pi1toppm ppmtoneo neotoppm
 # Also requires: pgmramp pamscale pbmmake pamenlarge rgb3toppm pamdepth
 
diff --git a/test/atk-roundtrip.test b/test/atk-roundtrip.test
index f87c2e78..97ac1be7 100755
--- a/test/atk-roundtrip.test
+++ b/test/atk-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtoatk atktopbm
 # Also requires: pbmmake
 
diff --git a/test/avs-roundtrip.test b/test/avs-roundtrip.test
index 042ce91e..255226db 100755
--- a/test/avs-roundtrip.test
+++ b/test/avs-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtoavs avstopam
 # Also requires: pamtopnm
 
diff --git a/test/bmp-roundtrip.test b/test/bmp-roundtrip.test
index df858a09..340eee66 100755
--- a/test/bmp-roundtrip.test
+++ b/test/bmp-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: bmptopnm ppmtobmp
 # Also requires: pamchannel pamtopnm pamseq
 
diff --git a/test/channel-stack-roundtrip.test b/test/channel-stack-roundtrip.test
index dae64605..a640b98d 100755
--- a/test/channel-stack-roundtrip.test
+++ b/test/channel-stack-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamchanel pamstack
 # Also requires: pamtopam pamstack pamtopnm
 
diff --git a/test/cis-roundtrip.test b/test/cis-roundtrip.test
index 4ad1a5e4..ad34173e 100755
--- a/test/cis-roundtrip.test
+++ b/test/cis-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtocis cistopbm
 # Also requires: pbmmake pamcut pamfile
 
diff --git a/test/cmuw-roundtrip.test b/test/cmuw-roundtrip.test
index 725f9131..8664a1e6 100755
--- a/test/cmuw-roundtrip.test
+++ b/test/cmuw-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtocmuwm cmuwmtopbm
 # Also requires:
 
diff --git a/test/cut-cat-roundtrip.test b/test/cut-cat-roundtrip.test
index 970c3e17..c2799a7b 100755
--- a/test/cut-cat-roundtrip.test
+++ b/test/cut-cat-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamcut
 # Also requires: pamfile pnmcat pnmpad pnmcrop
 
@@ -12,34 +12,34 @@ padded_ppm=${tmpdir}/padded.ppm
 
 echo "Test 1.  Should print 1926073387 101484 six times"
 
-testimg_ppm_sum=`cat testimg.ppm | cksum`
+testimg_ppm_sum=`cksum < testimg.ppm`
 echo ${testimg_ppm_sum}
 
- imgsize=$(pamfile -size testimg.ppm)
- iw=$(echo ${imgsize} | cut -d" " -f1)
- ih=$(echo ${imgsize} | cut -d" " -f2)
+imgsize=$(pamfile -size testimg.ppm)
+width=$(echo ${imgsize} | cut -d " " -f 1)
+height=$(echo ${imgsize} | cut -d " " -f 2)
 
 for i in 0 1 128 224 225
   do
   pamcut -left=$((i+1)) testimg.ppm > ${right_ppm}
   pamcut -right=$i      testimg.ppm > ${left_ppm}
   pnmcat -lr ${left_ppm} ${right_ppm} | \
-    pamcut -left=0 -width=${iw} | cksum
+    pamcut -left=0 -width=${width} | cksum
   rm ${left_ppm} ${right_ppm}
   done
 
 echo "Test 2.  Should print 3891261972 202953 1926073387 101484 six times"
 # Padding added to right.
 
-pnmpad -right=${iw} -black testimg.ppm | cksum | tr '\n' ' '
+pnmpad -right=${width} -black testimg.ppm | cksum | tr '\n' ' '
 echo ${testimg_ppm_sum}
 
 for border in 0 1 128 224 225
   do
-  pamcut -left=$((${border}+1)) -width=${iw} -pad testimg.ppm > ${right_ppm}
-  pamcut -right=${border} -width=${iw} -pad testimg.ppm > ${left_ppm}
+  pamcut -left=$((${border}+1)) -width=${width} -pad testimg.ppm > ${right_ppm}
+  pamcut -right=${border} -width=${width} -pad testimg.ppm > ${left_ppm}
   pnmcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \
-    pamcut -left=$((${iw}-${border}-1))  -width=$((${iw}*2)) | \
+    pamcut -left=$((${width}-${border}-1))  -width=$((${width}*2)) | \
     tee ${padded_ppm} | cksum | tr '\n' ' '
   pnmcrop -black -right ${padded_ppm} | cksum
   rm ${left_ppm} ${right_ppm} ${padded_ppm}
@@ -54,21 +54,22 @@ for border in 0 1 70 147
   pamcut -top=$((${border}+1)) testimg.ppm > ${bottom_ppm}
   pamcut -bottom=${border}     testimg.ppm > ${top_ppm}
   pnmcat -tb ${top_ppm} ${bottom_ppm} | \
-    pamcut -top=0 -height=${ih} | cksum
+    pamcut -top=0 -height=${height} | cksum
   rm ${top_ppm} ${bottom_ppm}
   done
 
 echo "Test 4.  Should print 26789469 202953 1926073387 101484 five times"
 # Padding added to bottom.
 
-pnmpad -bottom=${ih} -black testimg.ppm | cksum | tr '\n' ' '
+pnmpad -bottom=${height} -black testimg.ppm | cksum | tr '\n' ' '
 echo ${testimg_ppm_sum}
 for border in 0 1 70 147
   do
-  pamcut -top=$((${border}+1)) -height=${ih} -pad testimg.ppm > ${bottom_ppm}
-  pamcut -bottom=${border}     -height=${ih} -pad testimg.ppm > ${top_ppm}
+  pamcut -top=$((${border}+1)) -height=${height} -pad testimg.ppm \
+    > ${bottom_ppm}
+  pamcut -bottom=${border}     -height=${height} -pad testimg.ppm > ${top_ppm}
   pnmcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \
-    pamcut -top=$((${ih}-${border}-1))  -height=$((${ih}*2)) | \
+    pamcut -top=$((${height}-${border}-1))  -height=$((${height}*2)) | \
     tee ${padded_ppm} | cksum | tr '\n' ' 'cksum
   pnmcrop -black -bottom ${padded_ppm} | cksum
   rm ${top_ppm} ${bottom_ppm} ${padded_ppm}
@@ -82,19 +83,19 @@ padded_pbm=${tmpdir}/padded.pbm
 
 echo "Test 5.  Should print 281226646 481 six times"
 
-maze_pbm_sum=`cat maze.pbm | cksum`
+maze_pbm_sum=`cksum < maze.pbm`
 echo ${maze_pbm_sum}
 
 imgsize=$(pamfile -size maze.pbm)
-iw=$(echo ${imgsize} | cut -d" " -f1)
-ih=$(echo ${imgsize} | cut -d" " -f2)
+width=$(echo ${imgsize} | cut -d " " -f 1)
+height=$(echo ${imgsize} | cut -d " " -f 2)
 
 for i in 0 1 10 30 50
   do
   pamcut -left=$((i+1)) maze.pbm > ${right_ppm}
   pamcut -right=$i      maze.pbm > ${left_ppm}
   pnmcat -lr ${left_ppm} ${right_ppm} | \
-    pamcut -left=0 -width=${iw} | cksum
+    pamcut -left=0 -width=${width} | cksum
   rm ${left_ppm} ${right_ppm}
   done
 
@@ -102,15 +103,15 @@ for i in 0 1 10 30 50
 echo "Test 6.  Should print 1748767123 895 281226646 481 six times"
 # Padding added to right.
 
-pnmpad -right=${iw} -black maze.pbm | cksum | tr '\n' ' '
+pnmpad -right=${width} -black maze.pbm | cksum | tr '\n' ' '
 echo ${maze_pbm_sum}
 
 for border in 0 1 10 30 50
   do
-  pamcut -left=$((${border}+1)) -width=${iw} -pad maze.pbm > ${right_ppm}
-  pamcut -right=${border} -width=${iw} -pad maze.pbm > ${left_ppm}
+  pamcut -left=$((${border}+1)) -width=${width} -pad maze.pbm > ${right_ppm}
+  pamcut -right=${border} -width=${width} -pad maze.pbm > ${left_ppm}
   pnmcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \
-    pamcut -left=$((${iw}-${border}-1))  -width=$((${iw}*2)) | \
+    pamcut -left=$((${width}-${border}-1))  -width=$((${width}*2)) | \
     tee ${padded_ppm} | cksum | tr '\n' ' '
   pnmcrop -black -right ${padded_ppm} | cksum
   rm ${left_ppm} ${right_ppm} ${padded_ppm}
@@ -125,21 +126,21 @@ for border in 0 1 12 21 31 44
   pamcut -top=$((${border}+1)) maze.pbm > ${bottom_ppm}
   pamcut -bottom=${border}     maze.pbm > ${top_ppm}
   pnmcat -tb ${top_ppm} ${bottom_ppm} | \
-    pamcut -top=0 -height=${ih} | cksum
+    pamcut -top=0 -height=${height} | cksum
   rm ${top_ppm} ${bottom_ppm}
   done
 
 echo "Test 8.  Should print 1346655680 954 281226646 481 five times"
 # Padding added to bottom.
 
-pnmpad -bottom=${ih} -black maze.pbm | cksum | tr '\n' ' '
+pnmpad -bottom=${height} -black maze.pbm | cksum | tr '\n' ' '
 echo ${maze_pbm_sum}
 for border in 0 1 10 50
   do
-  pamcut -top=$((${border}+1)) -height=${ih} -pad maze.pbm > ${bottom_ppm}
-  pamcut -bottom=${border}     -height=${ih} -pad maze.pbm > ${top_ppm}
+  pamcut -top=$((${border}+1)) -height=${height} -pad maze.pbm > ${bottom_ppm}
+  pamcut -bottom=${border}     -height=${height} -pad maze.pbm > ${top_ppm}
   pnmcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \
-    pamcut -top=$((${ih}-${border}-1))  -height=$((${ih}*2)) | \
+    pamcut -top=$((${height}-${border}-1))  -height=$((${height}*2)) | \
     tee ${padded_ppm} | cksum | tr '\n' ' 'cksum
   pnmcrop -black -bottom ${padded_ppm} | cksum
   rm ${top_ppm} ${bottom_ppm} ${padded_ppm}
diff --git a/test/cut-paste-roundtrip.test b/test/cut-paste-roundtrip.test
index ac2c0fe7..bec8baf5 100755
--- a/test/cut-paste-roundtrip.test
+++ b/test/cut-paste-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamcut pnmpaste
 # Also requires: pbmmake pnmpad
 
diff --git a/test/enlarge-reduce-roundtrip.test b/test/enlarge-reduce-roundtrip.test
index 54b52c60..5d223cf1 100755
--- a/test/enlarge-reduce-roundtrip.test
+++ b/test/enlarge-reduce-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamenlarge pbmpscale pbmreduce
 # Also requires: pbmtext
 
diff --git a/test/eyuvtoppm.test b/test/eyuvtoppm.test
index b28b4539..6bbc2e7e 100755
--- a/test/eyuvtoppm.test
+++ b/test/eyuvtoppm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: eyuvtoppm
 # Also requires:
 
diff --git a/test/facesaver-roundtrip.test b/test/facesaver-roundtrip.test
index f4b8f069..75fcf662 100755
--- a/test/facesaver-roundtrip.test
+++ b/test/facesaver-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmtofs fstopgm
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/fiasco-roundtrip.test b/test/fiasco-roundtrip.test
index 8325a37d..8d5fdaa6 100755
--- a/test/fiasco-roundtrip.test
+++ b/test/fiasco-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtofiasco fiascotopnm
 # Also requires: pnmpad pnmpsnr
 
diff --git a/test/fits-roundtrip.test b/test/fits-roundtrip.test
index e793df9a..030a519e 100755
--- a/test/fits-roundtrip.test
+++ b/test/fits-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtofits fitstopnm
 # Also requires:
 
diff --git a/test/g3-roundtrip.test b/test/g3-roundtrip.test
index f35c4935..2736c09a 100755
--- a/test/g3-roundtrip.test
+++ b/test/g3-roundtrip.test
@@ -11,7 +11,7 @@ pagemax_pbm=${tmpdir}/pagemax.pbm
 
 echo "Test 1.  Should print 0 0 0 : 0 or 0 0 0 0 : 0 total three times"
 
-width=$(pamfile -size maze.pbm | cut -d" " -f1)
+width=$(pamfile -size maze.pbm | cut -d " " -f 1) 
 
 pbmtog3 -nofixedwidth maze.pbm | \
 g3topbm -width=${width} | cmp -s - maze.pbm
diff --git a/test/gem-roundtrip.test b/test/gem-roundtrip.test
index 106fe2cf..d97a5cb9 100755
--- a/test/gem-roundtrip.test
+++ b/test/gem-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtogem gemtopnm
 # Also requires:
 
diff --git a/test/gif-transparent1.test b/test/gif-transparent1.test
index 4684d1fc..c2da5468 100755
--- a/test/gif-transparent1.test
+++ b/test/gif-transparent1.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: giftopnm pamtogif ppmtogif
 # Also requires: pamarith pamcomp pamdepth pamenlarge pamstack pbmmake
 # Also requires: pnminvert ppmchange ppmpat ppmtopgm ppmtoppm 
diff --git a/test/hdiff-roundtrip.test b/test/hdiff-roundtrip.test
index a4a4a906..ec7afc2c 100755
--- a/test/hdiff-roundtrip.test
+++ b/test/hdiff-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: hdifftopam pamtohdiff
 # Also requires:
 
diff --git a/test/ilbm-roundtrip.ok b/test/ilbm-roundtrip.ok
index fcbdf4f6..07c44515 100644
--- a/test/ilbm-roundtrip.ok
+++ b/test/ilbm-roundtrip.ok
@@ -9,6 +9,10 @@ Test 2.  Should produce 1926073387 101484 three times
 1926073387 101484
 Test 3.  Should print 984199586 101484
 984199586 101484
-Test 4.  Should print 2059976475 661 twice
+Test 4.  Should print 2059976475 661 three times
 2059976475 661
 2059976475 661
+2059976475 661
+Test 5.  Should print 482756572 101484 twice
+482756572 101484
+482756572 101484
diff --git a/test/ilbm-roundtrip.test b/test/ilbm-roundtrip.test
index 85e04b26..c0b684ed 100755
--- a/test/ilbm-roundtrip.test
+++ b/test/ilbm-roundtrip.test
@@ -1,6 +1,6 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtoilbm ilbmtoppm
-# Also requires: pamseq pamdepth pamtopnm pnmremap
+# Also requires: pamseq pamdepth pamtopnm pnmremap pnmcolormap
 
 echo "Test 1.  Should produce 669206373 10102 five times"
 #Output is PPM raw, 57 by 59  maxval 255
@@ -16,14 +16,25 @@ ppmtoilbm testimg.ppm | ilbmtoppm | cksum
 ppmtoilbm -24force testimg.ppm | ilbmtoppm | cksum
 ppmtoilbm -dcbits 8 8 8 -nocompress testimg.ppm | ilbmtoppm | cksum
 
+tmpdir=${tmpdir:-/tmp}
 
 echo "Test 3.  Should print 984199586 101484"
-pamseq 3 5 -tupletype=RGB | pamdepth 255 | pamtopnm | \
+test_ppm=${tmpdir}/test.ppm
+pamseq 3 5 -tupletype=RGB | pamdepth 255 | pamtopnm | tee ${test_ppm} | \
   pnmremap -mapfile=- testimg.ppm | ppmtoilbm | ilbmtoppm | cksum
 
 
-echo "Test 4.  Should print 2059976475 661 twice"
-pamseq 3 5 -tupletype=RGB | pamtopnm | \
-  ppmtoilbm -compress | ilbmtoppm | cksum
-pamseq 3 5 -tupletype=RGB | pamtopnm | \
-  ppmtoilbm -nocompress | ilbmtoppm | cksum
+echo "Test 4.  Should print 2059976475 661 three times"
+cat ${test_ppm} | cksum
+ppmtoilbm -compress ${test_ppm} | ilbmtoppm | cksum
+ppmtoilbm -nocompress ${test_ppm} | ilbmtoppm | cksum
+
+rm ${test_ppm}
+
+echo "Test 5.  Should print 482756572 101484 twice"
+mapfile=${tmpdir}/mapfile
+pnmcolormap 32 testimg.ppm > ${mapfile}
+ppmtoilbm -map ${mapfile} testimg.ppm | ilbmtoppm | tee ${test_ppm} | cksum
+ppmtoilbm -map ${mapfile} ${test_ppm} | ilbmtoppm | cksum
+
+rm ${mapfile} ${test_ppm}
diff --git a/test/jbig-roundtrip.test b/test/jbig-roundtrip.test
index eac742ff..11cd1778 100755
--- a/test/jbig-roundtrip.test
+++ b/test/jbig-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtojbig jbigtopnm
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/jpeg-roundtrip.test b/test/jpeg-roundtrip.test
index 7cc0fc20..834c02e5 100755
--- a/test/jpeg-roundtrip.test
+++ b/test/jpeg-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtojpeg jpegtopnm
 # Also requires: pnmpsnr
 
diff --git a/test/jpeg2k-roundtrip.test b/test/jpeg2k-roundtrip.test
index 0995849d..4a09201d 100755
--- a/test/jpeg2k-roundtrip.test
+++ b/test/jpeg2k-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtojpeg2k jpeg2ktopam
 # Also requires:
 
diff --git a/test/leaf-roundtrip.test b/test/leaf-roundtrip.test
index 5628ed01..94b31092 100755
--- a/test/leaf-roundtrip.test
+++ b/test/leaf-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtoleaf leaftoppm
 # Also requires:
 
diff --git a/test/lookup-roundtrip.test b/test/lookup-roundtrip.test
index 491294a2..19ebd40a 100755
--- a/test/lookup-roundtrip.test
+++ b/test/lookup-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamlookup pamunlookup
 # Also requires: ppmhist
 
diff --git a/test/lps-roundtrip.ok b/test/lps-roundtrip.ok
index 277907af..c2c8ab3b 100644
--- a/test/lps-roundtrip.ok
+++ b/test/lps-roundtrip.ok
@@ -1,2 +1,4 @@
-Test.  Should print match
+Test 1.  Should print match
 match
+Test 2.  Should print 0
+0
diff --git a/test/lps-roundtrip.test b/test/lps-roundtrip.test
index 71cd354d..78350d71 100755
--- a/test/lps-roundtrip.test
+++ b/test/lps-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtolps pstopnm
 # Also requires: gs pamdepth pamscale pnmcrop pnmpsnr pamfile
 
@@ -9,17 +9,25 @@
 
 tmpdir=${tmpdir:-/tmp}
 test_pgm=${tmpdir}/test.pgm
+test_ps=${tmpdir}/test.ps
 
-echo "Test.  Should print match"
+echo "Test 1.  Should print match"
 
 xysize=$(pamfile -size testgrid.pbm | awk '{print "-xsize="$1,"-ysize="$2}')
 pamdepth 255 testgrid.pbm > ${test_pgm}
   
-pbmtolps -dpi 72 testgrid.pbm | \
+pbmtolps -dpi 72 testgrid.pbm | tee ${test_ps} | \
     pstopnm -dpi $((72*12)) -stdout -pgm | \
     pnmcrop -white | pamscale ${xysize}  | \
     pnmpsnr -target=30 - ${test_pgm}
-  
+
     # ghostscript version 8.71: pnmpsnr lumina 33.14dB
+
+
+echo "Test 2.  Should print 0"
+
+pbmtolps -dpi 72 < testgrid.pbm | sed 's/noname/testgrid.pbm/' | \
+    cmp -s ${test_ps} -
+    echo $?
   
 rm ${test_pgm}
diff --git a/test/macp-roundtrip.test b/test/macp-roundtrip.test
index b264e3d1..9def7c4c 100755
--- a/test/macp-roundtrip.test
+++ b/test/macp-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtomacp macptopbm
 # Also requires: pnmcrop pbmpage pbmupc pnmpad pbmmake
 
diff --git a/test/mda-roundtrip.test b/test/mda-roundtrip.test
index 6b4d89b9..c47d433e 100755
--- a/test/mda-roundtrip.test
+++ b/test/mda-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtomda mdatopbm
 # Also requires: pbmmake pnmpad pamcut pamfile
 
diff --git a/test/mgr-roundtrip.test b/test/mgr-roundtrip.test
index d96d836d..9fb6211c 100755
--- a/test/mgr-roundtrip.test
+++ b/test/mgr-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtomgr mgrtopbm
 # Also requires: pbmmake
 
diff --git a/test/mrf-roundtrip.test b/test/mrf-roundtrip.test
index 8513a908..5ce604e6 100755
--- a/test/mrf-roundtrip.test
+++ b/test/mrf-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtomrf mrftopbm
 # Also requires:
 
diff --git a/test/pad-crop-roundtrip.test b/test/pad-crop-roundtrip.test
index 8cca8a5f..31e02c99 100755
--- a/test/pad-crop-roundtrip.test
+++ b/test/pad-crop-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmcrop pnmmargin pnmpad
 # Also requires:
 
diff --git a/test/palm-roundtrip2.test b/test/palm-roundtrip2.test
index 4c94df8c..f0c9b7c8 100755
--- a/test/palm-roundtrip2.test
+++ b/test/palm-roundtrip2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtopalm palmtopnm
 # Also requires: pnmremap
 
diff --git a/test/pamarith-compare-equal.test b/test/pamarith-compare-equal.test
index 0af9ee27..7d1062b7 100755
--- a/test/pamarith-compare-equal.test
+++ b/test/pamarith-compare-equal.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamarith
 # Also requires: ppmpat pnminvert pamfile pbmmake pgmmake pamcut
 
diff --git a/test/pamarith-multiple-input.test b/test/pamarith-multiple-input.test
index 7df08817..b9c09662 100755
--- a/test/pamarith-multiple-input.test
+++ b/test/pamarith-multiple-input.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamarith
 # Also requires: pgmmake ppmpat pamfunc
 
@@ -14,7 +14,7 @@ pgmmake -maxval=99 0.01 16 11 > ${input1_pgm}
 
 add_command="pamarith -add "${input1_pgm}
 
-for ((i=1 ; i<10 ; i++ ))
+for i in 1 2 3 4 5 6 7 8 9 # for i in `seq 9`
   do
   echo ${i}":"
   add_command=${add_command}" "${input1_pgm}
@@ -58,4 +58,4 @@ for function in "-add" "-and" "-or" "-xor" "-nand" "-nor"
   pamarith ${function} ${g2_ppm} ${g3_ppm} ${g2_ppm} | cksum
   done
 
-rm ${g2_ppm} ${g3_ppm}
\ No newline at end of file
+rm ${g2_ppm} ${g3_ppm}
diff --git a/test/pamarith.test b/test/pamarith.test
index b6b4538c..9c95db80 100755
--- a/test/pamarith.test
+++ b/test/pamarith.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamarith
 # Also requires: pamtopnm rgb3toppm pamenlarge pnmcat pamseq pbmmake pgmmake
 # Also requires: ppmpat pamchannel
diff --git a/test/pambackground.test b/test/pambackground.test
index 522f4823..eca9cc93 100755
--- a/test/pambackground.test
+++ b/test/pambackground.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pambackground
 # Also requires: pamgradient pamseq pbmmake pnmmargin pnmremap pnmtile pnmpad
 
diff --git a/test/pambrighten.test b/test/pambrighten.test
index 3e1a3eb1..00e405dd 100755
--- a/test/pambrighten.test
+++ b/test/pambrighten.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pambrighten
 # Also requires: pgmramp
 
diff --git a/test/pamchannel.test b/test/pamchannel.test
index bce1d4eb..f72725ee 100755
--- a/test/pamchannel.test
+++ b/test/pamchannel.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamchannel
 # Also requires: pamtopam pamtopnm
 
diff --git a/test/pamcrater.test b/test/pamcrater.test
index 25b12135..61414480 100755
--- a/test/pamcrater.test
+++ b/test/pamcrater.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamcrater pamshadedrelief
 # Also requires: pamstack pamvalidate pamcut pamflip
 
diff --git a/test/pamcut.test b/test/pamcut.test
index e18c3cf2..2299b4bc 100755
--- a/test/pamcut.test
+++ b/test/pamcut.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamcut pbmmake
 # Also requires: pamfile
 
@@ -27,8 +27,9 @@ pamcut -top 10 -left 10 -width 207 -height 129 testimg.ppm | cksum
 
 echo "Test 5. Should print 281226646 481 five times"
 
-width=$(pamfile -size maze.pbm | awk '{print $1}')
-height=$(pamfile -size maze.pbm | awk '{print $2}')
+mazesize=$(pamfile -size maze.pbm)
+width=$(echo ${mazesize} | cut -d " " -f 1)
+height=$(echo ${mazesize} | cut -d " " -f 2)
  
 pamcut -croptop 0 -cropleft 0 -cropbottom 0 -cropright 0 maze.pbm | \
   cksum
diff --git a/test/pamdepth-roundtrip.test b/test/pamdepth-roundtrip.test
index d3f0d6d3..6da9a612 100755
--- a/test/pamdepth-roundtrip.test
+++ b/test/pamdepth-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamdepth pgmtopbm
 # Also requires:
 
diff --git a/test/pamdice-roundtrip.test b/test/pamdice-roundtrip.test
index 741615f5..4d3fba19 100755
--- a/test/pamdice-roundtrip.test
+++ b/test/pamdice-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamdice pamundice
 # Also requires: pamfile
 
@@ -6,8 +6,8 @@ tmpdir=${tmpdir:-/tmp}
 fname_stem=${tmpdir}/pamdice_part
 
 mazesize=$(pamfile -size maze.pbm)
-mw=$(echo ${mazesize} | cut -d" " -f1)
-mh=$(echo ${mazesize} | cut -d" " -f2)
+mw=$(echo ${mazesize} | cut -d " " -f 1)
+mh=$(echo ${mazesize} | cut -d " " -f 2)
 
 echo "Test 1.  Should print 281226646 481"
 
diff --git a/test/pamdice.test b/test/pamdice.test
index 25695d5a..04dd4d78 100755
--- a/test/pamdice.test
+++ b/test/pamdice.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamdice
 # Also requires: pbmmake
 
diff --git a/test/pamditherbw-random.test b/test/pamditherbw-random.test
index 5bff4bac..7a5de7bd 100755
--- a/test/pamditherbw-random.test
+++ b/test/pamditherbw-random.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamditherbw
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/pamditherbw.test b/test/pamditherbw.test
index 43d2b00f..3f37f117 100755
--- a/test/pamditherbw.test
+++ b/test/pamditherbw.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamditherbw
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/pamedge.test b/test/pamedge.test
index c63b30cc..8121f858 100755
--- a/test/pamedge.test
+++ b/test/pamedge.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamedge
 # Also requires: pbmpscale pbmtext pgmtopbm pgmtopgm ppmtopgm
 
diff --git a/test/pamendian-roundtrip.ok b/test/pamendian-roundtrip.ok
index 50450617..6245abb9 100644
--- a/test/pamendian-roundtrip.ok
+++ b/test/pamendian-roundtrip.ok
@@ -1,4 +1,5 @@
-Test 1: Should print '0 0 0 : 0'
+Test 1.  Should print '0 0 0 : 0'
 0 0 0 : 0
-Test 2 should print echo '0 0 0 0 0 : 0'
+Test 2.  Should print '0 0 0 0 0 : 0' twice
+0 0 0 0 0 : 0
 0 0 0 0 0 : 0
diff --git a/test/pamendian-roundtrip.test b/test/pamendian-roundtrip.test
index aed03c76..b060b704 100755
--- a/test/pamendian-roundtrip.test
+++ b/test/pamendian-roundtrip.test
@@ -2,7 +2,7 @@
 # This script tests: pamendian
 # Also requires: pamdepth pgmtopbm pamseq
 
-echo "Test 1: Should print '0 0 0 : 0'" 
+echo "Test 1.  Should print '0 0 0 : 0'" 
 
 tmpdir=${tmpdir:-/tmp}
 test0_pam=${tmpdir}/test0.pam
@@ -15,8 +15,12 @@ pamendian < ${test0_pam} | pamendian |\
 rm ${test0_pam}
 
 
-echo "Test 2 should print echo '0 0 0 0 0 : 0'" 
+echo "Test 2.  Should print '0 0 0 0 0 : 0' twice" 
 
 pamdepth 65535 testgrid.pbm | pamendian | pamendian | \
   pgmtopbm -th -val=0.5 | cmp -s - testgrid.pbm
+  echo ${PIPESTATUS[@]} ":" $?
+
+pamdepth 4095 maze.pbm | pamendian | pamendian | \
+  pgmtopbm -th -val=0.5 | cmp -s - maze.pbm
   echo ${PIPESTATUS[@]} ":" $?
\ No newline at end of file
diff --git a/test/pamenlarge-pbm.test b/test/pamenlarge-pbm.test
index 87493516..fbb2eced 100755
--- a/test/pamenlarge-pbm.test
+++ b/test/pamenlarge-pbm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamenlarge
 # Also requires: pbmmake pnmpad
 
@@ -18,22 +18,24 @@ LC_ALL=C awk 'BEGIN { print "P4";         # header
 # Test 1.
 echo "test 1"
  
-for xs in `seq 23`
+for xs in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # for xs in `seq 23`
   do
-  pamenlarge -xscale=$xs ${complete256_pbm} | cksum
+  pamenlarge -xscale=${xs} ${complete256_pbm} | cksum
   done
 
 # Test 2.
 echo "test 2"
 
-for xs1 in `seq 15`
+for xs1 in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  # for xs in `seq 15`
   do
-  xs2=$((30-$xs1))
-  pamenlarge -xscale=$xs1 ${complete256_pbm} | pamenlarge -xscale=$xs2 | cksum
-  if [ $xs1 != $xs2 ]; then
-  pamenlarge -xscale=$xs2 ${complete256_pbm} | pamenlarge -xscale=$xs1 | cksum
+  xs2=$((30-${xs1}))
+  pamenlarge -xscale=${xs1} ${complete256_pbm} | \
+    pamenlarge -xscale=${xs2} | cksum
+  if [ ${xs1} != ${xs2} ]; then
+  pamenlarge -xscale=${xs2} ${complete256_pbm} | \
+    pamenlarge -xscale=${xs1} | cksum
   fi
-  pamenlarge -xscale=$(($xs1 * $xs2)) ${complete256_pbm} | cksum
+  pamenlarge -xscale=$((${xs1} * ${xs2})) ${complete256_pbm} | cksum
   done
 
 rm ${complete256_pbm}
@@ -43,19 +45,19 @@ echo "test 3"
 
 test3_pbm=${tmpdir}/test3.pbm
 
-for width in `seq 16`
+for width in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  # for width in `seq 16`
   do
   pbmmake -g ${width} 1 | pnmpad -top=1 -white | \
       pnmpad -bottom=1 -black > ${test3_pbm}.${width}
   done
  
-  for xscale in `seq 16`
+  for xscale in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  # for xscale in `seq 16`
     do echo -n ${xscale} " "
-    for width in `seq 16`
+    for width in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  # for width in `seq 16` 
       do pamenlarge -xscale=${xscale} ${test3_pbm}.${width} ; done | cksum
       #
       # unlike most other tests we take the cksum of a composite PBM file
       #
     done
 
-rm ${test3_pbm}.[1-9]  ${test3_pbm}.1[0-6]
\ No newline at end of file
+rm ${test3_pbm}.[1-9]  ${test3_pbm}.1[0-6]
diff --git a/test/pamenlarge.test b/test/pamenlarge.test
index 851362e8..7c46881d 100755
--- a/test/pamenlarge.test
+++ b/test/pamenlarge.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamenlarge
 # Also requires: pamchannel pamseq pamtopnm
 
diff --git a/test/pamexec.test b/test/pamexec.test
index ec57f4ae..7c2bf054 100755
--- a/test/pamexec.test
+++ b/test/pamexec.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamexec
 # Also requires: pbmtext pamfile pbmminkowski pbmtog3 g3topbm
 
@@ -6,7 +6,9 @@ tmpdir=${tmpdir:-/tmp}
 test_pbm=${tmpdir}/test.pbm
 combined_pbm=${tmpdir}/combined.pbm
 
-for i in `seq 0 9`; do echo $i | pbmtext -builtin=fixed > ${test_pbm}$i; done
+for i in 0 1 2 3 4 5 6 7 8 9  # for i in `seq 0 9`
+  do echo ${i} | pbmtext -builtin=fixed > ${test_pbm}${i}
+  done
 cat ${test_pbm}[0123456789] > ${combined_pbm}
 
 echo "Test 1 : Should print 10 stdin: PBM RAW 21 24 1 1 BLACKANDWHITE twice"
@@ -16,7 +18,8 @@ pamexec "pamfile -mach" ${combined_pbm}  | uniq -c | sed 's/^ *//'
 
 echo "Test 2: Should print 1791121103 989 twice"
 
-for i in `seq 0 9`; do pbmminkowski ${test_pbm}$i   ; done | cksum
+for i in 0 1 2 3 4 5 6 7 8 9  # for i in `seq 0 9`
+  do pbmminkowski ${test_pbm}${i}; done | cksum
 pamexec "pbmminkowski" ${combined_pbm} | cksum
 
 rm ${test_pbm}[0123456789]
diff --git a/test/pamfile.test b/test/pamfile.test
index 41aa3c85..a0a5c65b 100755
--- a/test/pamfile.test
+++ b/test/pamfile.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamfile
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/pamfind.test b/test/pamfind.test
index e689754f..87ef5f9f 100755
--- a/test/pamfind.test
+++ b/test/pamfind.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamfind
 # Also requires:
 
diff --git a/test/pamfix.test b/test/pamfix.test
index 1293dfe2..89d3beb6 100755
--- a/test/pamfix.test
+++ b/test/pamfix.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamfix
 # Also requires: pbmmake
 
@@ -9,37 +9,37 @@ echo "Test 1"
 
 pbmmake -g 5 5 | pamfix -truncate -plain
 
-echo -e "P1\n5 5\n01010\n10101\n01010\n00001\n1" |\
+printf "P1\n5 5\n01010\n10101\n01010\n00001\n1\n" |\
   pamfix -truncate -plain
 
-echo -e "P1\n5 5\n01010\n10101\n01010\n0000\n1" |\
+printf "P1\n5 5\n01010\n10101\n01010\n0000\n1\n" |\
   pamfix -truncate -plain
 
-echo -e "P1\n5 5\n01010\n10102\n01010\n00001\n1" |\
+printf "P1\n5 5\n01010\n10102\n01010\n00001\n1\n" |\
   pamfix -truncate -plain
 
 # Test 2
 
 echo "Test 2"
 
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 0" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 0\n" |\
   pamfix -truncate -plain
 
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7\n" |\
   pamfix -truncate -plain
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 8" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 8\n" |\
   pamfix -truncate -plain
 
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 8" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 8\n" |\
   pamfix -change -plain
 
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 8" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 5\n6 7 8\n" |\
  pamfix -clip -plain
 
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 8\n0 0 0" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 8\n0 0 0\n" |\
   pamfix -change -truncate -plain
 
-echo -e "P2\n3 3\n7\n0 1 2\n3 4 8\n0 0 0" |\
+printf "P2\n3 3\n7\n0 1 2\n3 4 8\n0 0 0\n" |\
   pamfix -clip -truncate -plain
 
 # Test Invalid
@@ -53,17 +53,17 @@ echo "Invalid command-line combination, invalid input" 1>&2
 echo "Error messages should appear below the line." 1>&2
 echo "-----------------------------------------------------------" 1>&2
 
-echo -e "P2\n3 2\n7\n0 1 2\n6 7 8" | pamfix -change -clip > ${test_out} || \
+printf "P2\n3 2\n7\n0 1 2\n6 7 8\n" | pamfix -change -clip > ${test_out} || \
   echo -n "Expected failure 1";
   test -s ${test_out}; echo " "$?
   rm -f ${test_out}
 
-echo -e "P1\n5 5" | pamfix -truncate -plain > ${test_out} || \
+printf "P1\n5 5\n" | pamfix -truncate -plain > ${test_out} || \
   echo -n "Expected failure 2";
   test -s ${test_out}; echo " "$?
   rm -f ${test_out}
 
-echo -e "P2\n3 3\255" | pamfix -truncate -plain > ${test_out} || \
+printf "P2\n3 3\255\n" | pamfix -truncate -plain > ${test_out} || \
   echo -n "Expected failure 3";
   test -s ${test_out}; echo " "$?
   rm -f ${test_out}
diff --git a/test/pamflip-pbm-roundtrip.ok b/test/pamflip-pbm-roundtrip.ok
new file mode 100644
index 00000000..c72e40d6
--- /dev/null
+++ b/test/pamflip-pbm-roundtrip.ok
@@ -0,0 +1,122 @@
+Test 1.  Should print 281226646 481 seven times
+281226646 481
+281226646 481
+281226646 481
+281226646 481
+281226646 481
+281226646 481
+281226646 481
+Test 2.  Should print 1576602925 8 fourteen times
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+1576602925 8
+Test 3.  Should print N : 0 thirty-two times
+1 : 0
+2 : 0
+3 : 0
+4 : 0
+5 : 0
+6 : 0
+7 : 0
+8 : 0
+9 : 0
+10 : 0
+11 : 0
+12 : 0
+13 : 0
+14 : 0
+15 : 0
+16 : 0
+17 : 0
+18 : 0
+19 : 0
+20 : 0
+21 : 0
+22 : 0
+23 : 0
+24 : 0
+25 : 0
+26 : 0
+27 : 0
+28 : 0
+29 : 0
+30 : 0
+31 : 0
+32 : 0
+Test 4.  Should print N : 0 thirty-two times
+1 : 0
+2 : 0
+3 : 0
+4 : 0
+5 : 0
+6 : 0
+7 : 0
+8 : 0
+9 : 0
+10 : 0
+11 : 0
+12 : 0
+13 : 0
+14 : 0
+15 : 0
+16 : 0
+17 : 0
+18 : 0
+19 : 0
+20 : 0
+21 : 0
+22 : 0
+23 : 0
+24 : 0
+25 : 0
+26 : 0
+27 : 0
+28 : 0
+29 : 0
+30 : 0
+31 : 0
+32 : 0
+Test 5.  Should print N : 0 thirty-two times
+1 : 0
+2 : 0
+3 : 0
+4 : 0
+5 : 0
+6 : 0
+7 : 0
+8 : 0
+9 : 0
+10 : 0
+11 : 0
+12 : 0
+13 : 0
+14 : 0
+15 : 0
+16 : 0
+17 : 0
+18 : 0
+19 : 0
+20 : 0
+21 : 0
+22 : 0
+23 : 0
+24 : 0
+25 : 0
+26 : 0
+27 : 0
+28 : 0
+29 : 0
+30 : 0
+31 : 0
+32 : 0
diff --git a/test/pamflip-pbm-roundtrip.test b/test/pamflip-pbm-roundtrip.test
new file mode 100755
index 00000000..71f2e926
--- /dev/null
+++ b/test/pamflip-pbm-roundtrip.test
@@ -0,0 +1,74 @@
+#! /bin/sh
+# This script tests: pamflip
+# Also requires: ppmpat pamseq pamtopnm
+
+tmpdir=${tmpdir:-/tmp}
+dot_pbm=${tmpdir}/dot.pbm
+noise_pbm=${tmpdir}/noise.pbm
+
+echo "Test 1.  Should print 281226646 481 seven times"
+
+pamflip -null maze.pbm | cksum
+pamflip -lr maze.pbm | pamflip -lr | cksum
+pamflip -tb maze.pbm | pamflip -tb | cksum
+pamflip -r180 maze.pbm | pamflip -r180 | cksum
+pamflip -xy maze.pbm | pamflip -xy | cksum
+pamflip -r90 maze.pbm | pamflip -r90 | pamflip -r90 | pamflip -r90 | cksum
+pamflip -r270 maze.pbm | pamflip -r270 | pamflip -r270 | pamflip -r270 | cksum
+
+echo "Test 2.  Should print 1576602925 8 fourteen times"
+
+pbmmake -b 1 1 | tee ${dot_pbm} | cksum
+pamflip -null ${dot_pbm} | cksum
+
+# the next six aren't round-trip
+pamflip -lr ${dot_pbm} | cksum
+pamflip -tb ${dot_pbm} | cksum
+pamflip -r180 ${dot_pbm} | cksum
+pamflip -xy ${dot_pbm} | cksum
+pamflip -r90 ${dot_pbm} | cksum
+pamflip -r270 ${dot_pbm} | cksum
+
+pamflip -lr ${dot_pbm} | pamflip -lr | cksum
+pamflip -tb ${dot_pbm} | pamflip -tb | cksum
+pamflip -r180 ${dot_pbm} | pamflip -r180 | cksum
+pamflip -xy ${dot_pbm} | pamflip -xy | cksum
+pamflip -r90 ${dot_pbm} | pamflip -r90 | pamflip -r90 | pamflip -r90 | cksum
+pamflip -r270 ${dot_pbm} | pamflip -r270 | \
+    pamflip -r270 | pamflip -r270 | cksum
+
+rm ${dot_pbm}
+
+echo "Test 3.  Should print N : 0 thirty-two times"
+
+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \
+         20 21 22 23 24 25 26 27 28 29 30 31 32 
+  do
+  pbmnoise -randomseed=${i} -pack ${i} 3 > ${noise_pbm} && \
+    pamflip -lr ${noise_pbm} | pamflip -lr | cmp -s - ${noise_pbm}
+  echo $i : $?
+  rm ${noise_pbm}
+  done
+
+echo "Test 4.  Should print N : 0 thirty-two times"
+
+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \
+         20 21 22 23 24 25 26 27 28 29 30 31 32 
+  do
+  pbmnoise -randomseed=${i} -pack 7 ${i} > ${noise_pbm} && \
+    pamflip -tb ${noise_pbm} | pamflip -tb | cmp -s - ${noise_pbm}
+  echo $i : $?
+  rm ${noise_pbm}
+  done
+
+
+echo "Test 5.  Should print N : 0 thirty-two times"
+
+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \
+         20 21 22 23 24 25 26 27 28 29 30 31 32 
+  do
+  pbmnoise -randomseed=${i} -pack ${i} ${i} > ${noise_pbm} && \
+    pamflip -xy ${noise_pbm} | pamflip -xy | cmp -s - ${noise_pbm}
+  echo $i : $?
+  rm ${noise_pbm}
+  done
diff --git a/test/pamflip-roundtrip.ok b/test/pamflip-roundtrip.ok
index 48d5ab62..70ed6424 100644
--- a/test/pamflip-roundtrip.ok
+++ b/test/pamflip-roundtrip.ok
@@ -1,4 +1,4 @@
-Test 1.  Should produce 1988581932 2989 fifteen times
+Test 1.  Should print 1988581932 2989 fifteen times
 1988581932 2989
 1988581932 2989
 1988581932 2989
@@ -14,7 +14,7 @@ Test 1.  Should produce 1988581932 2989 fifteen times
 1988581932 2989
 1988581932 2989
 1988581932 2989
-Test 2.  Should produce 2729474106 27 nine times
+Test 2.  Should print 2729474106 27 nine times
 2729474106 27
 2729474106 27
 2729474106 27
@@ -24,7 +24,7 @@ Test 2.  Should produce 2729474106 27 nine times
 2729474106 27
 2729474106 27
 2729474106 27
-Test 3.  Should produce 1849343241 27 nine times
+Test 3.  Should print 1849343241 27 nine times
 1849343241 27
 1849343241 27
 1849343241 27
@@ -35,7 +35,7 @@ Test 3.  Should produce 1849343241 27 nine times
 1849343241 27
 1849343241 27
 Test 4.  Should print a single pixel PPM image maxval 65535 in 
-plain (ascii) format; then produce 2434897823 19 nine times
+plain (ascii) format; then print 2434897823 19 fifteen times
 P3
 1 1
 65535
@@ -49,7 +49,13 @@ P3
 2434897823 19
 2434897823 19
 2434897823 19
-Test 4.  Should produce 281226646 481 seven times
+2434897823 19
+2434897823 19
+2434897823 19
+2434897823 19
+2434897823 19
+2434897823 19
+Test 5.  Should print 281226646 481 seven times
 281226646 481
 281226646 481
 281226646 481
diff --git a/test/pamflip-roundtrip.test b/test/pamflip-roundtrip.test
index 27a3c1f6..6103f6fb 100755
--- a/test/pamflip-roundtrip.test
+++ b/test/pamflip-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamflip
 # Also requires: ppmpat pamseq pamtopnm
 
@@ -8,7 +8,7 @@ test1_pgm=${tmpdir}/test1.pgm
 test2_pgm=${tmpdir}/test2.pgm
 dot_ppm=${tmpdir}/dot.ppm
 
-echo "Test 1.  Should produce 1988581932 2989 fifteen times"
+echo "Test 1.  Should print 1988581932 2989 fifteen times"
 
 ppmpat -tartan -mesh \
        -color=rgb:0/0/0,rgb:ff/00/ff,rgb:80/90/20 31 32 > ${tartan_ppm}
@@ -38,7 +38,7 @@ rm ${tartan_ppm}
 
 pamseq 1 15 | pamtopnm -assume > ${test1_pgm}
 
-echo "Test 2.  Should produce 2729474106 27 nine times"
+echo "Test 2.  Should print 2729474106 27 nine times"
 
 pamflip -null ${test1_pgm} | cksum
 pamflip -lr ${test1_pgm} | pamflip -lr | cksum
@@ -55,7 +55,7 @@ pamflip -r270 ${test1_pgm} | pamflip -r270 | \
 pamflip -r180 ${test1_pgm} > ${test2_pgm}
 rm ${test1_pgm}
 
-echo "Test 3.  Should produce 1849343241 27 nine times"
+echo "Test 3.  Should print 1849343241 27 nine times"
 
 pamflip -null ${test2_pgm} | cksum
 pamflip -lr ${test2_pgm} | pamflip -lr | cksum
@@ -79,10 +79,19 @@ P3
 EOF
 
 echo "Test 4.  Should print a single pixel PPM image maxval 65535 in "
-echo "plain (ascii) format; then produce 2434897823 19 nine times"
+echo "plain (ascii) format; then print 2434897823 19 fifteen times"
 
 pamflip -null -plain ${dot_ppm}
+
+# These are not round-trip
 pamflip -null ${dot_ppm} | cksum
+pamflip -lr ${dot_ppm} | cksum
+pamflip -tb ${dot_ppm} | cksum
+pamflip -xy ${dot_ppm} | cksum
+pamflip -r90 ${dot_ppm} | cksum
+pamflip -r180 ${dot_ppm} | cksum
+pamflip -r270 ${dot_ppm} | cksum
+
 pamflip -lr ${dot_ppm} | pamflip -lr | cksum
 pamflip -tb ${dot_ppm} | pamflip -tb | cksum
 pamflip -r180 ${dot_ppm} | pamflip -r180 | cksum
@@ -95,7 +104,7 @@ pamflip -r270 ${dot_ppm} | pamflip -r270 | \
 
 rm ${dot_ppm}
 
-echo "Test 4.  Should produce 281226646 481 seven times"
+echo "Test 5.  Should print 281226646 481 seven times"
 
 pamflip -null maze.pbm | cksum
 pamflip -lr maze.pbm | pamflip -lr | cksum
@@ -104,5 +113,3 @@ pamflip -r180 maze.pbm | pamflip -r180 | cksum
 pamflip -xy maze.pbm | pamflip -xy | cksum
 pamflip -r90 maze.pbm | pamflip -r90 | pamflip -r90 | pamflip -r90 | cksum
 pamflip -r270 maze.pbm | pamflip -r270 | pamflip -r270 | pamflip -r270 | cksum
-
-# TODO: PBM various lengths: samples with -lr
diff --git a/test/pamflip1.test b/test/pamflip1.test
index b30bf6b0..f8da3a74 100755
--- a/test/pamflip1.test
+++ b/test/pamflip1.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamflip
 # Also requires: pamseq
 
diff --git a/test/pamflip2.test b/test/pamflip2.test
index 8df293b5..0393d73e 100755
--- a/test/pamflip2.test
+++ b/test/pamflip2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamflip
 # Also requires:
 
diff --git a/test/pamfunc.test b/test/pamfunc.test
index fbb39164..0d1a4f3c 100755
--- a/test/pamfunc.test
+++ b/test/pamfunc.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamfunc
 # Also requires: pamseq pamtopnm pbmmake
 
diff --git a/test/pamgauss.test b/test/pamgauss.test
index 87e172a8..6c3eff78 100755
--- a/test/pamgauss.test
+++ b/test/pamgauss.test
@@ -1,16 +1,16 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamgauss
 # Also requires: pamfile
 
 echo "Test 1"
 
-for i in `seq 3 11`
-do
-for s in `seq 1 9`
-do
-pamgauss $i $i -oversample=1 -sigma=.$s | cksum
-done
-done
+for i in 3 4 5 6 7 8 9 10 11    # for i in `seq 3 11`
+  do
+  for s in 1 2 3 4 5 6 7 8 9    # for s in `seq 9`
+    do
+    pamgauss ${i} ${i} -oversample=1 -sigma=.${s} | cksum
+    done
+  done
 
 echo "Test 2"
 
diff --git a/test/pamhue-roundtrip.test b/test/pamhue-roundtrip.test
index 643ac99a..d68ee344 100755
--- a/test/pamhue-roundtrip.test
+++ b/test/pamhue-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamhue
 # Also requires:
 
diff --git a/test/pammixmulti-identity.test b/test/pammixmulti-identity.test
index d205c359..21136fbe 100755
--- a/test/pammixmulti-identity.test
+++ b/test/pammixmulti-identity.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pammixmulti
 # Also requires: pgmnoise pnminvert pamsumm
 
diff --git a/test/pamrecolor.test b/test/pamrecolor.test
index 67c6f19d..6f323169 100755
--- a/test/pamrecolor.test
+++ b/test/pamrecolor.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamrecolor
 # Also requires: ppmtopgm pgmmake
 
diff --git a/test/pamscale-filters1.test b/test/pamscale-filters1.test
index 63e0d012..575355c6 100755
--- a/test/pamscale-filters1.test
+++ b/test/pamscale-filters1.test
@@ -5,8 +5,8 @@
 tmpdir=${tmpdir:-/tmp}
 enlarge_ppm=${tmpdir}/enlarge.ppm
 
-width_height=`pamfile -size testimg.ppm | \
-                awk '{print "-width="$1, "-height="$2}'`
+width_height=$(pamfile -size testimg.ppm | \
+                awk '{print "-width="$1, "-height="$2}')
 
 # The target values here were determined by running the test on a
 # 32-bit GNU/Linux system and subtracting 2.5 (dB) from observed
diff --git a/test/pamscale-filters2.test b/test/pamscale-filters2.test
index f7370020..764488c5 100755
--- a/test/pamscale-filters2.test
+++ b/test/pamscale-filters2.test
@@ -5,8 +5,8 @@
 tmpdir=${tmpdir:-/tmp}
 stretch_ppm=${tmpdir}/stretch.ppm
 
-width_height=`pamfile -size testimg.ppm | \
-                awk '{print "-width="$1, "-height="$2}'`
+width_height=$(pamfile -size testimg.ppm | \
+               awk '{print "-width="$1, "-height="$2}')
 
 pamstretch -xscale=4 -yscale=3 testimg.ppm | pamvalidate > ${stretch_ppm}
 echo -xscale=4 -yscale=3 mitchell:  
diff --git a/test/pamscale-filters3.test b/test/pamscale-filters3.test
index 5a865508..23e79373 100755
--- a/test/pamscale-filters3.test
+++ b/test/pamscale-filters3.test
@@ -5,8 +5,8 @@
 tmpdir=${tmpdir:-/tmp}
 stretch_ppm=${tmpdir}/stretch.ppm
 
-width_height=`pamfile -size testimg.ppm | \
-                awk '{print "-width="$1, "-height="$2}'`
+width_height=$(pamfile -size testimg.ppm | \
+               awk '{print "-width="$1, "-height="$2}')
 
 pamstretch-gen 3.96 testimg.ppm | pamvalidate > ${stretch_ppm}
 echo 3.96 hermite:  
diff --git a/test/pamscale-reportonly.test b/test/pamscale-reportonly.test
index a5d2cdcc..f65bcb93 100755
--- a/test/pamscale-reportonly.test
+++ b/test/pamscale-reportonly.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamscale
 # Also requires:
 
diff --git a/test/pamseq.test b/test/pamseq.test
index a98a6545..3fe0fc31 100755
--- a/test/pamseq.test
+++ b/test/pamseq.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamseq
 # Also requires:
 
diff --git a/test/pamslice-roundtrip.test b/test/pamslice-roundtrip.test
index d1a8a72c..2b7929cf 100755
--- a/test/pamslice-roundtrip.test
+++ b/test/pamslice-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamslice pamdeinterlace
 # Also requires: pamfile pamcut pamtopnm pamflip
 
@@ -7,14 +7,14 @@ echo "Test 1.  Should print 139976034 137 twice"
 # Add header and reconstruct pbm image.
 # Note that in pamslice output 0 is white and 1 is black: opposite of PBM
 
-mwidth=$(pamfile -size maze.pbm | cut -d" " -f1)
+mwidth=$(pamfile -size maze.pbm | cut -d " " -f 1)
 height=16
 
 pamcut -top=0 -left=0 -height=${height} maze.pbm | cksum
 
 (echo "P1"
  echo "${mwidth} ${height}"
- for ((i = 0; i < ${height}; ++i))
+ for i in `seq 0 $((${height}-1))` 
      do
      pamslice -row=$i maze.pbm
      done | cut -d" " -f2- | sed 'y/01/10/' ) \
@@ -27,7 +27,6 @@ echo "Test 2.  Should print 1624460505 574 three times"
 # whole image takes much time.
 # Add header and reconstruct ppm image.
 
-
 tmpdir=${tmpdir:-/tmp}
 test1711_ppm=${tmpdir}/test1711.ppm
 
@@ -37,21 +36,20 @@ pamcut -left=50 -top=50 -width=17 -height=11 testimg.ppm | \
 (echo "P3"
  echo "17 11"
  echo "255"
- for ((i = 0; i < 11; ++i))
+ for i in 0 1 2 3 4 5 6 7 8 9 10   # for i in `seq 0 10`
      do
-     pamslice -row=$i ${test1711_ppm}
+     pamslice -row=${i} ${test1711_ppm}
      done | cut -d" " -f2- ) \
  | pamtopnm | cksum
 
 # Same as above test 2, but take cols instead of rows.
-# Should print 914327477 4864
 
 (echo "P3"
  echo "11 17"
  echo "255"
- for ((i = 0; i < 17; ++i))
+ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16    # for i in `seq 0 16`
      do
-     pamslice -col=$i ${test1711_ppm}
+     pamslice -col=${i} ${test1711_ppm}
      done | cut -d " " -f2- ) | pamflip -xy | cksum
 
 echo "Test 3.  Should print 1624460505 574"
@@ -66,10 +64,10 @@ pamdeinterlace -takeeven ${test1711_ppm} > ${testeven_ppm}
 ( echo "P3"
   echo "17 11"
   echo "255"
-  ( for ((i = 0; i < 5; ++i))
+  ( for i in  0 1 2 3 4 
         do
-        pamslice -row=$i ${testeven_ppm}
-        pamslice -row=$i ${testodd_ppm}
+        pamslice -row=${i} ${testeven_ppm}
+        pamslice -row=${i} ${testodd_ppm}
         done
         pamslice -row=5 ${testeven_ppm};
   ) | cut -d" " -f2- ) | pamtopnm | cksum
diff --git a/test/pamstretch.test b/test/pamstretch.test
index 8cbc555a..38e3a649 100755
--- a/test/pamstretch.test
+++ b/test/pamstretch.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamstretch
 # Also requires: pamcut pamfile
 
diff --git a/test/pamsumm.test b/test/pamsumm.test
index 32a9b8c1..fb15c0c4 100755
--- a/test/pamsumm.test
+++ b/test/pamsumm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamsumm
 # Also requires:
 
diff --git a/test/pamtable.test b/test/pamtable.test
index 335d45c4..037d3b07 100755
--- a/test/pamtable.test
+++ b/test/pamtable.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtable
 # Also requires: pamseq pamdepth pbmmake ppmrainbow
 
@@ -9,12 +9,13 @@ echo
 pamseq 4 1 -tupletype=RGBA | pamtable
 echo
 for maxval in 9 10 9999 10000 65535
-  do pbmmake -g 2 2 | pamdepth $maxval | pamtable
-     echo
-     ppmrainbow -width=3 -height=2 -norepeat black white | \
-     pamdepth $maxval | pamtable
-     echo
-     ppmrainbow -width=4 -height=2 -norepeat red blue green | \
-     pamdepth $maxval | pamtable
-     echo
+  do
+  pbmmake -g 2 2 | pamdepth ${maxval} | pamtable
+  echo
+  ppmrainbow -width=3 -height=2 -norepeat black white | \
+    pamdepth ${maxval} | pamtable
+  echo
+  ppmrainbow -width=4 -height=2 -norepeat red blue green | \
+    pamdepth ${maxval} | pamtable
+  echo
   done
diff --git a/test/pamtopam.test b/test/pamtopam.test
index e9b4f93d..c12470ec 100755
--- a/test/pamtopam.test
+++ b/test/pamtopam.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtopam
 # Also requires: pgmmake pamseq
 
diff --git a/test/pamundice.test b/test/pamundice.test
index 1e3dd31b..14b43dfb 100755
--- a/test/pamundice.test
+++ b/test/pamundice.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamundice
 # Also requires: pamfile pgmmake pnmtile pnmcat
 
@@ -7,8 +7,8 @@ fname_stem=${tmpdir}/part
 
 echo "Test 1.  Should print 2096818803 2818 twice"
 
-for ((x=0; x<3; ++x))
-  do for ((y=0; y<5; ++y))
+for x in 0 1 2
+  do for y in 0 1 2 3 4
     do
     pgmmake "."$(( x* 25 + y )) 11 17 > ${fname_stem}_${y}_${x}.pgm
     done
@@ -23,7 +23,7 @@ echo "Test 2.  Should print 2096818803 2818 twice"
 
 tempfile=${tmpdir}/temp
 
-for ((y=0; y<5; ++y))
+for y in 0 1 2 3 4
   do
   pamundice -across=3 ${fname_stem}"_"$y"_%1a".pgm > ${tempfile}_"$y"
   done
@@ -33,7 +33,7 @@ rm ${tempfile}_[01234]
 
 # Note: the following 2 are valid.  There should not be warning messages.
 
-for ((x=0; x<3; ++x))
+for x in 0 1 2
   do
   pamundice -down=5 ${fname_stem}"_%1d_"$x.pgm > ${tempfile}"_"$x
   done
@@ -45,15 +45,15 @@ rm ${fname_stem}_?_?.pgm
 
 echo "Test 3.  Should print 2096818803 2818 twice"
 
-for ((x=0; x<2; ++x))
-  do for ((y=0; y<5; ++y))
+for x in 0 1
+  do for y in 0 1 2 3 4
     do
     pgmmake "."$(( x* 25 + y )) 12 17 > ${fname_stem}_${y}_${x}.pgm
     done
   done
 
-for ((x=2; x<3; ++x))
-  do for ((y=0; y<5; ++y))
+for x in 2
+  do for y in 0 1 2 3 4
     do
     pgmmake "."$(( x* 25 + y )) 11 17 > ${fname_stem}_${y}_${x}.pgm
     done
@@ -64,15 +64,15 @@ pamundice -across=3 -down=5 \
 
 rm ${fname_stem}_?_?.pgm
 
-for ((x=0; x<3; ++x))
-  do for ((y=0; y<4; ++y))
+for x in 0 1 2
+  do for y in 0 1 2 3
     do
     pgmmake "."$(( x* 25 + y )) 11 18 > ${fname_stem}_${y}_${x}.pgm
     done
   done
 
-for ((x=0; x<3; ++x))
-  do for ((y=4; y<5; ++y))
+for x in 0 1 2
+  do for y in 4
     do
     pgmmake "."$(( x* 25 + y )) 11 17 > ${fname_stem}_${y}_${x}.pgm
     done
@@ -88,17 +88,17 @@ rm ${fname_stem}_?_?.pgm
 echo "Test 4.  Should print 2434390296 4436 four times"
 
 msize=$(pamfile -size maze.pbm)
-mw=$(echo ${msize} | cut -d" " -f1)
-mh=$(echo ${msize} | cut -d" " -f2)
+mw=$(echo ${msize} | cut -d " " -f 1)
+mh=$(echo ${msize} | cut -d " " -f 2)
 
 pnmtile $((${mw} * 2)) $((${mh} * 5)) maze.pbm | cksum
 
-for x in `seq 0 1`
-  do for y in `seq 0 4`
+for x in 0 1
+  do for y in 0 1 2 3 4
     do cp maze.pbm ${fname_stem}_${y}_${x}.pbm; done
   done
 
-for (( i=0 ; i<=9; ++i))
+for i in 0 1 2 3 4 5 6 7 8 9
   do
   echo maze.pbm
   done | pamundice -down=5 -across=2 -listfile=- | cksum
@@ -184,8 +184,10 @@ pamundice -down=5 -across=2 -voverlap=$((${mh}+1)) \
   rm -f ${test_out}
 
 # corrupt listfile : file names do not exist
-seq 10 | sed -e 's/^/::::::/' -e 's/$/::::::/' | \
-  pamundice -down=5 -across=2 -listfile=- > ${test_out} || \
+for i in 0 1 2 3 4 5 6 7 8 9
+  do
+  mktemp -u XXXXXXXXXX.${i} || echo ":::::::::::"${i}":::::::::::"
+  done | pamundice -down=5 -across=2 -listfile=- > ${test_out} || \
   echo -n "Expected failure 11"
   test -s ${test_out}; echo " "$?
   rm -f ${test_out}
diff --git a/test/pamvalidate.test b/test/pamvalidate.test
index 4cabc7df..708197da 100755
--- a/test/pamvalidate.test
+++ b/test/pamvalidate.test
@@ -1,20 +1,20 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamvalidate
 # Also requires:
 
 echo "valid"
-echo -e "P1\n5 5\n01010\n10101\n01010\n00000\n11111\n" | pamvalidate -plain
+printf "P1\n5 5\n01010\n10101\n01010\n00000\n11111\n" | pamvalidate -plain
 
 echo "not valid: Should print 0 four times"
-echo -e "P1\n5 5\n01010\n10101\n01010\n00000\n1111\n"  | pamvalidate | \
+printf "P1\n5 5\n01010\n10101\n01010\n00000\n1111\n"  | pamvalidate | \
   wc -c | tr -d ' '
 
-echo -e "P1\n5 5\n01010\n10102\n01010\n00001\n11111\n" | pamvalidate | \
+printf "P1\n5 5\n01010\n10102\n01010\n00001\n11111\n" | pamvalidate | \
   wc -c | tr -d ' '
 
-echo -e "P1\n5\n01010\n10101\n01010\n00000\n11111\n" | pamvalidate | \
+printf "P1\n5\n01010\n10101\n01010\n00000\n11111\n" | pamvalidate | \
   wc -c | tr -d ' '
 
-echo -e "P1\n5 5" | pamvalidate | wc -c | tr -d ' '
+printf "P1\n5 5" | pamvalidate | wc -c | tr -d ' '
 
 
diff --git a/test/pbm-misc-converters.ok b/test/pbm-misc-converters.ok
index a137102f..1ae5d817 100644
--- a/test/pbm-misc-converters.ok
+++ b/test/pbm-misc-converters.ok
@@ -1,27 +1,58 @@
-1638343024 43
-2141128209 77
-2542756600 120
-3102495729 32
-2414506375 47
-3241517214 145
-1454090165 46
-1436169407 46
-1454090165 46
-2912484298 46
-3576177652 52
-1478164284 52
-3213223606 141
-3213223606 141
-3213223606 141
-1463148415 108
-203901789 30
-3732005859 92
-2459345477 86
-424535246 92
-609530223 252
-4195053594 248
-2602382240 43
-129620534 361
-2256096096 80
-1349121911 149
+pbmto10x
+3017587389 501
+3017587389 501
+pbmto4425
+2529120683 622
+2529120683 622
+pbmtoascii
+2361485126 1740
+2361485126 1740
+4017331268 450
+pbmtodjvurle
+2707446245 1744
+2707446245 1744
+pbmtoepson
+2100180787 510
+2100180787 510
+2963515498 510
+2100180787 510
+1513122412 510
+pbmtogo
+34750317 804
+34750317 804
+pbmtoibm23xx
+1731023722 546
+1731023722 546
+pbmtolj
+1540204160 762
+1540204160 762
+908699854 763
+908699854 763
+pbmtoln03
+1554612498 636
+1554612498 636
+pbmtomatrixorbital
+1574732995 458
+1574732995 458
+pbmtonokia
+3813814418 972
+3813814418 972
+1385394245 966
+3924854157 972
+3970098281 3388
+167529797 3384
+2260274013 483
+pbmtoplot
+2120102625 5318
+2120102625 5318
+pbmtoptx
+541430122 708
+541430122 708
+pbmtozinc
+2297581967 1725
+2297581967 1725
+pbmtobbnbg
+3481527833 672
+pbmtoppa
+3955750161 284701
 3955750161 284701
diff --git a/test/pbm-misc-converters.test b/test/pbm-misc-converters.test
index ad96f13c..ba350bc7 100755
--- a/test/pbm-misc-converters.test
+++ b/test/pbm-misc-converters.test
@@ -1,40 +1,98 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmto10x pbmto4425 pbmtoascii pbmtobbnbg
 # This script tests: pbmtodjvurle pbmtoepson pbmtogo pbmtoibm23xx
 # This script tests: pbmtolj pbmtoln03 pbmtomatrixorbital pbmtonokia
-# This script tests: pbmtoplot pbmtoptx pbmtozinc
-# Also requires: pbmpage pbmtoppa
+# This script tests: pbmtoplot pbmtoppa pbmtoptx pbmtozinc
+# Also requires: pbmpage
 
 # Note: one-way test.
 # These converters do not have counterparts that work in the opposite
 # direction.  We check whether the output is unchanged from older
 # versions.
 
-pbmto10x             testgrid.pbm | cksum
-pbmto4425            testgrid.pbm | cksum
-pbmtoascii           testgrid.pbm | cksum
-pbmtoascii -2x4      testgrid.pbm | cksum
-pbmtobbnbg         < testgrid.pbm | cksum
-pbmtodjvurle         testgrid.pbm | cksum
-pbmtoepson           testgrid.pbm | cksum
-pbmtoepson -protocol=escp   testgrid.pbm | cksum
-pbmtoepson -protocol=escp9  testgrid.pbm | cksum
-pbmtoepson -nonadjacent     testgrid.pbm | cksum
-pbmtogo              testgrid.pbm | cksum
-pbmtoibm23xx -xres=60 -yres=60 testgrid.pbm | cksum
-pbmtolj              testgrid.pbm | cksum
-pbmtolj  -packbits   testgrid.pbm | cksum
-pbmtolj  -compress   testgrid.pbm | cksum
-pbmtoln03            testgrid.pbm | cksum
-pbmtomatrixorbital < testgrid.pbm | cksum
-pbmtonokia -fmt HEX_NOL testgrid.pbm | cksum
-pbmtonokia -fmt HEX_NGG testgrid.pbm | cksum
-pbmtonokia -fmt HEX_NPM testgrid.pbm | cksum
-pbmtonokia -fmt NOL  testgrid.pbm | cksum
-pbmtonokia -fmt NGG  testgrid.pbm | cksum
-pbmtonokia -fmt NPM  testgrid.pbm | cksum
-pbmtoplot            testgrid.pbm | cksum
-pbmtoptx             testgrid.pbm | cksum
-pbmtozinc            testgrid.pbm | cksum
-
-(pbmpage 1; pbmpage 2; pbmpage 3) | pbmtoppa | cksum
+echo "pbmto10x"
+pbmto10x               maze.pbm | cksum
+pbmto10x             < maze.pbm | cksum
+
+echo "pbmto4425"
+pbmto4425              maze.pbm | cksum
+pbmto4425            < maze.pbm | cksum
+
+# Asciitopgm works in the opposite direction, but the round-trip is not accurate
+
+echo "pbmtoascii"
+pbmtoascii             maze.pbm | cksum
+pbmtoascii           < maze.pbm | cksum
+pbmtoascii -2x4        maze.pbm | cksum
+
+echo "pbmtodjvurle"
+pbmtodjvurle           maze.pbm | cksum
+pbmtodjvurle         < maze.pbm | cksum
+
+echo "pbmtoepson"
+pbmtoepson             maze.pbm | cksum
+pbmtoepson           < maze.pbm | cksum
+pbmtoepson -protocol=escp   maze.pbm | cksum
+pbmtoepson -protocol=escp9  maze.pbm | cksum
+pbmtoepson -nonadjacent     maze.pbm | cksum
+
+echo "pbmtogo"
+pbmtogo                maze.pbm | cksum
+pbmtogo              < maze.pbm | cksum
+
+echo "pbmtoibm23xx"
+pbmtoibm23xx -xres=60 -yres=60    maze.pbm | cksum
+pbmtoibm23xx -xres=60 -yres=60  < maze.pbm | cksum
+
+echo "pbmtolj"
+pbmtolj                maze.pbm | cksum
+pbmtolj              < maze.pbm | cksum
+pbmtolj  -packbits     maze.pbm | cksum
+pbmtolj  -compress     maze.pbm | cksum
+
+echo "pbmtoln03"
+pbmtoln03              maze.pbm | cksum
+pbmtoln03            < maze.pbm | cksum
+
+echo "pbmtomatrixorbital"
+pbmtomatrixorbital     maze.pbm | cksum
+pbmtomatrixorbital   < maze.pbm | cksum
+
+echo "pbmtonokia"
+pbmtonokia -fmt HEX_NOL   maze.pbm | cksum
+pbmtonokia -fmt HEX_NOL < maze.pbm | cksum
+pbmtonokia -fmt HEX_NGG   maze.pbm | cksum
+pbmtonokia -fmt HEX_NPM   maze.pbm | cksum
+pbmtonokia -fmt NOL       maze.pbm | cksum
+pbmtonokia -fmt NGG       maze.pbm | cksum
+pbmtonokia -fmt NPM       maze.pbm | cksum
+
+echo "pbmtoplot"
+pbmtoplot              maze.pbm | cksum
+pbmtoplot            < maze.pbm | cksum
+
+echo "pbmtoptx"
+pbmtoptx               maze.pbm | cksum
+pbmtoptx             < maze.pbm | cksum
+
+# pbmtozinc embeds input filename in the output
+
+echo "pbmtozinc"
+pbmtozinc   maze.pbm | cksum
+pbmtozinc < maze.pbm | sed 's/noname/maze/' | cksum
+
+# pbmtobbnbg input must be from stdin
+
+echo "pbmtobbnbg"
+pbmtobbnbg < maze.pbm | cksum
+
+# pbmtoppa has constraints on what can be accepted as input; maze.pbm is not accepted
+# pbmpage produces suitable input
+
+tmpdir=${tmpdir:-/tmp}
+testpage_pbm=${tmpdir}/testpage.pbm
+
+echo "pbmtoppa"
+(pbmpage 1; pbmpage 2; pbmpage 3) | tee ${testpage_pbm} | pbmtoppa | cksum
+pbmtoppa ${testpage_pbm} | cksum
+rm ${testpage_pbm}
diff --git a/test/pbm-ppm-roundtrip.test b/test/pbm-ppm-roundtrip.test
index 23b6c1c4..9a3ff79f 100755
--- a/test/pbm-ppm-roundtrip.test
+++ b/test/pbm-ppm-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmtoppm ppmtopgm ppmtoppm pgmtopbm
 # Also requires: pbmmake ppmcolormask pnminvert
 
diff --git a/test/pbmclean.test b/test/pbmclean.test
index 0e17ba8a..7c0c4d6d 100755
--- a/test/pbmclean.test
+++ b/test/pbmclean.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmclean
 # Also requires: pbmmake pbmpage pbmtext pnmmargin pnmpad
 
diff --git a/test/pbmlife.test b/test/pbmlife.test
index b4d65ec4..c292ee65 100755
--- a/test/pbmlife.test
+++ b/test/pbmlife.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmlife pbmminkowski
 # Also requires: pbmtext
 
diff --git a/test/pbmmake.test b/test/pbmmake.test
index eef4e0da..c3691b80 100755
--- a/test/pbmmake.test
+++ b/test/pbmmake.test
@@ -1,25 +1,26 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmmake
 # Also requires:
 
 echo "Test 1"
 
-for i in `seq 1 8`
-do
-for color in -white -black -gray
-do
-pbmmake -plain $color $i $i | tr -d '\n'; echo
-done
-done
+for size in 1 2 3 4 5 6 7 8             # for size in `seq 8`
+  do
+  for color in -white -black -gray
+    do
+    pbmmake -plain ${color} ${size} ${size} | tr -d '\n'; echo
+    done
+  done
 
 echo "Test 2"
 
-for i in `seq 8 5 98`
-do
- ( pbmmake -w $i $i ;
-  pbmmake -b $i $i ;
-  pbmmake  -g $i $i ) | cksum
-done
+for size in 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 83 88 93 98
+	    # for size in `seq 8 5 98`
+  do
+  ( pbmmake -w ${size} ${size} ;
+    pbmmake -b ${size} ${size} ;
+    pbmmake -g ${size} ${size} ) | cksum
+  done
 
 echo "Test Invalid"
 
diff --git a/test/pbmminkowski.test b/test/pbmminkowski.test
index 3ad96dfa..790e45bd 100755
--- a/test/pbmminkowski.test
+++ b/test/pbmminkowski.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmminkowski
 # Also requires: pbmmake pnmpad
 
diff --git a/test/pbmnoise-parameters.test b/test/pbmnoise-parameters.test
index f3348ae8..e467bfd5 100755
--- a/test/pbmnoise-parameters.test
+++ b/test/pbmnoise-parameters.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmnoise
 # Also requires:
 
diff --git a/test/pbmnoise1.test b/test/pbmnoise1.test
index 1b8fc241..855a5629 100755
--- a/test/pbmnoise1.test
+++ b/test/pbmnoise1.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmnoise
 #
 
@@ -13,7 +13,9 @@ done
 
 echo "Test 2."
 
-for ((i=0 ; i<=32; i++))
+for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \
+	 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 
+         # for i in `seq 0 32`
   do
   pbmnoise -endian=little -randomseed=11 -ratio=$i/32 -plain 32 1 | \
   tr '\n' ' ';  echo
diff --git a/test/pbmnoise2.test b/test/pbmnoise2.test
index 7476d03c..8845e3b8 100755
--- a/test/pbmnoise2.test
+++ b/test/pbmnoise2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmnoise
 # Also requires: pgmhist
 
diff --git a/test/pbmpage.test b/test/pbmpage.test
index 2ee27122..2805ec97 100755
--- a/test/pbmpage.test
+++ b/test/pbmpage.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmpage
 # Also requires:
 
diff --git a/test/pbmpscale.test b/test/pbmpscale.test
index a92511b0..9c38bb2e 100755
--- a/test/pbmpscale.test
+++ b/test/pbmpscale.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmpscale
 # Also requires: pbmtext
 
diff --git a/test/pbmtext-bdf.test b/test/pbmtext-bdf.test
index d3d4b37f..f1d2019e 100755
--- a/test/pbmtext-bdf.test
+++ b/test/pbmtext-bdf.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtext
 # Also requires:
 
diff --git a/test/pbmtext-iso88591.test b/test/pbmtext-iso88591.test
index 69e6ec90..6df296dd 100755
--- a/test/pbmtext-iso88591.test
+++ b/test/pbmtext-iso88591.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtext
 # Also requires:
 
diff --git a/test/pbmtext.test b/test/pbmtext.test
index a7c75c23..b82b0771 100755
--- a/test/pbmtext.test
+++ b/test/pbmtext.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtext
 # Also requires: pamfile
 
@@ -41,7 +41,7 @@ for flags in "" "-builtin fixed"
 do
 pbmtext ${flags} ${text} | tee ${temp_pbm} | cksum
 width1=`pamfile ${temp_pbm} | awk '$2=="PBM" && NR==1 {w=$4}; END {print w}' `
-width2=`pbmtext ${flags} ${text} --dry-run | awk '{print $1}' `
+width2=`pbmtext ${flags} ${text} --dry-run | cut -d " " -f 1`
 
 if [ ${width1} -eq ${width2} ]; then
     pbmtext ${flags} -width=${width1} ${text} | cksum
diff --git a/test/pbmtog3.test b/test/pbmtog3.test
index c23e8af0..8b9c29e1 100755
--- a/test/pbmtog3.test
+++ b/test/pbmtog3.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtog3
 # Also requires: pbmmake
 
diff --git a/test/pbmtopgm.test b/test/pbmtopgm.test
index 53b25aab..46c04705 100755
--- a/test/pbmtopgm.test
+++ b/test/pbmtopgm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtopgm
 # Also requires:
 
diff --git a/test/pbmupc.test b/test/pbmupc.test
index f4a4d1e8..8d726de5 100755
--- a/test/pbmupc.test
+++ b/test/pbmupc.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmupc
 # Also requires:
 
diff --git a/test/pcx-roundtrip.ok b/test/pcx-roundtrip.ok
index 968f46b9..0f5ac87d 100644
--- a/test/pcx-roundtrip.ok
+++ b/test/pcx-roundtrip.ok
@@ -1,5 +1,9 @@
+Test 1.  Should print 1926073387 101484
 1926073387 101484
+Test 2.  Should print 369063776 101484 three times
 369063776 101484
 369063776 101484
 369063776 101484
-829921912 685
+Test 3.  Should print 669206373 10102 twice
+669206373 10102
+669206373 10102
diff --git a/test/pcx-roundtrip.test b/test/pcx-roundtrip.test
index 3dba42b9..3a78faba 100755
--- a/test/pcx-roundtrip.test
+++ b/test/pcx-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtopcx pcxtoppm
 # Also requires: pnmremap
 
@@ -29,17 +29,16 @@ P3
 255 255 255
 EOF
 
-# Test 1. Should print 1926073387 101484
+echo "Test 1.  Should print 1926073387 101484"
 ppmtopcx testimg.ppm | pcxtoppm | cksum
 
-# Test 2.  Should print 369063776 101484 three times
+echo "Test 2.  Should print 369063776 101484 three times"
 pnmremap testimg.ppm -mapfile=${pcxstd_ppm} | tee ${testpcx_ppm} | cksum
 ppmtopcx -stdpalette -packed ${testpcx_ppm} | pcxtoppm | cksum
 ppmtopcx -stdpalette -packed -8bit ${testpcx_ppm} | pcxtoppm | cksum
 
 rm ${testpcx_ppm} ${pcxstd_ppm}
 
-# Test 3. Should print 829921912 685 which is the
-# result of:
-# pgmtoppm < testgrid.pbm | cksum
-ppmtopcx -stdpalette -packed testgrid.pbm | pcxtoppm | cksum
+echo "Test 3.  Should print 669206373 10102 twice"
+pgmtoppm < maze.pbm | cksum
+ppmtopcx -stdpalette -packed maze.pbm | pcxtoppm | cksum
diff --git a/test/pdb-roundtrip.ok b/test/pdb-roundtrip.ok
index b903da8d..fbc897fe 100644
--- a/test/pdb-roundtrip.ok
+++ b/test/pdb-roundtrip.ok
@@ -1,18 +1,18 @@
-pbm grid
+Test 1: pbm grid : Should print 2224198737 25671 three times
 2224198737 25671
 2224198737 25671
 2224198737 25671
-pbm tiled
+Test 2: pbmnoise : Should print 0 0 0 0 : 0 four times
 0 0 0 0 : 0
 0 0 0 0 : 0
 0 0 0 0 : 0
 0 0 0 0 : 0
-pgm ellipse
+Test 3: pgm ellipse : Should print 0 0 0 0 0 : 0 four times
 0 0 0 0 0 : 0
 0 0 0 0 0 : 0
 0 0 0 0 0 : 0
 0 0 0 0 0 : 0
-pgm ellipse -4depth
+Test 4: pgm ellipse -4depth : Should print 0 0 0 0 0 : 0 three times
 0 0 0 0 0 : 0
 0 0 0 0 0 : 0
 0 0 0 0 0 : 0
diff --git a/test/pdb-roundtrip.test b/test/pdb-roundtrip.test
index 32d7aa87..c31a63e1 100755
--- a/test/pdb-roundtrip.test
+++ b/test/pdb-roundtrip.test
@@ -3,35 +3,29 @@
 # Also requires: pnmtile pgmramp pamtopnm pamdepth
 
 tmpdir=${tmpdir:-/tmp}
-tiled_pbm=${tmpdir}/tiled.pbm
+noise_pbm=${tmpdir}/noise.pbm
 ellipse_pgm=${tmpdir}/ellipse.pgm
 
 
-# Test 1. Should produce 2224198737 25671
-# 3 times 
-echo pbm grid
+echo "Test 1: pbm grid : Should print 2224198737 25671 three times"
 for flag in "-compressed" "-maybecompressed" "-uncompressed"
    do
    pamtopdbimg ${flag} testgrid.pbm | pdbimgtopam | cksum
    done
 
 
-# Test 2. Should produce 0 0 0
-# 4 times 
-echo pbm tiled
-pnmtile 160 160 testgrid.pbm > ${tiled_pbm}
+echo "Test 2: pbmnoise : Should print 0 0 0 0 : 0 four times" 
+pbmnoise -randomseed=1 160 160 > ${noise_pbm}
 for flag in "" "-compressed" "-maybecompressed" "-uncompressed"
   do
-  pamtopdbimg ${flag} ${tiled_pbm} | pdbimgtopam | pamtopnm | \
-    cmp -s - ${tiled_pbm}
+  pamtopdbimg ${flag} ${noise_pbm} | pdbimgtopam | pamtopnm | \
+    cmp -s - ${noise_pbm}
   echo ${PIPESTATUS[@]} ":" $?
   done
-rm ${tiled_pbm}
+rm ${noise_pbm}
 
 
-# Test 3. Should produce 0 0 0
-# 4 times
-echo pgm ellipse
+echo "Test 3: pgm ellipse : Should print 0 0 0 0 0 : 0 four times"
 pgmramp -ellipse 160 160 -maxval=3 > ${ellipse_pgm}
 for flag in "" "-compressed" "-maybecompressed" "-uncompressed"
     do
@@ -42,9 +36,7 @@ for flag in "" "-compressed" "-maybecompressed" "-uncompressed"
 rm ${ellipse_pgm}
 
 
-# Test 3. Should produce 0 0 0
-# 3 times 
-echo pgm ellipse -4depth
+echo "Test 4: pgm ellipse -4depth : Should print 0 0 0 0 0 : 0 three times"
 pgmramp -ellipse 160 160 -maxval=15 > ${ellipse_pgm}
 for flag in "-compressed" "-maybecompressed" "-uncompressed"
     do
@@ -52,4 +44,4 @@ for flag in "-compressed" "-maybecompressed" "-uncompressed"
       pamtopnm | pamdepth 15 | cmp -s - ${ellipse_pgm}
     echo ${PIPESTATUS[@]} ":" $?
     done
-rm ${ellipse_pgm}
\ No newline at end of file
+rm ${ellipse_pgm}
diff --git a/test/pfm-roundtrip.test b/test/pfm-roundtrip.test
index f1b5d418..95bfc62f 100755
--- a/test/pfm-roundtrip.test
+++ b/test/pfm-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtopfm pfmtopam
 # Also requires: pamtopnm
 
diff --git a/test/pgmbentley.test b/test/pgmbentley.test
index 0429d54b..800aa1f7 100755
--- a/test/pgmbentley.test
+++ b/test/pgmbentley.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmbentley
 # Also requires: pgmramp
 
diff --git a/test/pgmhist.test b/test/pgmhist.test
index b028b07a..83f3c52e 100755
--- a/test/pgmhist.test
+++ b/test/pgmhist.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmhist
 # Also requires: pgmramp
 
diff --git a/test/pgmmake.test b/test/pgmmake.test
index 0ec5efd6..84c03778 100755
--- a/test/pgmmake.test
+++ b/test/pgmmake.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmmake
 # Also requires:
 
diff --git a/test/pgmminkowski.test b/test/pgmminkowski.test
index 9d8c257d..e81de3e1 100755
--- a/test/pgmminkowski.test
+++ b/test/pgmminkowski.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmminkowski
 # Also requires: pbmmake pgmmake pnmpad
 
diff --git a/test/pgmnoise-parameters.test b/test/pgmnoise-parameters.test
index bf3deb3f..2615c8e8 100755
--- a/test/pgmnoise-parameters.test
+++ b/test/pgmnoise-parameters.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmnoise
 # Also requires:
 
diff --git a/test/pgmnoise.ok b/test/pgmnoise.ok
index 80376c78..d98ee053 100644
--- a/test/pgmnoise.ok
+++ b/test/pgmnoise.ok
@@ -77,7 +77,7 @@ Should print four identical lines
 969759084 1682
 969759084 1682
 Test 6.
-First column should be 2^n - 1
+First column should be 2^n - 1.  Last column should be 'pool'.
 1 pgmnoise: method: pool
 3 pgmnoise: method: pool
 7 pgmnoise: method: pool
@@ -86,6 +86,9 @@ First column should be 2^n - 1
 63 pgmnoise: method: pool
 127 pgmnoise: method: pool
 255 pgmnoise: method: pool
+511 pgmnoise: method: pool
+1023 pgmnoise: method: pool
+65535 pgmnoise: method: pool
 Test Invalid
 Expected failure 1 1
 Expected failure 2 1
diff --git a/test/pgmnoise.test b/test/pgmnoise.test
index 4a6e21dd..45374793 100755
--- a/test/pgmnoise.test
+++ b/test/pgmnoise.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmnoise
 # Also requires: pgmhist pamvalidate pamfile
 
@@ -17,7 +17,7 @@ pgmnoise --randomseed=5489 -maxval=9999 -plain 5 20
 
 
 echo "Test 3."
-for maxval in `seq 16` 255 65535
+for maxval in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 255 65535
   do
   echo ${maxval}
   pgmnoise -maxval=${maxval} -randomseed=1 -plain 16 1 | tr '\n' ' '
@@ -26,7 +26,8 @@ echo
 
 echo "Test 4."
 # Check for maxval violation
-for maxval in `seq 16` 30 31 32 254 255 256 65534 65535
+for maxval in  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \
+               30 31 32 254 255 256 65534 65535
   do
   echo -n ${maxval} " "
   pgmnoise -maxval=${maxval} -randomseed=1 -plain ${maxval} 10 | \
@@ -42,20 +43,29 @@ for xysize in "1 10000" "100 100" "250 40" "1000 10"
 
 
 tmpdir=${tmpdir:-/tmp}
-messages=${tmpdir}/messages
+outfile=${tmpdir}/out
 
 echo "Test 6."
-echo "First column should be 2^n - 1"
+echo "First column should be 2^n - 1.  Last column should be 'pool'."
 # The "pool" method of generating pixvals is used iff maxval is
 # a power of 2 minus 1: 1, 3, 7, 15, 31 ...
-for maxval in `seq 35; seq 60 69; seq 120 129; seq 250 259`
-  do
-  pgmnoise -maxval=${maxval} -randomseed=1 -verbose 1 1 > /dev/null \
-  2> ${messages}
-  awk -v mval=${maxval} '/method/ && /pool/ { print mval, $0 }' ${messages}
-  done
 
-  rm ${messages}
+    
+for maxval in \
+    1 2 3 4 5 6 7 8 9 \
+    10 11 12 13 14 15 16 17 18 19 \
+    20 21 22 23 24 25 26 27 28 29 \
+    30 31 32 33  60 61 62 63 64 65 \
+    127 255 511 1023  65535 \
+    129 142 186 219 677 1068 1788 1820 2067 2154 2301 2317 \
+    5180 5321 5596 6304 7565 9525 \
+    10501 14178 25797 27451 28653
+    do
+    pgmnoise -maxval=${maxval} -plain -randomseed=1 -verbose 1 1 \
+		 > /dev/null 2> ${outfile}
+    awk -v mval=${maxval} '/method/ && /pool/ { print mval, $0 }' ${outfile}
+    rm ${outfile}
+    done
 
 
 echo "Test Invalid"
diff --git a/test/pgmramp.test b/test/pgmramp.test
index 50a3cf6d..c3b0ad1c 100755
--- a/test/pgmramp.test
+++ b/test/pgmramp.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmramp
 # Also requires:
 
diff --git a/test/pgmtopgm.ok b/test/pgmtopgm.ok
index 53c25a44..38cfd268 100644
--- a/test/pgmtopgm.ok
+++ b/test/pgmtopgm.ok
@@ -1 +1,11 @@
-729348909 237
+Test 1.  Should print two identical PGM images
+P2
+10 1
+255
+0 0 0 0 0 0 0 0 0 0
+P2
+10 1
+255
+0 0 0 0 0 0 0 0 0 0
+Test 2.  Should print 2582999797 3376
+2582999797 3376
diff --git a/test/pgmtopgm.test b/test/pgmtopgm.test
index e919fdac..d81260d8 100755
--- a/test/pgmtopgm.test
+++ b/test/pgmtopgm.test
@@ -1,6 +1,12 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmtopgm
-# Also requires:
+# Also requires: pgmmake
 
+echo "Test 1.  Should print two identical PGM images"
 
-pgmtopgm < testgrid.pbm | cksum
+pgmmake -plain 0 10 1
+pgmmake 0 10 1 | pgmtopgm -plain
+
+echo "Test 2.  Should print 2582999797 3376"
+
+pgmtopgm < maze.pbm | cksum
diff --git a/test/pgmtoppm.test b/test/pgmtoppm.test
index 622a0688..d98418b8 100755
--- a/test/pgmtoppm.test
+++ b/test/pgmtoppm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmtoppm
 # Also requires: pamtopnm pnminvert pamseq pgmramp
 
diff --git a/test/pi3-roundtrip.test b/test/pi3-roundtrip.test
index 6c75acc7..d795157d 100755
--- a/test/pi3-roundtrip.test
+++ b/test/pi3-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtopi3 pi3topbm
 # Also requires: pbmmake pamcut pamfile
 
diff --git a/test/pict-roundtrip.test b/test/pict-roundtrip.test
index cd207d48..b4910064 100755
--- a/test/pict-roundtrip.test
+++ b/test/pict-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: picttoppm ppmtopict
 # Also requires: pamseq pamdepth pamtopnm pnmremap
 
diff --git a/test/png-roundtrip.test b/test/png-roundtrip.test
index fcb5927a..97cf9b2c 100755
--- a/test/png-roundtrip.test
+++ b/test/png-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pngtopam pnmtopng
 # Also requires:
 
diff --git a/test/png-roundtrip2.test b/test/png-roundtrip2.test
index 5705a1ae..85149a91 100755
--- a/test/png-roundtrip2.test
+++ b/test/png-roundtrip2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pngtopam pamtopng
 # Also requires:
 
diff --git a/test/pnm-pam-roundtrip.test b/test/pnm-pam-roundtrip.test
index 13925f74..da3021f9 100755
--- a/test/pnm-pam-roundtrip.test
+++ b/test/pnm-pam-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtopam pamtopnm
 # Also requires:
 
diff --git a/test/pnm-plain-roundtrip.test b/test/pnm-plain-roundtrip.test
index bf685e85..14b8ca57 100755
--- a/test/pnm-plain-roundtrip.test
+++ b/test/pnm-plain-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtopnm
 #
 
diff --git a/test/pnmcat.test b/test/pnmcat.test
index c098d967..173aa608 100755
--- a/test/pnmcat.test
+++ b/test/pnmcat.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmcat
 # Also requires: pbmmake pgmramp ppmtoppm
 
diff --git a/test/pnmcolormap.test b/test/pnmcolormap.test
index 90d11f6d..089e0d1e 100755
--- a/test/pnmcolormap.test
+++ b/test/pnmcolormap.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmcolormap
 # Also requires:
 
diff --git a/test/pnmcrop-blank.test b/test/pnmcrop-blank.test
index 087ad65e..bb26bdc0 100755
--- a/test/pnmcrop-blank.test
+++ b/test/pnmcrop-blank.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmcrop
 # Also requires: pbmmake ppmmake
 
diff --git a/test/pnmcrop1.ok b/test/pnmcrop1.ok
index d02d14b3..d979d2db 100644
--- a/test/pnmcrop1.ok
+++ b/test/pnmcrop1.ok
@@ -1,103 +1,82 @@
 Test 1
-test.pbm
-
-0 0 -7 0 28 25 rgb-1:1/1/1 0.000000
--white
-0 0 -7 0 28 25 rgb-1:1/1/1 0.000000
--black
-0 0 0 -2 28 30 rgb-1:0/0/0 0.000000
--sides
-0 0 -7 0 28 25 rgb-1:1/1/1 0.000000
--top
-0 0 -7 0 28 25 rgb-1:1/1/1 0.000000
--bottom
-0 0 0 0 28 32 rgb-1:1/1/1 0.000000
--left
-0 0 0 0 28 32 rgb-1:1/1/1 0.000000
--right
-0 0 0 0 28 32 rgb-1:1/1/1 0.000000
--top -bottom
-0 0 -7 0 28 25 rgb-1:1/1/1 0.000000
--bottom -bg-corner=bottomright
-0 0 0 -2 28 30 rgb-1:0/0/0 0.000000
--right -bg-corner=bottomright
-0 0 0 0 28 32 rgb-1:0/0/0 0.000000
--bg-color=white
-0 0 0 0 28 32 rgb-1:1/1/1 0.000000
--bg-color=black
-0 0 0 -2 28 30 rgb-1:0/0/0 0.000000
--bg-color=red
-0 0 0 0 28 32 rgb-1:0/0/0 0.000000
-test.ppm
-
+file: maze.pbm option: 
+0 0 -7 0 71 68 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -white
+0 0 -7 0 71 68 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -black
+0 0 0 -2 71 73 rgb-1:0/0/0 0.000000
+file: maze.pbm option: -sides
+0 0 -7 0 71 68 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -top
+0 0 -7 0 71 68 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -bottom
+0 0 0 0 71 75 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -left
+0 0 0 0 71 75 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -right
+0 0 0 0 71 75 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -top -bottom
+0 0 -7 0 71 68 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -bottom -bg-corner=bottomright
+0 0 0 -2 71 73 rgb-1:0/0/0 0.000000
+file: maze.pbm option: -right -bg-corner=bottomright
+0 0 0 0 71 75 rgb-1:0/0/0 0.000000
+file: maze.pbm option: -bg-color=white
+0 0 0 0 71 75 rgb-1:1/1/1 0.000000
+file: maze.pbm option: -bg-color=black
+0 0 0 -2 71 73 rgb-1:0/0/0 0.000000
+file: maze.pbm option: -bg-color=red
+0 0 0 0 71 75 rgb-1:0/0/0 0.000000
+file: rose.ppm option: 
 0 0 0 0 250 161 rgb-255:127/127/127 0.000000
--white
+file: rose.ppm option: -white
 -6 0 0 0 244 161 rgb-255:255/255/255 0.000000
--black
+file: rose.ppm option: -black
 0 -11 0 0 239 161 rgb-255:0/0/0 0.000000
--sides
+file: rose.ppm option: -sides
 -6 0 0 0 244 161 rgb-255:255/255/255 0.000000
--top
+file: rose.ppm option: -top
 0 0 0 0 250 161 rgb-255:127/127/127 0.000000
--bottom
+file: rose.ppm option: -bottom
 0 0 0 0 250 161 rgb-255:127/127/127 0.000000
--left
+file: rose.ppm option: -left
 0 0 0 0 250 161 rgb-255:127/127/127 0.000000
--right
+file: rose.ppm option: -right
 0 0 0 0 250 161 rgb-255:127/127/127 0.000000
--top -bottom
+file: rose.ppm option: -top -bottom
 0 0 0 0 250 161 rgb-255:127/127/127 0.000000
--bottom -bg-corner=bottomright
+file: rose.ppm option: -bottom -bg-corner=bottomright
 0 0 0 0 250 161 rgb-255:0/0/0 0.000000
--right -bg-corner=bottomright
+file: rose.ppm option: -right -bg-corner=bottomright
 0 -11 0 0 239 161 rgb-255:0/0/0 0.000000
--bg-color=white
+file: rose.ppm option: -bg-color=white
 -6 0 0 0 244 161 rgb-255:255/255/255 0.000000
--bg-color=black
+file: rose.ppm option: -bg-color=black
 0 -11 0 0 239 161 rgb-255:0/0/0 0.000000
--bg-color=red
+file: rose.ppm option: -bg-color=red
 0 0 0 0 250 161 rgb-255:255/0/0 0.000000
-Test 2
-test.pbm
-
-3130931737 109
-3130931737 109
--white
-3130931737 109
-3130931737 109
--top
-3130931737 109
-3130931737 109
-test.ppm
-
-1435955776 120765
-1435955776 120765
--white
-638507845 117867
-638507845 117867
--top
-1435955776 120765
-1435955776 120765
+Test 2.  Should print 0 six times
+file: maze.pbm option:
+0
+file: maze.pbm option: -white
+0
+file: maze.pbm option: -top
+0
+file: rose.ppm option:
+0
+file: rose.ppm option: -white
+0
+file: rose.ppm option: -top
+0
 Test Invalid
--reportfull -reportsize
 Expected failure:  -reportfull -reportsize 1
--reportfull -borderfile=testgrid.pbm
 Expected failure:  -reportfull -borderfile=testgrid.pbm 1
--reportsize -borderfile=testgrid.pbm
 Expected failure:  -reportsize -borderfile=testgrid.pbm 1
--black -white
 Expected failure:  -black -white 1
--black -sides
 Expected failure:  -black -sides 1
--white -bg-color=red
 Expected failure:  -white -bg-color=red 1
--white -bg-corner=topleft
 Expected failure:  -white -bg-corner=topleft 1
--white -bg-corner=top
 Expected failure:  -white -bg-corner=top 1
--blank-image=pasturize
 Expected failure:  -blank-image=pasturize 1
--bg-color=black -closeness=-1
 Expected failure:  -bg-color=black -closeness=-1 1
--bg-color=black -closeness=101
 Expected failure:  -bg-color=black -closeness=101 1
diff --git a/test/pnmcrop1.test b/test/pnmcrop1.test
index 936cbd95..00d5ee80 100755
--- a/test/pnmcrop1.test
+++ b/test/pnmcrop1.test
@@ -1,13 +1,13 @@
-#! /bin/bash
+ #! /bin/sh
 # This script tests: pnmcrop
 # Also requires: pnmpad pnmmargin pamcut
 
 tmpdir=${tmpdir:-/tmp}
 
-test_pbm=${tmpdir}/test.pbm
-test_ppm=${tmpdir}/test.ppm
+test_pbm=${tmpdir}/maze.pbm
+test_ppm=${tmpdir}/rose.ppm
 
-pnmmargin -white 7 testgrid.pbm | pnmpad -black -bottom=2  > ${test_pbm}
+pnmmargin -white 7 maze.pbm | pnmpad -black -bottom=2  > ${test_pbm}
 pnmmargin -white 6 testimg.ppm  | pnmpad -black -right=11  > ${test_ppm}
 
 #Test 1
@@ -15,36 +15,41 @@ echo Test 1
 
 for input_file in ${test_pbm} ${test_ppm}
   do
-  echo `basename ${input_file}`
+  bfile=`basename ${input_file}`
   for option in "" "-white" "-black" "-sides" \
               "-top" "-bottom" "-left" "-right" "-top -bottom" \
               "-bottom -bg-corner=bottomright" \
               "-right -bg-corner=bottomright" \
               "-bg-color=white" "-bg-color=black" "-bg-color=red"
     do
-    echo ${option}
+    echo "file: ${bfile} option: ${option}"
     pnmcrop -reportfull ${option} ${input_file} || echo fail
     done
   done
 
 #Test 2
-echo Test 2
+echo "Test 2.  Should print 0 six times"
+
+out_pnm=${tmpdir}/out.pnm
 
 for input_file in ${test_pbm} ${test_ppm}
   do
-  echo `basename ${input_file}`
+  bfile=`basename ${input_file}`
   for option in "" "-white" "-top"
     do
-    echo ${option}
+    echo file: ${bfile} option: ${option}
     # Normal crop operation
-    pnmcrop ${option} ${input_file} | cksum
+    pnmcrop ${option} ${input_file} > ${out_pnm}
 
     # Compute edge extents with pnmcrop; let pamcut do the actual cropping
     pamcut ${input_file} `pnmcrop -reportsize ${option} ${input_file} | \
         awk 'NF==6 && NR==1 && \
              $1<=0 && $2<=0 && $3<=0 && $4<=0 && $5>=0 && $6>=0 \
-             { printf("-cropleft=%d -cropright=%d  ", -$1, -$2);
-               printf("-croptop=%d -cropbottom=%d", -$3, -$4) }' ` | cksum
+             { printf("-cropleft=%d -cropright=%d ", -$1, -$2);
+               printf("-croptop=%d -cropbottom=%d ", -$3, -$4) }' ` | \
+        cmp -s - ${out_pnm}
+    echo $?
+    rm ${out_pnm}
     done
   done
 
@@ -72,7 +77,6 @@ for option in "-reportfull -reportsize" \
               "-bg-color=black -closeness=-1" \
               "-bg-color=black -closeness=101"
     do
-    echo ${option}
     pnmcrop -reportfull ${option} testgrid.pbm > ${test_out} || \
         echo -n "Expected failure: " ${option}
         test -s ${test_out}; echo " "$?
diff --git a/test/pnmcrop2.test b/test/pnmcrop2.test
index d6c83c73..3d402a57 100755
--- a/test/pnmcrop2.test
+++ b/test/pnmcrop2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmcrop
 # Also requires:
 
@@ -44,7 +44,7 @@ for corner in topleft topright bottomleft bottomright
 
 echo Test 3
 
-for closeness in `seq 0 6`
+for closeness in 0 1 2 3 4 5 6  # for closeness in `seq 0 6`
   do
   echo ${closeness}
   pnmcrop -reportfull -bg-corner=topleft -closeness=${closeness} ${test_pgm} \
diff --git a/test/pnmcrop3.ok b/test/pnmcrop3.ok
index 6824143a..5a86139c 100644
--- a/test/pnmcrop3.ok
+++ b/test/pnmcrop3.ok
@@ -86,5 +86,5 @@ P1
 1111111111111
 -3 -1 -1 -1 9 13
 544280424 101484
-4294967295 0
-4294967295 0
+Expected failure 1 1
+Expected failure 2 1
diff --git a/test/pnmcrop3.test b/test/pnmcrop3.test
index c46fd7ea..04cf6f52 100755
--- a/test/pnmcrop3.test
+++ b/test/pnmcrop3.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmcrop
 # Also requires: pnmpad pamfile pgmmake
 
@@ -16,7 +16,7 @@ pnmpad -top=11 -bottom=1 -left=21 -right=9 testimg.ppm > ${test_ppm}
 pnmpad -top=4 -bottom=4 -left=8 -right=5 testgrid.pbm > ${border_pbm}
 pnmpad -top=7 -bottom=5 -left=30 -right=0 testimg.ppm > ${border_ppm}
 
-pgmmake 0.5 `pamfile -size ${test_pbm}` > ${gray_pgm}
+pgmmake 0.5 $(pamfile -size ${test_pbm}) > ${gray_pgm}
 
 # Test 1
 echo Test 1
@@ -38,7 +38,7 @@ echo Test 2
 for input_file in ${test_pbm} ${test_ppm}
   do
   echo `basename ${input_file}`
-  for margin in `seq 0 5`
+  for margin in 0 1 2 3 4 5  # for margin in `seq 0 5`
     do
     pnmcrop -reportsize -margin=${margin} ${input_file} || echo fail2
     done
@@ -59,13 +59,22 @@ pnmcrop -borderfile=${border_pbm} ${test_pbm} | pnmcrop -black -reportsize
 
 pnmcrop -borderfile=${border_ppm} ${test_ppm} | cksum 
 
-# The following two cases are expected to fai
+test_out=${tmpdir}/test_out
 
+# The following two cases are expected to fail
+
+echo "Border file size mismatch" 1>&2
 echo "Error messages should appear below the line." 1>&2
 echo "--------------------------------------------" 1>&2
 
-pnmcrop -borderfile=${border_ppm} ${test_pbm} | cksum 
-pnmcrop -borderfile=${border_pbm} ${test_ppm} | cksum 
+pnmcrop -borderfile=${border_ppm} ${test_pbm} > ${test_out} || \
+        echo -n "Expected failure 1";
+        test -s ${test_out}; echo " "$?
+        rm ${test_out}
 
+pnmcrop -borderfile=${border_pbm} ${test_ppm} > ${test_out} || \
+        echo -n "Expected failure 2";
+        test -s ${test_out}; echo " "$?
+        rm ${test_out}
 
-rm ${test_pbm} ${test_ppm} ${border_pbm} ${border_ppm} ${gray_pgm}
\ No newline at end of file
+rm ${test_pbm} ${test_ppm} ${border_pbm} ${border_ppm} ${gray_pgm}
diff --git a/test/pnminvert-roundtrip.test b/test/pnminvert-roundtrip.test
index ddc5dc5d..c0f702c2 100755
--- a/test/pnminvert-roundtrip.test
+++ b/test/pnminvert-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnminvert
 # Also requires:
 
diff --git a/test/pnminvert.test b/test/pnminvert.test
index 68a4e066..d2789bdf 100755
--- a/test/pnminvert.test
+++ b/test/pnminvert.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnminvert
 # Also requires: pbmmake pamchannel pamtopnm
 
diff --git a/test/pnmpad-reportonly.ok b/test/pnmpad-reportonly.ok
new file mode 100644
index 00000000..e7d0a0d1
--- /dev/null
+++ b/test/pnmpad-reportonly.ok
@@ -0,0 +1,67 @@
+Test 1.  Should print 0 0 0 0 227 149 six times
+0 0 0 0 227 149
+0 0 0 0 227 149
+0 0 0 0 227 149
+0 0 0 0 227 149
+0 0 0 0 227 149
+0 0 0 0 227 149
+Test 2.  Should print 10 0 0 0 110 17 seven times
+10 0 0 0 110 17
+10 0 0 0 110 17
+10 0 0 0 110 17
+10 0 0 0 110 17
+10 0 0 0 110 17
+10 0 0 0 110 17
+10 0 0 0 110 17
+Test 3.  Should print 0 10 0 0 110 19 eight times
+0 10 0 0 110 19
+0 10 0 0 110 19
+0 10 0 0 110 19
+0 10 0 0 110 19
+0 10 0 0 110 19
+0 10 0 0 110 19
+0 10 0 0 110 19
+0 10 0 0 110 19
+Test 4.  Should print 10 10 0 0 120 19 four times
+10 10 0 0 120 19
+10 10 0 0 120 19
+10 10 0 0 120 19
+10 10 0 0 120 19
+Test 5.  Should print 0 0 10 0 27 110 seven times
+0 0 10 0 27 110
+0 0 10 0 27 110
+0 0 10 0 27 110
+0 0 10 0 27 110
+0 0 10 0 27 110
+0 0 10 0 27 110
+0 0 10 0 27 110
+Test 6.  Should print 0 0 0 10 19 110 eight times
+0 0 0 10 19 110
+0 0 0 10 19 110
+0 0 0 10 19 110
+0 0 0 10 19 110
+0 0 0 10 19 110
+0 0 0 10 19 110
+0 0 0 10 19 110
+0 0 0 10 19 110
+Test 7.  Should print 0 0 12 12 27 124 four times
+0 0 12 12 27 124
+0 0 12 12 27 124
+0 0 12 12 27 124
+0 0 12 12 27 124
+Test 8.  Should print 5 10 0 0 115 17 seven times
+5 10 0 0 115 17
+5 10 0 0 115 17
+5 10 0 0 115 17
+5 10 0 0 115 17
+5 10 0 0 115 17
+5 10 0 0 115 17
+5 10 0 0 115 17
+Test 9.  Should print 0 0 4 8 19 112 seven times
+0 0 4 8 19 112
+0 0 4 8 19 112
+0 0 4 8 19 112
+0 0 4 8 19 112
+0 0 4 8 19 112
+0 0 4 8 19 112
+0 0 4 8 19 112
diff --git a/test/pnmpad-reportonly.test b/test/pnmpad-reportonly.test
new file mode 100755
index 00000000..ccd79e69
--- /dev/null
+++ b/test/pnmpad-reportonly.test
@@ -0,0 +1,129 @@
+#! /bin/sh
+# This script tests: pnmpad
+# Also requires: pbmmake pgmmake ppmmake pamfile
+
+tmpdir=${tmpdir:-/tmp}
+
+test1_pbm=${tmpdir}/test1.pbm
+test2_pbm=${tmpdir}/test2.pbm
+test_pgm=${tmpdir}/test.pgm
+test_ppm=${tmpdir}/test.ppm
+
+testimg_size=$(pamfile -size testimg.ppm) 
+
+echo "Test 1.  Should print 0 0 0 0 ${testimg_size} six times" 
+
+for pad in "" "-left=0" "-right=0" "-top=0" "-bottom=0" \
+           "-left=0 -right=0 -top=0 -bottom=0"
+  do
+  pnmpad -reportonly ${pad} testimg.ppm || echo "failure"
+  done
+
+
+echo "Test 2.  Should print 10 0 0 0 110 17 seven times" 
+ 
+pbmmake -w 100 17 > ${test1_pbm}
+for pad in "-left=10" \
+           "-left=10 -right=0" \
+           "-left=10 -width=90" \
+           "-left=10 -width=105" \
+           "-left=10 -width=110" \
+           "-right=0 -width=110" \
+           "-halign=1.0 -width=110"
+  do
+  pnmpad -reportonly ${pad} ${test1_pbm} || echo "failure"
+  done
+
+
+echo "Test 3.  Should print 0 10 0 0 110 19 eight times" 
+pgmmake 0.5 100 19 > ${test_pgm}
+for pad in "-right=10" \
+           "-right=10 -left=0" \
+           "-right=10 -width=90" \
+           "-right=10 -width=105" \
+           "-right=10 -width=110" \
+           "-left=0 -width=110" \
+           "-halign=0.0 -width=110" \
+           "-right=1 -mwidth=11"
+  do
+  pnmpad -reportonly ${pad} ${test_pgm} || echo "failure"
+  done
+
+
+echo "Test 4.  Should print 10 10 0 0 120 19 four times" 
+for pad in "-left=10 -right=10" \
+           "-right=10 -width=120" \
+           "-halign=0.5 -width=120" \
+           "-left=1 -right=1 -mwidth=30"
+  do
+  pnmpad -reportonly ${pad} ${test_pgm} || echo "failure"
+  done
+
+
+echo "Test 5.  Should print 0 0 10 0 27 110 seven times" 
+ 
+pbmmake -w 27 100 > ${test2_pbm}
+for pad in "-top=10" \
+           "-top=10 -bottom=0" \
+           "-top=10 -height=50" \
+           "-top=10 -height=101" \
+           "-top=10 -height=110" \
+           "-bottom=0 -height=110" \
+           "-valign=1.0 -height=110"
+  do
+  pnmpad -reportonly ${pad} ${test2_pbm} || echo "failure"
+  done
+
+
+echo "Test 6.  Should print 0 0 0 10 19 110 eight times" 
+ppmmake rgb:33/44/55 19 100 > ${test_ppm}
+for pad in "-bottom=10" \
+           "-bottom=10 -top=0" \
+           "-bottom=10 -height=10" \
+           "-bottom=10 -height=107" \
+           "-bottom=10 -height=110" \
+           "-top=0 -height=110" \
+           "-valign=0.0 -height=110" \
+           "-bottom=1 -mheight=10"
+  do
+  pnmpad -reportonly ${pad} ${test_ppm} || echo "failure"
+  done
+
+
+echo "Test 7.  Should print 0 0 12 12 27 124 four times" 
+for pad in "-top=12 -bottom=12" \
+           "-top=12 -height=124" \
+           "-valign=0.5 -height=124" \
+           "-top=11 -bottom=11 -mheight=4"
+  do
+  pnmpad -reportonly ${pad} ${test2_pbm} || echo "failure"
+  done
+
+
+echo "Test 8.  Should print 5 10 0 0 115 17 seven times"
+for pad in "-l 5 -r 10 -w 115" \
+           "-l 5       -w 115" \
+           "     -r 10 -w 115" \
+           "-l 5 -r 10       " \
+           "-halign 0.333 -w 115 " \
+           "-l 2 -r 4 -mw 23" \
+           "-halign 0.333 -mw 23"
+  do
+  pnmpad -reportonly ${pad} ${test1_pbm} || echo "failure"
+  done
+
+
+echo "Test 9.  Should print 0 0 4 8 19 112 seven times"
+for pad in "-t 4 -b 8 -h 112" \
+           "-t 4      -h 112" \
+           "     -b 8 -h 112" \
+           "-t 4 -b 8       " \
+           "-t 4 -b 8 -mh 14" \
+           "-valign 0.333 -mh 14" \
+           "-valign 0.333 -h 112"
+  do
+  pnmpad -reportonly ${pad} ${test_ppm} || echo "failure"
+  done
+
+
+rm ${test1_pbm} ${test2_pbm} ${test_pgm} ${test_ppm}
diff --git a/test/pnmpaste-pbm.test b/test/pnmpaste-pbm.test
index b75797af..70f2b266 100755
--- a/test/pnmpaste-pbm.test
+++ b/test/pnmpaste-pbm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmpaste
 # Also requires: pbmmake
 
diff --git a/test/pnmpsnr.test b/test/pnmpsnr.test
index 2de7fc95..3223f86d 100755
--- a/test/pnmpsnr.test
+++ b/test/pnmpsnr.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmpsnr
 # Also requires: pbmmake
 
diff --git a/test/pnmquant.test b/test/pnmquant.test
index 24cee077..100fb52e 100755
--- a/test/pnmquant.test
+++ b/test/pnmquant.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmquant
 # Also requires: ppmhist
 
diff --git a/test/pnmquantall.test b/test/pnmquantall.test
index 4c1bb77f..fb3beebb 100755
--- a/test/pnmquantall.test
+++ b/test/pnmquantall.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmquantall
 # Also requires: ppmtorgb3 pgmhist pnmcat
 
diff --git a/test/pnmremap1.test b/test/pnmremap1.test
index b1cdd6d9..fcd382a7 100755
--- a/test/pnmremap1.test
+++ b/test/pnmremap1.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmremap
 # Also requires: pamseq pamtopnm
 
diff --git a/test/pnmremap2.test b/test/pnmremap2.test
index 76c2d566..7eea2c4a 100755
--- a/test/pnmremap2.test
+++ b/test/pnmremap2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmremap
 # Also requires: pamdepth pamseq pamtopnm
 
diff --git a/test/pnmshear.test b/test/pnmshear.test
index a19a9852..42e5c816 100755
--- a/test/pnmshear.test
+++ b/test/pnmshear.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmshear
 # Also requires: pbmmake pnmpad
 
diff --git a/test/pnmtopnm-plain.ok b/test/pnmtopnm-plain.ok
index 02d99f1e..640f0964 100644
--- a/test/pnmtopnm-plain.ok
+++ b/test/pnmtopnm-plain.ok
@@ -1,48 +1,51 @@
+Test.  Should print three identical images in plain format, twice each
 P1
-14 16
-10101010101010
-11111111111111
-10101010101010
-11111111111111
-10101010101010
-11111111111111
-10101010101010
-11111111111111
-10101010101010
-11111111111111
-10101010101010
-11111111111111
-10101010101010
-11111111111111
-10101010101010
-11111111111111
+5 5
+01010
+10101
+01010
+10101
+01010
+P1
+5 5
+01010
+10101
+01010
+10101
+01010
+P2
+8 8
+7
+0 0 1 1 2 2 3 3
+0 1 1 2 2 3 3 4
+1 1 2 2 3 3 4 4
+1 2 2 3 3 4 4 5
+2 2 3 3 4 4 5 5
+2 3 3 4 4 5 5 6
+3 3 4 4 5 5 6 6
+3 4 4 5 5 6 6 7
 P2
-14 16
+8 8
+7
+0 0 1 1 2 2 3 3 
+0 1 1 2 2 3 3 4 
+1 1 2 2 3 3 4 4 
+1 2 2 3 3 4 4 5 
+2 2 3 3 4 4 5 5 
+2 3 3 4 4 5 5 6 
+3 3 4 4 5 5 6 6 
+3 4 4 5 5 6 6 7 
+P3
+4 4
 255
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 255 0 255 0 255 0 255 0 255 0 255 0 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 
+0 31 255  0 31 255  63 0 0  0 31 255
+0 31 255  0 31 255  0 31 255  63 0 0
+0 31 255  63 0 0  63 0 0  63 0 0
+63 0 0  0 31 255  63 0 0  63 0 0
 P3
-14 16
+4 4
 255
-0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 
-0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 
-0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
+0 31 255 0 31 255 63 0 0 0 31 255 
+0 31 255 0 31 255 0 31 255 63 0 0 
+0 31 255 63 0 0 63 0 0 63 0 0 
+63 0 0 0 31 255 63 0 0 63 0 0 
diff --git a/test/pnmtopnm-plain.test b/test/pnmtopnm-plain.test
index 5b7e4b48..87b74064 100755
--- a/test/pnmtopnm-plain.test
+++ b/test/pnmtopnm-plain.test
@@ -1,10 +1,14 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtopnm
-# Also requires: pgmtopgm ppmtoppm
+# Also requires: pbmmake pgmramp ppmpat
 
-pamtopnm -plain testgrid.pbm
+echo "Test.  Should print three identical images in plain format, twice each"
 
-pgmtopgm < testgrid.pbm | pamtopnm -plain
+pbmmake -g 5 5 -plain
+pbmmake -g 5 5 | pamtopnm -plain
 
-ppmtoppm < testgrid.pbm | pamtopnm -plain | \
-  head -n11
+pgmramp -maxval 7 -diag 8 8 -plain
+pgmramp -maxval 7 -diag 8 8 | pamtopnm -plain
+
+ppmpat -g2 -color=rgb:00/1f/ff,rgb:3f/00/00 -mesh 4 4 -plain
+ppmpat -g2 -color=rgb:00/1f/ff,rgb:3f/00/00 -mesh 4 4 | pamtopnm -plain
diff --git a/test/ppmbrighten.test b/test/ppmbrighten.test
index 29ec78fb..e346d1d0 100755
--- a/test/ppmbrighten.test
+++ b/test/ppmbrighten.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmbrighten
 # Also requires: pnmnorm pambrighten pamsumm 
 
diff --git a/test/ppmchange-roundtrip.test b/test/ppmchange-roundtrip.test
index c1a35078..5bd18150 100755
--- a/test/ppmchange-roundtrip.test
+++ b/test/ppmchange-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmchange
 # Also requires: pgmtopbm pnminvert ppmtopgm
 
diff --git a/test/ppmchange.test b/test/ppmchange.test
index a749a5d2..a579631b 100755
--- a/test/ppmchange.test
+++ b/test/ppmchange.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmchange
 # Also requires: ppmrainbow pgmramp ppmhist
 
diff --git a/test/ppmcie.test b/test/ppmcie.test
index 0ce69dea..dd7f121f 100755
--- a/test/ppmcie.test
+++ b/test/ppmcie.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmcie
 # Also requires: pamsumm pamsharpness
 
diff --git a/test/ppmdfont.test b/test/ppmdfont.test
index 7d894789..e6b461f1 100755
--- a/test/ppmdfont.test
+++ b/test/ppmdfont.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmdmkfont ppmddumpfont ppmdcfont
 # Also requires:
 
diff --git a/test/ppmdim.test b/test/ppmdim.test
index 848e2e9f..48d9e891 100755
--- a/test/ppmdim.test
+++ b/test/ppmdim.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmdim
 # Also requires: pamfunc pamarith pamsumm
 
diff --git a/test/ppmdither.test b/test/ppmdither.test
index 7e32ef59..f82c34ff 100755
--- a/test/ppmdither.test
+++ b/test/ppmdither.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmdither
 # Also requires:
 
diff --git a/test/ppmforge-parameters.test b/test/ppmforge-parameters.test
index efc846a8..83758213 100755
--- a/test/ppmforge-parameters.test
+++ b/test/ppmforge-parameters.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmforge
 # Also requires: pamfile
 
diff --git a/test/ppmforge.test b/test/ppmforge.test
index 959eb360..e83ad553 100755
--- a/test/ppmforge.test
+++ b/test/ppmforge.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmforge
 # Also requires: pnmpsnr
 
diff --git a/test/ppmhist.test b/test/ppmhist.test
index b5812503..34eb0ea0 100755
--- a/test/ppmhist.test
+++ b/test/ppmhist.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmhist
 # Also requires: pgmramp pamtopnm pbmmake pamseq ppmpat
 
diff --git a/test/ppmmake.test b/test/ppmmake.test
index 26b592f7..714573b2 100755
--- a/test/ppmmake.test
+++ b/test/ppmmake.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmmake
 # Also requires:
 
diff --git a/test/ppmmix.test b/test/ppmmix.test
index e1c6486b..c3900baf 100755
--- a/test/ppmmix.test
+++ b/test/ppmmix.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmmix
 # Also requires: pamdepth pamenlarge pamsumm pbmmake
 # Also requires: pgmtopgm pnminvert ppmtopgm
diff --git a/test/ppmpat-random.test b/test/ppmpat-random.test
index 44dd2485..b1b78d94 100755
--- a/test/ppmpat-random.test
+++ b/test/ppmpat-random.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmpat
 # Also requires:
 
diff --git a/test/ppmpat.test b/test/ppmpat.test
index 6e916944..8f00b9f5 100755
--- a/test/ppmpat.test
+++ b/test/ppmpat.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmpat
 # Also requires:
 
diff --git a/test/ppmrelief.test b/test/ppmrelief.test
index 3467dcde..c7241663 100755
--- a/test/ppmrelief.test
+++ b/test/ppmrelief.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmrelief
 # Also requires: pbmmake pgmramp pamflip
 
diff --git a/test/ppmrough.test b/test/ppmrough.test
index bd4211a3..b10ba941 100755
--- a/test/ppmrough.test
+++ b/test/ppmrough.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmrough
 # Also requires:
 
diff --git a/test/ppmshift.ok b/test/ppmshift.ok
index e18de8f0..735ac445 100755
--- a/test/ppmshift.ok
+++ b/test/ppmshift.ok
@@ -2,13 +2,22 @@ Test 1. Should print: 3705777303 101484
 3705777303 101484
 Test 2. Should print: 202790723 685
 202790723 685
-Test 3. Should print: 0 : 0
-0 : 0
-Test 4. (15) Should print: 0 : 0
-0 : 0
-Test 4. (16) Should print: 0 : 0
-0 : 0
-Test 4. (20) Should print: 0 : 0
-0 : 0
-Test 4. (1000) Should print: 0 : 0
-0 : 0
+Test 3. Should print: 0 0 : 0
+0 0 : 0
+Test 4.  Should print: 0 0 : 0
+0 0 : 0
+Test 5. (1) Should print: 1 twice
+1
+1
+Test 5. (15) Should print: 1 twice
+1
+1
+Test 5. (16) Should print: 1 twice
+1
+1
+Test 5. (20) Should print: 1 twice
+1
+1
+Test 5. (1000) Should print: 1 twice
+1
+1
diff --git a/test/ppmshift.test b/test/ppmshift.test
index cd086d68..fff193b3 100755
--- a/test/ppmshift.test
+++ b/test/ppmshift.test
@@ -1,6 +1,6 @@
 #! /bin/bash
 # This script tests: ppmshift
-# Also requires:
+# Also requires: pgmtoppm
 
 echo "Test 1. Should print: 3705777303 101484"
 ppmshift -seed=1 10 testimg.ppm | cksum
@@ -8,20 +8,35 @@ ppmshift -seed=1 10 testimg.ppm | cksum
 echo "Test 2. Should print: 202790723 685"
 ppmshift -seed=1 1 testgrid.pbm | cksum
 
-echo "Test 3. Should print: 0 : 0"
-ppmshift -seed=1 0 testimg.ppm | cmp -s - testimg.ppm | \
+echo "Test 3. Should print: 0 0 : 0"
+ppmshift -seed=1 0 testimg.ppm | cmp -s - testimg.ppm
   echo ${PIPESTATUS[@]} ":" $?
 
 tmpdir=${tmpdir:-/tmp}
-test_pbm=${tmpdir}/test.pbm
+test0_ppm=${tmpdir}/test0.ppm
+test14_ppm=${tmpdir}/test14.ppm
 
-ppmshift -seed=2 14 testgrid.pbm > ${test_pbm}
+pgmtoppm < maze.pbm > ${test0_ppm}
 
-for i in 15 16 20 1000
-  do
-  echo "Test 4. ("$i") Should print: 0 : 0"
-  ppmshift -seed=2 $i testgrid.pbm > ${test_pbm} | cmp -s - testgrid.ppm | \
+echo "Test 4.  Should print: 0 0 : 0"
+  ppmshift -seed=2 0 maze.pbm | cmp -s - ${test0_ppm}
     echo ${PIPESTATUS[@]} ":" $?
+
+ppmshift -seed=2 14 maze.pbm > ${test14_ppm}
+
+for i in 1 15 16 20 1000
+  do
+  echo "Test 5. ("$i") Should print: 1 twice"
+  ppmshift -seed=2 $i maze.pbm | cmp -s - ${test0_ppm}
+    echo $?
+  ppmshift -seed=2 $i maze.pbm | cmp -s - ${test14_ppm}
+    echo $?
   done
 
-rm ${test_pbm}
\ No newline at end of file
+# In Test 5 the image files are not supposed to match.
+# When cmp finds a difference, it may terminate and stop reading input from
+# the pipe at that point.  This may cause a "broken pipe" exception; however
+# this does not always happen.  The broken pipe shows up as a non-zero value
+# for ${PIPESTATUS[0]}.
+
+rm ${test0_ppm} ${test14_ppm}
diff --git a/test/ppmspread.ok b/test/ppmspread.ok
index 7d44ab8e..40f44465 100755
--- a/test/ppmspread.ok
+++ b/test/ppmspread.ok
@@ -1,6 +1,12 @@
-Test 1. Should print 639729144 101484
+Test 1.
+stdin: PPM RAW 227 149 3 255 RGB
+stdin: PPM RAW 227 149 3 255 RGB
+Test 2.
+57 59
+57 59
+Test 3. Should print 281226646 481
+281226646 481
+Test 4. Should print 639729144 101484
 639729144 101484
-Test 2. Should print 3278353642 685
+Test 5. Should print 3278353642 685
 3278353642 685
-Test 3. Should print 2425386270 41
-2425386270 41
diff --git a/test/ppmspread.test b/test/ppmspread.test
index 871f7438..d7e0fb37 100755
--- a/test/ppmspread.test
+++ b/test/ppmspread.test
@@ -1,12 +1,28 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmspread
-# Also requires: ppmtopgm pgmtopbm
+# Also requires: pamfile ppmtopgm pgmtopbm
 
-echo "Test 1. Should print 639729144 101484"
+# Input/output size does not change
+
+echo "Test 1."
+cat testimg.ppm | pamfile -machine
+ppmspread -randomseed=100 20 testimg.ppm | pamfile -machine
+
+echo "Test 2."
+pamfile -size maze.pbm
+ppmspread -randomseed=100 20 maze.pbm | pamfile -size
+
+# No change when spread distance value is 0
+
+echo "Test 3. Should print 281226646 481"
+ppmspread -randomseed=1 0 maze.pbm | ppmtopgm | pgmtopbm | cksum
+
+# The following tests will fail when changes are made to the random
+# number generator
+
+echo "Test 4. Should print 639729144 101484"
 ppmspread -randomseed=1 10 testimg.ppm | cksum
 
-echo "Test 2. Should print 3278353642 685"
+echo "Test 5. Should print 3278353642 685"
 ppmspread -randomseed=1 1 testgrid.pbm | cksum
 
-echo "Test 3. Should print 2425386270 41"
-ppmspread -randomseed=1 0 testgrid.pbm | ppmtopgm | pgmtopbm | cksum
diff --git a/test/ppmtoapplevol.ok b/test/ppmtoapplevol.ok
new file mode 100644
index 00000000..46acda60
--- /dev/null
+++ b/test/ppmtoapplevol.ok
@@ -0,0 +1,6 @@
+Test: should print 1518149010 3065
+1518149010 3065
+Test Invalid
+Expected failure 1 1
+Expected failure 2 1
+Expected failure 3 1
diff --git a/test/ppmtoapplevol.test b/test/ppmtoapplevol.test
new file mode 100755
index 00000000..6b109251
--- /dev/null
+++ b/test/ppmtoapplevol.test
@@ -0,0 +1,30 @@
+#! /bin/sh
+# This script tests: ppmtoapplevol 
+# Also requires: ppmmake pbmmake
+
+echo "Test: should print 1518149010 3065"
+ppmmake rgb:0/0/0 255 12 | ppmtoapplevol | cksum
+
+echo "Invalid input." 1>&2
+echo "Error messages should appear below the line." 1>&2
+echo "-----------------------------------------------------------" 1>&2
+
+echo "Test Invalid"
+
+tmpdir=${tmpdir:-/tmp}
+test_out=${tmpdir}/test_out
+
+pbmmake 10 11 | ppmtoapplevol > ${test_out} || \
+  echo -n "Expected failure 1"
+  test -s ${test_out}; echo " "$?
+  rm -f ${test_out}
+ 
+pbmmake 10 13 | ppmtoapplevol > ${test_out} || \
+  echo -n "Expected failure 2"
+  test -s ${test_out}; echo " "$?
+  rm -f ${test_out}
+ 
+pbmmake 256 12 | ppmtoapplevol > ${test_out} || \
+  echo -n "Expected failure 3"
+  test -s ${test_out}; echo " "$?
+  rm -f ${test_out}
diff --git a/test/ppmtoarbtxt-roundtrip.test b/test/ppmtoarbtxt-roundtrip.test
index 7c64114e..f63aabe2 100755
--- a/test/ppmtoarbtxt-roundtrip.test
+++ b/test/ppmtoarbtxt-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtoarbtxt
 # Also requires: pnminvert pamtopnm
 
diff --git a/test/ppmtopgm.test b/test/ppmtopgm.test
index 8503194b..696b660c 100755
--- a/test/ppmtopgm.test
+++ b/test/ppmtopgm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtopgm
 # Also requires:
 
diff --git a/test/ppmtoppm.test b/test/ppmtoppm.test
index 411c17f6..90ff2ddf 100755
--- a/test/ppmtoppm.test
+++ b/test/ppmtoppm.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtoppm
 # Also requires: pbmmake pgmramp
 
diff --git a/test/ppmwheel.test b/test/ppmwheel.test
index 150a75e5..fc390f26 100755
--- a/test/ppmwheel.test
+++ b/test/ppmwheel.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmwheel
 # Also requires:
 
diff --git a/test/ps-alt-roundtrip.test b/test/ps-alt-roundtrip.test
index 07081d3a..bdecaffd 100755
--- a/test/ps-alt-roundtrip.test
+++ b/test/ps-alt-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtoepsi pbmtopsg3 psidtopgm pstopnm
 # Also requires: gs pnmcrop
 
diff --git a/test/ps-flate-roundtrip.test b/test/ps-flate-roundtrip.test
index 888f2856..9fc24ddb 100755
--- a/test/ps-flate-roundtrip.test
+++ b/test/ps-flate-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtops pstopnm
 # Also requires: pamtopnm gs zlib
 
diff --git a/test/ps-roundtrip.test b/test/ps-roundtrip.test
index efce4fd6..8b107315 100755
--- a/test/ps-roundtrip.test
+++ b/test/ps-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtops pstopnm
 # Also requires: pamtopnm gs pbmmake pnmshear pnmpad pnmcat
 
diff --git a/test/random-generator.test b/test/random-generator.test
index 23dc1903..14b6f11a 100755
--- a/test/random-generator.test
+++ b/test/random-generator.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmnoise
 # Also requires:
 
diff --git a/test/sbig-roundtrip.test b/test/sbig-roundtrip.test
index 1fdaccfd..2611fa89 100755
--- a/test/sbig-roundtrip.test
+++ b/test/sbig-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmtosbig sbigtopgm
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/sgi-roundtrip.test b/test/sgi-roundtrip.test
index 073755d8..50a9fbc2 100755
--- a/test/sgi-roundtrip.test
+++ b/test/sgi-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtosgi sgitopnm
 # Also requires: rgb3toppm pamdepth pamtopnm pgmtopbm
 
diff --git a/test/st4-roundtrip.test b/test/st4-roundtrip.test
index ffe8f348..f2e15078 100755
--- a/test/st4-roundtrip.test
+++ b/test/st4-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmtost4 st4topgm
 # Also requires: pamchannel pamtopnm pamcut
 
diff --git a/test/stdin-pam1.ok b/test/stdin-pam1.ok
new file mode 100644
index 00000000..31f24b3d
--- /dev/null
+++ b/test/stdin-pam1.ok
@@ -0,0 +1,41 @@
+pamaddnoise -seed=1: 0 0 0 0
+pamaltsat -strength=1: 0 0 0 0
+pambackground: 0 0 0 0
+pambayer -type=2: 0 0 0 0
+pambrighten: 0 0 0 0
+pamcut: 0 0 0 0
+pamdeinterlace: 0 0 0 0
+pamdepth 15: 0 0 0 0
+pamditherbw -threshold: 0 0 0 0
+pamedge: 0 0 0 0
+pamexec cat: 0 0 0 0
+pamfile -size: 0 0 0 0
+pamfind -target=1: 0 0 0 0
+pamfix: 0 0 0 0
+pamflip -lr: 0 0 0 0
+pamfunc -not: 0 0 0 0
+pamhomography -from 0,0,0,1,1,0,1,1: 0 0 0 0
+pamhue -huechange=60: 0 0 0 0
+pamlevels -f1 rgb:0/0/0 -t1 rgb:0/0/0 -f2 rgb:ff/ff/ff -t2 rgb:ff/ff/ff: 0 0 0 0
+pammixinterlace: 0 0 0 0
+pammosaicknit: 0 0 0 0
+pamoil: 0 0 0 0
+pamperspective 0 0 0 1 1 0 1 1: 0 0 0 0
+pamrecolor: 0 0 0 0
+pamrubber -quad 1 1 2 2: 0 0 0 0
+pamscale 2: 0 0 0 0
+pamshadedrelief: 0 0 0 0
+pamsharpness: 0 0 0 0
+pamsistoaglyph: 0 0 0 0
+pamslice -row=1: 0 0 0 0
+pamstack: 0 0 0 0
+pamstereogram -randomseed=1: 0 0 0 0
+pamstretch 1: 0 0 0 0
+pamstretch-gen 1: 0 0 0 0
+pamsumm -max: 0 0 0 0
+pamsummcol -mean: 0 0 0 0
+pamtable: 0 0 0 0
+pamthreshold: 0 0 0 0
+pamtilt: 0 0 0 0
+pamtopnm: 0 0 0 0
+pamwipeout -tb: 0 0 0 0
diff --git a/test/stdin-pam1.test b/test/stdin-pam1.test
new file mode 100755
index 00000000..68d0d34c
--- /dev/null
+++ b/test/stdin-pam1.test
@@ -0,0 +1,72 @@
+#! /bin/bash
+# This script tests: pamaddnoise pamaltsat pambackground pambayer
+# This script tests: pambrighten pamcut pamdeinterlace pamdepth pamditherbw
+# This script tests: pamedge pamexec pamfile pamfind pamfix pamflip
+# This script tests: pamfunc pamhomography pamhue pamlevels
+# This script tests: pammixinterlace pammosaicknit pamoil
+# This script tests: pamperspective pamrecolor pamrubber pamscale
+# This script tests: pamshadedrelief pamsharpness pamsistoaglyph
+# This script tests: pamslice pamstack pamstereogram pamstretch
+# This script tests: pamstretch-gen pamsumm pamsummcol pamtable pamthreshold
+# This script tests: pamtilt pamtopnm pamwipeout
+# Also requires: pbmmake
+
+tmpdir=${tmpdir:-/tmp}
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+small_pbm=${tmpdir}/small.pbm
+
+pbmmake -g 5 5 > ${small_pbm}
+
+for testprog in \
+    "pamaddnoise -seed=1" \
+    "pamaltsat -strength=1" \
+    pambackground \
+    "pambayer -type=2" \
+    pambrighten \
+    pamcut \
+    pamdeinterlace \
+    "pamdepth 15" \
+    "pamditherbw -threshold" \
+    pamedge \
+    "pamexec cat" \
+    "pamfile -size" \
+    "pamfind -target=1" \
+    pamfix \
+    "pamflip -lr" \
+    "pamfunc -not" \
+    "pamhomography -from 0,0,0,1,1,0,1,1" \
+    "pamhue -huechange=60" \
+    "pamlevels -f1 rgb:0/0/0 -t1 rgb:0/0/0 -f2 rgb:ff/ff/ff -t2 rgb:ff/ff/ff" \
+    pammixinterlace \
+    pammosaicknit \
+    pamoil \
+    "pamperspective 0 0 0 1 1 0 1 1" \
+    pamrecolor \
+    "pamrubber -quad 1 1 2 2" \
+    "pamscale 2" \
+    pamshadedrelief \
+    pamsharpness \
+    pamsistoaglyph \
+    "pamslice -row=1" \
+    pamstack \
+    "pamstereogram -randomseed=1" \
+    "pamstretch 1" \
+    "pamstretch-gen 1" \
+    "pamsumm -max" \
+    "pamsummcol -mean" \
+    pamtable \
+    pamthreshold \
+    pamtilt \
+    pamtopnm \
+    "pamwipeout -tb"
+  do
+  ${testprog} ${small_pbm} > ${out1};      status1=$?
+  ${testprog} < ${small_pbm} > ${out2};    status2=$?
+  test -s ${out1};                         status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+  done
+
+rm ${small_pbm}
diff --git a/test/stdin-pam2.ok b/test/stdin-pam2.ok
new file mode 100644
index 00000000..dd3148e8
--- /dev/null
+++ b/test/stdin-pam2.ok
@@ -0,0 +1,5 @@
+pammasksharpen: 0 0 0 0
+pammixmulti: 0 0 0 0
+pamdice: 0 0 0 0
+pamlookup: 0 0 0 0
+pamunlookup: 0 0 0 0
diff --git a/test/stdin-pam2.test b/test/stdin-pam2.test
new file mode 100755
index 00000000..f47df604
--- /dev/null
+++ b/test/stdin-pam2.test
@@ -0,0 +1,70 @@
+#! /bin/bash
+# This script tests: pammasksharpen pammixmulti pamdice
+# This script tests: pamlookup pamunlookup
+# Also requires: pbmmake
+
+tmpdir=${tmpdir:-/tmp}
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+small_pbm=${tmpdir}/small.pbm
+
+pbmmake -g 3 3 > ${small_pbm}
+
+for testprog in \
+    pammasksharpen \
+    pammixmulti
+  do
+  ${testprog} ${small_pbm}   ${small_pbm} > ${out1};   status1=$?
+  ${testprog} ${small_pbm} < ${small_pbm} > ${out2};   status2=$?
+  test -s ${out1};                                     status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+done
+
+
+  dicestem=${tmpdir}/dice
+
+  testprog="pamdice -outstem=${dicestem}"
+  ${testprog} ${small_pbm};   status1=$?
+  cat ${dicestem}_*_*.pbm > ${out1}
+  rm ${dicestem}_*_*.pbm
+  ${testprog} < ${small_pbm}; status2=$?
+  cat ${dicestem}_*_*.pbm > ${out2}
+  rm ${dicestem}_*_*.pbm
+  test -s ${out1};            status3=$?
+  cmp -s ${out1} ${out2}
+  echo pamdice: ${status1} ${status2} ${status3} $?
+  # Do not use testprog, which contains a variable, in the above
+  # Same for pamlookup, pamunlookup
+  rm ${out1} ${out2}
+
+lookup_ppm=${tmpdir}/lookup.ppm
+
+cat > ${lookup_ppm} <<EOF
+P3
+2 1
+2
+0 0 0
+0 1 2
+EOF
+
+  testprog="pamlookup -lookupfile=${lookup_ppm}"
+  ${testprog}   ${small_pbm} > ${out1}; status1=$?
+  ${testprog} < ${small_pbm} > ${out2}; status2=$?
+  test -s ${out1};                      status3=$?
+  cmp -s ${out1} ${out2}
+  echo pamlookup": "${status1} ${status2} ${status3} $?
+  rm ${out2}
+
+  testprog="pamunlookup -lookupfile=${lookup_ppm}"
+  ${testprog}   ${out1} > ${out3}; status1=$?
+  ${testprog} < ${out1} > ${out4}; status2=$?
+  test -s ${out1};                 status3=$?
+  cmp -s ${out3} ${out4}
+  echo pamunlookup": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out3} ${out4}
+
+rm ${lookup_ppm} ${small_pbm}
diff --git a/test/stdin-pam3.ok b/test/stdin-pam3.ok
new file mode 100644
index 00000000..0ec9cf5d
--- /dev/null
+++ b/test/stdin-pam3.ok
@@ -0,0 +1,32 @@
+Test.  Should print (command): 0 0 0 0
+The following are exceptions: should print (command): 0 0 0 1
+pamtotga, pamtotiff
+
+pamtoavs: 0 0 0 0
+avstopam: 0 0 0 0
+pamtohdiff: 0 0 0 0
+hdifftopam: 0 0 0 0
+pamtojpeg2k: 0 0 0 0
+jpeg2ktopam: 0 0 0 0
+pamtopdbimg -fixedtime: 0 0 0 0
+pdbimgtopam: 0 0 0 0
+pamtopfm: 0 0 0 0
+pfmtopam: 0 0 0 0
+pamtopng: 0 0 0 0
+pngtopam: 0 0 0 0
+pamtosrf: 0 0 0 0
+srftopam: 0 0 0 0
+pamtosvg: 0 0 0 0
+svgtopam: 0 0 0 0
+pamtowinicon: 0 0 0 0
+winicontopam: 0 0 0 0
+pamtotga: 0 0 0 1
+tgatoppm: 0 0 0 0
+pamtoxvmini: 0 0 0 0
+xvminitoppm: 0 0 0 0
+pamtofits: 0 0 0 0
+fitstopnm: 0 0 0 0
+pamtogif: 0 0 0 0
+giftopnm: 0 0 0 0
+pamtotiff: 0 0 0 1
+tifftopnm: 0 0 0 0
diff --git a/test/stdin-pam3.test b/test/stdin-pam3.test
new file mode 100755
index 00000000..169bb5cd
--- /dev/null
+++ b/test/stdin-pam3.test
@@ -0,0 +1,73 @@
+#! /bin/sh
+# This script tests: pamtoavs avstopam
+# This script tests: pamtohdiff hdifftopam
+# This script tests: pamtojpeg2k jpeg2ktopam
+# This script tests: pamtopdbimg pdbimgtopam
+# This script tests: pamtopfm pfmtopam
+# This script tests: pamtopng pngtopam
+# This script tests: pamtosrf srftopam
+# This script tests: pamtosvg svgtopam
+# This script tests: pamtowinicon winicontopam
+# This script tests: pamtotga tgatoppm
+# This script tests: pamtoxvmini xvminitoppm
+# This script tests: pamtofits fitstopnm
+# This script tests: pamtogif giftopnm
+# This script tests: pamtotiff tifftopnm
+# Also requires: pgmmake
+
+tmpdir=${tmpdir:-/tmp}
+test_pgm=${tmpdir}/test.ppm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+
+pgmmake -maxval 3 0.25 32 32 > ${test_pgm}
+
+echo "Test.  Should print (command): 0 0 0 0"
+echo "The following are exceptions: should print (command): 0 0 0 1"
+echo "pamtotga, pamtotiff"
+echo
+
+for fmt in \
+    avs \
+    hdiff \
+    jpeg2k \
+    pdbimg \
+    pfm \
+    png \
+    srf \
+    svg \
+    winicon \
+    tga \
+    xvmini \
+    fits \
+    gif \
+    tiff
+  do
+
+  if [ ${fmt} = pdbimg ]
+      then testprog1="pamtopdbimg -fixedtime";
+      else testprog1="pamto"${fmt};
+  fi
+
+  case $fmt in
+      "tga" | "xvmini")        testprog2=${fmt}"toppm";;
+      "fits" | "gif" | "tiff") testprog2=${fmt}"topnm";;
+      *) testprog2=${fmt}"topam";
+  esac
+
+  ${testprog1} ${test_pgm} > ${out1};      status1=$?
+  ${testprog1} < ${test_pgm} > ${out2};    status2=$?
+  test -s ${out1};                         status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog1}": "${status1} ${status2} ${status3} $?
+
+  ${testprog2} ${out1} > ${out3};      status4=$?
+  ${testprog2} < ${out1} > ${out4};    status5=$?
+  test -s ${out3};                     status6=$?
+  cmp -s ${out3} ${out4}
+  echo ${testprog2}": "${status4} ${status5} ${status6} $?
+  done
+
+rm ${test_pgm}
diff --git a/test/stdin-pbm1.ok b/test/stdin-pbm1.ok
new file mode 100644
index 00000000..0dd83466
--- /dev/null
+++ b/test/stdin-pbm1.ok
@@ -0,0 +1,9 @@
+pbmclean: 0 0 0 0
+pbmlife: 0 0 0 0
+pbmmask: 0 0 0 0
+pbmminkowski: 0 0 0 0
+pbmtoepsi: 0 0 0 0
+pbmtopsg3: 0 0 0 0
+pbmpscale 1 : 0 0 0 0
+pbmreduce -threshold 2 : 0 0 0 0
+pbmtopgm 2 2 : 0 0 0 0
diff --git a/test/stdin-pbm1.test b/test/stdin-pbm1.test
new file mode 100755
index 00000000..4e99ba0b
--- /dev/null
+++ b/test/stdin-pbm1.test
@@ -0,0 +1,45 @@
+#! /bin/sh
+# This script tests: pbmclean pbmlife pbmmask pbmminkowski pbmtoepsi
+# This script tests: pbmtopsg3 pbmpscale pbmreduce pbmtopgm
+# Also requires: pbmmake
+
+# Tests whether output is unchanged when
+# (1) input is a named file: pbm-command input-file
+# (2) input is from stdin:   pbm-command < input-file
+
+tmpdir=${tmpdir:-/tmp}
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+small_pbm=${tmpdir}/small.pbm
+
+pbmmake -b 3 3 > ${small_pbm}
+
+for testprog in \
+        pbmclean \
+        pbmlife \
+        pbmmask \
+        pbmminkowski \
+        pbmtoepsi \
+        pbmtopsg3 \
+        "pbmpscale 1 " \
+        "pbmreduce -threshold 2 " \
+        "pbmtopgm 2 2 "
+  do
+  ${testprog} ${small_pbm} > ${out1};      status1=$?
+  ${testprog} < ${small_pbm} > ${out2};    status2=$?
+  test -s ${out1};                         status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+  done
+
+rm ${small_pbm}
+
+# For Pbm converters not tested here see pbm-misc-converters.test
+
+# These programs do not have a converter in the opposite direction:
+# Brushtopbm
+# Ddbugtopbm
+# Thinkjettopbm (?)
diff --git a/test/stdin-pbm2.ok b/test/stdin-pbm2.ok
new file mode 100644
index 00000000..c77f7b13
--- /dev/null
+++ b/test/stdin-pbm2.ok
@@ -0,0 +1,28 @@
+pbmtoatk: 0 0 0 0
+atktopbm: 0 0 0 0
+pbmtocis: 0 0 0 0
+cistopbm: 0 0 0 0
+pbmtocmuwm: 0 0 0 0
+cmuwmtopbm: 0 0 0 0
+pbmtoescp2: 0 0 0 0
+escp2topbm: 0 0 0 0
+pbmtog3: 0 0 0 0
+g3topbm: 0 0 0 0
+pbmtogem: 0 0 0 0
+gemtopnm: 0 0 0 0
+pbmtomacp: 0 0 0 0
+macptopbm: 0 0 0 0
+pbmtomda: 0 0 0 0
+mdatopbm: 0 0 0 0
+pbmtomgr: 0 0 0 0
+mgrtopbm: 0 0 0 0
+pbmtomrf: 0 0 0 0
+mrftopbm: 0 0 0 0
+pbmtopi3: 0 0 0 0
+pi3topbm: 0 0 0 0
+pbmtosunicon: 0 0 0 0
+sunicontopnm: 0 0 0 0
+pbmtowbmp: 0 0 0 0
+wbmptopbm: 0 0 0 0
+pbmtoybm: 0 0 0 0
+ybmtopbm: 0 0 0 0
diff --git a/test/stdin-pbm2.test b/test/stdin-pbm2.test
new file mode 100755
index 00000000..724a9934
--- /dev/null
+++ b/test/stdin-pbm2.test
@@ -0,0 +1,78 @@
+#! /bin/sh
+# This script tests: atktopbm pbmtoatk
+# This script tests: cistopbm pbmtocis
+# This script tests: cmuwmtopbm pbmtocmuwm
+# This script tests: escp2topbm pbmtoescp2
+# This script tests: g3topbm pbmtog3
+# This script tests: gemtopbm pbmtogem
+# This script tests: macptopbm pbmtomacp
+# This script tests: mdatopbm pbmtomda
+# This script tests: mgrtopbm pbmtomgr
+# This script tests: mrftopbm pbmtomrf
+# This script tests: pi3topbm pbmtopi3
+# This script tests: sunicontopbm pbmtosunicon
+# This script tests: wbmptopbm pbmtowbmp
+# This script tests: ybmtopbm pbmtoybm
+# Also requires:
+
+tmpdir=${tmpdir:-/tmp}
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+
+for fmt in  \
+        atk \
+        cis \
+        cmuwm \
+        escp2 \
+        g3 \
+        gem \
+        macp \
+        mda \
+        mgr \
+        mrf \
+        pi3 \
+        sunicon \
+        wbmp \
+        ybm
+  do
+  testprog1="pbmto"${fmt}
+
+  if [ ${fmt} = "sunicon" -o ${fmt} = "gem" ];
+    then testprog2=${fmt}"topnm";
+    else testprog2=${fmt}"topbm";
+  fi
+
+  ${testprog1} testgrid.pbm > ${out1};     status1=$?
+  ${testprog1} < testgrid.pbm > ${out2};   status2=$?
+  test -s ${out1};                         status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog1}": "${status1} ${status2} ${status3} $?
+  rm ${out2}
+
+  ${testprog2} ${out1} > ${out3};      status3=$?
+  ${testprog2} < ${out1} > ${out4};    status4=$?
+
+  if [ ${fmt} = "xbm" ];
+    then sed -i '3s/noname/testgrid/' ${out3};
+  fi
+
+  test -s ${out3};                         status5=$?
+  cmp -s ${out3} ${out4}
+  echo ${testprog2}": "${status3} ${status4} ${status5} $?
+  rm ${out1} ${out3} ${out4}
+  done
+
+# We don't test Pbmtopgm Pgmtopbm Asciitopbm Asciitopgm here
+
+# Pbmtopk Pktopbm require resolution output pk file, tk file
+#            some conditions apply to input image dimensions
+
+# These three programs embed the input file name in the output
+# If the input is from stdin, "noname"
+# Pbmtolps tested in lps-roundtrip.test
+# Pbmtoxbm           xbm-roundtrip.test
+# Pbmtozinc          pbm-misc-converters.test
+
+# Icontopbm Pbmtoicon Pbmtox10bm are legacy
diff --git a/test/stdin-pgm1.ok b/test/stdin-pgm1.ok
new file mode 100644
index 00000000..b3159517
--- /dev/null
+++ b/test/stdin-pgm1.ok
@@ -0,0 +1,11 @@
+pgmabel: 0 0 0 0
+pgmbentley: 0 0 0 0
+pgmdeshadow: 0 0 0 0
+pgmenhance: 0 0 0 0
+pgmhist: 0 0 0 0
+pgmmedian: 0 0 0 0
+pgmminkowski: 0 0 0 0
+pgmtexture: 0 0 0 0
+pgmtopbm -th : 0 0 0 0
+pgmtoppm rgb:00/00/00 : 0 0 0 0
+rawtopgm -headerskip 11 3 3 : 0 0 0 0
diff --git a/test/stdin-pgm1.test b/test/stdin-pgm1.test
new file mode 100755
index 00000000..f5980cdc
--- /dev/null
+++ b/test/stdin-pgm1.test
@@ -0,0 +1,47 @@
+#! /bin/sh
+# This script tests: pgmabel pgmbentley pgmdeshadow pgmenhance pgmhist
+# This script tests: pgmmedian pgmminkowski pgmtexture pgmtopbm pgmtoppm
+# This script tests: rawtopgm
+# Also requires: pgmmake
+
+tmpdir=${tmpdir:-/tmp}
+small_pgm=${tmpdir}/small.pgm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+
+pgmmake 0.5 3 3 > ${small_pgm}
+
+for testprog in  \
+        pgmabel \
+        pgmbentley \
+        pgmdeshadow \
+        pgmenhance \
+        pgmhist \
+        pgmmedian \
+        pgmminkowski \
+        pgmtexture \
+        "pgmtopbm -th " \
+        "pgmtoppm rgb:00/00/00 " \
+	"rawtopgm -headerskip 11 3 3 "
+  do
+  ${testprog} ${small_pgm} > ${out1};      status1=$?
+  ${testprog} < ${small_pgm} > ${out2};    status2=$?
+  test -s ${out1};                         status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+  done
+
+rm ${small_pgm}
+
+
+# Pgmtopgm accepts input only from stdin
+
+# These three programs are legacy
+# Pgmedge
+# Pgmnorm
+# Pgmoil
+
+# Pgmmorphconv needs template file
diff --git a/test/stdin-pgm2.ok b/test/stdin-pgm2.ok
new file mode 100644
index 00000000..ee6d8082
--- /dev/null
+++ b/test/stdin-pgm2.ok
@@ -0,0 +1,6 @@
+pgmtofs : 0 0 0 0
+fstopgm : 0 0 0 0
+pgmtolispm : 0 0 0 0
+lispmtopgm : 0 0 0 0
+pgmtost4 : 0 0 0 0
+st4topgm : 0 0 0 0
diff --git a/test/stdin-pgm2.test b/test/stdin-pgm2.test
new file mode 100755
index 00000000..3a6220d8
--- /dev/null
+++ b/test/stdin-pgm2.test
@@ -0,0 +1,49 @@
+#! /bin/sh
+# This script tests: pgmtofs fstopgm
+# This script tests: pgmtolispm lispmtopgm
+# This script tests: pgmtost4 st4topgm
+# Also requires: pgmmake
+
+tmpdir=${tmpdir:-/tmp}
+test_pgm=${tmpdir}/test.pgm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+
+pgmmake 0.75 192 165 > ${test_pgm}
+
+for fmt in  \
+        fs \
+        lispm \
+	st4
+  do
+  testprog1="pgmto"${fmt}
+  testprog2=${fmt}"topgm"
+
+  ${testprog1} ${test_pgm} > ${out1};   status1=$?
+  ${testprog1} < ${test_pgm} > ${out2}; status2=$?
+  test -s ${out1};                      status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog1}" :" ${status1} ${status2} ${status3} $?
+  rm ${out2}
+
+  ${testprog2} ${out1} > ${out3};     status4=$?
+  ${testprog2} < ${out1} > ${out4};   status5=$?
+  test -s ${out3};                    status6=$?
+  cmp -s ${out3} ${out4}
+  echo ${testprog2}" :" ${status4} ${status5} ${status6} $?
+
+  rm ${out1} ${out3} ${out4}
+  done
+
+rm ${test_pgm}
+
+# pgmtost4 size must be 192 x 165
+
+# The following programs do not have converters in the opposite direction:
+# Bioradtopgm
+# Hipstopgm
+# Psidtopgm
+# Rawtopgm
+# Spottopgm
diff --git a/test/stdin-pnm1.ok b/test/stdin-pnm1.ok
new file mode 100644
index 00000000..0a63558c
--- /dev/null
+++ b/test/stdin-pnm1.ok
@@ -0,0 +1,23 @@
+pnmalias: 0 0 0 0
+pnmcat -lr : 0 0 0 0
+pnmcolormap all : 0 0 0 0
+pnmconvol -matrix=-1,3,-1 : 0 0 0 0
+pnmcrop: 0 0 0 0
+pnmgamma -ungamma 0.5 : 0 0 0 0
+pnmhisteq: 0 0 0 0
+pnmhistmap: 0 0 0 0
+pnminvert: 0 0 0 0
+pnmmargin 2 : 0 0 0 0
+pnmmercator: 0 0 0 0
+pnmmontage: 0 0 0 0
+pnmnlfilt 0.5 0.5 : 0 0 0 0
+pnmnorm: 0 0 0 0
+pnmpad: 0 0 0 0
+pnmquant 64 : 0 0 0 0
+pnmrotate 90 : 0 0 0 0
+pnmscalefixed 1 : 0 0 0 0
+pnmshear 45 : 0 0 0 0
+pnmsmooth: 0 0 0 0
+pnmtile 4 4 : 0 0 0 0
+pnmtoddif: 0 0 0 0
+pnmtopclxl -colorok : 0 0 0 0
diff --git a/test/stdin-pnm1.test b/test/stdin-pnm1.test
new file mode 100755
index 00000000..e692ceba
--- /dev/null
+++ b/test/stdin-pnm1.test
@@ -0,0 +1,60 @@
+#! /bin/sh
+# This script tests: pnmalias pnmcat pnmcolormap pnmconvol pnmcrop pnmgamma
+# This script tests: pnmhisteq pnmhistmap pnminvert pnmmargin pnmmercator
+# This script tests: pnmmontage pnmnlfilt pnmnorm pnmpad pnmquant pnmrotate
+# This script tests: pnmscalefixed pnmshear pnmsmooth pnmtile pnmtoddif
+# This script tests: pnmtopclxl
+# Also requires: ppmpat pamflip
+
+tmpdir=${tmpdir:-/tmp}
+small_ppm=${tmpdir}/test.ppm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+
+ppmpat -g2 -color=rgb:00/00/ff,rgb:ff/00/00 -mesh 4 4 > ${small_ppm}
+
+for testprog in  \
+        pnmalias \
+        "pnmcat -lr " \
+        "pnmcolormap all " \
+        "pnmconvol -matrix=-1,3,-1 " \
+        pnmcrop \
+        "pnmgamma -ungamma 0.5 " \
+        pnmhisteq \
+        pnmhistmap \
+        pnminvert \
+        "pnmmargin 2 " \
+        pnmmercator \
+        pnmmontage \
+        "pnmnlfilt 0.5 0.5 " \
+        pnmnorm \
+        pnmpad \
+        "pnmquant 64 " \
+        "pnmrotate 90 " \
+        "pnmscalefixed 1 " \
+        "pnmshear 45 " \
+        pnmsmooth \
+        "pnmtile 4 4 " \
+	pnmtoddif \
+	"pnmtopclxl -colorok "
+  do
+  ${testprog} ${small_ppm} > ${out1};      status1=$?
+  ${testprog} < ${small_ppm} > ${out2};    status2=$?
+  test -s ${out1};                         status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+  done
+
+
+rm ${small_ppm}
+
+# Pnmquantall: overwrites input files
+# Pnmremap: requires -mapfile=file
+# Pnmpsnr : compares two input files
+# Pnmindex: no input from stdin
+# Pnmpaste: requires two input files
+# Pnmstitch: requires two input files
+
+# pnmmargin: uses pamflip
+# pnmsmooth: uses pnmconvol
\ No newline at end of file
diff --git a/test/stdin-pnm2.ok b/test/stdin-pnm2.ok
new file mode 100644
index 00000000..093ff3f7
--- /dev/null
+++ b/test/stdin-pnm2.ok
@@ -0,0 +1,28 @@
+Test.  Should print (command): 0 0 0
+The following are exceptions: should print (command): 0 0 0 1
+pnmtops, pstopnm, pnmtoxwd, pnmtotiffcmyk
+
+pnmtofiasco --progress-meter 0 : 0 0 0 0
+fiascotopnm: 0 0 0 0
+pnmtojbig: 0 0 0 0
+jbigtopnm: 0 0 0 0
+pnmtojpeg: 0 0 0 0
+jpegtopnm: 0 0 0 0
+pnmtopalm: 0 0 0 0
+palmtopnm: 0 0 0 0
+pnmtopng: 0 0 0 0
+pngtopam: 0 0 0 0
+pnmtops: 0 0 0 1
+pstopnm -stdout : 0 0 0 1
+pnmtorast: 0 0 0 0
+rasttopnm: 0 0 0 0
+pnmtorle: 0 0 0 0
+rletopnm: 0 0 0 0
+pnmtosgi: 0 0 0 0
+sgitopnm: 0 0 0 0
+pnmtosir: 0 0 0 0
+sirtopnm: 0 0 0 0
+pnmtoxwd: 0 0 0 1
+xwdtopnm: 0 0 0 0
+pnmtotiffcmyk: 0 0 0 1
+tifftopnm: 0 0 0 0
diff --git a/test/stdin-pnm2.test b/test/stdin-pnm2.test
new file mode 100755
index 00000000..7622c279
--- /dev/null
+++ b/test/stdin-pnm2.test
@@ -0,0 +1,91 @@
+#! /bin/sh
+# This script tests: pnmtofiasco fiascotopnm
+# This script tests: pnmtojbig jbigtopnm
+# This script tests: pnmtojpeg jpegtopnm
+# This script tests: pnmtopalm palmtopnm
+# This script tests: pnmtopng pngtopam
+# This script tests: pnmtops pstopnm
+# This script tests: pnmtorast rasttopnm
+# This script tests: pnmtorle rletopnm
+# This script tests: pnmtosgi sgitopnm
+# This script tests: pnmtosir sirtopnm
+# This script tests: pnmtoxwd xwdtopnm
+# This script tests: pnmtotiffcmyk tifftopnm
+# Also requires: pgmramp
+
+tmpdir=${tmpdir:-/tmp}
+test_pgm=${tmpdir}/test.pgm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+
+pgmramp -diag 32 32 > ${test_pgm}
+
+echo "Test.  Should print (command): 0 0 0"
+echo "The following are exceptions: should print (command): 0 0 0 1"
+echo "pnmtops, pstopnm, pnmtoxwd, pnmtotiffcmyk"
+echo
+
+export NO_ADD_RLE_HISTORY=1
+# Suppress command-line sequence, execution time in pnmtorle header
+
+for fmt in  \
+        fiasco \
+        jbig \
+        jpeg \
+        palm \
+        png \
+        ps \
+        rast \
+        rle \
+        sgi \
+        sir \
+        xwd \
+	tiffcmyk
+  do
+
+  if [ ${fmt} = "fiasco" ]
+    then testprog1="pnmto"${fmt}" --progress-meter 0 ";
+  else
+      testprog1="pnmto"${fmt};
+  fi
+
+  if [ ${fmt} = "png" ]
+    then testprog2="pngtopam";
+  elif [ ${fmt} = "ps" ]
+    then testprog2="pstopnm -stdout ";
+  elif [ ${fmt} = "tiffcmyk" ]
+    then testprog2="tifftopnm";
+  else
+    testprog2=${fmt}"topnm";
+  fi
+
+  ${testprog1} ${test_pgm} > ${out1};   status1=$?
+  ${testprog1} < ${test_pgm} > ${out2}; status2=$?
+  test -s ${out1};                      status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog1}": "${status1} ${status2} ${status3} $?
+  rm ${out2}
+
+  ${testprog2} ${out1} > ${out3};       status4=$?
+  ${testprog2} < ${out1} > ${out4};     status5=$?
+  test -s ${out3};                      status6=$?
+  cmp -s ${out3} ${out4}
+  echo ${testprog2}": "${status4} ${status5} ${status6} $?
+  rm ${out1} ${out3} ${out4}
+
+  done
+
+rm ${test_pgm}
+
+
+# pnmtofiasco  width, height must be even and at least 32
+#              use --progressmeter option to suppress progress meter
+#
+# pnmtojbig    input must be bilevel black-white or gray
+# pnmtops      input file name embedded in output
+# pnmtotiffcmyk  input file name embedded in output
+#                "Standard input" if from stdin
+# pnmtoxwd     input file name embedded in output
+#              "stdin" if from stdin
diff --git a/test/stdin-ppm1.ok b/test/stdin-ppm1.ok
new file mode 100644
index 00000000..e84a31ea
--- /dev/null
+++ b/test/stdin-ppm1.ok
@@ -0,0 +1,15 @@
+ppmchange: 0 0 0 0
+ppmcolormask -color=rgb:0/0/ff : 0 0 0 0
+ppmdim 0.5 : 0 0 0 0
+ppmdist: 0 0 0 0
+ppmdither: 0 0 0 0
+ppmflash 0.5 : 0 0 0 0
+ppmglobe 12 : 0 0 0 0
+ppmhist: 0 0 0 0
+ppmlabel: 0 0 0 0
+ppmntsc: 0 0 0 0
+ppmrelief: 0 0 0 0
+ppmshadow: 0 0 0 0
+ppmshift 2 -seed=1 : 0 0 0 0
+ppmspread 2 -randomseed=1 : 0 0 0 0
+ppmtv 0.5 : 0 0 0 0
diff --git a/test/stdin-ppm1.test b/test/stdin-ppm1.test
new file mode 100755
index 00000000..84614326
--- /dev/null
+++ b/test/stdin-ppm1.test
@@ -0,0 +1,58 @@
+#! /bin/sh
+# This script tests: ppmchange ppmcolormask ppmdim ppmdist ppmdither ppmflash
+# This script tests: ppmglobe ppmhist ppmlabel ppmntsc ppmrelief ppmshadow
+# This script tests: ppmshift ppmspread ppmtv
+# Also requires: ppmpat
+
+tmpdir=${tmpdir:-/tmp}
+test_ppm=${tmpdir}/test.ppm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+
+ppmpat -g2 -color=rgb:00/00/ff,rgb:ff/00/00 -mesh 12 12 > ${test_ppm}
+
+for testprog in  \
+        ppmchange \
+        "ppmcolormask -color=rgb:0/0/ff " \
+        "ppmdim 0.5 " \
+        ppmdist \
+        ppmdither \
+        "ppmflash 0.5 " \
+        "ppmglobe 12 " \
+        ppmhist \
+        ppmlabel \
+        ppmntsc \
+        ppmrelief \
+        ppmshadow \
+        "ppmshift 2 -seed=1 " \
+        "ppmspread 2 -randomseed=1 " \
+        "ppmtv 0.5 "
+  do
+  ${testprog} ${test_ppm} > ${out1};      status1=$?
+  ${testprog} < ${test_ppm} > ${out2};    status2=$?
+  test -s ${out1};                        status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+  done
+
+rm ${test_ppm}
+
+# These utlities do not have a counterpart "ppmto*" program
+
+# Gouldtoppm
+# Imgtoppm
+# Mtvtoppm
+# Pc1toppm
+# Pgmtoppm
+# Qrttoppm
+# Rawtoppm
+# Sldtoppm
+# Spctoppm
+# Ximtoppm
+
+# Tgatoppm -> Pamtotga
+# Xvminitoppm -> Pamtoxvmini
+
+# Ppm3d and Ppmmix require input two files
+# Ppmfade produces a series of output files
diff --git a/test/stdin-ppm2.ok b/test/stdin-ppm2.ok
new file mode 100644
index 00000000..e3fb4219
--- /dev/null
+++ b/test/stdin-ppm2.ok
@@ -0,0 +1,11 @@
+ppmtoacad: 0 0 0 0
+ppmtoapplevol: 0 0 0 0
+ppmtoascii: 0 0 0 0
+ppmtolj: 0 0 0 0
+ppmtomitsu: 0 0 0 0
+ppmtopgm: 0 0 0 0
+ppmtopuzz: 0 0 0 0
+ppmtosixel: 0 0 0 0
+ppmtoterm: 0 0 0 0
+ppmtoicr: 0 0 0 0
+ppmtoyuvsplit: 0 0 0 0
diff --git a/test/stdin-ppm2.test b/test/stdin-ppm2.test
new file mode 100755
index 00000000..81b3954e
--- /dev/null
+++ b/test/stdin-ppm2.test
@@ -0,0 +1,68 @@
+#! /bin/sh
+# This script tests: ppmtoacad ppmtoapplevol ppmtoascii ppmtolj ppmtomitsu
+# This script tests: ppmtopgm ppmtopuzz ppmtosixel ppmtoterm
+# This script tests: ppmtoicr ppmtoyuvsplit
+# Also requires: ppmpat
+
+tmpdir=${tmpdir:-/tmp}
+test_ppm=${tmpdir}/test.ppm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+
+ppmpat -g2 -color=rgb:00/00/ff,rgb:ff/00/00 -mesh 12 12 > ${test_ppm}
+
+# These converters do not have counterparts in the reverse direction
+
+for testprog in  \
+        ppmtoacad \
+        ppmtoapplevol \
+        ppmtoascii \
+        ppmtolj \
+        ppmtomitsu \
+        ppmtopgm \
+        ppmtopuzz \
+        ppmtosixel \
+        ppmtoterm
+  do
+  ${testprog} ${test_ppm} > ${out1};      status1=$?
+  ${testprog} < ${test_ppm} > ${out2};    status2=$?
+  test -s ${out1};                        status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+  done
+
+rm ${test_ppm}
+
+testprog=ppmtoicr
+
+# File name embedded in output; "untitled" if no name
+
+  ${testprog} testgrid.pbm > ${out1};     status1=$?
+  ${testprog} < testgrid.pbm > ${out2};   status2=$?
+  test -s ${out1};                        status3=$?
+  sed 's/untitled/testgrid.pbm/g' ${out2} | cmp -s ${out1} -
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+
+testprog=ppmtoyuvsplit
+
+# Produces three output files
+
+  ${testprog} ${tmpdir}/base testgrid.pbm;     status1=$?
+  cat ${tmpdir}/base.Y  ${tmpdir}/base.U  ${tmpdir}/base.V > ${out1}
+  rm ${tmpdir}/base.Y  ${tmpdir}/base.U  ${tmpdir}/base.V
+
+  ${testprog} ${tmpdir}/base < testgrid.pbm;   status2=$?
+  cat ${tmpdir}/base.Y  ${tmpdir}/base.U  ${tmpdir}/base.V > ${out2}
+  rm ${tmpdir}/base.Y  ${tmpdir}/base.U  ${tmpdir}/base.V
+  test -s ${out1};                             status3=$?
+  cmp -s ${out1} ${out2}
+  echo ${testprog}": "${status1} ${status2} ${status3} $?
+  rm ${out1} ${out2}
+
+# Ppmtoppm input is from standard input
+
+# Ppmtoapplevol height must be 12
+# Ppmtoarbtxt needs body template file
+# Ppmtompeg parameter file must be given
diff --git a/test/stdin-ppm3.ok b/test/stdin-ppm3.ok
new file mode 100644
index 00000000..f7ba5623
--- /dev/null
+++ b/test/stdin-ppm3.ok
@@ -0,0 +1,20 @@
+ppmtobmp: 0 0 0 0
+bmptopnm: 0 0 0 0
+ppmtoilbm: 0 0 0 0
+ilbmtoppm: 0 0 0 0
+ppmtoleaf: 0 0 0 0
+leaftoppm: 0 0 0 0
+ppmtoneo: 0 0 0 0
+neotoppm: 0 0 0 0
+ppmtopcx: 0 0 0 0
+pcxtoppm: 0 0 0 0
+ppmtopi1: 0 0 0 0
+pi1toppm: 0 0 0 0
+ppmtopict: 0 0 0 0
+picttoppm: 0 0 0 0
+ppmtopj: 0 0 0 0
+pjtoppm: 0 0 0 0
+ppmtospu: 0 0 0 0
+sputoppm: 0 0 0 0
+ppmtoxpm: 0 0 0 0
+xpmtoppm: 0 0 0 0
diff --git a/test/stdin-ppm3.test b/test/stdin-ppm3.test
new file mode 100755
index 00000000..605b535b
--- /dev/null
+++ b/test/stdin-ppm3.test
@@ -0,0 +1,77 @@
+#! /bin/sh
+# This script tests: ppmtobmp bmptopnm
+# This script tests: ppmtoilbm ilbmtoppm
+# This script tests: ppmtoleaf leaftoppm
+# This script tests: ppmtoneo neotoppm
+# This script tests: ppmtopcx pcxtoppm
+# This script tests: ppmtopi1 pi1toppm
+# This script tests: ppmtopict picttoppm
+# This script tests: ppmtopj pjtoppm
+# This script tests: ppmtospu sputoppm
+# This script tests: ppmtoxpm xpmtoppm
+# Also requires: ppmmake
+
+tmpdir=${tmpdir:-/tmp}
+small_ppm=${tmpdir}/small.ppm
+large_ppm=${tmpdir}/large.ppm
+out1=${tmpdir}/out1
+out2=${tmpdir}/out2
+out3=${tmpdir}/out3
+out4=${tmpdir}/out4
+
+ppmmake -maxval 65535 rgb:00/00/00 8 3 > ${small_ppm}
+ppmmake -maxval 7 rgb:00/00/00 320 200 > ${large_ppm}
+
+for fmt in \
+        bmp \
+        ilbm \
+        leaf \
+        neo \
+        pcx \
+        pi1 \
+        pict \
+        pj \
+        spu \
+        xpm
+  do
+  testprog1="ppmto"${fmt}
+  if [ ${fmt} = "bmp" ]
+    then testprog2=${fmt}"topnm";
+  else testprog2=${fmt}"toppm";
+  fi
+
+  if [ ${fmt} = "spu" ]
+    then test_ppm=${large_ppm};
+  else test_ppm=${small_ppm};
+  fi
+
+  ${testprog1} ${test_ppm} > ${out1};    status1=$?
+  ${testprog1} < ${test_ppm} > ${out2};  status2=$?
+  test -s ${out1};                       status3=$?
+  if [ ${fmt} = "xpm" ]
+    then
+    sed -i '/^static char/s/static char .* = {/static char file/' \
+	    ${out1} ${out2};
+  fi
+  cmp -s ${out1} ${out2}
+  echo ${testprog1}": "${status1} ${status2} ${status3} $?
+  rm ${out2}
+
+  ${testprog2} ${out1} > ${out3};      status4=$?
+  ${testprog2} < ${out1} > ${out4};    status5=$?
+  test -s ${out1};                     status6=$?
+  cmp -s ${out3} ${out4}
+  echo ${testprog2}": "${status4} ${status5} ${status6} $?
+  rm ${out1} ${out3} ${out4}
+  done
+
+rm ${small_ppm} ${large_ppm}
+
+# ppmtopict width must be 8 or more
+
+# ppmtospu sputoppm width=320 height=200 fixed
+
+# Eyuvtoppm, Yuvtoppm width, height are mandatory
+
+# Ppmtowinicon Winicontoppm legacy
+# Winicontoppm max size 255 255
diff --git a/test/sunicon-roundtrip.test b/test/sunicon-roundtrip.test
index c5b85909..38513ea8 100755
--- a/test/sunicon-roundtrip.test
+++ b/test/sunicon-roundtrip.test
@@ -1,27 +1,26 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtosunicon sunicontopnm
-# Also requires: pamcut pnmpad
+# Also requires: pbmnoise
 
-# Width of Sun icons are multiples of 8.
-
-#imgsize=$(pamfile -size maze.pbm | awk '{print "-width="$1, "-height="$2}')
+# Width of a Sun icon is always a multiple of 8.
 
 tmpdir=${tmpdir:-/tmp}
 
-maze16_pbm=${tmpdir}/maze16.pbm
-maze32_pbm=${tmpdir}/maze32.pbm
-maze64_pbm=${tmpdir}/maze64.pbm
-
-pamcut -top=0 -left=0 -width=16 -height=16 maze.pbm > ${maze16_pbm} 
-pamcut -top=0 -left=0 -width=32 -height=32 maze.pbm > ${maze32_pbm} 
-pnmpad -width=64 -height=64 maze.pbm > ${maze64_pbm} 
+noise16_pbm=${tmpdir}/noise16.pbm
+noise32_pbm=${tmpdir}/noise32.pbm
+noise64_pbm=${tmpdir}/noise64.pbm
 
 echo "Test.  Should print 0 three times"
-pbmtosunicon ${maze16_pbm} | sunicontopnm | cmp -s - ${maze16_pbm}
-echo $?
-pbmtosunicon ${maze32_pbm} | sunicontopnm | cmp -s - ${maze32_pbm}
-echo $?
-pbmtosunicon ${maze64_pbm} | sunicontopnm | cmp -s - ${maze64_pbm}
-echo $?
+pbmnoise -randomseed=1 16 16 > ${noise16_pbm} && \
+  pbmtosunicon ${noise16_pbm} | sunicontopnm | cmp -s - ${noise16_pbm}
+  echo $?
+
+pbmnoise -randomseed=1 32 32 > ${noise32_pbm} && \
+  pbmtosunicon ${noise32_pbm} | sunicontopnm | cmp -s - ${noise32_pbm}
+  echo $?
+
+pbmnoise -randomseed=1 64 64 > ${noise64_pbm} && \
+  pbmtosunicon ${noise64_pbm} | sunicontopnm | cmp -s - ${noise64_pbm}
+  echo $?
 
-rm ${maze16_pbm} ${maze32_pbm} ${maze64_pbm}
\ No newline at end of file
+rm ${noise16_pbm} ${noise32_pbm} ${noise64_pbm}
\ No newline at end of file
diff --git a/test/sunrast-roundtrip.test b/test/sunrast-roundtrip.test
index a5cfa8c7..dfe68402 100755
--- a/test/sunrast-roundtrip.test
+++ b/test/sunrast-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtorast rasttopnm
 # Also requires:
 
diff --git a/test/symmetry.ok b/test/symmetry.ok
index a5945014..111f09cf 100644
--- a/test/symmetry.ok
+++ b/test/symmetry.ok
@@ -1,5 +1,8 @@
+Test 1.
 ok
+Test 2.
 ok
+Test 3.  Should print ok 7 times
 ok
 ok
 ok
@@ -7,7 +10,9 @@ ok
 ok
 ok
 ok
+Test 4.
 ok
+Test 5.  Should print ok 7 times.
 ok
 ok
 ok
@@ -15,4 +20,5 @@ ok
 ok
 ok
 ok
+Test 6.
 ok
diff --git a/test/symmetry.test b/test/symmetry.test
index 52ba6388..3c495778 100755
--- a/test/symmetry.test
+++ b/test/symmetry.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pgmramp pamgauss pgmkernel pbmmake pbmpscale
 # Also requires: pamflip
 
@@ -25,7 +25,7 @@
 
 tmpdir=${tmpdir:-/tmp}
 
-# Test 1.
+echo "Test 1."
 rect_pgm=${tmpdir}/rect.pgm
 
 pgmramp -rect 31 31 > ${rect_pgm}
@@ -37,7 +37,8 @@ pgmramp -rect 31 31 > ${rect_pgm}
 
 rm ${rect_pgm}
 
-# Test 2.
+
+echo "Test 2."
 circle_pgm=${tmpdir}/circle.pgm
 pgmramp -ell 63 63 > ${circle_pgm}
 
@@ -48,7 +49,8 @@ pgmramp -ell 63 63 > ${circle_pgm}
 
 rm ${circle_pgm}
 
-# Test 3.  Should print "ok" 7 times
+
+echo "Test 3.  Should print ok 7 times"
 gauss_pgm=${tmpdir}/gauss.pgm
 for size in 3 4 5 8 13 21 25
 do
@@ -63,7 +65,7 @@ rm ${gauss_pgm}
 done
 
 
-# Test 4.
+echo "Test 4."
 kernel_pgm=${tmpdir}/kernel.pgm
 pgmkernel 15 15 > ${kernel_pgm}
 
@@ -74,12 +76,12 @@ pgmkernel 15 15 > ${kernel_pgm}
 
 rm ${kernel_pgm}
 
-# Test 5.
-# Should print "ok" 7 times.
+
+echo "Test 5.  Should print ok 7 times."
 pscale_pbm=${tmpdir}/pscale.pbm
-for size in `seq 1 7`
-do
-pbmmake -g 5 5 | pbmpscale $size > ${pscale_pbm}
+for size in 1 2 3 4 5 6 7  # for size in `seq 7`
+  do
+  pbmmake -g 5 5 | pbmpscale ${size} > ${pscale_pbm}
 
 ( for op in -null -tb -lr -r90
     do pamflip $op ${pscale_pbm} | cksum
@@ -89,7 +91,8 @@ pbmmake -g 5 5 | pbmpscale $size > ${pscale_pbm}
 rm ${pscale_pbm}
 done
 
-# Test 6.
+
+echo "Test 6."
 ell_pgm=${tmpdir}/ell.pgm
 pgmramp -ell 101 33 > ${ell_pgm}
 
diff --git a/test/tiff-flate-lzw-roundtrip.test b/test/tiff-flate-lzw-roundtrip.test
index f62c6767..2b0a4536 100755
--- a/test/tiff-flate-lzw-roundtrip.test
+++ b/test/tiff-flate-lzw-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtotiff tifftopnm
 # Also requires: ppmpat
 
diff --git a/test/tiff-roundtrip.test b/test/tiff-roundtrip.test
index b4169319..c33ee904 100755
--- a/test/tiff-roundtrip.test
+++ b/test/tiff-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtotiff tifftopnm
 # Also requires: ppmpat pampick ppmtopgm
 
diff --git a/test/tiffcmyk-roundtrip.test b/test/tiffcmyk-roundtrip.test
index 133c81b7..ebbc5666 100755
--- a/test/tiffcmyk-roundtrip.test
+++ b/test/tiffcmyk-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtotiffcmyk tifftopnm
 # Also requires: pnmpsnr
 
diff --git a/test/utahrle-roundtrip.test b/test/utahrle-roundtrip.test
index 17f1a6c4..4dce0b40 100755
--- a/test/utahrle-roundtrip.test
+++ b/test/utahrle-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtorle rletopnm
 # Also requires: pamchannel pamtopnm
 
diff --git a/test/wbmp-roundtrip.test b/test/wbmp-roundtrip.test
index 6197032c..cf747487 100755
--- a/test/wbmp-roundtrip.test
+++ b/test/wbmp-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtowbmp wbmptopbm
 # Also requires:
 
diff --git a/test/winicon-roundtrip.test b/test/winicon-roundtrip.test
index b4814fee..0acadd53 100755
--- a/test/winicon-roundtrip.test
+++ b/test/winicon-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtowinicon ppmtowinicon winicontopam
 # Also requires: pamchannel pamcut pamdepth pamtopam
 
diff --git a/test/winicon-roundtrip2.test b/test/winicon-roundtrip2.test
index d1f29cc9..eae4ce90 100755
--- a/test/winicon-roundtrip2.test
+++ b/test/winicon-roundtrip2.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtowinicon winicontopam
 # Also requires: pamchannel pamdepth pamstack pamtopam pbmmake ppmpat
 
diff --git a/test/xbm-roundtrip.test b/test/xbm-roundtrip.test
index 3f06e9a5..a8754150 100755
--- a/test/xbm-roundtrip.test
+++ b/test/xbm-roundtrip.test
@@ -1,8 +1,8 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pbmtoxbm xbmtopbm
 # Also requires:
 
 echo "Test.  Should print 281226646 481 twice"
 
 pbmtoxbm maze.pbm | xbmtopbm | cksum
-pbmtoxbm -x10 maze.pbm | xbmtopbm | cksum
+pbmtoxbm -x10 < maze.pbm | xbmtopbm | cksum
diff --git a/test/xpm-roundtrip.test b/test/xpm-roundtrip.test
index 61a5192d..6e3e415b 100755
--- a/test/xpm-roundtrip.test
+++ b/test/xpm-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtoxpm xpmtoppm
 # Also requires: pgmtopbm ppmtopgm
 
diff --git a/test/xv-roundtrip.test b/test/xv-roundtrip.test
index d73933a1..70b298df 100755
--- a/test/xv-roundtrip.test
+++ b/test/xv-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pamtoxvmini xvminitoppm
 # Also requires: pamdepth
 
diff --git a/test/xwd-roundtrip.test b/test/xwd-roundtrip.test
index 4dffbbb0..2d00971d 100755
--- a/test/xwd-roundtrip.test
+++ b/test/xwd-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: pnmtoxwd xwdtopnm
 # Also requires: pamchannel pamtopnm pamdepth
 
diff --git a/test/yuv-roundtrip.test b/test/yuv-roundtrip.test
index e339b418..68f459e8 100755
--- a/test/yuv-roundtrip.test
+++ b/test/yuv-roundtrip.test
@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 # This script tests: ppmtoyuv yuvtoppm
 # Also requires: pamgradient
 
diff --git a/urt/Makefile b/urt/Makefile
index 0aef5290..8c85dab4 100644
--- a/urt/Makefile
+++ b/urt/Makefile
@@ -10,10 +10,10 @@ default: all
 include $(BUILDDIR)/config.mk
 
 LIBOBJECTS = Runput.o cmd_name.o \
-	rle_addhist.o rle_error.o rle_getcom.o rle_getrow.o rle_getskip.o \
+	rle_addhist.o rle_getcom.o rle_getrow.o rle_getskip.o \
 	rle_global.o rle_hdr.o rle_open_f.o rle_putcom.o rle_putrow.o \
-        rle_row_alc.o \
-        scanargs.o vaxshort.o     
+	rle_row_alc.o \
+	vaxshort.o     
 
 MERGE_OBJECTS =
 
diff --git a/urt/README b/urt/README
index dc68889d..2cfbb3e2 100644
--- a/urt/README
+++ b/urt/README
@@ -18,3 +18,8 @@ in its initializer in the original.  But GNU C Library Version 2
 defines stdout as a variable, so that wouldn't compile.  So I changed
 it to NULL and added a line to rle_hdr_init to set that field to
 'stdout' dynamically.  2000.06.02 BJH.
+
+---
+
+Cleanup by Akira F Urushibata 2022.03.06
+Unused functions removed.
\ No newline at end of file
diff --git a/urt/Runput.c b/urt/Runput.c
index 3bc562ac..1a7f2f7b 100644
--- a/urt/Runput.c
+++ b/urt/Runput.c
@@ -1,14 +1,14 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
@@ -18,146 +18,146 @@
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  *  to have all "void" functions so declared.
  */
-/* 
+/*
  * Runput.c - General purpose Run Length Encoding.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	Mon Aug  9 1982
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        Mon Aug  9 1982
  * Copyright (c) 1982,1986 Spencer W. Thomas
- * 
+ *
  * $Id: Runput.c,v 3.0.1.1 1992/01/28 18:17:40 spencer Exp $
- * 
- * Modified by:	Todd W. Fuqua
- * 	Date:	Jul 22 1984
+ *
+ * Modified by: Todd W. Fuqua
+ *      Date:   Jul 22 1984
  * convert to new RLE format to make room for larger frame buffers
  */
 
 /* THIS IS WAY OUT OF DATE.  See rle.5.
  * The output file format is:
- * 
- * Word 0:	A "magic" number.  The top byte of the word contains
- *		the letter 'R' or the letter 'W'.  'W' indicates that
- *		only black and white information was saved.  The bottom
- *		byte is one of the following:
- *	' ':	Means a straight "box" save, -S flag was given.
- *	'B':	Image saved with background color, clear screen to
- *		background before restoring image.
- *	'O':	Image saved in overlay mode.
- * 
- * Words 1-6:	The structure
- * {     short   xpos,			Lower left corner
+ *
+ * Word 0:      A "magic" number.  The top byte of the word contains
+ *              the letter 'R' or the letter 'W'.  'W' indicates that
+ *              only black and white information was saved.  The bottom
+ *              byte is one of the following:
+ *      ' ':    Means a straight "box" save, -S flag was given.
+ *      'B':    Image saved with background color, clear screen to
+ *              background before restoring image.
+ *      'O':    Image saved in overlay mode.
+ *
+ * Words 1-6:   The structure
+ * {     short   xpos,                  Lower left corner
  *             ypos,
- *             xsize,			Size of saved box
+ *             xsize,                   Size of saved box
  *             ysize;
- *     char    rgb[3];			Background color
- *     char    map;			flag for map presence
+ *     char    rgb[3];                  Background color
+ *     char    map;                     flag for map presence
  * }
- * 
- * If the map flag is non-zero, then the color map will follow as 
+ *
+ * If the map flag is non-zero, then the color map will follow as
  * 3*256 16 bit words, first the red map, then the green map, and
  * finally the blue map.
- * 
+ *
  * Following the setup information is the Run Length Encoded image.
  * Each instruction consists of a 4-bit opcode, a 12-bit datum and
  * possibly one or more following words (all words are 16 bits).  The
  * instruction opcodes are:
- * 
+ *
  * SkipLines (1):   The bottom 10 bits are an unsigned number to be added to
- *		    current Y position.
- * 
+ *                  current Y position.
+ *
  * SetColor (2):    The datum indicates which color is to be loaded with
- * 		    the data described by the following ByteData and
- * 		    RunData instructions.  0->red, 1->green, 2->blue.  The
- * 		    operation also resets the X position to the initial
- * 		    X (i.e. a carriage return operation is performed).
- * 
+ *                  the data described by the following ByteData and
+ *                  RunData instructions.  0->red, 1->green, 2->blue.  The
+ *                  operation also resets the X position to the initial
+ *                  X (i.e. a carriage return operation is performed).
+ *
  * SkipPixels (3):  The bottom 10 bits are an unsigned number to be
- * 		    added to the current X position.
- * 
+ *                  added to the current X position.
+ *
  * ByteData (5):    The datum is one less than the number of bytes of
- * 		    color data following.  If the number of bytes is
- * 		    odd, a filler byte will be appended to the end of
- * 		    the byte string to make an integral number of 16-bit
- * 		    words.  The bytes are in PDP-11 order.  The X
- * 		    position is incremented to follow the last byte of
- * 		    data.
- * 
- * RunData (6):	    The datum is one less than the run length.  The
- * 		    following word contains (in its lower 8 bits) the
- * 		    color of the run.  The X position is incremented to
- * 		    follow the last byte in the run.
+ *                  color data following.  If the number of bytes is
+ *                  odd, a filler byte will be appended to the end of
+ *                  the byte string to make an integral number of 16-bit
+ *                  words.  The bytes are in PDP-11 order.  The X
+ *                  position is incremented to follow the last byte of
+ *                  data.
+ *
+ * RunData (6):     The datum is one less than the run length.  The
+ *                  following word contains (in its lower 8 bits) the
+ *                  color of the run.  The X position is incremented to
+ *                  follow the last byte in the run.
  */
 
 #include    <string.h>
-#include	<stdio.h>
+#include        <stdio.h>
 
-#include	"rle_put.h"
-#include	"rle.h"
-#include	"rle_code.h"
+#include        "rle_put.h"
+#include        "rle.h"
+#include        "rle_code.h"
 #include    "vaxshort.h"
 #include    "Runput.h"
 
-#define UPPER 255			/* anything bigger ain't a byte */
+#define UPPER 255                       /* anything bigger ain't a byte */
 
 /*
  * Macros to make writing instructions with correct byte order easier.
  */
 /* Write a two-byte value in little_endian order. */
-#define	put16(a)    (putc((a)&0xff,rle_fd),putc((char)(((a)>>8)&0xff),rle_fd))
+#define put16(a)    (putc((a)&0xff,rle_fd),putc((char)(((a)>>8)&0xff),rle_fd))
 
 /* short instructions */
-#define mk_short_1(oper,a1)		/* one argument short */ \
+#define mk_short_1(oper,a1)             /* one argument short */ \
     putc(oper,rle_fd), putc((char)a1,rle_fd)
 
-#define mk_short_2(oper,a1,a2)		/* two argument short */ \
+#define mk_short_2(oper,a1,a2)          /* two argument short */ \
     putc(oper,rle_fd), putc((char)a1,rle_fd), put16(a2)
 
 /* long instructions */
-#define mk_long_1(oper,a1)		/* one argument long */ \
+#define mk_long_1(oper,a1)              /* one argument long */ \
     putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), put16(a1)
 
-#define mk_long_2(oper,a1,a2)		/* two argument long */ \
+#define mk_long_2(oper,a1,a2)           /* two argument long */ \
     putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), \
     put16(a1), put16(a2)
 
 /* choose between long and short format instructions */
 /* NOTE: these macros can only be used where a STATEMENT is legal */
 
-#define mk_inst_1(oper,a1)		/* one argument inst */ \
+#define mk_inst_1(oper,a1)              /* one argument inst */ \
     if (a1>UPPER) (mk_long_1(oper,a1)); else (mk_short_1(oper,a1))
 
-#define mk_inst_2(oper,a1,a2)		/* two argument inst */ \
+#define mk_inst_2(oper,a1,a2)           /* two argument inst */ \
     if (a1>UPPER) (mk_long_2(oper,a1,a2)); else (mk_short_2(oper,a1,a2))
 
-/* 
+/*
  * Opcode definitions
  */
-#define	    RSkipLines(n)   	    mk_inst_1(RSkipLinesOp,(n))
+#define     RSkipLines(n)           mk_inst_1(RSkipLinesOp,(n))
 
-#define	    RSetColor(c)	    mk_short_1(RSetColorOp,(c))
-				    /* has side effect of performing */
-				    /* "carriage return" action */
+#define     RSetColor(c)            mk_short_1(RSetColorOp,(c))
+                                    /* has side effect of performing */
+                                    /* "carriage return" action */
 
-#define	    RSkipPixels(n)	    mk_inst_1(RSkipPixelsOp,(n))
+#define     RSkipPixels(n)          mk_inst_1(RSkipPixelsOp,(n))
 
-#define	    RNewLine		    RSkipLines(1)
+#define     RNewLine                RSkipLines(1)
 
-#define	    RByteData(n)	    mk_inst_1(RByteDataOp,n)
-					/* followed by ((n+1)/2)*2 bytes */
-					/* of data.  If n is odd, last */
-					/* byte will be ignored */
-					/* "cursor" is left at pixel */
-					/* following last pixel written */
+#define     RByteData(n)            mk_inst_1(RByteDataOp,n)
+                                        /* followed by ((n+1)/2)*2 bytes */
+                                        /* of data.  If n is odd, last */
+                                        /* byte will be ignored */
+                                        /* "cursor" is left at pixel */
+                                        /* following last pixel written */
 
-#define	    RRunData(n,c)	    mk_inst_2(RRunDataOp,(n),(c))
-					/* next word contains color data */
-					/* "cursor" is left at pixel after */
-					/* end of run */
+#define     RRunData(n,c)           mk_inst_2(RRunDataOp,(n),(c))
+                                        /* next word contains color data */
+                                        /* "cursor" is left at pixel after */
+                                        /* end of run */
 
-#define     REOF		    mk_inst_1(REOFOp,0)
-					/* Really opcode only */
+#define     REOF                    mk_inst_1(REOFOp,0)
+                                        /* Really opcode only */
 
 /*****************************************************************
  * TAG( RunSetup )
@@ -167,33 +167,33 @@ void
 RunSetup(rle_hdr * the_hdr)
 {
     struct XtndRsetup setup;
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
 
     put16( RLE_MAGIC );
 
     if ( the_hdr->background == 2 )
-	setup.h_flags = H_CLEARFIRST;
+        setup.h_flags = H_CLEARFIRST;
     else if ( the_hdr->background == 0 )
-	setup.h_flags = H_NO_BACKGROUND;
+        setup.h_flags = H_NO_BACKGROUND;
     else
-	setup.h_flags = 0;
+        setup.h_flags = 0;
     if ( the_hdr->alpha )
-	setup.h_flags |= H_ALPHA;
+        setup.h_flags |= H_ALPHA;
     if ( the_hdr->comments != NULL && *the_hdr->comments != NULL )
-	setup.h_flags |= H_COMMENT;
+        setup.h_flags |= H_COMMENT;
 
     setup.h_ncolors = the_hdr->ncolors;
-    setup.h_pixelbits = 8;		/* Grinnell dependent */
+    setup.h_pixelbits = 8;              /* Grinnell dependent */
     if ( the_hdr->ncmap > 0 && the_hdr->cmap == NULL )
     {
-	fprintf( stderr,
+        fprintf( stderr,
        "%s: Color map of size %d*%d specified, but not supplied, writing %s\n",
-		 the_hdr->cmd, the_hdr->ncmap, (1 << the_hdr->cmaplen),
-		 the_hdr->file_name );
-	the_hdr->ncmap = 0;
+                 the_hdr->cmd, the_hdr->ncmap, (1 << the_hdr->cmaplen),
+                 the_hdr->file_name );
+        the_hdr->ncmap = 0;
     }
-    setup.h_cmaplen = the_hdr->cmaplen;	/* log2 of color map size */
-    setup.h_ncmap = the_hdr->ncmap;	/* no of color channels */
+    setup.h_cmaplen = the_hdr->cmaplen; /* log2 of color map size */
+    setup.h_ncmap = the_hdr->ncmap;     /* no of color channels */
     vax_pshort(setup.hc_xpos,the_hdr->xmin);
     vax_pshort(setup.hc_ypos,the_hdr->ymin);
     vax_pshort(setup.hc_xlen,the_hdr->xmax - the_hdr->xmin + 1);
@@ -201,61 +201,61 @@ RunSetup(rle_hdr * the_hdr)
     fwrite((char *)&setup, SETUPSIZE, 1, rle_fd);
     if ( the_hdr->background != 0 )
     {
-	register int i;
-	register rle_pixel *background =
-	    (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
-	register int *bg_color;
-	/* 
-	 * If even number of bg color bytes, put out one more to get to 
-	 * 16 bit boundary.
-	 */
-	bg_color = the_hdr->bg_color;
-	for ( i = 0; i < the_hdr->ncolors; i++ )
-	    background[i] =  *bg_color++;
-	/* Extra byte, if written, should be 0. */
-	background[i] = 0;
-	fwrite((char *)background, (the_hdr->ncolors / 2) * 2 + 1, 1, rle_fd);
-	free( background );
+        int i;
+        rle_pixel *background =
+            (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
+        int *bg_color;
+        /*
+         * If even number of bg color bytes, put out one more to get to
+         * 16 bit boundary.
+         */
+        bg_color = the_hdr->bg_color;
+        for ( i = 0; i < the_hdr->ncolors; i++ )
+            background[i] =  *bg_color++;
+        /* Extra byte, if written, should be 0. */
+        background[i] = 0;
+        fwrite((char *)background, (the_hdr->ncolors / 2) * 2 + 1, 1, rle_fd);
+        free( background );
     }
     else
-	putc( '\0', rle_fd );
+        putc( '\0', rle_fd );
     if (the_hdr->ncmap > 0)
     {
-	/* Big-endian machines are harder */
-	register int i, nmap = (1 << the_hdr->cmaplen) *
-			       the_hdr->ncmap;
-	register char *h_cmap = (char *)malloc( nmap * 2 );
-	if ( h_cmap == NULL )
-	{
-	    fprintf( stderr,
-	     "%s: Malloc failed for color map of size %d, writing %s\n",
-		     the_hdr->cmd, nmap, the_hdr->file_name );
-	    exit( 1 );
-	}
-	for ( i = 0; i < nmap; i++ )
-	    vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] );
-
-	fwrite( h_cmap, nmap, 2, rle_fd );
-	free( h_cmap );
+        /* Big-endian machines are harder */
+        int i, nmap = (1 << the_hdr->cmaplen) *
+                               the_hdr->ncmap;
+        char *h_cmap = (char *)malloc( nmap * 2 );
+        if ( h_cmap == NULL )
+        {
+            fprintf( stderr,
+             "%s: Malloc failed for color map of size %d, writing %s\n",
+                     the_hdr->cmd, nmap, the_hdr->file_name );
+            exit( 1 );
+        }
+        for ( i = 0; i < nmap; i++ )
+            vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] );
+
+        fwrite( h_cmap, nmap, 2, rle_fd );
+        free( h_cmap );
     }
 
     /* Now write out comments if given */
     if ( setup.h_flags & H_COMMENT )
     {
-	int comlen;
-	register CONST_DECL char ** com_p;
+        int comlen;
+        CONST_DECL char ** com_p;
 
-	/* Get the total length of comments */
-	comlen = 0;
-	for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ )
-	    comlen += 1 + strlen( *com_p );
+        /* Get the total length of comments */
+        comlen = 0;
+        for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ )
+            comlen += 1 + strlen( *com_p );
 
-	put16( comlen );
-	for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ )
-	    fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd );
+        put16( comlen );
+        for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ )
+            fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd );
 
-	if ( comlen & 1 )	/* if odd length, round up */
-	    putc( '\0', rle_fd );
+        if ( comlen & 1 )       /* if odd length, round up */
+            putc( '\0', rle_fd );
     }
 }
 
@@ -266,7 +266,7 @@ RunSetup(rle_hdr * the_hdr)
 void
 RunSkipBlankLines(int nblank, rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     RSkipLines(nblank);
 }
 
@@ -278,7 +278,7 @@ RunSkipBlankLines(int nblank, rle_hdr * the_hdr)
 void
 RunSetColor(int c, rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     RSetColor(c);
 }
 
@@ -291,10 +291,10 @@ RunSetColor(int c, rle_hdr * the_hdr)
 void
 RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     if (! last && nskip > 0)
     {
-	RSkipPixels(nskip);
+        RSkipPixels(nskip);
     }
 }
 
@@ -306,10 +306,10 @@ RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr)
 void
 RunNewScanLine(int flag, rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     if (flag)
     {
-	RNewLine;
+        RNewLine;
     }
 }
 
@@ -320,14 +320,14 @@ RunNewScanLine(int flag, rle_hdr * the_hdr)
 void
 Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     if (n == 0)
-	return;
+        return;
 
     RByteData(n-1);
     fwrite((char *)buf, n, 1, rle_fd);
     if ( n & 1 )
-	putc( 0, rle_fd );
+        putc( 0, rle_fd );
 }
 
 /*****************************************************************
@@ -339,7 +339,7 @@ Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr)
 void
 Runputrun(int color, int n, int last, rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     RRunData(n-1,color);
 }
 
@@ -351,6 +351,6 @@ Runputrun(int color, int n, int last, rle_hdr * the_hdr)
 void
 RunputEof(rle_hdr * the_hdr)
 {
-    register FILE * rle_fd = the_hdr->rle_file;
+    FILE * rle_fd = the_hdr->rle_file;
     REOF;
 }
diff --git a/urt/Runput.h b/urt/Runput.h
index 776e3ec5..1d22a971 100644
--- a/urt/Runput.h
+++ b/urt/Runput.h
@@ -1,4 +1,4 @@
-void 
+void
 RunSetup(rle_hdr * the_hdr);
 
 void
diff --git a/urt/cmd_name.c b/urt/cmd_name.c
index 31fe5f42..4b3f169b 100644
--- a/urt/cmd_name.c
+++ b/urt/cmd_name.c
@@ -1,27 +1,27 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * cmd_name.c - Extract command name from argv[0].
- * 
- * Author:	Spencer W. Thomas
- * 		EECS Dept.
- * 		University of Michigan
- * Date:	Wed Jun 27 1990
+ *
+ * Author:      Spencer W. Thomas
+ *              EECS Dept.
+ *              University of Michigan
+ * Date:        Wed Jun 27 1990
  * Copyright (c) 1990, University of Michigan
  */
 
@@ -35,23 +35,23 @@ char *
 cmd_name( argv )
 char **argv;
 {
-    register char *cp, *a;
+    char *cp, *a;
 
     /* Be paranoid. */
     if ( !argv || !(a = *argv) )
-	return no_name;
+        return no_name;
 
     /* Find end of file name. */
     for ( cp = a; *cp; cp++ )
-	;
+        ;
 
     /* Find last / or beginning of command name. */
     for ( cp--; *cp != '/' && cp > a; cp-- )
-	;
-    
+        ;
+
     /* If it's a /, skip it. */
     if ( *cp == '/' )
-	cp++;
+        cp++;
 
     return cp;
 }
diff --git a/urt/rle.h b/urt/rle.h
index 00717748..1e7ddd0c 100644
--- a/urt/rle.h
+++ b/urt/rle.h
@@ -50,19 +50,19 @@ typedef unsigned short rle_map;
 /*
  * Defines for traditional channel numbers.
  */
-#define RLE_RED     0   /* Red channel traditionally here. */
-#define RLE_GREEN   1   /* Green channel traditionally here. */
-#define RLE_BLUE    2   /* Blue channel traditionally here. */
-#define RLE_ALPHA      -1   /* Alpha channel here. */
+#define RLE_RED    0   /* Red channel traditionally here. */
+#define RLE_GREEN  1   /* Green channel traditionally here. */
+#define RLE_BLUE   2   /* Blue channel traditionally here. */
+#define RLE_ALPHA -1   /* Alpha channel here. */
 
 /*
  * Return values from rle_get_setup.
  */
-#define RLE_SUCCESS  0
-#define RLE_NOT_RLE -1
-#define RLE_NO_SPACE    -2
-#define RLE_EMPTY   -3
-#define RLE_EOF     -4
+#define RLE_SUCCESS   0
+#define RLE_NOT_RLE  -1
+#define RLE_NO_SPACE -2
+#define RLE_EMPTY    -3
+#define RLE_EOF      -4
 
 /*
  * "Magic" value for is_init field.  Pi * 2^29.
@@ -103,7 +103,7 @@ typedef
          *      bits[c/8] & (1 << (c%8))
          */
 #define RLE_SET_BIT(glob,bit) \
-        ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))
+            ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))
 #define RLE_CLR_BIT(glob,bit) \
             ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7)))
 #define RLE_BIT(glob,bit) \
@@ -167,13 +167,6 @@ extern int rle_get_error( int code,
 
 /* From rle_getrow.c */
 
-/*****************************************************************
- * TAG( rle_debug )
- *
- * Turn RLE debugging on or off.
- */
-extern void rle_debug( int on_off );
-
 int
 rle_get_setup(rle_hdr * const the_hdr);
 
@@ -239,16 +232,6 @@ extern void rle_hdr_clear( rle_hdr *the_hdr );
 
 /* From rle_putrow.c. */
 
-/*****************************************************************
- * TAG( rgb_to_bw )
- *
- * Converts RGB data to gray data via the NTSC Y transform.
- */
-extern void rgb_to_bw( rle_pixel *red_row,
-                       rle_pixel *green_row,
-                       rle_pixel *blue_row,
-                       rle_pixel *bw_row,
-                       int rowlen );
 
 /*****************************************************************
  * TAG( rle_puteof )
@@ -285,13 +268,6 @@ extern void rle_put_setup( rle_hdr * the_hdr );
  */
 extern void rle_skiprow( rle_hdr *the_hdr, int nrow );
 
-/* From rle_cp.c */
-/*****************************************************************
- * TAG( rle_cp )
- * Copy image data from input to output with minimal interpretation.
- */
-extern void rle_cp( rle_hdr *in_hdr, rle_hdr *out_hdr );
-
 /* From rle_row_alc.c. */
 /*****************************************************************
  * TAG( rle_row_alloc )
@@ -308,14 +284,6 @@ extern int rle_row_alloc( rle_hdr * the_hdr,
      */
 extern void rle_row_free( rle_hdr *the_hdr, rle_pixel **scanp );
 
-/* From buildmap.c. */
-/*
- * buildmap - build a more usable colormap from data in the_hdr struct.
-     */
-extern rle_pixel **buildmap( rle_hdr *the_hdr,
-                             int minmap,
-                             double orig_gamma,
-                             double new_gamma );
 
 /* From rle_getcom.c. */
 /*****************************************************************
@@ -329,55 +297,11 @@ rle_getcom(const char * const name,
 
 /* From rle_putcom.c. */
 
-/* Delete a specific comment from the image comments. */
-const char *
-rle_delcom(const char * const name,
-           rle_hdr *    const the_hdr);
-
 /* Put (or replace) a comment into the image comments. */
 const char *
 rle_putcom(const char * const value,
            rle_hdr *    const the_hdr);
 
-/* From dither.c. */
-/*****************************************************************
- * TAG( bwdithermap )
- * Create a color map for ordered dithering in grays.
- */
-extern void bwdithermap( int levels, double gamma, int bwmap[],
-                         int divN[256], int modN[256], int magic[16][16] );
-/*****************************************************************
- * TAG( ditherbw )
- * Dither a gray-scale value.
- */
-extern int ditherbw( int x, int y, int val,
-                     int divN[256], int modN[256], int magic[16][16] );
-/*****************************************************************
- * TAG( dithergb )
- * Dither a color value.
- */
-extern int dithergb( int x, int y, int r, int g, int b,
-                     int divN[256], int modN[256], int magic[16][16] );
-/*****************************************************************
- * TAG( dithermap )
- * Create a color map for ordered dithering in color.
- */
-extern void dithermap( int levels, double gamma, int rgbmap[][3],
-                       int divN[256], int modN[256], int magic[16][16] );
-/*****************************************************************
- * TAG( make_square )
- * Make a 16x16 magic square for ordered dithering.
- */
-extern void make_square( double N, int divN[256], int modN[256],
-                         int magic[16][16] );
-
-/* From float_to_exp.c. */
-/*****************************************************************
- * TAG( float_to_exp )
- * Convert a list of floating point numbers to "exp" format.
- */
-extern void float_to_exp( int count, float * floats, rle_pixel * pixels );
-
 /* From rle_open_f.c. */
 /*****************************************************************
  * TAG( rle_open_f )
@@ -398,24 +322,6 @@ rle_open_f_noexit(const char * const prog_name,
                   const char * const file_name,
                   const char * const mode);
 
-/*****************************************************************
- * TAG( rle_close_f )
- *
- * Close a file opened by rle_open_f.  If the file is stdin or stdout,
- * it will not be closed.
- */
-extern void
-rle_close_f( FILE *fd );
-
-/* From colorquant.c. */
-/*****************************************************************
- * TAG( colorquant )
- * Compute a colormap for quantizing an image to a limited set of colors.
- */
-extern int colorquant( rle_pixel *red, rle_pixel *green, rle_pixel *blue,
-                       unsigned long pixels, rle_pixel *colormap[3],
-                       int colors, int bits,
-                       rle_pixel *rgbmap, int fast, int otherimages );
 
 /* From rle_addhist.c. */
 
@@ -432,38 +338,5 @@ rle_addhist(char *          argv[],
  */
 extern char *cmd_name( char **argv );
 
-/* From scanargs.c. */
-/*****************************************************************
- * TAG( scanargs )
- * Scan command argument list and parse arguments.
- */
-extern int scanargs( int argc,
-                     char **argv,
-                     const char *format,
-                     ... );
-
-/* From hilbert.c */
-/*****************************************************************
- * TAG( hilbert_i2c )
- * Convert an index into a Hilbert curve to a set of coordinates.
- */
-extern void hilbert_c2i( int n, int m, int a[], long int *r );
-
-/*****************************************************************
- * TAG( hilbert_c2i )
- * Convert coordinates of a point on a Hilbert curve to its index.
- */
-extern void hilbert_i2c( int n, int m, long int r, int a[] );
-
-/* From inv_cmap.c */
-/*****************************************************************
- * TAG( inv_cmap )
- * Compute an inverse colormap efficiently.
- */
-extern void inv_cmap( int colors,
-                      unsigned char *colormap[3],
-                      int bits,
-                      unsigned long *dist_buf,
-                      unsigned char *rgbmap );
 
 #endif /* RLE_H */
diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c
index b1651754..45c3dbfd 100644
--- a/urt/rle_addhist.c
+++ b/urt/rle_addhist.c
@@ -1,25 +1,25 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * rle_addhist.c - Add to the HISTORY comment in header
- * 
+ *
  * Author:  Andrew Marriott.
- *      School of Computer Science 
+ *      School of Computer Science
  *      Curtin University of Technology
  * Date:    Mon Sept 10 1988
  * Copyright (c) 1988, Curtin University of Technology
@@ -35,7 +35,7 @@
 
 /*****************************************************************
  * TAG( rle_addhist )
- * 
+ *
  * Put a history comment into the header struct.
  * Inputs:
  *  argv:       Command line history to add to comments.
@@ -68,7 +68,7 @@ rle_addhist(char *          argv[],
 
     if (getenv("NO_ADD_RLE_HISTORY"))
         return;
-    
+
     length = 0;
     for (i = 0; argv[i]; ++i)
         length += strlen(argv[i]) +1;   /* length of each arg plus space. */
@@ -83,7 +83,7 @@ rle_addhist(char *          argv[],
         old = rle_getcom(histoire, in_hdr);     /* get old comment. */
     else
         old = NULL;
-    
+
     if (old && *old)
         length += strlen(old);       /* add length if there. */
 
@@ -104,6 +104,6 @@ rle_addhist(char *          argv[],
     strcat(newc,"on ");
     strcat(newc,timedate);         /* \n supplied by time. */
     strcat(newc,padding);          /* to line up multiple histories.*/
-    
+
     rle_putcom(newc, out_hdr);
 }
diff --git a/urt/rle_code.h b/urt/rle_code.h
index 955e7d42..493cdc02 100644
--- a/urt/rle_code.h
+++ b/urt/rle_code.h
@@ -1,50 +1,50 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * rle_code.h - Definitions for Run Length Encoding.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	Mon Aug  9 1982
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        Mon Aug  9 1982
  * Copyright (c) 1982 Spencer W. Thomas
- * 
+ *
  * $Header: /usr/users/spencer/src/urt/include/RCS/rle_code.h,v 3.0 90/08/03 15:19:48 spencer Exp $
  */
 
 #ifndef RLE_MAGIC
 
-/* 
+/*
  * Opcode definitions
  */
 
 #define     LONG                0x40
-#define	    RSkipLinesOp	1
-#define	    RSetColorOp		2
-#define	    RSkipPixelsOp	3
-#define	    RByteDataOp		5
-#define	    RRunDataOp		6
-#define	    REOFOp		7
+#define     RSkipLinesOp        1
+#define     RSetColorOp         2
+#define     RSkipPixelsOp       3
+#define     RByteDataOp         5
+#define     RRunDataOp          6
+#define     REOFOp              7
 
-#define     H_CLEARFIRST        0x1	/* clear framebuffer flag */
-#define	    H_NO_BACKGROUND	0x2	/* if set, no bg color supplied */
-#define	    H_ALPHA		0x4   /* if set, alpha channel (-1) present */
-#define	    H_COMMENT		0x8	/* if set, comments present */
+#define     H_CLEARFIRST        0x1   /* clear framebuffer flag */
+#define     H_NO_BACKGROUND     0x2   /* if set, no bg color supplied */
+#define     H_ALPHA             0x4   /* if set, alpha channel (-1) present */
+#define     H_COMMENT           0x8   /* if set, comments present */
 
 struct XtndRsetup
 {
@@ -54,17 +54,16 @@ struct XtndRsetup
             hc_ylen[2];
     char    h_flags,
             h_ncolors,
-	    h_pixelbits,
-	    h_ncmap,
-	    h_cmaplen;
+            h_pixelbits,
+            h_ncmap,
+            h_cmaplen;
 };
-#define	    SETUPSIZE	((4*2)+5)
+#define     SETUPSIZE   ((4*2)+5)
 
 /* "Old" RLE format magic numbers */
-#define	    RMAGIC	('R' << 8)	/* top half of magic number */
-#define	    WMAGIC	('W' << 8)	/* black&white rle image */
+#define     RMAGIC      ('R' << 8)      /* top half of magic number */
+#define     WMAGIC      ('W' << 8)      /* black&white rle image */
 
-#define	    RLE_MAGIC	((short)0xcc52)	/* RLE file magic number */
+#define     RLE_MAGIC   ((short)0xcc52) /* RLE file magic number */
 
 #endif /* RLE_MAGIC */
-
diff --git a/urt/rle_config.h b/urt/rle_config.h
index 57126a18..5923c00d 100644
--- a/urt/rle_config.h
+++ b/urt/rle_config.h
@@ -49,7 +49,7 @@
 
 /* Typedef for void * so we can use it consistently. */
 #ifdef VOID_STAR
-typedef	void *void_star;
+typedef void *void_star;
 #else
 typedef char *void_star;
 #endif
@@ -59,7 +59,7 @@ typedef char *void_star;
  * before including this file.
  */
 #ifndef NO_DECLARE_MALLOC
-#   include <sys/types.h>	/* For size_t. */
+#   include <sys/types.h>       /* For size_t. */
     extern void_star malloc( size_t );
     extern void_star calloc( size_t, size_t );
     extern void_star realloc( void_star, size_t );
@@ -75,12 +75,12 @@ extern char *getenv( CONST_DECL char *name );
      * TAG( bstring bzero )
      * 'Byte string' functions.
      */
-#   define bzero( _str, _n )		memset( _str, '\0', _n )
-#   define bcopy( _from, _to, _count )	memcpy( _to, _from, _count )
+#   define bzero( _str, _n )            memset( _str, '\0', _n )
+#   define bcopy( _from, _to, _count )  memcpy( _to, _from, _count )
 #endif
 
 #ifdef NEED_SETLINEBUF
-#   define setlinebuf( _s )	setvbuf( (_s), NULL, _IOLBF, 0 )
+#   define setlinebuf( _s )     setvbuf( (_s), NULL, _IOLBF, 0 )
 #endif
 
 #endif
diff --git a/urt/rle_error.c b/urt/rle_error.c
deleted file mode 100644
index 801eee17..00000000
--- a/urt/rle_error.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is
- * preserved on all copies.
- *
- * There is no warranty or other guarantee of fitness for this software,
- * it is provided solely "as is".  Bug reports or fixes may be sent
- * to the author, who may or may not act on them as he desires.
- *
- * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the
- * source is available for no extra charge.
- *
- * If you modify this software, you should include a notice giving the
- * name of the person performing the modification, the date of modification,
- * and the reason for such modification.
- */
-/*
- * rle_error.c - Error message stuff for URT.
- *
- * Author:	Spencer W. Thomas
- * 		EECS Dept.
- * 		University of Michigan
- * Date:	Mon Mar  2 1992
- * Copyright (c) 1992, University of Michigan
- */
-
-#include <string.h>
-
-#include "rle_config.h"
-#include "rle.h"
-
-/*****************************************************************
- * TAG( rle_get_error )
- *
- * Print an error message for the return code from rle_get_setup
- * Inputs:
- * 	code:		The return code from rle_get_setup.
- *	pgmname:	Name of this program (argv[0]).
- *	fname:		Name of the input file.
- * Outputs:
- * 	Prints an error message on standard output.
- *	Returns code.
- */
-int
-rle_get_error( code, pgmname, fname )
-    int code;
-    CONST_DECL char *pgmname;
-    CONST_DECL char *fname;
-{
-    if (! fname || strcmp( fname, "-" ) == 0 )
-        fname = "Standard Input";
-
-    switch( code )
-    {
-    case RLE_SUCCESS:		/* success */
-        break;
-
-    case RLE_NOT_RLE:		/* Not an RLE file */
-        fprintf( stderr, "%s: %s is not an RLE file\n",
-                 pgmname, fname );
-        break;
-
-    case RLE_NO_SPACE:			/* malloc failed */
-        fprintf( stderr,
-                 "%s: Malloc failed reading header of file %s\n",
-                 pgmname, fname );
-        break;
-
-    case RLE_EMPTY:
-        fprintf( stderr, "%s: %s is an empty file\n",
-                 pgmname, fname );
-        break;
-
-    case RLE_EOF:
-        fprintf( stderr,
-                 "%s: RLE header of %s is incomplete (premature EOF)\n",
-                 pgmname, fname );
-        break;
-
-    default:
-        fprintf( stderr, "%s: Error encountered reading header of %s\n",
-                 pgmname, fname );
-        break;
-    }
-    return code;
-}
-
-
diff --git a/urt/rle_getcom.c b/urt/rle_getcom.c
index 4226eaaf..a0a1e5ae 100644
--- a/urt/rle_getcom.c
+++ b/urt/rle_getcom.c
@@ -1,27 +1,27 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * rle_getcom.c - Get specific comments from the_hdr structure.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	Sun Jan 25 1987
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        Sun Jan 25 1987
  * Copyright (c) 1987, University of Utah
  */
 
@@ -31,21 +31,21 @@
 
 /*****************************************************************
  * TAG( match )
- * 
+ *
  * Match a name against a test string for "name=value" or "name".
  * If it matches name=value, return pointer to value part, if just
  * name, return pointer to NUL at end of string.  If no match, return NULL.
  *
  * Inputs:
- * 	n:	Name to match.  May also be "name=value" to make it easier
- *		to replace comments.
- *	v:	Test string.
+ *      n:      Name to match.  May also be "name=value" to make it easier
+ *              to replace comments.
+ *      v:      Test string.
  * Outputs:
- * 	Returns pointer as above.
+ *      Returns pointer as above.
  * Assumptions:
- *	[None]
+ *      [None]
  * Algorithm:
- *	[None]
+ *      [None]
  */
 static const char *
 match(const char * const nArg,
@@ -69,17 +69,17 @@ match(const char * const nArg,
 
 /*****************************************************************
  * TAG( rle_getcom )
- * 
+ *
  * Return a pointer to the value part of a name=value pair in the comments.
  * Inputs:
- * 	name:		Name part of the comment to search for.
- *	the_hdr:	rle_dflt_hdr structure.
+ *      name:           Name part of the comment to search for.
+ *      the_hdr:        rle_dflt_hdr structure.
  * Outputs:
- * 	Returns pointer to value part of comment or NULL if no match.
+ *      Returns pointer to value part of comment or NULL if no match.
  * Assumptions:
- *	[None]
+ *      [None]
  * Algorithm:
- *	[None]
+ *      [None]
  */
 const char *
 rle_getcom(const char * const name,
diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c
index ae220f5b..a24870ac 100644
--- a/urt/rle_getrow.c
+++ b/urt/rle_getrow.c
@@ -1,14 +1,14 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
@@ -18,15 +18,15 @@
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  *  to have all "void" functions so declared.
  */
-/* 
+/*
  * rle_getrow.c - Read an RLE file in.
- * 
+ *
  * Author:  Spencer W. Thomas
  *      Computer Science Dept.
  *      University of Utah
  * Date:    Wed Apr 10 1985
  * Copyright (c) 1985 Spencer W. Thomas
- * 
+ *
  * $Id: rle_getrow.c,v 3.0.1.5 1992/03/04 19:33:08 spencer Exp spencer $
  */
 
@@ -43,7 +43,7 @@
 /* Read a two-byte "short" that started in VAX (LITTLE_ENDIAN) order */
 #define VAXSHORT( var, fp )\
     { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; }
-  
+
 /* Instruction format -- first byte is opcode, second is datum. */
 
 #define OPCODE(inst) (inst[0] & ~LONG)
@@ -77,7 +77,7 @@ rle_get_setup(rle_hdr * const the_hdr) {
     FILE * infile = the_hdr->rle_file;
     int i;
     char * comment_buf;
-    
+
     /* Clear old stuff out of the header. */
     rle_hdr_clear(the_hdr);
     if (the_hdr->is_init != RLE_INIT_MAGIC)
@@ -167,7 +167,7 @@ rle_get_setup(rle_hdr * const the_hdr) {
         evenlen = (comlen + 1) & ~1;    /* make it even */
         if (evenlen) {
             MALLOCARRAY(comment_buf, evenlen);
-    
+
             if (comment_buf == NULL) {
                 pm_error("Malloc failed for comment buffer of size %d "
                          "in rle_get_setup, reading '%s'",
@@ -218,78 +218,13 @@ rle_get_setup(rle_hdr * const the_hdr) {
 
 
 
-void
-rle_get_setup_ok(rle_hdr *    const the_hdr,
-                 const char * const prog_name,
-                 const char * const file_name) {
-/*-----------------------------------------------------------------------------
-  Read the initialization information from an RLE file.
-
-  Inputs:
-   the_hdr:    Contains pointer to the input file.
-   prog_name:  Program name to be printed in the error message.
-       file_name:  File name to be printed in the error message.
-                   If NULL, the string "stdin" is generated.
-
-  Outputs:
-   the_hdr:    Initialized with information from the input file.
-       If reading the header fails, it prints an error message
-       and exits with the appropriate status code.
-  Algorithm:
-   rle_get_setup does all the work.
----------------------------------------------------------------------------- */
-    int code;
-
-    /* Backwards compatibility: if is_init is not properly set, 
-     * initialize the header.
-     */
-    if (the_hdr->is_init != RLE_INIT_MAGIC) {
-        FILE * const f = the_hdr->rle_file;
-        rle_hdr_init( the_hdr );
-        the_hdr->rle_file = f;
-        rle_names(the_hdr, prog_name, file_name, 0);
-    }
-
-    code = rle_get_error(rle_get_setup(the_hdr),
-                         the_hdr->cmd, the_hdr->file_name);
-    if (code)
-        exit(code);
-}
-
-
-
-void
-rle_debug( on_off )
-    int on_off;
-{
-/*-----------------------------------------------------------------------------
-  Turn RLE debugging on or off.
-  Inputs:
-   on_off:     if 0, stop debugging, else start.
-  Outputs:
-   Sets internal debug flag.
-  Assumptions:
-   [None]
-  Algorithm:
-   [None]
----------------------------------------------------------------------------- */
-    debug_f = on_off;
-
-    /* Set line buffering on stderr.  Character buffering is the default, and
-     * it is SLOOWWW for large amounts of output.
-     */
-    setvbuf(stderr, NULL, _IOLBF, 0);
-}
-
-
-
 int
 rle_getrow(rle_hdr *    const the_hdr,
            rle_pixel ** const scanline) {
 /*-----------------------------------------------------------------------------
   Get a scanline from the input file.
   Inputs:
-   the_hdr:    Header structure containing information about 
+   the_hdr:    Header structure containing information about
            the input file.
   Outputs:
    scanline:   an array of pointers to the individual color
@@ -304,10 +239,10 @@ rle_getrow(rle_hdr *    const the_hdr,
    specified (the_hdr->background is true), just set the
    scanlines to the background color.  If clear-to-background is
    not set, just increment the scanline number and return.
-  
+
    Otherwise, read input until a vertical skip is encountered,
    decoding the instructions into scanline data.
- 
+
    If ymax is reached (or, somehow, passed), continue reading and
    discarding input until end of image.
 ---------------------------------------------------------------------------- */
diff --git a/urt/rle_getskip.c b/urt/rle_getskip.c
index 1366e162..3d36fba4 100644
--- a/urt/rle_getskip.c
+++ b/urt/rle_getskip.c
@@ -1,27 +1,27 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * rle_getskip.c - Skip scanlines on input.
- * 
- * Author:	Spencer W. Thomas
- * 		EECS Dept.
- * 		University of Michigan
- * Date:	Wed Jun 27 1990
+ *
+ * Author:      Spencer W. Thomas
+ *              EECS Dept.
+ *              University of Michigan
+ * Date:        Wed Jun 27 1990
  * Copyright (c) 1990, University of Michigan
  */
 
@@ -32,133 +32,133 @@
 
 /* Read a two-byte "short" that started in VAX (LITTLE_ENDIAN) order */
 #define VAXSHORT( var, fp )\
-	{ var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; }
-  
+        { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; }
+
 /* Instruction format -- first byte is opcode, second is datum. */
 
 #define OPCODE(inst) (inst[0] & ~LONG)
 #define LONGP(inst) (inst[0] & LONG)
-#define DATUM(inst) (inst[1] & 0xff)	/* Make sure it's unsigned. */
+#define DATUM(inst) (inst[1] & 0xff)    /* Make sure it's unsigned. */
 
 /*****************************************************************
  * TAG( rle_getskip )
- * 
+ *
  * Skip the next scanline with data on it.
  * Most useful for skipping to end-of-image.
  * Inputs:
- * 	the_hdr:	Describes input image.
+ *      the_hdr:        Describes input image.
  * Outputs:
- * 	Returns the number of the next scanline.  At EOF returns 32768.
+ *      Returns the number of the next scanline.  At EOF returns 32768.
  * Assumptions:
- * 	rle_get_setup has been called.
+ *      rle_get_setup has been called.
  * Algorithm:
- * 	Read input to the beginning of the next scanline, or to EOF or
- * 	end of image.
+ *      Read input to the beginning of the next scanline, or to EOF or
+ *      end of image.
  */
 unsigned int
 rle_getskip( the_hdr )
 rle_hdr *the_hdr;
 {
     unsigned char inst[2];
-    register FILE *infile = the_hdr->rle_file;
+    FILE *infile = the_hdr->rle_file;
     int nc;
 
     /* Add in vertical skip from last scanline */
-    if ( the_hdr->priv.get.vert_skip > 0) 
-	the_hdr->priv.get.scan_y += the_hdr->priv.get.vert_skip;
+    if ( the_hdr->priv.get.vert_skip > 0)
+        the_hdr->priv.get.scan_y += the_hdr->priv.get.vert_skip;
     the_hdr->priv.get.vert_skip = 0;
 
     if ( the_hdr->priv.get.is_eof )
-	return 32768;		/* too big for 16 bits, signal EOF */
-    
+        return 32768;           /* too big for 16 bits, signal EOF */
+
     /* Otherwise, read and interpret instructions until a skipLines
      * instruction is encountered.
      */
     for (;;)
     {
         inst[0] = getc( infile );
-	inst[1] = getc( infile );
-	if ( feof(infile) )
-	{
-	    the_hdr->priv.get.is_eof = 1;
-	    break;		/* <--- one of the exits */
-	}
-
-	switch( OPCODE(inst) )
-	{
-	case RSkipLinesOp:
-	    if ( LONGP(inst) )
-	    {
-		VAXSHORT( the_hdr->priv.get.vert_skip, infile );
-	    }
-	    else
-		the_hdr->priv.get.vert_skip = DATUM(inst);
-	    break;			/* need to break for() here, too */
-
-	case RSetColorOp:
-	    /* No-op here. */
-	    break;
-
-	case RSkipPixelsOp:
-	    if ( LONGP(inst) )
-	    {
-		(void)getc( infile );
-		(void)getc( infile );
-	    }
-	    break;
-
-	case RByteDataOp:
-	    if ( LONGP(inst) )
-	    {
-	        VAXSHORT( nc, infile );
-	    }
-	    else
-		nc = DATUM(inst);
-	    nc++;
-	    if ( the_hdr->priv.get.is_seek )
-		fseek( infile, ((nc + 1) / 2) * 2, 1 );
-	    else
-	    {
-		register int ii;
-		for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- )
-		    (void) getc( infile );	/* discard it */
-	    }
-
-	    break;
-
-	case RRunDataOp:
-	    if ( LONGP(inst) )
-	    {
-		(void)getc( infile );
-		(void)getc( infile );
-	    }
-	    (void)getc( infile );
-	    (void)getc( infile );
-	    break;
-
-	case REOFOp:
-	    the_hdr->priv.get.is_eof = 1;
-	    break;
-
-	default:
-	    fprintf( stderr,
-		     "%s: rle_getskip: Unrecognized opcode: %d, reading %s\n",
-		     the_hdr->cmd, OPCODE(inst), the_hdr->file_name );
-	    exit(1);
-	}
-	if ( OPCODE(inst) == REOFOp )
-	    break;			/* <--- the other loop exit */
-	if ( OPCODE(inst) == RSkipLinesOp )
-	    break;
+        inst[1] = getc( infile );
+        if ( feof(infile) )
+        {
+            the_hdr->priv.get.is_eof = 1;
+            break;              /* <--- one of the exits */
+        }
+
+        switch( OPCODE(inst) )
+        {
+        case RSkipLinesOp:
+            if ( LONGP(inst) )
+            {
+                VAXSHORT( the_hdr->priv.get.vert_skip, infile );
+            }
+            else
+                the_hdr->priv.get.vert_skip = DATUM(inst);
+            break;                      /* need to break for() here, too */
+
+        case RSetColorOp:
+            /* No-op here. */
+            break;
+
+        case RSkipPixelsOp:
+            if ( LONGP(inst) )
+            {
+                (void)getc( infile );
+                (void)getc( infile );
+            }
+            break;
+
+        case RByteDataOp:
+            if ( LONGP(inst) )
+            {
+                VAXSHORT( nc, infile );
+            }
+            else
+                nc = DATUM(inst);
+            nc++;
+            if ( the_hdr->priv.get.is_seek )
+                fseek( infile, ((nc + 1) / 2) * 2, 1 );
+            else
+            {
+                int ii;
+                for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- )
+                    (void) getc( infile );      /* discard it */
+            }
+
+            break;
+
+        case RRunDataOp:
+            if ( LONGP(inst) )
+            {
+                (void)getc( infile );
+                (void)getc( infile );
+            }
+            (void)getc( infile );
+            (void)getc( infile );
+            break;
+
+        case REOFOp:
+            the_hdr->priv.get.is_eof = 1;
+            break;
+
+        default:
+            fprintf( stderr,
+                     "%s: rle_getskip: Unrecognized opcode: %d, reading %s\n",
+                     the_hdr->cmd, OPCODE(inst), the_hdr->file_name );
+            exit(1);
+        }
+        if ( OPCODE(inst) == REOFOp )
+            break;                      /* <--- the other loop exit */
+        if ( OPCODE(inst) == RSkipLinesOp )
+            break;
     }
 
     /* Return the number of the NEXT scanline. */
     the_hdr->priv.get.scan_y +=
-	the_hdr->priv.get.vert_skip;
+        the_hdr->priv.get.vert_skip;
     the_hdr->priv.get.vert_skip = 0;
 
     if ( the_hdr->priv.get.is_eof )
-	return 32768;		/* too big for 16 bits, signal EOF */
+        return 32768;           /* too big for 16 bits, signal EOF */
     else
-	return the_hdr->priv.get.scan_y;
+        return the_hdr->priv.get.scan_y;
 }
diff --git a/urt/rle_global.c b/urt/rle_global.c
index 6014a229..f7228ea9 100644
--- a/urt/rle_global.c
+++ b/urt/rle_global.c
@@ -1,14 +1,14 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
@@ -18,15 +18,15 @@
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  *  to have all "void" functions so declared.
  */
-/* 
+/*
  * rle_global.c - Global variable initialization for rle routines.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	Thu Apr 25 1985
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        Thu Apr 25 1985
  * Copyright (c) 1985,1986 Spencer W. Thomas
- * 
+ *
  * $Id: rle_global.c,v 3.0.1.1 1992/01/28 18:23:03 spencer Exp $
  */
 
@@ -39,40 +39,40 @@
 
 struct rle_dispatch_tab rle_DTable[] = {
     {
-	" OB",
-	RunSetup,
-	RunSkipBlankLines,
-	RunSetColor,
-	RunSkipPixels,
-	RunNewScanLine,
-	Runputdata,
-	Runputrun,
-	DefaultBlockHook,
-	RunputEof
+        " OB",
+        RunSetup,
+        RunSkipBlankLines,
+        RunSetColor,
+        RunSkipPixels,
+        RunNewScanLine,
+        Runputdata,
+        Runputrun,
+        DefaultBlockHook,
+        RunputEof
     },
 };
 
 static int bg_color[3] = { 0, 0, 0 };
 
 rle_hdr rle_dflt_hdr = {
-    RUN_DISPATCH,		/* dispatch value */
-    3,				/* 3 colors */
-    bg_color,			/* background color */
-    0,				/* (alpha) if 1, save alpha channel */
-    2,				/* (background) 0->just save pixels, */
-				/* 1->overlay, 2->clear to bg first */
-    0, 511,			/* (xmin, xmax) X bounds to save */
-    0, 511,			/* (ymin, ymax) Y bounds to save */
-    0,				/* ncmap (if != 0, save color map) */
-    8,				/* cmaplen (log2 of length of color map) */
-    NULL,			/* pointer to color map */
-    NULL,			/* pointer to comment strings */
-    NULL,			/* output file -- must be set dynamically */
-    { 7 },			/* RGB channels only */
-    0L,				/* Can't free name and file fields. */
-    "Urt",			/* Default "program name". */
-    "no file",			/* No file name given. */
-    0				/* First image. */
+    RUN_DISPATCH,               /* dispatch value */
+    3,                          /* 3 colors */
+    bg_color,                   /* background color */
+    0,                          /* (alpha) if 1, save alpha channel */
+    2,                          /* (background) 0->just save pixels, */
+                                /* 1->overlay, 2->clear to bg first */
+    0, 511,                     /* (xmin, xmax) X bounds to save */
+    0, 511,                     /* (ymin, ymax) Y bounds to save */
+    0,                          /* ncmap (if != 0, save color map) */
+    8,                          /* cmaplen (log2 of length of color map) */
+    NULL,                       /* pointer to color map */
+    NULL,                       /* pointer to comment strings */
+    NULL,                       /* output file -- must be set dynamically */
+    { 7 },                      /* RGB channels only */
+    0L,                         /* Can't free name and file fields. */
+    "Urt",                      /* Default "program name". */
+    "no file",                  /* No file name given. */
+    0                           /* First image. */
     /* Can't initialize the union */
 };
 
@@ -82,6 +82,6 @@ void
 NullputEof(the_hdr)
 rle_hdr * the_hdr;
 {
-				/* do nothing */
+                                /* do nothing */
 }
 #endif
diff --git a/urt/rle_hdr.c b/urt/rle_hdr.c
index bdb728d2..8ceaa9eb 100644
--- a/urt/rle_hdr.c
+++ b/urt/rle_hdr.c
@@ -40,7 +40,7 @@ rle_names(rle_hdr *    const hdrP,
           const char * const pgmname,
           const char * const fname,
           int          const imgNum) {
-/*---------------------------------------------------------------------------- 
+/*----------------------------------------------------------------------------
  * Load program and file names into header.
  * Inputs:
  *  hdrP:      Header to modify.
diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c
index 1aeb6448..65362a53 100644
--- a/urt/rle_open_f.c
+++ b/urt/rle_open_f.c
@@ -322,31 +322,3 @@ rle_open_f(const char * prog_name, const char * file_name, const char * mode)
     return fp;
 }
 
-
-/*****************************************************************
- * TAG( rle_close_f )
- *
- * Close a file opened by rle_open_f.  If the file is stdin or stdout,
- * it will not be closed.
- * Inputs:
- *  fd: File to close.
- * Outputs:
- *  None.
- * Assumptions:
- *  fd is open.
- * Algorithm:
- *  If fd is NULL, just return.
- *  If fd is stdin or stdout, don't close it.  Otherwise, call fclose.
- */
-void
-rle_close_f( fd )
-    FILE *fd;
-{
-    if ( fd == NULL || fd == stdin || fd == stdout )
-        return;
-    else
-        fclose( fd );
-}
-
-
-
diff --git a/urt/rle_put.h b/urt/rle_put.h
index 1f8cc85b..bfabd617 100644
--- a/urt/rle_put.h
+++ b/urt/rle_put.h
@@ -1,29 +1,29 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * rle_put.h - Definitions and a few global variables for rle_putrow/putraw.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	Mon Aug  9 1982
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        Mon Aug  9 1982
  * Copyright (c) 1982 Spencer W. Thomas
- * 
+ *
  * $Id: rle_put.h,v 3.0.1.2 1992/02/27 21:14:35 spencer Exp $
  */
 
@@ -35,7 +35,7 @@
  */
 #ifdef __cplusplus        /* Cfront 2.0  or g++ */
 #ifndef c_plusplus
-#define c_plusplus        
+#define c_plusplus
 #endif
 extern "C" {
 #endif
@@ -67,38 +67,38 @@ struct rle_dispatch_tab {
 
 extern struct rle_dispatch_tab rle_DTable[];
 
-/* 
+/*
  * These definitions presume the existence of a variable called
  * "fileptr", declared "long * fileptr".  *fileptr should be
  * initialized to 0 before calling Setup().
  * A pointer "the_hdr" declared "rle_hdr * the_hdr" is also
  * presumed to exist.
  */
-#define	    rle_magic		(rle_DTable[(int)the_hdr->dispatch].magic)
-#define	    Setup()		(*rle_DTable[(int)the_hdr->dispatch].setup)(the_hdr)
-#define	    SkipBlankLines(n)	(*rle_DTable[(int)the_hdr->dispatch].skipBlankLines)(n, the_hdr)
-#define	    SetColor(c)		(*rle_DTable[(int)the_hdr->dispatch].setColor)(c, the_hdr)
-#define	    SkipPixels(n, l, r)	(*rle_DTable[(int)the_hdr->dispatch].skipPixels)(n,l,r, the_hdr)
-#define	    NewScanLine(flag)	(*rle_DTable[(int)the_hdr->dispatch].newScanLine)(flag, the_hdr)
-#define	    putdata(buf, len)	(*rle_DTable[(int)the_hdr->dispatch].putdat)(buf, len, the_hdr)
-#define	    putrun(val, len, f)	(*rle_DTable[(int)the_hdr->dispatch].putrn)(val,len,f, the_hdr)
-#define	    BlockHook()		(*rle_DTable[(int)the_hdr->dispatch].blockHook)(the_hdr)
-#define	    PutEof()		(*rle_DTable[(int)the_hdr->dispatch].putEof)(the_hdr)
+#define     rle_magic           (rle_DTable[(int)the_hdr->dispatch].magic)
+#define     Setup()             (*rle_DTable[(int)the_hdr->dispatch].setup)(the_hdr)
+#define     SkipBlankLines(n)   (*rle_DTable[(int)the_hdr->dispatch].skipBlankLines)(n, the_hdr)
+#define     SetColor(c)         (*rle_DTable[(int)the_hdr->dispatch].setColor)(c, the_hdr)
+#define     SkipPixels(n, l, r) (*rle_DTable[(int)the_hdr->dispatch].skipPixels)(n,l,r, the_hdr)
+#define     NewScanLine(flag)   (*rle_DTable[(int)the_hdr->dispatch].newScanLine)(flag, the_hdr)
+#define     putdata(buf, len)   (*rle_DTable[(int)the_hdr->dispatch].putdat)(buf, len, the_hdr)
+#define     putrun(val, len, f) (*rle_DTable[(int)the_hdr->dispatch].putrn)(val,len,f, the_hdr)
+#define     BlockHook()         (*rle_DTable[(int)the_hdr->dispatch].blockHook)(the_hdr)
+#define     PutEof()            (*rle_DTable[(int)the_hdr->dispatch].putEof)(the_hdr)
 
 void
 DefaultBlockHook(rle_hdr * the_hdr);
-/* 
+/*
  * States for run detection
  */
-#define	DATA	0
-#define	RUN1	1
-#define RUN2	2
-#define	RUN3	3
-#define RUN4	4
-#define RUN5	5
-#define RUN6	6
-#define RUN7	7
-#define	INRUN	-1
+#define DATA    0
+#define RUN1    1
+#define RUN2    2
+#define RUN3    3
+#define RUN4    4
+#define RUN5    5
+#define RUN6    6
+#define RUN7    7
+#define INRUN  -1
 
 #ifdef __cplusplus
 }
diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c
index ab2eb208..0bebd8d7 100644
--- a/urt/rle_putcom.c
+++ b/urt/rle_putcom.c
@@ -1,23 +1,23 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
  * name of the person performing the modification, the date of modification,
  * and the reason for such modification.
  */
-/* 
+/*
  * rle_putcom.c - Add a picture comment to the header struct.
- * 
+ *
  * Author:  Spencer W. Thomas
  *      Computer Science Dept.
  *      University of Utah
@@ -33,7 +33,7 @@
 
 /*****************************************************************
  * TAG( match )
- * 
+ *
  * Match a name against a test string for "name=value" or "name".
  * If it matches name=value, return pointer to value part, if just
  * name, return pointer to NUL at end of string.  If no match, return NULL.
@@ -72,7 +72,7 @@ match(const char * const nArg,
 
 /*****************************************************************
  * TAG( rle_putcom )
- * 
+ *
  * Put a comment into the header struct.
  * Inputs:
  *  value:      Value to add to comments.
@@ -124,46 +124,3 @@ rle_putcom(const char * const value,
 
     return NULL;
 }
-
-
-
-/*****************************************************************
- * TAG( rle_delcom )
- * 
- * Delete a comment from header struct.
- * Inputs:
- *  name:       Name of comment to delete.
- *  the_hdr:    Header to delete comment from.
- * Outputs:
- *  the_hdr:    Modified header struct.
- *  Returns original comment value.
- * Assumptions:
- *  [None]
- * Algorithm:
- *  [None]
- */
-const char *
-rle_delcom(const char * const name,
-           rle_hdr *    const the_hdr) {
-
-    const char * v = NULL;
-
-    if (the_hdr->comments == NULL)
-        v = NULL;
-    else {
-        const char ** cp;
-
-        for (cp = the_hdr->comments; *cp != NULL; ++cp)
-            if (match(name, *cp) != NULL) {
-                v = *cp;
-                for ( ; *cp != NULL; ++cp)
-                    *cp = cp[1];
-                break;
-            }
-        /* Not found */
-        if (*the_hdr->comments == NULL)
-            the_hdr->comments = NULL;
-    }
-
-    return v;
-}
diff --git a/urt/rle_putrow.c b/urt/rle_putrow.c
index 399633e4..5f808c92 100644
--- a/urt/rle_putrow.c
+++ b/urt/rle_putrow.c
@@ -1,14 +1,14 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
@@ -18,60 +18,57 @@
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  *  to have all "void" functions so declared.
  */
-/* 
+/*
  * rle_putrow.c - Save a row of the fb to a file.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	1 April 1981
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        1 April 1981
  * Copyright (c) 1981,1986 Spencer W. Thomas
  *
  * $Id: rle_putrow.c,v 3.0.1.2 1992/01/28 18:29:22 spencer Exp $
  */
- 
+
 #include <stdio.h>
 
 #include "rle_put.h"
 #include "rle.h"
 
 
-#define FASTRUNS		/* Faster run finding */
-#ifdef vax
-#define LOCC			/* Use vax instructions for more speed */
-#endif
+#define FASTRUNS                /* Faster run finding */
 
-#define	FALSE	0
-#define	TRUE	1
+#define FALSE   0
+#define TRUE    1
 
 /* Save some typing. */
 #define PBRUN the_hdr->priv.put.brun
 
 /*****************************************************************
  * TAG( findruns )
- * 
+ *
  * Find runs not a given color in the row.
  * Inputs:
- * 	row:		Row of pixel values
- *	rowlen:		Number of pixels in the row.
- *	color:		Color to compare against.
- *	nrun:		Number of runs already found (in different colors).
- *	brun:		Runs found in other color channels already.
+ *      row:            Row of pixel values
+ *      rowlen:         Number of pixels in the row.
+ *      color:          Color to compare against.
+ *      nrun:           Number of runs already found (in different colors).
+ *      brun:           Runs found in other color channels already.
  * Outputs:
- * 	brun:		Modified to reflect merging of runs in this color.
- *	Returns number of runs in brun.
+ *      brun:           Modified to reflect merging of runs in this color.
+ *      Returns number of runs in brun.
  * Assumptions:
  *
  * Algorithm:
- * 	Search for occurrences of pixels not of the given color outside
- *	the runs already found.  When some are found, add a new run or
- *	extend an existing one.  Adjacent runs with fewer than two
- *	pixels intervening are merged.
+ *      Search for occurrences of pixels not of the given color outside
+ *      the runs already found.  When some are found, add a new run or
+ *      extend an existing one.  Adjacent runs with fewer than two
+ *      pixels intervening are merged.
  */
 static int
-findruns(rle_pixel * const row, 
-         int         const rowlen, 
-         int         const color, 
+findruns(rle_pixel * const row,
+         int         const rowlen,
+         int         const color,
          int         const nrunAlready,
          short    (* const brun)[2]) {
 
@@ -99,9 +96,9 @@ findruns(rle_pixel * const row,
         /* Assert: 0 <= i <= rowlen
          * brun[i] is the run following the "blank" space being
          * searched.  If i == rowlen, search after brun[i-1].
-	 */
+         */
 
-	/* get lower and upper bounds of search */
+        /* get lower and upper bounds of search */
 
         if ( i == 0 )
             lower = 0;
@@ -118,15 +115,13 @@ findruns(rle_pixel * const row,
                  i, lower, upper );
 #endif
         /* Search for beginning of run != color */
-#if  defined(LOCC)&defined(vax)
-        s = upper - skpc( (char *)row + lower, upper - lower + 1, color ) + 1;
-#else
+
         for ( s = lower; s <= upper; s++ )
             if ( row[s] != color )
                 break;
-#endif
 
-        if ( s <= upper )	/* found a new run? */
+
+        if ( s <= upper )       /* found a new run? */
         {
             if ( s > lower + 1 || i == 0 ) /* disjoint from preceding run? */
             {
@@ -144,19 +139,16 @@ findruns(rle_pixel * const row,
             }
             else
             {
-                i--;		/* just add to preceding run */
+                i--;            /* just add to preceding run */
 #ifdef DEBUG
                 fprintf( stderr, "Adding to previous run\n" );
 #endif
             }
 
-#if defined(LOCC)&defined(vax)
-            s = upper - locc( (char *)row + s, upper - s + 1, color ) + 1;
-#else
             for ( ; s <= upper; s++ )
                 if ( row[s] == color )
                     break;
-#endif
+
             brun[i][1] = s - 1;
 
 #ifdef DEBUG
@@ -180,7 +172,7 @@ findruns(rle_pixel * const row,
             putc( '\n', stderr );
 #endif
         }
-	
+
         /* Search in next space */
         i++;
     }
@@ -193,319 +185,313 @@ findruns(rle_pixel * const row,
 /*****************************************************************
  * TAG( rle_putrow )
  * Write a scanline to the output file.
- * 
+ *
  * Inputs:
- *	rows:		Pointer to vector of pointers to
- *			rle_pixel arrays containing the pixel information.
- *			If NULL, rowlen scanlines are skipped.
- *	rowlen:		The number of pixels in the scanline, or the
- *			number of scanlines to skip (see above).
+ *      rows:           Pointer to vector of pointers to
+ *                      rle_pixel arrays containing the pixel information.
+ *                      If NULL, rowlen scanlines are skipped.
+ *      rowlen:         The number of pixels in the scanline, or the
+ *                      number of scanlines to skip (see above).
  * Outputs:
- * 	Run length encoded information is written to the_hdr.rle_file.
+ *      Run length encoded information is written to the_hdr.rle_file.
  * Assumptions:
- * 	I'm sure there are lots of assumptions in here.
+ *      I'm sure there are lots of assumptions in here.
  * Algorithm:
- * 	There are two parts:
- * 		1. Find all "sufficiently long" runs of background
- * 		   color.  These will not be saved at all.
- * 		2. For each run of non-background, for each color
- * 		   channel, find runs of identical pixel values
- * 		   between "data" segments (of differing pixel
- * 		   values).
- * 	For part 1, "sufficiently long" is 2 pixels, if the following
- * 	data is less than 256 pixels long, otherwise it is 4 pixels.
- * 	This is enforced by a post-process merge.
+ *      There are two parts:
+ *              1. Find all "sufficiently long" runs of background
+ *                 color.  These will not be saved at all.
+ *              2. For each run of non-background, for each color
+ *                 channel, find runs of identical pixel values
+ *                 between "data" segments (of differing pixel
+ *                 values).
+ *      For part 1, "sufficiently long" is 2 pixels, if the following
+ *      data is less than 256 pixels long, otherwise it is 4 pixels.
+ *      This is enforced by a post-process merge.
  *
- * 	Part 1 can be done in two different ways, depending on whether
- * 	FASTRUNS is defined or not.  With FASTRUNS defined, it finds
- * 	runs of the background pixel value in each channel
- * 	independently, and then merges the results.  With FASTRUNS not
- * 	defined, it scans all channels in parallel.
+ *      Part 1 can be done in two different ways, depending on whether
+ *      FASTRUNS is defined or not.  With FASTRUNS defined, it finds
+ *      runs of the background pixel value in each channel
+ *      independently, and then merges the results.  With FASTRUNS not
+ *      defined, it scans all channels in parallel.
  *
- * 	Part 2 uses a state machine.  For each run of non-background
- * 	data, it searches for sufficiently long sequences of a single
- * 	value (in each channel independently).  Sufficiently long is 4
- * 	pixels if the following data is < 256 pixels, 6 pixels
- * 	otherwise.  This is because the startup cost for the run is 2
- * 	bytes, and the startup cost for a data segment is 2 bytes if
- * 	it is < 256 pixels long, 4 bytes otherwise.  Thus a run
- * 	shorter than 4 or 6 pixels (respectively) would actually make
- * 	the output longer.  An additional pixel is required if the
- * 	preceding data is an odd number of pixels long (because a
- * 	filler byte will be output at the end of it.)
+ *      Part 2 uses a state machine.  For each run of non-background
+ *      data, it searches for sufficiently long sequences of a single
+ *      value (in each channel independently).  Sufficiently long is 4
+ *      pixels if the following data is < 256 pixels, 6 pixels
+ *      otherwise.  This is because the startup cost for the run is 2
+ *      bytes, and the startup cost for a data segment is 2 bytes if
+ *      it is < 256 pixels long, 4 bytes otherwise.  Thus a run
+ *      shorter than 4 or 6 pixels (respectively) would actually make
+ *      the output longer.  An additional pixel is required if the
+ *      preceding data is an odd number of pixels long (because a
+ *      filler byte will be output at the end of it.)
  */
 
 void
 rle_putrow(rows, rowlen, the_hdr)
-register rle_pixel *rows[];
+rle_pixel *rows[];
 int rowlen;
-register rle_hdr * the_hdr;
+rle_hdr * the_hdr;
 {
-    register int i, j;
+    int i, j;
     int nrun;
-    register rle_pixel *row;
+    rle_pixel *row;
     int mask;
     char bits[256];
-    short   state,		/* State of run-finding state machine. */
-	    dstart,		/* Starting point for current data segment. */
-    	    dend,		/* Ending point of current data segment. */
-	    rstart = 0,		/* Starting point of current run. */
-	    runval = 0;		/* Data value for current run. */
+    short   state,              /* State of run-finding state machine. */
+            dstart,             /* Starting point for current data segment. */
+            dend,               /* Ending point of current data segment. */
+            rstart = 0,         /* Starting point of current run. */
+            runval = 0;         /* Data value for current run. */
 
     if (rows == NULL)
     {
-	the_hdr->priv.put.nblank += rowlen;
-	return;
+        the_hdr->priv.put.nblank += rowlen;
+        return;
     }
-    /* 
+    /*
      * If not done already, allocate space to remember runs of
      * non-background color.  A run of bg color must be at least 2
      * bytes long to count, so there can be at most rowlen/3 of them.
      */
     if ( PBRUN == NULL )
     {
-	PBRUN = (short (*)[2])malloc(
-	    (unsigned)((rowlen/3 + 1) * 2 * sizeof(short)) );
-	if ( PBRUN == NULL )
-	{
-	    fprintf( stderr, "%s: Malloc failed in rle_putrow, writing %s\n",
-		     the_hdr->cmd, the_hdr->file_name );
-	    exit(1);
-	}
+        PBRUN = (short (*)[2])malloc(
+            (unsigned)((rowlen/3 + 1) * 2 * sizeof(short)) );
+        if ( PBRUN == NULL )
+        {
+            fprintf( stderr, "%s: Malloc failed in rle_putrow, writing %s\n",
+                     the_hdr->cmd, the_hdr->file_name );
+            exit(1);
+        }
     }
     /* Unpack bitmask in the_hdr struct */
     for ( i=0; i < the_hdr->ncolors; i++ )
-	bits[i] = RLE_BIT( *the_hdr, i );
+        bits[i] = RLE_BIT( *the_hdr, i );
     bits[255] = RLE_BIT( *the_hdr, -1 );
 
-    /* 
+    /*
      * If saving only non-background pixels, find runs of them.  Note
      * that the alpha channel is considered to be background iff it is
      * zero.
      */
-#ifdef	FASTRUNS
+#ifdef  FASTRUNS
     if ( the_hdr->background )
     {
-	/* 
-	 * Find runs in each color individually, merging them as we go.
-	 */
-	nrun = 0;		/* start out with no runs */
-	/* Alpha channel first */
-	if ( the_hdr->alpha )
-	    nrun = findruns( rows[-1], rowlen, 0, nrun, PBRUN );
-	/* Now the color channels */
-	for ( i = 0; i < the_hdr->ncolors; i++ )
-	    if ( bits[i] )
-		nrun = findruns( rows[i], rowlen, the_hdr->bg_color[i],
-				 nrun, PBRUN );
+        /*
+         * Find runs in each color individually, merging them as we go.
+         */
+        nrun = 0;               /* start out with no runs */
+        /* Alpha channel first */
+        if ( the_hdr->alpha )
+            nrun = findruns( rows[-1], rowlen, 0, nrun, PBRUN );
+        /* Now the color channels */
+        for ( i = 0; i < the_hdr->ncolors; i++ )
+            if ( bits[i] )
+                nrun = findruns( rows[i], rowlen, the_hdr->bg_color[i],
+                                 nrun, PBRUN );
     }
     else
     {
-	PBRUN[0][0] = 0;
-	PBRUN[0][1] = rowlen-1;
-	nrun = 1;
+        PBRUN[0][0] = 0;
+        PBRUN[0][1] = rowlen-1;
+        nrun = 1;
     }
-#else				/* FASTRUNS */
-    if (the_hdr->background)	/* find non-background runs */
+#else                           /* FASTRUNS */
+    if (the_hdr->background)    /* find non-background runs */
     {
-	j = 0;
-	for (i=0; i<rowlen; i++)
-	    if (!same_color( i, rows, the_hdr->bg_color,
-			     the_hdr->ncolors, bits ) ||
-		(the_hdr->alpha && rows[-1][i] != 0))
-	    {
-		if (j > 0 && i - PBRUN[j-1][1] <= 2)
-		    j--;
-		else
-		    PBRUN[j][0] = i; /* start of run */
-		for ( i++;
-		      i < rowlen && 
-			( !same_color( i, rows, the_hdr->bg_color,
-					 the_hdr->ncolors, bits ) ||
-			  (the_hdr->alpha && rows[-1][i] != 0) );
-		      i++)
-		    ;			/* find the end of this run */
-		PBRUN[j][1] = i-1;    /* last in run */
-		j++;
-	    }
-	nrun = j;
+        j = 0;
+        for (i=0; i<rowlen; i++)
+            if (!same_color( i, rows, the_hdr->bg_color,
+                             the_hdr->ncolors, bits ) ||
+                (the_hdr->alpha && rows[-1][i] != 0))
+            {
+                if (j > 0 && i - PBRUN[j-1][1] <= 2)
+                    j--;
+                else
+                    PBRUN[j][0] = i; /* start of run */
+                for ( i++;
+                      i < rowlen &&
+                        ( !same_color( i, rows, the_hdr->bg_color,
+                                         the_hdr->ncolors, bits ) ||
+                          (the_hdr->alpha && rows[-1][i] != 0) );
+                      i++)
+                    ;                   /* find the end of this run */
+                PBRUN[j][1] = i-1;    /* last in run */
+                j++;
+            }
+        nrun = j;
     }
     else
     {
-	PBRUN[0][0] = 0;
-	PBRUN[0][1] = rowlen-1;
-	nrun = 1;
+        PBRUN[0][0] = 0;
+        PBRUN[0][1] = rowlen-1;
+        nrun = 1;
     }
-#endif				/* FASTRUNS */
+#endif                          /* FASTRUNS */
     /* One final pass merges runs with fewer than 4 intervening pixels
      * if the second run is longer than 255 pixels.  This is because
      * the startup cost for such a run is 4 bytes.
      */
     if ( nrun > 1 )
     {
-	for ( i = nrun - 1; i > 0; i-- )
-	{
-	    if ( PBRUN[i][1] - PBRUN[i][0] > 255 &&
-		 PBRUN[i-1][1] + 4 > PBRUN[i][0] )
-	    {
-		PBRUN[i-1][1] = PBRUN[i][1];
-		for ( j = i; j < nrun - 1; j++ )
-		{
-		    PBRUN[j][0] = PBRUN[j+1][0];
-		    PBRUN[j][1] = PBRUN[j+1][1];
-		}
-		nrun--;
-	    }
-	}
+        for ( i = nrun - 1; i > 0; i-- )
+        {
+            if ( PBRUN[i][1] - PBRUN[i][0] > 255 &&
+                 PBRUN[i-1][1] + 4 > PBRUN[i][0] )
+            {
+                PBRUN[i-1][1] = PBRUN[i][1];
+                for ( j = i; j < nrun - 1; j++ )
+                {
+                    PBRUN[j][0] = PBRUN[j+1][0];
+                    PBRUN[j][1] = PBRUN[j+1][1];
+                }
+                nrun--;
+            }
+        }
     }
 
     if (nrun > 0)
     {
-	if (the_hdr->priv.put.nblank > 0)
-	{
-	    SkipBlankLines(the_hdr->priv.put.nblank);
-	    the_hdr->priv.put.nblank = 0;
-	}
-	for ( mask = (the_hdr->alpha ? -1 : 0);
-	      mask < the_hdr->ncolors;
-	      mask++)			/* do all colors */
-	{
-	    if ( ! bits[mask & 0xff] )
-	    {
-		continue;
-	    }
-	    row = rows[mask];
-	    SetColor(mask);
-	    if (PBRUN[0][0] > 0)
-	    {
-		SkipPixels(PBRUN[0][0], FALSE, FALSE);
-	    }
-	    for (j=0; j<nrun; j++)
-	    {
-		state = DATA;
-		dstart = PBRUN[j][0];
-		dend = PBRUN[j][1];
-		for (i=dstart; i<=dend; i++)
-		{
-		    switch(state)
-		    {
-		    case DATA:
-			if (i > dstart && runval == row[i])
-			{
-			    /* 2 in a row may be a run. */
-			    /* If odd data length, start with RUN1 */
-			    if ( ((i - dstart) % 2) == 0)
-				state = RUN1;
-			    else
-				state = RUN2;
-			}
-			else
-			{
-			    runval = row[i];	/* maybe a run starts here? */
-			    rstart = i;
-			}
-			break;
-	    
-		    case RUN4:
-			if (runval == row[i])
-			{
-			    /* If the following data might be longer
-			     * than 255 pixels then look for 8 in a
-			     * row, otherwise, 6 in a row is
-			     * sufficient.  Fake this by skipping to
-			     * state RUN5.
-			     */
-			    if ( dend - i > 255 )
-				state  = RUN5;	/* Need some more. */
-			    else
-				state = RUN7;	/* Next one makes a run. */
-			    
-			}
-			else
-			{
-			    state = DATA;	/* Nope, back to data */
-			    runval = row[i];	/* but maybe a new run here? */
-			    rstart = i;
-			}
-			break;
-
-		    case RUN1:
-		    case RUN2:
-		    case RUN3:
-		    case RUN5:
-		    case RUN6:
-			if (runval == row[i])
-			{
-			    /* Move to the next state. */
-			    state++;
-			}
-			else
-			{
-			    state = DATA;	/* Nope, back to data */
-			    runval = row[i];	/* but maybe a new run here? */
-			    rstart = i;
-			}
-			break;
-
-
-		    case RUN7:
-			if (runval == row[i])	/* enough in a row for a run */
-			{
-			    state = INRUN;
-			    putdata(row + dstart, rstart - dstart);
+        if (the_hdr->priv.put.nblank > 0)
+        {
+            SkipBlankLines(the_hdr->priv.put.nblank);
+            the_hdr->priv.put.nblank = 0;
+        }
+        for ( mask = (the_hdr->alpha ? -1 : 0);
+              mask < the_hdr->ncolors;
+              mask++)                   /* do all colors */
+        {
+            if ( ! bits[mask & 0xff] )
+            {
+                continue;
+            }
+            row = rows[mask];
+            SetColor(mask);
+            if (PBRUN[0][0] > 0)
+            {
+                SkipPixels(PBRUN[0][0], FALSE, FALSE);
+            }
+            for (j=0; j<nrun; j++)
+            {
+                state = DATA;
+                dstart = PBRUN[j][0];
+                dend = PBRUN[j][1];
+                for (i=dstart; i<=dend; i++)
+                {
+                    switch(state)
+                    {
+                    case DATA:
+                        if (i > dstart && runval == row[i])
+                        {
+                            /* 2 in a row may be a run. */
+                            /* If odd data length, start with RUN1 */
+                            if ( ((i - dstart) % 2) == 0)
+                                state = RUN1;
+                            else
+                                state = RUN2;
+                        }
+                        else
+                        {
+                            runval = row[i];    /* maybe a run starts here? */
+                            rstart = i;
+                        }
+                        break;
+
+                    case RUN4:
+                        if (runval == row[i])
+                        {
+                            /* If the following data might be longer
+                             * than 255 pixels then look for 8 in a
+                             * row, otherwise, 6 in a row is
+                             * sufficient.  Fake this by skipping to
+                             * state RUN5.
+                             */
+                            if ( dend - i > 255 )
+                                state  = RUN5;  /* Need some more. */
+                            else
+                                state = RUN7;   /* Next one makes a run. */
+
+                        }
+                        else
+                        {
+                            state = DATA;       /* Nope, back to data */
+                            runval = row[i];    /* but maybe a new run here? */
+                            rstart = i;
+                        }
+                        break;
+
+                    case RUN1:
+                    case RUN2:
+                    case RUN3:
+                    case RUN5:
+                    case RUN6:
+                        if (runval == row[i])
+                        {
+                            /* Move to the next state. */
+                            state++;
+                        }
+                        else
+                        {
+                            state = DATA;       /* Nope, back to data */
+                            runval = row[i];    /* but maybe a new run here? */
+                            rstart = i;
+                        }
+                        break;
+
+
+                    case RUN7:
+                        if (runval == row[i])   /* enough in a row for a run */
+                        {
+                            state = INRUN;
+                            putdata(row + dstart, rstart - dstart);
 #ifdef FASTRUNS
-#ifdef LOCC
-			    /* Shortcut to find end of run! */
-			    i = dend - skpc( (char *)row + i, dend + 1 - i,
-					     runval );
-#else
-			    while ( row[++i] == runval && i <= dend)
-				; /* not quite so good, but not bad */
-			    i--;
-#endif /* LOCC */
+                            while ( row[++i] == runval && i <= dend)
+                                ; /* not quite so good, but not bad */
+                            i--;
 #endif /* FASTRUNS */
-			}
-			else
-			{
-			    state = DATA;		/* not a run, */
-			    runval = row[i];	/* but may this starts one */
-			    rstart = i;
-			}
-			break;
-	    
-		    case INRUN:
-			if (runval != row[i])	/* if run out */
-			{
-			    state = DATA;
-			    putrun(runval, i - rstart, FALSE);
-			    runval = row[i];	/* who knows, might be more */
-			    rstart = i;
-			    dstart = i;	/* starting a new 'data' run */
-			}
-			break;
-		    }
-		}
-		if (state == INRUN)
-		    putrun(runval, i - rstart, TRUE);	/* last bit */
-		else
-		    putdata(row + dstart, i - dstart);
-
-		if (j < nrun-1)
-		    SkipPixels(
-			    PBRUN[j+1][0] - dend - 1,
-			    FALSE, state == INRUN);
-		else
-		{
-		    if (rowlen - dend > 0)
-			SkipPixels(
-			    rowlen - dend - 1,
-			    TRUE, state == INRUN);
-		}
-	    }
-
-	    if ( mask != the_hdr->ncolors - 1 )
-		NewScanLine(FALSE);
-	}
+                        }
+                        else
+                        {
+                            state = DATA;               /* not a run, */
+                            runval = row[i];    /* but may this starts one */
+                            rstart = i;
+                        }
+                        break;
+
+                    case INRUN:
+                        if (runval != row[i])   /* if run out */
+                        {
+                            state = DATA;
+                            putrun(runval, i - rstart, FALSE);
+                            runval = row[i];    /* who knows, might be more */
+                            rstart = i;
+                            dstart = i; /* starting a new 'data' run */
+                        }
+                        break;
+                    }
+                }
+                if (state == INRUN)
+                    putrun(runval, i - rstart, TRUE);   /* last bit */
+                else
+                    putdata(row + dstart, i - dstart);
+
+                if (j < nrun-1)
+                    SkipPixels(
+                            PBRUN[j+1][0] - dend - 1,
+                            FALSE, state == INRUN);
+                else
+                {
+                    if (rowlen - dend > 0)
+                        SkipPixels(
+                            rowlen - dend - 1,
+                            TRUE, state == INRUN);
+                }
+            }
+
+            if ( mask != the_hdr->ncolors - 1 )
+                NewScanLine(FALSE);
+        }
     }
 
     /* Increment to next scanline */
@@ -517,55 +503,30 @@ register rle_hdr * the_hdr;
 
 
 /*****************************************************************
- * TAG( rle_skiprow )
- * 
- * Skip rows in RLE file.
- * Inputs:
- * 	the_hdr:    	Header struct for RLE output file.
- *  	nrow:	    	Number of rows to skip.
- * Outputs:
- * 	Increments the nblank field in the the_hdr struct, so that a Skiplines
- *  	code will be output the next time rle_putrow or rle_putraw is called.
- * Assumptions:
- * 	Only effective when called between rle_putrow or rle_putraw calls (or
- *  	some other routine that follows the same conventions.
- * Algorithm:
- *	[None]
- */
-void
-rle_skiprow( the_hdr, nrow )
-rle_hdr *the_hdr;
-int nrow;
-{
-    the_hdr->priv.put.nblank += nrow;
-}
-
-
-/*****************************************************************
  * TAG( rle_put_init )
- * 
- * Initialize the header structure for writing scanlines. 
+ *
+ * Initialize the header structure for writing scanlines.
  * Inputs:
- *	[None]
+ *      [None]
  * Outputs:
- * 	the_hdr:	Private portions initialized for output.
+ *      the_hdr:        Private portions initialized for output.
  * Assumptions:
- *	[None]
+ *      [None]
  * Algorithm:
- *	[None]
+ *      [None]
  */
 void
 rle_put_init( the_hdr )
-register rle_hdr *the_hdr;
+rle_hdr *the_hdr;
 {
     the_hdr->dispatch = RUN_DISPATCH;
 
     if ( the_hdr->is_init != RLE_INIT_MAGIC )
     {
-	the_hdr->cmd = "Urt";
-	the_hdr->file_name = "some file";
+        the_hdr->cmd = "Urt";
+        the_hdr->file_name = "some file";
     }
-    the_hdr->priv.put.nblank = 0;	/* Reinit static vars */
+    the_hdr->priv.put.nblank = 0;       /* Reinit static vars */
     /* Would like to be able to free previously allocated storage,
      * but can't count on a non-NULL value being a valid pointer.
      */
@@ -574,37 +535,37 @@ register rle_hdr *the_hdr;
 
     /* Only save alpha if alpha AND alpha channel bit are set. */
     if ( the_hdr->alpha )
-	the_hdr->alpha = (RLE_BIT( *the_hdr, -1 ) != 0);
+        the_hdr->alpha = (RLE_BIT( *the_hdr, -1 ) != 0);
     else
-	RLE_CLR_BIT( *the_hdr, -1 );
+        RLE_CLR_BIT( *the_hdr, -1 );
 }
 
 /*****************************************************************
  * TAG( rle_put_setup )
- * 
+ *
  * Initialize for writing RLE, and write header to output file.
  * Inputs:
- * 	the_hdr:	Describes output image.
+ *      the_hdr:        Describes output image.
  * Outputs:
- * 	the_hdr:	Initialized.
+ *      the_hdr:        Initialized.
  * Assumptions:
- *	Lots of them.
+ *      Lots of them.
  * Algorithm:
- *	[None]
+ *      [None]
  */
 void
 rle_put_setup( the_hdr )
-register rle_hdr * the_hdr;
+rle_hdr * the_hdr;
 {
     rle_put_init( the_hdr );
-    the_hdr->img_num++;		/* Count output images. */
+    the_hdr->img_num++;         /* Count output images. */
     Setup();
 }
 
 void
 DefaultBlockHook(rle_hdr * the_hdr)
 {
-    					/* Do nothing */
+                                        /* Do nothing */
 }
 
 /*****************************************************************
@@ -613,18 +574,18 @@ DefaultBlockHook(rle_hdr * the_hdr)
  */
 void
 rle_puteof( the_hdr )
-register rle_hdr * the_hdr;
+rle_hdr * the_hdr;
 {
     /* Don't puteof twice. */
     if ( the_hdr->dispatch == NO_DISPATCH )
-	return;
+        return;
     PutEof();
     fflush( the_hdr->rle_file );
     /* Free storage allocated by rle_put_init. */
     if ( PBRUN != NULL )
     {
-	free( PBRUN );
-	PBRUN = NULL;
+        free( PBRUN );
+        PBRUN = NULL;
     }
     /* Signal that puteof has been called. */
     the_hdr->dispatch = NO_DISPATCH;
@@ -633,97 +594,33 @@ register rle_hdr * the_hdr;
 #ifndef FASTRUNS
 /*****************************************************************
  * TAG( same_color )
- * 
+ *
  * Determine if the color at the given index position in the scan rows
  * is the same as the background color.
  * Inputs:
- * 	index:	    Index to the pixel position in each row.
- *	rows:	    array of pointers to the scanlines
- *	bg_color:   the background color
- *	ncolors:    number of color elements/pixel
+ *      index:      Index to the pixel position in each row.
+ *      rows:       array of pointers to the scanlines
+ *      bg_color:   the background color
+ *      ncolors:    number of color elements/pixel
  * Outputs:
- * 	TRUE if the color at row[*][i] is the same as bg_color[*].
+ *      TRUE if the color at row[*][i] is the same as bg_color[*].
  * Assumptions:
- *	[None]
+ *      [None]
  * Algorithm:
- *	[None]
+ *      [None]
  */
 static int
 same_color( index, rows, bg_color, ncolors, bits )
-register rle_pixel *rows[];
-register int bg_color[];
+rle_pixel *rows[];
+int bg_color[];
 char *bits;
 {
-    register int i;
+    int i;
 
     for ( i = 0; i < ncolors; i++, bits++ )
-	if ( *bits &&
-	     rows[i][index] != bg_color[i] )
-	    return 0;
-    return 1;				/* all the same */
+        if ( *bits &&
+             rows[i][index] != bg_color[i] )
+            return 0;
+    return 1;                           /* all the same */
 }
 #endif /* !FASTRUNS */
-
-/*****************************************************************
- * TAG( rgb_to_bw )
- * 
- * Perform the NTSC Y transform on RGB data to get B&W data.
- * Inputs:
- * 	red_row, green_row, blue_row:	Given RGB pixel data.
- *	rowlen:	    Number of pixels in the rows.
- * Outputs:
- * 	bw_row:	    Output B&W data.  May coincide with one of the
- *		    inputs.
- * Assumptions:
- *	[None]
- * Algorithm:
- * 	BW = .30*R + .59*G + .11*B
- */
-void
-rgb_to_bw( red_row, green_row, blue_row, bw_row, rowlen )
-rle_pixel *red_row;
-rle_pixel *green_row;
-rle_pixel *blue_row;
-rle_pixel *bw_row;
-int rowlen;
-{
-    register int x, bw;
-
-    for (x=0; x<rowlen; x++)
-    {
-	/* 68000 won't store float > 127 into byte? */
-	/* HP compiler blows it */
-	bw = 0.5 + .30*red_row[x] + .59*green_row[x] + .11*blue_row[x];
-	bw_row[x] = bw;
-    }
-}
-
-#ifdef LOCC
-/*ARGSUSED*/
-locc( p, l, c )
-register char *p;
-register int l;
-register int c;
-{
-    asm( "locc	r9,r10,(r11)" );
-#ifdef lint
-    c = (int) p;		/* why doesn't ARGSUSED work? */
-    l = c;
-    return l;			/* Needs return value, at least */
-#endif
-}
-
-/*ARGSUSED*/
-skpc( p, l, c )
-register char *p;
-register int l;
-register int c;
-{
-    asm( "skpc r9,r10,(r11)" );
-#ifdef lint
-    c = (int) p;		/* why doesn't ARGSUSED work? */
-    l = c;
-    return l;			/* Needs return value, at least */
-#endif
-}
-#endif
diff --git a/urt/rle_row_alc.c b/urt/rle_row_alc.c
index 982e1c5e..d7631744 100644
--- a/urt/rle_row_alc.c
+++ b/urt/rle_row_alc.c
@@ -1,14 +1,14 @@
 /*
  * This software is copyrighted as noted below.  It may be freely copied,
- * modified, and redistributed, provided that the copyright notice is 
+ * modified, and redistributed, provided that the copyright notice is
  * preserved on all copies.
- * 
+ *
  * There is no warranty or other guarantee of fitness for this software,
  * it is provided solely "as is".  Bug reports or fixes may be sent
  * to the author, who may or may not act on them as he desires.
  *
  * You may not include this software in a program or other software product
- * without supplying the source, or without informing the end-user that the 
+ * without supplying the source, or without informing the end-user that the
  * source is available for no extra charge.
  *
  * If you modify this software, you should include a notice giving the
@@ -18,13 +18,13 @@
  *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  *  to have all "void" functions so declared.
  */
-/* 
+/*
  * rle_row_alc.c - Allocate buffers for rle_getrow/rle_putrow.
- * 
- * Author:	Spencer W. Thomas
- * 		Computer Science Dept.
- * 		University of Utah
- * Date:	Fri Nov 14 1986
+ *
+ * Author:      Spencer W. Thomas
+ *              Computer Science Dept.
+ *              University of Utah
+ * Date:        Fri Nov 14 1986
  * Copyright (c) 1986, Spencer W. Thomas
  */
 
@@ -35,24 +35,24 @@
 
 /*****************************************************************
  * TAG( rle_row_alloc )
- * 
+ *
  * Allocate buffer space for use by rle_getrow and rle_putrow.
  * Inputs:
- * 	the_hdr:	Header structure for RLE file to be read or
- *			written.
+ *      the_hdr:        Header structure for RLE file to be read or
+ *                      written.
  * Outputs:
- *	scanp:		Pointer to pointer to created scanline buffer.
- *			This pointer is adjusted for the alpha channel,
- *			if present.
- *	Returns 0 for success, -1 if malloc failed.
+ *      scanp:          Pointer to pointer to created scanline buffer.
+ *                      This pointer is adjusted for the alpha channel,
+ *                      if present.
+ *      Returns 0 for success, -1 if malloc failed.
  * Assumptions:
- * 	No input scanline will extend beyond the declared xmax endpoint.
+ *      No input scanline will extend beyond the declared xmax endpoint.
  * Algorithm:
- *	Count number of channels actually used (check bitmap).
- * 	Allocate nchan*rowlength pixels, allocate a buffer
- *	to hold ncolors+alpha pointers, and give each channel
- *	rowlength pixels.  Rowlength is xmax + 1, to allow for rle_getrow
- *	usage.
+ *      Count number of channels actually used (check bitmap).
+ *      Allocate nchan*rowlength pixels, allocate a buffer
+ *      to hold ncolors+alpha pointers, and give each channel
+ *      rowlength pixels.  Rowlength is xmax + 1, to allow for rle_getrow
+ *      usage.
  */
 int
 rle_row_alloc( the_hdr, scanp )
@@ -64,33 +64,33 @@ rle_pixel ***scanp;
 
     rowlen = the_hdr->xmax + 1;
     if ( the_hdr->alpha && RLE_BIT( *the_hdr, RLE_ALPHA ) )
-	nchan++;
+        nchan++;
     for ( i = 0; i < the_hdr->ncolors; i++ )
-	if ( RLE_BIT( *the_hdr, i ) )
-	     nchan++;
+        if ( RLE_BIT( *the_hdr, i ) )
+             nchan++;
 
     ncol = the_hdr->ncolors + the_hdr->alpha;
 
     if ( (scanbuf = (rle_pixel **)malloc( ncol * sizeof(rle_pixel *) )) == 0 )
-	return -1;
+        return -1;
     if ( (pixbuf = (rle_pixel *)malloc( nchan * rowlen *
-				       sizeof(rle_pixel) )) == 0 )
+                                       sizeof(rle_pixel) )) == 0 )
     {
-	free( scanbuf );
-	return -1;
+        free( scanbuf );
+        return -1;
     }
 
     if ( the_hdr->alpha )
-	scanbuf++;
+        scanbuf++;
 
     for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ )
-	if ( RLE_BIT( *the_hdr, i ) )
-	{
-	    scanbuf[i] = pixbuf;
-	    pixbuf += rowlen;
-	}
-	else
-	    scanbuf[i] = 0;
+        if ( RLE_BIT( *the_hdr, i ) )
+        {
+            scanbuf[i] = pixbuf;
+            pixbuf += rowlen;
+        }
+        else
+            scanbuf[i] = 0;
     *scanp = scanbuf;
 
     return 0;
@@ -99,18 +99,18 @@ rle_pixel ***scanp;
 
 /*****************************************************************
  * TAG( rle_row_free )
- * 
+ *
  * Free storage allocated by rle_row_alloc().
  * Inputs:
- * 	the_hdr:	Header structure as above.
- *	scanp:		Pointer to scanbuf above.
+ *      the_hdr:        Header structure as above.
+ *      scanp:          Pointer to scanbuf above.
  * Outputs:
- * 	Frees storage referenced by scanp and nrawp.
+ *      Frees storage referenced by scanp and nrawp.
  * Assumptions:
- * 	Storage was allocated by rle_row_alloc, or by use of same
- *	algorithm, at least.
+ *      Storage was allocated by rle_row_alloc, or by use of same
+ *      algorithm, at least.
  * Algorithm:
- * 	free scanp[0] and scanp.
+ *      free scanp[0] and scanp.
  */
 void
 rle_row_free( the_hdr, scanp )
@@ -120,12 +120,12 @@ rle_pixel **scanp;
     int i;
 
     if ( the_hdr->alpha )
-	scanp--;
+        scanp--;
     for ( i = 0; i < the_hdr->ncolors + the_hdr->alpha; i++ )
-	if ( scanp[i] != 0 )
-	{
-	    free( (char *)scanp[i] );
-	    break;
-	}
+        if ( scanp[i] != 0 )
+        {
+            free( (char *)scanp[i] );
+            break;
+        }
     free( (char *)scanp );
 }
diff --git a/urt/scanargs.c b/urt/scanargs.c
deleted file mode 100644
index 1dcdd235..00000000
--- a/urt/scanargs.c
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- * $Id: scanargs.c,v 3.0.1.3 1992/02/27 21:18:14 spencer Exp $
- *              Version 7 compatible
- *      Argument scanner, scans argv style argument list.
- *
- *      Some stuff is a kludge because sscanf screws up
- *
- *      Gary Newman - 10/4/1979 - Ampex Corp.
- *
- *      Modified by Spencer W. Thomas, Univ. of Utah, 5/81 to
- *      add args introduced by  a flag, add qscanargs call,
- *      allow empty flags.
- *
- *      If you make improvements we'd like to get them too.
- *      Jay Lepreau     lepreau@utah-20, decvax!harpo!utah-cs!lepreau
- *      Spencer Thomas  thomas@utah-20, decvax!harpo!utah-cs!thomas
- *
- *      (I know the code is ugly, but it just grew, you see ...)
- *
- * Modified by: Spencer W. Thomas
- *      Date:   Feb 25 1983
- * 1. Fixed scanning of optional args.  Now args introduced by a flag
- *    must follow the flag which introduces them and precede any other
- *    flag argument.  It is still possible for a flag introduced
- *    argument to be mistaken for a "bare" argument which occurs
- *    earlier in the format string.  This implies that flags may not
- *    be conditional upon other flags, and a message will be generated
- *    if this is attempted.
- *
- * 2. Usage message can be formatted by inserting newlines, tabs and
- *    spaces into the format string.  This is especially useful for
- *    long argument lists.
- *
- * 3. Added n/N types for "numeric" args.  These args are scanned
- *    using the C language conventions - a number starting 0x is
- *    hexadecimal, a number starting with 0 is octal, otherwise it is
- *    decimal.
- *
- *  Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
- *  to have all "void" functions so declared.
- */
-
-#include <stdio.h>
-#include <ctype.h>
-#include <stdarg.h>
-
-#include "netpbm/pm_c_util.h"
-#include "netpbm/nstring.h"
-#include "rle_config.h"
-#include "rle.h"
-
-/*
- * An explicit assumption is made in this code that all pointers look
- * alike, except possible char * pointers.
- */
-typedef int *ptr;
-
-#define YES 1
-#define NO 0
-#define ERROR(msg)  {fprintf(stderr, "%s\n", msg); goto error; }
-
-/*
- * Storage allocation macros
- */
-#define NEW( type, cnt )        (type *) malloc( (cnt) * sizeof( type ) )
-#define RENEW( type, ptr, cnt ) (type *) realloc( ptr, (cnt) * sizeof( type ) )
-
-static CONST_DECL char * prformat( CONST_DECL char *, int );
-static int isnum( CONST_DECL char *, int, int );
-static int      _do_scanargs( int argc, char **argv, CONST_DECL char *format,
-                              va_list argl );
-void            scan_usage( char **, CONST_DECL char * );
-
-/*
- * Argument list is (argc, argv, format, ... )
- */
-int
-scanargs ( int argc, char **argv, CONST_DECL char *format, ... )
-{
-    va_list argl;
-    int retval;
-    va_start( argl, format );
-    retval = _do_scanargs( argc, argv, format, argl );
-    va_end( argl );
-    return retval;
-}
-
-/*
- * This routine is necessary because of a pyramid compiler botch that
- * uses parameter registers in a varargs routine.  The extra
- * subroutine call isolates the args on the register stack so they
- * don't get trashed.
- */
-
-static int
-_do_scanargs( argc, argv, format, argl )
-int     argc;                   /* Actual arguments */
-char  **argv;
-CONST_DECL char   *format;
-va_list argl;
-{
-
-    int    check;                       /* check counter to be sure all argvs
-                                           are processed */
-    register CONST_DECL char  *cp;
-    int    cnt;
-    int     optarg = 0;                 /* where optional args start */
-    int     nopt = 0;
-    char    tmpflg,                     /* temp flag */
-            typchr;                     /* type char from format string */
-    char    c;
-    bool  * arg_used;                   /* array of flags */
-    ptr     aptr = 0;                   /* pointer to return loc */
-
-    bool    required;
-    int     excnt;                      /* which flag is set */
-    unsigned int exflag;                /* How many of a set of exclusive
-                                           flags is set */
-
-    bool    list_of;                    /* set if parsing off a list of args */
-    bool    comma_list;                 /* set if AT&T style multiple args */
-    bool    no_usage;                   /* If set, don't print usage msg. */
-    bool    help = NO;                  /* If set, always print usage. */
-    int   * cnt_arg = 0;                /* where to stuff list count */
-    int     list_cnt;                   /* how many in list */
-    /* These are used to build return lists */
-    char ** strlist = 0;
-    int   * intlist = 0;
-    long  * longlist = 0;
-    float * fltlist = 0;
-    double *dbllist = 0;
-    char  * argp;                       /* Pointer to argument. */
-
-    CONST_DECL char   *ncp;             /* remember cp during flag scanning */
-    static char   cntrl[7] = "%  %1s";  /* control string for scanf's */
-    char    junk[2];                    /* junk buffer for scanf's */
-
-    /* Set up for argument counting. */
-    arg_used = NEW( bool, argc );
-    if (arg_used == NULL)
-    {
-        fprintf(stderr, "malloc failed in scanargs, exiting\n");
-        exit(-1);
-    }
-    else
-    {
-        for (cnt=0; cnt<argc; cnt++)
-            arg_used[cnt] = NO;
-    }
-    check = 0;
-
-    /* Scan for -help in arg list. */
-    for ( cnt=1; cnt<argc; cnt++ )
-        if ( strcmp( argv[cnt], "-help" ) == 0 )
-        {
-            check += cnt;
-            arg_used[cnt] = YES;
-            if ( argc == 2 )
-            {
-                scan_usage( argv, format );
-                return 0;
-            }
-            else
-                help = YES;
-        }
-
-    /* If format string ends in @, don't print a usage message. */
-    no_usage = *(format + strlen( format ) - 1) == '&';
-
-    cp = format;
-    /*
-     * Skip program name
-     */
-    while ( *cp != ' ' && *cp != '\t' && *cp != '\n' && *cp != '\0' )
-        cp++;
-
-    while (*cp)
-    {
-        required = NO;                  /* reset per-arg flags */
-        list_of = NO;
-        comma_list = NO;
-        list_cnt = 0;
-        switch (*(cp++))
-        {
-            default:                    /* all other chars */
-                break;
-            case ' ':                   /* separators */
-            case '\t':
-            case '\n':
-                optarg = 0;             /* end of optional arg string */
-                break;
-
-            case '(':                   /* Surrounds a comment. */
-            {
-                int depth = 1;          /* Count parenthesis depth. */
-                while ( *cp && depth > 0 )
-                    switch ( *(cp++) )
-                    {
-                    case '(':   depth++;                break;
-                    case ')':   depth--;                break;
-                    }
-                break;
-            }
-
-            case '!':                   /* required argument */
-                required = YES;
-            case '%':                   /* not required argument */
-reswitch:                               /* after finding '*' or ',' */
-                switch (typchr = *(cp++))
-                {
-                    case ',':           /* argument is AT&T list of things */
-                        comma_list = YES;
-                    case '*':           /* argument is list of things */
-                        list_of = YES;
-                        list_cnt = 0;   /* none yet */
-                        cnt_arg = va_arg( argl, int *); /* item count * here */
-                        goto reswitch;  /* try again */
-
-                    case '$':           /* "rest" of argument list */
-                        while ( argc > 1 && !arg_used[argc-1] )
-                            argc--;     /* find last used argument */
-                        *va_arg( argl, int * ) = argc;
-                        break;
-
-                    case '&':           /* Return unused args. */
-                        /* Count how many.  Always include argv[0]. */
-                        for ( nopt = cnt = 1; cnt < argc; cnt++ )
-                            if ( !arg_used[cnt] )
-                                nopt++;
-                        if ( nopt == 1 )
-                            nopt = 0;   /* Special case for no args. */
-                        if ( nopt > 0 )
-                        {
-                            strlist = NEW( char *, nopt + 1 );
-                            /* Copy program name, for sure. */
-                            strlist[0] = argv[0];
-                            for ( nopt = cnt = 1; cnt < argc; cnt++ )
-                                if ( !arg_used[cnt] )
-                                {
-                                    strlist[nopt++] = argv[cnt];
-                                    check += cnt;
-                                    arg_used[cnt] = 1;
-                                }
-                            strlist[nopt] = NULL;
-                        }
-                        else
-                            strlist = NULL;     /* No args, return empty. */
-
-                        /* Return count and arg list. */
-                        *va_arg( argl, int * ) = nopt;
-                        *va_arg( argl, char *** ) = strlist;
-                        break;
-
-                    case '-':           /* argument is flag */
-                        if (optarg > 0)
-                            ERROR("Format error: flag conditional on flag not allowed");
-
-                    /* go back to label */
-                        ncp = cp-1;     /* remember */
-                        cp -= 3;
-                        for (excnt = exflag = 0
-                                ; *cp != ' ' && !(*cp=='-' &&(cp[-1]=='!'||cp[-1]=='%'));
-                                (--cp, excnt++))
-                        {
-                            for (cnt = optarg+1; cnt < argc; cnt++)
-                            {
-                            /* flags all start with - */
-                                if (*argv[cnt] == '-' && !arg_used[cnt] &&
-                                        !ISDIGIT(argv[cnt][1]))
-                                    if (*(argv[cnt] + 1) == *cp)
-                                    {
-                                        if (*(argv[cnt] + 2) != 0)
-                                            ERROR ("extra flags ignored");
-                                        if (exflag)
-                                            ERROR ("more than one exclusive flag chosen");
-                                        exflag++;
-                                        required = NO;
-                                        check += cnt;
-                                        arg_used[cnt] = 1;
-                                        nopt = cnt;
-                                        *va_arg( argl, int *) |= (1 << excnt);
-                                        break;
-                                    }
-                            }
-                        }
-                        if (required)
-                            ERROR ("flag argument missing");
-                        cp = ncp;
-                        /*
-                         * If none of these flags were found, skip any
-                         * optional arguments (in the varargs list, too).
-                         */
-                        if (!exflag)
-                        {
-                            (void)va_arg( argl, int * );/* skip the arg, too */
-                            while (*++cp && ! ISSPACE(*cp))
-                                if (*cp == '!' || *cp == '%')
-                                {
-                                    if ( *++cp == '*' || *cp == ',' )
-                                    {
-                                        cp++;
-                                        (void)va_arg( argl, int * );
-                                    }
-                                    /*
-                                     * Assume that char * might be a
-                                     * different size, but that all
-                                     * other pointers are same size.
-                                     */
-                                    if ( *cp == 's' )
-                                        (void)va_arg( argl, char * );
-                                    else
-                                        (void)va_arg( argl, ptr );
-                                }
-                        }
-                        else
-                        {
-                            optarg = nopt;
-                            cp++;       /* skip over - */
-                        }
-
-                        break;
-
-                    case 's':           /* char string */
-                    case 'd':           /* decimal # */
-                    case 'o':           /* octal # */
-                    case 'x':           /* hexadecimal # */
-                    case 'n':           /* "number" in C syntax */
-                    case 'f':           /* floating # */
-                    case 'D':           /* long decimal # */
-                    case 'O':           /* long octal # */
-                    case 'X':           /* long hexadecimal # */
-                    case 'N':           /* long number in C syntax */
-                    case 'F':           /* double precision floating # */
-#if defined(sgi) && !defined(mips)
-                        /* Fix for broken SGI IRIS 2400/3000 floats */
-                        if ( typchr == 'F' ) typchr = 'f';
-#endif /* sgi */
-                        for (cnt = optarg+1; cnt < argc; cnt++)
-                        {
-                            argp = argv[cnt];
-
-                            if ( isnum( argp, typchr, comma_list ) )
-                            {
-                                ;       /* it's ok, then */
-                            }
-                            else if ( *argp == '-' && argp[1] != '\0' )
-                                if ( optarg > 0 ) /* end optional args? */
-                                {
-                                    /* Eat the arg, too, if necessary */
-                                    if ( list_cnt == 0 ) {
-                                        if ( typchr == 's' )
-                                            (void)va_arg( argl, char * );
-                                        else
-                                            (void)va_arg( argl, ptr );
-                    }
-                                    break;
-                                }
-                                else
-                                    continue;
-                            else if ( typchr != 's' )
-                                continue;       /* not number, keep looking */
-
-                            /*
-                             * Otherwise usable argument may already
-                             * be used.  (Must check this after
-                             * checking for flag, though.)
-                             */
-                            if (arg_used[cnt]) continue;
-
-                            /*
-                             * If it's a comma-and-or-space-separated
-                             * list then count how many, and separate
-                             * the list into an array of strings.
-                             */
-                            if ( comma_list )
-                            {
-                                register char * s;
-                                int pass;
-
-                                /*
-                                 * Copy the string so we remain nondestructive
-                                 */
-                                s = NEW( char, strlen(argp)+1 );
-                                strcpy( s, argp );
-                                argp = s;
-
-                                /*
-                                 * On pass 0, just count them.  On
-                                 * pass 1, null terminate each string
-                                 */
-                                for ( pass = 0; pass <= 1; pass++ )
-                                {
-                                    for ( s = argp; *s != '\0'; )
-                                    {
-                                        if ( pass )
-                                            strlist[list_cnt] = s;
-                                        while ( (c = *s) != '\0' && c != ' ' &&
-                                                c != '\t' && c != ',' )
-                                            s++;
-                                        if ( pass )
-                                            *s = '\0';
-
-                                        list_cnt++;     /* count separators */
-                                        /*
-                                         * Two commas in a row give a null
-                                         * string, but two spaces
-                                         * don't.  Also skip spaces
-                                         * after a comma.
-                                         */
-                                        if ( c != '\0' )
-                                            while ( *++s == ' ' || *s == '\t' )
-                                                ;
-                                    }
-                                    if ( pass == 0 )
-                                    {
-                                        strlist = NEW( char *, list_cnt );
-                                        list_cnt = 0;
-                                    }
-                                }
-                            }
-                            else if ( list_of )
-                                list_cnt++;   /* getting them one at a time */
-                            /*
-                             * If it's either type of list, then alloc
-                             * storage space for the returned values
-                             * (except that comma-separated string
-                             * lists already are done).
-                             */
-                            if ( list_of )
-                            {
-                                if ( list_cnt == 1 || comma_list )
-                                    switch( typchr )
-                                    {
-                                        case 's':
-                                            if ( !comma_list )
-                                                strlist = NEW( char *, 1 );
-                                            aptr = (ptr) &strlist[0];
-                                            break;
-                                        case 'n':
-                                        case 'd':
-                                        case 'o':
-                                        case 'x':
-                                            intlist = NEW( int, list_cnt );
-                                            aptr = (ptr) &intlist[0];
-                                            break;
-                                        case 'N':
-                                        case 'D':
-                                        case 'O':
-                                        case 'X':
-                                            longlist = NEW( long, list_cnt );
-                                            aptr = (ptr) &longlist[0];
-                                            break;
-                                        case 'f':
-                                            fltlist = NEW( float, list_cnt );
-                                            aptr = (ptr) &fltlist[0];
-                                            break;
-                                        case 'F':
-                                            dbllist = NEW( double, list_cnt );
-                                            aptr = (ptr) &dbllist[0];
-                                            break;
-                                    }
-                                else
-                                    switch( typchr )
-                                    {
-                                        case 's':
-                                            strlist = RENEW( char *, strlist,
-                                                             list_cnt );
-                                            aptr = (ptr) &strlist[list_cnt-1];
-                                            break;
-                                        case 'n':
-                                        case 'd':
-                                        case 'o':
-                                        case 'x':
-                                            intlist = RENEW( int, intlist,
-                                                             list_cnt );
-                                            aptr = (ptr) &intlist[list_cnt-1];
-                                            break;
-                                        case 'N':
-                                        case 'D':
-                                        case 'O':
-                                        case 'X':
-                                            longlist = RENEW( long, longlist,
-                                                              list_cnt );
-                                            aptr = (ptr) &longlist[list_cnt-1];
-                                            break;
-                                        case 'f':
-                                            fltlist = RENEW( float, fltlist,
-                                                             list_cnt );
-                                            aptr = (ptr) &fltlist[list_cnt-1];
-                                            break;
-                                        case 'F':
-                                            dbllist = RENEW( double, dbllist,
-                                                             list_cnt );
-                                            aptr = (ptr) &dbllist[list_cnt-1];
-                                            break;
-                                    }
-                            }
-                            else
-                                aptr = va_arg( argl, ptr );
-
-                            if ( typchr == 's' )
-                            {
-                                if ( ! comma_list )
-                                    *(char **)aptr = argp;
-                            }
-                            else
-                            {
-                                nopt = 0;
-                                do {
-                                    /*
-                                     * Need to update aptr if parsing
-                                     * a comma list
-                                     */
-                                    if ( comma_list && nopt > 0 )
-                                    {
-                                        argp = strlist[nopt];
-                                        switch( typchr )
-                                        {
-                                            case 'n':
-                                            case 'd':
-                                            case 'o':
-                                            case 'x':
-                                                aptr = (ptr) &intlist[nopt];
-                                                break;
-                                            case 'N':
-                                            case 'D':
-                                            case 'O':
-                                            case 'X':
-                                                aptr = (ptr) &longlist[nopt];
-                                                break;
-                                            case 'f':
-                                                aptr = (ptr) &fltlist[nopt];
-                                                break;
-                                            case 'F':
-                                                aptr = (ptr) &dbllist[nopt];
-                                                break;
-                                        }
-                                    }
-                                    /*
-                                     * Do conversion for n and N types
-                                     */
-                                    tmpflg = typchr;
-                                    if (typchr == 'n' || typchr == 'N' ) {
-                                        if (*argp != '0')
-                                            tmpflg = 'd';
-                                        else if (*(argp+1) == 'x' ||
-                                                 *(argp+1) == 'X')
-                                        {
-                                            tmpflg = 'x';
-                                            argp += 2;
-                                        }
-                                        else
-                                            tmpflg = 'o';
-                    }
-                                    if (typchr == 'N')
-                                        tmpflg = toupper( tmpflg );
-
-
-                                    /* put in conversion */
-                                    if ( isupper( tmpflg ) )
-                                    {
-                                        cntrl[1] = 'l';
-                                        cntrl[2] = tolower( tmpflg );
-                                    }
-                                    else
-                                    {
-                                        cntrl[1] = tmpflg;
-                                        cntrl[2] = ' ';
-                                    }
-                                    if (sscanf (argp, cntrl, aptr, junk) != 1)
-                                        ERROR ("Bad numeric argument");
-                                } while ( comma_list && ++nopt < list_cnt );
-                            }
-                            check += cnt;
-                            arg_used[cnt] = 1;
-                            required = NO;
-                            /*
-                             * If not looking for multiple args,
-                             * then done, otherwise, keep looking.
-                             */
-                            if ( !( list_of && !comma_list ) )
-                                break;
-                            else
-                                continue;
-                        }
-                        if (required)
-                            switch (typchr)
-                            {
-                                case 'x':
-                                case 'X':
-                                    ERROR ("missing hexadecimal argument");
-                                case 's':
-                                    ERROR ("missing string argument");
-                                case 'o':
-                                case 'O':
-                                    ERROR ("missing octal argument");
-                                case 'd':
-                                case 'D':
-                                    ERROR ("missing decimal argument");
-                                case 'f':
-                                case 'F':
-                                    ERROR ("missing floating argument");
-                                case 'n':
-                                case 'N':
-                                    ERROR ("missing numeric argument");
-                            }
-                        if ( list_cnt > 0 )
-                        {
-                            *cnt_arg = list_cnt;
-                            switch ( typchr )
-                            {
-                                case 's':
-                                    *va_arg( argl, char *** ) = strlist;
-                                    break;
-                                case 'n':
-                                case 'd':
-                                case 'o':
-                                case 'x':
-                                    *va_arg( argl, int ** ) = intlist;
-                                    break;
-                                case 'N':
-                                case 'D':
-                                case 'O':
-                                case 'X':
-                                    *va_arg( argl, long ** ) = longlist;
-                                    break;
-                                case 'f':
-                                    *va_arg( argl, float ** ) = fltlist;
-                                    break;
-                                case 'F':
-                                    *va_arg( argl, double **) = dbllist;
-                                    break;
-                            }
-                            if ( typchr != 's' && comma_list )
-                                free( (char *) strlist );
-                        }
-                        else if ( cnt >= argc )
-                        {
-                            /* Fell off end looking, so must eat the arg */
-                            if ( typchr == 's' )
-                                (void)va_arg( argl, char * );
-                            else
-                                (void)va_arg( argl, ptr );
-                        }
-                        break;
-                    default:            /* error */
-                        fprintf (stderr,
-                                 "scanargs: Corrupt or invalid format spec\n");
-                        return 0;
-                }
-        }
-    }
-
-    /*  Count up empty flags */
-    for (cnt=1; cnt<argc; cnt++)
-        if (argv[cnt][0] == '-' && argv[cnt][1] == '-' && argv[cnt][2] == 0
-            && !arg_used[cnt] )
-            check += cnt;
-
-    /* sum from 1 to N = n*(n+1)/2 used to count up checks */
-    if (check != (((argc - 1) * argc) / 2))
-        ERROR ("extra arguments not processed");
-
-    /* If -help, always print usage. */
-    if ( help )
-        scan_usage( argv, format );
-
-    free(arg_used);
-    return 1;
-
-error:
-    if ( !no_usage )
-        scan_usage( argv, format );
-    free(arg_used);
-    return 0;
-}
-
-void
-scan_usage( argv, format )
-char ** argv;
-CONST_DECL char * format;
-{
-    register CONST_DECL char * cp;
-
-    fprintf (stderr, "usage : ");
-    if (*(cp = format) != ' ')
-    {
-        if ( *cp == '%' )
-        {
-            /*
-             * This is bogus, but until everyone can agree on a name
-             * for (rindex/strrchr) ....
-             */
-            for ( cp = argv[0]; *cp != '\0'; cp++ )
-                ;                       /* find the end of the string */
-            for ( ; cp > argv[0] && *cp != '/'; cp-- )
-                ;                       /* find the last / */
-            if ( *cp == '/' )
-                cp++;
-            fprintf( stderr, "%s", cp );
-
-            cp = format + 1;            /* reset to where it should be */
-        }
-        while (putc (*cp++, stderr) != ' ');
-    }
-    else
-        fprintf (stderr, "?? ");
-    while (*cp == ' ')
-        cp++;
-    (void)prformat (cp, NO);
-}
-
-static CONST_DECL char *
-prformat (format, recurse)
-CONST_DECL char   *format;
-int     recurse;
-{
-    register CONST_DECL char  *cp;
-    bool    required, comma_list;
-    int    list_of, depth;
-
-    cp = format;
-    if (recurse)
-        putc (' ', stderr);
-
-    required = NO;
-    list_of = 0;
-    comma_list = NO;
-    while (*cp)
-    {
-        switch (*cp)
-        {
-            default:
-                cp++;
-                break;
-            case ' ':
-            case '\n':
-            case '\t':
-                /* allow annotations */
-                for ( ; format < cp; format++ )
-                    putc( *format, stderr );
-                putc(*cp, stderr);
-                format = ++cp;
-                break;
-
-            case '(':
-                /* Parentheses surround an arbitrary (parenthesis
-                 * balanced) comment.
-                 */
-                for ( ; format < cp; format++ )
-                    putc( *format, stderr );
-                for ( cp++, depth = 1; *cp && depth > 0; )
-                {
-                    /* Don't print last close paren. */
-                    if ( *cp != ')' || depth > 1 )
-                        putc( *cp, stderr );
-                    switch( *(cp++) )
-                    {
-                    case '(':   depth++;                break;
-                    case ')':   depth--;                break;
-                    }
-                }
-                format = cp;
-                break;
-
-            case '!':
-                required = YES;
-            case '%':
-reswitch:
-                switch (*++cp)
-                {
-                    case ',':
-                        comma_list = YES;
-                    case '*':
-                        list_of++;
-                        goto reswitch;
-
-                    case '$':           /* "rest" of argument list */
-                        if (!required)
-                            putc ('[', stderr);
-                        for (; format < cp - 1 - list_of; format++)
-                            putc (*format, stderr);
-                        fputs( " ...", stderr );
-                        if ( !required )
-                            putc( ']', stderr );
-                        break;
-
-                    case '-':           /* flags */
-                        if (!required)
-                            putc ('[', stderr);
-                        putc ('-', stderr);
-
-                        if (cp - format > 2 + list_of)
-                            putc ('{', stderr);
-                        cp = format;
-                        while (*cp != '%' && *cp != '!')
-                            putc (*cp++, stderr);
-                        if (cp - format > 1 + list_of)
-                            putc ('}', stderr);
-                        cp += 2;        /* skip !- or %- */
-                        if (*cp && !ISSPACE(*cp))
-                            cp = prformat (cp, YES);
-                                        /* this is a recursive call */
-
-                        cp--;   /* don't ignore next character */
-
-                        if (!required)
-                            putc (']', stderr);
-                        break;
-                    case 's':           /* char string */
-                    case 'd':           /* decimal # */
-                    case 'o':           /* octal # */
-                    case 'x':           /* hexadecimal # */
-                    case 'f':           /* floating # */
-                    case 'D':           /* long decimal # */
-                    case 'O':           /* long octal # */
-                    case 'X':           /* long hexadecimal # */
-                    case 'F':           /* double precision floating # */
-                    case 'n':           /* numeric arg (C format) */
-                    case 'N':           /* long numeric arg */
-                        if (!required)
-                            putc ('[', stderr);
-                        for (; format < cp - 1 - list_of; format++)
-                            putc (*format, stderr);
-                        if ( list_of != 0 )
-                        {
-                            if ( comma_list )
-                                putc( ',', stderr );
-                            else
-                                putc( ' ', stderr );
-                            fputs( "...", stderr );
-                        }
-                        if (!required)
-                            putc (']', stderr);
-                        break;
-                    default:
-                        break;
-                }
-                required = NO;
-                list_of = NO;
-                comma_list = NO;
-                if (*cp)                /* check for end of string */
-                    format = ++cp;
-                if (*cp && !ISSPACE(*cp))
-                    putc (' ', stderr);
-        }
-        if (recurse && ISSPACE(*cp))
-            break;
-    }
-    if (!recurse)
-    {
-        for ( ; format < cp; format++ )
-            putc( *format, stderr );
-        putc ('\n', stderr);
-    }
-    return (cp);
-}
-
-/*
- * isnum - determine whether a string MIGHT represent a number.
- * typchr indicates the type of argument we are looking for, and
- * determines the legal character set.  If comma_list is YES, then
- * space and comma are also legal characters.
- */
-static int
-isnum( str, typchr, comma_list )
-register CONST_DECL char * str;
-int typchr;
-int comma_list;
-{
-    register CONST_DECL char *allowed, *digits, *cp;
-    int hasdigit = NO;
-
-    switch( typchr )
-    {
-        case 'n':
-        case 'N':
-            allowed = " \t,+-x0123456789abcdefABCDEF";
-            break;
-        case 'd':
-        case 'D':
-            allowed = " \t,+-0123456789";
-            break;
-        case 'o':
-        case 'O':
-            allowed = " \t,01234567";
-            break;
-        case 'x':
-        case 'X':
-            allowed = " \t,0123456789abcdefABCDEF";
-            break;
-        case 'f':
-        case 'F':
-            allowed = " \t,+-eE.0123456789";
-            break;
-        case 's':                       /* only throw out decimal numbers */
-        default:
-            allowed = " \t,+-.0123456789";
-            break;
-    }
-    digits = allowed;
-    while ( *digits != '0' )
-        digits++;
-    if ( ! comma_list )
-        allowed += 3;                 /* then don't allow space, tab, comma */
-
-    while ( *str != '\0' )
-    {
-        for ( cp = allowed; *cp != '\0' && *cp != *str; cp++ )
-            ;
-        if ( *cp == '\0' )
-            return NO;               /* if not in allowed chars, not number */
-        if ( cp - digits >= 0 )
-            hasdigit = YES;
-        str++;
-    }
-    return hasdigit;
-}
diff --git a/urt/vaxshort.c b/urt/vaxshort.c
index 9a83cecb..c39e78ec 100644
--- a/urt/vaxshort.c
+++ b/urt/vaxshort.c
@@ -1,5 +1,5 @@
 /*
- *			V A X S H O R T
+ *                      V A X S H O R T
  *
  *  Code to manipulate 16-bit integers in VAX order in a
  *  machine independent manner.
@@ -7,21 +7,21 @@
  *  (VAX is a trademark of Digital Equipment Corporation)
  *
  *  Author -
- *	Michael John Muuss
+ *      Michael John Muuss
  *
  *  Source -
- *	SECAD/VLD Computing Consortium, Bldg 394
- *	The U. S. Army Ballistic Research Laboratory
- *	Aberdeen Proving Ground, Maryland  21005-5066
+ *      SECAD/VLD Computing Consortium, Bldg 394
+ *      The U. S. Army Ballistic Research Laboratory
+ *      Aberdeen Proving Ground, Maryland  21005-5066
  *
  *  Distribution Status -
- *	Public Domain, Distribution Unlimited.
+ *      Public Domain, Distribution Unlimited.
  */
 
 #include "vaxshort.h"
 
 /*
- *			V A X _ G S H O R T
+ *                      V A X _ G S H O R T
  *
  *  Obtain a 16-bit signed integer from two adjacent characters,
  *  stored in VAX order, regardless of word alignment.
@@ -29,24 +29,24 @@
 int
 vax_gshort(char *msgp)
 {
-	register unsigned char *p = (unsigned char *) msgp;
-	register int	i;
+        unsigned char *p = (unsigned char *) msgp;
+        int     i;
 
-	if( (i = (p[1] << 8) | p[0]) & 0x8000 )
-		return(i | ~0xFFFF);	/* Sign extend */
-	return(i);
+        if( (i = (p[1] << 8) | p[0]) & 0x8000 )
+                return(i | ~0xFFFF);    /* Sign extend */
+        return(i);
 }
 
 /*
- *			V A X _ P S H O R T
+ *                      V A X _ P S H O R T
  */
 char *
 vax_pshort(char *msgp, unsigned short s)
 {
 
-	msgp[0] = s & 0xFF;
-	msgp[1] = s >> 8;
-	return(msgp+2);
+        msgp[0] = s & 0xFF;
+        msgp[1] = s >> 8;
+        return(msgp+2);
 }
 
 
diff --git a/version.mk b/version.mk
index 5cd4fcb1..e72d68a9 100644
--- a/version.mk
+++ b/version.mk
@@ -1,3 +1,3 @@
 NETPBM_MAJOR_RELEASE = 10
-NETPBM_MINOR_RELEASE = 97
-NETPBM_POINT_RELEASE = 6
+NETPBM_MINOR_RELEASE = 98
+NETPBM_POINT_RELEASE = 0