From: Yoshida Hiroshi <BXH04165@nifty.ne.jp>
Subject: Add support for libjpeg6b and other misc fixes.
 Also convert to autoconf.

--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,51 @@
+#
+# Makefile for autoconf tutorial
+#
+
+CC = @CC@
+DEFS = @DEFS@
+CFLAGS = @CFLAGS@
+XLIB = @X_LIBS@ @X_PRE_LIBS@ -lX11 @X_EXTRA_LIBS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+
+SRCS = bright.c clip.c cmuwmraster.c compress.c config.c \
+dither.c faces.c fbm.c fill.c gif.c halftone.c imagetypes.c img.c jpeg.c \
+mac.c mc_tables.c mcidas.c merge.c misc.c new.c niff.c options.c \
+pbm.c pcx.c pdsuncomp.c reduce.c rle.c rlelib.c root.c rotate.c \
+send.c smooth.c sunraster.c tiff.c undither.c value.c vff.c \
+vicar.c window.c xbitmap.c xloadimage.c xpixmap.c xwd.c zio.c zoom.c
+
+OBJS = $(SRCS:.c=.o)
+PROG = xloadimage
+
+all: $(PROG) uufilter
+
+$(PROG): $(OBJS)
+	./build-info
+	$(CC) $(CFLAGS) -c $(DEFS) build.c
+	$(CC) -o $@ $(OBJS) build.o$(LDFLAGS) $(XLIB) $(LIBS)
+
+uufilter: uufilter.c
+	$(CC) $(CFLAGS) $(DEFS) uufilter.c -o $@
+
+.c.o: config.h image.h
+	$(CC) $(CFLAGS) -c $(DEFS) $<
+
+build.c:
+	./build-info
+clean:
+	rm -f $(PROG) uufilter build.c *.o
+
+distclean:
+	make clean
+	rm -f config.log config.cache config.status config.h Makefile
+
+config.h.in: configure.ac
+	autoheader
+
+configure: configure.ac
+	autoconf
+
+Makefile: Makefile.in
+	./configure
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,30 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(xloadimage.c)
+AC_CONFIG_HEADER(config.h)
+
+dnl Checks for programs.
+AC_PROG_CC
+
+dnl Checks for header files.
+AC_PATH_XTRA
+AC_HEADER_STDC
+AC_CHECK_HEADERS(malloc.h strings.h sys/time.h unistd.h)
+
+dnl Checks for libraries.
+dnl Replace `main' with a function in -lm:
+AC_CHECK_LIB(m, main)
+dnl Replace `main' with a function in -lz:
+AC_CHECK_LIB(z, main)
+dnl Replace `main' with a function in -ljpeg:
+AC_CHECK_LIB(jpeg, main)
+dnl Replace `main' with a function in -ltiff:
+AC_CHECK_LIB(tiff, main)
+
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+
+dnl Checks for library functions.
+AC_TYPE_SIGNAL
+AC_CHECK_FUNCS(mkdir select)
+
+AC_OUTPUT(Makefile)
--- /dev/null
+++ b/configure.scan
@@ -0,0 +1,32 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(buildshar.c)
+
+dnl Checks for programs.
+AC_PROG_CC
+
+dnl Checks for libraries.
+dnl Replace `main' with a function in -lX11:
+AC_CHECK_LIB(X11, main)
+dnl Replace `main' with a function in -lXext:
+AC_CHECK_LIB(Xext, main)
+dnl Replace `main' with a function in -ljpeg:
+AC_CHECK_LIB(jpeg, main)
+dnl Replace `main' with a function in -lm:
+AC_CHECK_LIB(m, main)
+dnl Replace `main' with a function in -ltiff:
+AC_CHECK_LIB(tiff, main)
+dnl Replace `main' with a function in -lz:
+AC_CHECK_LIB(z, main)
+
+dnl Checks for header files.
+AC_PATH_X
+AC_HEADER_STDC
+AC_CHECK_HEADERS(malloc.h strings.h sys/time.h unistd.h)
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+
+dnl Checks for library functions.
+AC_TYPE_SIGNAL
+AC_CHECK_FUNCS(mkdir select)
+
+AC_OUTPUT(Makefile)
--- a/fbm.c
+++ b/fbm.c
@@ -45,12 +45,12 @@ static int  fbmin_img_bits;	       /* co
 static int  fbmin_img_rowlen;	       /* length of one row of data */
 static int  fbmin_img_plnlen;	       /* length of one plane of data */
 static int  fbmin_img_clrlen;	       /* length of the colormap */
-static int  fbmin_img_aspect;	       /* image aspect ratio */
+static double  fbmin_img_aspect;	       /* image aspect ratio */
 static int  fbmin_img_physbits;	       /* physical bits per pixel */
 static char *fbmin_img_title;		/* name of image */
 static char *fbmin_img_credit;		/* credit for image */
 
