about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/hpcdtoppm/Makefile22
-rw-r--r--converter/ppm/hpcdtoppm/README37
-rwxr-xr-xconverter/ppm/hpcdtoppm/hpcdtoppm18
-rwxr-xr-xconverter/ppm/hpcdtoppm/pcdovtoppm172
-rw-r--r--converter/ppm/ilbm.h92
-rw-r--r--converter/ppm/ilbmtoppm.c4
-rw-r--r--converter/ppm/picttoppm.c2265
-rw-r--r--converter/ppm/pjtoppm.c2
-rw-r--r--converter/ppm/ppmtoapplevol.c2
-rw-r--r--converter/ppm/ppmtoarbtxt.c2
-rw-r--r--converter/ppm/ppmtobmp.c2
-rw-r--r--converter/ppm/ppmtoilbm.c210
-rw-r--r--converter/ppm/ppmtomitsu.c2
-rw-r--r--converter/ppm/ppmtompeg/LOGIC2
-rw-r--r--converter/ppm/ppmtompeg/Makefile2
-rw-r--r--converter/ppm/ppmtompeg/bsearch.c58
-rw-r--r--converter/ppm/ppmtompeg/docs/template.param2
-rw-r--r--converter/ppm/ppmtompeg/examples/payam.param2
-rw-r--r--converter/ppm/ppmtompeg/examples/payam18.param2
-rw-r--r--converter/ppm/ppmtompeg/examples/template.param2
-rw-r--r--converter/ppm/ppmtompeg/frame.c68
-rw-r--r--converter/ppm/ppmtompeg/frametype.c39
-rw-r--r--converter/ppm/ppmtompeg/jpeg.c230
-rw-r--r--converter/ppm/ppmtompeg/mheaders.c4
-rw-r--r--converter/ppm/ppmtompeg/mpeg.c241
-rw-r--r--converter/ppm/ppmtompeg/opts.c110
-rw-r--r--converter/ppm/ppmtompeg/parallel.c379
-rw-r--r--converter/ppm/ppmtompeg/param.c83
-rw-r--r--converter/ppm/ppmtompeg/parse_huff.pl2
-rw-r--r--converter/ppm/ppmtompeg/psearch.c2
-rw-r--r--converter/ppm/ppmtompeg/psocket.c63
-rw-r--r--converter/ppm/ppmtompeg/rate.c192
-rw-r--r--converter/ppm/ppmtompeg/readframe.c103
-rw-r--r--converter/ppm/ppmtompeg/specifics.c74
-rw-r--r--converter/ppm/ppmtopcx.c584
-rw-r--r--converter/ppm/ppmtospu.c2
-rw-r--r--converter/ppm/sldtoppm.c2
-rw-r--r--converter/ppm/xim.h14
-rw-r--r--converter/ppm/ximtoppm.c93
-rw-r--r--converter/ppm/xpmtoppm.README2
-rw-r--r--converter/ppm/xpmtoppm.c8
41 files changed, 2768 insertions, 2427 deletions
diff --git a/converter/ppm/hpcdtoppm/Makefile b/converter/ppm/hpcdtoppm/Makefile
index 5777a84f..9633017e 100644
--- a/converter/ppm/hpcdtoppm/Makefile
+++ b/converter/ppm/hpcdtoppm/Makefile
@@ -7,11 +7,29 @@ VPATH=.:$(SRCDIR)/$(SUBDIR)
 
 include $(BUILDDIR)/config.mk
 
-all: hpcdtoppm
+SCRIPTS =  pcdovtoppm
+
+ifeq ($(file <hpcdtoppm-import/Makefile)x,x)
+  # The file does not exist, which means user did not augment the
+  # Netpbm source tree by adding hpcdtoppm source code.
+  #
+  # Therefore, we package the dummy 'hpcdtoppm' program that just tells the
+  # user how to get the real one.
+  #
+  # See README in this directory.
+  #
+  # (Note that empty file and nonexistent file look the same with
+  # $(file)).
+  SCRIPTS += hpcdtoppm
+else
+  SUBDIRS += hpcdtoppm-import
+endif
 
-SCRIPTS = hpcdtoppm pcdovtoppm
 MERGE_OBJECTS =
 
+.PHONY: all
+all: $(BINARIES) $(SUBDIRS:%=%/all)
+
 include $(SRCDIR)/common.mk
 
 install.bin install.merge: install.bin.local
diff --git a/converter/ppm/hpcdtoppm/README b/converter/ppm/hpcdtoppm/README
index a1c7c8c2..ec23ec1b 100644
--- a/converter/ppm/hpcdtoppm/README
+++ b/converter/ppm/hpcdtoppm/README
@@ -1,20 +1,25 @@
-This 'hpcdtoppm' directory is really just a placeholder for the real
-Hpcdtoppm source code.  
+The 'hpcdtoppm' code in this directory is just a dummy version of the program
+that tells you where to get the real code.
 
-The real Hpcdtoppm source code cannot be distributed on Sourceforge
-because a copyright holder does not license it in a way open enough to
-meet Sourceforge's requirements.
+The real "hpcdtoppm' source code cannot be distributed on Sourceforge because
+a copyright holder does not license it in a way open enough to meet
+Sourceforge's requirements.
 
-Therefore, the Netpbm maintainer distributes Hpcdtoppm via another channel
-and distributes this dummy directory in the main Netpbm source tree on 
-Sourceforge.  When you run the program named 'hpcdtoppm' in this directory,
-it tells you how to get the real Hpcdtoppm.
+Therefore, the Netpbm maintainer distributes 'hpcdtoppm' via another channel
+and distributes this dummy directory in the main Netpbm source tree on
+Sourceforge.
 
-When you get the real Hpcdtoppm tarball, just unpack it and replace
-this entire 'hpcdtoppm' directory with its contents.  Then build
-Netpbm normally.
+The code is at 
+
+  http://ibiblio.org/pub/Linux/apps/graphics/convert/hpcdtoppm-netpbm.tgz
+
+When you get the real 'hpcdtoppm' tarball, just unpack its contents into the
+'hpcdtoppm-import' subdirectory.  Then build Netpbm normally.  The build
+detects the presence of the code and builds and packages the real 'hpcdtoppm'
+program instead of the dummy one.
+
+Bear in mind when you get the real 'hpcdtoppm' that it is not as openly
+licensed as what's in the rest of the Netpbm source tree.  As you'll see in
+the license that comes with 'hpcdtoppm', you may _not_ sell it to someone
+else.)
 
-Bear in mind when you get the real Hpcdtoppm, that it is not as openly
-licensed as what's in the rest of the Netpbm source tree.  As you'll
-see in the license that comes with Hpcdtoppm, you may _not_ sell it to
-someone else.)
diff --git a/converter/ppm/hpcdtoppm/hpcdtoppm b/converter/ppm/hpcdtoppm/hpcdtoppm
index 2af4a384..2a61aa9d 100755
--- a/converter/ppm/hpcdtoppm/hpcdtoppm
+++ b/converter/ppm/hpcdtoppm/hpcdtoppm
@@ -8,18 +8,16 @@ The real 'hpcdtoppm' is a program that converts an image from Photo CD format
 to PPM format.  The program you are running now just issues the message you
 are reading.
 
-Please get a copy of Hpcdtoppm from 
-
-  http://terasaur.org/item/show/hpcdtoppm-netpbm-convert-photo-cd/4967
-
-and replace this stand-in program with the real one.
+Instructions for getting the 'hpcdtoppm' source code and building it into
+Netpbm are in the file converter/ppm/hpcdtoppm/README in the distributed
+Netpbm source tree.
 
 The point of this is that this stand-in 'hpcdtoppm' is distributed with Netpbm
-on Sourceforge.  Hpcdtoppm does not meet the requirements to be distributed on
-Sourceforge because a copyright holder does not permit people to sell copies.
-At one time, the real Hpcdtoppm was distributed with Netpbm on Sourceforge by
-mistake.
+on Sourceforge.  'hpcdtoppm' does not meet the requirements to be distributed
+on Sourceforge because a copyright holder does not permit people to sell
+copies.  At one time, the real 'hpcdtoppm' was distributed with Netpbm on
+Sourceforge by mistake.
 
 EOF
 
-exit 1
\ No newline at end of file
+exit 1
diff --git a/converter/ppm/hpcdtoppm/pcdovtoppm b/converter/ppm/hpcdtoppm/pcdovtoppm
index 01a68313..2a875690 100755
--- a/converter/ppm/hpcdtoppm/pcdovtoppm
+++ b/converter/ppm/hpcdtoppm/pcdovtoppm
@@ -19,12 +19,16 @@
 # Rewritten in sh by Steve McIntyre <93sam@debian.org>, 2001
 
 # You may want to change the default values in the next 6 lines:
-maxwidth=1152   # maximum width of the index image
-size=192                # make the images about this big
-across=6                # show this many images per row
-colors="noquant"        # maximum amount of colors or noquant (no quantization)
-back="-black"   # default background color
-font=" "                # default font or none (pbmtext's internal font)
+maxwidth=1152     # maximum width of the index image
+size=192          # make the images about this big
+across=6          # show this many images per row
+colors="noquant"  # maximum amount of colors or noquant (no quantization)
+back="-black"     # default background color
+font=" "          # default font or none (pbmtext's internal font)
+
+plainopt=""       # output plain ppm
+quietopt=""       # quiet operation (currently no effect)
+versionopt=0
 
 usage ()
 {
@@ -47,79 +51,108 @@ usage ()
     exit 1
 }
 
+version ()
+{
+    # report version using pnmscale
+    pnmscale -version $quietopt
+    exit 0
+}
+
 # Parse the options
 while :; do
     case "$1" in 
-        -m*)
+        -m|-ma|-max|-maxw|-maxwi|-maxwid|-maxwidt|-maxwidth )
              if [ $# -lt 2 ] ; then usage; fi
              maxwidth="$2"
              shift
              shift
              ;;
 
-        -s*)
+        -s|-si|-siz|-size )
              if [ $# -lt 2 ] ; then usage; fi
              size="$2"
              shift
              shift
              ;;
 
-            -a*)
-                if [ $# -lt 2 ] ; then usage; fi
-                across="$2"
-                shift
-                shift
-                ;;
-
-            -c*)
-                if [ $# -lt 2 ] ; then usage; fi
-                colors="$2"
-                shift
-                shift
-                ;;
-
-            -f*)
-                if [ $# -lt 2 ] ; then usage; fi
-                font="-font $2"
-                shift
-                shift
-                ;;
-
-            -b*)
-                back="-black"
-                shift
-                ;;
-
-            -w*)
-                back="-white"
-                shift
-                ;;
-
-            -*)
-                echo "$0 : Unknown option $1"
-                echo " "
-                usage
-                ;;
-
-            *)
-                break
-                ;;
+         -a|-ac|-acr|-acro|-acros|-across )
+             if [ $# -lt 2 ] ; then usage; fi
+             across="$2"
+             shift
+             shift
+             ;;
+
+         -c|-co|-col|-colo|-color|-colors )
+             if [ $# -lt 2 ] ; then usage; fi
+             colors="$2"
+             shift
+             shift
+             ;;
+
+         -f|-fo|-fon|-font )
+             if [ $# -lt 2 ] ; then usage; fi
+             font="-font $2"
+             shift
+             shift
+             ;;
+
+         -b|-bl|-bla|-blac|-black )
+             back="-black"
+             shift
+             ;;
+
+         -w|-wh|-whi|-whit|-white )
+             back="-white"
+             shift
+             ;;
+             
+         -p|-pl|-pla|-plai|-plain )
+             plainopt="-plain"
+             shift
+             ;;
+            
+         -q|-qu|-qui|-quie|-quiet )
+             quietopt="-quiet"
+             shift
+             ;;
+             
+         -v|-ve|-ver|-vers|-versi|-versio|-version )
+             versionopt="1"
+             shift
+             ;;
+                    
+         -*)
+             echo "$0 : Unknown option $1" 1>&2
+             echo " " 1>&2
+             usage
+             ;;
+
+         *)
+             break
+             ;;
 
     esac
 done
 
-if [ $# = 0 ]; then
+if [ $versionopt -eq 1 ] ; then
+    version
+elif [ $# -eq 0 ] ; then
     usage
 fi
 
-tmpfile=`tempfile -p pi -m 600`
+tempdir=$(mktemp -d "${TMPDIR:-/tmp}/pcdovtoppm.XXXXXXXX") ||
+    { echo "Could not create temporary file. Exiting." 1>&2; exit 1; }
+trap 'rm -rf $tempdir' 0
+
+tmpfile=$(mktemp --tmpdir piXXXXXX)
 
 # Convert the PCD overview file to many PPM images
 if [ -f $1 ] ; then
-    hpcdtoppm -Overview $1 $tmpfile
+    hpcdtoppm -Overview $1 $tmpfile ||
+        { echo "$0: Hpcdtoppm failed. Exiting" 1>&2 ; exit 1; }
 else
-    echo "$0 : Could not access $1"
-    echo " "
+    echo "$0 : Could not access $1" 1>&2
+    echo " " 1>&2
     usage
 fi
 
@@ -145,16 +178,17 @@ do
             fi
         fi
     fi
-    imagefile=pi.${row}.${col}.$$
+    imagefile=${tempdir}/pi.${row}.${col}
     rm -f $imagefile
     ttext="$i:t"
 
     if [ "$back" = "-white" ] ; then
-        pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2| \
-        pnmcat $back -tb $tmpfile - > $imagefile
+        pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | \
+        pamcat $back -topbottom $tmpfile - > $imagefile
     else
         pbmtext $font "$ttext" | pnmcrop -quiet | pnmmargin -white 2 | \
-        pnminvert | pnmcat $back -tb $tmpfile - > $imagefile
+          pnminvert | \
+          pamcat $back -topbottom $tmpfile - > $imagefile
     fi
 
     rm -f $tmpfile
@@ -163,12 +197,12 @@ do
     imagefiles="$imagefiles $imagefile"
 
     if [ $col -ge $across -o $width -gt $maxwidth ] ; then
-        rowfile=pi.${row}.$$
+        rowfile=${tempdir}/pi.${row}
         rm -f $rowfile
     if [ "$colors" = "n" ] ; then
-        pnmcat $back -lr -jbottom $imagefiles > $rowfile
+        pamcat $back -leftright -jbottom $imagefiles > $rowfile
     else
-        pnmcat $back -lr -jbottom $imagefiles | \
+        pamcat $back -leftright -jbottom $imagefiles | \
         ppmquant -quiet $colors > $rowfile
     fi
     rm -f $imagefiles
@@ -183,25 +217,27 @@ do
 done
 
 if [ -n $imagefiles ] ; then
-    rowfile=pi.${row}.$$
+    rowfile=${tempdir}/pi.${row}
     rm -f $rowfile
     if [ "$colors" = "n" ] ; then
-        pnmcat $back -lr -jbottom $imagefiles > $rowfile
+        pamcat $back -leftright -jbottom $imagefiles > $rowfile
     else
-        pnmcat $back -lr -jbottom $imagefiles | \
-        ppmquant -quiet $colors > $rowfile
+        pamcat $back -leftright -jbottom $imagefiles | \
+          ppmquant -quiet $colors > $rowfile
     fi
     rm -f $imagefiles
     rowfiles="$rowfiles $rowfile"
 fi
 
 if [ $(echo $rowfiles|wc -w) -eq 1 ] ; then
-    cat $rowfiles
+    ppmtoppm $plainopt < $rowfiles
 else
     if [ "$colors" = "n" ] ; then
-        pnmcat $back -tb $rowfiles
+        pamcat $back -topbottom $rowfiles | \
+          ppmtoppm $plainopt
     else
-        pnmcat $back -tb $rowfiles | ppmquant -quiet $colors
+        pamcat $back -tb $rowfiles | \
+          ppmquant $plainopt -quiet $colors
     fi
 fi
 
@@ -210,5 +246,3 @@ rm -f $rowfiles
 exit 0
 
 
-
-
diff --git a/converter/ppm/ilbm.h b/converter/ppm/ilbm.h
index dbe47758..c0fac7d2 100644
--- a/converter/ppm/ilbm.h
+++ b/converter/ppm/ilbm.h
@@ -25,8 +25,8 @@ typedef struct {
 #define mskHasTransparentColor  2
 #define mskLasso                3       /* can't handle this */
 #define mskMAXKNOWN             mskLasso
-static const char * mskNAME[] = { 
-    "none", "mask plane", "transparent color", "lasso" 
+static const char * mskNAME[] = {
+    "none", "mask plane", "transparent color", "lasso"
 };
 
 #define cmpNone                 0
@@ -147,98 +147,98 @@ typedef unsigned long   IFF_ID;
 #define MAKE_ID(a, b, c, d) \
     ((IFF_ID)(a)<<24 | (IFF_ID)(b)<<16 | (IFF_ID)(c)<<8 | (IFF_ID)(d))
 
-#define ID_FORM     MAKE_ID('F', 'O', 'R', 'M')     
+#define ID_FORM     MAKE_ID('F', 'O', 'R', 'M')
     /* EA IFF 85 group identifier */
-#define ID_CAT      MAKE_ID('C', 'A', 'T', ' ')     
+#define ID_CAT      MAKE_ID('C', 'A', 'T', ' ')
     /* EA IFF 85 group identifier */
-#define ID_LIST     MAKE_ID('L', 'I', 'S', 'T')     
+#define ID_LIST     MAKE_ID('L', 'I', 'S', 'T')
     /* EA IFF 85 group identifier */
-#define ID_PROP     MAKE_ID('P', 'R', 'O', 'P')     
+#define ID_PROP     MAKE_ID('P', 'R', 'O', 'P')
     /* EA IFF 85 group identifier */
-#define ID_END      MAKE_ID('E', 'N', 'D', ' ')     
+#define ID_END      MAKE_ID('E', 'N', 'D', ' ')
     /* unofficial END-of-FORM identifier (see Amiga RKM Devices Ed.3
        page 376) */
-#define ID_ILBM     MAKE_ID('I', 'L', 'B', 'M')     
+#define ID_ILBM     MAKE_ID('I', 'L', 'B', 'M')
     /* EA IFF 85 raster bitmap form */
-#define ID_DEEP     MAKE_ID('D', 'E', 'E', 'P')     
+#define ID_DEEP     MAKE_ID('D', 'E', 'E', 'P')
     /* Chunky pixel image files (Used in TV Paint) */
-#define ID_RGB8     MAKE_ID('R', 'G', 'B', '8')     
+#define ID_RGB8     MAKE_ID('R', 'G', 'B', '8')
     /* RGB image forms, Turbo Silver (Impulse) */
-#define ID_RGBN     MAKE_ID('R', 'G', 'B', 'N')     
+#define ID_RGBN     MAKE_ID('R', 'G', 'B', 'N')
     /* RGB image forms, Turbo Silver (Impulse) */
-#define ID_PBM      MAKE_ID('P', 'B', 'M', ' ')     
+#define ID_PBM      MAKE_ID('P', 'B', 'M', ' ')
     /* 256-color chunky format (DPaint 2 ?) */
-#define ID_ACBM     MAKE_ID('A', 'C', 'B', 'M')     
+#define ID_ACBM     MAKE_ID('A', 'C', 'B', 'M')
     /* Amiga Contiguous Bitmap (AmigaBasic) */
 
 /* generic */
 
-#define ID_FVER     MAKE_ID('F', 'V', 'E', 'R')     
+#define ID_FVER     MAKE_ID('F', 'V', 'E', 'R')
     /* AmigaOS version string */
-#define ID_JUNK     MAKE_ID('J', 'U', 'N', 'K')     
+#define ID_JUNK     MAKE_ID('J', 'U', 'N', 'K')
     /* always ignore this chunk */
-#define ID_ANNO     MAKE_ID('A', 'N', 'N', 'O')     
+#define ID_ANNO     MAKE_ID('A', 'N', 'N', 'O')
     /* EA IFF 85 Generic Annotation chunk */
-#define ID_AUTH     MAKE_ID('A', 'U', 'T', 'H')     
+#define ID_AUTH     MAKE_ID('A', 'U', 'T', 'H')
     /* EA IFF 85 Generic Author chunk */
-#define ID_CHRS     MAKE_ID('C', 'H', 'R', 'S')     
+#define ID_CHRS     MAKE_ID('C', 'H', 'R', 'S')
     /* EA IFF 85 Generic character string chunk */
-#define ID_NAME     MAKE_ID('N', 'A', 'M', 'E')     
+#define ID_NAME     MAKE_ID('N', 'A', 'M', 'E')
     /* EA IFF 85 Generic Name of art, music, etc. chunk */
-#define ID_TEXT     MAKE_ID('T', 'E', 'X', 'T')     
+#define ID_TEXT     MAKE_ID('T', 'E', 'X', 'T')
     /* EA IFF 85 Generic unformatted ASCII text chunk */
-#define ID_copy     MAKE_ID('(', 'c', ')', ' ')     
+#define ID_copy     MAKE_ID('(', 'c', ')', ' ')
 /* EA IFF 85 Generic Copyright text chunk */
 
 /* ILBM chunks */
 
-#define ID_BMHD     MAKE_ID('B', 'M', 'H', 'D')     
+#define ID_BMHD     MAKE_ID('B', 'M', 'H', 'D')
     /* ILBM BitmapHeader */
-#define ID_CMAP     MAKE_ID('C', 'M', 'A', 'P')     
+#define ID_CMAP     MAKE_ID('C', 'M', 'A', 'P')
     /* ILBM 8bit RGB colormap */
-#define ID_GRAB     MAKE_ID('G', 'R', 'A', 'B')     
-    /* ILBM "hotspot" coordiantes */
-#define ID_DEST     MAKE_ID('D', 'E', 'S', 'T')     
+#define ID_GRAB     MAKE_ID('G', 'R', 'A', 'B')
+    /* ILBM "hotspot" coordinates */
+#define ID_DEST     MAKE_ID('D', 'E', 'S', 'T')
     /* ILBM destination image info */
-#define ID_SPRT     MAKE_ID('S', 'P', 'R', 'T')     
+#define ID_SPRT     MAKE_ID('S', 'P', 'R', 'T')
     /* ILBM sprite identifier */
-#define ID_CAMG     MAKE_ID('C', 'A', 'M', 'G')     
+#define ID_CAMG     MAKE_ID('C', 'A', 'M', 'G')
     /* Amiga viewportmodes */
-#define ID_BODY     MAKE_ID('B', 'O', 'D', 'Y')     
+#define ID_BODY     MAKE_ID('B', 'O', 'D', 'Y')
     /* ILBM image data */
-#define ID_CRNG     MAKE_ID('C', 'R', 'N', 'G')     
+#define ID_CRNG     MAKE_ID('C', 'R', 'N', 'G')
     /* color cycling */
-#define ID_CCRT     MAKE_ID('C', 'C', 'R', 'T')     
+#define ID_CCRT     MAKE_ID('C', 'C', 'R', 'T')
     /* color cycling */
-#define ID_CLUT     MAKE_ID('C', 'L', 'U', 'T')     
+#define ID_CLUT     MAKE_ID('C', 'L', 'U', 'T')
     /* Color Lookup Table chunk */
-#define ID_DPI      MAKE_ID('D', 'P', 'I', ' ')     
+#define ID_DPI      MAKE_ID('D', 'P', 'I', ' ')
     /* Dots per inch chunk */
-#define ID_DPPV     MAKE_ID('D', 'P', 'P', 'V')     
+#define ID_DPPV     MAKE_ID('D', 'P', 'P', 'V')
     /* DPaint perspective chunk (EA) */
-#define ID_DRNG     MAKE_ID('D', 'R', 'N', 'G')     
+#define ID_DRNG     MAKE_ID('D', 'R', 'N', 'G')
     /* DPaint IV enhanced color cycle chunk (EA) */
-#define ID_EPSF     MAKE_ID('E', 'P', 'S', 'F')     
+#define ID_EPSF     MAKE_ID('E', 'P', 'S', 'F')
     /* Encapsulated Postscript chunk */
-#define ID_CMYK     MAKE_ID('C', 'M', 'Y', 'K')     
+#define ID_CMYK     MAKE_ID('C', 'M', 'Y', 'K')
     /* Cyan, Magenta, Yellow, & Black color map (Soft-Logik) */
-#define ID_CNAM     MAKE_ID('C', 'N', 'A', 'M')     
+#define ID_CNAM     MAKE_ID('C', 'N', 'A', 'M')
     /* Color naming chunk (Soft-Logik) */
-#define ID_PCHG     MAKE_ID('P', 'C', 'H', 'G')     
+#define ID_PCHG     MAKE_ID('P', 'C', 'H', 'G')
     /* Line by line palette control information (Sebastiano Vigna) */
-#define ID_PRVW     MAKE_ID('P', 'R', 'V', 'W')     
+#define ID_PRVW     MAKE_ID('P', 'R', 'V', 'W')
     /* A mini duplicate ILBM used for preview (Gary Bonham) */
-#define ID_XBMI     MAKE_ID('X', 'B', 'M', 'I')     
+#define ID_XBMI     MAKE_ID('X', 'B', 'M', 'I')
     /* eXtended BitMap Information (Soft-Logik) */
-#define ID_CTBL     MAKE_ID('C', 'T', 'B', 'L')     
+#define ID_CTBL     MAKE_ID('C', 'T', 'B', 'L')
     /* Newtek Dynamic Ham color chunk */
-#define ID_DYCP     MAKE_ID('D', 'Y', 'C', 'P')     
+#define ID_DYCP     MAKE_ID('D', 'Y', 'C', 'P')
     /* Newtek Dynamic Ham chunk */
-#define ID_SHAM     MAKE_ID('S', 'H', 'A', 'M')     
+#define ID_SHAM     MAKE_ID('S', 'H', 'A', 'M')
     /* Sliced HAM color chunk */
-#define ID_ABIT     MAKE_ID('A', 'B', 'I', 'T')     
+#define ID_ABIT     MAKE_ID('A', 'B', 'I', 'T')
     /* ACBM body chunk */
-#define ID_DCOL     MAKE_ID('D', 'C', 'O', 'L')     
+#define ID_DCOL     MAKE_ID('D', 'C', 'O', 'L')
     /* unofficial direct color */
 #define ID_DPPS     MAKE_ID('D', 'P', 'P', 'S')
     /* ? */
diff --git a/converter/ppm/ilbmtoppm.c b/converter/ppm/ilbmtoppm.c
index 92d4d6f2..b9b89862 100644
--- a/converter/ppm/ilbmtoppm.c
+++ b/converter/ppm/ilbmtoppm.c
@@ -1597,8 +1597,8 @@ rgbn_to_ppm(FILE *         const ifP,
  Multipalette chunk reader
 
     Currently there are three multipalette formats:
-        SHAM - sliced HAM (obselete)
-        CTBL - dynamic HAM/Hires (obselete)
+        SHAM - sliced HAM (obsolete)
+        CTBL - dynamic HAM/Hires (obsolete)
         PCHG - palette change
     There is no official documentation available for SHAM and CTBL, so
    this is mostly guesswork from other sources and hexdumps of pictures...
diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c
index be6a3f97..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,31 +47,115 @@ 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.
  */
 
 struct Rect {
-    Word top;
-    Word left;
-    Word bottom;
-    Word right;
+/*----------------------------------------------------------------------------
+   A rectangle - description of a region of an image raster.
+
+   If last row or column is before first, it is a null rectangle - it
+   describes no pixels.
+-----------------------------------------------------------------------------*/
+    Word top;     /* Start row */
+    Word left;    /* Start column */
+    Word bottom;  /* End row */
+    Word right;   /* End column */
+
+    /* "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 {
@@ -88,14 +173,21 @@ struct Pattern {
     Byte pix[64];
 };
 
-struct rgbPlanes {
+struct RgbPlanes {
+/*----------------------------------------------------------------------------
+   A raster, as three planes: red, green, blue.
+
+   Each plane is an array in row-major order.
+-----------------------------------------------------------------------------*/
+    unsigned int width;
+    unsigned int height;
     Word * red;
     Word * grn;
     Word * blu;
 };
 
-struct canvas {
-    struct rgbPlanes planes;
+struct Canvas {
+    struct RgbPlanes planes;
 };
 
 typedef void (*transfer_func) (struct RGBColor* src, struct RGBColor* dst);
@@ -105,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 };
@@ -142,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.
 
@@ -173,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) {
@@ -186,9 +277,9 @@ allocateRaster(struct raster * const rasterP,
    multiple of 16, because we've seen many images in which the PICT raster
    does contain that much padding on the right.  I don't know why; I could
    understand a multiple of 8, since in 1 bpp image, the smallest unit
-   expressable in PICT is 8 pixels.  But why 16?  The images we saw came
+   expressible in PICT is 8 pixels.  But why 16?  The images we saw came
    from Adobe Illustrator 10 in March 2007, supplied by
-   Guillermo Gómez Valcárcel.
+   Guillermo Gomez Valcarcel.
 -----------------------------------------------------------------------------*/
     unsigned int const allocWidth = ROUNDUP(width, 16);
 
@@ -202,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).
 
-           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.
+           If the image is compressed, each row is compressed separately, with
+           the planes opaque to the compressor.
 
-           We have yet to see if we can properly interpret 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.
+
+           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;
@@ -244,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
@@ -307,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;
@@ -326,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);
 }
@@ -354,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" },
@@ -407,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" },
@@ -428,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" },
@@ -437,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" },
@@ -447,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];
 
@@ -465,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;
 
@@ -474,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;
@@ -485,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
@@ -510,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);
@@ -613,7 +716,7 @@ picComment(Word const type,
         break;
     }
     if (remainingLength > 0)
-        skip(remainingLength);
+        skip(ifP, remainingLength);
 }
 
 
@@ -621,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);
 }
 
 
@@ -633,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);
 }
 
 
@@ -669,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;
 
 
 
@@ -714,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)
@@ -737,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'.
@@ -762,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);
 
