Second GRR patch for David Koblas' giftool 1.0:  cleanup of unused variables,
improper program return value, missing headers, etc. (as detected by "gcc
-Wall"), including a fix for an apparent bug in the -rgb option (undocumented
"-rgb ## ## ##" variant).

Note that the original giftool web site has been sold to Verio (/NTT).  An
unauthorized site is available here:

	http://the-labs.com/GIFTool/

I have not downloaded that version; caveat emptor.

Koblas himself is somewhat more difficult to find these days, but an
August 2001 posting associates him with extra.com:

	http://www.caucho.com/support/resin-interest/0108/0040.html
	From: David Koblas (koblas_at_excitecorp.com)
	[...]
	David,
	koblas[_at_]extra.com

Extra.com is registered to Koblas through October 2011 (first registered
in late 1994):

	Registrant:
	Extra Mile Consulting (EXTRA-DOM)
	   PO Box 1352
	   Mountain Veiw, CA 94042
	   US

	   Domain Name: EXTRA.COM

	   Administrative Contact, Technical Contact:
	      Koblas, David  (DK101)     koblas@EXTRA.COM
	      Extra Mile Consulting
	      PO Box 1352
	      Mt View, CA 94042
	      US
	      (650) 555 1212 fax: (415) 284-1401

Note also that www.extra.com is home to ZipOn Systems, a.k.a. zipon.com,
which lists the same post-office box on its privacy page; it is similarly
registered to Koblas (through May 2007):

	Registrant:
	Koblas, David (APRKXLPASD)
	   Extra Mile Consulting
	   PO Box 1352
	   Mt View, CA 94042
	   US

	   Domain Name: ZIPON.COM

	   Administrative Contact:
	      Koblas, David  (DK101)     koblas@EXTRA.COM
	      Extra Mile Consulting
	      PO Box 1352
	      Mt View, CA 94042
	      US
	      (650) 555 1212 fax: (415) 284-1401

However, presumably if he were interested in supporting giftool anymore,
he'd at least set up a web page for it (or relicense it under the GPL or
whatever).  So consider carefully before pestering him about it...

Greg Roelofs
newt/pobox.com
20050130


diff -u giftool-grr1/Makefile giftool-grr2/Makefile
--- giftool-grr1/Makefile	1996-04-04 11:30:32.000000000 -0800
+++ giftool-grr2/Makefile	2005-01-30 17:07:37.000000000 -0800
@@ -1,7 +1,8 @@
 CC = gcc
 
 #CFLAGS = -O2
-CFLAGS = -O3
+#CFLAGS = -O3
+CFLAGS = -O3 -Wall
 
 LIBS = # -lsent
 
diff -u giftool-grr1/main.c giftool-grr2/main.c
--- giftool-grr1/main.c	1996-06-02 16:24:05.000000000 -0700
+++ giftool-grr2/main.c	2005-01-30 18:36:32.000000000 -0800
@@ -15,8 +15,10 @@
 */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
-extern char *strchr();
+/* extern char *strchr(); */
 #define TRUE 1
 #define FALSE 0
 #include "gif.h"
@@ -1129,7 +1131,7 @@
 			continue;
 		cnt++;
 		if (cur->info.transparent != -1) {
-			fprintf(stderr,"Warning: image %d was already transparent\n");
+			fprintf(stderr,"Warning: image %d was already transparent\n", cnt);
 		}
 
 		if (cur->data.image.cmapSize != 0) {
@@ -1259,24 +1261,24 @@
 	fprintf(stderr,"\n");
 	fprintf(stderr,"For instance you could say 'giftool -B -i *.gif' to convert all your images\nto interlaced GIF files in one easy step.\n");
 	fprintf(stderr,"\n");
-	fprintf(stderr,"giftool version 1.0-grr is Copyright 1994 Home Pages, Inc and is shareware.\n");
+	fprintf(stderr,"giftool version 1.0-grr2 is Copyright 1994 Home Pages, Inc and is shareware.\n");
 	fprintf(stderr,"Please, use the -info option to read the licensing information.\n");
 	exit(1);
 }
 
