1diff :  xv-3.10a-jumbo-fix-enh-patch-20070520.txt
2
3This is a unified diff.  It should be applied (using Larry Wall's "patch"
4program) to the stock XV 3.10a sources.  See the "How to build" section of
5README.jumbo, which, along with roughly 40 other new files and 3 new sub-
6directories, should have been unpacked along with this jumbo patch:
7
8	README.jumbo
9	README.pcd
10	bits/br_bzip2
11	bits/br_jp2
12	bits/br_jpc
13	bits/br_mag
14	bits/br_maki
15	bits/br_mgcsfx
16	bits/br_pcd
17	bits/br_pi
18	bits/br_pic
19	bits/br_pic2
20	bits/br_png
21	bits/br_zx
22	contrib/
23	contrib/fnkey-scripts/
24	contrib/fnkey-scripts/README
25	contrib/fnkey-scripts/jpegcrop.sh
26	contrib/fnkey-scripts/jpegeditcom.sh
27	contrib/fnkey-scripts/jpeglogrot.sh
28	contrib/fnkey-scripts/jpegrot.sh
29	contrib/fnkey-scripts/jpegundocrop.sh
30	contrib/fedora/
31	contrib/fedora/README
32	contrib/fedora/Build-FC5
33	docs/xvdocs.pdf
34	tiff/RANLIB.sh
35	xv_mgcsfx.sample
36	xvhips.c
37	xvhips.h
38	xvjp2k.c
39	xvmag.c
40	xvmaki.c
41	xvmgcsfx.c
42	xvml.c
43	xvml.h
44	xvpcd.c
45	xvpi.c
46	xvpic.c
47	xvpic2.c
48	xvpng.c
49	xvvd.c
50	xvwbmp.c
51	xvzx.c
52
53
54diffs below:
55
56	Imakefile
57	Makefile
58	Makefile.std
59	bggen.c
60	bits/br_targa
61	bits/icon
62	cleandir
63	config.h
64	copyright.h
65	docs/bggen.man
66	docs/xcmap.man
67	docs/xv.man
68	docs/xvp2p.man
69	tiff/Makefile
70	tiff/Makefile.std
71	vdcomp.c
72	xcmap.c
73	xv.c
74	xv.h
75	xv24to8.c
76	xvalg.c
77	xvbmp.c
78	xvbrowse.c
79	xvbutt.c
80	xvcolor.c
81	xvctrl.c
82	xvcut.c
83	xvdflt.c
84	xvdflt.h
85	xvdial.c
86	xvdir.c
87	xvevent.c
88	xvfits.c
89	xvgam.c
90	xvgif.c
91	xvgifwr.c
92	xvgrab.c
93	xvgraf.c
94	xviff.c
95	xvimage.c
96	xvinfo.c
97	xviris.c
98	xvjpeg.c
99	xvmisc.c
100	xvpbm.c
101	xvpcx.c
102	xvpds.c
103	xvpictoppm.c
104	xvpm.c
105	xvpopup.c
106	xvps.c
107	xvrle.c
108	xvroot.c
109	xvscrl.c
110	xvsmooth.c
111	xvsunras.c
112	xvtarga.c
113	xvtext.c
114	xvtiff.c
115	xvtiffwr.c
116	xvxbm.c
117	xvxpm.c
118	xvxwd.c
119
120
121diff -ru xv-3.10a/Imakefile xv-3.10a-enhancements/Imakefile
122--- xv-3.10a/Imakefile	1995-01-13 12:24:01.000000000 -0800
123+++ xv-3.10a-enhancements/Imakefile	2005-04-17 14:04:22.000000000 -0700
124@@ -104,6 +104,11 @@
125 SGI = -Dsgi
126 #endif
127
128+/* install directory of xv_mgcsfx.sample. */
129+MGCSFXDIR = $(LIBDIR)
130+/* Directory of default configuration file. */
131+MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"
132+
133
134
135
136@@ -137,6 +142,8 @@
137 #if defined(SCOArchitecture)
138 SCO= -Dsco -DPOSIX -DNO_RANDOM
139 SYS_LIBRARIES=        -lm -lc -lx
140+#elif defined(HPArchitecture)
141+SYS_LIBRARIES=        -lm -lV3
142 #else
143 SYS_LIBRARIES=        -lm
144 #endif
145@@ -147,7 +154,7 @@
146
147 DEFINES= $(SCO) $(UNIX) $(NODIRENT) $(VPRINTF) $(TIMERS) \
148 	$(HPUX7) $(JPEG) $(TIFF) $(PDS) $(DXWM) $(RAND) \
149-	$(BACKING_STORE) $(BSDTYPES) $(SGI)
150+	$(BACKING_STORE) $(BSDTYPES) $(SGI) $(MGCSFX)
151
152 INCLUDES = $(JPEGINCLUDE) $(TIFFINCLUDE)
153
154@@ -157,7 +164,9 @@
155 	xvdial.c xvgraf.c xvsunras.c xvjpeg.c xvps.c xvpopup.c xvdflt.c \
156 	xvtiff.c xvtiffwr.c xvpds.c xvrle.c xviris.c xvgrab.c vprintf.c \
157 	xvbrowse.c xvtext.c xvpcx.c xviff.c xvtarga.c xvxpm.c xvcut.c \
158-	xvxwd.c xvfits.c
159+	xvxwd.c xvfits.c xvpng.c xvzx.c xvwbmp.c xvpcd.c \
160+	xvmag.c xvpic.c xvmaki.c xvpi.c xvpic2.c xvvd.c xvmgcsfx.c \
161+	xvml.c
162
163 OBJS1 =	xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
164 	xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
165@@ -165,7 +174,9 @@
166 	xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o \
167 	xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o \
168 	xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
169-	xvxwd.o xvfits.o
170+	xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o \
171+	xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
172+	xvml.o
173
174 SRCS2=	bggen.c
175 OBJS2=	bggen.o
176@@ -266,6 +277,8 @@
177 InstallManPageLong(docs/xvp2p,$(MANDIR),xvpictoppm)
178 InstallManPageLong(docs/vdcomp,$(MANDIR),vdcomp)
179
180+InstallNonExecFile(xv_mgcsfx.sample,$(MGCSFXDIR))
181+
182 tar:
183 	tar cf xv.tar Makefile* Imakefile *.c *.h bits docs \
184 		 docs unsupt vms $(JPEGDIR) $(TIFFDIR) $(MISC)
185diff -ru xv-3.10a/Makefile xv-3.10a-enhancements/Makefile
186--- xv-3.10a/Makefile	1995-01-23 12:20:54.000000000 -0800
187+++ xv-3.10a-enhancements/Makefile	2007-05-20 21:17:35.000000000 -0700
188@@ -2,7 +2,11 @@
189
190 # your C compiler (and options) of choice
191 CC = cc
192-# CC = gcc -ansi
193+#CC = gcc -ansi
194+# note that -ansi kills __USE_MISC (gcc 2.95.3), which, at least on Linux,
195+# determines whether stdlib.h includes prototypes for mktemp(), random(), etc.
196+# (i.e., if you use it, you will get unnecessary compiler warnings)
197+#CC = gcc
198
199 # use this if you're using 'cc' on a DEC Alpha (OSF/1) or MIPS (Ultrix) system:
200 # CC = cc -std1 -Olimit 750
201@@ -14,8 +18,20 @@
202 #       -Wuninitialized -Wparentheses
203
204
205-CCOPTS = -O
206-
207+CCOPTS = -O
208+#
209+# these are the usual optimization and warning options for gcc; all such
210+# warnings but one (mktemp() use) have been eliminated (at least on Linux):
211+#CCOPTS = -O3 -Wall
212+#
213+# slightly more warnings... older code often made non-const pointers to
214+# static strings (nothing should blow up unless something tries to write
215+# to them):
216+#CCOPTS = -O3 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wnested-externs
217+#
218+# for the next step up in gcc noise, try adding -W (but note that it adds a
219+# huge number of unused-parameter and signed/unsigned comparison warnings):
220+#CCOPTS = -O3 -Wall -W
221
222 ### NOTE: Sun running OpenWindows:
223 ### if you're using a SUN running OPENWINDOWS, you need to add these two
224@@ -27,50 +43,155 @@
225 ### '-I' options on the CCOPTS line to tell the compiler where said files are.
226
227
228+# older Unixen don't support the -p option, but its lack may mean installation
229+# will fail (if more than one directory level is missing)
230+MKDIR = mkdir -p
231+
232+
233+# BeOS _may_ need to use a different version (below), but probably not
234+CLEANDIR = cleandir
235+
236+
237 ### Installation locations
238-BINDIR = /usr/local/bin
239-MANDIR = /usr/local/man/man1
240+### NOTE: Users of old K&R compilers (i.e., any version not supporting C89
241+### string concatenation, such as "fub" "ar" => "fubar") should update
242+### xvtext.c:1831 (or thereabouts) if either PREFIX or DOCDIR changes:
243+PREFIX = /usr/local
244+BINDIR = $(PREFIX)/bin
245+MANDIR = $(PREFIX)/share/man/man1
246 MANSUF = 1
247-LIBDIR = /usr/local/lib
248+DOCDIR = $(PREFIX)/share/doc/xv
249+LIBDIR = $(PREFIX)/lib/xv
250+SYSCONFDIR = /etc
251+DESTDIR =
252
253
254 buildit: all
255
256
257 ########################### CONFIGURATION OPTIONS ############################
258-### NOTE: be sure to check 'config.h', for a few other configuration options
259+### NOTE: be sure to check 'config.h', for a few other configuration options
260 ##############################################################################
261
262 ###
263+### if, for whatever reason, you're unable to get the TIFF library to compile
264+### on your machine, *COMMENT OUT* the following lines
265+###
266+### GRR 20050319:  USE_TILED_TIFF_BOTLEFT_FIX enables an experimental fix for
267+###   tiled TIFFs with ORIENTATION_BOTLEFT.  It may break other tiled TIFFs,
268+###   or it may be required for certain other TIFF types (e.g., strips with
269+###   ORIENTATION_BOTLEFT).  I don't have a sufficient variety of TIFF test
270+###   images at hand.
271+###
272+#TIFF    = -DDOTIFF
273+TIFF    = -DDOTIFF -DUSE_TILED_TIFF_BOTLEFT_FIX
274+###
275+#TIFFDIR = tiff
276+TIFFDIR = /usr
277+#TIFFDIR = /usr/local
278+#TIFFDIR = ../../libtiff
279+###
280+TIFFINC = -I$(TIFFDIR)/include
281+#TIFFINC = -I$(TIFFDIR)
282+###
283+### libtiff 3.5 and up may be compiled with zlib and libjpeg, but the
284+### dependency is properly handled in LIBS line ~247 lines below
285+###
286+TIFFLIB = -L$(TIFFDIR)/lib -ltiff
287+#TIFFLIB = $(TIFFDIR)/lib/libtiff.a
288+#TIFFLIB = -L$(TIFFDIR) -ltiff
289+#TIFFLIB = $(TIFFDIR)/libtiff.a
290+###
291+### this is intended to build the ancient version (3.3.016 beta) that's
292+### included in the "tiff" subdir of XV, not an arbitrary copy of libtiff:
293+###
294+#$(TIFFLIB):
295+#	( cd $(TIFFDIR) ; make CC='$(CC)' COPTS='$(CCOPTS) $(MCHN)' )
296+
297+
298+###
299 ### if, for whatever reason, you're unable to get the JPEG library to compile
300 ### on your machine, *COMMENT OUT* the following lines
301 ###
302+### NOTE: /usr/sfw can be used on Solaris with "Sun freeware" installed
303+###
304 JPEG    = -DDOJPEG
305-JPEGDIR = jpeg
306-JPEGINC = -I$(JPEGDIR)
307-JPEGLIB = $(JPEGDIR)/libjpeg.a
308-$(JPEGDIR)/jconfig.h:
309-	cd $(JPEGDIR) ; ./configure CC='$(CC)'
310-$(JPEGLIB):  $(JPEGDIR)/jconfig.h
311-	cd $(JPEGDIR) ; make
312+#JPEGDIR = jpeg
313+JPEGDIR = /usr
314+#JPEGDIR = /usr/local
315+#JPEGDIR = ../../libjpeg
316+#JPEGDIR = /usr/sfw
317+###
318+JPEGINC = -I$(JPEGDIR)/include
319+#JPEGINC = -I$(JPEGDIR)
320+###
321+JPEGLIB = -L$(JPEGDIR)/lib -ljpeg
322+#JPEGLIB = -L$(JPEGDIR) -ljpeg
323+#JPEGLIB = $(JPEGDIR)/libjpeg.a
324+###
325+### this is intended to build the ancient version (5a) that's included in the
326+### "jpeg" subdir of XV, not an arbitrary copy of libjpeg:
327+###
328+#$(JPEGDIR)/jconfig.h:
329+#	cd $(JPEGDIR) ; ./configure CC='$(CC)'
330+#$(JPEGLIB):  $(JPEGDIR)/jconfig.h
331+#	cd $(JPEGDIR) ; make
332
333
334 ###
335-### if, for whatever reason, you're unable to get the TIFF library to compile
336+### if, for whatever reason, you're unable to get the PNG library to compile
337 ### on your machine, *COMMENT OUT* the following lines
338 ###
339-TIFF    = -DDOTIFF
340-TIFFDIR = tiff
341-TIFFINC = -I$(TIFFDIR)
342-TIFFLIB = $(TIFFDIR)/libtiff.a
343-$(TIFFLIB):
344-	( cd $(TIFFDIR) ; make CC='$(CC)' )
345+PNG    = -DDOPNG
346+PNGDIR = /usr
347+#PNGDIR = /usr/local
348+#PNGDIR = ../../libpng
349+###
350+PNGINC = -I$(PNGDIR)/include
351+#PNGINC = -I$(PNGDIR)
352+###
353+PNGLIB = -L$(PNGDIR)/lib -lpng
354+#PNGLIB = -L$(PNGDIR) -lpng
355+#PNGLIB = $(PNGDIR)/libpng.a
356+
357+
358+###
359+### if, for whatever reason, you're unable to get both the PNG library and
360+### (newer versions of) the TIFF library to compile on your machine, *COMMENT
361+### OUT* the following lines
362+###
363+ZLIBDIR = /usr
364+#ZLIBDIR = /usr/local
365+#ZLIBDIR = ../../zlib
366+###
367+ZLIBINC = -I$(ZLIBDIR)/include
368+#ZLIBINC = -I$(ZLIBDIR)
369+###
370+ZLIBLIB = -L$(ZLIBDIR)/lib -lz
371+#ZLIBLIB = -L$(ZLIBDIR) -lz
372+#ZLIBLIB = $(ZLIBDIR)/libz.a
373+
374+
375+###
376+### if, for whatever reason, you're unable to get the JasPer JPEG-2000 library
377+### to compile on your machine, *COMMENT OUT* the following lines
378+###
379+JP2K    = -DDOJP2K
380+###
381+#JP2KDIR = ../../jasper
382+JP2KDIR = /usr/local/lib
383+###
384+#JP2KINC = -I$(JP2KDIR)
385+JP2KINC = -I/usr/local/include
386+###
387+#JP2KLIB = -L$(JP2KDIR) -ljasper
388+JP2KLIB = $(JP2KDIR)/libjasper.a
389
390
391 ###
392 ### if, for whatever reason, you're unable to get the PDS/VICAR support
393 ### to compile (xvpds.c, and vdcomp.c), *COMMENT OUT* the following line,
394-### and also remove 'vdcomp' from the 'all:' dependancy
395+### and also remove 'vdcomp' from the 'all:' dependency
396 ###
397 PDS = -DDOPDS
398
399@@ -78,46 +199,60 @@
400 #----------System V----------
401
402 # if you are running on a SysV-based machine, such as HP, Silicon Graphics,
403-# Solaris, etc., uncomment the following line to get mostly there.
404-#UNIX = -DSVR4
405+# Solaris, etc.; uncomment one of the following lines to get you *most* of
406+# the way there.  SYSV means System V R3.
407+# UNIX = -DSVR4
408+# UNIX = -DSYSV
409+
410
411+#----------Machine-Specific Configurations----------
412+
413+### If you are using a BeOS system, uncomment the following line
414+#MCHN = -DUSE_GETCWD -I/usr/X11/include -L/usr/X11/lib
415+###
416+### The stock version of cleandir now should work for BeOS, too, so try
417+### leaving this commented out:
418+#CLEANDIR = cleandir.BeOS
419
420-#----------Machine Specific Configurations----------
421
422 ### If you are using an SGI system, uncomment the following line
423 #MCHN = -Dsgi
424
425
426-### For HP-UX, uncomment the following line:
427+### For HP-UX, uncomment the following line
428 #MCHN= -Dhpux -D_HPUX_SOURCE
429 # To use old HP compilers (HPUX 7.0 or so), you may need
430 #MCHN= -Dhpux -D_HPUX_SOURCE +Ns4000
431 #
432-# also, if you're using HP's compiler, add '-Aa' to whichever of those
433+# Also, if you're using HP's compiler, add '-Aa' to whichever of those
434 # two lines you're using, to turn on ANSI C mode.  Or so I'm told.
435 #
436-# note:  You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
437+# Note:  You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
438 # to whichever of those lines you used, as HP tends to store their X11
439 # include files in a non-standard place...
440+#
441+# And you probably have to add '-lV3' to the end of the LIBS def when
442+# using XV's AUTO_EXPAND option.
443
444
445-### for LINUX, uncomment the following line
446-#MCHN = -DLINUX
447+### for Linux, uncomment one of the following lines:
448+#MCHN = -DLINUX -L/usr/X11R6/lib
449+#MCHN = -DLINUX -L/usr/X11R6/lib64
450
451
452 # For SCO 1.1 (UNIX 3.2v2) machines, uncomment the following:
453 #MCHN = -Dsco -DPOSIX
454 #
455 # For ODT 2.0 (UNIX 3.2v4) machines, uncomment the following:
456-#MCHN= -Dsco -DPOSIX -DNO_RANDOM
457+#MCHN= -Dsco -DPOSIX -DNO_RANDOM
458 #
459 # Also, you should add '-lc -lx' to the end of the LIBS def below
460 # -lx must be after -lc so you get the right directory routines.
461
462
463 # for UMAX V by Encore Computers uncomment the following line for
464-# the portable c compiler, system specific definitions and
465-# location of local X11 library(if site specific, modify -L option)
466+# the portable C compiler, system-specific definitions and
467+# location of local X11 library (if site-specific, modify -L option)
468 # No other switches should be necessary, or so I'm told...
469 #
470 #MCHN = -q extensions=pcc_c -D__UMAXV__ -L/usr2/usr/lib/X11 -DSVR4
471@@ -147,8 +282,8 @@
472 #TIMERS = -DUSLEEP
473
474
475-# if XV locks up whenever you click on *any* of the buttons, the Timer()
476-# function in xvmisc.c is going out to lunch.  A simple workaround is to
477+# if XV locks up whenever you click on *any* of the buttons, the Timer()
478+# function in xvmisc.c is going out to lunch.  A simple workaround is to
479 # uncomment the following line:
480 #TIMERS = -DNOTIMER
481
482@@ -160,7 +295,7 @@
483 #DXWM = -DDXWM
484
485
486-# if, during compilation, your system complains about the types
487+# if, during compilation, your system complains about the types
488 # 'u_long', 'u_short', 'u_int', etc. as being undefined, uncomment the
489 # following line:
490 #BSDTYPES = -DBSDTYPES
491@@ -177,18 +312,38 @@
492 #VPRINTF = -DNEED_VPRINTF -DLONGINT -DNOSTDHDRS
493
494
495+# if your machine puts the prototype for 'malloc()' in malloc.h rather than
496+# stdlib.h, uncomment the following line:
497+#
498+#MALLOC = -DNEED_MALLOC_H
499
500
501-################ END OF CONFIGURATION OPTIONS #################
502+# if your X Window System compiled with -DX_LOCALE,
503+# uncomment the following line:
504+# TVL10N = -DX_LOCALE
505+
506+# Install directory of xv_mgcsfx.sample.
507+MGCSFXDIR = $(LIBDIR)
508+# Directory of default configuration file.
509+MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"
510+
511
512
513
514+################ END OF CONFIGURATION OPTIONS #################
515+
516
517-CFLAGS = $(CCOPTS) $(JPEG) $(JPEGINC) $(TIFF) $(TIFFINC) $(PDS) \
518-	$(NODIRENT) $(VPRINTF) $(TIMERS) $(UNIX) $(BSDTYPES) $(RAND) \
519-	$(DXWM) $(MCHN)
520
521-LIBS = -lX11 $(JPEGLIB) $(TIFFLIB) -lm
522+
523+CFLAGS = $(CCOPTS) $(PNG) $(PNGINC) $(ZLIBINC) $(JPEG) $(JPEGINC) \
524+	$(TIFF) $(TIFFINC) $(PDS) $(JP2K) $(JP2KINC) $(TVL10N) $(MGCSFX) \
525+	$(UNIX) $(BSDTYPES) $(RAND) $(MALLOC) $(DXWM) $(MCHN) $(NODIRENT) \
526+	$(VPRINTF) $(TIMERS) -DDOCDIR=\"$(DOCDIR)\" \
527+	-DSYSCONFDIR=\"$(SYSCONFDIR)\" -DXVEXECPATH=\"$(LIBDIR)\"
528+
529+### remove -lm for BeOS:
530+LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -L/usr/X11R6/lib -lX11 -lm
531+#LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -lX11
532
533 OBJS = 	xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
534 	xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
535@@ -196,7 +351,9 @@
536 	xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o \
537 	xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o \
538 	xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
539-	xvxwd.o xvfits.o
540+	xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o xvhips.o \
541+	xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
542+	xvml.o xvjp2k.o
543
544 MISC = README INSTALL CHANGELOG IDEAS
545
546@@ -206,10 +363,12 @@
547
548
549
550-all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
551+#all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
552+all: xv bggen vdcomp xcmap xvpictoppm
553
554
555-xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
556+#xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
557+xv: $(OBJS)
558 	$(CC) -o xv $(CFLAGS) $(OBJS) $(LIBS)
559
560 bggen: bggen.c
561@@ -231,23 +390,47 @@
562
563 clean:  xvclean
564 	rm -f bggen vdcomp xcmap xvpictoppm
565-	./cleandir $(JPEGDIR)
566-	rm -f $(JPEGDIR)/jconfig.h $(JPEGDIR)/Makefile
567-	./cleandir $(TIFFDIR)
568+#	clean only local jpeg and tiff dirs, not user's or system's copies:
569+	./$(CLEANDIR) jpeg
570+	rm -f jpeg/jconfig.h jpeg/Makefile
571+	./$(CLEANDIR) tiff
572
573
574+# could also do some shell trickery here to attempt mkdir only if dir is
575+# missing (e.g., "test -d <dir> || $(MKDIR) <dir>")
576 install: all
577-	cp xv bggen vdcomp xcmap xvpictoppm $(BINDIR)
578-	cp docs/xv.man     $(MANDIR)/xv.$(MANSUF)
579-	cp docs/bggen.man  $(MANDIR)/bggen.$(MANSUF)
580-	cp docs/xcmap.man  $(MANDIR)/xcmap.$(MANSUF)
581-	cp docs/xvp2p.man  $(MANDIR)/xvpictoppm.$(MANSUF)
582-	cp docs/vdcomp.man $(MANDIR)/vdcomp.$(MANSUF)
583-	cp docs/xvdocs.ps* $(LIBDIR)
584+	$(MKDIR) $(DESTDIR)$(BINDIR)
585+	cp xv bggen vdcomp xcmap xvpictoppm $(DESTDIR)$(BINDIR)/.
586+	chmod 755 $(DESTDIR)$(BINDIR)/xv $(DESTDIR)$(BINDIR)/bggen \
587+	  $(DESTDIR)$(BINDIR)/vdcomp $(DESTDIR)$(BINDIR)/xcmap \
588+	  $(DESTDIR)$(BINDIR)/xvpictoppm
589+#
590+	$(MKDIR) $(DESTDIR)$(MANDIR)
591+	cp docs/xv.man     $(DESTDIR)$(MANDIR)/xv.$(MANSUF)
592+	cp docs/bggen.man  $(DESTDIR)$(MANDIR)/bggen.$(MANSUF)
593+	cp docs/xcmap.man  $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF)
594+	cp docs/xvp2p.man  $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF)
595+	cp docs/vdcomp.man $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
596+	chmod 644 $(DESTDIR)$(MANDIR)/xv.$(MANSUF) \
597+	  $(DESTDIR)$(MANDIR)/bggen.$(MANSUF) \
598+	  $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF) \
599+	  $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF) \
600+	  $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
601+#
602+	$(MKDIR) $(DESTDIR)$(DOCDIR)		# or $(DESTDIR)$(LIBDIR)
603+	cp README.jumbo docs/xvdocs.pdf docs/xvdocs.ps $(DESTDIR)$(DOCDIR)/.
604+	chmod 644 $(DESTDIR)$(DOCDIR)/README.jumbo \
605+	  $(DESTDIR)$(DOCDIR)/xvdocs.pdf $(DESTDIR)$(DOCDIR)/xvdocs.ps
606+#
607+	#$(MKDIR) $(DESTDIR)$(SYSCONFDIR)
608+	#cp xv_mgcsfx.sample $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
609+	#chmod 644 $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
610+
611
612 tar:
613+#	tar only local jpeg and tiff dirs, not user's or system's copies:
614 	tar cvf xv.tar Makefile* Imakefile *.c *.h bits \
615-		docs unsupt vms $(JPEGDIR) $(TIFFDIR) $(MISC)
616+		docs unsupt vms jpeg tiff $(MISC)
617
618 xvtar:
619 	tar cvf xv.tar Makefile* Imakefile *.c *.h bits
620@@ -257,26 +440,28 @@
621
622 ################# bitmap dependencies ####################
623
624-xv.o:      	bits/icon bits/iconmask bits/runicon bits/runiconm
625-xv.o:      	bits/cboard50 bits/gray25
626+xv.o:		bits/icon bits/iconmask bits/runicon bits/runiconm
627+xv.o:		bits/cboard50 bits/gray25
628
629 xvbrowse.o:	bits/br_file bits/br_dir bits/br_exe bits/br_chr bits/br_blk
630-xvbrowse.o:	bits/br_sock bits/br_fifo bits/br_error bits/br_unknown
631-xvbrowse.o:	bits/br_cmpres bits/br_gif bits/br_pm bits/br_pbm
632+xvbrowse.o:	bits/br_sock bits/br_fifo bits/br_error # bits/br_unknown
633+xvbrowse.o:	bits/br_cmpres bits/br_bzip2 bits/br_gif bits/br_pm bits/br_pbm
634 xvbrowse.o:	bits/br_sunras bits/br_bmp bits/br_utah bits/br_iris
635-xvbrowse.o:	bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds
636-xvbrowse.o:	bits/br_ps bits/br_iff bits/br_targa bits/br_xpm
637+xvbrowse.o:	bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds bits/br_pcd
638+xvbrowse.o:	bits/br_ps bits/br_iff bits/br_targa bits/br_xpm bits/br_xwd
639+xvbrowse.o:	bits/br_fits bits/br_png bits/br_zx bits/br_mag bits/br_maki
640+xvbrowse.o:	bits/br_pic bits/br_pi bits/br_pic2 bits/br_mgcsfx
641+xvbrowse.o:	bits/br_jp2 bits/br_jpc
642 xvbrowse.o:	bits/br_trash bits/fcurs bits/fccurs bits/fdcurs bits/fcursm
643-xvbrowse.o:     bits/br_xwd
644
645 xvbutt.o:	bits/cboard50 bits/rb_frame bits/rb_frame1 bits/rb_top
646 xvbutt.o:	bits/rb_bot bits/rb_dtop bits/rb_dbot bits/rb_body
647 xvbutt.o:	bits/rb_dot bits/cb_check bits/mb_chk
648
649 xvctrl.o:	bits/gray25 bits/gray50 bits/i_fifo bits/i_chr bits/i_dir
650-xvctrl.o: 	bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
651+xvctrl.o:	bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
652 xvctrl.o:	bits/h_rotl bits/h_rotr bits/fliph bits/flipv bits/p10
653-xvctrl.o:	bits/m10 bits/cut bits/copy bits/paste bits/clear
654+xvctrl.o:	bits/m10 bits/cut bits/copy bits/paste bits/clear
655 xvctrl.o:	bits/uicon bits/oicon1 bits/oicon2 bits/icon
656 xvctrl.o:	bits/padimg bits/annot
657
658@@ -285,13 +470,13 @@
659 xvdflt.o:	bits/logo_top bits/logo_bot bits/logo_out bits/xv_jhb
660 xvdflt.o:	bits/xv_cpyrt bits/xv_rev bits/xv_ver
661 xvdflt.o:	bits/xf_left bits/xf_right bits/font5x9.h
662-xvdflt.o:       xvdflt.h
663+xvdflt.o:	xvdflt.h
664
665 xvdial.o:	bits/dial_cw1 bits/dial_ccw1 bits/dial_cw2 bits/dial_ccw2
666
667 xvdir.o:	bits/d_load bits/d_save
668
669-xvevent.o:	bits/dropper bits/dropperm bits/pen bits/penm
670+xvevent.o:	bits/dropper bits/dropperm bits/pen bits/penm
671 xvevent.o:	bits/blur bits/blurm
672
673 xvgam.o:	bits/h_rotl bits/h_rotr bits/h_flip bits/h_sinc bits/h_sdec
674diff -ru xv-3.10a/Makefile.std xv-3.10a-enhancements/Makefile.std
675--- xv-3.10a/Makefile.std	1995-01-23 17:06:26.000000000 -0800
676+++ xv-3.10a-enhancements/Makefile.std	2007-05-20 21:17:35.000000000 -0700
677@@ -2,7 +2,11 @@
678
679 # your C compiler (and options) of choice
680 CC = cc
681-# CC = gcc -ansi
682+#CC = gcc -ansi
683+# note that -ansi kills __USE_MISC (gcc 2.95.3), which, at least on Linux,
684+# determines whether stdlib.h includes prototypes for mktemp(), random(), etc.
685+# (i.e., if you use it, you will get unnecessary compiler warnings)
686+#CC = gcc
687
688 # use this if you're using 'cc' on a DEC Alpha (OSF/1) or MIPS (Ultrix) system:
689 # CC = cc -std1 -Olimit 750
690@@ -14,8 +18,20 @@
691 #       -Wuninitialized -Wparentheses
692
693
694-CCOPTS = -O
695-
696+CCOPTS = -O
697+#
698+# these are the usual optimization and warning options for gcc; all such
699+# warnings but one (mktemp() use) have been eliminated (at least on Linux):
700+#CCOPTS = -O3 -Wall
701+#
702+# slightly more warnings... older code often made non-const pointers to
703+# static strings (nothing should blow up unless something tries to write
704+# to them):
705+#CCOPTS = -O3 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wnested-externs
706+#
707+# for the next step up in gcc noise, try adding -W (but note that it adds a
708+# huge number of unused-parameter and signed/unsigned comparison warnings):
709+#CCOPTS = -O3 -Wall -W
710
711 ### NOTE: Sun running OpenWindows:
712 ### if you're using a SUN running OPENWINDOWS, you need to add these two
713@@ -27,50 +43,155 @@
714 ### '-I' options on the CCOPTS line to tell the compiler where said files are.
715
716
717+# older Unixen don't support the -p option, but its lack may mean installation
718+# will fail (if more than one directory level is missing)
719+MKDIR = mkdir -p
720+
721+
722+# BeOS _may_ need to use a different version (below), but probably not
723+CLEANDIR = cleandir
724+
725+
726 ### Installation locations
727-BINDIR = /usr/local/bin
728-MANDIR = /usr/local/man/man1
729+### NOTE: Users of old K&R compilers (i.e., any version not supporting C89
730+### string concatenation, such as "fub" "ar" => "fubar") should update
731+### xvtext.c:1831 (or thereabouts) if either PREFIX or DOCDIR changes:
732+PREFIX = /usr/local
733+BINDIR = $(PREFIX)/bin
734+MANDIR = $(PREFIX)/share/man/man1
735 MANSUF = 1
736-LIBDIR = /usr/local/lib
737+DOCDIR = $(PREFIX)/share/doc/xv
738+LIBDIR = $(PREFIX)/lib/xv
739+SYSCONFDIR = /etc
740+DESTDIR =
741
742
743 buildit: all
744
745
746 ########################### CONFIGURATION OPTIONS ############################
747-### NOTE: be sure to check 'config.h', for a few other configuration options
748+### NOTE: be sure to check 'config.h', for a few other configuration options
749 ##############################################################################
750
751 ###
752+### if, for whatever reason, you're unable to get the TIFF library to compile
753+### on your machine, *COMMENT OUT* the following lines
754+###
755+### GRR 20050319:  USE_TILED_TIFF_BOTLEFT_FIX enables an experimental fix for
756+###   tiled TIFFs with ORIENTATION_BOTLEFT.  It may break other tiled TIFFs,
757+###   or it may be required for certain other TIFF types (e.g., strips with
758+###   ORIENTATION_BOTLEFT).  I don't have a sufficient variety of TIFF test
759+###   images at hand.
760+###
761+#TIFF    = -DDOTIFF
762+TIFF    = -DDOTIFF -DUSE_TILED_TIFF_BOTLEFT_FIX
763+###
764+#TIFFDIR = tiff
765+TIFFDIR = /usr
766+#TIFFDIR = /usr/local
767+#TIFFDIR = ../../libtiff
768+###
769+TIFFINC = -I$(TIFFDIR)/include
770+#TIFFINC = -I$(TIFFDIR)
771+###
772+### libtiff 3.5 and up may be compiled with zlib and libjpeg, but the
773+### dependency is properly handled in LIBS line ~247 lines below
774+###
775+TIFFLIB = -L$(TIFFDIR)/lib -ltiff
776+#TIFFLIB = $(TIFFDIR)/lib/libtiff.a
777+#TIFFLIB = -L$(TIFFDIR) -ltiff
778+#TIFFLIB = $(TIFFDIR)/libtiff.a
779+###
780+### this is intended to build the ancient version (3.3.016 beta) that's
781+### included in the "tiff" subdir of XV, not an arbitrary copy of libtiff:
782+###
783+#$(TIFFLIB):
784+#	( cd $(TIFFDIR) ; make CC='$(CC)' COPTS='$(CCOPTS) $(MCHN)' )
785+
786+
787+###
788 ### if, for whatever reason, you're unable to get the JPEG library to compile
789 ### on your machine, *COMMENT OUT* the following lines
790 ###
791+### NOTE: /usr/sfw can be used on Solaris with "Sun freeware" installed
792+###
793 JPEG    = -DDOJPEG
794-JPEGDIR = jpeg
795-JPEGINC = -I$(JPEGDIR)
796-JPEGLIB = $(JPEGDIR)/libjpeg.a
797-$(JPEGDIR)/jconfig.h:
798-	cd $(JPEGDIR) ; ./configure CC='$(CC)'
799-$(JPEGLIB):  $(JPEGDIR)/jconfig.h
800-	cd $(JPEGDIR) ; make
801+#JPEGDIR = jpeg
802+JPEGDIR = /usr
803+#JPEGDIR = /usr/local
804+#JPEGDIR = ../../libjpeg
805+#JPEGDIR = /usr/sfw
806+###
807+JPEGINC = -I$(JPEGDIR)/include
808+#JPEGINC = -I$(JPEGDIR)
809+###
810+JPEGLIB = -L$(JPEGDIR)/lib -ljpeg
811+#JPEGLIB = -L$(JPEGDIR) -ljpeg
812+#JPEGLIB = $(JPEGDIR)/libjpeg.a
813+###
814+### this is intended to build the ancient version (5a) that's included in the
815+### "jpeg" subdir of XV, not an arbitrary copy of libjpeg:
816+###
817+#$(JPEGDIR)/jconfig.h:
818+#	cd $(JPEGDIR) ; ./configure CC='$(CC)'
819+#$(JPEGLIB):  $(JPEGDIR)/jconfig.h
820+#	cd $(JPEGDIR) ; make
821
822
823 ###
824-### if, for whatever reason, you're unable to get the TIFF library to compile
825+### if, for whatever reason, you're unable to get the PNG library to compile
826 ### on your machine, *COMMENT OUT* the following lines
827 ###
828-TIFF    = -DDOTIFF
829-TIFFDIR = tiff
830-TIFFINC = -I$(TIFFDIR)
831-TIFFLIB = $(TIFFDIR)/libtiff.a
832-$(TIFFLIB):
833-	( cd $(TIFFDIR) ; make CC='$(CC)' )
834+PNG    = -DDOPNG
835+PNGDIR = /usr
836+#PNGDIR = /usr/local
837+#PNGDIR = ../../libpng
838+###
839+PNGINC = -I$(PNGDIR)/include
840+#PNGINC = -I$(PNGDIR)
841+###
842+PNGLIB = -L$(PNGDIR)/lib -lpng
843+#PNGLIB = -L$(PNGDIR) -lpng
844+#PNGLIB = $(PNGDIR)/libpng.a
845+
846+
847+###
848+### if, for whatever reason, you're unable to get both the PNG library and
849+### (newer versions of) the TIFF library to compile on your machine, *COMMENT
850+### OUT* the following lines
851+###
852+ZLIBDIR = /usr
853+#ZLIBDIR = /usr/local
854+#ZLIBDIR = ../../zlib
855+###
856+ZLIBINC = -I$(ZLIBDIR)/include
857+#ZLIBINC = -I$(ZLIBDIR)
858+###
859+ZLIBLIB = -L$(ZLIBDIR)/lib -lz
860+#ZLIBLIB = -L$(ZLIBDIR) -lz
861+#ZLIBLIB = $(ZLIBDIR)/libz.a
862+
863+
864+###
865+### if, for whatever reason, you're unable to get the JasPer JPEG-2000 library
866+### to compile on your machine, *COMMENT OUT* the following lines
867+###
868+JP2K    = -DDOJP2K
869+###
870+#JP2KDIR = ../../jasper
871+JP2KDIR = /usr/local/lib
872+###
873+#JP2KINC = -I$(JP2KDIR)
874+JP2KINC = -I/usr/local/include
875+###
876+#JP2KLIB = -L$(JP2KDIR) -ljasper
877+JP2KLIB = $(JP2KDIR)/libjasper.a
878
879
880 ###
881 ### if, for whatever reason, you're unable to get the PDS/VICAR support
882 ### to compile (xvpds.c, and vdcomp.c), *COMMENT OUT* the following line,
883-### and also remove 'vdcomp' from the 'all:' dependancy
884+### and also remove 'vdcomp' from the 'all:' dependency
885 ###
886 PDS = -DDOPDS
887
888@@ -78,46 +199,60 @@
889 #----------System V----------
890
891 # if you are running on a SysV-based machine, such as HP, Silicon Graphics,
892-# Solaris, etc., uncomment the following line to get mostly there.
893-#UNIX = -DSVR4
894+# Solaris, etc.; uncomment one of the following lines to get you *most* of
895+# the way there.  SYSV means System V R3.
896+# UNIX = -DSVR4
897+# UNIX = -DSYSV
898+
899
900+#----------Machine-Specific Configurations----------
901+
902+### If you are using a BeOS system, uncomment the following line
903+#MCHN = -DUSE_GETCWD -I/usr/X11/include -L/usr/X11/lib
904+###
905+### The stock version of cleandir now should work for BeOS, too, so try
906+### leaving this commented out:
907+#CLEANDIR = cleandir.BeOS
908
909-#----------Machine Specific Configurations----------
910
911 ### If you are using an SGI system, uncomment the following line
912 #MCHN = -Dsgi
913
914
915-### For HP-UX, uncomment the following line:
916+### For HP-UX, uncomment the following line
917 #MCHN= -Dhpux -D_HPUX_SOURCE
918 # To use old HP compilers (HPUX 7.0 or so), you may need
919 #MCHN= -Dhpux -D_HPUX_SOURCE +Ns4000
920 #
921-# also, if you're using HP's compiler, add '-Aa' to whichever of those
922+# Also, if you're using HP's compiler, add '-Aa' to whichever of those
923 # two lines you're using, to turn on ANSI C mode.  Or so I'm told.
924 #
925-# note:  You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
926+# Note:  You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
927 # to whichever of those lines you used, as HP tends to store their X11
928 # include files in a non-standard place...
929+#
930+# And you probably have to add '-lV3' to the end of the LIBS def when
931+# using XV's AUTO_EXPAND option.
932
933
934-### for LINUX, uncomment the following line
935-#MCHN = -DLINUX
936+### for Linux, uncomment one of the following lines:
937+#MCHN = -DLINUX -L/usr/X11R6/lib
938+#MCHN = -DLINUX -L/usr/X11R6/lib64
939
940
941 # For SCO 1.1 (UNIX 3.2v2) machines, uncomment the following:
942 #MCHN = -Dsco -DPOSIX
943 #
944 # For ODT 2.0 (UNIX 3.2v4) machines, uncomment the following:
945-#MCHN= -Dsco -DPOSIX -DNO_RANDOM
946+#MCHN= -Dsco -DPOSIX -DNO_RANDOM
947 #
948 # Also, you should add '-lc -lx' to the end of the LIBS def below
949 # -lx must be after -lc so you get the right directory routines.
950
951
952 # for UMAX V by Encore Computers uncomment the following line for
953-# the portable c compiler, system specific definitions and
954-# location of local X11 library(if site specific, modify -L option)
955+# the portable C compiler, system-specific definitions and
956+# location of local X11 library (if site-specific, modify -L option)
957 # No other switches should be necessary, or so I'm told...
958 #
959 #MCHN = -q extensions=pcc_c -D__UMAXV__ -L/usr2/usr/lib/X11 -DSVR4
960@@ -147,8 +282,8 @@
961 #TIMERS = -DUSLEEP
962
963
964-# if XV locks up whenever you click on *any* of the buttons, the Timer()
965-# function in xvmisc.c is going out to lunch.  A simple workaround is to
966+# if XV locks up whenever you click on *any* of the buttons, the Timer()
967+# function in xvmisc.c is going out to lunch.  A simple workaround is to
968 # uncomment the following line:
969 #TIMERS = -DNOTIMER
970
971@@ -160,7 +295,7 @@
972 #DXWM = -DDXWM
973
974
975-# if, during compilation, your system complains about the types
976+# if, during compilation, your system complains about the types
977 # 'u_long', 'u_short', 'u_int', etc. as being undefined, uncomment the
978 # following line:
979 #BSDTYPES = -DBSDTYPES
980@@ -177,18 +312,38 @@
981 #VPRINTF = -DNEED_VPRINTF -DLONGINT -DNOSTDHDRS
982
983
984+# if your machine puts the prototype for 'malloc()' in malloc.h rather than
985+# stdlib.h, uncomment the following line:
986+#
987+#MALLOC = -DNEED_MALLOC_H
988
989
990-################ END OF CONFIGURATION OPTIONS #################
991+# if your X Window System compiled with -DX_LOCALE,
992+# uncomment the following line:
993+# TVL10N = -DX_LOCALE
994+
995+# Install directory of xv_mgcsfx.sample.
996+MGCSFXDIR = $(LIBDIR)
997+# Directory of default configuration file.
998+MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"
999+
1000
1001
1002
1003+################ END OF CONFIGURATION OPTIONS #################
1004+
1005
1006-CFLAGS = $(CCOPTS) $(JPEG) $(JPEGINC) $(TIFF) $(TIFFINC) $(PDS) \
1007-	$(NODIRENT) $(VPRINTF) $(TIMERS) $(UNIX) $(BSDTYPES) $(RAND) \
1008-	$(DXWM) $(MCHN)
1009
1010-LIBS = -lX11 $(JPEGLIB) $(TIFFLIB) -lm
1011+
1012+CFLAGS = $(CCOPTS) $(PNG) $(PNGINC) $(ZLIBINC) $(JPEG) $(JPEGINC) \
1013+	$(TIFF) $(TIFFINC) $(PDS) $(JP2K) $(JP2KINC) $(TVL10N) $(MGCSFX) \
1014+	$(UNIX) $(BSDTYPES) $(RAND) $(MALLOC) $(DXWM) $(MCHN) $(NODIRENT) \
1015+	$(VPRINTF) $(TIMERS) -DDOCDIR=\"$(DOCDIR)\" \
1016+	-DSYSCONFDIR=\"$(SYSCONFDIR)\" -DXVEXECPATH=\"$(LIBDIR)\"
1017+
1018+### remove -lm for BeOS:
1019+LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -L/usr/X11R6/lib -lX11 -lm
1020+#LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -lX11
1021
1022 OBJS = 	xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
1023 	xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
1024@@ -196,7 +351,9 @@
1025 	xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o \
1026 	xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o \
1027 	xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
1028-	xvxwd.o xvfits.o
1029+	xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o xvhips.o \
1030+	xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
1031+	xvml.o xvjp2k.o
1032
1033 MISC = README INSTALL CHANGELOG IDEAS
1034
1035@@ -206,10 +363,12 @@
1036
1037
1038
1039-all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
1040+#all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
1041+all: xv bggen vdcomp xcmap xvpictoppm
1042
1043
1044-xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
1045+#xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
1046+xv: $(OBJS)
1047 	$(CC) -o xv $(CFLAGS) $(OBJS) $(LIBS)
1048
1049 bggen: bggen.c
1050@@ -231,23 +390,47 @@
1051
1052 clean:  xvclean
1053 	rm -f bggen vdcomp xcmap xvpictoppm
1054-	./cleandir $(JPEGDIR)
1055-	rm -f $(JPEGDIR)/jconfig.h $(JPEGDIR)/Makefile
1056-	./cleandir $(TIFFDIR)
1057+#	clean only local jpeg and tiff dirs, not user's or system's copies:
1058+	./$(CLEANDIR) jpeg
1059+	rm -f jpeg/jconfig.h jpeg/Makefile
1060+	./$(CLEANDIR) tiff
1061
1062
1063+# could also do some shell trickery here to attempt mkdir only if dir is
1064+# missing (e.g., "test -d <dir> || $(MKDIR) <dir>")
1065 install: all
1066-	cp xv bggen vdcomp xcmap xvpictoppm $(BINDIR)
1067-	cp docs/xv.man     $(MANDIR)/xv.$(MANSUF)
1068-	cp docs/bggen.man  $(MANDIR)/bggen.$(MANSUF)
1069-	cp docs/xcmap.man  $(MANDIR)/xcmap.$(MANSUF)
1070-	cp docs/xvp2p.man  $(MANDIR)/xvpictoppm.$(MANSUF)
1071-	cp docs/vdcomp.man $(MANDIR)/vdcomp.$(MANSUF)
1072-	cp docs/xvdocs.ps* $(LIBDIR)
1073+	$(MKDIR) $(DESTDIR)$(BINDIR)
1074+	cp xv bggen vdcomp xcmap xvpictoppm $(DESTDIR)$(BINDIR)/.
1075+	chmod 755 $(DESTDIR)$(BINDIR)/xv $(DESTDIR)$(BINDIR)/bggen \
1076+	  $(DESTDIR)$(BINDIR)/vdcomp $(DESTDIR)$(BINDIR)/xcmap \
1077+	  $(DESTDIR)$(BINDIR)/xvpictoppm
1078+#
1079+	$(MKDIR) $(DESTDIR)$(MANDIR)
1080+	cp docs/xv.man     $(DESTDIR)$(MANDIR)/xv.$(MANSUF)
1081+	cp docs/bggen.man  $(DESTDIR)$(MANDIR)/bggen.$(MANSUF)
1082+	cp docs/xcmap.man  $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF)
1083+	cp docs/xvp2p.man  $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF)
1084+	cp docs/vdcomp.man $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
1085+	chmod 644 $(DESTDIR)$(MANDIR)/xv.$(MANSUF) \
1086+	  $(DESTDIR)$(MANDIR)/bggen.$(MANSUF) \
1087+	  $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF) \
1088+	  $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF) \
1089+	  $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
1090+#
1091+	$(MKDIR) $(DESTDIR)$(DOCDIR)		# or $(DESTDIR)$(LIBDIR)
1092+	cp README.jumbo docs/xvdocs.pdf docs/xvdocs.ps $(DESTDIR)$(DOCDIR)/.
1093+	chmod 644 $(DESTDIR)$(DOCDIR)/README.jumbo \
1094+	  $(DESTDIR)$(DOCDIR)/xvdocs.pdf $(DESTDIR)$(DOCDIR)/xvdocs.ps
1095+#
1096+	#$(MKDIR) $(DESTDIR)$(SYSCONFDIR)
1097+	#cp xv_mgcsfx.sample $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
1098+	#chmod 644 $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
1099+
1100
1101 tar:
1102+#	tar only local jpeg and tiff dirs, not user's or system's copies:
1103 	tar cvf xv.tar Makefile* Imakefile *.c *.h bits \
1104-		docs unsupt vms $(JPEGDIR) $(TIFFDIR) $(MISC)
1105+		docs unsupt vms jpeg tiff $(MISC)
1106
1107 xvtar:
1108 	tar cvf xv.tar Makefile* Imakefile *.c *.h bits
1109@@ -257,26 +440,28 @@
1110
1111 ################# bitmap dependencies ####################
1112
1113-xv.o:      	bits/icon bits/iconmask bits/runicon bits/runiconm
1114-xv.o:      	bits/cboard50 bits/gray25
1115+xv.o:		bits/icon bits/iconmask bits/runicon bits/runiconm
1116+xv.o:		bits/cboard50 bits/gray25
1117
1118 xvbrowse.o:	bits/br_file bits/br_dir bits/br_exe bits/br_chr bits/br_blk
1119-xvbrowse.o:	bits/br_sock bits/br_fifo bits/br_error bits/br_unknown
1120-xvbrowse.o:	bits/br_cmpres bits/br_gif bits/br_pm bits/br_pbm
1121+xvbrowse.o:	bits/br_sock bits/br_fifo bits/br_error # bits/br_unknown
1122+xvbrowse.o:	bits/br_cmpres bits/br_bzip2 bits/br_gif bits/br_pm bits/br_pbm
1123 xvbrowse.o:	bits/br_sunras bits/br_bmp bits/br_utah bits/br_iris
1124-xvbrowse.o:	bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds
1125-xvbrowse.o:	bits/br_ps bits/br_iff bits/br_targa bits/br_xpm
1126+xvbrowse.o:	bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds bits/br_pcd
1127+xvbrowse.o:	bits/br_ps bits/br_iff bits/br_targa bits/br_xpm bits/br_xwd
1128+xvbrowse.o:	bits/br_fits bits/br_png bits/br_zx bits/br_mag bits/br_maki
1129+xvbrowse.o:	bits/br_pic bits/br_pi bits/br_pic2 bits/br_mgcsfx
1130+xvbrowse.o:	bits/br_jp2 bits/br_jpc
1131 xvbrowse.o:	bits/br_trash bits/fcurs bits/fccurs bits/fdcurs bits/fcursm
1132-xvbrowse.o:     bits/br_xwd
1133
1134 xvbutt.o:	bits/cboard50 bits/rb_frame bits/rb_frame1 bits/rb_top
1135 xvbutt.o:	bits/rb_bot bits/rb_dtop bits/rb_dbot bits/rb_body
1136 xvbutt.o:	bits/rb_dot bits/cb_check bits/mb_chk
1137
1138 xvctrl.o:	bits/gray25 bits/gray50 bits/i_fifo bits/i_chr bits/i_dir
1139-xvctrl.o: 	bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
1140+xvctrl.o:	bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
1141 xvctrl.o:	bits/h_rotl bits/h_rotr bits/fliph bits/flipv bits/p10
1142-xvctrl.o:	bits/m10 bits/cut bits/copy bits/paste bits/clear
1143+xvctrl.o:	bits/m10 bits/cut bits/copy bits/paste bits/clear
1144 xvctrl.o:	bits/uicon bits/oicon1 bits/oicon2 bits/icon
1145 xvctrl.o:	bits/padimg bits/annot
1146
1147@@ -285,13 +470,13 @@
1148 xvdflt.o:	bits/logo_top bits/logo_bot bits/logo_out bits/xv_jhb
1149 xvdflt.o:	bits/xv_cpyrt bits/xv_rev bits/xv_ver
1150 xvdflt.o:	bits/xf_left bits/xf_right bits/font5x9.h
1151-xvdflt.o:       xvdflt.h
1152+xvdflt.o:	xvdflt.h
1153
1154 xvdial.o:	bits/dial_cw1 bits/dial_ccw1 bits/dial_cw2 bits/dial_ccw2
1155
1156 xvdir.o:	bits/d_load bits/d_save
1157
1158-xvevent.o:	bits/dropper bits/dropperm bits/pen bits/penm
1159+xvevent.o:	bits/dropper bits/dropperm bits/pen bits/penm
1160 xvevent.o:	bits/blur bits/blurm
1161
1162 xvgam.o:	bits/h_rotl bits/h_rotr bits/h_flip bits/h_sinc bits/h_sdec
1163diff -ru xv-3.10a/bggen.c xv-3.10a-enhancements/bggen.c
1164--- xv-3.10a/bggen.c	1994-12-22 14:34:41.000000000 -0800
1165+++ xv-3.10a-enhancements/bggen.c	2005-04-17 14:04:22.000000000 -0700
1166@@ -18,6 +18,11 @@
1167 #include <stdio.h>
1168 #include <math.h>
1169
1170+#ifdef __STDC__
1171+#  include <stdlib.h>	/* atoi() */
1172+#  include <ctype.h>	/* isdigit() */
1173+#endif
1174+
1175 #ifndef M_PI
1176 #  define M_PI       3.1415926535897932385
1177 #endif
1178@@ -29,7 +34,7 @@
1179 #define MAXCOLS  128
1180
1181 /* some VMS thing... */
1182-#ifdef vax11c
1183+#if defined(vax11c) || (defined(__sony_news) && (defined(bsd43) || defined(__bsd43) || defined(SYSTYPE_BSD) || defined(__SYSTYPE_BSD)))
1184 #include <ctype.h>
1185 #endif
1186
1187@@ -46,8 +51,8 @@
1188
1189 typedef unsigned char byte;
1190
1191-struct   color { int   r,g,b;
1192-		 int   y;
1193+struct   color { int   r,g,b;
1194+		 int   y;
1195 	       } colors[MAXCOLS], *cur, *nex;
1196
1197 int      numcols;
1198@@ -62,7 +67,7 @@
1199 double computeDist PARM((int, int, int, int, int));
1200 void   writePPM    PARM((byte *, int, int, int));
1201
1202-
1203+
1204 /*************************************/
1205 int main(argc,argv)
1206      int    argc;
1207@@ -80,18 +85,18 @@
1208   char *geom    = NULL;
1209   char *rptgeom = NULL;
1210
1211-
1212+
1213 #ifdef VMS
1214   getredirection(&argc, &argv);
1215 #endif
1216-
1217+
1218
1219   for (i=1; i<argc; i++) {
1220     if (!strncmp(argv[i],"-d",(size_t) 2)) {         /* -d disp */
1221       i++;  if (i<argc) dname = argv[i];
1222     }
1223   }
1224-
1225+
1226   if ((theDisp = XOpenDisplay(dname)) == NULL) {
1227     fprintf(stderr,"bggen:  Warning - can't open display, screen %s",
1228 	    "size unknown, color names not accepted.\n");
1229@@ -99,41 +104,41 @@
1230
1231
1232   cnt = 0;  numcols = 0;
1233-
1234+
1235   /* parse cmd-line args */
1236   for (i=1; i<argc; i++) {
1237     if (!strcmp(argv[i],"-h")) {                          /* -h high */
1238       i++;  if (i<argc) high = atoi(argv[i]);
1239       hset++;
1240     }
1241-
1242+
1243     else if (!strcmp(argv[i],"-w")) {                     /* -w wide */
1244       i++;  if (i<argc) wide = atoi(argv[i]);
1245       wset++;
1246     }
1247-
1248+
1249     else if (!strcmp(argv[i],"-b")) {                     /* -b bits */
1250       i++;  if (i<argc) bits = atoi(argv[i]);
1251     }
1252-
1253+
1254     else if (!strncmp(argv[i],"-g",(size_t) 2)) {         /* -g geom */
1255       i++;  if (i<argc) geom = argv[i];
1256     }
1257-
1258+
1259     else if (!strncmp(argv[i],"-d",(size_t) 2)) {         /* -d disp */
1260       i++;  if (i<argc) dname = argv[i];
1261     }
1262-
1263+
1264     else if (!strcmp(argv[i],"-G")) {                      /* -G rptgeom */
1265       i++;  if (i<argc) rptgeom = argv[i];
1266     }
1267-
1268+
1269     else if (!strncmp(argv[i],"-a",(size_t) 2)) doascii++;  /* -a */
1270-
1271+
1272     else if (!strcmp(argv[i],"-r")) {                     /* -r rot */
1273       i++;  if (i<argc) rot = atoi(argv[i]);
1274     }
1275-
1276+
1277     else if (argv[i][0]=='-') usage();    /* any other '-' option is unknown */
1278
1279     else if (isdigit(argv[i][0])) {
1280@@ -143,7 +148,7 @@
1281       case 2:  colors[numcols].b = atoi(argv[i]);  break;
1282       }
1283       cnt++;
1284-
1285+
1286       if (cnt==3) {
1287 	if (numcols<MAXCOLS) numcols++;
1288 	cnt = 0;
1289@@ -176,50 +181,50 @@
1290       }
1291     }
1292   }
1293-
1294-
1295-
1296+
1297+
1298+
1299   /* print error/usage message, if appropriate */
1300   if (cnt || numcols==0 || high<1 || wide<1 || bits<1 || bits>8) usage();
1301-
1302-
1303+
1304+
1305   if (geom) {
1306     int x,y;  unsigned int w,h;
1307     i = XParseGeometry(geom, &x, &y, &w, &h);
1308     if (i&WidthValue)  { wset++;  wide = (int) w; }
1309     if (i&HeightValue) { hset++;  high = (int) h; }
1310   }
1311-
1312-
1313+
1314+
1315   /* attempt to connect to X server and get screen dimensions */
1316   if (theDisp) {
1317     i = DefaultScreen(theDisp);
1318     if (!wset) wide = DisplayWidth(theDisp, i);
1319     if (!hset) high = DisplayHeight(theDisp, i);
1320   }
1321-
1322-
1323+
1324+
1325   /* normalize 'rot' */
1326   while (rot<   0) rot += 360;
1327   while (rot>=360) rot -= 360;
1328-
1329-
1330+
1331+
1332   rptwide = wide;  rpthigh = high;
1333   if (rptgeom) {
1334     int x,y;  unsigned int w,h;
1335     i = XParseGeometry(rptgeom, &x, &y, &w, &h);
1336     if (i&WidthValue)  rptwide = (int) w;
1337     if (i&HeightValue) rpthigh = (int) h;
1338-
1339+
1340     RANGE(rptwide, 1, wide);
1341     RANGE(rpthigh, 1, high);
1342   }
1343-
1344-
1345
1346-
1347+
1348+
1349+
1350   rpic24 = (byte *) malloc(rptwide * rpthigh * 3 * sizeof(byte));
1351-  if (rptwide != wide || rpthigh != high)
1352+  if (rptwide != wide || rpthigh != high)
1353     pic24  = (byte *) malloc(wide * high * 3 * sizeof(byte));
1354   else pic24 = rpic24;
1355
1356@@ -229,7 +234,7 @@
1357     exit(1);
1358   }
1359   for (i=0, pp=pic24; i<wide*high*3; i++) *pp++ = 0;
1360-
1361+
1362
1363
1364   /*** generate image ***/
1365@@ -244,34 +249,34 @@
1366       }
1367     }
1368   }
1369-
1370-
1371+
1372+
1373   else if (rot==0) {   /* un-rotated linear (vertical) gradient */
1374     for (i=0; i<numcols; i++)
1375       colors[i].y = ((rpthigh-1) * i) / (numcols-1);
1376-
1377+
1378     cur = &colors[0];  nex = cur+1;
1379-
1380+
1381     for (i=0; i<rpthigh; i++) {
1382       pp = rpic24 + (i * rptwide * 3);
1383
1384       /* advance to next pair of colors if we're outside region */
1385       while (nex->y < i) { cur++; nex++; }
1386-
1387+
1388       r = cur->r + ((nex->r - cur->r) * (i - cur->y)) / (nex->y - cur->y);
1389       g = cur->g + ((nex->g - cur->g) * (i - cur->y)) / (nex->y - cur->y);
1390       b = cur->b + ((nex->b - cur->b) * (i - cur->y)) / (nex->y - cur->y);
1391-
1392+
1393       r = r & bmask[bits-1];
1394       g = g & bmask[bits-1];
1395       b = b & bmask[bits-1];
1396-
1397+
1398       for (j=0; j<rptwide; j++) {
1399 	*pp++ = (byte) r;  *pp++ = (byte) g;  *pp++ = (byte) b;
1400       }
1401     }
1402   }
1403-
1404+
1405   else dorot(rpic24, rptwide, rpthigh, rot);
1406
1407
1408@@ -293,7 +298,7 @@
1409 	y = ((i-ay) % rpthigh);
1410
1411 	sp = rpic24 + (y * rptwide + x) * 3;
1412-
1413+
1414 	pp[0] = *sp++;  pp[1] = *sp++;  pp[2] = *sp++;
1415       }
1416     }
1417@@ -355,12 +360,12 @@
1418     mind = computeDist(w-1,  0,    cx, cy, rot);
1419     maxd = computeDist(0,    h-1,  cx, cy, rot);
1420   }
1421-
1422+
1423   del = maxd - mind;         /* maximum distance */
1424-
1425+
1426   distdebug = 0;
1427-
1428-
1429+
1430+
1431   for (y=0; y<h; y++) {
1432     pp = pic + (y * w * 3);
1433     for (x=0; x<w; x++) {
1434@@ -368,11 +373,11 @@
1435       rat = (d - mind) / del;
1436       if (rat<0.0) rat = 0.0;
1437       if (rat>1.0) rat = 1.0;
1438-
1439+
1440       cval = rat * nc1;
1441       bc   = floor(cval);
1442       crat = cval - bc;
1443-
1444+
1445       if (bc < nc1) {
1446 	r = colors[bc].r + crat * (colors[bc+1].r - colors[bc].r);
1447 	g = colors[bc].g + crat * (colors[bc+1].g - colors[bc].g);
1448@@ -383,7 +388,7 @@
1449 	g = colors[nc1].g;
1450 	b = colors[nc1].b;
1451       }
1452-
1453+
1454       *pp++ = (byte) r;  *pp++ = (byte) g;  *pp++ = (byte) b;
1455     }
1456   }
1457@@ -395,9 +400,9 @@
1458      int x,y,cx,cy,rot;
1459 {
1460   /* rot has to be in range 0-359 */
1461-
1462-  double x1, y1, x2, y2, x3, y3, d, d1, b, theta;
1463-
1464+
1465+  double x1, y1, x2, y2, x3, y3, d, d1, b;
1466+
1467   if (rot == 0)   return (double) (y - cy);
1468   if (rot == 180) return (double) (cy - y);
1469
1470@@ -407,7 +412,7 @@
1471   /* x2,y2 = vertical projection onto a || line that runs through cx,cy */
1472   x2 = x1;
1473   y2 = cy - (cx-x2)*tant1;
1474-
1475+
1476   d1 = y2 - y1;  /* vertical distance between lines */
1477   b  = d1 * cost1;
1478
1479@@ -435,11 +440,11 @@
1480      int   w,h,doascii;
1481 {
1482   /* dumps a pic24 in PPM format to stdout */
1483-
1484+
1485   int x,y;
1486-
1487+
1488   printf("P%s %d %d 255\n", (doascii) ? "3" : "6", w, h);
1489-
1490+
1491   for (y=0; y<h; y++) {
1492     if (doascii) {
1493       for (x=0; x<w; x++, pic+=3)
1494diff -ru xv-3.10a/bits/br_targa xv-3.10a-enhancements/bits/br_targa
1495--- xv-3.10a/bits/br_targa	1994-12-22 14:35:30.000000000 -0800
1496+++ xv-3.10a-enhancements/bits/br_targa	2007-04-15 10:40:46.000000000 -0700
1497@@ -1,6 +1,6 @@
1498-#define br_targa_width 48
1499-#define br_targa_height 48
1500-static unsigned char br_targa_bits[] = {
1501+#define br_tga_width 48
1502+#define br_tga_height 48
1503+static unsigned char br_tga_bits[] = {
1504    0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
1505    0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
1506    0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
1507diff -ru xv-3.10a/bits/icon xv-3.10a-enhancements/bits/icon
1508--- xv-3.10a/bits/icon	1994-12-22 14:35:28.000000000 -0800
1509+++ xv-3.10a-enhancements/bits/icon	2004-04-28 08:00:16.000000000 -0700
1510@@ -1,5 +1,6 @@
1511 #define icon_width 40
1512 #define icon_height 32
1513+#ifndef OMIT_ICON_BITS
1514 static unsigned char icon_bits[] = {
1515    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1516    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
1517@@ -15,3 +16,4 @@
1518    0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1519    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1520    0x00, 0x00, 0x00, 0x00};
1521+#endif
1522diff -ru xv-3.10a/cleandir xv-3.10a-enhancements/cleandir
1523--- xv-3.10a/cleandir	1994-12-22 14:34:50.000000000 -0800
1524+++ xv-3.10a-enhancements/cleandir	2004-05-10 23:19:16.000000000 -0700
1525@@ -1,9 +1,13 @@
1526-#!/bin/csh -f
1527+#!/bin/sh -f
1528 # cleandir: if called with an argument, cd's there and does a 'make clean'
1529 #
1530
1531-if ( x$1 != x ) then
1532-  echo "cleaning $1 subdirectory"
1533-  cd $1
1534-  make clean
1535-endif
1536+if [ x"$1" != x ]; then
1537+  if [ -f "$1"/makefile -o -f "$1"/Makefile ]; then
1538+    echo "cleaning '$1' subdirectory"
1539+    cd "$1"
1540+    make clean
1541+# else
1542+#   echo "no makefile found; NOT cleaning '$1' subdirectory"
1543+  fi
1544+fi
1545diff -ru xv-3.10a/config.h xv-3.10a-enhancements/config.h
1546--- xv-3.10a/config.h	1995-01-05 10:49:21.000000000 -0800
1547+++ xv-3.10a-enhancements/config.h	2007-05-14 08:51:10.000000000 -0700
1548@@ -6,25 +6,42 @@
1549 /***************************************************************************
1550  * GZIP'd file support
1551  *
1552- * if you have the gnu uncompression utility 'gunzip', XV can use it to
1553- * automatically 'unzip' any gzip'd files.  To enable this feature,
1554- * change 'undef' to 'define' in the following line.  Needless to say, if
1555- * your gunzip is installed elsewhere on your machine, change the 'GUNZIP'
1556- * definition appropriately. (use 'which gunzip' to find if you have gunzip,
1557- * and where it lives)
1558+ * if you have the GNU uncompression utility 'gunzip' (or 'gzip' itself,
1559+ * which is just a link to gunzip), XV can use it to automatically 'unzip'
1560+ * any gzip'd files.  To enable this feature, change 'undef' to 'define' in
1561+ * the following line.  Needless to say, if your gunzip is installed elsewhere
1562+ * on your machine, change the 'GUNZIP' definition appropriately. (use
1563+ * 'which gunzip' to find if you have gunzip, and where it lives; ditto for
1564+ * gzip)
1565  */
1566-#undef USE_GUNZIP
1567+#define USE_GUNZIP
1568
1569 #ifdef USE_GUNZIP
1570 #  ifdef VMS
1571 #    define GUNZIP "UNCOMPRESS"
1572 #  else
1573-#    define GUNZIP "/usr/local/bin/gunzip -q"
1574+#    define GUNZIP "gzip -dq"
1575 #  endif
1576 #endif
1577
1578
1579 /***************************************************************************
1580+ * BZIP2'd file support
1581+ *
1582+ * if you have the uncompression utility 'bunzip2' (or 'bzip2' itself, which
1583+ * is just a link to bunzip2), XV can use it to automatically 'unzip' any
1584+ * bzip2'd files.  To enable this feature, change 'undef' to 'define' in the
1585+ * following line (if not already done).  Use 'which bunzip2' or 'which bzip2'
1586+ * to find if you have bzip2/bunzip2, and where it lives.
1587+ */
1588+#define USE_BUNZIP2
1589+
1590+#ifdef USE_BUNZIP2
1591+#  define BUNZIP2 "bzip2 -d"  /* should this include the full path? */
1592+#endif
1593+
1594+
1595+/***************************************************************************
1596  * compress'd file support
1597  *
1598  * if you have GUNZIP defined above, just ignore this, as 'gunzip' can
1599@@ -37,9 +54,16 @@
1600  */
1601 #define UNCOMPRESS "/usr/ucb/uncompress"
1602
1603-#if defined(hpux) || defined(SVR4) || defined(__386BSD__)
1604+#if defined(hpux) || defined(SVR4) || \
1605+    defined(__386BSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
1606+    defined(__linux__)
1607+    /*
1608+     I want to use BSD macro for checking if this OS is *BSD or not,
1609+     but the macro is defined in <sys/parm.h>, which I don't know all
1610+     machine has or not.
1611+     */
1612 #  undef  UNCOMPRESS
1613-#  define UNCOMPRESS "/usr/bin/uncompress"
1614+#  define UNCOMPRESS "uncompress"
1615 #endif
1616
1617 #if defined(sgi)
1618@@ -70,18 +94,18 @@
1619  * PostScript file input support:
1620  *
1621  * if you have the 'ghostscript' package installed (version 2.6 or later),
1622- * XV can use it to read and display PostScript files.  To do so,
1623+ * XV can use it to read and display PostScript files.  To do so,
1624  * uncomment the '#define GS_PATH' line, below.  You probably will not
1625  * need to modify the GS_LIB or GS_DEV lines, but if you do modify them,
1626  * be sure to uncomment them, as well.
1627  *
1628- * the ghostscript package can be acquired via anonymous ftp on
1629+ * the ghostscript package can be acquired via anonymous ftp on
1630  * prep.ai.mit.edu, in the 'pub/gnu' directory
1631  *
1632- * GS_PATH specifies the complete path to your gs executable.
1633+ * GS_PATH specifies the complete path to your gs executable.
1634  *
1635- * GS_LIB should be set if there's some other gs libs that should be
1636- * searched, but aren't by default.  (In which case you should probably
1637+ * GS_LIB should be set if there's some other gs libs that should be
1638+ * searched, but aren't by default.  (In which case you should probably
1639  * just fix your 'gs' so it looks in the right places without being told...)
1640  *
1641  * GS_DEV is the file format that ghostscript will convert PS into.  It
1642@@ -89,6 +113,7 @@
1643  */
1644
1645 /* #define GS_PATH "/usr/local/bin/gs" */
1646+#define GS_PATH "gs"
1647 /* #define GS_LIB  "."                 */
1648 /* #define GS_DEV  "ppmraw"            */
1649
1650@@ -97,10 +122,10 @@
1651  * 'old-style' XV logo image:
1652  *
1653  * XV now has a nifty, new logo image.  The downside is that it increases
1654- * the size of the 'xv' executable by 250K or so, and it's possible that
1655- * your compiler may choke while compiling 'xvdflt.c'.  If you're compiler
1656+ * the size of the 'xv' executable by 250K or so, and it's possible that
1657+ * your compiler may choke while compiling 'xvdflt.c'.  If your compiler
1658  * can't handle it, or you're running Linux on a system with minimal memory,
1659- * change 'undef' to 'define' in the following line
1660+ * change 'undef' to 'define' in the following line:
1661  */
1662
1663 #undef USEOLDPIC
1664@@ -108,8 +133,8 @@
1665
1666 /***************************************************************************
1667  * Backing Store:
1668- *
1669- * XV can request that 'Backing Store' may be turned on ('WhenMapped') for
1670+ *
1671+ * XV can request that 'Backing Store' may be turned on ('WhenMapped') for
1672  * several of its windows, which may help performance over a slow network
1673  * connection.  However, it has been known to behave strangely (or crash)
1674  * on some X servers, so it's left here as an option.  If you run into trouble
1675@@ -119,3 +144,218 @@
1676
1677 #define BACKING_STORE
1678
1679+
1680+/***************************************************************************
1681+ * TIFF YCbCr-to-RGB conversion:
1682+ *
1683+ * Newer versions of libtiff can be compiled with libjpeg for JPEG-in-TIFF
1684+ * support, and according to Scott Marovich, "the IJG JPEG Library...sometimes
1685+ * seems to produce slightly more accurate results" (one known example:  the
1686+ * 'quad-jpeg.tif' test image).  In addition, libtiff can be compiled with
1687+ * "old JPEG" support, although its configure script will not enable that by
1688+ * default.  Change 'define' and 'undef' in the following lines as you wish,
1689+ * but note that defining LIBTIFF_HAS_OLDJPEG_SUPPORT when such is _not_ the
1690+ * case will result in crashes when encountering old-JPEG TIFFs:
1691+ */
1692+
1693+#define USE_LIBJPEG_FOR_TIFF_YCbCr_RGB_CONVERSION
1694+#undef LIBTIFF_HAS_OLDJPEG_SUPPORT
1695+
1696+
1697+/***************************************************************************
1698+ * PhotoCD/MAG/PIC/MAKI/Pi/PIC2/HIPS format Support:
1699+ *
1700+ * if, for whatever reason--say, security concerns--you don't want to
1701+ * include support for one or more of the PhotoCD, MAG/MAKI/Pi/PIC/PIC2
1702+ * (Japanese), or HIPS (astronomical) image formats, change the relevant
1703+ * 'define' to 'undef' in the following lines.  Conversely, if you *do*
1704+ * want them, change 'undef' to 'define' as appropriate.
1705+ */
1706+
1707+#define HAVE_PCD	/* believed to be reasonably safe */
1708+
1709+#undef HAVE_MAG		/* probable security issues */
1710+#undef HAVE_MAKI	/* probable security issues */
1711+#undef HAVE_PI		/* probable security issues */
1712+#undef HAVE_PIC		/* probable security issues */
1713+#undef HAVE_PIC2	/* probable security issues */
1714+
1715+#undef HAVE_HIPS	/* probable security issues */
1716+
1717+
1718+/***************************************************************************
1719+ * MacBinary file support:
1720+ *
1721+ * if you want XV to be able to handle ``MacBinary'' files (which have
1722+ * 128 byte info file header at the head), change 'undef' to 'define'
1723+ * in the following line.
1724+ */
1725+
1726+#undef MACBINARY
1727+
1728+
1729+/***************************************************************************
1730+ * Auto Expand support:
1731+ *
1732+ * if you want to extract archived file automatically and regard it as
1733+ * a directory, change 'undef' to 'define' in the AUTO_EXPAND line.
1734+ *
1735+ * Virtual Thumbdir support:
1736+ *
1737+ * if you want Virtual directory based Thumbdir(It means that XV
1738+ * doesn't forget builded Icons still be quited even if the directory
1739+ * is read-only), change 'undef' to 'define' the VIRTUAL_TD line.
1740+ */
1741+
1742+#undef AUTO_EXPAND
1743+#undef VIRTUAL_TD
1744+
1745+#if defined(VIRTUAL_TD) && !defined(AUTO_EXPAND)
1746+#  undef VIRTUAL_TD
1747+#endif
1748+
1749+
1750+/***************************************************************************
1751+ * Adjust the aspect ratio of Icons:
1752+ *
1753+ * if you want to adjust the aspect ratio of the icons in Visual
1754+ * Schnauzer, change 'undef' to 'define' in the following line.
1755+ */
1756+
1757+#undef VS_ADJUST
1758+
1759+
1760+/***************************************************************************
1761+ * Restore original colormap:
1762+ *
1763+ * if you want to restore original colormap when icons in Visual
1764+ * Shunauzer is double-clicked, change 'undef' to 'define' in the
1765+ * following line.
1766+ */
1767+
1768+#undef VS_RESCMAP
1769+
1770+
1771+/***************************************************************************
1772+ * TextViewer l10n support:
1773+ *
1774+ * if you want XV to show the text in Japanese on TextViewer, change
1775+ * 'undef' to 'define' in the following line.
1776+ */
1777+
1778+#undef TV_L10N
1779+
1780+#ifdef TV_L10N
1781+/*
1782+ * if you want to change the default code-set used in case that XV
1783+ * fails to select correct code-set, uncomment the '#define
1784+ * LOCALE_DEFAULT' line and change the 'LOCALE_DEFAULT' definition
1785+ * appropriately.
1786+ * (0:ASCII, 1:EUC-j, 2:JIS, 3:MS Kanji) */
1787+
1788+/* #  define LOCALE_DEFAULT 0 */
1789+
1790+/*
1791+ * Uncomment and edit the following lines, if your X Window System was
1792+ * not compiled with -DX_LOCALE and you failed to display the Japanese
1793+ * text in TextViewer.  You don't have to write locale name of JIS code-set
1794+ * and Microsoft code-set, if your system doesn't support those code-sets.
1795+ */
1796+
1797+/*
1798+#  define LOCALE_NAME_EUC     "ja_JP.EUC"
1799+#  define LOCALE_NAME_JIS     "ja_JP.JIS"
1800+#  define LOCALE_NAME_MSCODE  "ja_JP.SJIS"
1801+*/
1802+
1803+/*
1804+ * if your system doesn't have the Japanese fonts in the sizes,
1805+ * Uncomment and edit the following font size entries.
1806+ */
1807+
1808+/* #  define TV_FONTSIZE 14,16,24 */
1809+
1810+/*
1811+ * If you need, uncomment and modify the following font name.
1812+ */
1813+
1814+/* #  define TV_FONTSET "-*-fixed-medium-r-normal--%d-*" */
1815+#endif /* TV_L10N */
1816+
1817+
1818+/***************************************************************************
1819+ * User definable filter support:
1820+ *
1821+ * Use the filters as input and output method for load and save unsupported
1822+ * image format file. The filter command is recognized by definition of
1823+ * magic number or suffix in "~/.xv_mgcsfx" .
1824+ * To enable this feature, change 'undef' to 'define' in the following line.
1825+ */
1826+#undef HAVE_MGCSFX
1827+
1828+#ifdef HAVE_MGCSFX
1829+/*
1830+ * Support symbol 'auto' as <input image type> in startup file. This type
1831+ * cannot use pipe as input; it writes to a temporary file and recognizes
1832+ * the actual filetype by XV processing.
1833+ */
1834+#  define HAVE_MGCSFX_AUTO
1835+
1836+/*
1837+ * The startup file of definition for MgcSfx. 'MGCSFX_SITE_RC' is read
1838+ * first and '~/MGCSFX_RC' is second. So same definitions in both files
1839+ * are overridden by '~/MGCSFX_RC'
1840+ * To define startup file, see the sample of startup file 'xv_mgcsfx.sample'.
1841+ */
1842+#  define MGCSFX_SITE_RC  "xv_mgcsfx"
1843+#  define MGCSFX_RC       ".xv_mgcsfx"
1844+
1845+/*
1846+ * If you want startup file to pass preprocessor in reading time, then
1847+ * change 'undef' to 'define' in the following line.
1848+ *
1849+ * WARNING : If you decide to use preprocessor, you must not write
1850+ *           '# <comment>' style comment in startup file. Because,
1851+ *           preprocessor can't recognize.  */
1852+#  undef USE_MGCSFX_PREPROCESSOR
1853+
1854+#  ifdef USE_MGCSFX_PREPROCESSOR
1855+/*
1856+ * This is used like "system("MGCSFX_PREPROCESSOR MGCSFX_RC > tmp_name");",
1857+ * and read tmp_name instead of MGCSFX_RC.
1858+ */
1859+#    define MGCSFX_PREPROCESSOR "/usr/lib/cpp"
1860+/* #    define MGCSFX_PREPROCESSOR "cc -E" */
1861+
1862+#  endif /* USE_MGCSFX_PREPROCESSOR */
1863+
1864+/*
1865+ * Default string of command. If input command is required for undefined file,
1866+ * dialog is popuped with 'MGCSFX_DEFAULT_INPUT_COMMAND'. And, if output
1867+ * command is required in save dialog of MgcSfx, dialog is popuped with
1868+ * 'MGCSFX_DEFAULT_OUTPUT_COMMAND'.
1869+ *
1870+ * WARNING : Now, supported only 'PNM' image format, when command input is
1871+ *           required. You should define filter which use 'PNM' image format
1872+ *           as input or output.
1873+ */
1874+#  define MGCSFX_DEFAULT_INPUT_COMMAND  "tifftopnm"
1875+#  define MGCSFX_DEFAULT_OUTPUT_COMMAND "pnmtotiff"
1876+
1877+#endif /* HAVE_MGCSFX */
1878+
1879+
1880+/***************************************************************************
1881+ * Multi-Lingual TextViewer
1882+ *
1883+ * if you want XV to show the text in multi-lingual on TextViewer, change
1884+ * 'undef' to 'define' in the following line.
1885+ */
1886+
1887+#undef TV_MULTILINGUAL
1888+
1889+#define TV_DEFAULT_CODESET TV_EUC_JAPAN
1890+
1891+#ifdef TV_MULTILINGUAL
1892+#  undef TV_L10N
1893+#endif
1894diff -ru xv-3.10a/copyright.h xv-3.10a-enhancements/copyright.h
1895--- xv-3.10a/copyright.h	1994-12-22 14:34:56.000000000 -0800
1896+++ xv-3.10a-enhancements/copyright.h	2007-05-20 21:35:34.000000000 -0700
1897@@ -1,11 +1,11 @@
1898 /* Copyright Notice
1899  * ================
1900  * Copyright 1989, 1994 by John Bradley
1901- *
1902- * Permission to copy and distribute XV in its entirety, for non-commercial
1903- * purposes, is hereby granted without fee, provided that this license
1904+ *
1905+ * Permission to copy and distribute XV in its entirety, for non-commercial
1906+ * purposes, is hereby granted without fee, provided that this license
1907  * information and copyright notice appear unmodified in all copies.
1908- *
1909+ *
1910  * Note that distributing XV 'bundled' in with any product is considered
1911  * to be a 'commercial purpose'.
1912  *
1913@@ -13,16 +13,16 @@
1914  * and/or configured to be in their 'unregistered copy' mode, so that it
1915  * is made obvious to the user that XV is shareware, and that they should
1916  * consider donating, or at least reading this License Info.
1917- *
1918+ *
1919  * The software may be modified for your own purposes, but modified
1920  * versions may not be distributed without prior consent of the author.
1921- *
1922+ *
1923  * This software is provided 'as-is', without any express or implied
1924  * warranty.  In no event will the author be held liable for any damages
1925  * arising from the use of this software.
1926- *
1927+ *
1928  * If you would like to do something with XV that this copyright
1929- * prohibits (such as distributing it with a commercial product,
1930+ * prohibits (such as distributing it with a commercial product,
1931  * using portions of the source in some other program, etc.), please
1932  * contact the author (preferably via email).  Arrangements can
1933  * probably be worked out.
1934@@ -34,13 +34,13 @@
1935  * larger donations are quite welcome.  Folks who donate $25 or more
1936  * can receive a Real Nice bound copy of the XV manual for no extra
1937  * charge.
1938- *
1939+ *
1940  * Commercial, government, and institutional users must register their
1941  * copies of XV, for the price of $25 per workstation/X terminal or per
1942  * XV user, whichever is less.  Note that it does NOT say 'simultaneous user',
1943- * but rather, the total number of people who use XV on any sort of
1944- * recurring basis. Site licenses are available (and recommended) for those
1945- * who wish to run XV on a large (>10) number of machines.
1946+ * but rather, the total number of people who use XV on any sort of
1947+ * recurring basis. Site licenses are available (and recommended) for those
1948+ * who wish to run XV on a large (>10) number of machines.
1949  * Contact the author for more details.
1950  *
1951  * The author may be contacted via:
1952@@ -56,3 +56,51 @@
1953  * The author may not be contacted by (voice) phone.  Please don't try.
1954  *
1955  */
1956+
1957+/*
1958+ * Portions copyright 2000-2007 by Greg Roelofs and contributors:
1959+ *
1960+ *   Andrey A. Chernov [ache]
1961+ *     (http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-ab)
1962+ *   Andreas Dilger (adilger clusterfs.com)
1963+ *   Alexander Lehmann (lehmann usa.net)
1964+ *   Alexey Spiridonov (http://www-math.mit.edu/~lesha/)
1965+ *   Anthony Thyssen (http://www.cit.gu.edu.au/~anthony/)
1966+ *   Bruno Rohee (http://bruno.rohee.com/)
1967+ *   David A. Clunie (http://www.dclunie.com/xv-pcd.html)
1968+ *   Erling A. Jacobsen (linuxcub email.dk)
1969+ *   Egmont Koblinger (egmont users.sourceforge.net)
1970+ *   Fabian Greffrath (fabian debian-unofficial.org)
1971+ *   Greg Roelofs (http://pobox.com/~newt/greg_contact.html)
1972+ *   Guido Vollbeding (http://sylvana.net/guido/)
1973+ *   IKEMOTO Masahiro (ikeyan airlab.cs.ritsumei.ac.jp)
1974+ *   John Cooper (john.cooper third-harmonic.com)
1975+ *   John C. Elliott (http://www.seasip.demon.co.uk/ZX/zxdload.html)
1976+ *   John D. Baker (http://mylinuxisp.com/~jdbaker/)
1977+ *   J�rgen Grahn (jgrahn algonet.se)
1978+ *   John H. Bradley, of course (http://www.trilon.com/xv/)
1979+ *   Jean-Pierre Demailly (http://www-fourier.ujf-grenoble.fr/~demailly/)
1980+ *   John Rochester (http://www.freebsd.org/cgi/query-pr.cgi?pr=2920)
1981+ *   (also http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-af, -ag)
1982+ *   James Roberts Kirkpatrick (uwyo.edu)
1983+ *   Joe Zbiciak (http://spatula-city.org/~im14u2c/)
1984+ *   Kyoichiro Suda (http://www.coara.or.jp/~sudakyo/XV_jp.html)
1985+ *   Landon Curt "chongo" Noll (http://www.isthe.com/chongo/)
1986+ *   Larry Jones (lawrence.jones ugs.com)
1987+ *   Peter Jordan (http://www.ibiblio.org/pub/Linux/apps/graphics/viewers/X/)
1988+ *   Pawel S. Veselov (http://manticore.2y.net/wbmp.html)
1989+ *   Ross Combs (rocombs cs.nmsu.edu)
1990+ *   Robin Humble (http://www.cita.utoronto.ca/~rjh/)
1991+ *   Sean Borman (http://www.nd.edu/~sborman/software/xvwheelmouse.html)
1992+ *   TenThumbs (tenthumbs cybernex.net)
1993+ *   Scott B. Marovich (formerly marovich hpl.hp.com)
1994+ *   Tim Adye (http://hepwww.rl.ac.uk/Adye/xv-psnewstyle.html)
1995+ *   Tim Ramsey (tar pobox.com)
1996+ *   Tetsuya INOUE (tin329 chino.it.okayama-u.ac.jp)
1997+ *   Tavis Ormandy (taviso gentoo.org)
1998+ *   Werner Fink (http://www.suse.de/~werner/)
1999+ *
2000+ * Other credits are as listed on the XV Downloads page or in the respective
2001+ * patches (e.g., the jp-extension patches or within the PNG patch).
2002+ *
2003+ */
2004diff -ru xv-3.10a/docs/bggen.man xv-3.10a-enhancements/docs/bggen.man
2005--- xv-3.10a/docs/bggen.man	1994-12-22 14:35:22.000000000 -0800
2006+++ xv-3.10a-enhancements/docs/bggen.man	2007-04-22 17:32:11.000000000 -0700
2007@@ -1,4 +1,4 @@
2008-.TH bggen l
2009+.TH bggen 1
2010 .SH NAME
2011 bggen \- generates colored backgrounds on X11 displays
2012 .SH SYNTAX
2013diff -ru xv-3.10a/docs/xcmap.man xv-3.10a-enhancements/docs/xcmap.man
2014--- xv-3.10a/docs/xcmap.man	1994-12-22 14:35:23.000000000 -0800
2015+++ xv-3.10a-enhancements/docs/xcmap.man	2007-04-22 17:32:31.000000000 -0700
2016@@ -1,4 +1,4 @@
2017-.TH xcmap 1X
2018+.TH xcmap 1
2019 .SH NAME
2020 xcmap \- displays the default colormap on X11 displays
2021 .SH SYNTAX
2022diff -ru xv-3.10a/docs/xv.man xv-3.10a-enhancements/docs/xv.man
2023--- xv-3.10a/docs/xv.man	1994-12-22 14:35:22.000000000 -0800
2024+++ xv-3.10a-enhancements/docs/xv.man	2007-04-22 17:32:53.000000000 -0700
2025@@ -1,4 +1,4 @@
2026-.TH XV l "2 December 1994" "Rev. 3.10"
2027+.TH XV 1 "22 April 2007" "Rev. 3.10a-jumboFix+Enh"
2028 .SH NAME
2029 \fBxv\fP \- interactive image display for the X Window System
2030 .SH SYNTAX
2031@@ -8,14 +8,17 @@
2032 .SH DESCRIPTION
2033 The
2034 .I xv
2035-program displays images in the GIF, JPEG, TIFF,
2036-PBM, PGM, PPM, X11 bitmap, Utah Raster Toolkit RLE, PDS/VICAR, Sun Rasterfile,
2037-BMP, PCX, IRIS RGB, XPM, Targa, XWD, possibly PostScript, and PM formats on
2038-workstations and terminals running the X Window System, Version 11.
2039+program displays images on workstations and terminals running the X Window
2040+System, Version 11.  Supported image formats include
2041+PBM, PGM, PPM, X11 bitmap, XWD, XPM, Utah Raster Toolkit RLE, PDS/VICAR,
2042+FITS, Sun Rasterfile, GIF, PCX, Targa/TGA, BMP, WBMP, IRIS RGB, Spectrum
2043+SCREEN$, PM, and optionally PNG, JPEG, JPEG 2000, JP2, TIFF, PostScript,
2044+PDF, G3 fax, MAG, PIC, MAKI (640x400), PI, and PIC2.
2045 .LP
2046-The documentation for XV is now distributed
2047+Aside from the usage screen (available by typing 'xv -help' at the command
2048+line), documentation for XV is now distributed
2049 .I only
2050-as a PostScript file, as it has gotten enormous,
2051+as a PostScript (or PDF) file, as it has gotten enormous
2052 and is no longer very well suited to the 'man' page format.
2053 Print a copy of the (100-ish page) manual found in
2054 .IR docs/xvdocs.ps .
2055@@ -26,9 +29,14 @@
2056 If you don't
2057 .I have
2058 the PostScript file, it is part of the standard XV distribution, the
2059-latest version of which can be obtained via anonymous ftp from
2060+latest version of which can be obtained from
2061+.IR http://www.trilon.com/xv/
2062+or via anonymous ftp from
2063 .IR ftp.cis.upenn.edu
2064-in the directory pub/xv
2065+in the directory pub/xv .
2066+.PP
2067+This version has been patched with the XV Jumbo Patches, available from
2068+.IR http://pobox.com/~newt/greg_xv.html .
2069 .PP
2070 .SH AUTHOR
2071-John Bradley
2072+John Bradley (and many contributors)
2073diff -ru xv-3.10a/docs/xvp2p.man xv-3.10a-enhancements/docs/xvp2p.man
2074--- xv-3.10a/docs/xvp2p.man	1994-12-22 14:35:25.000000000 -0800
2075+++ xv-3.10a-enhancements/docs/xvp2p.man	2007-04-22 17:33:23.000000000 -0700
2076@@ -1,4 +1,4 @@
2077-.TH xvpictoppm 1X
2078+.TH xvpictoppm 1
2079 .SH NAME
2080 xvpictoppm \- converts XV 'thumbnail' files to standard PPM format
2081 .SH SYNTAX
2082diff -ru xv-3.10a/tiff/Makefile xv-3.10a-enhancements/tiff/Makefile
2083--- xv-3.10a/tiff/Makefile	1994-12-22 14:35:12.000000000 -0800
2084+++ xv-3.10a-enhancements/tiff/Makefile	2005-04-17 14:45:28.000000000 -0700
2085@@ -30,13 +30,15 @@
2086 # OF THIS SOFTWARE.
2087 #
2088
2089-AR=     ar
2090-RANLIB=	./RANLIB.csh
2091+AR=	ar
2092+CHMOD=	chmod
2093+#RANLIB=	./RANLIB.csh
2094+RANLIB=	./RANLIB.sh
2095
2096 IPATH= -I.
2097
2098 COPTS=	-O
2099-CFLAGS=	${COPTS} ${IPATH}
2100+CFLAGS=	${COPTS} ${IPATH} -D_BSD_SOURCE
2101
2102 INCS=	tiff.h tiffio.h
2103
2104@@ -60,6 +62,7 @@
2105
2106 ${ALL}:	${OBJS}
2107 	${AR} rc libtiff.a $?
2108+	${CHMOD} +x ${RANLIB}
2109 	${RANLIB} libtiff.a
2110
2111 ${OBJS}:	tiffio.h tiff.h tiffcomp.h tiffiop.h tiffconf.h
2112diff -ru xv-3.10a/tiff/Makefile.std xv-3.10a-enhancements/tiff/Makefile.std
2113--- xv-3.10a/tiff/Makefile.std	1994-12-22 14:35:16.000000000 -0800
2114+++ xv-3.10a-enhancements/tiff/Makefile.std	2004-05-16 18:50:39.000000000 -0700
2115@@ -30,8 +30,10 @@
2116 # OF THIS SOFTWARE.
2117 #
2118
2119-AR=     /bin/ar
2120-RANLIB=	./RANLIB.csh
2121+AR=	/bin/ar
2122+CHMOD=	chmod
2123+#RANLIB=	./RANLIB.csh
2124+RANLIB=	./RANLIB.sh
2125
2126 IPATH= -I.
2127
2128@@ -60,6 +62,7 @@
2129
2130 ${ALL}:	${OBJS}
2131 	${AR} rc libtiff.a $?
2132+	${CHMOD} +x ${RANLIB}
2133 	${RANLIB} libtiff.a
2134
2135 ${OBJS}:	tiffio.h tiff.h tiffcomp.h tiffiop.h tiffconf.h
2136diff -ru xv-3.10a/vdcomp.c xv-3.10a-enhancements/vdcomp.c
2137--- xv-3.10a/vdcomp.c	1994-12-22 14:34:47.000000000 -0800
2138+++ xv-3.10a-enhancements/vdcomp.c	2007-04-15 21:09:55.000000000 -0700
2139@@ -5,8 +5,8 @@
2140 /*  Decompresses images using Kris Becker's subroutine DECOMP.C     */
2141 /*  which is included in this program in a shortened version.       */
2142 /*                                                                  */
2143-/*  Reads a variable length compressed PDS image and outputs a      */
2144-/*  fixed length uncompressed image file in PDS format with         */
2145+/*  Reads a variable-length compressed PDS image and outputs a      */
2146+/*  fixed-length uncompressed image file in PDS format with         */
2147 /*  labels, image histogram, engineering table, line header table   */
2148 /*  and an image with PDS, FITS, VICAR or no labels.  If used on    */
2149 /*  a non-byte-swapped machine the image histogram is un-swapped.   */
2150@@ -96,40 +96,54 @@
2151 #include <stdio.h>
2152 #include <stdlib.h>
2153
2154-/* include a malloc.h, of some sort... */
2155-#ifndef VMS   /* VMS hates multi-line '#if's */
2156-# if !defined(ibm032)                    && \
2157-     !defined(__convex__)                && \
2158-     !(defined(vax) && !defined(ultrix)) && \
2159-     !defined(mips)                      && \
2160-     !defined(apollo)                    && \
2161-     !defined(pyr)                       && \
2162-     !defined(__UMAXV__)                 && \
2163-     !defined(bsd43)                     && \
2164-     !defined(aux)                       && \
2165-     !defined(__bsdi__)                  && \
2166-     !defined(sequent)
2167-
2168-#  if defined(hp300) || defined(hp800) || defined(NeXT)
2169-#   include <sys/malloc.h>                /* it's in 'sys' on HPs and NeXT */
2170-#  else
2171-#   include <malloc.h>
2172-#  endif
2173-# endif
2174+/* include a malloc.h of some sort (if needed...most systems use stdlib.h) */
2175+#ifndef VMS   /* VMS hates multi-line "#if"s */
2176+   /*
2177+    * I want to use BSD macro for checking if this OS is *BSD or not,
2178+    * but the macro is defined in <sys/parm.h>, which I don't know all
2179+    * machine has or not.
2180+    */
2181+#  if !defined(ibm032)                    && \
2182+      !defined(__convex__)                && \
2183+      !(defined(vax) && !defined(ultrix)) && \
2184+      !defined(mips)                      && \
2185+      !defined(apollo)                    && \
2186+      !defined(pyr)                       && \
2187+      !defined(sequent)                   && \
2188+      !defined(__UMAXV__)                 && \
2189+      !defined(aux)                       && \
2190+      !defined(bsd43)                     && \
2191+      !defined(__bsd43)                   && \
2192+      !defined(__bsdi__)                  && \
2193+      !defined(__386BSD__)                && \
2194+      !defined(__FreeBSD__)               && \
2195+      !defined(__OpenBSD__)               && \
2196+      !defined(__NetBSD__)                && \
2197+      !defined(__DARWIN__)
2198+
2199+#    if defined(hp300) || defined(hp800) || defined(NeXT)
2200+#      include <sys/malloc.h>    /* it's in "sys" on HPs and NeXT */
2201+#    else
2202+#      include <malloc.h>        /* FIXME: should explicitly list systems that NEED this, not everyone that doesn't */
2203+#    endif
2204+
2205+#  endif /* !most modern systems */
2206 #endif /* !VMS */
2207
2208
2209 #include <X11/Xos.h>
2210
2211-#define TRUE                  1
2212-#define FALSE                 0
2213+#define TRUE         1
2214+#define FALSE        0
2215+
2216+#define NAMELEN      1024           /* inname and outname sizes     */
2217
2218-                                    /* pc i/o defines               */
2219-#define O_BINARY         0x8000     /* file mode is binary          */
2220+                                    /* PC I/O defines               */
2221+#define O_BINARY     0x8000         /* file mode is binary          */
2222
2223-                                    /* vax i/o defines              */
2224-#define RECORD_TYPE      "rfm=fix"  /* VAX fixed length output      */
2225-#define CTX              "ctx=bin"  /* no translation of \n         */
2226+                                    /* VAX/VMS I/O defines          */
2227+#define RECORD_TYPE  "rfm=fix"      /* VAX/VMS fixed-length output  */
2228+#define CTX          "ctx=bin"      /* no translation of \n         */
2229 #define FOP          "fop=cif,sup"  /* file processing ops          */
2230
2231 typedef struct leaf { struct leaf *right;
2232@@ -142,9 +156,9 @@
2233  once the tree is created by the accompanying routine huff_tree.
2234 **************************************************************************/
2235
2236-  NODE *tree;
2237+static NODE *tree;
2238
2239-/* subroutine definitions                                           */
2240+/* subroutine definitions */
2241
2242 #undef PARM
2243 #ifdef __STDC__
2244@@ -172,11 +186,11 @@
2245 void free_tree    PARM((int *));
2246 int  free_node    PARM((NODE *, int));
2247
2248-/* global variables                                                 */
2249+/* global variables */
2250
2251 int                infile;
2252 FILE               *outfile;
2253-char               inname[1024],outname[1024];
2254+char               inname[NAMELEN], outname[NAMELEN];
2255 int                output_format;
2256 int                record_bytes, max_lines;
2257 int                line_samples, fits_pad;
2258@@ -185,8 +199,8 @@
2259
2260 /*************************************************/
2261 int main(argc,argv)
2262-     int  argc;
2263-     char **argv;
2264+  int  argc;
2265+  char **argv;
2266 {
2267   unsigned char ibuf[2048],obuf[2048];
2268   unsigned char blank=32;
2269@@ -200,12 +214,12 @@
2270   /*                                                                   */
2271   /*********************************************************************/
2272
2273-  strcpy(inname,"   ");
2274+  strcpy(inname,"   ");
2275   strcpy(outname,"   ");
2276   output_format = 0;
2277
2278   if (argc == 1);                     /* prompt user for parameters */
2279-  else if (argc == 2 && (strncmp(argv[1],"help",(size_t) 4) == 0 ||
2280+  else if (argc == 2 && (strncmp(argv[1],"help",(size_t) 4) == 0 ||
2281 			 strncmp(argv[1],"HELP",(size_t) 4) == 0 ||
2282 			 strncmp(argv[1],"?",   (size_t) 1) == 0)) {
2283     fprintf(stderr,
2284@@ -214,18 +228,22 @@
2285     fprintf(stderr,"   infile        - name of compressed image file. \n");
2286     fprintf(stderr,"   outfile       - name of uncompressed output file.\n");
2287     fprintf(stderr,"   output format - selected from the following list:\n");
2288-    fprintf(stderr,"\n");
2289-    fprintf(stderr,"     1  SFDU/PDS format [DEFAULT].\n");
2290-    fprintf(stderr,"     2  FITS format.              \n");
2291-    fprintf(stderr,"     3  VICAR format.             \n");
2292-    fprintf(stderr,"     4  Unlabelled binary array.  \n\n");
2293+    fprintf(stderr,"\n");
2294+    fprintf(stderr,"     1  SFDU/PDS format [DEFAULT].\n");
2295+    fprintf(stderr,"     2  FITS format.              \n");
2296+    fprintf(stderr,"     3  VICAR format.             \n");
2297+    fprintf(stderr,"     4  Unlabelled binary array.  \n\n");
2298     exit(1);
2299-  }
2300+  }
2301   else {
2302-    strcpy(inname,argv[1]);
2303-    if (argc >= 3) strcpy(outname,argv[2]);
2304+    strncpy(inname, argv[1], sizeof(inname)-1);
2305+    inname[sizeof(inname)-1] = '\0';
2306+    if (argc >= 3) {
2307+      strncpy(outname, argv[2], sizeof(outname)-1);
2308+      outname[sizeof(outname)-1] = '\0';
2309+    }
2310     if (argc == 3) output_format = 1;
2311-    if (argc == 4) sscanf(argv[3],"%d",&output_format);
2312+    if (argc == 4) sscanf(argv[3],"%d",&output_format);
2313   }
2314
2315   host = check_host();
2316@@ -244,13 +262,13 @@
2317     case 4: no_labels(host);     break;
2318   }
2319
2320-  if (record_bytes == 836) {  /* set up values for image sizes */
2321+  if (record_bytes == 836) {  /* set up values for image sizes */
2322     max_lines    =  800;
2323     fits_pad     = 2240;
2324     line_samples =  800;
2325   }
2326   else {
2327-    max_lines    = 1056;
2328+    max_lines    = 1056;
2329     fits_pad     = 1536;
2330     line_samples = 1204;
2331   }
2332@@ -394,12 +412,12 @@
2333     if (record_bytes == 1204) /* do checksum for viking */
2334       for (i=0; i<record_bytes; i++) checksum += (int)obuf[i];
2335
2336-    if ((line % 100 == 0) && (outfile != stdout))
2337+    if ((line % 100 == 0) && (outfile != stdout))
2338       fprintf(stderr,"\nline %d",line);
2339
2340   } while (length > 0 && line < max_lines);
2341
2342-  if (record_bytes == 1204  && (outfile  != stdout))
2343+  if (record_bytes == 1204  && (outfile  != stdout))
2344     /* print checksum for viking */
2345     fprintf(stderr,"\n Image label checksum = %d computed checksum = %d\n",
2346 	    label_checksum,checksum);
2347@@ -425,33 +443,36 @@
2348 /*********************************************************************/
2349
2350 int get_files(host)
2351-int host;
2352+  int host;
2353 {
2354-  short   shortint;
2355   typedef long    off_t;
2356+  short   shortint;
2357+  char    *s;
2358
2359   if (inname[0] == ' ') {
2360     printf("\nEnter name of file to be decompressed: ");
2361-    gets (inname);
2362+    fgets(inname, sizeof(inname), stdin);
2363+    if ((s = strchr(inname, '\n')) != NULL)
2364+      *s = '\0';
2365   }
2366
2367-  if (host == 1 | host == 2) {
2368-    if ((infile = open(inname,O_RDONLY | O_BINARY)) <= 0) {
2369-      fprintf(stderr,"\ncan't open input file: %s\n",inname);
2370+  if (host == 1 || host == 2) {
2371+    if ((infile = open(inname, O_RDONLY | O_BINARY)) <= 0) {
2372+      fprintf(stderr,"\ncan't open input file: %s\n", inname);
2373       exit(1);
2374     }
2375   }
2376-  else if (host == 3 | host == 5) {
2377-    if ((infile = open(inname,O_RDONLY)) <= 0) {
2378-      fprintf(stderr,"\ncan't open input file: %s\n",inname);
2379+  else if (host == 3 || host == 5) {
2380+    if ((infile = open(inname, O_RDONLY)) <= 0) {
2381+      fprintf(stderr,"\ncan't open input file: %s\n", inname);
2382       exit(1);
2383     }
2384
2385     /****************************************************************/
2386-    /* If we are on a vax see if the file is in var length format.  */
2387-    /* This logic is in here in case the vax file has been stored   */
2388+    /* If we are on a VAX see if the file is in var length format.  */
2389+    /* This logic is in here in case the VAX file has been stored   */
2390     /* in fixed or undefined format.  This might be necessary since */
2391-    /* vax variable length files can't be moved to other computer   */
2392+    /* VAX variable-length files can't be moved to other computer   */
2393     /* systems with standard comm programs (kermit, for example).   */
2394     /****************************************************************/
2395
2396@@ -459,9 +480,9 @@
2397        read(infile,&shortint, (size_t) 2);
2398        if (shortint > 0 && shortint < 80) {
2399 	 host = 4;              /* change host to 4                */
2400-	 printf("This is not a VAX variable length file.");
2401+	 printf("This is not a VAX variable-length file.");
2402        }
2403-       else printf("This is a VAX variable length file.");
2404+       else printf("This is a VAX variable-length file.");
2405        lseek(infile,(off_t) 0,0);     /* reposition to beginning of file */
2406      }
2407   }
2408@@ -474,13 +495,17 @@
2409       printf("\n  3.  VICAR format.");
2410       printf("\n  4.  Unlabelled binary array.\n");
2411       printf("\n  Enter format number:");
2412-      gets(inname);
2413+      fgets(inname, sizeof(inname), stdin);
2414+      if ((s = strchr(inname, '\n')) != NULL)
2415+        *s = '\0';
2416       output_format = atoi(inname);
2417     } while (output_format < 1 || output_format > 4);
2418
2419   if (outname[0] == ' ') {
2420     printf("\nEnter name of uncompressed output file: ");
2421-    gets (outname);
2422+    fgets(outname, sizeof(outname), stdin);
2423+    if ((s = strchr(outname, '\n')) != NULL)
2424+      *s = '\0';
2425   }
2426
2427   return(host);
2428@@ -495,68 +520,68 @@
2429 /*********************************************************************/
2430
2431 void open_files(host)
2432-int *host;
2433+  int *host;
2434 {
2435   if (*host == 1 || *host == 2 || *host == 5)  {
2436     if (outname[0] == '-') outfile=stdout;
2437-    else if ((outfile = fopen(outname,"wb"))==NULL) {
2438-      fprintf(stderr,"\ncan't open output file: %s\n",outname);
2439+    else if ((outfile = fopen(outname, "wb"))==NULL) {
2440+      fprintf(stderr,"\ncan't open output file: %s\n", outname);
2441       exit(1);
2442     }
2443   }
2444
2445   else if (*host == 3 || *host == 4) {
2446     if (output_format == 1) {     /* write PDS format blocks */
2447-      if (record_bytes == 836) {
2448-	if ((outfile=fopen(outname,"w"
2449+      if (record_bytes == 836) {
2450+	if ((outfile=fopen(outname, "w"
2451 #ifdef VMS
2452 			   ,"mrs=836",FOP,CTX,RECORD_TYPE
2453 #endif
2454 			   ))==NULL) {
2455-	  fprintf(stderr,"\ncan't open output file: %s\n",outname);
2456+	  fprintf(stderr,"\ncan't open output file: %s\n", outname);
2457 	  exit(1);
2458 	}
2459       }
2460       else {
2461-	if ((outfile=fopen(outname,"w"
2462+	if ((outfile=fopen(outname, "w"
2463 #ifdef VMS
2464 			   ,"mrs=1204",FOP,CTX,RECORD_TYPE
2465 #endif
2466 			   ))==NULL) {
2467-	  fprintf(stderr,"\ncan't open output file: %s\n",outname);
2468+	  fprintf(stderr,"\ncan't open output file: %s\n", outname);
2469 	  exit(1);
2470 	}
2471       }
2472     }
2473     else if (output_format == 2) {  /* write FITS format blocks */
2474-      if ((outfile=fopen(outname,"w"
2475+      if ((outfile=fopen(outname, "w"
2476 #ifdef VMS
2477 			 ,"mrs=2880",FOP,CTX,RECORD_TYPE
2478 #endif
2479 			 ))==NULL) {
2480-	fprintf(stderr,"\ncan't open output file: %s\n",outname);
2481+	fprintf(stderr,"\ncan't open output file: %s\n", outname);
2482 	exit(1);
2483       }
2484     }
2485
2486-    else {                       /* write fixed length records */
2487-      if (record_bytes == 836) {
2488-	if ((outfile=fopen(outname,"w"
2489+    else {                       /* write fixed-length records */
2490+      if (record_bytes == 836) {
2491+	if ((outfile=fopen(outname, "w"
2492 #ifdef VMS
2493 			   ,"mrs=800",FOP,CTX,RECORD_TYPE
2494 #endif
2495 			   ))==NULL) {
2496-	  fprintf(stderr,"\ncan't open output file: %s\n",outname);
2497+	  fprintf(stderr,"\ncan't open output file: %s\n", outname);
2498 	  exit(1);
2499 	}
2500       }
2501       else {
2502-	if ((outfile=fopen(outname,"w"
2503+	if ((outfile=fopen(outname, "w"
2504 #ifdef VMS
2505 			   ,"mrs=1204",FOP,CTX,RECORD_TYPE
2506 #endif
2507 			   ))==NULL) {
2508-	  fprintf(stderr,"\ncan't open output file: %s\n",outname);
2509+	  fprintf(stderr,"\ncan't open output file: %s\n", outname);
2510 	  exit(1);
2511 	}
2512       }
2513@@ -572,11 +597,11 @@
2514 /*********************************************************************/
2515
2516 void pds_labels(host)
2517-     int host;
2518+  int host;
2519 {
2520-  char          outstring[80],ibuf[2048];
2521+  char          ibuf[2048];
2522   unsigned char cr=13,lf=10,blank=32;
2523-  short         length,nlen,total_bytes,line,i;
2524+  short         length,total_bytes,i;
2525
2526
2527   total_bytes = 0;
2528@@ -613,11 +638,11 @@
2529 	       (size_t) 53,(size_t) 1,outfile);
2530       else
2531         fwrite("CCSD3ZF0000100000001NJPL3IF0PDS200000001 = SFDU_LABEL",
2532-	       (size_t) 53,(size_t) 1,outfile);
2533+	       (size_t) 53,(size_t) 1,outfile);
2534
2535       fprintf(outfile,"%c%c",cr,lf);
2536       fwrite("/*          FILE FORMAT AND LENGTH */",(size_t) 37,(size_t) 1,
2537-	     outfile);
2538+	     outfile);
2539       fprintf(outfile,"%c%c",cr,lf);
2540       fwrite("RECORD_TYPE                      = FIXED_LENGTH",(size_t) 47,
2541 	     (size_t) 1,outfile);
2542@@ -710,7 +735,7 @@
2543       }
2544       else {
2545 	strcpy(ibuf+35,"60");
2546-	length = length - 2;
2547+	length = length - 2;
2548       }
2549
2550       fwrite(ibuf,(size_t) length,(size_t) 1,outfile);
2551@@ -730,7 +755,7 @@
2552     }
2553
2554     else if ((i = strncmp(ibuf," ENCODING",(size_t) 9)) == 0);
2555-
2556+
2557     /*****************************************************************/
2558     /* delete the encoding type label in the image object            */
2559     /*****************************************************************/
2560@@ -787,10 +812,10 @@
2561 /*********************************************************************/
2562
2563 void fits_labels(host)
2564-int host;
2565+  int host;
2566 {
2567   char          ibuf[2048],outstring[80];
2568-  short         length,nlen,total_bytes,line,i;
2569+  short         length,total_bytes,i;
2570   unsigned char cr=13,lf=10,blank=32;
2571
2572   do {
2573@@ -799,7 +824,7 @@
2574     /*****************************************************************/
2575     /* find the checksum and store in label_checksum                 */
2576     /*****************************************************************/
2577-    if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
2578+    if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
2579       ibuf[length]   = '\0';
2580       label_checksum = atol(ibuf+35);
2581     }
2582@@ -842,7 +867,7 @@
2583
2584   if (record_bytes == 836)
2585     strcpy(outstring,"NAXIS1  =                  800");
2586-  else
2587+  else
2588     strcpy(outstring,"NAXIS1  =                 1204");
2589
2590   strcat(outstring,"                                               ");
2591@@ -862,7 +887,7 @@
2592
2593   strcpy(outstring,"END                             ");
2594   strcat(outstring,"                                               ");
2595-
2596+
2597   fwrite(outstring,(size_t) 78,(size_t) 1,outfile);
2598   fprintf(outfile,"%c%c",cr,lf);
2599   total_bytes = total_bytes + 80;
2600@@ -871,6 +896,7 @@
2601   for (i=total_bytes; i<2880; i++) fputc(blank,outfile);
2602 }
2603
2604+
2605 /*********************************************************************/
2606 /*                                                                   */
2607 /* subroutine vicar_labels - write vicar labels to output file       */
2608@@ -878,11 +904,10 @@
2609 /*********************************************************************/
2610
2611 void vicar_labels(host)
2612-int host;
2613-
2614+  int host;
2615 {
2616   char          ibuf[2048],outstring[80];
2617-  short         length,nlen,total_bytes,line,i;
2618+  short         length,total_bytes,i;
2619   unsigned char cr=13,lf=10,blank=32;
2620
2621   do {
2622@@ -890,7 +915,7 @@
2623     /*****************************************************************/
2624     /* find the checksum and store in label_checksum                 */
2625     /*****************************************************************/
2626-    if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
2627+    if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
2628       ibuf[length]   = '\0';
2629       label_checksum = atol(ibuf+35);
2630     }
2631@@ -950,10 +975,10 @@
2632 /*********************************************************************/
2633
2634 void no_labels(host)
2635-int host;
2636+  int host;
2637 {
2638-  char          ibuf[2048],outstring[80];
2639-  short         length,nlen,total_bytes,line,i;
2640+  char          ibuf[2048];
2641+  short         length,i;
2642
2643   do {
2644     length = read_var(ibuf,host);
2645@@ -961,7 +986,7 @@
2646     /*****************************************************************/
2647     /* find the checksum and store in label_checksum                 */
2648     /*****************************************************************/
2649-    if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
2650+    if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
2651       ibuf[length]   = '\0';
2652       label_checksum = atol(ibuf+35);
2653     }
2654@@ -984,15 +1009,16 @@
2655   open_files(&host);
2656 }
2657
2658+
2659 /*********************************************************************/
2660 /*                                                                   */
2661-/* subroutine read_var - read variable length records from input file*/
2662+/* subroutine read_var - read variable-length records from input file*/
2663 /*                                                                   */
2664 /*********************************************************************/
2665
2666 int read_var(ibuf,host)
2667-char  *ibuf;
2668-int   host;
2669+  char  *ibuf;
2670+  int   host;
2671 {
2672   int   length,result,nlen;
2673   char  temp;
2674@@ -1027,19 +1053,19 @@
2675     return (length);
2676
2677   case 3: /*******************************************************/
2678-          /* VAX host with variable length support               */
2679+          /* VAX host with variable-length support               */
2680           /*******************************************************/
2681     length = read(infile,ibuf,(size_t) 2048/* upper bound */);
2682     return (length);
2683
2684   case 4: /*******************************************************/
2685-          /* VAX host, but not a variable length file            */
2686+          /* VAX host, but not a variable-length file            */
2687           /*******************************************************/
2688     length = 0;
2689     result = read(infile,&length,(size_t) 2);
2690     nlen =   read(infile,ibuf,(size_t) length+(length%2));
2691
2692-    /* check to see if we crossed a vax record boundary          */
2693+    /* check to see if we crossed a VAX record boundary          */
2694     while (nlen < length)
2695       nlen += read(infile,ibuf+nlen,(size_t) length+(length%2)-nlen);
2696     return (length);
2697@@ -1061,6 +1087,7 @@
2698   return 0;
2699 }
2700
2701+
2702 /*********************************************************************/
2703 /*                                                                   */
2704 /* subroutine check_host - find out what kind of machine we are on   */
2705@@ -1115,23 +1142,23 @@
2706 	   "Host 5 - 32 bit integers without swapping, no var len support.");
2707   }
2708
2709-  if ((*outname)!='-') fprintf(stderr,"%s\n",hostname);
2710+  if ((*outname) != '-') fprintf(stderr, "%s\n", hostname);
2711   return(host);
2712 }
2713
2714
2715-int swap_int(inval)  /* swap 4 byte integer                       */
2716-     int inval;
2717+int swap_int(inval)  /* swap 4 byte integer */
2718+  int inval;
2719 {
2720-  union /* this union is used to swap 16 and 32 bit integers          */
2721+  union /* this union is used to swap 16 and 32 bit integers */
2722     {
2723       char  ichar[4];
2724       short slen;
2725       int   llen;
2726     } onion;
2727   char   temp;
2728-
2729-  /* byte swap the input field                                      */
2730+
2731+  /* byte swap the input field */
2732   onion.llen   = inval;
2733   temp   = onion.ichar[0];
2734   onion.ichar[0]=onion.ichar[3];
2735@@ -1146,17 +1173,13 @@
2736 /****************************************************************************
2737 *_TITLE decompress - decompresses image lines stored in compressed format   *
2738 *_ARGS  TYPE       NAME      I/O        DESCRIPTION                         */
2739-        char *ibuf;        /* I         Compressed data buffer              */
2740-        char *obuf;        /* O         Decompressed image line             */
2741-        int       *nin;   /* I         Number of bytes on input buffer     */
2742-        int       *nout;  /* I         Number of bytes in output buffer    */
2743-
2744+        char       *ibuf;  /* I         Compressed data buffer              */
2745+        char       *obuf;  /* O         Decompressed image line             */
2746+        int        *nin;   /* I         Number of bytes on input buffer     */
2747+        int        *nout;  /* I         Number of bytes in output buffer    */
2748 {
2749-  /* The external root pointer to tree */
2750-  extern NODE *tree;
2751-
2752   dcmprs(ibuf,obuf,nin,nout,tree);
2753-
2754+
2755   return;
2756 }
2757
2758@@ -1165,10 +1188,8 @@
2759 /***************************************************************************
2760 *_TITLE decmpinit - initializes the Huffman tree                           *
2761 *_ARGS  TYPE       NAME      I/O        DESCRIPTION                        */
2762-        int      *hist;  /* I         First-difference histogram.        */
2763-
2764+        int        *hist;  /* I         First-difference histogram.        */
2765 {
2766-  extern NODE *tree;          /* Huffman tree root pointer */
2767   tree = huff_tree(hist);
2768   return;
2769 }
2770@@ -1178,8 +1199,7 @@
2771 /****************************************************************************
2772 *_TITLE huff_tree - constructs the Huffman tree; returns pointer to root    *
2773 *_ARGS  TYPE          NAME        I/O   DESCRIPTION                         */
2774-        int     *hist;     /* I    First difference histogram          */
2775-
2776+        int          *hist;     /* I    First difference histogram          */
2777 {
2778   /*  Local variables used */
2779   int freq_list[512];      /* Histogram frequency list */
2780@@ -1189,7 +1209,6 @@
2781   NODE **np;        /* Node list pointer */
2782
2783   int num_freq;   /* Number non-zero frequencies in histogram */
2784-  int sum;                 /* Sum of all frequencies */
2785
2786   short int num_nodes; /* Counter for DN initialization */
2787   short int cnt;       /* Miscellaneous counter */
2788@@ -1228,7 +1247,7 @@
2789
2790     j = 0;
2791     for (i=4 ; --i >= 0 ; j = (j << 8) | *(cp+i));
2792-
2793+
2794     /* Now make the assignment */
2795     *fp++ = j;
2796     temp = new_node(num_nodes);
2797@@ -1341,7 +1360,7 @@
2798       l--;
2799       if ( j <= freq_list) break;
2800     }
2801-
2802+
2803   }
2804   return;
2805 }
2806@@ -1362,9 +1381,9 @@
2807   NODE *ptr = root;        /* pointer to position in tree */
2808   unsigned char test;      /* test byte for bit set */
2809   unsigned char idn;       /* input compressed byte */
2810-
2811+
2812   char odn;                /* last dn value decompressed */
2813-
2814+
2815   char *ilim = ibuf + *nin;         /* end of compressed bytes */
2816   char *olim = obuf + *nout;        /* end of output buffer */
2817
2818@@ -1406,10 +1425,9 @@
2819 /****************************************************************************
2820 *_TITLE free_tree - free memory of all allocated nodes                      *
2821 *_ARGS  TYPE       NAME       I/O        DESCRIPTION                        */
2822-        int      *nfreed;  /* O        Return of total count of nodes     *
2823+        int        *nfreed;  /* O        Return of total count of nodes     *
2824 *                                        freed.                             */
2825-
2826-/*
2827+/*                                                                          *
2828 *_DESCR This routine is supplied to the programmer to free up all the       *
2829 *       allocated memory required to build the huffman tree.  The count     *
2830 *       of the nodes freed is returned in the parameter 'nfreed'.  The      *
2831@@ -1417,16 +1435,13 @@
2832 *       than one file per run, the program will not keep allocating new     *
2833 *       memory without first deallocating all previous nodes associated     *
2834 *       with the previous file decompression.                               *
2835-
2836+*                                                                           *
2837 *_HIST  16-AUG-89 Kris Becker   USGS, Flagstaff Original Version            *
2838 *_END                                                                       *
2839 ****************************************************************************/
2840-
2841 {
2842   int total_free = 0;
2843
2844-  extern NODE *tree;      /* Huffman tree root pointer */
2845-
2846   *nfreed = free_node(tree,total_free);
2847
2848   return;
2849@@ -1435,36 +1450,33 @@
2850
2851 int free_node(pnode,total_free)
2852 /***************************************************************************
2853-*_TITLE free_node - deallocates an allocated NODE pointer
2854+*_TITLE free_node - deallocates an allocated NODE pointer                  *
2855 *_ARGS  TYPE     NAME          I/O   DESCRIPTION                           */
2856         NODE     *pnode;       /* I  Pointer to node to free               */
2857-        int       total_free;   /* I  Total number of freed nodes           */
2858-
2859-/*
2860+        int      total_free;   /* I  Total number of freed nodes           */
2861+/*                                                                         *
2862 *_DESCR  free_node will check both right and left pointers of a node       *
2863 *        and then free the current node using the free() C utility.        *
2864 *        Note that all nodes attached to the node via right or left        *
2865 *        pointers area also freed, so be sure that this is the desired     *
2866 *        result when calling this routine.                                 *
2867-
2868+*                                                                          *
2869 *        This routine is supplied to allow successive calls to the         *
2870 *        decmpinit routine.  It will free up the memory allocated          *
2871 *        by previous calls to the decmpinit routine.  The call to free     *
2872-*        a previous huffman tree is:  total = free_node(tree,(int) 0);    *
2873+*        a previous huffman tree is:  total = free_node(tree,(int) 0);     *
2874 *        This call must be done by the programmer application routine      *
2875 *        and is not done by any of these routines.                         *
2876 *_HIST   16-AUG-89  Kris Becker U.S.G.S  Flagstaff Original Version        */
2877 {
2878   if (pnode == (NODE *) NULL) return(total_free);
2879-
2880+
2881   if (pnode->right != (NODE *) NULL)
2882     total_free = free_node(pnode->right,total_free);
2883   if (pnode->left != (NODE *) NULL)
2884     total_free = free_node(pnode->left,total_free);
2885-
2886+
2887   free((char *) pnode);
2888   return(total_free + 1);
2889 }
2890
2891-
2892-
2893diff -ru xv-3.10a/xcmap.c xv-3.10a-enhancements/xcmap.c
2894--- xv-3.10a/xcmap.c	1995-01-03 13:14:52.000000000 -0800
2895+++ xv-3.10a-enhancements/xcmap.c	2007-04-15 13:12:41.000000000 -0700
2896@@ -9,6 +9,9 @@
2897
2898 /* include files */
2899 #include <stdio.h>
2900+#ifdef __STDC__
2901+#  include <stdlib.h>   /* exit(), abs() */
2902+#endif
2903 #include <sys/types.h>
2904 #include <ctype.h>
2905
2906@@ -18,7 +21,7 @@
2907 #include <X11/cursorfont.h>
2908
2909 #ifdef VMS
2910-#define index strchr
2911+#  define index strchr
2912 #endif
2913
2914 typedef unsigned char byte;
2915@@ -58,7 +61,7 @@
2916        int  main             PARM((int, char **));
2917 static void HandleEvent      PARM((XEvent *));
2918 static void Syntax           PARM((void));
2919-static void FatalError       PARM((char *));
2920+static void FatalError       PARM((const char *));
2921 static void Quit             PARM((void));
2922 static void CreateMainWindow PARM((char *, char *, int, char **));
2923 static void DrawWindow       PARM((int,int,int,int));
2924@@ -75,50 +78,50 @@
2925   int        i;
2926   char      *display, *geom;
2927   XEvent     event;
2928-
2929+
2930   cmd = argv[0];
2931   display = geom = NULL;
2932-
2933-
2934+
2935+
2936   /*********************Options*********************/
2937-
2938+
2939   for (i = 1; i < argc; i++) {
2940     char *strind;
2941-
2942+
2943     if (!strncmp(argv[i],"-g", (size_t)2)) {	/* geometry */
2944       i++;
2945       geom = argv[i];
2946       continue;
2947     }
2948-
2949+
2950     if (argv[i][0] == '=') {		/* old-style geometry */
2951       geom = argv[i];
2952       continue;
2953     }
2954-
2955+
2956     if (!strncmp(argv[i],"-d",(size_t) 2)) {	/* display */
2957       i++;
2958       display = argv[i];
2959       continue;
2960     }
2961-
2962+
2963     strind = (char *) index(argv[i], ':');	/* old-style display */
2964     if(strind != NULL) {
2965       display = argv[i];
2966       continue;
2967     }
2968-
2969+
2970     Syntax();
2971   }
2972-
2973-
2974+
2975+
2976   /*****************************************************/
2977-
2978+
2979   /* Open up the display. */
2980-
2981+
2982   if ( (theDisp=XOpenDisplay(display)) == NULL)
2983     FatalError("can't open display");
2984-
2985+
2986   theScreen = DefaultScreen(theDisp);
2987   theCmap   = DefaultColormap(theDisp, theScreen);
2988   rootW     = RootWindow(theDisp,theScreen);
2989@@ -126,9 +129,9 @@
2990   fcol      = WhitePixel(theDisp,theScreen);
2991   bcol      = BlackPixel(theDisp,theScreen);
2992   theVisual = DefaultVisual(theDisp,theScreen);
2993-
2994+
2995   dispcells = DisplayCells(theDisp, theScreen);
2996-
2997+
2998   if (dispcells>256) {
2999     sprintf(tmpstr,"dispcells = %d.  %s",
3000 	    dispcells, "This program can only deal with <= 8-bit displays.");
3001@@ -140,27 +143,32 @@
3002     nxcells = nycells = 8;
3003   else if (dispcells>4)
3004     nxcells = nycells = 4;
3005-  else
3006+  else if (dispcells>2)
3007     nxcells = nycells = 2;
3008-
3009+  else
3010+  {
3011+    nxcells = 2;
3012+    nycells = 1;
3013+  }
3014+
3015   /**************** Create/Open X Resources ***************/
3016   if ((mfinfo = XLoadQueryFont(theDisp,FONT))==NULL) {
3017     sprintf(tmpstr,"couldn't open '%s' font",FONT);
3018     FatalError(tmpstr);
3019   }
3020-
3021+
3022   mfont=mfinfo->fid;
3023   XSetFont(theDisp,theGC,mfont);
3024   XSetForeground(theDisp,theGC,fcol);
3025   XSetBackground(theDisp,theGC,bcol);
3026-
3027+
3028   CreateMainWindow(cmd,geom,argc,argv);
3029-  Resize(WIDE,HIGH);
3030-
3031-  XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
3032+  Resize((int)WIDE,(int)HIGH);
3033+
3034+  XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
3035 	       | StructureNotifyMask | ButtonPressMask);
3036   XMapWindow(theDisp,mainW);
3037-
3038+
3039   /**************** Main loop *****************/
3040   while (1) {
3041     XNextEvent(theDisp, &event);
3042@@ -177,41 +185,41 @@
3043   switch (event->type) {
3044   case Expose: {
3045     XExposeEvent *exp_event = (XExposeEvent *) event;
3046-
3047-    if (exp_event->window==mainW)
3048+
3049+    if (exp_event->window==mainW)
3050       DrawWindow(exp_event->x,exp_event->y,
3051 		 exp_event->width, exp_event->height);
3052   }
3053     break;
3054-
3055+
3056   case ButtonPress: {
3057     XButtonEvent *but_event = (XButtonEvent *) event;
3058-
3059-    if (but_event->window == mainW && but_event->button == Button1)
3060+
3061+    if (but_event->window == mainW && but_event->button == Button1)
3062       TrackMouse(but_event->x, but_event->y);
3063   }
3064     break;
3065-
3066+
3067   case KeyPress: {
3068     XKeyEvent *key_event = (XKeyEvent *) event;
3069     KeySym ks;
3070     XComposeStatus status;
3071-
3072+
3073     XLookupString(key_event,tmpstr,128,&ks,&status);
3074     if (tmpstr[0]=='q' || tmpstr[0]=='Q') Quit();
3075   }
3076     break;
3077-
3078+
3079   case ConfigureNotify: {
3080     XConfigureEvent *conf_event = (XConfigureEvent *) event;
3081-
3082-    if (conf_event->window == mainW &&
3083-	(conf_event->width != WIDE || conf_event->height != HIGH))
3084-      Resize(conf_event->width, conf_event->height);
3085+    int w = conf_event->width, h = conf_event->height;
3086+
3087+    if (conf_event->window == mainW && (w != WIDE || h != HIGH))
3088+      Resize((int)(w ? w : WIDE), (int)(h ? h : HIGH));
3089   }
3090     break;
3091-
3092-
3093+
3094+
3095   case CirculateNotify:
3096   case MapNotify:
3097   case DestroyNotify:
3098@@ -220,7 +228,7 @@
3099   case UnmapNotify:
3100   case MappingNotify:
3101   case ClientMessage:         break;
3102-
3103+
3104   default:		/* ignore unexpected events */
3105     break;
3106   }  /* end of switch */
3107@@ -237,10 +245,10 @@
3108
3109
3110 /***********************************/
3111-static void FatalError (identifier)
3112-     char *identifier;
3113+static void FatalError(identifier)
3114+     const char *identifier;
3115 {
3116-  fprintf(stderr, "%s: %s\n",cmd, identifier);
3117+  fprintf(stderr, "%s: %s\n", cmd, identifier);
3118   exit(-1);
3119 }
3120
3121@@ -262,24 +270,33 @@
3122   XSizeHints hints;
3123   int i,x,y;
3124   unsigned int w,h;
3125-
3126+
3127   WIDE = HIGH = 256;			/* default window size */
3128-
3129+
3130   x=y=w=h=1;
3131+  hints.flags = 0;
3132+
3133   i=XParseGeometry(geom,&x,&y,&w,&h);
3134-  if (i&WidthValue)  WIDE = (int) w;
3135-  if (i&HeightValue) HIGH = (int) h;
3136-
3137-  if (i&XValue || i&YValue) hints.flags = USPosition;
3138-  else hints.flags = PPosition;
3139-
3140-  hints.flags |= USSize;
3141-
3142-  if (i&XValue && i&XNegative)
3143-    x = XDisplayWidth(theDisp,theScreen)-WIDE-abs(x);
3144-  if (i&YValue && i&YNegative)
3145-    y = XDisplayHeight(theDisp,theScreen)-HIGH-abs(y);
3146-
3147+  if (i&WidthValue)
3148+  {
3149+    WIDE = (int) w;
3150+    hints.flags |= USSize;
3151+  }
3152+  if (i&HeightValue)
3153+  {
3154+    HIGH = (int) h;
3155+    hints.flags |= USSize;
3156+  }
3157+
3158+  if (i&XValue || i&YValue)
3159+  {
3160+    if (i&XNegative)
3161+      x = XDisplayWidth(theDisp,theScreen)-WIDE-abs(x);
3162+    if (i&YNegative)
3163+      y = XDisplayHeight(theDisp,theScreen)-HIGH-abs(y);
3164+    hints.flags |= USPosition;
3165+  }
3166+
3167   hints.x=x;             hints.y=y;
3168   hints.width  = WIDE;   hints.height = HIGH;
3169   hints.max_width  = DisplayWidth(theDisp,theScreen);
3170@@ -288,22 +305,22 @@
3171   hints.min_height = 16;
3172   hints.width_inc = hints.height_inc = 16;
3173   hints.flags |= PMaxSize | PMinSize | PResizeInc;
3174-
3175+
3176   xswa.background_pixel = bcol;
3177   xswa.border_pixel     = fcol;
3178   xswa.cursor = XCreateFontCursor (theDisp, XC_top_left_arrow);
3179   xswamask = CWBackPixel | CWBorderPixel | CWCursor;
3180-
3181+
3182   mainW = XCreateWindow(theDisp,rootW,x,y,(unsigned int) WIDE,
3183-			(unsigned int) HIGH, 2, 0,
3184+			(unsigned int) HIGH, 2, 0,
3185 			(unsigned int) CopyFromParent,
3186 			CopyFromParent, xswamask, &xswa);
3187-
3188+
3189   XSetStandardProperties(theDisp,mainW,"xcmap","xcmap",None,
3190 			 argv,argc,&hints);
3191-
3192+
3193   if (!mainW) FatalError("Can't open main window");
3194-
3195+
3196 }
3197
3198
3199@@ -312,11 +329,11 @@
3200      int x,y,w,h;
3201 {
3202   int i,j,x1,y1,x2,y2;
3203-
3204+
3205   x1 = x / cWIDE;      y1 = y / cHIGH;	/* (x1,y1) (x2,y2): bounding */
3206   x2 = ((x+w) + cWIDE - 1) / cWIDE;		/*       rect in cell coords */
3207   y2 = ((y+h) + cHIGH - 1) / cHIGH;
3208-
3209+
3210   for (i=y1; i<y2; i++) {
3211     for (j=x1; j<x2; j++) {
3212       XSetForeground(theDisp,theGC,(unsigned long) (i*nycells+j) );
3213@@ -343,18 +360,18 @@
3214 {
3215   /* called when there's a button press in the window.  draws the pixel
3216      value, and loops until button is released */
3217-
3218+
3219   Window        rootW,childW;
3220   int           rx,ry,x,y;
3221   unsigned int  mask;
3222-
3223+
3224   pvalup = 0;
3225   DrawPixValue(mx,my);
3226-
3227+
3228   while (1) {
3229     if (XQueryPointer(theDisp,mainW,&rootW,&childW,&rx,&ry,&x,&y,&mask)) {
3230       if (!(mask & Button1Mask)) break;    /* button released */
3231-
3232+
3233       DrawPixValue(x,y);
3234     }
3235   }
3236@@ -367,10 +384,10 @@
3237 {
3238   static unsigned long pix, lastpix;
3239   static int           pvaly;
3240-
3241+
3242   if (x<0) x=0;  if (x>=WIDE) x=WIDE-1;
3243   if (y<0) y=0;  if (y>=HIGH) y=HIGH-1;
3244-
3245+
3246   if (!pvalup) {	/* it's not up.  make it so */
3247     if (y >= HIGH/2) pvaly = 0;  else pvaly = HIGH - 12;
3248     pvalup = 1;
3249@@ -378,30 +395,30 @@
3250     XClearArea(theDisp,mainW,0,pvaly,
3251 	       (unsigned int) WIDE, (unsigned int) 13,True);
3252   }
3253-
3254+
3255   x /= cWIDE;  y /= cHIGH;
3256-
3257+
3258   pix = y * nxcells + x;
3259-
3260+
3261   if (pix != lastpix) {
3262     XColor def;
3263     char  *sp;
3264-
3265+
3266     XSetForeground(theDisp,theGC,fcol);
3267     lastpix = def.pixel = pix;
3268     if (pix<dispcells) {
3269       XQueryColor(theDisp, theCmap, &def);
3270       sprintf(tmpstr, "Pix %3ld = ($%04x, $%04x, $%04x)",
3271 	      pix, def.red, def.green, def.blue);
3272-
3273-      /* make the hex uppercase */
3274-      for (sp=tmpstr+4; *sp; sp++)
3275+
3276+      /* make the hex uppercase */
3277+      for (sp=tmpstr+4; *sp; sp++)
3278 	if (islower(*sp)) *sp = toupper(*sp);
3279     }
3280     else {
3281       sprintf(tmpstr, "Pix %3ld is out of legal range. ", pix);
3282     }
3283-
3284+
3285     XDrawImageString(theDisp,mainW,theGC,5,pvaly+10,tmpstr,
3286 		     (int) strlen(tmpstr));
3287   }
3288diff -ru xv-3.10a/xv.c xv-3.10a-enhancements/xv.c
3289--- xv-3.10a/xv.c	1995-01-19 10:08:43.000000000 -0800
3290+++ xv-3.10a-enhancements/xv.c	2007-05-13 18:44:55.000000000 -0700
3291@@ -33,9 +33,9 @@
3292
3293 /* a mono-spaced font needed for the 'pixel value tracking' feature */
3294 #define MFONT1 "-misc-fixed-medium-r-normal-*-13-*"
3295-#define MFONT2 "6x13"
3296+#define MFONT2 "6x13"
3297 #define MFONT3 "-*-courier-medium-r-*-*-12-*"
3298-#define MFONT4 "fixed"
3299+#define MFONT4 "fixed"
3300
3301
3302 /* default positions for various windows */
3303@@ -54,14 +54,35 @@
3304 static int    randomShow = 0;   /* do a 'random' slideshow */
3305 static int    startIconic = 0;  /* '-iconic' option */
3306 static int    defaultVis  = 0;  /* true if using DefaultVisual */
3307+#ifdef HAVE_G3
3308+static int    fax = 0;          /* temporary(?) kludge */
3309+int           highresfax = 0;
3310+#endif
3311 static double hexpand = 1.0;    /* '-expand' argument */
3312 static double vexpand = 1.0;    /* '-expand' argument */
3313-static char  *maingeom = NULL;
3314-static char  *icongeom = NULL;
3315+static const char *maingeom = NULL;
3316+static const char *icongeom = NULL;
3317 static Atom   __SWM_VROOT = None;
3318
3319 static char   basefname[128];   /* just the current fname, no path */
3320
3321+#ifdef TV_L10N
3322+#  ifndef TV_FONTSET
3323+#    define TV_FONTSET "-*-fixed-medium-r-normal--%d-*"
3324+#  endif
3325+#  ifndef TV_FONTSIZE
3326+#    define TV_FONTSIZE 14,16
3327+#  endif
3328+static int    mfontsize[] = { TV_FONTSIZE, 0 };
3329+static char   mfontset[256];
3330+#endif
3331+
3332+#ifdef HAVE_JP2K
3333+static byte jp2k_magic[12] =
3334+  { 0, 0, 0, 0x0c, 'j', 'P', ' ', ' ', 0x0d, 0x0a, 0x87, 0x0a };
3335+#endif
3336+
3337+
3338 /* things to do upon successfully loading an image */
3339 static int    autoraw    = 0;   /* force raw if using stdcmap */
3340 static int    autodither = 0;   /* dither */
3341@@ -78,6 +99,12 @@
3342
3343 static int    force8     = 0;   /* force 8-bit mode */
3344 static int    force24    = 0;   /* force 24-bit mode */
3345+#ifdef HAVE_PCD
3346+static int    PcdSize    = -1;  /* force dialog to ask */
3347+#endif
3348+
3349+static float  waitsec_nonfinal = -1;  /* "normal" waitsec value */
3350+static float  waitsec_final = -1;     /* final-image waitsec value */
3351
3352 /* used in DeleteCmd() and Quit() */
3353 static char  **mainargv;
3354@@ -92,7 +119,7 @@
3355 static void parseResources           PARM((int, char **));
3356 static void parseCmdLine             PARM((int, char **));
3357 static void verifyArgs               PARM((void));
3358-static void printoption              PARM((char *));
3359+static void printoption              PARM((const char *));
3360 static void cmdSyntax                PARM((void));
3361 static void rmodeSyntax              PARM((void));
3362 static int  openPic                  PARM((int));
3363@@ -103,32 +130,34 @@
3364 static void openNextLoop             PARM((void));
3365 static void openPrevPic              PARM((void));
3366 static void openNamedPic             PARM((void));
3367-static int  findRandomPic            PARM((void));
3368 static void mainLoop                 PARM((void));
3369-static void createMainWindow         PARM((char *, char *));
3370-static void setWinIconNames          PARM((char *));
3371+static void createMainWindow         PARM((const char *, const char *));
3372+static void setWinIconNames          PARM((const char *));
3373 static void makeDispNames            PARM((void));
3374 static void fixDispNames             PARM((void));
3375 static void deleteFromList           PARM((int));
3376-static int  argcmp                   PARM((char *, char *, int, int, int *));
3377+static int  argcmp                   PARM((const char *, const char *,
3378+                                           int, int, int *));
3379 static void add_filelist_to_namelist PARM((char *, char **, int *, int));
3380
3381
3382 /* formerly local vars in main, made local to this module when
3383    parseResources() and parseCmdLine() were split out of main() */
3384-
3385-int   imap, ctrlmap, gmap, browmap, cmtmap, clrroot, nopos, limit2x;
3386-char *display, *whitestr, *blackstr, *histr, *lostr,
3387-     *infogeom, *fgstr, *bgstr, *ctrlgeom, *gamgeom, *browgeom, *tmpstr;
3388-char *rootfgstr, *rootbgstr, *visualstr, *textgeom, *cmtgeom;
3389-char *monofontname, *flistName;
3390-int  curstype, stdinflag, browseMode, savenorm, preview, pscomp, preset,
3391-     rmodeset, gamset, cgamset, perfect, owncmap, rwcolor, stdcmap;
3392-int  nodecor;
3393-double gamval, rgamval, ggamval, bgamval;
3394-
3395-
3396
3397+static int   imap, ctrlmap, gmap, browmap, cmtmap, clrroot, nopos, limit2x;
3398+static const char *histr, *lostr, *fgstr, *bgstr, *tmpstr;
3399+static const char *infogeom, *ctrlgeom, *gamgeom, *browgeom, *textgeom, *cmtgeom;
3400+static char *display, *whitestr, *blackstr;
3401+static char *rootfgstr, *rootbgstr, *imagebgstr, *visualstr;
3402+static char *monofontname, *flistName;
3403+#ifdef TV_L10N
3404+static char **misscharset, *defstr;
3405+static int nmisscharset;
3406+#endif
3407+static int  curstype, stdinflag, browseMode, savenorm, preview, pscomp, preset,
3408+            rmodeset, gamset, cgamset, perfect, owncmap, rwcolor, stdcmap;
3409+static int  nodecor;
3410+static double gamval, rgamval, ggamval, bgamval;
3411
3412 /*******************************************/
3413 int main(argc, argv)
3414@@ -137,6 +166,9 @@
3415 /*******************************************/
3416 {
3417   int    i;
3418+#ifdef TV_L10N
3419+  int    j;
3420+#endif
3421   XColor ecdef;
3422   Window rootReturn, parentReturn, *children;
3423   unsigned int numChildren, rootDEEP;
3424@@ -153,6 +185,13 @@
3425   /*** variable Initialization                       ***/
3426   /*****************************************************/
3427
3428+#ifdef TV_L10N
3429+  /* setlocale(LC_ALL, localeList[LOCALE_EUCJ]); */
3430+  setlocale(LC_ALL, "");
3431+  xlocale = (int)XSupportsLocale();	/* assume that (Bool) is (int) */
3432+	/* if X doesn't support ja_JP.ujis text viewer l10n doesn't work. */
3433+#endif
3434+
3435   xv_getwd(initdir, sizeof(initdir));
3436   searchdir[0] = '\0';
3437   fullfname[0] = '\0';
3438@@ -162,7 +201,7 @@
3439
3440   /* init internal variables */
3441   display = NULL;
3442-  fgstr = bgstr = rootfgstr = rootbgstr = NULL;
3443+  fgstr = bgstr = rootfgstr = rootbgstr = imagebgstr = NULL;
3444   histr = lostr = whitestr = blackstr = NULL;
3445   visualstr = monofontname = flistName = NULL;
3446   winTitle = NULL;
3447@@ -172,21 +211,26 @@
3448
3449   picComments = (char *) NULL;
3450
3451+  if (picExifInfo) free(picExifInfo);
3452+  picExifInfo = (byte *) NULL;
3453+  picExifInfoSize = 0;
3454+
3455   numPages = 1;  curPage = 0;
3456   pageBaseName[0] = '\0';
3457
3458   LocalCmap = browCmap = 0;
3459   stdinflag = 0;
3460-  autoclose = autoDelete = 0;
3461+  autoclose = autoDelete = 0;
3462   cmapInGam = 0;
3463   grabDelay = 0;
3464+  startGrab = 0;
3465   showzoomcursor = 0;
3466   perfect = owncmap = stdcmap = rwcolor = 0;
3467
3468   ignoreConfigs = 0;
3469-  browPerfect = 1;
3470+  browPerfect = 1;
3471   gamval = rgamval = ggamval = bgamval = 1.0;
3472-
3473+
3474   picType = -1;              /* gets set once file is loaded */
3475   colorMapMode = CM_NORMAL;
3476   haveStdCmap  = STD_NONE;
3477@@ -221,24 +265,27 @@
3478   cmd = (char *) rindex(argv[0],'/');
3479   if (!cmd) cmd = argv[0]; else cmd++;
3480
3481-  tmpstr = (char *) getenv("TMPDIR");
3482-  if (!tmpstr) tmpdir = "/tmp";
3483-  else {
3484-    tmpdir = (char *) malloc(strlen(tmpstr) + 1);
3485-    if (!tmpdir) FatalError("can't malloc 'tmpdir'\n");
3486-    strcpy(tmpdir, tmpstr);
3487-  }
3488+  tmpstr = (const char *) getenv("TMPDIR");
3489+  if (!tmpstr) tmpstr = "/tmp";
3490+  tmpdir = (char *) malloc(strlen(tmpstr) + 1);
3491+  if (!tmpdir) FatalError("can't malloc 'tmpdir'\n");
3492+  strcpy(tmpdir, tmpstr);
3493+
3494+#ifdef AUTO_EXPAND
3495+  Vdinit();
3496+  vd_handler_setup();
3497+#endif
3498
3499   /* init command-line options flags */
3500-  infogeom = DEFINFOGEOM;  ctrlgeom = DEFCTRLGEOM;
3501+  infogeom = DEFINFOGEOM;  ctrlgeom = DEFCTRLGEOM;
3502   gamgeom  = DEFGAMGEOM;   browgeom = DEFBROWGEOM;
3503   textgeom = DEFTEXTGEOM;  cmtgeom  = DEFCMTGEOM;
3504
3505-  ncols = -1;  mono = 0;
3506+  ncols = -1;  mono = 0;
3507   ninstall = 0;  fixedaspect = 0;  noFreeCols = nodecor = 0;
3508   DEBUG = 0;  bwidth = 2;
3509   nolimits = useroot = clrroot = noqcheck = 0;
3510-  waitsec = -1;  waitloop = 0;  automax = 0;
3511+  waitsec = waitsec_final = -1.0;  waitloop = 0;  automax = 0;
3512   rootMode = 0;  hsvmode = 0;
3513   rmodeset = gamset = cgamset = 0;
3514   nopos = limit2x = 0;
3515@@ -251,6 +298,10 @@
3516   preset = 0;
3517   viewonly = 0;
3518
3519+#ifdef ENABLE_FIXPIX_SMOOTH
3520+  do_fixpix_smooth = 0;
3521+#endif
3522+
3523   /* init 'xormasks' array */
3524   xorMasks[0] = 0x01010101;
3525   xorMasks[1] = 0x02020203;
3526@@ -268,15 +319,38 @@
3527   defaspect = normaspect = 1.0;
3528   mainW = dirW = infoW = ctrlW = gamW = psW = (Window) NULL;
3529   anyBrowUp = 0;
3530+  incrementalSearchTimeout = 30;
3531
3532 #ifdef HAVE_JPEG
3533   jpegW = (Window) NULL;  jpegUp = 0;
3534 #endif
3535
3536+#ifdef HAVE_JP2K
3537+  jp2kW = (Window) NULL;  jp2kUp = 0;
3538+#endif
3539+
3540 #ifdef HAVE_TIFF
3541   tiffW = (Window) NULL;  tiffUp = 0;
3542 #endif
3543
3544+#ifdef HAVE_PNG
3545+  pngW = (Window) NULL;  pngUp = 0;
3546+#endif
3547+
3548+  pcdW = (Window) NULL;  pcdUp = 0;
3549+
3550+#ifdef HAVE_PIC2
3551+  pic2W = (Window) NULL;  pic2Up = 0;
3552+#endif
3553+
3554+#ifdef HAVE_PCD
3555+  pcdW = (Window) NULL;  pcdUp = 0;
3556+#endif
3557+
3558+#ifdef HAVE_MGCSFX
3559+  mgcsfxW = (Window) NULL;  mgcsfxUp = 0;
3560+#endif
3561+
3562   imap = ctrlmap = gmap = browmap = cmtmap = 0;
3563
3564   ch_offx = ch_offy = p_offx = p_offy = 0;
3565@@ -303,13 +377,35 @@
3566   verifyArgs();
3567
3568
3569+#if 0
3570+#ifdef XVEXECPATH
3571+  /* set up path to search for external executables */
3572+  {
3573+    char *systempath = getenv("PATH");
3574+    char *xvexecpath = getenv("XVPATH");
3575+    if (xvexecpath == NULL) xvexecpath = XVEXECPATH;
3576+    /* FIXME: can systempath == NULL? */
3577+    strcat(systempath, ":");		/* FIXME: writing to mem we don't own */
3578+    strcat(systempath, xvexecpath);	/* FIXME: writing to mem we don't own */
3579+    /* FIXME:  was there supposed to be a setenv() call in here? */
3580+    if (DEBUG)
3581+      fprintf(stderr, "DEBUG: executable search path: %s\n", systempath);
3582+  }
3583+#endif
3584+#endif
3585+
3586+
3587   /*****************************************************/
3588   /*** X Setup                                       ***/
3589   /*****************************************************/
3590-
3591+
3592   theScreen = DefaultScreen(theDisp);
3593   theCmap   = DefaultColormap(theDisp, theScreen);
3594-  rootW     = RootWindow(theDisp,theScreen);
3595+  if (spec_window) {
3596+	rootW = spec_window;
3597+  } else {
3598+	rootW = RootWindow(theDisp,theScreen);
3599+  }
3600   theGC     = DefaultGC(theDisp,theScreen);
3601   theVisual = DefaultVisual(theDisp,theScreen);
3602   ncells    = DisplayCells(theDisp, theScreen);
3603@@ -320,53 +416,67 @@
3604
3605   rootDEEP = dispDEEP;
3606
3607-  /* things dependant on theVisual:
3608-   *    dispDEEP, theScreen, rootW, ncells, theCmap, theGC,
3609+  /* things dependent on theVisual:
3610+   *    dispDEEP, theScreen, rootW, ncells, theCmap, theGC,
3611    *    vrWIDE, dispWIDE, vrHIGH, dispHIGH, maxWIDE, maxHIGH
3612    */
3613
3614
3615-
3616   /* if we *haven't* had a non-default visual specified,
3617-     see if we have a TrueColor or DirectColor visual of 24 or 32 bits,
3618+     see if we have a TrueColor or DirectColor visual of 24 or 32 bits,
3619      and if so, use that as the default visual (prefer TrueColor) */
3620
3621   if (!visualstr && !useroot) {
3622+    VisualID     defvid;
3623     XVisualInfo *vinfo, rvinfo;
3624     int          best,  numvis;
3625     long         flags;
3626
3627-    best = -1;
3628+    best          = -1;
3629     rvinfo.class  = TrueColor;
3630     rvinfo.screen = theScreen;
3631-    flags = VisualClassMask | VisualScreenMask;
3632-
3633+    flags         = VisualClassMask | VisualScreenMask;
3634+    defvid        = XVisualIDFromVisual(DefaultVisual(theDisp,
3635+						      DefaultScreen(theDisp)));
3636+
3637     vinfo = XGetVisualInfo(theDisp, flags, &rvinfo, &numvis);
3638-    if (vinfo) {     /* look for a TrueColor, 24-bit or more (pref 24) */
3639-      for (i=0, best = -1; i<numvis; i++) {
3640+    if (vinfo) {
3641+      /* Check list, use 'default', first 24-bit, or first >24-bit */
3642+      for (i=0; i<numvis && best==-1; i++) {   /* default? */
3643+	if ((vinfo[i].visualid == defvid) && (vinfo[i].depth >= 24)) best=i;
3644+      }
3645+      for (i=0; i<numvis && best==-1; i++) {   /* 24-bit ? */
3646 	if (vinfo[i].depth == 24) best = i;
3647-	else if (vinfo[i].depth>24 && best<0) best = i;
3648+      }
3649+      for (i=0; i<numvis && best==-1; i++) {   /* >24-bit ? */
3650+	if (vinfo[i].depth >= 24) best = i;
3651       }
3652     }
3653
3654     if (best == -1) {   /* look for a DirectColor, 24-bit or more (pref 24) */
3655       rvinfo.class = DirectColor;
3656       if (vinfo) XFree((char *) vinfo);
3657+
3658       vinfo = XGetVisualInfo(theDisp, flags, &rvinfo, &numvis);
3659       if (vinfo) {
3660-	for (i=0, best = -1; i<numvis; i++) {
3661+	for (i=0; i<numvis && best==-1; i++) {   /* default? */
3662+	  if ((vinfo[i].visualid == defvid) && (vinfo[i].depth >= 24)) best=i;
3663+	}
3664+	for (i=0; i<numvis && best==-1; i++) {   /* 24-bit ? */
3665 	  if (vinfo[i].depth == 24) best = i;
3666-	  else if (vinfo[i].depth>24 && best<0) best = i;
3667+	}
3668+	for (i=0; i<numvis && best==-1; i++) {   /* >24-bit ? */
3669+	  if (vinfo[i].depth >= 24) best = i;
3670 	}
3671       }
3672     }
3673-
3674+
3675     if (best>=0 && best<numvis) useOtherVisual(vinfo, best);
3676     if (vinfo) XFree((char *) vinfo);
3677   }
3678
3679
3680-
3681+
3682   if (visualstr && useroot) {
3683     fprintf(stderr, "%s: %sUsing default visual.\n",
3684 	    cmd, "Warning:  Can't use specified visual on root.  ");
3685@@ -401,11 +511,11 @@
3686       long vinfomask;
3687       int numvis, best;
3688
3689-      if (vclass >= 0) {
3690+      if (vclass >= 0) {
3691 	rvinfo.class = vclass;   vinfomask = VisualClassMask;
3692       }
3693       else { rvinfo.visualid = vid;  vinfomask = VisualIDMask; }
3694-
3695+
3696       rvinfo.screen = theScreen;
3697       vinfomask |= VisualScreenMask;
3698
3699@@ -429,9 +539,9 @@
3700   /* make linear colormap for DirectColor visual */
3701   if (theVisual->class == DirectColor) makeDirectCmap();
3702
3703-  defaultVis = (XVisualIDFromVisual(theVisual) ==
3704+  defaultVis = (XVisualIDFromVisual(theVisual) ==
3705        XVisualIDFromVisual(DefaultVisual(theDisp, DefaultScreen(theDisp))));
3706-
3707+
3708
3709   /* turn GraphicsExposures OFF in the default GC */
3710   {
3711@@ -441,9 +551,6 @@
3712   }
3713
3714
3715-  if (!useroot && limit2x) { maxWIDE *= 2;  maxHIGH *= 2; }
3716-  if (nolimits) { maxWIDE = 65000; maxHIGH = 65000; }
3717-
3718   XSetErrorHandler(xvErrorHandler);
3719
3720   /* always search for virtual root window */
3721@@ -456,14 +563,14 @@
3722     Atom actual_type;
3723     int actual_format;
3724     unsigned long nitems, bytesafter;
3725-    Window *newRoot = NULL;
3726+    byte *newRoot = NULL;   /* byte instead of Window avoids type-pun warning */
3727     XWindowAttributes xwa;
3728     if (XGetWindowProperty (theDisp, children[i], __SWM_VROOT, 0L, 1L,
3729 	  False, XA_WINDOW, &actual_type, &actual_format, &nitems,
3730 	  &bytesafter, (unsigned char **) &newRoot) == Success && newRoot) {
3731-      vrootW = *newRoot;
3732+      vrootW = *(Window *)newRoot;
3733       XGetWindowAttributes(theDisp, vrootW, &xwa);
3734-      vrWIDE = xwa.width;  vrHIGH = xwa.height;
3735+      maxWIDE = vrWIDE = xwa.width;  maxHIGH = vrHIGH = xwa.height;
3736       dispDEEP = xwa.depth;
3737       break;
3738     }
3739@@ -472,7 +579,8 @@
3740   vrootW = pseudo_root(theDisp, theScreen);
3741 #endif
3742
3743-
3744+  if (!useroot && limit2x) { maxWIDE *= 2;  maxHIGH *= 2; }
3745+  if (nolimits) { maxWIDE = 65000; maxHIGH = 65000; }
3746
3747
3748   if (clrroot || useroot) {
3749@@ -486,13 +594,14 @@
3750   arrow     = XCreateFontCursor(theDisp,(u_int) curstype);
3751   cross     = XCreateFontCursor(theDisp,XC_crosshair);
3752   tcross    = XCreateFontCursor(theDisp,XC_tcross);
3753+  tlcorner  = XCreateFontCursor(theDisp,XC_top_left_corner);
3754   zoom      = XCreateFontCursor(theDisp,XC_sizing);
3755
3756   {
3757     XColor fc, bc;
3758     fc.red = fc.green = fc.blue = 0xffff;
3759     bc.red = bc.green = bc.blue = 0x0000;
3760-
3761+
3762     XRecolorCursor(theDisp, zoom, &fc, &bc);
3763   }
3764
3765@@ -541,7 +650,7 @@
3766
3767
3768   /* set up fg,bg colors */
3769-  fg = black;   bg = white;
3770+  fg = black;   bg = white;
3771   if (fgstr && XParseColor(theDisp, theCmap, fgstr, &ecdef) &&
3772       xvAllocColor(theDisp, theCmap, &ecdef)) {
3773     fg = ecdef.pixel;
3774@@ -561,6 +670,18 @@
3775       xvAllocColor(theDisp, theCmap, &ecdef))  rootbg = ecdef.pixel;
3776
3777
3778+  /* GRR 19980308:  set up image bg color (for transparent images) */
3779+  have_imagebg = 0;
3780+  if (imagebgstr && XParseColor(theDisp, theCmap, imagebgstr, &ecdef) &&
3781+      xvAllocColor(theDisp, theCmap, &ecdef)) {
3782+    /* imagebg = ecdef.pixel; */
3783+    have_imagebg = 1;
3784+    imagebgR = ecdef.red;
3785+    imagebgG = ecdef.green;
3786+    imagebgB = ecdef.blue;
3787+  }
3788+
3789+
3790   /* set up hi/lo colors */
3791   i=0;
3792   if (dispDEEP > 1) {   /* only if we're on a reasonable display */
3793@@ -590,7 +711,7 @@
3794     if (theVisual->class == StaticGray || theVisual->class == GrayScale)
3795       mono = 1;
3796   }
3797-
3798+
3799
3800
3801   iconPix  = MakePix1(rootW, icon_bits,     icon_width,    icon_height);
3802@@ -598,32 +719,32 @@
3803   riconPix = MakePix1(rootW, runicon_bits,  runicon_width, runicon_height);
3804   riconmask= MakePix1(rootW, runiconm_bits, runiconm_width,runiconm_height);
3805
3806-  if (!iconPix || !iconmask || !riconPix || !riconmask)
3807+  if (!iconPix || !iconmask || !riconPix || !riconmask)
3808     FatalError("Unable to create icon pixmaps\n");
3809
3810-  gray50Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
3811+  gray50Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
3812 				(char *) cboard50_bits,
3813-				cboard50_width, cboard50_height,
3814+				cboard50_width, cboard50_height,
3815 				infofg, infobg, dispDEEP);
3816   if (!gray50Tile) FatalError("Unable to create gray50Tile bitmap\n");
3817
3818-  gray25Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
3819+  gray25Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
3820 				(char *) gray25_bits,
3821-				gray25_width, gray25_height,
3822+				gray25_width, gray25_height,
3823 				infofg, infobg, dispDEEP);
3824   if (!gray25Tile) FatalError("Unable to create gray25Tile bitmap\n");
3825
3826
3827   /* try to load fonts */
3828-  if ( (mfinfo = XLoadQueryFont(theDisp,FONT1))==NULL &&
3829-       (mfinfo = XLoadQueryFont(theDisp,FONT2))==NULL &&
3830-       (mfinfo = XLoadQueryFont(theDisp,FONT3))==NULL &&
3831-       (mfinfo = XLoadQueryFont(theDisp,FONT4))==NULL &&
3832+  if ( (mfinfo = XLoadQueryFont(theDisp,FONT1))==NULL &&
3833+       (mfinfo = XLoadQueryFont(theDisp,FONT2))==NULL &&
3834+       (mfinfo = XLoadQueryFont(theDisp,FONT3))==NULL &&
3835+       (mfinfo = XLoadQueryFont(theDisp,FONT4))==NULL &&
3836        (mfinfo = XLoadQueryFont(theDisp,FONT5))==NULL) {
3837-    sprintf(str,
3838+    sprintf(dummystr,
3839 	    "couldn't open the following fonts:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s",
3840 	    FONT1, FONT2, FONT3, FONT4, FONT5);
3841-    FatalError(str);
3842+    FatalError(dummystr);
3843   }
3844   mfont=mfinfo->fid;
3845   XSetFont(theDisp,theGC,mfont);
3846@@ -632,45 +753,100 @@
3847
3848   if (monofontname) {
3849     monofinfo = XLoadQueryFont(theDisp, monofontname);
3850-    if (!monofinfo) fprintf(stderr,"xv: unable to load font '%s'\n",
3851+    if (!monofinfo) fprintf(stderr,"xv: unable to load font '%s'\n",
3852 			    monofontname);
3853-  }
3854+  }
3855
3856   if (!monofinfo) {
3857-    if ((monofinfo = XLoadQueryFont(theDisp,MFONT1))==NULL &&
3858-	(monofinfo = XLoadQueryFont(theDisp,MFONT2))==NULL &&
3859-	(monofinfo = XLoadQueryFont(theDisp,MFONT3))==NULL &&
3860+    if ((monofinfo = XLoadQueryFont(theDisp,MFONT1))==NULL &&
3861+	(monofinfo = XLoadQueryFont(theDisp,MFONT2))==NULL &&
3862+	(monofinfo = XLoadQueryFont(theDisp,MFONT3))==NULL &&
3863 	(monofinfo = XLoadQueryFont(theDisp,MFONT4))==NULL) {
3864-      sprintf(str,"couldn't open %s fonts:\n\t%s\n\t%s\n\t%s\n\t%s",
3865+      sprintf(dummystr,"couldn't open %s fonts:\n\t%s\n\t%s\n\t%s\n\t%s",
3866 	      "any of the following",
3867 	      MFONT1, MFONT2, MFONT3, MFONT4);
3868-      FatalError(str);
3869+      FatalError(dummystr);
3870     }
3871   }
3872
3873   monofont=monofinfo->fid;
3874-
3875
3876-
3877-
3878+#ifdef TV_L10N
3879+  if (xlocale) {
3880+    i = 0;
3881+    while (mfontsize[i]) {
3882+      xlocale = 1;	/* True */
3883+
3884+      sprintf(mfontset, TV_FONTSET, mfontsize[i]);
3885+/*fprintf(stderr, "FontSet: %s\n", mfontset);*/
3886+
3887+      monofset = XCreateFontSet(theDisp, mfontset,
3888+				&misscharset, &nmisscharset, &defstr);
3889+#  if 0	/* not useful */
3890+      if (!monofset) {
3891+	/* the current locale is not supported */
3892+/*fprintf(stderr, "Current locale `%s' is not supported.\n", localeList[i]);*/
3893+	xlocale = 0;
3894+	break;
3895+      }
3896+#  endif
3897+/*fprintf(stderr, "# of misscharset in mfontsize[%d]: %d\n", i,nmisscharset);*/
3898+
3899+      for (j = 0; j < nmisscharset; j++) {
3900+	if (!strncmp(misscharset[j], "jisx0208", 8)) {
3901+	  /* font for JIS X 0208 is not found */
3902+	  xlocale = 0;
3903+	  break;
3904+	}
3905+      }
3906+
3907+      if (xlocale) {
3908+	monofsetinfo = XExtentsOfFontSet(monofset);
3909+	monofsetinfo->max_logical_extent.width = mfontsize[i];
3910+		/* correct size of TextViewer
3911+		   in case that JIS X 0208 is not found */
3912+	break;
3913+      }
3914+
3915+      i++;
3916+    } /* while (mfontsize[i]) */
3917+
3918+#  if 0
3919+    if (nmisscharset > 0) {
3920+      sprintf(dummystr,"missing %d charset:\n", nmisscharset);
3921+      for (i = 0; i < nmisscharset; i++) {
3922+	sprintf(dummystr, "%s\t%s\n", dummystr, misscharset[i]);
3923+      }
3924+#    if 0
3925+      FatalError(dummystr);
3926+#    else
3927+      fprintf(stderr, "%s", dummystr);
3928+#    endif
3929+    }
3930+#  endif
3931+  }
3932+#endif	/* TV_L10N */
3933+
3934+
3935+
3936   /* if ncols wasn't set, set it to 2^dispDEEP, unless dispDEEP=1, in which
3937      case ncols = 0;  (ncols = max number of colors allocated.  on 1-bit
3938      displays, no colors are allocated */
3939-
3940+
3941   if (ncols == -1) {
3942     if (dispDEEP>1) ncols = 1 << ((dispDEEP>8) ? 8 : dispDEEP);
3943     else ncols = 0;
3944   }
3945   else if (ncols>256) ncols = 256;       /* so program doesn't blow up */
3946-
3947-
3948+
3949+
3950   GenerateFSGamma();  /* has to be done before 'OpenBrowse()' is called */
3951-
3952-
3953-
3954+
3955+
3956+
3957   /* no filenames.  build one-name (stdio) list (if stdinflag) */
3958   if (numnames==0) {
3959-    if (stdinflag) {
3960+    if (stdinflag) {
3961       /* have to malloc namelist[0] so we can free it in deleteFromList() */
3962       namelist[0] = (char *) malloc(strlen(STDINSTR) + 1);
3963       if (!namelist[0]) FatalError("unable to to build namelist[0]");
3964@@ -679,16 +855,28 @@
3965     }
3966     else namelist[0] = NULL;
3967   }
3968-
3969+  else if (randomShow) {
3970+    int i, j;
3971+    char *tmp;
3972+
3973+    srandom((int)time((time_t *)0));
3974+    for (i = numnames; i > 1; i--) {
3975+      j = random() % i;
3976+      tmp = namelist[i-1];
3977+      namelist[i-1] = namelist[j];
3978+      namelist[j] = tmp;
3979+    }
3980+  }
3981+
3982   if (numnames) makeDispNames();
3983-
3984-
3985-  if (viewonly || autoquit) {
3986-    imap = ctrlmap = gmap = browmap = cmtmap = 0;
3987+
3988+
3989+  if (viewonly || autoquit) {
3990+    imap = ctrlmap = gmap = browmap = cmtmap = 0;
3991     novbrowse = 1;
3992   }
3993-
3994-
3995+
3996+
3997   /* create the info box window */
3998   CreateInfo(infogeom);
3999   XSelectInput(theDisp, infoW, ExposureMask | ButtonPressMask | KeyPressMask
4000@@ -698,12 +886,12 @@
4001     RedrawInfo(0,0,1000,1000);  /* explicit draw if mapped */
4002     XFlush(theDisp);
4003   }
4004-
4005-
4006+
4007+
4008   /* create the control box window */
4009   CreateCtrl(ctrlgeom);
4010   epicMode = EM_RAW;   SetEpicMode();
4011-
4012+
4013   XSelectInput(theDisp, ctrlW, ExposureMask | ButtonPressMask | KeyPressMask
4014 	       | StructureNotifyMask);
4015   if (ctrlmap < 0) {    /* map iconified */
4016@@ -719,22 +907,22 @@
4017     RedrawCtrl(0,0,1000,1000);   /* explicit draw if mapped */
4018     XFlush(theDisp);
4019   }
4020-
4021+
4022   fixDispNames();
4023   ChangedCtrlList();
4024-
4025+
4026   /* disable root modes if using non-default visual */
4027   if (!defaultVis) {
4028     for (i=RMB_ROOT; i<RMB_MAX; i++) rootMB.dim[i] = 1;
4029   }
4030-
4031-
4032+
4033+
4034   /* create the directory window */
4035   CreateDirW(NULL);
4036   XSelectInput(theDisp, dirW, ExposureMask | ButtonPressMask | KeyPressMask);
4037   browseCB.val = browseMode;
4038   savenormCB.val = savenorm;
4039-
4040+
4041   /* create the gamma window */
4042   CreateGam(gamgeom, (gamset) ? gamval : -1.0,
4043 	    (cgamset) ? rgamval : -1.0,
4044@@ -744,60 +932,84 @@
4045   XSelectInput(theDisp, gamW, ExposureMask | ButtonPressMask | KeyPressMask
4046 	       | StructureNotifyMask
4047 	       | (cmapInGam ? ColormapChangeMask : 0));
4048-
4049+
4050   GamBox(gmap);     /* map it (or not) */
4051-
4052-
4053-
4054+
4055+
4056+
4057   stdnfcols = 0;   /* so we don't try to free any if we don't create any */
4058-
4059+
4060   if (!novbrowse) {
4061     MakeBrowCmap();
4062     /* create the visual browser window */
4063     CreateBrowse(browgeom, fgstr, bgstr, histr, lostr);
4064-
4065+
4066     if (browmap) OpenBrowse();
4067   }
4068   else windowMB.dim[WMB_BROWSE] = 1;    /* disable visual schnauzer */
4069-
4070-
4071+
4072+
4073   CreateTextWins(textgeom, cmtgeom);
4074   if (cmtmap) OpenCommentText();
4075-
4076-
4077+
4078+
4079   /* create the ps window */
4080   CreatePSD(NULL);
4081   XSetTransientForHint(theDisp, psW, dirW);
4082   encapsCB.val = preview;
4083   pscompCB.val = pscomp;
4084-
4085-
4086+
4087+
4088 #ifdef HAVE_JPEG
4089   CreateJPEGW();
4090   XSetTransientForHint(theDisp, jpegW, dirW);
4091 #endif
4092-
4093+
4094+#ifdef HAVE_JP2K
4095+  CreateJP2KW();
4096+  XSetTransientForHint(theDisp, jp2kW, dirW);
4097+#endif
4098+
4099 #ifdef HAVE_TIFF
4100   CreateTIFFW();
4101   XSetTransientForHint(theDisp, tiffW, dirW);
4102 #endif
4103-
4104-
4105+
4106+#ifdef HAVE_PNG
4107+  CreatePNGW();
4108+  XSetTransientForHint(theDisp, pngW, dirW);
4109+#endif
4110+
4111+#ifdef HAVE_PCD
4112+  CreatePCDW();
4113+  XSetTransientForHint(theDisp, pcdW, dirW);
4114+#endif
4115+
4116+#ifdef HAVE_PIC2
4117+  CreatePIC2W();
4118+  XSetTransientForHint(theDisp, pic2W, dirW);
4119+#endif
4120+
4121+#ifdef HAVE_MGCSFX
4122+  CreateMGCSFXW();
4123+  XSetTransientForHint(theDisp, mgcsfxW, dirW);
4124+#endif
4125+
4126   LoadFishCursors();
4127   SetCursors(-1);
4128-
4129-
4130+
4131+
4132   /* if we're not on a colormapped display, turn off rwcolor */
4133   if (!CMAPVIS(theVisual)) {
4134     if (rwcolor) fprintf(stderr, "xv: not a colormapped display.  %s\n",
4135 			 "'rwcolor' turned off.");
4136-
4137+
4138     allocMode = AM_READONLY;
4139     dispMB.flags[DMB_COLRW] = 0;  /* de-'check' */
4140     dispMB.dim[DMB_COLRW] = 1;    /* and dim it */
4141   }
4142-
4143-
4144+
4145+
4146   if (force24) {
4147     Set824Menus(PIC24);
4148     conv24MB.flags[CONV24_LOCK]  = 1;
4149@@ -812,15 +1024,15 @@
4150     Set824Menus(PIC8);     /* default mode */
4151     picType = PIC8;
4152   }
4153-
4154-
4155-
4156+
4157+
4158+
4159   /* make std colormap, maybe */
4160   ChangeCmapMode(colorMapMode, 0, 0);
4161
4162
4163-
4164-
4165+
4166+
4167   /* Do The Thing... */
4168   mainLoop();
4169   Quit(0);
4170@@ -832,12 +1044,12 @@
4171 /*****************************************************/
4172 static void makeDirectCmap()
4173 {
4174-  int    i, j, cmaplen, numgot;
4175+  int    i, cmaplen, numgot;
4176   byte   origgot[256];
4177   XColor c;
4178   u_long rmask, gmask, bmask;
4179   int    rshift, gshift, bshift;
4180-
4181+
4182
4183   rmask = theVisual->red_mask;
4184   gmask = theVisual->green_mask;
4185@@ -849,22 +1061,22 @@
4186
4187   if (rshift<0) rmask = rmask << (-rshift);
4188            else rmask = rmask >> rshift;
4189-
4190+
4191   if (gshift<0) gmask = gmask << (-gshift);
4192            else gmask = gmask >> gshift;
4193-
4194+
4195   if (bshift<0) bmask = bmask << (-bshift);
4196            else bmask = bmask >> bshift;
4197
4198
4199   cmaplen = theVisual->map_entries;
4200   if (cmaplen>256) cmaplen=256;
4201-
4202+
4203
4204   /* try to alloc a 'cmaplen' long grayscale colormap.  May not get all
4205      entries for whatever reason.  Build table 'directConv[]' that
4206      maps range [0..(cmaplen-1)] into set of colors we did get */
4207-
4208+
4209   for (i=0; i<256; i++) {  origgot[i] = 0;  directConv[i] = 0; }
4210
4211   for (i=numgot=0; i<cmaplen; i++) {
4212@@ -882,9 +1094,9 @@
4213     }
4214   }
4215
4216-
4217+
4218   if (numgot == 0) FatalError("Got no entries in DirectColor cmap!\n");
4219-
4220+
4221   /* directConv may or may not have holes in it. */
4222   for (i=0; i<cmaplen; i++) {
4223     if (!origgot[i]) {
4224@@ -892,10 +1104,10 @@
4225       numbak = numfwd = 0;
4226       while ((i - numbak) >= 0       && !origgot[i-numbak]) numbak++;
4227       while ((i + numfwd) <  cmaplen && !origgot[i+numfwd]) numfwd++;
4228-
4229+
4230       if (i-numbak<0        || !origgot[i-numbak]) numbak = 999;
4231       if (i+numfwd>=cmaplen || !origgot[i+numfwd]) numfwd = 999;
4232-
4233+
4234       if      (numbak<numfwd) directConv[i] = directConv[i-numbak];
4235       else if (numfwd<999)    directConv[i] = directConv[i+numfwd];
4236       else FatalError("DirectColor cmap:  can't happen!");
4237@@ -926,14 +1138,14 @@
4238 {
4239   if (!vinfo || best<0) return;
4240
4241-  if (vinfo[best].visualid ==
4242+  if (vinfo[best].visualid ==
4243       XVisualIDFromVisual(DefaultVisual(theDisp, theScreen))) return;
4244
4245   theVisual = vinfo[best].visual;
4246
4247   if (DEBUG) {
4248     fprintf(stderr,"%s: using %s visual (0x%0x), depth = %d, screen = %d\n",
4249-	    cmd,
4250+	    cmd,
4251 	    (vinfo[best].class==StaticGray)  ? "StaticGray" :
4252 	    (vinfo[best].class==StaticColor) ? "StaticColor" :
4253 	    (vinfo[best].class==TrueColor)   ? "TrueColor" :
4254@@ -947,41 +1159,45 @@
4255 	    (int) vinfo[best].red_mask, (int) vinfo[best].green_mask,
4256 	    (int) vinfo[best].blue_mask, vinfo[best].bits_per_rgb);
4257   }
4258-
4259+
4260   dispDEEP  = vinfo[best].depth;
4261   theScreen = vinfo[best].screen;
4262-  rootW     = RootWindow(theDisp, theScreen);
4263+  if (spec_window) {
4264+	rootW = spec_window;
4265+  } else {
4266+	rootW = RootWindow(theDisp,theScreen);
4267+  }
4268   ncells    = vinfo[best].colormap_size;
4269   theCmap   = XCreateColormap(theDisp, rootW, theVisual, AllocNone);
4270-
4271+
4272   {
4273     /* create a temporary window using this visual so we can
4274        create a GC for this visual */
4275-
4276-    Window win;
4277+
4278+    Window win;
4279     XSetWindowAttributes xswa;
4280     XGCValues xgcv;
4281     unsigned long xswamask;
4282-
4283+
4284     XFlush(theDisp);
4285     XSync(theDisp, False);
4286-
4287+
4288     xswa.background_pixel = 0;
4289     xswa.border_pixel     = 1;
4290     xswa.colormap         = theCmap;
4291     xswamask = CWBackPixel | CWBorderPixel | CWColormap;
4292-
4293+
4294     win = XCreateWindow(theDisp, rootW, 0, 0, 100, 100, 2, (int) dispDEEP,
4295 			InputOutput, theVisual, xswamask, &xswa);
4296-
4297+
4298     XFlush(theDisp);
4299     XSync(theDisp, False);
4300-
4301+
4302     theGC = XCreateGC(theDisp, win, 0L, &xgcv);
4303-
4304+
4305     XDestroyWindow(theDisp, win);
4306   }
4307-
4308+
4309   vrWIDE = dispWIDE  = DisplayWidth(theDisp,theScreen);
4310   vrHIGH = dispHIGH  = DisplayHeight(theDisp,theScreen);
4311   maxWIDE = dispWIDE;  maxHIGH = dispHIGH;
4312@@ -1000,25 +1216,25 @@
4313   /* once through the argument list to find the display name
4314      and DEBUG level, if any */
4315
4316-  for (i=1; i<argc; i++) {
4317+  for (i=1; i<argc; ++i) {
4318     if (!strncmp(argv[i],"-help", (size_t) 5)) {  /* help */
4319       cmdSyntax();
4320       exit(0);
4321     }
4322
4323     else if (!argcmp(argv[i],"-display",4,0,&pm)) {
4324-      i++;
4325+      ++i;
4326       if (i<argc) display = argv[i];
4327       break;
4328     }
4329
4330-#ifdef VMS    /* in VMS, cmd-line-opts are in lower case */
4331+#ifdef VMS    /* in VMS, cmd-line opts are in lower case */
4332     else if (!argcmp(argv[i],"-debug",3,0,&pm)) {
4333-      { if (++i<argc) DEBUG = atoi(argv[i]); }
4334+      if (++i<argc) DEBUG = atoi(argv[i]);
4335     }
4336 #else
4337     else if (!argcmp(argv[i],"-DEBUG",2,0,&pm)) {
4338-      { if (++i<argc) DEBUG = atoi(argv[i]); }
4339+      if (++i<argc) DEBUG = atoi(argv[i]);
4340     }
4341 #endif
4342   }
4343@@ -1037,8 +1253,8 @@
4344       fprintf(stderr,"%s: unable to parse 'aspect' resource\n",cmd);
4345     else defaspect = (float) n / (float) d;
4346   }
4347-
4348-  if (rd_flag("2xlimit"))        limit2x     = def_int;
4349+
4350+  if (rd_flag("2xlimit"))        limit2x     = def_int;
4351   if (rd_flag("auto4x3"))        auto4x3     = def_int;
4352   if (rd_flag("autoClose"))      autoclose   = def_int;
4353   if (rd_flag("autoCrop"))       autocrop    = def_int;
4354@@ -1064,6 +1280,7 @@
4355   if (rd_flag("ctrlMap"))        ctrlmap     = def_int;
4356   if (rd_int ("cursor"))         curstype    = def_int;
4357   if (rd_int ("defaultPreset"))  preset      = def_int;
4358+  if (rd_int ("incrementalSearchTimeout"))  incrementalSearchTimeout = def_int;
4359
4360   if (rd_str ("driftKludge")) {
4361     if (sscanf(def_str,"%d %d", &kludge_offx, &kludge_offy) != 2) {
4362@@ -1073,7 +1290,7 @@
4363
4364   if (rd_str ("expand")) {
4365     if (index(def_str, ':')) {
4366-      if (sscanf(def_str, "%lf:%lf", &hexpand, &vexpand)!=2)
4367+      if (sscanf(def_str, "%lf:%lf", &hexpand, &vexpand)!=2)
4368 	{ hexpand = vexpand = 1.0; }
4369     }
4370     else hexpand = vexpand = atof(def_str);
4371@@ -1081,6 +1298,9 @@
4372
4373   if (rd_str ("fileList"))       flistName   = def_str;
4374   if (rd_flag("fixed"))          fixedaspect = def_int;
4375+#ifdef ENABLE_FIXPIX_SMOOTH
4376+  if (rd_flag("fixpix"))         do_fixpix_smooth = def_int;
4377+#endif
4378   if (rd_flag("force8"))         force8      = def_int;
4379   if (rd_flag("force24"))        force24     = def_int;
4380   if (rd_str ("foreground"))     fgstr       = def_str;
4381@@ -1092,23 +1312,39 @@
4382   if (rd_str ("highlight"))      histr       = def_str;
4383   if (rd_str ("iconGeometry"))   icongeom    = def_str;
4384   if (rd_flag("iconic"))         startIconic = def_int;
4385+  if (rd_str ("imageBackground")) imagebgstr = def_str;
4386   if (rd_str ("infoGeometry"))   infogeom    = def_str;
4387   if (rd_flag("infoMap"))        imap        = def_int;
4388   if (rd_flag("loadBrowse"))     browseMode  = def_int;
4389   if (rd_str ("lowlight"))       lostr       = def_str;
4390+#ifdef MACBINARY
4391+  if (rd_flag("macbinary"))      handlemacb  = def_int;
4392+#endif
4393+#ifdef HAVE_MGCSFX
4394+  if (rd_flag("mgcsfx"))         mgcsfx      = def_int;
4395+#endif
4396   if (rd_flag("mono"))           mono        = def_int;
4397   if (rd_str ("monofont"))       monofontname = def_str;
4398   if (rd_int ("ncols"))          ncols       = def_int;
4399   if (rd_flag("ninstall"))       ninstall    = def_int;
4400   if (rd_flag("nodecor"))        nodecor     = def_int;
4401   if (rd_flag("nolimits"))       nolimits    = def_int;
4402+#ifdef HAVE_MGCSFX
4403+  if (rd_flag("nomgcsfx"))       nomgcsfx    = def_int;
4404+#endif
4405+#if defined(HAVE_PIC) || defined(HAVE_PIC2)
4406+  if (rd_flag("nopicadjust"))    nopicadjust = def_int;
4407+#endif
4408   if (rd_flag("nopos"))          nopos       = def_int;
4409   if (rd_flag("noqcheck"))       noqcheck    = def_int;
4410   if (rd_flag("nostat"))         nostat      = def_int;
4411   if (rd_flag("ownCmap"))        owncmap     = def_int;
4412   if (rd_flag("perfect"))        perfect     = def_int;
4413+#ifdef HAVE_PIC2
4414+  if (rd_flag("pic2split"))      pic2split   = def_int;
4415+#endif
4416   if (rd_flag("popupKludge"))    winCtrPosKludge = def_int;
4417-  if (rd_str ("print"))          strncpy(printCmd, def_str,
4418+  if (rd_str ("print"))          strncpy(printCmd, def_str,
4419 					 (size_t) PRINTCMDLEN);
4420   if (rd_flag("pscompress"))     pscomp      = def_int;
4421   if (rd_flag("pspreview"))      preview     = def_int;
4422@@ -1117,18 +1353,34 @@
4423   if (rd_flag("reverse"))        revvideo    = def_int;
4424   if (rd_str ("rootBackground")) rootbgstr   = def_str;
4425   if (rd_str ("rootForeground")) rootfgstr   = def_str;
4426-  if (rd_int ("rootMode"))       { rootMode    = def_int;  rmodeset++; }
4427+  if (rd_int ("rootMode"))       { rootMode    = def_int;  ++rmodeset; }
4428   if (rd_flag("rwColor"))        rwcolor     = def_int;
4429   if (rd_flag("saveNormal"))     savenorm    = def_int;
4430   if (rd_str ("searchDirectory"))  strcpy(searchdir, def_str);
4431   if (rd_str ("textviewGeometry")) textgeom  = def_str;
4432   if (rd_flag("useStdCmap"))     stdcmap     = def_int;
4433   if (rd_str ("visual"))         visualstr   = def_str;
4434+#ifdef VS_ADJUST
4435+  if (rd_flag("vsadjust"))       vsadjust    = def_int;
4436+#endif
4437   if (rd_flag("vsDisable"))      novbrowse   = def_int;
4438   if (rd_str ("vsGeometry"))     browgeom    = def_str;
4439   if (rd_flag("vsMap"))          browmap     = def_int;
4440   if (rd_flag("vsPerfect"))      browPerfect = def_int;
4441   if (rd_str ("white"))          whitestr    = def_str;
4442+
4443+  /* Check for any command-bindings to the supported function keys */
4444+#define TMPLEN 80
4445+  for (i=0; i<FSTRMAX; ++i) {
4446+    char tmp[TMPLEN];
4447+
4448+    snprintf(tmp, TMPLEN, "F%dcommand", i+1);
4449+    if (rd_str(tmp))
4450+      fkeycmds[i] = def_str;
4451+    else
4452+      fkeycmds[i] = NULL;
4453+  }
4454+#undef TMPLEN
4455 }
4456
4457
4458@@ -1146,7 +1398,7 @@
4459
4460     not_in_first_half = 0;
4461
4462-    if (argv[i][0] != '-' && argv[i][0] != '+') {
4463+    if (argv[i][0] != '-' && argv[i][0] != '+') {
4464       /* a file name.  put it in list */
4465
4466       if (!nostat) {
4467@@ -1158,24 +1410,30 @@
4468       }
4469
4470       if (numnames<MAXNAMES) {
4471+#ifdef AUTO_EXPAND
4472+	if(Isarchive(argv[i]) == 0){ /* Not archive file */
4473+	  namelist[numnames++] = argv[i];
4474+	}
4475+#else
4476 	namelist[numnames++] = argv[i];
4477+#endif
4478 	if (numnames==MAXNAMES) {
4479-	  fprintf(stderr,"%s: too many filenames.  Only using first %d.\n",
4480+	  fprintf(stderr,"%s: too many filenames.  Using only first %d.\n",
4481 		  cmd, MAXNAMES);
4482 	}
4483       }
4484     }
4485
4486-    else if (!strcmp(argv[i],  "-"))                    /* stdin flag */
4487+    else if (!strcmp(argv[i],  "-"))                       /* stdin flag */
4488       stdinflag++;
4489
4490-    else if (!argcmp(argv[i],"-24",     3,1,&force24 ));  /* force24 */
4491-    else if (!argcmp(argv[i],"-2xlimit",3,1,&limit2x ));  /* 2xlimit */
4492-    else if (!argcmp(argv[i],"-4x3",    2,1,&auto4x3 ));  /* 4x3 */
4493-    else if (!argcmp(argv[i],"-8",      2,1,&force8  ));  /* force8 */
4494-    else if (!argcmp(argv[i],"-acrop",  3,1,&autocrop));  /* autocrop */
4495-
4496-    else if (!argcmp(argv[i],"-aspect",3,0,&pm)) {        /* def. aspect */
4497+    else if (!argcmp(argv[i],"-24",     3,1,&force24 ));   /* force24 */
4498+    else if (!argcmp(argv[i],"-2xlimit",3,1,&limit2x ));   /* 2xlimit */
4499+    else if (!argcmp(argv[i],"-4x3",    2,1,&auto4x3 ));   /* 4x3 */
4500+    else if (!argcmp(argv[i],"-8",      2,1,&force8  ));   /* force8 */
4501+    else if (!argcmp(argv[i],"-acrop",  3,1,&autocrop));   /* autocrop */
4502+
4503+    else if (!argcmp(argv[i],"-aspect",3,0,&pm)) {         /* def. aspect */
4504       int n,d;
4505       if (++i<argc) {
4506 	if (sscanf(argv[i],"%d:%d",&n,&d)!=2 || n<1 || d<1)
4507@@ -1184,57 +1442,65 @@
4508       }
4509     }
4510
4511-    else if (!argcmp(argv[i],"-best24",3,0,&pm))          /* -best */
4512+    else if (!argcmp(argv[i],"-windowid",3,0,&pm)) {
4513+      if (++i<argc) {
4514+	if (sscanf(argv[i], "%ld", &spec_window) != 1) {
4515+		fprintf(stderr,"%s: bad argument to -windowid '%s'\n",cmd,argv[i]);
4516+        }
4517+      }
4518+    }
4519+
4520+    else if (!argcmp(argv[i],"-best24",3,0,&pm))           /* -best */
4521       conv24 = CONV24_BEST;
4522-
4523-    else if (!argcmp(argv[i],"-bg",3,0,&pm))              /* bg color */
4524+
4525+    else if (!argcmp(argv[i],"-bg",3,0,&pm))               /* bg color */
4526       { if (++i<argc) bgstr = argv[i]; }
4527-
4528-    else if (!argcmp(argv[i],"-black",3,0,&pm))           /* black color */
4529+
4530+    else if (!argcmp(argv[i],"-black",3,0,&pm))            /* black color */
4531       { if (++i<argc) blackstr = argv[i]; }
4532-
4533-    else if (!argcmp(argv[i],"-bw",3,0,&pm))              /* border width */
4534+
4535+    else if (!argcmp(argv[i],"-bw",3,0,&pm))               /* border width */
4536       { if (++i<argc) bwidth=atoi(argv[i]); }
4537-
4538-    else if (!argcmp(argv[i],"-cecmap",4,1,&cmapInGam));  /* cmapInGam */
4539-
4540-    else if (!argcmp(argv[i],"-cegeometry",4,0,&pm))      /* gammageom */
4541+
4542+    else if (!argcmp(argv[i],"-cecmap",4,1,&cmapInGam));   /* cmapInGam */
4543+
4544+    else if (!argcmp(argv[i],"-cegeometry",4,0,&pm))       /* gammageom */
4545       { if (++i<argc) gamgeom = argv[i]; }
4546-
4547-    else if (!argcmp(argv[i],"-cemap",4,1,&gmap));        /* gmap */
4548-
4549-    else if (!argcmp(argv[i],"-cgamma",4,0,&pm)) {        /* color gamma */
4550+
4551+    else if (!argcmp(argv[i],"-cemap",4,1,&gmap));         /* gmap */
4552+
4553+    else if (!argcmp(argv[i],"-cgamma",4,0,&pm)) {         /* color gamma */
4554       if (i+3<argc) {
4555-	rgamval = atof(argv[++i]);
4556-	ggamval = atof(argv[++i]);
4557-	bgamval = atof(argv[++i]);
4558+	rgamval = atof(argv[++i]);
4559+	ggamval = atof(argv[++i]);
4560+	bgamval = atof(argv[++i]);
4561       }
4562       cgamset++;
4563     }
4564-
4565-    else if (!argcmp(argv[i],"-cgeometry",4,0,&pm))	  /* ctrlgeom */
4566+
4567+    else if (!argcmp(argv[i],"-cgeometry",4,0,&pm))	   /* ctrlgeom */
4568       { if (++i<argc) ctrlgeom = argv[i]; }
4569-
4570-    else if (!argcmp(argv[i],"-clear",4,1,&clrroot));	  /* clear */
4571-    else if (!argcmp(argv[i],"-close",4,1,&autoclose));	  /* close */
4572-    else if (!argcmp(argv[i],"-cmap", 3,1,&ctrlmap));	  /* ctrlmap */
4573
4574-    else if (!argcmp(argv[i],"-cmtgeometry",5,0,&pm))	  /* comment geom */
4575+    else if (!argcmp(argv[i],"-clear",4,1,&clrroot));	   /* clear */
4576+    else if (!argcmp(argv[i],"-close",4,1,&autoclose));	   /* close */
4577+    else if (!argcmp(argv[i],"-cmap", 3,1,&ctrlmap));	   /* ctrlmap */
4578+
4579+    else if (!argcmp(argv[i],"-cmtgeometry",5,0,&pm))	   /* comment geom */
4580       { if (++i<argc) cmtgeom = argv[i]; }
4581-
4582-    else if (!argcmp(argv[i],"-cmtmap",5,1,&cmtmap));	  /* map cmt window */
4583-
4584-    else if (!argcmp(argv[i],"-crop",3,0,&pm)) {          /* crop */
4585+
4586+    else if (!argcmp(argv[i],"-cmtmap",5,1,&cmtmap));	   /* map cmt window */
4587+
4588+    else if (!argcmp(argv[i],"-crop",3,0,&pm)) {           /* crop */
4589       if (i+4<argc) {
4590-	acropX = atoi(argv[++i]);
4591-	acropY = atoi(argv[++i]);
4592-	acropW = atoi(argv[++i]);
4593-	acropH = atoi(argv[++i]);
4594+	acropX = atoi(argv[++i]);
4595+	acropY = atoi(argv[++i]);
4596+	acropW = atoi(argv[++i]);
4597+	acropH = atoi(argv[++i]);
4598       }
4599       acrop++;
4600     }
4601-
4602-    else if (!argcmp(argv[i],"-cursor",3,0,&pm))	  /* cursor */
4603+
4604+    else if (!argcmp(argv[i],"-cursor",3,0,&pm))	   /* cursor */
4605       { if (++i<argc) curstype = atoi(argv[i]); }
4606
4607 #ifdef VMS    /* in VMS, cmd-line-opts are in lower case */
4608@@ -1247,84 +1513,100 @@
4609     }
4610 #endif
4611
4612-    else if (!argcmp(argv[i],"-dir",4,0,&pm))             /* search dir */
4613+    else if (!argcmp(argv[i],"-dir",4,0,&pm))              /* search dir */
4614       { if (++i<argc) strcpy(searchdir, argv[i]); }
4615
4616-    else if (!argcmp(argv[i],"-display",4,0,&pm))         /* display */
4617+    else if (!argcmp(argv[i],"-display",4,0,&pm))          /* display */
4618       { if (++i<argc) display = argv[i]; }
4619
4620-    else if (!argcmp(argv[i],"-dither",4,1,&autodither)); /* autodither */
4621+    else if (!argcmp(argv[i],"-dither",4,1,&autodither));  /* autodither */
4622
4623-    else if (!argcmp(argv[i],"-drift",3,0,&pm)) {         /* drift kludge */
4624+    else if (!argcmp(argv[i],"-drift",3,0,&pm)) {          /* drift kludge */
4625       if (i<argc-2) {
4626 	kludge_offx = atoi(argv[++i]);
4627 	kludge_offy = atoi(argv[++i]);
4628       }
4629     }
4630
4631-    else if (!argcmp(argv[i],"-expand",2,0,&pm)) {	  /* expand factor */
4632+    else if (!argcmp(argv[i],"-expand",2,0,&pm)) {	   /* expand factor */
4633       if (++i<argc) {
4634 	if (index(argv[i], ':')) {
4635-	  if (sscanf(argv[i], "%lf:%lf", &hexpand, &vexpand)!=2)
4636+	  if (sscanf(argv[i], "%lf:%lf", &hexpand, &vexpand)!=2)
4637 	    { hexpand = vexpand = 1.0; }
4638 	}
4639 	else hexpand = vexpand = atof(argv[i]);
4640       }
4641     }
4642
4643-    else if (!argcmp(argv[i],"-fg",3,0,&pm))              /* fg color */
4644+#ifdef HAVE_G3
4645+    else if (!argcmp(argv[i],"-fax",3,0,&highresfax));     /* fax */
4646+#endif
4647+
4648+    else if (!argcmp(argv[i],"-fg",3,0,&pm))               /* fg color */
4649       { if (++i<argc) fgstr = argv[i]; }
4650-
4651-    else if (!argcmp(argv[i],"-fixed",3,1,&fixedaspect)); /* fix asp. ratio */
4652-
4653-    else if (!argcmp(argv[i],"-flist",3,0,&pm))           /* file list */
4654+
4655+    else if (!argcmp(argv[i],"-fixed",5,1,&fixedaspect));  /* fix asp. ratio */
4656+
4657+#ifdef ENABLE_FIXPIX_SMOOTH
4658+    else if (!argcmp(argv[i],"-fixpix",5,1,&do_fixpix_smooth)); /* dithering */
4659+#endif
4660+
4661+    else if (!argcmp(argv[i],"-flist",3,0,&pm))            /* file list */
4662       { if (++i<argc) flistName = argv[i]; }
4663
4664-    else if (!argcmp(argv[i],"-gamma",3,0,&pm))	          /* gamma */
4665+    else if (!argcmp(argv[i],"-gamma",3,0,&pm))	           /* gamma */
4666       { if (++i<argc) gamval = atof(argv[i]);  gamset++; }
4667-
4668-    else if (!argcmp(argv[i],"-geometry",3,0,&pm))	  /* geometry */
4669+
4670+    else if (!argcmp(argv[i],"-geometry",3,0,&pm))	   /* geometry */
4671       { if (++i<argc) maingeom = argv[i]; }
4672-
4673-    else if (!argcmp(argv[i],"-grabdelay",3,0,&pm))	  /* grabDelay */
4674+
4675+    else if (!argcmp(argv[i],"-grabdelay",3,0,&pm))	   /* grabDelay */
4676       { if (++i<argc) grabDelay = atoi(argv[i]); }
4677-
4678-    else if (!argcmp(argv[i],"-gsdev",4,0,&pm))	          /* gsDevice */
4679+
4680+    else if (!argcmp(argv[i],"-gsdev",4,0,&pm))	           /* gsDevice */
4681       { if (++i<argc) gsDev = argv[i]; }
4682-
4683-    else if (!argcmp(argv[i],"-gsgeom",4,0,&pm))          /* gsGeometry */
4684+
4685+    else if (!argcmp(argv[i],"-gsgeom",4,0,&pm))           /* gsGeometry */
4686       { if (++i<argc) gsGeomStr = argv[i]; }
4687-
4688-    else if (!argcmp(argv[i],"-gsres",4,0,&pm))           /* gsResolution */
4689+
4690+    else if (!argcmp(argv[i],"-gsres",4,0,&pm))            /* gsResolution */
4691       { if (++i<argc) gsRes=abs(atoi(argv[i])); }
4692-
4693-    else if (!argcmp(argv[i],"-hflip",3,1,&autohflip));   /* hflip */
4694
4695-    else if (!argcmp(argv[i],"-hi",3,0,&pm))	          /* highlight */
4696+    else if (!argcmp(argv[i],"-hflip",3,1,&autohflip));    /* hflip */
4697+
4698+    else if (!argcmp(argv[i],"-hi",3,0,&pm))	           /* highlight */
4699       { if (++i<argc) histr = argv[i]; }
4700-
4701-    else if (!argcmp(argv[i],"-hist", 4,1,&autohisteq));  /* hist eq */
4702+
4703+#ifdef HAVE_G3
4704+    else if (!argcmp(argv[i],"-highresfax",4,0,&highresfax));/* high res. fax */
4705+#endif
4706+
4707+    else if (!argcmp(argv[i],"-hist", 4,1,&autohisteq));   /* hist eq */
4708
4709     else if (!argcmp(argv[i],"-hsv",   3,1,&hsvmode));     /* hsvmode */
4710
4711     else if (!argcmp(argv[i],"-icgeometry",4,0,&pm))       /* icon geometry */
4712       { if (++i<argc) icongeom = argv[i]; }
4713-
4714+
4715     else if (!argcmp(argv[i],"-iconic",4,1,&startIconic)); /* iconic */
4716-
4717+
4718     else if (!argcmp(argv[i],"-igeometry",3,0,&pm))        /* infogeom */
4719       { if (++i<argc) infogeom = argv[i]; }
4720-
4721-    else if (!argcmp(argv[i],"-imap",     3,1,&imap));        /* imap */
4722-    else if (!argcmp(argv[i],"-lbrowse",  3,1,&browseMode));  /* browse mode */
4723
4724-    else if (!argcmp(argv[i],"-lo",3,0,&pm))	        /* lowlight */
4725+    else if (!argcmp(argv[i],"-imap",3,1,&imap));          /* imap */
4726+
4727+    else if (!argcmp(argv[i],"-ibg",3,0,&pm))             /* image bkgd color */
4728+      { if (++i<argc) imagebgstr = argv[i]; }
4729+
4730+    else if (!argcmp(argv[i],"-lbrowse",3,1,&browseMode)); /* browse mode */
4731+
4732+    else if (!argcmp(argv[i],"-lo",3,0,&pm))	           /* lowlight */
4733       { if (++i<argc) lostr = argv[i]; }
4734
4735     else if (!argcmp(argv[i],"-loadclear",4,1,&clearonload)); /* clearonload */
4736
4737-
4738-    else not_in_first_half = 1;
4739+
4740+    else not_in_first_half = 1;
4741
4742
4743
4744@@ -1339,103 +1621,130 @@
4745     if (!argcmp(argv[i],"-max",4,1,&automax));	        /* auto maximize */
4746     else if (!argcmp(argv[i],"-maxpect",5,1,&pm))       /* auto maximize */
4747       { automax=pm; fixedaspect=pm; }
4748-
4749+
4750+#ifdef MACBINARY
4751+    else if (!argcmp(argv[i],"-macbinary",3,1,&handlemacb)); /* macbinary */
4752+#endif
4753+
4754     else if (!argcmp(argv[i],"-mfn",3,0,&pm))           /* mono font name */
4755       { if (++i<argc) monofontname = argv[i]; }
4756
4757+#ifdef HAVE_MGCSFX
4758+    else if (!argcmp(argv[i],"-mgcsfx", 4,1,&mgcsfx));  /* mgcsfx */
4759+#endif
4760+
4761     else if (!argcmp(argv[i],"-mono",3,1,&mono));	/* mono */
4762-
4763+
4764     else if (!argcmp(argv[i],"-name",3,0,&pm))          /* name */
4765       { if (++i<argc) winTitle = argv[i]; }
4766-
4767+
4768     else if (!argcmp(argv[i],"-ncols",3,0,&pm))        /* ncols */
4769       { if (++i<argc) ncols=abs(atoi(argv[i])); }
4770-
4771-    else if (!argcmp(argv[i],"-ninstall",  3,1,&ninstall));   /* inst cmaps?*/
4772+
4773+    else if (!argcmp(argv[i],"-ninstall",  3,1,&ninstall));   /* inst cmaps? */
4774     else if (!argcmp(argv[i],"-nodecor",   4,1,&nodecor));
4775     else if (!argcmp(argv[i],"-nofreecols",4,1,&noFreeCols));
4776     else if (!argcmp(argv[i],"-nolimits",  4,1,&nolimits));   /* nolimits */
4777+#ifdef HAVE_MGCSFX
4778+    else if (!argcmp(argv[i],"-nomgcsfx", 4,1,&nomgcsfx));    /* nomgcsfx */
4779+#endif
4780+#if defined(HAVE_PIC) || defined(HAVE_PIC2)
4781+    else if (!argcmp(argv[i],"-nopicadjust", 4,1,&nopicadjust));/*nopicadjust*/
4782+#endif
4783     else if (!argcmp(argv[i],"-nopos",     4,1,&nopos));      /* nopos */
4784     else if (!argcmp(argv[i],"-noqcheck",  4,1,&noqcheck));   /* noqcheck */
4785-    else if (!argcmp(argv[i],"-noresetroot",5,1,&resetroot)); /* reset root*/
4786+    else if (!argcmp(argv[i],"-noresetroot",5,1,&resetroot)); /* reset root */
4787     else if (!argcmp(argv[i],"-norm",      5,1,&autonorm));   /* norm */
4788     else if (!argcmp(argv[i],"-nostat",    4,1,&nostat));     /* nostat */
4789     else if (!argcmp(argv[i],"-owncmap",   2,1,&owncmap));    /* own cmap */
4790+#ifdef HAVE_PCD
4791+    else if (!argcmp(argv[i],"-pcd",       4,0,&pm))         /* pcd with size */
4792+      { if (i+1<argc) PcdSize = atoi(argv[++i]); }
4793+#endif
4794     else if (!argcmp(argv[i],"-perfect",   3,1,&perfect));    /* -perfect */
4795+#ifdef HAVE_PIC2
4796+    else if (!argcmp(argv[i],"-pic2split", 3,1,&pic2split));  /* pic2split */
4797+#endif
4798     else if (!argcmp(argv[i],"-pkludge",   3,1,&winCtrPosKludge));
4799     else if (!argcmp(argv[i],"-poll",      3,1,&polling));    /* chk mod? */
4800
4801     else if (!argcmp(argv[i],"-preset",3,0,&pm))      /* preset */
4802       { if (++i<argc) preset=abs(atoi(argv[i])); }
4803-
4804+
4805     else if (!argcmp(argv[i],"-quick24",5,0,&pm))     /* quick 24-to-8 conv */
4806       conv24 = CONV24_FAST;
4807-
4808+
4809     else if (!argcmp(argv[i],"-quit",   2,1,&autoquit));   /* auto-quit */
4810     else if (!argcmp(argv[i],"-random", 4,1,&randomShow)); /* random */
4811     else if (!argcmp(argv[i],"-raw",    4,1,&autoraw));    /* force raw */
4812
4813     else if (!argcmp(argv[i],"-rbg",3,0,&pm))      /* root background color */
4814       { if (++i<argc) rootbgstr = argv[i]; }
4815-
4816+
4817     else if (!argcmp(argv[i],"-rfg",3,0,&pm))      /* root foreground color */
4818       { if (++i<argc) rootfgstr = argv[i]; }
4819-
4820+
4821     else if (!argcmp(argv[i],"-rgb",4,1,&pm))      /* rgb mode */
4822       hsvmode = !pm;
4823-
4824+
4825     else if (!argcmp(argv[i],"-RM",3,0,&pm))	   /* auto-delete */
4826       autoDelete = 1;
4827-
4828+
4829     else if (!argcmp(argv[i],"-rmode",3,0,&pm))	   /* root pattern */
4830-      { if (++i<argc) rootMode = atoi(argv[i]);
4831+      { if (++i<argc) rootMode = atoi(argv[i]);
4832 	useroot++;  rmodeset++;
4833       }
4834-
4835+
4836     else if (!argcmp(argv[i],"-root",4,1,&useroot));  /* use root window */
4837-
4838+
4839     else if (!argcmp(argv[i],"-rotate",4,0,&pm))      /* rotate */
4840       { if (++i<argc) autorotate = atoi(argv[i]); }
4841-
4842+
4843     else if (!argcmp(argv[i],"-rv",3,1,&revvideo));   /* reverse video */
4844     else if (!argcmp(argv[i],"-rw",3,1,&rwcolor));    /* use r/w color */
4845
4846     else if (!argcmp(argv[i],"-slow24",3,0,&pm))      /* slow 24->-8 conv.*/
4847       conv24 = CONV24_SLOW;
4848-
4849+
4850     else if (!argcmp(argv[i],"-smooth",3,1,&autosmooth));  /* autosmooth */
4851+    else if (!argcmp(argv[i],"-startgrab",3,1,&startGrab)); /* startGrab */
4852     else if (!argcmp(argv[i],"-stdcmap",3,1,&stdcmap));    /* use stdcmap */
4853
4854     else if (!argcmp(argv[i],"-tgeometry",2,0,&pm))	   /* textview geom */
4855       { if (++i<argc) textgeom = argv[i]; }
4856-
4857+
4858     else if (!argcmp(argv[i],"-vflip",3,1,&autovflip));	   /* vflip */
4859     else if (!argcmp(argv[i],"-viewonly",4,1,&viewonly));  /* viewonly */
4860
4861     else if (!argcmp(argv[i],"-visual",4,0,&pm))           /* visual */
4862       { if (++i<argc) visualstr = argv[i]; }
4863-
4864+
4865+#ifdef VS_ADJUST
4866+    else if (!argcmp(argv[i],"-vsadjust", 3,1,&vsadjust));  /* vsadjust */
4867+#endif
4868+
4869     else if (!argcmp(argv[i],"-vsdisable",4,1,&novbrowse)); /* disable sch? */
4870-
4871+
4872     else if (!argcmp(argv[i],"-vsgeometry",4,0,&pm))	/* visSchnauzer geom */
4873       { if (++i<argc) browgeom = argv[i]; }
4874-
4875+
4876     else if (!argcmp(argv[i],"-vsmap",4,1,&browmap));	/* visSchnauzer map */
4877-
4878+
4879     else if (!argcmp(argv[i],"-vsperfect",3,1,&browPerfect));	/* vs perf. */
4880
4881     else if (!argcmp(argv[i],"-wait",3,0,&pm)) {        /* secs betwn pics */
4882       if (++i<argc) {
4883-	waitsec = abs(atoi(argv[i]));
4884-	if (waitsec<0) waitsec = 0;
4885+	char *comma = strchr(argv[i], ',');
4886+	waitsec_nonfinal = fabs(atof(argv[i]));
4887+	waitsec_final = comma? fabs(atof(comma+1)) : waitsec_nonfinal;
4888       }
4889     }
4890-
4891+
4892     else if (!argcmp(argv[i],"-white",3,0,&pm))	        /* white color */
4893       { if (++i<argc) whitestr = argv[i]; }
4894-
4895+
4896     else if (!argcmp(argv[i],"-wloop",3,1,&waitloop));	/* waitloop */
4897-
4898+
4899     else if (not_in_first_half) cmdSyntax();
4900   }
4901
4902@@ -1453,7 +1762,11 @@
4903   /* check options for validity */
4904
4905   if (strlen(searchdir)) {  /* got a search directory */
4906+#ifdef AUTO_EXPAND
4907+    if (Chvdir(searchdir)) {
4908+#else
4909     if (chdir(searchdir)) {
4910+#endif
4911       fprintf(stderr,"xv: unable to cd to directory '%s'.\n",searchdir);
4912       fprintf(stderr,
4913        "    Ignoring '-dir' option and/or 'xv.searchDirectory' resource\n");
4914@@ -1462,7 +1775,7 @@
4915   }
4916
4917
4918-  if (flistName)
4919+  if (flistName)
4920     add_filelist_to_namelist(flistName, namelist, &numnames, MAXNAMES);
4921
4922   RANGE(curstype,0,254);
4923@@ -1475,16 +1788,16 @@
4924
4925   /* if using root, generally gotta map ctrl window, 'cause there won't be
4926      any way to ask for it.  (no kbd or mouse events from rootW) */
4927-  if (useroot && !autoquit) ctrlmap = -1;
4928+  if (useroot && !autoquit) ctrlmap = -1;
4929+
4930
4931-
4932   if (abs(autorotate) !=   0 && abs(autorotate) != 90 &&
4933       abs(autorotate) != 180 && abs(autorotate) != 270) {
4934     fprintf(stderr,"Invalid auto rotation value (%d) ignored.\n", autorotate);
4935     fprintf(stderr,"  (Valid values:  0, +-90, +-180, +-270)\n");
4936
4937     autorotate = 0;
4938-  }
4939+  }
4940
4941
4942   if (grabDelay < 0 || grabDelay > 15) {
4943@@ -1498,9 +1811,9 @@
4944     fprintf(stderr,"  (Valid values:  1, 2, 3, 4)\n");
4945
4946     preset = 0;
4947-  }
4948+  }
4949
4950-  if (waitsec < 0) noFreeCols = 0;   /* disallow nfc if not doing slideshow */
4951+  if (waitsec < 0.0) noFreeCols = 0;   /* disallow nfc if not doing slideshow */
4952   if (noFreeCols && perfect) { perfect = 0;  owncmap = 1; }
4953
4954   /* decide what default color allocation stuff we've settled on */
4955@@ -1512,24 +1825,24 @@
4956
4957   defaultCmapMode = colorMapMode;  /* default mode for 8-bit images */
4958
4959-  if (nopos) {
4960-    maingeom = infogeom = ctrlgeom = gamgeom = browgeom = textgeom = NULL;
4961-    cmtgeom = NULL;
4962+  if (nopos) {
4963+    maingeom = infogeom = ctrlgeom = gamgeom = browgeom = textgeom = cmtgeom =
4964+      (const char *) NULL;
4965   }
4966
4967   /* if -root and -maxp, disallow 'integer' tiling modes */
4968-  if (useroot && fixedaspect && automax && !rmodeset &&
4969+  if (useroot && fixedaspect && automax && !rmodeset &&
4970       (rootMode == RM_TILE || rootMode == RM_IMIRROR))
4971     rootMode = RM_CSOLID;
4972 }
4973
4974
4975
4976+static int cpos = 0;
4977
4978 /***********************************/
4979-static int cpos = 0;
4980 static void printoption(st)
4981-     char *st;
4982+     const char *st;
4983 {
4984   if (strlen(st) + cpos > 78) {
4985     fprintf(stderr,"\n   ");
4986@@ -1540,8 +1853,26 @@
4987   cpos = cpos + strlen(st) + 1;
4988 }
4989
4990+
4991 static void cmdSyntax()
4992 {
4993+  /* GRR 19980605:  added version info for most common libraries */
4994+  fprintf(stderr, "XV - %s.\n", REVDATE);
4995+#ifdef HAVE_JPEG
4996+  VersionInfoJPEG();
4997+#endif
4998+#ifdef HAVE_JP2K
4999+  VersionInfoJP2K();
5000+#endif
5001+#ifdef HAVE_TIFF
5002+  VersionInfoTIFF();
5003+#endif
5004+#ifdef HAVE_PNG
5005+  VersionInfoPNG();
5006+#endif
5007+  /* pbm/pgm/ppm support is native, not via pbmplus/netpbm libraries */
5008+  fprintf(stderr, "\n");
5009+
5010   fprintf(stderr, "Usage:\n");
5011   printoption(cmd);
5012   printoption("[-]");
5013@@ -1579,8 +1910,14 @@
5014   printoption("[-/+dither]");
5015   printoption("[-drift dx dy]");
5016   printoption("[-expand exp | hexp:vexp]");
5017+#ifdef HAVE_G3
5018+  printoption("[-fax]");
5019+#endif
5020   printoption("[-fg color]");
5021   printoption("[-/+fixed]");
5022+#ifdef ENABLE_FIXPIX_SMOOTH
5023+  printoption("[-/+fixpix]");
5024+#endif
5025   printoption("[-flist fname]");
5026   printoption("[-gamma val]");
5027   printoption("[-geometry geom]");
5028@@ -1591,8 +1928,12 @@
5029   printoption("[-help]");
5030   printoption("[-/+hflip]");
5031   printoption("[-hi color]");
5032+#ifdef HAVE_G3
5033+  printoption("[-highresfax]");
5034+#endif
5035   printoption("[-/+hist]");
5036   printoption("[-/+hsv]");
5037+  printoption("[-ibg color]");  /* GRR 19980314 */
5038   printoption("[-icgeometry geom]");
5039   printoption("[-/+iconic]");
5040   printoption("[-igeometry geom]");
5041@@ -1600,9 +1941,15 @@
5042   printoption("[-/+lbrowse]");
5043   printoption("[-lo color]");
5044   printoption("[-/+loadclear]");
5045+#ifdef MACBINARY
5046+  printoption("[-/+macbinary]");
5047+#endif
5048   printoption("[-/+max]");
5049   printoption("[-/+maxpect]");
5050   printoption("[-mfn font]");
5051+#ifdef HAVE_MGCSFX
5052+  printoption("[-/+mgcsfx]");
5053+#endif
5054   printoption("[-/+mono]");
5055   printoption("[-name str]");
5056   printoption("[-ncols #]");
5057@@ -1610,13 +1957,25 @@
5058   printoption("[-/+nodecor]");
5059   printoption("[-/+nofreecols]");
5060   printoption("[-/+nolimits]");
5061+#ifdef HAVE_MGCSFX
5062+  printoption("[-/+nomgcsfx]");
5063+#endif
5064+#if defined(HAVE_PIC) || defined(HAVE_PIC2)
5065+  printoption("[-/+nopicadjust]");
5066+#endif
5067   printoption("[-/+nopos]");
5068   printoption("[-/+noqcheck]");
5069   printoption("[-/+noresetroot]");
5070   printoption("[-/+norm]");
5071   printoption("[-/+nostat]");
5072   printoption("[-/+owncmap]");
5073+#ifdef HAVE_PCD
5074+  printoption("[-pcd size(0=192*128,1,2,3,4=3072*2048)]");
5075+#endif
5076   printoption("[-/+perfect]");
5077+#ifdef HAVE_PIC2
5078+  printoption("[-/+pic2split]");
5079+#endif
5080   printoption("[-/+pkludge]");
5081   printoption("[-/+poll]");
5082   printoption("[-preset #]");
5083@@ -1635,17 +1994,22 @@
5084   printoption("[-/+rw]");
5085   printoption("[-slow24]");
5086   printoption("[-/+smooth]");
5087+  printoption("[-/+startgrab]");
5088   printoption("[-/+stdcmap]");
5089   printoption("[-tgeometry geom]");
5090   printoption("[-/+vflip]");
5091   printoption("[-/+viewonly]");
5092   printoption("[-visual type]");
5093+#ifdef VS_ADJUST
5094+  printoption("[-/+vsadjust]");
5095+#endif
5096   printoption("[-/+vsdisable]");
5097   printoption("[-vsgeometry geom]");
5098   printoption("[-/+vsmap]");
5099   printoption("[-/+vsperfect]");
5100-  printoption("[-wait seconds]");
5101+  printoption("[-wait secs[,final_secs]]");
5102   printoption("[-white color]");
5103+  printoption("[-windowid windowid]");
5104   printoption("[-/+wloop]");
5105   printoption("[filename ...]");
5106   fprintf(stderr,"\n\n");
5107@@ -1656,7 +2020,7 @@
5108 /***********************************/
5109 static void rmodeSyntax()
5110 {
5111-  fprintf(stderr,"%s: unknown root mode '%d'.  Valid modes are:\n",
5112+  fprintf(stderr,"%s: unknown root mode '%d'.  Valid modes are:\n",
5113 	  cmd, rootMode);
5114   fprintf(stderr,"\t0: tiling\n");
5115   fprintf(stderr,"\t1: integer tiling\n");
5116@@ -1668,6 +2032,7 @@
5117   fprintf(stderr,"\t7: centered on a 'brick' background\n");
5118   fprintf(stderr,"\t8: symmetrical tiling\n");
5119   fprintf(stderr,"\t9: symmetrical mirrored tiling\n");
5120+  fprintf(stderr,"\t10: upper left corner\n");
5121   fprintf(stderr,"\n");
5122   Quit(1);
5123 }
5124@@ -1675,17 +2040,15 @@
5125
5126 /***********************************/
5127 static int argcmp(a1, a2, minlen, plusallowed, plusminus)
5128-     char *a1, *a2;
5129+     const char *a1, *a2;
5130      int  minlen, plusallowed;
5131      int *plusminus;
5132 {
5133-  /* does a string compare between a1 and a2.  To return '0', a1 and a2
5134-     must match to the length of a2, and that length has to
5135+  /* does a string compare between a1 and a2.  To return '0', a1 and a2
5136+     must match to the length of a1, and that length has to
5137      be at least 'minlen'.  Otherwise, return non-zero.  plusminus set to '1'
5138      if '-option', '0' if '+option' */
5139
5140-  int i;
5141-
5142   if ((strlen(a1) < (size_t) minlen) || (strlen(a2) < (size_t) minlen))
5143     return 1;
5144   if (strlen(a1) > strlen(a2)) return 1;
5145@@ -1694,7 +2057,7 @@
5146
5147   if (a1[0]=='-' || (plusallowed && a1[0]=='+')) {
5148     /* only set if we match */
5149-    *plusminus = (a1[0] == '-');
5150+    *plusminus = (a1[0] == '-');
5151     return 0;
5152   }
5153
5154@@ -1721,8 +2084,11 @@
5155   int   oldCXOFF, oldCYOFF, oldCWIDE, oldCHIGH, wascropped;
5156   char *tmp;
5157   char *fullname,       /* full name of the original file */
5158-        filename[512],  /* full name of file to load (could be /tmp/xxx)*/
5159-        globnm[512];    /* globbed version of fullname of orig file */
5160+        filename[512];  /* full name of file to load (could be /tmp/xxx)*/
5161+#ifdef MACBINARY
5162+  char origname[512];	/* file name of original file (NO processing) */
5163+  origname[0] = '\0';
5164+#endif
5165
5166   xvbzero((char *) &pinfo, sizeof(PICINFO));
5167
5168@@ -1748,7 +2114,7 @@
5169
5170   /* if we're not loading next or prev page in a multi-page doc, kill off
5171      page files */
5172-  if (strlen(pageBaseName) && filenum!=OP_PAGEDN && filenum!=OP_PAGEUP)
5173+  if (strlen(pageBaseName) && filenum!=OP_PAGEDN && filenum!=OP_PAGEUP)
5174     killpage = 1;
5175
5176
5177@@ -1799,14 +2165,13 @@
5178   }
5179
5180   else if (filenum == PADDED) {
5181-    /* need fullfname (used for window/icon name),
5182+    /* need fullfname (used for window/icon name),
5183        basefname(compute from fullfname) */
5184
5185     i = LoadPad(&pinfo, fullfname);
5186     fullname = fullfname;
5187     strcpy(filename, fullfname);
5188-    tmp = BaseName(fullfname);
5189-    strcpy(basefname, tmp);
5190+    strcpy(basefname, BaseName(fullfname));
5191
5192     if (!i) goto FAILED;   /* shouldn't happen */
5193
5194@@ -1855,33 +2220,48 @@
5195       frompipe = 1;
5196     }
5197   }
5198+#ifdef AUTO_EXPAND
5199+  else {
5200+    fullname = (char *) malloc(MAXPATHLEN+2);
5201+    strcpy(fullname, namelist[filenum]);   // 1 of 2 places fullname != const
5202+    freename = 1;
5203+  }
5204+  tmp = (char *) rindex(fullname, '/');
5205+  if (tmp) {
5206+    *tmp = '\0';			   // 2 of 2 places fullname != const
5207+    Mkvdir(fullname);
5208+    *tmp = '/';
5209+  }
5210+  Dirtovd(fullname);
5211+#else
5212   else fullname = namelist[filenum];
5213-
5214+#endif
5215
5216   strcpy(fullfname, fullname);
5217-  tmp = BaseName(fullname);
5218-  strcpy(basefname, tmp);
5219+  strcpy(basefname, BaseName(fullname));
5220
5221
5222   /* chop off trailing ".Z", ".z", or ".gz" from displayed basefname, if any */
5223-  if (strlen(basefname) > (size_t) 2     &&
5224-      strcmp(basefname+strlen(basefname)-2,".Z")==0)
5225+  if (strlen(basefname)>2 && strcmp(basefname+strlen(basefname)-2,".Z")==0)
5226     basefname[strlen(basefname)-2]='\0';
5227   else {
5228 #ifdef GUNZIP
5229-    if (strlen(basefname)>2 && strcmp(basefname+strlen(basefname)-2,".Z")==0)
5230+    if (strlen(basefname)>2 && strcmp(basefname+strlen(basefname)-2,".z")==0)
5231       basefname[strlen(basefname)-2]='\0';
5232-
5233-    else if (strlen(basefname)>3 &&
5234-	     strcmp(basefname+strlen(basefname)-3,".gz")==0)
5235+    else
5236+    if (strlen(basefname)>3 && strcmp(basefname+strlen(basefname)-3,".gz")==0)
5237       basefname[strlen(basefname)-3]='\0';
5238-#endif /* GUNZIP */
5239+#endif
5240+#ifdef BUNZIP2
5241+    if (strlen(basefname)>4 && strcmp(basefname+strlen(basefname)-4,".bz2")==0)
5242+      basefname[strlen(basefname)-4]='\0';
5243+#endif
5244   }
5245
5246
5247   if (filenum == LOADPIC && ISPIPE(fullname[0])) {
5248     /* if we're reading from a pipe, 'filename' will have the /tmp/xvXXXXXX
5249-       filename, and we can skip a lot of stuff:  (such as prepending
5250+       filename, and we can skip a lot of stuff:  (such as prepending
5251        'initdir' to relative paths, dealing with reading from stdin, etc. */
5252
5253     /* at this point, fullname = "! do some commands",
5254@@ -1891,11 +2271,11 @@
5255
5256   else {  /* NOT reading from a PIPE */
5257
5258-    /* if fullname doesn't start with a '/' (ie, it's a relative path),
5259-       (and it's not LOADPIC and it's not the special case '<stdin>')
5260+    /* if fullname doesn't start with a '/' (ie, it's a relative path),
5261+       (and it's not LOADPIC and it's not the special case '<stdin>')
5262        then we need to prepend a directory name to it:
5263-
5264-       prepend 'initdir',
5265+
5266+       prepend 'initdir',
5267        if we have a searchdir (ie, we have multiple places to look),
5268              see if such a file exists (via fopen()),
5269        if it does, we're done.
5270@@ -1904,7 +2284,7 @@
5271        if it does, we're done.
5272        if it doesn't, remove all prepended directories, and fall through
5273              to error code below.  */
5274-
5275+
5276     if (filenum!=LOADPIC && fullname[0]!='/' && strcmp(fullname,STDINSTR)!=0) {
5277       char *tmp1;
5278
5279@@ -1954,28 +2334,40 @@
5280 	}
5281       }
5282     }
5283-
5284+
5285     strcpy(filename, fullname);
5286-
5287-
5288+
5289+
5290     /* if the file is STDIN, write it out to a temp file */
5291
5292     if (strcmp(filename,STDINSTR)==0) {
5293-      FILE *fp;
5294+      FILE *fp = NULL;
5295+#ifndef USE_MKSTEMP
5296+      int tmpfd;
5297+#endif
5298
5299-#ifndef VMS
5300+#ifndef VMS
5301       sprintf(filename,"%s/xvXXXXXX",tmpdir);
5302 #else /* it is VMS */
5303       sprintf(filename, "[]xvXXXXXX");
5304 #endif
5305+
5306+#ifdef USE_MKSTEMP
5307+      fp = fdopen(mkstemp(filename), "w");
5308+#else
5309       mktemp(filename);
5310+      tmpfd = open(filename,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
5311+      if (tmpfd < 0) FatalError("openPic(): can't create temporary file");
5312+      fp = fdopen(tmpfd,"w");
5313+#endif
5314+      if (!fp) FatalError("openPic(): can't write temporary file");
5315
5316       clearerr(stdin);
5317-      fp = fopen(filename,"w");
5318-      if (!fp) FatalError("openPic(): can't write temporary file");
5319-
5320       while ( (i=getchar()) != EOF) putc(i,fp);
5321       fclose(fp);
5322+#ifndef USE_MKSTEMP
5323+      close(tmpfd);
5324+#endif
5325
5326       /* and remove it from list, since we can never reload from stdin */
5327       if (strcmp(namelist[0], STDINSTR)==0) deleteFromList(0);
5328@@ -1990,20 +2382,26 @@
5329     (no pipes or stdin, though it could be compressed) to be loaded */
5330   filetype = ReadFileType(filename);
5331
5332+#ifdef HAVE_MGCSFX
5333+  if (mgcsfx && filetype == RFT_UNKNOWN){ /* force use MgcSfx */
5334+    if(getInputCom() != 0) filetype = RFT_MGCSFX;
5335+  }
5336+#endif
5337
5338-  if (filetype == RFT_COMPRESS) {   /* a compressed file.  uncompress it */
5339+  /* if it's a compressed file, uncompress it: */
5340+  if ((filetype == RFT_COMPRESS) || (filetype == RFT_BZIP2)) {
5341     char tmpname[128];
5342
5343     if (
5344 #ifndef VMS
5345-	UncompressFile(filename, tmpname)
5346+	UncompressFile(filename, tmpname, filetype)
5347 #else
5348-	UncompressFile(basefname, tmpname)
5349+	UncompressFile(basefname, tmpname, filetype)
5350 #endif
5351 	) {
5352
5353       filetype = ReadFileType(tmpname);    /* and try again */
5354-
5355+
5356       /* if we made a /tmp file (from stdin, etc.) won't need it any more */
5357       if (strcmp(fullname,filename)!=0) unlink(filename);
5358
5359@@ -2013,7 +2411,58 @@
5360
5361     WaitCursor();
5362   }
5363-
5364+
5365+#ifdef MACBINARY
5366+  if (handlemacb && macb_file == True) {
5367+    char tmpname[128];
5368+
5369+    if (RemoveMacbinary(filename, tmpname)) {
5370+      if (strcmp(fullname,filename)!=0) unlink(filename);
5371+      strcpy(origname, filename);
5372+      strcpy(filename, tmpname);
5373+    }
5374+    else filetype = RFT_ERROR;
5375+
5376+    WaitCursor();
5377+  }
5378+#endif
5379+
5380+#ifdef HAVE_MGCSFX_AUTO
5381+  if (filetype == RFT_MGCSFX) {
5382+      char tmpname[128], tmp[256];
5383+      char *icom;
5384+
5385+      if ((icom = mgcsfx_auto_input_com(filename)) != NULL) {
5386+	sprintf(tmpname, "%s/xvmsautoXXXXXX", tmpdir);
5387+#ifdef USE_MKSTEMP
5388+	close(mkstemp(tmpname));
5389+#else
5390+	mktemp(tmpname);
5391+#endif
5392+	SetISTR(ISTR_INFO, "Converting to known format by MgcSfx auto...");
5393+	sprintf(tmp,"%s >%s", icom, tmpname);
5394+      }
5395+      else goto ms_auto_no;
5396+
5397+#ifndef VMS
5398+      if (system(tmp))
5399+#else
5400+      if (!system(tmp))
5401+#endif
5402+      {
5403+	SetISTR(ISTR_INFO, "Unable to convert '%s' by MgcSfx auto.",
5404+	  BaseName(filename));
5405+	Warning();
5406+	filetype = RFT_ERROR;
5407+	goto ms_auto_no;
5408+      }
5409+
5410+      filetype = ReadFileType(tmpname);
5411+      if (strcmp(fullname,filename)!=0) unlink(filename);
5412+      strcpy(filename, tmpname);
5413+  }
5414+ms_auto_no:
5415+#endif /* HAVE_MGCSFX_AUTO */
5416
5417   if (filetype == RFT_ERROR) {
5418     char  foostr[512];
5419@@ -2027,10 +2476,16 @@
5420
5421   if (filetype == RFT_UNKNOWN) {
5422     /* view as a text/hex file */
5423-    TextView(filename);
5424+#ifdef MACBINARY
5425+    if (origname[0])
5426+      i = TextView(origname);
5427+    else
5428+#endif
5429+      i = TextView(filename);
5430     SetISTR(ISTR_INFO,"'%s' not in a recognized format.", basefname);
5431     /* Warning();  */
5432-    goto SHOWN_AS_TEXT;
5433+    if (i) goto SHOWN_AS_TEXT;
5434+    else   goto FAILED;
5435   }
5436
5437   if (filetype < RFT_ERROR) {
5438@@ -2058,8 +2513,9 @@
5439   if (filetype == RFT_XBM && (!i || pinfo.w==0 || pinfo.h==0)) {
5440     /* probably just a '.h' file or something... */
5441     SetISTR(ISTR_INFO," ");
5442-    TextView(filename);
5443-    goto SHOWN_AS_TEXT;
5444+    i = TextView(filename);
5445+    if (i) goto SHOWN_AS_TEXT;
5446+    else   goto FAILED;
5447   }
5448
5449   if (!i) {
5450@@ -2084,7 +2540,7 @@
5451   /**************/
5452   /* SUCCESS!!! */
5453   /**************/
5454-
5455+
5456
5457  GOTIMAGE:
5458   /* successfully read this picture.  No failures from here on out
5459@@ -2097,7 +2553,7 @@
5460   if (conv24MB.flags[CONV24_LOCK]) {  /* locked */
5461     if (pinfo.type==PIC24 && picType==PIC8) {           /* 24 -> 8 bit */
5462       byte *pic8;
5463-      pic8 = Conv24to8(pinfo.pic, pinfo.w, pinfo.h, ncols,
5464+      pic8 = Conv24to8(pinfo.pic, pinfo.w, pinfo.h, ncols,
5465 		       pinfo.r, pinfo.g, pinfo.b);
5466       free(pinfo.pic);
5467       pinfo.pic = pic8;
5468@@ -2108,7 +2564,7 @@
5469
5470     else if (pinfo.type!=PIC24 && picType==PIC24) {    /* 8 -> 24 bit */
5471       byte *pic24;
5472-      pic24 = Conv8to24(pinfo.pic, pinfo.w, pinfo.h,
5473+      pic24 = Conv8to24(pinfo.pic, pinfo.w, pinfo.h,
5474 			pinfo.r, pinfo.g, pinfo.b);
5475       free(pinfo.pic);
5476       pinfo.pic  = pic24;
5477@@ -2144,7 +2600,7 @@
5478
5479   if (mainW && !useroot) {
5480     /* avoid generating excess configure events while we resize the window */
5481-    XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
5482+    XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
5483 		 | StructureNotifyMask
5484                  | ButtonPressMask | KeyReleaseMask
5485                  | EnterWindowMask | LeaveWindowMask);
5486@@ -2162,11 +2618,13 @@
5487   pHIGH = pinfo.h;
5488   if (pinfo.frmType >=0) SetDirSaveMode(F_FORMAT, pinfo.frmType);
5489   if (pinfo.colType >=0) SetDirSaveMode(F_COLORS, pinfo.colType);
5490-
5491+
5492   SetISTR(ISTR_FORMAT, pinfo.fullInfo);
5493   strcpy(formatStr, pinfo.shrtInfo);
5494   picComments = pinfo.comment;
5495   ChangeCommentText();
5496+  picExifInfo = pinfo.exifInfo;
5497+  picExifInfoSize = pinfo.exifInfoSize;
5498
5499   for (i=0; i<256; i++) {
5500     rMap[i] = pinfo.r[i];
5501@@ -2194,12 +2652,15 @@
5502   if (fullname && strcmp(fullname,filename)!=0) unlink(filename);
5503
5504
5505-  SetISTR(ISTR_INFO,formatStr);
5506-
5507+  SetISTR(ISTR_INFO, "%s", formatStr);
5508+
5509   SetInfoMode(INF_PART);
5510-  SetISTR(ISTR_FILENAME,
5511-	  (filenum==DFLTPIC || filenum==GRABBED || frompipe)
5512-	  ? "<none>" : basefname);
5513+  if (filenum==DFLTPIC || filenum==GRABBED || frompipe)
5514+    SetISTR(ISTR_FILENAME, "<none>");
5515+  else if (numPages > 1)
5516+    SetISTR(ISTR_FILENAME, "%s  Page %d of %d", basefname, curPage+1, numPages);
5517+  else
5518+    SetISTR(ISTR_FILENAME, "%s", basefname);
5519
5520   SetISTR(ISTR_RES,"%d x %d",pWIDE,pHIGH);
5521   SetISTR(ISTR_COLOR, "");
5522@@ -2219,7 +2680,7 @@
5523
5524
5525   /* handle various 'auto-whatever' command line options
5526-     Note that if 'frompoll' is set, things that have to do with
5527+     Note that if 'frompoll' is set, things that have to do with
5528      setting the expansion factor are skipped, as we'll want it to
5529      display in the (already-existing) window at the same size */
5530
5531@@ -2254,7 +2715,7 @@
5532       w = eWIDE;  h = (w*3) / 4;
5533       eWIDE = w;  eHIGH = h;
5534     }
5535-
5536+
5537
5538     if (eWIDE != cWIDE || eHIGH != cHIGH) epic = (byte *) NULL;
5539
5540@@ -2306,14 +2767,14 @@
5541     aspWIDE = eWIDE;  aspHIGH = eHIGH;   /* aspect-corrected eWIDE,eHIGH */
5542
5543     if (hexpand < 0.0) eWIDE=(int)(aspWIDE / -hexpand);  /* neg:  reciprocal */
5544-                  else eWIDE=(int)(aspWIDE *  hexpand);
5545+                  else eWIDE=(int)(aspWIDE *  hexpand);
5546     if (vexpand < 0.0) eHIGH=(int)(aspHIGH / -vexpand);  /* neg:  reciprocal */
5547-                  else eHIGH=(int)(aspHIGH *  vexpand);
5548+                  else eHIGH=(int)(aspHIGH *  vexpand);
5549
5550     if (maingeom) {
5551       /* deal with geometry spec.  Note, they shouldn't have given us
5552        *both* an expansion factor and a geomsize.  The geomsize wins out */
5553-
5554+
5555       int i,x,y,gewide,gehigh;  u_int w,h;
5556
5557       gewide = eWIDE;  gehigh = eHIGH;
5558@@ -2321,11 +2782,11 @@
5559
5560       if (i&WidthValue)  gewide = (int) w;
5561       if (i&HeightValue) gehigh = (int) h;
5562-
5563+
5564       /* handle case where the pinheads only specified width *or * height */
5565       if (( i&WidthValue && ~i&HeightValue) ||
5566 	  (~i&WidthValue &&  i&HeightValue)) {
5567-
5568+
5569 	if (i&WidthValue) { gehigh = (aspHIGH * gewide) / pWIDE; }
5570 	             else { gewide = (aspWIDE * gehigh) / pHIGH; }
5571       }
5572@@ -2391,7 +2852,7 @@
5573
5574     /* if we're using an integer tiled root mode, truncate eWIDE/eHIGH to
5575        be an integer divisor of the display size */
5576-
5577+
5578     if (useroot && (rootMode == RM_TILE || rootMode == RM_IMIRROR)) {
5579       /* make picture size a divisor of the rootW size.  round down */
5580       i = (dispWIDE + eWIDE-1) / eWIDE;   eWIDE = (dispWIDE + i-1) / i;
5581@@ -2409,7 +2870,7 @@
5582     if (autodither && ncols>0) epicMode = EM_DITH;
5583
5584     /* if in CM_STDCMAP mode, and *not* in '-wait 0', then autodither */
5585-    if (colorMapMode == CM_STDCMAP && waitsec != 0) epicMode = EM_DITH;
5586+    if (colorMapMode == CM_STDCMAP && waitsec != 0.0) epicMode = EM_DITH;
5587
5588     /* if -smooth or image has been shrunk to fit screen */
5589     if (autosmooth || (pWIDE >maxWIDE || pHIGH>maxHIGH)
5590@@ -2419,7 +2880,7 @@
5591
5592     /* 'dithering' makes no sense in 24-bit mode */
5593     if (picType == PIC24 && epicMode == EM_DITH) epicMode = EM_RAW;
5594-
5595+
5596     SetEpicMode();
5597   } /* end of !frompoll */
5598
5599@@ -2450,7 +2911,7 @@
5600   if (useroot) mainW = vrootW;
5601   if (eWIDE != cWIDE || eHIGH != cHIGH) epic = (byte *) NULL;
5602
5603-  NewPicGetColors(autonorm, autohisteq);
5604+  NewPicGetColors(autonorm, autohisteq);
5605
5606   GenerateEpic(eWIDE, eHIGH);     /* want to dither *after* color allocs */
5607   CreateXImage();
5608@@ -2474,7 +2935,7 @@
5609   SetISTR(ISTR_INFO,"%s  %s  %s", formatStr,
5610 	  (picType==PIC8) ? "8-bit mode." : "24-bit mode.",
5611 	  tmp);
5612-
5613+
5614   SetInfoMode(INF_FULL);
5615   if (freename) free(fullname);
5616
5617@@ -2495,20 +2956,24 @@
5618      to generate the correct exposes (particularly with 'BitGravity' turned
5619      on */
5620
5621-  if (mainW && !useroot) GenExpose(mainW, 0, 0, (u_int) eWIDE, (u_int) eHIGH);
5622+  /*Brian T. Schellenberger: fix for X 4.2 refresh problem*/
5623+  if (mainW && !useroot) {
5624+    XSync(theDisp, False);
5625+    GenExpose(mainW, 0, 0, (u_int) eWIDE, (u_int) eHIGH);
5626+  }
5627
5628   return 1;
5629
5630-
5631+
5632  FAILED:
5633   SetCursors(-1);
5634   KillPageFiles(pinfo.pagebname, pinfo.numpages);
5635
5636-  if (fullname && strcmp(fullname,filename)!=0)
5637+  if (fullname && strcmp(fullname,filename)!=0)
5638     unlink(filename);   /* kill /tmp file */
5639   if (freename) free(fullname);
5640
5641-  if (!fromint && !polling && filenum>=0 && filenum<nList.nstr)
5642+  if (!fromint && !polling && filenum>=0 && filenum<nList.nstr)
5643     deleteFromList(filenum);
5644
5645   if (polling) sleep(1);
5646@@ -2527,6 +2992,9 @@
5647 }
5648
5649
5650+extern byte ZXheader[128];	/* [JCE] Spectrum screen magic number is
5651+                                  defined in xvzx.c */
5652+
5653
5654 /********************************/
5655 int ReadFileType(fname)
5656@@ -2539,76 +3007,118 @@
5657
5658   FILE *fp;
5659   byte  magicno[30];    /* first 30 bytes of file */
5660-  int   rv, n;
5661+  int   rv=RFT_UNKNOWN, n;
5662+#ifdef MACBINARY
5663+  int   macbin_alrchk = False;
5664+#endif
5665
5666   if (!fname) return RFT_ERROR;   /* shouldn't happen */
5667
5668   fp = xv_fopen(fname, "r");
5669   if (!fp) return RFT_ERROR;
5670
5671-  n = fread(magicno, (size_t) 1, (size_t) 30, fp);
5672+  if (strlen(fname) > 4 &&
5673+      strcasecmp(fname+strlen(fname)-5, ".wbmp")==0)          rv = RFT_WBMP;
5674+
5675+  n = fread(magicno, (size_t) 1, sizeof(magicno), fp);
5676   fclose(fp);
5677
5678-  if (n<30) return RFT_UNKNOWN;    /* files less than 30 bytes long... */
5679+  if (n<=0) return RFT_UNKNOWN;
5680+
5681+  /* it is just barely possible that a few files could legitimately be as small
5682+     as 30 bytes (e.g., binary P{B,G,P}M format), so zero out rest of "magic
5683+     number" buffer and don't quit immediately if we read something small but
5684+     not empty */
5685+  if (n<30) memset(magicno+n, 0, sizeof(magicno)-n);
5686
5687-  rv = RFT_UNKNOWN;
5688+#ifdef MACBINARY
5689+  macb_file = False;
5690+  while (1) {
5691+#endif
5692
5693-  if (strncmp((char *) magicno,"GIF87a", (size_t) 6)==0 ||
5694-      strncmp((char *) magicno,"GIF89a", (size_t) 6)==0)        rv = RFT_GIF;
5695+#ifdef HAVE_MGCSFX
5696+  if (is_mgcsfx(fname, magicno, 30) != 0) rv = RFT_MGCSFX;
5697+  else
5698+#endif
5699+       if (strncmp((char *) magicno,"GIF87a", (size_t) 6)==0 ||
5700+	   strncmp((char *) magicno,"GIF89a", (size_t) 6)==0) rv = RFT_GIF;
5701
5702   else if (strncmp((char *) magicno,"VIEW", (size_t) 4)==0 ||
5703-	   strncmp((char *) magicno,"WEIV", (size_t) 4)==0)     rv = RFT_PM;
5704+	   strncmp((char *) magicno,"WEIV", (size_t) 4)==0)   rv = RFT_PM;
5705+
5706+#ifdef HAVE_PIC2
5707+  else if (magicno[0]=='P' && magicno[1]=='2' &&
5708+	   magicno[2]=='D' && magicno[3]=='T')                rv = RFT_PIC2;
5709+#endif
5710
5711-  else if (magicno[0] == 'P' && magicno[1]>='1' &&
5712-	   magicno[1]<='6')                             rv = RFT_PBM;
5713+  else if (magicno[0] == 'P' && magicno[1]>='1' &&
5714+	   (magicno[1]<='6' || magicno[1]=='8'))              rv = RFT_PBM;
5715
5716   /* note: have to check XPM before XBM, as first 2 chars are the same */
5717   else if (strncmp((char *) magicno, "/* XPM */", (size_t) 9)==0) rv = RFT_XPM;
5718
5719   else if (strncmp((char *) magicno,"#define", (size_t) 7)==0 ||
5720-	   (magicno[0] == '/' && magicno[1] == '*'))    rv = RFT_XBM;
5721+	   (magicno[0] == '/' && magicno[1] == '*'))          rv = RFT_XBM;
5722
5723   else if (magicno[0]==0x59 && (magicno[1]&0x7f)==0x26 &&
5724-	   magicno[2]==0x6a && (magicno[3]&0x7f)==0x15) rv = RFT_SUNRAS;
5725+	   magicno[2]==0x6a && (magicno[3]&0x7f)==0x15)       rv = RFT_SUNRAS;
5726
5727-  else if (magicno[0] == 'B' && magicno[1] == 'M')      rv = RFT_BMP;
5728+  else if (magicno[0] == 'B' && magicno[1] == 'M')            rv = RFT_BMP;
5729
5730-  else if (magicno[0]==0x52 && magicno[1]==0xcc)        rv = RFT_UTAHRLE;
5731+  else if (magicno[0]==0x52 && magicno[1]==0xcc)              rv = RFT_UTAHRLE;
5732
5733   else if ((magicno[0]==0x01 && magicno[1]==0xda) ||
5734-	   (magicno[0]==0xda && magicno[1]==0x01))      rv = RFT_IRIS;
5735+	   (magicno[0]==0xda && magicno[1]==0x01))            rv = RFT_IRIS;
5736
5737-  else if (magicno[0]==0x1f && magicno[1]==0x9d)        rv = RFT_COMPRESS;
5738+  else if (magicno[0]==0x1f && magicno[1]==0x9d)              rv = RFT_COMPRESS;
5739
5740 #ifdef GUNZIP
5741-  else if (magicno[0]==0x1f && magicno[1]==0x8b)        rv = RFT_COMPRESS;
5742+  else if (magicno[0]==0x1f && magicno[1]==0x8b)              rv = RFT_COMPRESS;
5743+#endif
5744+
5745+#ifdef BUNZIP2
5746+  else if (magicno[0]==0x42 && magicno[1]==0x5a)              rv = RFT_BZIP2;
5747 #endif
5748
5749-  else if (magicno[0]==0x0a && magicno[1] <= 5)         rv = RFT_PCX;
5750+  else if (magicno[0]==0x0a && magicno[1] <= 5)               rv = RFT_PCX;
5751
5752-  else if (strncmp((char *) magicno,   "FORM", (size_t) 4)==0 &&
5753-	   strncmp((char *) magicno+8, "ILBM", (size_t) 4)==0)   rv = RFT_IFF;
5754+  else if (strncmp((char *) magicno,   "FORM", (size_t) 4)==0 &&
5755+	   strncmp((char *) magicno+8, "ILBM", (size_t) 4)==0) rv = RFT_IFF;
5756
5757   else if (magicno[0]==0 && magicno[1]==0 &&
5758 	   magicno[2]==2 && magicno[3]==0 &&
5759 	   magicno[4]==0 && magicno[5]==0 &&
5760-	   magicno[6]==0 && magicno[7]==0)              rv = RFT_TARGA;
5761+	   magicno[6]==0 && magicno[7]==0)                    rv = RFT_TARGA;
5762
5763   else if (magicno[4]==0x00 && magicno[5]==0x00 &&
5764-	   magicno[6]==0x00 && magicno[7]==0x07)        rv = RFT_XWD;
5765+	   magicno[6]==0x00 && magicno[7]==0x07)              rv = RFT_XWD;
5766
5767-  else if (strncmp((char *) magicno,"SIMPLE  ", (size_t) 8)==0 &&
5768-	   magicno[29] == 'T')                          rv = RFT_FITS;
5769-
5770+  else if (strncmp((char *) magicno,"SIMPLE  ", (size_t) 8)==0 &&
5771+	   magicno[29] == 'T')                                rv = RFT_FITS;
5772+
5773+  /* [JCE] Spectrum screen */
5774+  else if (memcmp(magicno, ZXheader, (size_t) 18)==0)         rv = RFT_ZX;
5775
5776 #ifdef HAVE_JPEG
5777-  else if (magicno[0]==0xff && magicno[1]==0xd8 &&
5778-	   magicno[2]==0xff)                            rv = RFT_JFIF;
5779+  else if (magicno[0]==0xff && magicno[1]==0xd8 &&
5780+	   magicno[2]==0xff)                                  rv = RFT_JFIF;
5781+#endif
5782+
5783+#ifdef HAVE_JP2K
5784+  else if (magicno[0]==0xff && magicno[1]==0x4f &&
5785+           magicno[2]==0xff && magicno[3]==0x51)              rv = RFT_JPC;
5786+
5787+  else if (memcmp(magicno, jp2k_magic, sizeof(jp2k_magic))==0) rv = RFT_JP2;
5788 #endif
5789
5790 #ifdef HAVE_TIFF
5791   else if ((magicno[0]=='M' && magicno[1]=='M') ||
5792-	   (magicno[0]=='I' && magicno[1]=='I'))        rv = RFT_TIFF;
5793+	   (magicno[0]=='I' && magicno[1]=='I'))              rv = RFT_TIFF;
5794+#endif
5795+
5796+#ifdef HAVE_PNG
5797+  else if (magicno[0]==0x89 && magicno[1]=='P' &&
5798+           magicno[2]=='N'  && magicno[3]=='G')               rv = RFT_PNG;
5799 #endif
5800
5801 #ifdef HAVE_PDS
5802@@ -2620,11 +3130,67 @@
5803       rv = RFT_PDSVICAR;
5804 #endif
5805
5806-#ifdef GS_PATH
5807+#ifdef GS_PATH   /* Ghostscript handles both PostScript and PDF */
5808   else if (strncmp((char *) magicno, "%!",     (size_t) 2)==0 ||
5809-	   strncmp((char *) magicno, "\004%!", (size_t) 3)==0)   rv = RFT_PS;
5810+	   strncmp((char *) magicno, "\004%!", (size_t) 3)==0 ||
5811+           strncmp((char *) magicno, "%PDF",   (size_t) 4)==0) rv = RFT_PS;
5812+#endif
5813+
5814+#ifdef HAVE_G3
5815+  else if ((magicno[0]==  1 && magicno[1]==  1 &&
5816+            magicno[2]== 77 && magicno[3]==154 &&
5817+            magicno[4]==128 && magicno[5]==  0 &&
5818+            magicno[6]==  1 && magicno[7]== 77)
5819+           || highresfax || fax) /* kludge! */                rv = RFT_G3;
5820+#endif
5821+
5822+#ifdef HAVE_MAG
5823+  else if (strncmp((char *) magicno,"MAKI02  ", (size_t) 8)==0) rv = RFT_MAG;
5824+#endif
5825+
5826+#ifdef HAVE_MAKI
5827+  else if (strncmp((char *) magicno,"MAKI01A ", (size_t) 8)==0 ||
5828+	   strncmp((char *) magicno,"MAKI01B ", (size_t) 8)==0) rv = RFT_MAKI;
5829+#endif
5830+
5831+#ifdef HAVE_PIC
5832+  else if (magicno[0]=='P' && magicno[1]=='I'&&magicno[2]=='C') rv = RFT_PIC;
5833+#endif
5834+
5835+#ifdef HAVE_PI
5836+  else if (magicno[0]=='P' && magicno[1]=='i')                rv = RFT_PI;
5837+#endif
5838+
5839+#ifdef HAVE_HIPS
5840+  else if (strstr((char *) magicno, "./digest"))              rv = RFT_HIPS;
5841+#endif
5842+
5843+#ifdef HAVE_PCD
5844+  else if (magicno[0]==0xff && magicno[1]==0xff &&
5845+           magicno[2]==0xff && magicno[3]==0xff)              rv = RFT_PCD;
5846 #endif
5847
5848+#ifdef MACBINARY
5849+    /* Now we try to handle MacBinary files, but the method is VERY dirty... */
5850+    if (macbin_alrchk == True) {
5851+      macb_file = True;
5852+      break;
5853+    }
5854+
5855+    if (rv != RFT_UNKNOWN)
5856+      break;
5857+
5858+    /* Skip MACBSIZE and recheck */
5859+    macbin_alrchk = True;
5860+    fp = xv_fopen(fname, "r");
5861+    if (!fp) return RFT_ERROR;
5862+    fseek(fp, MACBSIZE, SEEK_SET);
5863+    n = fread(magicno, (size_t) 1, (size_t) 30, fp);
5864+    fclose(fp);
5865+
5866+    if (n<30) return RFT_UNKNOWN;    /* files less than 30 bytes long... */
5867+  }
5868+#endif
5869   return rv;
5870 }
5871
5872@@ -2637,9 +3203,10 @@
5873      PICINFO *pinfo;
5874 {
5875   /* if quick is set, we're being called to generate icons, or something
5876-     like that.  We should load the image as quickly as possible.  Currently,
5877-     this only affects the LoadPS routine, which, if quick is set, only
5878-     generates the page file for the first page of the document */
5879+     like that.  We should load the image as quickly as possible.  Previously,
5880+     this affected only the LoadPS routine, which, if quick is set, only
5881+     generates the page file for the first page of the document.  Now it
5882+     also affects PCD, which loads only a thumbnail. */
5883
5884   int rv = 0;
5885
5886@@ -2650,7 +3217,11 @@
5887   switch (ftype) {
5888   case RFT_GIF:     rv = LoadGIF   (fname, pinfo);         break;
5889   case RFT_PM:      rv = LoadPM    (fname, pinfo);         break;
5890+#ifdef HAVE_MGCSFX
5891+  case RFT_PBM:     rv = LoadPBM   (fname, pinfo, -1);     break;
5892+#else
5893   case RFT_PBM:     rv = LoadPBM   (fname, pinfo);         break;
5894+#endif
5895   case RFT_XBM:     rv = LoadXBM   (fname, pinfo);         break;
5896   case RFT_SUNRAS:  rv = LoadSunRas(fname, pinfo);         break;
5897   case RFT_BMP:     rv = LoadBMP   (fname, pinfo);         break;
5898@@ -2662,21 +3233,69 @@
5899   case RFT_XPM:     rv = LoadXPM   (fname, pinfo);         break;
5900   case RFT_XWD:     rv = LoadXWD   (fname, pinfo);         break;
5901   case RFT_FITS:    rv = LoadFITS  (fname, pinfo, quick);  break;
5902+  case RFT_ZX:      rv = LoadZX    (fname, pinfo);         break; /* [JCE] */
5903+  case RFT_WBMP:    rv = LoadWBMP  (fname, pinfo);         break;
5904+
5905+#ifdef HAVE_PCD
5906+  /* if quick is switched on, use the smallest image size; don't ask the user */
5907+  case RFT_PCD:     rv = LoadPCD   (fname, pinfo, quick ? 0 : PcdSize);  break;
5908+#endif
5909
5910 #ifdef HAVE_JPEG
5911-  case RFT_JFIF:    rv = LoadJFIF  (fname, pinfo, quick);    break;
5912+  case RFT_JFIF:    rv = LoadJFIF  (fname, pinfo, quick);  break;
5913+#endif
5914+
5915+#ifdef HAVE_JP2K
5916+  case RFT_JPC:     rv = LoadJPC   (fname, pinfo, quick);  break;
5917+  case RFT_JP2:     rv = LoadJP2   (fname, pinfo, quick);  break;
5918 #endif
5919
5920 #ifdef HAVE_TIFF
5921-  case RFT_TIFF:    rv = LoadTIFF  (fname, pinfo);           break;
5922+  case RFT_TIFF:    rv = LoadTIFF  (fname, pinfo, quick);  break;
5923+#endif
5924+
5925+#ifdef HAVE_PNG
5926+  case RFT_PNG:     rv = LoadPNG   (fname, pinfo);         break;
5927 #endif
5928
5929 #ifdef HAVE_PDS
5930-  case RFT_PDSVICAR: rv = LoadPDS  (fname, pinfo);           break;
5931+  case RFT_PDSVICAR: rv = LoadPDS  (fname, pinfo);         break;
5932+#endif
5933+
5934+#ifdef HAVE_G3
5935+  case RFT_G3:      rv = LoadG3    (fname, pinfo);         break;
5936 #endif
5937
5938 #ifdef GS_PATH
5939-  case RFT_PS:      rv = LoadPS    (fname, pinfo, quick);    break;
5940+  case RFT_PS:      rv = LoadPS    (fname, pinfo, quick);  break;
5941+#endif
5942+
5943+#ifdef HAVE_MAG
5944+  case RFT_MAG:     rv = LoadMAG   (fname, pinfo);         break;
5945+#endif
5946+
5947+#ifdef HAVE_MAKI
5948+  case RFT_MAKI:    rv = LoadMAKI  (fname, pinfo);         break;
5949+#endif
5950+
5951+#ifdef HAVE_PIC
5952+  case RFT_PIC:     rv = LoadPIC   (fname, pinfo);         break;
5953+#endif
5954+
5955+#ifdef HAVE_PI
5956+  case RFT_PI:      rv = LoadPi    (fname, pinfo);         break;
5957+#endif
5958+
5959+#ifdef HAVE_PIC2
5960+  case RFT_PIC2:    rv = LoadPIC2  (fname, pinfo, quick);  break;
5961+#endif
5962+
5963+#ifdef HAVE_HIPS
5964+  case RFT_HIPS:    rv = LoadHIPS  (fname, pinfo);         break;
5965+#endif
5966+
5967+#ifdef HAVE_MGCSFX
5968+  case RFT_MGCSFX:  rv = LoadMGCSFX (fname, pinfo);        break;
5969 #endif
5970
5971   }
5972@@ -2685,13 +3304,17 @@
5973
5974
5975 /********************************/
5976-int UncompressFile(name, uncompname)
5977+int UncompressFile(name, uncompname, filetype)
5978      char *name, *uncompname;
5979+     int filetype;
5980 {
5981   /* returns '1' on success, with name of uncompressed file in uncompname
5982      returns '0' on failure */
5983
5984   char namez[128], *fname, buf[512];
5985+#ifndef USE_MKSTEMP
5986+  int tmpfd;
5987+#endif
5988
5989   fname = name;
5990   namez[0] = '\0';
5991@@ -2703,7 +3326,7 @@
5992      to what it was.  necessary because uncompress doesn't handle files
5993      that don't end with '.Z' */
5994
5995-  if (strlen(name) >= (size_t) 2            &&
5996+  if (strlen(name) >= (size_t) 2            &&
5997       strcmp(name + strlen(name)-2,".Z")!=0 &&
5998       strcmp(name + strlen(name)-2,".z")!=0) {
5999     strcpy(namez, name);
6000@@ -2721,34 +3344,50 @@
6001 #endif   /* not VMS and not GUNZIP */
6002
6003
6004-
6005 #ifndef VMS
6006   sprintf(uncompname, "%s/xvuXXXXXX", tmpdir);
6007-  mktemp(uncompname);
6008-  sprintf(buf,"%s -c %s >%s", UNCOMPRESS, fname, uncompname);
6009-#else /* it IS VMS */
6010+#else
6011   strcpy(uncompname, "[]xvuXXXXXX");
6012+#endif
6013+
6014+#ifdef USE_MKSTEMP
6015+  close(mkstemp(uncompname));
6016+#else
6017   mktemp(uncompname);
6018-#  ifdef GUNZIP
6019-  sprintf(buf,"%s %s %s", UNCOMPRESS, fname, uncompname);
6020-#  else
6021-  sprintf(buf,"%s %s", UNCOMPRESS, fname);
6022-#  endif
6023+  tmpfd = open(uncompname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
6024+  if (tmpfd < 0) FatalError("UncompressFile(): can't create temporary file");
6025+  close(tmpfd);
6026+#endif
6027+
6028+#ifndef VMS
6029+  if (filetype == RFT_COMPRESS)
6030+    sprintf(buf,"%s -c '%s' > '%s'", UNCOMPRESS, fname, uncompname);
6031+# ifdef BUNZIP2
6032+  else if (filetype == RFT_BZIP2)
6033+    sprintf(buf,"%s -c '%s' > '%s'", BUNZIP2, fname, uncompname);
6034+# endif
6035+#else /* it IS VMS */
6036+# ifdef GUNZIP
6037+  sprintf(buf,"%s '%s' '%s'", UNCOMPRESS, fname, uncompname);
6038+# else
6039+  sprintf(buf,"%s '%s'", UNCOMPRESS, fname);
6040+# endif
6041 #endif
6042
6043   SetISTR(ISTR_INFO, "Uncompressing '%s'...", BaseName(fname));
6044 #ifndef VMS
6045-  if (system(buf)) {
6046+  if (system(buf))
6047 #else
6048-  if (!system(buf)) {
6049+  if (!system(buf))
6050 #endif
6051+  {
6052     SetISTR(ISTR_INFO, "Unable to uncompress '%s'.", BaseName(fname));
6053     Warning();
6054     return 0;
6055   }
6056
6057-#ifndef VMS
6058-  /* if we renamed the file to end with a .Z for the sake of 'uncompress',
6059+#ifndef VMS
6060+  /* if we renamed the file to end with a .Z for the sake of 'uncompress',
6061      rename it back to what it once was... */
6062
6063   if (strlen(namez)) {
6064@@ -2769,9 +3408,65 @@
6065     }
6066    */
6067 #endif /* not VMS */
6068-
6069+
6070+  return 1;
6071+}
6072+
6073+
6074+#ifdef MACBINARY
6075+/********************************/
6076+int RemoveMacbinary(src, dst)
6077+     char *src, *dst;
6078+{
6079+  char buffer[8192]; /* XXX */
6080+  int n, eof;
6081+#ifndef USE_MKSTEMP
6082+  int tmpfd;
6083+#endif
6084+  FILE *sfp, *dfp;
6085+
6086+  sprintf(dst, "%s/xvmXXXXXX", tmpdir);
6087+#ifdef USE_MKSTEMP
6088+  close(mkstemp(dst));
6089+#else
6090+  mktemp(dst);
6091+  tmpfd = open(dst,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
6092+  if (tmpfd < 0) FatalError("RemoveMacbinary(): can't create temporary file");
6093+#endif
6094+
6095+  SetISTR(ISTR_INFO, "Removing MacBinary...");
6096+
6097+  sfp = xv_fopen(src, "r");
6098+#ifdef USE_MKSTEMP
6099+  dfp = xv_fopen(dst, "w");
6100+#else
6101+  dfp = fdopen(tmpfd, "w");
6102+#endif
6103+  if (!sfp || !dfp) {
6104+    SetISTR(ISTR_INFO, "Unable to remove a InfoFile header form '%s'.", src);
6105+    Warning();
6106+    return 0;
6107+  }
6108+  fseek(sfp, MACBSIZE, SEEK_SET);
6109+  while ((n = fread(buffer, 1, sizeof(buffer), sfp)) == 8192) /* XXX */
6110+    fwrite(buffer, 1, n, dfp);
6111+  if ((eof = feof(sfp)))
6112+    fwrite(buffer, 1, n, dfp);
6113+  fclose(sfp);
6114+  fflush(dfp);
6115+  fclose(dfp);
6116+#ifndef USE_MKSTEMP
6117+  close(tmpfd);
6118+#endif
6119+  if (!eof) {
6120+    SetISTR(ISTR_INFO, "Unable to remove a InfoFile header form '%s'.", src);
6121+    Warning();
6122+    return 0;
6123+  }
6124+
6125   return 1;
6126 }
6127+#endif
6128
6129
6130 /********************************/
6131@@ -2789,6 +3484,10 @@
6132     sprintf(tmp, "%s%d", bname, i);
6133     unlink(tmp);
6134   }
6135+
6136+  /* GRR 20070506:  basename file doesn't go away, at least on Linux and for
6137+   *   GIF and TIFF images, so explicitly unlink() it, too */
6138+  unlink(bname);
6139 }
6140
6141
6142@@ -2798,11 +3497,11 @@
6143 {
6144   int i;
6145
6146-  /* some stuff that necessary whenever running an algorithm or
6147+  /* some stuff that necessary whenever running an algorithm or
6148      installing a new 'pic' (or switching 824 modes) */
6149
6150   numcols = 0;   /* gets set by SortColormap:  set to 0 for PIC24 images */
6151-  for (i=0; i<256; i++) cols[i]=infobg;
6152+  for (i=0; i<256; i++) cols[i]=infobg;
6153
6154   if (picType == PIC8) {
6155     byte trans[256];
6156@@ -2811,18 +3510,18 @@
6157   }
6158
6159   if (picType == PIC8) {
6160-    /* see if image is a b/w bitmap.
6161+    /* see if image is a b/w bitmap.
6162        If so, use '-black' and '-white' colors */
6163     if (numcols == 2) {
6164       if ((rMap[0] == gMap[0] && rMap[0] == bMap[0] && rMap[0] == 255) &&
6165 	  (rMap[1] == gMap[1] && rMap[1] == bMap[1] && rMap[1] ==   0)) {
6166 	/* 0=wht, 1=blk */
6167-	rMap[0] = (whtRGB>>16)&0xff;
6168-	gMap[0] = (whtRGB>>8)&0xff;
6169+	rMap[0] = (whtRGB>>16)&0xff;
6170+	gMap[0] = (whtRGB>>8)&0xff;
6171 	bMap[0] = whtRGB&0xff;
6172
6173 	rMap[1] = (blkRGB>>16)&0xff;
6174-	gMap[1] = (blkRGB>>8)&0xff;
6175+	gMap[1] = (blkRGB>>8)&0xff;
6176 	bMap[1] = blkRGB&0xff;
6177       }
6178
6179@@ -2852,10 +3551,10 @@
6180     }
6181
6182     /* save the desired RGB colormap (before dicking with it) */
6183-    for (i=0; i<numcols; i++) {
6184-      rorg[i] = rcmap[i] = rMap[i];
6185-      gorg[i] = gcmap[i] = gMap[i];
6186-      borg[i] = bcmap[i] = bMap[i];
6187+    for (i=0; i<numcols; i++) {
6188+      rorg[i] = rcmap[i] = rMap[i];
6189+      gorg[i] = gcmap[i] = gMap[i];
6190+      borg[i] = bcmap[i] = bMap[i];
6191     }
6192   }
6193
6194@@ -2888,19 +3587,29 @@
6195 {
6196   /* cmd is something like: "! bggen 100 0 0"
6197    *
6198-   * runs command (with "> /tmp/xv******" appended).
6199+   * runs command (with "> /tmp/xv******" appended).
6200    * returns "/tmp/xv******" in fname
6201    * returns '0' if everything's cool, '1' on error
6202    */
6203
6204   char fullcmd[512], tmpname[64], str[512];
6205   int i;
6206+#ifndef USE_MKSTEMP
6207+  int tmpfd;
6208+#endif
6209
6210   if (!cmd || (strlen(cmd) < (size_t) 2)) return 1;
6211
6212   sprintf(tmpname,"%s/xvXXXXXX", tmpdir);
6213+#ifdef USE_MKSTEMP
6214+  close(mkstemp(tmpname));
6215+#else
6216   mktemp(tmpname);
6217-  if (tmpname[0] == '\0') {   /* mktemp() blew up */
6218+  tmpfd = open(tmpname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
6219+  if (tmpfd < 0) FatalError("openPic(): can't create temporary file");
6220+  close(tmpfd);
6221+#endif
6222+  if (tmpname[0] == '\0') {   /* mktemp() or mkstemp() blew up */
6223     sprintf(str,"Unable to create temporary filename.");
6224     ErrPopUp(str, "\nHow unlikely!");
6225     return 1;
6226@@ -2939,26 +3648,21 @@
6227 {
6228   int i;
6229
6230+  waitsec = (numnames <= 1)? waitsec_final : waitsec_nonfinal;
6231+
6232   if (!numnames) {  openPic(DFLTPIC);  return; }
6233
6234   i = 0;
6235-  if (!randomShow) {
6236-    while (numnames>0) {
6237-      if (openPic(0)) return;  /* success */
6238-      else {
6239-	if (polling && !i)
6240-	  fprintf(stderr,"%s: POLLING: Waiting for file '%s' \n\tto %s\n",
6241-		  cmd, namelist[0], "be created, or whatever...");
6242-	i = 1;
6243-      }
6244+  while (numnames>0) {
6245+    if (openPic(0)) return;  /* success */
6246+    else {
6247+      if (polling && !i)
6248+	fprintf(stderr,"%s: POLLING: Waiting for file '%s' \n\tto %s\n",
6249+		cmd, namelist[0], "be created, or whatever...");
6250+      i = 1;
6251     }
6252   }
6253
6254-  else {    /* pick random first picture */
6255-    for (i=findRandomPic();  i>=0;  i=findRandomPic())
6256-      if (openPic(i)) return;    /* success */
6257-  }
6258-
6259   if (numnames>1) FatalError("couldn't open any pictures");
6260   else Quit(-1);
6261 }
6262@@ -2970,11 +3674,11 @@
6263   int i;
6264
6265   if (curname>=0) i = curname+1;
6266-  else if (nList.selected >= 0 && nList.selected < numnames)
6267+  else if (nList.selected >= 0 && nList.selected < numnames)
6268        i = nList.selected;
6269   else i = 0;
6270
6271-
6272+
6273   while (i<numnames && !openPic(i));
6274   if (i<numnames) return;    /* success */
6275
6276@@ -2987,19 +3691,15 @@
6277 {
6278   int i;
6279
6280-  if (!randomShow) {
6281-    if (curname>=0) i = curname+1;
6282-    else if (nList.selected >= 0 && nList.selected < numnames)
6283-      i = nList.selected;
6284-    else i = 0;
6285+  if (curname>=0) i = curname+1;
6286+  else if (nList.selected >= 0 && nList.selected < numnames)
6287+    i = nList.selected;
6288+  else i = 0;
6289
6290-    while (i<numnames && !openPic(i));
6291-    if (i<numnames) return;    /* success */
6292-  }
6293-  else {
6294-    for (i=findRandomPic(); i>=0; i=findRandomPic())
6295-      if (openPic(i)) return;
6296-  }
6297+  waitsec = (i == numnames-1)? waitsec_final : waitsec_nonfinal;
6298+
6299+  while (i<numnames && !openPic(i));
6300+  if (i<numnames) return;    /* success */
6301
6302   Quit(0);
6303 }
6304@@ -3012,25 +3712,21 @@
6305
6306   j = loop = 0;
6307   while (1) {
6308-    if (!randomShow) {
6309
6310-      if (curname>=0) i = curname+1;
6311-      else if (nList.selected >= 0 && nList.selected < numnames)
6312-	i = nList.selected;
6313-      else i = 0;
6314+    if (curname>=0) i = curname+1;
6315+    else if (nList.selected >= 0 && nList.selected < numnames)
6316+      i = nList.selected;
6317+    else i = 0;
6318+
6319+    if (loop) {  i = 0;   loop = 0; }
6320
6321-      if (loop) {  i = 0;   loop = 0; }
6322+    waitsec = (i == numnames-1)? waitsec_final : waitsec_nonfinal;
6323
6324-      while (i<numnames && !openPic(i));
6325-      if (i<numnames) return;
6326-    }
6327-    else {
6328-      for (i=findRandomPic(); i>=0; i=findRandomPic())
6329-	if (openPic(i)) return;
6330-    }
6331+    while (i<numnames && !openPic(i));
6332+    if (i<numnames) return;
6333
6334     loop = 1;        /* back to top of list */
6335-    if (j) break;                         /* we're in a 'failure loop' */
6336+    if (j) break;    /* we're in a 'failure loop' */
6337     j++;
6338   }
6339
6340@@ -3044,7 +3740,7 @@
6341   int i;
6342
6343   if (curname>0) i = curname-1;
6344-  else if (nList.selected>0 && nList.selected < numnames)
6345+  else if (nList.selected>0 && nList.selected < numnames)
6346     i = nList.selected - 1;
6347   else i = numnames-1;
6348
6349@@ -3063,64 +3759,24 @@
6350   openPic(LOADPIC);
6351 }
6352
6353-
6354-
6355-
6356-/****************/
6357-static int findRandomPic()
6358-/****************/
6359-{
6360-  static byte *loadList;
6361-  static int   left_to_load, listLen = -1;
6362-  int          k;
6363-  time_t       t;
6364-
6365-  /* picks a random name out of the list, and returns it's index.  If there
6366-     are no more names to pick, it returns '-1' and resets itself */
6367-
6368-  if (!loadList || numnames!=listLen) {
6369-    if (loadList) free(loadList);
6370-    else {
6371-      time(&t);
6372-      srandom((unsigned int) t); /* seed the random */
6373-    }
6374-
6375-    left_to_load = listLen = numnames;
6376-    loadList = (byte *) malloc((size_t) listLen);
6377-    for (k=0; k<listLen; k++) loadList[k] = 0;
6378-  }
6379-
6380-  if (left_to_load <= 0) {   /* we've loaded all the pics */
6381-    for (k=0; k<listLen; k++) loadList[k] = 0;   /* clear flags */
6382-    left_to_load = listLen;
6383-    return -1;   /* 'done' return */
6384-  }
6385-
6386-  for (k=abs(random()) % listLen;  loadList[k];  k = (k+1) % listLen);
6387-
6388-  left_to_load--;
6389-  loadList[k] = TRUE;
6390-
6391-  return k;
6392-}
6393-
6394 /****************/
6395 static void mainLoop()
6396 {
6397-  /* search forward until we manage to display a picture,
6398-     then call EventLoop.  EventLoop will eventually return
6399+  /* search forward until we manage to display a picture,
6400+     then call EventLoop.  EventLoop will eventually return
6401      NEXTPIC, PREVPIC, NEXTQUIT, QUIT, or, if >= 0, a filenum to GOTO */
6402
6403   int i;
6404
6405-  /* if curname<0 (there is no 'current' file), 'Next' means view the
6406+  /* if curname<0 (there is no 'current' file), 'Next' means view the
6407      selected file (or the 0th file, if no selection either), and 'Prev' means
6408      view the one right before the selected file */
6409
6410-  openFirstPic();   /* find first displayable picture, exit if none */
6411+  /* find first displayable picture, exit if none */
6412+  if (!startGrab) openFirstPic();
6413
6414   if (!pic)  {  /* must've opened a text file...  display dflt pic */
6415-    openPic(DFLTPIC);
6416+    if (!startGrab) openPic(DFLTPIC);
6417     if (mainW && !useroot) RaiseTextWindows();
6418   }
6419
6420@@ -3133,7 +3789,7 @@
6421     }
6422
6423     else if (i==PREVPIC) {
6424-      if (curname>0 || (curname<0 && nList.selected>0))
6425+      if (curname>0 || (curname<0 && nList.selected>0))
6426 	openPrevPic();
6427     }
6428
6429@@ -3151,7 +3807,7 @@
6430
6431     else if (i==THISNEXT) {  /* open current sel, 'next' until success */
6432       int j;
6433-      j = nList.selected;
6434+      j = nList.selected;
6435       if (j<0) j = 0;
6436       while (j<numnames && !openPic(j));
6437       if (!pic) openPic(DFLTPIC);
6438@@ -3169,7 +3825,7 @@
6439
6440 /***********************************/
6441 static void createMainWindow(geom, name)
6442-     char *geom, *name;
6443+     const char *geom, *name;
6444 {
6445   XSetWindowAttributes xswa;
6446   unsigned long        xswamask;
6447@@ -3195,22 +3851,35 @@
6448   i = XParseGeometry(geom,&x,&y,&w,&h);
6449
6450   hints.flags = 0;
6451-  if ((i&XValue || i&YValue)) hints.flags = USPosition;
6452+  if (i&XValue || i&YValue)
6453+      hints.flags |= USPosition;
6454
6455-  if (i&XValue && i&XNegative) x = vrWIDE - eWIDE - abs(x);
6456-  if (i&YValue && i&YNegative) y = vrHIGH - eHIGH - abs(y);
6457+  hints.win_gravity = NorthWestGravity;
6458+  if (i&XValue && i&XNegative) {
6459+    hints.win_gravity = NorthEastGravity;
6460+    x = vrWIDE - (eWIDE + 2 * bwidth) - x;
6461+  }
6462+  if (i&YValue && i&YNegative) {
6463+    hints.win_gravity = (hints.win_gravity == NorthWestGravity) ?
6464+      SouthWestGravity : SouthEastGravity;
6465+    y = vrHIGH - (eHIGH + 2 * bwidth) - y;
6466+  }
6467+  hints.flags |= PWinGravity;
6468
6469-  if (x+eWIDE > vrWIDE) x = vrWIDE - eWIDE;   /* keep on screen */
6470+  /* keep on screen */
6471+  if (x+eWIDE > vrWIDE) x = vrWIDE - eWIDE;
6472   if (y+eHIGH > vrHIGH) y = vrHIGH - eHIGH;
6473-
6474+  if (x < 0) x = 0;
6475+  if (y < 0) y = 0;
6476
6477 #define VROOT_TRANS
6478 #ifdef VROOT_TRANS
6479-  if (vrootW != rootW) { /* virtual window manager running */
6480+  if (vrootW != rootW && !(hints.flags & USPosition)) { /* virtual window manager running */
6481     int x1,y1;
6482     Window child;
6483+
6484     XTranslateCoordinates(theDisp, rootW, vrootW, x, y, &x1, &y1, &child);
6485-    if (DEBUG) fprintf(stderr,"translate:  %d,%d -> %d,%d\n",x,y,x1,y1);
6486+    if (DEBUG) fprintf(stderr,"translate:  %d,%d -> %d,%d\n", x, y, x1, y1);
6487     x = x1;  y = y1;
6488   }
6489 #endif
6490@@ -3218,13 +3887,13 @@
6491   hints.x = x;                  hints.y = y;
6492   hints.width = eWIDE;          hints.height = eHIGH;
6493   hints.max_width  = maxWIDE;   hints.max_height = maxHIGH;
6494-  hints.flags |= USSize | PMaxSize;
6495-
6496-  xswa.bit_gravity = StaticGravity;
6497+  hints.flags |= PSize | PMaxSize;
6498+
6499+  xswa.bit_gravity      = StaticGravity;
6500   xswa.background_pixel = bg;
6501   xswa.border_pixel     = fg;
6502   xswa.colormap         = theCmap;
6503-
6504+
6505   xswa.backing_store    = WhenMapped;
6506
6507   /* NOTE: I've turned 'backing-store' off on the image window, as some
6508@@ -3233,9 +3902,9 @@
6509      improvement anyway (for the image window), unless you're on a slow
6510      network.  In any event, I'm not *turning off* backing store, I'm
6511      just not explicitly turning it *on*.  If your X server is set up
6512-     that windows, by default, have backing-store turned on, then the
6513+     that windows, by default, have backing-store turned on, then the
6514      image window will, too */
6515-
6516+
6517   xswamask = CWBackPixel | CWBorderPixel | CWColormap /* | CWBackingStore */;
6518   if (!clearonload) xswamask |= CWBitGravity;
6519
6520@@ -3244,18 +3913,18 @@
6521     xwa.width = eWIDE;  xwa.height = eHIGH;
6522
6523     /* try to keep the damned thing on-screen, if possible */
6524-    if (xwa.x + xwa.width  > dispWIDE) xwa.x = dispWIDE - xwa.width;
6525-    if (xwa.y + xwa.height > dispHIGH) xwa.y = dispHIGH - xwa.height;
6526+    if (xwa.x + xwa.width  > vrWIDE) xwa.x = vrWIDE - xwa.width;
6527+    if (xwa.y + xwa.height > vrHIGH) xwa.y = vrHIGH - xwa.height;
6528     if (xwa.x < 0) xwa.x = 0;
6529     if (xwa.y < 0) xwa.y = 0;
6530
6531     SetWindowPos(&xwa);
6532     hints.flags = PSize | PMaxSize;
6533-  }
6534+  }
6535
6536   else {
6537     mainW = XCreateWindow(theDisp,rootW,x,y, (u_int) eWIDE, (u_int) eHIGH,
6538-			  (u_int) bwidth, (int) dispDEEP, InputOutput,
6539+			  (u_int) bwidth, (int) dispDEEP, InputOutput,
6540 			  theVisual, xswamask, &xswa);
6541     if (!mainW) FatalError("can't create window!");
6542
6543@@ -3267,15 +3936,11 @@
6544     }
6545   }
6546
6547-
6548-  XSetStandardProperties(theDisp,mainW,"","",None,NULL,0,&hints);
6549-  setWinIconNames(name);
6550-
6551   xwmh.input = True;
6552   xwmh.flags = InputHint;
6553
6554-  xwmh.icon_pixmap = iconPix;
6555-  xwmh.icon_mask   = iconmask;
6556+  xwmh.icon_pixmap = iconPix;
6557+  xwmh.icon_mask   = iconmask;
6558   xwmh.flags |= (IconPixmapHint | IconMaskHint);
6559
6560
6561@@ -3295,14 +3960,15 @@
6562       }
6563     }
6564   }
6565-  XSetWMHints(theDisp, mainW, &xwmh);
6566
6567   classh.res_name = "xv";
6568   classh.res_class = "XVroot";
6569-  XSetClassHint(theDisp, mainW, &classh);
6570
6571+  XmbSetWMProperties(theDisp, mainW, NULL, NULL, NULL, 0, &hints, &xwmh,
6572+                     &classh);
6573+  setWinIconNames(name);
6574
6575-  if (nodecor) {   /* turn of image window decorations (in MWM) */
6576+  if (nodecor) {   /* turn of image window decorations (in MWM) */
6577     Atom mwm_wm_hints;
6578     struct s_mwmhints {
6579       long   flags;
6580@@ -3311,7 +3977,7 @@
6581       u_long input_mode;
6582       long   status;
6583     } mwmhints;
6584-
6585+
6586     mwm_wm_hints = XInternAtom(theDisp, "_MOTIF_WM_HINTS", False);
6587     if (mwm_wm_hints != None) {
6588       xvbzero((char *) &mwmhints, sizeof(mwmhints));
6589@@ -3319,20 +3985,20 @@
6590       mwmhints.decorations = 4;
6591
6592       XChangeProperty(theDisp, mainW, mwm_wm_hints, mwm_wm_hints, 32,
6593-		      PropModeReplace, (byte *) &mwmhints,
6594-		      (int) (sizeof(mwmhints))/4);
6595+		      PropModeReplace, (byte *) &mwmhints,
6596+		      (int) (sizeof(mwmhints))/4);
6597       XSync(theDisp, False);
6598     }
6599   }
6600
6601-
6602+
6603   firstTime = 0;
6604 }
6605
6606
6607 /***********************************/
6608 static void setWinIconNames(name)
6609-     char *name;
6610+     const char *name;
6611 {
6612   char winname[256], iconname[256];
6613
6614@@ -3362,12 +4028,12 @@
6615
6616 /***********************************/
6617 void FixAspect(grow,w,h)
6618-int   grow;
6619-int   *w, *h;
6620+     int   grow;
6621+     int   *w, *h;
6622 {
6623   /* computes new values of eWIDE and eHIGH which will have aspect ratio
6624-     'normaspect'.  If 'grow' it will preserve aspect by enlarging,
6625-     otherwise, it will shrink to preserve aspect ratio.
6626+     'normaspect'.  If 'grow' it will preserve aspect by enlarging,
6627+     otherwise, it will shrink to preserve aspect ratio.
6628      Returns these values in 'w' and 'h' */
6629
6630   float xr,yr,curaspect,a,exp;
6631@@ -3380,14 +4046,14 @@
6632   curaspect  = xr / yr;
6633
6634   /* if too narrow & shrink, shrink height.  too wide and grow, grow height */
6635-  if ((curaspect < normaspect && !grow) ||
6636+  if ((curaspect < normaspect && !grow) ||
6637       (curaspect > normaspect &&  grow)) {    /* modify height */
6638     exp = curaspect / normaspect;
6639     *h = (int) (eHIGH * exp + .5);
6640   }
6641
6642   /* if too narrow & grow, grow width.  too wide and shrink, shrink width */
6643-  if ((curaspect < normaspect &&  grow) ||
6644+  if ((curaspect < normaspect &&  grow) ||
6645       (curaspect > normaspect && !grow)) {    /* modify width */
6646     exp = normaspect / curaspect;
6647     *w = (int) (eWIDE * exp + .5);
6648@@ -3423,22 +4089,22 @@
6649   suffix = namelist[0];
6650   prelen = 0;   /* length of prefix to be removed */
6651   n = i = 0;    /* shut up pesky compiler warnings */
6652-
6653+
6654   done = 0;
6655   while (!done) {
6656     suffix = (char *) index(suffix,'/');    /* find next '/' in file name */
6657     if (!suffix) break;
6658-
6659+
6660     suffix++;                       /* go past it */
6661     n = suffix - namelist[0];
6662     for (i=1; i<numnames; i++) {
6663       if (strncmp(namelist[0], namelist[i], (size_t) n)!=0) { done=1; break; }
6664     }
6665-
6666+
6667     if (!done) prelen = n;
6668   }
6669-
6670-  for (i=0; i<numnames; i++)
6671+
6672+  for (i=0; i<numnames; i++)
6673     dispnames[i] = namelist[i] + prelen;
6674 }
6675
6676@@ -3447,20 +4113,20 @@
6677 static void fixDispNames()
6678 {
6679   /* fix dispnames array so that names don't go off right edge */
6680-
6681+
6682   int   i,j;
6683   char *tmp;
6684-
6685+
6686   for (i=j=0; i<numnames; i++) {
6687     char *dname;
6688-
6689+
6690     dname = dispnames[i];
6691     if (StringWidth(dname) > (nList.w-10-16)) {  /* have to trunc. */
6692       tmp = dname;
6693       while (1) {
6694 	tmp = (char *) index(tmp,'/'); /* find next '/' in filename */
6695 	if (!tmp) { tmp = dname;  break; }
6696-
6697+
6698 	tmp++;                   /* move to char following the '/' */
6699 	if (StringWidth(tmp) <= (nList.w-10-16)) { /* is cool now */
6700 	  j++;  break;
6701@@ -3484,9 +4150,9 @@
6702
6703   name = GetDirFName();
6704   GetDirPath(cwd);
6705-
6706+
6707   AddFNameToCtrlList(cwd, name);
6708-
6709+
6710   if (select) {
6711     nList.selected = numnames-1;
6712     curname = numnames - 1;
6713@@ -3498,35 +4164,35 @@
6714
6715 /***********************************/
6716 void AddFNameToCtrlList(fpath,fname)
6717-     char *fpath, *fname;
6718+     const char *fpath, *fname;
6719 {
6720   /* stick given path/name into 'namelist'.  Doesn't redraw list */
6721-
6722-  char *fullname, *dname;
6723+
6724+  char *fullname;
6725   char cwd[MAXPATHLEN], globnm[MAXPATHLEN+100];
6726   int i;
6727-
6728+
6729   if (!fpath) fpath = "";  /* bulletproofing... */
6730-  if (!fname) fname = "";
6731-
6732+  if (!fname) fname = "";
6733+
6734   if (numnames == MAXNAMES) return;  /* full up */
6735-
6736+
6737   /* handle globbing */
6738   if (fname[0] == '~') {
6739     strcpy(globnm, fname);
6740     Globify(globnm);
6741     fname = globnm;
6742   }
6743-
6744+
6745   if (fname[0] != '/') {  /* prepend path */
6746     strcpy(cwd, fpath);   /* copy it to a modifiable place */
6747-
6748+
6749     /* make sure fpath has a trailing '/' char */
6750     if (strlen(cwd)==0 || cwd[strlen(cwd)-1]!='/') strcat(cwd, "/");
6751-
6752+
6753     fullname = (char *) malloc(strlen(cwd) + strlen(fname) + 2);
6754     if (!fullname) FatalError("couldn't alloc name in AddFNameToCtrlList()\n");
6755-
6756+
6757     sprintf(fullname, "%s%s", cwd, fname);
6758   }
6759   else {                 /* copy name to fullname */
6760@@ -3534,15 +4200,15 @@
6761     if (!fullname) FatalError("couldn't alloc name in AddFNameToCtrlList()\n");
6762     strcpy(fullname, fname);
6763   }
6764-
6765-
6766+
6767+
6768   /* see if this name is a duplicate.  Don't add it if it is. */
6769   for (i=0; i<numnames; i++)
6770     if (strcmp(fullname, namelist[i]) == 0) {
6771       free(fullname);
6772       return;
6773     }
6774-
6775+
6776   namelist[numnames] = fullname;
6777   numnames++;
6778   makeDispNames();
6779@@ -3578,7 +4244,7 @@
6780   /* called to enable/disable the Prev/Next buttons whenever curname and/or
6781      numnames and/or nList.selected change */
6782
6783-  /* if curname<0 (there is no 'current' file), 'Next' means view the
6784+  /* if curname<0 (there is no 'current' file), 'Next' means view the
6785      selected file (or the 0th file, if no selection either), and 'Prev' means
6786      view the one right before the selected file */
6787
6788@@ -3591,18 +4257,19 @@
6789     BTSetActive(&but[BPREV], (curname>0));
6790   }
6791 }
6792-
6793+
6794
6795 /***********************************/
6796 int DeleteCmd()
6797 {
6798   /* 'delete' button was pressed.  Pop up a dialog box to determine
6799      what should be deleted, then do it.
6800-     returns '1' if THE CURRENTLY VIEWED entry was deleted from the list,
6801-     in which case the 'selected' filename on the ctrl list is now
6802+     returns '1' if THE CURRENTLY VIEWED entry was deleted from the list,
6803+     in which case the 'selected' filename on the ctrl list is now
6804      different, and should be auto-loaded, or something */
6805
6806-  static char *bnames[] = { "\004Disk File", "\nList Entry", "\033Cancel" };
6807+  static const char *bnames[] =
6808+    { "\004Disk File", "\nList Entry", "\033Cancel" };
6809   char str[512];
6810   int  del, i, delnum, rv;
6811
6812@@ -3610,15 +4277,14 @@
6813   delnum = nList.selected;
6814   if (delnum < 0 || delnum >= numnames) return 0;
6815
6816-  sprintf(str,"Delete '%s'?\n\n%s%s",
6817-	  namelist[delnum],
6818+  sprintf(str, "Delete '%s'?\n\n%s%s", namelist[delnum],
6819 	  "'List Entry' deletes selection from list.\n",
6820 	  "'Disk File' deletes file associated with selection.");
6821
6822   del = PopUp(str, bnames, 3);
6823-
6824+
6825   if (del == 2) return 0;   /* cancel */
6826-
6827+
6828   if (del == 0) {           /* 'Disk File' */
6829     char *name;
6830     if (namelist[delnum][0] != '/') {    /* prepend 'initdir' */
6831@@ -3669,13 +4335,13 @@
6832
6833   if (delnum != numnames-1) {
6834     /* snip out of namelist and dispnames lists */
6835-    xvbcopy((char *) &namelist[delnum+1], (char *) &namelist[delnum],
6836+    xvbcopy((char *) &namelist[delnum+1], (char *) &namelist[delnum],
6837 	  (numnames - delnum - 1) * sizeof(namelist[0]));
6838
6839-    xvbcopy((char *) &dispnames[delnum+1], (char *) &dispnames[delnum],
6840+    xvbcopy((char *) &dispnames[delnum+1], (char *) &dispnames[delnum],
6841 	  (numnames - delnum - 1) * sizeof(dispnames[0]));
6842   }
6843-
6844+
6845   numnames--;
6846   if (numnames==0) BTSetActive(&but[BDELETE],0);
6847   windowMB.dim[WMB_TEXTVIEW] = (numnames==0);
6848@@ -3686,7 +4352,7 @@
6849   if (nList.selected >= numnames) nList.selected = numnames-1;
6850   if (nList.selected < 0) nList.selected = 0;
6851
6852-  SCSetRange(&nList.scrl, 0, numnames - nList.nlines,
6853+  SCSetRange(&nList.scrl, 0, numnames - nList.nlines,
6854 	     nList.scrl.val, nList.nlines-1);
6855   ScrollToCurrent(&nList);
6856   DrawCtrlNumFiles();
6857@@ -3753,7 +4419,7 @@
6858     if (useroot && resetroot) ClearRoot();
6859
6860     if (mainW == (Window) NULL || useroot) {  /* window not visible */
6861-      useroot = 0;
6862+      useroot = 0;
6863
6864       if (haveoldinfo) {             /* just remap mainW and resize it */
6865 	XWMHints xwmh;
6866@@ -3771,8 +4437,8 @@
6867 	xwmh.input = True;
6868 	xwmh.flags = InputHint;
6869
6870-	xwmh.icon_pixmap = iconPix;
6871-	xwmh.icon_mask   = iconmask;
6872+	xwmh.icon_pixmap = iconPix;
6873+	xwmh.icon_mask   = iconmask;
6874 	xwmh.flags |= ( IconPixmapHint | IconMaskHint) ;
6875
6876 	xwmh.flags |= StateHint;
6877@@ -3787,7 +4453,7 @@
6878       else {                         /* first time.  need to create mainW */
6879 	mainW = (Window) NULL;
6880 	createMainWindow(maingeom, fnam);
6881-	XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
6882+	XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
6883 		     | StructureNotifyMask | ButtonPressMask
6884 		     | KeyReleaseMask | ColormapChangeMask
6885 		     | EnterWindowMask | LeaveWindowMask );
6886@@ -3802,7 +4468,7 @@
6887
6888     else {                            /* mainW already visible */
6889       createMainWindow(maingeom, fnam);
6890-      XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
6891+      XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
6892 		   | StructureNotifyMask | ButtonPressMask
6893 		   | KeyReleaseMask | ColormapChangeMask
6894 		   | EnterWindowMask | LeaveWindowMask );
6895@@ -3845,13 +4511,13 @@
6896       if (LocalCmap) regen=1;
6897
6898       /* this reallocs the colors */
6899-      if (colorMapMode==CM_PERFECT || colorMapMode==CM_OWNCMAP)
6900+      if (colorMapMode==CM_PERFECT || colorMapMode==CM_OWNCMAP)
6901 	ChangeCmapMode(CM_NORMAL, 0, 0);
6902-
6903-
6904+
6905+
6906       XUnmapWindow(theDisp, mainW);
6907       mainW = vrootW;
6908-
6909+
6910       if (!ctrlUp) {    /* make sure ctrl is up when going to 'root' mode */
6911 	XWMHints xwmh;
6912 	xwmh.input         = True;
6913@@ -3861,7 +4527,7 @@
6914 	CtrlBox(1);
6915       }
6916     }
6917-
6918+
6919     useroot = 1;
6920     rootMode = dispMode - RMB_ROOT;
6921     ew = eWIDE;  eh = eHIGH;
6922@@ -3877,7 +4543,7 @@
6923       GenerateEpic(ew, eh);
6924       CreateXImage();
6925     }
6926-    else if (regen) CreateXImage();
6927+    else if (regen) CreateXImage();
6928
6929     KillOldRootInfo();
6930     MakeRootPic();
6931@@ -3923,7 +4589,7 @@
6932
6933
6934   if (*numn == maxn) {
6935-    fprintf(stderr, "%s: too many filenames.  Only using first %d.\n",
6936+    fprintf(stderr, "%s: too many filenames.  Using only first %d.\n",
6937 	    flist, maxn);
6938   }
6939
6940@@ -3947,14 +4613,14 @@
6941
6942 /***********************************/
6943 int rd_int(name)
6944-     char *name;
6945+     const char *name;
6946 {
6947   /* returns '1' if successful.  result in def_int */
6948
6949   if (rd_str_cl(name, "", 0)) {     /* sets def_str */
6950     if (sscanf(def_str, "%d", &def_int) == 1) return 1;
6951     else {
6952-      fprintf(stderr, "%s: couldn't read integer value for %s resource\n",
6953+      fprintf(stderr, "%s: couldn't read integer value for %s resource\n",
6954 	      cmd, name);
6955       return 0;
6956     }
6957@@ -3965,7 +4631,7 @@
6958
6959 /***********************************/
6960 int rd_str(name)
6961-     char *name;
6962+     const char *name;
6963 {
6964   return rd_str_cl(name, "", 0);
6965 }
6966@@ -3973,17 +4639,17 @@
6967
6968 /***********************************/
6969 int rd_flag(name)
6970-char *name;
6971+     const char *name;
6972 {
6973   /* returns '1' if successful.  result in def_int */
6974-
6975+
6976   char buf[256];
6977
6978   if (rd_str_cl(name, "", 0)) {  /* sets def_str */
6979     strcpy(buf, def_str);
6980     lower_str(buf);
6981
6982-    def_int = (strcmp(buf, "on")==0) ||
6983+    def_int = (strcmp(buf, "on")==0) ||
6984               (strcmp(buf, "1")==0) ||
6985 	      (strcmp(buf, "true")==0) ||
6986 	      (strcmp(buf, "yes")==0);
6987@@ -3992,16 +4658,16 @@
6988
6989   else return 0;
6990 }
6991-
6992+
6993
6994
6995
6996 static int xrm_initted = 0;
6997-
6998+
6999 /***********************************/
7000 int rd_str_cl (name_str, class_str, reinit)
7001-     char *name_str;
7002-     char *class_str;
7003+     const char *name_str;
7004+     const char *class_str;
7005      int  reinit;
7006 {
7007   /* note: *all* X resource reading goes through this routine... */
7008@@ -4043,16 +4709,30 @@
7009       unsigned long nitems, nleft;
7010       byte *data;
7011
7012-      i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0),
7013-			     resAtom, 0L, 1L, False,
7014-			     XA_STRING, &actType, &actFormat, &nitems, &nleft,
7015-			     (unsigned char **) &data);
7016+      if (spec_window) {
7017+        i = XGetWindowProperty(theDisp, spec_window,
7018+			       resAtom, 0L, 1L, False,
7019+			       XA_STRING, &actType, &actFormat, &nitems, &nleft,
7020+			       (unsigned char **) &data);
7021+      } else {
7022+        i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0),
7023+			       resAtom, 0L, 1L, False,
7024+			       XA_STRING, &actType, &actFormat, &nitems, &nleft,
7025+			       (unsigned char **) &data);
7026+      }
7027       if (i==Success && actType==XA_STRING && actFormat==8) {
7028 	if (nitems>0 && data) XFree(data);
7029-	i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0), resAtom, 0L,
7030-			       (long) ((nleft+4+3)/4),
7031-			       False, XA_STRING, &actType, &actFormat,
7032-			       &nitems, &nleft, (unsigned char **) &data);
7033+        if (spec_window) {
7034+	  i = XGetWindowProperty(theDisp, spec_window, resAtom, 0L,
7035+			         (long) ((nleft+4+3)/4),
7036+			         False, XA_STRING, &actType, &actFormat,
7037+			         &nitems, &nleft, (unsigned char **) &data);
7038+        } else {
7039+	  i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0), resAtom, 0L,
7040+			         (long) ((nleft+4+3)/4),
7041+			         False, XA_STRING, &actType, &actFormat,
7042+			         &nitems, &nleft, (unsigned char **) &data);
7043+        }
7044 	if (i==Success && actType==XA_STRING && actFormat==8 && data) {
7045 	  def_resource = XrmGetStringDatabase((char *) data);
7046 	  XFree(data);
7047@@ -4064,50 +4744,51 @@
7048
7049
7050     if (!gotit) {
7051-      xrm_str = XResourceManagerString(theDisp);
7052-
7053+      xrm_str = XResourceManagerString(theDisp);
7054+
7055       if (xrm_str) {
7056 	def_resource = XrmGetStringDatabase(xrm_str);
7057 	if (DEBUG) fprintf(stderr,"rd_str_cl: Using RESOURCE_MANAGER prop.\n");
7058       }
7059       else {    /* no RESOURCE_MANAGER prop.  read from 'likely' file */
7060-	char foo[256], *homedir, *xenviron;
7061+	char foo[256], *xenviron;
7062+	const char *homedir;
7063 	XrmDatabase res1;
7064-
7065+
7066 #ifdef VMS
7067 	strcpy(foo, "SYS$LOGIN:DECW$XDEFAULTS.DAT");
7068 #else
7069-	homedir = (char *) getenv("HOME");
7070+	homedir = (const char *) getenv("HOME");
7071 	if (!homedir) homedir = ".";
7072 	sprintf(foo,"%s/.Xdefaults", homedir);
7073 #endif
7074-
7075+
7076 	def_resource = XrmGetFileDatabase(foo);
7077-
7078+
7079 	if (DEBUG) {
7080 	  fprintf(stderr,"rd_str_cl: No RESOURCE_MANAGER prop.\n");
7081 	  fprintf(stderr,"rd_str_cl: Using file '%s' (%s)  ",
7082 		  foo, (def_resource) ? "success" : "failure");
7083 	}
7084-
7085-
7086+
7087+
7088 	/* merge file pointed to by XENVIRONMENT */
7089 	xenviron = (char *) getenv("XENVIRONMENT");
7090 	if (xenviron) {
7091 	  res1 = XrmGetFileDatabase(xenviron);
7092-
7093+
7094 	  if (DEBUG) {
7095 	    fprintf(stderr,"merging XENVIRONMENT='%s' (%s)  ",
7096 		    xenviron, (res1) ? "success" : "failure");
7097 	  }
7098-
7099+
7100 	  if (res1) {    /* merge databases */
7101 	    if (!def_resource) def_resource = res1;
7102 	    else XrmMergeDatabases(res1, &def_resource);
7103 	  }
7104 	}
7105-
7106-
7107+
7108+
7109 	if (DEBUG) fprintf(stderr,"\n\n");
7110       }
7111     }
7112@@ -4120,16 +4801,15 @@
7113   strcpy (q_name, PROGNAME);
7114   strcat (q_name, ".");
7115   strcat (q_name, name_str);
7116-
7117+
7118   strcpy (q_class, "Program");
7119   strcat (q_class, ".");
7120   strcat (q_class, class_str);
7121
7122   (void) XrmGetResource(def_resource, q_name, q_class, &type, &result);
7123-
7124+
7125   def_str = result.addr;
7126-  if (def_str) return (1);
7127-  else return (0);
7128+  if (def_str) return 1;
7129+  else return 0;
7130 }
7131
7132-
7133diff -ru xv-3.10a/xv.h xv-3.10a-enhancements/xv.h
7134--- xv-3.10a/xv.h	1995-01-23 12:22:23.000000000 -0800
7135+++ xv-3.10a-enhancements/xv.h	2007-05-20 21:26:40.000000000 -0700
7136@@ -1,6 +1,6 @@
7137 /*
7138  *  xv.h  -  header file for xv, but you probably guessed as much
7139- *
7140+ *
7141  *  Author:    John Bradley  (bradley@cis.upenn.edu)
7142  */
7143
7144@@ -8,8 +8,16 @@
7145 #include "config.h"
7146
7147
7148-#define REVDATE   "Version 3.10a  Rev: 12/29/94"
7149-#define VERSTR    "3.10a"
7150+/* xv 3.10a:				19941229 */
7151+/* PNG patch 1.2d:			19960731 */
7152+/* GRR orig jumbo fixes patch:		20000213 */
7153+/* GRR orig jumbo enhancements patch:	20000220 */
7154+/* GRR 1st public jumbo F+E patches:	20040531 */
7155+/* GRR 2nd public jumbo F+E patches:	20050410 */
7156+/* GRR 3rd public jumbo F+E patches:	20050501 */
7157+/* GRR 4th public jumbo F+E patch:  	20070520 */
7158+#define REVDATE   "version 3.10a-jumboFix+Enh of 20070520"
7159+#define VERSTR    "3.10a-20070520"
7160
7161 /*
7162  * uncomment the following, and modify for your site, but only if you've
7163@@ -43,6 +51,10 @@
7164 /* START OF MACHINE-DEPENDENT CONFIGURATION INFO */
7165 /*************************************************/
7166
7167+
7168+#define ENABLE_FIXPIX_SMOOTH	/* GRR 19980607 */
7169+
7170+
7171 /* Things to make xv more likely to just build, without the user tweaking
7172    the makefile */
7173
7174@@ -61,16 +73,38 @@
7175 #  define SVR4
7176 #endif
7177
7178+#if defined(__sony_news) && defined(bsd43) && !defined(__bsd43)
7179+#  define __bsd43
7180+#elif defined(__sony_news) && (defined(SYSTYPE_BSD) || defined(__SYSTYPE_BSD)) && !defined(bsd43) && !defined(__bsd43)
7181+#  define bsd43
7182+#  define __bsd43
7183+#endif
7184+
7185+#include <signal.h>      /* for interrupt handling */
7186+
7187+/* at least on Linux, the following file (1) includes sys/types.h and
7188+ * (2) defines __USE_BSD (which was not defined before here), so __linux__
7189+ * block is now moved after this #include */
7190+#include <X11/Xos.h>     /* need type declarations immediately */
7191+
7192
7193-#ifdef LINUX
7194+#ifdef __linux__
7195 #  ifndef _LINUX_LIMITS_H
7196 #    include <linux/limits.h>
7197 #  endif
7198+#  ifndef USLEEP
7199+#    define USLEEP
7200+#  endif
7201+   /* want only one or the other defined, not both: */
7202+#  if !defined(BSDTYPES) && !defined(__USE_BSD)
7203+#    define BSDTYPES
7204+#  endif
7205+#  if defined(BSDTYPES) && defined(__USE_BSD)
7206+#    undef BSDTYPES
7207+#  endif
7208 #endif
7209
7210
7211-#include <X11/Xos.h>     /* need type declarations immediately */
7212-
7213 /*********************************************************/
7214
7215
7216@@ -99,6 +133,16 @@
7217 #endif
7218
7219
7220+#if defined(__sony_news) && defined(__bsd43)
7221+#  include <unistd.h>
7222+#endif
7223+
7224+
7225+#if defined(__FreeBSD__)
7226+#  include <sys/param.h>
7227+#endif
7228+
7229+
7230 /* include files */
7231 #include <stdio.h>
7232 #include <math.h>
7233@@ -114,18 +158,24 @@
7234
7235 #ifndef VMS
7236 #  include <errno.h>
7237-   extern int   errno;             /* SHOULD be in errno.h, but often isn't */
7238 #  ifndef __NetBSD__
7239-     extern char *sys_errlist[];     /* this too... */
7240+#    if !(defined __GLIBC__ && __GLIBC__ >= 2)
7241+       extern int   errno;         /* SHOULD be in errno.h, but often isn't */
7242+       extern char *sys_errlist[]; /* this too... */
7243+#    endif
7244 #  endif
7245 #endif
7246
7247
7248 /* not everyone has the strerror() function, or so I'm told */
7249-#ifndef VMS
7250-#  define ERRSTR(x) sys_errlist[x]
7251-#else
7252+#ifdef VMS
7253 #  define ERRSTR(x) strerror(x, vaxc$errno)
7254+#else
7255+#  if defined(__BEOS__) || defined(__linux__) /* or all modern/glibc systems? */
7256+#    define ERRSTR(x) strerror(x)
7257+#  else
7258+#    define ERRSTR(x) sys_errlist[x]
7259+#  endif
7260 #endif
7261
7262
7263@@ -146,28 +196,20 @@
7264 #endif
7265
7266
7267-/* lots of things don't have <malloc.h> */
7268-/* A/UX systems include it from stdlib, from Xos.h */
7269-#ifndef VMS   /* VMS hates multi-line '#if's */
7270-# if !defined(ibm032)                    && \
7271-     !defined(__convex__)                && \
7272-     !(defined(vax) && !defined(ultrix)) && \
7273-     !defined(mips)                      && \
7274-     !defined(apollo)                    && \
7275-     !defined(pyr)                       && \
7276-     !defined(__UMAXV__)                 && \
7277-     !defined(bsd43)                     && \
7278-     !defined(aux)                       && \
7279-     !defined(__bsdi__)                  && \
7280-     !defined(sequent)
7281-
7282+/* GRR 20070512:  Very few modern systems even have a malloc.h anymore;
7283+ *                stdlib.h is, well, the standard.  (Former explicitly listed
7284+ *                "don't include" systems:  ibm032, __convex__, non-ultrix vax,
7285+ *                mips, apollo, pyr, sequent, __UMAXV__, aux, bsd43, __bsd43,
7286+ *                __bsdi__, __386BSD__, __FreeBSD__, __OpenBSD__, __NetBSD__,
7287+ *                __DARWIN__, VMS.)  Anyone who _does_ need it can explicitly
7288+ *                define NEED_MALLOC_H in the makefile. */
7289+#ifdef NEED_MALLOC_H
7290 #  if defined(hp300) || defined(hp800) || defined(NeXT)
7291-#   include <sys/malloc.h>                /* it's in 'sys' on HPs and NeXT */
7292+#    include <sys/malloc.h>    /* it's in "sys" on HPs and NeXT */
7293 #  else
7294-#   include <malloc.h>
7295+#    include <malloc.h>
7296 #  endif
7297-# endif
7298-#endif /* !VMS */
7299+#endif
7300
7301
7302
7303@@ -179,9 +221,10 @@
7304 #include <X11/Xatom.h>
7305 #include <X11/Xmd.h>
7306
7307+#ifdef TV_L10N
7308+#  include <X11/Xlocale.h>
7309+#endif
7310
7311-#undef SIGCHLD           /* defined in both Xos.h and signal.h */
7312-#include <signal.h>      /* for interrupt handling */
7313
7314 #include <sys/types.h>
7315
7316@@ -205,6 +248,10 @@
7317 #    include <limits.h>
7318 #  endif
7319
7320+#  ifdef __BEOS__
7321+#    include <socket.h>
7322+#  endif
7323+
7324 /*** for select() call ***/
7325 #  ifdef __hpux
7326 #    define XV_FDTYPE (int *)
7327@@ -259,7 +306,7 @@
7328  * make them if missing, along with a few fictitious ones
7329  *      Cameron Simpson  (cameron@cse.unsw.edu.au)
7330  */
7331-
7332+
7333 #ifndef         S_ISDIR         /* missing POSIX-type macros */
7334 #  define       S_ISDIR(mode)   (((mode)&S_IFMT) == S_IFDIR)
7335 #  define       S_ISBLK(mode)   (((mode)&S_IFMT) == S_IFBLK)
7336@@ -288,7 +335,9 @@
7337 #  endif
7338 #endif
7339
7340-
7341+#ifndef S_IRWUSR
7342+#  define S_IRWUSR	(S_IRUSR|S_IWUSR)	/* or (S_IREAD|S_IWRITE) */
7343+#endif
7344
7345 #ifndef MAXPATHLEN
7346 #  define MAXPATHLEN 256
7347@@ -308,36 +357,90 @@
7348
7349 #ifndef VMS       /* VMS hates multi-line definitions */
7350 #  if defined(SVR4)  || defined(SYSV) || defined(sco) || \
7351-      defined(XENIX) || defined(__osf__)
7352+      defined(XENIX) || defined(__osf__) || defined(__linux__)
7353 #    undef  USE_GETCWD
7354 #    define USE_GETCWD          /* use 'getcwd()' instead of 'getwd()' */
7355+#  endif                        /* >> SECURITY ISSUE << */
7356+#endif
7357+
7358+
7359+/* GRR 20040430:  This is new and still not fully deployed.  No doubt there
7360+ *                are other systems that have mkstemp() (SUSv3); we can add
7361+ *                them later. */
7362+#ifndef VMS       /* VMS hates multi-line definitions */
7363+#  if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
7364+      defined(__bsdi__)
7365+#    ifndef USE_MKSTEMP
7366+#      define USE_MKSTEMP       /* use 'mkstemp()' instead of 'mktemp()' */
7367+#    endif                      /* >> SECURITY ISSUE << */
7368 #  endif
7369 #endif
7370
7371
7372+/* GRR 20040503:  This is new and so far tested only under Linux.  But it
7373+ *                allows -wait to work with subsecond values as long as
7374+ *                times() exists and clock_t is a long int (latter matters
7375+ *                only if/when clocks wrap, which for Linux is multiples of
7376+ *                497.11 days since the last reboot). */
7377+#if defined(__linux__)
7378+#  define USE_TICKS             /* use times()/Timer(), not time()/sleep() */
7379+#  include <limits.h>           /* LONG_MAX (really want CLOCK_T_MAX) */
7380+#  include <sys/times.h>        /* times() */
7381+#  ifndef CLK_TCK               /* can be undefined in strict-ANSI mode */
7382+#    define CLK_TCK CLOCKS_PER_SEC   /* claimed to be same thing in time.h */
7383+#  endif
7384+#endif
7385+
7386+#if (defined(SYSV) || defined(SVR4) || defined(linux)) && !defined(USE_GETCWD)
7387+#  define USE_GETCWD
7388+#endif
7389+
7390+#ifndef SEEK_SET
7391+#  define SEEK_SET 0
7392+#  define SEEK_CUR 1
7393+#  define SEEK_END 2
7394+#endif
7395+
7396+#if defined(__mips) && defined(__SYSTYPE_BSD43)
7397+#  define strstr(A,B) pds_strstr((A),(B))
7398+#  undef S_IFIFO
7399+#endif /* !mips_bsd */
7400+
7401 /*****************************/
7402 /* END OF CONFIGURATION INFO */
7403 /*****************************/
7404
7405+
7406 #ifdef DOJPEG
7407-#define HAVE_JPEG
7408+#  define HAVE_JPEG
7409+#endif
7410+
7411+#ifdef DOJP2K
7412+#  define HAVE_JP2K
7413 #endif
7414
7415 #ifdef DOTIFF
7416-#define HAVE_TIFF
7417+#  define HAVE_TIFF
7418+#endif
7419+
7420+#ifdef DOPNG
7421+#  define HAVE_PNG
7422 #endif
7423
7424 #ifdef DOPDS
7425-#define HAVE_PDS
7426+#  define HAVE_PDS
7427 #endif
7428
7429+#ifdef DOG3
7430+#  define HAVE_G3
7431+#endif
7432
7433
7434-#define PROGNAME  "xv"             /* used in resource database */
7435+#define PROGNAME   "xv"            /* used in resource database */
7436
7437-#define MAXNAMES 4096              /* max # of files in ctrlW list */
7438+#define MAXNAMES   65536           /* max # of files in ctrlW list */
7439
7440-#define MAXBRWIN   4               /* max # of vis browser windows */
7441+#define MAXBRWIN   16              /* max # of vis browser windows */
7442
7443 /* strings in the INFOBOX (used in SetISTR and GetISTR) */
7444 #define NISTR         10    /* number of ISTRs */
7445@@ -432,7 +535,7 @@
7446 #define F_COLORS    0
7447 #define F_FORMAT    1
7448
7449-/* the following list give indicies into saveColors[] array in xvdir.c */
7450+/* the following list give indices into saveColors[] array in xvdir.c */
7451 #define F_FULLCOLOR 0
7452 #define F_GREYSCALE 1
7453 #define F_BWDITHER  2
7454@@ -440,49 +543,115 @@
7455 #define F_MAXCOLORS 4   /* length of saveColors[] array */
7456
7457
7458-/* following list gives indicies into 'saveFormats[]' array in xvdir.c
7459-   note that JPEG and TIFF entries may or may not exist, and following
7460-   constants have to be adjusted accordingly.  Also, don't worry about
7461-   duplicate cases if JPGINC or TIFINC = 0.  All code that references
7462-   F_JPEG or F_TIFF is #ifdef'd, so it won't be a problem */
7463+/* The following list gives indices into 'saveFormats[]' array in xvdir.c.
7464+   Note that JPEG, TIFF, and other entries may or may not exist, so the
7465+   following constants have to be adjusted accordingly.  Also, don't worry
7466+   about duplicate cases if, e.g., JPGINC or TIFINC = 0.  All code that
7467+   references F_JPEG, F_TIFF, etc., is #ifdef'd, so it won't be a problem. */
7468
7469 #ifdef HAVE_JPEG
7470-#define F_JPGINC  1
7471+#  define F_JPGINC  1
7472 #else
7473-#define F_JPGINC  0
7474+#  define F_JPGINC  0
7475+#endif
7476+
7477+#ifdef HAVE_JP2K
7478+#  define F_JP2INC  1   /* provides both JPC and JP2 */
7479+#else
7480+#  define F_JP2INC  0
7481 #endif
7482
7483 #ifdef HAVE_TIFF
7484-#define F_TIFINC  1
7485+#  define F_TIFINC  1
7486+#else
7487+#  define F_TIFINC  0
7488+#endif
7489+
7490+#ifdef HAVE_PNG
7491+#  define F_PNGINC  1
7492+#else
7493+#  define F_PNGINC  0
7494+#endif
7495+
7496+#ifdef HAVE_MAG
7497+#  define F_MAGINC  1
7498+#else
7499+#  define F_MAGINC  0
7500+#endif
7501+
7502+#ifdef HAVE_PIC
7503+#  define F_PICINC  1
7504+#else
7505+#  define F_PICINC  0
7506+#endif
7507+
7508+#ifdef HAVE_MAKI
7509+#  define F_MAKINC  1
7510+#else
7511+#  define F_MAKINC  0
7512+#endif
7513+
7514+#ifdef HAVE_PI
7515+#  define F_PAIINC  1
7516+#else
7517+#  define F_PAIINC  0
7518+#endif
7519+
7520+#ifdef HAVE_PIC2
7521+#  define F_PC2INC  1
7522 #else
7523-#define F_TIFINC  0
7524+#  define F_PC2INC  0
7525 #endif
7526
7527+#ifdef HAVE_MGCSFX
7528+#  define F_MGCSFXINC  1
7529+#else
7530+#  define F_MGCSFXINC  0
7531+#endif
7532
7533-#define F_GIF         0
7534-#define F_JPEG      ( 0 + F_JPGINC)
7535-#define F_TIFF      ( 0 + F_JPGINC + F_TIFINC)
7536-#define F_PS        ( 1 + F_JPGINC + F_TIFINC)
7537-#define F_PBMRAW    ( 2 + F_JPGINC + F_TIFINC)
7538-#define F_PBMASCII  ( 3 + F_JPGINC + F_TIFINC)
7539-#define F_XBM       ( 4 + F_JPGINC + F_TIFINC)
7540-#define F_XPM       ( 5 + F_JPGINC + F_TIFINC)
7541-#define F_BMP       ( 6 + F_JPGINC + F_TIFINC)
7542-#define F_SUNRAS    ( 7 + F_JPGINC + F_TIFINC)
7543-#define F_IRIS      ( 8 + F_JPGINC + F_TIFINC)
7544-#define F_TARGA     ( 9 + F_JPGINC + F_TIFINC)
7545-#define F_FITS      (10 + F_JPGINC + F_TIFINC)
7546-#define F_PM        (11 + F_JPGINC + F_TIFINC)
7547-#define F_DELIM1    (12 + F_JPGINC + F_TIFINC)     /* ----- */
7548-#define F_FILELIST  (13 + F_JPGINC + F_TIFINC)
7549-#define F_MAXFMTS   (14 + F_JPGINC + F_TIFINC)     /* 15, normally */
7550+#ifdef MACBINARY
7551+#  define MACBSIZE 128
7552+#endif
7553+
7554+/* NOTE:  order must match saveFormats[] in xvdir.c */
7555+/* [this works best when first one is always present, but...we like PNG :-) ] */
7556+#define F_PNG         0
7557+#define F_JPEG      ( 0 + F_PNGINC)
7558+#define F_JPC       ( 0 + F_PNGINC + F_JPGINC)
7559+#define F_JP2       ( 0 + F_PNGINC + F_JPGINC + F_JP2INC)
7560+#define F_GIF       ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC)  /* always avail; index varies */
7561+#define F_TIFF      ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC + F_TIFINC)
7562+#define F_PS        ( 1 + F_TIFF)
7563+#define F_PBMRAW    ( 2 + F_TIFF)
7564+#define F_PBMASCII  ( 3 + F_TIFF)
7565+#define F_XBM       ( 4 + F_TIFF)
7566+#define F_XPM       ( 5 + F_TIFF)
7567+#define F_BMP       ( 6 + F_TIFF)
7568+#define F_SUNRAS    ( 7 + F_TIFF)
7569+#define F_IRIS      ( 8 + F_TIFF)
7570+#define F_TARGA     ( 9 + F_TIFF)
7571+#define F_FITS      (10 + F_TIFF)
7572+#define F_PM        (11 + F_TIFF)
7573+#define F_ZX        (12 + F_TIFF)   /* [JCE] */
7574+#define F_WBMP      (13 + F_TIFF)
7575+#define JP_EXT_F    (F_WBMP)
7576+#define F_MAG       (JP_EXT_F + F_MAGINC)
7577+#define F_PIC       (JP_EXT_F + F_MAGINC + F_PICINC)
7578+#define F_MAKI      (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC)
7579+#define F_PI        (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC + F_PAIINC)
7580+#define F_PIC2      (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC + F_PAIINC + F_PC2INC)
7581+#define F_MGCSFX    (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC + F_PAIINC + F_PC2INC + F_MGCSFXINC)
7582+#define JP_EXT_F_END (F_MGCSFX)
7583+#define F_DELIM1    (JP_EXT_F_END + 1)   /* ----- */
7584+#define F_FILELIST  (JP_EXT_F_END + 2)
7585+#define F_MAXFMTS   (JP_EXT_F_END + 3)   /* 27, normally (with all formats) */
7586
7587
7588
7589 /* return values from ReadFileType()
7590  * positive values are *definitely* readable formats (HAVE_*** is defined)
7591  * negative values are random files that XV can't read, but display as
7592- *   different icons in the visual browser
7593+ *   different icons in the visual browser
7594  */
7595 #define RFT_ERROR    -1    /* couldn't open file, or whatever... */
7596 #define RFT_UNKNOWN   0
7597@@ -505,6 +674,22 @@
7598 #define RFT_XPM      17
7599 #define RFT_XWD      18
7600 #define RFT_FITS     19
7601+#define RFT_PNG      20
7602+#define RFT_ZX       21    /* [JCE] */
7603+#define RFT_WBMP     22
7604+#define RFT_PCD      23
7605+#define RFT_HIPS     24
7606+#define RFT_BZIP2    25
7607+#define RFT_JPC      26
7608+#define RFT_JP2      27
7609+#define RFT_G3       28
7610+#define JP_EXT_RFT   (RFT_G3)
7611+#define RFT_MAG      (JP_EXT_RFT + 1)
7612+#define RFT_MAKI     (JP_EXT_RFT + 2)
7613+#define RFT_PIC      (JP_EXT_RFT + 3)
7614+#define RFT_PI       (JP_EXT_RFT + 4)
7615+#define RFT_PIC2     (JP_EXT_RFT + 5)
7616+#define RFT_MGCSFX   (JP_EXT_RFT + 6)
7617
7618 /* definitions for page up/down, arrow up/down list control */
7619 #define LS_PAGEUP   0
7620@@ -563,7 +748,8 @@
7621 #define RM_CBRICK  7     /* centered on a 'brick' bg */
7622 #define RM_ECENTER 8     /* symmetrical tiled */
7623 #define RM_ECMIRR  9     /* symmetrical mirror tiled */
7624-#define RM_MAX     RM_ECMIRR
7625+#define RM_UPLEFT 10     /* just in upper left corner */
7626+#define RM_MAX     RM_UPLEFT
7627
7628
7629 /* values of colorMapMode */
7630@@ -613,10 +799,11 @@
7631 #define RMB_CBRICK   8
7632 #define RMB_ECENTER  9
7633 #define RMB_ECMIRR   10
7634-#define RMB_MAX      11
7635+#define RMB_UPLEFT   11
7636+#define RMB_MAX      12
7637
7638
7639-/* indicies into conv24MB */
7640+/* indices into conv24MB */
7641 #define CONV24_8BIT  0
7642 #define CONV24_24BIT 1
7643 #define CONV24_SEP1  2
7644@@ -631,7 +818,7 @@
7645 #define PIC8  CONV24_8BIT
7646 #define PIC24 CONV24_24BIT
7647
7648-/* indicies into algMB */
7649+/* indices into algMB */
7650 #define ALG_NONE      0
7651 #define ALG_SEP1      1  /* separator */
7652 #define ALG_BLUR      2
7653@@ -648,7 +835,7 @@
7654 #define ALG_MAX       13
7655
7656
7657-/* indicies into sizeMB */
7658+/* indices into sizeMB */
7659 #define SZMB_NORM     0
7660 #define SZMB_MAXPIC   1
7661 #define SZMB_MAXPECT  2
7662@@ -663,7 +850,7 @@
7663 #define SZMB_INTEXP   11
7664 #define SZMB_MAX      12
7665
7666-/* indicies into windowMB */
7667+/* indices into windowMB */
7668 #define WMB_BROWSE    0
7669 #define WMB_COLEDIT   1
7670 #define WMB_INFO      2
7671@@ -742,15 +929,15 @@
7672
7673 typedef unsigned char byte;
7674
7675-typedef struct scrl {
7676+typedef struct scrl {
7677                  Window win;            /* window ID */
7678 		 int x,y,w,h;           /* window coords in parent */
7679 		 int len;               /* length of major axis */
7680 		 int vert;              /* true if vertical, else horizontal */
7681 		 int active;            /* true if scroll bar can do anything*/
7682-		 int min,max;           /* min/max values 'pos' can take */
7683-		 int val;               /* 'value' of scrollbar */
7684-		 int page;              /* amt val change on pageup/pagedown */
7685+		 double min,max;        /* min/max values 'pos' can take */
7686+		 double val;            /* 'value' of scrollbar */
7687+		 double page;           /* amt val change on pageup/pagedown */
7688 		 int tpos;              /* thumb pos. (pixels from tmin) */
7689 		 int tmin,tmax;         /* min/max thumb offsets (from 0,0) */
7690 		 int tsize;             /* size of thumb (in pixels) */
7691@@ -765,11 +952,12 @@
7692 typedef struct { Window win;            /* window ID */
7693 		 int x,y,w,h;           /* window coords in parent */
7694 		 int active;            /* true if can do anything*/
7695-		 int min,max;           /* min/max values 'pos' can take */
7696-		 int val;               /* 'value' of dial */
7697-		 int page;              /* amt val change on pageup/pagedown */
7698-		 char *title;           /* title for this guage */
7699-		 char *units;           /* string appended to value */
7700+		 double min,max;        /* min/max values 'pos' can take */
7701+		 double val;            /* 'value' of dial */
7702+		 double inc;            /* amt val change on up/down */
7703+		 double page;           /* amt val change on pageup/pagedown */
7704+		 const char *title;     /* title for this gauge */
7705+		 const char *units;     /* string appended to value */
7706 		 u_long fg,bg,hi,lo;    /* colors */
7707 		 int rad, cx, cy;       /* internals */
7708 		 int bx[4], by[4];      /* more internals */
7709@@ -785,7 +973,7 @@
7710 		 int active;            /* if false, stipple gray */
7711 		 int toggle;            /* if true, clicking toggles state */
7712 		 u_long fg,bg,hi,lo;    /* colors */
7713-		 char *str;             /* string in button */
7714+		 const char *str;       /* string in button */
7715 		 Pixmap pix;            /* use pixmap instead of string */
7716 		 u_int pw,ph;           /* size of pixmap */
7717 		 int colorpix;          /* multi-color pixmap */
7718@@ -797,21 +985,23 @@
7719 typedef struct rbutt {
7720                  Window        win;      /* parent window */
7721 		 int           x,y;      /* position in parent */
7722-		 char         *str;      /* the message string */
7723+		 const char    *str;     /* the message string */
7724 		 int           selected; /* selected or not */
7725 		 int           active;   /* selectable? */
7726 		 struct rbutt *next;     /* pointer to next in group */
7727-		 u_long fg,bg,hi,lo;     /* colors */
7728+		 u_long        fg,bg;    /* colors */
7729+		 u_long        hi,lo;    /* colors */
7730 	       } RBUTT;
7731
7732
7733
7734 typedef struct { Window        win;      /* parent window */
7735 		 int           x,y;      /* position in parent */
7736-		 char         *str;      /* the message string */
7737+		 const char   *str;      /* the message string */
7738 		 int           val;      /* 1=selected, 0=not */
7739 		 int           active;   /* selectable? */
7740-		 u_long fg,bg,hi,lo;     /* colors */
7741+		 u_long        fg,bg;    /* colors */
7742+		 u_long        hi,lo;    /* colors */
7743 	       } CBUTT;
7744
7745
7746@@ -819,11 +1009,11 @@
7747 typedef struct { Window        win;            /* parent window */
7748 		 int           x,y;            /* position in parent */
7749 		 unsigned int  w,h;
7750-		 char         *title;          /* title string in norm state */
7751+		 const char   *title;          /* title string in norm state */
7752 		 int           active;         /* selectable? */
7753-		 char        **list;           /* list of strings in menu */
7754+		 const char  **list;           /* list of strings in menu */
7755 		 int           nlist;          /* # of strings in menu */
7756-		 byte          flags[MAXMBLEN];  /* checkmarks on items */
7757+		 byte          flags[MAXMBLEN]; /* checkmarks on items */
7758 		 int           hascheck;       /* leave room for checkmark? */
7759 		 byte          dim[MAXMBLEN];  /* dim individual choices */
7760 		 Pixmap        pix;            /* use pixmap instd of string */
7761@@ -833,17 +1023,18 @@
7762 	       } MBUTT;
7763
7764
7765-typedef struct { Window win;            /* window */
7766-		 int x,y;               /* size of window */
7767+typedef struct { Window       win;       /* window */
7768+		 int          x,y;       /* size of window */
7769 		 unsigned int w,h;
7770-		 u_long fg,bg,hi,lo;    /* colors */
7771-		 char **str;            /* ptr to list of strings */
7772-		 int   nstr;            /* number of strings */
7773-		 int   selected;        /* number of 'selected' string */
7774-		 int   nlines;          /* number of lines shown at once */
7775-		 SCRL  scrl;            /* scrollbar that controls list */
7776-		 int   filetypes;       /* true if filetype icons to be drawn*/
7777-		 int   dirsonly;        /* if true, only dirs selectable */
7778+		 u_long       fg,bg;     /* colors */
7779+		 u_long       hi,lo;     /* colors */
7780+		 /* const? */ char **str;   /* ptr to list of strings */
7781+		 int          nstr;      /* number of strings */
7782+		 int          selected;  /* number of 'selected' string */
7783+		 int          nlines;    /* number of lines shown at once */
7784+		 SCRL         scrl;      /* scrollbar that controls list */
7785+		 int          filetypes; /* true if filetype icons to be drawn*/
7786+		 int          dirsonly;  /* if true, only dirs selectable */
7787 	       } LIST;
7788
7789
7790@@ -865,6 +1056,9 @@
7791 		 char  shrtInfo[128];        /* short format info */
7792 		 char *comment;              /* comment text */
7793
7794+		 byte *exifInfo;             /* image info from digicam */
7795+		 int   exifInfoSize;         /* size of image info */
7796+
7797 		 int   numpages;             /* # of page files, if >1 */
7798 		 char  pagebname[64];        /* basename of page files */
7799 	       } PICINFO;
7800@@ -881,18 +1075,18 @@
7801
7802 #define GVMAX 8
7803
7804-typedef struct {  Window win;          /* window ID */
7805-		  Window gwin;         /* graph subwindow */
7806-		  int    spline;       /* spline curve or lines? */
7807-		  int    entergamma;   /* currently entering gamma value */
7808-		  int    gammamode;    /* currently using gamma function */
7809-		  double gamma;        /* gamma value (if gammamode) */
7810-		  int    nhands;       /* current # of handles */
7811-		  XPoint hands[MAX_GHANDS];   /* positions of handles */
7812-		  byte   func[256];    /* output function of GRAF */
7813-		  BUTT   butts[N_GFB]; /* control buttons */
7814-		  u_long fg,bg;        /* colors */
7815-		  char   *str;         /* title string */
7816+typedef struct {  Window win;               /* window ID */
7817+		  Window gwin;              /* graph subwindow */
7818+		  int    spline;            /* spline curve or lines? */
7819+		  int    entergamma;        /* currently entering gamma value */
7820+		  int    gammamode;         /* currently using gamma function */
7821+		  double gamma;             /* gamma value (if gammamode) */
7822+		  int    nhands;            /* current # of handles */
7823+		  XPoint hands[MAX_GHANDS]; /* positions of handles */
7824+		  byte   func[256];         /* output function of GRAF */
7825+		  BUTT   butts[N_GFB];      /* control buttons */
7826+		  u_long fg,bg;             /* colors */
7827+		  const char *str;          /* title string */
7828 		  char   gvstr[GVMAX+1];    /* gamma value input string */
7829 		  void   (*drawobj)PARM((void));
7830 		} GRAF;
7831@@ -932,18 +1126,23 @@
7832 /* X stuff */
7833 WHERE Display       *theDisp;
7834 WHERE int           theScreen;
7835-WHERE unsigned int  ncells, dispWIDE, dispHIGH, dispDEEP;
7836-WHERE unsigned int  vrWIDE, vrHIGH, maxWIDE, maxHIGH;
7837+WHERE unsigned int  ncells, dispDEEP; /* root color sizes */
7838+WHERE unsigned int  dispWIDE, dispHIGH; /* screen sizes */
7839+WHERE unsigned int  vrWIDE, vrHIGH, maxWIDE, maxHIGH; /* virtual root and max image sizes */
7840 WHERE Colormap      theCmap, LocalCmap;
7841-WHERE Window        rootW, mainW, vrootW;
7842+WHERE Window        spec_window, rootW, mainW, vrootW;
7843 WHERE GC            theGC;
7844 WHERE u_long        black, white, fg, bg, infofg, infobg;
7845 WHERE u_long        hicol, locol;
7846 WHERE u_long        blkRGB, whtRGB;
7847 WHERE Font          mfont, monofont;
7848 WHERE XFontStruct   *mfinfo, *monofinfo;
7849+#ifdef TV_L10N
7850+WHERE XFontSet      monofset;
7851+WHERE XFontSetExtents *monofsetinfo;
7852+#endif
7853 WHERE Visual        *theVisual;
7854-WHERE Cursor        arrow, cross, tcross, zoom, inviso;
7855+WHERE Cursor        arrow, cross, tcross, zoom, inviso, tlcorner;
7856 WHERE Pixmap        iconPix, iconmask;
7857 WHERE Pixmap        riconPix, riconmask;
7858 WHERE int           showzoomcursor;
7859@@ -959,6 +1158,12 @@
7860 WHERE char           formatStr[80];         /* short-form 'file format' */
7861 WHERE int            picType;               /* CONV24_8BIT,CONV24_24BIT,etc.*/
7862 WHERE char          *picComments;           /* text comments on current pic */
7863+WHERE byte          *picExifInfo;           /* image info from digicam */
7864+WHERE int            picExifInfoSize;       /* size of image info */
7865+
7866+#ifdef TV_L10N
7867+WHERE int            xlocale;		    /* true if Xlib supports locale */
7868+#endif
7869
7870 WHERE int            numPages, curPage;     /* for multi-page files */
7871 WHERE char           pageBaseName[64];      /* basename for multi-page files */
7872@@ -972,12 +1177,12 @@
7873                                    /* this is converted to 'theImage' */
7874 WHERE int           eWIDE, eHIGH;  /* size of epic */
7875
7876-WHERE byte          *egampic;      /* expanded, gammified cpic
7877+WHERE byte          *egampic;      /* expanded, gammified cpic
7878 				      (only used in 24-bit mode) */
7879
7880 WHERE int           p_offx, p_offy;  /* offset of reparented windows */
7881 WHERE int           ch_offx,ch_offy; /* ChngAttr ofst for reparented windows */
7882-WHERE int           kludge_offx,     /* WM kludges for SetWindowPos routine */
7883+WHERE int           kludge_offx,     /* WM kludges for SetWindowPos routine */
7884                     kludge_offy;
7885 WHERE int           winCtrPosKludge; /* kludge for popup positioning... */
7886
7887@@ -993,6 +1198,26 @@
7888 WHERE unsigned long  cols[256];    /* maps pic pixel values to X pixel vals */
7889 WHERE int            fc2pcol[256]; /* maps freecols into pic pixel values */
7890 WHERE int            numcols;      /* # of desired colors in picture */
7891+#ifdef MACBINARY
7892+WHERE char           macb_file;    /* True if this file type is MacBinary */
7893+WHERE int            handlemacb;   /* True if we want to handle MacBinary */
7894+#endif
7895+#if defined(HAVE_PIC) || defined(HAVE_PIC2)
7896+WHERE int            nopicadjust;  /* True if we don't want to adjust aspect */
7897+#endif
7898+#ifdef HAVE_PIC2
7899+WHERE int            pic2split;    /* True if we want to split multiblocks */
7900+#endif
7901+#ifdef VS_ADJUST
7902+WHERE int            vsadjust; /* True if we want to adjust aspect of icons */
7903+#endif
7904+#ifdef HAVE_MGCSFX
7905+WHERE int            mgcsfx;    /* True if we want to force use MgcSfx */
7906+WHERE int            nomgcsfx;  /* True if we don't want to use MgcSfx */
7907+#endif
7908+
7909+#define FSTRMAX 12   /* Number of function keys to support. */
7910+WHERE char          *fkeycmds[FSTRMAX]; /* command to run when F# is pressed */
7911
7912 /* Std Cmap stuff */
7913 WHERE byte           stdr[256], stdg[256], stdb[256];  /* std 3/3/2 cmap */
7914@@ -1025,7 +1250,7 @@
7915
7916 WHERE int           ncols;         /* max # of (different) colors to alloc */
7917
7918-WHERE char          str[128];      /* dummy string used for error messages */
7919+WHERE char          dummystr[128]; /* dummy string used for error messages */
7920 WHERE char          initdir[MAXPATHLEN];   /* cwd when xv was started */
7921 WHERE char          searchdir[MAXPATHLEN]; /* '-dir' option */
7922 WHERE char          fullfname[MAXPATHLEN]; /* full name of current file */
7923@@ -1047,42 +1272,47 @@
7924                     noFreeCols,    /* don't free colors when loading new pic */
7925                     autoquit,      /* quit in '-root' or when click on win */
7926                     xerrcode,      /* errorcode of last X error */
7927-                    grabDelay;     /* # of seconds to sleep at start of Grab */
7928+                    grabDelay,     /* # of seconds to sleep at start of Grab */
7929+                    startGrab;     /* start immediate grab ? */
7930
7931 WHERE int           state824;      /* displays warning when going 8->24 */
7932
7933 WHERE float         defaspect,     /* default aspect ratio to use */
7934                     normaspect;    /* normal aspect ratio of this picture */
7935
7936-WHERE unsigned long rootbg, rootfg;   /* fg/bg for root border */
7937-WHERE int           waitsec;          /* secs btwn pics. -1=wait for event */
7938-WHERE int           waitloop;         /* loop at end of slide show? */
7939-WHERE int           automax;          /* maximize pic on open */
7940-WHERE int           rootMode;         /* mode used for -root images */
7941+WHERE u_long        rootbg, rootfg; /* fg/bg for root border */
7942+WHERE u_short       imagebgR;
7943+WHERE u_short       imagebgG;      /* GRR 19980308:  bg for transpar. images */
7944+WHERE u_short       imagebgB;
7945+WHERE int           have_imagebg;
7946+WHERE double        waitsec;       /* secs btwn pics. -1.0=wait for event */
7947+WHERE int           waitloop;      /* loop at end of slide show? */
7948+WHERE int           automax;       /* maximize pic on open */
7949+WHERE int           rootMode;      /* mode used for -root images */
7950
7951-WHERE int           nostat;           /* if true, don't stat() in LdCurDir */
7952+WHERE int           nostat;        /* if true, don't stat() in LdCurDir */
7953
7954-WHERE int           ctrlColor;        /* whether or not to use colored butts */
7955+WHERE int           ctrlColor;     /* whether or not to use colored butts */
7956
7957-WHERE char         *def_str;          /* used by rd_*() routines */
7958+WHERE char         *def_str;       /* used by rd_*() routines */
7959 WHERE int           def_int;
7960-WHERE char         *tmpdir;           /* equal to "/tmp" or $TMPDIR env var */
7961-WHERE Pixmap        gray25Tile,       /* used for 3d effect on 1-bit disp's */
7962+WHERE char         *tmpdir;        /* equal to "/tmp" or $TMPDIR env var */
7963+WHERE Pixmap        gray25Tile,    /* used for 3d effect on 1-bit disp's */
7964                     gray50Tile;
7965-WHERE int           autoDelete;       /* delete cmd-line files on exit? */
7966+WHERE int           autoDelete;    /* delete cmd-line files on exit? */
7967
7968 #define PRINTCMDLEN 256
7969-WHERE char          printCmd[PRINTCMDLEN];
7970+WHERE char          printCmd[PRINTCMDLEN];
7971
7972 /* stuff used for 'info' box */
7973 WHERE Window        infoW;
7974-WHERE int           infoUp;       /* boolean:  whether infobox is visible */
7975+WHERE int           infoUp;        /* boolean:  whether infobox is visible */
7976 WHERE int           infoMode;
7977
7978
7979 /* stuff used for 'ctrl' box */
7980 WHERE Window        ctrlW;
7981-WHERE int           ctrlUp;       /* boolean:  whether ctrlbox is visible */
7982+WHERE int           ctrlUp;        /* boolean:  whether ctrlbox is visible */
7983 WHERE char         *namelist[MAXNAMES];  /* list of file names from argv */
7984 WHERE char         *origlist[MAXNAMES];  /* only names from argv (autoDelete)*/
7985 WHERE int           orignumnames;
7986@@ -1121,25 +1351,31 @@
7987
7988
7989 /* stuff used for 'browse' box */
7990-WHERE int           anyBrowUp;            /* whether *any* browser visible */
7991+WHERE int           anyBrowUp;              /* whether *any* browser visible */
7992+WHERE int           incrementalSearchTimeout;
7993
7994 /* stuff used for textview windows */
7995-WHERE int           anyTextUp;            /* are any text windows visible? */
7996-WHERE int           commentUp;            /* comment window up? */
7997+WHERE int           anyTextUp;              /* are any text windows visible? */
7998+WHERE int           commentUp;              /* comment window up? */
7999
8000 /* stuff used for xvcut.c */
8001-WHERE int           forceClipFile;        /* don't use property clipboard */
8002-WHERE int           clearR, clearG, clearB;  /* clear color in 24-bit mode */
8003+WHERE int           forceClipFile;          /* don't use property clipboard */
8004+WHERE int           clearR, clearG, clearB; /* clear color in 24-bit mode */
8005
8006
8007 /* stuff used for 'ps' box */
8008 WHERE Window        psW;
8009-WHERE int           psUp;       /* is psW mapped, or what? */
8010-WHERE CBUTT         encapsCB, pscompCB;
8011-WHERE char         *gsDev, *gsGeomStr;
8012+WHERE int           psUp;         /* is psW mapped, or what? */
8013+WHERE CBUTT         encapsCB, pscompCB;
8014+WHERE const char   *gsDev, *gsGeomStr;
8015 WHERE int           gsRes;
8016
8017
8018+/* stuff used for 'pcd' box */
8019+WHERE Window        pcdW;
8020+WHERE int           pcdUp;        /* is pcdW mapped, or what? */
8021+
8022+
8023 #ifdef HAVE_JPEG
8024 /* stuff used for 'jpeg' box */
8025 WHERE Window        jpegW;
8026@@ -1147,6 +1383,13 @@
8027 #endif
8028
8029
8030+#ifdef HAVE_JP2K
8031+/* stuff used for 'jp2k' box */
8032+WHERE Window        jp2kW;
8033+WHERE int           jp2kUp;       /* is jp2kW mapped, or what? */
8034+#endif
8035+
8036+
8037 #ifdef HAVE_TIFF
8038 /* stuff used for 'tiff' box */
8039 WHERE Window        tiffW;
8040@@ -1154,6 +1397,91 @@
8041 #endif
8042
8043
8044+#ifdef HAVE_PNG
8045+/* stuff used for 'png' box */
8046+WHERE Window        pngW;
8047+WHERE int           pngUp;        /* is pngW mapped, or what? */
8048+#endif
8049+
8050+
8051+#ifdef ENABLE_FIXPIX_SMOOTH
8052+WHERE int           do_fixpix_smooth;  /* GRR 19980607: runtime FS dithering */
8053+#endif
8054+
8055+#ifdef HAVE_PIC2
8056+/* stuff used for 'pic2' box */
8057+WHERE Window        pic2W;
8058+WHERE int           pic2Up;      /* is pic2W mapped, or what? */
8059+#endif /* HAVE_PIC2 */
8060+
8061+#ifdef HAVE_PCD
8062+/* stuff used for 'pcd' box */
8063+WHERE Window        pcdW;
8064+WHERE int           pcdUp;       /* is pcdW mapped, or what? */
8065+#endif /* HAVE_PCD */
8066+
8067+#ifdef HAVE_MGCSFX
8068+/* stuff used for 'mgcsfx' box */
8069+WHERE Window        mgcsfxW;
8070+WHERE Window        mgcsfxNameW;
8071+WHERE int           mgcsfxUp;      /* is mgcsfxW mapped, or what? */
8072+#endif /* HAVE_MGCSFX */
8073+
8074+#ifdef TV_L10N
8075+/* stuff used for TextViewer Japanization */
8076+#  define LOCALE_USASCII    0
8077+#  define LOCALE_EUCJ       1
8078+#  define LOCALE_JIS        2
8079+#  define LOCALE_MSCODE     3
8080+
8081+#  ifndef LOCALE_DEFAULT
8082+#    define LOCALE_DEFAULT  0
8083+#  endif /* !LOCALE_DEFAULT */
8084+
8085+#  ifndef MAIN
8086+     extern char *localeList[];
8087+#  else
8088+#    ifndef LOCALE_NAME_EUC
8089+#      ifndef X_LOCALE
8090+#        if defined(__FreeBSD__)
8091+	   char *localeList[] = {"", "ja_JP.EUC", "none", "none"};
8092+#        elif defined(__linux__)
8093+	   char *localeList[] = {"", "ja_JP.eucJP", "none", "ja_JP.SJIS"};
8094+#        elif defined(__sun) || defined(sun)
8095+	   char *localeList[] = {"", "ja", "none", "none"};
8096+#        elif defined(__sgi)	/* sgi, __sgi, __sgi__ (gcc) */
8097+	   char *localeList[] = {"", "ja_JP.EUC", "none", "none"};
8098+#        elif defined(sony_news)
8099+	   char *localeList[] = {"", "ja_JP.EUC", "none", "ja_JP.SJIS"};
8100+#        elif defined(nec)
8101+	   char *localeList[] = {"", "japan", "none", "none"};
8102+#        elif defined(__hpux)
8103+	   char *localeList[] = {"", "japanese.euc", "none", "japanese"};
8104+#        elif defined(__osf__)
8105+	   char *localeList[] = {"", "ja_JP.deckanji", "none", "ja_JP.SJIS"};
8106+#        elif defined(_AIX)
8107+	   char *localeList[] = {"", "ja_JP", "none", "Ja_JP" };
8108+#        elif defined(__bsdi)
8109+	   char *localeList[] = {"", "Japanese-EUC", "none", "none" };
8110+#        else
8111+	   char *localeList[] = {"", "ja_JP.EUC", "ja_JP.JIS", "ja_JP.SJIS"};
8112+#        endif
8113+#      else
8114+#        if (XlibSpecificationRelease > 5)
8115+           char *localeList[] = {"", "ja_JP.eucJP", "ja_JP.JIS7",
8116+				 "ja_JP.SJIS"};
8117+#        else
8118+           char *localeList[] = {"", "ja_JP.ujis", "ja_JP.jis7",
8119+				 "ja_JP.mscode"};
8120+#        endif
8121+#      endif /* X_LOCALE */
8122+#    else
8123+       char *localeList[] = {"", LOCALE_NAME_EUC,
8124+			     LOCALE_NAME_JIS, LOCALE_NAME_MSCODE};
8125+#    endif /* LOCALE_NAME_EUC */
8126+#  endif /* MAIN */
8127+#endif /* TV_L10N */
8128+
8129 #undef WHERE
8130
8131
8132@@ -1161,172 +1489,115 @@
8133 /* function declarations for externally-callable functions */
8134
8135 /****************************** XV.C ****************************/
8136-int   ReadFileType      PARM((char *));
8137-int   ReadPicFile       PARM((char *, int, PICINFO *, int));
8138-int   UncompressFile    PARM((char *, char *));
8139-void  KillPageFiles     PARM((char *, int));
8140-
8141-void NewPicGetColors    PARM((int, int));
8142-void FixAspect          PARM((int, int *, int *));
8143-void ActivePrevNext     PARM((void));
8144-int  DeleteCmd          PARM((void));
8145-void StickInCtrlList    PARM((int));
8146-void AddFNameToCtrlList PARM((char *, char *));
8147-void ChangedCtrlList    PARM((void));
8148-void HandleDispMode     PARM((void));
8149-char *lower_str         PARM((char *));
8150-int  rd_int             PARM((char *));
8151-int  rd_str             PARM((char *));
8152-int  rd_flag            PARM((char *));
8153-int  rd_str_cl          PARM((char *, char *, int));
8154+int   ReadFileType         PARM((char *));
8155+int   ReadPicFile          PARM((char *, int, PICINFO *, int));
8156+int   UncompressFile       PARM((char *, char *, int));
8157+void  KillPageFiles        PARM((char *, int));
8158+#ifdef MACBINARY
8159+int   RemoveMacbinary      PARM((char *, char *));
8160+#endif
8161+
8162+void NewPicGetColors       PARM((int, int));
8163+void FixAspect             PARM((int, int *, int *));
8164+void ActivePrevNext        PARM((void));
8165+int  DeleteCmd             PARM((void));
8166+void StickInCtrlList       PARM((int));
8167+void AddFNameToCtrlList    PARM((const char *, const char *));
8168+void ChangedCtrlList       PARM((void));
8169+void HandleDispMode        PARM((void));
8170+char *lower_str            PARM((char *));
8171+int  rd_int                PARM((const char *));
8172+int  rd_str                PARM((const char *));
8173+int  rd_flag               PARM((const char *));
8174
8175-/****************************** XVEVENT.C ****************************/
8176-int  EventLoop          PARM((void));
8177-int  HandleEvent        PARM((XEvent *, int *));
8178
8179-void SelectDispMB       PARM((int));
8180-void Select24to8MB      PARM((int));
8181-void SelectRootMB       PARM((int));
8182-void SelectWindowMB     PARM((int));
8183-void SelectSizeMB       PARM((int));
8184-
8185-void DoPrint            PARM((void));
8186-void NewCutBuffer       PARM((char *));
8187-void DrawWindow         PARM((int,int,int,int));
8188-void WResize            PARM((int, int));
8189-void WRotate            PARM((void));
8190-void WCrop              PARM((int, int, int, int));
8191-void WUnCrop            PARM((void));
8192-void GetWindowPos       PARM((XWindowAttributes *));
8193-void SetWindowPos       PARM((XWindowAttributes *));
8194-void SetEpicMode        PARM((void));
8195-int  xvErrorHandler     PARM((Display *, XErrorEvent *));
8196-
8197-/****************************** XVROOT.C ****************************/
8198-void MakeRootPic        PARM((void));
8199-void ClearRoot          PARM((void));
8200-void SaveRootInfo       PARM((void));
8201-void KillOldRootInfo    PARM((void));
8202+/*************************** XV24TO8.C **************************/
8203+void Init24to8             PARM((void));
8204+byte *Conv24to8            PARM((byte *, int, int, int,
8205+				 byte *, byte *, byte *));
8206
8207-/*************************** XVMISC.C ***************************/
8208-void StoreDeleteWindowProp  PARM((Window));
8209-Window CreateWindow         PARM((char *, char *, char *, int, int,
8210-				  u_long, u_long, int));
8211-void DrawString             PARM((Window, int, int, char *));
8212-void CenterString           PARM((Window, int, int, char *));
8213-void ULineString            PARM((Window, int, int, char *));
8214-int  StringWidth            PARM((char *));
8215-int  CursorKey              PARM((KeySym, int, int));
8216-void FakeButtonPress        PARM((BUTT *));
8217-void FakeKeyPress           PARM((Window, KeySym));
8218-void GenExpose              PARM((Window, int, int, u_int, u_int));
8219-void DimRect                PARM((Window, int, int, u_int, u_int, u_long));
8220-
8221-void Draw3dRect             PARM((Window, int, int, u_int, u_int, int, int,
8222-				    u_long, u_long, u_long));
8223-
8224-void RemapKeyCheck          PARM((KeySym, char *, int *));
8225-void xvDestroyImage         PARM((XImage *));
8226-void SetCropString          PARM((void));
8227-void SetSelectionString     PARM((void));
8228-void Warning                PARM((void));
8229-void FatalError             PARM((char *));
8230-void Quit                   PARM((int));
8231-void LoadFishCursors        PARM((void));
8232-void WaitCursor             PARM((void));
8233-void SetCursors             PARM((int));
8234-char *BaseName              PARM((char *));
8235-
8236-void DrawTempGauge          PARM((Window, int, int, int, int, double,
8237-				  u_long, u_long, u_long, u_long, char *));
8238-void ProgressMeter          PARM((int, int, int, char *));
8239-void XVDeletedFile          PARM((char *));
8240-void XVCreatedFile          PARM((char *));
8241-void xvbcopy                PARM((char *, char *, size_t));
8242-int  xvbcmp                 PARM((char *, char *, size_t));
8243-void xvbzero                PARM((char *, size_t));
8244-void xv_getwd               PARM((char *, size_t));
8245-char *xv_strstr             PARM((char *, char *));
8246-FILE *xv_fopen              PARM((char *, char *));
8247-void Timer                  PARM((int));
8248+byte *Conv8to24            PARM((byte *, int, int, byte *, byte *, byte *));
8249
8250-/*************************** XVCOLOR.C ***************************/
8251-void   SortColormap         PARM((byte *, int, int, int *, byte*,byte*,byte*,
8252-				  byte *, byte *));
8253-void   ColorCompress8       PARM((byte *));
8254-void   AllocColors          PARM((void));
8255-Status xvAllocColor         PARM((Display *, Colormap, XColor *));
8256-void   xvFreeColors         PARM((Display *, Colormap, u_long *, int, u_long));
8257-void   FreeColors           PARM((void));
8258-void   ApplyEditColor       PARM((int));
8259-int    MakeStdCmaps         PARM((void));
8260-void   MakeBrowCmap         PARM((void));
8261-void   ChangeCmapMode       PARM((int, int, int));
8262
8263-/*************************** XVIMAGE.C ***************************/
8264-void Resize                 PARM((int, int));
8265-void GenerateCpic           PARM((void));
8266-void GenerateEpic           PARM((int, int));
8267-void DoZoom                 PARM((int, int, u_int));
8268-void Crop                   PARM((void));
8269-void UnCrop                 PARM((void));
8270-void AutoCrop               PARM((void));
8271-int  DoAutoCrop             PARM((void));
8272-void DoCrop                 PARM((int, int, int, int));
8273-void Rotate                 PARM((int));
8274-void DoRotate               PARM((int));
8275-void RotatePic              PARM((byte *, int, int *, int *, int));
8276-void Flip                   PARM((int));
8277-void FlipPic                PARM((byte *, int, int, int));
8278-void InstallNewPic          PARM((void));
8279-void DrawEpic               PARM((void));
8280-void KillOldPics            PARM((void));
8281-
8282-byte *FSDither              PARM((byte *, int, int, int,
8283-				  byte *, byte *, byte *, int, int));
8284-
8285-void CreateXImage           PARM((void));
8286-XImage *Pic8ToXImage        PARM((byte *, u_int, u_int, u_long *,
8287-				  byte *, byte *, byte *));
8288-
8289-XImage *Pic24ToXImage       PARM((byte *, u_int, u_int));
8290-
8291-void Set824Menus            PARM((int));
8292-void Change824Mode          PARM((int));
8293-void FreeEpic               PARM((void));
8294-void InvertPic24            PARM((byte *, int, int));
8295+/*************************** XVALG.C ***************************/
8296+void AlgInit               PARM((void));
8297+void DoAlg                 PARM((int));
8298
8299-byte *XVGetSubImage         PARM((byte *, int, int,int, int,int,int,int));
8300
8301-int  DoPad                  PARM((int, char *, int, int, int, int));
8302-int  LoadPad                PARM((PICINFO *, char *));
8303+/*************************** XVBROWSE.C ************************/
8304+void CreateBrowse          PARM((const char *, const char *, const char *,
8305+				 const char *, const char *));
8306+void OpenBrowse            PARM((void));
8307+void HideBrowseWindows     PARM((void));
8308+void UnHideBrowseWindows   PARM((void));
8309+void SetBrowseCursor       PARM((Cursor));
8310+void KillBrowseWindows     PARM((void));
8311+int  BrowseCheckEvent      PARM((XEvent *, int *, int *));
8312+int  BrowseDelWin          PARM((Window));
8313+void SetBrowStr            PARM((const char *));
8314+void RegenBrowseIcons      PARM((void));
8315+void BRDeletedFile         PARM((char *));
8316+void BRCreatedFile         PARM((char *));
8317
8318-/*************************** XVALG.C ***************************/
8319-void AlgInit                PARM((void));
8320-void DoAlg                  PARM((int));
8321
8322-/*************************** XVSMOOTH.C ***************************/
8323-byte *SmoothResize          PARM((byte *, int, int, int, int, byte *, byte *,
8324-				  byte *, byte *, byte *, byte *, int));
8325+/**************************** XVBUTT.C ***************************/
8326+void BTCreate              PARM((BUTT *, Window, int, int, u_int, u_int,
8327+				 const char *, u_long, u_long, u_long, u_long));
8328
8329-byte *Smooth24              PARM((byte *, int, int, int, int, int,
8330-				  byte *, byte *, byte *));
8331+void BTSetActive           PARM((BUTT *, int));
8332+void BTRedraw              PARM((BUTT *));
8333+int  BTTrack               PARM((BUTT *));
8334
8335-byte *DoColorDither         PARM((byte *, byte *, int, int, byte *, byte *,
8336-				  byte *, byte *, byte *, byte *, int));
8337
8338-byte *Do332ColorDither      PARM((byte *, byte *, int, int, byte *, byte *,
8339-				  byte *, byte *, byte *, byte *, int));
8340+RBUTT *RBCreate            PARM((RBUTT *, Window, int, int, const char *,
8341+				 u_long, u_long, u_long, u_long));
8342
8343-/*************************** XV24TO8.C **************************/
8344-void Init24to8             PARM((void));
8345-byte *Conv24to8            PARM((byte *, int, int, int,
8346-				 byte *, byte *, byte *));
8347+void   RBRedraw            PARM((RBUTT *, int));
8348+void   RBSelect            PARM((RBUTT *, int));
8349+int    RBWhich             PARM((RBUTT *));
8350+int    RBCount             PARM((RBUTT *));
8351+void   RBSetActive         PARM((RBUTT *, int, int));
8352+int    RBClick             PARM((RBUTT *, int, int));
8353+int    RBTrack             PARM((RBUTT *, int));
8354+
8355+
8356+void   CBCreate            PARM((CBUTT *, Window, int, int, const char *,
8357+				 u_long, u_long, u_long, u_long));
8358+
8359+void   CBRedraw            PARM((CBUTT *));
8360+void   CBSetActive         PARM((CBUTT *, int));
8361+int    CBClick             PARM((CBUTT *,int,int));
8362+int    CBTrack             PARM((CBUTT *));
8363+
8364+
8365+void   MBCreate            PARM((MBUTT *, Window, int, int, u_int, u_int,
8366+				 const char *, const char * const *, int,
8367+				 u_long, u_long, u_long, u_long));
8368+
8369+void   MBRedraw            PARM((MBUTT *));
8370+void   MBSetActive         PARM((MBUTT *, int));
8371+int    MBWhich             PARM((MBUTT *));
8372+void   MBSelect            PARM((MBUTT *, int));
8373+int    MBClick             PARM((MBUTT *, int, int));
8374+int    MBTrack             PARM((MBUTT *));
8375+
8376+
8377+/*************************** XVCOLOR.C ***************************/
8378+void   SortColormap        PARM((byte *, int, int, int *, byte*,byte*,byte*,
8379+				 byte *, byte *));
8380+void   ColorCompress8      PARM((byte *));
8381+void   AllocColors         PARM((void));
8382+Status xvAllocColor        PARM((Display *, Colormap, XColor *));
8383+void   xvFreeColors        PARM((Display *, Colormap, u_long *, int, u_long));
8384+void   FreeColors          PARM((void));
8385+void   ApplyEditColor      PARM((int));
8386+int    MakeStdCmaps        PARM((void));
8387+void   MakeBrowCmap        PARM((void));
8388+void   ChangeCmapMode      PARM((int, int, int));
8389
8390-byte *Conv8to24            PARM((byte *, int, int, byte *, byte *, byte *));
8391
8392 /**************************** XVCTRL.C **************************/
8393-void   CreateCtrl          PARM((char *));
8394+void   CreateCtrl          PARM((const char *));
8395 void   SetButtPix          PARM((BUTT *, Pixmap, int, int));
8396 Pixmap MakePix1            PARM((Window, byte *, int, int));
8397
8398@@ -1337,7 +1608,7 @@
8399 void DrawCtrlStr           PARM((void));
8400 void ScrollToCurrent       PARM((LIST *));
8401
8402-void LSCreate              PARM((LIST *, Window, int, int, int, int, int,
8403+void LSCreate              PARM((LIST *, Window, int, int, int, int, int,
8404 				 char **, int, u_long, u_long, u_long, u_long,
8405 				 void (*)(int, SCRL *), int, int));
8406
8407@@ -1346,20 +1617,56 @@
8408 void LSChangeData          PARM((LIST *, char **, int));
8409 void LSNewData             PARM((LIST *, char **, int));
8410 void LSKey                 PARM((LIST *, int));
8411+int  rd_str_cl             PARM((const char *, const char *, int));
8412
8413
8414-/*************************** XVINFO.C ***************************/
8415-void  CreateInfo           PARM((char *));
8416-void  InfoBox              PARM((int));
8417-void  RedrawInfo           PARM((int, int, int, int));
8418-void  SetInfoMode          PARM((int));
8419-char *GetISTR              PARM((int));
8420+/**************************** XVCUT.C ***************************/
8421+int  CutAllowed            PARM((void));
8422+int  PasteAllowed          PARM((void));
8423+void DoImgCopy             PARM((void));
8424+void DoImgCut              PARM((void));
8425+void DoImgClear            PARM((void));
8426+void DoImgPaste            PARM((void));
8427
8428-#if defined(__STDC__) && !defined(NOSTDHDRS)
8429-void  SetISTR(int, ...);
8430-#else
8431-void  SetISTR();
8432-#endif
8433+void SaveToClip            PARM((byte *));
8434+void InitSelection         PARM((void));
8435+int  HaveSelection         PARM((void));
8436+int  GetSelType            PARM((void));
8437+void GetSelRCoords         PARM((int *, int *, int *, int *));
8438+void EnableSelection       PARM((int));
8439+void DrawSelection         PARM((int));
8440+int  DoSelection           PARM((XButtonEvent *));
8441+void MoveGrowSelection     PARM((int, int, int, int));
8442+void BlinkSelection        PARM((int));
8443+void FlashSelection        PARM((int));
8444+
8445+void CropRect2Rect         PARM((int*,int*,int*,int*, int,int,int,int));
8446+void CoordE2C              PARM((int, int, int *, int *));
8447+void CoordC2E              PARM((int, int, int *, int *));
8448+void CoordP2C              PARM((int, int, int *, int *));
8449+void CoordC2P              PARM((int, int, int *, int *));
8450+void CoordP2E              PARM((int, int, int *, int *));
8451+void CoordE2P              PARM((int, int, int *, int *));
8452+
8453+
8454+/*************************** XVDFLT.C ***************************/
8455+void LoadDfltPic           PARM((PICINFO *));
8456+void xbm2pic               PARM((byte *, int, int, byte *, int, int, int, int,
8457+				 int));
8458+void DrawStr2Pic           PARM((char *, int, int, byte *, int, int, int));
8459+
8460+
8461+/*************************** XVDIAL.C ***************************/
8462+void DCreate               PARM((DIAL *, Window, int, int, int, int,
8463+                                 double, double, double, double, double,
8464+                                 u_long, u_long, u_long, u_long,
8465+                                 const char *, const char *));
8466+
8467+void DSetRange             PARM((DIAL *, double,double,double,double,double));
8468+void DSetVal               PARM((DIAL *, double));
8469+void DSetActive            PARM((DIAL *, int));
8470+void DRedraw               PARM((DIAL *));
8471+int  DTrack                PARM((DIAL *, int, int));
8472
8473
8474 /**************************** XVDIR.C ***************************/
8475@@ -1376,15 +1683,15 @@
8476 void TrackDDirW            PARM((int,int));
8477 int  DirKey                PARM((int));
8478 int  DoSave                PARM((void));
8479-void SetDirFName           PARM((char *));
8480+void SetDirFName           PARM((const char *));
8481 char *GetDirFName          PARM((void));
8482 char *GetDirFullName       PARM((void));
8483 void SetDirSaveMode        PARM((int, int));
8484 int  Globify               PARM((char *));
8485-FILE *OpenOutFile          PARM((char *));
8486-int  CloseOutFile          PARM((FILE *, char *, int));
8487+FILE *OpenOutFile          PARM((const char *));
8488+int  CloseOutFile          PARM((FILE *, const char *, int));
8489
8490-byte *GenSavePic           PARM((int*, int*,int*, int*, int*,
8491+byte *GenSavePic           PARM((int*, int*,int*, int*, int*,
8492 				 byte**, byte**, byte**));
8493 void GetSaveSize           PARM((int *, int *));
8494
8495@@ -1392,47 +1699,30 @@
8496 int  CheckPoll             PARM((int));
8497 void DIRDeletedFile        PARM((char *));
8498 void DIRCreatedFile        PARM((char *));
8499+FILE *pic2_OpenOutFile     PARM((char *, int *));
8500+void pic2_KillNullFile     PARM((FILE *));
8501+int  OpenOutFileDesc       PARM((char *));
8502
8503
8504-/*************************** XVBROWSE.C ************************/
8505-void CreateBrowse          PARM((char *, char *, char *, char *, char *));
8506-void OpenBrowse            PARM((void));
8507-void HideBrowseWindows     PARM((void));
8508-void UnHideBrowseWindows   PARM((void));
8509-void SetBrowseCursor       PARM((Cursor));
8510-void KillBrowseWindows     PARM((void));
8511-int  BrowseCheckEvent      PARM((XEvent *, int *, int *));
8512-int  BrowseDelWin          PARM((Window));
8513-void SetBrowStr            PARM((char *));
8514-void RegenBrowseIcons      PARM((void));
8515-void BRDeletedFile         PARM((char *));
8516-void BRCreatedFile         PARM((char *));
8517-
8518-
8519-/*************************** XVTEXT.C ************************/
8520-void CreateTextWins        PARM((char *, char *));
8521-void TextView              PARM((char *));
8522-void OpenTextView          PARM((char *, int, char *, int));
8523-
8524-void OpenCommentText       PARM((void));
8525-void CloseCommentText      PARM((void));
8526-void ChangeCommentText     PARM((void));
8527-
8528-void ShowLicense           PARM((void));
8529-void ShowKeyHelp           PARM((void));
8530-
8531-void HideTextWindows       PARM((void));
8532-void UnHideTextWindows     PARM((void));
8533-void RaiseTextWindows      PARM((void));
8534-void SetTextCursor         PARM((Cursor));
8535-void KillTextWindows       PARM((void));
8536-int  TextCheckEvent        PARM((XEvent *, int *, int *));
8537-int  TextDelWin            PARM((Window));
8538+/****************************** XVEVENT.C ****************************/
8539+int  EventLoop             PARM((void));
8540+int  HandleEvent           PARM((XEvent *, int *));
8541
8542+void NewCutBuffer          PARM((char *));
8543+void DrawWindow            PARM((int,int,int,int));
8544+void WResize               PARM((int, int));
8545+void WRotate               PARM((void));
8546+void WCrop                 PARM((int, int, int, int));
8547+void WUnCrop               PARM((void));
8548+void GetWindowPos          PARM((XWindowAttributes *));
8549+void SetWindowPos          PARM((XWindowAttributes *));
8550+void SetEpicMode           PARM((void));
8551+int  xvErrorHandler        PARM((Display *, XErrorEvent *));
8552
8553
8554 /**************************** XVGAM.C **************************/
8555-void CreateGam             PARM((char *, double, double, double, double, int));
8556+void CreateGam             PARM((const char *, double, double, double, double,
8557+				 int));
8558 int  GamCheckEvent         PARM((XEvent *));
8559 void GamBox                PARM((int));
8560 void NewCMap               PARM((void));
8561@@ -1450,173 +1740,344 @@
8562 byte *GammifyPic24         PARM((byte *, int, int));
8563 void GamSetAutoApply       PARM((int));
8564
8565-/*************************** XVSCRL.C ***************************/
8566-void SCCreate              PARM((SCRL *, Window, int, int, int, int,
8567-				 int, int, int, int, u_long, u_long,
8568-				 u_long, u_long, void (*)(int, SCRL *)));
8569
8570-void SCChange              PARM((SCRL *, int, int, int, int, int,
8571-				 int, int, int));
8572+/**************************** XVGRAB.C ***************************/
8573+int Grab                   PARM((void));
8574+int LoadGrab               PARM((PICINFO *));
8575
8576-void SCSetRange            PARM((SCRL *, int, int, int, int));
8577-int  SCSetVal              PARM((SCRL *, int));
8578-void SCRedraw              PARM((SCRL *));
8579-void SCTrack               PARM((SCRL *, int, int));
8580
8581+/**************************** XVGRAF.C ***************************/
8582+void   CreateGraf          PARM((GRAF *, Window, int, int,
8583+				 u_long, u_long, const char *));
8584
8585-/*************************** XVDIAL.C ***************************/
8586-void DCreate               PARM((DIAL *, Window, int, int, int, int, int,
8587-				 int, int, int, u_long, u_long, u_long,
8588-				 u_long, char *, char *));
8589+void   InitGraf            PARM((GRAF *));
8590+void   RedrawGraf          PARM((GRAF *, int));
8591+int    ClickGraf           PARM((GRAF *, Window, int, int));
8592+int    GrafKey             PARM((GRAF *, char *));
8593+void   GenerateGrafFunc    PARM((GRAF *, int));
8594+void   Graf2Str            PARM((GRAF_STATE *, char *));
8595+int    Str2Graf            PARM((GRAF_STATE *, const char *));
8596+void   GetGrafState        PARM((GRAF *, GRAF_STATE *));
8597+int    SetGrafState        PARM((GRAF *, GRAF_STATE *));
8598+void   InitSpline          PARM((int *, int *, int, double *));
8599+double EvalSpline          PARM((int *, int *, double *, int, double));
8600
8601-void DSetRange             PARM((DIAL *, int, int, int, int));
8602-void DSetVal               PARM((DIAL *, int));
8603-void DSetActive            PARM((DIAL *, int));
8604-void DRedraw               PARM((DIAL *));
8605-int  DTrack                PARM((DIAL *, int, int));
8606
8607+/*************************** XVIMAGE.C ***************************/
8608+void Resize                PARM((int, int));
8609+void GenerateCpic          PARM((void));
8610+void GenerateEpic          PARM((int, int));
8611+void DoZoom                PARM((int, int, u_int));
8612+void Crop                  PARM((void));
8613+void UnCrop                PARM((void));
8614+void AutoCrop              PARM((void));
8615+int  DoAutoCrop            PARM((void));
8616+void DoCrop                PARM((int, int, int, int));
8617+void Rotate                PARM((int));
8618+void DoRotate              PARM((int));
8619+void RotatePic             PARM((byte *, int, int *, int *, int));
8620+void Flip                  PARM((int));
8621+void FlipPic               PARM((byte *, int, int, int));
8622+void InstallNewPic         PARM((void));
8623+void DrawEpic              PARM((void));
8624+void KillOldPics           PARM((void));
8625
8626-/**************************** XVBUTT.C ***************************/
8627-void BTCreate              PARM((BUTT *, Window, int, int, u_int, u_int,
8628-				 char *, u_long, u_long, u_long, u_long));
8629+byte *FSDither             PARM((byte *, int, int, int,
8630+				 byte *, byte *, byte *, int, int));
8631
8632-void BTSetActive           PARM((BUTT *, int));
8633-void BTRedraw              PARM((BUTT *));
8634-int  BTTrack               PARM((BUTT *));
8635+void CreateXImage          PARM((void));
8636+XImage *Pic8ToXImage       PARM((byte *, u_int, u_int, u_long *,
8637+				 byte *, byte *, byte *));
8638
8639+XImage *Pic24ToXImage      PARM((byte *, u_int, u_int));
8640
8641-RBUTT *RBCreate            PARM((RBUTT *, Window, int, int, char *,
8642-				 u_long, u_long, u_long, u_long));
8643+void Set824Menus           PARM((int));
8644+void Change824Mode         PARM((int));
8645+void FreeEpic              PARM((void));
8646+void InvertPic24           PARM((byte *, int, int));
8647
8648-void   RBRedraw            PARM((RBUTT *, int));
8649-void   RBSelect            PARM((RBUTT *, int));
8650-int    RBWhich             PARM((RBUTT *));
8651-int    RBCount             PARM((RBUTT *));
8652-void   RBSetActive         PARM((RBUTT *, int, int));
8653-int    RBClick             PARM((RBUTT *, int, int));
8654-int    RBTrack             PARM((RBUTT *, int));
8655+byte *XVGetSubImage        PARM((byte *, int, int,int, int,int,int,int));
8656
8657+int  DoPad                 PARM((int, char *, int, int, int, int));
8658+int  LoadPad               PARM((PICINFO *, char *));
8659
8660-void   CBCreate            PARM((CBUTT *, Window, int, int, char *,
8661-				 u_long, u_long, u_long, u_long));
8662
8663-void   CBRedraw            PARM((CBUTT *));
8664-void   CBSetActive         PARM((CBUTT *, int));
8665-int    CBClick             PARM((CBUTT *,int,int));
8666-int    CBTrack             PARM((CBUTT *));
8667+/*************************** XVINFO.C ***************************/
8668+void  CreateInfo           PARM((const char *));
8669+void  InfoBox              PARM((int));
8670+void  RedrawInfo           PARM((int, int, int, int));
8671+void  SetInfoMode          PARM((int));
8672+char *GetISTR              PARM((int));
8673
8674+#if defined(__STDC__) && !defined(NOSTDHDRS)
8675+void  SetISTR(int, ...);
8676+#else
8677+void  SetISTR();
8678+#endif
8679
8680-void   MBCreate            PARM((MBUTT *, Window, int, int, u_int, u_int,
8681-				 char *,
8682-				 char **, int,u_long,u_long, u_long, u_long));
8683
8684-void   MBRedraw            PARM((MBUTT *));
8685-void   MBSetActive         PARM((MBUTT *, int));
8686-int    MBWhich             PARM((MBUTT *));
8687-void   MBSelect            PARM((MBUTT *, int));
8688-int    MBClick             PARM((MBUTT *, int, int));
8689-int    MBTrack             PARM((MBUTT *));
8690+/*************************** XVMISC.C ***************************/
8691+void StoreDeleteWindowProp PARM((Window));
8692+Window CreateWindow        PARM((const char *, const char *, const char *,
8693+				 int, int, u_long, u_long, int));
8694+void DrawString            PARM((Window, int, int, const char *));
8695+void CenterString          PARM((Window, int, int, const char *));
8696+void ULineString           PARM((Window, int, int, const char *));
8697+int  StringWidth           PARM((const char *));
8698+int  CursorKey             PARM((KeySym, int, int));
8699+void FakeButtonPress       PARM((BUTT *));
8700+void FakeKeyPress          PARM((Window, KeySym));
8701+void GenExpose             PARM((Window, int, int, u_int, u_int));
8702+void DimRect               PARM((Window, int, int, u_int, u_int, u_long));
8703+
8704+void Draw3dRect            PARM((Window, int, int, u_int, u_int, int, int,
8705+				 u_long, u_long, u_long));
8706+
8707+void RemapKeyCheck         PARM((KeySym, char *, int *));
8708+void xvDestroyImage        PARM((XImage *));
8709+void SetCropString         PARM((void));
8710+void SetSelectionString    PARM((void));
8711+void Warning               PARM((void));
8712+void FatalError            PARM((const char *));
8713+void Quit                  PARM((int));
8714+void LoadFishCursors       PARM((void));
8715+void WaitCursor            PARM((void));
8716+void SetCursors            PARM((int));
8717+const char *BaseName       PARM((const char *));
8718+
8719+void DrawTempGauge         PARM((Window, int, int, int, int, double, u_long,
8720+				 u_long, u_long, u_long, const char *));
8721+void ProgressMeter         PARM((int, int, int, const char *));
8722+void XVDeletedFile         PARM((char *));
8723+void XVCreatedFile         PARM((char *));
8724+void xvbcopy               PARM((const char *, char *, size_t));
8725+int  xvbcmp                PARM((const char *, const char *, size_t));
8726+void xvbzero               PARM((char *, size_t));
8727+void xv_getwd              PARM((char *, size_t));
8728+char *xv_strstr            PARM((const char *, const char *));
8729+FILE *xv_fopen             PARM((const char *, const char *));
8730+void xv_mktemp             PARM((char *, const char *));
8731+void Timer                 PARM((int));
8732
8733
8734-/**************************** XVGRAF.C ***************************/
8735-void   CreateGraf          PARM((GRAF *, Window, int, int,
8736-				 u_long, u_long, char *));
8737+/*************************** XVPOPUP.C ***************************/
8738+void  CenterMapWindow      PARM((Window, int, int, int, int));
8739+int   PopUp                PARM((const char *, const char **, int));
8740+void  ErrPopUp             PARM((const char *, const char *));
8741+int   GetStrPopUp          PARM((const char *, const char **, int, char *, int,
8742+				 const char *, int));
8743+int   GrabPopUp            PARM((int *, int *));
8744+int   PadPopUp             PARM((int *, char **, int *, int *, int *, int *));
8745+void  ClosePopUp           PARM((void));
8746+void  OpenAlert            PARM((const char *));
8747+void  CloseAlert           PARM((void));
8748+int   PUCheckEvent         PARM((XEvent *));
8749
8750-void   InitGraf            PARM((GRAF *));
8751-void   RedrawGraf          PARM((GRAF *, int));
8752-int    ClickGraf           PARM((GRAF *, Window, int, int));
8753-int    GrafKey             PARM((GRAF *, char *));
8754-void   GenerateGrafFunc    PARM((GRAF *, int));
8755-void   Graf2Str            PARM((GRAF_STATE *, char *));
8756-int    Str2Graf            PARM((GRAF_STATE *, char *));
8757-void   GetGrafState        PARM((GRAF *, GRAF_STATE *));
8758-int    SetGrafState        PARM((GRAF *, GRAF_STATE *));
8759-void   InitSpline          PARM((int *, int *, int, double *));
8760-double EvalSpline          PARM((int *, int *, double *, int, double));
8761
8762+/**************************** XVROOT.C ****************************/
8763+void MakeRootPic           PARM((void));
8764+void ClearRoot             PARM((void));
8765+void SaveRootInfo          PARM((void));
8766+void KillOldRootInfo       PARM((void));
8767
8768-/**************************** XVGIF.C ***************************/
8769-int LoadGIF                PARM((char *, PICINFO *));
8770
8771-/*************************** XVGIFWR.C **************************/
8772-int WriteGIF               PARM((FILE *, byte *, int, int, int,
8773-				 byte *, byte *, byte *, int, int, char *));
8774+/*************************** XVSCRL.C ***************************/
8775+void SCCreate              PARM((SCRL *, Window, int, int, int, int,
8776+				 int, int, int, int, u_long, u_long,
8777+				 u_long, u_long, void (*)(int, SCRL *)));
8778
8779-/**************************** XVPM.C ****************************/
8780-int LoadPM                 PARM((char *, PICINFO *));
8781-int WritePM                PARM((FILE *, byte *, int, int, int, byte *,
8782-				 byte *, byte *, int, int, char *));
8783+void SCChange              PARM((SCRL *, int, int, int, int, int,
8784+				 int, int, int));
8785
8786-/**************************** XVPBM.C ***************************/
8787-int LoadPBM                PARM((char *, PICINFO *));
8788-int WritePBM               PARM((FILE *, byte *, int, int, int, byte *,
8789-				 byte *, byte *, int, int, int, char *));
8790+void SCSetRange            PARM((SCRL *, int, int, int, int));
8791+int  SCSetVal              PARM((SCRL *, int));
8792+void SCRedraw              PARM((SCRL *));
8793+void SCTrack               PARM((SCRL *, int, int));
8794
8795-/**************************** XVXBM.C ***************************/
8796-int LoadXBM                PARM((char *, PICINFO *));
8797-int WriteXBM               PARM((FILE *, byte *, int, int, byte *, byte *,
8798-				 byte *, char *));
8799
8800-/**************************** XVSUNRAS.C ***************************/
8801-int LoadSunRas             PARM((char *, PICINFO *));
8802-int WriteSunRas            PARM((FILE *, byte *, int, int, int, byte *,
8803-				 byte *, byte*, int, int, int));
8804+/*************************** XVSMOOTH.C ***************************/
8805+byte *SmoothResize         PARM((byte *, int, int, int, int, byte *, byte *,
8806+				 byte *, byte *, byte *, byte *, int));
8807
8808-/**************************** XVBMP.C ***************************/
8809-int LoadBMP                PARM((char *, PICINFO *));
8810-int WriteBMP               PARM((FILE *, byte *, int, int, int, byte *,
8811-				 byte *, byte *, int, int));
8812+byte *Smooth24             PARM((byte *, int, int, int, int, int,
8813+				 byte *, byte *, byte *));
8814
8815-/**************************** XVRLE.C ***************************/
8816-int LoadRLE                PARM((char *, PICINFO *));
8817+byte *DoColorDither        PARM((byte *, byte *, int, int, byte *, byte *,
8818+				 byte *, byte *, byte *, byte *, int));
8819
8820-/**************************** XVIRIS.C ***************************/
8821-int LoadIRIS               PARM((char *, PICINFO *));
8822-int WriteIRIS              PARM((FILE *, byte *, int, int, int, byte *,
8823-				 byte *, byte *, int, int));
8824+byte *Do332ColorDither     PARM((byte *, byte *, int, int, byte *, byte *,
8825+				 byte *, byte *, byte *, byte *, int));
8826
8827-/**************************** XVPCX.C ***************************/
8828-int LoadPCX                PARM((char *, PICINFO *));
8829
8830-/**************************** XVIFF.C ***************************/
8831-int LoadIFF                PARM((char *, PICINFO *));
8832+/*************************** XVTEXT.C ************************/
8833+void CreateTextWins        PARM((const char *, const char *));
8834+int  TextView              PARM((const char *));
8835+void OpenTextView          PARM((const char *, int, const char *, int));
8836
8837-/**************************** XVTARGA.C ***************************/
8838-int LoadTarga              PARM((char *, PICINFO *));
8839-int WriteTarga             PARM((FILE *, byte *, int, int, int, byte *,
8840-				 byte *, byte *, int, int));
8841+void OpenCommentText       PARM((void));
8842+void CloseCommentText      PARM((void));
8843+void ChangeCommentText     PARM((void));
8844
8845-/**************************** XVXPM.C ***************************/
8846-int LoadXPM                PARM((char *, PICINFO *));
8847-int WriteXPM               PARM((FILE *, byte *, int, int, int, byte *,
8848-				 byte *, byte *, int, int, char *, char *));
8849+void ShowLicense           PARM((void));
8850+void ShowKeyHelp           PARM((void));
8851
8852-/**************************** XVXWD.C ***************************/
8853-int LoadXWD                PARM((char *, PICINFO *));
8854+void HideTextWindows       PARM((void));
8855+void UnHideTextWindows     PARM((void));
8856+void RaiseTextWindows      PARM((void));
8857+void SetTextCursor         PARM((Cursor));
8858+void KillTextWindows       PARM((void));
8859+int  TextCheckEvent        PARM((XEvent *, int *, int *));
8860+int  TextDelWin            PARM((Window));
8861+
8862+int  CharsetCheckEvent     PARM((XEvent *));
8863+int  CharsetDelWin         PARM((Window));
8864+
8865+
8866+/**************************** XVVD.C ****************************/
8867+void  Vdinit               PARM((void));
8868+void  Vdsettle             PARM((void));
8869+int   Chvdir               PARM((char *));
8870+void  Dirtovd              PARM((char *));
8871+void  Vdtodir              PARM((char *));
8872+void  Dirtosubst           PARM((char *));
8873+int   Mkvdir               PARM((char *));
8874+void  Mkvdir_force         PARM((char *));
8875+int   Rmvdir               PARM((char *));
8876+int   Movevdir             PARM((char *, char *));
8877+int   Isarchive            PARM((char *));
8878+int   Isvdir               PARM((char *));
8879+void  vd_HUPhandler        PARM((void));
8880+void  vd_handler           PARM((int));
8881+int   vd_Xhandler          PARM((Display *, XErrorEvent *));
8882+int   vd_XIOhandler        PARM((Display *));
8883+void  vd_handler_setup     PARM((void));
8884+
8885+
8886+
8887+/*=======================================================================*/
8888+/*                             IMAGE FORMATS                             */
8889+/*=======================================================================*/
8890+
8891+/**************************** XVBMP.C ***************************/
8892+int LoadBMP                PARM((char *, PICINFO *));
8893+int WriteBMP               PARM((FILE *, byte *, int, int, int, byte *,
8894+				 byte *, byte *, int, int));
8895
8896 /**************************** XVFITS.C ***************************/
8897 int LoadFITS               PARM((char *, PICINFO *, int));
8898 int WriteFITS              PARM((FILE *, byte *, int, int, int, byte *,
8899 				 byte *, byte *, int, int, char *));
8900
8901+/**************************** XVGIF.C ***************************/
8902+int LoadGIF                PARM((char *, PICINFO *));
8903+
8904+/**************************** XVGIFWR.C **************************/
8905+int WriteGIF               PARM((FILE *, byte *, int, int, int,
8906+				 byte *, byte *, byte *, int, int, char *));
8907+
8908+/**************************** XVHIPS.C ***************************/
8909+int   LoadHIPS             PARM((char *, PICINFO *));
8910+
8911+/**************************** XVIFF.C ***************************/
8912+int LoadIFF                PARM((char *, PICINFO *));
8913+
8914+/**************************** XVIRIS.C ***************************/
8915+int LoadIRIS               PARM((char *, PICINFO *));
8916+int WriteIRIS              PARM((FILE *, byte *, int, int, int, byte *,
8917+				 byte *, byte *, int, int));
8918+
8919+/**************************** XVJP2K.C ***************************/
8920+int  LoadJPC               PARM((char *, register PICINFO *, int));
8921+int  LoadJP2               PARM((char *, register PICINFO *, int));
8922+void CreateJP2KW           PARM((void));
8923+void JP2KSaveParams        PARM((int, char *, int));
8924+void JP2KDialog            PARM((int vis));
8925+int  JP2KCheckEvent        PARM((register XEvent *));
8926+void VersionInfoJP2K       PARM((void));		/* GRR 20070304 */
8927+
8928 /**************************** XVJPEG.C ***************************/
8929 int  LoadJFIF              PARM((char *, PICINFO *, int));
8930 void CreateJPEGW           PARM((void));
8931 void JPEGDialog            PARM((int));
8932 int  JPEGCheckEvent        PARM((XEvent *));
8933 void JPEGSaveParams        PARM((char *, int));
8934+void VersionInfoJPEG       PARM((void));		/* GRR 19980605 */
8935
8936-/**************************** XVTIFF.C ***************************/
8937-int   LoadTIFF             PARM((char *, PICINFO *));
8938-void  CreateTIFFW          PARM((void));
8939-void  TIFFDialog           PARM((int));
8940-int   TIFFCheckEvent       PARM((XEvent *));
8941-void  TIFFSaveParams       PARM((char *, int));
8942+/**************************** XVMAG.C ***************************/
8943+int   LoadMAG              PARM((char *, PICINFO *));
8944+int   WriteMAG             PARM((FILE *, byte *, int, int, int,
8945+				 byte *, byte *, byte *, int, int, char *));
8946+
8947+/**************************** XVMAKI.C ***************************/
8948+int   LoadMAKI             PARM((char *, PICINFO *));
8949+int   WriteMAKI            PARM((FILE *, byte *, int, int, int,
8950+				 byte *, byte *, byte *, int, int));
8951+
8952+/**************************** XVMGCSFX.C ***************************/
8953+int   is_mgcsfx            PARM((char *, unsigned char *, int));
8954+char *mgcsfx_auto_input_com PARM((char *));
8955+int   LoadMGCSFX           PARM((char *, PICINFO *));
8956+void  CreateMGCSFXW        PARM((void));
8957+void  MGCSFXDialog         PARM((int));
8958+int   MGCSFXCheckEvent     PARM((XEvent *));
8959+int   MGCSFXSaveParams     PARM((char *, int));
8960+
8961+int getInputCom            PARM((void));
8962+int getOutputCom           PARM((void));
8963+
8964+/**************************** XVPBM.C ***************************/
8965+#ifdef HAVE_MGCSFX
8966+int LoadPBM                PARM((char *, PICINFO *, int));
8967+#else
8968+int LoadPBM                PARM((char *, PICINFO *));
8969+#endif
8970+int WritePBM               PARM((FILE *, byte *, int, int, int, byte *,
8971+				 byte *, byte *, int, int, int, char *));
8972+
8973+/**************************** XVPCD.C ***************************/
8974+int   LoadPCD              PARM((char *, PICINFO *, int));
8975+void  CreatePCDW           PARM((void));
8976+void  PCDDialog            PARM((int));
8977+int   PCDCheckEvent        PARM((XEvent *));
8978+void  PCDSetParamOptions   PARM((const char *));
8979+
8980+/**************************** XVPCX.C ***************************/
8981+int LoadPCX                PARM((char *, PICINFO *));
8982
8983 /**************************** XVPDS.C ***************************/
8984 int LoadPDS                PARM((char *, PICINFO *));
8985
8986-/*************************** XVPS.C ***************************/
8987+/**************************** XVPI.C ***************************/
8988+int   LoadPi               PARM((char *, PICINFO *));
8989+int   WritePi              PARM((FILE *, byte *, int, int, int,
8990+				 byte *, byte *, byte *, int, int, char *));
8991+
8992+/**************************** XVPIC.C ***************************/
8993+int   LoadPIC              PARM((char *, PICINFO *));
8994+int   WritePIC             PARM((FILE *, byte *, int, int, int,
8995+				 byte *, byte *, byte *, int, int, char *));
8996+
8997+/**************************** XVPIC2.C ***************************/
8998+int   LoadPIC2             PARM((char *, PICINFO *, int));
8999+void  CreatePIC2W          PARM((void));
9000+void  PIC2Dialog           PARM((int));
9001+int   PIC2CheckEvent       PARM((XEvent *));
9002+int   PIC2SetParamOptions  PARM((char *));
9003+
9004+/**************************** XVPM.C ****************************/
9005+int LoadPM                 PARM((char *, PICINFO *));
9006+int WritePM                PARM((FILE *, byte *, int, int, int, byte *,
9007+				 byte *, byte *, int, int, char *));
9008+
9009+/**************************** XVPNG.C ***************************/
9010+int  LoadPNG               PARM((char *, PICINFO *));
9011+void CreatePNGW            PARM((void));
9012+void PNGDialog             PARM((int));
9013+int  PNGCheckEvent         PARM((XEvent *));
9014+void PNGSaveParams         PARM((char *, int));
9015+void VersionInfoPNG        PARM((void));		/* GRR 19980605 */
9016+
9017+/**************************** XVPS.C ****************************/
9018 void  CreatePSD            PARM((char *));
9019 void  PSDialog             PARM((int));
9020 int   PSCheckEvent         PARM((XEvent *));
9021@@ -1624,56 +2085,46 @@
9022 void  PSResize             PARM((void));
9023 int   LoadPS               PARM((char *, PICINFO *, int));
9024
9025-/*************************** XVPOPUP.C ***************************/
9026-void  CenterMapWindow      PARM((Window, int, int, int, int));
9027-int   PopUp                PARM((char *, char **, int));
9028-void  ErrPopUp             PARM((char *, char *));
9029-int   GetStrPopUp          PARM((char *, char **, int, char *, int,
9030-				 char *, int));
9031-int   GrabPopUp            PARM((int *, int *));
9032-int   PadPopUp             PARM((int *, char **, int *, int *, int *, int *));
9033-void  ClosePopUp           PARM((void));
9034-void  OpenAlert            PARM((char *));
9035-void  CloseAlert           PARM((void));
9036-int   PUCheckEvent         PARM((XEvent *));
9037-void  TextRect             PARM((Window, char *, int, int, int, int, u_long));
9038+/**************************** XVRLE.C ***************************/
9039+int LoadRLE                PARM((char *, PICINFO *));
9040
9041-/*************************** XVDFLT.C ***************************/
9042-void LoadDfltPic           PARM((PICINFO *));
9043-void xbm2pic               PARM((byte *, int, int, byte *, int, int, int, int,
9044-				 int));
9045-void DrawStr2Pic           PARM((char *, int, int, byte *, int, int, int));
9046+/**************************** XVSUNRAS.C ***************************/
9047+int LoadSunRas             PARM((char *, PICINFO *));
9048+int WriteSunRas            PARM((FILE *, byte *, int, int, int, byte *,
9049+				 byte *, byte*, int, int, int));
9050
9051-/**************************** XVGRAB.C ***************************/
9052-int Grab                   PARM((void));
9053-int LoadGrab               PARM((PICINFO *));
9054+/**************************** XVTARGA.C ***************************/
9055+int LoadTarga              PARM((char *, PICINFO *));
9056+int WriteTarga             PARM((FILE *, byte *, int, int, int, byte *,
9057+				 byte *, byte *, int, int));
9058
9059+/**************************** XVTIFF.C ***************************/
9060+int   LoadTIFF             PARM((char *, PICINFO *, int));
9061+void  CreateTIFFW          PARM((void));
9062+void  TIFFDialog           PARM((int));
9063+int   TIFFCheckEvent       PARM((XEvent *));
9064+void  TIFFSaveParams       PARM((char *, int));
9065+void  VersionInfoTIFF      PARM((void));		/* GRR 19980605 */
9066
9067-/**************************** XVCUT.C ***************************/
9068-int  CutAllowed            PARM((void));
9069-int  PasteAllowed          PARM((void));
9070-void DoImgCopy             PARM((void));
9071-void DoImgCut              PARM((void));
9072-void DoImgClear            PARM((void));
9073-void DoImgPaste            PARM((void));
9074+/**************************** XVWBMP.C ***************************/
9075+int LoadWBMP               PARM((char *, PICINFO *));
9076+int WriteWBMP              PARM((FILE *, byte *, int, int, int, byte *,
9077+				 byte *, byte *, int, int));
9078
9079-void SaveToClip            PARM((byte *));
9080-void InitSelection         PARM((void));
9081-int  HaveSelection         PARM((void));
9082-int  GetSelType            PARM((void));
9083-void GetSelRCoords         PARM((int *, int *, int *, int *));
9084-void EnableSelection       PARM((int));
9085-void DrawSelection         PARM((int));
9086-int  DoSelection           PARM((XButtonEvent *));
9087-void MoveGrowSelection     PARM((int, int, int, int));
9088-void BlinkSelection        PARM((int));
9089-void FlashSelection        PARM((int));
9090+/**************************** XVXBM.C ***************************/
9091+int LoadXBM                PARM((char *, PICINFO *));
9092+int WriteXBM               PARM((FILE *, byte *, int, int, byte *, byte *,
9093+				 byte *, char *));
9094
9095-void CropRect2Rect         PARM((int*,int*,int*,int*, int,int,int,int));
9096-void CoordE2C              PARM((int, int, int *, int *));
9097-void CoordC2E              PARM((int, int, int *, int *));
9098-void CoordP2C              PARM((int, int, int *, int *));
9099-void CoordC2P              PARM((int, int, int *, int *));
9100-void CoordP2E              PARM((int, int, int *, int *));
9101-void CoordE2P              PARM((int, int, int *, int *));
9102+/**************************** XVXPM.C ***************************/
9103+int LoadXPM                PARM((char *, PICINFO *));
9104+int WriteXPM               PARM((FILE *, byte *, int, int, int, byte *,
9105+				 byte *, byte *, int, int, char *, char *));
9106
9107+/**************************** XVXWD.C ***************************/
9108+int LoadXWD                PARM((char *, PICINFO *));
9109+
9110+/**************************** XVZX.C [JCE] **********************/
9111+int LoadZX                 PARM((char *, PICINFO *));
9112+int WriteZX                PARM((FILE *, byte *, int, int, int, byte *,
9113+				 byte *, byte *, int, int, char *));
9114diff -ru xv-3.10a/xv24to8.c xv-3.10a-enhancements/xv24to8.c
9115--- xv-3.10a/xv24to8.c	1995-01-13 11:49:21.000000000 -0800
9116+++ xv-3.10a-enhancements/xv24to8.c	2007-05-12 13:56:44.000000000 -0700
9117@@ -14,15 +14,15 @@
9118  *
9119  * The Conv24to8 procedure will set up the following:  it will allocate, make
9120  * & return 'pic8', a 'w' by 'h' (passed in values) 8-bit picture.
9121- * it will load up the rmap, gmap and bmap colormap arrays.  it will NOT
9122+ * it will load up the rmap, gmap and bmap colormap arrays.  it will NOT
9123  * calculate numcols, since the cmap sort procedure has to be called anyway
9124  *
9125- * Conv24to8 returns 'pic8' if successful, 'NULL' on failure (presumably on a
9126+ * Conv24to8 returns 'pic8' if successful, 'NULL' on failure (presumably on a
9127  * malloc())
9128  *
9129- * The 'slow' code, while still based on Heckbert's Median Cut algorithm,
9130+ * The 'slow' code, while still based on Heckbert's Median Cut algorithm,
9131  * has been shamelessly lifted from the Independent JPEG Group's software
9132- * (jquant2.c), as (for a variety of reasons) theirs was far better than
9133+ * (jquant2.c), as (for a variety of reasons) theirs was far better than
9134  * the version I was previously using.  Thanks guys!
9135  *
9136  * Also, as is my way, I've stripped out most of the IJG's well-written
9137@@ -65,10 +65,10 @@
9138 {
9139   /* returns pointer to new 8-bit-per-pixel image (w*h) if successful, or
9140      NULL if unsuccessful */
9141-
9142+
9143   int   i;
9144   byte *pic8;
9145-
9146+
9147   if (!pic24) return NULL;
9148
9149   pic8 = (byte *) malloc((size_t) (w * h));
9150@@ -79,9 +79,9 @@
9151
9152   if (nc<=0) nc = 255;  /* 'nc == 0' breaks code */
9153
9154-  if (!noqcheck && quick_check(pic24, w,h, pic8, rm,gm,bm, nc)) {
9155+  if (!noqcheck && quick_check(pic24, w,h, pic8, rm,gm,bm, nc)) {
9156     SetISTR(ISTR_INFO,"No color compression was necessary.\n");
9157-    return pic8;
9158+    return pic8;
9159   }
9160
9161   switch (conv24) {
9162@@ -89,19 +89,19 @@
9163     SetISTR(ISTR_INFO,"Doing 'quick' 24-bit to 8-bit conversion.");
9164     i = quick_quant(pic24, w, h, pic8, rm, gm, bm, nc);
9165     break;
9166-
9167+
9168   case CONV24_BEST:
9169     SetISTR(ISTR_INFO,"Doing 'best' 24-bit to 8-bit conversion.");
9170     i = ppm_quant(pic24, w, h, pic8, rm, gm, bm, nc);
9171     break;
9172-
9173+
9174   case CONV24_SLOW:
9175   default:
9176     SetISTR(ISTR_INFO,"Doing 'slow' 24-bit to 8-bit conversion.");
9177     i = slow_quant(pic24, w, h, pic8, rm, gm, bm, nc);
9178     break;
9179   }
9180-
9181+
9182   if (i) { free(pic8);  pic8 = NULL; }
9183   return pic8;
9184 }
9185@@ -134,7 +134,7 @@
9186
9187   return pic24;
9188 }
9189-
9190+
9191
9192 /****************************/
9193 static int quick_check(pic24, w,h, pic8, rmap,gmap,bmap, maxcol)
9194@@ -154,10 +154,10 @@
9195   if (maxcol>256) maxcol = 256;
9196
9197   /* put the first color in the table by hand */
9198-  nc = 0;  mid = 0;
9199+  nc = 0;  mid = 0;
9200
9201   for (i=w*h,p=pic24; i; i--) {
9202-    col  = (((u_long) *p++) << 16);
9203+    col  = (((u_long) *p++) << 16);
9204     col += (((u_long) *p++) << 8);
9205     col +=  *p++;
9206
9207@@ -184,7 +184,7 @@
9208      pic24 into colormap offsets into 'colors' */
9209
9210   for (i=w*h,p=pic24, pix=pic8; i; i--,pix++) {
9211-    col  = (((u_long) *p++) << 16);
9212+    col  = (((u_long) *p++) << 16);
9213     col += (((u_long) *p++) << 8);
9214     col +=  *p++;
9215
9216@@ -206,7 +206,7 @@
9217
9218   /* and load up the 'desired colormap' */
9219   for (i=0; i<nc; i++) {
9220-    rmap[i] =  colors[i]>>16;
9221+    rmap[i] =  colors[i]>>16;
9222     gmap[i] = (colors[i]>>8) & 0xff;
9223     bmap[i] =  colors[i]     & 0xff;
9224   }
9225@@ -224,7 +224,7 @@
9226 {
9227   /* called after 'pic8' has been alloced, pWIDE,pHIGH set up, mono/1-bit
9228      checked already */
9229-
9230+
9231 /* up to 256 colors:     3 bits R, 3 bits G, 2 bits B  (RRRGGGBB) */
9232 #define RMASK      0xe0
9233 #define RSHIFT        0
9234@@ -252,7 +252,7 @@
9235     gmap[i] = (((i<<GSHIFT) & GMASK) * 255 + GMASK/2) / GMASK;
9236     bmap[i] = (((i<<BSHIFT) & BMASK) * 255 + BMASK/2) / BMASK;
9237   }
9238-
9239+
9240
9241   thisline = (int *) malloc(pwide3 * sizeof(int));
9242   nextline = (int *) malloc(pwide3 * sizeof(int));
9243@@ -262,40 +262,40 @@
9244     fprintf(stderr,"%s: unable to allocate memory in quick_quant()\n", cmd);
9245     return(1);
9246   }
9247-
9248+
9249   /* get first line of picture */
9250   for (j=pwide3, tmpptr=nextline; j; j--) *tmpptr++ = (int) *p24++;
9251-
9252+
9253   for (i=0; i<h; i++) {
9254     tmpptr = thisline;  thisline = nextline;  nextline = tmpptr;   /* swap */
9255-
9256+
9257     if ((i&0x3f) == 0) WaitCursor();
9258
9259     if (i!=imax)   /* get next line */
9260       for (j=pwide3, tmpptr=nextline; j; j--)
9261 	*tmpptr++ = (int) *p24++;
9262-
9263+
9264     for (j=0, thisptr=thisline, nextptr=nextline; j<w; j++,pp++) {
9265       r1 = *thisptr++;  g1 = *thisptr++;  b1 = *thisptr++;
9266-      RANGE(r1,0,255);  RANGE(g1,0,255);  RANGE(b1,0,255);
9267-
9268+      RANGE(r1,0,255);  RANGE(g1,0,255);  RANGE(b1,0,255);
9269+
9270       /* choose actual pixel value */
9271-      val = (((r1&RMASK)>>RSHIFT) | ((g1&GMASK)>>GSHIFT) |
9272+      val = (((r1&RMASK)>>RSHIFT) | ((g1&GMASK)>>GSHIFT) |
9273 	     ((b1&BMASK)>>BSHIFT));
9274       *pp = val;
9275-
9276+
9277       /* compute color errors */
9278       r1 -= rmap[val];
9279       g1 -= gmap[val];
9280       b1 -= bmap[val];
9281-
9282+
9283       /* Add fractions of errors to adjacent pixels */
9284       if (j!=jmax) {  /* adjust RIGHT pixel */
9285 	thisptr[0] += (r1*7) / 16;
9286 	thisptr[1] += (g1*7) / 16;
9287 	thisptr[2] += (b1*7) / 16;
9288       }
9289-
9290+
9291       if (i!=imax) {	/* do BOTTOM pixel */
9292 	nextptr[0] += (r1*5) / 16;
9293 	nextptr[1] += (g1*5) / 16;
9294@@ -316,7 +316,7 @@
9295       }
9296     }
9297   }
9298-
9299+
9300   free(thisline);
9301   free(nextline);
9302   return 0;
9303@@ -329,7 +329,7 @@
9304 #undef BMASK
9305 #undef BSHIFT
9306 }
9307-
9308+
9309
9310
9311
9312@@ -381,7 +381,7 @@
9313
9314 /* Luminance macro. */
9315
9316-/*
9317+/*
9318  * #define PPM_LUMIN(p) \
9319  *   ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
9320  */
9321@@ -449,18 +449,18 @@
9322      byte *pic24, *pic8, *rmap, *gmap, *bmap;
9323      int  cols, rows, newcolors;
9324 {
9325-  pixel**          pixels;
9326-  register pixel*  pP;
9327-  int              row;
9328-  register int     col, limitcol;
9329-  pixval           maxval, newmaxval;
9330-  int              colors;
9331-  register int     index;
9332-  chist_vec chv, colormap;
9333-  chash_table  cht;
9334-  int              i;
9335-  unsigned char    *picptr;
9336-  static char      *fn = "ppmquant()";
9337+  pixel**           pixels;
9338+  register pixel*   pP;
9339+  int               row;
9340+  register int      col, limitcol;
9341+  pixval            maxval, newmaxval;
9342+  int               colors;
9343+  register int      index;
9344+  chist_vec         chv, colormap;
9345+  chash_table       cht;
9346+  int               i;
9347+  unsigned char     *picptr;
9348+  static const char *fn = "ppmquant()";
9349
9350   index = 0;
9351   maxval = 255;
9352@@ -472,7 +472,7 @@
9353
9354   if (DEBUG) fprintf(stderr,"%s: remapping to ppm-style internal fmt\n", fn);
9355   WaitCursor();
9356-
9357+
9358   pixels = (pixel **) malloc(rows * sizeof(pixel *));
9359   if (!pixels) FatalError("couldn't allocate 'pixels' array");
9360   for (row=0; row<rows; row++) {
9361@@ -488,7 +488,7 @@
9362   if (DEBUG) fprintf(stderr,"%s: done format remapping\n", fn);
9363
9364
9365-
9366+
9367
9368   /*
9369    *  attempt to make a histogram of the colors, unclustered.
9370@@ -503,7 +503,7 @@
9371
9372     chv = ppm_computechist(pixels, cols, rows, MAXCOLORS, &colors);
9373     if (chv != (chist_vec) 0) break;
9374-
9375+
9376     if (DEBUG) fprintf(stderr, "%s: too many colors!\n", fn);
9377     newmaxval = maxval / 2;
9378     if (DEBUG) fprintf(stderr, "%s: rescaling colors (maxval=%d) %s\n",
9379@@ -635,7 +635,7 @@
9380   int boxes;
9381
9382   bv = (box_vector) malloc(sizeof(struct box) * newcolors);
9383-  colormap = (chist_vec)
9384+  colormap = (chist_vec)
9385              malloc(sizeof(struct chist_item) * newcolors );
9386
9387   if (!bv || !colormap) FatalError("unable to malloc in mediancut()");
9388@@ -723,7 +723,7 @@
9389       else if (gl >= bl)
9390 	qsort((char*) &(chv[indx]), (size_t) clrs, sizeof(struct chist_item),
9391 	      greencompare );
9392-      else
9393+      else
9394 	qsort((char*) &(chv[indx]), (size_t) clrs, sizeof(struct chist_item),
9395 	      bluecompare );
9396     }
9397@@ -750,7 +750,7 @@
9398     ++boxes;
9399     qsort((char*) bv, (size_t) boxes, sizeof(struct box), sumcompare);
9400   }  /* while (boxes ... */
9401-
9402+
9403   /*
9404    ** Ok, we've got enough boxes.  Now choose a representative color for
9405    ** each box.  There are a number of possible ways to make this choice.
9406@@ -761,7 +761,7 @@
9407    ** method is used by switching the commenting on the REP_ defines at
9408    ** the beginning of this source file.
9409    */
9410-
9411+
9412   for (bi=0; bi<boxes; bi++) {
9413     /* REP_AVERAGE_PIXELS version */
9414     register int indx = bv[bi].index;
9415@@ -791,7 +791,7 @@
9416 static int redcompare(p1, p2)
9417      const void *p1, *p2;
9418 {
9419-  return (int) PPM_GETR( ((chist_vec)p1)->color ) -
9420+  return (int) PPM_GETR( ((chist_vec)p1)->color ) -
9421          (int) PPM_GETR( ((chist_vec)p2)->color );
9422 }
9423
9424@@ -799,7 +799,7 @@
9425 static int greencompare(p1, p2)
9426      const void *p1, *p2;
9427 {
9428-  return (int) PPM_GETG( ((chist_vec)p1)->color ) -
9429+  return (int) PPM_GETG( ((chist_vec)p1)->color ) -
9430          (int) PPM_GETG( ((chist_vec)p2)->color );
9431 }
9432
9433@@ -807,7 +807,7 @@
9434 static int bluecompare(p1, p2)
9435      const void *p1, *p2;
9436 {
9437-  return (int) PPM_GETB( ((chist_vec)p1)->color ) -
9438+  return (int) PPM_GETB( ((chist_vec)p1)->color ) -
9439          (int) PPM_GETB( ((chist_vec)p2)->color );
9440 }
9441
9442@@ -821,7 +821,7 @@
9443
9444
9445 /****************************************************************************/
9446-static chist_vec
9447+static chist_vec
9448   ppm_computechist(pixels, cols, rows, maxcolors, colorsP)
9449      pixel** pixels;
9450      int cols, rows, maxcolors;
9451@@ -840,7 +840,7 @@
9452
9453
9454 /****************************************************************************/
9455-static chash_table ppm_computechash(pixels, cols, rows,
9456+static chash_table ppm_computechash(pixels, cols, rows,
9457 					    maxcolors, colorsP )
9458      pixel** pixels;
9459      int cols, rows, maxcolors;
9460@@ -861,14 +861,14 @@
9461
9462       for (chl = cht[hash]; chl != (chist_list) 0; chl = chl->next)
9463 	if (PPM_EQUAL(chl->ch.color, *pP)) break;
9464-
9465+
9466       if (chl != (chist_list) 0) ++(chl->ch.value);
9467       else {
9468 	if ((*colorsP)++ > maxcolors) {
9469 	  ppm_freechash(cht);
9470 	  return (chash_table) 0;
9471 	}
9472-
9473+
9474 	chl = (chist_list) malloc(sizeof(struct chist_list_item));
9475 	if (!chl) FatalError("ran out of memory computing hash table");
9476
9477@@ -878,7 +878,7 @@
9478 	cht[hash] = chl;
9479       }
9480     }
9481-
9482+
9483   return cht;
9484 }
9485
9486@@ -1114,7 +1114,7 @@
9487   register int i;
9488   register long maxc = 0;
9489   boxptr which = NULL;
9490-
9491+
9492   for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
9493     if (boxp->colorcount > maxc && boxp->volume > 0) {
9494       which = boxp;
9495@@ -1133,7 +1133,7 @@
9496   register int i;
9497   register INT32 maxv = 0;
9498   boxptr which = NULL;
9499-
9500+
9501   for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
9502     if (boxp->volume > maxv) {
9503       which = boxp;
9504@@ -1153,11 +1153,11 @@
9505   int c0min,c0max,c1min,c1max,c2min,c2max;
9506   INT32 dist0,dist1,dist2;
9507   long ccount;
9508-
9509+
9510   c0min = boxp->c0min;  c0max = boxp->c0max;
9511   c1min = boxp->c1min;  c1max = boxp->c1max;
9512   c2min = boxp->c2min;  c2max = boxp->c2max;
9513-
9514+
9515   if (c0max > c0min)
9516     for (c0 = c0min; c0 <= c0max; c0++)
9517       for (c1 = c1min; c1 <= c1max; c1++) {
9518@@ -1229,7 +1229,7 @@
9519   dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
9520   dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
9521   boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
9522-
9523+
9524   ccount = 0;
9525   for (c0 = c0min; c0 <= c0max; c0++)
9526     for (c1 = c1min; c1 <= c1max; c1++) {
9527@@ -1315,11 +1315,11 @@
9528   long c0total = 0;
9529   long c1total = 0;
9530   long c2total = 0;
9531-
9532+
9533   c0min = boxp->c0min;  c0max = boxp->c0max;
9534   c1min = boxp->c1min;  c1max = boxp->c1max;
9535   c2min = boxp->c2min;  c2max = boxp->c2max;
9536-
9537+
9538   for (c0 = c0min; c0 <= c0max; c0++)
9539     for (c1 = c1min; c1 <= c1max; c1++) {
9540       histp = & histogram[c0][c1][c2min];
9541@@ -1332,7 +1332,7 @@
9542 	}
9543       }
9544     }
9545-
9546+
9547   sl_colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
9548   sl_colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
9549   sl_colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
9550@@ -1505,12 +1505,12 @@
9551   bptr = bestdist;
9552   for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
9553     *bptr++ = 0x7FFFFFFFL;
9554-
9555+
9556   /* Nominal steps between cell centers ("x" in Thomas article) */
9557 #define STEP_C0  ((1 << C0_SHIFT) * C0_SCALE)
9558 #define STEP_C1  ((1 << C1_SHIFT) * C1_SCALE)
9559 #define STEP_C2  ((1 << C2_SHIFT) * C2_SCALE)
9560-
9561+
9562   for (i = 0; i < numcolors; i++) {
9563     icolor = colorlist[i];
9564     /* Compute (square of) distance from minc0/c1/c2 to this color */
9565@@ -1576,7 +1576,7 @@
9566   minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
9567   minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
9568   minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
9569-
9570+
9571   numcolors = find_nearby_colors(minc0, minc1, minc2, colorlist);
9572
9573   /* Determine the actually nearest colors. */
9574diff -ru xv-3.10a/xvalg.c xv-3.10a-enhancements/xvalg.c
9575--- xv-3.10a/xvalg.c	1994-12-22 14:34:47.000000000 -0800
9576+++ xv-3.10a-enhancements/xvalg.c	2007-05-12 16:07:37.000000000 -0700
9577@@ -38,7 +38,7 @@
9578 				 double, int));
9579 static void doPixel        PARM((byte *,int,int,byte *, int,int,int,int,
9580 				 int, int));
9581-static void doSpread       PARM((byte *,int,int,byte *, int,int,int,int,
9582+static void doSpread       PARM((byte *,int,int,byte *, int,int,int,int,
9583 				 int, int));
9584 static void doMedianFilter PARM((byte *,int,int,byte *, int,int,int,int, int));
9585
9586@@ -53,7 +53,7 @@
9587 static int  start24bitAlg  PARM((byte **, byte **));
9588 static void end24bitAlg    PARM((byte *, byte *));
9589
9590-static void printUTime     PARM((char *));
9591+static void printUTime     PARM((const char *));
9592
9593 static byte *origPic = (byte *) NULL;
9594 static int  origPicType;
9595@@ -70,10 +70,11 @@
9596
9597 /***************************/
9598 static void printUTime(str)
9599-     char *str;
9600+     const char *str;
9601 {
9602 #ifdef TIMING_TEST
9603-  int i;  struct rusage ru;
9604+  int i;
9605+  struct rusage ru;
9606
9607   i = getrusage(RUSAGE_SELF, &ru);
9608   fprintf(stderr,"%s: utime = %d.%d seconds\n",
9609@@ -89,7 +90,7 @@
9610 /************************************************************/
9611 void AlgInit()
9612 {
9613-  /* called whenver an image file is loaded.  disposes of origPic
9614+  /* called whenver an image file is loaded.  disposes of origPic
9615      if neccessary, and points it to null */
9616
9617   if (origPic) free(origPic);
9618@@ -160,16 +161,16 @@
9619 {
9620   /* runs a n*n convolution mask (all 1's) over 'pic',
9621      producing a 24-bit version.  Then calls 24to8 to generate a new 8-bit
9622-     image, and installs it.
9623+     image, and installs it.
9624
9625      Note that 'n' must be odd for things to work properly */
9626
9627-  byte        *pic24, *tmpPic;
9628-  int          i, sx,sy,sw,sh, n;
9629-  static char *labels[] = { "\nOk", "\033Cancel" };
9630-  char         txt[256];
9631-  static char  buf[64] = { '3', '\0' };
9632-
9633+  byte              *pic24, *tmpPic;
9634+  int                i, sx,sy,sw,sh, n;
9635+  static const char *labels[] = { "\nOk", "\033Cancel" };
9636+  char               txt[256];
9637+  static char        buf[64] = { '3', '\0' };
9638+
9639   sprintf(txt, "Blur:                                   \n\n%s",
9640 	  "Enter mask size (ex. 3, 5, 7, ...)");
9641
9642@@ -178,7 +179,7 @@
9643   n = atoi(buf);
9644
9645   if (n < 1 || (n&1)!=1) {
9646-    ErrPopUp("Error:  The value entered must be odd and greater than zero.",
9647+    ErrPopUp("Error:  The value entered must be odd and greater than zero.",
9648 	     "\nOh!");
9649     return;
9650   }
9651@@ -194,7 +195,7 @@
9652
9653   if (start24bitAlg(&pic24, &tmpPic)) return;
9654   xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
9655-
9656+
9657   doBlurConvolv(pic24, pWIDE,pHIGH, tmpPic, sx,sy,sw,sh, n);
9658
9659   end24bitAlg(pic24, tmpPic);
9660@@ -207,12 +208,12 @@
9661 {
9662   /* runs an edge-enhancment algorithm */
9663
9664-  byte        *pic24, *tmpPic;
9665-  int          i, sx,sy,sw,sh, n;
9666-  static char *labels[] = { "\nOk", "\033Cancel" };
9667-  char         txt[256];
9668-  static char  buf[64] = { '7', '5', '\0' };
9669-
9670+  byte              *pic24, *tmpPic;
9671+  int                i, sx,sy,sw,sh, n;
9672+  static const char *labels[] = { "\nOk", "\033Cancel" };
9673+  char               txt[256];
9674+  static char        buf[64] = { '7', '5', '\0' };
9675+
9676   sprintf(txt, "Sharpen:                                   \n\n%s",
9677 	  "Enter enhancement factor (0-99%)");
9678
9679@@ -236,7 +237,7 @@
9680
9681   if (start24bitAlg(&pic24, &tmpPic)) return;
9682   xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
9683-
9684+
9685   doSharpConvolv(pic24, pWIDE,pHIGH, tmpPic, sx,sy,sw,sh, n);
9686
9687   end24bitAlg(pic24, tmpPic);
9688@@ -248,7 +249,7 @@
9689 static void EdgeDetect()
9690 {
9691   byte *pic24, *p24, *tmpPic, *tlp;
9692-  char *str;
9693+  const char *str;
9694   int  i, j, v, maxv, sx,sy,sw,sh;
9695
9696   WaitCursor();
9697@@ -264,7 +265,7 @@
9698   xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
9699
9700   doEdgeConvolv(pic24, pWIDE, pHIGH, tmpPic, sx,sy,sw,sh);
9701-
9702+
9703   SetISTR(ISTR_INFO, "%snormalizing...", str);
9704
9705   /* Normalize results */
9706@@ -292,19 +293,19 @@
9707 /************************/
9708 static void TinFoil()
9709 {
9710-  byte *pic24, *p24, *tmpPic, *tp, *tlp;
9711-  char *str;
9712-  int  i, j, v, maxv,sx,sy,sw,sh;
9713-
9714+  byte *pic24, *tmpPic, *tp, *tlp;
9715+  const char *str;
9716+  int  i, j, v, sx,sy,sw,sh;
9717+
9718   WaitCursor();
9719-
9720+
9721   str = "Doing cheesy embossing effect...";
9722   SetISTR(ISTR_INFO, str);
9723-
9724+
9725   if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
9726   else { sx = 0;  sy = 0;  sw = pWIDE;  sh = pHIGH; }
9727   CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
9728-
9729+
9730   if (start24bitAlg(&pic24, &tmpPic)) return;
9731   xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
9732
9733@@ -315,9 +316,9 @@
9734       *tp++ = 128;  *tp++ = 128;  *tp++ = 128;
9735     }
9736   }
9737-
9738+
9739   doAngleConvolv(pic24, pWIDE, pHIGH, tmpPic, sx,sy,sw,sh);
9740-
9741+
9742   /* mono-ify selected area of tmpPic */
9743   for (i=sy; i<sy+sh; i++) {
9744     tp = tlp = tmpPic + (i*pWIDE + sx) * 3;
9745@@ -327,9 +328,9 @@
9746       tp[0] = tp[1] = tp[2] = (byte) v;
9747     }
9748   }
9749-
9750+
9751   end24bitAlg(pic24, tmpPic);
9752-}
9753+}
9754
9755
9756 /************************/
9757@@ -345,7 +346,7 @@
9758   if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
9759   else { sx = 0;  sy = 0;  sw = pWIDE;  sh = pHIGH; }
9760   CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
9761-
9762+
9763   if (start24bitAlg(&pic24, &tmpPic)) return;
9764   xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
9765
9766@@ -365,7 +366,7 @@
9767   if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
9768   else { sx = 0;  sy = 0;  sw = pWIDE;  sh = pHIGH; }
9769   CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
9770-
9771+
9772   WaitCursor();
9773
9774   if (start24bitAlg(&pic24, &tmpPic)) return;
9775@@ -381,12 +382,12 @@
9776 static void FineRotate(clr)
9777      int clr;
9778 {
9779-  byte        *pic24, *tmpPic;
9780-  int          i,sx,sy,sw,sh;
9781-  double       rotval;
9782-  static char *labels[] = { "\nOk", "\033Cancel" };
9783-  char         txt[256];
9784-  static char  buf[64] = { '\0' };
9785+  byte              *pic24, *tmpPic;
9786+  int                i,sx,sy,sw,sh;
9787+  double             rotval;
9788+  static const char *labels[] = { "\nOk", "\033Cancel" };
9789+  char               txt[256];
9790+  static char        buf[64] = { '\0' };
9791
9792   sprintf(txt, "Rotate (%s):\n\nEnter rotation angle, in degrees:  (>0 = CCW)",
9793 	  (clr ? "Clear" : "Copy"));
9794@@ -396,12 +397,12 @@
9795   rotval = atof(buf);
9796
9797   if (rotval == 0.0) return;
9798-
9799+
9800
9801   if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
9802   else { sx = 0;  sy = 0;  sw = pWIDE;  sh = pHIGH; }
9803   CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
9804-
9805+
9806   WaitCursor();
9807
9808   if (start24bitAlg(&pic24, &tmpPic)) return;
9809@@ -416,11 +417,11 @@
9810 /************************/
9811 static void Pixelize()
9812 {
9813-  byte        *pic24, *tmpPic;
9814-  int          i,sx,sy,sw,sh, pixX,pixY,err;
9815-  static char *labels[] = { "\nOk", "\033Cancel" };
9816-  char         txt[256];
9817-  static char  buf[64] = { '4', '\0' };
9818+  byte              *pic24, *tmpPic;
9819+  int                i,sx,sy,sw,sh, pixX,pixY,err;
9820+  static const char *labels[] = { "\nOk", "\033Cancel" };
9821+  char               txt[256];
9822+  static char        buf[64] = { '4', '\0' };
9823
9824   sprintf(txt, "Pixelize:\n\nEnter new pixel size, in image pixels:  %s",
9825 	  "(ex. '3', '5x8')");
9826@@ -443,11 +444,11 @@
9827     return;
9828   }
9829
9830-
9831+
9832   if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
9833   else { sx = 0;  sy = 0;  sw = pWIDE;  sh = pHIGH; }
9834   CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
9835-
9836+
9837   WaitCursor();
9838
9839   if (start24bitAlg(&pic24, &tmpPic)) return;
9840@@ -463,11 +464,11 @@
9841 /************************/
9842 static void Spread()
9843 {
9844-  byte        *pic24, *tmpPic;
9845-  int          i,sx,sy,sw,sh, pixX,pixY,err;
9846-  static char *labels[] = { "\nOk", "\033Cancel" };
9847-  char         txt[256];
9848-  static char  buf[64] = { '5', '\0' };
9849+  byte              *pic24, *tmpPic;
9850+  int                i,sx,sy,sw,sh, pixX,pixY,err;
9851+  static const char *labels[] = { "\nOk", "\033Cancel" };
9852+  char               txt[256];
9853+  static char        buf[64] = { '5', '\0' };
9854
9855   sprintf(txt, "Spread:\n\nEnter spread factor (or x,y factors):  %s",
9856 	  "(ex. '10', '1x5')");
9857@@ -493,11 +494,11 @@
9858     return;
9859   }
9860
9861-
9862+
9863   if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
9864   else { sx = 0;  sy = 0;  sw = pWIDE;  sh = pHIGH; }
9865   CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
9866-
9867+
9868   WaitCursor();
9869
9870   if (start24bitAlg(&pic24, &tmpPic)) return;
9871@@ -516,12 +517,12 @@
9872   /* runs median filter algorithm (for n*n rect centered around each pixel,
9873      replace with median value */
9874
9875-  byte        *pic24, *tmpPic;
9876-  int          i, sx,sy,sw,sh, n;
9877-  static char *labels[] = { "\nOk", "\033Cancel" };
9878-  char         txt[256];
9879-  static char  buf[64] = { '3', '\0' };
9880-
9881+  byte              *pic24, *tmpPic;
9882+  int                i, sx,sy,sw,sh, n;
9883+  static const char *labels[] = { "\nOk", "\033Cancel" };
9884+  char               txt[256];
9885+  static char        buf[64] = { '3', '\0' };
9886+
9887   sprintf(txt, "DeSpeckle (median filter):                          \n\n%s",
9888 	  "Enter mask size (ex. 3, 5, 7, ...)");
9889
9890@@ -530,7 +531,7 @@
9891   n = atoi(buf);
9892
9893   if (n < 1 || (n&1)!=1) {
9894-    ErrPopUp("Error:  The value entered must be odd and greater than zero.",
9895+    ErrPopUp("Error:  The value entered must be odd and greater than zero.",
9896 	     "\nOh!");
9897     return;
9898   }
9899@@ -546,7 +547,7 @@
9900
9901   if (start24bitAlg(&pic24, &tmpPic)) return;
9902   xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
9903-
9904+
9905   doMedianFilter(pic24, pWIDE,pHIGH, tmpPic, sx,sy,sw,sh, n);
9906
9907   end24bitAlg(pic24, tmpPic);
9908@@ -560,7 +561,7 @@
9909      int   w,h, selx,sely,selw,selh, n;
9910 {
9911
9912-  /* convolves with an n*n array, consisting of only 1's.
9913+  /* convolves with an n*n array, consisting of only 1's.
9914      Operates on rectangular region 'selx,sely,selw,selh' (in pic coords)
9915      Region is guaranteed to be completely within pic boundaries
9916      'n' must be odd */
9917@@ -568,7 +569,7 @@
9918   register byte *p24;
9919   register int   rsum,gsum,bsum;
9920   byte          *rp;
9921-  int            i,j,k,x,y,x1,y1,count,n2;
9922+  int            x,y,x1,y1,count,n2;
9923
9924
9925   printUTime("start of blurConvolv");
9926@@ -589,7 +590,7 @@
9927       for (y1=y-n2; y1<=y+n2; y1++) {
9928
9929 	if (y1>=sely && y1<sely+selh) {
9930-	  p24 = pic24 + y1*w*3 +(x-n2)*3;
9931+	  p24 = pic24 + y1*w*3 +(x-n2)*3;
9932
9933 	  for (x1=x-n2; x1<=x+n2; x1++) {
9934 	    if (x1>=selx && x1<selx+selw) {
9935@@ -631,7 +632,7 @@
9936   byte  *p24;
9937   int    rv, gv, bv;
9938   byte  *rp;
9939-  int    i,j,k,x,y,x1,y1;
9940+  int    i,x,y;
9941   double fact, ifact, hue,sat,val, vsum;
9942   double *linem1, *line0, *linep1, *tmpptr;
9943
9944@@ -673,7 +674,7 @@
9945   for (y=sely+1; y<(sely+selh)-1; y++) {
9946     ProgressMeter(sely+1, (sely+selh)-2, y, "Sharpen");
9947     if ((y & 15) == 0) WaitCursor();
9948-
9949+
9950     tmpptr = linem1;   linem1 = line0;   line0 = linep1;   linep1 = tmpptr;
9951
9952     /* get next line */
9953@@ -691,7 +692,7 @@
9954       vsum = linem1[i-1] + linem1[i] + linem1[i+1] +
9955 	     line0 [i-1] + line0 [i] + line0 [i+1] +
9956 	     linep1[i-1] + linep1[i] + linep1[i+1];
9957-
9958+
9959       rgb2hsv((int) p24[0], (int) p24[1], (int) p24[2], &hue, &sat, &val);
9960
9961       val = ((val - (fact * vsum) / 9) / ifact);
9962@@ -723,22 +724,22 @@
9963 {
9964
9965   /* convolves with two edge detection masks (vertical and horizontal)
9966-     simultaneously, taking Max(abs(results))
9967-
9968+     simultaneously, taking Max(abs(results))
9969+
9970      The two masks are (hard coded):
9971
9972           -1 0 1             -1 -1 -1
9973       H = -1 0 1     and V =  0  0  0
9974           -1 0 1              1  1  1
9975
9976-     divided into
9977+     divided into
9978            -1 0 0         0 0 0         0 0 1        0  1 0
9979        a =  0 0 0 ,  b = -1 0 1 ,  c =  0 0 0 ,  d = 0  0 0 .
9980             0 0 1         0 0 0        -1 0 0        0 -1 0
9981
9982      So H = a + b + c,  V = a - c - d.
9983      gradient = max(abs(H),abs(V)).
9984-
9985+
9986      Also, only does pixels in which the masks fit fully onto the picture
9987      (no pesky boundary conditionals)  */
9988
9989@@ -746,7 +747,7 @@
9990   register byte *p24;
9991   register int   bperlin, a, b, c, d, rsum, gsum, bsum;
9992   byte          *rp;
9993-  int            i, x, y;
9994+  int            x, y;
9995
9996
9997   printUTime("start of edgeConvolv");
9998@@ -818,13 +819,13 @@
9999 {
10000
10001   /* convolves with edge detection mask, at 45 degrees to horizontal.
10002-
10003+
10004      The mask is (hard coded):
10005
10006              -2 -1 0
10007              -1  0 1
10008               0  1 2
10009-
10010+
10011      Also, only does pixels in which the masks fit fully onto the picture
10012      (no pesky boundary conditionals)
10013
10014@@ -833,7 +834,7 @@
10015   register byte *p24;
10016   register int   bperlin,rsum,gsum,bsum;
10017   byte          *rp;
10018-  int            i, x,y;
10019+  int            x,y;
10020
10021
10022   printUTime("start of doAngleConvolv");
10023@@ -912,14 +913,14 @@
10024      for each pixel in the image (assume, for a second, a grayscale image),
10025      compute a histogram of the n*n rectangle centered on the pixel.
10026      replace the pixel with the color that had the greatest # of hits in
10027-     the histogram.  Note that 'n' should be odd.
10028+     the histogram.  Note that 'n' should be odd.
10029
10030      I've modified the algorithm to do the *right* thing for RGB images.
10031      (jhb, 6/94)  */
10032
10033
10034   register byte *pp;
10035-  register int   bperlin, rsum,gsum,bsum;
10036+  register int   bperlin;
10037   byte          *rp, *p24, *plin;
10038   int            i,j,k,x,y,n2,col,cnt,maxcnt;
10039   int           *nnrect;
10040@@ -933,7 +934,7 @@
10041
10042   /* nnrect[] is an n*n array of ints, with '-1' meaning 'outside the region'
10043      otherwise they'll have 24-bit RGB values */
10044-
10045+
10046   nnrect = (int *) malloc(n * n * sizeof(int));
10047   if (!nnrect) FatalError("can't malloc nnrect[] in doOilPaint()\n");
10048
10049@@ -943,13 +944,13 @@
10050
10051     p24 = pic24 + ((y-n2)*w + selx-n2)*3;   /* pts to top-left of mask */
10052     rp  = results + (y*w + selx)*3;
10053-
10054+
10055     for (x=selx; x<selx+selw; x++) {
10056       /* fill 'nnrect' with valid pixels from n*n region centered round x,y */
10057       pp = plin = p24;
10058       for (i=y-n2, k=0; i<y+n2; i++) {
10059 	for (j=x-n2; j<x+n2; j++, k++, pp+=3) {
10060-	  if (i>=sely && i<sely+selh && j>=selx && j<selx+selw) {
10061+	  if (i>=sely && i<sely+selh && j>=selx && j<selx+selw) {
10062 	    nnrect[k] = (((int) pp[0])<<16) | (((int) pp[1])<<8) | pp[2];
10063 	  }
10064 	  else nnrect[k] = -1;
10065@@ -957,7 +958,7 @@
10066 	plin += bperlin;  pp = plin;
10067       }
10068
10069-
10070+
10071       /* find 'most popular color' in nnrect, not counting '-1' */
10072       maxcnt = cnt = col = 0;
10073       for (i=0; i<n*n; i++) {
10074@@ -1021,7 +1022,7 @@
10075     p24 = pic24 + (y*w + selx) * 3;
10076     rf += (double) p24[0];  gf += (double) p24[1];  bf += (double) p24[2];
10077     i++;
10078-
10079+
10080     p24 = pic24 + (y*w + (selx+selw-1)) * 3;
10081     rf += (double) p24[0];  gf += (double) p24[1];  bf += (double) p24[2];
10082     i++;
10083@@ -1047,7 +1048,7 @@
10084       if (dx==0 && dy==0) { ex = selx;  ey = sely; }  /* don't care */
10085       else if (dx==0) {	ex = cx;  ey = (dy<0) ? sely : sely+selh-1; }
10086       else if (dy==0) {	ey = cy;  ex = (dx<0) ? selx : selx+selw-1; }
10087-      else {
10088+      else {
10089 	slope = ((double) dy) / dx;
10090 	if (fabs(slope) > fabs(dslope)) {   /* y axis is major */
10091 	  ey = (dy<0) ? sely : sely+selh-1;
10092@@ -1092,7 +1093,7 @@
10093   printUTime("end of blend");
10094 }
10095
10096-
10097+
10098
10099 /************************/
10100 static void doRotate(pic24, w, h, results, selx,sely,selw,selh, rotval, clear)
10101@@ -1104,7 +1105,7 @@
10102      by the amount specified in degrees (rotval), and stores the result in
10103      'results', which is also a w*h 24-bit image.  The rotated bits are
10104      clipped to fit in 'results'.  If 'clear', the (unrotated) rectangular
10105-     region is cleared (in results) first.
10106+     region is cleared (in results) first.
10107      sel[x,y,w,h] is guaranteed to be within image bounds */
10108
10109   byte  *pp, *dp;
10110@@ -1118,7 +1119,7 @@
10111   printUTime("start of rotate");
10112
10113   /*
10114-   * cfx,cfy  -  center point of sel rectangle (double)
10115+   * cfx,cfy  -  center point of sel rectangle (double)
10116    * rx1,ry1  -  top-left  of sel, rotated
10117    * rx2,ry2  -  bot-left  of sel, rotated
10118    * rx3,ry3  -  top-right of sel, rotated
10119@@ -1174,7 +1175,7 @@
10120   /* now, for each pixel in rb[x,y,w,h], do the inverse rotation to see if
10121      it would be in the original unrotated selection rectangle.  if it *is*,
10122      compute and store an appropriate color, otherwise skip it */
10123-
10124+
10125   for (y=rby; y<rby+rbh; y++) {
10126     dp = results + (y * w + rbx) * 3;
10127
10128@@ -1194,7 +1195,7 @@
10129 	int    p0r,p0g,p0b, p1r,p1g,p1b, p2r,p2g,p2b, p3r,p3g,p3b;
10130 	int    rv,gv,bv;
10131 	double rd,gd,bd, p0wgt, p1wgt, p2wgt, p3wgt;
10132-
10133+
10134 	/* compute the color, same idea as in Smooth**().  The color
10135 	   will be a linear combination of the colors of the center pixel,
10136 	   its left-or-right neighbor, its top-or-bottom neighbor, and
10137@@ -1265,9 +1266,9 @@
10138 }
10139 #endif /* ROTATE_FOO */
10140
10141-	dp[0] = (byte) (rv&0xff);
10142-	dp[1] = (byte) (gv&0xff);
10143-	dp[2] = (byte) (bv&0xff);
10144+	dp[0] = (byte) (rv&0xff);
10145+	dp[1] = (byte) (gv&0xff);
10146+	dp[2] = (byte) (bv&0xff);
10147       }
10148     }
10149   }
10150@@ -1311,11 +1312,11 @@
10151 #ifdef FOO
10152   fprintf(stderr,"rotXfer:  rotating (%4d,%4d) %7.2f degrees around",
10153 	  x,y, rad*180.0 / M_PI);
10154-  fprintf(stderr,"(%4d,%4d) -> %7.2f %7.2f  (d=%f ang=%f)\n",
10155+  fprintf(stderr,"(%4d,%4d) -> %7.2f %7.2f  (d=%f ang=%f)\n",
10156 	  cx,cy, *rx,*ry, d, ang);
10157 #endif
10158 }
10159-
10160+
10161
10162
10163 /************************/
10164@@ -1323,29 +1324,29 @@
10165      byte *pic24, *results;
10166      int   w, h, selx,sely,selw,selh, pixX,pixY;
10167 {
10168-  /* runs 'pixelization' algorithm.  replaces each pixX-by-pixY region
10169+  /* runs 'pixelization' algorithm.  replaces each pixX-by-pixY region
10170      (smaller on edges) with the average color within that region */
10171-
10172+
10173   byte  *pp;
10174   int    nwide, nhigh, i,j, x,y, x1,y1, stx,sty;
10175   int    nsum, rsum, gsum, bsum;
10176-
10177+
10178   printUTime("start of pixelize");
10179-
10180+
10181   /* center grid on selection */
10182   nwide = (selw + pixX-1) / pixX;
10183   nhigh = (selh + pixY-1) / pixY;
10184-
10185+
10186   stx = selx - (nwide*pixX - selw)/2;
10187   sty = sely - (nhigh*pixY - selh)/2;
10188-
10189+
10190   y = sty;
10191   for (i=0; i<nhigh; i++, y+=pixY) {
10192     ProgressMeter(0, nhigh-1, i, "Pixelize");
10193-
10194+
10195     x = stx;
10196     for (j=0; j<nwide; j++, x+=pixX) {
10197-
10198+
10199       /* COMPUTE AVERAGE COLOR FOR RECT:[x,y,pixX,pixY] */
10200       nsum = rsum = gsum = bsum = 0;
10201       for (y1=y; y1<y+pixY; y1++) {
10202@@ -1357,17 +1358,17 @@
10203 	  }
10204 	}
10205       }
10206-
10207+
10208       if (nsum>0) {   /* just to be safe... */
10209 	rsum /= nsum;  gsum /= nsum;  bsum /= nsum;
10210 	RANGE(rsum,0,255);  RANGE(gsum,0,255);  RANGE(bsum,0,255);
10211       }
10212-
10213-
10214+
10215+
10216       /* STORE color in rect:[x,y,pixX,pixY] */
10217       for (y1=y; y1<y+pixY; y1++) {
10218 	if (!j && (y1 & 255)==0) WaitCursor();
10219-
10220+
10221 	pp = results + (y1 * w + x) * 3;
10222 	for (x1=x; x1<x+pixX; x1++, pp+=3) {
10223 	  if (PTINRECT(x1,y1, selx,sely,selw,selh)) {
10224@@ -1381,7 +1382,7 @@
10225   printUTime("end of pixelize");
10226 }
10227
10228-
10229+
10230
10231 /************************/
10232 static void doSpread(pic24, w, h, results, selx,sely,selw,selh, pixX, pixY)
10233@@ -1393,17 +1394,17 @@
10234      by pixX,pixY.  If pixX<0, it is treated as a single 'distance' value
10235      (after being abs()'d). */
10236
10237-  /* assumes that initially 'results' is a copy of pic24.  Doesn't
10238+  /* assumes that initially 'results' is a copy of pic24.  Doesn't
10239      even look at pic24 */
10240-
10241+
10242   byte  *pp, *dp, r,g,b;
10243-  int    x,y, dx,dy, x1,y1, d, xrng, xoff, yrng, yoff, i,j;
10244+  int    x,y, x1,y1, d;
10245   int    minx, maxx, miny, maxy, rdist;
10246   time_t nowT;
10247
10248   time(&nowT);
10249   srandom((unsigned int) nowT);
10250-
10251+
10252   printUTime("start of spread");
10253
10254   for (y=sely; y<sely+selh; y++) {
10255@@ -1453,7 +1454,7 @@
10256   printUTime("end of spread");
10257 }
10258
10259-
10260+
10261
10262 /************************/
10263 static void doMedianFilter(pic24, w, h, results, selx,sely,selw,selh, n)
10264@@ -1468,7 +1469,7 @@
10265   register byte *p24;
10266   register int   rsum,gsum,bsum;
10267   byte          *rp;
10268-  int            i,j,k,x,y,x1,y1,count,n2,nsq,c2;
10269+  int            x,y,x1,y1,count,n2,nsq,c2;
10270   int           *rtab, *gtab, *btab;
10271
10272   printUTime("start of doMedianFilter");
10273@@ -1494,7 +1495,7 @@
10274       for (y1=y-n2; y1<=y+n2; y1++) {
10275
10276 	if (y1>=sely && y1<sely+selh) {
10277-	  p24 = pic24 + y1*w*3 +(x-n2)*3;
10278+	  p24 = pic24 + y1*w*3 +(x-n2)*3;
10279
10280 	  for (x1=x-n2; x1<=x+n2; x1++) {
10281 	    if (x1>=selx && x1<selx+selw) {
10282@@ -1509,12 +1510,12 @@
10283       }
10284
10285
10286-      /* now sort the rtab,gtab,btab arrays, (using shell sort)
10287-	 and pick the middle value.  doing it in-line, rather than
10288+      /* now sort the rtab,gtab,btab arrays, (using shell sort)
10289+	 and pick the middle value.  doing it in-line, rather than
10290 	 as a function call (ie, 'qsort()') , for speed */
10291-      {
10292+      {
10293 	int i,j,t,d;
10294-
10295+
10296 	for (d=count/2;  d>0;  d=d/2) {
10297 	  for (i=d; i<count; i++) {
10298 	    for (j=i-d;  j>=0 && rtab[j]>rtab[j+d];  j-=d) {
10299@@ -1531,14 +1532,14 @@
10300 	  }
10301 	}
10302       }
10303-
10304+
10305       c2 = count/2;
10306       *rp++ = (byte) ( (count&1) ? rtab[c2] : (rtab[c2] + rtab[c2-1])/2);
10307       *rp++ = (byte) ( (count&1) ? gtab[c2] : (gtab[c2] + gtab[c2-1])/2);
10308       *rp++ = (byte) ( (count&1) ? btab[c2] : (btab[c2] + btab[c2-1])/2);
10309     }
10310   }
10311-
10312+
10313   free(rtab);  free(gtab);  free(btab);
10314   printUTime("end of doMedianFilter");
10315 }
10316@@ -1549,7 +1550,7 @@
10317 static void intsort(a, n)
10318      int *a, n;
10319 {
10320-  /* uses the shell-sort algorithm.  for the relatively small data sets
10321+  /* uses the shell-sort algorithm.  for the relatively small data sets
10322      we'll be using, should be quicker than qsort() because of all the
10323      function calling overhead associated with qsort(). */
10324
10325@@ -1571,7 +1572,7 @@
10326      byte **pic24, **tmpPic;
10327 {
10328   /* generates a 24-bit version of 'pic', if neccessary, and also mallocs
10329-   * a pWIDE*pHIGH*3 24-bit output pic.
10330+   * a pWIDE*pHIGH*3 24-bit output pic.
10331    *
10332    * Returns '1' if there's some sort of screwup, '0' if cool
10333    */
10334@@ -1588,7 +1589,7 @@
10335   *tmpPic = (byte *) calloc((size_t) (pWIDE * pHIGH * 3), (size_t) 1);
10336   if (!(*tmpPic)) {
10337     SetCursors(-1);
10338-    ErrPopUp("Unable to malloc() tmp 24-bit image in start24bitAlg()",
10339+    ErrPopUp("Unable to malloc() tmp 24-bit image in start24bitAlg()",
10340 	     "\nTough!");
10341     if (picType == PIC8) free(*pic24);
10342     return 1;
10343@@ -1609,16 +1610,16 @@
10344   saveOrigPic();  /* also kills pic/cpic/epic/egampic/theImage, NOT pic24 */
10345
10346   /* copy results to pic24 */
10347-  xvbcopy((char *) outPic, (char *) pic24, (size_t) (pWIDE*pHIGH*3));
10348+  xvbcopy((char *) outPic, (char *) pic24, (size_t) (pWIDE*pHIGH*3));
10349   free(outPic);
10350
10351   if (picType == PIC8) {
10352     pic = Conv24to8(pic24, pWIDE, pHIGH, ncols, rMap,gMap,bMap);
10353     free(pic24);
10354-    if (!pic) {
10355+    if (!pic) {
10356       SetCursors(-1);
10357       ErrPopUp("Some sort of failure occured in 24to8 conversion\n","\nDamn!");
10358-      NoAlg();
10359+      NoAlg();
10360       return;
10361     }
10362   }
10363@@ -1632,7 +1633,7 @@
10364 static void saveOrigPic()
10365 {
10366   /* saves original picture into origPic, if it hasn't already been done.
10367-     This allows us to undo algorithms...
10368+     This allows us to undo algorithms...
10369
10370      Also, frees all pics, (except 'pic', if we're in PIC24 mode) */
10371
10372@@ -1649,7 +1650,7 @@
10373     /* make a backup copy of 'pic' */
10374     origPic = (byte *) malloc((size_t)(pWIDE*pHIGH*((picType==PIC8) ? 1 : 3)));
10375     if (!origPic) FatalError("out of memory in 'saveOrigPic()'");
10376-    xvbcopy((char *) pic, (char *) origPic,
10377+    xvbcopy((char *) pic, (char *) origPic,
10378 	    (size_t) (pWIDE * pHIGH * ((picType==PIC8) ? 1 : 3)));
10379
10380     origPicType = picType;
10381diff -ru xv-3.10a/xvbmp.c xv-3.10a-enhancements/xvbmp.c
10382--- xv-3.10a/xvbmp.c	1994-12-22 14:34:42.000000000 -0800
10383+++ xv-3.10a-enhancements/xvbmp.c	2007-05-13 17:46:16.000000000 -0700
10384@@ -1,5 +1,5 @@
10385 /*
10386- * xvbmp.c - i/o routines for .BMP files (MS Windows 3.x)
10387+ * xvbmp.c - I/O routines for .BMP files (MS Windows 3.x and later; OS/2)
10388  *
10389  * LoadBMP(fname, numcols)
10390  * WriteBMP(fp, pic, ptype, w, h, r, g, b, numcols, style);
10391@@ -9,30 +9,39 @@
10392
10393 #include "xv.h"
10394
10395-/* comments on error handling:
10396-   a truncated file is not considered a Major Error.  The file is loaded, the
10397-   rest of the pic is filled with 0's.
10398-
10399-   a file with garbage characters in it is an unloadable file.  All allocated
10400-   stuff is tossed, and LoadPBM returns non-zero
10401-
10402-   not being able to malloc is a Fatal Error.  The program is aborted. */
10403-
10404-
10405-#define BI_RGB  0
10406-#define BI_RLE8 1
10407-#define BI_RLE4 2
10408+/* Comments on error-handling:
10409+   A truncated file is not considered a Major Error.  The file is loaded,
10410+   and the rest of the pic is filled with 0's.
10411+
10412+   A file with garbage characters in it is an unloadable file.  All allocated
10413+   stuff is tossed, and LoadBMP returns non-zero.
10414+
10415+   Not being able to malloc is a Fatal Error.  The program is aborted. */
10416+
10417+
10418+#define BI_RGB       0   /* a.k.a. uncompressed */
10419+#define BI_RLE8      1
10420+#define BI_RLE4      2
10421+#define BI_BITFIELDS 3   /* BMP version 4 */
10422+#define BI_JPEG      4   /* BMP version 5 (not yet supported) */
10423+#define BI_PNG       5   /* BMP version 5 (not yet supported) */
10424
10425 #define WIN_OS2_OLD 12
10426 #define WIN_NEW     40
10427 #define OS2_NEW     64
10428
10429+#if (defined(UINT_MAX) && UINT_MAX != 0xffffffffU)
10430+#  error XV's BMP code requires 32-bit unsigned integer type, but u_int isn't
10431+#endif
10432+
10433 static long filesize;
10434
10435 static int   loadBMP1   PARM((FILE *, byte *, u_int, u_int));
10436 static int   loadBMP4   PARM((FILE *, byte *, u_int, u_int, u_int));
10437 static int   loadBMP8   PARM((FILE *, byte *, u_int, u_int, u_int));
10438-static int   loadBMP24  PARM((FILE *, byte *, u_int, u_int));
10439+static int   loadBMP16  PARM((FILE *, byte *, u_int, u_int, u_int *));
10440+static int   loadBMP24  PARM((FILE *, byte *, u_int, u_int, u_int));
10441+static int   loadBMP32  PARM((FILE *, byte *, u_int, u_int, u_int *));
10442 static u_int getshort   PARM((FILE *));
10443 static u_int getint     PARM((FILE *));
10444 static void  putshort   PARM((FILE *, int));
10445@@ -41,7 +50,7 @@
10446 static void  writeBMP4  PARM((FILE *, byte *, int, int));
10447 static void  writeBMP8  PARM((FILE *, byte *, int, int));
10448 static void  writeBMP24 PARM((FILE *, byte *, int, int));
10449-static int   bmpError   PARM((char *, char *));
10450+static int   bmpError   PARM((const char *, const char *));
10451
10452
10453 #define FERROR(fp) (ferror(fp) || feof(fp))
10454@@ -52,15 +61,15 @@
10455      PICINFO *pinfo;
10456 /*******************************************/
10457 {
10458-  FILE         *fp;
10459-  int          i, c, c1, rv;
10460-  unsigned int bfSize, bfOffBits, biSize, biWidth, biHeight, biPlanes;
10461-  unsigned int biBitCount, biCompression, biSizeImage, biXPelsPerMeter;
10462-  unsigned int biYPelsPerMeter, biClrUsed, biClrImportant;
10463-  int bPad;
10464-  char         *cmpstr;
10465-  byte         *pic24, *pic8;
10466-  char          buf[512], *bname;
10467+  FILE       *fp;
10468+  int        i, c, c1, rv, bPad;
10469+  u_int      bfSize, bfOffBits, biSize, biWidth, biHeight, biPlanes;
10470+  u_int      biBitCount, biCompression, biSizeImage, biXPelsPerMeter;
10471+  u_int      biYPelsPerMeter, biClrUsed, biClrImportant;
10472+  u_int      colormask[3];
10473+  char       buf[512], rgb_bits[16];
10474+  const char *cmpstr, *bname;
10475+  byte       *pic24, *pic8;
10476
10477   /* returns '1' on success */
10478
10479@@ -69,7 +78,7 @@
10480
10481   fp = xv_fopen(fname,"r");
10482   if (!fp) return (bmpError(bname, "couldn't open file"));
10483-
10484+
10485   fseek(fp, 0L, 2);      /* figure out the file size */
10486   filesize = ftell(fp);
10487   fseek(fp, 0L, 0);
10488@@ -98,17 +107,16 @@
10489     biClrUsed       = getint(fp);
10490     biClrImportant  = getint(fp);
10491   }
10492-
10493   else {    /* old bitmap format */
10494     biWidth         = getshort(fp);          /* Types have changed ! */
10495     biHeight        = getshort(fp);
10496     biPlanes        = getshort(fp);
10497     biBitCount      = getshort(fp);
10498-
10499-    /* Not in old versions so have to compute them*/
10500+
10501+    /* not in old versions, so have to compute them */
10502     biSizeImage = (((biPlanes * biBitCount*biWidth)+31)/32)*4*biHeight;
10503-
10504-    biCompression   = BI_RGB;
10505+
10506+    biCompression   = BI_RGB;
10507     biXPelsPerMeter = biYPelsPerMeter = 0;
10508     biClrUsed       = biClrImportant  = 0;
10509   }
10510@@ -126,22 +134,39 @@
10511   if (FERROR(fp)) { bmpError(bname,"EOF reached in file header"); goto ERROR; }
10512
10513
10514-  /* error checking */
10515-  if ((biBitCount!=1 && biBitCount!=4 && biBitCount!=8 && biBitCount!=24) ||
10516-      biPlanes!=1 || biCompression>BI_RLE4) {
10517+  /* error-checking */
10518+  if ((biBitCount!=1 && biBitCount!=4 && biBitCount!=8 &&
10519+       biBitCount!=16 && biBitCount!=24 && biBitCount!=32) ||
10520+      biPlanes!=1 || biCompression>BI_PNG ||
10521+      biWidth<=0 || biHeight<=0 ||
10522+      (biClrUsed && biClrUsed > (1 << biBitCount))) {
10523+
10524+    sprintf(buf,
10525+	    "Unsupported BMP type (%dx%d, Bits=%d, Colors=%d, Planes=%d, "
10526+	    "Compr=%d)",
10527+	    biWidth, biHeight, biBitCount, biClrUsed, biPlanes, biCompression);
10528
10529-    sprintf(buf,"Bogus BMP File!  (bitCount=%d, Planes=%d, Compression=%d)",
10530-	    biBitCount, biPlanes, biCompression);
10531+    bmpError(bname, buf);
10532+    goto ERROR;
10533+  }
10534+
10535+  if (biCompression>BI_BITFIELDS) {
10536+    sprintf(buf, "Unsupported BMP compression method (%s)",
10537+	    biCompression == BI_JPEG? "JPEG" :
10538+	    biCompression == BI_PNG? "PNG" :
10539+	    "unknown/newer than v5");
10540
10541     bmpError(bname, buf);
10542     goto ERROR;
10543   }
10544
10545   if (((biBitCount==1 || biBitCount==24) && biCompression != BI_RGB) ||
10546-      (biBitCount==4 && biCompression==BI_RLE8) ||
10547-      (biBitCount==8 && biCompression==BI_RLE4)) {
10548+      (biBitCount==4 && biCompression!=BI_RGB && biCompression!=BI_RLE4) ||
10549+      (biBitCount==8 && biCompression!=BI_RGB && biCompression!=BI_RLE8) ||
10550+      ((biBitCount==16 || biBitCount==32) &&
10551+       biCompression!=BI_RGB && biCompression!=BI_BITFIELDS)) {
10552
10553-    sprintf(buf,"Bogus BMP File!  (bitCount=%d, Compression=%d)",
10554+    sprintf(buf,"Unsupported BMP type (bitCount=%d, Compression=%d)",
10555 	    biBitCount, biCompression);
10556
10557     bmpError(bname, buf);
10558@@ -153,13 +178,21 @@
10559   if (biSize != WIN_OS2_OLD) {
10560     /* skip ahead to colormap, using biSize */
10561     c = biSize - 40;    /* 40 bytes read from biSize to biClrImportant */
10562-    for (i=0; i<c; i++) getc(fp);
10563-
10564+    for (i=0; i<c; i++)
10565+      getc(fp);
10566     bPad = bfOffBits - (biSize + 14);
10567   }
10568
10569+  /* 16-bit or 32-bit color mask */
10570+  if (biCompression==BI_BITFIELDS) {
10571+    colormask[0] = getint(fp);
10572+    colormask[1] = getint(fp);
10573+    colormask[2] = getint(fp);
10574+    bPad -= 12;
10575+  }
10576+
10577   /* load up colormap, if any */
10578-  if (biBitCount!=24) {
10579+  if (biBitCount == 1 || biBitCount == 4 || biBitCount == 8) {
10580     int i, cmaplen;
10581
10582     cmaplen = (biClrUsed) ? biClrUsed : 1 << biBitCount;
10583@@ -173,7 +206,7 @@
10584       }
10585     }
10586
10587-    if (FERROR(fp))
10588+    if (FERROR(fp))
10589       { bmpError(bname,"EOF reached in BMP colormap"); goto ERROR; }
10590
10591     if (DEBUG>1) {
10592@@ -188,7 +221,7 @@
10593   if (biSize != WIN_OS2_OLD) {
10594     /* Waste any unused bytes between the colour map (if present)
10595        and the start of the actual bitmap data. */
10596-
10597+
10598     while (bPad > 0) {
10599       (void) getc(fp);
10600       bPad--;
10601@@ -197,31 +230,57 @@
10602
10603   /* create pic8 or pic24 */
10604
10605-  if (biBitCount==24) {
10606-    pic24 = (byte *) calloc((size_t) biWidth * biHeight * 3, (size_t) 1);
10607+  if (biBitCount==16 || biBitCount==24 || biBitCount==32) {
10608+    u_int npixels = biWidth * biHeight;
10609+    u_int count = 3 * npixels;
10610+
10611+    if (biWidth == 0 || biHeight == 0 || npixels/biWidth != biHeight ||
10612+        count/3 != npixels)
10613+      return (bmpError(bname, "image dimensions too large"));
10614+    pic24 = (byte *) calloc((size_t) count, (size_t) 1);
10615     if (!pic24) return (bmpError(bname, "couldn't malloc 'pic24'"));
10616   }
10617   else {
10618-    pic8 = (byte *) calloc((size_t) biWidth * biHeight, (size_t) 1);
10619+    u_int npixels = biWidth * biHeight;
10620+
10621+    if (biWidth == 0 || biHeight == 0 || npixels/biWidth != biHeight)
10622+      return (bmpError(bname, "image dimensions too large"));
10623+    pic8 = (byte *) calloc((size_t) npixels, (size_t) 1);
10624     if (!pic8) return(bmpError(bname, "couldn't malloc 'pic8'"));
10625   }
10626
10627   WaitCursor();
10628
10629   /* load up the image */
10630-  if      (biBitCount == 1) rv = loadBMP1(fp,pic8,biWidth,biHeight);
10631-  else if (biBitCount == 4) rv = loadBMP4(fp,pic8,biWidth,biHeight,
10632-					  biCompression);
10633-  else if (biBitCount == 8) rv = loadBMP8(fp,pic8,biWidth,biHeight,
10634-					  biCompression);
10635-  else                      rv = loadBMP24(fp,pic24,biWidth,biHeight);
10636+  switch (biBitCount) {
10637+  case 1:
10638+    rv = loadBMP1(fp, pic8, biWidth, biHeight);
10639+    break;
10640+  case 4:
10641+    rv = loadBMP4(fp, pic8, biWidth, biHeight, biCompression);
10642+    break;
10643+  case 8:
10644+    rv = loadBMP8(fp, pic8, biWidth, biHeight, biCompression);
10645+    break;
10646+  case 16:
10647+    rv = loadBMP16(fp, pic24, biWidth, biHeight,           /*  v-- BI_RGB */
10648+                   biCompression == BI_BITFIELDS? colormask : NULL);
10649+    break;
10650+  default:
10651+    if (biBitCount == 32 && biCompression == BI_BITFIELDS)
10652+      rv = loadBMP32(fp, pic24, biWidth, biHeight, colormask);
10653+    else /* 24 or (32 and BI_RGB) */
10654+      rv = loadBMP24(fp, pic24, biWidth, biHeight, biBitCount);
10655+    break;
10656+  }
10657+
10658+  if (rv) bmpError(bname, "File appears truncated.  Winging it.");
10659
10660-  if (rv) bmpError(bname, "File appears truncated.  Winging it.\n");
10661
10662   fclose(fp);
10663
10664
10665-  if (biBitCount == 24) {
10666+  if (biBitCount > 8) {
10667     pinfo->pic  = pic24;
10668     pinfo->type = PIC24;
10669   }
10670@@ -233,6 +292,22 @@
10671   cmpstr = "";
10672   if      (biCompression == BI_RLE4) cmpstr = ", RLE4 compressed";
10673   else if (biCompression == BI_RLE8) cmpstr = ", RLE8 compressed";
10674+  else if (biCompression == BI_BITFIELDS) {
10675+    int    bit, c[3], i;
10676+    u_int  mask;
10677+
10678+    for (i = 0; i < 3; ++i) {
10679+      mask = colormask[i];
10680+      c[i] = 0;
10681+      for (bit = 0; bit < 32; ++bit) {
10682+        if (mask & 1)
10683+          ++c[i];
10684+        mask >>= 1;
10685+      }
10686+    }
10687+    sprintf(rgb_bits, ", RGB%d%d%d", c[0], c[1], c[2]);
10688+    cmpstr = rgb_bits;
10689+  }
10690
10691   pinfo->w = biWidth;  pinfo->h = biHeight;
10692   pinfo->normw = pinfo->w;   pinfo->normh = pinfo->h;
10693@@ -254,7 +329,7 @@
10694  ERROR:
10695   fclose(fp);
10696   return 0;
10697-}
10698+}
10699
10700
10701 /*******************************************/
10702@@ -264,12 +339,13 @@
10703      u_int  w,h;
10704 {
10705   int   i,j,c,bitnum,padw;
10706-  byte *pp;
10707+  byte *pp = pic8 + ((h - 1) * w);
10708+  size_t l = w*h;
10709
10710   c = 0;
10711   padw = ((w + 31)/32) * 32;  /* 'w', padded to be a multiple of 32 */
10712
10713-  for (i=h-1; i>=0; i--) {
10714+  for (i=h-1; i>=0 && (pp - pic8 <= l); i--) {
10715     pp = pic8 + (i * w);
10716     if ((i&0x3f)==0) WaitCursor();
10717     for (j=bitnum=0; j<padw; j++,bitnum++) {
10718@@ -277,7 +353,7 @@
10719 	c = getc(fp);
10720 	bitnum = 0;
10721       }
10722-
10723+
10724       if (j<w) {
10725 	*pp++ = (c & 0x80) ? 1 : 0;
10726 	c <<= 1;
10727@@ -287,7 +363,7 @@
10728   }
10729
10730   return (FERROR(fp));
10731-}
10732+}
10733
10734
10735
10736@@ -298,25 +374,25 @@
10737      u_int  w,h,comp;
10738 {
10739   int   i,j,c,c1,x,y,nybnum,padw,rv;
10740-  byte *pp;
10741-
10742-
10743+  byte *pp = pic8 + ((h - 1) * w);
10744+  size_t l = w*h;
10745+
10746   rv = 0;
10747   c = c1 = 0;
10748-
10749+
10750   if (comp == BI_RGB) {   /* read uncompressed data */
10751     padw = ((w + 7)/8) * 8; /* 'w' padded to a multiple of 8pix (32 bits) */
10752-
10753-    for (i=h-1; i>=0; i--) {
10754+
10755+    for (i=h-1; i>=0 && (pp - pic8 <= l); i--) {
10756       pp = pic8 + (i * w);
10757       if ((i&0x3f)==0) WaitCursor();
10758-
10759+
10760       for (j=nybnum=0; j<padw; j++,nybnum++) {
10761 	if ((nybnum & 1) == 0) { /* read next byte */
10762 	  c = getc(fp);
10763 	  nybnum = 0;
10764 	}
10765-
10766+
10767 	if (j<w) {
10768 	  *pp++ = (c & 0xf0) >> 4;
10769 	  c <<= 4;
10770@@ -325,55 +401,55 @@
10771       if (FERROR(fp)) break;
10772     }
10773   }
10774-
10775+
10776   else if (comp == BI_RLE4) {  /* read RLE4 compressed data */
10777-    x = y = 0;
10778+    x = y = 0;
10779     pp = pic8 + x + (h-y-1)*w;
10780-
10781+
10782     while (y<h) {
10783       c = getc(fp);  if (c == EOF) { rv = 1;  break; }
10784-
10785+
10786       if (c) {                                   /* encoded mode */
10787 	c1 = getc(fp);
10788-	for (i=0; i<c; i++,x++,pp++)
10789+	for (i=0; i<c && (pp - pic8 <= l); i++,x++,pp++)
10790 	  *pp = (i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f);
10791       }
10792-
10793+
10794       else {    /* c==0x00  :  escape codes */
10795 	c = getc(fp);  if (c == EOF) { rv = 1;  break; }
10796-
10797+
10798 	if      (c == 0x00) {                    /* end of line */
10799 	  x=0;  y++;  pp = pic8 + x + (h-y-1)*w;
10800-	}
10801-
10802+	}
10803+
10804 	else if (c == 0x01) break;               /* end of pic8 */
10805-
10806+
10807 	else if (c == 0x02) {                    /* delta */
10808 	  c = getc(fp);  x += c;
10809 	  c = getc(fp);  y += c;
10810 	  pp = pic8 + x + (h-y-1)*w;
10811 	}
10812-
10813+
10814 	else {                                   /* absolute mode */
10815-	  for (i=0; i<c; i++, x++, pp++) {
10816+	  for (i=0; i<c && (pp - pic8 <= l); i++, x++, pp++) {
10817 	    if ((i&1) == 0) c1 = getc(fp);
10818 	    *pp = (i&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f);
10819 	  }
10820-
10821+
10822 	  if (((c&3)==1) || ((c&3)==2)) getc(fp);  /* read pad byte */
10823 	}
10824       }  /* escape processing */
10825       if (FERROR(fp)) break;
10826     }  /* while */
10827   }
10828-
10829+
10830   else {
10831     fprintf(stderr,"unknown BMP compression type 0x%0x\n", comp);
10832   }
10833-
10834+
10835   if (FERROR(fp)) rv = 1;
10836   return rv;
10837-}
10838+}
10839
10840
10841
10842@@ -384,14 +460,18 @@
10843      u_int  w,h,comp;
10844 {
10845   int   i,j,c,c1,padw,x,y,rv;
10846-  byte *pp;
10847-
10848+  byte *pp = pic8 + ((h - 1) * w);
10849+  size_t l = w*h;
10850+  byte *pend;
10851+
10852   rv = 0;
10853
10854+  pend = pic8 + w * h;
10855+
10856   if (comp == BI_RGB) {   /* read uncompressed data */
10857     padw = ((w + 3)/4) * 4; /* 'w' padded to a multiple of 4pix (32 bits) */
10858
10859-    for (i=h-1; i>=0; i--) {
10860+    for (i=h-1; i>=0 && (pp - pic8 <= l); i--) {
10861       pp = pic8 + (i * w);
10862       if ((i&0x3f)==0) WaitCursor();
10863
10864@@ -404,15 +484,15 @@
10865   }
10866
10867   else if (comp == BI_RLE8) {  /* read RLE8 compressed data */
10868-    x = y = 0;
10869+    x = y = 0;
10870     pp = pic8 + x + (h-y-1)*w;
10871
10872-    while (y<h) {
10873+    while (y<h && pp<=pend) {
10874       c = getc(fp);  if (c == EOF) { rv = 1;  break; }
10875
10876       if (c) {                                   /* encoded mode */
10877 	c1 = getc(fp);
10878-	for (i=0; i<c; i++,x++,pp++) *pp = c1;
10879+	for (i=0; i<c && pp<=pend; i++,x++,pp++) *pp = c1;
10880       }
10881
10882       else {    /* c==0x00  :  escape codes */
10883@@ -420,7 +500,7 @@
10884
10885 	if      (c == 0x00) {                    /* end of line */
10886 	  x=0;  y++;  pp = pic8 + x + (h-y-1)*w;
10887-	}
10888+	}
10889
10890 	else if (c == 0x01) break;               /* end of pic8 */
10891
10892@@ -431,49 +511,156 @@
10893 	}
10894
10895 	else {                                   /* absolute mode */
10896-	  for (i=0; i<c; i++, x++, pp++) {
10897+	  for (i=0; i<c && pp<=pend; i++, x++, pp++) {
10898 	    c1 = getc(fp);
10899 	    *pp = c1;
10900 	  }
10901-
10902+
10903 	  if (c & 1) getc(fp);  /* odd length run: read an extra pad byte */
10904 	}
10905       }  /* escape processing */
10906       if (FERROR(fp)) break;
10907     }  /* while */
10908   }
10909-
10910+
10911   else {
10912     fprintf(stderr,"unknown BMP compression type 0x%0x\n", comp);
10913   }
10914
10915   if (FERROR(fp)) rv = 1;
10916   return rv;
10917-}
10918+}
10919
10920
10921
10922 /*******************************************/
10923-static int loadBMP24(fp, pic24, w, h)
10924+static int loadBMP16(fp, pic24, w, h, mask)
10925+     FILE  *fp;
10926+     byte  *pic24;
10927+     u_int w, h, *mask;
10928+{
10929+  int	 x, y;
10930+  byte	*pp = pic24 + ((h - 1) * w * 3);
10931+  size_t l = w*h*3;
10932+  u_int	 buf, colormask[6];
10933+  int	 i, bit, bitshift[6], colorbits[6], bitshift2[6];
10934+
10935+  if (mask == NULL) {  /* RGB555 */
10936+    colormask[0] = 0x00007c00;
10937+    colormask[1] = 0x000003e0;
10938+    colormask[2] = 0x0000001f;
10939+    colormask[3] = 0x7c000000;
10940+    colormask[4] = 0x03e00000;
10941+    colormask[5] = 0x001f0000;
10942+    bitshift[0] =  7;	bitshift2[0] = 0;
10943+    bitshift[1] =  2;	bitshift2[1] = 0;
10944+    bitshift[2] =  0;	bitshift2[2] = 3;
10945+    bitshift[3] = 23;	bitshift2[3] = 0;
10946+    bitshift[4] = 18;	bitshift2[4] = 0;
10947+    bitshift[5] = 13;	bitshift2[5] = 0;
10948+  } else {
10949+    colormask[0] = mask[0];
10950+    colormask[1] = mask[1];
10951+    colormask[2] = mask[2];
10952+    colormask[3] = (mask[0] & 0xffff) << 16;
10953+    colormask[4] = (mask[1] & 0xffff) << 16;
10954+    colormask[5] = (mask[2] & 0xffff) << 16;
10955+
10956+    for (i = 0; i < 3; ++i) {
10957+      buf = colormask[i];
10958+
10959+      bitshift[i] = 0;
10960+      for (bit = 0; bit < 32; ++bit) {
10961+	if (buf & 1)
10962+	  break;
10963+	else
10964+	  ++bitshift[i];
10965+	buf >>= 1;
10966+      }
10967+      bitshift[i+3] = bitshift[i] + 16;
10968+
10969+      colorbits[i] = 0;
10970+      for (; bit < 32; ++bit) {
10971+	if (buf & 1)
10972+	  ++colorbits[i];
10973+	else
10974+	  break;
10975+	buf >>= 1;
10976+      }
10977+      if (colorbits[i] > 8) { /* over 8-bit depth */
10978+	bitshift[i] += (colorbits[i] - 8);
10979+	bitshift[i+3] = bitshift[i] + 16;
10980+	bitshift2[i] = bitshift2[i+3] = 0;
10981+      } else
10982+	bitshift2[i] = bitshift2[i+3] = 8 - colorbits[i];
10983+    }
10984+  }
10985+
10986+  if (DEBUG > 1)
10987+    fprintf(stderr, "loadBMP16: bitfields\n"
10988+	    "\tR: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
10989+	    "\t             (mask = %08x, shift >>%2d, <<%2d)\n"
10990+	    "\tG: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
10991+	    "\t             (mask = %08x, shift >>%2d, <<%2d)\n"
10992+	    "\tB: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
10993+	    "\t             (mask = %08x, shift >>%2d, <<%2d)\n",
10994+	    colorbits[0], colormask[0], bitshift[0], bitshift2[0],
10995+	    colormask[3], bitshift[3], bitshift2[3],
10996+	    colorbits[1], colormask[1], bitshift[1], bitshift2[1],
10997+	    colormask[4], bitshift[4], bitshift2[4],
10998+	    colorbits[2], colormask[2], bitshift[2], bitshift2[2],
10999+	    colormask[5], bitshift[5], bitshift2[5]);
11000+
11001+  for (y = h-1; y >= 0 && (pp - pic24 <= l); y--) {
11002+    pp = pic24 + (3 * w * y);
11003+    if ((y&0x3f)==0) WaitCursor();
11004+
11005+    for (x = w; x > 1; x -= 2) {
11006+      buf = getint(fp);
11007+      *(pp++) = (buf & colormask[0]) >> bitshift[0] << bitshift2[0];
11008+      *(pp++) = (buf & colormask[1]) >> bitshift[1] << bitshift2[1];
11009+      *(pp++) = (buf & colormask[2]) >> bitshift[2] << bitshift2[2];
11010+      *(pp++) = (buf & colormask[3]) >> bitshift[3] << bitshift2[3];
11011+      *(pp++) = (buf & colormask[4]) >> bitshift[4] << bitshift2[4];
11012+      *(pp++) = (buf & colormask[5]) >> bitshift[5] << bitshift2[5];
11013+    }
11014+    if (w & 1) { /* padded to 2 pix */
11015+      buf = getint(fp);
11016+      *(pp++) = (buf & colormask[0]) >> bitshift[0];
11017+      *(pp++) = (buf & colormask[1]) >> bitshift[1];
11018+      *(pp++) = (buf & colormask[2]) >> bitshift[2];
11019+    }
11020+  }
11021+
11022+  return FERROR(fp)? 1 : 0;
11023+}
11024+
11025+
11026+
11027+/*******************************************/
11028+static int loadBMP24(fp, pic24, w, h, bits)   /* also handles 32-bit BI_RGB */
11029      FILE *fp;
11030      byte *pic24;
11031-     u_int  w,h;
11032+     u_int  w,h, bits;
11033 {
11034   int   i,j,padb,rv;
11035-  byte *pp;
11036+  byte *pp = pic24 + ((h - 1) * w * 3);
11037+  size_t l = w*h*3;
11038
11039   rv = 0;
11040
11041   padb = (4 - ((w*3) % 4)) & 0x03;  /* # of pad bytes to read at EOscanline */
11042+  if (bits==32) padb = 0;
11043
11044   for (i=h-1; i>=0; i--) {
11045     pp = pic24 + (i * w * 3);
11046     if ((i&0x3f)==0) WaitCursor();
11047-
11048-    for (j=0; j<w; j++) {
11049+
11050+    for (j=0; j<w && (pp - pic24 <= l); j++) {
11051       pp[2] = getc(fp);   /* blue */
11052       pp[1] = getc(fp);   /* green */
11053       pp[0] = getc(fp);   /* red */
11054+      if (bits==32) getc(fp);
11055       pp += 3;
11056     }
11057
11058@@ -484,30 +671,94 @@
11059   }
11060
11061   return rv;
11062-}
11063+}
11064+
11065+
11066+
11067+/*******************************************/
11068+static int loadBMP32(fp, pic24, w, h, colormask) /* 32-bit BI_BITFIELDS only */
11069+     FILE  *fp;
11070+     byte  *pic24;
11071+     u_int w, h, *colormask;
11072+{
11073+  int	 x, y;
11074+  byte	*pp;
11075+  u_int	 buf;
11076+  int	 i, bit, bitshift[3], colorbits[3], bitshift2[3];
11077+
11078+  for (i = 0; i < 3; ++i) {
11079+    buf = colormask[i];
11080+
11081+    bitshift[i] = 0;
11082+    for (bit = 0; bit < 32; ++bit) {
11083+      if (buf & 1)
11084+	break;
11085+      else
11086+	++bitshift[i];
11087+      buf >>= 1;
11088+    }
11089+
11090+    colorbits[i] = 0;
11091+    for (; bit < 32; ++bit) {
11092+      if (buf & 1)
11093+	++colorbits[i];
11094+      else
11095+	break;
11096+      buf >>= 1;
11097+    }
11098+    if (colorbits[i] > 8) {  /* over 8-bit depth */
11099+      bitshift[i] += (colorbits[i] - 8);
11100+      bitshift2[i] = 0;
11101+    } else
11102+      bitshift2[i] = 8 - colorbits[i];
11103+  }
11104+
11105+  if (DEBUG > 1)
11106+    fprintf(stderr, "loadBMP32: bitfields\n"
11107+	    "\tR: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
11108+	    "\tG: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
11109+	    "\tB: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n",
11110+	    colorbits[0], colormask[0], bitshift[0], bitshift2[0],
11111+	    colorbits[1], colormask[1], bitshift[1], bitshift2[1],
11112+	    colorbits[2], colormask[2], bitshift[2], bitshift2[2]);
11113+
11114+  for (y = h-1; y >= 0; y--) {
11115+    pp = pic24 + (3 * w * y);
11116+    if ((y&0x3f)==0) WaitCursor();
11117+
11118+    for(x = w; x > 0; x --) {
11119+      buf = getint(fp);
11120+      *(pp++) = (buf & colormask[0]) >> bitshift[0] << bitshift2[0];
11121+      *(pp++) = (buf & colormask[1]) >> bitshift[1] << bitshift2[1];
11122+      *(pp++) = (buf & colormask[2]) >> bitshift[2] << bitshift2[2];
11123+    }
11124+  }
11125+
11126+  return FERROR(fp)? 1 : 0;
11127+}
11128
11129
11130
11131 /*******************************************/
11132-static unsigned int getshort(fp)
11133+static u_int getshort(fp)
11134      FILE *fp;
11135 {
11136   int c, c1;
11137   c = getc(fp);  c1 = getc(fp);
11138-  return ((unsigned int) c) + (((unsigned int) c1) << 8);
11139+  return ((u_int) c) + (((u_int) c1) << 8);
11140 }
11141
11142
11143 /*******************************************/
11144-static unsigned int getint(fp)
11145+static u_int getint(fp)
11146      FILE *fp;
11147 {
11148   int c, c1, c2, c3;
11149   c = getc(fp);  c1 = getc(fp);  c2 = getc(fp);  c3 = getc(fp);
11150-  return ((unsigned int) c) +
11151-         (((unsigned int) c1) << 8) +
11152-	 (((unsigned int) c2) << 16) +
11153-	 (((unsigned int) c3) << 24);
11154+  return  ((u_int) c) +
11155+	 (((u_int) c1) << 8) +
11156+	 (((u_int) c2) << 16) +
11157+	 (((u_int) c3) << 24);
11158 }
11159
11160
11161@@ -518,7 +769,7 @@
11162 {
11163   int c, c1;
11164
11165-  c = ((unsigned int ) i) & 0xff;  c1 = (((unsigned int) i)>>8) & 0xff;
11166+  c = ((u_int) i) & 0xff;  c1 = (((u_int) i)>>8) & 0xff;
11167   putc(c, fp);   putc(c1,fp);
11168 }
11169
11170@@ -529,10 +780,10 @@
11171      int i;
11172 {
11173   int c, c1, c2, c3;
11174-  c  = ((unsigned int ) i)      & 0xff;
11175-  c1 = (((unsigned int) i)>>8)  & 0xff;
11176-  c2 = (((unsigned int) i)>>16) & 0xff;
11177-  c3 = (((unsigned int) i)>>24) & 0xff;
11178+  c  =  ((u_int) i)      & 0xff;
11179+  c1 = (((u_int) i)>>8)  & 0xff;
11180+  c2 = (((u_int) i)>>16) & 0xff;
11181+  c3 = (((u_int) i)>>24) & 0xff;
11182
11183   putc(c, fp);   putc(c1,fp);  putc(c2,fp);  putc(c3,fp);
11184 }
11185@@ -562,11 +813,11 @@
11186    *    8-bit image
11187    * note that PIC24 and F_BWDITHER/F_REDUCED won't happen
11188    *
11189-   * if colorstyle == F_BWDITHER, it writes a 1-bit image
11190+   * if colorstyle == F_BWDITHER, it writes a 1-bit image
11191    *
11192    */
11193
11194-  int i,j, nc, nbits, bperlin, cmaplen;
11195+  int i,j, nc, nbits, bperlin, cmaplen, npixels;
11196   byte *graypic, *sp, *dp, graymap[256];
11197
11198   nc = nbits = cmaplen = 0;
11199@@ -576,10 +827,16 @@
11200     /* generate a faked 8-bit per pixel image with a grayscale cmap,
11201        so that it can just fall through existing 8-bit code */
11202
11203-    graypic = (byte *) malloc((size_t) w*h);
11204+    npixels = w * h;
11205+    if (w <= 0 || h <= 0 || npixels/w != h) {
11206+      SetISTR(ISTR_WARNING, "image dimensions too large");
11207+      return -1;
11208+    }
11209+
11210+    graypic = (byte *) malloc((size_t) npixels);
11211     if (!graypic) FatalError("unable to malloc in WriteBMP()");
11212
11213-    for (i=0,sp=pic824,dp=graypic; i<w*h; i++,sp+=3, dp++) {
11214+    for (i=0,sp=pic824,dp=graypic; i<npixels; i++,sp+=3, dp++) {
11215       *dp = MONO(sp[0],sp[1],sp[2]);
11216     }
11217
11218@@ -611,7 +868,7 @@
11219     for (i=0; i<numcols; i++) {
11220       /* see if color #i is a duplicate */
11221       for (j=0; j<i; j++) {
11222-	if (rmap[i] == rmap[j] && gmap[i] == gmap[j] &&
11223+	if (rmap[i] == rmap[j] && gmap[i] == gmap[j] &&
11224 	    bmap[i] == bmap[j]) break;
11225       }
11226
11227@@ -689,13 +946,13 @@
11228 #else
11229   if (!FERROR(fp)) return -1;
11230 #endif
11231-
11232+
11233   return 0;
11234 }
11235
11236
11237-
11238-
11239+
11240+
11241 /*******************************************/
11242 static void writeBMP1(fp, pic8, w, h)
11243      FILE *fp;
11244@@ -708,7 +965,7 @@
11245   padw = ((w + 31)/32) * 32;  /* 'w', padded to be a multiple of 32 */
11246
11247   for (i=h-1; i>=0; i--) {
11248-    pp = pic8 + (i * w);
11249+    pp = pic8 + (i * w);
11250     if ((i&0x3f)==0) WaitCursor();
11251
11252     for (j=bitnum=c=0; j<=padw; j++,bitnum++) {
11253@@ -716,7 +973,7 @@
11254 	putc(c,fp);
11255 	bitnum = c = 0;
11256       }
11257-
11258+
11259       c <<= 1;
11260
11261       if (j<w) {
11262@@ -724,7 +981,7 @@
11263       }
11264     }
11265   }
11266-}
11267+}
11268
11269
11270
11271@@ -758,7 +1015,7 @@
11272       }
11273     }
11274   }
11275-}
11276+}
11277
11278
11279
11280@@ -768,7 +1025,7 @@
11281      byte *pic8;
11282      int  w,h;
11283 {
11284-  int   i,j,c,padw;
11285+  int   i,j,padw;
11286   byte *pp;
11287
11288   padw = ((w + 3)/4) * 4; /* 'w' padded to a multiple of 4pix (32 bits) */
11289@@ -780,7 +1037,7 @@
11290     for (j=0; j<w; j++) putc(pc2nc[*pp++], fp);
11291     for ( ; j<padw; j++) putc(0, fp);
11292   }
11293-}
11294+}
11295
11296
11297 /*******************************************/
11298@@ -789,7 +1046,7 @@
11299      byte *pic24;
11300      int  w,h;
11301 {
11302-  int   i,j,c,padb;
11303+  int   i,j,padb;
11304   byte *pp;
11305
11306   padb = (4 - ((w*3) % 4)) & 0x03;  /* # of pad bytes to write at EOscanline */
11307@@ -807,7 +1064,7 @@
11308
11309     for (j=0; j<padb; j++) putc(0, fp);
11310   }
11311-}
11312+}
11313
11314
11315
11316@@ -816,7 +1073,7 @@
11317
11318 /*******************************************/
11319 static int bmpError(fname, st)
11320-     char *fname, *st;
11321+     const char *fname, *st;
11322 {
11323   SetISTR(ISTR_WARNING,"%s:  %s", fname, st);
11324   return 0;
11325diff -ru xv-3.10a/xvbrowse.c xv-3.10a-enhancements/xvbrowse.c
11326--- xv-3.10a/xvbrowse.c	1995-01-19 09:49:17.000000000 -0800
11327+++ xv-3.10a-enhancements/xvbrowse.c	2007-05-13 17:50:18.000000000 -0700
11328@@ -1,6 +1,6 @@
11329 /*
11330  *  xvbrowse.c  -  visual schnauzer routines
11331- *
11332+ *
11333  *  includes:
11334  *      void CreateBrowse(char *, char *, char *, char *, char *);
11335  *      void OpenBrowse();
11336@@ -19,11 +19,16 @@
11337
11338 #define NEEDSDIR
11339 #include "xv.h"
11340+#include <unistd.h>   /* access() */
11341
11342 #if defined(VMS) || defined(isc)
11343 typedef unsigned int mode_t;  /* file mode bits */
11344 #endif
11345
11346+#ifndef MAX
11347+#  define MAX(a,b) (((a)>(b))?(a):(b))   /* used only for wheelmouse support */
11348+#endif
11349+
11350
11351 /* load up built-in icons */
11352 #include "bits/br_file"
11353@@ -34,27 +39,40 @@
11354 #include "bits/br_sock"
11355 #include "bits/br_fifo"
11356 #include "bits/br_error"
11357-#include "bits/br_unknown"
11358+/* #include "bits/br_unknown"	commented out (near line 492) */
11359+
11360 #include "bits/br_cmpres"
11361+#include "bits/br_bzip2"
11362
11363-#include "bits/br_gif"
11364-#include "bits/br_pm"
11365-#include "bits/br_pbm"
11366-#include "bits/br_xbm"
11367-#include "bits/br_sunras"
11368 #include "bits/br_bmp"
11369-#include "bits/br_utah"
11370+#include "bits/br_fits"
11371+#include "bits/br_gif"
11372+#include "bits/br_iff"
11373 #include "bits/br_iris"
11374-#include "bits/br_pcx"
11375 #include "bits/br_jfif"
11376-#include "bits/br_tiff"
11377+#include "bits/br_jp2"
11378+#include "bits/br_jpc"
11379+#include "bits/br_mag"
11380+#include "bits/br_maki"
11381+#include "bits/br_mgcsfx"
11382+#include "bits/br_pbm"
11383+#include "bits/br_pcd"
11384+#include "bits/br_pcx"
11385 #include "bits/br_pds"
11386+#include "bits/br_pi"
11387+#include "bits/br_pic"
11388+#include "bits/br_pic2"
11389+#include "bits/br_pm"
11390+#include "bits/br_png"
11391 #include "bits/br_ps"
11392-#include "bits/br_iff"
11393+#include "bits/br_sunras"
11394 #include "bits/br_targa"
11395+#include "bits/br_tiff"
11396+#include "bits/br_utah"
11397+#include "bits/br_xbm"
11398 #include "bits/br_xpm"
11399 #include "bits/br_xwd"
11400-#include "bits/br_fits"
11401+#include "bits/br_zx"	/* [JCE] The Spectrum+3 icon */
11402
11403 #include "bits/br_trash"
11404 #include "bits/fcurs"
11405@@ -90,17 +108,28 @@
11406 #define BF_COMPRESS 21
11407 #define BF_PS       22
11408 #define BF_IFF      23
11409-#define BF_TARGA    24
11410+#define BF_TGA      24
11411 #define BF_XPM      25
11412 #define BF_XWD      26
11413 #define BF_FITS     27
11414-#define BF_MAX      28    /* # of built-in icons */
11415+#define BF_PNG      28
11416+#define BF_ZX       29    /* [JCE] Spectrum SCREEN$ */
11417+#define BF_PCD      30
11418+#define BF_BZIP2    31
11419+#define BF_JP2      32
11420+#define BF_JPC      33
11421+#define JP_EXT_BF   (BF_JPC)
11422+#define BF_MAG      (JP_EXT_BF + 1)
11423+#define BF_MAKI     (JP_EXT_BF + 2)
11424+#define BF_PIC      (JP_EXT_BF + 3)
11425+#define BF_PI       (JP_EXT_BF + 4)
11426+#define BF_PIC2     (JP_EXT_BF + 5)
11427+#define BF_MGCSFX   (JP_EXT_BF + 6)
11428+#define JP_EXT_BF_END  (BF_MGCSFX)
11429+#define BF_MAX      (JP_EXT_BF_END + 1)    /* # of built-in icons */
11430
11431 #define ISLOADABLE(ftyp) (ftyp!=BF_DIR  && ftyp!=BF_CHR && ftyp!=BF_BLK && \
11432-			  ftyp!=BF_SOCK && ftyp!=BF_FIFO)
11433-
11434-#define DEF_BROWWIDE 615   /* default size of window */
11435-#define DEF_BROWHIGH 356
11436+			  ftyp!=BF_SOCK && ftyp!=BF_FIFO)
11437
11438 #define SCROLLVERT  8      /* height of scroll region at top/bottom of iconw */
11439 #define PAGEVERT    40     /* during rect drag, if further than this, page */
11440@@ -113,59 +142,93 @@
11441 #define BOTMARGIN 58       /* room for a row of buttons and a line of text */
11442 #define LRMARGINS 5        /* left and right margins */
11443
11444-#define ISIZE_WIDE   80    /* maximum size of an icon */
11445-#define ISIZE_HIGH   60
11446+/* some people like bigger icons; 4:3 aspect ratio is recommended
11447+ * (NOTE:  standard XV binaries will not be able to read larger icons!) */
11448+#ifndef ISIZE_WIDE
11449+#  define ISIZE_WIDE 80    /* maximum size of an icon */
11450+#endif
11451+#ifndef ISIZE_HIGH
11452+#  define ISIZE_HIGH 60
11453+#endif
11454+
11455+#ifndef ISIZE_WPAD
11456+#  define ISIZE_WPAD 16    /* extra horizontal padding between icons */
11457+#endif
11458+
11459+#ifndef INUM_WIDE
11460+#  define INUM_WIDE 6      /* size initial window to hold this many icons */
11461+#endif
11462+#ifndef INUM_HIGH
11463+#  define INUM_HIGH 3
11464+#endif
11465
11466-#define ISPACE_WIDE (ISIZE_WIDE+16)   /* icon spacing */
11467+#define ISPACE_WIDE (ISIZE_WIDE+ISIZE_WPAD)   /* icon spacing */
11468 #define ISPACE_TOP  4                 /* dist btwn top of ISPACE and ISIZE */
11469 #define ISPACE_TTOP 4                 /* dist btwn bot of icon and title */
11470 #define ISPACE_HIGH (ISIZE_HIGH+ISPACE_TOP+ISPACE_TTOP+16+4)
11471
11472 #define DBLCLICKTIME 300  /* milliseconds */
11473
11474-/* button/menu indicies */
11475-#define BR_CHDIR    0
11476-#define BR_DELETE   1
11477-#define BR_MKDIR    2
11478-#define BR_RENAME   3
11479-#define BR_RESCAN   4
11480-#define BR_UPDATE   5
11481-#define BR_NEWWIN   6
11482-#define BR_GENICON  7
11483-#define BR_SELALL   8
11484-#define BR_TEXTVIEW 9
11485-#define BR_RECURSUP 10
11486-#define BR_QUIT     11
11487-#define BR_CLOSE    12
11488-#define BR_NBUTTS   13   /* # of command buttons */
11489-#define BR_SEP1     13   /* separator */
11490-#define BR_HIDDEN   14
11491-#define BR_SELFILES 15
11492-#define BR_NCMDS    16   /* # of menu commands */
11493+#define COUNT(x) (sizeof (x) / sizeof (x)[0])
11494+
11495+/* button/menu indices */
11496+#define BR_CHDIR      0
11497+#define BR_DELETE     1
11498+#define BR_MKDIR      2
11499+#define BR_RENAME     3
11500+#define BR_RESCAN     4
11501+#define BR_UPDATE     5
11502+#define BR_NEWWIN     6
11503+#define BR_GENICON    7
11504+#define BR_SELALL     8
11505+#define BR_TEXTVIEW   9
11506+#define BR_RECURSUP   10
11507+#define BR_QUIT       11
11508+#define BR_CLOSE      12
11509+#define BR_NBUTTS     13   /* # of command buttons */
11510+#define BR_SEP1       13   /* separator */
11511+#define BR_HIDDEN     14
11512+#define BR_SELFILES   15
11513+#define BR_CLIPBRD    16
11514+#ifdef AUTO_EXPAND
11515+#  define BR_CLEARVD  17
11516+#  define BR_NCMDS    18   /* # of menu commands */
11517+#else
11518+#  define BR_NCMDS    17   /* # of menu commands */
11519+#endif
11520
11521 #define BUTTW 80
11522 #define BUTTH 24
11523
11524-static char *showHstr = "Show hidden files";
11525-static char *hideHstr = "Hide 'hidden' files";
11526-
11527-static char *cmdMList[] = { "Change directory...\t^c",
11528-		            "Delete file(s)\t^d",
11529-			    "New directory...\t^n",
11530-			    "Rename file...\t^r",
11531-			    "Rescan directory\t^s",
11532-			    "Update icons\t^u",
11533-			    "Open new window\t^w",
11534-			    "Generate icon(s)\t^g",
11535-			    "Select all files\t^a",
11536-			    "Text view\t^t",
11537-			    "Recursive Update\t^e",
11538-			    "Quit xv\t^q",
11539-			    "Close window\t^c",
11540-			    MBSEP,
11541-			    "Show hidden files",     /* no equiv */
11542-			    "Select files...\t^f"
11543-			    };
11544+/* original size of window was 615 x 356 (for 80x60 thumbnails in 6x3 array) */
11545+#define DEF_BROWWIDE  (ISPACE_WIDE * INUM_WIDE + LRMARGINS * 2 + 29)
11546+#define DEF_BROWHIGH  (ISPACE_HIGH * INUM_HIGH + BUTTH * 2 + 16 + 28)
11547+/* last number is a fudge--e.g., extra spaces, borders, etc. -----^  */
11548+
11549+static const char *showHstr = "Show hidden files";
11550+static const char *hideHstr = "Hide 'hidden' files";
11551+
11552+static const char *cmdMList[] = { "Change directory...\t^c",
11553+				  "Delete file(s)\t^d",
11554+				  "New directory...\t^n",
11555+				  "Rename file...\t^r",
11556+				  "Rescan directory\t^s",
11557+				  "Update icons\t^u",
11558+				  "Open new window\t^w",
11559+				  "Generate icon(s)\t^g",
11560+				  "Select all files\t^a",
11561+				  "Text view\t^t",
11562+				  "Recursive Update\t^e",
11563+				  "Quit xv\t^q",
11564+				  "Close window\t^c",
11565+				  MBSEP,
11566+				  "Show hidden files",     /* no equiv */
11567+				  "Select files...\t^f",
11568+				  "Clipboard\t^x"
11569+#ifdef AUTO_EXPAND
11570+				  , "Clear virtual directory"
11571+#endif
11572+				  };
11573
11574
11575 #define MAXDEEP 30     /* maximum directory depth */
11576@@ -183,32 +246,43 @@
11577 	       } BFIL;
11578
11579 /* data needed per schnauzer window */
11580-typedef struct {  Window win, iconW;
11581-		  int    vis, wasvis;
11582+typedef struct {  Window        win, iconW;
11583+		  int           vis, wasvis;
11584
11585-		  int    wide, high;
11586-		  int    iwWide, iwHigh;
11587-		  int    numWide, numHigh, visHigh;
11588-
11589-		  SCRL   scrl;
11590-		  BUTT   but[BR_NBUTTS];
11591-		  MBUTT  dirMB, cmdMB;
11592-		  char   dispstr[256];
11593-		  int    numbutshown;
11594-		  int    showhidden;
11595-
11596-		  int    numlit;
11597-		  BFIL  *bfList;
11598-		  int    bfLen;
11599-		  int    lastIconClicked;
11600+		  int           wide, high;
11601+		  int           iwWide, iwHigh;
11602+		  int           numWide, numHigh, visHigh;
11603+
11604+		  SCRL          scrl;
11605+		  BUTT          but[BR_NBUTTS];
11606+		  MBUTT         dirMB, cmdMB;
11607+		  char          dispstr[256];
11608+		  int           numbutshown;
11609+		  int           showhidden;
11610+
11611+		  int           numlit;
11612+		  BFIL         *bfList;
11613+		  int           bfLen;
11614+		  int           lastIconClicked;
11615 		  unsigned long lastClickTime;
11616
11617-		  int    ndirs;
11618-		  char  *mblist[MAXDEEP];
11619-		  char   path[MAXPATHLEN+2];   /* '/' terminated */
11620+		  int           ndirs;
11621+		  const char   *mblist[MAXDEEP];
11622+		  char          path[MAXPATHLEN+2];   /* '/' terminated */
11623+
11624+		  char         *str;
11625+		  int           siz, len;
11626+		  time_t        lst;
11627 		} BROWINFO;
11628
11629
11630+/* keep track of last icon visible in each path */
11631+typedef struct IVIS IVIS;
11632+    struct IVIS { IVIS   *next;
11633+                  char   *name;
11634+                  int    icon;
11635+                };
11636+
11637 static Cursor   movecurs, copycurs, delcurs;
11638 static BROWINFO binfo[MAXBRWIN];
11639 static Pixmap   bfIcons[BF_MAX], trashPix;
11640@@ -220,7 +294,7 @@
11641 static void closeBrowse      PARM((BROWINFO *));
11642 static int  brChkEvent       PARM((BROWINFO *, XEvent *));
11643 static void resizeBrowse     PARM((BROWINFO *, int, int));
11644-static void setBrowStr       PARM((BROWINFO *, char *));
11645+static void setBrowStr       PARM((BROWINFO *, const char *));
11646 static void doCmd            PARM((BROWINFO *, int));
11647 static void drawBrow         PARM((BROWINFO *));
11648 static void drawNumfiles     PARM((BROWINFO *));
11649@@ -255,12 +329,12 @@
11650 static void rescanDir        PARM((BROWINFO *));
11651 static int  namcmp           PARM((const void *, const void *));
11652 static void freeBfList       PARM((BROWINFO *br));
11653-static char **getDirEntries  PARM((char *, int *, int));
11654+static char **getDirEntries  PARM((const char *, int *, int));
11655 static void computeScrlVals  PARM((BROWINFO *, int *, int *));
11656 static void genSelectedIcons PARM((BROWINFO *));
11657 static void genIcon          PARM((BROWINFO *, BFIL *));
11658 static void loadThumbFile    PARM((BROWINFO *, BFIL *));
11659-static void writeThumbFile   PARM((BROWINFO *, BFIL *, byte *, int,
11660+static void writeThumbFile   PARM((BROWINFO *, BFIL *, byte *, int,
11661 				      int, char *));
11662
11663 static void makeThumbDir     PARM((BROWINFO *));
11664@@ -278,14 +352,14 @@
11665 static void doSelFilesCmd    PARM((BROWINFO *));
11666
11667 static void doRecurseCmd     PARM((BROWINFO *));
11668-static void recurseUpdate    PARM((BROWINFO *, char *));
11669+static void recurseUpdate    PARM((BROWINFO *, const char *));
11670
11671 static void rm_file          PARM((BROWINFO *, char *));
11672 static void rm_dir           PARM((BROWINFO *, char *));
11673 static void rm_dir1          PARM((BROWINFO *));
11674
11675-static void dragFiles        PARM((BROWINFO *, BROWINFO *, char *, char *,
11676-				   char *, char **, int, int));
11677+static void dragFiles        PARM((BROWINFO *, BROWINFO *, char *, char *,
11678+				   const char *, char **, int, int));
11679 static int  moveFile         PARM((char *, char *));
11680 static int  copyFile         PARM((char *, char *));
11681 static void cp               PARM((void));
11682@@ -294,16 +368,25 @@
11683 static void cp_special       PARM((struct stat *, int));
11684 static void cp_fifo          PARM((struct stat *, int));
11685
11686+#ifdef AUTO_EXPAND
11687+static int  stat2bf          PARM((u_int, char *));
11688+#else
11689 static int  stat2bf          PARM((u_int));
11690+#endif
11691
11692 static int  selmatch         PARM((char *, char *));
11693 static int  selmatch1        PARM((char *, char *));
11694+static void recIconVisible   PARM((char *, int));
11695+static void restIconVisible  PARM((BROWINFO *));
11696+
11697+static void clipChanges      PARM((BROWINFO *));
11698
11699
11700
11701 /***************************************************************/
11702 void CreateBrowse(geom, fgstr, bgstr, histr, lostr)
11703-     char *geom, *fgstr, *bgstr, *histr, *lostr;
11704+     const char *geom;
11705+     const char *fgstr, *bgstr, *histr, *lostr;
11706 {
11707   int                   i;
11708   XSizeHints            hints;
11709@@ -369,8 +452,8 @@
11710       if (gset & YNegative) gy1 = gy - i * 20;
11711 	               else gy1 = gy + i * 20;
11712
11713-      if ((gset & WidthValue) && (gset & HeightValue))
11714-	sprintf(wgeom, "%dx%d%s%d%s%d", gw, gh,
11715+      if ((gset & WidthValue) && (gset & HeightValue))
11716+	sprintf(wgeom, "%dx%d%s%d%s%d", gw, gh,
11717 		(gset & XNegative) ? "-" : "+", abs(gx1),
11718 		(gset & YNegative) ? "-" : "+", abs(gy1));
11719       else
11720@@ -402,11 +485,11 @@
11721
11722     /* note: everything is sized and positioned in ResizeBrowse() */
11723
11724-    br->iconW = XCreateSimpleWindow(theDisp, br->win, 1,1, 100,100,
11725+    br->iconW = XCreateSimpleWindow(theDisp, br->win, 1,1, 100,100,
11726 				     1,browfg,browbg);
11727     if (!br->iconW) FatalError("can't create schnauzer icon window!");
11728
11729-    SCCreate(&(br->scrl), br->win, 0,0, 1,100, 0,0,0,0,
11730+    SCCreate(&(br->scrl), br->win, 0,0, 1,100, 0,0,0,0,
11731 	     browfg, browbg, browhi, browlo, drawIconWin);
11732
11733
11734@@ -448,10 +531,12 @@
11735 	     "Text view",browfg,browbg,browhi,browlo);
11736     BTCreate(&(br->but[BR_RECURSUP]), br->win, 0,0,BUTTW,BUTTH,
11737 	     "RecursUpd",browfg,browbg,browhi,browlo);
11738-    BTCreate(&(br->but[BR_QUIT]),  br->win, 0,0,BUTTW,BUTTH,
11739+    BTCreate(&(br->but[BR_QUIT]), br->win, 0,0,BUTTW,BUTTH,
11740 	     "Quit xv",browfg,browbg,browhi,browlo);
11741-    BTCreate(&(br->but[BR_CLOSE]),  br->win, 0,0,BUTTW,BUTTH,
11742+    BTCreate(&(br->but[BR_CLOSE]), br->win, 0,0,BUTTW,BUTTH,
11743 	     "Close",browfg,browbg,browhi,browlo);
11744+    BTCreate(&(br->but[BR_CLIPBRD]), br->win, 0,0,BUTTW,BUTTH,
11745+	     "Clipboard",browfg,browbg,browhi,browlo);
11746
11747     XMapSubwindows(theDisp, br->win);
11748
11749@@ -486,55 +571,62 @@
11750   bfIcons[BF_SOCK]=MakePix1(br->win,br_sock_bits,br_sock_width,br_sock_height);
11751   bfIcons[BF_FIFO]=MakePix1(br->win,br_fifo_bits,br_fifo_width,br_fifo_height);
11752
11753-  bfIcons[BF_ERROR]   = MakePix1(br->win, br_error_bits,
11754+  bfIcons[BF_ERROR]   = MakePix1(br->win, br_error_bits,
11755 			       br_error_width,     br_error_height);
11756
11757 /* bfIcons[BF_UNKNOWN] = MakePix1(br->win, br_unknown_bits,
11758                                 br_unknown_width, br_unknown_height); */
11759-
11760   bfIcons[BF_UNKNOWN] = bfIcons[BF_FILE];
11761
11762-  bfIcons[BF_GIF] =MakePix1(br->win,br_gif_bits, br_gif_width, br_gif_height);
11763-  bfIcons[BF_PM]  =MakePix1(br->win,br_pm_bits,  br_pm_width,  br_pm_height);
11764-  bfIcons[BF_PBM] =MakePix1(br->win,br_pbm_bits, br_pbm_width, br_pbm_height);
11765-  bfIcons[BF_XBM] =MakePix1(br->win,br_xbm_bits, br_xbm_width, br_xbm_height);
11766-
11767-  bfIcons[BF_SUNRAS]  = MakePix1(br->win, br_sunras_bits,
11768-				 br_sunras_width, br_sunras_height);
11769-  bfIcons[BF_BMP]     = MakePix1(br->win,br_bmp_bits,
11770-				 br_bmp_width, br_bmp_height);
11771-  bfIcons[BF_UTAHRLE] = MakePix1(br->win, br_utahrle_bits,
11772-				 br_utahrle_width, br_utahrle_height);
11773+  bfIcons[BF_COMPRESS] = MakePix1(br->win, br_cmpres_bits,
11774+				  br_cmpres_width, br_cmpres_height);
11775+  bfIcons[BF_BZIP2]    = MakePix1(br->win, br_bzip2_bits,
11776+				  br_bzip2_width, br_bzip2_height);
11777
11778+  bfIcons[BF_BMP] =MakePix1(br->win,br_bmp_bits, br_bmp_width, br_bmp_height);
11779+  bfIcons[BF_FITS]=MakePix1(br->win,br_fits_bits,br_fits_width,br_fits_height);
11780+  bfIcons[BF_GIF] =MakePix1(br->win,br_gif_bits, br_gif_width, br_gif_height);
11781+  bfIcons[BF_IFF] =MakePix1(br->win,br_iff_bits, br_iff_width, br_iff_height);
11782   bfIcons[BF_IRIS]=MakePix1(br->win,br_iris_bits,br_iris_width,br_iris_height);
11783-  bfIcons[BF_PCX] =MakePix1(br->win,br_pcx_bits, br_pcx_width, br_pcx_height);
11784   bfIcons[BF_JFIF]=MakePix1(br->win,br_jfif_bits,br_jfif_width,br_jfif_height);
11785-  bfIcons[BF_TIFF]=MakePix1(br->win,br_tiff_bits,br_tiff_width,br_tiff_height);
11786+  bfIcons[BF_JP2] =MakePix1(br->win,br_jp2_bits, br_jp2_width, br_jp2_height);
11787+  bfIcons[BF_JPC] =MakePix1(br->win,br_jpc_bits, br_jpc_width, br_jpc_height);
11788+  bfIcons[BF_MAG] =MakePix1(br->win,br_mag_bits, br_mag_width, br_mag_height);
11789+  bfIcons[BF_MAKI]=MakePix1(br->win,br_maki_bits,br_maki_width,br_maki_height);
11790+  bfIcons[BF_PBM] =MakePix1(br->win,br_pbm_bits, br_pbm_width, br_pbm_height);
11791+  bfIcons[BF_PCD] =MakePix1(br->win,br_pcd_bits, br_pcd_width, br_pcd_height);
11792+  bfIcons[BF_PCX] =MakePix1(br->win,br_pcx_bits, br_pcx_width, br_pcx_height);
11793   bfIcons[BF_PDS] =MakePix1(br->win,br_pds_bits, br_pds_width, br_pds_height);
11794-
11795-  bfIcons[BF_COMPRESS]= MakePix1(br->win, br_cmpres_bits,
11796-				 br_cmpres_width, br_cmpres_height);
11797-
11798+  bfIcons[BF_PIC2]=MakePix1(br->win,br_pic2_bits,br_pic2_width,br_pic2_height);
11799+  bfIcons[BF_PIC] =MakePix1(br->win,br_pic_bits, br_pic_width, br_pic_height);
11800+  bfIcons[BF_PI]  =MakePix1(br->win,br_pi_bits,  br_pi_width,  br_pi_height);
11801+  bfIcons[BF_PM]  =MakePix1(br->win,br_pm_bits,  br_pm_width,  br_pm_height);
11802+  bfIcons[BF_PNG] =MakePix1(br->win,br_png_bits, br_png_width, br_png_height);
11803   bfIcons[BF_PS]  =MakePix1(br->win,br_ps_bits,  br_ps_width,  br_ps_height);
11804-  bfIcons[BF_IFF] =MakePix1(br->win,br_iff_bits, br_iff_width, br_iff_height);
11805-
11806-  bfIcons[BF_TARGA]   = MakePix1(br->win, br_targa_bits,
11807-				 br_targa_width, br_targa_height);
11808-
11809+  bfIcons[BF_TGA] =MakePix1(br->win,br_tga_bits, br_tga_width, br_tga_height);
11810+  bfIcons[BF_TIFF]=MakePix1(br->win,br_tiff_bits,br_tiff_width,br_tiff_height);
11811+  bfIcons[BF_XBM] =MakePix1(br->win,br_xbm_bits, br_xbm_width, br_xbm_height);
11812   bfIcons[BF_XPM] =MakePix1(br->win,br_xpm_bits, br_xpm_width, br_xpm_height);
11813   bfIcons[BF_XWD] =MakePix1(br->win,br_xwd_bits, br_xwd_width, br_xwd_height);
11814-  bfIcons[BF_FITS]=MakePix1(br->win,br_fits_bits,br_fits_width,br_fits_height);
11815+  bfIcons[BF_ZX]  =MakePix1(br->win,br_zx_bits,  br_zx_width,  br_zx_height);
11816+
11817+  bfIcons[BF_SUNRAS]  = MakePix1(br->win, br_sunras_bits,
11818+				 br_sunras_width, br_sunras_height);
11819+  bfIcons[BF_UTAHRLE] = MakePix1(br->win, br_utahrle_bits,
11820+				 br_utahrle_width, br_utahrle_height);
11821+  bfIcons[BF_MGCSFX]  = MakePix1(br->win, br_mgcsfx_bits,
11822+				 br_mgcsfx_width, br_mgcsfx_height);
11823
11824
11825   /* check that they all got built */
11826   for (i=0; i<BF_MAX && bfIcons[i]; i++);
11827-  if (i<BF_MAX)
11828+  if (i<BF_MAX)
11829     FatalError("unable to create all built-in icons for schnauzer");
11830
11831   for (i=0; i<MAXBRWIN; i++) {
11832     resizeBrowse(&binfo[i], DEF_BROWWIDE, DEF_BROWHIGH);
11833
11834-    XSelectInput(theDisp, binfo[i].win, ExposureMask | ButtonPressMask |
11835+    XSelectInput(theDisp, binfo[i].win, ExposureMask | ButtonPressMask |
11836 		 KeyPressMask | StructureNotifyMask);
11837   }
11838
11839@@ -557,7 +649,7 @@
11840     movecurs = XCreatePixmapCursor(theDisp,mcpix,fcmpix,&cursfg,&cursbg,13,13);
11841     copycurs = XCreatePixmapCursor(theDisp,ccpix,fcmpix,&cursfg,&cursbg,13,13);
11842     delcurs  = XCreatePixmapCursor(theDisp,dcpix,fcmpix,&cursbg,&cursfg,13,13);
11843-    if (!movecurs || !copycurs || !delcurs)
11844+    if (!movecurs || !copycurs || !delcurs)
11845       FatalError("unable to create schnauzer cursors...");
11846   }
11847   else FatalError("unable to create schnauzer cursors...");
11848@@ -566,7 +658,7 @@
11849   XFreePixmap(theDisp, ccpix);
11850   XFreePixmap(theDisp, dcpix);
11851   XFreePixmap(theDisp, fcmpix);
11852-
11853+
11854
11855   hasBeenSized = 1;  /* we can now start looking at browse events */
11856 }
11857@@ -576,9 +668,10 @@
11858 void OpenBrowse()
11859 {
11860   /* opens up a single browser window */
11861-  int i;
11862+
11863+  int       i;
11864   BROWINFO *br;
11865-  char     path[MAXPATHLEN+1];
11866+  char      path[MAXPATHLEN+1];
11867
11868   /* find next browser to be opened */
11869   for (i=0; i<MAXBRWIN; i++) {
11870@@ -586,11 +679,11 @@
11871     if (!br->vis) break;
11872   }
11873   if (i==MAXBRWIN) return;  /* full up: shouldn't happen */
11874-
11875+
11876   anyBrowUp = 1;
11877   XMapRaised(theDisp, br->win);
11878   br->vis = 1;
11879-
11880+
11881   freeBfList(br);
11882
11883   /* see if some browser is pointing to the same path as CWD.  If so,
11884@@ -645,7 +738,7 @@
11885   /* free all info for this browse window */
11886   freeBfList(br);
11887   sprintf(br->path, BOGUSPATH);
11888-
11889+
11890   /* turn on 'open new window' command doodads */
11891   windowMB.dim[WMB_BROWSE] = 0;
11892   for (i=0; i<MAXBRWIN; i++) {
11893@@ -698,6 +791,9 @@
11894   }
11895 }
11896
11897+#ifdef VS_RESCMAP
11898+static int _IfTempOut=0;
11899+#endif
11900
11901 /***************************************************************/
11902 void KillBrowseWindows()
11903@@ -730,7 +826,6 @@
11904   return 0;
11905 }
11906
11907-
11908 /***************************************************************/
11909 static int brChkEvent(br, xev)
11910      BROWINFO *br;
11911@@ -739,22 +834,36 @@
11912   /* checks event to see if it's a browse-window related thing.  If it
11913      is, it eats the event and returns '1', otherwise '0'. */
11914
11915-  int    i, rv;
11916-  char buf[1024];
11917-
11918-  rv = 1;
11919+  int rv = 1;
11920
11921   if (!hasBeenSized) return 0;  /* ignore evrythng until we get 1st Resize */
11922
11923+
11924+#ifdef VS_RESCMAP
11925+  /* force change color map if have LocalCmap */
11926+  if (browPerfect && browCmap && (_IfTempOut==2)) {
11927+    int i;
11928+    XSetWindowAttributes xswa;
11929+
11930+    xswa.colormap = LocalCmap? LocalCmap : theCmap;
11931+    for (i=0; i<MAXBRWIN; ++i)
11932+      XChangeWindowAttributes(theDisp, binfo[i].win, CWColormap, &xswa);
11933+    XFlush(theDisp);
11934+    _IfTempOut=1;
11935+  }
11936+#endif
11937+
11938   if (xev->type == Expose) {
11939     int x,y,w,h;
11940     XExposeEvent *e = (XExposeEvent *) xev;
11941     x = e->x;  y = e->y;  w = e->width;  h = e->height;
11942
11943     /* throw away excess redraws for 'dumb' windows */
11944-    if (e->count > 0 && (e->window == br->scrl.win)) {}
11945+    if (e->count > 0 && (e->window == br->scrl.win))
11946+      ;
11947
11948-    else if (e->window == br->scrl.win) SCRedraw(&(br->scrl));
11949+    else if (e->window == br->scrl.win)
11950+      SCRedraw(&(br->scrl));
11951
11952     else if (e->window == br->win || e->window == br->iconW) { /* smart wins */
11953       /* group individual expose rects into a single expose region */
11954@@ -788,7 +897,7 @@
11955 	fprintf(stderr,"grouped %d expose events into %d,%d %dx%d rect\n",
11956 		count, rect.x, rect.y, rect.width, rect.height);
11957       }
11958-
11959+
11960       if      (e->window == br->win)   drawBrow(br);
11961
11962       else if (e->window == br->iconW)
11963@@ -807,13 +916,55 @@
11964     int i,x,y;
11965     x = e->x;  y = e->y;
11966
11967+#ifdef VS_RESCMAP
11968+    if (browCmap && browPerfect && (_IfTempOut!=0)) {
11969+      XSetWindowAttributes  xswa;
11970+      _IfTempOut--;
11971+      xswa.colormap = browCmap;
11972+      for(i=0;i<MAXBRWIN;i++)
11973+        XChangeWindowAttributes(theDisp, binfo[i].win, CWColormap, &xswa);
11974+      XFlush(theDisp);
11975+    }
11976+#endif
11977+
11978     if (e->button == Button1) {
11979       if      (e->window == br->win)      clickBrow(br,x,y);
11980       else if (e->window == br->scrl.win) SCTrack(&(br->scrl),x,y);