@@ -780,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) {
 
@@ -792,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
@@ -804,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);
@@ -818,14 +942,36 @@ readRect(struct Rect * const r) {
 
 
 static int
+rectisnull(struct Rect * const r) {
+
+    return r->top >= r->bottom || r->left >= r->right;
+}
+
+
+
+static int
 rectwidth(const struct Rect * const r) {
+
     return r->right - r->left;
 }
 
 
 
+static bool
+rectequal(const struct Rect * const comparand,
+          const struct Rect * const comparator) {
+
+    return
+        comparand->top    == comparator->top &&
+        comparand->bottom == comparator->bottom &&
+        comparand->left   == comparator->left &&
+        comparand->right  == comparator->right;
+}
+
+
 static int
 rectheight(const struct Rect * const r) {
+
     return r->bottom - r->top;
 }
 
@@ -834,6 +980,7 @@ rectheight(const struct Rect * const r) {
 static bool
 rectsamesize(struct Rect const r1,
              struct Rect const r2) {
+
     return r1.right - r1.left == r2.right - r2.left &&
            r1.bottom - r1.top == r2.bottom - r2.top ;
 }
@@ -841,14 +988,18 @@ rectsamesize(struct Rect const r1,
 
 
 static void
-rectinter(struct Rect   const r1,
-          struct Rect   const r2,
-          struct Rect * const intersectionP) {
+rectintersect(const struct Rect * const r1P,
+              const struct Rect * const r2P,
+              struct Rect *       const intersectionP) {
+/*----------------------------------------------------------------------------
+   Compute the intersection of two rectangles.
 
-    intersectionP->left   = MAX(r1.left,   r2.left);
-    intersectionP->top    = MAX(r1.top,    r2.top);
-    intersectionP->right  = MIN(r1.right,  r2.right);
-    intersectionP->bottom = MIN(r1.bottom, r2.bottom);
+   Note that if the rectangles are disjoint, the result is a null rectangle.
+-----------------------------------------------------------------------------*/
+    intersectionP->left   = MAX(r1P->left,   r2P->left);
+    intersectionP->top    = MAX(r1P->top,    r2P->top);
+    intersectionP->right  = MIN(r1P->right,  r2P->right);
+    intersectionP->bottom = MIN(r1P->bottom, r2P->bottom);
 }
 
 
@@ -857,16 +1008,17 @@ static void
 rectscale(struct Rect * const r,
           double        const xscale,
           double        const yscale) {
-    r->left *= xscale;
-    r->right *= xscale;
-    r->top *= yscale;
+
+    r->left   *= xscale;
+    r->right  *= xscale;
+    r->top    *= yscale;
     r->bottom *= yscale;
 }
 
 
 
 static void
-    initBlitList(blitList * const blitListP) {
+initBlitList(BlitList * const blitListP) {
 
     blitListP->firstP          = NULL;
     blitListP->connectorP      = &blitListP->firstP;
@@ -876,16 +1028,16 @@ static void
 
 
 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)
@@ -902,7 +1054,7 @@ addBlitList(blitList *        const blitListP,
         biP->next = NULL;
 
         *blitListP->connectorP = biP;
-        blitListP->connectorP = &biP->next;
+        blitListP->connectorP  = &biP->next;
     }
 }
 
@@ -927,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) {
 
@@ -940,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;
 }
 
 
@@ -1064,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;
@@ -1150,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;
     }
 }
@@ -1192,43 +1364,122 @@ decode16(unsigned char * const sixteen) {
 
 
 static void
-doDiffSize(struct Rect       const clipsrc,
-           struct Rect       const clipdst,
-           int               const pixSize,
-           int               const xsize,
-           int               const ysize,
+closeValidatePamscalePipe(FILE * const pipeP) {
+
+    int rc;
+
+    rc = pclose(pipeP);
+
+    if (rc != 0)
+        pm_error("pamscale failed.  pclose() returned Errno %s (%d)",
+                 strerror(errno), errno);
+}
+
+
+
+static void
+convertScaledPpm(const char *      const scaledFilename,
+                 transfer_func     const trf,
+                 struct RgbPlanes  const dst,
+                 unsigned int      const dstadd) {
+
+    Word * reddst;
+    Word * grndst;
+    Word * bludst;
+    FILE * scaledP;
+    int cols, rows, format;
+    pixval maxval;
+    pixel * pixrow;
+
+    reddst = &dst.red[0];  /* initial value */
+    grndst = &dst.grn[0];  /* initial value */
+    bludst = &dst.blu[0];  /* initial value */
+
+    scaledP = pm_openr(scaledFilename);
+
+    ppm_readppminit(scaledP, &cols, &rows, &maxval, &format);
+
+    pixrow = ppm_allocrow(cols);
+
+    if (trf) {
+        unsigned int row;
+
+        for (row = 0; row < rows; ++row) {
+            unsigned int col;
+
+            ppm_readppmrow(scaledP, pixrow, cols, maxval, format);
+
+            for (col = 0; col < cols; ++col) {
+                struct RGBColor dst_c, src_c;
+                dst_c.red = *reddst;
+                dst_c.grn = *grndst;
+                dst_c.blu = *bludst;
+                src_c.red = PPM_GETR(pixrow[col]) * 65536L / (maxval + 1);
+                src_c.grn = PPM_GETG(pixrow[col]) * 65536L / (maxval + 1);
+                src_c.blu = PPM_GETB(pixrow[col]) * 65536L / (maxval + 1);
+                (*trf)(&src_c, &dst_c);
+                *reddst++ = dst_c.red;
+                *grndst++ = dst_c.grn;
+                *bludst++ = dst_c.blu;
+            }
+            reddst += dstadd;
+            grndst += dstadd;
+            bludst += dstadd;
+        }
+    } else {
+        unsigned int row;
+
+        for (row = 0; row < rows; ++row) {
+            unsigned int col;
+
+            ppm_readppmrow(scaledP, pixrow, cols, maxval, format);
+
+            for (col = 0; col < cols; ++col) {
+                *reddst++ = PPM_GETR(pixrow[col]) * 65536L / (maxval + 1);
+                *grndst++ = PPM_GETG(pixrow[col]) * 65536L / (maxval + 1);
+                *bludst++ = PPM_GETB(pixrow[col]) * 65536L / (maxval + 1);
+            }
+            reddst += dstadd;
+            grndst += dstadd;
+            bludst += dstadd;
+        }
+    }
+    assert(reddst == &dst.red[dst.height * dst.width]);
+    assert(grndst == &dst.grn[dst.height * dst.width]);
+    assert(bludst == &dst.blu[dst.height * dst.width]);
+
+    ppm_freerow(pixrow);
+    pm_close(scaledP);
+}
+
+
+
+static void
+doDiffSize(struct Rect       const srcRect,
+           struct Rect       const dstRect,
+           unsigned int      const pixSize,
            transfer_func     const trf,
            struct RGBColor * const color_map,
            unsigned char *   const src,
-           int               const srcwid,
-           struct rgbPlanes  const dst,
-           unsigned int      const dstwid) {
-
-    unsigned int const dstadd = dstwid - rectwidth(&clipdst);
+           unsigned int      const srcwid,
+           struct RgbPlanes  const dst) {
+/*----------------------------------------------------------------------------
+   Generate the raster in the plane buffers indicated by 'dst'.
 
+   'src' is the source pixels as a row-major array with rows 'srcwid' bytes
+   long.
+-----------------------------------------------------------------------------*/
     FILE * pamscalePipeP;
     const char * command;
-    FILE * scaled;
-    int cols, rows, format;
-    pixval maxval;
-    pixel * row;
-    pixel * rowp;
     FILE * tempFileP;
     const char * tempFilename;
-    Word * reddst;
-    Word * grndst;
-    Word * bludst;
-
-    reddst = dst.red;  /* initial value */
-    grndst = dst.grn;  /* initial value */
-    bludst = dst.blu;  /* initial value */
 
     pm_make_tmpfile(&tempFileP, &tempFilename);
 
     pm_close(tempFileP);
 
-    pm_asprintf(&command, "pamscale -xsize %d -ysize %d > %s",
-                rectwidth(&clipdst), rectheight(&clipdst), tempFilename);
+    pm_asprintf(&command, "pamscale -xsize %u -ysize %u > %s",
+                rectwidth(&dstRect), rectheight(&dstRect), tempFilename);
 
     pm_message("running command '%s'", command);
 
@@ -1239,108 +1490,61 @@ doDiffSize(struct Rect       const clipsrc,
 
     pm_strfree(command);
 
-    fprintf(pamscalePipeP, "P6\n%d %d\n%d\n",
-            rectwidth(&clipsrc), rectheight(&clipsrc), PPM_MAXMAXVAL);
+    fprintf(pamscalePipeP, "P6\n%u %u\n%u\n",
+            rectwidth(&srcRect), rectheight(&srcRect), PPM_MAXMAXVAL);
 
     switch (pixSize) {
     case 8: {
-        unsigned int rowNumber;
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const row = &src[rowNumber * srcwid];
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                unsigned int const colorIndex = row[colNumber];
+        unsigned int row;
+        for (row = 0; row < rectheight(&srcRect); ++row) {
+            unsigned char * const rowBytes = &src[row * srcwid];
+            unsigned int col;
+            for (col = 0; col < rectwidth(&srcRect); ++col) {
+                unsigned int const colorIndex = rowBytes[col];
                 struct RGBColor * const ct = &color_map[colorIndex];
                 fputc(redepth(ct->red, 65535L), pamscalePipeP);
                 fputc(redepth(ct->grn, 65535L), pamscalePipeP);
                 fputc(redepth(ct->blu, 65535L), pamscalePipeP);
             }
         }
-    }
-    break;
+    } break;
     case 16: {
-        unsigned int rowNumber;
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const row = &src[rowNumber * srcwid];
-            unsigned int colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                struct RGBColor const color = decode16(&row[colNumber * 2]);
+        unsigned int row;
+        for (row = 0; row < rectheight(&srcRect); ++row) {
+            unsigned char * const rowBytes = &src[row * srcwid];
+            unsigned int col;
+            for (col = 0; col < rectwidth(&srcRect); ++col) {
+                struct RGBColor const color = decode16(&rowBytes[col * 2]);
                 fputc(redepth(color.red, 32), pamscalePipeP);
                 fputc(redepth(color.grn, 32), pamscalePipeP);
                 fputc(redepth(color.blu, 32), pamscalePipeP);
             }
         }
-    }
-    break;
+    } break;
     case 32: {
-        unsigned int const planeSize = rectwidth(&clipsrc);
-        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 colNumber;
-            for (colNumber = 0; colNumber < xsize; ++colNumber) {
-                fputc(redepth(redPlane[colNumber], 256), pamscalePipeP);
-                fputc(redepth(grnPlane[colNumber], 256), pamscalePipeP);
-                fputc(redepth(bluPlane[colNumber], 256), pamscalePipeP);
+        unsigned int const planeSize = rectwidth(&srcRect);
+        unsigned int row;
+
+        for (row = 0; row < rectheight(&srcRect); ++row) {
+            unsigned char * const rowBytes = &src[row * srcwid];
+            unsigned char * const redPlane = &rowBytes[planeSize * 0];
+            unsigned char * const grnPlane = &rowBytes[planeSize * 1];
+            unsigned char * const bluPlane = &rowBytes[planeSize * 2];
+
+            unsigned int col;
+            for (col = 0; col < rectwidth(&srcRect); ++col) {
+                fputc(redepth(redPlane[col], 256), pamscalePipeP);
+                fputc(redepth(grnPlane[col], 256), pamscalePipeP);
+                fputc(redepth(bluPlane[col], 256), pamscalePipeP);
             }
         }
-    }
-    break;
-    }
+    } break;
+    } /* switch */
 
-    if (pclose(pamscalePipeP))
-        pm_error("pamscale failed.  pclose() returned Errno %s (%d)",
-                 strerror(errno), errno);
+    closeValidatePamscalePipe(pamscalePipeP);
 
-    ppm_readppminit(scaled = pm_openr(tempFilename), &cols, &rows,
-                    &maxval, &format);
-    row = ppm_allocrow(cols);
-    /* couldn't hurt to assert cols, rows and maxval... */
-
-    if (trf == NULL) {
-        while (rows-- > 0) {
-            unsigned int i;
-            ppm_readppmrow(scaled, row, cols, maxval, format);
-            for (i = 0, rowp = row; i < cols; ++i, ++rowp) {
-                *reddst++ = PPM_GETR(*rowp) * 65536L / (maxval + 1);
-                *grndst++ = PPM_GETG(*rowp) * 65536L / (maxval + 1);
-                *bludst++ = PPM_GETB(*rowp) * 65536L / (maxval + 1);
-            }
-            reddst += dstadd;
-            grndst += dstadd;
-            bludst += dstadd;
-        }
-    }
-    else {
-        while (rows-- > 0) {
-            unsigned int i;
-            ppm_readppmrow(scaled, row, cols, maxval, format);
-            for (i = 0, rowp = row; i < cols; i++, rowp++) {
-                struct RGBColor dst_c, src_c;
-                dst_c.red = *reddst;
-                dst_c.grn = *grndst;
-                dst_c.blu = *bludst;
-                src_c.red = PPM_GETR(*rowp) * 65536L / (maxval + 1);
-                src_c.grn = PPM_GETG(*rowp) * 65536L / (maxval + 1);
-                src_c.blu = PPM_GETB(*rowp) * 65536L / (maxval + 1);
-                (*trf)(&src_c, &dst_c);
-                *reddst++ = dst_c.red;
-                *grndst++ = dst_c.grn;
-                *bludst++ = dst_c.blu;
-            }
-            reddst += dstadd;
-            grndst += dstadd;
-            bludst += dstadd;
-        }
-    }
+    convertScaledPpm(tempFilename, trf, dst, dst.width-rectwidth(&dstRect));
 
-    pm_close(scaled);
-    ppm_freerow(row);
     pm_strfree(tempFilename);
     unlink(tempFilename);
 }
@@ -1348,7 +1552,7 @@ doDiffSize(struct Rect       const clipsrc,
 
 
 static void
-getRgb(struct rgbPlanes  const planes,
+getRgb(struct RgbPlanes  const planes,
        unsigned int      const index,
        struct RGBColor * const rgbP) {
 
@@ -1362,7 +1566,7 @@ getRgb(struct rgbPlanes  const planes,
 static void
 putRgb(struct RGBColor  const rgb,
        unsigned int     const index,
-       struct rgbPlanes const planes) {
+       struct RgbPlanes const planes) {
 
     planes.red[index] = rgb.red;
     planes.grn[index] = rgb.grn;
@@ -1372,182 +1576,171 @@ putRgb(struct RGBColor  const rgb,
 
 
 static void
-doSameSize(transfer_func           trf,
-           int               const pixSize,
-           int               const xsize,
-           int               const ysize,
-           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.
------------------------------------------------------------------------------*/
-    switch (pixSize) {
-    case 8: {
-        unsigned int rowNumber;
+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) {
 
-        for (rowNumber = 0; rowNumber < ysize; ++rowNumber) {
-            unsigned char * const srcrow = &src[rowNumber * srcwid];
-            unsigned int const dstRowCurs = rowNumber * dstwid;
+    unsigned int rowNumber;
 
-            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;
+    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;
+            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;
+
+        unsigned int colNumber;
+
+        for (colNumber = 0; colNumber < xsize; ++colNumber) {
+            unsigned int const dstCursor = dstRowCurs + colNumber;
 
-        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;
+            struct RGBColor srcColor;
 
-            unsigned int colNumber;
+            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,
-               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) {
+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);
     }
 }
 
@@ -1557,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,
+       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.
@@ -1579,11 +1771,12 @@ doBlit(struct Rect       const srcRect,
    with 'dstwid' words per row.
 -----------------------------------------------------------------------------*/
     unsigned char * src;
-    struct rgbPlanes dst;
+    struct RgbPlanes dst;
     int dstoff;
-    int xsize;
-    int ysize;
     transfer_func trf;
+        /* A transfer function to use as we transfer the pixels.
+           NULL for none.
+        */
 
     if (verbose) {
         dumpRect("copying from:", srcRect);
@@ -1601,12 +1794,17 @@ doBlit(struct Rect       const srcRect,
         assert(srcRowNumber < srcplane.rowCount);
         assert(srcRowOffset < srcplane.rowSize);
         src = srcplane.bytes + srcRowNumber * srcplane.rowSize + srcRowOffset;
-        xsize = rectwidth(&srcRect);
-        ysize = rectheight(&srcRect);
     }
 
+    /* This 'dstoff'/'dstadd' abomination has to be fixed.  We need to pass to
+       'doDiffSize' the whole actual canvas, 'canvasPlanes', and tell it to
+       what part of the canvas to write.  It can compute the location of each
+       destination row as it comes to it.
+     */
     dstoff = (dstRect.top - dstBounds.top) * dstwid +
         (dstRect.left - dstBounds.left);
+    dst.height = canvasPlanes.height - (dstRect.top - dstBounds.top);
+    dst.width  = canvasPlanes.width;
     dst.red = canvasPlanes.red + dstoff;
     dst.grn = canvasPlanes.grn + dstoff;
     dst.blu = canvasPlanes.blu + dstoff;
@@ -1615,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, xsize, ysize,
-                   trf, color_map, src, srcplane.rowSize, dst, dstwid);
+        doDiffSize(srcRect, dstRect, pixSize,
+                   trf, colorMap, src, srcplane.rowSize, dst);
     else {
-        if (trf == NULL)
-            blitIdempotent(pixSize, xsize, ysize, src, srcplane.rowSize,
-                           color_map, dst, dstwid);
-        else
-            doSameSize(trf, pixSize, xsize, ysize, 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.
 
@@ -1652,43 +1846,27 @@ 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.
         */
         struct Rect clipsrc;
         struct Rect clipdst;
 
-        rectinter(srcBounds, srcRect, &clipsrc);
-        rectinter(dstBounds, dstRect, &clipdst);
+        rectintersect(&srcBounds, &srcRect, &clipsrc);
+        rectintersect(&dstBounds, &dstRect, &clipdst);
 
         if (blitListP) {
             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;
 }
 
 
@@ -1702,11 +1880,14 @@ blit(struct Rect       const srcRect,
 static void
 allocPlanes(unsigned int       const width,
             unsigned int       const height,
-            struct rgbPlanes * const planesP) {
+            struct RgbPlanes * const planesP) {
 
     unsigned int const planelen = width * height;
 
-    struct rgbPlanes planes;
+    struct RgbPlanes planes;
+
+    planes.width  = width;
+    planes.height = height;
 
     MALLOCARRAY(planes.red, planelen);
     MALLOCARRAY(planes.grn, planelen);
@@ -1725,7 +1906,7 @@ allocPlanes(unsigned int       const width,
 
 
 static void
-freePlanes(struct rgbPlanes const planes) {
+freePlanes(struct RgbPlanes const planes) {
 
     free(planes.red);
     free(planes.grn);
@@ -1743,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;
@@ -1759,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;
@@ -1777,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);
@@ -1855,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);
@@ -1882,7 +2061,7 @@ doBlitList(struct canvas * const canvasP,
 
 static void
 outputPpm(FILE *           const ofP,
-          struct rgbPlanes const planes) {
+          struct RgbPlanes const planes) {
 
     unsigned int width;
     unsigned int height;
@@ -1922,18 +2101,20 @@ outputPpm(FILE *           const ofP,
  * is padded with a null.
  */
 static Word
-get_op(int const version) {
-    if ((align & 1) && version == 2) {
+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);
 }
 
 
@@ -1941,11 +2122,12 @@ get_op(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 */
@@ -1958,14 +2140,23 @@ ClipRgn(struct canvas * const canvasP,
            it to accept this clip rectangle, this program found the image to
            have an invalid raster.
         */
+        struct Rect clipRgnParm;
+
+        readRect(ifP, &clipRgnParm);
+
+        rectintersect(&clipRgnParm, &picFrame, &clip_rect);
 
-        readRect(&clip_rect);
-        rectinter(clip_rect, picFrame, &clip_rect);
-        /* XXX should clip this by picFrame */
+        if (!rectequal(&clipRgnParm, &clip_rect)) {
+            pm_message("ClipRgn opcode says to clip to a region which "
+                       "is not contained within the picture frame.  "
+                       "Ignoring the part outside the picture frame.");
+            dumpRect("ClipRgn:", clipRgnParm);
+            dumpRect("Picture frame:", picFrame);
+        }
         if (verbose)
             dumpRect("clipping to", clip_rect);
     } else
-        skip(len - 2);
+        skip(ifP, len - 2);
 }
 
 
@@ -1973,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);
@@ -2024,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);
@@ -2046,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.
          */
@@ -2059,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;
 }
 
 
@@ -2166,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) {
 /*----------------------------------------------------------------------------
@@ -2222,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) {
 /*----------------------------------------------------------------------------
@@ -2237,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");
@@ -2269,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.
+
+ 'row' is a row number in the raster.
 
-   'linelen' is the number of bytes of PICT that the PICT says hold the
-   compressed version of that row.
+ '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).
+ '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);
@@ -2333,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);
 
@@ -2412,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);
 
@@ -2474,10 +2674,6 @@ interpretOneRasterBlock(unsigned char * const block,
 
 
 
-static unsigned int const maxPixelBytesPerBlock = 1024;
-
-
-
 static void
 interpretCompressedLine(unsigned char * const linebuf,
                         unsigned int    const linelen,
@@ -2485,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 */
@@ -2518,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);
 }
 
 
@@ -2551,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.
@@ -2574,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)
@@ -2585,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);
 
@@ -2611,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);
@@ -2663,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;
@@ -2700,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);
 }
 
 
@@ -2717,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);
 }
 
 
@@ -2729,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;
@@ -2747,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]);
@@ -2764,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);
 }
 
 
@@ -2776,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);
 }
 
 
@@ -2788,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);
 }
 
 
@@ -2800,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);
 }
@@ -2815,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);
 }
 
 