-main(int argc, char *argv[]) 
+int main(int argc, char *argv[]) 
 {
-	int		c, i;
+	int		i;
 	int		batchMode = 0;
-	int		interlace = 0, batchInterlace = 0;
+	int		interlace = 0;
 	int		print     = 0;
 	int		stripComments = 0, printComments = 0;
-	int		addTrans  = 0, optimize = 0;
+	int		optimize = 0;
 	char		*transPixel = NULL, *outFile = NULL;
 	char		*addComment = NULL;
-	GIFStream	*stream;
 	int		idx;
 	int		stdinMode = 0;
+	int		errorCount = 0;
 
 	for (idx = 1; idx < argc && 
 			(argv[idx][0] == '-' || argv[idx][0] == '+'); idx++) {
@@ -1319,7 +1321,7 @@
 			if (isdigit(*arg) && strchr(arg, ',') == NULL) {
 				static char	buf[24];
 				if (idx == argc-2) usage();
-				sprintf(buf, "%d,%d,%d", arg, argv[idx+1], argv[idx+2]);
+				sprintf(buf, "%d,%d,%d", atoi(arg), atoi(argv[idx+1]), atoi(argv[idx+2]));
 				idx += 2;
 				transPixel = buf;
 			} else {
@@ -1393,10 +1395,14 @@
 					out = outFile;
 				}
 			}
-			if (status)
+			if (status) {
 				fprintf(stderr, "error writing %s\n", out);
+				if (errorCount < 255)
+					++errorCount;
+			}
 
 			GIFFree(stream);
 		}
 	}
+	return errorCount;
 }
diff -u giftool-grr1/readGIF.c giftool-grr2/readGIF.c
--- giftool-grr1/readGIF.c	1996-04-05 07:07:50.000000000 -0800
+++ giftool-grr2/readGIF.c	2005-01-30 17:15:36.000000000 -0800
@@ -25,6 +25,8 @@
 /* +-------------------------------------------------------------------+ */
 
 #include <stdio.h>
+#include <stdlib.h>   /* malloc(), realloc() */
+#include <string.h>   /* strncmp(), memcpy() */
 #include <setjmp.h>
 
 #include "gif.h"
@@ -71,7 +73,6 @@
 static jmp_buf                  setjmp_buffer;
 
 static int    verbose = FALSE;
-static int    showComment = FALSE;
 
 int     GIFTest(char *file)
 {
@@ -95,7 +96,7 @@
 {
 	unsigned char   buf[256];
 	unsigned char   c;
-	GIFStream	*stream;
+	GIFStream	*stream = NULL;
 	GIFData		*cur, **end;
 	GIF89info	info;
 	int		resetInfo = TRUE;
@@ -355,8 +356,6 @@
 
 static void initLWZ(int input_code_size)
 {
-	static int	inited = FALSE;
-
 	set_code_size = input_code_size;
 	code_size     = set_code_size + 1;
 	clear_code    = 1 << set_code_size ;
@@ -510,7 +509,7 @@
 			unsigned char *data)
 {
        unsigned char	*dp, c;      
-       int		v, xpos = 0, ypos = 0, pass = 0;
+       int		v, xpos = 0, ypos = 0;
 
 	/*
 	**  Initialize the Compression routines
diff -u giftool-grr1/writeGIF.c giftool-grr2/writeGIF.c
--- giftool-grr1/writeGIF.c	1996-04-05 07:17:17.000000000 -0800
+++ giftool-grr2/writeGIF.c	2005-01-30 17:11:58.000000000 -0800
@@ -48,6 +48,7 @@
 */
 
 #include <stdio.h>
+#include <stdlib.h>   /* qsort() */
 #include "gif.h"
 
 #define TRUE 1
@@ -84,13 +85,16 @@
 struct cval { 
 	int idx, cnt;
 };
-static int cvalCMP(struct cval *a, struct cval *b)
+
+/* static int cvalCMP(struct cval *a, struct cval *b) */
+static int cvalCMP(const void *a, const void *b)
 {
-	return b->cnt - a->cnt;
+	return ((struct cval *)b)->cnt - ((struct cval *)a)->cnt;
 }
+
 static int optimizeCMAP(GIFStream *stream)
 {
-	GIFData	*cur, *img;
+	GIFData	*cur, *img=NULL;
 	int	count = 0;
 
 	for (cur = stream->data; cur != NULL; cur = cur->next) {
@@ -116,7 +120,7 @@
 		unsigned char	*dp = img->data.image.data;
 		unsigned char	*ep = dp + img->width * img->height;
 		struct cval 	vals[256];
-		int		i, j;
+		int		i;
 		unsigned char	tmap[256][3], rmap[256];
 
 
@@ -507,14 +511,12 @@
 static void putImage(FILE *fp, int interlaced, int bpp, int width, int height, 
 			unsigned char *data)
 {
-	unsigned char	*end = data + width * height;
 	int		left = interlaced ? width : width * height;
 	int		cury = 0, pass = 0;
 	unsigned char	*dp = data;
 	long		fcode;
 	code_int	v, i, ent, disp, hsize_reg;
 	int		c, hshift;
-	int		skip = 8;
 
 	if (bpp <= 1) {
 		g_init_bits = 3;
