about summary refs log tree commit diff
path: root/urt
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-03-27 01:46:26 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-03-27 01:46:26 +0000
commitdff6b9fdfeb78fe21a66aa459ddc1d5f7e362dfa (patch)
treeb147568ccffc4cdba9e2a98de1452450ba8e55c3 /urt
parent4ce684c4978610d1ea42be1b00f7332f3f5f337a (diff)
downloadnetpbm-mirror-dff6b9fdfeb78fe21a66aa459ddc1d5f7e362dfa.tar.gz
netpbm-mirror-dff6b9fdfeb78fe21a66aa459ddc1d5f7e362dfa.tar.xz
netpbm-mirror-dff6b9fdfeb78fe21a66aa459ddc1d5f7e362dfa.zip
Promote Advanced (10.73) to Stable
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@2692 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'urt')
-rw-r--r--urt/Makefile10
-rw-r--r--urt/cmd_name.c3
-rw-r--r--urt/rle.h6
-rw-r--r--urt/rle_addhist.c12
-rw-r--r--urt/rle_config.h31
-rw-r--r--urt/rle_error.c1
-rw-r--r--urt/rle_getcom.c1
-rw-r--r--urt/rle_getrow.c690
-rw-r--r--urt/rle_getskip.c2
-rw-r--r--urt/rle_global.c2
-rw-r--r--urt/rle_hdr.c5
-rw-r--r--urt/rle_open_f.c17
-rw-r--r--urt/rle_put.h1
-rw-r--r--urt/rle_putcom.c4
-rw-r--r--urt/rle_putrow.c3
-rw-r--r--urt/rle_row_alc.c2
-rw-r--r--urt/scanargs.c38
17 files changed, 369 insertions, 459 deletions
diff --git a/urt/Makefile b/urt/Makefile
index 57543b0c..0aef5290 100644
--- a/urt/Makefile
+++ b/urt/Makefile
@@ -5,6 +5,8 @@ endif
 SUBDIR = urt
 VPATH=.:$(SRCDIR)/$(SUBDIR)
 
+default: all
+
 include $(BUILDDIR)/config.mk
 
 LIBOBJECTS = Runput.o cmd_name.o \
@@ -15,6 +17,9 @@ LIBOBJECTS = Runput.o cmd_name.o \
 
 MERGE_OBJECTS =
 
+OMIT_URT_RULE = 1
+include $(SRCDIR)/common.mk
+
 all: librle.a
 
 librle.a: $(LIBOBJECTS)
@@ -24,11 +29,8 @@ librle.a: $(LIBOBJECTS)
 
 # Rule for objects.
 $(LIBOBJECTS): %.o: %.c importinc
-	$(CC) -c -I importinc -o $@ \
-	  $< $(CPPFLAGS) $(CFLAGS) $(CFLAGS_PERSONAL) $(CADD)
+	$(CC) -c $(INCLUDES) -o $@ $< $(CFLAGS_ALL)
 
 BINARIES =
 SCRIPTS =
 
-OMIT_URT_RULE = 1
-include $(SRCDIR)/common.mk
diff --git a/urt/cmd_name.c b/urt/cmd_name.c
index 1f8f0edf..31fe5f42 100644
--- a/urt/cmd_name.c
+++ b/urt/cmd_name.c
@@ -26,6 +26,9 @@
  */
 
 #include "rle.h"
+
+
+
 static char no_name[] = "(no-name)";
 
 char *
diff --git a/urt/rle.h b/urt/rle.h
index 71f15d28..0766d22a 100644
--- a/urt/rle.h
+++ b/urt/rle.h
@@ -30,14 +30,8 @@
 #ifndef RLE_H
 #define RLE_H
 
-#include "rle_config.h"     /* Configuration parameters. */
-
 #include <stdio.h>      /* Declare FILE. */
 