@@ -2844,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);
@@ -2859,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);
@@ -2871,19 +3088,32 @@ RGBBkCol(struct canvas * const canvasP,
 
 
 
-#define PIXEL_INDEX(x,y) ((y) - picFrame.top) * rowlen + (x) - picFrame.left
+static unsigned int
+pixelIndex(struct Rect  const picFrame,
+           unsigned int const x,
+           unsigned int const y) {
+
+    unsigned int const rowLen = picFrame.right - picFrame.left;
+
+    assert(y >= picFrame.top  && y < picFrame.bottom);
+    assert(x >= picFrame.left && x < picFrame.right);
+
+    return (y - picFrame.top) * rowLen + (x - picFrame.left);
+}
+
+
 
 static void
-draw_pixel(struct canvas *   const canvasP,
-           int               const x,
-           int               const y,
-           struct RGBColor * const clr,
-           transfer_func           trf) {
+drawPixel(struct Canvas *   const canvasP,
+          int               const x,
+          int               const y,
+          struct RGBColor * const clr,
+          transfer_func           trf) {
 
     if (x < clip_rect.left || x >= clip_rect.right ||
         y < clip_rect.top  || y >= clip_rect.bottom) {
     } else {
-        unsigned int const i = PIXEL_INDEX(x, y);
+        unsigned int const i = pixelIndex(picFrame, x, y);
 
         struct RGBColor dst;
 
@@ -2902,55 +3132,66 @@ draw_pixel(struct canvas *   const canvasP,
 
 
 static void
-draw_pen_rect(struct canvas * const canvasP,
-              struct Rect *   const r) {
+drawPenRect(struct Canvas * const canvasP,
+            struct Rect *   const rP) {
 
-    int const rowadd = rowlen - (r->right - r->left);
+    if (!rectisnull(rP)) {
+        unsigned int const rowadd = rowlen - (rP->right - rP->left);
 
-    int i;
-    int x, y;
-    struct RGBColor dst;
+        unsigned int i;
+        unsigned int y;
 
-    i = PIXEL_INDEX(r->left, r->top);  /* initial value */
+        dumpRect("BRYAN: drawing rectangle ", *rP);
+        i = pixelIndex(picFrame, rP->left, rP->top);  /* initial value */
 
-    for (y = r->top; y < r->bottom; y++) {
-        for (x = r->left; x < r->right; x++) {
-            dst.red = canvasP->planes.red[i];
-            dst.grn = canvasP->planes.grn[i];
-            dst.blu = canvasP->planes.blu[i];
+        for (y = rP->top; y < rP->bottom; ++y) {
 
-            if (pen_pat.pix[(x & 7) + (y & 7) * 8])
-                (*pen_trf)(&black, &dst);
-            else
-                (*pen_trf)(&white, &dst);
+            unsigned int x;
+
+            for (x = rP->left; x < rP->right; ++x) {
 
-            canvasP->planes.red[i] = dst.red;
-            canvasP->planes.grn[i] = dst.grn;
-            canvasP->planes.blu[i] = dst.blu;
+                struct RGBColor dst;
 
-            i++;
+                assert(i < canvasP->planes.height * canvasP->planes.width);
+
+                dst.red = canvasP->planes.red[i];
+                dst.grn = canvasP->planes.grn[i];
+                dst.blu = canvasP->planes.blu[i];
+
+                if (pen_pat.pix[(x & 7) + (y & 7) * 8])
+                    (*pen_trf)(&black, &dst);
+                else
+                    (*pen_trf)(&white, &dst);
+
+                canvasP->planes.red[i] = dst.red;
+                canvasP->planes.grn[i] = dst.grn;
+                canvasP->planes.blu[i] = dst.blu;
+
+                ++i;
+            }
+            i += rowadd;
         }
-        i += rowadd;
     }
 }
 
 
 
 static void
-draw_pen(struct canvas * const canvasP,
-         int             const x,
-         int             const y) {
+drawPen(struct Canvas * const canvasP,
+        int             const x,
+        int             const y) {
 
-    struct Rect penrect;
+    struct Rect unclippedPenrect;
+    struct Rect clippedPenrect;
 
-    penrect.left = x;
-    penrect.right = x + pen_width;
-    penrect.top = y;
-    penrect.bottom = y + pen_height;
+    unclippedPenrect.left = x;
+    unclippedPenrect.right = x + pen_width;
+    unclippedPenrect.top = y;
+    unclippedPenrect.bottom = y + pen_height;
 
-    rectinter(penrect, clip_rect, &penrect);
+    rectintersect(&unclippedPenrect, &clip_rect, &clippedPenrect);
 
-    draw_pen_rect(canvasP, &penrect);
+    drawPenRect(canvasP, &clippedPenrect);
 }
 
 /*
@@ -2967,11 +3208,11 @@ draw_pen(struct canvas * const canvasP,
  * Paul Heckbert    3 Sep 85
  */
 static void
-scan_line(struct canvas * const canvasP,
-          short           const x1,
-          short           const y1,
-          short           const x2,
-          short           const y2) {
+scanLine(struct Canvas * const canvasP,
+         short           const x1,
+         short           const y1,
+         short           const x2,
+         short           const y2) {
 
     int d, x, y, ax, ay, sx, sy, dx, dy;
 
@@ -2985,7 +3226,7 @@ scan_line(struct canvas * const canvasP,
         if (ax>ay) {        /* x dominant */
             d = ay-(ax>>1);
             for (;;) {
-                draw_pen(canvasP, x, y);
+                drawPen(canvasP, x, y);
                 if (x==x2) return;
                 if ((x > rowlen) && (sx > 0)) return;
                 if (d>=0) {
@@ -2999,7 +3240,7 @@ scan_line(struct canvas * const canvasP,
         else {          /* y dominant */
             d = ax-(ay>>1);
             for (;;) {
-                draw_pen(canvasP, x, y);
+                drawPen(canvasP, x, y);
                 if (y==y2) return;
                 if ((y > collen) && (sy > 0)) return;
                 if (d>=0) {
@@ -3018,17 +3259,20 @@ scan_line(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);
-  scan_line(canvasP, p1.x,p1.y,current.x,current.y);
+
+  scanLine(canvasP, p1.x,p1.y,current.x,current.y);
 }
 
 
@@ -3036,17 +3280,20 @@ 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);
 
     if (!blitListP)
-        scan_line(canvasP, current.x, current.y, p1.x, p1.y);
+        scanLine(canvasP, current.x, current.y, p1.x, p1.y);
 
     current.x = p1.x;
     current.y = p1.y;
@@ -3057,20 +3304,24 @@ 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;
 
     if (!blitListP)
-        scan_line(canvasP, p1.x, p1.y, current.x, current.y);
+        scanLine(canvasP, p1.x, p1.y, current.x, current.y);
 }
 
 
@@ -3078,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)
-        scan_line(canvasP, current.x, current.y, p1.x, p1.y);
+        scanLine(canvasP, current.x, current.y, p1.x, p1.y);
+
     current.x = p1.x;
     current.y = p1.y;
 }
@@ -3098,17 +3355,17 @@ ShortLineFrom(struct canvas * const canvasP,
 
 
 static void
-do_paintRect(struct canvas * const canvasP,
-             struct Rect     const prect) {
+doPaintRect(struct Canvas * const canvasP,
+            struct Rect     const prect) {
 
     struct Rect rect;
 
     if (verbose)
         dumpRect("painting", prect);
 
-    rectinter(clip_rect, prect, &rect);
+    rectintersect(&clip_rect, &prect, &rect);
 
-    draw_pen_rect(canvasP, &rect);
+    drawPenRect(canvasP, &rect);
 }
 
 
@@ -3116,13 +3373,15 @@ do_paintRect(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)
-        do_paintRect(canvasP, cur_rect);
+        doPaintRect(canvasP, cur_rect);
 }
 
 
@@ -3130,19 +3389,20 @@ 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)
-        do_paintRect(canvasP, cur_rect);
+        doPaintRect(canvasP, cur_rect);
 }
 
 
 
 static void
-do_frameRect(struct canvas * const canvasP,
-             struct Rect     const rect) {
+doFrameRect(struct Canvas * const canvasP,
+            struct Rect     const rect) {
 
     if (verbose)
         dumpRect("framing", rect);
@@ -3151,13 +3411,13 @@ do_frameRect(struct canvas * const canvasP,
         unsigned int x, y;
 
         for (x = rect.left; x <= rect.right - pen_width; x += pen_width) {
-            draw_pen(canvasP, x, rect.top);
-            draw_pen(canvasP, x, rect.bottom - pen_height);
+            drawPen(canvasP, x, rect.top);
+            drawPen(canvasP, x, rect.bottom - pen_height);
         }
 
         for (y = rect.top; y <= rect.bottom - pen_height ; y += pen_height) {
-            draw_pen(canvasP, rect.left, y);
-            draw_pen(canvasP, rect.right - pen_width, y);
+            drawPen(canvasP, rect.left, y);
+            drawPen(canvasP, rect.right - pen_width, y);
         }
     }
 }
@@ -3167,13 +3427,15 @@ do_frameRect(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)
-        do_frameRect(canvasP, cur_rect);
+        doFrameRect(canvasP, cur_rect);
 }
 
 
@@ -3181,12 +3443,13 @@ 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)
-        do_frameRect(canvasP, cur_rect);
+        doFrameRect(canvasP, cur_rect);
 }
 
 
@@ -3194,7 +3457,7 @@ frameSameRect(struct canvas * const canvasP,
 /* a stupid shell sort - I'm so embarrassed  */
 
 static void
-poly_sort(int const sort_index, struct Point points[]) {
+polySort(int const sort_index, struct Point points[]) {
   int d, i, j, temp;
 
   /* initialize and set up sort interval */
@@ -3227,9 +3490,9 @@ poly_sort(int const sort_index, struct Point points[]) {
 /* Watch out for the lack of error checking in the next two functions ... */
 
 static void
-scan_poly(struct canvas * const canvasP,
-          int             const np,
-          struct Point          pts[]) {
+scanPoly(struct Canvas * const canvasP,
+         int             const np,
+         struct Point          pts[]) {
 
   int dx,dy,dxabs,dyabs,i,scan_index,j,k,px,py;
   int sdx,sdy,x,y,toggle,old_sdy,sy0;
@@ -3283,7 +3546,7 @@ scan_poly(struct canvas * const canvasP,
         scan_index++;
       }
       px += sdx;
-      draw_pen(canvasP, px, py);
+      drawPen(canvasP, px, py);
     }
       }
     else
@@ -3299,7 +3562,7 @@ scan_poly(struct canvas * const canvasP,
         old_sdy = sdy;
         if (sdy != 0) scan_index--;
       }
-      draw_pen(canvasP, px,py);
+      drawPen(canvasP, px,py);
       coord[scan_index].x = px;
       coord[scan_index].y = py;
       scan_index++;
@@ -3312,14 +3575,14 @@ scan_poly(struct canvas * const canvasP,
   scan_index--;
   if (sy0 + sdy == 0) scan_index--;
 
-  poly_sort(scan_index, coord);
+  polySort(scan_index, coord);
 
   toggle = 0;
   for (i = 0; i < scan_index; i++) {
     if ((coord[i].y == coord[i+1].y) && (toggle == 0))
       {
     for (j = coord[i].x; j <= coord[i+1].x; j++)
-      draw_pen(canvasP, j, coord[i].y);
+      drawPen(canvasP, j, coord[i].y);
     toggle = 1;
       }
     else
@@ -3332,21 +3595,26 @@ scan_poly(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(ifP, &bb);
 
-  readRect(&bb);
-  for (i=0; i<np; ++i)
-    readPoint(&pts[i]);
+  for (i = 0; i < np; ++i)
+      readPoint(ifP, &pts[i]);
 
   /* scan convert poly ... */
   if (!blitListP)
-      scan_poly(canvasP, np, pts);
+      scanPoly(canvasP, np, pts);
 }
 
 
@@ -3354,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);
@@ -3369,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);
 }
 
 
@@ -3390,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));
 }
 
 
@@ -3404,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);
 }
@@ -3418,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);
 }
@@ -3430,9 +3708,10 @@ TxSize(struct canvas * const canvasP,
 
 
 static void
-skip_text(blitList * const blitListP) {
+skipText(FILE *     const ifP,
+         BlitList * const blitListP) {
 
-    skip(readByte());
+    skip(ifP, readByte(ifP));
 
     blitListP->unblittableText = true;
 }
@@ -3440,7 +3719,7 @@ skip_text(blitList * const blitListP) {
 
 
 static int
-abs_value(int const x) {
+absValue(int const x) {
     if (x < 0)
         return -x;
     else
@@ -3450,18 +3729,18 @@ abs_value(int const x) {
 
 
 static struct font*
-get_font(int const font,
-         int const size,
-         int const style) {
+getFont(int const font,
+        int const size,
+        int const style) {
 
     int closeness, bestcloseness;
-    struct fontinfo* fi, *best;
+    struct FontInfo* fi, *best;
 
     best = 0;
     for (fi = fontlist; fi; fi = fi->next) {
-        closeness = abs_value(fi->font - font) * 10000 +
-            abs_value(fi->size - size) * 100 +
-            abs_value(fi->style - style);
+        closeness = absValue(fi->font - font) * 10000 +
+            absValue(fi->size - size) * 100 +
+            absValue(fi->style - style);
         if (!best || closeness < bestcloseness) {
             best = fi;
             bestcloseness = closeness;
@@ -3515,9 +3794,10 @@ rotate(int * const x,
 
 
 static void
-do_ps_text(struct canvas * const canvasP,
-           Word            const tx,
-           Word            const ty) {
+doPsText(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         Word            const tx,
+         Word            const ty) {
 
     int len, width, i, w, h, x, y, rx, ry, o;
     Byte str[256], ch;
@@ -3532,12 +3812,12 @@ do_ps_text(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;
     }
@@ -3567,7 +3847,7 @@ do_ps_text(struct canvas * const canvasP,
                 if ((rx >= picFrame.left) && (rx < picFrame.right) &&
                     (ry >= picFrame.top) && (ry < picFrame.bottom))
                 {
-                    o = PIXEL_INDEX(rx, ry);
+                    o = pixelIndex(picFrame, rx, ry);
                     if (glyph->bmap[h * glyph->width + w]) {
                         canvasP->planes.red[o] = foreground.red;
                         canvasP->planes.grn[o] = foreground.grn;
@@ -3584,27 +3864,28 @@ do_ps_text(struct canvas * const canvasP,
 
 
 static void
-do_text(struct canvas *  const canvasP,
-        blitList *       const blitListP,
-        Word             const startx,
-        Word             const starty) {
+doText(FILE *           const ifP,
+       struct Canvas *  const canvasP,
+       BlitList *       const blitListP,
+       Word             const startx,
+       Word             const starty) {
 
     if (blitListP)
-        skip_text(blitListP);
+        skipText(ifP, blitListP);
     else {
-        if (!(tfont = get_font(text_font, text_size, text_face)))
+        if (!(tfont = getFont(text_font, text_size, text_face)))
             tfont = pbm_defaultfont("bdf");
 
         if (ps_text)
-            do_ps_text(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;
@@ -3616,8 +3897,8 @@ do_text(struct canvas *  const canvasP,
                             struct RGBColor * const colorP =
                                 glyph->bmap[h * glyph->width + w] ?
                                 &black : &white;
-                            draw_pixel(canvasP,
-                                       x + w + glyph->x, dy, colorP, text_trf);
+                            drawPixel(canvasP,
+                                      x + w + glyph->x, dy, colorP, text_trf);
                         }
                     }
                     x += glyph->xadd;
@@ -3634,15 +3915,16 @@ do_text(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);
 
-    do_text(canvasP, blitListP, p.x, p.y);
+    doText(ifP, canvasP, blitListP, p.x, p.y);
 }
 
 
@@ -3650,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);
 
-    do_text(canvasP, blitListP, current.x, current.y);
+    doText(ifP, canvasP, blitListP, current.x, current.y);
 }
 
 
@@ -3664,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);
 
-    do_text(canvasP, blitListP, current.x, current.y);
+    doText(ifP, canvasP, blitListP, current.x, current.y);
 }
 
 
@@ -3678,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);
@@ -3692,7 +3978,7 @@ DHDVText(struct canvas * const canvasP,
     current.x += dh;
     current.y += dv;
 
-    do_text(canvasP, blitListP, current.x, current.y);
+    doText(ifP, canvasP, blitListP, current.x, current.y);
 }
 
 
@@ -3702,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);
@@ -3761,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);
 }
 
 
@@ -3773,78 +4061,80 @@ 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
-do_pixmap(struct canvas * const canvasP,
-          blitList *      const blitListP,
-          int             const version,
-          Word            const rowBytes,
-          int             const is_region) {
+doPixmap(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
+         int             const version,
+         Word            const rowBytes,
+         int             const is_region) {
 /*----------------------------------------------------------------------------
    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);
 }
 
 
 
 static void
-do_bitmap(FILE *          const ifP,
-          struct canvas * const canvasP,
-          blitList *      const blitListP,
-          int             const version,
-          int             const rowBytes,
-          int             const is_region) {
+doBitmap(FILE *          const ifP,
+         struct Canvas * const canvasP,
+         BlitList *      const blitListP,
+         int             const version,
+         int             const rowBytes,
+         int             const is_region) {
 /*----------------------------------------------------------------------------
    Do a bitmap.  That's one bit per pixel, 0 is white, 1 is black.
 
@@ -3854,22 +4144,22 @@ do_bitmap(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";
 
@@ -3886,8 +4176,9 @@ do_bitmap(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;
@@ -3895,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)
-        do_pixmap(canvasP, blitListP, version, rowBytes, 0);
+        doPixmap(ifP, canvasP, blitListP, version, rowBytes, 0);
     else
-        do_bitmap(ifp, canvasP, blitListP, version, rowBytes, 0);
+        doBitmap(ifP, canvasP, blitListP, version, rowBytes, 0);
 }
 
 
@@ -3910,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;
@@ -3919,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)
-        do_pixmap(canvasP, blitListP, version, rowBytes, 1);
+        doPixmap(ifP, canvasP, blitListP, version, rowBytes, 1);
     else
-        do_bitmap(ifp, canvasP, blitListP, version, rowBytes, 1);
+        doBitmap(ifP, canvasP, blitListP, version, rowBytes, 1);
 }
 
 
@@ -3935,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" },
@@ -4051,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)" },
@@ -4067,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)" },
@@ -4109,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) {
@@ -4124,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);
@@ -4142,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)
@@ -4156,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)
@@ -4170,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);
 }
@@ -4178,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);
 
@@ -4194,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);
@@ -4223,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 "
@@ -4247,8 +4554,9 @@ interpretPict(FILE * const ofP) {
     if (verbose)
         pm_message("PICT version %u", version);
 
-    while((opcode = get_op(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)
@@ -4263,79 +4571,30 @@ 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);
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/pjtoppm.c b/converter/ppm/pjtoppm.c
index b0c879a0..e556803f 100644
--- a/converter/ppm/pjtoppm.c
+++ b/converter/ppm/pjtoppm.c
@@ -161,7 +161,7 @@ main(int argc, const char ** argv) {
                 switch (c) {
                 case 'M':   /* transmission mode */
                     if (val != 0 && val != 1)
-                        pm_error("unimplemented trasmission mode %d", val);
+                        pm_error("unimplemented transmission mode %d", val);
                     mode = val;
                     modeIsSet = true;
                     break;
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/ppmtoarbtxt.c b/converter/ppm/ppmtoarbtxt.c
index 6d4ed04e..6d4c6eac 100644
--- a/converter/ppm/ppmtoarbtxt.c
+++ b/converter/ppm/ppmtoarbtxt.c
@@ -1079,7 +1079,7 @@ readSkeletonFile(const char *      const filename,
                 int rc;
                 rc = getc(sklfileP);
                 if (rc == EOF) {
-                    /* Not a replacement sequence, just an escape caharacter
+                    /* Not a replacement sequence, just an escape character
                        at the end of the file.
                     */
                     Buffer_add(&buffer, escape);
diff --git a/converter/ppm/ppmtobmp.c b/converter/ppm/ppmtobmp.c
index f89cec8d..41cee482 100644
--- a/converter/ppm/ppmtobmp.c
+++ b/converter/ppm/ppmtobmp.c
@@ -138,7 +138,7 @@ parseCommandLine(int argc, const char ** argv,
         cmdlineP->inputFilename = pm_strdup(argv[1]);
     else
         pm_error("Too many arguments.  The only argument accepted "
-                 "is the input file specificaton");
+                 "is the input file specification");
 
     free(option_def);
 }
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/converter/ppm/ppmtomitsu.c b/converter/ppm/ppmtomitsu.c
index 5b0b3245..50b790d6 100644
--- a/converter/ppm/ppmtomitsu.c
+++ b/converter/ppm/ppmtomitsu.c
@@ -705,7 +705,7 @@ main(int argc, char * argv[]) {
         for (row = 0; row < rows; ++row)
             ppm_readppmrow(ifP, pixels[row], cols, maxval, format);
 
-        /* first check wether we can use the lut transfer */
+        /* first check whether we can use the lut transfer */
 
         table = ppm_computecolorhist(pixels, cols, rows, MAXLUTCOL+1,
                                      &nColor);
diff --git a/converter/ppm/ppmtompeg/LOGIC b/converter/ppm/ppmtompeg/LOGIC
index 8c19dc8d..b346d597 100644
--- a/converter/ppm/ppmtompeg/LOGIC
+++ b/converter/ppm/ppmtompeg/LOGIC
@@ -45,7 +45,7 @@ is ready.
 
 When an encoder server finishes an assignment, it connects to the master
 server TCP listen port and tells the master it is done, and receives over
-the same connetion its next assignment.  If there is no more work to do,
+the same connection its next assignment.  If there is no more work to do,
 the master server instead tells the encoder server just to terminate.
 
 When the master server has told every encoder server to terminate, it
diff --git a/converter/ppm/ppmtompeg/Makefile b/converter/ppm/ppmtompeg/Makefile
index eeab9727..9ad09c77 100644
--- a/converter/ppm/ppmtompeg/Makefile
+++ b/converter/ppm/ppmtompeg/Makefile
@@ -124,7 +124,7 @@ profile: LDFLAGS_TARGET = \
 PERL = perl
 
 # The following stuff is for the Huffman encoding tables.  It's commented-out
-# because you probably don't want to change this.  If you do, then uncommment
+# because you probably don't want to change this.  If you do, then uncomment
 # it.
 #
 # huff.h: huff.c
diff --git a/converter/ppm/ppmtompeg/bsearch.c b/converter/ppm/ppmtompeg/bsearch.c
index c618bbd4..b825ef72 100644
--- a/converter/ppm/ppmtompeg/bsearch.c
+++ b/converter/ppm/ppmtompeg/bsearch.c
@@ -26,7 +26,7 @@
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  */
 
-/*  
+/*
  *  $Header: /n/picasso/project/mpeg/mpeg_dist/mpeg_encode/RCS/bsearch.c,v 1.10 1995/08/07 21:49:01 smoot Exp $
  *  $Log: bsearch.c,v $
  *  Revision 1.10  1995/08/07 21:49:01  smoot
@@ -37,7 +37,7 @@
  *  (B frames which are backward P's at the start of a sequence)
  *
  *  Revision 1.8  1995/03/27 19:17:43  smoot
- *  killed useless type error messge (int32 defiend as int)
+ *  killed useless type error message (int32 defined as int)
  *
  * Revision 1.7  1995/01/19  23:07:20  eyhung
  * Changed copyrights
@@ -194,7 +194,7 @@ FindBestMatchExhaust(const LumBlock * const blockP,
 
     /* maybe should try spiral pattern centered around  prev motion vector? */
 
-    /* try a spiral pattern */    
+    /* try a spiral pattern */
     for (distance = stepSize;
          distance <= searchRange;
          distance += stepSize) {
@@ -212,7 +212,7 @@ FindBestMatchExhaust(const LumBlock * const blockP,
                         m.y = my; m.x = mx;
                         diff = LumAddMotionError(currentBlockP, blockP, prev,
                                                  by, bx, m, bestDiff);
-                        
+
                         if (diff < bestDiff) {
                             *motionP = m;
                             bestDiff = diff;
@@ -237,7 +237,7 @@ FindBestMatchExhaust(const LumBlock * const blockP,
                         diff = LumAddMotionError(currentBlockP, blockP, prev,
                                                  by, bx,
                                                  m, bestDiff);
-                        
+
                         if (diff < bestDiff) {
                             *motionP = m;
                             bestDiff = diff;
@@ -310,7 +310,7 @@ FindBestMatchTwoLevel(const LumBlock * const blockP,
     if (VALID_MOTION(*motionP)) {
         bestDiff = LumAddMotionError(currentBlockP, blockP, prev, by, bx,
                                      *motionP, bestSoFar);
-        
+
         if (bestSoFar < bestDiff)
             bestDiff = bestSoFar;
     } else {
@@ -323,7 +323,7 @@ FindBestMatchTwoLevel(const LumBlock * const blockP,
 
     /* maybe should try spiral pattern centered around  prev motion vector? */
 
-    /* try a spiral pattern */    
+    /* try a spiral pattern */
     for ( distance = 2; distance <= searchRange; distance += 2 ) {
         tempRightMY = MIN(distance, rightMY);
         tempRightMX = MIN(distance, rightMX);
@@ -339,7 +339,7 @@ FindBestMatchTwoLevel(const LumBlock * const blockP,
                         m.y = my; m.x = mx;
                         diff = LumAddMotionError(currentBlockP, blockP, prev,
                                                  by, bx, m, bestDiff);
-                        
+
                         if (diff < bestDiff) {
                             *motionP = m;
                             bestDiff = diff;
@@ -361,7 +361,7 @@ FindBestMatchTwoLevel(const LumBlock * const blockP,
                         m.y = my; m.x = mx;
                         diff = LumAddMotionError(currentBlockP, blockP, prev,
                                                  by, bx, m, bestDiff);
-                        
+
                         if (diff < bestDiff) {
                             *motionP = m;
                             bestDiff = diff;
@@ -423,7 +423,7 @@ trySpacing(int              const spacing,
            MpegFrame *      const prev,
            int              const by,
            int              const bx) {
-           
+
     int tempRightMY, tempRightMX;
     int my;
     int bestDiff;
@@ -435,7 +435,7 @@ trySpacing(int              const spacing,
 
     tempRightMY = MIN(rightMY, center.y + spacing + 1);
     tempRightMX = MIN(rightMX, center.x + spacing + 1);
-    
+
     for (my = center.y - spacing; my < tempRightMY; my += spacing) {
         if (my >= leftMY) {
             int mx;
@@ -446,7 +446,7 @@ trySpacing(int              const spacing,
                     m.y = my; m.x = mx;
                     diff = LumAddMotionError(currentBlockP, blockP, prev,
                                              by, bx, m, bestDiff);
-                    
+
                     if (diff < bestDiff) {
                         /* We have a new best */
                         newCenter = m;
@@ -466,7 +466,7 @@ static void
 chooseNewSpacing(int   const oldSpacing,
                  int   const stepSize,
                  int * const newSpacingP) {
-        
+
     if (stepSize == 2) {  /* make sure spacing is even */
         if (oldSpacing == 2)
             *newSpacingP = 0;
@@ -530,7 +530,7 @@ FindBestMatchLogarithmic(const LumBlock * const blockP,
 
     /* Start at (0,0) */
     center.y = center.x = 0;
-    
+
     while (spacing >= stepSize) {
         trySpacing(spacing, center, bestDiff,
                    &center, &bestDiff,
@@ -580,7 +580,7 @@ FindBestMatchSubSample(const LumBlock * const blockP,
                        int              const searchRange) {
 
     /* too lazy to write the code for this... */
-    
+
     return FindBestMatchExhaust(blockP, currentBlockP, prev,
                                 by, bx, motionP, bestSoFar,
                                 searchRange);
@@ -671,9 +671,9 @@ BMotionSearchNoInterp(const LumBlock * const currentBlockP,
     /* CALL SEARCH PROCEDURE */
     switch(psearchAlg) {
     case PSEARCH_SUBSAMPLE:
-        *forwardErrP = PSubSampleSearch(currentBlockP, prev, by, bx, 
+        *forwardErrP = PSubSampleSearch(currentBlockP, prev, by, bx,
                                         &motionP->fwd,searchRangeB);
-        *backErrP = PSubSampleSearch(currentBlockP, next, by, bx, 
+        *backErrP = PSubSampleSearch(currentBlockP, next, by, bx,
                                      &motionP->bwd, searchRangeB);
         break;
     case PSEARCH_EXHAUSTIVE:
@@ -690,9 +690,9 @@ BMotionSearchNoInterp(const LumBlock * const currentBlockP,
                                      *forwardErrP, searchRangeB);
         break;
     case PSEARCH_LOGARITHMIC:
-        *forwardErrP = PLogarithmicSearch(currentBlockP, prev, by, bx, 
+        *forwardErrP = PLogarithmicSearch(currentBlockP, prev, by, bx,
                                           &motionP->fwd, searchRangeB);
-        *backErrP = PLogarithmicSearch(currentBlockP, next, by, bx, 
+        *backErrP = PLogarithmicSearch(currentBlockP, next, by, bx,
                                        &motionP->bwd, searchRangeB);
         break;
     case PSEARCH_TWOLEVEL:
@@ -731,7 +731,7 @@ BMotionSearchNoInterp(const LumBlock * const currentBlockP,
  * *fmyP,fmxP,bmyP,bmxP are inputs as well as outputs.  We do not update
  * them if it would make the error worse than the existing values.  Otherwise,
  * we update them to the vectors we find to be best.
- * 
+ *
  *===========================================================================*/
 static int
 BMotionSearchSimple(const LumBlock * const currentBlockP,
@@ -750,7 +750,7 @@ BMotionSearchSimple(const LumBlock * const currentBlockP,
     /* STEP 1 */
     BMotionSearchNoInterp(currentBlockP, prev, next, by, bx, motionP,
                           &forwardErr, &backErr, TRUE);
-              
+
     /* STEP 2 */
 
     ComputeBMotionLumBlock(prev, next, by, bx, MOTION_INTERPOLATE,
@@ -799,7 +799,7 @@ BMotionSearchCross2(const LumBlock * const currentBlockP,
                     int              const bx,
                     motion *         const motionP,
                     int              const oldMode) {
-    
+
     int retval;
     LumBlock forwardBlock, backBlock;
     int32   forwardErr, backErr;
@@ -816,19 +816,19 @@ BMotionSearchCross2(const LumBlock * const currentBlockP,
 
     {
         /* STEP 2 */
-        
+
         struct motion motion;
         motion.fwd = motionP->fwd;
         motion.bwd.y = motion.bwd.x = 0;
         ComputeBMotionLumBlock(prev, next, by, bx, MOTION_FORWARD, motion,
                                &forwardBlock);
-        
+
         motion.fwd.y = motion.fwd.x = 0;
         motion.bwd = motionP->bwd;
         ComputeBMotionLumBlock(prev, next, by, bx, MOTION_BACKWARD, motion,
                                &backBlock);
     }
-    /* try a cross-search; total of 4 local searches */    
+    /* try a cross-search; total of 4 local searches */
     newMotion = *motionP;
 
     interpErrF = FindBestMatch(&forwardBlock, currentBlockP,
@@ -934,11 +934,11 @@ BMotionSearchExhaust(const LumBlock * const currentBlockP,
                                            motion, &forwardBlock);
 
                     newMotion = motion.fwd;
-                    
+
                     diff = FindBestMatch(&forwardBlock,
                                          currentBlockP, next, by, bx,
                                          &newMotion, bestDiff, searchRangeB);
-                    
+
                     if (diff < bestDiff) {
                         motionP->fwd = motion.fwd;
                         motionP->bwd = newMotion;
@@ -968,7 +968,7 @@ BMotionSearchExhaust(const LumBlock * const currentBlockP,
  *
  * PRECONDITIONS:   The relevant block in 'current' is valid (it has not
  *          been dct'd).  Thus, the data in 'current' can be
- *          accesed through y_blocks, cr_blocks, and cb_blocks.
+ *          accessed through y_blocks, cr_blocks, and cb_blocks.
  *          This is not the case for the blocks in 'prev' and
  *          'next.'  Therefore, references into 'prev' and 'next'
  *          should be done
@@ -1001,7 +1001,7 @@ BMotionSearch(const LumBlock * const currentBlockP,
         PMotionSearch(currentBlockP, next, by, bx, &motionP->bwd);
         return MOTION_BACKWARD;
     }
-  
+
     /* otherwise simply call the appropriate algorithm, based on user
        preference
     */
diff --git a/converter/ppm/ppmtompeg/docs/template.param b/converter/ppm/ppmtompeg/docs/template.param
index 78ad5300..fb837428 100644
--- a/converter/ppm/ppmtompeg/docs/template.param
+++ b/converter/ppm/ppmtompeg/docs/template.param
@@ -138,7 +138,7 @@ BQSCALE		25
 # this must be ORIGINAL or DECODED
 REFERENCE_FRAME	ORIGINAL
 
-# for parallel parameters see parallel.param in the exmaples subdirectory
+# for parallel parameters see parallel.param in the examples subdirectory
 
 # if you want constant bit-rate mode, specify it as follows (number is bits/sec):
 BIT_RATE  1000000
diff --git a/converter/ppm/ppmtompeg/examples/payam.param b/converter/ppm/ppmtompeg/examples/payam.param
index ce886914..e9287a89 100644
--- a/converter/ppm/ppmtompeg/examples/payam.param
+++ b/converter/ppm/ppmtompeg/examples/payam.param
@@ -16,7 +16,7 @@ kh*.pnm	[1-3]
 END_INPUT
 
 
-# motion vector search paramters
+# motion vector search parameters
 
 # MAD or MSE -- must be upper case
 ERROR		MAD
diff --git a/converter/ppm/ppmtompeg/examples/payam18.param b/converter/ppm/ppmtompeg/examples/payam18.param
index 7f7b767e..95839e83 100644
--- a/converter/ppm/ppmtompeg/examples/payam18.param
+++ b/converter/ppm/ppmtompeg/examples/payam18.param
@@ -15,7 +15,7 @@ kh*.pnm	[1-39]
 END_INPUT
 
 
-# motion vector search paramters
+# motion vector search parameters
 
 # FULL or HALF -- must be upper case
 PIXEL		HALF
diff --git a/converter/ppm/ppmtompeg/examples/template.param b/converter/ppm/ppmtompeg/examples/template.param
index 78ad5300..fb837428 100644
--- a/converter/ppm/ppmtompeg/examples/template.param
+++ b/converter/ppm/ppmtompeg/examples/template.param
@@ -138,7 +138,7 @@ BQSCALE		25
 # this must be ORIGINAL or DECODED
 REFERENCE_FRAME	ORIGINAL
 
-# for parallel parameters see parallel.param in the exmaples subdirectory
+# for parallel parameters see parallel.param in the examples subdirectory
 
 # if you want constant bit-rate mode, specify it as follows (number is bits/sec):
 BIT_RATE  1000000
diff --git a/converter/ppm/ppmtompeg/frame.c b/converter/ppm/ppmtompeg/frame.c
index f5a0d39d..09e35410 100644
--- a/converter/ppm/ppmtompeg/frame.c
+++ b/converter/ppm/ppmtompeg/frame.c
@@ -12,7 +12,7 @@
  *  Frame_AllocYCC                               *
  *  Frame_AllocDecoded                           *
  *  Frame_AllocHalf                                  *
- *  Frame_Resize                                     * 
+ *  Frame_Resize                                     *
  *                                       *
  *===========================================================================*/
 
@@ -52,7 +52,7 @@
  *===========*/
 
 /* The maximum number of B-Frames allowed between reference frames. */
-#define  B_FRAME_RUN  16    
+#define  B_FRAME_RUN  16
 
 /*==================*
  * GLOBAL VARIABLES *
@@ -64,13 +64,13 @@ static unsigned int numOfFrames;
 
 /*====================================================
 * Resize_Array_Width
-*    
+*
 *   This function will resize any array width up
 * or down in size.  The algorithm is based on the
 * least common multiple approach more commonly
 * used in audio frequency adjustments.
 *=====================================================*/
-static void 
+static void
 Resize_Array_Width(uint8 ** const inarray,
                    int      const in_x,
                    int      const in_y,
@@ -86,7 +86,7 @@ Resize_Array_Width(uint8 ** const inarray,
     uint8 pointA,pointB;
     double slope,diff;
 #endif
-    
+
     for (i = 0; i < in_y; ++i) {     /* For each row */
         unsigned int j;
         inptr = &inarray[i][0];
@@ -106,7 +106,7 @@ Resize_Array_Width(uint8 ** const inarray,
                     in_total = in_total - out_x;
                     --inptr;
                 }
-            } else {  
+            } else {
 #ifdef DOING_INTERPOLATION
                 pointA = *inptr;
 #endif
@@ -124,10 +124,10 @@ Resize_Array_Width(uint8 ** const inarray,
                 } else {
                     *outptr = (pointB -
                                (uint8)(slope*(((float)(out_x)) - diff)));
-                } 
+                }
 #endif
                 /* Non-Interpolative solution */
-                *outptr = *inptr;  
+                *outptr = *inptr;
 
                 ++outptr;
                 out_total = out_total + in_x;
@@ -153,7 +153,7 @@ Resize_Array_Width(uint8 ** const inarray,
 * Same as Resize_array_Width except pointer
 * manipulation must change.
 *===============================*/
-static void 
+static void
 Resize_Array_Height(uint8 ** const inarray,
                     int      const in_x,
                     int      const in_y,
@@ -176,7 +176,7 @@ Resize_Array_Height(uint8 ** const inarray,
         out_total = 0;
         k = 0;
         for(j=0; j < out_y; ++j){  /* for each output value */
-            if (in_total == out_total) {  
+            if (in_total == out_total) {
                 outarray[j][i] = inarray[k][i];
                 out_total=out_total+in_y;
                 while(in_total < out_total){
@@ -187,7 +187,7 @@ Resize_Array_Height(uint8 ** const inarray,
                     in_total = in_total - out_y;
                     --k;
                 }
-            } else {  
+            } else {
 #ifdef DOING_INTERPOLATION
                 pointA = inarray[k][i];
                 if (k != (in_y - 1)) {
@@ -210,7 +210,7 @@ Resize_Array_Height(uint8 ** const inarray,
                     in_total = in_total - out_y;
                     --k;
                 }
-            } 
+            }
         }
     }
 }
@@ -220,7 +220,7 @@ Resize_Array_Height(uint8 ** const inarray,
 /*========================================================
 * Resize_Width
 *======================================================*/
-static void  
+static void
 Resize_Width(MpegFrame * const omfrw,
              MpegFrame * const mfrw,
              int         const in_x,
@@ -274,12 +274,12 @@ Resize_Width(MpegFrame * const omfrw,
             free(mfrw->orig_y[i]);
         }
         free(mfrw->orig_y);
-        
+
         for (i = 0; i < in_y / 2; ++i) {
             free(mfrw->orig_cr[i]);
         }
         free(mfrw->orig_cr);
-        
+
         for (i = 0; i < in_y / 2; ++i) {
             free(mfrw->orig_cb[i]);
         }
@@ -300,9 +300,9 @@ Resize_Height(MpegFrame * const omfrh,
               int         const in_x,
               int         const in_y,
               int         const out_y) {
-    
-    unsigned int y; 
-    
+
+    unsigned int y;
+
     Fsize_y = out_y;
 
     /* Allocate new frame memory */
@@ -347,12 +347,12 @@ Resize_Height(MpegFrame * const omfrh,
             free(mfrh->orig_y[i]);
         }
         free(mfrh->orig_y);
-        
+
     for (i = 0; i < in_y / 2; ++i) {
         free(mfrh->orig_cr[i]);
     }
     free(mfrh->orig_cr);
-    
+
     for (i = 0; i < in_y / 2; ++i) {
         free(mfrh->orig_cb[i]);
     }
@@ -386,8 +386,8 @@ Frame_Init(unsigned int const numOfFramesRequested) {
     for (idx = 0; idx < numOfFrames; ++idx) {
         MALLOCVAR(frameMemory[idx]);
         frameMemory[idx]->inUse = FALSE;
-        frameMemory[idx]->orig_y = NULL;    
-        frameMemory[idx]->y_blocks = NULL; 
+        frameMemory[idx]->orig_y = NULL;
+        frameMemory[idx]->y_blocks = NULL;
         frameMemory[idx]->decoded_y = NULL;
         frameMemory[idx]->halfX = NULL;
         frameMemory[idx]->next = NULL;
@@ -458,11 +458,11 @@ FreeFrame(MpegFrame * const frameP) {
             for ( i = 0; i < Fsize_y; ++i )
                 free(frameP->halfX[i]);
             free(frameP->halfX);
-            
+
             for (i = 0; i < Fsize_y-1; ++i)
                 free(frameP->halfY[i]);
             free(frameP->halfY);
-            
+
             for (i = 0; i < Fsize_y-1; ++i)
                 free(frameP->halfBoth[i]);
             free(frameP->halfBoth);
@@ -542,7 +542,7 @@ GetUnusedFrame() {
                 "See the man page for help.\n");
         exit(1);
     }
-    return frameMemory[idx]; 
+    return frameMemory[idx];
 }
 
 
@@ -638,7 +638,7 @@ Frame_AllocBlocks(MpegFrame * const frameP) {
             MALLOCARRAY(frameP->y_blocks[i], dctx);
             ERRCHK(frameP->y_blocks[i], "malloc");
         }
-    
+
         MALLOCARRAY(frameP->cr_blocks, dcty / 2);
         ERRCHK(frameP->cr_blocks, "malloc");
         MALLOCARRAY(frameP->cb_blocks, dcty / 2);
@@ -672,7 +672,7 @@ Frame_AllocYCC(MpegFrame * const frameP) {
         /* already allocated */
     } else {
         unsigned int y;
-    
+
         DBG_PRINT(("ycc_calc:\n"));
         /*
          * first, allocate tons of memory
@@ -755,7 +755,7 @@ Frame_AllocHalf(MpegFrame * const frameP) {
  *
  *  allocate memory for decoded frame for the given frame, if required
  *  if makeReference == TRUE, then makes it reference frame
- * 
+ *
  * RETURNS: nothing
  *
  * SIDE EFFECTS:    none
@@ -781,14 +781,14 @@ Frame_AllocDecoded(MpegFrame * const frameP,
             MALLOCARRAY(frameP->decoded_y[y], Fsize_x);
             ERRCHK(frameP->decoded_y[y], "malloc");
         }
-        
+
         MALLOCARRAY(frameP->decoded_cr, Fsize_y / 2);
         ERRCHK(frameP->decoded_cr, "malloc");
         for (y = 0; y < (Fsize_y / 2); ++y) {
             MALLOCARRAY(frameP->decoded_cr[y], Fsize_x / 2);
             ERRCHK(frameP->decoded_cr[y], "malloc");
         }
-        
+
         MALLOCARRAY(frameP->decoded_cb, Fsize_y / 2);
         ERRCHK(frameP->decoded_cb, "malloc");
         for (y = 0; y < (Fsize_y / 2); ++y) {
@@ -810,7 +810,7 @@ Frame_AllocDecoded(MpegFrame * const frameP,
  *
  * Frame_Resize                  by James Boucher
  *                Boston University Multimedia Communications Lab
- *  
+ *
  *     This function takes the mf input frame, read in READFrame(),
  * and resizes all the input component arrays to the output
  * dimensions specified in the parameter file as OUT_SIZE.
@@ -828,11 +828,11 @@ Frame_Resize(MpegFrame * const omf,
     MpegFrame * frameAP;  /* intermediate frame */
 
     MALLOCVAR_NOFAIL(frameAP);
-    
+
     if (insize_x != outsize_x && insize_y != outsize_y) {
         Resize_Width(frameAP, mf, insize_x, insize_y, outsize_x);
         Resize_Height(omf, frameAP, outsize_x, insize_y, outsize_y);
-    } else 
+    } else
         if (insize_x ==outsize_x && insize_y != outsize_y) {
             Resize_Height(omf, mf, insize_x, insize_y, outsize_y);
         } else
@@ -843,3 +843,5 @@ Frame_Resize(MpegFrame * const omf,
 
     free(frameAP);
 }
+
+
diff --git a/converter/ppm/ppmtompeg/frametype.c b/converter/ppm/ppmtompeg/frametype.c
index 09afa403..debefcdc 100644
--- a/converter/ppm/ppmtompeg/frametype.c
+++ b/converter/ppm/ppmtompeg/frametype.c
@@ -13,7 +13,7 @@
  *	FType_FutureRef	returns the number of the future reference frame     *
  *	FType_PastRef	returns the number of the past reference frame	     *
  *									     *
- * 00.12.07 change malloc from frameTable to calloc to fix bug 
+ * 00.12.07 change malloc from frameTable to calloc to fix bug
  *===========================================================================*/
 
 /*
@@ -86,24 +86,24 @@ FType_Type(unsigned int const frameNum) {
 
     char retval;
 
-    if (use_cache) 
+    if (use_cache)
         return frameTable[frameNum].typ;
-  
+
     if (frameNum+1 == numFrames) {
         /* It's the last frame in the sequence.  If the pattern says it's
            a B, we convert it to I because a B frame makes no sense as the
            last frame of a sequence.
         */
-        if (patternedType == 'b') 
+        if (patternedType == 'b')
             retval = 'i';
-        else 
+        else
             retval = patternedType;
     } else {
         if (specificsOn) {
             static int lastI = -1;
             int newtype;
-      
-            if (lastI > frameNum) 
+
+            if (lastI > frameNum)
                 lastI = -1;
             newtype = SpecTypeLookup(frameNum);
             switch (newtype) {
@@ -119,13 +119,13 @@ FType_Type(unsigned int const frameNum) {
                 break;
             default:
                 if (lastI != -1) {
-                    unsigned int const pretendFrameNumber = 
+                    unsigned int const pretendFrameNumber =
                         (frameNum - lastI + firstI) % framePatternLen;
                     retval = framePattern[pretendFrameNumber];
-                } else 
+                } else
                     retval = patternedType;
             }
-        } else 
+        } else
             retval = patternedType;
     }
     return retval;
@@ -180,7 +180,7 @@ FType_PastRef(currFrameNum)
     } else {
       index = currFrameNum % framePatternLen;
       pastIndex = frameTable[index].prev->number;
-      
+
       return currFrameNum -
 	(((index-pastIndex)+framePatternLen) % framePatternLen);
     }
@@ -227,14 +227,14 @@ SetFramePattern(const char * const pattern) {
     firstI = -1;
     for (index = 0; index < len; index++) {
         switch( SIMPLE_ASCII_UPPER(pattern[index]) ) {
-        case 'I':	
+        case 'I':
             buf[index] = 'i';
             if (firstI == -1) firstI = index;
             break;
-        case 'P':	
-            buf[index] = 'p'; 
+        case 'P':
+            buf[index] = 'p';
             break;
-        case 'B':	
+        case 'B':
             buf[index] = 'b';
             break;
         default:
@@ -248,7 +248,7 @@ SetFramePattern(const char * const pattern) {
 
     framePattern = buf;
     framePatternLen = len;
-    
+
     /* Used to ComputeFrameTable(), but now must wait until param
        parsed. (STDIN or not)
     */
@@ -259,7 +259,7 @@ SetFramePattern(const char * const pattern) {
 void
 ComputeFrameTable(unsigned int const numFramesArg) {
 /*----------------------------------------------------------------------------
-  Compute a table of I, P, B frames to help in determining dependencie
+  Compute a table of I, P, B frames to help in determining dependency
 
   'numFrames' == 0 means number of frames is not known at this time.
 -----------------------------------------------------------------------------*/
@@ -339,7 +339,7 @@ ComputeFrameTable(unsigned int const numFramesArg) {
 	        break;
         }
     }
-    
+
     /* why? SRS */
     frameTable[table_size].number = framePatternLen;
     ptr = firstB;
@@ -362,3 +362,6 @@ ComputeFrameTable(unsigned int const numFramesArg) {
     if (numFrames)
         use_cache = TRUE;
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/jpeg.c b/converter/ppm/ppmtompeg/jpeg.c
index 24c9ae2d..4540f6f0 100644
--- a/converter/ppm/ppmtompeg/jpeg.c
+++ b/converter/ppm/ppmtompeg/jpeg.c
@@ -1,12 +1,12 @@
 /*===========================================================================*
- * jpeg.c                              
- *                                     
- *  procedures to deal with JPEG files 
- *                                     
- * EXPORTED PROCEDURES:                
- *  JMovie2JPEG                        
- *      ReadJPEG                      
- *                                    
+ * jpeg.c
+ *
+ *  procedures to deal with JPEG files
+ *
+ * EXPORTED PROCEDURES:
+ *  JMovie2JPEG
+ *      ReadJPEG
+ *
  *===========================================================================*/
 
 /* COPYRIGHT INFORMATION IS AT THE END OF THIS FILE */
@@ -20,7 +20,7 @@
 /* With the lossless jpeg patch applied to the Jpeg library
     (ftp://ftp.wizards.dupont.com/pub/ImageMagick/delegates/ljpeg-6b.tar.gz),
     the name of min_DCT_scaled_size changes to min_codec_data_unit,
-    for some reason.  With this macro, we change it back.  
+    for some reason.  With this macro, we change it back.
 */
 #define min_codec_data_unit min_DCT_scaled_size
 #include <jpeglib.h>
@@ -40,7 +40,7 @@
 /* make it happier.... */
 #undef DCTSIZE2
 
-/* jcopy_sample_rows() is an internal routine in the JPEG library, not 
+/* jcopy_sample_rows() is an internal routine in the JPEG library, not
    meant for use by us.  We should figure out what the official interface
    for this is and use it.  The following is copied out of jpegint.h, which
    is part of the JPEG library source code.
@@ -88,7 +88,7 @@ void
 JMovie2JPEG(const char * const infilename,
                 /* input filename string */
             const char * const obase,
-                /* output filename base string=>obase##.jpg */ 
+                /* output filename base string=>obase##.jpg */
             int          const start,
                 /* first frame to be extracted */
             int          const end
@@ -126,154 +126,154 @@ JMovie2JPEG(const char * const infilename,
        for the appending of the jpeg bitstream. It can be
        made smaller if you have a better idea of its expected size
     */
-    static unsigned char inbuffer[300000] = {    
-        0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46,  
+    static unsigned char inbuffer[300000] = {
+        0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46,
         0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
-        0x00, 0x01, 0x00, 0x00, 0xFF, 0xC0, 0x00, 0x11,  
+        0x00, 0x01, 0x00, 0x00, 0xFF, 0xC0, 0x00, 0x11,
         0x08, 0x00, 0xF0, 0x01, 0x40, 0x03, 0x01, 0x21,
-        0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xFF,  
+        0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xFF,
         0xDB, 0x00, 0x84, 0x00, 0x10, 0x0B, 0x0C, 0x0E,
-        0x0C, 0x0A, 0x10, 0x0E, 0x0D, 0x0E, 0x12,  
+        0x0C, 0x0A, 0x10, 0x0E, 0x0D, 0x0E, 0x12,
         0x11, 0x10, 0x13, 0x18, 0x28, 0x1A, 0x18, 0x16,
-        0x16, 0x18, 0x31, 0x23, 0x25, 0x1D, 0x28, 0x3A,  
+        0x16, 0x18, 0x31, 0x23, 0x25, 0x1D, 0x28, 0x3A,
         0x33, 0x3D, 0x3C, 0x39, 0x33, 0x38, 0x37, 0x40,
-        0x48, 0x5C, 0x4E, 0x40, 0x44, 0x57, 0x45, 0x37,  
+        0x48, 0x5C, 0x4E, 0x40, 0x44, 0x57, 0x45, 0x37,
         0x38, 0x50, 0x6D, 0x51, 0x57, 0x5F, 0x62, 0x67,
-        0x68, 0x67, 0x3E, 0x4D, 0x71, 0x79, 0x70, 0x64,  
+        0x68, 0x67, 0x3E, 0x4D, 0x71, 0x79, 0x70, 0x64,
         0x78, 0x5C, 0x65, 0x67, 0x63, 0x01, 0x11, 0x12,
-        0x12, 0x18, 0x15, 0x18, 0x2F, 0x1A, 0x1A, 0x2F,  
+        0x12, 0x18, 0x15, 0x18, 0x2F, 0x1A, 0x1A, 0x2F,
         0x63, 0x42, 0x38, 0x42, 0x63, 0x63, 0x63, 0x63,
-        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,  
-        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,  
-        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,  
-        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,  
-        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,  
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+        0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
         0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0xFF, 0xC4,
-        0x01, 0xA2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01,  
+        0x01, 0xA2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01,
         0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,  
+        0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
         0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
-        0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04,  
+        0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04,
         0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01,
-        0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05,  
+        0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05,
         0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
-        0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1,  
+        0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1,
         0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1,
-        0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09,   
+        0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09,
         0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26,
-        0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37,  
+        0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37,
         0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47,
-        0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57,  
+        0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57,
         0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67,
-        0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77,  
+        0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77,
         0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87,
-        0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96,  
+        0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96,
         0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5,
-        0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4,  
+        0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4,
         0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3,
-        0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2,  
+        0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2,
         0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA,
-        0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8,  
+        0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8,
         0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6,
-        0xF7, 0xF8, 0xF9, 0xFA, 0x01, 0x00, 0x03, 0x01,  
+        0xF7, 0xF8, 0xF9, 0xFA, 0x01, 0x00, 0x03, 0x01,
         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,  
-        0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
-        0x0A, 0x0B, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04,  
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
+        0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+        0x0A, 0x0B, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04,
         0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00,
-        0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11,  
+        0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11,
         0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51,
-        0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08,  
+        0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08,
         0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23,
-        0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1,   
+        0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1,
         0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17,
-        0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,  
+        0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,
         0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
-        0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54,  
+        0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54,
         0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64,
-        0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74,  
+        0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74,
         0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83,
-        0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92,  
+        0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92,
         0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
-        0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9,  
+        0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9,
         0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
-        0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,  
+        0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
         0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
-        0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5,  
+        0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5,
         0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4,
-        0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0xDA,  
+        0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0xDA,
         0x00, 0x0C, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03,
-        0x11, 0x00, 0x3F, 0x00  
+        0x11, 0x00, 0x3F, 0x00
 
     };
-    
+
     if (start > end) {
         fprintf(stderr,"bad frame numbers\n");
         exit(1);
     }
-    
+
     /* open J_Movie */
     inFile = fopen(infilename, "rb");
     if (inFile == NULL) {
         perror (infilename);
         exit(1);
     }
-    
-    /* get file descriptor */    
+
+    /* get file descriptor */
     fd = fileno(inFile);
-    
+
     /* The following lines parse the jpeg_movie header and recover the */
-    /* relavant information */
+    /* relevant information */
 
     fseek(inFile, 8 * sizeof(char), 0);
-    
+
     if (fread(&ver_no, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading version");
         exit(1);
-    }  
+    }
     if (ver_no != 2) {
         perror("Unrecognized version - Quantization tables may be wrong\n");
     }
     if (fread(&fps, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading fps");
         exit(1);
-    }  
+    }
     if (fread (&no_frames, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading no_frames");
         exit(1);
-    }  
+    }
 
     MALLOCARRAY(inoffsets, no_frames);
-    
+
     if (fread(&width, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading width");
         exit(1);
-    }  
+    }
     /* set image width in JFIF header */
     inbuffer[27] = (char)(0xFF & (width >> 8));
     inbuffer[28] = (char)(0xFF & width);
- 
+
     if (fread(&height, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading height");
         exit(1);
-    }  
+    }
     /* set image height in JFIF header */
     inbuffer[25] = (char)(0xFF & (height >> 8));
     inbuffer[26] = (char)(0xFF & height);
-    
+
     if (fread(&bandwidth, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading bandwidth");
         exit(1);
-    }  
-    
+    }
+
     if (fread(&qfactor, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading qfactor");
         exit(1);
-    }  
+    }
     /* The default quality factor = 100, therefore, if
        our quality factor does not equal 100 we must
        scale the quantization matrices in the JFIF header
-    */    
+    */
     /* Note values are clipped to a max of 255 */
     if (qfactor != 100) {
         for (Temp = 44; Temp < 108; ++Temp) {
@@ -283,13 +283,13 @@ JMovie2JPEG(const char * const infilename,
         for (Temp = 109; Temp < 173; ++Temp) {
             temp = (inbuffer[Temp]*qfactor)/100;
             inbuffer[Temp] = (char)((temp<255) ? temp : 255);
-        }    
+        }
     }
-  
+
     if (fread(&mapsize, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading mapsize");
         exit(1);
-    }  
+    }
     if (fread (&image_offset, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading image offset");
         exit(1);
@@ -298,32 +298,32 @@ JMovie2JPEG(const char * const infilename,
         perror("Error in reading audio tracks");
         exit(1);
     }
-    
+
     fread(junk,sizeof(int),1,inFile);
-    
+
     if (fread (&audiosize, sizeof(int), 1, inFile) != 1) {
         perror("Error in reading audiosize");
         exit(1);
     }
-    
+
     fseek (inFile, image_offset, 0);
-    
+
     last = MIN(end, no_frames-1);
 
     for (i = 0; i < no_frames; ++i)  {
         fread(&(inoffsets[i]), sizeof(int), 1, inFile);
     } /* Reads in the frame sizes into the array */
-    
+
     rewind(inFile);
 
-    /* Extract JFIF files from J_Movie */    
+    /* Extract JFIF files from J_Movie */
     for (i = start; i <= last; ++i) {
         size = inoffsets[i] - inoffsets[i-1]- 5;
-        lseek(fd, inoffsets[i-1], 0); 
+        lseek(fd, inoffsets[i-1], 0);
         read(fd, &(op_code), 1);
         while (op_code !=  0xffffffec) {
             read(fd,junk,audiosize);
-            read(fd, &(op_code), 1);  
+            read(fd, &(op_code), 1);
             size = size - audiosize ;
         } /* To skip the audio bytes in each frame */
         read(fd, jpeg_size, 4);
@@ -331,7 +331,7 @@ JMovie2JPEG(const char * const infilename,
         sprintf(ofname, "%s%d.jpg", obase, i);
         outFile = fopen(ofname, "wb");
         fwrite(inbuffer, (size+607), sizeof(char), outFile);
-        fclose(outFile);        
+        fclose(outFile);
     }
     free(inoffsets);
     fclose(inFile);
@@ -413,50 +413,50 @@ ReadJPEG(MpegFrame * const mf,
             jpeg_stdio_src(&cinfo, fp);
         }
     }
-  
+
     /* specify data source (eg, a file) */
-  
+
     jpeg_stdio_src(&cinfo, fp);
-  
+
     /* read file parameters with jpeg_read_header() */
-  
-  
+
+
     (void) jpeg_read_header(&cinfo, TRUE);
     /* We can ignore the return value from jpeg_read_header since
      *   (a) suspension is not possible with the stdio data source, and
      *   (b) we passed TRUE to reject a tables-only JPEG file as an error.
      */
-  
+
     /* set parameters for decompression */
     cinfo.raw_data_out = TRUE;
     cinfo.out_color_space = JCS_YCbCr;
-  
+
     /* calculate image output dimensions */
     jpeg_calc_output_dimensions(&cinfo);
     /* the above calculation will set these soon */
     /* for now we'll set them ourselves */
-    
+
     /* tell mpeg_encode the size of the JPEG Image*/
     Fsize_Note(mf->id,(int)(cinfo.image_width),(int)(cinfo.image_height));
-  
+
     /* Allocate memory for the raw YCbCr data to occupy*/
     Frame_AllocYCC(mf);      /*allocate space for mpeg frame*/
-  
+
     /* copy pointers to array structure- this make the following
        code more compact
     */
     orig[0] = mf->orig_y;
     orig[1] = mf->orig_cb;
     orig[2] = mf->orig_cr;
-  
+
     /* Note that we can use the info obtained from jpeg_read_header.
      */
-  
+
     /* Start decompressor */
-  
+
     jpeg_start_decompress(&cinfo);
-  
-  
+
+
     /* JSAMPLEs per row in output buffer  */
     /* collect component subsample values*/
     for (cp=0, compptr = cinfo.comp_info;
@@ -470,28 +470,28 @@ ReadJPEG(MpegFrame * const mf,
     max_h_samp = (temp_h<h_samp[2]) ? h_samp[2]:temp_h;
     temp_v = (v_samp[0]<v_samp[1]) ? v_samp[1] : v_samp[0];
     max_v_samp = (temp_v<v_samp[2]) ? v_samp[2]:temp_v;
-  
+
     /* Make an 8-row-high sample array that will go away when done
        with image
     */
     buffer_height = cinfo.max_v_samp_factor * minDctVScaledSize(cinfo);
-  
+
     for(cp=0,compptr = cinfo.comp_info;cp<cinfo.num_components;
         cp++,compptr++) {
         ncols[cp] = (JDIMENSION)((cinfo.image_width*compptr->h_samp_factor)/
                                  max_h_samp);
-    
+
         nrows[cp] = (JDIMENSION)((buffer_height*compptr->v_samp_factor)/
                                  max_v_samp);
-    
+
         scanarray[cp] = (*cinfo.mem->alloc_sarray)
             ((j_common_ptr) &cinfo, JPOOL_IMAGE, ncols[cp], nrows[cp]);
     }
-  
+
     /*  while (scan lines remain to be read)
            jpeg_read_scanlines(...);
     */
-  
+
     /* Here we use the library's state variable cinfo.output_scanline as the
      * loop counter, so that we don't have to keep track ourselves.
      */
@@ -525,29 +525,29 @@ ReadJPEG(MpegFrame * const mf,
             }
         } else
             pm_error("Invalid subsampling ratio");
-    
+
         /* transfer data from jpeg buffer to MPEG frame */
         /* calculate the row we wish to output into */
         for (ci = 0, compptr = cinfo.comp_info;
              ci < cinfo.num_components;
              ++ci, ++compptr) {
             current_row[ci] =((cinfo.output_scanline - buffer_height)*
-                              (v_samp[ci])/max_v_samp);  
-      
+                              (v_samp[ci])/max_v_samp);
+
             jcopy_sample_rows(scanarray[ci],0,(JSAMPARRAY)(orig[ci]),
                               current_row[ci],nrows[ci],ncols[ci]);
         }
-    }  
-  
+    }
+
     /* Step 7: Finish decompression */
-  
+
     (void) jpeg_finish_decompress(&cinfo);
     /* We can ignore the return value since suspension is not possible
      * with the stdio data source.
      */
-  
+
     /* Step 8: Release JPEG decompression object */
-  
+
     /*
     ** DO NOT release the cinfo struct if we are reading from stdin, this
     ** is because the cinfo struct contains the read buffer, and the read
@@ -572,7 +572,7 @@ ReadJPEG(MpegFrame * const mf,
        think that jpeg_destroy can do an error exit, but why assume
        anything...)
     */
-  
+
     /* At this point you may want to check to see whether any corrupt-data
      * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
      * If you prefer to treat corrupt data as a fatal error, override the
diff --git a/converter/ppm/ppmtompeg/mheaders.c b/converter/ppm/ppmtompeg/mheaders.c
index 4cfe49ac..98e1b063 100644
--- a/converter/ppm/ppmtompeg/mheaders.c
+++ b/converter/ppm/ppmtompeg/mheaders.c
@@ -39,7 +39,7 @@
  *  $Header: /n/picasso/project/mpeg/mpeg_dist/mpeg_encode/RCS/mheaders.c,v 1.15 1995/08/07 21:45:19 smoot Exp $
  *  $Log: mheaders.c,v $
  *  Revision 1.15  1995/08/07 21:45:19  smoot
- *  check for illegal MVs (shouldnt ever be called, but....)
+ *  check for illegal MVs (shouldn't ever be called, but....)
  *  fix bug which made us not weite Iframe Qscale changes
  *  warns if writing a size=0 mpeg
  *
@@ -746,7 +746,7 @@ Mhead_GenSequenceHeader(BitBucket *   const bbPtr,
     }
     Bitio_Write(bbPtr, pratio, 4);
 
-    /* Wrtie picture rate, negative values default to 30 fps. */
+    /* Write picture rate, negative values default to 30 fps. */
 
     if (pict_rate < 0) {
         fprintf(stderr, "PROGRAMMER ERROR:  pict_rate = %d\n", pict_rate);
diff --git a/converter/ppm/ppmtompeg/mpeg.c b/converter/ppm/ppmtompeg/mpeg.c
index dd0e0dbc..e67eec1e 100644
--- a/converter/ppm/ppmtompeg/mpeg.c
+++ b/converter/ppm/ppmtompeg/mpeg.c
@@ -91,7 +91,7 @@ static boolean  frameCountsUnknown;
 
 
 /*==================*
- * GLOBAL VARIABLES *   
+ * GLOBAL VARIABLES *
  *==================*/
 
 /* important -- don't initialize anything here */
@@ -142,14 +142,14 @@ ShowRemainingTime(boolean const childProcess) {
         /* nothing */;
     } else if ( numI + numP + numB == 0 ) {
         /* no time left */
-    } else if ( timeMask != 0 ) {   
+    } else if ( timeMask != 0 ) {
         /* haven't encoded all types yet */
     } else {
         static int  lastTime = 0;
         float   total;
         time_t  nowTime;
         float   secondsPerFrame;
-        
+
         time(&nowTime);
         secondsPerFrame = (nowTime-timeStart)/(float)framesOutput;
         total = secondsPerFrame*(float)(numI+numP+numB);
@@ -174,7 +174,7 @@ static void
 initTCTime(unsigned int const firstFrameNumber) {
 
     unsigned int frameNumber;
-    
+
     tc_hrs = 0; tc_min = 0; tc_sec = 0; tc_pict = 0; tc_extra = 0;
     for (frameNumber = 0; frameNumber < firstFrameNumber; ++frameNumber)
         IncrementTCTime();
@@ -201,13 +201,13 @@ IncrementTCTime() {
        otherwise, it is the number of extra 1/1001 frames we've passed by
 
        so far; for example, if fps = 24000/1001, then 24 frames = 24024/24000
-       seconds = 1 second + 24/24000 seconds = 1 + 1/1000 seconds; similary,
+       seconds = 1 second + 24/24000 seconds = 1 + 1/1000 seconds; similarly,
        if fps = 30000/1001, then 30 frames = 30030/30000 = 1 + 1/1000 seconds
        and if fps = 60000/1001, then 60 frames = 1 + 1/1000 seconds
 
        if fps = 24000/1001, then 1/1000 seconds = 24/1001 frames
        if fps = 30000/1001, then 1/1000 seconds = 30/1001 frames
-       if fps = 60000/1001, then 1/1000 seconds = 60/1001 frames     
+       if fps = 60000/1001, then 1/1000 seconds = 60/1001 frames
      */
 
     totalFramesSent++;
@@ -250,7 +250,7 @@ initializeRateControl(bool const wantUnderflowWarning,
         */
     }
 }
-    
+
 
 
 /*===========================================================================*
@@ -294,16 +294,16 @@ finishFrameOutput(MpegFrame * const frameP,
                   boolean     const childProcess,
                   boolean     const remoteIO) {
 
-    if ((referenceFrame == DECODED_FRAME) && 
+    if ((referenceFrame == DECODED_FRAME) &&
         childProcess && NonLocalRefFrame(frameP->id)) {
         if (remoteIO)
             SendDecodedFrame(frameP);
         else
             WriteDecodedFrame(frameP);
-            
+
         NotifyDecodeServerReady(frameP->id);
     }
-    
+
     if (separateFiles) {
         if (remoteIO)
             SendRemoteFrame(frameP->id, bbP);
@@ -314,7 +314,7 @@ finishFrameOutput(MpegFrame * const frameP,
     }
 }
 
-    
+
 
 
 static void
@@ -324,41 +324,41 @@ outputIFrame(MpegFrame * const frameP,
              int         const realEnd,
              MpegFrame * const pastRefFrameP,
              boolean     const separateFiles) {
-      
+
     /* only start a new GOP with I */
     /* don't start GOP if only doing frames */
     if (!separateFiles && currentGOP >= gopSize) {
-        boolean const closed = 
+        boolean const closed =
             (totalFramesSent == frameP->id || pastRefFrameP == NULL);
 
         static int num_gop = 0;
-    
+
         /* first, check to see if closed GOP */
-    
+
         /* new GOP */
-        if (num_gop != 0 && mult_seq_headers && 
+        if (num_gop != 0 && mult_seq_headers &&
             num_gop % mult_seq_headers == 0) {
             if (!realQuiet) {
-                fprintf(stdout, 
+                fprintf(stdout,
                         "Creating new Sequence before GOP %d\n", num_gop);
                 fflush(stdout);
             }
-      
+
             Mhead_GenSequenceHeader(
                 bbP, Fsize_x, Fsize_y,
                 /* pratio */    aspectRatio,
                 /* pict_rate */ frameRate, /* bit_rate */ bit_rate,
                 /* buf_size */  buf_size,  /* c_param_flag */ 1,
-                /* iq_matrix */ customQtable, 
+                /* iq_matrix */ customQtable,
                 /* niq_matrix */ customNIQtable,
                 /* ext_data */ NULL,  /* ext_data_size */ 0,
                 /* user_data */ NULL, /* user_data_size */ 0);
         }
-    
+
         if (!realQuiet)
             pm_message("Creating new GOP (closed = %s) before frame %d\n",
                        closed ? "YES" : "NO", frameP->id);
-    
+
         ++num_gop;
         Mhead_GenGOPHeader(bbP,  /* drop_frame_flag */ 0,
                            tc_hrs, tc_min, tc_sec, tc_pict,
@@ -371,13 +371,13 @@ outputIFrame(MpegFrame * const frameP,
         else
             SetGOPStartTime(pastRefFrameP->id + 1);
     }
-      
+
     if (frameP->id >= realStart && frameP->id <= realEnd)
         GenIFrame(bbP, frameP);
-      
+
     --numI;
     timeMask &= 0x6;
-      
+
     ++currentGOP;
     IncrementTCTime();
 }
@@ -396,7 +396,7 @@ outputPFrame(MpegFrame * const frameP,
 
     --numP;
     timeMask &= 0x5;
-    
+
     ++currentGOP;
     IncrementTCTime();
 }
@@ -464,7 +464,7 @@ getBFrame(int                  const frameNum,
         *bFramePP = bFrameP;
     } else {
         /* As the frame input is serial, we can't read the B frame now.
-           Rather, Caller has already read it and chained it to 
+           Rather, Caller has already read it and chained it to
            the previous reference frame.  So we get that copy now.
         */
         *bFramePP = pastRefFrameP->next;
@@ -510,15 +510,15 @@ processBFrames(MpegFrame *          const pastRefFrameP,
 
     assert(pastRefFrameP != NULL);
     assert(futureRefFrameP != NULL);
-    
-    for (frameNum = MAX(realStart, firstBFrameNum); 
-         frameNum < MIN(realEnd, futureRefFrameP->id); 
+
+    for (frameNum = MAX(realStart, firstBFrameNum);
+         frameNum < MIN(realEnd, futureRefFrameP->id);
          ++frameNum) {
 
         MpegFrame * bFrame;
         BitBucket * bbP;
 
-        getBFrame(frameNum, inputSourceP, pastRefFrameP, childProcess, 
+        getBFrame(frameNum, inputSourceP, pastRefFrameP, childProcess,
                   remoteIO,
                   &bFrame, IOtimeP, framesReadP);
 
@@ -554,7 +554,7 @@ processBFrames(MpegFrame *          const pastRefFrameP,
 
 
 static void
-processRefFrame(MpegFrame *    const frameP, 
+processRefFrame(MpegFrame *    const frameP,
                 BitBucket *    const wholeStreamBbP,
                 int            const realStart,
                 int            const realEnd,
@@ -574,18 +574,18 @@ processRefFrame(MpegFrame *    const frameP,
 -----------------------------------------------------------------------------*/
     if (frameP->id >= realStart && frameP->id <= realEnd) {
         bool const separateFiles = (wholeStreamBbP == NULL);
-  
+
         BitBucket * bbP;
-  
+
         if (separateFiles)
             bbP = bitioNew(outputFileName, frameP->id, remoteIO);
         else
             bbP = wholeStreamBbP;
-  
+
         /* first, output this reference frame */
         switch (frameP->type) {
         case TYPE_IFRAME:
-            outputIFrame(frameP, bbP, realStart, realEnd, pastRefFrameP, 
+            outputIFrame(frameP, bbP, realStart, realEnd, pastRefFrameP,
                          separateFiles);
             break;
         case TYPE_PFRAME:
@@ -595,10 +595,10 @@ processRefFrame(MpegFrame *    const frameP,
         default:
             pm_error("INTERNAL ERROR: non-reference frame passed to "
                      "ProcessRefFrame()");
-        }  
-        
+        }
+
         ++(*framesOutputP);
-        
+
         finishFrameOutput(frameP, bbP, separateFiles, referenceFrame,
                           childProcess, remoteIO);
     }
@@ -620,7 +620,7 @@ countFrames(unsigned int const firstFrame,
 -----------------------------------------------------------------------------*/
     unsigned int numI, numP, numB;
     unsigned int timeMask;
-            
+
     numI = 0; numP = 0; numB = 0;
     timeMask = 0;
     if (stdinUsed) {
@@ -663,7 +663,7 @@ readAndSaveFrame(struct inputSource * const inputSourceP,
    type 'frameType'.
 
    Increment *framesReadP.
-   
+
    Add the time it took to read it, in seconds, to *iotimeP.
 
    Iff we can't read because we hit end of file, return
@@ -672,11 +672,11 @@ readAndSaveFrame(struct inputSource * const inputSourceP,
     /* This really should be part of ReadNthFrame.  The frame should be chained
        to the input object, not the past reference frame.
     */
-       
+
     MpegFrame * p;
     MpegFrame * frameP;
     time_t ioTimeStart, ioTimeEnd;
-    
+
     time(&ioTimeStart);
 
     frameP = Frame_New(frameNumber, frameType);
@@ -687,15 +687,15 @@ readAndSaveFrame(struct inputSource * const inputSourceP,
         Frame_Free(frameP);
     else {
         ++(*framesReadP);
-    
+
         time(&ioTimeEnd);
         *ioTimeP += (ioTimeEnd - ioTimeStart);
 
-        /* Add the B frame to the end of the queue of B-frames 
+        /* Add the B frame to the end of the queue of B-frames
            for later encoding.
         */
         assert(pastRefFrameP != NULL);
-        
+
         p = pastRefFrameP;
         while (p->next != NULL)
             p = p->next;
@@ -726,7 +726,7 @@ doFirstFrameStuff(enum frameContext const context,
 -----------------------------------------------------------------------------*/
     *inputFrameBitsP = 24 * Fsize_x * Fsize_y;
     SetBlocksPerSlice();
-          
+
     if (context == CONTEXT_WHOLESTREAM) {
         int32 const bitstreamMode = getRateMode();
         char * userData;
@@ -742,11 +742,11 @@ doFirstFrameStuff(enum frameContext const context,
             bit_rate = -1;
             buf_size = -1;
         }
-        
+
         if (strlen(userDataFileName) != 0) {
             struct stat statbuf;
             FILE *fp;
-          
+
             stat(userDataFileName,&statbuf);
             userDataSize = statbuf.st_size;
             userData = malloc(userDataSize);
@@ -771,7 +771,7 @@ doFirstFrameStuff(enum frameContext const context,
         } else { /* Put in our UserData Header */
             const char * userDataString;
             time_t now;
-                    
+
             time(&now);
             pm_asprintf(&userDataString,"MPEG stream encoded by UCB Encoder "
                         "(mpeg_encode) v%s on %s.",
@@ -782,11 +782,11 @@ doFirstFrameStuff(enum frameContext const context,
         }
         Mhead_GenSequenceHeader(bbP, Fsize_x, Fsize_y,
                                 /* pratio */ aspectRatio,
-                                /* pict_rate */ frameRate, 
+                                /* pict_rate */ frameRate,
                                 /* bit_rate */ bit_rate,
                                 /* buf_size */ buf_size,
                                 /*c_param_flag */ 1,
-                                /* iq_matrix */ qtable, 
+                                /* iq_matrix */ qtable,
                                 /* niq_matrix */ niqtable,
                                 /* ext_data */ NULL,
                                 /* ext_data_size */ 0,
@@ -844,9 +844,9 @@ getPreviousFrame(unsigned int         const frameStart,
                      separateConversion, slaveConversion, inputConversion,
                      frameP, &endOfStream);
         assert(!endOfStream);  /* Because Stdin causes failure above */
-    }            
+    }
     ++(*framesReadP);
-    
+
     time(&ioTimeEnd);
     *ioTimeP += (ioTimeEnd-ioTimeStart);
 
@@ -858,7 +858,7 @@ getPreviousFrame(unsigned int         const frameStart,
 static void
 computeFrameRange(unsigned int         const frameStart,
                   unsigned int         const frameEnd,
-                  enum frameContext    const context, 
+                  enum frameContext    const context,
                   struct inputSource * const inputSourceP,
                   unsigned int *       const firstFrameP,
                   unsigned int *       const lastFrameP) {
@@ -881,13 +881,13 @@ computeFrameRange(unsigned int         const frameStart,
             *firstFrameP = frameStart;
 
         /* if last frame is B, need to read in P or I frame after it */
-        if ((FType_Type(frameEnd) == 'b') && 
+        if ((FType_Type(frameEnd) == 'b') &&
             (frameEnd != inputSourceP->numInputFiles-1)) {
             /* can't find the next reference frame interactively */
             if (inputSourceP->stdinUsed)
                 pm_error("Cannot encode frames from Standard Input "
                          "when last frame is a B-frame.");
-            
+
             *lastFrameP = FType_FutureRef(frameEnd);
         } else
             *lastFrameP = frameEnd;
@@ -930,11 +930,11 @@ getFrame(MpegFrame **         const framePP,
     time_t ioTimeStart, ioTimeEnd;
     MpegFrame * frameP;
     bool endOfStream;
-    
+
     time(&ioTimeStart);
 
     frameP = Frame_New(frameNumber, frameType);
-            
+
     if ((referenceFrame == DECODED_FRAME) &&
         ((frameNumber < realStart) || (frameNumber > realEnd)) ) {
         WaitForDecodedFrame(frameNumber);
@@ -952,13 +952,13 @@ getFrame(MpegFrame **         const framePP,
         ReadNthFrame(inputSourceP, frameNumber, remoteIO, childProcess,
                      separateConversion, slaveConversion, inputConversion,
                      frameP, &endOfStream);
-    
+
     if (endOfStream) {
         Frame_Free(frameP);
         *framePP = NULL;
     } else {
         ++(*framesReadP);
-            
+
         time(&ioTimeEnd);
         *ioTimeP += (ioTimeEnd - ioTimeStart);
 
@@ -988,9 +988,9 @@ handleBitRate(unsigned int const realEnd,
 static void
 doAFrame(unsigned int         const frameNumber,
          struct inputSource * const inputSourceP,
-         enum frameContext    const context, 
-         unsigned int         const frameStart, 
-         unsigned int         const frameEnd, 
+         enum frameContext    const context,
+         unsigned int         const frameStart,
+         unsigned int         const frameEnd,
          unsigned int         const realStart,
          unsigned int         const realEnd,
          bool                 const childProcess,
@@ -1017,7 +1017,7 @@ doAFrame(unsigned int         const frameNumber,
    output each frame to its own individual file instead.
 -----------------------------------------------------------------------------*/
     char const frameType = FType_Type(frameNumber);
-    
+
     *endOfStreamP = FALSE;  /* initial assumption */
 
     if (frameType == 'b') {
@@ -1026,44 +1026,44 @@ doAFrame(unsigned int         const frameNumber,
            just read it later.
         */
         *newPastRefFramePP = pastRefFrameP;
-        if (inputSourceP->stdinUsed) 
+        if (inputSourceP->stdinUsed)
             readAndSaveFrame(inputSourceP,
                              frameNumber, frameType, inputConversion,
                              pastRefFrameP, framesReadP, &IOtime,
                              endOfStreamP);
     } else {
         MpegFrame * frameP;
-        
+
         getFrame(&frameP, inputSourceP, frameNumber, frameType,
                  realStart, realEnd, referenceFrame, childProcess,
                  remoteIO,
                  separateConversion, slaveConversion, inputConversion,
                  framesReadP, &IOtime);
-        
+
         if (frameP) {
             *endOfStreamP = FALSE;
 
             if (!*firstFrameDoneP) {
                 doFirstFrameStuff(context, userDataFileName, wholeStreamBbP,
                                   Fsize_x, Fsize_y, aspectRatio,
-                                  frameRate, qtable, niqtable, 
+                                  frameRate, qtable, niqtable,
                                   inputFrameBitsP);
-            
+
                 *firstFrameDoneP = TRUE;
             }
             processRefFrame(frameP, wholeStreamBbP, frameStart, frameEnd,
-                            pastRefFrameP, childProcess, outputFileName, 
+                            pastRefFrameP, childProcess, outputFileName,
                             framesReadP, framesOutputP);
-                
+
             if (pastRefFrameP) {
                 processBFrames(pastRefFrameP, frameP, realStart, realEnd,
-                               inputSourceP, remoteIO, childProcess, 
+                               inputSourceP, remoteIO, childProcess,
                                &IOtime, wholeStreamBbP, outputFileName,
                                framesReadP, framesOutputP, &currentGOP);
             }
             if (pastRefFrameP != NULL)
                 Frame_Free(pastRefFrameP);
-        
+
             *newPastRefFramePP = frameP;
         } else
             *endOfStreamP = TRUE;
@@ -1074,13 +1074,13 @@ doAFrame(unsigned int         const frameNumber,
 
 void
 GenMPEGStream(struct inputSource * const inputSourceP,
-              enum frameContext    const context, 
-              unsigned int         const frameStart, 
-              unsigned int         const frameEnd, 
-              int32                const qtable[], 
-              int32                const niqtable[], 
+              enum frameContext    const context,
+              unsigned int         const frameStart,
+              unsigned int         const frameEnd,
+              int32                const qtable[],
+              int32                const niqtable[],
               bool                 const childProcess,
-              FILE *               const ofP, 
+              FILE *               const ofP,
               const char *         const outputFileName,
               bool                 const wantVbvUnderflowWarning,
               bool                 const wantVbvOverflowWarning,
@@ -1129,7 +1129,7 @@ GenMPEGStream(struct inputSource * const inputSourceP,
                  "(%u frames)", frameEnd, inputSourceP->numInputFiles);
 
     if (context == CONTEXT_WHOLESTREAM &&
-        !inputSourceP->stdinUsed && 
+        !inputSourceP->stdinUsed &&
         FType_Type(inputSourceP->numInputFiles-1) == 'b')
         pm_message("WARNING:  "
                    "One or more B-frames at end will not be encoded.  "
@@ -1188,27 +1188,27 @@ GenMPEGStream(struct inputSource * const inputSourceP,
          frameNumber <= lastFrame && !endOfStream;
          ++frameNumber) {
 
-        doAFrame(frameNumber, inputSourceP, context, 
+        doAFrame(frameNumber, inputSourceP, context,
                  frameStart, frameEnd, realStart, realEnd,
                  childProcess, outputFileName,
                  pastRefFrameP, &pastRefFrameP,
                  &framesRead, &framesOutput, &firstFrameDone, streamBbP,
                  inputFrameBitsP, &endOfStream);
     }
-    
+
     if (pastRefFrameP != NULL)
         Frame_Free(pastRefFrameP);
-    
+
     /* SEQUENCE END CODE */
     if (context == CONTEXT_WHOLESTREAM)
         Mhead_GenSequenceEnder(streamBbP);
-    
+
     if (streamBbP)
         numBits = streamBbP->cumulativeBits;
     else {
         /* What should the correct value be?  Most likely 1.  "numBits" is
-           used below, so we need to make sure it's properly initialized 
-           to somthing (anything).  
+           used below, so we need to make sure it's properly initialized
+           to something (anything).
         */
         numBits = 1;
     }
@@ -1272,9 +1272,9 @@ SetGOPSize(size)
  *
  *===========================================================================*/
 void
-PrintStartStats(time_t               const startTime, 
+PrintStartStats(time_t               const startTime,
                 bool                 const specificFrames,
-                unsigned int         const firstFrame, 
+                unsigned int         const firstFrame,
                 unsigned int         const lastFrame,
                 struct inputSource * const inputSourceP) {
 
@@ -1296,7 +1296,7 @@ PrintStartStats(time_t               const startTime,
             fprintf(stdout, "\n\n");
         }
     }
-    
+
     for (i = 0; i < 2; ++i) {
         if ( ( i == 0 ) && (! realQuiet) ) {
             fpointer = stdout;
@@ -1322,15 +1322,15 @@ PrintStartStats(time_t               const startTime,
             fprintf(fpointer, "INPUT FROM FILES:\n");
 
             GetNthInputFileName(inputSourceP, 0, &inputFileName);
-            fprintf(fpointer, "FIRST FILE:  %s/%s\n", 
+            fprintf(fpointer, "FIRST FILE:  %s/%s\n",
                     currentPath, inputFileName);
             pm_strfree(inputFileName);
-            GetNthInputFileName(inputSourceP, inputSourceP->numInputFiles-1, 
+            GetNthInputFileName(inputSourceP, inputSourceP->numInputFiles-1,
                                 &inputFileName);
-            fprintf(fpointer, "LAST FILE:  %s/%s\n", 
+            fprintf(fpointer, "LAST FILE:  %s/%s\n",
                     currentPath, inputFileName);
             pm_strfree(inputFileName);
-        }    
+        }
         fprintf(fpointer, "OUTPUT:  %s\n", outputFileName);
 
         if (resizeFrame)
@@ -1341,15 +1341,15 @@ PrintStartStats(time_t               const startTime,
         fprintf(fpointer, "SLICES PER FRAME:  %d\n", slicesPerFrame);
         if (searchRangeP==searchRangeB)
             fprintf(fpointer, "RANGE:  +/-%d\n", searchRangeP/2);
-        else fprintf(fpointer, "RANGES:  +/-%d %d\n", 
+        else fprintf(fpointer, "RANGES:  +/-%d %d\n",
                      searchRangeP/2,searchRangeB/2);
-        fprintf(fpointer, "PIXEL SEARCH:  %s\n", 
+        fprintf(fpointer, "PIXEL SEARCH:  %s\n",
                 pixelFullSearch ? "FULL" : "HALF");
         fprintf(fpointer, "PSEARCH:  %s\n", PSearchName());
         fprintf(fpointer, "BSEARCH:  %s\n", BSearchName());
-        fprintf(fpointer, "QSCALE:  %d %d %d\n", qscaleI, 
+        fprintf(fpointer, "QSCALE:  %d %d %d\n", qscaleI,
                 GetPQScale(), GetBQScale());
-        if (specificsOn) 
+        if (specificsOn)
             fprintf(fpointer, "(Except as modified by Specifics file)\n");
         if ( referenceFrame == DECODED_FRAME ) {
             fprintf(fpointer, "REFERENCE FRAME:  DECODED\n");
@@ -1386,22 +1386,22 @@ NonLocalRefFrame(int const id) {
     boolean retval;
 
     int const lastIPid = FType_PastRef(id);
-    
+
     /* might be accessed by B-frame */
-    
+
     if (lastIPid+1 < realStart)
         retval = TRUE;
     else {
         unsigned int const nextIPid = FType_FutureRef(id);
-        
+
         /* if B-frame is out of range, then current frame can be
-           ref'd by it 
+           ref'd by it
         */
-        
+
         /* might be accessed by B-frame */
         if (nextIPid > realEnd+1)
             retval = TRUE;
-        
+
         /* might be accessed by P-frame */
         if ((nextIPid > realEnd) && (FType_Type(nextIPid) == 'p'))
             retval = TRUE;
@@ -1410,7 +1410,7 @@ NonLocalRefFrame(int const id) {
 }
 
 
- 
+
 /*===========================================================================*
  *
  * SetFrameRate
@@ -1508,9 +1508,9 @@ ComputeDHMSTime(someTime, timeText)
 
 
 void
-ComputeGOPFrames(int            const whichGOP, 
-                 unsigned int * const firstFrameP, 
-                 unsigned int * const lastFrameP, 
+ComputeGOPFrames(int            const whichGOP,
+                 unsigned int * const firstFrameP,
+                 unsigned int * const lastFrameP,
                  unsigned int   const numFrames) {
 /*----------------------------------------------------------------------------
    Figure out which frames are in GOP number 'whichGOP'.
@@ -1537,7 +1537,7 @@ ComputeGOPFrames(int            const whichGOP,
         if (gopNum == whichGOP) {
             foundGop = TRUE;
             firstFrame = frameNum;
-        }           
+        }
 
         /* go past one gop */
         /* must go past at least one frame */
@@ -1551,7 +1551,7 @@ ComputeGOPFrames(int            const whichGOP,
                 ++frameNum;
                 ++passedB;
             }
-        } while ((frameNum < numFrames) && 
+        } while ((frameNum < numFrames) &&
                  ((FType_Type(frameNum) != 'i') || (currGOP < gopSize)));
 
         currGOP -= gopSize;
@@ -1583,7 +1583,7 @@ doEndStats(FILE *       const fpointer,
 
     fprintf(fpointer, "TIME COMPLETED:  %s", ctime(&endTime));
     fprintf(fpointer, "%s\n\n", timeText);
-        
+
     ShowIFrameSummary(inputFrameBits, totalBits, fpointer);
     ShowPFrameSummary(inputFrameBits, totalBits, fpointer);
     ShowBFrameSummary(inputFrameBits, totalBits, fpointer);
@@ -1595,7 +1595,7 @@ doEndStats(FILE *       const fpointer,
     if (diffTime > 0) {
         fprintf(fpointer, "Total Frames Per Sec Elapsed:  %f (%ld mps)\n",
                 (float)framesOutput/(float)diffTime,
-                (long)((float)framesOutput * 
+                (long)((float)framesOutput *
                        (float)inputFrameBits /
                        (256.0*24.0*(float)diffTime)));
     } else {
@@ -1613,7 +1613,7 @@ doEndStats(FILE *       const fpointer,
             frameRateRounded, frameRateRounded*totalBits/framesOutput);
     fprintf(fpointer, "MPEG file created in :  %s\n", outputFileName);
     fprintf(fpointer, "\n\n");
-        
+
     if ( computeMVHist ) {
         ShowPMVHistogram(fpointer);
         ShowBBMVHistogram(fpointer);
@@ -1637,7 +1637,7 @@ doEndStats(FILE *       const fpointer,
 void
 PrintEndStats(time_t       const startTime,
               time_t       const endTime,
-              unsigned int const inputFrameBits, 
+              unsigned int const inputFrameBits,
               unsigned int const totalBits) {
 
     float   totalCPU;
@@ -1652,7 +1652,7 @@ PrintEndStats(time_t       const startTime,
         doEndStats(stdout, startTime, endTime, inputFrameBits,
                    totalBits, totalCPU);
     }
-    
+
     if (statFile) {
         doEndStats(statFile, startTime, endTime, inputFrameBits,
                    totalBits, totalCPU);
@@ -1664,7 +1664,7 @@ PrintEndStats(time_t       const startTime,
 
 
 void
-ReadDecodedRefFrame(MpegFrame *  const frameP, 
+ReadDecodedRefFrame(MpegFrame *  const frameP,
                     unsigned int const frameNumber) {
 
     FILE    *fpointer;
@@ -1689,7 +1689,7 @@ ReadDecodedRefFrame(MpegFrame *  const frameP,
         }}
 
     Frame_AllocDecoded(frameP, TRUE);
-    
+
     for ( y = 0; y < height; y++ ) {
         size_t bytesRead;
 
@@ -1697,7 +1697,7 @@ ReadDecodedRefFrame(MpegFrame *  const frameP,
         if (bytesRead != width)
             pm_error("Could not read enough bytes from '%s;", fileName);
     }
-    
+
     for (y = 0; y < (height >> 1); y++) {           /* U */
         size_t const bytesToRead = width/2;
         size_t bytesRead;
@@ -1706,7 +1706,7 @@ ReadDecodedRefFrame(MpegFrame *  const frameP,
         if (bytesRead != bytesToRead)
             pm_message("Could not read enough bytes from '%s'", fileName);
     }
-    
+
     for (y = 0; y < (height >> 1); y++) {           /* V */
         size_t const bytesToRead = width/2;
         size_t bytesRead;
@@ -1724,7 +1724,7 @@ static void
 OpenBitRateFile() {
     bitRateFile = fopen(bitRateFileName, "w");
     if ( bitRateFile == NULL ) {
-        pm_message("ERROR:  Could not open bit rate file:  '%s'", 
+        pm_message("ERROR:  Could not open bit rate file:  '%s'",
                    bitRateFileName);
         showBitRatePerFrame = FALSE;
     }
@@ -1736,3 +1736,6 @@ static void
 CloseBitRateFile() {
     fclose(bitRateFile);
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/opts.c b/converter/ppm/ppmtompeg/opts.c
index 553e29d0..6f5f9816 100644
--- a/converter/ppm/ppmtompeg/opts.c
+++ b/converter/ppm/ppmtompeg/opts.c
@@ -1,29 +1,29 @@
 /*===========================================================================*
- * opts.c								     *
- *									     *
+ * opts.c                                                                    *
+ *                                                                           *
  *      Special C code to handle TUNEing options                             *
- *									     *
- * EXPORTED PROCEDURES:							     *
+ *                                                                           *
+ * EXPORTED PROCEDURES:                                                      *
  *      Tune_Init                                                            *
  *      CollectQuantStats                                                    *
- *									     *
+ *                                                                           *
  *===========================================================================*/
 
 
 /*
  * Copyright (c) 1995 The Regents of the University of California.
  * All rights reserved.
- * 
+ *
  * Permission to use, copy, modify, and distribute this software and its
  * documentation for any purpose, without fee, and without written agreement is
  * hereby granted, provided that the above copyright notice and the following
  * two paragraphs appear in all copies of this software.
- * 
+ *
  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
+ *
  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
@@ -95,9 +95,9 @@ boolean BSkipBlocks = TRUE;
  *
  * SkipSpacesTabs
  *
- *	skip all spaces and tabs
+ *      skip all spaces and tabs
  *
- * RETURNS:	point to next character not a space or tab
+ * RETURNS:     point to next character not a space or tab
  *
  * SIDE EFFECTS:    none
  *
@@ -120,12 +120,12 @@ SkipSpacesTabs(const char * const start) {
  *
  *     Setup variables to collect statistics on quantization values
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:    sets collect_quant and collect_quant_fp
  *
  *===========================================================================*/
-static void 
+static void
 SetupCollectQuantStats(const char * const charPtr)
 {
   char fname[256];
@@ -164,23 +164,23 @@ SetupCollectQuantStats(const char * const charPtr)
  *
  *     Do a transform on small lum values
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:    sets kill_dim, kill_dim_break, kill_dim_end
  *
  *===========================================================================*/
-static void 
+static void
 SetupKillDimAreas(const char * const charPtr)
 {
   int items_scanned;
 
   kill_dim = TRUE;
-  items_scanned = sscanf(charPtr, "%d %d %f", 
-			 &kill_dim_break, &kill_dim_end, &kill_dim_slope);
+  items_scanned = sscanf(charPtr, "%d %d %f",
+                         &kill_dim_break, &kill_dim_end, &kill_dim_slope);
   if (items_scanned != 3) {
     kill_dim_slope = 0.25;
-    items_scanned = sscanf(charPtr, "%d %d", 
-			   &kill_dim_break, &kill_dim_end);
+    items_scanned = sscanf(charPtr, "%d %d",
+                           &kill_dim_break, &kill_dim_end);
     if (items_scanned != 2) {
       /* Use defaults */
       kill_dim_break = 20;
@@ -206,12 +206,12 @@ SetupKillDimAreas(const char * const charPtr)
  *
  *     Setup encoder to squash small changes in Y or Cr/Cb values
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
- * SIDE EFFECTS:    sets squash_max_differences SquashMaxLum SquashMaxChr 
+ * SIDE EFFECTS:    sets squash_max_differences SquashMaxLum SquashMaxChr
  *
  *===========================================================================*/
-static void 
+static void
 SetupSquashSmall(const char * const charPtr)
 {
   squash_small_differences = TRUE;
@@ -229,13 +229,13 @@ SetupSquashSmall(const char * const charPtr)
  *
  *     Setup encoder to use DCT for rate-distortion estimat ein Psearches
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:    sets SearchCompareMode and
  *                        can change LocalDCTRateScale, LocalDCTDistortScale
  *
  *===========================================================================*/
-static void 
+static void
 SetupLocalDCT(const char * const charPtr)
 {
   int num_scales=0;
@@ -260,12 +260,12 @@ SetupLocalDCT(const char * const charPtr)
  *
  *     Setup encoder to find distribution for I-frames, and use for -snr
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:    sets DoLaplace, L1, L2, and Lambdas
  *
  *===========================================================================*/
-static void 
+static void
 SetupLaplace()
 {
   int i;
@@ -339,18 +339,18 @@ SetupWriteDistortions(const char * const charPtr)
     default:
       fprintf(stderr, "Unknown TUNE parameter setting format %s\n", cp);
     }}
-}  
+}
 
 /*=====================*
  * EXPORTED PROCEDURES *
  *=====================*/
 
-void 
+void
 CalcLambdas(void) {
 
   int i,j,n;
   double var;
-  
+
   n = LaplaceNum;
   for (i = 0;   i < 3;  i++) {
     for (j = 0;  j < 64;  j++) {
@@ -365,10 +365,10 @@ CalcLambdas(void) {
  *
  * Mpost_UnQuantZigBlockLaplace
  *
- *	unquantize and zig-zag (decode) a single block, using the distrib to get vals
+ *      unquantize and zig-zag (decode) a single block, using the distrib to get vals
  *      Iblocks only now
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:    none
  *
@@ -381,22 +381,22 @@ Mpost_UnQuantZigBlockLaplace(in, out, qscale, iblock)
     boolean iblock;
 {
     register int index;
-    int	    position;
-    register int	    qentry;
-    int	    level, coeff;
+    int     position;
+    register int            qentry;
+    int     level, coeff;
     double low, high;
     double mid,lam;
 
     /* qtable[0] must be 8 */
     out[0][0] = (int16)(in[0] * 8);
-    
+
     for ( index = 1;  index < DCTSIZE_SQ;  index++ ) {
       position = ZAG[index];
       level = in[index];
-      
+
       if (level == 0) {
-	((int16 *)out)[position] = 0;
-	continue;
+        ((int16 *)out)[position] = 0;
+        continue;
       }
       qentry = qtable[position] * qscale;
       coeff = (level*qentry)/8;
@@ -406,25 +406,25 @@ Mpost_UnQuantZigBlockLaplace(in, out, qscale, iblock)
       mid = (1.0/lam) * log(0.5*(exp(-lam*low)+exp(-lam*high)));
       mid = ABS(mid);
       if (mid - floor(mid) > .4999) {
-	mid = ceil(mid);
+        mid = ceil(mid);
       } else {
-	mid = floor(mid);
+        mid = floor(mid);
       }
       if (level<0) {mid = -mid;}
 /*printf("(%2.1lf-%2.1lf): old: %d vs %d\n",low,high,coeff,(int) mid);*/
       coeff = mid;
       if ( (coeff & 1) == 0 ) {
-	if ( coeff < 0 ) {
-	  coeff++;
-	} else if ( coeff > 0 ) {
-	  coeff--;
-	}
+        if ( coeff < 0 ) {
+          coeff++;
+        } else if ( coeff > 0 ) {
+          coeff--;
+        }
       }
       ((int16 *)out)[position] = coeff;
     }
 }
 
-int 
+int
 mse(Block blk1, Block blk2)
 {
   register int index, error, tmp;
@@ -449,7 +449,7 @@ mse(Block blk1, Block blk2)
  *
  *     Do any setup needed before coding stream
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:  varies
  *
@@ -458,7 +458,7 @@ void Tune_Init()
 {
   int i;
 
-  /* Just check for each, and do whats needed */
+  /* Just check for each, and do what's needed */
   if (collect_quant) {
     if (!pureDCT) {
       pureDCT = TRUE;
@@ -467,14 +467,14 @@ void Tune_Init()
     }
     fprintf(collect_quant_fp, "# %s\n", outputFileName);
     fprintf(collect_quant_fp, "#");
-    for (i=0; i<64; i++) 
+    for (i=0; i<64; i++)
       fprintf(collect_quant_fp, " %d", qtable[i]);
     fprintf(collect_quant_fp, "\n#");
-    for (i=0; i<64; i++) 
+    for (i=0; i<64; i++)
       fprintf(collect_quant_fp, " %d", niqtable[i]);
-    fprintf(collect_quant_fp, "\n# %d %d %d\n\n", 
-	    GetIQScale(), GetPQScale(), GetBQScale());
-    
+    fprintf(collect_quant_fp, "\n# %d %d %d\n\n",
+            GetIQScale(), GetPQScale(), GetBQScale());
+
   }
 
   if (DoLaplace) {
@@ -486,7 +486,7 @@ void Tune_Init()
     decodeRefFrames = TRUE;
     printSNR = TRUE;
   }
-    
+
 }
 
 /*===========================================================================*
@@ -495,7 +495,7 @@ void Tune_Init()
  *
  *     Handle the strings following TUNE
  *
- * RETURNS:	nothing
+ * RETURNS:     nothing
  *
  * SIDE EFFECTS:  varies
  *
@@ -503,7 +503,7 @@ void Tune_Init()
 void ParseTuneParam(const char * const charPtr)
 {
   switch (ASCII_TOUPPER(*charPtr)) {
-  case 'B': 
+  case 'B':
     if (1 != sscanf(charPtr+2, "%d", &block_bound)) {
       fprintf(stderr, "Invalid tuning parameter (b) in parameter file.\n");
     }
diff --git a/converter/ppm/ppmtompeg/parallel.c b/converter/ppm/ppmtompeg/parallel.c
index e3bcec1a..0fe635ed 100644
--- a/converter/ppm/ppmtompeg/parallel.c
+++ b/converter/ppm/ppmtompeg/parallel.c
@@ -1,8 +1,8 @@
 /*===========================================================================*
- * parallel.c              
- *                         
- *  Procedures to make encoder run in parallel   
- *                             
+ * parallel.c
+ *
+ *  Procedures to make encoder run in parallel
+ *
  *===========================================================================*/
 
 /* COPYRIGHT INFORMATION IS AT THE END OF THIS FILE */
@@ -13,8 +13,8 @@
  *==============*/
 
 #define _XOPEN_SOURCE 500 /* Make sure stdio.h contains pclose() */
-/* _ALL_SOURCE is needed on AIX to make the C library include the 
-   socket services (e.g. define struct sockaddr) 
+/* _ALL_SOURCE is needed on AIX to make the C library include the
+   socket services (e.g. define struct sockaddr)
 
    Note that AIX standards.h actually sets feature declaration macros such
    as _XOPEN_SOURCE, unless they are already set.
@@ -93,7 +93,8 @@ struct scheduler {
  * CONSTANTS        *
  *==================*/
 
-#define TERMINATE_PID_SIGNAL    SIGTERM  /* signal used to terminate forked childs */
+#define TERMINATE_PID_SIGNAL    SIGTERM
+  /* signal used to terminate forked children */
 #ifndef MAXARGS
 #define MAXARGS     1024   /* Max Number of arguments in safe_fork command */
 #endif
@@ -187,8 +188,8 @@ errorExit(const char format[], ...) {
 
 
 static void
-TransmitPortNum(const char * const hostName, 
-                int          const portNum, 
+TransmitPortNum(const char * const hostName,
+                int          const portNum,
                 int          const newPortNum) {
 /*----------------------------------------------------------------------------
    Transmit the port number 'newPortNum' to the master on port 'portNum'
@@ -196,15 +197,15 @@ TransmitPortNum(const char * const hostName,
 -----------------------------------------------------------------------------*/
     int clientSocket;
     const char * error;
-    
+
     ConnectToSocket(hostName, portNum, &hostEntry, &clientSocket, &error);
-    
+
     if (error)
         errorExit("Can't connect in order to transmit port number.  %s",
                   error);
 
     WriteInt(clientSocket, newPortNum);
-    
+
     close(clientSocket);
 }
 
@@ -215,19 +216,19 @@ readYUVDecoded(int          const socketFd,
                unsigned int const Fsize_x,
                unsigned int const Fsize_y,
                MpegFrame *  const frameP) {
-    
+
     unsigned int y;
-    
+
     for (y = 0; y < Fsize_y; ++y)         /* Y */
-        ReadBytes(socketFd, 
+        ReadBytes(socketFd,
                   (unsigned char *)frameP->decoded_y[y], Fsize_x);
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* U */
-        ReadBytes(socketFd, 
+        ReadBytes(socketFd,
                   (unsigned char *)frameP->decoded_cb[y], (Fsize_x >> 1));
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* V */
-        ReadBytes(socketFd, 
+        ReadBytes(socketFd,
                   (unsigned char *)frameP->decoded_cr[y], (Fsize_x >> 1));
 }
 
@@ -238,19 +239,19 @@ writeYUVDecoded(int          const socketFd,
                 unsigned int const Fsize_x,
                 unsigned int const Fsize_y,
                 MpegFrame *  const frameP) {
-    
+
     unsigned int y;
-    
+
     for (y = 0; y < Fsize_y; ++y)         /* Y */
-        WriteBytes(socketFd, 
+        WriteBytes(socketFd,
                   (unsigned char *)frameP->decoded_y[y], Fsize_x);
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* U */
-        WriteBytes(socketFd, 
+        WriteBytes(socketFd,
                    (unsigned char *)frameP->decoded_cb[y], (Fsize_x >> 1));
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* V */
-        WriteBytes(socketFd, 
+        WriteBytes(socketFd,
                    (unsigned char *)frameP->decoded_cr[y], (Fsize_x >> 1));
 }
 
@@ -261,19 +262,19 @@ writeYUVOrig(int          const socketFd,
              unsigned int const Fsize_x,
              unsigned int const Fsize_y,
              MpegFrame *  const frameP) {
-    
+
     unsigned int y;
-    
+
     for (y = 0; y < Fsize_y; ++y)         /* Y */
-        WriteBytes(socketFd, 
+        WriteBytes(socketFd,
                   (unsigned char *)frameP->orig_y[y], Fsize_x);
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* U */
-        WriteBytes(socketFd, 
+        WriteBytes(socketFd,
                    (unsigned char *)frameP->orig_cb[y], (Fsize_x >> 1));
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* V */
-        WriteBytes(socketFd, 
+        WriteBytes(socketFd,
                    (unsigned char *)frameP->orig_cr[y], (Fsize_x >> 1));
 }
 
@@ -284,19 +285,19 @@ readYUVOrig(int          const socketFd,
             unsigned int const Fsize_x,
             unsigned int const Fsize_y,
             MpegFrame *  const frameP) {
-    
+
     unsigned int y;
-    
+
     for (y = 0; y < Fsize_y; ++y)         /* Y */
-        ReadBytes(socketFd, 
+        ReadBytes(socketFd,
                   (unsigned char *)frameP->orig_y[y], Fsize_x);
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* U */
-        ReadBytes(socketFd, 
+        ReadBytes(socketFd,
                   (unsigned char *)frameP->orig_cb[y], (Fsize_x >> 1));
-    
+
     for (y = 0; y < (Fsize_y >> 1); ++y)  /* V */
-        ReadBytes(socketFd, 
+        ReadBytes(socketFd,
                   (unsigned char *)frameP->orig_cr[y], (Fsize_x >> 1));
 }
 
@@ -340,20 +341,20 @@ NotifyDecodeServerReady(int const id) {
     int   clientSocket;
     time_t  tempTimeStart, tempTimeEnd;
     const char * error;
-    
+
     time(&tempTimeStart);
-    
+
     ConnectToSocket(IOhostName, decodePortNumber, &hostEntry, &clientSocket,
                     &error);
-    
+
     if (error)
         errorExit("CHILD: Can't connect to decode server to tell it a frame "
                 "is ready.  %s", error);
-    
+
     WriteInt(clientSocket, id);
-    
+
     close(clientSocket);
-    
+
     time(&tempTimeEnd);
     IOtime += (tempTimeEnd-tempTimeStart);
 }
@@ -461,23 +462,23 @@ SendDecodedFrame(MpegFrame * const frameP) {
    Send frame *frameP to the decode server.
 -----------------------------------------------------------------------------*/
     int const negativeTwo = -2;
-    
+
     int clientSocket;
     const char * error;
-    
+
     /* send to IOServer */
     ConnectToSocket(IOhostName, ioPortNumber, &hostEntry,
                     &clientSocket, &error);
     if (error)
         errorExit("CHILD: Can't connect to decode server to "
                   "give it a decoded frame.  %s", error);
-    
+
     WriteInt(clientSocket, negativeTwo);
-    
+
     WriteInt(clientSocket, frameP->id);
 
     writeYUVDecoded(clientSocket, Fsize_x, Fsize_y, frameP);
-    
+
     close(clientSocket);
 }
 
@@ -490,11 +491,11 @@ SendDecodedFrame(MpegFrame * const frameP) {
  *
  * RETURNS: nothing
  *
- * SIDE EFFECTS:   
+ * SIDE EFFECTS:
  *
  *===========================================================================*/
 void
-GetRemoteDecodedRefFrame(MpegFrame * const frameP, 
+GetRemoteDecodedRefFrame(MpegFrame * const frameP,
                          int         const frameNumber) {
 /*----------------------------------------------------------------------------
    Get decoded frame number 'frameNumber' *frameP from the decode server.
@@ -551,7 +552,7 @@ static void cleanup_fork( dummy )       /* try to kill all child processes */
 #endif
 
     if (kill(ClientPid[i], TERMINATE_PID_SIGNAL)) {
-      fprintf(stderr, "cleanup_fork: killed PID=%d failed (errno %d)\n", 
+      fprintf(stderr, "cleanup_fork: killed PID=%d failed (errno %d)\n",
           ClientPid[i], errno);
     }
   }
@@ -574,24 +575,24 @@ static int safe_fork(command)       /* fork child process and remember its PID *
   static int init=0;
   char *argis[MAXARGS];
   register int i=1;
-  
+
   if (!(argis[0] = strtok(command, " \t"))) return(0); /* tokenize */
   while ((argis[i] = strtok(NULL, " \t")) && i < MAXARGS) ++i;
   argis[i] = NULL;
-  
+
 #ifdef DEBUG_FORK
-  {register int i=0; 
+  {register int i=0;
    fprintf(stderr, "Command %s becomes:\n", command);
    while(argis[i]) {fprintf(stderr, "--%s--\n", argis[i]); ++i;} }
 #endif
-  
+
   if (!init) {          /* register clean-up routine */
     signal (SIGQUIT, cleanup_fork);
     signal (SIGTERM, cleanup_fork);
     signal (SIGINT , cleanup_fork);
     init=1;
   }
-  
+
   if (-1 == (ClientPid[current_max_forked_pid] = fork()) )  {
     perror("safe_fork: fork failed ");
     return(-1);
@@ -682,25 +683,25 @@ decodedFrameToDisk(int const otherSock) {
     MpegFrame * frameP;
 
     ReadInt(otherSock, &frameNumber);
-    
+
     if (debugSockets) {
-        fprintf(stdout, "INPUT SERVER:  GETTING DECODED FRAME %d\n", 
+        fprintf(stdout, "INPUT SERVER:  GETTING DECODED FRAME %d\n",
                 frameNumber);
         fflush(stdout);
     }
 
     /* should read frame from socket, then write to disk */
     frameP = Frame_New(frameNumber, 'i');
-    
+
     Frame_AllocDecoded(frameP, TRUE);
-    
+
     readYUVDecoded(otherSock, Fsize_x, Fsize_y, frameP);
 
     /* now output to disk */
     WriteDecodedFrame(frameP);
 
     Frame_Free(frameP);
-}        
+}
 
 
 
@@ -708,12 +709,12 @@ static void
 decodedFrameFromDisk(int const otherSock) {
 
     /* request for decoded frame from disk */
-            
+
     int frameNumber;
     MpegFrame * frameP;
 
     ReadInt(otherSock, &frameNumber);
-    
+
     if (debugSockets) {
         fprintf(stdout, "INPUT SERVER:  READING DECODED FRAME %d "
                 "from DISK\n", frameNumber);
@@ -722,15 +723,15 @@ decodedFrameFromDisk(int const otherSock) {
 
     /* should read frame from disk, then write to socket */
     frameP = Frame_New(frameNumber, 'i');
-    
+
     Frame_AllocDecoded(frameP, TRUE);
-    
+
     ReadDecodedRefFrame(frameP, frameNumber);
-    
+
     writeYUVDecoded(otherSock, Fsize_x, Fsize_y, frameP);
-    
+
     Frame_Free(frameP);
-}        
+}
 
 
 
@@ -762,10 +763,10 @@ routeFromSocketToDisk(int              const otherSock,
 
         MALLOCARRAY_NOFAIL(bigBuffer, bigBufferSize);
     }
-    
+
     /* now read in the bytes */
     ReadBytes(otherSock, bigBuffer, numBytes);
-    
+
     /* open file to output this stuff to */
     pm_asprintf(&fileName, "%s.frame.%d", outputFileName, frameNumber);
     filePtr = fopen(fileName, "wb");
@@ -777,9 +778,9 @@ routeFromSocketToDisk(int              const otherSock,
 
     /* now write the bytes here */
     fwrite(bigBuffer, sizeof(char), numBytes, filePtr);
-    
+
     fclose(filePtr);
-    
+
     if (debugSockets) {
         fprintf(stdout, "====I/O SERVER:  WROTE FRAME %d to disk\n",
                 frameNumber);
@@ -788,7 +789,7 @@ routeFromSocketToDisk(int              const otherSock,
 
     *bigBufferP     = bigBuffer;
     *bigBufferSizeP = bigBufferSize;
-}        
+}
 
 
 
@@ -803,7 +804,7 @@ readConvertWriteToSocket(struct inputSource * const inputSourceP,
    the "base format" result to socket 'otherSock'.
 -----------------------------------------------------------------------------*/
     FILE * convertedFileP;
-    
+
     convertedFileP = ReadIOConvert(inputSourceP, frameNumber);
     if (convertedFileP) {
         bool eof;
@@ -811,21 +812,21 @@ readConvertWriteToSocket(struct inputSource * const inputSourceP,
         while (!eof) {
             unsigned char buffer[1024];
             unsigned int numBytes;
-            
+
             numBytes = fread(buffer, 1, sizeof(buffer), convertedFileP);
-            
+
             if (numBytes > 0) {
                 WriteInt(otherSock, numBytes);
                 WriteBytes(otherSock, buffer, numBytes);
             } else
                 eof = TRUE;
         }
-        
+
         if (strcmp(ioConversion, "*") == 0 )
             fclose(convertedFileP);
         else
             pclose(convertedFileP);
-        
+
         *endOfStreamP = FALSE;
     } else
         *endOfStreamP = TRUE;
@@ -848,13 +849,13 @@ readWriteYuvToSocket(struct inputSource * const inputSourceP,
     MpegFrame * frameP;
 
     frameP = Frame_New(frameNumber, 'i');
-    
+
     ReadFrame(frameP, inputSourceP, frameNumber, inputConversion,
               endOfStreamP);
-    
+
     if (!*endOfStreamP) {
         writeYUVOrig(otherSock, Fsize_x, Fsize_y, frameP);
-        
+
         {
             /* Make sure we don't leave until other processor read
                everything
@@ -907,7 +908,7 @@ processNextConnection(int                  const serverSocket,
     int          otherSock;
     int          command;
     const char * error;
-    
+
     AcceptConnection(serverSocket, &otherSock, &error);
     if (error)
         errorExit("I/O SERVER: Failed to accept next connection.  %s", error);
@@ -948,12 +949,12 @@ processNextConnection(int                  const serverSocket,
     }
     close(otherSock);
 }
- 
+
 
 
 void
 IoServer(struct inputSource * const inputSourceP,
-         const char *         const parallelHostName, 
+         const char *         const parallelHostName,
          int                  const portNum) {
 /*----------------------------------------------------------------------------
    Execute an I/O server.
@@ -979,7 +980,7 @@ IoServer(struct inputSource * const inputSourceP,
 
     bigBufferSize = 0;  /* Start with no buffer */
     bigBuffer = NULL;
-    
+
     /* once we get IO port num, should transmit it to parallel server */
 
     CreateListeningSocket(&serverSocket, &ioPortNum, &error);
@@ -1043,12 +1044,12 @@ SendRemoteFrame(int const frameNumber, BitBucket * const bb) {
     WriteInt(clientSocket, negativeFour);
 
     WriteInt(clientSocket, frameNumber);
-    
+
     if (frameNumber != -1) {
         /* send number of bytes */
-        
+
         WriteInt(clientSocket, (bb->totalbits+7)>>3);
-    
+
         /* now send the bytes themselves */
         Bitio_WriteToSocket(bb, clientSocket);
     }
@@ -1062,11 +1063,11 @@ SendRemoteFrame(int const frameNumber, BitBucket * const bb) {
 
 
 void
-GetRemoteFrame(MpegFrame * const frameP, 
+GetRemoteFrame(MpegFrame * const frameP,
                int         const frameNumber) {
 /*----------------------------------------------------------------------------
    Get a frame from the I/O server.
-   
+
    This is intended for use by a child.
 -----------------------------------------------------------------------------*/
     int           clientSocket;
@@ -1084,7 +1085,7 @@ GetRemoteFrame(MpegFrame * const frameP,
                     &clientSocket, &error);
 
     if (error)
-        errorExit("CHILD: Can't connect to I/O server to get a frame.  %s", 
+        errorExit("CHILD: Can't connect to I/O server to get a frame.  %s",
                   error);
 
     WriteInt(clientSocket, frameNumber);
@@ -1104,7 +1105,7 @@ GetRemoteFrame(MpegFrame * const frameP,
 
                 if (numBytes > sizeof(buffer))
                     errorExit("Invalid message received: numBytes = %d, "
-                              "which is greater than %u", 
+                              "which is greater than %u",
                               numBytes, (unsigned)sizeof(numBytes));
                 ReadBytes(clientSocket, buffer, numBytes);
 
@@ -1162,9 +1163,9 @@ getAndProcessACombineConnection(int const outputServerSocket) {
     if (error)
         errorExit("COMBINE SERVER: "
                   "Failed to accept next connection.  %s", error);
-    
+
     ReadInt(otherSock, &command);
-    
+
     if (command == -2) {
         /* this is notification from non-remote process that a
            frame is done.
@@ -1173,7 +1174,7 @@ getAndProcessACombineConnection(int const outputServerSocket) {
 
         ReadInt(otherSock, &frameStart);
         ReadInt(otherSock, &frameEnd);
-            
+
         machineDebug("COMBINE_SERVER: Frames %d - %d done",
                      frameStart, frameEnd);
         {
@@ -1199,7 +1200,7 @@ openInputFile(const char * const fileName,
 
     FILE * inputFileP;
     unsigned int attempts;
-    
+
     inputFileP = NULL;
     attempts = 0;
 
@@ -1207,14 +1208,14 @@ openInputFile(const char * const fileName,
         inputFileP = fopen(fileName, "rb");
         if (inputFileP == NULL) {
             pm_message("ERROR  Couldn't read frame file '%s' errno = %d (%s)"
-                       "attempt %d", 
+                       "attempt %d",
                        fileName, errno, strerror(errno), attempts);
             pm_sleep(1000);
         }
         ++attempts;
     }
     if (inputFileP == NULL)
-        pm_error("Unable to open file '%s' after %d attempts.", 
+        pm_error("Unable to open file '%s' after %d attempts.",
                  fileName, attempts);
 
     *inputFilePP = inputFileP;
@@ -1239,7 +1240,7 @@ waitForOutputFile(void *        const inputHandle,
         const char * fileName;
 
         while (!frameDone[frameNumber]) {
-            machineDebug("COMBINE_SERVER: Waiting for frame %u done", 
+            machineDebug("COMBINE_SERVER: Waiting for frame %u done",
                          frameNumber);
 
             getAndProcessACombineConnection(outputServerSocket);
@@ -1274,8 +1275,8 @@ unlinkFile(void *       const inputHandle,
 
 
 void
-CombineServer(int          const numFrames, 
-              const char * const masterHostName, 
+CombineServer(int          const numFrames,
+              const char * const masterHostName,
               int          const masterPortNum,
               const char * const outputFileName) {
 /*----------------------------------------------------------------------------
@@ -1287,17 +1288,17 @@ CombineServer(int          const numFrames,
   FILE * ofP;
   const char * error;
   struct combineControl combineControl;
-  
+
   /* once we get Combine port num, should transmit it to parallel server */
-  
+
   CreateListeningSocket(&outputServerSocket, &combinePortNum, &error);
   if (error)
       errorExit("Unable to create socket on which to listen.  %s", error);
 
   machineDebug("COMBINE SERVER: LISTENING ON PORT %d", combinePortNum);
-  
+
   TransmitPortNum(masterHostName, masterPortNum, combinePortNum);
-  
+
   MALLOCARRAY_NOFAIL(frameDone, numFrames);
   {
       unsigned int i;
@@ -1305,16 +1306,16 @@ CombineServer(int          const numFrames,
           frameDone[i] = FALSE;
   }
   ofP = pm_openw(outputFileName);
-  
+
   combineControl.numFrames = numFrames;
 
   FramesToMPEG(ofP, &combineControl, &waitForOutputFile, &unlinkFile);
 
   machineDebug("COMBINE SERVER: Shutting down");
-  
+
   /* tell Master server we are done */
   TransmitPortNum(masterHostName, masterPortNum, combinePortNum);
-  
+
   close(outputServerSocket);
 
   fclose(ofP);
@@ -1340,18 +1341,18 @@ startCombineServer(const char * const encoderName,
     int          otherSock;
     const char * error;
 
-    pm_snprintf(command, sizeof(command), 
+    pm_snprintf(command, sizeof(command),
                 "%s %s -max_machines %d -output_server %s %d %d %s",
-                encoderName, 
+                encoderName,
                 debugMachines ? "-debug_machines" : "",
-                numMachines, masterHostName, masterPortNum, 
+                numMachines, masterHostName, masterPortNum,
                 numInputFiles, paramFileName);
-    
+
     machineDebug("MASTER: Starting combine server with shell command '%s'",
                  command);
 
     safe_fork(command);
-    
+
     machineDebug("MASTER: Listening for connection back from "
                  "new Combine server");
 
@@ -1382,9 +1383,9 @@ startDecodeServer(const char * const encoderName,
     int          otherSock;
     const char * error;
 
-    pm_snprintf(command, sizeof(command), 
+    pm_snprintf(command, sizeof(command),
                 "%s %s -max_machines %d -decode_server %s %d %d %s",
-                encoder_name, 
+                encoder_name,
                 debugMachines ? "-debug_machines" : "",
                 numMachines, masterHostName, masterPortNum,
                 numInputFiles, paramFileName);
@@ -1404,9 +1405,9 @@ startDecodeServer(const char * const encoderName,
                   "decode server.  %s", error);
 
     ReadInt(otherSock, decodePortNumP);
-    
+
     close(otherSock);
-    
+
     machineDebug("MASTER:  Decode port number = %d", *decodePortNumP);
 }
 
@@ -1420,11 +1421,11 @@ startIoServer(const char *   const encoderName,
               int            const masterSocket,
               const char *   const paramFileName,
               int *          const ioPortNumP) {
-              
+
     char         command[1024];
     int          otherSock;
     const char * error;
-    
+
     sprintf(command, "%s -max_machines %d -io_server %s %d %s",
             encoderName, numChildren, masterHostName, masterPortNum,
             paramFileName);
@@ -1433,7 +1434,7 @@ startIoServer(const char *   const encoderName,
                  command);
 
     safe_fork(command);
-    
+
     machineDebug("MASTER: Listening for connection back from "
                  "new I/O server");
 
@@ -1442,14 +1443,14 @@ startIoServer(const char *   const encoderName,
         errorExit("MASTER SERVER: "
                   "Failed to accept connection back from the new "
                   "I/O server.  %s", error);
-    
+
     ReadInt(otherSock, ioPortNumP);
     close(otherSock);
-    
+
     machineDebug("MASTER:  I/O port number = %d", *ioPortNumP);
-}    
-    
-    
+}
+
+
 
 static void
 extendToEndOfPattern(unsigned int * const nFramesP,
@@ -1458,7 +1459,7 @@ extendToEndOfPattern(unsigned int * const nFramesP,
                      unsigned int   const numFramesInStream) {
 
     assert(framePatternLen >= 1);
-        
+
     while (startFrame + *nFramesP < numFramesInStream &&
            (startFrame + *nFramesP) % framePatternLen != 0)
         ++(*nFramesP);
@@ -1478,7 +1479,7 @@ allocateInitialFrames(struct scheduler * const schedulerP,
 /*----------------------------------------------------------------------------
    Choose which frames, to hand out to the new child numbered 'childNum'.
 -----------------------------------------------------------------------------*/
-    unsigned int const framesPerChild = 
+    unsigned int const framesPerChild =
         MAX(1, ((schedulerP->numFramesInJob - schedulerP->nextFrame) /
                 (schedulerP->numMachines - childNum)));
 
@@ -1507,7 +1508,7 @@ allocateInitialFrames(struct scheduler * const schedulerP,
 static float
 taperedGoalTime(struct childState const childState[],
                 unsigned int      const remainingFrameCount) {
-        
+
     float        goalTime;
     float        allChildrenFPS;
     float        remainingJobTime;
@@ -1515,9 +1516,9 @@ taperedGoalTime(struct childState const childState[],
     float        sum;
     int          numMachinesToEstimate;
     unsigned int childNum;
-    
+
     /* frames left = lastFrameInStream - startFrame + 1 */
-    for (childNum = 0, sum = 0.0, numMachinesToEstimate = 0; 
+    for (childNum = 0, sum = 0.0, numMachinesToEstimate = 0;
          childNum < numMachines; ++childNum) {
         if (!childState[childNum].finished) {
             if (childState[childNum].fps < 0.0 )
@@ -1526,12 +1527,12 @@ taperedGoalTime(struct childState const childState[],
                 sum += childState[childNum].fps;
         }
     }
-    
+
     allChildrenFPS = (float)numMachines *
         (sum/(float)(numMachines-numMachinesToEstimate));
-    
+
     remainingJobTime = (float)remainingFrameCount/allChildrenFPS;
-    
+
     goalTime = MAX(5.0, remainingJobTime/2);
 
     return goalTime;
@@ -1575,23 +1576,23 @@ allocateMoreFrames(struct scheduler * const schedulerP,
 
     if (!goalTimeSpecified) {
         goalTime = taperedGoalTime(childState,
-                                   schedulerP->numFramesInJob - 
+                                   schedulerP->numFramesInJob -
                                    schedulerP->nextFrame);
-    
+
         pm_message("MASTER: ASSIGNING %s %.2f seconds of work",
                    machineName[childNum], goalTime);
     } else
         goalTime = goalTimeArg;
-    
+
     if (childState[childNum].numSeconds != 0)
-        avgFps = (float)childState[childNum].numFrames / 
+        avgFps = (float)childState[childNum].numFrames /
             childState[childNum].numSeconds;
     else
         avgFps = 0.1;       /* arbitrary small value */
 
     nFrames = MAX(1u, (unsigned int)(goalTime * avgFps + 0.5));
-    
-    nFrames = MIN(nFrames, 
+
+    nFrames = MIN(nFrames,
                   schedulerP->numFramesInJob - schedulerP->nextFrame);
 
     if (forceIalign)
@@ -1648,7 +1649,7 @@ startChildren(struct scheduler *   const schedulerP,
     MALLOCARRAY_NOFAIL(childState, schedulerP->numMachines);
 
     childrenLeftCurrentIoServer = 0;  /* No current I/O server yet */
-    
+
     numIoServers = 0;  /* None created yet */
 
     for (childNum = 0; childNum < schedulerP->numMachines; ++childNum) {
@@ -1669,17 +1670,17 @@ startChildren(struct scheduler *   const schedulerP,
                          machineName[childNum]);
         } else {
             childState[childNum].finished   = FALSE;
-        
+
             if (remote[childNum]) {
                 if (childrenLeftCurrentIoServer == 0) {
-                    startIoServer(encoderName, schedulerP->numMachines, 
+                    startIoServer(encoderName, schedulerP->numMachines,
                                   masterHostName, masterPortNum, masterSocket,
                                   paramFileName, &ioPortNum[numIoServers++]);
-                    
+
                     childrenLeftCurrentIoServer = SOMAXCONN;
                 }
                 --childrenLeftCurrentIoServer;
-            } 
+            }
             pm_snprintf(command, sizeof(command),
                         "%s %s -l %s %s "
                         "%s %s -child %s %d %d %d %d %d %d "
@@ -1689,22 +1690,22 @@ startChildren(struct scheduler *   const schedulerP,
                         beNice ? "nice" : "",
                         executable[childNum],
                         debugMachines ? "-debug_machines" : "",
-                        masterHostName, masterPortNum, 
+                        masterHostName, masterPortNum,
                         remote[childNum] ? ioPortNum[numIoServers-1] : 0,
                         combinePortNum, decodePortNum, childNum,
                         remote[childNum] ? 1 : 0,
                         startFrame, startFrame + nFrames - 1,
-                        remote[childNum] ? 
+                        remote[childNum] ?
                           remoteParamFile[childNum] : paramFileName
                 );
-        
+
             machineDebug("MASTER: Starting child server "
                          "with shell command '%s'", command);
 
             safe_fork(command);
 
             machineDebug("MASTER: Frames %d-%d assigned to new child %s",
-                         startFrame, startFrame + nFrames - 1, 
+                         startFrame, startFrame + nFrames - 1,
                          machineName[childNum]);
         }
         childState[childNum].startFrame = startFrame;
@@ -1720,7 +1721,7 @@ startChildren(struct scheduler *   const schedulerP,
 static void
 noteFrameDone(const char * const combineHostName,
               int          const combinePortNum,
-              unsigned int const frameStart, 
+              unsigned int const frameStart,
               unsigned int const frameEnd) {
 /*----------------------------------------------------------------------------
    Tell the Combine server that frames 'frameStart' through 'frameEnd'
@@ -1738,7 +1739,7 @@ noteFrameDone(const char * const combineHostName,
 
     ConnectToSocket(combineHostName, combinePortNum, &hostEntP,
                     &clientSocket, &error);
-    
+
     if (error)
         errorExit("MASTER: Can't connect to Combine server to tell it frames "
                   "are done.  %s", error);
@@ -1775,7 +1776,7 @@ feedTheChildren(struct scheduler * const schedulerP,
    As children finish assignments, inform the combine server at
    'combineHostName':'combinePortNum' of such.
 
-   Note that the children got initial assigments when they were created.
+   Note that the children got initial assignments when they were created.
    So the first thing we do is wait for them to finish those.
 -----------------------------------------------------------------------------*/
     unsigned int numFinished;
@@ -1808,7 +1809,7 @@ feedTheChildren(struct scheduler * const schedulerP,
         ReadInt(otherSock, &seconds);
 
         csP = &childState[childNum];
-        
+
         csP->numSeconds += seconds;
         csP->fps = (float)csP->numFrames / (float)csP->numSeconds;
 
@@ -1818,7 +1819,7 @@ feedTheChildren(struct scheduler * const schedulerP,
             framesPerSecond = (float)csP->lastNumFrames * 2.0;
 
         machineDebug("MASTER: Child %s FINISHED ASSIGNMENT.  "
-                     "%f frames per second", 
+                     "%f frames per second",
                      machineName[childNum], framesPerSecond);
 
         noteFrameDone(combineHostName, combinePortNum, csP->startFrame,
@@ -1855,7 +1856,7 @@ feedTheChildren(struct scheduler * const schedulerP,
         close(otherSock);
 
         machineDebug("MASTER: %d/%d DONE; %d ARE ASSIGNED",
-                     framesDone, schedulerP->numFramesInJob, 
+                     framesDone, schedulerP->numFramesInJob,
                      schedulerP->nextFrame - framesDone);
     }
 }
@@ -1898,7 +1899,7 @@ waitForCombineServerToTerminate(int const masterSocket) {
     }
     close(otherSock);
 }
-    
+
 
 
 static void
@@ -1932,46 +1933,46 @@ printFinalStats(FILE *            const statfileP,
                     (unsigned int)(startUpEnd - startUpBegin));
             fprintf(fileP, "SHUT DOWN TIME:  %u seconds\n",
                     (unsigned int)(shutDownEnd - shutDownBegin));
-            
-            fprintf(fileP, 
+
+            fprintf(fileP,
                     "%14.14s %8.8s %8.8s %12.12s %9.9s\n",
                     "MACHINE", "Frames", "Seconds", "Frames/Sec",
                     "Self Time");
 
-            fprintf(fileP, 
+            fprintf(fileP,
                     "%14.14s %8.8s %8.8s %12.12s %9.9s\n",
                     "--------------", "--------", "--------", "------------",
                     "---------");
 
             totalFPS = 0.0;
             for (childNum = 0; childNum < numChildren; ++childNum) {
-                float const localFPS = 
+                float const localFPS =
                     (float)childState[childNum].numFrames /
                     childState[childNum].numSeconds;
                 fprintf(fileP, "%14.14s %8u %8u %12.4f %8u\n",
-                        machineName[childNum], 
-                        childState[childNum].numFrames, 
+                        machineName[childNum],
+                        childState[childNum].numFrames,
                         childState[childNum].numSeconds,
-                        localFPS, 
+                        localFPS,
                         (unsigned int)((float)numFrames/localFPS));
                 totalFPS += localFPS;
             }
 
-            fprintf(fileP, 
+            fprintf(fileP,
                     "%14.14s %8.8s %8.8s %12.12s %9.9s\n",
                     "--------------", "--------", "--------", "------------",
                     "---------");
 
-            fprintf(fileP, "%14s %8.8s %8u %12.4f\n", 
-                    "OPTIMAL", "", 
+            fprintf(fileP, "%14s %8.8s %8u %12.4f\n",
+                    "OPTIMAL", "",
                     (unsigned int)((float)numFrames/totalFPS),
                     totalFPS);
-            
+
             {
                 unsigned int const diffTime = shutDownEnd - startUpBegin;
-                
-                fprintf(fileP, "%14s %8.8s %8u %12.4f\n", 
-                        "ACTUAL", "", diffTime, 
+
+                fprintf(fileP, "%14s %8.8s %8u %12.4f\n",
+                        "ACTUAL", "", diffTime,
                         (float)numFrames / diffTime);
             }
             fprintf(fileP, "\n\n");
@@ -1983,7 +1984,7 @@ printFinalStats(FILE *            const statfileP,
 
 void
 MasterServer(struct inputSource * const inputSourceP,
-             const char *         const paramFileName, 
+             const char *         const paramFileName,
              const char *         const outputFileName) {
 /*----------------------------------------------------------------------------
    Execute the master server function.
@@ -2025,21 +2026,21 @@ MasterServer(struct inputSource * const inputSourceP,
         fprintf(stdout, "---MASTER USING PORT %d\n", portNum);
 
     startCombineServer(encoder_name, numMachines, hostName, portNum,
-                       inputSourceP->numInputFiles, 
-                       paramFileName, masterSocket, 
+                       inputSourceP->numInputFiles,
+                       paramFileName, masterSocket,
                        &combinePortNum);
 
     if (referenceFrame == DECODED_FRAME)
         startDecodeServer(encoder_name, numMachines, hostName, portNum,
-                          inputSourceP->numInputFiles, 
+                          inputSourceP->numInputFiles,
                           paramFileName, masterSocket,
                           &decodePortNum);
 
     startChildren(&scheduler, encoder_name, hostName, portNum,
                   paramFileName, parallelPerfect, forceIalign,
-                  framePatternLen, parallelTestFrames, 
+                  framePatternLen, parallelTestFrames,
                   niceProcesses,
-                  masterSocket, combinePortNum, decodePortNum, 
+                  masterSocket, combinePortNum, decodePortNum,
                   ioPortNum, &numIoServers,
                   &childState);
 
@@ -2076,10 +2077,10 @@ MasterServer(struct inputSource * const inputSourceP,
 
 
 void
-NotifyMasterDone(const char * const masterHostName, 
-                 int          const masterPortNum, 
+NotifyMasterDone(const char * const masterHostName,
+                 int          const masterPortNum,
                  int          const childNum,
-                 unsigned int const seconds, 
+                 unsigned int const seconds,
                  boolean *    const moreWorkToDoP,
                  int *        const nextFrameStartP,
                  int *        const nextFrameEndP) {
@@ -2098,11 +2099,11 @@ NotifyMasterDone(const char * const masterHostName,
     time_t tempTimeStart, tempTimeEnd;
     const char * error;
 
-    machineDebug("CHILD: NOTIFYING MASTER Machine %d assignment complete", 
+    machineDebug("CHILD: NOTIFYING MASTER Machine %d assignment complete",
                  childNum);
 
     time(&tempTimeStart);
-    
+
     ConnectToSocket(masterHostName, masterPortNum, &hostEntry,
                     &clientSocket, &error);
     if (error)
@@ -2132,9 +2133,9 @@ NotifyMasterDone(const char * const masterHostName,
 
 
 void
-DecodeServer(int          const numInputFiles, 
-             const char * const decodeFileName, 
-             const char * const masterHostName, 
+DecodeServer(int          const numInputFiles,
+             const char * const decodeFileName,
+             const char * const masterHostName,
              int          const masterPortNum) {
 /*----------------------------------------------------------------------------
    Execute the decode server.
@@ -2220,7 +2221,7 @@ DecodeServer(int          const numInputFiles,
             }
         } else {
             frameDone[frameReady] = TRUE;
-            
+
             machineDebug("DECODE SERVER:  FRAME %d READY", frameReady);
 
             if ( waitMachine[frameReady] ) {
@@ -2233,7 +2234,7 @@ DecodeServer(int          const numInputFiles,
                                     &clientSocket, &error);
                     if (error)
                         errorExit("DECODE SERVER: "
-                                  "Can't connect to child machine.  %s", 
+                                  "Can't connect to child machine.  %s",
                                   error);
                     close(clientSocket);
                     waitPtr = waitList[waitPtr]-1;
@@ -2243,7 +2244,7 @@ DecodeServer(int          const numInputFiles,
 
         close(otherSock);
     }
-    
+
     machineDebug("DECODE SERVER:  Shutting down");
 
     /* tell Master server we are done */
diff --git a/converter/ppm/ppmtompeg/param.c b/converter/ppm/ppmtompeg/param.c
index ce2cadf1..9499b4ea 100644
--- a/converter/ppm/ppmtompeg/param.c
+++ b/converter/ppm/ppmtompeg/param.c
@@ -1,8 +1,8 @@
 /*===========================================================================*
- * param.c              
- *                      
- *  Procedures to read in parameter file  
- *                                    
+ * param.c
+ *
+ *  Procedures to read in parameter file
+ *
  *===========================================================================*/
 
 /* COPYRIGHT INFORMATION IS AT THE END OF THIS FILE */
@@ -10,9 +10,9 @@
 #define _DEFAULT_SOURCE 1
     /* New name for SVID & BSD source defines */
 #define _XOPEN_SOURCE 500
-    /* This makes sure popen() is in stdio.h.  In GNU libc 2.1.3, 
+    /* This makes sure popen() is in stdio.h.  In GNU libc 2.1.3,
      _POSIX_C_SOURCE = 2 is sufficient, but on AIX 4.3, the higher level
-     _XOPEN_SOURCE is required.  2000.09.09 
+     _XOPEN_SOURCE is required.  2000.09.09
 
      This also makes sure strdup() is in string.h.
     */
@@ -125,11 +125,6 @@ int mult_seq_headers = 0;  /* 0 for none, N for header/N GOPs */
 
 extern char currentPath[MAXPATHLEN];
 
-static const char * const optionText[LAST_OPTION+1] = { 
-    "GOP_SIZE", "PATTERN", "PIXEL", "PQSCALE",
-    "OUTPUT", "RANGE", "PSEARCH_ALG", "IQSCALE", "INPUT_DIR",
-    "INPUT_CONVERT", "INPUT", "BQSCALE", "BASE_FILE_FORMAT",
-    "SLICES_PER_FRAME", "BSEARCH_ALG", "REFERENCE_FRAME"};
 static bool optionSeen[NUM_OPTIONS+1];
     /* optionSeen[x] means we have seen option x in the parameter file we've
        been reading.
@@ -250,7 +245,7 @@ ReadMachineNames(FILE * const fpointer)
  *
  * GetFrameRate
  *
- * take a character string with the input frame rate 
+ * take a character string with the input frame rate
  * and return the correct frame rate code for use in the Sequence header
  *
  * RETURNS: frame rate code as per MPEG-I spec
@@ -292,7 +287,7 @@ mergeInputSource(struct inputSource *       const baseSourceP,
     unsigned int i;
 
     baseSourceP->ifArraySize += addedSourceP->numInputFileEntries;
-    REALLOCARRAY_NOFAIL(baseSourceP->inputFileEntries, 
+    REALLOCARRAY_NOFAIL(baseSourceP->inputFileEntries,
                         baseSourceP->ifArraySize);
     for (i = 0; i < addedSourceP->numInputFileEntries; ++i)
         baseSourceP->inputFileEntries[baseSourceP->numInputFileEntries++] =
@@ -303,7 +298,7 @@ mergeInputSource(struct inputSource *       const baseSourceP,
 
 /* Forward declaration for recursively called function */
 static void
-ReadInputFileNames(FILE *               const fpointer, 
+ReadInputFileNames(FILE *               const fpointer,
                    const char *         const endInput,
                    struct inputSource * const inputSourceP);
 
@@ -355,11 +350,11 @@ expandBackTickLine(const char *         const input,
 
 
 static void
-ReadInputFileNames(FILE *               const fpointer, 
+ReadInputFileNames(FILE *               const fpointer,
                    const char *         const endInput,
                    struct inputSource * const inputSourceP) {
 /*----------------------------------------------------------------------------
-   Read a list of input file names from the parameter file.  Add 
+   Read a list of input file names from the parameter file.  Add
    the information to *inputSourceP.
 
    If inputSourceP == NULL, read off the list, but ignore it.
@@ -384,7 +379,7 @@ ReadInputFileNames(FILE *               const fpointer,
         else {
             if (strncmp(input, endInput, strlen(endInput)) == 0)
                 endStatementRead = TRUE;
-            else if ((input[0] == '#') || (input[0] == '\n')) { 
+            else if ((input[0] == '#') || (input[0] == '\n')) {
                 /* It's a comment or blank line.  Ignore it */
             } else if (input[0] == '`' ) {
                 expandBackTickLine(input, inputSourceP);
@@ -405,7 +400,7 @@ static void
 initOptionSeen(void) {
 
     unsigned int index;
-    
+
     for (index = FIRST_OPTION; index < NUM_OPTIONS; ++index)
         optionSeen[index] = FALSE;
 }
@@ -477,7 +472,7 @@ verifyNoMissingCombineFramesOption(void) {
 static void
 verifyNoMissingOption(int  const function) {
 /*----------------------------------------------------------------------------
-  Verify that the parameter file contains every option it is supposed to. 
+  Verify that the parameter file contains every option it is supposed to.
   Abort program if not.
 -----------------------------------------------------------------------------*/
     switch(function) {
@@ -515,7 +510,7 @@ processIqtable(FILE * const fpointer) {
                         &qtable[row*8+2],  &qtable[row*8+3],
                         &qtable[row*8+4],  &qtable[row*8+5],
                         &qtable[row*8+6],  &qtable[row*8+7])) {
-            pm_error("Line %d of IQTABLE doesn't have 8 elements!", 
+            pm_error("Line %d of IQTABLE doesn't have 8 elements!",
                      row);
         }
         for (col = 0; col < 8; ++col) {
@@ -528,7 +523,7 @@ processIqtable(FILE * const fpointer) {
             }
         }
     }
-            
+
     if (qtable[0] != 8) {
         pm_message("Warning:  IQTable Element 1,1 reset to 8, "
                    "since it must be 8.");
@@ -593,15 +588,15 @@ removeTrailingWhite(const char *  const rawLine,
         pm_error("Unable to get memory to process parameter file");
 
     p = buffer + strlen(buffer) - 1;  /* Point to last character */
-    
+
     /* Position p to just before the trailing white space (might be one
        character before beginning of string!)
     */
     while (p >= buffer && isspace(*p))
         --p;
-    
+
     ++p;  /* Move to first trailing whitespace character */
-    
+
     *p = '\0';  /* Chop off all the trailing whitespace */
 
     *editedLineP = buffer;
@@ -622,7 +617,7 @@ readNiqTable(FILE * const fpointer) {
                         &niqtable[row*8+2],  &niqtable[row*8+3],
                         &niqtable[row*8+4],  &niqtable[row*8+5],
                         &niqtable[row*8+6],  &niqtable[row*8+7])) {
-            pm_error("Line %d of NIQTABLE doesn't have 8 elements!", 
+            pm_error("Line %d of NIQTABLE doesn't have 8 elements!",
                      row);
         }
         for ( col = 0; col < 8; col++ ) {
@@ -675,7 +670,7 @@ processParamLine(char const input[],
             optionSeen[OPTION_ASPECT_RATIO] = TRUE;
         }
         break;
-        
+
     case 'B':
         if (strneq(input, "BQSCALE", 7)) {
             SetBQScale(atoi(SkipSpacesTabs(&input[7])));
@@ -694,7 +689,7 @@ processParamLine(char const input[],
             optionSeen[OPTION_BIT_RATE] = TRUE;
         } else if (strneq(input, "BUFFER_SIZE", 11)) {
             setBufferSize(SkipSpacesTabs(&input[11]));
-            optionSeen[OPTION_BUFFER_SIZE] = TRUE;                  
+            optionSeen[OPTION_BUFFER_SIZE] = TRUE;
         }
         break;
 
@@ -717,8 +712,8 @@ processParamLine(char const input[],
 
             strcpy(currentFramePath, arg);
         } else if (strneq(input, "FRAME_INPUT", 11)) {
-            ReadInputFileNames(fpointer, "FRAME_END_INPUT", 
-                               frameInputSourceP->stdinUsed ? 
+            ReadInputFileNames(fpointer, "FRAME_END_INPUT",
+                               frameInputSourceP->stdinUsed ?
                                NULL : frameInputSourceP);
             optionSeen[OPTION_FRAME_INPUT] = TRUE;
         } else if (strneq(input, "FORCE_I_ALIGN", 13)) {
@@ -726,7 +721,7 @@ processParamLine(char const input[],
         } else if (strneq(input, "FORCE_ENCODE_LAST_FRAME", 23)) {
             /* NO-OP.  We used to drop trailing B frames by default and you
                needed this option to change the last frame to I so you could
-               encode all the frames.  Now we just do that all the time.  
+               encode all the frames.  Now we just do that all the time.
                Why wouldn't we?
             */
         } else if (strneq(input, "FRAME_RATE", 10)) {
@@ -737,7 +732,7 @@ processParamLine(char const input[],
             optionSeen[OPTION_FRAME_RATE] = TRUE;
         }
         break;
-        
+
     case 'G':
         if (strneq(input, "GOP_SIZE", 8)) {
             SetGOPSize(atoi(SkipSpacesTabs(&input[8])));
@@ -749,8 +744,8 @@ processParamLine(char const input[],
 
             strcpy(currentGOPPath, arg);
         } else if (strneq(input, "GOP_INPUT", 9)) {
-            ReadInputFileNames(fpointer, "GOP_END_INPUT", 
-                               gopInputSourceP->stdinUsed ? 
+            ReadInputFileNames(fpointer, "GOP_END_INPUT",
+                               gopInputSourceP->stdinUsed ?
                                NULL : gopInputSourceP);
             optionSeen[OPTION_GOP_INPUT] = TRUE;
         } else if (strneq(input, "GAMMA", 5)) {
@@ -759,7 +754,7 @@ processParamLine(char const input[],
             optionSeen[OPTION_GAMMA] = TRUE;
         }
         break;
-        
+
     case 'I':
         if (strneq(input, "IQSCALE", 7)) {
             SetIQScale(atoi(SkipSpacesTabs(&input[7])));
@@ -774,7 +769,7 @@ processParamLine(char const input[],
             strcpy(inputConversion, SkipSpacesTabs(&input[13]));
             optionSeen[OPTION_INPUT_CONVERT] = TRUE;
         } else if (streq(input, "INPUT")) {
-            ReadInputFileNames(fpointer, "END_INPUT", 
+            ReadInputFileNames(fpointer, "END_INPUT",
                                inputSourceP->stdinUsed ?
                                NULL : inputSourceP);
             optionSeen[OPTION_INPUT] = TRUE;
@@ -792,7 +787,7 @@ processParamLine(char const input[],
         if (strneq(input, "KEEP_TEMP_FILES", 15))
             keepTempFiles = TRUE;
         break;
-        
+
     case 'N':
       if (strneq(input, "NIQTABLE", 8)) {
           readNiqTable(fpointer);
@@ -808,11 +803,11 @@ processParamLine(char const input[],
                 strcpy(outputFileName, arg);
             else
                 sprintf(outputFileName, "%s.gop.%d", arg, whichGOP);
-            
+
             optionSeen[OPTION_OUTPUT] = TRUE;
         }
         break;
-        
+
     case 'P':
         if (strneq(input, "PATTERN", 7)) {
             SetFramePattern(SkipSpacesTabs(&input[7]));
@@ -842,7 +837,7 @@ processParamLine(char const input[],
             optionSeen[OPTION_PARALLEL] = TRUE;
         }
         break;
-        
+
     case 'R':
         if (strneq(input, "RANGE", 5)) {
             processRanges(SkipSpacesTabs(&input[5]));
@@ -900,14 +895,14 @@ processParamLine(char const input[],
             optionSeen[OPTION_USER_DATA] = TRUE;
         }
         break;
-        
+
     case 'W':
         if (strneq(input, "WARN_UNDERFLOW", 14))
             paramP->warnUnderflow = TRUE;
         if (strneq(input, "WARN_OVERFLOW", 13))
             paramP->warnOverflow = TRUE;
         break;
-        
+
     case 'Y':
         if (strneq(input, "YUV_SIZE", 8)) {
             const char * const arg = SkipSpacesTabs(&input[8]);
@@ -934,7 +929,7 @@ processParamLine(char const input[],
 
 
 void
-ReadParamFile(const char *         const fileName, 
+ReadParamFile(const char *         const fileName,
               majorProgramFunction const function,
               struct params *      const paramP) {
 /*----------------------------------------------------------------------------
@@ -1014,7 +1009,7 @@ ReadParamFile(const char *         const fileName,
   if (yuvUsed) {
       if (!optionSeen[OPTION_YUV_SIZE])
           pm_error("YUV format used but YUV_SIZE not given");
-      
+
       if (!optionSeen[OPTION_YUV_FORMAT]) {
           strcpy (yuvConversion, "EYUV");
           pm_message("WARNING:  YUV format not specified; "
@@ -1031,7 +1026,7 @@ ReadParamFile(const char *         const fileName,
   if (optionSeen[OPTION_IO_CONVERT] != optionSeen[OPTION_SLAVE_CONVERT])
       pm_error("Must have either both IO_SERVER_CONVERT and SLAVE_CONVERT "
                "or neither");
-      
+
   if (optionSeen[OPTION_DEFS_SPECIFICS] && !optionSeen[OPTION_SPECIFICS])
       pm_error("Does not make sense to define Specifics file options, "
                "but no specifics file!");
diff --git a/converter/ppm/ppmtompeg/parse_huff.pl b/converter/ppm/ppmtompeg/parse_huff.pl
index 1fc6466c..633e5877 100644
--- a/converter/ppm/ppmtompeg/parse_huff.pl
+++ b/converter/ppm/ppmtompeg/parse_huff.pl
@@ -51,7 +51,7 @@
 #    composed of 1, 0, space, and 's'.  Spaces are ignored, and
 #    s corresponds to the sign bit.  In the output of this program,
 #    We'll completely right-shift the data, with a 0 for the sign
-#    bit.  The encoder will make appropriate changes before outputing.
+#    bit.  The encoder will make appropriate changes before outputting.
 
 
 open(HUFFC, "> huff.c") || die "Can't write huff.c: $!\n";
diff --git a/converter/ppm/ppmtompeg/psearch.c b/converter/ppm/ppmtompeg/psearch.c
index 3cca1241..e350137e 100644
--- a/converter/ppm/ppmtompeg/psearch.c
+++ b/converter/ppm/ppmtompeg/psearch.c
@@ -58,7 +58,7 @@ int psearchAlg;
  *
  * PRECONDITIONS:   The relevant block in 'current' is valid (it has not
  *          been dct'd).  Thus, the data in 'current' can be
- *          accesed through y_blocks, cr_blocks, and cb_blocks.
+ *          accessed through y_blocks, cr_blocks, and cb_blocks.
  *          This is not the case for the blocks in 'prev.'
  *          Therefore, references into 'prev' should be done
  *          through the struct items ref_y, ref_cr, ref_cb
diff --git a/converter/ppm/ppmtompeg/psocket.c b/converter/ppm/ppmtompeg/psocket.c
index 6a50dc27..aac61022 100644
--- a/converter/ppm/ppmtompeg/psocket.c
+++ b/converter/ppm/ppmtompeg/psocket.c
@@ -10,15 +10,15 @@
 ============================================================================*/
 
 #define _XOPEN_SOURCE 500 /* Make sure stdio.h contains pclose() */
-/* _ALL_SOURCE is needed on AIX to make the C library include the 
-   socket services (e.g. define struct sockaddr) 
+/* _ALL_SOURCE is needed on AIX to make the C library include the
+   socket services (e.g. define struct sockaddr)
 
    Note that AIX standards.h actually sets feature declaration macros such
    as _XOPEN_SOURCE, unless they are already set.
 */
 #define _ALL_SOURCE
 #define __EXTENSIONS__
-  /* __EXTENSIONS__ is for a broken Sun C library (uname SunOS kosh 5.8 
+  /* __EXTENSIONS__ is for a broken Sun C library (uname SunOS kosh 5.8
      generic_108528-16 sun4u sparc).  When you define _XOPEN_SOURCE,
      it's vnode.h and resource.h fail to define some data types that they
      need (e.g. timestruct_t).  But with __EXTENSIONS__, they declare the
@@ -126,8 +126,8 @@ unmarshallInt(unsigned char const buffer[],
 
 
 static void
-safeRead(int             const fd, 
-         unsigned char * const buf, 
+safeRead(int             const fd,
+         unsigned char * const buf,
          unsigned int    const nbyte) {
 /*----------------------------------------------------------------------------
     Safely read from file 'fd'.  Keep reading until we get
@@ -144,7 +144,7 @@ safeRead(int             const fd,
             errorExit("read (of %u bytes (total %u) ) returned "
                       "errno %d (%s)",
                       nbyte-numRead, nbyte, errno, strerror(errno));
-        else 
+        else
             numRead += result;
     }
 }
@@ -203,8 +203,8 @@ marshallInt(int              const value,
 
 
 static void
-safeWrite(int             const fd, 
-          unsigned char * const buf, 
+safeWrite(int             const fd,
+          unsigned char * const buf,
           unsigned int    const nbyte) {
 /*----------------------------------------------------------------------------
   Safely write to file 'fd'.  Keep writing until we write 'nbyte'
@@ -217,7 +217,7 @@ safeWrite(int             const fd,
     while (numWritten < nbyte) {
         int const result = write(fd, &buf[numWritten], nbyte-numWritten);
 
-        if (result == -1) 
+        if (result == -1)
             errorExit("write (of %u bytes (total %u) ) returned "
                       "errno %d (%s)",
                       nbyte-numWritten, nbyte, errno, strerror(errno));
@@ -251,8 +251,8 @@ WriteInt(int const socketFd,
 
 
 void
-ConnectToSocket(const char *      const machineName, 
-                int               const portNum, 
+ConnectToSocket(const char *      const machineName,
+                int               const portNum,
                 struct hostent ** const hostEnt,
                 int *             const socketFdP,
                 const char **     const errorP) {
@@ -266,7 +266,7 @@ ConnectToSocket(const char *      const machineName,
    **hostEnt.
 -----------------------------------------------------------------------------*/
     int rc;
-    
+
     *errorP = NULL;  /* initial value */
 
     if ((*hostEnt) == NULL) {
@@ -277,15 +277,15 @@ ConnectToSocket(const char *      const machineName,
     if (!*errorP) {
         rc = socket(AF_INET, SOCK_STREAM, 0);
         if (rc < 0)
-            pm_asprintf(errorP, "socket() failed with errno %d (%s)", 
+            pm_asprintf(errorP, "socket() failed with errno %d (%s)",
                         errno, strerror(errno));
         else {
             int const socketFd = rc;
-            
+
             int rc;
             unsigned short tempShort;
             struct sockaddr_in  nameEntry;
-            
+
             nameEntry.sin_family = AF_INET;
             memset((void *) nameEntry.sin_zero, 0, 8);
             memcpy((void *) &(nameEntry.sin_addr.s_addr),
@@ -293,12 +293,12 @@ ConnectToSocket(const char *      const machineName,
                    (size_t) (*hostEnt)->h_length);
             tempShort = portNum;
             nameEntry.sin_port = htons(tempShort);
-            
+
             rc = connect(socketFd, (struct sockaddr *) &nameEntry,
                          sizeof(struct sockaddr));
-            
+
             if (rc != 0)
-                pm_asprintf(errorP, 
+                pm_asprintf(errorP,
                             "connect() to host '%s', port %d failed with "
                             "errno %d (%s)",
                             machineName, portNum, errno, strerror(errno));
@@ -317,7 +317,7 @@ ConnectToSocket(const char *      const machineName,
 static bool
 portInUseErrno(int const testErrno) {
 /*----------------------------------------------------------------------------
-   Return TRUE iff 'testErrno' is what a bind() would return if one requestd
+   Return TRUE iff 'testErrno' is what a bind() would return if one requested
    a port number that is unavailable (but other port numbers might be).
 -----------------------------------------------------------------------------*/
     bool retval;
@@ -340,19 +340,19 @@ static void
 bindToUnusedPort(int              const socketFd,
                  unsigned short * const portNumP,
                  const char **    const errorP) {
-    
+
     bool foundPort;
     unsigned short trialPortNum;
 
     *errorP = NULL;  /* initial value */
 
-    for (foundPort = FALSE, trialPortNum = 2048; 
-         !foundPort && trialPortNum < 16384 && !*errorP; 
+    for (foundPort = FALSE, trialPortNum = 2048;
+         !foundPort && trialPortNum < 16384 && !*errorP;
          ++trialPortNum) {
-        
+
         struct sockaddr_in nameEntry;
         int rc;
-        
+
         memset((char *) &nameEntry, 0, sizeof(nameEntry));
         nameEntry.sin_family = AF_INET;
         nameEntry.sin_port   = htons(trialPortNum);
@@ -365,10 +365,10 @@ bindToUnusedPort(int              const socketFd,
             *portNumP = trialPortNum;
         } else if (!portInUseErrno(errno))
             pm_asprintf(errorP, "bind() of TCP port number %hu failed "
-                        "with errno %d (%s)", 
+                        "with errno %d (%s)",
                         trialPortNum, errno, strerror(errno));
     }
-    
+
     if (!*errorP && !foundPort)
         pm_asprintf(errorP, "Unable to find a free port.  Every TCP port "
                     "in the range 2048-16383 is in use");
@@ -389,7 +389,7 @@ CreateListeningSocket(int *         const socketP,
    partner can connect).
 -----------------------------------------------------------------------------*/
     int rc;
-    
+
     rc = socket(AF_INET, SOCK_STREAM, 0);
     if (rc < 0)
         pm_asprintf(errorP,
@@ -415,7 +415,7 @@ CreateListeningSocket(int *         const socketP,
             rc = listen(socketFd, SOMAXCONN);
             if (rc != 0)
                 pm_asprintf(errorP, "Unable to listen on TCP socket.  "
-                            "listen() fails with errno %d (%s)", 
+                            "listen() fails with errno %d (%s)",
                             errno, strerror(errno));
         }
         if (*errorP)
@@ -433,11 +433,11 @@ AcceptConnection(int           const listenSocketFd,
     struct sockaddr otherSocket;
     socklenx_t      otherSize;
         /* This is an ugly dual-meaning variable.  As input to accept(),
-           it is the storage size of 'otherSocket'.  As output, it is the 
+           it is the storage size of 'otherSocket'.  As output, it is the
            data length of 'otherSocket'.
         */
     int             rc;
-    
+
     otherSize = sizeof(otherSocket);
 
     rc = accept(listenSocketFd, &otherSocket, &otherSize);
@@ -450,3 +450,6 @@ AcceptConnection(int           const listenSocketFd,
         *errorP = NULL;
     }
 }
+
+
+
diff --git a/converter/ppm/ppmtompeg/rate.c b/converter/ppm/ppmtompeg/rate.c
index 6ec330cf..3fa41102 100644
--- a/converter/ppm/ppmtompeg/rate.c
+++ b/converter/ppm/ppmtompeg/rate.c
@@ -1,6 +1,6 @@
 /*============================================================================*
  * rate.c								      *
- *									      * 
+ *									      *
  *	Procedures concerned with rate control                                *
  *									      *
  * EXPORTED PROCEDURES:							      *
@@ -75,7 +75,7 @@
 
 #define MAX_BIT_RATE 104857600		/* 18 digit number in units of 400 */
 #define MAX_BUFFER_SIZE 16760832        /* 10 digit number in units of 16k */
-#define DEFAULT_BUFFER_SIZE 327680      /* maximun for "constrained" bitstream */
+#define DEFAULT_BUFFER_SIZE 327680      /* maximum for "constrained" bitstream */
 #define DEFAULT_VBV_FULLNESS 3          /* wait till 1/3 full */
 #define DEFAULT_PICT_RATE_CODE 5        /* code for 30 Frames/sec */
 #define DEFAULT_PICT_RATE 30            /* 30 frames per second */
@@ -92,7 +92,7 @@ static bool wantVbvUnderflowWarning;
 static bool wantVbvOverflowWarning;
 
 /*   Variables for the VBV buffer defined in MPEG specs */
-static unsigned int VBV_remainingDelay; 
+static unsigned int VBV_remainingDelay;
     /* delay in units of 1/90000 seconds */
 static int32 VBV_buffer = 0;	  /* fullness of the theoretical VBV buffer */
 static int32 bufferFillRate = 0;    /* constant rate at which buffer filled */
@@ -104,7 +104,7 @@ static int Xi, Xp, Xb;  /*  Global complexity measure  */
 static int Si, Sp, Sb;  /*  Total # bits for last pict of type (Overhead?) */
 
 static float Qi, Qp, Qb; /* avg quantizaton for last picture of type  */
-     
+
 /*  Target bit allocations for each type of picture*/
 int Ti, Tp, Tb;
 
@@ -175,24 +175,6 @@ static int Qscale;	       /* Clipped, truncated quantization value */
 static FILE *RC_FILE;
 #endif
 
-static const char * const Frame_header1 = 
-"  Fm         #     Bit      GOP                    V                ";
-static const char * const Frame_header2 = 
-"   #  type   MBs   Alloc    left  Ni Np Nb  N_act  buff   Q_rc Qscale";
-static const char * const Frame_header3 = 
-"----     -  ----  ------ -------  -- -- --  -----  ------ ----   ----";
-static const char * const Frame_trailer1 = 
-"                      avg          virt     %    GOP      %     VBV";
-static const char * const Frame_trailer2 = 
-"    Sx    Qx      Xx  act N_act  buffer alloc    left  left     buf  delay";
-static const char * const Frame_trailer3 = 
-"------ --.-- -------  --- --.-- -------   --- -------   --- ------- ------";
-
-static const char * const MB_header1 = 
-"MB#  #bits  Q mqt     Dj  Q_j   actj  N_act  totbits b/MB %alloc %done";
-static const char * const MB_header2 = 
-"---  ----- -- --- ------  ---  -----  --.--   ------ ----    ---   ---";
-
 static char rc_buffer[101];
 
 /*	EXTERNAL Variables  */
@@ -211,8 +193,8 @@ void checkSpatialActivity (Block blk0, Block blk1, Block blk2, Block blk3);
 void incNumBlocks (int num);
 void calculateVBVDelay (int num);
 int BlockExperiments  (int16 *OrigBlock, int16 *NewBlock, int control);
-     
-     
+
+
 
 static void
 analyzePattern(const char *  const framePattern,
@@ -226,10 +208,10 @@ analyzePattern(const char *  const framePattern,
     unsigned int i;
 
     /*  Initialize Pattern info */
-    *gop_xP = framePatternLen;    
+    *gop_xP = framePatternLen;
 
     for (i = 0, *gop_iP = 0, *gop_pP = 0, *gop_bP = 0, *errorP = NULL;
-         i < framePatternLen && !*errorP; 
+         i < framePatternLen && !*errorP;
          ++i) {
         switch(framePattern[i]) {
         case 'i': ++*gop_iP; break;
@@ -241,7 +223,7 @@ analyzePattern(const char *  const framePattern,
     }
     assert(*gop_xP == *gop_iP + *gop_pP + *gop_bP);
 }
-  
+
 
 
 /*===========================================================================*
@@ -252,7 +234,7 @@ analyzePattern(const char *  const framePattern,
  *
  * RETURNS:	nothing
  *
- * SIDE EFFECTS:   many global variables 
+ * SIDE EFFECTS:   many global variables
  *
  * NOTES:  Get rid of the redundant pattern stuff!!
  *===========================================================================*/
@@ -266,7 +248,7 @@ initRateControl(bool const wantUnderflowWarning,
     wantVbvOverflowWarning  = wantOverflowWarning;
 
     DBG_PRINT(("Initializing Allocation Data\n"));
-  
+
 #ifdef RC_STATS_FILE
     RC_FILE = fopen("RC_STATS_FILE", "w");
     if ( RC_FILE  == NULL) {
@@ -278,7 +260,7 @@ initRateControl(bool const wantUnderflowWarning,
 #endif
 
     VBV_remainingDelay = 0;
-  
+
     analyzePattern(framePattern, framePatternLen,
                    &GOP_X, &GOP_I, &GOP_P, &GOP_B, &error);
 
@@ -291,46 +273,46 @@ initRateControl(bool const wantUnderflowWarning,
     }
 
 
-    /* Initializing GOP bit allocation */	
+    /* Initializing GOP bit allocation */
     rc_R = 0;
     rc_G = (bit_rate * GOP_X/frameRateRounded);
-  
+
     /*   Initialize the "global complexity measures" */
     Xi = (160 * bit_rate/115);
     Xp = (60 * bit_rate/115);
     Xb = (42 * bit_rate/115);
-  
+
     /*   Initialize MB counters */
     rc_totalMBBits= rc_bitsThisMB= rc_totalFrameBits=rc_totalOverheadBits = 0;
     rc_numBlocks = rc_totalQuant = 0;
-  
+
     /*   init virtual buffers  */
     reactionParameter = (2 * bit_rate / frameRateRounded);
     d0_i = (10 * reactionParameter / 31);
     d0_p = (Kp * d0_i);
     d0_b = (Kb * d0_i);
-  
+
     lastFrameVirtBuf = d0_i;	/*  start with I Frame */
     rc_Q = lastFrameVirtBuf  * 31 / reactionParameter;
-  
+
     /*   init spatial activity measures */
     avg_act = 400;		/* Suggested initial value */
     N_act = 1;
-  
+
     mquant = rc_Q * N_act;
-  
+
     frameDelayIncrement = (90000 / frameRateRounded);
         /* num of "delay" units per frame */
-    bufferFillRate = bit_rate / frameRateRounded; 
+    bufferFillRate = bit_rate / frameRateRounded;
         /* VBV buf fills at constant rate */
     VBV_buffer = buffer_size;
     DBG_PRINT(("VBV- delay: %d, fill rate: %d, delay/Frame: %d units, "
                "buffer size: %d\n",
-               VBV_remainginDelay, bufferFillRate, frameDelayIncrement, 
+               VBV_remainginDelay, bufferFillRate, frameDelayIncrement,
                buffer_size));
-  
+
     result = initGOPRateControl();
-  
+
     return result;
 }
 
@@ -343,21 +325,21 @@ initRateControl(bool const wantUnderflowWarning,
  *
  * RETURNS:	nothing
  *
- * SIDE EFFECTS:   many global variables 
+ * SIDE EFFECTS:   many global variables
  *
  *===========================================================================*/
 int
 initGOPRateControl()
 {
     DBG_PRINT(("Initializing new GOP\n"));
-  
+
     Nx = GOP_X;
     Ni = GOP_I;
     Np = GOP_P;
     Nb = GOP_B;
-  
+
     rc_R += rc_G;
-  
+
     DBG_PRINT(("bufsize: %d, bitrate: %d, pictrate: %d, GOP bits: %d\n",
                buffer_size, bit_rate, frameRateRounded, rc_R));
     DBG_PRINT(("Xi: %d, Xp: %d, Xb: %d Nx: %d, Ni: %d, Np: %d, Nb: %d\n",
@@ -389,20 +371,20 @@ targetRateControl(MpegFrame * const frame) {
     float tempX, tempY, tempZ;
     int result;
     int frameType;
-  
+
     minimumBits = (bit_rate / (8 * frameRateRounded));
-  
+
     /*   Check if new GOP */
     if (Nx == 0) {
         initGOPRateControl();
     }
-  
+
     if (MB_cnt < 0) {MB_cnt = determineMBCount();}
-  
+
     switch (frame->type) {
     case TYPE_IFRAME:
         frameType = 'I';
-    
+
         tempX = ( (Np * Ki * Xp) / (Xi * Kp) );
         tempY = ( (Nb * Ki * Xb) / (Xi*Kb) );
         tempZ = Ni + tempX + tempY;
@@ -411,7 +393,7 @@ targetRateControl(MpegFrame * const frame) {
         current_Tx = Ti = result;
         lastFrameVirtBuf = d0_i;
         break;
-    
+
     case TYPE_PFRAME:
         frameType = 'P';
         tempX =  ( (Ni * Kp * Xi) / (Ki * Xp) );
@@ -422,7 +404,7 @@ targetRateControl(MpegFrame * const frame) {
         current_Tx = Tp = result;
         lastFrameVirtBuf = d0_p;
         break;
-    
+
     case TYPE_BFRAME:
         frameType = 'B';
         tempX =  ( (Ni * Kb * Xi) / (Ki * Xb) );
@@ -433,17 +415,17 @@ targetRateControl(MpegFrame * const frame) {
         current_Tx = Tb = result;
         lastFrameVirtBuf = d0_b;
         break;
-    
+
     default:
         frameType = 'X';
     }
-  
+
     N_act = 1;
     rc_Q = lastFrameVirtBuf  * 31 / reactionParameter;
     mquant = rc_Q * N_act;
     Qscale = (mquant > 31 ? 31 : mquant);
     Qscale = (Qscale < 1 ? 1 : Qscale);
-  
+
 #ifdef HEINOUS_DEBUG_MODE
     {
         const char * strPtr;
@@ -459,15 +441,15 @@ targetRateControl(MpegFrame * const frame) {
     /*   Print Frame info */
     sprintf(rc_buffer, "%4d     %1c  %4d  %6d %7d  "
             "%2d %2d %2d   %2.2f  %6d %4d    %3d",
-            frame->id,frameType,MB_cnt,current_Tx,rc_R,Ni,Np,Nb, 
+            frame->id,frameType,MB_cnt,current_Tx,rc_R,Ni,Np,Nb,
             N_act, lastFrameVirtBuf, rc_Q, Qscale);
-  
+
 #ifdef RC_STATS_FILE
     fprintf(RC_FILE,"%s\n", rc_buffer);
     fflush(RC_FILE);
 #endif
     DBG_PRINT(("%s\n",rc_buffer));
-  
+
     /*  Print headers for Macroblock info */
     if (RC_MB_SAMPLE_RATE) {
 #ifdef HEINOUS_DEBUG_MODE
@@ -483,7 +465,7 @@ targetRateControl(MpegFrame * const frame) {
 
 
 
-static void 
+static void
 updateVBVBuffer(int const frameBits) {
 /*----------------------------------------------------------------------------
   Update the VBV buffer after each frame.  This theoretical buffer is
@@ -532,11 +514,11 @@ updateRateControl(int const type) {
     pctAllocUsed = (totalBits *100 / current_Tx);
     rc_R -= totalBits;
     pctGOPUsed = (rc_R *100/ rc_G);
-  
+
     avg_act = (total_act_j / MB_cnt);
-  
+
     updateVBVBuffer(totalBits);
-  
+
     switch (type) {
     case TYPE_IFRAME:
         Ti = current_Tx;
@@ -563,9 +545,9 @@ updateRateControl(int const type) {
         Xb = frameComplexity;
         break;
     }
-  
+
 #ifdef HEINOUS_DEBUG_MODE
-    {  
+    {
         /*  Print Frame info */
         const char * strPtr;
         strPtr = Frame_trailer1;
@@ -575,26 +557,26 @@ updateRateControl(int const type) {
         strPtr = Frame_trailer3;
         DBG_PRINT(("%s\n",strPtr));
     }
-#endif  
+#endif
     sprintf(rc_buffer, "%6d  %2.2f  %6d  %3d  %2.2f %7d   "
             "%3d %7d   %3d  %6d %6d",
-            totalBits, avgQuant, frameComplexity, avg_act, N_act, 
-            currentVirtBuf, pctAllocUsed, rc_R, pctGOPUsed, 
+            totalBits, avgQuant, frameComplexity, avg_act, N_act,
+            currentVirtBuf, pctAllocUsed, rc_R, pctGOPUsed,
             VBV_buffer, VBV_remainingDelay);
 #ifdef RC_STATS_FILE
     fprintf(RC_FILE,"%s\n", rc_buffer);
     fflush(RC_FILE);
 #endif
     DBG_PRINT(("%s\n",rc_buffer));
-  
+
     Nx--;
     rc_totalMBBits= rc_bitsThisMB= rc_totalFrameBits=rc_totalOverheadBits = 0;
     rc_numBlocks = rc_totalQuant = total_act_j = currentVirtBuf = 0;
-  
+
     DBG_PRINT(("GOP now has %d bits remaining (%3d%%) for %d frames .. , "
-               "Ni= %d, Np= %d, Nb= %d\n", 
+               "Ni= %d, Np= %d, Nb= %d\n",
                rc_R, (rc_R*100/rc_G), (Ni+Np+Nb), Ni, Np, Nb));
-  
+
 }
 
 
@@ -622,21 +604,21 @@ int type;
   int pctUsed, pctDone;
   int bitsThisMB;
   int bitsPerMB;
-  
+
   bitsThisMB = rc_bitsThisMB;
   totalBits = rc_totalFrameBits;
-  bitsPerMB = (totalBits / rc_numBlocks); 
-  pctDone = (rc_numBlocks * 100/ MB_cnt); 
+  bitsPerMB = (totalBits / rc_numBlocks);
+  pctDone = (rc_numBlocks * 100/ MB_cnt);
   pctUsed = (totalBits *100/current_Tx);
-  
+
   sprintf(rc_buffer, "%3d  %5d %2d %3d %6d  %3d %6d   %2.2f   %6d %4d    %3d   %3d\n",
-	  (rc_numBlocks - 1), bitsThisMB, Qscale, mquant, currentVirtBuf, 
+	  (rc_numBlocks - 1), bitsThisMB, Qscale, mquant, currentVirtBuf,
 	  rc_Q, act_j, N_act, totalBits, bitsPerMB, pctUsed, pctDone);
 #ifdef RC_STATS_FILE
   fprintf(RC_FILE, "%s", rc_buffer);
   fflush(RC_FILE);
 #endif
-  
+
   if ( (RC_MB_SAMPLE_RATE) && ((rc_numBlocks -1) % RC_MB_SAMPLE_RATE)) {
     DBG_PRINT(("%s\n", rc_buffer));
   } else {
@@ -695,7 +677,7 @@ void incMacroBlockBits(num)
  *
  * RETURNS:     new Qscale
  *
- * SIDE EFFECTS:   
+ * SIDE EFFECTS:
  *
  *===========================================================================*/
 int needQScaleChange(oldQScale, blk0, blk1, blk2, blk3)
@@ -705,19 +687,19 @@ int needQScaleChange(oldQScale, blk0, blk1, blk2, blk3)
      Block blk2;
      Block blk3;
 {
-  
+
   /*   One more MacroBlock seen */
   rc_numBlocks++;		/* this notes each block num in MB */
-  
+
   checkBufferFullness(oldQScale);
-  
+
   checkSpatialActivity(blk0, blk1, blk2, blk3);
-  
+
   mquant = rc_Q * N_act;
   Qscale = (mquant > 31 ? 31 : mquant);
   Qscale = (Qscale < 1 ? 1 : Qscale);
   rc_totalQuant += Qscale;
-  
+
   if (oldQScale == Qscale)
     return -1;
   else
@@ -727,7 +709,7 @@ int needQScaleChange(oldQScale, blk0, blk1, blk2, blk3)
 
 /*===========================================================================*
  *
- * determineMBCount() 
+ * determineMBCount()
  *
  *      Determines number of Macro Blocks in frame from the frame sizes
  *	passed.
@@ -741,7 +723,7 @@ int
   determineMBCount ()
 {
   int y,x;
-  
+
   x = (Fsize_x +15)/16;
   y = (Fsize_y +15)/16;
   return  (x * y);
@@ -769,11 +751,11 @@ void checkBufferFullness (oldQScale)
      int oldQScale;
 {
   int temp;
-  
+
   temp = lastFrameVirtBuf + rc_totalFrameBits;
   temp -=  (current_Tx * rc_numBlocks / MB_cnt);
   currentVirtBuf = temp;
-  
+
   rc_Q = (currentVirtBuf * 31 / reactionParameter);
   return;
 }
@@ -783,8 +765,8 @@ void checkBufferFullness (oldQScale)
  *
  * void checkSpatialActivity()
  *
- *      Calcualtes the spatial activity for the four luminance blocks of the
- *	macroblock.  Along with the normalized reference quantization parameter 
+ *      Calculates the spatial activity for the four luminance blocks of the
+ *	macroblock.  Along with the normalized reference quantization parameter
  *  (rc_Q) , it determines the quantization factor for the next macroblock.
  *
  * RETURNS:     nothing
@@ -801,19 +783,19 @@ void checkSpatialActivity(blk0, blk1, blk2, blk3)
      Block blk3;
 {
   int temp;
-  int16 *blkArray[4]; 
+  int16 *blkArray[4];
   int16 *curBlock;
   int16 *blk_ptr;
   int var[4];
   int i, j;
-  
-  
+
+
   blkArray[0] = (int16 *) blk0;
   blkArray[1] = (int16 *) blk1;
   blkArray[2] = (int16 *) blk2;
   blkArray[3] = (int16 *) blk3;
-  
-  
+
+
   for (i =0; i < 4; i++) {	/* Compute the activity in each block */
     curBlock = blkArray[i];
     blk_ptr = curBlock;
@@ -821,14 +803,14 @@ void checkSpatialActivity(blk0, blk1, blk2, blk3)
     /*  Find the mean pixel value */
     for (j=0; j < DCTSIZE_SQ; j ++) {
       P_mean += *(blk_ptr++);
-      /*			P_mean += curBlock[j]; 
+      /*			P_mean += curBlock[j];
 				if (curBlock[j] != *(blk_ptr++)) {
 				printf("ARRAY ERROR: block %d\n", j);
 				}
 				*/
     }
     P_mean /= DCTSIZE_SQ;
-    
+
     /*  Now find the variance  */
     curBlock = blkArray[i];
     blk_ptr = curBlock;
@@ -839,25 +821,25 @@ void checkSpatialActivity(blk0, blk1, blk2, blk3)
 	printf("ARRAY ERROR: block %d\n", j);
       }
       temp = curBlock[j] - P_mean;
-#endif      
+#endif
       temp = *(blk_ptr++) - P_mean;
       var[i] += (temp * temp);
     }
     var[i] /= DCTSIZE_SQ;
   }
-  
+
   /*  Choose the minimum variance from the 4 blocks and use as the activity */
   var_sblk  = var[0];
   for (i=1; i < 4; i++) {
     var_sblk = (var_sblk < var[i] ? var_sblk : var[i]);
   }
-  
-  
+
+
   act_j = 1 + var_sblk;
   total_act_j += act_j;
   temp = (2 * act_j + avg_act);
   N_act = ( (float) temp / (float) (act_j + 2*avg_act) );
-  
+
   return;
 }
 
@@ -900,7 +882,7 @@ int getRateMode()
 void setBitRate (const char * const charPtr)
 {
   int rate, rnd;
-  
+
   rate = atoi(charPtr);
   if (rate > 0) {
     RateControlMode = FIXED_RATE;
@@ -915,7 +897,7 @@ void setBitRate (const char * const charPtr)
   rate = (rate > MAX_BIT_RATE ? MAX_BIT_RATE : rate);
   bit_rate = rate;
   DBG_PRINT(("Bit rate is: %d\n", bit_rate));
-} 
+}
 
 
 
@@ -957,7 +939,7 @@ int getBitRate ()
 void setBufferSize (const char * const charPtr)
 {
   int size;
-  
+
   size = atoi(charPtr);
   size = (size > MAX_BUFFER_SIZE ? MAX_BUFFER_SIZE : size);
   if (size > 0) {
diff --git a/converter/ppm/ppmtompeg/readframe.c b/converter/ppm/ppmtompeg/readframe.c
index 2a359b2f..dcc02052 100644
--- a/converter/ppm/ppmtompeg/readframe.c
+++ b/converter/ppm/ppmtompeg/readframe.c
@@ -1,13 +1,13 @@
 /*===========================================================================*
- * readframe.c                    
- *                                
- *  procedures to read in frames  
- *                                
- * EXPORTED PROCEDURES:           
- *  ReadFrame                     
- *  SetFileType                   
- *  SetFileFormat                 
- *                                
+ * readframe.c
+ *
+ *  procedures to read in frames
+ *
+ * EXPORTED PROCEDURES:
+ *  ReadFrame
+ *  SetFileType
+ *  SetFileFormat
+ *
  *===========================================================================*/
 
 /* COPYRIGHT INFORMATION IS AT THE END OF THIS FILE */
@@ -62,7 +62,7 @@ struct YuvLine {
 #ifdef __OS2__
   #define popen _popen
 #endif
-   
+
 
 /*==================*
  * Global VARIABLES *
@@ -100,7 +100,7 @@ static void DoKillDim (MpegFrame *mf, int w, int h);
 
 
 
-void    
+void
 SetResize(bool const set) {
     resizeFrame = set;
 }
@@ -134,7 +134,7 @@ ReadPNM(MpegFrame * const mpegFrameP,
 static void
 openFile(struct inputSource * const inputSourceP,
          unsigned int         const frameNumber,
-         const char *         const conversion, 
+         const char *         const conversion,
          FILE **              const ifPP) {
 
     if (inputSourceP->stdinUsed) {
@@ -145,24 +145,24 @@ openFile(struct inputSource * const inputSourceP,
                 "INPUT_CONVERTER * in the parameter file or supply the "
                 "frames in files by specifying a directory with "
                 "INPUT_DIRECTORY in the parameter file.");
-        
+
         *ifPP = stdin;
     } else {
         const char * fileName;
         const char * fullFileName;
-        
+
         GetNthInputFileName(inputSourceP, frameNumber, &fileName);
-        
+
         pm_asprintf(&fullFileName, "%s/%s", currentPath, fileName);
-        
+
         CurrFile = fullFileName;
-        
+
         if (fileType == ANY_FILE_TYPE) {
             char command[1024];
             const char * convertPtr;
             char * commandPtr;
             const char * charPtr;
-            
+
             /* replace every occurrence of '*' with fullFileName */
             convertPtr = conversion;
             commandPtr = command;
@@ -172,7 +172,7 @@ openFile(struct inputSource * const inputSourceP,
                     ++commandPtr;
                     ++convertPtr;
                 }
-                
+
                 if (*convertPtr == '*') {
                     /* copy fullFileName */
                     charPtr = fullFileName;
@@ -185,7 +185,7 @@ openFile(struct inputSource * const inputSourceP,
                 }
             }
             *commandPtr = '\0';
-            
+
             *ifPP = popen(command, "r");
             if (*ifPP == NULL) {
                 pm_message(
@@ -201,7 +201,7 @@ openFile(struct inputSource * const inputSourceP,
             *ifPP = fopen(fullFileName, "rb");
             if (*ifPP == NULL)
                 pm_error("Couldn't open input file '%s'", fullFileName);
-            
+
             if (baseFormat == JMOVIE_FILE_TYPE)
                 unlink(fullFileName);
         }
@@ -238,7 +238,7 @@ fileIsAtEnd(FILE * const ifP) {
 
     c = getc(ifP);
     if (c == EOF) {
-        if (feof(ifP)) 
+        if (feof(ifP))
             eof = TRUE;
         else
             pm_error("File error on getc() to position to image");
@@ -248,7 +248,7 @@ fileIsAtEnd(FILE * const ifP) {
         eof = FALSE;
 
         rc = ungetc(c, ifP);
-        if (rc == EOF) 
+        if (rc == EOF)
             pm_error("File error doing ungetc() to position to image.");
     }
     return eof;
@@ -262,14 +262,11 @@ ReadFrameFile(MpegFrame *  const frameP,
               const char * const conversion,
               bool *       const eofP) {
 /*----------------------------------------------------------------------------
-   Read a frame from the file 'ifP'.
+   Read a frame from the file 'ifP', doing adjustments as indicated.
 
    Return *eofP == TRUE iff we encounter EOF before we can get the
    frame.
 -----------------------------------------------------------------------------*/
-    MpegFrame   tempFrame;
-    MpegFrame * framePtr;
-
     /* To make this code fit Netpbm properly, we should remove handling
        of all types except PNM and use pm_nextimage() to handle sensing
        of end of stream.
@@ -278,53 +275,59 @@ ReadFrameFile(MpegFrame *  const frameP,
     if (fileIsAtEnd(ifP))
         *eofP = TRUE;
     else {
+        MpegFrame   preResizeFrame;
+            /* The frame object that holds the frame before resizing */
+        MpegFrame * rawFrameP;
+            /* The frame object with which we read in the raw frame */
+
         *eofP = FALSE;
 
         if (resizeFrame) {
-            tempFrame.inUse = FALSE;
-            tempFrame.orig_y = NULL;
-            tempFrame.y_blocks = NULL;
-            tempFrame.decoded_y = NULL;
-            tempFrame.halfX = NULL;
-            framePtr = &tempFrame;
+            preResizeFrame.inUse = FALSE;
+            preResizeFrame.orig_y = NULL;
+            preResizeFrame.y_blocks = NULL;
+            preResizeFrame.decoded_y = NULL;
+            preResizeFrame.halfX = NULL;
+            rawFrameP = &preResizeFrame;
         } else
-            framePtr = frameP;
+            rawFrameP = frameP;
 
         switch(baseFormat) {
         case YUV_FILE_TYPE:
 
             /* Encoder YUV */
             if ((strncmp (yuvConversion, "EYUV", 4) == 0) ||
-                (strncmp (yuvConversion, "UCB", 3) == 0)) 
+                (strncmp (yuvConversion, "UCB", 3) == 0))
 
-                ReadEYUV(framePtr, ifP, realWidth, realHeight);
+                ReadEYUV(rawFrameP, ifP, realWidth, realHeight);
 
             else
                 /* Abekas-type (interlaced) YUV */
-                ReadAYUV(framePtr, ifP, realWidth, realHeight);
+                ReadAYUV(rawFrameP, ifP, realWidth, realHeight);
 
             break;
         case Y_FILE_TYPE:
-            ReadY(framePtr, ifP, realWidth, realHeight);
+            ReadY(rawFrameP, ifP, realWidth, realHeight);
             break;
         case PNM_FILE_TYPE:
-            ReadPNM(framePtr, ifP);
+            ReadPNM(rawFrameP, ifP);
             break;
         case SUB4_FILE_TYPE:
-            ReadSub4(framePtr, ifP, yuvWidth, yuvHeight);
+            ReadSub4(rawFrameP, ifP, yuvWidth, yuvHeight);
             break;
         case JPEG_FILE_TYPE:
         case JMOVIE_FILE_TYPE:
-            ReadJPEG(framePtr, ifP);
+            ReadJPEG(rawFrameP, ifP);
             break;
         default:
             break;
         }
 
-        if (resizeFrame)
-            Frame_Resize(frameP, &tempFrame, Fsize_x, Fsize_y, 
+        if (resizeFrame) {
+            assert(rawFrameP == &preResizeFrame);
+            Frame_Resize(frameP, &preResizeFrame, Fsize_x, Fsize_y,
                          outputWidth, outputHeight);
-    
+        }
         if (GammaCorrection)
             DoGamma(frameP, Fsize_x, Fsize_y);
 
@@ -338,7 +341,7 @@ ReadFrameFile(MpegFrame *  const frameP,
 
 
 void
-ReadFrame(MpegFrame *          const frameP, 
+ReadFrame(MpegFrame *          const frameP,
           struct inputSource * const inputSourceP,
           unsigned int         const frameNumber,
           const char *         const conversion,
@@ -693,7 +696,7 @@ SeparateLine(fpointer, lineptr, width)
         fprintf(stderr, "       or any even-length string consisting of the letters U, V, and Y.\n");
             exit(1);
         }
-    
+
     }
 
 }
@@ -738,7 +741,7 @@ ReadY(mf, fpointer, width, height)
     for (y = Fsize_y; y < height; y++) {
     safe_fread(junk, 1, width, fpointer);
     }
-    
+
     for (y = 0 ; y < (Fsize_y >> 1); y++) {
       memset(mf->orig_cb[y], 128, (Fsize_x>>1));
       memset(mf->orig_cr[y], 128, (Fsize_x>>1));
@@ -830,7 +833,7 @@ int w,h;
   int i,j;
 
   if (!init_done) {
-    for(i=0; i<256; i++) 
+    for(i=0; i<256; i++)
       GammaVal[i]=(unsigned char) (pow(((double) i)/255.0,GammaValue)*255.0+0.5);
     init_done=TRUE;
   }
@@ -871,7 +874,7 @@ int w,h;
                         ^ kill_dim_break
                              ^kill_dim_end
               kill_dim_slope gives the slope (y = kill_dim_slope * x +0)
-              from 0 to kill_dim_break                      
+              from 0 to kill_dim_break
  *
  *===========================================================================*/
 
@@ -930,7 +933,7 @@ int w,h;
  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  */
 
-/*  
+/*
  *  $Header: /n/picasso/project/mpeg/mpeg_dist/mpeg_encode/RCS/readframe.c,v 1.27 1995/08/14 22:31:40 smoot Exp $
  *  $Log: readframe.c,v $
  *  Revision 1.27  1995/08/14 22:31:40  smoot
diff --git a/converter/ppm/ppmtompeg/specifics.c b/converter/ppm/ppmtompeg/specifics.c
index a8a48af3..bd74e805 100644
--- a/converter/ppm/ppmtompeg/specifics.c
+++ b/converter/ppm/ppmtompeg/specifics.c
@@ -41,6 +41,7 @@
 
 #include "netpbm/mallocvar.h"
 #include "netpbm/nstring.h"
+#include "netpbm/pm_system.h"
 
 #include "all.h"
 #include "mtypes.h"
@@ -67,7 +68,7 @@ void Parse_Specifics_File_v1 (FILE *fp);
 void Parse_Specifics_File_v2 (FILE *fp);
 FrameSpecList *MakeFslEntry (void);
 void AddSlc (FrameSpecList *c,int snum, int qs);
-Block_Specifics *AddBs (FrameSpecList *c,int bnum, 
+Block_Specifics *AddBs (FrameSpecList *c,int bnum,
 				    boolean rel, int qs);
 FrameSpecList *MakeFslEntry (void);
 #define my_upper(c) (((c>='a') && (c<='z')) ? (c-'a'+'A') : c)
@@ -144,7 +145,7 @@ static char version = -1;
  *   Cpp's and reads in the specifics file.  Creates fsl data structure.
  *
  *   Returns: nothing
- * 
+ *
  *   Modifies: fsl, file specificsFile".cpp"
  *
  *================================================================
@@ -152,38 +153,37 @@ static char version = -1;
 void
 Specifics_Init() {
 
-    FILE *specificsFP;
-  
-    {
-        const char * command;
-        pm_asprintf(&command, "rm -f %s.cpp", specificsFile);
-        system(command);
-        pm_strfree(command);
-    }
+    /* 'specificsFile' is a global variable whose value is the name of the
+       specifics file, given by the parameter file.
+    */
+
+    FILE *       specificsFP;
+    const char * preprocessedFileNm;
+
+    pm_message("Specifics file: %s", specificsFile);
+
+    pm_asprintf(&preprocessedFileNm, "%s.cpp", specificsFile);
+
+    pm_system_lp("rm", NULL, NULL, NULL, NULL, "-f", preprocessedFileNm);
+
     {
         const char * command;
-        pm_asprintf(&command, "cpp -P %s %s %s.cpp",
-                    specificsDefines, specificsFile, specificsFile);
-        system(command);
+        pm_asprintf(&command, "cpp -P %s '%s' -o '%s'",
+                    specificsDefines, specificsFile, preprocessedFileNm);
+        pm_system(NULL, NULL, NULL, NULL, command);
         pm_strfree(command);
     }
-    strcat(specificsFile, ".cpp");
-    if ((specificsFP = fopen(specificsFile, "r")) == NULL) {
-        fprintf(stderr, "Error with specifics file, cannot open %s\n",
-                specificsFile);
-        exit(1);
-    }
-    printf("Specifics file: %s\n", specificsFile);
+
+    specificsFP = pm_openr(preprocessedFileNm);
+
+    pm_system_lp("rm", NULL, NULL, NULL, NULL, "-f", preprocessedFileNm);
 
     Parse_Specifics_File(specificsFP);
-    {
-        const char * command;
-        pm_asprintf(&command, "rm -f %s.cpp", specificsFile);
-        system(command);
-        pm_strfree(command);
-    }
-}
 
+    pm_close(specificsFP);
+
+    pm_strfree(preprocessedFileNm);
+}
 
 
 
@@ -244,7 +244,7 @@ FILE *fp;
       fprintf(stderr, "Specifics file: What? *%s*\n", line);
       break;
     }}
-  
+
 }
 
 /* Version 1 */
@@ -253,7 +253,7 @@ FILE *fp;
 {
   char line[1024],*lp;
   FrameSpecList *current, *new;
-  char typ; 
+  char typ;
   int fnum,snum, bnum, qs, newqs;
 
   fsl = MakeFslEntry();
@@ -301,7 +301,7 @@ FILE *fp;
       fprintf(stderr," What? *%s*\n", line);
       break;
     }}
-  
+
 }
 
 
@@ -382,7 +382,7 @@ Parse_Specifics_File_v2(FILE * const fP) {
                 } else {
                     numScanned =
                         2 + sscanf(lp, "%s %d %d %d %d",
-                                   kind, &fx, &fy, &sx, &sy); 
+                                   kind, &fx, &fy, &sx, &sy);
                 }
 
                 qs = newqs;
@@ -573,7 +573,7 @@ int start_qs;
   FrameSpecList *tmp;
   boolean found_it;
   static int leftovers = 0;  /* Used in case of forced movement into 1..31 range */
-  
+
   *info = (BlockMV * )NULL;
   if (last == (FrameSpecList *) NULL){
     /* No cache, try to find number fn */
@@ -590,7 +590,7 @@ int start_qs;
   } else {
     if (last->framenum != fn) { /* cache miss! */
       /* first check if it is next */
-      if ((last->next != (FrameSpecList *) NULL) && 
+      if ((last->next != (FrameSpecList *) NULL) &&
 	  (last->next->framenum == fn)) {
 	last = last->next;
       } else {
@@ -617,13 +617,13 @@ int start_qs;
     fprintf(stderr, "PROGRAMMER ERROR: last has wrong number!\n");
     return -1; /* no data on it */
   }
-  
+
   switch(typ) {
   case 0: /* Frame: num is ignored */
     leftovers = 0;
 #ifdef BLEAH
     printf("QSchange frame %d to %d\n", fn, last->qscale);
-#endif 
+#endif
     return last->qscale;
     break;
 
@@ -683,8 +683,8 @@ int start_qs;
   /* no luck */
   return -1;
 }
-     
-    
+
+
 /*================================================================
  *
  *  SpecTypeLookup
diff --git a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c
index fa68edc5..5b7e1003 100644
--- a/converter/ppm/ppmtopcx.c
+++ b/converter/ppm/ppmtopcx.c
@@ -12,7 +12,7 @@
 **
 ** 11/Dec/94: first version
 ** 12/Dec/94: added handling of "packed" format (16 colors or less)
-** 
+**
 ** ZSoft PCX File Format Technical Reference Manual
 ** http://bespin.org/~qz/pc-gpe/pcx.txt
 ** http://web.archive.org/web/20100206055706/http://www.qzx.com/pc-gpe/pcx.txt
@@ -31,13 +31,13 @@
 #define PCX_MAXVAL      (pixval)255
 
 
-struct cmdlineInfo {
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    const char *inputFilespec;  /* '-' if stdin */
+    const char * inputFilespec;  /* '-' if stdin */
     unsigned int truecolor;   /* -24bit option */
-    unsigned int use_8_bit; /* -8bit option */
+    unsigned int use8Bit; /* -8bit option */
     unsigned int planes;    /* zero means minimum */
     unsigned int packed;
     unsigned int verbose;
@@ -49,16 +49,16 @@ struct cmdlineInfo {
 
 
 
-struct pcxCmapEntry {
+struct PcxCmapEntry {
     unsigned char r;
     unsigned char g;
     unsigned char b;
 };
 
-static struct pcxCmapEntry
+static struct PcxCmapEntry
 pcxCmapEntryFromPixel(pixel const colorPixel) {
 
-    struct pcxCmapEntry retval;
+    struct PcxCmapEntry retval;
 
     retval.r = PPM_GETR(colorPixel);
     retval.g = PPM_GETG(colorPixel);
@@ -70,11 +70,11 @@ pcxCmapEntryFromPixel(pixel const colorPixel) {
 
 
 static void
-parseCommandLine(int argc, char ** argv,
-                 struct cmdlineInfo * const cmdlineP) {
+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.
@@ -82,7 +82,7 @@ parseCommandLine(int argc, char ** argv,
    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;
+    optEntry * option_def;
         /* Instructions to pm_optParseOptions3 on how to parse our options.
          */
     optStruct3 opt;
@@ -94,15 +94,15 @@ parseCommandLine(int argc, char ** argv,
     MALLOCARRAY(option_def, 100);
 
     option_def_index = 0;   /* incremented by OPTENT3 */
-    OPTENT3(0, "24bit",     OPT_FLAG,   NULL,                  
+    OPTENT3(0, "24bit",     OPT_FLAG,   NULL,
             &cmdlineP->truecolor,    0);
-    OPTENT3(0, "8bit",      OPT_FLAG,   NULL,    
-            &cmdlineP->use_8_bit,    0);
-    OPTENT3(0, "planes",    OPT_UINT,   &cmdlineP->planes, 
+    OPTENT3(0, "8bit",      OPT_FLAG,   NULL,
+            &cmdlineP->use8Bit,    0);
+    OPTENT3(0, "planes",    OPT_UINT,   &cmdlineP->planes,
             &planesSpec,             0);
-    OPTENT3(0, "packed",    OPT_FLAG,   NULL,                  
+    OPTENT3(0, "packed",    OPT_FLAG,   NULL,
             &cmdlineP->packed,       0);
-    OPTENT3(0, "verbose",   OPT_FLAG,   NULL,                  
+    OPTENT3(0, "verbose",   OPT_FLAG,   NULL,
             &cmdlineP->verbose,      0);
     OPTENT3(0, "stdpalette", OPT_FLAG,  NULL,
             &cmdlineP->stdpalette,   0);
@@ -115,7 +115,7 @@ parseCommandLine(int argc, char ** argv,
     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, argv, opt, sizeof(opt), 0 );
+    pm_optParseOptions3( &argc, (char **)argv, opt, sizeof(opt), 0 );
         /* Uses and sets argc, argv, and some of *cmdline_p and others. */
 
     if (!xposSpec)
@@ -141,17 +141,17 @@ parseCommandLine(int argc, char ** argv,
             pm_error("-planes is meaningless with -packed.");
         if (cmdlineP->truecolor)
             pm_error("-planes is meaningless with -24bit");
-        if (cmdlineP->use_8_bit)
+        if (cmdlineP->use8Bit)
             pm_error("-planes is meaningless with -8bit");
     }
-    
+
     if (paletteSpec && cmdlineP->stdpalette)
         pm_error("You can't specify both -palette and -stdpalette");
 
     if (!paletteSpec)
         cmdlineP->palette = NULL;
 
-    if (cmdlineP->use_8_bit && cmdlineP->truecolor) 
+    if (cmdlineP->use8Bit && cmdlineP->truecolor)
         pm_error("You cannot specify both -8bit and -truecolor");
 
     if (argc-1 < 1)
@@ -172,11 +172,11 @@ parseCommandLine(int argc, char ** argv,
  * Write out a two-byte little-endian word to the PCX file
  */
 static void
-Putword(int    const w, 
-        FILE * const fp) {
+putword(unsigned int const w,
+        FILE *       const fp) {
 
     int rc;
-    
+
     rc = pm_writelittleshort(fp, w);
 
     if (rc != 0)
@@ -189,26 +189,24 @@ Putword(int    const w,
  * Write out a byte to the PCX file
  */
 static void
-Putbyte(int    const b, 
-        FILE * const fp) {
+putbyte(unsigned int const b,
+        FILE *       const ofP) {
 
     int rc;
 
-    rc = fputc(b & 0xff, fp);
+    rc = fputc(b & 0xff, ofP);
+
     if (rc == EOF)
         pm_error("Error writing byte to output file.");
 }
 
 
 
-static const unsigned char bitmask[] = {1, 2, 4, 8, 16, 32, 64, 128};
-
-
 static void
-extractPlane(unsigned char * const rawrow, 
-             int             const cols, 
-             unsigned char * const buf, 
-             int             const plane) {
+extractPlane(unsigned char * const rawrow,
+             unsigned int    const cols,
+             unsigned char * const buf,
+             unsigned int    const plane) {
 /*----------------------------------------------------------------------------
    From the image row 'rawrow', which is an array of 'cols' palette indices
    (as unsigned 8 bit integers), extract plane number 'plane' and return
@@ -223,12 +221,10 @@ extractPlane(unsigned char * const rawrow,
     int cbit;  /* Significance of bit representing current column in output */
     unsigned char *cp;  /* Ptr to next output byte to fill */
     unsigned char byteUnderConstruction;
-    
+
     cp = buf;  /* initial value */
 
-    cbit = 7;
-    byteUnderConstruction = 0x00;
-    for (col = 0; col < cols; ++col) {
+    for (col = 0, cbit = 7, byteUnderConstruction = 0x00; col < cols; ++col) {
         if (rawrow[col] & planeMask)
             byteUnderConstruction |= (1 << cbit);
 
@@ -250,14 +246,17 @@ extractPlane(unsigned char * const rawrow,
 
 
 static void
-PackBits(unsigned char * const rawrow, 
-         int             const width, 
-         unsigned char * const buf, 
-         int             const bits) {
+packBits(unsigned char * const rawrow,
+         unsigned int    const width,
+         unsigned char * const buf,
+         unsigned int    const bits) {
 
-    int x, i, shift;
+    unsigned int x;
+    int i;
+    int shift;
 
-    shift = i = -1;
+    shift = -1;
+    i = -1;
 
     for (x = 0; x < width; ++x) {
         if (shift < 0) {
@@ -273,71 +272,73 @@ PackBits(unsigned char * const rawrow,
 
 
 static void
-write_header(FILE *              const fp, 
-             int                 const cols, 
-             int                 const rows, 
-             int                 const BitsPerPixel, 
-             int                 const Planes, 
-             struct pcxCmapEntry const cmap16[],
-             unsigned int        const xPos, 
-             unsigned int        const yPos) {
-
-    int i, BytesPerLine;
-
-    Putbyte(PCX_MAGIC, fp);        /* .PCX magic number            */
-    Putbyte(0x05, fp);             /* PC Paintbrush version        */
-    Putbyte(0x01, fp);             /* .PCX run length encoding     */
-    Putbyte(BitsPerPixel, fp);     /* bits per pixel               */
-    
-    Putword(xPos, fp);             /* x1   - image left            */
-    Putword(yPos, fp);             /* y1   - image top             */
-    Putword(xPos+cols-1, fp);      /* x2   - image right           */
-    Putword(yPos+rows-1, fp);      /* y2   - image bottom          */
-
-    Putword(cols, fp);             /* horizontal resolution        */
-    Putword(rows, fp);             /* vertical resolution          */
+writeHeader(FILE *              const ofP,
+            unsigned int        const cols,
+            unsigned int        const rows,
+            unsigned int        const bitsPerPixel,
+            unsigned int        const planes,
+            struct PcxCmapEntry const cmap16[],
+            unsigned int        const xPos,
+            unsigned int        const yPos) {
+
+    unsigned int bytesPerLine;
+
+    putbyte(PCX_MAGIC, ofP);        /* .PCX magic number            */
+    putbyte(0x05, ofP);             /* PC Paintbrush version        */
+    putbyte(0x01, ofP);             /* .PCX run length encoding     */
+    putbyte(bitsPerPixel, ofP);     /* bits per pixel               */
+
+    putword(xPos, ofP);             /* x1   - image left            */
+    putword(yPos, ofP);             /* y1   - image top             */
+    putword(xPos+cols-1, ofP);      /* x2   - image right           */
+    putword(yPos+rows-1, ofP);      /* y2   - image bottom          */
+
+    putword(cols, ofP);             /* horizontal resolution        */
+    putword(rows, ofP);             /* vertical resolution          */
 
     /* Write out the Color Map for images with 16 colors or less */
-    if (cmap16)
+    if (cmap16) {
+        unsigned int i;
         for (i = 0; i < 16; ++i) {
-            Putbyte(cmap16[i].r, fp);
-            Putbyte(cmap16[i].g, fp);
-            Putbyte(cmap16[i].b, fp);
+            putbyte(cmap16[i].r, ofP);
+            putbyte(cmap16[i].g, ofP);
+            putbyte(cmap16[i].b, ofP);
         }
-    else {
+    } else {
         unsigned int i;
         for (i = 0; i < 16; ++i) {
-            Putbyte(0, fp);
-            Putbyte(0, fp);
-            Putbyte(0, fp);
+            putbyte(0, ofP);
+            putbyte(0, ofP);
+            putbyte(0, ofP);
         }
     }
-    Putbyte(0, fp);                /* reserved byte                */
-    Putbyte(Planes, fp);           /* number of color planes       */
+    putbyte(0, ofP);                /* reserved byte                */
+    putbyte(planes, ofP);           /* number of color planes       */
 
-    BytesPerLine = ((cols * BitsPerPixel) + 7) / 8;
-    Putword(BytesPerLine, fp);    /* number of bytes per scanline */
+    bytesPerLine = ((cols * bitsPerPixel) + 7) / 8;
+    putword(bytesPerLine, ofP);    /* number of bytes per scanline */
 
-    Putword(1, fp);                /* palette info                 */
+    putword(1, ofP);                /* palette info                 */
 
     {
         unsigned int i;
         for (i = 0; i < 58; ++i)        /* fill to end of header        */
-            Putbyte(0, fp);
+            putbyte(0, ofP);
     }
 }
 
 
 
 static void
-PCXEncode(FILE *                const fp, 
-          const unsigned char * const buf, 
-          int                   const Size) {
+pcxEncode(FILE *                const ofP,
+          const unsigned char * const buf,
+          unsigned int          const size) {
 
-    const unsigned char * const end = buf + Size;
+    const unsigned char * const end = buf + size;
 
     const unsigned char * currentP;
-    int previous, count;
+    unsigned int          previous;
+    unsigned int          count;
 
     currentP = buf;
     previous = *currentP++;
@@ -350,19 +351,19 @@ PCXEncode(FILE *                const fp,
         else {
             if (count > 1 || (previous & 0xc0) == 0xc0) {
                 count |= 0xc0;
-                Putbyte ( count , fp );
+                putbyte ( count , ofP );
             }
-            Putbyte(previous, fp);
+            putbyte(previous, ofP);
             previous = c;
-            count   = 1;
+            count = 1;
         }
     }
 
     if (count > 1 || (previous & 0xc0) == 0xc0) {
         count |= 0xc0;
-        Putbyte ( count , fp );
+        putbyte(count, ofP);
     }
-    Putbyte(previous, fp);
+    putbyte(previous, ofP);
 }
 
 
@@ -377,10 +378,10 @@ indexOfColor(colorhash_table const cht,
 -----------------------------------------------------------------------------*/
 
     int const rc = ppm_lookupcolor(cht, &color);
-            
+
     if (rc < 0)
         pm_error("Image contains color which is not "
-                 "in the palette: %u/%u/%u", 
+                 "in the palette: %u/%u/%u",
                  PPM_GETR(color), PPM_GETG(color), PPM_GETB(color));
 
     return rc;
@@ -389,61 +390,46 @@ indexOfColor(colorhash_table const cht,
 
 
 static void
-ppmTo16ColorPcx(pixel **            const pixels, 
-                int                 const cols, 
-                int                 const rows, 
-                struct pcxCmapEntry const pcxcmap[], 
-                int                 const colors, 
-                colorhash_table     const cht, 
-                bool                const packbits,
-                unsigned int        const planesRequested,
-                unsigned int        const xPos,
-                unsigned int        const yPos) {
+writeRaster16Color(FILE * const ofP,
+                   pixel **            const pixels,
+                   unsigned int        const cols,
+                   unsigned int        const rows,
+                   unsigned int        const planes,
+                   colorhash_table     const cht,
+                   bool                const packbits,
+                   unsigned int        const bitsPerPixel) {
+
+    unsigned int const bytesPerLine = ((cols * bitsPerPixel) + 7) / 8;
+
+    unsigned char * indexRow;  /* malloc'ed */
+    /* indexRow[x] is the palette index of the pixel at column x of
+       the row currently being processed
+    */
+    unsigned char * planesrow; /* malloc'ed */
+    /* This is the input for a single row to the compressor */
 
-    int Planes, BytesPerLine, BitsPerPixel;
-    unsigned char *indexRow;  /* malloc'ed */
-        /* indexRow[x] is the palette index of the pixel at column x of
-           the row currently being processed
-        */
-    unsigned char *planesrow; /* malloc'ed */
-        /* This is the input for a single row to the compressor */
-    int row;
+    unsigned int row;
 
-    if (packbits) {
-        Planes = 1;
-        if (colors > 4)        BitsPerPixel = 4;
-        else if (colors > 2)   BitsPerPixel = 2;
-        else                   BitsPerPixel = 1;
-    } else {
-        BitsPerPixel = 1;
-        if (planesRequested)
-            Planes = planesRequested;
-        else {
-            if (colors > 8)        Planes = 4;
-            else if (colors > 4)   Planes = 3;
-            else if (colors > 2)   Planes = 2;
-            else                   Planes = 1;
-        }
-    }
-    BytesPerLine = ((cols * BitsPerPixel) + 7) / 8;
     MALLOCARRAY_NOFAIL(indexRow, cols);
-    MALLOCARRAY_NOFAIL(planesrow, BytesPerLine);
+    MALLOCARRAY(planesrow, bytesPerLine);
+
+    if (!planesrow)
+        pm_error("Failed to allocate buffer for a line of %u bytes",
+                 bytesPerLine);
 
-    write_header(stdout, cols, rows, BitsPerPixel, Planes, pcxcmap, 
-                 xPos, yPos);
     for (row = 0; row < rows; ++row) {
-        int col;
+        unsigned int col;
         for (col = 0; col < cols; ++col)
             indexRow[col] = indexOfColor(cht, pixels[row][col]);
 
         if (packbits) {
-            PackBits(indexRow, cols, planesrow, BitsPerPixel);
-            PCXEncode(stdout, planesrow, BytesPerLine);
+            packBits(indexRow, cols, planesrow, bitsPerPixel);
+            pcxEncode(ofP, planesrow, bytesPerLine);
         } else {
             unsigned int plane;
-            for (plane = 0; plane < Planes; ++plane) {
+            for (plane = 0; plane < planes; ++plane) {
                 extractPlane(indexRow, cols, planesrow, plane);
-                PCXEncode(stdout, planesrow, BytesPerLine);
+                pcxEncode(stdout, planesrow, bytesPerLine);
             }
         }
     }
@@ -454,83 +440,142 @@ ppmTo16ColorPcx(pixel **            const pixels,
 
 
 static void
-ppmTo256ColorPcx(pixel **            const pixels, 
-                 int                 const cols, 
-                 int                 const rows, 
-                 struct pcxCmapEntry const pcxcmap[], 
-                 int                 const colors, 
+ppmTo16ColorPcx(pixel **            const pixels,
+                unsigned int        const cols,
+                unsigned int        const rows,
+                struct PcxCmapEntry const pcxcmap[],
+                unsigned int        const colorCt,
+                colorhash_table     const cht,
+                bool                const packbits,
+                unsigned int        const planesRequested,
+                unsigned int        const xPos,
+                unsigned int        const yPos) {
+
+    unsigned int planes;
+    unsigned int bitsPerPixel;
+
+    if (packbits) {
+        planes = 1;
+        if (colorCt > 4)        bitsPerPixel = 4;
+        else if (colorCt > 2)   bitsPerPixel = 2;
+        else                    bitsPerPixel = 1;
+    } else {
+        bitsPerPixel = 1;
+        if (planesRequested)
+            planes = planesRequested;
+        else {
+            if (colorCt > 8)        planes = 4;
+            else if (colorCt > 4)   planes = 3;
+            else if (colorCt > 2)   planes = 2;
+            else                   planes = 1;
+        }
+    }
+
+    writeHeader(stdout, cols, rows, bitsPerPixel, planes, pcxcmap,
+                xPos, yPos);
+
+    writeRaster16Color(stdout, pixels, cols, rows, planes, cht, packbits,
+                       bitsPerPixel);
+}
+
+
+
+static void
+ppmTo256ColorPcx(pixel **            const pixels,
+                 unsigned int        const cols,
+                 unsigned int        const rows,
+                 struct PcxCmapEntry const pcxcmap[],
+                 unsigned int        const colorCt,
                  colorhash_table     const cht,
-                 unsigned int        const xPos, 
+                 unsigned int        const xPos,
                  unsigned int        const yPos) {
 
-    int row;
-    unsigned int i;
-    unsigned char *rawrow;
+    unsigned char * rawrow;
+    unsigned int    row;
+
+    MALLOCARRAY(rawrow, cols);
 
-    rawrow = (unsigned char *)pm_allocrow(cols, sizeof(unsigned char));
+    if (!rawrow)
+        pm_error("Failed to allocate a buffer for %u columns", cols);
 
     /* 8 bits per pixel, 1 plane */
-    write_header(stdout, cols, rows, 8, 1, NULL, xPos, yPos);
+    writeHeader(stdout, cols, rows, 8, 1, NULL, xPos, yPos);
     for (row = 0; row < rows; ++row) {
-        int col;
+        unsigned int col;
         for (col = 0; col < cols; ++col)
             rawrow[col] = indexOfColor(cht, pixels[row][col]);
-        PCXEncode(stdout, rawrow, cols);
+        pcxEncode(stdout, rawrow, cols);
+
     }
-    Putbyte(PCX_256_COLORS, stdout);
-    for (i = 0; i < MAXCOLORS; ++i) {
-        Putbyte(pcxcmap[i].r, stdout);
-        Putbyte(pcxcmap[i].g, stdout);
-        Putbyte(pcxcmap[i].b, stdout);
+    putbyte(PCX_256_COLORS, stdout);
+
+    {
+        unsigned int i;
+
+        for (i = 0; i < MAXCOLORS; ++i) {
+            putbyte(pcxcmap[i].r, stdout);
+            putbyte(pcxcmap[i].g, stdout);
+            putbyte(pcxcmap[i].b, stdout);
+        }
     }
-    pm_freerow((void*)rawrow);
+    free(rawrow);
 }
 
 
 
 static void
-ppmToTruecolorPcx(pixel **     const pixels, 
-                  int          const cols, 
-                  int          const rows, 
+ppmToTruecolorPcx(pixel **     const pixels,
+                  unsigned int const cols,
+                  unsigned int const rows,
                   pixval       const maxval,
-                  unsigned int const xPos, 
+                  unsigned int const xPos,
                   unsigned int const yPos) {
 
-    unsigned char *redrow, *greenrow, *bluerow;
-    int col, row;
+    unsigned char * redrow;
+    unsigned char * grnrow;
+    unsigned char * blurow;
+    unsigned int    row;
+
+    MALLOCARRAY(redrow, cols);
+    MALLOCARRAY(grnrow, cols);
+    MALLOCARRAY(blurow, cols);
 
-    redrow   = (unsigned char *)pm_allocrow(cols, sizeof(unsigned char));
-    greenrow = (unsigned char *)pm_allocrow(cols, sizeof(unsigned char));
-    bluerow  = (unsigned char *)pm_allocrow(cols, sizeof(unsigned char));
+    if (!redrow || !grnrow || !blurow)
+        pm_error("Unable to allocate buffer for a row of %u pixels", cols);
 
     /* 8 bits per pixel, 3 planes */
-    write_header(stdout, cols, rows, 8, 3, NULL, xPos, yPos);
-    for( row = 0; row < rows; row++ ) {
-        register pixel *pP = pixels[row];
-        for( col = 0; col < cols; col++, pP++ ) {
-            if( maxval != PCX_MAXVAL ) {
-                redrow[col]   = (long)PPM_GETR(*pP) * PCX_MAXVAL / maxval;
-                greenrow[col] = (long)PPM_GETG(*pP) * PCX_MAXVAL / maxval;
-                bluerow[col]  = (long)PPM_GETB(*pP) * PCX_MAXVAL / maxval;
-            }
-            else {
-                redrow[col]   = PPM_GETR(*pP);
-                greenrow[col] = PPM_GETG(*pP);
-                bluerow[col]  = PPM_GETB(*pP);
+    writeHeader(stdout, cols, rows, 8, 3, NULL, xPos, yPos);
+
+    for (row = 0; row < rows; ++row) {
+        pixel * const pixrow = pixels[row];
+
+        unsigned int col;
+
+        for (col = 0; col < cols; ++col) {
+            pixel const pix = pixrow[col];
+
+            if (maxval != PCX_MAXVAL) {
+                redrow[col] = (long)PPM_GETR(pix) * PCX_MAXVAL / maxval;
+                grnrow[col] = (long)PPM_GETG(pix) * PCX_MAXVAL / maxval;
+                blurow[col] = (long)PPM_GETB(pix) * PCX_MAXVAL / maxval;
+            } else {
+                redrow[col] = PPM_GETR(pix);
+                grnrow[col] = PPM_GETG(pix);
+                blurow[col] = PPM_GETB(pix);
             }
         }
-        PCXEncode(stdout, redrow, cols);
-        PCXEncode(stdout, greenrow, cols);
-        PCXEncode(stdout, bluerow, cols);
+        pcxEncode(stdout, redrow, cols);
+        pcxEncode(stdout, grnrow, cols);
+        pcxEncode(stdout, blurow, cols);
     }
-    pm_freerow((void*)bluerow);
-    pm_freerow((void*)greenrow);
-    pm_freerow((void*)redrow);
+    free(blurow);
+    free(grnrow);
+    free(redrow);
 }
 
 
 
-static const struct pcxCmapEntry 
+static const struct PcxCmapEntry
 stdPalette[] = {
     {   0,   0,   0 },
     {   0,   0, 170 },
@@ -565,7 +610,7 @@ putPcxColorInHash(colorhash_table const cht,
     int rc;
 
     PPM_DEPTH(ppmColor, newPcxColor, PCX_MAXVAL, maxval);
-        
+
     rc = ppm_lookupcolor(cht, &ppmColor);
 
     if (rc == -1)
@@ -577,8 +622,8 @@ putPcxColorInHash(colorhash_table const cht,
            'maxval' is less than PCX_MAXVAL), and two distinct
            colors in the standard palette are indistinguishable at
            subject image color resolution.
-           
-           So we have to figure out wether color 'newPcxColor' or
+
+           So we have to figure out whether color 'newPcxColor' or
            'existingPcxColor' is a better match for 'ppmColor'.
         */
 
@@ -588,8 +633,8 @@ putPcxColorInHash(colorhash_table const cht,
         pixel existingPcxColor;
 
         PPM_DEPTH(idealPcxColor, ppmColor, maxval, PCX_MAXVAL);
-        
-        PPM_ASSIGN(existingPcxColor, 
+
+        PPM_ASSIGN(existingPcxColor,
                    stdPalette[existingColorIndex].r,
                    stdPalette[existingColorIndex].g,
                    stdPalette[existingColorIndex].b);
@@ -608,19 +653,18 @@ putPcxColorInHash(colorhash_table const cht,
 
 
 static void
-generateStandardPalette(struct pcxCmapEntry ** const pcxcmapP,
+generateStandardPalette(struct PcxCmapEntry ** const pcxcmapP,
                         pixval                 const maxval,
                         colorhash_table *      const chtP,
-                        int *                  const colorsP) {
+                        unsigned int *         const colorsP) {
 
     unsigned int const stdPaletteSize = 16;
-    unsigned int colorIndex;
-    struct pcxCmapEntry * pcxcmap;
-    colorhash_table cht;
+
+    unsigned int          colorIndex;
+    struct PcxCmapEntry * pcxcmap;
+    colorhash_table       cht;
 
     MALLOCARRAY_NOFAIL(pcxcmap, MAXCOLORS);
-    
-    *pcxcmapP = pcxcmap;
 
     cht = ppm_alloccolorhash();
 
@@ -629,8 +673,8 @@ generateStandardPalette(struct pcxCmapEntry ** const pcxcmapP,
             /* The color of this colormap entry, in PCX resolution */
 
         pcxcmap[colorIndex] = stdPalette[colorIndex];
-        
-        PPM_ASSIGN(pcxColor, 
+
+        PPM_ASSIGN(pcxColor,
                    stdPalette[colorIndex].r,
                    stdPalette[colorIndex].g,
                    stdPalette[colorIndex].b);
@@ -648,65 +692,65 @@ generateStandardPalette(struct pcxCmapEntry ** const pcxcmapP,
         pcxcmap[colorIndex].b = 0;
     }
 
+    *pcxcmapP = pcxcmap;
     *chtP = cht;
     *colorsP = stdPaletteSize;
 }
-    
+
 
 
 static void
 readPpmPalette(const char *   const paletteFileName,
-               pixel       (* const ppmPaletteP)[], 
+               pixel       (* const ppmPaletteP)[],
                unsigned int * const paletteSizeP) {
 
     FILE * pfP;
     pixel ** pixels;
     int cols, rows;
     pixval maxval;
-    
+
     pfP = pm_openr(paletteFileName);
 
     pixels = ppm_readppm(pfP, &cols, &rows, &maxval);
 
     pm_close(pfP);
-    
+
     *paletteSizeP = rows * cols;
-    if (*paletteSizeP > MAXCOLORS) 
+    if (*paletteSizeP > MAXCOLORS)
         pm_error("ordered palette image contains %d pixels.  Maximum is %d",
                  *paletteSizeP, MAXCOLORS);
 
     {
-        int j;
-        int row;
-        j = 0;  /* initial value */
-        for (row = 0; row < rows; ++row) {
-            int col;
-            for (col = 0; col < cols; ++col) 
+        unsigned int j;
+        unsigned int row;
+        for (row = 0, j = 0; row < rows; ++row) {
+            unsigned int col;
+            for (col = 0; col < cols; ++col)
                 (*ppmPaletteP)[j++] = pixels[row][col];
         }
     }
     ppm_freearray(pixels, rows);
-}        
+}
 
 
 
 static void
-readPaletteFromFile(struct pcxCmapEntry ** const pcxcmapP,
+readPaletteFromFile(struct PcxCmapEntry ** const pcxcmapP,
                     const char *           const paletteFileName,
                     pixval                 const maxval,
                     colorhash_table *      const chtP,
-                    int *                  const colorsP) {
+                    unsigned int *         const colorsP) {
 
     unsigned int colorIndex;
     pixel ppmPalette[MAXCOLORS];
     unsigned int paletteSize;
-    struct pcxCmapEntry * pcxcmap;
+    struct PcxCmapEntry * pcxcmap;
     colorhash_table cht;
 
     readPpmPalette(paletteFileName, &ppmPalette, &paletteSize);
 
     MALLOCARRAY_NOFAIL(pcxcmap, MAXCOLORS);
-    
+
     *pcxcmapP = pcxcmap;
 
     cht = ppm_alloccolorhash();
@@ -716,8 +760,8 @@ readPaletteFromFile(struct pcxCmapEntry ** const pcxcmapP,
             /* The color of this colormap entry, in PCX resolution */
 
         pcxcmap[colorIndex] = pcxCmapEntryFromPixel(ppmPalette[colorIndex]);
-        
-        PPM_ASSIGN(pcxColor, 
+
+        PPM_ASSIGN(pcxColor,
                    ppmPalette[colorIndex].r,
                    ppmPalette[colorIndex].g,
                    ppmPalette[colorIndex].b);
@@ -728,12 +772,12 @@ readPaletteFromFile(struct pcxCmapEntry ** const pcxcmapP,
     *chtP = cht;
     *colorsP = paletteSize;
 }
-    
+
 
 
 static void
 moveBlackToIndex0(colorhist_vector const chv,
-                  int              const colors) {
+                  unsigned int     const colorCt) {
 /*----------------------------------------------------------------------------
    If black is in the palette, make it at Index 0.
 -----------------------------------------------------------------------------*/
@@ -745,19 +789,20 @@ moveBlackToIndex0(colorhist_vector const chv,
 
     blackPresent = FALSE;  /* initial assumption */
 
-    for (i = 0; i < colors; ++i)
+    for (i = 0; i < colorCt; ++i)
         if (PPM_EQUAL(chv[i].color, blackPixel))
             blackPresent = TRUE;
-            
+
     if (blackPresent) {
         /* We use a trick here.  ppm_addtocolorhist() always adds to the
            beginning of the table and if the color is already elsewhere in
            the table, removes it.
         */
-        int colors2;
-        colors2 = colors;
-        ppm_addtocolorhist(chv, &colors2, MAXCOLORS, &blackPixel, 0, 0);
-        assert(colors2 == colors);
+        int colorCt2;
+
+        colorCt2 = colorCt;
+        ppm_addtocolorhist(chv, &colorCt2, MAXCOLORS, &blackPixel, 0, 0);
+        assert(colorCt2 == colorCt);
     }
 }
 
@@ -765,12 +810,12 @@ moveBlackToIndex0(colorhist_vector const chv,
 
 static void
 makePcxColormapFromImage(pixel **               const pixels,
-                         int                    const cols,
-                         int                    const rows,
+                         unsigned int           const cols,
+                         unsigned int           const rows,
                          pixval                 const maxval,
-                         struct pcxCmapEntry ** const pcxcmapP,
+                         struct PcxCmapEntry ** const pcxcmapP,
                          colorhash_table *      const chtP,
-                         int *                  const colorsP,
+                         unsigned int *         const colorCtP,
                          bool *                 const tooManyColorsP) {
 /*----------------------------------------------------------------------------
    Make a colormap (palette) for the PCX header that can be used
@@ -780,35 +825,35 @@ makePcxColormapFromImage(pixel **               const pixels,
    *pcxcmapP.
 
    Also return a lookup hash to relate a color in the image to the
-   appropriate index in *pcxcmapP.  Return that in newly malloc'ed 
+   appropriate index in *pcxcmapP.  Return that in newly malloc'ed
    storage as *chtP.
 
-   Iff there are too many colors to do that (i.e. more than 256), 
+   Iff there are too many colors to do that (i.e. more than 256),
    return *tooManyColorsP == TRUE.
 -----------------------------------------------------------------------------*/
-    int colors;
+    int colorCt;
     colorhist_vector chv;
 
     pm_message("computing colormap...");
 
-    chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colors);
+    chv = ppm_computecolorhist(pixels, cols, rows, MAXCOLORS, &colorCt);
     if (chv == NULL)
         *tooManyColorsP = TRUE;
     else {
-        int i;
-        struct pcxCmapEntry * pcxcmap;
+        unsigned int i;
+        struct PcxCmapEntry * pcxcmap;
 
         *tooManyColorsP = FALSE;
 
-        pm_message("%d colors found", colors);
-        
-        moveBlackToIndex0(chv, colors);
+        pm_message("%d colors found", colorCt);
+
+        moveBlackToIndex0(chv, colorCt);
 
         MALLOCARRAY_NOFAIL(pcxcmap, MAXCOLORS);
 
         *pcxcmapP = pcxcmap;
 
-        for (i = 0; i < colors; ++i) {
+        for (i = 0; i < colorCt; ++i) {
             pixel p;
 
             PPM_DEPTH(p, chv[i].color, maxval, PCX_MAXVAL);
@@ -825,9 +870,9 @@ makePcxColormapFromImage(pixel **               const pixels,
             pcxcmap[i].b = 0;
         }
 
-        *chtP = ppm_colorhisttocolorhash(chv, colors);
+        *chtP = ppm_colorhisttocolorhash(chv, colorCt);
 
-        *colorsP = colors;
+        *colorCtP = colorCt;
 
         ppm_freecolorhist(chv);
     }
@@ -835,45 +880,45 @@ makePcxColormapFromImage(pixel **               const pixels,
 
 
 
-static void 
-ppmToPalettePcx(pixel **            const pixels, 
-                int                 const cols, 
-                int                 const rows,
+static void
+ppmToPalettePcx(pixel **            const pixels,
+                unsigned int        const cols,
+                unsigned int        const rows,
                 pixval              const maxval,
-                unsigned int        const xPos, 
+                unsigned int        const xPos,
                 unsigned int        const yPos,
-                struct pcxCmapEntry const pcxcmap[],
+                struct PcxCmapEntry const pcxcmap[],
                 colorhash_table     const cht,
-                int                 const colors,
+                unsigned int        const colorCt,
                 bool                const packbits,
                 unsigned int        const planes,
-                bool                const use_8_bit) {
-    
+                bool                const use8Bit) {
+
     /* convert image */
-    if( colors <= 16 && !use_8_bit )
-        ppmTo16ColorPcx(pixels, cols, rows, pcxcmap, colors, cht, 
+    if (colorCt <= 16 && !use8Bit )
+        ppmTo16ColorPcx(pixels, cols, rows, pcxcmap, colorCt, cht,
                         packbits, planes, xPos, yPos);
     else
-        ppmTo256ColorPcx(pixels, cols, rows, pcxcmap, colors, cht,
+        ppmTo256ColorPcx(pixels, cols, rows, pcxcmap, colorCt, cht,
                          xPos, yPos);
 }
 
 
 
 int
-main(int argc, char *argv[]) {
+main(int argc, const char *argv[]) {
 
-    struct cmdlineInfo cmdline;
-    FILE* ifP;
+    struct CmdlineInfo cmdline;
+    FILE * ifP;
     int rows, cols;
     pixval maxval;
     pixel **pixels;
-    struct pcxCmapEntry * pcxcmap;
+    struct PcxCmapEntry * pcxcmap;
     colorhash_table cht;
     bool truecolor;
-    int colors;
+    unsigned int colorCt;
 
-    ppm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
@@ -886,17 +931,17 @@ main(int argc, char *argv[]) {
     else {
         if (cmdline.stdpalette) {
             truecolor = FALSE;
-            generateStandardPalette(&pcxcmap, maxval, &cht, &colors);
+            generateStandardPalette(&pcxcmap, maxval, &cht, &colorCt);
         } else if (cmdline.palette) {
             truecolor = FALSE;
-            readPaletteFromFile(&pcxcmap, cmdline.palette, maxval, 
-                                &cht, &colors);
+            readPaletteFromFile(&pcxcmap, cmdline.palette, maxval,
+                                &cht, &colorCt);
         } else {
             bool tooManyColors;
             makePcxColormapFromImage(pixels, cols, rows, maxval,
-                                     &pcxcmap, &cht, &colors,
+                                     &pcxcmap, &cht, &colorCt,
                                      &tooManyColors);
-            
+
             if (tooManyColors) {
                 pm_message("too many colors - writing a 24bit PCX file");
                 pm_message("if you want a non-24bit file, "
@@ -908,16 +953,19 @@ main(int argc, char *argv[]) {
     }
 
     if (truecolor)
-        ppmToTruecolorPcx(pixels, cols, rows, maxval, 
+        ppmToTruecolorPcx(pixels, cols, rows, maxval,
                           cmdline.xpos, cmdline.ypos);
     else {
-        ppmToPalettePcx(pixels, cols, rows, maxval, 
+        ppmToPalettePcx(pixels, cols, rows, maxval,
                         cmdline.xpos, cmdline.ypos,
-                        pcxcmap, cht, colors, cmdline.packed, 
-                        cmdline.planes, cmdline.use_8_bit);
-        
+                        pcxcmap, cht, colorCt, cmdline.packed,
+                        cmdline.planes, cmdline.use8Bit);
+
         ppm_freecolorhash(cht);
         free(pcxcmap);
     }
     return 0;
 }
+
+
+
diff --git a/converter/ppm/ppmtospu.c b/converter/ppm/ppmtospu.c
index b558c1fe..a6acbaa0 100644
--- a/converter/ppm/ppmtospu.c
+++ b/converter/ppm/ppmtospu.c
@@ -292,7 +292,7 @@ computePalette(struct PixelType * const pixelType) {
 
     /* Uses popularity algorithm */
 
-    /* Count the occurences of each color */
+    /* Count the occurrences of each color */
 
     for (i = 0; i < 512; ++i)
         hist[i] = 0;
diff --git a/converter/ppm/sldtoppm.c b/converter/ppm/sldtoppm.c
index 2dc049f8..2fef0233 100644
--- a/converter/ppm/sldtoppm.c
+++ b/converter/ppm/sldtoppm.c
@@ -600,7 +600,7 @@ slider(slvecfn   slvec,
             curcolor = cw & 0xFF;
             break;
 
-        default:              /*  Co-ordinates  */
+        default:              /*  Coordinates  */
             lx = vec.f.x = cw;
             ly = vec.f.y = sli();
             vec.t.x = sli();
diff --git a/converter/ppm/xim.h b/converter/ppm/xim.h
index 70a9a761..116312bb 100644
--- a/converter/ppm/xim.h
+++ b/converter/ppm/xim.h
@@ -6,7 +6,7 @@
 ** Taken from the X.V11R4 version of XimHeader.h:
 **
 ** Author: Philip R. Thompson
-** Address:  phils@athena.mit.edu, 9-526 
+** Address:  phils@athena.mit.edu, 9-526
 ** Note:  size of header should be 1024 (1K) bytes.
 ** $Header: /mit/phils/X/RCS/XimHeader.h,v 1.7 89/11/09 17:26:54 phils Exp Locker: phils $
 ** $Date: 89/11/09 17:26:54 $
@@ -24,7 +24,7 @@ typedef struct ImageHeader {
     char file_version[8];   /* header version */
     char header_size[8];    /* Size of file header in bytes  */
     char image_width[8];    /* Width of the raster image */
-    char image_height[8];   /* Height of the raster imgage */
+    char image_height[8];   /* Height of the raster image */
     char num_colors[8];     /* Actual number of entries in c_map */
     char num_channels[3];   /* 0 or 1 = pixmap, 3 = RG&B buffers */
     char bytes_per_line[5]; /* bytes per scanline */
@@ -63,9 +63,9 @@ typedef struct XimImage {
     short tpics, npics;    /* number of images, total & left in file */
     short ncolors;         /*   "    "  colors in the color table */
     Color* colors;         /* colortable, one byte per r/g/b & pixel */
-    const char* author;    /* author credit, copyright, etc */
-    const char* date;      /* date image was made, grabbed, etc. */
-    const char* program;   /* program used to make this */
+    const char* author;         /* author credit, copyright, etc */
+    const char* date;           /* date image was made, grabbed, etc. */
+    const char* program;        /* program used to make this */
     short ncomments;       /* number of comments strings */
     char** comments;      /* pointers to null terminated strings */
     char* offset;         /* original offset in machine memory */
@@ -81,7 +81,7 @@ typedef struct XimImage {
 typedef struct XimAsciiHeader {
     char file_version[4];   /* header version */
     char header_size[8];    /* Size of file header (fixed part only) */
-    char image_height[8];   /* Height of the raster imgage in pixels */
+    char image_height[8];   /* Height of the raster image in pixels */
     char image_width[8];    /* Width of the raster image in pixels */
     char bytes_line[8];     /* Actual # of bytes separating scanlines */
     char bits_channel[4];   /* Bits per channel (usually 1 or 8) */
@@ -111,7 +111,7 @@ typedef struct XimAsciiHeader {
 
 /* Note:
 * - All data is in char's in order to maintain easily portability
-*   across machines, and some human readibility.
+*   across machines, and some human readability.
 * - Images may be stored as pixmaps (8 bits/pixel) or as separate
 *   red, green, blue channel data (24+ bits/pixel).
 * - An alpha channel is optional and is found after every num_channels
diff --git a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c
index 92b123f6..d839e770 100644
--- a/converter/ppm/ximtoppm.c
+++ b/converter/ppm/ximtoppm.c
@@ -22,7 +22,9 @@
 #include "shhopt.h"
 #include "nstring.h"
 
-struct cmdlineInfo {
+
+
+struct CmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
@@ -34,8 +36,8 @@ struct cmdlineInfo {
 
 
 static void
-parseCommandLine(int argc, char ** argv,
-                 struct cmdlineInfo *cmdlineP) {
+parseCommandLine(int argc, const char ** argv,
+                 struct CmdlineInfo *cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that many of the strings that this function returns in the
    *cmdlineP structure are actually in the supplied argv array.  And
@@ -50,14 +52,14 @@ parseCommandLine(int argc, char ** argv,
     unsigned int alphaoutSpec;
 
     option_def_index = 0;   /* incremented by OPTENT3 */
-    OPTENT3(0,   "alphaout",   OPT_STRING, 
+    OPTENT3(0,   "alphaout",   OPT_STRING,
             &cmdlineP->alpha_filename, &alphaoutSpec, 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, argv, opt, sizeof(opt), 0);
+    pm_optParseOptions3(&argc, (char**)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and all of *cmdlineP. */
 
     if (!alphaoutSpec)
@@ -67,21 +69,21 @@ parseCommandLine(int argc, char ** argv,
         cmdlineP->input_filename = "-";  /* he wants stdin */
     else if (argc - 1 == 1)
         cmdlineP->input_filename = strdup(argv[1]);
-    else 
+    else
         pm_error("Too many arguments.  The only argument accepted "
                  "is the input file specification");
 
-    if (cmdlineP->alpha_filename && 
+    if (cmdlineP->alpha_filename &&
         streq(cmdlineP->alpha_filename, "-"))
         cmdlineP->alpha_stdout = TRUE;
-    else 
+    else
         cmdlineP->alpha_stdout = FALSE;
 }
 
 
 
 /* The subroutines are excerpted and slightly modified from the
-   X.V11R4 version of xim_io.c. 
+   X.V11R4 version of xim_io.c.
 */
 
 static int
@@ -100,6 +102,11 @@ ReadXimHeader(FILE *     const in_fp,
         pm_message("ReadXimHeader: unable to read file header" );
         return(0);
     }
+    /* Force broken ASCIIZ strings to at least be valid ASCIIZ */
+    a_head.author [sizeof(a_head.author)  - 1] = '\0';
+    a_head.date   [sizeof(a_head.date)    - 1] = '\0';
+    a_head.program[sizeof(a_head.program) - 1] = '\0';
+
     if (atoi(a_head.header_size) != sizeof(ImageHeader)) {
         pm_message("ReadXimHeader: header size mismatch" );
         return(0);
@@ -113,14 +120,16 @@ ReadXimHeader(FILE *     const in_fp,
     header->ncolors = atoi(a_head.num_colors);
     header->nchannels = atoi(a_head.num_channels);
     header->bytes_per_line = atoi(a_head.bytes_per_line);
-/*    header->npics = atoi(a_head.num_pictures);
-*/
+#if 0
+    header->npics = atoi(a_head.num_pictures);
+#endif
     header->bits_channel = atoi(a_head.bits_per_channel);
     header->alpha_flag = atoi(a_head.alpha_channel);
     header->author = pm_strdup(a_head.author);
     header->date = pm_strdup(a_head.date);
     header->program = pm_strdup(a_head.program);
-    /* Do double checking for bakwards compatibility */
+
+    /* Do double checking for backwards compatibility */
     if (header->npics == 0)
         header->npics = 1;
     if (header->bits_channel == 0)
@@ -130,7 +139,7 @@ ReadXimHeader(FILE *     const in_fp,
         header->bits_channel = 8;
     }
     if ((int)header->bytes_per_line == 0)
-        header->bytes_per_line = 
+        header->bytes_per_line =
             (header->bits_channel == 1 && header->nchannels == 1) ?
                 (header->width + 7) / 8 :
                 header->width;
@@ -186,9 +195,10 @@ ReadImageChannel(FILE *         const infp,
             }
             marker += i;
         }
-        /* return to the beginning of the next image's bufffer */
+        /* return to the beginning of the next image's buffer */
         if (fseek(infp, marker, 0) == -1) {
-            pm_message("ReadImageChannel: can't fseek to location in image buffer" );
+            pm_message("ReadImageChannel: can't fseek to location "
+                       "in image buffer");
             return(0);
         }
         free((char *)line);
@@ -271,7 +281,7 @@ ReadXimImage(FILE *     const in_fp,
 *  Author: Philip Thompson
 *  $Date: 89/11/01 10:14:23 $
 *  $Revision: 1.14 $
-*  Purpose: General xim libray of utililities
+*  Purpose: General xim library of utililities
 *  Copyright (c) 1988  Philip R. Thompson
 *                Computer Resource Laboratory (CRL)
 *                Dept. of Architecture and Planning
@@ -297,28 +307,26 @@ ReadXimImage(FILE *     const in_fp,
 ***********************************************************************/
 
 static int
-ReadXim(in_fp, xim)
-    FILE *in_fp;
-    XimImage *xim;
-{
+ReadXim(FILE *     const in_fp,
+        XimImage * const xim) {
+
     if (!ReadXimHeader(in_fp, xim)) {
         pm_message("can't read xim header" );
-    return(0);
-    }
-    if (!ReadXimImage(in_fp, xim)) {
+        return 0;
+    } else if (!ReadXimImage(in_fp, xim)) {
         pm_message("can't read xim data" );
-    return(0);
-    }
-    return(1);
+        return 0;
+    } else
+        return 1;
 }
 
 
 
 int
-main(int argc,
-     char *argv[]) {
+main(int          argc,
+     const char **argv) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     FILE *ifP, *imageout_file, *alpha_file;
     XimImage xim;
     pixel *pixelrow, colormap[256];
@@ -330,24 +338,24 @@ main(int argc,
     pixval maxval;
     bool success;
 
-    ppm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
-    
+
     ifP = pm_openr(cmdline.input_filename);
-    
+
     if (cmdline.alpha_stdout)
         alpha_file = stdout;
-    else if (cmdline.alpha_filename == NULL) 
+    else if (cmdline.alpha_filename == NULL)
         alpha_file = NULL;
     else
         alpha_file = pm_openw(cmdline.alpha_filename);
-    
-    if (cmdline.alpha_stdout) 
+
+    if (cmdline.alpha_stdout)
         imageout_file = NULL;
     else
         imageout_file = stdout;
-    
+
     success = ReadXim(ifP, &xim);
     if (!success)
         pm_error("can't read Xim file");
@@ -374,7 +382,7 @@ main(int argc,
             "unknown Xim file type, nchannels == %d, bits_channel == %d",
             xim.nchannels, xim.bits_channel);
 
-    if (imageout_file) 
+    if (imageout_file)
         ppm_writeppminit(imageout_file, cols, rows, maxval, 0);
     if (alpha_file)
         pgm_writepgminit(alpha_file, cols, rows, maxval, 0);
@@ -386,8 +394,8 @@ main(int argc,
         if (mapped) {
             byte * const ximrow = xim.data + row * xim.bytes_per_line;
             unsigned int col;
-            
-            for (col = 0; col < cols; ++col) 
+
+            for (col = 0; col < cols; ++col)
                 pixelrow[col] = colormap[ximrow[col]];
             alpharow[col] = 0;
         } else {
@@ -403,11 +411,11 @@ main(int argc,
                            redrow[col], grnrow[col], blurow[col]);
                 if (xim.nchannels > 3)
                     alpharow[col] = othrow[col];
-                else 
+                else
                     alpharow[col] = 0;
             }
         }
-        if (imageout_file) 
+        if (imageout_file)
             ppm_writeppmrow(imageout_file, pixelrow, cols, maxval, 0);
         if (alpha_file)
             pgm_writepgmrow(alpha_file, alpharow, cols, maxval, 0);
@@ -420,3 +428,6 @@ main(int argc,
 
     return 0;
 }
+
+
+
diff --git a/converter/ppm/xpmtoppm.README b/converter/ppm/xpmtoppm.README
index b5e254fa..0a32113c 100644
--- a/converter/ppm/xpmtoppm.README
+++ b/converter/ppm/xpmtoppm.README
@@ -49,7 +49,7 @@ xpmtoppm.c:
   - Now understands multword X11 color names
   
   - Now reads multiple color keys. Takes the color
-    of the hightest available key. Lines no longer need
+    of the highest available key. Lines no longer need
     to begin with key 'c'.
     
   - expanded line buffer to from 500 to 2048 for bigger files
diff --git a/converter/ppm/xpmtoppm.c b/converter/ppm/xpmtoppm.c
index 46101a09..c97b9fdc 100644
--- a/converter/ppm/xpmtoppm.c
+++ b/converter/ppm/xpmtoppm.c
@@ -544,7 +544,7 @@ interpretXpm3ColorTableLine(char               const line[],
                     addToColorMap(hashP, colorName, curbuf, isTransparent);
                     highkey = curkey;
                 }
-                /* intialize state to process this new key */
+                /* initialize state to process this new key */
                 curkey = key;
                 curbuf[0] = '\0';
                 isTransparent = FALSE;
@@ -606,7 +606,7 @@ readXpm3Header(FILE *             const ifP,
                ColorNameHash **   const colorNameHashPP) {
 /*----------------------------------------------------------------------------
   Read the header of the XPM file on stream *ifP.  Assume the
-  getLine() stream is presently positioned to the beginning of the
+  getLine() stream is currently positioned to the beginning of the
   file and it is a Version 3 XPM file.  Leave the stream positioned
   after the header.
 
@@ -721,7 +721,7 @@ readXpm1Header(FILE *           const ifP,
                ColorNameHash ** const colorNameHashPP) {
 /*----------------------------------------------------------------------------
   Read the header of the XPM file on stream *ifP.  Assume the
-  getLine() stream is presently positioned to the beginning of the
+  getLine() stream is currently positioned to the beginning of the
   file and it is a Version 1 XPM file.  Leave the stream positioned
   after the header.
 
@@ -1074,7 +1074,7 @@ main(int argc, char *argv[]) {
 **  - Now understands multiword X11 color names
 **
 **  - Now reads multiple color keys. Takes the color
-**    of the hightest available key. Lines no longer need
+**    of the highest available key. Lines no longer need
 **    to begin with key 'c'.
 **
 **  - expanded line buffer to from 500 to 2048 for bigger files