-static fbmin_image_test()
+static int fbmin_image_test()
 {
   if (fbmin_img_width < 1 || fbmin_img_width > 32767) {
     fprintf (stderr, "Invalid width (%d) on input\n", fbmin_img_width);
@@ -93,7 +93,7 @@ static fbmin_image_test()
   }
 
   if (fbmin_img_aspect < 0.01 || fbmin_img_aspect > 100.0) {
-    fprintf (stderr, "Invalid aspect ratio %lg on input\n",
+    fprintf (stderr, "Invalid aspect ratio %1.3f on input\n",
 	     fbmin_img_aspect);
     return FBMIN_ERR_BAD_SD;
   }
@@ -133,7 +133,7 @@ ZFILE *s;
   fbmin_img_rowlen   = atoi(phdr.rowlen);
   fbmin_img_plnlen   = atoi(phdr.plnlen);
   fbmin_img_clrlen   = atoi(phdr.clrlen);
-  fbmin_img_aspect   = atoi(phdr.aspect);
+  fbmin_img_aspect   = atof(phdr.aspect);
   fbmin_img_physbits = atoi(phdr.physbits);
   fbmin_img_title    = phdr.title;
   fbmin_img_credit   = phdr.credits;
--- a/image.h
+++ b/image.h
@@ -8,6 +8,10 @@
  * copyright information.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "copyright.h"
 
 #include <stdio.h>
--- a/imagetypes.c
+++ b/imagetypes.c
@@ -17,6 +17,7 @@
 /* SUPPRESS 560 */
 
 extern int errno;
+extern int findImage(char *name, char *fullname);
 
 /* load a named image
  */
--- a/imagetypes.h
+++ b/imagetypes.h
@@ -28,10 +28,10 @@ Image *pdsLoad();
 #else
 Image *vicarLoad();
 #endif
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
 Image *jpegLoad();
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
 Image *tiffLoad();
 #endif
 
@@ -56,18 +56,18 @@ int pdsIdent();
 #else
 int vicarIdent();
 #endif
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
 int jpegIdent();
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
 int tiffIdent();
 #endif
 
 void niffDump();
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
 void jpegDump();
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
 void tiffDump();
 #endif
 void pbmDump();
@@ -85,10 +85,10 @@ struct {
   niffIdent,      niffLoad,      niffDump,    "niff",      "Native Image File Format (NIFF)",
   sunRasterIdent, sunRasterLoad, NULL,        "sunraster", "Sun Rasterfile",
   gifIdent,       gifLoad,       NULL,        "gif",       "GIF Image",
-#ifdef HAS_JPEG
+#ifdef HAVE_LIBJPEG
   jpegIdent,      jpegLoad,      jpegDump,    "jpeg",      "JFIF-style JPEG Image",
 #endif
-#ifdef HAS_TIFF
+#ifdef HAVE_LIBTIFF
   tiffIdent,      tiffLoad,      tiffDump,    "tiff",      "TIFF image",
 #endif
   fbmIdent,       fbmLoad,       NULL,        "fbm",       "FBM Image",
--- a/img.c
+++ b/img.c
@@ -413,7 +413,7 @@ static Image *load_img(name)
      char *name;
 {
   ZFILE           *file;
-  Image           *image;
+  Image           *image = NULL;
   unsigned long    w, h, nplanes, headlength, scanwidth;
   int              colors;
   long             i, dummy;
@@ -632,9 +632,9 @@ static Image *load_ximg(name)
 {
   void            transferRGBMap();
   ZFILE          *file;
-  Image          *image;
+  Image          *image = NULL;
   unsigned long   w, h, nplanes, scanwidth;
-  int             i, color, colors;
+  int             color, colors;
   struct RGB_LIST
   {
     unsigned int red;
--- a/jpeg.c
+++ b/jpeg.c
@@ -4,509 +4,314 @@
  * free JPEG software.  See jpeg.README for more information.
  *
  * This code is based on example.c from the IJG v4 distribution.
+ * 1998/08/19: Change for IJG v6.0a. dump Progressive JPEG support.
  */
 
 #include "image.h"	/* xloadimage declarations */
-#include "jpeg.conf.h"  /* definitions used in jpeg directory */
-#include "jpeg/jinclude.h" /* IJG declarations */
+#ifdef HAVE_LIBJPEG
+#include "options.h"
+#include <jpeglib.h>
+#include <jerror.h>
 #include <setjmp.h>	/* need setjmp/longjmp */
 
-/* Error-catching routines */
+#undef  DEBUG
+/* #define  DEBUG */
+#undef  debug
+
+#ifdef DEBUG
+# define debug(xx)	fprintf(stderr,xx)
+#else
+# define debug(xx)
+#endif
+
+static Image *image;    /* xloadimage image being returned */
 
 static char *filename;
-static unsigned int verbose;
-static unsigned int identify;
 static jmp_buf setjmp_buffer;	/* for return to caller */
-static external_methods_ptr emethods; /* needed for access to message_parm */
+ZFILE * zinput_file;	/* tells input routine where to read JPEG */
+static JOCTET jpeg_read_buff[1024 * 16];
 
-static void
-trace_message (msgtext)
-     char *msgtext;
+/*
+ * source manager
+ */
+static void init_source( j_decompress_ptr cinfo)
 {
-  fprintf(stderr, "jpegLoad: %s - ", filename);
-  fprintf(stderr, msgtext,
-	  emethods->message_parm[0], emethods->message_parm[1],
-	  emethods->message_parm[2], emethods->message_parm[3],
-	  emethods->message_parm[4], emethods->message_parm[5],
-	  emethods->message_parm[6], emethods->message_parm[7]);
-  fprintf(stderr, "\n");	/* there is no \n in the format string! */
-}
 
-static void
-error_exit (msgtext)
-     char *msgtext;
-{
-  trace_message(msgtext);	/* report the error message */
-  (*emethods->free_all) ();	/* clean up memory allocation & temp files */
-  longjmp(setjmp_buffer, 1);	/* return control to outer routine */
+    debug("init_source()");
 }
 
+static boolean fill_input_buffer( j_decompress_ptr cinfo)
+{
+    struct jpeg_source_mgr *src = cinfo->src;
 
-/* Output-acceptance routines */
-
-static Image *image;		/* xloadimage image being returned */
-static int rows_put;		/* Number of rows copied to image */
-
-
-static void
-output_init (cinfo)
-     decompress_info_ptr cinfo;
-/* Initialize for output */
-{
-  int i;
-
-  if (cinfo->out_color_space == CS_GRAYSCALE) {
-    image = newRGBImage(cinfo->image_width,cinfo->image_height,8);
-    image->title = dupString(filename);
-    /* set a linear map */
-    for(i=0;i<256;i++) {
-      *(image->rgb.red + i) = 
-	*(image->rgb.green + i) = 
-	  *(image->rgb.blue + i) = i<<8;
-    }
-    image->rgb.used = 256;
-  } else if (cinfo->out_color_space == CS_RGB) {
-    image = newTrueImage(cinfo->image_width,cinfo->image_height);
-    image->title = dupString(filename);
-  } else {
-    image = NULL;
-    ERREXIT(cinfo->emethods, "Cannot cope with JPEG image colorspace");
-  }
-  rows_put = 0;
+    debug("fill_input_buffer()");
+#ifdef DEBUG
+    fprintf( stderr,"fill_input_buffer(): %d  ",src->bytes_in_buffer);
+#endif
+    src->next_input_byte = jpeg_read_buff;
+    src->bytes_in_buffer = zread(zinput_file,
+				 jpeg_read_buff, sizeof(jpeg_read_buff));
+    if(src->bytes_in_buffer <= 0){
+	WARNMS(cinfo, JWRN_JPEG_EOF);
+	jpeg_read_buff[0] = 0xFF;
+	jpeg_read_buff[1] = JPEG_EOI;
+	src->bytes_in_buffer = 2;
+    }
+    return TRUE;
+}
+
+static void skip_input_data( j_decompress_ptr cinfo, long num_bytes)
+{
+    int rest;
+    struct jpeg_source_mgr *src = cinfo->src;
+
+    debug("skip_input_data()");
+#ifdef DEBUG
+    fprintf(stderr,": %ld,%d  ", num_bytes, src->bytes_in_buffer);
+#endif
+    if( num_bytes < 1) return;
+    rest = src->bytes_in_buffer;
+    if( num_bytes < rest) {
+	src->next_input_byte += num_bytes;
+	src->bytes_in_buffer -= num_bytes;;
+	return;
+    }
+    num_bytes -= rest;
+    while( num_bytes--) {
+	zgetc(zinput_file);
+    }
+    fill_input_buffer(cinfo);
 }
 
-
-static void
-put_color_map (cinfo, num_colors, colormap)
-     decompress_info_ptr cinfo;
-     int num_colors;
-     JSAMPARRAY colormap;
-/* Write the color map -- should not be called */
+static boolean resync_to_restart( j_decompress_ptr cinfo, int desired)
 {
-  fprintf(stderr, "put_color_map called: there is a bug here somewhere!\n");
+    return jpeg_resync_to_restart( cinfo, desired);
 }
 
-
-static void
-put_pixel_rows (cinfo, num_rows, pixel_data)
-     decompress_info_ptr cinfo;
-     int num_rows;
-     JSAMPIMAGE pixel_data;
-/* Write some rows of output data */
-{
-  register unsigned char *bufp;
-  register JSAMPROW ptr0, ptr1, ptr2;
-  register long col;
-  long width = cinfo->image_width;
-  int row;
-  
-  if (cinfo->out_color_space == CS_GRAYSCALE) {
-    bufp = image->data + rows_put * width;
-    /* Assume JSAMPLE == chars */
-    for (row = 0; row < num_rows; row++) {
-      bcopy(pixel_data[0][row],bufp,width);
-      bufp += width;
-    }
-  } else {
-    bufp = image->data + rows_put * width * 3;
-    for (row = 0; row < num_rows; row++) {
-      ptr0 = pixel_data[0][row];
-      ptr1 = pixel_data[1][row];
-      ptr2 = pixel_data[2][row];
-      for (col = width; col > 0; col--) {
-	*bufp++ = *ptr0++;
-	*bufp++ = *ptr1++;
-	*bufp++ = *ptr2++;
-      }
-    }
-  }
-  rows_put += num_rows;
+static void term_source( j_decompress_ptr cinfo)
+{
+    debug("term_source()");
 }
 
-
+/*
+ *  error manager
+ */
 static void
-output_term (cinfo)
-     decompress_info_ptr cinfo;
-/* Finish up at the end of the output */
+output_message ( j_common_ptr cominfo)
 {
-  /* No work here */
-}
-
+    char buf[JMSG_LENGTH_MAX];
 
-/* Input-file-reading routine */
-
-
-static ZFILE * input_file;	/* tells input routine where to read JPEG */
+    (*cominfo->err->format_message)(cominfo, buf);
+    fprintf(stderr, "jpegLoad: %s - %s\n", filename, buf);
+}
 
 
-static int
-read_jpeg_data (cinfo)
-     decompress_info_ptr cinfo;
+static void error_exit (j_common_ptr cominfo)
 {
-  cinfo->next_input_byte = cinfo->input_buffer + MIN_UNGET;
-
-  cinfo->bytes_in_buffer = zread(input_file,
-				 (byte *)cinfo->next_input_byte,
-				 JPEG_BUF_SIZE);
-  
-  if (cinfo->bytes_in_buffer <= 0) {
-    WARNMS(cinfo->emethods, "Premature EOF in JPEG file");
-    cinfo->next_input_byte[0] = (char) 0xFF;
-    cinfo->next_input_byte[1] = (char) 0xD9; /* EOI marker */
-    cinfo->bytes_in_buffer = 2;
-  }
-
-  return JGETC(cinfo);
+    output_message( cominfo);
+    longjmp(setjmp_buffer, 1);	/* return control to outer routine */
 }
 
 
-/*  Required control-hook routine */
-
-
 static void
-d_ui_method_selection (cinfo)
-     decompress_info_ptr cinfo;
+jpegInfo (cinfo)
+     j_decompress_ptr cinfo;
 {
-  /* if grayscale input, force grayscale output; */
-  /* else leave the output colorspace as set by main routine. */
-  if (cinfo->jpeg_color_space == CS_GRAYSCALE)
-    cinfo->out_color_space = CS_GRAYSCALE;
-
-  /* Create display of image parameters */
-  if (verbose) {
+    /* Create display of image parameters */
     printf("%s is a %dx%d JPEG image, color space ", filename,
 	   cinfo->image_width, cinfo->image_height);
     switch (cinfo->jpeg_color_space) {
-    case CS_UNKNOWN:
-      printf("Unknown");
-      break;
-    case CS_GRAYSCALE:
-      printf("Grayscale");
-      break;
-    case CS_RGB:
-      printf("RGB");
-      break;
-    case CS_YCbCr:
-      printf("YCbCr");
-      break;
-    case CS_YIQ:
-      printf("YIQ");
-      break;
-    case CS_CMYK:
-      printf("CMYK");
-      break;
+    case JCS_GRAYSCALE:
+	printf("Grayscale");
+	break;
+    case JCS_RGB:
+	printf("RGB");
+	break;
+    case JCS_YCbCr:
+	printf("YCbCr");
+	break;
+    case JCS_CMYK:
+	printf("CMYK");
+	break;
+    case JCS_YCCK:
+	printf("YCCK");
+	break;
+    case JCS_UNKNOWN:
+    default:
+	printf("Unknown");
+	break;
     }
     printf(", %d comp%s,", cinfo->num_components,
-	   cinfo->num_components ? "s." : ".");
+	   (cinfo->num_components - 1) ? "s" : "");
+    if (cinfo->progressive_mode)
+	printf(" Progressive,");
     if (cinfo->arith_code)
-      printf(" Arithmetic coding\n");
+	printf(" Arithmetic coding.\n");
     else
-      printf(" Huffman coding\n");
-  }
-
-  /* Turn off caching beyond this point of the file */
-  znocache(input_file);
-
-  /* If we only wanted to identify the image, abort now */
-  if (identify) {
-    (*emethods->free_all) ();	/* clean up memory allocation & temp files */
-    longjmp(setjmp_buffer, 10);	/* return control with success code */
-  }
-
-  /* select output routines */
-  cinfo->methods->output_init = output_init;
-  cinfo->methods->put_color_map = put_color_map;
-  cinfo->methods->put_pixel_rows = put_pixel_rows;
-  cinfo->methods->output_term = output_term;
+	printf(" Huffman coding.\n");
 }
 
 
 /* Main control routine for loading */
 
-
 Image *
-jpegLoad (fullname, name, vbose)
+jpegLoad (fullname, name, verbose)
      char *fullname, *name;
-     unsigned int vbose;
+     unsigned int verbose;
 {
-  struct Decompress_info_struct cinfo;
-  struct Decompress_methods_struct dc_methods;
-  struct External_methods_struct e_methods;
-
-  input_file = zopen(fullname);	/* Open the input file */
-  if (input_file == NULL)
-    return NULL;
-
-  /* Quick check to see if file starts with JPEG SOI marker */
-  if (zgetc(input_file) != 0xFF || zgetc(input_file) != 0xD8) {
-    zclose(input_file);
-    return NULL;
-  }
+    struct jpeg_decompress_struct cinfo;
+    struct jpeg_source_mgr src_mgr;
+    struct jpeg_error_mgr err_mgr;
+    int i, row_stride;
+    byte *bufp;
+
+    zinput_file = zopen(fullname);	/* Open the input file */
+    if (zinput_file == NULL)
+	return NULL;
+    filename = name;		/* copy parms to static vars */
+    image = NULL;		/* in case we fail before creating image */
+
+    jpeg_create_decompress(&cinfo);
+    src_mgr.init_source = init_source;
+    src_mgr.fill_input_buffer = fill_input_buffer;
+    src_mgr.skip_input_data = skip_input_data;
+    src_mgr.resync_to_restart = resync_to_restart;
+    src_mgr.term_source = term_source;
+    cinfo.src = &src_mgr;	/* links to method structs */
+    err_mgr.error_exit = error_exit; /* supply error-exit routine */
+    err_mgr.output_message = output_message;
+    err_mgr.trace_level = 0;	/* default = no tracing */
+    err_mgr.num_warnings = 0;	/* no warnings emitted yet */
+    cinfo.err = jpeg_std_error(&err_mgr);
+
+    src_mgr.bytes_in_buffer = 0;
+    fill_input_buffer( &cinfo);
+    /* Quick check to see if file starts with JPEG SOI marker */
+    if(jpeg_read_buff[0] != 0xFF || jpeg_read_buff[1] != 0xD8) {
+	zclose(zinput_file);
+	return NULL;
+    }
+
+    /* prepare setjmp context for possible exit from error_exit */
+    if (setjmp(setjmp_buffer)) {
+	/* If we get here, the JPEG code has signaled an error. */
+	/* Return as much of the image as we could get. */
+	jpeg_destroy_decompress(&cinfo);
+	zclose(zinput_file);
+	return image;
+    }
+
+    jpeg_read_header(&cinfo, TRUE);
+    if (verbose) jpegInfo(&cinfo);
+    /* Turn off caching beyond this point of the file */
+    znocache(zinput_file);
+    jpeg_start_decompress(&cinfo);
+
+    switch (cinfo.out_color_space) {
+    case JCS_GRAYSCALE:
+	image = newRGBImage(cinfo.image_width,cinfo.image_height,8);
+	image->title = dupString(filename);
+	/* set a linear map */
+	for(i=0;i<256;i++) {
+	    *(image->rgb.red + i) =
+		*(image->rgb.green + i) =
+		*(image->rgb.blue + i) = i << 8;
+	}
+	image->rgb.used = 256;
+	break;
+    case JCS_RGB:
+	image = newTrueImage(cinfo.image_width,cinfo.image_height);
+	image->title = dupString(filename);
+	break;
+    default:
+	image = NULL;
+	ERREXITS(&cinfo, 1, "Cannot cope with JPEG image colorspace");
+    }
+
+    row_stride = cinfo.output_width * cinfo.output_components;
+    bufp = image->data;
+    while (cinfo.output_scanline < cinfo.output_height) {
+	jpeg_read_scanlines(&cinfo, &bufp, 1);
+	bufp += row_stride;
+    }
+
+    jpeg_finish_decompress(&cinfo);
+    jpeg_destroy_decompress(&cinfo);
+    zclose(zinput_file);		/* Done, close the input file */
 
-  filename = name;		/* copy parms to static vars */
-  verbose = vbose;
-  identify = 0;
-
-  image = NULL;			/* in case we fail before creating image */
-
-  cinfo.methods = &dc_methods;	/* links to method structs */
-  cinfo.emethods = &e_methods;
-  emethods = &e_methods;	/* save struct addr for possible access */
-  e_methods.error_exit = error_exit; /* supply error-exit routine */
-  e_methods.trace_message = trace_message; /* supply trace-message routine */
-  e_methods.trace_level = 0;	/* default = no tracing */
-  e_methods.num_warnings = 0;	/* no warnings emitted yet */
-  e_methods.first_warning_level = 0; /* display first corrupt-data warning */
-  e_methods.more_warning_level = 3; /* but suppress additional ones */
-
-  /* prepare setjmp context for possible exit from error_exit */
-  if (setjmp(setjmp_buffer)) {
-    /* If we get here, the JPEG code has signaled an error. */
-    /* Return as much of the image as we could get. */
-    zclose(input_file);
     return image;
-  }
-
-  jselmemmgr(&e_methods);	/* select std memory allocation routines */
-
-  /* Set up default decompression parameters. */
-  j_d_defaults(&cinfo, TRUE);
-
-  /* Override default methods */
-  dc_methods.d_ui_method_selection = d_ui_method_selection;
-  dc_methods.read_jpeg_data = read_jpeg_data;
-
-  /* Insert fake SOI into the input buffer --- needed cause we read it above */
-  cinfo.next_input_byte = cinfo.input_buffer + MIN_UNGET;
-  cinfo.next_input_byte[0] = (char) 0xFF;
-  cinfo.next_input_byte[1] = (char) 0xD8; /* SOI marker */
-  cinfo.bytes_in_buffer = 2;
-
-  /* Set up to read a JFIF or baseline-JPEG file. */
-  /* This is the only JPEG file format currently supported. */
-  jselrjfif(&cinfo);
-
-  /* Here we go! */
-  jpeg_decompress(&cinfo);
-
-  zclose(input_file);		/* Done, close the input file */
-
-  return image;
 }
 
 
-/* Main control routine for identifying JPEG without loading */
-
-
+/*
+  Main control routine for identifying JPEG without loading
+  return 0: Not jpeg file.
+  */
 int
 jpegIdent (fullname, name)
      char *fullname, *name;
 {
-  struct Decompress_info_struct cinfo;
-  struct Decompress_methods_struct dc_methods;
-  struct External_methods_struct e_methods;
-
-  input_file = zopen(fullname);	/* Open the input file */
-  if (input_file == NULL)
-    return 0;
-
-  /* Quick check to see if file starts with JPEG SOI marker */
-  if (zgetc(input_file) != 0xFF || zgetc(input_file) != 0xD8) {
-    zclose(input_file);
-    return 0;
-  }
+    struct jpeg_decompress_struct cinfo;
+    struct jpeg_source_mgr src_mgr;
+    struct jpeg_error_mgr err_mgr;
+
+    zinput_file = zopen(fullname);	/* Open the input file */
+    if (zinput_file == NULL)
+	return 0;
+
+    filename = name;		/* copy parms to static vars */
+
+    jpeg_create_decompress(&cinfo);
+    src_mgr.init_source = init_source;
+    src_mgr.fill_input_buffer = fill_input_buffer;
+    src_mgr.skip_input_data = skip_input_data;
+    src_mgr.resync_to_restart = resync_to_restart;
+    src_mgr.term_source = term_source;
+    cinfo.src = &src_mgr;	/* links to method structs */
+    err_mgr.error_exit = error_exit; /* supply error-exit routine */
+    err_mgr.output_message = output_message;
+    err_mgr.trace_level = 0;	/* default = no tracing */
+    err_mgr.num_warnings = 0;	/* no warnings emitted yet */
+    cinfo.err = jpeg_std_error(&err_mgr);
+
+    src_mgr.bytes_in_buffer = 0;
+    fill_input_buffer( &cinfo);
+    /* Quick check to see if file starts with JPEG SOI marker */
+    if(jpeg_read_buff[0] != 0xFF || jpeg_read_buff[1] != 0xD8) {
+	jpeg_destroy_decompress(&cinfo);
+	zclose(zinput_file);
+	return 0;
+    }
+
+    /* prepare setjmp context for expected exit via longjmp */
+    if (setjmp(setjmp_buffer)) {
+	/* If we get here, the JPEG code has signaled an error. */
+	/* Return 0 since error in the headers means the image is unloadable. */
+	jpeg_destroy_decompress(&cinfo);
+	zclose(zinput_file);
+	return 0;
+    }
+
+    jpeg_read_header(&cinfo, TRUE);
+    jpegInfo(&cinfo);
+    /* Turn off caching beyond this point of the file */
+    znocache(zinput_file);
+    jpeg_destroy_decompress(&cinfo);
+    zclose(zinput_file);
 
-  /* We want to find and display the image dimensions, and also
-   * verify that the header markers are not corrupt.  To do this,
-   * we fire up the JPEG decoder as normal, but when d_ui_method_selection
-   * is called, we abort the process by longjmp'ing back here.
-   * This works nicely since the headers are all read at that point.
-   */
-
-  filename = name;		/* copy parms to static vars */
-  verbose = 1;
-  identify = 1;
-
-  cinfo.methods = &dc_methods;	/* links to method structs */
-  cinfo.emethods = &e_methods;
-  emethods = &e_methods;	/* save struct addr for possible access */
-  e_methods.error_exit = error_exit; /* supply error-exit routine */
-  e_methods.trace_message = trace_message; /* supply trace-message routine */
-  e_methods.trace_level = 0;	/* default = no tracing */
-  e_methods.num_warnings = 0;	/* no warnings emitted yet */
-  e_methods.first_warning_level = 0; /* display first corrupt-data warning */
-  e_methods.more_warning_level = 3; /* but suppress additional ones */
-
-  /* prepare setjmp context for expected exit via longjmp */
-  switch (setjmp(setjmp_buffer)) {
-  case 0:
-    /* First time thru, keep going */
-    break;
-  case 10:
-    /* Successful exit from d_ui_method_selection; return A-OK */
-    zclose(input_file);
     return 1;
-  default:
-    /* If we get here, the JPEG code has signaled an error. */
-    /* Return 0 since error in the headers means the image is unloadable. */
-    zclose(input_file);
-    return 0;
-  }
-
-  jselmemmgr(&e_methods);	/* select std memory allocation routines */
-
-  /* Set up default decompression parameters. */
-  j_d_defaults(&cinfo, TRUE);
-
-  /* Override default methods */
-  dc_methods.d_ui_method_selection = d_ui_method_selection;
-  dc_methods.read_jpeg_data = read_jpeg_data;
-
-  /* Insert fake SOI into the input buffer --- needed cause we read it above */
-  cinfo.next_input_byte = cinfo.input_buffer + MIN_UNGET;
-  cinfo.next_input_byte[0] = (char) 0xFF;
-  cinfo.next_input_byte[1] = (char) 0xD8; /* SOI marker */
-  cinfo.bytes_in_buffer = 2;
-
-  /* Set up to read a JFIF or baseline-JPEG file. */
-  /* This is the only JPEG file format currently supported. */
-  jselrjfif(&cinfo);
-
-  /* Here we go! */
-  jpeg_decompress(&cinfo);
-
-  /* Don't expect to get here since d_ui_method_selection should do longjmp */
-
-  zclose(input_file);
-  return 0;
-}
-
-/* information necessary to extract image data
- */
-static struct {
-  Image *image;
-  byte *current_row;
-  unsigned int bytes_per_row;
-} ReadInfo;
-
-static void input_init(cinfo)
-compress_info_ptr cinfo;
-{
-  /* this is done in jpegDump()
-   */
-}
-
-static void input_term(cinfo)
-compress_info_ptr cinfo;
-{
-  /* there is no shutdown necessary
-   */
-}
-
-/* this reads a single raster line
- */
-static void read_row(cinfo, pixel_rows)
-     compress_info_ptr cinfo;
-     JSAMPARRAY pixel_rows;
-{
-  register int x;
-  register int pixlen;
-  register byte *src_row_ptr;
-  register byte *dest_red_ptr;
-  register byte *dest_green_ptr;
-  register byte *dest_blue_ptr;
-  register Pixel pixval;
-  register byte mask;
-
-  switch (ReadInfo.image->type) {
-  case IBITMAP:
-    mask = 0x80;
-    src_row_ptr = ReadInfo.current_row;
-    dest_red_ptr = (byte *)pixel_rows[0];
-    for (x = 0; x < cinfo->image_width; x++) {
-      pixval = ((*src_row_ptr & mask) > 0 ? 1 : 0);
-
-      /* we use the "red" color value under the assumption that they
-       * are all equal.  that can be wrong if the user used -foreground
-       * or -background.  I don't care right now.
-       */
-      *(dest_red_ptr++) = ReadInfo.image->rgb.red[pixval] >> 8;
-      mask >>= 1;
-      if (mask == 0) {
-	mask = 0x80;
-	src_row_ptr++;
-      }
-    }
-    break;
-
-  case IRGB:
-    /* this expands the pixel value into its components
-     */
-    pixlen = ReadInfo.image->pixlen;
-    src_row_ptr = ReadInfo.current_row;
-    dest_red_ptr = (byte *)pixel_rows[0];
-    dest_green_ptr = (byte *)pixel_rows[1];
-    dest_blue_ptr = (byte *)pixel_rows[2];
-    for (x = 0; x < cinfo->image_width; x++) {
-      pixval = memToVal(src_row_ptr, pixlen);
-      *(dest_red_ptr++) = ReadInfo.image->rgb.red[pixval] >> 8;
-      *(dest_green_ptr++) = ReadInfo.image->rgb.green[pixval] >> 8;
-      *(dest_blue_ptr++) = ReadInfo.image->rgb.blue[pixval] >> 8;
-      src_row_ptr += pixlen;
-    }
-    break;
-
-  case ITRUE:
-    src_row_ptr = ReadInfo.current_row;
-    dest_red_ptr = (byte *)pixel_rows[0];
-    dest_green_ptr = (byte *)pixel_rows[1];
-    dest_blue_ptr = (byte *)pixel_rows[2];
-    for (x = 0; x < cinfo->image_width; x++) {
-      *(dest_red_ptr++) = *(src_row_ptr++);
-      *(dest_green_ptr++) = *(src_row_ptr++);
-      *(dest_blue_ptr++) = *(src_row_ptr++);
-    }
-    break;
-  }
-  ReadInfo.current_row += ReadInfo.bytes_per_row;
 }
 
 /*
- * This routine gets control after the input file header has been read.
- * It must determine what output JPEG file format is to be written,
- * and make any other compression parameter changes that are desirable.
+ * Dump Jpeg
  */
 
-static void
-c_ui_method_selection (cinfo)
-     compress_info_ptr cinfo;
-{
-  /* If the input is gray scale, generate a monochrome JPEG file. */
-  if (cinfo->in_color_space == CS_GRAYSCALE)
-    j_monochrome_default(cinfo);
-  jselwjfif(cinfo);
-}
-
 /* parse options passed to jpegDump
  */
-static void parseOptions(cinfo, options, verbose)
-     compress_info_ptr cinfo;
-     char *options;
-     int verbose;
+static void parseOptions(j_compress_ptr cinfo, char *options, int verbose)
 {
   char *name, *value;
 
-  /* (Re-)initialize the system-dependent error and memory managers. */
-  jselerror(cinfo->emethods);	/* error/trace message routines */
-  jselmemmgr(cinfo->emethods);	/* memory allocation routines */
-  cinfo->methods->c_ui_method_selection = c_ui_method_selection;
-
-  /* Set up default JPEG parameters. */
-  /* Note that default -quality level here need not, and does not,
-   * match the default scaling for an explicit -qtables argument.
-   */
-  j_c_defaults(cinfo, 75, FALSE); /* default quality level = 75 */
-
   while (getNextTypeOption(&options, &name, &value) > 0) {
     if (!strncmp("arithmetic", name, strlen(name))) {
       /* Use arithmetic coding. */
@@ -524,7 +329,7 @@ static void parseOptions(cinfo, options,
       /* Force a monochrome JPEG file to be generated. */
       if (verbose)
 	printf("  Creating a grayscale/monochrome file.\n");
-      j_monochrome_default(cinfo);
+      jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
     }
     else if (!strncmp("nointerleave", name, strlen(name))) {
       /* Create noninterleaved file. */
@@ -536,16 +341,18 @@ static void parseOptions(cinfo, options,
       fprintf(stderr, "jpegDump: sorry, multiple-scan support was not compiled\n");
 #endif
     }
+    else if (!strncmp("progressive", name, strlen(name))) {
+      /* Enable progressive JPEG. */
+      if (verbose)
+	printf("  Progressive JPEG.\n");
+      jpeg_simple_progression (cinfo);
+    }
     else if (!strncmp("optimize", name, strlen(name)) ||
 	     !strncmp("optimise", name, strlen(name))) {
       /* Enable entropy parm optimization. */
-#ifdef ENTROPY_OPT_SUPPORTED
       if (verbose)
 	printf("  Optimizing entropy.\n");
       cinfo->optimize_coding = TRUE;
-#else
-      fprintf(stderr, "jpegDump: sorry, entropy optimization was not compiled\n");
-#endif
     }
     else if (!strncmp("quality", name, strlen(name))) {
       /* Quality factor (quantization table scaling factor). */
@@ -561,7 +368,7 @@ static void parseOptions(cinfo, options,
 	 */
 	if (verbose)
 	  printf("  Using a quality factor of %d.\n", val);
-	j_set_quality(cinfo, val, FALSE);
+	jpeg_set_quality(cinfo, val, FALSE);
 #if 0
 	/* Change scale factor in case -qtables is present. */
 	q_scale_factor = j_quality_scaling(val);
@@ -626,74 +433,134 @@ static void parseOptions(cinfo, options,
   }
 }
 
-void jpegDump(image, options, file, verbose)
-    Image *image;
-    char *options;
-    char *file;
-{
-  struct Compress_info_struct cinfo;
-  struct Compress_methods_struct c_methods;
-  struct External_methods_struct e_methods;
-
-  if (verbose)
-    printf("Dumping JFIF-style JPEG image to %s.\n", file);
-
-  /* Set up links to method structures. */
-  cinfo.methods = &c_methods;
-  cinfo.emethods = &e_methods;
-
-  /* set up "input methods" that handle "reading" from our image file
-   */
-  cinfo.methods->input_init = input_init;
-  cinfo.methods->input_term = input_term;
-  cinfo.methods->get_input_row = read_row;
-
-  /* set up output file; there is no input file
-   */
-  cinfo.input_file = NULL;
-  cinfo.output_file = fopen(file, "w");
-  if (cinfo.output_file == NULL) {
-    perror(file);
-    return;
-  }
+/* this reads a single raster line
+ */
 
-  ReadInfo.image = image;
-  ReadInfo.current_row = image->data;
+byte *current_row;
+unsigned int bytes_per_row;
 
-  /* parse the options the user gave us
-   */
-  parseOptions(&cinfo, options, verbose);
-
-  /* set up image information
-   */
-  cinfo.image_width = image->width;
-  cinfo.image_height = image->height;
-
-  switch (image->type) {
-  case IBITMAP:
-    ReadInfo.bytes_per_row = (image->width / 8) + (image->width % 8 ? 1 : 0);
-    cinfo.input_components = 1;
-    cinfo.in_color_space = CS_GRAYSCALE;
-    cinfo.data_precision = 8;
-    break;
-  case IRGB:
-    ReadInfo.bytes_per_row = image->width * image->pixlen;
-    cinfo.input_components = 3;
-    cinfo.in_color_space = CS_RGB;
-    cinfo.data_precision = 8;
-    break;
-  case ITRUE:
-    ReadInfo.bytes_per_row = image->width * image->pixlen;
-    cinfo.input_components = 3;
-    cinfo.in_color_space = CS_RGB;
-    cinfo.data_precision = 8;
-    break;
-  }
+static byte *read_row(Image *image, byte *pixel_rows)
+{
+    int x;
+    int pixlen;
+    byte *src_row_ptr = current_row;
+    byte *dest_row_ptr = pixel_rows;
+    Pixel pixval;
+    byte mask;
+
+    switch (image->type) {
+    case IBITMAP:
+	mask = 0x80;
+	for (x = 0; x < image->width; x++) {
+	    pixval = ((*src_row_ptr & mask) > 0 ? 1 : 0);
+
+	    /* we use the "red" color value under the assumption that they
+	     * are all equal.  that can be wrong if the user used -foreground
+	     * or -background.  I don't care right now.
+	     */
+	    *dest_row_ptr++ = image->rgb.red[pixval] >> 8;
+	    mask >>= 1;
+	    if (mask == 0) {
+		mask = 0x80;
+		src_row_ptr++;
+	    }
+	}
+	break;
 
-  /* compress, baby
-   */
-  jpeg_compress(&cinfo);
+    case IRGB:
+	/* this expands the pixel value into its components
+	 */
+	pixlen = image->pixlen;
+	for (x = 0; x < image->width; x++) {
+	    pixval = memToVal(src_row_ptr, pixlen);
+	    *dest_row_ptr++ = image->rgb.red[pixval] >> 8;
+	    *dest_row_ptr++ = image->rgb.green[pixval] >> 8;
+	    *dest_row_ptr++ = image->rgb.blue[pixval] >> 8;
+	    src_row_ptr += pixlen;
+	}
+	break;
+
+    case ITRUE:
+	return current_row;
+	break;
+    }
+    return pixel_rows;
+}
+
+void jpegDump(Image *image, char *options, char *file, int verbose)
+{
+    struct jpeg_compress_struct cinfo;
+    struct jpeg_error_mgr jerr;
+    FILE * outfile;		/* target file */
+    JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
+
+    cinfo.err = jpeg_std_error(&jerr);
+    jpeg_create_compress(&cinfo);
+
+    if ((outfile = fopen(file, "w")) == NULL) {
+	perror(file);
+	return;
+    }
+    jpeg_stdio_dest(&cinfo, outfile);
+
+    cinfo.image_width = image->width;
+    cinfo.image_height = image->height;
+
+    /* set # of color components per pixel & colospace fo input image */
+    switch (image->type) {
+    case IBITMAP:
+	bytes_per_row = (image->width / 8) + (image->width % 8 ? 1 : 0);
+	cinfo.input_components = 1;
+	cinfo.in_color_space = JCS_GRAYSCALE;
+	row_pointer[0] = lmalloc( cinfo.image_width * cinfo.input_components);
+	break;
+    case IRGB:
+	bytes_per_row = image->width * image->pixlen;
+	cinfo.input_components = 3;
+	cinfo.in_color_space = JCS_RGB;    /* colorspace of input image */
+	row_pointer[0] = lmalloc( cinfo.image_width * cinfo.input_components);
+	break;
+    case ITRUE:
+	bytes_per_row = image->width * image->pixlen;
+	cinfo.input_components = 3;
+	cinfo.in_color_space = JCS_RGB;    /* colorspace of input image */
+	row_pointer[0] = image->data;
+	break;
+    }
+    /* Now use the library's routine to set default compression parameters.
+     * (You must set at least cinfo.in_color_space before calling this,
+     * since the defaults depend on the source color space.)
+     */
+    jpeg_set_defaults(&cinfo);
+    /* Now you can set any non-default parameters you wish to.
+     * Here we just illustrate the use of quality (quantization table) scaling:
+     */
+    jpeg_set_quality(&cinfo, 75, TRUE /* limit to baseline-JPEG values */);
+    if( cinfo.in_color_space == JCS_GRAYSCALE)
+	jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE);
+    parseOptions(&cinfo, options, verbose);
+
+    jpeg_start_compress(&cinfo, TRUE);
+
+    current_row = image->data;
+    while (cinfo.next_scanline < cinfo.image_height) {
+	/* jpeg_write_scanlines expects an array of pointers to scanlines.
+	 * Here the array is only one element long, but you could pass
+	 * more than one scanline at a time if that's more convenient.
+	 */
+	row_pointer[0] = read_row(image, row_pointer[0]);
+	(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
+	current_row += bytes_per_row;
+    }
 
-  fclose(cinfo.output_file);
-  return;
+    jpeg_finish_compress(&cinfo);
+    fclose(outfile);
+    jpeg_destroy_compress(&cinfo);
+    if (image->type == IBITMAP || image->type == IRGB) {
+	lfree( row_pointer[0]);
+    }
 }
+
+#else /* !HAVE_LIBJPEG */
+static int unused;
+#endif /* !HAVE_LIBJPEG */
--- a/misc.c
+++ b/misc.c
@@ -32,8 +32,10 @@ static char *signalName(sig)
   switch (sig) {
   case SIGSEGV:
     return("SEGV");
+#ifdef	SIGBUS
   case SIGBUS:
     return("BUS");
+#endif
   case SIGFPE:
     return("FPE");
   case SIGILL:
--- a/niff.c
+++ b/niff.c
@@ -8,6 +8,7 @@
  * this is in the public domain.
  */
 
+#include <unistd.h>
 #include "image.h"
 #include "niff.h"
 
@@ -17,8 +18,7 @@ static void babble(name, header, title)
 {
   printf("%s is a %dx%d ", name,
 	 memToVal(header->width, 4),
-	 memToVal(header->height, 4),
-	 memToVal(header->depth, 4));
+	 memToVal(header->height, 4));
   if (memToVal(header->version, 4) != NIFF_VERSION)
     printf("version %d ", memToVal(header->version, 4));
   printf("NIFF ");
@@ -121,8 +121,8 @@ Image *niffLoad(fullname, name, verbose)
   struct niff_header header;
   char *title;
   unsigned int width, height, depth;
-  Image *image;
-  unsigned int data_size;
+  Image *image = NULL;
+  unsigned int data_size = 0;
 
   if (! (zf= zopen(fullname)))
     return(NULL);
@@ -191,7 +191,7 @@ void niffDump(image, options, filename,
   unsigned int a;
   struct niff_header header;
   struct niff_cmap cmap;
-  unsigned int data_size;
+  unsigned int data_size = 0;
 
   if (verbose)
     printf("Dumping NIFF image to %s.\n", filename);
--- a/pbm.c
+++ b/pbm.c
@@ -12,6 +12,7 @@
  */
 
 #include "image.h"
+#include "options.h"
 #include "pbm.h"
 
 /* SUPPRESS 558 */
@@ -188,14 +189,14 @@ Image *pbmLoad(fullname, name, verbose)
      char         *fullname, *name;
      unsigned int  verbose;
 { ZFILE        *zf;
-  Image        *image;
+  Image        *image = NULL;
   int           pbm_type;
   int           x, y;
   int           width, height, maxval, depth;
   unsigned int  linelen;
   byte          srcmask, destmask;
   byte         *destptr, *destline;
-  int           src, size;
+  int           src = 0, size;
   int           red, grn, blu;
 
   if (! (zf= zopen(fullname)))
--- a/rlelib.c
+++ b/rlelib.c
@@ -980,7 +980,8 @@ struct sv_globals * globals;
  *	Returns code.
  */
 
-rle_get_error( code, pgmname, fname )
+int rle_get_error( code, pgmname, fname )
+int code;
 char *pgmname;
 char *fname;
 {
@@ -1595,7 +1596,7 @@ int magic[16][16];
 
 	total = size * size;
 
-	i = 0;
+	i = bx = by = 0;
 	li = -1;
 	for(j=0;j<total;j++)	
 	{
--- a/sunraster.c
+++ b/sunraster.c
@@ -240,7 +240,8 @@ Image *sunRasterLoad(fullname, name, ver
   case RTIFF: /* sorry, don't even know what these are */
   case RIFF:
   default:
-    fprintf(stderr, "%s: Unsupported Sun Rasterfile image type (sorry)\n");
+    fprintf(stderr, "%s: Unsupported Sun Rasterfile image type (sorry)\n",
+	    name);
     return(NULL);
   }
 
--- a/tiff.c
+++ b/tiff.c
@@ -5,10 +5,10 @@
  * jim frost 09.05.93
  */
 
-#ifdef HAS_TIFF
-
 #include "image.h"
-#include "tiff/tiffio.h"
+#ifdef HAVE_LIBTIFF
+
+#include <tiffio.h>
 
 /* this structure contains all the information we care about WRT a TIFF
  * image.
@@ -217,7 +217,7 @@ static void babble(name, info)
 	   compressionName(info->compression));
   }
   if (info->title)
-    printf("Titled \"%s\"");
+    printf("Titled \"%s\"", info->title);
   printf("\n");
 }
 
@@ -227,14 +227,14 @@ int tiffIdent(fullname, name)
   struct tiff_info info;
 
   tiff = is_tiff(fullname, name, &info);
-  babble(name, info);
   if (tiff == NULL)
     return(0);
+  babble(name, &info);
   if (tiff == (TIFF *)-1) /* is TIFF, but can't open it */
     return(1);
   TIFFClose(tiff);
 
-  babble(fullname, name, info);
+/*  babble(fullname, name, info); */
   return(1);
 }
 
@@ -404,6 +404,7 @@ Image *tiffLoad(fullname, name, verbose)
     if (info.samplesperpixel != 3) {
       fprintf(stderr,
 	      "%s: Can't handle TIFF RGB images with %d samples per pixel, sorry\n",
+	      fullname,
 	      info.samplesperpixel);
       image = NULL;
       break;
@@ -624,6 +625,6 @@ void tiffDump(image, options, file, verb
   TIFFClose(out);
 }
 
-#else /* !HAS_TIFF */
+#else /* !HAVE_LIBTIFF */
 static int unused;
-#endif /* !HAS_TIFF */
+#endif /* !HAVE_LIBTIFF */
--- a/uufilter.c
+++ b/uufilter.c
@@ -11,8 +11,9 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
-main(argc, argv)
+int main(argc, argv)
      int argc;
      char **argv;
 {
@@ -64,7 +65,7 @@ main(argc, argv)
       fprintf(stderr, "Ignoring header line: %s\n", buf);
   }
   if (feof(inf)) {
-    fprintf(stderr, "No 'begin' line, sorry.\n", infilename);
+    fprintf(stderr, "%s: No 'begin' line, sorry.\n", infilename);
     exit(1);
   }
 
--- a/vff.c
+++ b/vff.c
@@ -29,6 +29,7 @@
  */
 
 
+#include <ctype.h>
 #include "image.h"
 
 #define HEAD_BUF_SIZE	2048
--- a/window.c
+++ b/window.c
@@ -15,7 +15,7 @@
 #include <X11/Xatom.h>
 #include <signal.h>
 #include <errno.h>
-#include <sys/types.h>
+#include <sys/time.h>
 #ifdef HAS_POLL
 #include <poll.h>
 #else /* !HAS_POLL */
@@ -616,13 +616,13 @@ char imageInWindow(disp, scrn, image, gl
     lastx= (winwidth || winheight); /* user set size flag */
     if (!winwidth) {
       winwidth= image->width;
-      if (winwidth > DisplayWidth(disp, scrn) * 0.9)
-	winwidth= DisplayWidth(disp, scrn) * 0.9;
+      if (winwidth > DisplayWidth(disp, scrn) * 0.98)
+	winwidth= DisplayWidth(disp, scrn) * 0.98;
     }
     if (!winheight) {
       winheight= image->height;
-      if (winheight > DisplayHeight(disp, scrn) * 0.9)
-	winheight= DisplayHeight(disp, scrn) * 0.9;
+      if (winheight > DisplayHeight(disp, scrn) * 0.95)
+	winheight= DisplayHeight(disp, scrn) * 0.95;
     }
   }
 
@@ -902,10 +902,25 @@ char imageInWindow(disp, scrn, image, gl
 
     switch (event.any.type) {
     case ButtonPress:
-      if (event.button.button == 1) {
+      switch (event.button.button) {
+      case 1:
 	lastx= event.button.x;
 	lasty= event.button.y;
 	break;
+      case 3:
+	if (delay)
+	  alarm(0);
+	{
+	   Cursor cursor;
+	   cursor= swa_view.cursor;
+	   swa_view.cursor= XCreateFontCursor(disp, XC_watch);
+	   XChangeWindowAttributes(disp, ViewportWin, CWCursor, &swa_view);
+	   XFreeCursor(disp, cursor);
+	   XFlush(disp);
+	   cleanUpImage(disp, scrn, swa_view.cursor, pixmap,
+			image, ximageinfo);
+	}
+	return(' ');
       }
       break;
 
--- a/xbitmap.c
+++ b/xbitmap.c
@@ -132,7 +132,7 @@ Image *xbitmapLoad(fullname, name, verbo
   char          name_and_type[MAX_SIZE];
   char         *type;
   int           value;
-  int           v10p;
+  int           v10p = 0;
   unsigned int  linelen, dlinelen;
   unsigned int  x, y;
   unsigned int  w = 0, h = 0;
--- a/xloadimage.c
+++ b/xloadimage.c
@@ -18,8 +18,6 @@
 #endif
 #include <signal.h>
 
-extern double atof();
-
 char *ProgramName= "xloadimage";
 
 /* if an image loader needs to have our display and screen, it will get
@@ -192,7 +190,9 @@ main(argc, argv)
    */
 
   signal(SIGSEGV, internalError);
+#ifdef	SIGBUS
   signal(SIGBUS, internalError);
+#endif
   signal(SIGFPE, internalError);
   signal(SIGILL, internalError);
 #if defined(_AIX) && defined(_IBMR2)