-#ifdef c_plusplus
-#define USE_PROTOTYPES
-#endif
-
 enum rle_dispatch {
     NO_DISPATCH = -1,
     RUN_DISPATCH = 0
diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c
index 04e26206..b1651754 100644
--- a/urt/rle_addhist.c
+++ b/urt/rle_addhist.c
@@ -25,19 +25,13 @@
  * Copyright (c) 1988, Curtin University of Technology
  */
 
-#include "rle.h"
-
 #include <string.h>
 #include <stdio.h>
-
-#ifdef  USE_TIME_H
 #include <time.h>
-#else
-#include <sys/types.h>
-#include <sys/time.h>
-#endif
 
-#include "mallocvar.h"
+#include "netpbm/mallocvar.h"
+#include "rle.h"
+
 
 /*****************************************************************
  * TAG( rle_addhist )
diff --git a/urt/rle_config.h b/urt/rle_config.h
index f3fa5bbc..57126a18 100644
--- a/urt/rle_config.h
+++ b/urt/rle_config.h
@@ -1,10 +1,7 @@
-/* rle_config.h
- * 
- * Automatically generated by make-config-h script.
- * DO NOT EDIT THIS FILE.
- * Edit include/makefile.src and the configuration file instead.
- */
-#if defined(WIN32) && !defined(__CYGWIN__)
+#ifndef RLE_CONFIG_H_INCLUDED
+#define RLE_CONFIG_H_INCLUDED
+#include "pm_config.h"
+#if MSVCRT
 #define NO_OPEN_PIPES
 #endif
 
@@ -26,7 +23,6 @@
 #define NO_MAKE_MAKEFILE NO_MAKE_MAKEFILE
 #define NO_TOOLS NO_TOOLS
 #define USE_TIME_H USE_TIME_H
-#define USE_PROTOTYPES USE_PROTOTYPES
 #define USE_RANDOM USE_RANDOM
 #define USE_STDARG USE_STDARG
 #define USE_STDLIB_H USE_STDLIB_H
@@ -58,37 +54,20 @@ typedef	void *void_star;
 typedef char *void_star;
 #endif
 
-#ifdef USE_STDLIB_H
-#include <stdlib.h>
-#else
-
 /* Some programs include files from other packages that also declare
  * malloc.  Avoid double declaration by #define NO_DECLARE_MALLOC
  * before including this file.
  */
 #ifndef NO_DECLARE_MALLOC
-#ifdef USE_PROTOTYPES
 #   include <sys/types.h>	/* For size_t. */
     extern void_star malloc( size_t );
     extern void_star calloc( size_t, size_t );
     extern void_star realloc( void_star, size_t );
     extern void free( void_star );
-#else
-    extern void_star malloc();
-    extern void_star realloc();
-    extern void_star calloc();
-    extern void free();
-    extern void cfree();
-#endif /* USE_PROTOTYPES */
 #endif /* NO_DECLARE_MALLOC */
 
-#ifdef USE_PROTOTYPES
 extern char *getenv( CONST_DECL char *name );
-#else
-extern char *getenv();
-#endif
 
-#endif /* USE_STDLIB_H */
 
 #ifdef NEED_BSTRING
     /* From bstring.c. */
@@ -103,3 +82,5 @@ extern char *getenv();
 #ifdef NEED_SETLINEBUF
 #   define setlinebuf( _s )	setvbuf( (_s), NULL, _IOLBF, 0 )
 #endif
+
+#endif
diff --git a/urt/rle_error.c b/urt/rle_error.c
index acaca1a6..da314f0b 100644
--- a/urt/rle_error.c
+++ b/urt/rle_error.c
@@ -27,6 +27,7 @@
 
 #include <string.h>
 
+#include "rle_config.h"
 #include "rle.h"
 
 /*****************************************************************
diff --git a/urt/rle_getcom.c b/urt/rle_getcom.c
index 20da56a9..4226eaaf 100644
--- a/urt/rle_getcom.c
+++ b/urt/rle_getcom.c
@@ -26,6 +26,7 @@
  */
 
 #include <stdio.h>
+
 #include "rle.h"
 
 /*****************************************************************
diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c
index fadf5441..679811cc 100644
--- a/urt/rle_getrow.c
+++ b/urt/rle_getrow.c
@@ -33,8 +33,8 @@
 #include <string.h>
 #include <stdio.h>
 
-#include "pm.h"
-#include "mallocvar.h"
+#include "netpbm/pm.h"
+#include "netpbm/mallocvar.h"
 
 #include "rle.h"
 #include "rle_code.h"
@@ -52,27 +52,26 @@
 
 static int     debug_f;     /* If non-zero, print debug info. */
 
-/*****************************************************************
- * TAG( rle_get_setup )
- * 
- * Read the initialization information from an RLE file.
- * Inputs:
- *  the_hdr:    Contains pointer to the input file.
- * Outputs:
- *  the_hdr:    Initialized with information from the
- *          input file.
- *  Returns 0 on success, -1 if the file is not an RLE file,
- *  -2 if malloc of the color map failed, -3 if an immediate EOF
- *  is hit (empty input file), and -4 if an EOF is encountered reading
- *  the setup information.
- * Assumptions:
- *  infile points to the "magic" number in an RLE file (usually
- * byte 0 in the file).
- * Algorithm:
- *  Read in the setup info and fill in the_hdr.
- */
 int
 rle_get_setup(rle_hdr * const the_hdr) {
+/*-----------------------------------------------------------------------------
+  Read the initialization information from an RLE file.
+  Inputs:
+    the_hdr:    Contains pointer to the input file.
+  Outputs:
+    the_hdr:    Initialized with information from the input file.
+  Returns
+     0  on success,
+     -1 if the file is not an RLE file,
+     -2 if malloc of the color map failed,
+     -3 if an immediate EOF is hit (empty input file)
+     -4 if an EOF is encountered reading the setup information.
+  Assumptions:
+    infile points to the "magic" number in an RLE file (usually  byte 0
+    in the file).
+  Algorithm:
+    Read in the setup info and fill in the_hdr.
+---------------------------------------------------------------------------- */
     struct XtndRsetup setup;
     short magic;
     FILE * infile = the_hdr->rle_file;
@@ -80,116 +79,106 @@ rle_get_setup(rle_hdr * const the_hdr) {
     char * comment_buf;
     
     /* Clear old stuff out of the header. */
-    rle_hdr_clear( the_hdr );
-    if ( the_hdr->is_init != RLE_INIT_MAGIC )
-        rle_names( the_hdr, "Urt", "some file", 0 );
-    the_hdr->img_num++;     /* Count images. */
+    rle_hdr_clear(the_hdr);
+    if (the_hdr->is_init != RLE_INIT_MAGIC)
+        rle_names(the_hdr, "Urt", "some file", 0);
+    ++the_hdr->img_num;     /* Count images. */
 
-    VAXSHORT( magic, infile );
-    if ( feof( infile ) )
+    VAXSHORT(magic, infile);
+    if (feof(infile))
         return RLE_EMPTY;
-    if ( magic != RLE_MAGIC )
+    if (magic != RLE_MAGIC)
         return RLE_NOT_RLE;
-    fread( &setup, 1, SETUPSIZE, infile );  /* assume VAX packing */
-    if ( feof( infile ) )
+    fread(&setup, 1, SETUPSIZE, infile);  /* assume VAX packing */
+    if (feof( infile))
         return RLE_EOF;
 
     /* Extract information from setup */
     the_hdr->ncolors = setup.h_ncolors;
-    for ( i = 0; i < the_hdr->ncolors; i++ )
-        RLE_SET_BIT( *the_hdr, i );
+    for (i = 0; i < the_hdr->ncolors; ++i)
+        RLE_SET_BIT(*the_hdr, i);
 
-    if ( !(setup.h_flags & H_NO_BACKGROUND) && setup.h_ncolors > 0 )
-    {
+    if (!(setup.h_flags & H_NO_BACKGROUND) && setup.h_ncolors > 0) {
         rle_pixel * bg_color;
 
         MALLOCARRAY(the_hdr->bg_color, setup.h_ncolors);
         MALLOCARRAY(bg_color, 1 + (setup.h_ncolors / 2) * 2);
-        RLE_CHECK_ALLOC( the_hdr->cmd, the_hdr->bg_color && bg_color,
-                         "background color" );
-        fread( (char *)bg_color, 1, 1 + (setup.h_ncolors / 2) * 2, infile );
-        for ( i = 0; i < setup.h_ncolors; i++ )
+        RLE_CHECK_ALLOC(the_hdr->cmd, the_hdr->bg_color && bg_color,
+                        "background color" );
+        fread((char *)bg_color, 1, 1 + (setup.h_ncolors / 2) * 2, infile);
+        for (i = 0; i < setup.h_ncolors; ++i)
             the_hdr->bg_color[i] = bg_color[i];
-        free( bg_color );
-    }
-    else
-    {
-        (void)getc( infile );   /* skip filler byte */
+        free(bg_color);
+    } else {
+        getc(infile);   /* skip filler byte */
         the_hdr->bg_color = NULL;
     }
 
-    if ( setup.h_flags & H_NO_BACKGROUND )
+    if (setup.h_flags & H_NO_BACKGROUND)
         the_hdr->background = 0;
-    else if ( setup.h_flags & H_CLEARFIRST )
+    else if (setup.h_flags & H_CLEARFIRST)
         the_hdr->background = 2;
     else
         the_hdr->background = 1;
-    if ( setup.h_flags & H_ALPHA )
-    {
+    if (setup.h_flags & H_ALPHA) {
         the_hdr->alpha = 1;
         RLE_SET_BIT( *the_hdr, RLE_ALPHA );
-    }
-    else
+    } else
         the_hdr->alpha = 0;
 
-    the_hdr->xmin = vax_gshort( setup.hc_xpos );
-    the_hdr->ymin = vax_gshort( setup.hc_ypos );
-    the_hdr->xmax = the_hdr->xmin + vax_gshort( setup.hc_xlen ) - 1;
-    the_hdr->ymax = the_hdr->ymin + vax_gshort( setup.hc_ylen ) - 1;
+    the_hdr->xmin = vax_gshort(setup.hc_xpos);
+    the_hdr->ymin = vax_gshort(setup.hc_ypos);
+    the_hdr->xmax = the_hdr->xmin + vax_gshort(setup.hc_xlen) - 1;
+    the_hdr->ymax = the_hdr->ymin + vax_gshort(setup.hc_ylen) - 1;
 
     the_hdr->ncmap = setup.h_ncmap;
     the_hdr->cmaplen = setup.h_cmaplen;
-    if ( the_hdr->ncmap > 0 )
-    {
+    if (the_hdr->ncmap > 0) {
         int const maplen = the_hdr->ncmap * (1 << the_hdr->cmaplen);
+
         int i;
         char *maptemp;
 
         MALLOCARRAY(the_hdr->cmap, maplen);
         MALLOCARRAY(maptemp, 2 * maplen);
-        if ( the_hdr->cmap == NULL || maptemp == NULL )
-        {
+        if (the_hdr->cmap == NULL || maptemp == NULL) {
             pm_error("Malloc failed for color map of size %d*%d "
                      "in rle_get_setup, reading '%s'",
                      the_hdr->ncmap, (1 << the_hdr->cmaplen),
                      the_hdr->file_name );
             return RLE_NO_SPACE;
         }
-        fread( maptemp, 2, maplen, infile );
-        for ( i = 0; i < maplen; i++ )
-            the_hdr->cmap[i] = vax_gshort( &maptemp[i * 2] );
-        free( maptemp );
+        fread(maptemp, 2, maplen, infile);
+        for (i = 0; i < maplen; ++i)
+            the_hdr->cmap[i] = vax_gshort(&maptemp[i * 2]);
+        free(maptemp);
     }
 
     /* Check for comments */
-    if ( setup.h_flags & H_COMMENT )
-    {
+    if (setup.h_flags & H_COMMENT) {
         short comlen, evenlen;
-        register char * cp;
+        char * cp;
 
-        VAXSHORT( comlen, infile ); /* get comment length */
+        VAXSHORT(comlen, infile); /* get comment length */
         evenlen = (comlen + 1) & ~1;    /* make it even */
-        if ( evenlen )
-        {
+        if (evenlen) {
             MALLOCARRAY(comment_buf, evenlen);
     
-            if ( comment_buf == NULL )
-            {
+            if (comment_buf == NULL) {
                 pm_error("Malloc failed for comment buffer of size %d "
                          "in rle_get_setup, reading '%s'",
                          comlen, the_hdr->file_name );
                 return RLE_NO_SPACE;
             }
-            fread( comment_buf, 1, evenlen, infile );
+            fread(comment_buf, 1, evenlen, infile);
             /* Count the comments */
-            for ( i = 0, cp = comment_buf; cp < comment_buf + comlen; cp++ )
-                if ( *cp == 0 )
-                    i++;
-            i++;            /* extra for NULL pointer at end */
+            for (i = 0, cp = comment_buf; cp < comment_buf + comlen; ++cp)
+                if (*cp == '\0')
+                    ++i;
+            ++i;            /* extra for NULL pointer at end */
             /* Get space to put pointers to comments */
             MALLOCARRAY(the_hdr->comments, i);
-            if ( the_hdr->comments == NULL )
-            {
+            if (the_hdr->comments == NULL) {
                 pm_error("Malloc failed for %d comment pointers "
                          "in rle_get_setup, reading '%s'",
                          i, the_hdr->file_name );
@@ -197,366 +186,331 @@ rle_get_setup(rle_hdr * const the_hdr) {
             }
             /* Get pointers to the comments */
             *the_hdr->comments = comment_buf;
-            for ( i = 1, cp = comment_buf + 1;
-                  cp < comment_buf + comlen;
-                  cp++ )
-                if ( *(cp - 1) == 0 )
+            for (i = 1, cp = comment_buf + 1;
+                 cp < comment_buf + comlen;
+                 ++cp)
+                if (*(cp - 1) == '\0')
                     the_hdr->comments[i++] = cp;
             the_hdr->comments[i] = NULL;
-        }
-        else
+        } else
             the_hdr->comments = NULL;
-    }
-    else
+    } else
         the_hdr->comments = NULL;
 
     /* Initialize state for rle_getrow */
     the_hdr->priv.get.scan_y = the_hdr->ymin;
     the_hdr->priv.get.vert_skip = 0;
     the_hdr->priv.get.is_eof = 0;
-    the_hdr->priv.get.is_seek = ftell( infile ) > 0;
+    the_hdr->priv.get.is_seek = ftell(infile) > 0;
     debug_f = 0;
 
-    if ( !feof( infile ) )
+    if (!feof(infile))
         return RLE_SUCCESS; /* success! */
-    else
-    {
+    else {
         the_hdr->priv.get.is_eof = 1;
         return RLE_EOF;
     }
 }
 
 
-/*****************************************************************
- * TAG( rle_get_setup_ok )
- * 
- * Read the initialization information from an RLE file.
- * Inputs:
- *  the_hdr:    Contains pointer to the input file.
- *  prog_name:  Program name to be printed in the error message.
- *      file_name:  File name to be printed in the error message.
- *                  If NULL, the string "stdin" is generated.
- * Outputs:
- *  the_hdr:    Initialized with information from the
- *          input file.
- *      If reading the header fails, it prints an error message
- *  and exits with the appropriate status code.
- * Algorithm:
- *  rle_get_setup does all the work.
- */
+
 void
-rle_get_setup_ok( the_hdr, prog_name, file_name )
-rle_hdr * the_hdr;
-const char *prog_name;
-const char *file_name;
-{
+rle_get_setup_ok(rle_hdr *    const the_hdr,
+                 const char * const prog_name,
+                 const char * const file_name) {
+/*-----------------------------------------------------------------------------
+  Read the initialization information from an RLE file.
+
+  Inputs:
+   the_hdr:    Contains pointer to the input file.
+   prog_name:  Program name to be printed in the error message.
+       file_name:  File name to be printed in the error message.
+                   If NULL, the string "stdin" is generated.
+
+  Outputs:
+   the_hdr:    Initialized with information from the input file.
+       If reading the header fails, it prints an error message
+       and exits with the appropriate status code.
+  Algorithm:
+   rle_get_setup does all the work.
+---------------------------------------------------------------------------- */
     int code;
 
     /* Backwards compatibility: if is_init is not properly set, 
      * initialize the header.
      */
-    if ( the_hdr->is_init != RLE_INIT_MAGIC )
-    {
-    FILE *f = the_hdr->rle_file;
-    rle_hdr_init( the_hdr );
-    the_hdr->rle_file = f;
-    rle_names( the_hdr, prog_name, file_name, 0 );
+    if (the_hdr->is_init != RLE_INIT_MAGIC) {
+        FILE * const f = the_hdr->rle_file;
+        rle_hdr_init( the_hdr );
+        the_hdr->rle_file = f;
+        rle_names(the_hdr, prog_name, file_name, 0);
     }
 
-    code = rle_get_error( rle_get_setup( the_hdr ),
-              the_hdr->cmd, the_hdr->file_name );
+    code = rle_get_error(rle_get_setup(the_hdr),
+                         the_hdr->cmd, the_hdr->file_name);
     if (code)
-    exit( code );
+        exit(code);
 }
 
 
-/*****************************************************************
- * TAG( rle_debug )
- * 
- * Turn RLE debugging on or off.
- * Inputs:
- *  on_off:     if 0, stop debugging, else start.
- * Outputs:
- *  Sets internal debug flag.
- * Assumptions:
- *  [None]
- * Algorithm:
- *  [None]
- */
+
 void
 rle_debug( on_off )
-int on_off;
+    int on_off;
 {
+/*-----------------------------------------------------------------------------
+  Turn RLE debugging on or off.
+  Inputs:
+   on_off:     if 0, stop debugging, else start.
+  Outputs:
+   Sets internal debug flag.
+  Assumptions:
+   [None]
+  Algorithm:
+   [None]
+---------------------------------------------------------------------------- */
     debug_f = on_off;
 
     /* Set line buffering on stderr.  Character buffering is the default, and
      * it is SLOOWWW for large amounts of output.
      */
-    setvbuf( stderr, NULL, _IOLBF, 0);
-/*
-    setlinebuf( stderr );
-*/
+    setvbuf(stderr, NULL, _IOLBF, 0);
 }
 
 
-/*****************************************************************
- * TAG( rle_getrow )
- * 
- * Get a scanline from the input file.
- * Inputs:
- *  the_hdr:    Header structure containing information about 
- *          the input file.
- * Outputs:
- *  scanline:   an array of pointers to the individual color
- *          scanlines.  Scanline is assumed to have
- *          the_hdr->ncolors pointers to arrays of rle_pixel,
- *          each of which is at least the_hdr->xmax+1 long.
- *  Returns the current scanline number.
- * Assumptions:
- *  rle_get_setup has already been called.
- * Algorithm:
- *  If a vertical skip is being executed, and clear-to-background is
- *  specified (the_hdr->background is true), just set the
- *  scanlines to the background color.  If clear-to-background is
- *  not set, just increment the scanline number and return.
- * 
- *  Otherwise, read input until a vertical skip is encountered,
- *  decoding the instructions into scanline data.
- *
- *  If ymax is reached (or, somehow, passed), continue reading and
- *  discarding input until end of image.
- */
+
 int
-rle_getrow( the_hdr, scanline )
-rle_hdr * the_hdr;
-rle_pixel *scanline[];
-{
-    register rle_pixel * scanc;
-    register int nc;
-    register FILE *infile = the_hdr->rle_file;
-    int scan_x = the_hdr->xmin, /* current X position */
-        max_x = the_hdr->xmax,  /* End of the scanline */
-       channel = 0;         /* current color channel */
+rle_getrow(rle_hdr *    const the_hdr,
+           rle_pixel ** const scanline) {
+/*-----------------------------------------------------------------------------
+  Get a scanline from the input file.
+  Inputs:
+   the_hdr:    Header structure containing information about 
+           the input file.
+  Outputs:
+   scanline:   an array of pointers to the individual color
+           scanlines.  Scanline is assumed to have
+           the_hdr->ncolors pointers to arrays of rle_pixel,
+           each of which is at least the_hdr->xmax+1 long.
+   Returns the current scanline number.
+  Assumptions:
+   rle_get_setup has already been called.
+  Algorithm:
+   If a vertical skip is being executed, and clear-to-background is
+   specified (the_hdr->background is true), just set the
+   scanlines to the background color.  If clear-to-background is
+   not set, just increment the scanline number and return.
+  
+   Otherwise, read input until a vertical skip is encountered,
+   decoding the instructions into scanline data.
+ 
+   If ymax is reached (or, somehow, passed), continue reading and
+   discarding input until end of image.
+---------------------------------------------------------------------------- */
+    FILE * const infile = the_hdr->rle_file;
+
+    rle_pixel * scanc;
+
+    int scan_x; /* current X position */
+    int max_x;  /* End of the scanline */
+    int channel;         /* current color channel */
     int ns;         /* Number to skip */
+    int nc;
     short word, long_data;
     char inst[2];
 
+    scan_x = the_hdr->xmin; /* initial value */
+    max_x = the_hdr->xmax;  /* initial value */
+    channel = 0; /* initial value */
     /* Clear to background if specified */
-    if ( the_hdr->background != 1 )
-    {
-    if ( the_hdr->alpha && RLE_BIT( *the_hdr, -1 ) )
-        memset( (char *)scanline[-1] + the_hdr->xmin, 0,
-           the_hdr->xmax - the_hdr->xmin + 1 );
-    for ( nc = 0; nc < the_hdr->ncolors; nc++ )
-        if ( RLE_BIT( *the_hdr, nc ) ) {
-        /* Unless bg color given explicitly, use 0. */
-        if ( the_hdr->background != 2 || the_hdr->bg_color[nc] == 0 )
-            memset( (char *)scanline[nc] + the_hdr->xmin, 0,
-               the_hdr->xmax - the_hdr->xmin + 1 );
-        else
-            memset((char *)scanline[nc] + the_hdr->xmin,
-                   the_hdr->bg_color[nc],
+    if (the_hdr->background != 1) {
+        if (the_hdr->alpha && RLE_BIT( *the_hdr, -1))
+            memset((char *)scanline[-1] + the_hdr->xmin, 0,
                    the_hdr->xmax - the_hdr->xmin + 1);
+        for (nc = 0; nc < the_hdr->ncolors; ++nc) {
+            if (RLE_BIT( *the_hdr, nc)) {
+                /* Unless bg color given explicitly, use 0. */
+                if (the_hdr->background != 2 || the_hdr->bg_color[nc] == 0)
+                    memset((char *)scanline[nc] + the_hdr->xmin, 0,
+                           the_hdr->xmax - the_hdr->xmin + 1);
+                else
+                    memset((char *)scanline[nc] + the_hdr->xmin,
+                           the_hdr->bg_color[nc],
+                           the_hdr->xmax - the_hdr->xmin + 1);
+            }
         }
     }
 
     /* If skipping, then just return */
-    if ( the_hdr->priv.get.vert_skip > 0 )
-    {
-    the_hdr->priv.get.vert_skip--;
-    the_hdr->priv.get.scan_y++;
-    if ( the_hdr->priv.get.vert_skip > 0 ) {
-        if ( the_hdr->priv.get.scan_y >= the_hdr->ymax )
-        {
-        int y = the_hdr->priv.get.scan_y;
-        while ( rle_getskip( the_hdr ) != 32768 )
-            ;
-        return y;
+    if (the_hdr->priv.get.vert_skip > 0) {
+        --the_hdr->priv.get.vert_skip;
+        ++the_hdr->priv.get.scan_y;
+        if (the_hdr->priv.get.vert_skip > 0) {
+            if (the_hdr->priv.get.scan_y >= the_hdr->ymax) {
+                int const y = the_hdr->priv.get.scan_y;
+                while (rle_getskip(the_hdr) != 32768)
+                    ;
+                return y;
+            } else
+                return the_hdr->priv.get.scan_y;
         }
-        else
-        return the_hdr->priv.get.scan_y;
-    }
     }
 
     /* If EOF has been encountered, return also */
-    if ( the_hdr->priv.get.is_eof )
-    return ++the_hdr->priv.get.scan_y;
+    if (the_hdr->priv.get.is_eof)
+        return ++the_hdr->priv.get.scan_y;
 
     /* Otherwise, read and interpret instructions until a skipLines
-     * instruction is encountered.
-     */
-    if ( RLE_BIT( *the_hdr, channel ) )
-    scanc = scanline[channel] + scan_x;
+       instruction is encountered.
+    */
+    if (RLE_BIT(*the_hdr, channel))
+        scanc = scanline[channel] + scan_x;
     else
-    scanc = NULL;
-    for (;;)
-    {
-    inst[0] = getc( infile );
-    inst[1] = getc( infile );
-    if ( feof(infile) )
-    {
-        the_hdr->priv.get.is_eof = 1;
-        break;      /* <--- one of the exits */
-    }
-
-    switch( OPCODE(inst) )
-    {
-    case RSkipLinesOp:
-        if ( LONGP(inst) )
-        {
-        VAXSHORT( the_hdr->priv.get.vert_skip, infile );
+        scanc = NULL;
+    for (;;) {
+        inst[0] = getc(infile);
+        inst[1] = getc(infile);
+        if (feof(infile)) {
+            the_hdr->priv.get.is_eof = 1;
+            break;      /* <--- one of the exits */
         }
-        else
-        the_hdr->priv.get.vert_skip = DATUM(inst);
-        if (debug_f)
-        fprintf(stderr, "Skip %d Lines (to %d)\n",
-            the_hdr->priv.get.vert_skip,
-            the_hdr->priv.get.scan_y +
-                the_hdr->priv.get.vert_skip );
-
-        break;          /* need to break for() here, too */
-
-    case RSetColorOp:
-        channel = DATUM(inst);  /* select color channel */
-        if ( channel == 255 )
-        channel = -1;
-        scan_x = the_hdr->xmin;
-        if ( RLE_BIT( *the_hdr, channel ) )
-        scanc = scanline[channel]+scan_x;
-        if ( debug_f )
-        fprintf( stderr, "Set color to %d (reset x to %d)\n",
-             channel, scan_x );
-        break;
-
-    case RSkipPixelsOp:
-        if ( LONGP(inst) )
-        {
-        VAXSHORT( long_data, infile );
-        scan_x += long_data;
-        scanc += long_data;
-        if ( debug_f )
-            fprintf( stderr, "Skip %d pixels (to %d)\n",
-                long_data, scan_x );
-        }
-        else
-        {
-        scan_x += DATUM(inst);
-        scanc += DATUM(inst);
-        if ( debug_f )
-            fprintf( stderr, "Skip %d pixels (to %d)\n",
-                DATUM(inst), scan_x );
-        }
-        break;
 
-    case RByteDataOp:
-        if ( LONGP(inst) )
-        {
-        VAXSHORT( nc, infile );
-        }
-        else
-        nc = DATUM(inst);
-        nc++;
-        if ( debug_f ) {
-        if ( RLE_BIT( *the_hdr, channel ) )
-            fprintf( stderr, "Pixel data %d (to %d):", nc, scan_x+nc );
-        else
-            fprintf( stderr, "Pixel data %d (to %d)\n", nc, scan_x+nc);
-        }
-        if ( RLE_BIT( *the_hdr, channel ) )
-        {
-        /* Don't fill past end of scanline! */
-        if ( scan_x + nc > max_x )
-        {
-            ns = scan_x + nc - max_x - 1;
-            nc -= ns;
-        }
-        else
-            ns = 0;
-        fread( (char *)scanc, 1, nc, infile );
-        while ( ns-- > 0 )
-            (void)getc( infile );
-        if ( nc & 1 )
-            (void)getc( infile );   /* throw away odd byte */
-        }
-        else
-        if ( the_hdr->priv.get.is_seek )
-            fseek( infile, ((nc + 1) / 2) * 2, 1 );
-        else
-        {
-            register int ii;
-            for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- )
-            (void) getc( infile );  /* discard it */
-        }
+        switch(OPCODE(inst)) {
+        case RSkipLinesOp:
+            if (LONGP(inst)) {
+                VAXSHORT(the_hdr->priv.get.vert_skip, infile);
+            } else
+                the_hdr->priv.get.vert_skip = DATUM(inst);
+            if (debug_f)
+                pm_message("Skip %d Lines (to %d)",
+                           the_hdr->priv.get.vert_skip,
+                           the_hdr->priv.get.scan_y +
+                           the_hdr->priv.get.vert_skip);
+
+            break;          /* need to break for() here, too */
+
+        case RSetColorOp:
+            channel = DATUM(inst);  /* select color channel */
+            if (channel == 255)
+                channel = -1;
+            scan_x = the_hdr->xmin;
+            if (RLE_BIT(*the_hdr, channel))
+                scanc = scanline[channel]+scan_x;
+            if (debug_f)
+                pm_message("Set color to %d (reset x to %d)",
+                           channel, scan_x );
+            break;
+
+        case RSkipPixelsOp:
+            if (LONGP(inst)) {
+                VAXSHORT(long_data, infile);
+                scan_x += long_data;
+                scanc += long_data;
+                if (debug_f)
+                    pm_message("Skip %d pixels (to %d)", long_data, scan_x);
+            } else {
+                scan_x += DATUM(inst);
+                scanc += DATUM(inst);
+                if (debug_f)
+                    pm_message("Skip %d pixels (to %d)", DATUM(inst), scan_x);
+            }
+            break;
+
+        case RByteDataOp:
+            if (LONGP(inst)) {
+                VAXSHORT(nc, infile);
+            } else
+                nc = DATUM(inst);
+            ++nc;
+            if (debug_f) {
+                if (RLE_BIT(*the_hdr, channel))
+                    pm_message("Pixel data %d (to %d):", nc, scan_x + nc);
+                else
+                    pm_message("Pixel data %d (to %d)", nc, scan_x + nc);
+            }
+            if (RLE_BIT(*the_hdr, channel)) {
+                /* Don't fill past end of scanline! */
+                if (scan_x + nc > max_x) {
+                    ns = scan_x + nc - max_x - 1;
+                    nc -= ns;
+                } else
+                    ns = 0;
+                fread((char *)scanc, 1, nc, infile);
+                while (ns-- > 0)
+                    getc(infile);
+                if (nc & 0x1)
+                    getc(infile);   /* throw away odd byte */
+            } else {
+                if (the_hdr->priv.get.is_seek)
+                    fseek(infile, ((nc + 1) / 2) * 2, 1);
+                else {
+                    int ii;
+                    for (ii = ((nc + 1) / 2) * 2; ii > 0; --ii)
+                        getc(infile);  /* discard it */
+                }
+            }
+            scanc += nc;
+            scan_x += nc;
+            if (debug_f && RLE_BIT(*the_hdr, channel)) {
+                rle_pixel * cp;
+                for (cp = scanc - nc; nc > 0; --nc)
+                    fprintf(stderr, "%02x", *cp++);
+                putc('\n', stderr);
+            }
+            break;
+
+        case RRunDataOp:
+            if (LONGP(inst)) {
+                VAXSHORT(nc, infile);
+            } else
+                nc = DATUM(inst);
+            ++nc;
+            scan_x += nc;
+
+            VAXSHORT(word, infile);
+            if (debug_f)
+                pm_message("Run length %d (to %d), data %02x",
+                           nc, scan_x, word);
+            if (RLE_BIT(*the_hdr, channel)) {
+                if (scan_x > max_x) {
+                    ns = scan_x - max_x - 1;
+                    nc -= ns;
+                } else
+                    ns = 0;
+                if (nc >= 10) {    /* break point for 785, anyway */
+                    memset((char *)scanc, word, nc);
+                    scanc += nc;
+                } else {
+                    for (nc--; nc >= 0; --nc, ++scanc)
+                        *scanc = word;
+                }
+            }
+            break;
 
-        scanc += nc;
-        scan_x += nc;
-        if ( debug_f && RLE_BIT( *the_hdr, channel ) )
-        {
-        rle_pixel * cp = scanc - nc;
-        for ( ; nc > 0; nc-- )
-            fprintf( stderr, "%02x", *cp++ );
-        putc( '\n', stderr );
-        }
-        break;
+        case REOFOp:
+            the_hdr->priv.get.is_eof = 1;
+            if (debug_f)
+                pm_message("End of Image");
+            break;
 
-    case RRunDataOp:
-        if ( LONGP(inst) )
-        {
-        VAXSHORT( nc, infile );
+        default:
+            pm_error("rle_getrow: Unrecognized opcode: %d, reading %s",
+                     inst[0], the_hdr->file_name);
         }
-        else
-        nc = DATUM(inst);
-        nc++;
-        scan_x += nc;
-
-        VAXSHORT( word, infile );
-        if ( debug_f )
-        fprintf( stderr, "Run length %d (to %d), data %02x\n",
-                nc, scan_x, word );
-        if ( RLE_BIT( *the_hdr, channel ) )
-        {
-        if ( scan_x > max_x )
-        {
-            ns = scan_x - max_x - 1;
-            nc -= ns;
-        } 
-        else
-            ns = 0;
-        if ( nc >= 10 )     /* break point for 785, anyway */
-        {
-            memset((char *)scanc, word, nc);
-            scanc += nc;
-        }
-        else
-            for ( nc--; nc >= 0; nc--, scanc++ )
-            *scanc = word;
-        }
-        break;
-
-    case REOFOp:
-        the_hdr->priv.get.is_eof = 1;
-        if ( debug_f )
-        fprintf( stderr, "End of Image\n" );
-        break;
-
-    default:
-        fprintf( stderr,
-             "%s: rle_getrow: Unrecognized opcode: %d, reading %s\n",
-             the_hdr->cmd, inst[0], the_hdr->file_name );
-        exit(1);
-    }
-    if ( OPCODE(inst) == RSkipLinesOp || OPCODE(inst) == REOFOp )
-        break;          /* <--- the other loop exit */
+        if (OPCODE(inst) == RSkipLinesOp || OPCODE(inst) == REOFOp)
+            break;          /* <--- the other loop exit */
     }
 
     /* If at end, skip the rest of a malformed image. */
-    if ( the_hdr->priv.get.scan_y >= the_hdr->ymax )
-    {
-    int y = the_hdr->priv.get.scan_y;
-    while ( rle_getskip( the_hdr ) != 32768 )
-        ;
-    return y;
+    if (the_hdr->priv.get.scan_y >= the_hdr->ymax) {
+        int const y = the_hdr->priv.get.scan_y;
+        while (rle_getskip(the_hdr) != 32768 )
+            ;
+        return y;
     }
 
     return the_hdr->priv.get.scan_y;
 }
+
+
+
diff --git a/urt/rle_getskip.c b/urt/rle_getskip.c
index f1c333e7..1366e162 100644
--- a/urt/rle_getskip.c
+++ b/urt/rle_getskip.c
@@ -25,6 +25,8 @@
  * Copyright (c) 1990, University of Michigan
  */
 
+#include <stdlib.h>
+
 #include "rle.h"
 #include "rle_code.h"
 
diff --git a/urt/rle_global.c b/urt/rle_global.c
index 90d3f975..6014a229 100644
--- a/urt/rle_global.c
+++ b/urt/rle_global.c
@@ -31,6 +31,8 @@
  */
 
 #include <stdio.h>
+
+#include "rle_config.h"
 #include "rle_put.h"
 #include "rle.h"
 #include "Runput.h"
diff --git a/urt/rle_hdr.c b/urt/rle_hdr.c
index 3cc0401d..1611324c 100644
--- a/urt/rle_hdr.c
+++ b/urt/rle_hdr.c
@@ -25,10 +25,11 @@
  * Copyright (c) 1991, University of Michigan
  */
 
-#include "rle.h"
-
 #include <string.h>
 
+#include "rle_config.h"
+#include "rle.h"
+
 /*****************************************************************
  * TAG( rle_names )
  *
diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c
index 07dbea01..ae8548b9 100644
--- a/urt/rle_open_f.c
+++ b/urt/rle_open_f.c
@@ -15,8 +15,9 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-#include "pm_c_util.h"
-#include "nstring.h"
+#include "netpbm/pm_c_util.h"
+#include "netpbm/nstring.h"
+#include "rle_config.h"
 #include "rle.h"
 
 
@@ -52,7 +53,7 @@ my_popen(const char * const cmd,
         return NULL;
     }
 
-    if ( pipe(pipefd) < 0 )
+    if (pm_pipe(pipefd) < 0 )
         return NULL;
     
     /* Flush known files. */
@@ -199,11 +200,11 @@ dealWithSubprocess(const char *  const file_name,
         *noSubprocessP = FALSE;
         
         if (*mode == 'w')
-            asprintfN(&command, "compress > %s", file_name);
+            pm_asprintf(&command, "compress > %s", file_name);
         else if (*mode == 'a')
-            asprintfN(&command, "compress >> %s", file_name);
+            pm_asprintf(&command, "compress >> %s", file_name);
         else
-            asprintfN(&command, "compress -d < %s", file_name);
+            pm_asprintf(&command, "compress -d < %s", file_name);
         
         *fpP = my_popen(command, mode, &thepid);
 
@@ -215,7 +216,7 @@ dealWithSubprocess(const char *  const file_name,
             if (*catchingChildrenP < MAX_CHILDREN)
                 pids[(*catchingChildrenP)++] = thepid;
         }
-        strfree(command);
+        pm_strfree(command);
     } else {
         *noSubprocessP = TRUE;
         *errorP = NULL;
@@ -234,7 +235,7 @@ dealWithSubprocess(const char *  const file_name,
  *  will return a pointer to stdin or stdout depending on the mode.
  *    If the user specifies a non-null file name and an I/O error occurs
  *  when trying to open the file, rle_open_f will terminate execution with
- *  an appropiate error message.
+ *  an appropriate error message.
  *
  *  parameters
  *   input:
diff --git a/urt/rle_put.h b/urt/rle_put.h
index d611b438..1f8cc85b 100644
--- a/urt/rle_put.h
+++ b/urt/rle_put.h
@@ -28,6 +28,7 @@
  */
 
 #include "rle.h"
+#include "rle_config.h"
 
 /* ****************************************************************
  * Dispatch table for different output types.
diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c
index b1215661..ab2eb208 100644
--- a/urt/rle_putcom.c
+++ b/urt/rle_putcom.c
@@ -27,8 +27,8 @@
 
 #include <stdio.h>
 
-#include "mallocvar.h"
-#include "pm.h"
+#include "netpbm/mallocvar.h"
+#include "netpbm/pm.h"
 #include "rle.h"
 
 /*****************************************************************
diff --git a/urt/rle_putrow.c b/urt/rle_putrow.c
index 230720f8..399633e4 100644
--- a/urt/rle_putrow.c
+++ b/urt/rle_putrow.c
@@ -31,6 +31,7 @@
  */
  
 #include <stdio.h>
+
 #include "rle_put.h"
 #include "rle.h"
 
@@ -62,7 +63,7 @@
  * Assumptions:
  *
  * Algorithm:
- * 	Search for occurences of pixels not of the given color outside
+ * 	Search for occurrences of pixels not of the given color outside
  *	the runs already found.  When some are found, add a new run or
  *	extend an existing one.  Adjacent runs with fewer than two
  *	pixels intervening are merged.
diff --git a/urt/rle_row_alc.c b/urt/rle_row_alc.c
index 0f29523e..982e1c5e 100644
--- a/urt/rle_row_alc.c
+++ b/urt/rle_row_alc.c
@@ -28,7 +28,9 @@
  * Copyright (c) 1986, Spencer W. Thomas
  */
 
+#include <stdlib.h>
 #include <stdio.h>
+
 #include "rle.h"
 
 /*****************************************************************
diff --git a/urt/scanargs.c b/urt/scanargs.c
index b91f3e37..f3af3342 100644
--- a/urt/scanargs.c
+++ b/urt/scanargs.c
@@ -40,17 +40,14 @@
  *  to have all "void" functions so declared.
  */
 
-#include "rle.h"
 #include <stdio.h>
 #include <ctype.h>
-#ifndef USE_STDARG
-#include <varargs.h>
-#else
 #include <stdarg.h>
-#endif
 
-#include "pm_c_util.h"
-#include "nstring.h"
+#include "netpbm/pm_c_util.h"
+#include "netpbm/nstring.h"
+#include "rle_config.h"
+#include "rle.h"
 
 /* 
  * An explicit assumption is made in this code that all pointers look
@@ -68,48 +65,21 @@ typedef int *ptr;
 #define NEW( type, cnt )	(type *) malloc( (cnt) * sizeof( type ) )
 #define RENEW( type, ptr, cnt )	(type *) realloc( ptr, (cnt) * sizeof( type ) )
 
-#if defined(c_plusplus) && !defined(USE_PROTOTYPES)
-#define USE_PROTOTYPES
-#endif
-
-#ifndef USE_PROTOTYPES
-static char * prformat();
-static int isnum();
-static int	_do_scanargs();
-void		scan_usage();
-#else
 static CONST_DECL char * prformat( CONST_DECL char *, int );
 static int isnum( CONST_DECL char *, int, int );
 static int	_do_scanargs( int argc, char **argv, CONST_DECL char *format,
 			      va_list argl );
 void		scan_usage( char **, CONST_DECL char * );
-#endif
 
 /* 
  * Argument list is (argc, argv, format, ... )
  */
 int
-#ifndef USE_STDARG
-scanargs ( va_alist )
-va_dcl
-#else
 scanargs ( int argc, char **argv, CONST_DECL char *format, ... )
-#endif /* !USE_STDARG */
 {
     va_list argl;
     int retval;
-#ifndef USE_STDARG
-    int argc;
-    char ** argv;
-    CONST_DECL char *format;
-
-    va_start( argl );
-    argc = va_arg( argl, int );
-    argv = va_arg( argl, char ** );
-    format = va_arg( argl, CONST_DECL char * );
-#else
     va_start( argl, format );
-#endif
     retval = _do_scanargs( argc, argv, format, argl );
     va_end( argl );
     return retval;