diff --git a/ChangeLog.rss b/ChangeLog.rss
index 739c7f378..f17a4ea61 100644
--- a/ChangeLog.rss
+++ b/ChangeLog.rss
@@ -11,9 +11,21 @@
Tracking Slackware development in git.
en-us
urn:uuid:c964f45e-6732-11e8-bbe5-107b4450212f
- Sat, 27 May 2023 20:42:29 GMT
- Sat, 27 May 2023 21:35:39 GMT
+ Sun, 28 May 2023 18:25:43 GMT
+ Sun, 28 May 2023 19:33:30 GMT
maintain_current_git.sh v 1.17
+ -
+ Sun, 28 May 2023 18:25:43 GMT
+ Sun, 28 May 2023 18:25:43 GMT
+ https://git.slackware.nl/current/tag/?h=20230528182543
+ 20230528182543
+
+
+l/at-spi2-core-2.48.3-x86_64-1.txz: Upgraded.
+extra/xv/xv-4.1.1-x86_64-1.txz: Upgraded.
+ ]]>
+
+
-
Sat, 27 May 2023 20:42:29 GMT
Sat, 27 May 2023 20:42:29 GMT
diff --git a/ChangeLog.txt b/ChangeLog.txt
index a28279304..35afc3ee2 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,7 @@
+Sun May 28 18:25:43 UTC 2023
+l/at-spi2-core-2.48.3-x86_64-1.txz: Upgraded.
+extra/xv/xv-4.1.1-x86_64-1.txz: Upgraded.
++--------------------------+
Sat May 27 20:42:29 UTC 2023
d/gdb-13.2-x86_64-1.txz: Upgraded.
l/gc-8.2.4-x86_64-1.txz: Upgraded.
diff --git a/FILELIST.TXT b/FILELIST.TXT
index c2a271ee0..cc88bdfe7 100644
--- a/FILELIST.TXT
+++ b/FILELIST.TXT
@@ -1,20 +1,20 @@
-Sat May 27 20:47:51 UTC 2023
+Sun May 28 18:36:19 UTC 2023
Here is the file list for this directory. If you are using a
mirror site and find missing or extra files in the disk
subdirectories, please have the archive administrator refresh
the mirror.
-drwxr-xr-x 12 root root 4096 2023-05-27 20:42 .
+drwxr-xr-x 12 root root 4096 2023-05-28 18:28 .
-rw-r--r-- 1 root root 5767 2022-02-02 22:44 ./ANNOUNCE.15.0
-rw-r--r-- 1 root root 16617 2022-02-02 23:27 ./CHANGES_AND_HINTS.TXT
--rw-r--r-- 1 root root 1116082 2023-05-26 19:02 ./CHECKSUMS.md5
--rw-r--r-- 1 root root 163 2023-05-26 19:02 ./CHECKSUMS.md5.asc
+-rw-r--r-- 1 root root 1115340 2023-05-28 18:28 ./CHECKSUMS.md5
+-rw-r--r-- 1 root root 163 2023-05-28 18:28 ./CHECKSUMS.md5.asc
-rw-r--r-- 1 root root 17976 1994-06-10 02:28 ./COPYING
-rw-r--r-- 1 root root 35147 2007-06-30 04:21 ./COPYING3
-rw-r--r-- 1 root root 19573 2016-06-23 20:08 ./COPYRIGHT.TXT
-rw-r--r-- 1 root root 616 2006-10-02 04:37 ./CRYPTO_NOTICE.TXT
--rw-r--r-- 1 root root 644241 2023-05-27 20:42 ./ChangeLog.txt
+-rw-r--r-- 1 root root 644389 2023-05-28 18:25 ./ChangeLog.txt
drwxr-xr-x 3 root root 4096 2013-03-20 22:17 ./EFI
drwxr-xr-x 2 root root 4096 2023-05-25 00:23 ./EFI/BOOT
-rw-r--r-- 1 root root 1187840 2021-06-15 19:16 ./EFI/BOOT/bootx64.efi
@@ -25,9 +25,9 @@ drwxr-xr-x 2 root root 4096 2023-05-25 00:23 ./EFI/BOOT
-rwxr-xr-x 1 root root 2504 2019-07-05 18:54 ./EFI/BOOT/make-grub.sh
-rw-r--r-- 1 root root 10722 2013-09-21 19:02 ./EFI/BOOT/osdetect.cfg
-rw-r--r-- 1 root root 1273 2013-08-12 21:08 ./EFI/BOOT/tools.cfg
--rw-r--r-- 1 root root 1455456 2023-05-26 19:02 ./FILELIST.TXT
+-rw-r--r-- 1 root root 1454568 2023-05-28 18:28 ./FILELIST.TXT
-rw-r--r-- 1 root root 1572 2012-08-29 18:27 ./GPG-KEY
--rw-r--r-- 1 root root 872185 2023-05-27 20:47 ./PACKAGES.TXT
+-rw-r--r-- 1 root root 872185 2023-05-28 18:28 ./PACKAGES.TXT
-rw-r--r-- 1 root root 8034 2022-02-02 03:36 ./README.TXT
-rw-r--r-- 1 root root 3629 2023-05-25 00:09 ./README.initrd
-rw-r--r-- 1 root root 34162 2022-01-30 20:35 ./README_CRYPT.TXT
@@ -39,12 +39,12 @@ drwxr-xr-x 2 root root 4096 2023-05-25 00:23 ./EFI/BOOT
-rw-r--r-- 1 root root 17294 2008-12-08 18:13 ./SPEAK_INSTALL.TXT
-rw-r--r-- 1 root root 57187 2022-02-01 19:37 ./Slackware-HOWTO
-rw-r--r-- 1 root root 8700 2022-01-26 05:44 ./UPGRADE.TXT
-drwxr-xr-x 17 root root 4096 2023-03-21 21:21 ./extra
--rw-r--r-- 1 root root 47708 2023-03-21 21:21 ./extra/CHECKSUMS.md5
--rw-r--r-- 1 root root 163 2023-03-21 21:21 ./extra/CHECKSUMS.md5.asc
--rw-r--r-- 1 root root 59869 2023-03-21 21:21 ./extra/FILE_LIST
--rw-r--r-- 1 root root 1474002 2023-03-21 21:21 ./extra/MANIFEST.bz2
--rw-r--r-- 1 root root 35459 2023-03-21 21:21 ./extra/PACKAGES.TXT
+drwxr-xr-x 17 root root 4096 2023-05-28 18:27 ./extra
+-rw-r--r-- 1 root root 47021 2023-05-28 18:27 ./extra/CHECKSUMS.md5
+-rw-r--r-- 1 root root 163 2023-05-28 18:27 ./extra/CHECKSUMS.md5.asc
+-rw-r--r-- 1 root root 59029 2023-05-28 18:27 ./extra/FILE_LIST
+-rw-r--r-- 1 root root 1476695 2023-05-28 18:27 ./extra/MANIFEST.bz2
+-rw-r--r-- 1 root root 35459 2023-05-28 18:27 ./extra/PACKAGES.TXT
-rw-r--r-- 1 root root 149 2002-02-09 00:18 ./extra/README.TXT
drwxr-xr-x 2 root root 20480 2020-05-26 20:38 ./extra/aspell-word-lists
-rw-r--r-- 1 root root 171 2016-06-06 20:10 ./extra/aspell-word-lists/aspell-af-0.50_0-x86_64-5.txt
@@ -361,7 +361,7 @@ drwxr-xr-x 2 root root 4096 2023-03-08 20:34 ./extra/sendmail
-rw-r--r-- 1 root root 586 2023-03-08 18:55 ./extra/sendmail/sendmail-cf-8.17.1-noarch-7.txt
-rw-r--r-- 1 root root 118896 2023-03-08 18:55 ./extra/sendmail/sendmail-cf-8.17.1-noarch-7.txz
-rw-r--r-- 1 root root 163 2023-03-08 18:55 ./extra/sendmail/sendmail-cf-8.17.1-noarch-7.txz.asc
-drwxr-xr-x 15 root root 4096 2023-03-21 19:46 ./extra/source
+drwxr-xr-x 15 root root 4096 2023-05-28 18:16 ./extra/source
lrwxrwxrwx 1 root root 21 2021-04-29 18:18 ./extra/source/alpine -> ../../source/n/alpine
drwxr-xr-x 4 root root 4096 2022-09-06 18:32 ./extra/source/aspell-word-lists
-rwxr-xr-x 1 root root 3533 2022-09-06 18:32 ./extra/source/aspell-word-lists/aspell-dict.SlackBuild
@@ -608,20 +608,11 @@ drwxr-xr-x 2 root root 4096 2022-09-06 18:32 ./extra/source/xfractint
-rw-r--r-- 1 root root 1097840 2020-08-02 13:12 ./extra/source/xfractint/xfractint-20.04p16.tar.xz
-rwxr-xr-x 1 root root 4612 2022-09-06 18:32 ./extra/source/xfractint/xfractint.SlackBuild
-rw-r--r-- 1 root root 44 2019-10-18 18:31 ./extra/source/xfractint/xfractint.url
-drwxr-xr-x 2 root root 4096 2022-02-24 19:59 ./extra/source/xv
+drwxr-xr-x 2 root root 4096 2023-05-28 18:16 ./extra/source/xv
-rw-r--r-- 1 root root 683 2018-02-27 06:13 ./extra/source/xv/slack-desc
--rw-r--r-- 1 root root 1693808 1994-12-22 15:50 ./extra/source/xv/xv-3.10.tar.xz
--rw-r--r-- 1 root root 3294 2008-12-16 18:04 ./extra/source/xv/xv-3.10a-enhancements.20070520-20081216.diff.bz2
--rw-r--r-- 1 root root 25974 2007-05-21 05:19 ./extra/source/xv/xv-3.10a-jumbo-README.txt
--rw-r--r-- 1 root root 114978 2010-02-19 19:24 ./extra/source/xv/xv-3.10a-jumbo-additions.diff.bz2
--rw-r--r-- 1 root root 287250 2007-05-21 04:57 ./extra/source/xv/xv-3.10a-jumbo-fix-enh-patch-20070520.txt.bz2
--rw-r--r-- 1 root root 21943 1996-10-05 19:33 ./extra/source/xv/xv-3.10a.patch.gz
--rw-r--r-- 1 root root 4933 2015-03-28 21:28 ./extra/source/xv/xv-libpng-1.5.patch.gz
--rwxr-xr-x 1 root root 3736 2022-02-24 20:03 ./extra/source/xv/xv.SlackBuild
--rw-r--r-- 1 root root 229 2010-02-19 19:27 ./extra/source/xv/xv.jasper.diff.gz
--rw-r--r-- 1 root root 336 2022-02-24 20:04 ./extra/source/xv/xv.no.jasper.diff.gz
--rw-r--r-- 1 root root 317 2010-02-19 19:15 ./extra/source/xv/xv.prefix.diff.gz
--rw-r--r-- 1 root root 282 2010-02-19 19:16 ./extra/source/xv/xv.prefix_x86_64.diff.gz
+-rw-r--r-- 1 root root 4625029 2023-05-27 15:14 ./extra/source/xv/xv-4.1.1.tar.lz
+-rwxr-xr-x 1 root root 4176 2023-05-28 18:06 ./extra/source/xv/xv.SlackBuild
+-rw-r--r-- 1 root root 38 2023-05-28 17:57 ./extra/source/xv/xv.url
drwxr-xr-x 2 root root 4096 2023-03-21 21:21 ./extra/tigervnc
-rw-r--r-- 1 root root 0 2015-12-15 08:03 ./extra/tigervnc/the_fltk_package_must_also_be_installed
-rw-r--r-- 1 root root 474 2023-03-21 19:45 ./extra/tigervnc/tigervnc-1.13.1-x86_64-1.txt
@@ -639,10 +630,10 @@ drwxr-xr-x 2 root root 4096 2020-08-02 18:22 ./extra/xfractint
-rw-r--r-- 1 root root 409 2020-08-02 17:57 ./extra/xfractint/xfractint-20.04p16-x86_64-1.txt
-rw-r--r-- 1 root root 824600 2020-08-02 17:57 ./extra/xfractint/xfractint-20.04p16-x86_64-1.txz
-rw-r--r-- 1 root root 163 2020-08-02 17:57 ./extra/xfractint/xfractint-20.04p16-x86_64-1.txz.asc
-drwxr-xr-x 2 root root 4096 2022-02-25 00:07 ./extra/xv
--rw-r--r-- 1 root root 233 2022-02-24 20:04 ./extra/xv/xv-3.10a-x86_64-10.txt
--rw-r--r-- 1 root root 942524 2022-02-24 20:04 ./extra/xv/xv-3.10a-x86_64-10.txz
--rw-r--r-- 1 root root 163 2022-02-24 20:04 ./extra/xv/xv-3.10a-x86_64-10.txz.asc
+drwxr-xr-x 2 root root 4096 2023-05-28 18:27 ./extra/xv
+-rw-r--r-- 1 root root 233 2023-05-28 18:16 ./extra/xv/xv-4.1.1-x86_64-1.txt
+-rw-r--r-- 1 root root 1098144 2023-05-28 18:16 ./extra/xv/xv-4.1.1-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-05-28 18:16 ./extra/xv/xv-4.1.1-x86_64-1.txz.asc
drwxr-xr-x 3 root root 4096 2023-05-25 00:23 ./isolinux
-rw-r--r-- 1 root root 6185 2022-02-03 06:53 ./isolinux/README.TXT
-rw-r--r-- 1 root root 788 2007-03-17 19:50 ./isolinux/README_SPLIT.TXT
@@ -687,11 +678,11 @@ drwxr-xr-x 2 root root 4096 2022-02-03 07:02 ./patches
-rw-r--r-- 1 root root 575 2022-02-03 07:02 ./patches/FILE_LIST
-rw-r--r-- 1 root root 14 2022-02-03 07:02 ./patches/MANIFEST.bz2
-rw-r--r-- 1 root root 224 2022-02-03 07:02 ./patches/PACKAGES.TXT
-drwxr-xr-x 17 root root 4096 2023-05-27 20:47 ./slackware64
--rw-r--r-- 1 root root 340379 2023-05-27 20:47 ./slackware64/CHECKSUMS.md5
--rw-r--r-- 1 root root 163 2023-05-27 20:47 ./slackware64/CHECKSUMS.md5.asc
--rw-r--r-- 1 root root 421987 2023-05-27 20:46 ./slackware64/FILE_LIST
--rw-r--r-- 1 root root 4305122 2023-05-27 20:46 ./slackware64/MANIFEST.bz2
+drwxr-xr-x 17 root root 4096 2023-05-28 18:28 ./slackware64
+-rw-r--r-- 1 root root 340379 2023-05-28 18:28 ./slackware64/CHECKSUMS.md5
+-rw-r--r-- 1 root root 163 2023-05-28 18:28 ./slackware64/CHECKSUMS.md5.asc
+-rw-r--r-- 1 root root 421987 2023-05-28 18:27 ./slackware64/FILE_LIST
+-rw-r--r-- 1 root root 4293846 2023-05-28 18:27 ./slackware64/MANIFEST.bz2
lrwxrwxrwx 1 root root 15 2009-08-23 23:34 ./slackware64/PACKAGES.TXT -> ../PACKAGES.TXT
drwxr-xr-x 2 root root 32768 2023-05-25 00:32 ./slackware64/a
-rw-r--r-- 1 root root 327 2022-02-15 18:16 ./slackware64/a/aaa_base-15.1-x86_64-2.txt
@@ -2712,14 +2703,14 @@ drwxr-xr-x 2 root root 86016 2023-05-25 19:10 ./slackware64/kde
-rw-r--r-- 1 root root 32108 2023-05-14 05:16 ./slackware64/kde/svgpart-23.04.1-x86_64-1.txz
-rw-r--r-- 1 root root 163 2023-05-14 05:16 ./slackware64/kde/svgpart-23.04.1-x86_64-1.txz.asc
-rw-r--r-- 1 root root 277 2023-05-14 05:11 ./slackware64/kde/sweeper-23.04.1-x86_64-1.txt
--rw-r--r-- 1 root root 412632 2023-05-14 05:11 ./slackware64/kde/sweeper-23.04.1-x86_64-1.txz
--rw-r--r-- 1 root root 163 2023-05-14 05:11 ./slackware64/kde/sweeper-23.04.1-x86_64-1.txz.asc
--rw-r--r-- 1 root root 440 2023-05-14 04:35 ./slackware64/kde/syndication-5.106.0-x86_64-1.txt
--rw-r--r-- 1 root root 205272 2023-05-14 04:35 ./slackware64/kde/syndication-5.106.0-x86_64-1.txz
--rw-r--r-- 1 root root 163 2023-05-14 04:35 ./slackware64/kde/syndication-5.106.0-x86_64-1.txz.asc
--rw-r--r-- 1 root root 339 2023-05-14 04:27 ./slackware64/kde/syntax-highlighting-5.106.0-x86_64-1.txt
--rw-r--r-- 1 root root 1733404 2023-05-14 04:27 ./slackware64/kde/syntax-highlighting-5.106.0-x86_64-1.txz
--rw-r--r-- 1 root root 163 2023-05-14 04:27 ./slackware64/kde/syntax-highlighting-5.106.0-x86_64-1.txz.asc
+-rw-r--r-- 1 root root 412632 2023-05-14 05:11 ./slackware64/kde/sweeper-23.04.1-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-05-14 05:11 ./slackware64/kde/sweeper-23.04.1-x86_64-1.txz.asc
+-rw-r--r-- 1 root root 440 2023-05-14 04:35 ./slackware64/kde/syndication-5.106.0-x86_64-1.txt
+-rw-r--r-- 1 root root 205272 2023-05-14 04:35 ./slackware64/kde/syndication-5.106.0-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-05-14 04:35 ./slackware64/kde/syndication-5.106.0-x86_64-1.txz.asc
+-rw-r--r-- 1 root root 339 2023-05-14 04:27 ./slackware64/kde/syntax-highlighting-5.106.0-x86_64-1.txt
+-rw-r--r-- 1 root root 1733404 2023-05-14 04:27 ./slackware64/kde/syntax-highlighting-5.106.0-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-05-14 04:27 ./slackware64/kde/syntax-highlighting-5.106.0-x86_64-1.txz.asc
-rw-r--r-- 1 root root 265 2023-05-09 18:45 ./slackware64/kde/systemsettings-5.27.5-x86_64-1.txt
-rw-r--r-- 1 root root 352724 2023-05-09 18:45 ./slackware64/kde/systemsettings-5.27.5-x86_64-1.txz
-rw-r--r-- 1 root root 163 2023-05-09 18:45 ./slackware64/kde/systemsettings-5.27.5-x86_64-1.txz.asc
@@ -2748,7 +2739,7 @@ drwxr-xr-x 2 root root 86016 2023-05-25 19:10 ./slackware64/kde
-rw-r--r-- 1 root root 403 2023-04-20 20:52 ./slackware64/kde/zxing-cpp-2.0.0-x86_64-1.txt
-rw-r--r-- 1 root root 713544 2023-04-20 20:52 ./slackware64/kde/zxing-cpp-2.0.0-x86_64-1.txz
-rw-r--r-- 1 root root 163 2023-04-20 20:52 ./slackware64/kde/zxing-cpp-2.0.0-x86_64-1.txz.asc
-drwxr-xr-x 2 root root 86016 2023-05-27 20:46 ./slackware64/l
+drwxr-xr-x 2 root root 86016 2023-05-28 18:27 ./slackware64/l
-rw-r--r-- 1 root root 329 2022-03-06 20:00 ./slackware64/l/GConf-3.2.6-x86_64-8.txt
-rw-r--r-- 1 root root 928144 2022-03-06 20:00 ./slackware64/l/GConf-3.2.6-x86_64-8.txz
-rw-r--r-- 1 root root 163 2022-03-06 20:00 ./slackware64/l/GConf-3.2.6-x86_64-8.txz.asc
@@ -2830,9 +2821,9 @@ drwxr-xr-x 2 root root 86016 2023-05-27 20:46 ./slackware64/l
-rw-r--r-- 1 root root 269 2021-02-13 06:13 ./slackware64/l/at-spi2-atk-2.38.0-x86_64-3.txt
-rw-r--r-- 1 root root 79728 2021-02-13 06:13 ./slackware64/l/at-spi2-atk-2.38.0-x86_64-3.txz
-rw-r--r-- 1 root root 163 2021-02-13 06:13 ./slackware64/l/at-spi2-atk-2.38.0-x86_64-3.txz.asc
--rw-r--r-- 1 root root 456 2023-05-14 15:36 ./slackware64/l/at-spi2-core-2.48.2-x86_64-1.txt
--rw-r--r-- 1 root root 1103204 2023-05-14 15:36 ./slackware64/l/at-spi2-core-2.48.2-x86_64-1.txz
--rw-r--r-- 1 root root 163 2023-05-14 15:36 ./slackware64/l/at-spi2-core-2.48.2-x86_64-1.txz.asc
+-rw-r--r-- 1 root root 456 2023-05-28 17:53 ./slackware64/l/at-spi2-core-2.48.3-x86_64-1.txt
+-rw-r--r-- 1 root root 1104168 2023-05-28 17:53 ./slackware64/l/at-spi2-core-2.48.3-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-05-28 17:53 ./slackware64/l/at-spi2-core-2.48.3-x86_64-1.txz.asc
-rw-r--r-- 1 root root 173 2022-07-12 03:30 ./slackware64/l/atk-2.38.0-x86_64-1.txt
-rw-r--r-- 1 root root 376364 2022-07-12 03:30 ./slackware64/l/atk-2.38.0-x86_64-1.txz
-rw-r--r-- 1 root root 163 2022-07-12 03:30 ./slackware64/l/atk-2.38.0-x86_64-1.txz.asc
@@ -5499,15 +5490,15 @@ drwxr-xr-x 2 root root 12288 2023-05-26 19:01 ./slackware64/xfce
-rw-r--r-- 1 root root 163 2023-03-29 17:35 ./slackware64/xfce/garcon-4.18.1-x86_64-1.txz.asc
-rwxr-xr-x 1 root root 2897 2009-06-24 22:06 ./slackware64/xfce/install-packages
-rw-r--r-- 1 root root 446 2006-09-18 10:41 ./slackware64/xfce/install.end
--rw-r--r-- 1 root root 309 2023-05-23 18:16 ./slackware64/xfce/libxfce4ui-4.18.4-x86_64-1.txt
--rw-r--r-- 1 root root 364972 2023-05-23 18:16 ./slackware64/xfce/libxfce4ui-4.18.4-x86_64-1.txz
--rw-r--r-- 1 root root 163 2023-05-23 18:16 ./slackware64/xfce/libxfce4ui-4.18.4-x86_64-1.txz.asc
--rw-r--r-- 1 root root 316 2023-01-10 21:06 ./slackware64/xfce/libxfce4util-4.18.1-x86_64-1.txt
--rw-r--r-- 1 root root 138332 2023-01-10 21:06 ./slackware64/xfce/libxfce4util-4.18.1-x86_64-1.txz
--rw-r--r-- 1 root root 163 2023-01-10 21:06 ./slackware64/xfce/libxfce4util-4.18.1-x86_64-1.txz.asc
--rw-r--r-- 1 root root 3369 2020-12-07 21:31 ./slackware64/xfce/maketag
--rw-r--r-- 1 root root 3369 2020-12-07 21:31 ./slackware64/xfce/maketag.ez
--rw-r--r-- 1 root root 423 2023-05-14 15:36 ./slackware64/xfce/mousepad-0.6.1-x86_64-1.txt
+-rw-r--r-- 1 root root 309 2023-05-23 18:16 ./slackware64/xfce/libxfce4ui-4.18.4-x86_64-1.txt
+-rw-r--r-- 1 root root 364972 2023-05-23 18:16 ./slackware64/xfce/libxfce4ui-4.18.4-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-05-23 18:16 ./slackware64/xfce/libxfce4ui-4.18.4-x86_64-1.txz.asc
+-rw-r--r-- 1 root root 316 2023-01-10 21:06 ./slackware64/xfce/libxfce4util-4.18.1-x86_64-1.txt
+-rw-r--r-- 1 root root 138332 2023-01-10 21:06 ./slackware64/xfce/libxfce4util-4.18.1-x86_64-1.txz
+-rw-r--r-- 1 root root 163 2023-01-10 21:06 ./slackware64/xfce/libxfce4util-4.18.1-x86_64-1.txz.asc
+-rw-r--r-- 1 root root 3369 2020-12-07 21:31 ./slackware64/xfce/maketag
+-rw-r--r-- 1 root root 3369 2020-12-07 21:31 ./slackware64/xfce/maketag.ez
+-rw-r--r-- 1 root root 423 2023-05-14 15:36 ./slackware64/xfce/mousepad-0.6.1-x86_64-1.txt
-rw-r--r-- 1 root root 406612 2023-05-14 15:36 ./slackware64/xfce/mousepad-0.6.1-x86_64-1.txz
-rw-r--r-- 1 root root 163 2023-05-14 15:36 ./slackware64/xfce/mousepad-0.6.1-x86_64-1.txz.asc
-rw-r--r-- 1 root root 555 2020-12-07 21:31 ./slackware64/xfce/tagfile
@@ -5592,11 +5583,11 @@ drwxr-xr-x 2 root root 4096 2023-03-08 20:34 ./slackware64/y
-rw-r--r-- 1 root root 1491108 2023-02-19 18:31 ./slackware64/y/nethack-3.6.7-x86_64-1.txz
-rw-r--r-- 1 root root 163 2023-02-19 18:31 ./slackware64/y/nethack-3.6.7-x86_64-1.txz.asc
-rw-r--r-- 1 root root 26 2020-12-30 21:55 ./slackware64/y/tagfile
-drwxr-xr-x 18 root root 4096 2023-05-27 20:47 ./source
--rw-r--r-- 1 root root 599436 2023-05-27 20:47 ./source/CHECKSUMS.md5
--rw-r--r-- 1 root root 163 2023-05-27 20:47 ./source/CHECKSUMS.md5.asc
--rw-r--r-- 1 root root 833348 2023-05-27 20:47 ./source/FILE_LIST
--rw-r--r-- 1 root root 24536864 2023-05-27 20:47 ./source/MANIFEST.bz2
+drwxr-xr-x 18 root root 4096 2023-05-28 18:36 ./source
+-rw-r--r-- 1 root root 599436 2023-05-28 18:36 ./source/CHECKSUMS.md5
+-rw-r--r-- 1 root root 163 2023-05-28 18:36 ./source/CHECKSUMS.md5.asc
+-rw-r--r-- 1 root root 833348 2023-05-28 18:36 ./source/FILE_LIST
+-rw-r--r-- 1 root root 24537691 2023-05-28 18:36 ./source/MANIFEST.bz2
-rw-r--r-- 1 root root 828 2022-02-02 04:43 ./source/README.TXT
drwxr-xr-x 123 root root 4096 2023-05-17 20:46 ./source/a
-rw-r--r-- 1 root root 234 2022-10-16 18:39 ./source/a/FTBFSlog
@@ -9934,8 +9925,8 @@ drwxr-xr-x 2 root root 4096 2021-02-13 05:31 ./source/l/at-spi2-atk
-rwxr-xr-x 1 root root 3488 2021-02-13 05:31 ./source/l/at-spi2-atk/at-spi2-atk.SlackBuild
-rw-r--r-- 1 root root 126 2013-02-22 04:24 ./source/l/at-spi2-atk/doinst.sh.gz
-rw-r--r-- 1 root root 761 2018-02-27 06:12 ./source/l/at-spi2-atk/slack-desc
-drwxr-xr-x 2 root root 4096 2023-05-14 15:35 ./source/l/at-spi2-core
--rw-r--r-- 1 root root 554056 2023-05-11 17:26 ./source/l/at-spi2-core/at-spi2-core-2.48.2.tar.xz
+drwxr-xr-x 2 root root 4096 2023-05-28 17:53 ./source/l/at-spi2-core
+-rw-r--r-- 1 root root 554388 2023-05-27 15:05 ./source/l/at-spi2-core/at-spi2-core-2.48.3.tar.xz
-rwxr-xr-x 1 root root 3475 2021-03-31 19:04 ./source/l/at-spi2-core/at-spi2-core.SlackBuild
-rw-r--r-- 1 root root 948 2018-02-27 06:12 ./source/l/at-spi2-core/slack-desc
drwxr-xr-x 2 root root 4096 2022-07-12 02:58 ./source/l/atk
@@ -15242,15 +15233,15 @@ drwxr-xr-x 2 root root 4096 2023-02-28 19:27 ./source/xfce/xfce4-notifyd
-rw-r--r-- 1 root root 839 2018-03-01 19:39 ./source/xfce/xfce4-notifyd/slack-desc
-rw-r--r-- 1 root root 506883 2023-02-28 06:37 ./source/xfce/xfce4-notifyd/xfce4-notifyd-0.8.2.tar.lz
-rwxr-xr-x 1 root root 4023 2022-02-13 19:38 ./source/xfce/xfce4-notifyd/xfce4-notifyd.SlackBuild
--rw-r--r-- 1 root root 52 2023-02-11 20:27 ./source/xfce/xfce4-notifyd/xfce4-notifyd.url
-drwxr-xr-x 2 root root 4096 2023-05-23 18:11 ./source/xfce/xfce4-panel
-drwxr-xr-x 2 root root 4096 2021-02-22 01:27 ./source/xfce/xfce4-panel-profiles
--rw-r--r-- 1 root root 121 2019-08-02 07:05 ./source/xfce/xfce4-panel-profiles/doinst.sh.gz
--rw-r--r-- 1 root root 1138 2019-08-02 07:01 ./source/xfce/xfce4-panel-profiles/slack-desc
--rw-r--r-- 1 root root 63201 2021-02-22 01:26 ./source/xfce/xfce4-panel-profiles/xfce4-panel-profiles-1.0.13.tar.lz
--rwxr-xr-x 1 root root 3834 2021-02-22 01:27 ./source/xfce/xfce4-panel-profiles/xfce4-panel-profiles.SlackBuild
--rw-r--r-- 1 root root 896 2018-02-27 06:13 ./source/xfce/xfce4-panel/slack-desc
--rw-r--r-- 1 root root 1344602 2023-05-22 17:42 ./source/xfce/xfce4-panel/xfce4-panel-4.18.4.tar.lz
+-rw-r--r-- 1 root root 52 2023-02-11 20:27 ./source/xfce/xfce4-notifyd/xfce4-notifyd.url
+drwxr-xr-x 2 root root 4096 2023-05-23 18:11 ./source/xfce/xfce4-panel
+drwxr-xr-x 2 root root 4096 2021-02-22 01:27 ./source/xfce/xfce4-panel-profiles
+-rw-r--r-- 1 root root 121 2019-08-02 07:05 ./source/xfce/xfce4-panel-profiles/doinst.sh.gz
+-rw-r--r-- 1 root root 1138 2019-08-02 07:01 ./source/xfce/xfce4-panel-profiles/slack-desc
+-rw-r--r-- 1 root root 63201 2021-02-22 01:26 ./source/xfce/xfce4-panel-profiles/xfce4-panel-profiles-1.0.13.tar.lz
+-rwxr-xr-x 1 root root 3834 2021-02-22 01:27 ./source/xfce/xfce4-panel-profiles/xfce4-panel-profiles.SlackBuild
+-rw-r--r-- 1 root root 896 2018-02-27 06:13 ./source/xfce/xfce4-panel/slack-desc
+-rw-r--r-- 1 root root 1344602 2023-05-22 17:42 ./source/xfce/xfce4-panel/xfce4-panel-4.18.4.tar.lz
-rwxr-xr-x 1 root root 4782 2021-02-25 19:35 ./source/xfce/xfce4-panel/xfce4-panel.SlackBuild
-rw-r--r-- 1 root root 52 2022-12-17 20:44 ./source/xfce/xfce4-panel/xfce4-panel.url
drwxr-xr-x 2 root root 4096 2023-02-10 19:50 ./source/xfce/xfce4-power-manager
diff --git a/extra/source/xv/xv-3.10a-enhancements.20070520-20081216.diff b/extra/source/xv/xv-3.10a-enhancements.20070520-20081216.diff
deleted file mode 100644
index c9b5528f5..000000000
--- a/extra/source/xv/xv-3.10a-enhancements.20070520-20081216.diff
+++ /dev/null
@@ -1,293 +0,0 @@
- 20070621
- fixed improper ClearCode termination condition in GIF decoder (JZ); fixed
- some minor inconsistencies in Makefile (GRR)
- - xv-joe-zbiciak-20070621-gif-decoder-bugfix.dif
-
- 20080121
- removed duplicate "XDestroyWindow(theDisp, pngW);" in xvmisc.c (IMC); fixed
- empty-filename click-and-crash bug in xvdir.c (IMC, DB)
- - xv-ian-collier-20080118-crash-fixes.msg
- - xv-david-bath-20080901-empty-filename-save-crash-fix.dif
-
- 20081205
- reverted xvxwd.c to SJT's version (bug reported by Jari Ruusu)
-
- 20081216
- fixed crash-bug in IFF decoder (EP)
- - xv-elmar-plischke-20081216-xviff-crash-fix.dif
-
-
-
-diff -ru ../test3.20070520.stock/xv-3.10a/xv.h ./xv.h
---- ../test3.20070520.stock/xv-3.10a/xv.h 2007-05-20 22:23:33.000000000 -0700
-+++ ./xv.h 2008-12-16 09:45:00.000000000 -0800
-@@ -16,8 +16,9 @@
- /* GRR 2nd public jumbo F+E patches: 20050410 */
- /* GRR 3rd public jumbo F+E patches: 20050501 */
- /* GRR 4th public jumbo F+E patch: 20070520 */
--#define REVDATE "version 3.10a-jumboFix+Enh of 20070520"
--#define VERSTR "3.10a-20070520"
-+/* GRR 5th public jumbo F+E patch: 200xxxxx (probably mid-2009) */
-+#define REVDATE "version 3.10a-jumboFix+Enh of 20081216 (interim!)"
-+#define VERSTR "3.10a-20081216"
-
- /*
- * uncomment the following, and modify for your site, but only if you've
-
-
-
-diff -ru ../test3.20070520.stock/xv-3.10a/xvdir.c ./xvdir.c
---- ../test3.20070520.stock/xv-3.10a/xvdir.c 2007-05-20 22:23:33.000000000 -0700
-+++ ./xvdir.c 2008-01-21 13:02:38.000000000 -0800
-@@ -539,8 +539,9 @@
- return -1;
- }
-
-- /* handle clicks inside the filename box */
-- if (x > 80 &&
-+ /* handle clicks inside the filename box, but only when box is not empty */
-+ if (enPos > stPos &&
-+ x > 80 &&
- y > dList.y + (int) dList.h + 30 &&
- x < 80 + DNAMWIDE+6 &&
- y < dList.y + (int) dList.h + 30 + LINEHIGH+5) {
-
-
-
-diff -ru ../test3.20070520.stock/xv-3.10a/xvgif.c ./xvgif.c
---- ../test3.20070520.stock/xv-3.10a/xvgif.c 2007-05-20 22:23:33.000000000 -0700
-+++ ./xvgif.c 2007-06-21 09:36:40.000000000 -0700
-@@ -700,7 +700,7 @@
- * associated output code on the output queue.
- */
-
-- while (CurCode > BitMask) {
-+ while (CurCode >= ClearCode) { /* Joe Zbiciak fix, 20070621 */
- if (OutCount > 4096) break; /* corrupt file */
- OutCode[OutCount++] = Suffix[CurCode];
- CurCode = Prefix[CurCode];
-
-
-
-diff -ru ../test3.20070520.stock/xv-3.10a/xvmisc.c ./xvmisc.c
---- ../test3.20070520.stock/xv-3.10a/xvmisc.c 2007-05-20 22:23:33.000000000 -0700
-+++ ./xvmisc.c 2008-01-21 12:57:29.000000000 -0800
-@@ -561,10 +561,6 @@
- if (mgcsfxW) XDestroyWindow(theDisp, mgcsfxW);
- #endif
-
--#ifdef HAVE_PNG
-- if (pngW) XDestroyWindow(theDisp, pngW);
--#endif
--
- /* if NOT using stdcmap for images, free stdcmap */
- if (colorMapMode != CM_STDCMAP) {
- int j;
-
-
-
-[This one reverts xvxwd.c to the pre-2007 SJT version, which actually worked...]
-
-diff -ru ../test3.20070520.stock/xv-3.10a/xvxwd.c ./xvxwd.c
---- ../test3.20070520.stock/xv-3.10a/xvxwd.c 2007-05-20 22:23:33.000000000 -0700
-+++ ./xvxwd.c 2008-12-06 00:30:44.000000000 -0800
-@@ -19,6 +19,12 @@
- */
-
- #include "xv.h"
-+#include /* for CHAR_BIT */
-+
-+/* SJT: just in case ... */
-+#ifndef CHAR_BIT
-+# define CHAR_BIT 8
-+#endif
-
-
- /***************************** x11wd.h *****************************/
-@@ -83,9 +89,14 @@
- static int writebiglong PARM((FILE *, CARD32));
- #endif
-
-+static void getcolorshift PARM((CARD32, int *, int *)); /* SJT */
-+
-+/* SJT: for 16bpp and 24bpp shifts */
-+static int red_shift_right, red_justify_left,
-+ grn_shift_right, grn_justify_left,
-+ blu_shift_right, blu_justify_left;
- static byte *pic8, *pic24;
--static CARD32 red_mask, green_mask, blue_mask;
--static int red_shift, green_shift, blue_shift;
-+static CARD32 red_mask, grn_mask, blu_mask;
- static int bits_per_item, bits_used, bit_shift,
- bits_per_pixel, bits_per_rgb;
- static char buf[4];
-@@ -189,38 +200,34 @@
- return 0;
- }
-
-- switch (bits_per_pixel) {
-- case 16:
-- case 24:
-- case 32:
-- ;
-- default:
-- xwdError("True/Direct supports only 16, 24, and 32 bits");
-- return 0;
-- }
-+ for (row=0; row> red_shift & red_mask ;
-- *xP++ = ul >> green_shift & green_mask;
-- *xP++ = ul >> blue_shift & blue_mask ;
-- };
-- for (col=0; col> blue_shift & blue_mask ;
-- *xP++ = ul >> green_shift & green_mask;
-- *xP++ = ul >> red_shift & red_mask ;
-- };
-- for (col=0; col> red_shift_right) << red_justify_left;
-+ *xP++ = ((ul & grn_mask) >> grn_shift_right) << grn_justify_left;
-+ *xP++ = ((ul & blu_mask) >> blu_shift_right) << blu_justify_left;
-+ break;
-+
-+ default:
-+ xwdError("True/Direct supports only 16, 24, and 32 bits");
-+ return 0;
-+ }
- }
-+
-+ for (col=0; coltype = PIC24;
-@@ -445,28 +452,18 @@
- (i.e., 3 bytes, no alpha/padding) */
-
-
-- bits_used = bits_per_item;
-+ bits_used = bits_per_item;
-
- if (bits_per_pixel == sizeof(pixel_mask) * 8) pixel_mask = (CARD32) -1;
- else pixel_mask = (1 << bits_per_pixel) - 1;
-
-- red_mask = h11P->red_mask;
-- green_mask = h11P->grn_mask;
-- blue_mask = h11P->blu_mask;
--
-- red_shift = blue_shift = green_shift = 0;
-- while (!(red_mask & 1)) {
-- red_mask >>= 1;
-- ++red_shift;
-- }
-- while (!(blue_mask & 1)) {
-- blue_mask >>= 1;
-- ++blue_shift;
-- }
-- while (!(green_mask & 1)) {
-- green_mask >>= 1;
-- ++green_shift;
-- }
-+ red_mask = h11P->red_mask;
-+ grn_mask = h11P->grn_mask;
-+ blu_mask = h11P->blu_mask;
-+
-+ getcolorshift(red_mask, &red_shift_right, &red_justify_left);
-+ getcolorshift(grn_mask, &grn_shift_right, &grn_justify_left);
-+ getcolorshift(blu_mask, &blu_shift_right, &blu_justify_left);
-
- byteP = (char *) buf;
- shortP = (CARD16 *) buf;
-@@ -476,6 +473,45 @@
- }
-
-
-+/* SJT: figure out the proper shifts */
-+static void getcolorshift (CARD32 mask, int *rightshift, int *leftshift)
-+{
-+ int lshift, rshift;
-+ unsigned int uu;
-+
-+ if (mask == 0)
-+ {
-+ *rightshift = *leftshift = 0;
-+ return;
-+ }
-+
-+ uu = mask;
-+ lshift = rshift = 0;
-+ while ((uu & 0xf) == 0)
-+ {
-+ rshift += 4;
-+ uu >>= 4;
-+ }
-+ while ((uu & 1) == 0)
-+ {
-+ rshift++;
-+ uu >>= 1;
-+ }
-+
-+ while (uu != 0)
-+ {
-+ if (uu & 1)
-+ {
-+ lshift++;
-+ uu >>= 1;
-+ }
-+ }
-+ *rightshift = rshift;
-+ *leftshift = CHAR_BIT * sizeof(pixel) - lshift;
-+ return;
-+}
-+
-+
- /******************************/
- static CARD32 getpixnum(file)
- FILE* file;
-
-
-
-diff -ru ../test3.20070520.stock/xv-3.10a/xviff.c ./xviff.c
---- ../test3.20070520.stock/xv-3.10a/xviff.c 2007-05-13 17:50:59.000000000 -0700
-+++ ./xviff.c 2008-12-16 09:20:25.000000000 -0800
-@@ -73,6 +73,7 @@
- int BMHDok, CMAPok, CAMGok;
- int bmhd_width, bmhd_height, bmhd_bitplanes, bmhd_transcol;
- int i, j, k, lineskip, colors, fmt;
-+ int npixels = 0; /* needs to be initialized _outside_ while-loop */
- byte bmhd_masking, bmhd_compression;
- long chunkLen, camg_viewmode;
- byte *databuf, *dataptr, *cmapptr, *picptr, *pic, *bodyptr;
-@@ -138,7 +139,6 @@
- BODY chunk was found or dataptr ran over end of file */
-
- while ((rv<0) && (dataptr < (databuf + filesize))) {
-- int npixels = 0;
- chunkLen = (iff_getlong(dataptr + 4) + 1) & 0xfffffffe; /* make even */
-
- if (strncmp((char *) dataptr, "BMHD", (size_t) 4)==0) { /* BMHD chunk? */
diff --git a/extra/source/xv/xv-3.10a-jumbo-README.txt b/extra/source/xv/xv-3.10a-jumbo-README.txt
deleted file mode 100644
index 00b1c3e4e..000000000
--- a/extra/source/xv/xv-3.10a-jumbo-README.txt
+++ /dev/null
@@ -1,559 +0,0 @@
-This is the latest version of the XV jumbo patches I originally created in
-February 2000 (but never distributed) and eventually updated and released in
-May 2004, prompted by a discussion on LWN (http://lwn.net/Articles/76391/).
-Information about the patches, updates to the patches, and the patches
-themselves can all be found here:
-
- http://pobox.com/~newt/greg_xv.html
- http://freshmeat.net/projects/xvjumbopatches/
-
-(Use the "Subscribe to new releases" link on the latter page if you want to
-be notified of new versions automatically; trivial registration required.)
-
-These patches incorporate all of the fix- and enhancement-patches available
-from John's XV site (http://www.trilon.com/xv/downloads.html and
-ftp://ftp.trilon.com/pub/xv/patches/), plus a number of my own fixes and
-additions (security-related and otherwise), plus quite a few from other
-people. They're still not fully complete, and it's probable they never
-will be, but I do plan to continue tinkering with them whenever the mood
-strikes--and I may even release them publicly on rare occasions. (At the
-current rate, once every few years may be the best we can hope for....)
-
-Also be aware that several other people have had the same idea over the
-years. Ones I've found, more or less by accident, include:
-
- - Landon Curt "chongo" Noll (http://www.isthe.com/chongo/)
- http://www.isthe.com/chongo/src/xv-patch/
- - Mark Ashley
- http://www.ibiblio.org/pub/packages/solaris/sparc/html/xv.3.10a.p19.html
- - Peter Jordan
- http://www.ibiblio.org/pub/Linux/apps/graphics/viewers/X/xv-3.10a.patch.*
- - Uwe F. Mayer (http://www.tux.org/~mayer/)
- http://www.tux.org/~mayer/linux/book/node311.html
- - Kurt Wall
- http://www.kurtwerks.com/software/xv.html
- - Chisato Yamauchi (http://phe.phyas.aichi-edu.ac.jp/~cyamauch/index_en.html)
- http://phe.phyas.aichi-edu.ac.jp/~cyamauch/xv.html
- - Daisuke Yabuki
- http://www.optix.org/~dxy/solaris/xv/
- - Pekoe (http://pekoe.lair.net/)
- http://pekoe.lair.net/diary/xv.html
- - FreeBSD FreshPorts
- http://www.freshports.org/graphics/xv/
- - Kyoichiro Suda
- http://www.coara.or.jp/~sudakyo/XV_jp.html
-
-This is not an exhaustive list (e.g., Jörgen Grahn also had one). So far,
-most of the other patch-sets appear not to be as extensive or as up-to-date
-as my own, particularly now that the (very large) "Japanese extension" patches
-are incorporated--big thanks to Werner Fink of SuSE for that!
-
-Below I summarize the component patches that are encompassed by my jumbo
-bugfixes and jumbo enhancements patches, circa 2005. (As of 2007, they're
-distributed as a single monster-patch, and the "component patches" are now
-listed in the changelog section at the bottom of this file.) Unfortunately,
-some of my own additions never saw the light of day as standalone patches,
-but considering the number of overlaps (collisions) already implicit in the
-list, that would have been difficult to accomplish even if I'd had the time.
-
-Here's a quick guide to the "third-party" credits in the lists and changelog
-below:
-
- AAC = Andrey A. Chernov [ache]
- (http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-ab)
- AD = Andreas Dilger (adilger clusterfs.com)
- AL = Alexander Lehmann (lehmann usa.net)
- AS = Alexey Spiridonov (http://www-math.mit.edu/~lesha/)
- AT = Anthony Thyssen (http://www.cit.gu.edu.au/~anthony/)
- BR = Bruno Rohee (http://bruno.rohee.com/)
- DAC = David A. Clunie (http://www.dclunie.com/xv-pcd.html)
- EAJ = Erling A. Jacobsen (linuxcub email.dk)
- EK = Egmont Koblinger (egmont users.sourceforge.net)
- FG = Fabian Greffrath (fabian debian-unofficial.org)
- GRR = Greg Roelofs (http://pobox.com/~newt/greg_contact.html)
- GV = Guido Vollbeding (http://sylvana.net/guido/)
- IM = IKEMOTO Masahiro (ikeyan airlab.cs.ritsumei.ac.jp)
- JC = John Cooper (john.cooper third-harmonic.com)
- JCE = John C. Elliott (http://www.seasip.demon.co.uk/ZX/zxdload.html)
- JDB = John D. Baker (http://mylinuxisp.com/~jdbaker/)
- JG = Jörgen Grahn (jgrahn algonet.se)
- JHB = John H. Bradley, of course (http://www.trilon.com/xv/)
- JPD = Jean-Pierre Demailly (http://www-fourier.ujf-grenoble.fr/~demailly/)
- JR = John Rochester (http://www.freebsd.org/cgi/query-pr.cgi?pr=2920)
- (also http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-af, -ag)
- JRK = James Roberts Kirkpatrick (uwyo.edu)
- JZ = Joe Zbiciak (http://spatula-city.org/~im14u2c/)
- KS = Kyoichiro Suda (http://www.coara.or.jp/~sudakyo/XV_jp.html)
- LCN = Landon Curt "chongo" Noll (http://www.isthe.com/chongo/)
- LJ = Larry Jones (lawrence.jones ugs.com)
- PBJ = Peter Jordan (http://www.ibiblio.org/pub/Linux/apps/graphics/viewers/X/)
- PSV = Pawel S. Veselov (http://manticore.2y.net/wbmp.html)
- RAC = Ross Combs (rocombs cs.nmsu.edu)
- RJH = Robin Humble (http://www.cita.utoronto.ca/~rjh/)
- SB = Sean Borman (http://www.nd.edu/~sborman/software/xvwheelmouse.html)
- SJT = TenThumbs (tenthumbs cybernex.net)
- SBM = Scott B. Marovich (formerly marovich hpl.hp.com)
- TA = Tim Adye (http://hepwww.rl.ac.uk/Adye/xv-psnewstyle.html)
- TAR = Tim Ramsey (tar pobox.com)
- TI = Tetsuya INOUE (tin329 chino.it.okayama-u.ac.jp)
- TO = Tavis Ormandy (taviso gentoo.org)
- WF = Werner Fink (http://www.suse.de/~werner/)
-
-Other credits are as listed on the XV Downloads page or in the respective
-patches (e.g., the jp-extension patches or within the PNG patch).
-
-Finally, please note that these patches have not been blessed by John Bradley
-in any way (although I copied him on the May 2004 announcement and wrote to
-him again in May 2005), unless you count Debian's redistribution permission
-(Daniel Kirchheimer, 5 Dec 2005). Nor have I personally tested every change
-and feature! (See the BIG SCARY WARNING below for further caveats.) In other
-words, they're both completely unofficial and completely unguaranteed. But
-they seem to work for me. (And when they don't, I try to fix 'em--eventually,
-anyway... ;-) )
-
-Greg Roelofs, 20070520
-http://pobox.com/~newt/greg_contact.html
-
-
-How to build
-------------
-
-The following assumes you, the user, already have the libtiff,[1] libjpeg,[2]
-libpng,[3] zlib,[4] and JasPer[5] libraries downloaded, patched (if necessary),
-compiled, and installed, not to mention a C compiler and the bzip2,[6] tar,[7]
-patch,[8] and make[9] utilities. You should also have downloaded the original
-XV 3.10a source distribution from the XV Downloads page[10] and be able to edit
-its Makefile and config.h files as indicated in the INSTALL file. (Editing
-the Makefile will also allow you to disable some of the third-party libraries
-if you wish.) Finally, you should know what a Unix(-style) command line is,
-where to find one, and how to wield it with abandon (or at least with adult
-supervision)--and preferably not as the root user until the "make install"
-step. (A filesystem is a terrible thing to waste.)
-
- [1] http://www.remotesensing.org/libtiff/
- [2] http://www.ijg.org/
- [3] http://www.libpng.org/pub/png/libpng.html
- [4] http://www.zlib.net/
- [5] http://www.ece.uvic.ca/~mdadams/jasper/
- [6] http://sources.redhat.com/bzip2/
- [7] http://www.gnu.org/directory/devel/specific/tar.html
- [8] http://www.gnu.org/directory/devel/specific/patch.html
- [9] http://www.gnu.org/directory/devel/specific/make.html
- [10] http://www.trilon.com/xv/downloads.html#src-distrib
-
-+-------------------------------------------------------------------------+
-| |
-| BIG SCARY WARNING |
-| |
-| These patches work for Greg (and parts of them reportedly work for |
-| various other people), and so far Greg's CPU still computes and his |
-| hard disks haven't been wiped. But there's no guarantee that this |
-| will be the case for you! In particular, not every incorporated patch |
-| has been explicitly tested, nor has every possible subcase of the |
-| explicitly tested subset. (Read that again; it's grammatical.) Nor |
-| are these patches officially blessed by John Bradley in any way. In |
-| other words, if you use these patches, you do so at your own risk. |
-| (Greg doesn't believe there are any serious problems remaining, but |
-| then, what programmer ever does? Bugs happen.) |
-| |
-+-------------------------------------------------------------------------+
-
-Assuming you have the prerequisites out of the way and aren't scared
-off by the Big Scary Warning, here's the build procedure:
-
- tar xvzf xv-3.10a-jumbo-patches-20070520.tar.gz
- (or: gzip -dc xv-3.10a-jumbo-patches-20070520.tar.gz | tar xvf - )
-
- tar xvzf xv-3.10a.tar.gz
-
- cd xv-3.10a
-
- patch -p1 < ../xv-3.10a-jumbo-fix-enh-patch-20070520.txt
-
- edit Makefile and config.h as directed in INSTALL file (in particular,
- ensure paths to external libraries and header files are correct)
-
- make
-
- ./xv your_favorite_image your_other_favorite_image etc.
-
-If everything seems to be working to your satisfaction, go ahead and install:
-
- make -n install (and double-check that things will be installed
- where you want them to be)
-
- become root if necessary (e.g., type su)
-
- make install
- (or: sudo make install)
-
-That wasn't so hard, was it?
-
-
-Summary of incorporated and unincorporated patches (through 20050501)
----------------------------------------------------------------------
-(See the ChangeLog at the bottom for more recent incorporated patches.)
-
-fixes ((*) = listed on XV Downloads page, (f) = on ftp site only):
-
-20040516:
- - grabpatch (*) [obsoleted by new-xvgrab.c below]
- - vispatch (*)
- - mp-tiff-patch (*) [technically an enhancement, but JHB says...]
- - longname.patch (*) [*SECURITY*]
- - xpm.patch (*)
- - deepcolor.patch (*) [slightly modified for language conformance]
- - gifpatch (*)
- - exceed_grab.patch (*)
- - xv-redhat6-readme.txt (*) [slightly modified for portability]
- - beos.patch (*) [modified for portability]
- - croppad.patch (f)
- - epsfpatch (f)
- - tiff1200.patch (*)
- - gssafer.patch (*) [*SECURITY*]
- - new-xvgrab.c (f) [includes grabpatch but not exceed_grab.patch]
- - xcmap.diff (AD) [part of xv-3.10a-png-1.2d.tar.gz]
- - fixes for huge number gcc -Wall warnings--including two bugs (GRR)
- - fix for cleandir script when no makefile exists (GRR)
- - *SECURITY* fix for gets() in vdcomp.c (GRR, LCN vdcomp-security.patch)
- - *SECURITY* fix for getwd() on Linux (GRR, LCN Linux-compile.patch)
- - fix for "no fuss" Linux compiles (LCN Linux-compile.patch)
- - partial *SECURITY* fix for mktemp() in xv.c and xvdir.c (GRR)
- (remaining instances in xv.c (2), xvimage.c, xvfits.c, xvpds.c, xvps.c, and
- possibly xvtiff.c--most involve system())
- - freebsd-vdcomp-newline.patch (AAC)
- - xv-3.10a.patch.linux (PBJ) [/bin/sh versions of cleandir, RANLIB.sh only]
- - removed trailing white space (GRR) [purely cosmetic]
-20040523:
- - fixed compilation error in registered versions (GRR)
-20050410:
- - fix for YCbCr oversaturated-green bug(s) in TIFF decoder (GRR)
- - provisional fix for contiguous tiled TIFFs with bottom-* orientation (GRR)
- - fixes for gcc 3.3 -Wall warnings (GRR)
- - fix for incorrect 16/24-bit display of xwd dumps (SJT)
- - *SECURITY* fix for multiple input-validation bugs (OpenBSD/SuSE, Gentoo, GRR)
- (this also completes the partial mktemp() security fix listed above)
- - fix for (probable) 24-bit endianness bug in fixpix code (GRR)
-
-
-enhancements ((*) = listed on XV Downloads page, () = third-party):
-
-20040516:
- - xv-3.10a.JPEG-patch (*)
- (xv-3.10a.JPEG-patch.old differs only in ftp site listed in comments at top)
- - xv-3.10a.TIFF-patch (*)
- - xv-3.10a-png-1.2d.tar.gz (AL, AD) (*)
- (xvjpeg.diff and xvtiff.diff ignored; xcmap.diff included in fixes)
- - xvpng-1.2d-fix3.patch (GRR, SJT) (*)
- - pdf.patch (*)
- - windowid.patch + windowid.patch.readme (*)
- - bmp32.patch (*)
- - fixpix-20000610.tar.gz (GV)
- (identical to 19961127 version except for README updates and new Win32 file)
- [modified to be runtime-selectable via -/+fixpix option]
- - browse-remember.patch (JZ)
- - faster-smooth.patch (JZ)
- - PAM support (GRR)
- - PNG/GIF -ibg ("image background") transparency option (GRR)
- (does not yet support TIFF, XPM or TGA)
- - VersionInfo* in help screen (GRR)
- - minor grammar/spelling fixes (GRR)
- - floating-point support for -wait when USE_TICKS enabled (GRR)
- - wheelmouse.patch (SB)
- - freebsd-gravity-hints-patch (JR)
- - xv-zx.patch (JCE)
- - xv3.10a.wapbmp.patch (PSV)
- - xv-3.10a-pcd.patch.20010708 (DAC)
- - jp-ext-bzip2-1.1.patch
- (from ftp://ftp.freebsd.org/pub/FreeBSD/ports/local-distfiles/shige/xv/)
-20050410:
- - boosted maximum number of files from 4096 to 32768 (GRR)
- (note that OS kernel limits may also apply; for example, in Linux see
- MAX_ARG_PAGES in linux-/include/linux/binfmts.h)
- - xv-3.10a-bmp16.patch (KS)
- - final-image delay (e.g., "-wait 0.2,3" : pause 3 secs on final image) (GRR)
- - xv-numpad.patch (EK)
- - xv-delete-is-not-backspace.patch (EK)
- - made browser window (schnauzer) and icons configurable (AT, GRR)
-20050501:
- - xv-3.10a-bmpfix.patch (WF) [*SECURITY*]
- - xv310a-jp-extension-rev5.3.3.tar.gz (TI, IM, ..., WF)
- (adds support for MAG, MAKI, Pi, PIC, and PIC2 formats[!]; "magic suffix"
- detection/conversion; MacBinary prefixes; archives as virtual filesystems;
- multilingual text viewer [though not Unicode]; etc.)
- - xv-3.10a-yaos.dif (WF, TO) [*SECURITY*]
- (fixes a number of format-string issues and system() calls)
- - xv-3.10a.dif (WF) [*SECURITY*]
- (fixes more format-string issues, mktemp() and open() calls, and compilation
- warnings [mostly from jp-extension patch])
- - xv-3.10a-jumbo-jpd_startgrab-patch-20050420.txt (JPD)
- - PATCH.alwaysnever (LJ)
- - PATCH.bsd (LJ)
- - PATCH.linedraw (LJ)
- - PATCH.multipage (LJ)
- - PATCH.multipageGIF (LJ)
- - PATCH.random (LJ)
- - PATCH.stat (LJ)
- - PATCH.thumbs (LJ)
- - xv-startgrab-imake-hips.patch (JPD)
- ("hips" portion only; adds support for HIPS image format[!])
- - xv-3.10a-formatstr.patch (KS)
- - xv-3.10a-shortsleep.patch (KS)
- - xv-3.10a-locale-linux.patch (KS)
- - xv-3.10a-printkey.patch (KS)
- - xv-3.10a-sysconfdir.patch (KS)
- - added PREFIX and DESTDIR support to Makefile (KS, GRR)
- - xv-3.10a-xvexecpath.patch (but disabled pending fixes) (KS)
- - xv-3.10a-zeroquit.patch (KS, GRR)
-
-[!] Note that all six of these formats may still suffer from exploitable heap
- overflows [*SECURITY*] when decoding images with large (possibly invalid)
- dimensions; as a result, they are DISABLED by default. (Search for "GRR
- POSSIBLE OVERFLOW / FIXME" comments in xvmag.c, xvmaki.c, xvpi.c, xvpic.c,
- xvpic2.c, and xvhips.c, but keep in mind that these may not be exhaustive.)
- Users who choose to overlook these security issues can enable any or all
- of them by editing config.h.
-
-
-not (yet?) included:
-
- - others from http://www.coara.or.jp/~sudakyo/XV_jp.html (some are duplicates):
- -rw-r--r-- 4644 Mar 11 2004 xv-3.10a-directory.patch
- -rw-r--r-- 462 Mar 11 2004 xv-3.10a-dirwkey.patch
- -rw-r--r-- 688 Mar 11 2004 xv-3.10a-docdir.patch
- -rw-r--r-- 11952 Mar 11 2004 xv-3.10a-download-test0.patch
- -rw-r--r-- 41786 Mar 11 2004 xv-3.10a-download-test1.patch
- -rw-r--r-- 42397 Mar 11 2004 xv-3.10a-download-test2.patch
- -rw-r--r-- 47679 Mar 11 2004 xv-3.10a-download-test3.patch
- -rw-r--r-- 52745 Mar 11 2004 xv-3.10a-download-test4.patch
- -rw-r--r-- 3423 Apr 24 2004 xv-3.10a-keyzoom.patch
- -rw-r--r-- 12387 Mar 15 2004 xv-3.10a-menubutton.patch
- -rw-r--r-- 1178 Apr 24 2004 xv-3.10a-noblink.patch
- -rw-r--r-- 57092 Jul 9 2004 xv-3.10a-resolution.patch
- -rw-r--r-- 4645 Apr 24 2004 xv-3.10a-selall.patch
- -rw-r--r-- 702 Apr 24 2004 xv-3.10a-showlongname.patch
- -rw-r--r-- 1205 Apr 24 2004 xv-3.10a-staytoppdir.patch
- -rw-r--r-- 4228 Apr 24 2004 xv-3.10a-wheelmouse.patch
- -rw-r--r-- 744 Apr 24 2004 xv-3.10a-xvbutt_wait.patch
- -rw-r--r-- 3757 Jul 9 2004 xv-3.10a-xvscrl_button2.patch
- -rw-r--r-- 1494 Jul 9 2004 xv-3.10a-xvscrl_wait.patch
- -rw-r--r-- 19352 Jul 9 2004 xv-3.10a-xvzoom.patch
-
- - xv-3.10a+jp-extension-rev5.3.3+FLmask.v2.1+png+misc.patch ["mask" support]
-
- - xv-psnewstyle.patch (TA) [coming "soon"?]
- - xv-3.10a.patch.linux (PBJ) [maybe use vdcomp.c changes?]
- - xvxpm-anthony-thyssen.c (AT) ["slate grey" bug already gone?]
- - xv-geoff-kuenning-iconsize-slideshow.patch [var. icons; full-screen slides]
- - xv-scott-marovich-20070214-xvtiff.c.patch6.unified [TIFF CMYK support]
-
- - stuff in xv/unsupt:
- -rw-r--r-- 30527 Dec 22 1994 FITS.rite
- -rw-r--r-- 49152 Dec 22 1994 FITS.tar
- -rw-r--r-- 3753 Dec 22 1994 G3.patch1
- -rw-r--r-- 24576 Dec 22 1994 G3.tar
- -rw-r--r-- 1098 Dec 22 1994 INFO.cgm
- -rw-r--r-- 1941 Dec 22 1994 README
- -rwxr-xr-x 1059 Dec 22 1994 getweather
- -rwxr-xr-x 2186 Dec 22 1994 getweather.ksh
- -rw-r--r-- 856 Dec 22 1994 twm.fix
- -rw-r--r-- 844 Dec 22 1994 vargs.c
- -rw-r--r-- 47626 Dec 22 1994 vis
- -rw-r--r-- 21097 Dec 22 1994 xscm
-
-
-
-not finished (and/or even started ;-) ):
-
- - fix xvpng.c not to use direct struct access
- - (better) fix for never-ending pile of SLOW popups when viewing TIFFs with
- unknown tags (or truncated/corrupted images)
- - fix for minor .Z inefficiency in xv.c ("FIXME")
- - fix for filename entry-field mouse/cursor deficiencies
- (positioning fixed 20070104 by Ross Combs; would like select/cut/paste, too)
- - fix for .ppm.gz "disk leak" [can't reproduce...already fixed?]
- (maybe occurs only if filesystem is already nearly full? bad .gz?)
-
- - transparency support for TIFF, XPM and TGA images
- - support for tiled background image (with transparent foreground image)
- - MNG/JNG support
- - SVG support
-
-
-ChangeLog
----------
-
- 20000220
- original pair of jumbo patches, comprising perhaps 16 fix-patches and a
- dozen enhancement-patches; never publicly released
-
- 20040516
- first public release, incorporating 25 fix-patches and 21 enhancement-
- patches
-
- 20040523
- minor fix to xvctrl.c to support registered versions (GRR warnings-patch
- was slightly overzealous); switched to tarball packaging
-
- 20040531
- fixed undefined CLK_TCK with gcc -ansi (enh/USE_TICKS option); made
- libjpeg, libtiff, libpng and zlib sections of makefile more consistent
- (enh)
-
- 20040606
- added freshmeat link, build instructions, and changelog to jumbo README
- (this file)
-
- 20050213
- increased max number of files from 4096 to 32768 (enh)
-
- 20050320-20050410
- fixed two very long-standing YCbCr bugs in TIFF decoder (fix);
- provisionally fixed bug in TIFF decoder for contiguous tiled TIFFs with
- bottom-* orientation (fix/USE_TILED_TIFF_BOTLEFT_FIX option); fixed new
- gcc 3.3 warnings (fix); fixed incorrect 16/24-bit display of xwd dumps
- (fix); fixed multiple input-validation bugs (potential heap overflows)
- and mktemp() dependencies (*SECURITY* fixes: CAN-2004-1725, CAN-2004-
- 1726, CAN-2005-0665, CERT VU#622622, and others); added support for 16-
- and 32-bit BMPs using bitfields "compression" (enh); fixed probable byte-
- sex bug in 24-bit FixPix display code (enh/USE_24BIT_ENDIAN_FIX option);
- fixed numerical-keypad NumLock behavior and delete-key behavior in file-
- load/save window (enh); made schnauzer window and icons configurable (enh)
-
- 20050417
- incorporated "Japanese extension" patches, revision 5.3.3 (enh); fixed
- additional *SECURITY* issues (format-string vulnerabilities, system()
- and mktemp() calls, etc., but NOT heap overflows in new decoders) both
- in existing code and in jp-extension additions (enh)
-
- 20050425
- added support for -startgrab option (enh); added support for a "Never"
- button to file-overwrite popups (enh); added NetBSD and BSDI to list of
- mkstemp()-supporting systems (enh); improved line-drawing code to set the
- correct pixels for lines of all slopes (enh); added "Page n of m" to Info
- window for multipage images (enh); added support for multipage (animated)
- GIFs (enh); fixed -random support so randomized file list can be traversed
- normally in forward or backward direction (enh); added typecasts to stat()
- printfs for portability (enh); fixed erroneous use of "creation" time and
- forced unlink prior to overwrite in schnauzer thumbnail code (enh); added
- HIPS support (enh/HAVE_HIPS option)
-
- 20050501
- extended multipage keyboard support (PgUp/PgDn) to all windows except
- control ("console") and directory (enh); fixed minor (non-security)
- format-string issue in xv.c (enh); shortened delay on popup error windows
- from 3 seconds to 1 second (enh); tweaked text-viewer localization support
- (TV_L10N) for Linux (enh); added keyboard short cuts for Color and
- Grayscale buttons in print dialog (enh); added support for separate "magic
- suffix" (xv_mgcsfx) config dir (enh); added PREFIX and DESTDIR support to
- Makefile (enh); fixed handling of zero-length files and other text-viewer
- failures (enh)
-
- 20050528
- conditionally added missing alloca.h to xvpcd.c (required if alloca() is
- a macro and alloca.h not included in stdlib.h, for example); fixed bogus
- __S_IWRITE introduced in 20050501 release; fixed Makefile "install" target
- (mkdir, chmod); fixed bug in MUST macro in xvwbmp.c; fixed prototype
- warnings in xvevent.c, xvpcd.c (JRK, GRR)
- - xv-3.10a-jimkirk-fixes.patch
-
- 20050630
- fixed broken mkdir(.xvpics) introduced in 20050501 release (RJH, GRR);
- tweaked GUNZIP config for OpenBSD (GRR)
- - xv-3.10a-xvpics-mkdir-fix.patch
-
- 20051014
- fixed longstanding xvevent.c typo (wasJpegUp -> wasPngUp) that caused build
- failure if no JPEG support (TAR)
-
- 20051019
- fixed Darwin (Mac OS X) build error in xv.h and vdcomp.c due to lack of
- malloc.h (JDB)
-
- 20070210
- fixed minor grammos (GRR); promoted PNG to first position, demoted GIF to
- third (GRR); changed internal type of default image to PNG (GRR); increased
- max files again, to 65536 (GRR)
-
- 20070310
- incorporated JPEG-2000 patch (SBM, GRR); added manual fax options for
- unrecognized G3 images (SBM); relaxed 30-byte minimum file size (SBM)
- - http://www.ece.uvic.ca/~mdadams/jasper/software/xv-patches
-
- 20070318
- incorporated 16bps raw (binary) PPM patch (define ASSUME_RAW_PPM_LSB_FIRST
- for old behavior) (RAC, GRR); updated format list, web sites in xv man page
- (GRR); fixed Makefile "install" target to create any necessary directories
- (RAC, GRR); fixed GIF decoder bug (sizes of global, local color tables
- different) (GRR)
- - xv-ross-combs-ppm-16bps-rawbits.patch
-
- 20070325
- fixed invalid gamma assumption in PNG decoder (=> progressive color changes
- over load/save cycles) (GRR)
-
- 20070328
- fixed animated-GIF /tmp/xvpgXXXXXX droppings (GRR)
-
- 20070331
- fixed PNG duplicate-palette-entries bug (GRR)
-
- 20070415
- incorporated EXIF-preserve patch (GHK); added missing JP2/JPC VS bits code
- (GRR); added extended-warning options to CCOPTS (RAC); added "const" to
- huge number of function args (RAC, GRR); made more effectively static
- functions officially static (RAC); added mouse-clickability (but not
- selectability) to text-entry fields (RAC); fixed window positioning (race
- conditions?) under some virtual window managers (e.g., tvtwm) (RAC);
- removed explicit paths for external (de)compressors (GRR, RAC)
- - xv-geoff-kuenning-jpeg-exif-preserve.patch
- - xv-ross-combs-20070104.diff
-
- 20070422
- incorporated function-key-scripts patch (see contrib/fnkey-scripts) (AS);
- fixed man-page-section extensions ("1", not "l" or "1X") (FG); switched to
- more sensible install paths for docs (FG); added Fedora Core build script
- (see contrib/fedora) (JC); fixed VS to switch from move-mode to copy-mode
- if source dir is read-only (EAJ); extended VS incremental-search mode (EAJ)
- - xv-alexey-spiridonov-20070116-fnkey-scripts.tar.bz2
- - xv-fabian-greffrath-20070215-debian-04-manpages.dpatch
- - xv-fabian-greffrath-20070215-debian-03-makefiles.dpatch
- - xv-john-cooper-Build-FC5-script.sh
- - xv-erling-jacobsen-20060617-incr-search.patch
-
- 20070428
- modified install to include README.jumbo in docs (GRR); incorporated PNG
- no-stdio patch (SBM); fixed XWD endianness support, improved performance
- (replaces SJT 16/24-bit fix) (SBM)
- - xv-scott-marovich-20070214-xvpng.diff
- - xv-scott-marovich-20070214-xvxwd.c.patch
-
- 20070506
- added JPEG CMYK support (SBM); fixed TIFF (and others?) /tmp/xvpgXXXXXX
- droppings (GRR); added VS clipboard support (JG)
- - xv-scott-marovich-20070214-xvjpeg.c.patch
- - xv-jurgen-grahn-20051127-schnauzer-clip.patch
-
- 20070512
- inverted handling of malloc.h header file to require NEED_MALLOC_H macro
- for those few systems that actually need it (GRR)
-
- 20070513
- fixed GCC 4.1.x warnings (GRR); next round of const cleanup (GRR); fixed
- minor TIFF memleak (GRR)
-
- 20070514
- fixed TIFF YCbCr reference black/white levels (SBM); added option to use
- libjpeg YCbCr-to-RGB conversion for TIFF images (SBM, GRR)
- - xv-scott-marovich-20070214-xvtiff.c.patch2.unified
- - xv-scott-marovich-20070214-xvtiff.c.patch3.unified
-
- 20070519
- fixed handling of multi-page JPEG-compressed TIFFs (old or new) (SBM);
- added TIFF YCbCr separated-color-plane support (may require libtiff
- patch(es) to tif_ojpeg.c and/or tif_jpeg.c) (SBM)
- - xv-scott-marovich-20070214-xvtiff.c.patch4.unified
- - xv-scott-marovich-20070214-xvtiff.c.patch5.unified
-
- 20070520
- updated README.jumbo
diff --git a/extra/source/xv/xv-3.10a-jumbo-additions.diff b/extra/source/xv/xv-3.10a-jumbo-additions.diff
deleted file mode 100644
index 8f398ddf2..000000000
--- a/extra/source/xv/xv-3.10a-jumbo-additions.diff
+++ /dev/null
@@ -1,18743 +0,0 @@
-diff -u -r --new-file xv-3.10a.orig/README.jumbo xv-3.10a/README.jumbo
---- xv-3.10a.orig/README.jumbo 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/README.jumbo 2007-05-21 00:19:20.000000000 -0500
-@@ -0,0 +1,559 @@
-+This is the latest version of the XV jumbo patches I originally created in
-+February 2000 (but never distributed) and eventually updated and released in
-+May 2004, prompted by a discussion on LWN (http://lwn.net/Articles/76391/).
-+Information about the patches, updates to the patches, and the patches
-+themselves can all be found here:
-+
-+ http://pobox.com/~newt/greg_xv.html
-+ http://freshmeat.net/projects/xvjumbopatches/
-+
-+(Use the "Subscribe to new releases" link on the latter page if you want to
-+be notified of new versions automatically; trivial registration required.)
-+
-+These patches incorporate all of the fix- and enhancement-patches available
-+from John's XV site (http://www.trilon.com/xv/downloads.html and
-+ftp://ftp.trilon.com/pub/xv/patches/), plus a number of my own fixes and
-+additions (security-related and otherwise), plus quite a few from other
-+people. They're still not fully complete, and it's probable they never
-+will be, but I do plan to continue tinkering with them whenever the mood
-+strikes--and I may even release them publicly on rare occasions. (At the
-+current rate, once every few years may be the best we can hope for....)
-+
-+Also be aware that several other people have had the same idea over the
-+years. Ones I've found, more or less by accident, include:
-+
-+ - Landon Curt "chongo" Noll (http://www.isthe.com/chongo/)
-+ http://www.isthe.com/chongo/src/xv-patch/
-+ - Mark Ashley
-+ http://www.ibiblio.org/pub/packages/solaris/sparc/html/xv.3.10a.p19.html
-+ - Peter Jordan
-+ http://www.ibiblio.org/pub/Linux/apps/graphics/viewers/X/xv-3.10a.patch.*
-+ - Uwe F. Mayer (http://www.tux.org/~mayer/)
-+ http://www.tux.org/~mayer/linux/book/node311.html
-+ - Kurt Wall
-+ http://www.kurtwerks.com/software/xv.html
-+ - Chisato Yamauchi (http://phe.phyas.aichi-edu.ac.jp/~cyamauch/index_en.html)
-+ http://phe.phyas.aichi-edu.ac.jp/~cyamauch/xv.html
-+ - Daisuke Yabuki
-+ http://www.optix.org/~dxy/solaris/xv/
-+ - Pekoe (http://pekoe.lair.net/)
-+ http://pekoe.lair.net/diary/xv.html
-+ - FreeBSD FreshPorts
-+ http://www.freshports.org/graphics/xv/
-+ - Kyoichiro Suda
-+ http://www.coara.or.jp/~sudakyo/XV_jp.html
-+
-+This is not an exhaustive list (e.g., Jörgen Grahn also had one). So far,
-+most of the other patch-sets appear not to be as extensive or as up-to-date
-+as my own, particularly now that the (very large) "Japanese extension" patches
-+are incorporated--big thanks to Werner Fink of SuSE for that!
-+
-+Below I summarize the component patches that are encompassed by my jumbo
-+bugfixes and jumbo enhancements patches, circa 2005. (As of 2007, they're
-+distributed as a single monster-patch, and the "component patches" are now
-+listed in the changelog section at the bottom of this file.) Unfortunately,
-+some of my own additions never saw the light of day as standalone patches,
-+but considering the number of overlaps (collisions) already implicit in the
-+list, that would have been difficult to accomplish even if I'd had the time.
-+
-+Here's a quick guide to the "third-party" credits in the lists and changelog
-+below:
-+
-+ AAC = Andrey A. Chernov [ache]
-+ (http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-ab)
-+ AD = Andreas Dilger (adilger clusterfs.com)
-+ AL = Alexander Lehmann (lehmann usa.net)
-+ AS = Alexey Spiridonov (http://www-math.mit.edu/~lesha/)
-+ AT = Anthony Thyssen (http://www.cit.gu.edu.au/~anthony/)
-+ BR = Bruno Rohee (http://bruno.rohee.com/)
-+ DAC = David A. Clunie (http://www.dclunie.com/xv-pcd.html)
-+ EAJ = Erling A. Jacobsen (linuxcub email.dk)
-+ EK = Egmont Koblinger (egmont users.sourceforge.net)
-+ FG = Fabian Greffrath (fabian debian-unofficial.org)
-+ GRR = Greg Roelofs (http://pobox.com/~newt/greg_contact.html)
-+ GV = Guido Vollbeding (http://sylvana.net/guido/)
-+ IM = IKEMOTO Masahiro (ikeyan airlab.cs.ritsumei.ac.jp)
-+ JC = John Cooper (john.cooper third-harmonic.com)
-+ JCE = John C. Elliott (http://www.seasip.demon.co.uk/ZX/zxdload.html)
-+ JDB = John D. Baker (http://mylinuxisp.com/~jdbaker/)
-+ JG = Jörgen Grahn (jgrahn algonet.se)
-+ JHB = John H. Bradley, of course (http://www.trilon.com/xv/)
-+ JPD = Jean-Pierre Demailly (http://www-fourier.ujf-grenoble.fr/~demailly/)
-+ JR = John Rochester (http://www.freebsd.org/cgi/query-pr.cgi?pr=2920)
-+ (also http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-af, -ag)
-+ JRK = James Roberts Kirkpatrick (uwyo.edu)
-+ JZ = Joe Zbiciak (http://spatula-city.org/~im14u2c/)
-+ KS = Kyoichiro Suda (http://www.coara.or.jp/~sudakyo/XV_jp.html)
-+ LCN = Landon Curt "chongo" Noll (http://www.isthe.com/chongo/)
-+ LJ = Larry Jones (lawrence.jones ugs.com)
-+ PBJ = Peter Jordan (http://www.ibiblio.org/pub/Linux/apps/graphics/viewers/X/)
-+ PSV = Pawel S. Veselov (http://manticore.2y.net/wbmp.html)
-+ RAC = Ross Combs (rocombs cs.nmsu.edu)
-+ RJH = Robin Humble (http://www.cita.utoronto.ca/~rjh/)
-+ SB = Sean Borman (http://www.nd.edu/~sborman/software/xvwheelmouse.html)
-+ SJT = TenThumbs (tenthumbs cybernex.net)
-+ SBM = Scott B. Marovich (formerly marovich hpl.hp.com)
-+ TA = Tim Adye (http://hepwww.rl.ac.uk/Adye/xv-psnewstyle.html)
-+ TAR = Tim Ramsey (tar pobox.com)
-+ TI = Tetsuya INOUE (tin329 chino.it.okayama-u.ac.jp)
-+ TO = Tavis Ormandy (taviso gentoo.org)
-+ WF = Werner Fink (http://www.suse.de/~werner/)
-+
-+Other credits are as listed on the XV Downloads page or in the respective
-+patches (e.g., the jp-extension patches or within the PNG patch).
-+
-+Finally, please note that these patches have not been blessed by John Bradley
-+in any way (although I copied him on the May 2004 announcement and wrote to
-+him again in May 2005), unless you count Debian's redistribution permission
-+(Daniel Kirchheimer, 5 Dec 2005). Nor have I personally tested every change
-+and feature! (See the BIG SCARY WARNING below for further caveats.) In other
-+words, they're both completely unofficial and completely unguaranteed. But
-+they seem to work for me. (And when they don't, I try to fix 'em--eventually,
-+anyway... ;-) )
-+
-+Greg Roelofs, 20070520
-+http://pobox.com/~newt/greg_contact.html
-+
-+
-+How to build
-+------------
-+
-+The following assumes you, the user, already have the libtiff,[1] libjpeg,[2]
-+libpng,[3] zlib,[4] and JasPer[5] libraries downloaded, patched (if necessary),
-+compiled, and installed, not to mention a C compiler and the bzip2,[6] tar,[7]
-+patch,[8] and make[9] utilities. You should also have downloaded the original
-+XV 3.10a source distribution from the XV Downloads page[10] and be able to edit
-+its Makefile and config.h files as indicated in the INSTALL file. (Editing
-+the Makefile will also allow you to disable some of the third-party libraries
-+if you wish.) Finally, you should know what a Unix(-style) command line is,
-+where to find one, and how to wield it with abandon (or at least with adult
-+supervision)--and preferably not as the root user until the "make install"
-+step. (A filesystem is a terrible thing to waste.)
-+
-+ [1] http://www.remotesensing.org/libtiff/
-+ [2] http://www.ijg.org/
-+ [3] http://www.libpng.org/pub/png/libpng.html
-+ [4] http://www.zlib.net/
-+ [5] http://www.ece.uvic.ca/~mdadams/jasper/
-+ [6] http://sources.redhat.com/bzip2/
-+ [7] http://www.gnu.org/directory/devel/specific/tar.html
-+ [8] http://www.gnu.org/directory/devel/specific/patch.html
-+ [9] http://www.gnu.org/directory/devel/specific/make.html
-+ [10] http://www.trilon.com/xv/downloads.html#src-distrib
-+
-++-------------------------------------------------------------------------+
-+| |
-+| BIG SCARY WARNING |
-+| |
-+| These patches work for Greg (and parts of them reportedly work for |
-+| various other people), and so far Greg's CPU still computes and his |
-+| hard disks haven't been wiped. But there's no guarantee that this |
-+| will be the case for you! In particular, not every incorporated patch |
-+| has been explicitly tested, nor has every possible subcase of the |
-+| explicitly tested subset. (Read that again; it's grammatical.) Nor |
-+| are these patches officially blessed by John Bradley in any way. In |
-+| other words, if you use these patches, you do so at your own risk. |
-+| (Greg doesn't believe there are any serious problems remaining, but |
-+| then, what programmer ever does? Bugs happen.) |
-+| |
-++-------------------------------------------------------------------------+
-+
-+Assuming you have the prerequisites out of the way and aren't scared
-+off by the Big Scary Warning, here's the build procedure:
-+
-+ tar xvzf xv-3.10a-jumbo-patches-20070520.tar.gz
-+ (or: gzip -dc xv-3.10a-jumbo-patches-20070520.tar.gz | tar xvf - )
-+
-+ tar xvzf xv-3.10a.tar.gz
-+
-+ cd xv-3.10a
-+
-+ patch -p1 < ../xv-3.10a-jumbo-fix-enh-patch-20070520.txt
-+
-+ edit Makefile and config.h as directed in INSTALL file (in particular,
-+ ensure paths to external libraries and header files are correct)
-+
-+ make
-+
-+ ./xv your_favorite_image your_other_favorite_image etc.
-+
-+If everything seems to be working to your satisfaction, go ahead and install:
-+
-+ make -n install (and double-check that things will be installed
-+ where you want them to be)
-+
-+ become root if necessary (e.g., type su)
-+
-+ make install
-+ (or: sudo make install)
-+
-+That wasn't so hard, was it?
-+
-+
-+Summary of incorporated and unincorporated patches (through 20050501)
-+---------------------------------------------------------------------
-+(See the ChangeLog at the bottom for more recent incorporated patches.)
-+
-+fixes ((*) = listed on XV Downloads page, (f) = on ftp site only):
-+
-+20040516:
-+ - grabpatch (*) [obsoleted by new-xvgrab.c below]
-+ - vispatch (*)
-+ - mp-tiff-patch (*) [technically an enhancement, but JHB says...]
-+ - longname.patch (*) [*SECURITY*]
-+ - xpm.patch (*)
-+ - deepcolor.patch (*) [slightly modified for language conformance]
-+ - gifpatch (*)
-+ - exceed_grab.patch (*)
-+ - xv-redhat6-readme.txt (*) [slightly modified for portability]
-+ - beos.patch (*) [modified for portability]
-+ - croppad.patch (f)
-+ - epsfpatch (f)
-+ - tiff1200.patch (*)
-+ - gssafer.patch (*) [*SECURITY*]
-+ - new-xvgrab.c (f) [includes grabpatch but not exceed_grab.patch]
-+ - xcmap.diff (AD) [part of xv-3.10a-png-1.2d.tar.gz]
-+ - fixes for huge number gcc -Wall warnings--including two bugs (GRR)
-+ - fix for cleandir script when no makefile exists (GRR)
-+ - *SECURITY* fix for gets() in vdcomp.c (GRR, LCN vdcomp-security.patch)
-+ - *SECURITY* fix for getwd() on Linux (GRR, LCN Linux-compile.patch)
-+ - fix for "no fuss" Linux compiles (LCN Linux-compile.patch)
-+ - partial *SECURITY* fix for mktemp() in xv.c and xvdir.c (GRR)
-+ (remaining instances in xv.c (2), xvimage.c, xvfits.c, xvpds.c, xvps.c, and
-+ possibly xvtiff.c--most involve system())
-+ - freebsd-vdcomp-newline.patch (AAC)
-+ - xv-3.10a.patch.linux (PBJ) [/bin/sh versions of cleandir, RANLIB.sh only]
-+ - removed trailing white space (GRR) [purely cosmetic]
-+20040523:
-+ - fixed compilation error in registered versions (GRR)
-+20050410:
-+ - fix for YCbCr oversaturated-green bug(s) in TIFF decoder (GRR)
-+ - provisional fix for contiguous tiled TIFFs with bottom-* orientation (GRR)
-+ - fixes for gcc 3.3 -Wall warnings (GRR)
-+ - fix for incorrect 16/24-bit display of xwd dumps (SJT)
-+ - *SECURITY* fix for multiple input-validation bugs (OpenBSD/SuSE, Gentoo, GRR)
-+ (this also completes the partial mktemp() security fix listed above)
-+ - fix for (probable) 24-bit endianness bug in fixpix code (GRR)
-+
-+
-+enhancements ((*) = listed on XV Downloads page, () = third-party):
-+
-+20040516:
-+ - xv-3.10a.JPEG-patch (*)
-+ (xv-3.10a.JPEG-patch.old differs only in ftp site listed in comments at top)
-+ - xv-3.10a.TIFF-patch (*)
-+ - xv-3.10a-png-1.2d.tar.gz (AL, AD) (*)
-+ (xvjpeg.diff and xvtiff.diff ignored; xcmap.diff included in fixes)
-+ - xvpng-1.2d-fix3.patch (GRR, SJT) (*)
-+ - pdf.patch (*)
-+ - windowid.patch + windowid.patch.readme (*)
-+ - bmp32.patch (*)
-+ - fixpix-20000610.tar.gz (GV)
-+ (identical to 19961127 version except for README updates and new Win32 file)
-+ [modified to be runtime-selectable via -/+fixpix option]
-+ - browse-remember.patch (JZ)
-+ - faster-smooth.patch (JZ)
-+ - PAM support (GRR)
-+ - PNG/GIF -ibg ("image background") transparency option (GRR)
-+ (does not yet support TIFF, XPM or TGA)
-+ - VersionInfo* in help screen (GRR)
-+ - minor grammar/spelling fixes (GRR)
-+ - floating-point support for -wait when USE_TICKS enabled (GRR)
-+ - wheelmouse.patch (SB)
-+ - freebsd-gravity-hints-patch (JR)
-+ - xv-zx.patch (JCE)
-+ - xv3.10a.wapbmp.patch (PSV)
-+ - xv-3.10a-pcd.patch.20010708 (DAC)
-+ - jp-ext-bzip2-1.1.patch
-+ (from ftp://ftp.freebsd.org/pub/FreeBSD/ports/local-distfiles/shige/xv/)
-+20050410:
-+ - boosted maximum number of files from 4096 to 32768 (GRR)
-+ (note that OS kernel limits may also apply; for example, in Linux see
-+ MAX_ARG_PAGES in linux-/include/linux/binfmts.h)
-+ - xv-3.10a-bmp16.patch (KS)
-+ - final-image delay (e.g., "-wait 0.2,3" : pause 3 secs on final image) (GRR)
-+ - xv-numpad.patch (EK)
-+ - xv-delete-is-not-backspace.patch (EK)
-+ - made browser window (schnauzer) and icons configurable (AT, GRR)
-+20050501:
-+ - xv-3.10a-bmpfix.patch (WF) [*SECURITY*]
-+ - xv310a-jp-extension-rev5.3.3.tar.gz (TI, IM, ..., WF)
-+ (adds support for MAG, MAKI, Pi, PIC, and PIC2 formats[!]; "magic suffix"
-+ detection/conversion; MacBinary prefixes; archives as virtual filesystems;
-+ multilingual text viewer [though not Unicode]; etc.)
-+ - xv-3.10a-yaos.dif (WF, TO) [*SECURITY*]
-+ (fixes a number of format-string issues and system() calls)
-+ - xv-3.10a.dif (WF) [*SECURITY*]
-+ (fixes more format-string issues, mktemp() and open() calls, and compilation
-+ warnings [mostly from jp-extension patch])
-+ - xv-3.10a-jumbo-jpd_startgrab-patch-20050420.txt (JPD)
-+ - PATCH.alwaysnever (LJ)
-+ - PATCH.bsd (LJ)
-+ - PATCH.linedraw (LJ)
-+ - PATCH.multipage (LJ)
-+ - PATCH.multipageGIF (LJ)
-+ - PATCH.random (LJ)
-+ - PATCH.stat (LJ)
-+ - PATCH.thumbs (LJ)
-+ - xv-startgrab-imake-hips.patch (JPD)
-+ ("hips" portion only; adds support for HIPS image format[!])
-+ - xv-3.10a-formatstr.patch (KS)
-+ - xv-3.10a-shortsleep.patch (KS)
-+ - xv-3.10a-locale-linux.patch (KS)
-+ - xv-3.10a-printkey.patch (KS)
-+ - xv-3.10a-sysconfdir.patch (KS)
-+ - added PREFIX and DESTDIR support to Makefile (KS, GRR)
-+ - xv-3.10a-xvexecpath.patch (but disabled pending fixes) (KS)
-+ - xv-3.10a-zeroquit.patch (KS, GRR)
-+
-+[!] Note that all six of these formats may still suffer from exploitable heap
-+ overflows [*SECURITY*] when decoding images with large (possibly invalid)
-+ dimensions; as a result, they are DISABLED by default. (Search for "GRR
-+ POSSIBLE OVERFLOW / FIXME" comments in xvmag.c, xvmaki.c, xvpi.c, xvpic.c,
-+ xvpic2.c, and xvhips.c, but keep in mind that these may not be exhaustive.)
-+ Users who choose to overlook these security issues can enable any or all
-+ of them by editing config.h.
-+
-+
-+not (yet?) included:
-+
-+ - others from http://www.coara.or.jp/~sudakyo/XV_jp.html (some are duplicates):
-+ -rw-r--r-- 4644 Mar 11 2004 xv-3.10a-directory.patch
-+ -rw-r--r-- 462 Mar 11 2004 xv-3.10a-dirwkey.patch
-+ -rw-r--r-- 688 Mar 11 2004 xv-3.10a-docdir.patch
-+ -rw-r--r-- 11952 Mar 11 2004 xv-3.10a-download-test0.patch
-+ -rw-r--r-- 41786 Mar 11 2004 xv-3.10a-download-test1.patch
-+ -rw-r--r-- 42397 Mar 11 2004 xv-3.10a-download-test2.patch
-+ -rw-r--r-- 47679 Mar 11 2004 xv-3.10a-download-test3.patch
-+ -rw-r--r-- 52745 Mar 11 2004 xv-3.10a-download-test4.patch
-+ -rw-r--r-- 3423 Apr 24 2004 xv-3.10a-keyzoom.patch
-+ -rw-r--r-- 12387 Mar 15 2004 xv-3.10a-menubutton.patch
-+ -rw-r--r-- 1178 Apr 24 2004 xv-3.10a-noblink.patch
-+ -rw-r--r-- 57092 Jul 9 2004 xv-3.10a-resolution.patch
-+ -rw-r--r-- 4645 Apr 24 2004 xv-3.10a-selall.patch
-+ -rw-r--r-- 702 Apr 24 2004 xv-3.10a-showlongname.patch
-+ -rw-r--r-- 1205 Apr 24 2004 xv-3.10a-staytoppdir.patch
-+ -rw-r--r-- 4228 Apr 24 2004 xv-3.10a-wheelmouse.patch
-+ -rw-r--r-- 744 Apr 24 2004 xv-3.10a-xvbutt_wait.patch
-+ -rw-r--r-- 3757 Jul 9 2004 xv-3.10a-xvscrl_button2.patch
-+ -rw-r--r-- 1494 Jul 9 2004 xv-3.10a-xvscrl_wait.patch
-+ -rw-r--r-- 19352 Jul 9 2004 xv-3.10a-xvzoom.patch
-+
-+ - xv-3.10a+jp-extension-rev5.3.3+FLmask.v2.1+png+misc.patch ["mask" support]
-+
-+ - xv-psnewstyle.patch (TA) [coming "soon"?]
-+ - xv-3.10a.patch.linux (PBJ) [maybe use vdcomp.c changes?]
-+ - xvxpm-anthony-thyssen.c (AT) ["slate grey" bug already gone?]
-+ - xv-geoff-kuenning-iconsize-slideshow.patch [var. icons; full-screen slides]
-+ - xv-scott-marovich-20070214-xvtiff.c.patch6.unified [TIFF CMYK support]
-+
-+ - stuff in xv/unsupt:
-+ -rw-r--r-- 30527 Dec 22 1994 FITS.rite
-+ -rw-r--r-- 49152 Dec 22 1994 FITS.tar
-+ -rw-r--r-- 3753 Dec 22 1994 G3.patch1
-+ -rw-r--r-- 24576 Dec 22 1994 G3.tar
-+ -rw-r--r-- 1098 Dec 22 1994 INFO.cgm
-+ -rw-r--r-- 1941 Dec 22 1994 README
-+ -rwxr-xr-x 1059 Dec 22 1994 getweather
-+ -rwxr-xr-x 2186 Dec 22 1994 getweather.ksh
-+ -rw-r--r-- 856 Dec 22 1994 twm.fix
-+ -rw-r--r-- 844 Dec 22 1994 vargs.c
-+ -rw-r--r-- 47626 Dec 22 1994 vis
-+ -rw-r--r-- 21097 Dec 22 1994 xscm
-+
-+
-+
-+not finished (and/or even started ;-) ):
-+
-+ - fix xvpng.c not to use direct struct access
-+ - (better) fix for never-ending pile of SLOW popups when viewing TIFFs with
-+ unknown tags (or truncated/corrupted images)
-+ - fix for minor .Z inefficiency in xv.c ("FIXME")
-+ - fix for filename entry-field mouse/cursor deficiencies
-+ (positioning fixed 20070104 by Ross Combs; would like select/cut/paste, too)
-+ - fix for .ppm.gz "disk leak" [can't reproduce...already fixed?]
-+ (maybe occurs only if filesystem is already nearly full? bad .gz?)
-+
-+ - transparency support for TIFF, XPM and TGA images
-+ - support for tiled background image (with transparent foreground image)
-+ - MNG/JNG support
-+ - SVG support
-+
-+
-+ChangeLog
-+---------
-+
-+ 20000220
-+ original pair of jumbo patches, comprising perhaps 16 fix-patches and a
-+ dozen enhancement-patches; never publicly released
-+
-+ 20040516
-+ first public release, incorporating 25 fix-patches and 21 enhancement-
-+ patches
-+
-+ 20040523
-+ minor fix to xvctrl.c to support registered versions (GRR warnings-patch
-+ was slightly overzealous); switched to tarball packaging
-+
-+ 20040531
-+ fixed undefined CLK_TCK with gcc -ansi (enh/USE_TICKS option); made
-+ libjpeg, libtiff, libpng and zlib sections of makefile more consistent
-+ (enh)
-+
-+ 20040606
-+ added freshmeat link, build instructions, and changelog to jumbo README
-+ (this file)
-+
-+ 20050213
-+ increased max number of files from 4096 to 32768 (enh)
-+
-+ 20050320-20050410
-+ fixed two very long-standing YCbCr bugs in TIFF decoder (fix);
-+ provisionally fixed bug in TIFF decoder for contiguous tiled TIFFs with
-+ bottom-* orientation (fix/USE_TILED_TIFF_BOTLEFT_FIX option); fixed new
-+ gcc 3.3 warnings (fix); fixed incorrect 16/24-bit display of xwd dumps
-+ (fix); fixed multiple input-validation bugs (potential heap overflows)
-+ and mktemp() dependencies (*SECURITY* fixes: CAN-2004-1725, CAN-2004-
-+ 1726, CAN-2005-0665, CERT VU#622622, and others); added support for 16-
-+ and 32-bit BMPs using bitfields "compression" (enh); fixed probable byte-
-+ sex bug in 24-bit FixPix display code (enh/USE_24BIT_ENDIAN_FIX option);
-+ fixed numerical-keypad NumLock behavior and delete-key behavior in file-
-+ load/save window (enh); made schnauzer window and icons configurable (enh)
-+
-+ 20050417
-+ incorporated "Japanese extension" patches, revision 5.3.3 (enh); fixed
-+ additional *SECURITY* issues (format-string vulnerabilities, system()
-+ and mktemp() calls, etc., but NOT heap overflows in new decoders) both
-+ in existing code and in jp-extension additions (enh)
-+
-+ 20050425
-+ added support for -startgrab option (enh); added support for a "Never"
-+ button to file-overwrite popups (enh); added NetBSD and BSDI to list of
-+ mkstemp()-supporting systems (enh); improved line-drawing code to set the
-+ correct pixels for lines of all slopes (enh); added "Page n of m" to Info
-+ window for multipage images (enh); added support for multipage (animated)
-+ GIFs (enh); fixed -random support so randomized file list can be traversed
-+ normally in forward or backward direction (enh); added typecasts to stat()
-+ printfs for portability (enh); fixed erroneous use of "creation" time and
-+ forced unlink prior to overwrite in schnauzer thumbnail code (enh); added
-+ HIPS support (enh/HAVE_HIPS option)
-+
-+ 20050501
-+ extended multipage keyboard support (PgUp/PgDn) to all windows except
-+ control ("console") and directory (enh); fixed minor (non-security)
-+ format-string issue in xv.c (enh); shortened delay on popup error windows
-+ from 3 seconds to 1 second (enh); tweaked text-viewer localization support
-+ (TV_L10N) for Linux (enh); added keyboard short cuts for Color and
-+ Grayscale buttons in print dialog (enh); added support for separate "magic
-+ suffix" (xv_mgcsfx) config dir (enh); added PREFIX and DESTDIR support to
-+ Makefile (enh); fixed handling of zero-length files and other text-viewer
-+ failures (enh)
-+
-+ 20050528
-+ conditionally added missing alloca.h to xvpcd.c (required if alloca() is
-+ a macro and alloca.h not included in stdlib.h, for example); fixed bogus
-+ __S_IWRITE introduced in 20050501 release; fixed Makefile "install" target
-+ (mkdir, chmod); fixed bug in MUST macro in xvwbmp.c; fixed prototype
-+ warnings in xvevent.c, xvpcd.c (JRK, GRR)
-+ - xv-3.10a-jimkirk-fixes.patch
-+
-+ 20050630
-+ fixed broken mkdir(.xvpics) introduced in 20050501 release (RJH, GRR);
-+ tweaked GUNZIP config for OpenBSD (GRR)
-+ - xv-3.10a-xvpics-mkdir-fix.patch
-+
-+ 20051014
-+ fixed longstanding xvevent.c typo (wasJpegUp -> wasPngUp) that caused build
-+ failure if no JPEG support (TAR)
-+
-+ 20051019
-+ fixed Darwin (Mac OS X) build error in xv.h and vdcomp.c due to lack of
-+ malloc.h (JDB)
-+
-+ 20070210
-+ fixed minor grammos (GRR); promoted PNG to first position, demoted GIF to
-+ third (GRR); changed internal type of default image to PNG (GRR); increased
-+ max files again, to 65536 (GRR)
-+
-+ 20070310
-+ incorporated JPEG-2000 patch (SBM, GRR); added manual fax options for
-+ unrecognized G3 images (SBM); relaxed 30-byte minimum file size (SBM)
-+ - http://www.ece.uvic.ca/~mdadams/jasper/software/xv-patches
-+
-+ 20070318
-+ incorporated 16bps raw (binary) PPM patch (define ASSUME_RAW_PPM_LSB_FIRST
-+ for old behavior) (RAC, GRR); updated format list, web sites in xv man page
-+ (GRR); fixed Makefile "install" target to create any necessary directories
-+ (RAC, GRR); fixed GIF decoder bug (sizes of global, local color tables
-+ different) (GRR)
-+ - xv-ross-combs-ppm-16bps-rawbits.patch
-+
-+ 20070325
-+ fixed invalid gamma assumption in PNG decoder (=> progressive color changes
-+ over load/save cycles) (GRR)
-+
-+ 20070328
-+ fixed animated-GIF /tmp/xvpgXXXXXX droppings (GRR)
-+
-+ 20070331
-+ fixed PNG duplicate-palette-entries bug (GRR)
-+
-+ 20070415
-+ incorporated EXIF-preserve patch (GHK); added missing JP2/JPC VS bits code
-+ (GRR); added extended-warning options to CCOPTS (RAC); added "const" to
-+ huge number of function args (RAC, GRR); made more effectively static
-+ functions officially static (RAC); added mouse-clickability (but not
-+ selectability) to text-entry fields (RAC); fixed window positioning (race
-+ conditions?) under some virtual window managers (e.g., tvtwm) (RAC);
-+ removed explicit paths for external (de)compressors (GRR, RAC)
-+ - xv-geoff-kuenning-jpeg-exif-preserve.patch
-+ - xv-ross-combs-20070104.diff
-+
-+ 20070422
-+ incorporated function-key-scripts patch (see contrib/fnkey-scripts) (AS);
-+ fixed man-page-section extensions ("1", not "l" or "1X") (FG); switched to
-+ more sensible install paths for docs (FG); added Fedora Core build script
-+ (see contrib/fedora) (JC); fixed VS to switch from move-mode to copy-mode
-+ if source dir is read-only (EAJ); extended VS incremental-search mode (EAJ)
-+ - xv-alexey-spiridonov-20070116-fnkey-scripts.tar.bz2
-+ - xv-fabian-greffrath-20070215-debian-04-manpages.dpatch
-+ - xv-fabian-greffrath-20070215-debian-03-makefiles.dpatch
-+ - xv-john-cooper-Build-FC5-script.sh
-+ - xv-erling-jacobsen-20060617-incr-search.patch
-+
-+ 20070428
-+ modified install to include README.jumbo in docs (GRR); incorporated PNG
-+ no-stdio patch (SBM); fixed XWD endianness support, improved performance
-+ (replaces SJT 16/24-bit fix) (SBM)
-+ - xv-scott-marovich-20070214-xvpng.diff
-+ - xv-scott-marovich-20070214-xvxwd.c.patch
-+
-+ 20070506
-+ added JPEG CMYK support (SBM); fixed TIFF (and others?) /tmp/xvpgXXXXXX
-+ droppings (GRR); added VS clipboard support (JG)
-+ - xv-scott-marovich-20070214-xvjpeg.c.patch
-+ - xv-jurgen-grahn-20051127-schnauzer-clip.patch
-+
-+ 20070512
-+ inverted handling of malloc.h header file to require NEED_MALLOC_H macro
-+ for those few systems that actually need it (GRR)
-+
-+ 20070513
-+ fixed GCC 4.1.x warnings (GRR); next round of const cleanup (GRR); fixed
-+ minor TIFF memleak (GRR)
-+
-+ 20070514
-+ fixed TIFF YCbCr reference black/white levels (SBM); added option to use
-+ libjpeg YCbCr-to-RGB conversion for TIFF images (SBM, GRR)
-+ - xv-scott-marovich-20070214-xvtiff.c.patch2.unified
-+ - xv-scott-marovich-20070214-xvtiff.c.patch3.unified
-+
-+ 20070519
-+ fixed handling of multi-page JPEG-compressed TIFFs (old or new) (SBM);
-+ added TIFF YCbCr separated-color-plane support (may require libtiff
-+ patch(es) to tif_ojpeg.c and/or tif_jpeg.c) (SBM)
-+ - xv-scott-marovich-20070214-xvtiff.c.patch4.unified
-+ - xv-scott-marovich-20070214-xvtiff.c.patch5.unified
-+
-+ 20070520
-+ updated README.jumbo
-diff -u -r --new-file xv-3.10a.orig/README.pcd xv-3.10a/README.pcd
---- xv-3.10a.orig/README.pcd 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/README.pcd 2001-07-08 13:21:19.000000000 -0500
-@@ -0,0 +1,159 @@
-+Copyright 1993-2001 David Clunie.
-+
-+PCD patch for XV 3.10a Release Notes 2001/07/08.
-+
-+See also the progress notes at the end of this file. Thanks to all those
-+contributors who have substantially improved this patch.
-+
-+These patches allow xv to read Kodak photocd files and choose which of the
-+5 available resolutions one wants to view.
-+
-+When a photocd file is loaded, a dialog box asks which resolution you
-+would like. The visual schnauzer builds thumbnails by reading the lowest
-+resolution image. The selected resolution can be selected from the
-+command line with the -pcd option:
-+
-+ [-pcd 0|1|2|3|4]
-+
-+where:
-+
-+ 0=192*128, base/16 resolution
-+ 1=384*256, base/4 resolution
-+ 2=768*512, base resolution
-+ 3=1536*1024, 4base resolution
-+ 4=3072*2048 16base resolution.
-+
-+Note that the Pro format is not supported.
-+
-+The command line option allows loops without the dialog box popping up, eg.:
-+
-+ xv -pcd 1 -wloop -wait 10 *.pcd
-+
-+The code is pretty crude and was written quickly for a specific purpose and
-+has not really been cleaned up. It is poorly structured, full of debugging
-+codes and verbose comments, and there is very little attempt at optimizing
-+things. No profiling has been done.
-+
-+There is not yet support for overview files, nor is there a facility to
-+use the higher resolution chroma planes from when viewing lower resolution
-+images.
-+
-+It's only claim to fame is that it works and produces reasonable looking
-+images.
-+
-+The outline of this is shamelessly derived from xvpbm.c to read the
-+file, and xvtiffwr.c to handle the popup window and X stuff (X never
-+has been my forte !), and the PhotoCD format information (though not
-+the code) was found in Hadmut Danisch's (danisch@ira.uka.de) hpcdtoppm
-+program in which he has reverse engineered the format by studying
-+hex dumps of PhotoCDs ! The color stuff and Huffman decding were
-+extensively revised by Matthew Francey.
-+
-+Feel free to send me comments or improvements, or even better, more
-+information about the photo CD format ... hopefully someone who really
-+knows what they are doing will tidy it up or do a neater job.
-+
-+david (dclunie@dclunie.com)
-+
-+---------
-+
-+The trace #define in xvpcd.c is now in the right place, and the ansi
-+prototype for the magnify function has been fixed. Colin made me switch to
-+xvbcopy() which seems like a good idea for System V victims.
-+
-+---------
-+
-+Date: Wed, 22 Dec 1993 16:09:52 --1000
-+From: colinc@fitmail.fit.qut.edu.au (Colin Canfield )
-+
-+I have done some more work using your patch I thought you might be intested in.
-+The major change was adding a size parameter to the LoadPCD; either -1 to mean
-+the popup or else the size you desired. This allows batch mode processing,
-+specifically xv -pcd , and the visual schnauzer can work in
-+quick mode (ie. you don't have to select each image size when it is building
-+the icons)
-+
-+I have added an xbm file for the file type but haven't drawn an icon for it,
-+this is in bitmaps/br_pcd.xbm. I will just send you the new files.
-+
-+---------
-+
-+From: andrew@andrew.triumf.ca (Andrew Daviel)
-+Date: 16 Feb 1995 23:32:21 GMT
-+
-+This is David Clunie's patch for xv-3.00 tuned a bit to work
-+on xv-3.10. The code's all the same except for replacing
-+"trace" with "fprintf" in xvpcd.c and adding an "unsigned" qualifier to
-+keep my compiler (gcc) happy. Oh yes, changed RFT_PCD to 20 as
-+John Bradley has now used 15 through 19.
-+
-+---------
-+
-+From: dclunie@flash.us.com (David A. Clunie)
-+Date: Thu Jun 15 14:43:46 GMT+0300 1995
-+
-+Andrew's patch didn't include Colin's browser changes, so I redid the
-+xv-3.10 update from scratch ... it seems pretty much the same as
-+Andrew's changes. I also edited the Imakefile and Makefiles in order
-+to support the PCD changes, as well as make the install process a
-+little more flexible, with options to strip and set modes and so on.
-+Also made RFT_PCD 25 so as not to conflict with magpic patch from Japan
-+by Ikemoto Masahiro , and used his
-+bitmap icon for pcd files.
-+
-+Now there are two versions of the patch, one which should be applied
-+to the xv-3.10 distribution.
-+
-+The other should be applied to xv-3.10 AFTER Ikemoto Masahiro's
-+Patch.magpic2.PhotoCD.XV319a, in order to add the browser features to
-+the latter, as well as fixing a Makefile typo (was xcpcd.c not xvpcd.c)
-+and including unistd.h for the SEEK_xxx constants in the magicpic
-+stuff.
-+
-+---------
-+
-+Subject: Re: photo-cd patch for xv
-+From: Matthew Francey
-+Date: Mon, 26 Mar 2001 15:37:55 +0000
-+
-+Attached is a revised version of xvpcd.c; the areas that I have
-+re-written or changed are in a different coding style so you can tell
-+what has changed. The GNU 'indent' program can be run against the file
-+to enforce a consistent style ..
-+
-+Here is what I've done though:
-+
-+a) huffman table reader re-written, because it would fail on some
-+ photocd files with "unusual" huffman codes.
-+
-+b) the huffman-coded corrections are now properly applied
-+
-+c) the corrections can sometimes over or underflow; clipping has been
-+ introduced and effectively fixes the problem, but I suspect that
-+ there is something deeper going on.
-+
-+d) the "official" YCC->sRGB transform is done. a "beyond 100% white"
-+ mapping table was snarfed from ImageMagick. an option for using a
-+ flat linear LUT was added -- this can make somewhat over-exposed images
-+ look alot nicer.
-+
-+e) there were strange problems where the code wouldn't be able to find
-+ the huffman tables and data for the 16base image (the bit-buffering
-+ code was starting mid-sector, instead of at a sector boundary). Looking
-+ at a pcd file with a hex editor suggests to me that it is possible to
-+ just skip directly to these huffman tables -- no special "+12" and such
-+ constants necessary. But I haven't tried this yet.
-+
-+The results: I've been able to read about 50 or 60 .pcd files [scattered
-+in age from 6 years old to scans done last week] with this code without
-+incident. Image quality at the high resolution is excellent. Even the
-+trivial amount of LUT control is useful when dealing with over-exposed
-+images.
-+
-+If I get around to it: finer LUT control to take advantage of the
-+slightly extended dynamic range of PhotoCD scans, especially in regards to
-+dark or somewhat underexposed scenes.
-+
-+
-+
-+
-diff -u -r --new-file xv-3.10a.orig/bits/br_bzip2 xv-3.10a/bits/br_bzip2
---- xv-3.10a.orig/bits/br_bzip2 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_bzip2 1998-04-12 21:23:39.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_bzip2_width 48
-+#define br_bzip2_height 48
-+static unsigned char br_bzip2_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x7c, 0xbe, 0x3d, 0x0e, 0x02, 0x20, 0xfc, 0xbe, 0x7d, 0x1f, 0x02,
-+ 0x20, 0xcc, 0xb0, 0x6d, 0x1b, 0x02, 0x20, 0xcc, 0x98, 0x6d, 0x1b, 0x02,
-+ 0x20, 0xfc, 0x98, 0x6d, 0x18, 0x02, 0x20, 0x7c, 0x8c, 0x7d, 0x0c, 0x02,
-+ 0x20, 0xcc, 0x8c, 0x3d, 0x0e, 0x02, 0x20, 0xcc, 0x84, 0x0d, 0x06, 0x02,
-+ 0x20, 0xcc, 0x86, 0x0d, 0x03, 0x02, 0x20, 0xfc, 0xbe, 0x0d, 0x1f, 0x02,
-+ 0x20, 0x7c, 0xbe, 0x0d, 0x1f, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_jp2 xv-3.10a/bits/br_jp2
---- xv-3.10a.orig/bits/br_jp2 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_jp2 2005-05-09 00:00:27.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_jp2_width 48
-+#define br_jp2_height 48
-+static unsigned char br_jp2_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0xfb, 0xf1, 0x01, 0x02,
-+ 0x20, 0x00, 0xfb, 0xfb, 0x03, 0x02, 0x20, 0x00, 0x1b, 0x1b, 0x03, 0x02,
-+ 0x20, 0x00, 0x1b, 0x1b, 0x00, 0x02, 0x20, 0x00, 0x1b, 0x1b, 0x00, 0x02,
-+ 0x20, 0x00, 0x9b, 0x1b, 0x00, 0x02, 0x20, 0x00, 0xfb, 0x19, 0x00, 0x02,
-+ 0x20, 0x00, 0xfb, 0x18, 0x00, 0x02, 0x20, 0x18, 0x1b, 0x18, 0x00, 0x02,
-+ 0x20, 0x18, 0x1b, 0x18, 0x00, 0x02, 0x20, 0xb8, 0x1b, 0x18, 0x03, 0x02,
-+ 0x20, 0xf0, 0x19, 0xf8, 0x03, 0x02, 0x20, 0xe0, 0x18, 0xf0, 0x01, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_jpc xv-3.10a/bits/br_jpc
---- xv-3.10a.orig/bits/br_jpc 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_jpc 2005-05-09 00:00:27.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_jpc_width 48
-+#define br_jpc_height 48
-+static unsigned char br_jpc_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0xfb, 0xf1, 0x01, 0x02,
-+ 0x20, 0x00, 0xfb, 0xfb, 0x03, 0x02, 0x20, 0x00, 0x1b, 0x1b, 0x03, 0x02,
-+ 0x20, 0x00, 0x1b, 0x03, 0x03, 0x02, 0x20, 0x00, 0x1b, 0x03, 0x03, 0x02,
-+ 0x20, 0x00, 0x9b, 0x83, 0x01, 0x02, 0x20, 0x00, 0xfb, 0xc1, 0x01, 0x02,
-+ 0x20, 0x00, 0xfb, 0xe0, 0x00, 0x02, 0x20, 0x18, 0x1b, 0x70, 0x00, 0x02,
-+ 0x20, 0x18, 0x1b, 0x38, 0x00, 0x02, 0x20, 0xb8, 0x1b, 0x18, 0x00, 0x02,
-+ 0x20, 0xf0, 0x19, 0xf8, 0x03, 0x02, 0x20, 0xe0, 0x18, 0xf8, 0x03, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_mag xv-3.10a/bits/br_mag
---- xv-3.10a.orig/bits/br_mag 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_mag 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_mag_width 48
-+#define br_mag_height 48
-+static unsigned char br_mag_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x0c, 0x86, 0xc1, 0x0f, 0x02,
-+ 0x20, 0x0c, 0xc6, 0xe3, 0x1f, 0x02, 0x20, 0x1c, 0xe7, 0x67, 0x18, 0x02,
-+ 0x20, 0x1c, 0x77, 0x6e, 0x18, 0x02, 0x20, 0xbc, 0x37, 0x6c, 0x00, 0x02,
-+ 0x20, 0xbc, 0x37, 0x6c, 0x00, 0x02, 0x20, 0xec, 0x36, 0x6c, 0x1e, 0x02,
-+ 0x20, 0xec, 0xf6, 0x6f, 0x1e, 0x02, 0x20, 0x4c, 0xf6, 0x6f, 0x18, 0x02,
-+ 0x20, 0x4c, 0x36, 0x6c, 0x18, 0x02, 0x20, 0x0c, 0x36, 0x6c, 0x18, 0x02,
-+ 0x20, 0x0c, 0x36, 0xec, 0x1f, 0x02, 0x20, 0x0c, 0x36, 0xcc, 0x0f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_maki xv-3.10a/bits/br_maki
---- xv-3.10a.orig/bits/br_maki 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_maki 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_maki_width 48
-+#define br_maki_height 48
-+static unsigned char br_maki_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x83, 0x61, 0x18, 0x33, 0x02,
-+ 0x20, 0x83, 0xf1, 0x98, 0x33, 0x02, 0x20, 0xc7, 0xf9, 0x99, 0x31, 0x02,
-+ 0x20, 0xc7, 0x9d, 0xdb, 0x30, 0x02, 0x20, 0xef, 0x0d, 0xfb, 0x30, 0x02,
-+ 0x20, 0xef, 0x0d, 0x7b, 0x30, 0x02, 0x20, 0xbb, 0x0d, 0x7b, 0x30, 0x02,
-+ 0x20, 0xbb, 0xfd, 0xdb, 0x30, 0x02, 0x20, 0x93, 0xfd, 0xdb, 0x30, 0x02,
-+ 0x20, 0x93, 0x0d, 0x9b, 0x31, 0x02, 0x20, 0x83, 0x0d, 0x9b, 0x31, 0x02,
-+ 0x20, 0x83, 0x0d, 0x1b, 0x33, 0x02, 0x20, 0x83, 0x0d, 0x1b, 0x33, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_mgcsfx xv-3.10a/bits/br_mgcsfx
---- xv-3.10a.orig/bits/br_mgcsfx 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_mgcsfx 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_mgcsfx_width 48
-+#define br_mgcsfx_height 48
-+static unsigned char br_mgcsfx_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x3c, 0xcf, 0x71, 0x00, 0x02,
-+ 0x20, 0x6c, 0x61, 0xda, 0x00, 0x02, 0x20, 0x6c, 0x67, 0xd8, 0x1e, 0x02,
-+ 0x20, 0x3c, 0x61, 0xd8, 0x1e, 0x02, 0x20, 0x6c, 0x61, 0xda, 0x00, 0x02,
-+ 0x20, 0x6c, 0xcf, 0x71, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x4e, 0x7a, 0xef, 0x3d, 0x02, 0x20, 0xd3, 0x32, 0x68, 0x6c, 0x02,
-+ 0x20, 0xc3, 0x32, 0xe4, 0x6c, 0x02, 0x20, 0x5b, 0x33, 0x62, 0x6c, 0x02,
-+ 0x20, 0x53, 0x33, 0x61, 0x6c, 0x02, 0x20, 0x4e, 0x7a, 0xef, 0x3d, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_pcd xv-3.10a/bits/br_pcd
---- xv-3.10a.orig/bits/br_pcd 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_pcd 1995-06-15 23:31:53.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_pcd_width 48
-+#define br_pcd_height 48
-+static unsigned char br_pcd_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x67, 0x00, 0xe0, 0x1c, 0x02,
-+ 0x20, 0x6f, 0x00, 0xf0, 0x3d, 0x02, 0x20, 0x6b, 0x00, 0xb0, 0x2d, 0x02,
-+ 0x20, 0x6b, 0x00, 0x33, 0x2c, 0x02, 0x20, 0x6b, 0x00, 0x33, 0x2c, 0x02,
-+ 0x20, 0xeb, 0x98, 0x37, 0x2c, 0x02, 0x20, 0xef, 0xbd, 0x37, 0x2c, 0x02,
-+ 0x20, 0x67, 0x2d, 0x33, 0x2c, 0x02, 0x20, 0x63, 0x2d, 0x33, 0x2c, 0x02,
-+ 0x20, 0x63, 0x2d, 0x33, 0x2c, 0x02, 0x20, 0x63, 0x2d, 0xb3, 0x2d, 0x02,
-+ 0x20, 0x63, 0x3d, 0xf7, 0x3d, 0x02, 0x20, 0x63, 0x19, 0xe6, 0x1c, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_pi xv-3.10a/bits/br_pi
---- xv-3.10a.orig/bits/br_pi 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_pi 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_pi_width 48
-+#define br_pi_height 48
-+static unsigned char br_pi_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x80, 0x1f, 0x7e, 0x00, 0x02,
-+ 0x20, 0x80, 0x3f, 0x7e, 0x00, 0x02, 0x20, 0x80, 0x31, 0x18, 0x00, 0x02,
-+ 0x20, 0x80, 0x31, 0x18, 0x00, 0x02, 0x20, 0x80, 0x31, 0x18, 0x00, 0x02,
-+ 0x20, 0x80, 0x39, 0x18, 0x00, 0x02, 0x20, 0x80, 0x1f, 0x18, 0x00, 0x02,
-+ 0x20, 0x80, 0x0f, 0x18, 0x00, 0x02, 0x20, 0x80, 0x01, 0x18, 0x00, 0x02,
-+ 0x20, 0x80, 0x01, 0x18, 0x00, 0x02, 0x20, 0x80, 0x01, 0x18, 0x00, 0x02,
-+ 0x20, 0x80, 0x01, 0x7e, 0x00, 0x02, 0x20, 0x80, 0x01, 0x7e, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_pic xv-3.10a/bits/br_pic
---- xv-3.10a.orig/bits/br_pic 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_pic 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_pic_width 48
-+#define br_pic_height 48
-+static unsigned char br_pic_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xf0, 0xf3, 0xf3, 0x01, 0x02,
-+ 0x20, 0xf0, 0xf7, 0xfb, 0x03, 0x02, 0x20, 0x30, 0xc6, 0x18, 0x03, 0x02,
-+ 0x20, 0x30, 0xc6, 0x18, 0x00, 0x02, 0x20, 0x30, 0xc6, 0x18, 0x00, 0x02,
-+ 0x20, 0x30, 0xc7, 0x18, 0x00, 0x02, 0x20, 0xf0, 0xc3, 0x18, 0x00, 0x02,
-+ 0x20, 0xf0, 0xc1, 0x18, 0x00, 0x02, 0x20, 0x30, 0xc0, 0x18, 0x00, 0x02,
-+ 0x20, 0x30, 0xc0, 0x18, 0x00, 0x02, 0x20, 0x30, 0xc0, 0x18, 0x03, 0x02,
-+ 0x20, 0x30, 0xf0, 0xfb, 0x03, 0x02, 0x20, 0x30, 0xf0, 0xf3, 0x01, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_pic2 xv-3.10a/bits/br_pic2
---- xv-3.10a.orig/bits/br_pic2 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_pic2 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,27 @@
-+#define br_pic2_width 48
-+#define br_pic2_height 48
-+static unsigned char br_pic2_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x3f, 0x3f, 0x1f, 0x1f, 0x02,
-+ 0x20, 0x7f, 0xbf, 0xbf, 0x3f, 0x02, 0x20, 0x63, 0x8c, 0xb1, 0x31, 0x02,
-+ 0x20, 0x63, 0x8c, 0x01, 0x30, 0x02, 0x20, 0x63, 0x8c, 0x01, 0x30, 0x02,
-+ 0x20, 0x73, 0x8c, 0x01, 0x30, 0x02, 0x20, 0x3f, 0x8c, 0x01, 0x18, 0x02,
-+ 0x20, 0x1f, 0x8c, 0x01, 0x0c, 0x02, 0x20, 0x03, 0x8c, 0x01, 0x06, 0x02,
-+ 0x20, 0x03, 0x8c, 0x01, 0x03, 0x02, 0x20, 0x03, 0x8c, 0xb1, 0x01, 0x02,
-+ 0x20, 0x03, 0xbf, 0xbf, 0x3f, 0x02, 0x20, 0x03, 0x3f, 0x9f, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03};
-diff -u -r --new-file xv-3.10a.orig/bits/br_png xv-3.10a/bits/br_png
---- xv-3.10a.orig/bits/br_png 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_png 1996-06-13 16:32:08.000000000 -0500
-@@ -0,0 +1,28 @@
-+#define br_png_width 48
-+#define br_png_height 48
-+static unsigned char br_png_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0xf8, 0x19, 0xc3, 0x07, 0x02, 0x20, 0x18, 0x3b, 0x63, 0x0c, 0x02,
-+ 0x20, 0x18, 0x3b, 0x33, 0x00, 0x02, 0x20, 0x18, 0x5b, 0x33, 0x00, 0x02,
-+ 0x20, 0xf8, 0x59, 0x33, 0x0f, 0x02, 0x20, 0x18, 0x98, 0x33, 0x0c, 0x02,
-+ 0x20, 0x18, 0x98, 0x33, 0x0c, 0x02, 0x20, 0x18, 0x18, 0x63, 0x0c, 0x02,
-+ 0x20, 0x18, 0x18, 0xc3, 0x0b, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03,
-+ };
-diff -u -r --new-file xv-3.10a.orig/bits/br_zx xv-3.10a/bits/br_zx
---- xv-3.10a.orig/bits/br_zx 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/bits/br_zx 1998-08-06 15:00:03.000000000 -0500
-@@ -0,0 +1,28 @@
-+#define br_zx_width 48
-+#define br_zx_height 48
-+static unsigned char br_zx_bits[] = {
-+ 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x09, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x11, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x81, 0x00,
-+ 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x20, 0x00, 0x00, 0x00, 0xff, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0xff, 0xff, 0xff, 0x7f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x7f, 0xce, 0x01, 0x0e, 0x02, 0x20, 0x61, 0x84, 0x00, 0x11, 0x02,
-+ 0x20, 0x30, 0x48, 0x00, 0x10, 0x02, 0x20, 0x18, 0x38, 0x10, 0x08, 0x02,
-+ 0x20, 0x0c, 0x30, 0x10, 0x0e, 0x02, 0x20, 0x06, 0x68, 0x7c, 0x10, 0x02,
-+ 0x20, 0x03, 0x48, 0x10, 0x10, 0x02, 0x20, 0x41, 0x84, 0x10, 0x11, 0x02,
-+ 0x20, 0x7f, 0xce, 0x01, 0x0e, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0xff, 0xff, 0xff, 0xff, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x40, 0x02, 0x20, 0xff, 0xff, 0xff, 0x3f, 0x02,
-+ 0x20, 0x00, 0x00, 0x00, 0x10, 0x02, 0x20, 0x00, 0x00, 0x00, 0x08, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0x84, 0x03, 0x20, 0x00, 0x00, 0x00, 0xc2, 0x03,
-+ 0x20, 0x00, 0x00, 0x00, 0xe1, 0x03, 0x20, 0x00, 0x00, 0x80, 0xf0, 0x02,
-+ 0x20, 0x00, 0x00, 0x40, 0x78, 0x02, 0x20, 0x00, 0x00, 0x20, 0x3c, 0x02,
-+ 0x20, 0x00, 0x00, 0x10, 0x1e, 0x02, 0x20, 0x00, 0x00, 0x08, 0x0f, 0x03,
-+ 0x20, 0x00, 0x00, 0x84, 0x87, 0x03, 0x20, 0x00, 0x00, 0xc2, 0xc3, 0x03,
-+ 0x20, 0x00, 0x00, 0xe1, 0xe1, 0x03, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x03,
-+ };
-diff -u -r --new-file xv-3.10a.orig/contrib/fedora/Build-FC5 xv-3.10a/contrib/fedora/Build-FC5
---- xv-3.10a.orig/contrib/fedora/Build-FC5 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fedora/Build-FC5 2006-06-01 10:12:47.000000000 -0500
-@@ -0,0 +1,56 @@
-+#!/bin/bash
-+#
-+# prep and build XV for FC5
-+#
-+# adapted from Slackware 10.2 -- john.cooper@third-harmonic.com
-+#
-+
-+if [ ${1}foo == "__LOGGED__foo" ]; then
-+ shift
-+else
-+ for i in `seq 0 9`
-+ do
-+ if [ -e ${0}.log.$((9-i)) ]; then
-+ mv ${0}.log.$((9-i)) ${0}.log.$((9-i+1))
-+ fi
-+ done
-+
-+ exec $0 __LOGGED__ $@ 2>&1 | tee $BUILDDIR/$0.log.0
-+ exit $?
-+fi
-+
-+SOURCE=`pwd`
-+if [ "$BUILD" = "" ]; then
-+ BUILD=./build
-+fi
-+
-+if [ ! -d $BUILD ]; then
-+ mkdir -p $BUILD
-+fi
-+
-+PFLAGS="--verbose --backup --suffix=.orig"
-+
-+function bail()
-+ {
-+ echo "$0: failed $1"
-+ exit 1
-+ }
-+
-+cd $BUILD
-+rm -rf xv-3.10
-+tar xzvf $SOURCE/xv-3.10.tar.gz
-+cd xv-3.10
-+zcat $SOURCE/xv-3.10a.patch.gz | patch -p0 $PFLAGS || \
-+ bail $SOURCE/xv-3.10a.patch.gz
-+bzcat $SOURCE/xv-3.10a-jumbo-fix-patch-20050410.txt.bz2 | patch -p1 $PFLAGS || \
-+ bail $SOURCE/xv-3.10a-jumbo-fix-patch-20050410.txt.bz2
-+bzcat $SOURCE/xv-3.10a-jumbo-enh-patch-20050501.txt.bz2 | patch -p1 $PFLAGS || \
-+ bail $SOURCE/xv-3.10a-jumbo-enh-patch-20050501.txt.bz2
-+zcat $SOURCE/xv.prefix.diff.gz | patch -p1 $PFLAGS || \
-+ bail $SOURCE/xv.prefix.diff.gz
-+make -f Makefile.std || bail make
-+strip --strip-unneeded bggen vdcomp xcmap xv xvpictoppm || bail strip
-+
-+exit $?
-+
-+# vi:set ts=4:
-diff -u -r --new-file xv-3.10a.orig/contrib/fedora/README xv-3.10a/contrib/fedora/README
---- xv-3.10a.orig/contrib/fedora/README 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fedora/README 2006-06-01 10:12:47.000000000 -0500
-@@ -0,0 +1,16 @@
-+Greg,
-+ After winding up in dark lonely places trying to
-+get xv-3.10a to build on FC5 I suspected I was missing
-+something. Then I happened on your patch manifest
-+in Slackware 10.2.
-+
-+I bandsawed the script a bit to use in propagating XV
-+to a handful of personal FC5 machines. Attached for
-+reference.
-+
-+Thanks for your effort!
-+
-+-john
-+
-+--
-+john.cooper@third-harmonic.com
-diff -u -r --new-file xv-3.10a.orig/contrib/fnkey-scripts/README xv-3.10a/contrib/fnkey-scripts/README
---- xv-3.10a.orig/contrib/fnkey-scripts/README 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fnkey-scripts/README 2007-01-16 02:41:51.000000000 -0600
-@@ -0,0 +1,111 @@
-+-- License and Disclaimer --
-+
-+This patch & script package was written by Alexey Spiridonov, and is
-+licensed under the GNU GPLv2. There is NO WARRANTY.
-+
-+XV is copyrighted by John Bradley.
-+
-+-- What is this? --
-+
-+This is a small patch for XV that allows you to run scripts by pressing
-+a key from F1 through F12 (or more, just change 12 to your number in the
-+patch file).
-+
-+The patch enables a number of useful features. Here is a my set-up:
-+
-+F1: Losslessly rotate JPEG 90 degrees to the right.
-+F2: Losslessly rotate JPEG 90 degrees to the left.
-+
-+F3: Print the current selection rectangle (on the terminal where xv was
-+ launched). This is useful for quickly recording a bunch of positions in
-+ an image. Use case:
-+ I'm annotating face positions.
-+ 1) Select Joe in picture, hit F3, type "Joe" in the terminal.
-+ 2) Select Jane in the picture, ...
-+ ...
-+ n) Copy the text visible in the terminal, and paste it into the
-+ JPEG comment.
-+ Of course, i would write a more convenient script if I annotated faces
-+ with any any frequency.
-+
-+F4: Edit JPEG comment (I use it for annotations/tags).
-+
-+F5: Log a 'losslessly rotate right' command for batch processing. This
-+ writes the rotation command for the current file into a shell script
-+ somewhere ("~/photos/bin/rotscript" by default). This is great for
-+ slower computers because you don't have to wait for each image to
-+ rotate; instead, you just rotate them all at once by running the
-+ resulting script.
-+F6: Log a 'losslessly rotate left' batch command.
-+
-+F8: Crop image on disk, but back-up the uncropped version. You can make
-+ a succession of crops this way, with a backup made at every step.
-+ This wastes disk space, so be sure to clean up once you get a crop you
-+ like.
-+F7: Undo the last crop done on this image. This can be repeated until you're
-+ back at the original.
-+
-+-- Installation --
-+
-+I'll tell you how to get the set-up I described above. Of course, you can
-+customize it to your heart's content.
-+
-+(( 1 ))
-+
-+Go to:
-+
-+ http://www.sonic.net/~roelofs/greg_xv.html
-+
-+and follow the XV install instructions there. If you are okay with
-+reading shell scripts, you might also give this a shot:
-+
-+ http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/media-gfx/xv/xv-3.10a-r12.ebuild
-+
-+When you're ready to type "make install", do the following to apply my patch:
-+
-+ $ cd WHEREVER_YOU_COMPILED_XV
-+ $ patch -p1 --dry-run < PATH/TO/xv-3.10a-fkey-command-patch.greg-xv
-+
-+Hopefully, the above command won't complain; if it does, Greg Roelofs
-+probably changed his patchset, and my patch has become out of date -- let me
-+know. If that went well, run:
-+
-+ $ patch -p1 < PATH/TO/xv-3.10a-fkey-command-patch.greg-xv
-+
-+Now, simply recompile and install as described in the other instructions.
-+
-+(( 2 ))
-+
-+Copy 'jpegcrop.sh', 'jpegeditcom.sh', 'jpegundocrop.sh', 'jpegrot.sh',
-+'jpeglogrot.sh' to some convenient directory.
-+
-+Suggestions: ~/photos/bin, /usr/local/bin, etc...
-+
-+Edit 'jpeglogrot.sh' and 'jpegeditcom.sh'. In the former, you need to
-+customize the path to 'jpegrot.sh'. In the latter, you should make set
-+your favorite editor. The spots to customize are marked as such.
-+
-+(( 3 ))
-+
-+Open .Xdefaults in your favorite text editor, and paste the following lines
-+there:
-+
-+xv.F1command: ~/photos/bin/jpegrot.sh 90 %s
-+xv.F2command: ~/photos/bin/jpegrot.sh 270 %s
-+xv.F3command: @echo "The selection rect for '%s' is at (%d, %d) of size %dx%d."
-+xv.F4command: @~/photos/bin/jpegeditcom.sh %s &
-+xv.F5command: @~/photos/bin/jpeglogrot.sh 90 %s
-+xv.F6command: @~/photos/bin/jpeglogrot.sh 270 %s
-+xv.F7command: ~/photos/bin/jpegundocrop.sh %s
-+xv.F8command: ~/photos/bin/jpegcrop.sh %s %d %d %d %d
-+
-+Change '~/photos/bin/' to the directory you chose in (( 2 )). In case you're
-+wondering what the '@' symbol means, it tells XV not to reload the file
-+after running this command. The default is to reload the file.
-+
-+-- Apologies --
-+
-+I didn't get a chance to run through the above instructions and check
-+that they work. I know they're right in spirit, but I might've made a typo
-+or two. Even if it's obvious to you, would you please let me know by writing
-+to lesha at mit dot edu?
-diff -u -r --new-file xv-3.10a.orig/contrib/fnkey-scripts/jpegcrop.sh xv-3.10a/contrib/fnkey-scripts/jpegcrop.sh
---- xv-3.10a.orig/contrib/fnkey-scripts/jpegcrop.sh 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fnkey-scripts/jpegcrop.sh 2006-03-11 21:30:03.000000000 -0600
-@@ -0,0 +1,33 @@
-+#!/bin/bash
-+FILE=$1
-+WIDTH=$4
-+HEIGHT=$5
-+XPOS=$2
-+YPOS=$3
-+if [[ $XPOS -lt 0 ]]; then
-+ echo "Negative x position $XPOS converted to zero, width adjusted."
-+ WIDTH=$((WIDTH+XPOS))
-+ XPOS=0
-+fi
-+if [[ $YPOS -lt 0 ]]; then
-+ echo "Negative y position $YPOS converted to zero, height adjusted."
-+ HEIGHT=$((HEIGHT+YPOS))
-+ YPOS=0
-+fi
-+if [[ $(($WIDTH+$HEIGHT)) == 0 ]]; then
-+ echo "Refusing to crop $FILE with an empty rectangle."
-+ exit 1
-+fi
-+
-+TMPFILE=`mktemp $FILE.tmp-jpeg-rot-XXXXXXXX`
-+if jpegtran -optimize -progressive -crop ${WIDTH}x${HEIGHT}+${XPOS}+${YPOS} \
-+ -copy all $FILE > $TMPFILE; then
-+ COUNT=`echo $FILE-uncropped | wc -c`
-+ NEXT=$((`ls $FILE-uncropped* | cut -b $COUNT- | grep '^[0-9]*$' \
-+ | sed 's/^0*/'/ | sort -n | tail -n 1`+1))
-+ # the targets shouldn't exist, but -i just in case
-+ mv -i $FILE $FILE-uncropped$NEXT
-+ mv -i $TMPFILE $FILE
-+else
-+ rm $TMPFILE
-+fi
-diff -u -r --new-file xv-3.10a.orig/contrib/fnkey-scripts/jpegeditcom.sh xv-3.10a/contrib/fnkey-scripts/jpegeditcom.sh
---- xv-3.10a.orig/contrib/fnkey-scripts/jpegeditcom.sh 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fnkey-scripts/jpegeditcom.sh 2007-01-16 00:23:04.000000000 -0600
-@@ -0,0 +1,12 @@
-+#!/bin/bash
-+CFILE=`mktemp $1.tmp-jpeg-comments-XXXXXXXX`
-+TMPFILE=`mktemp $1.tmp-jpeg-XXXXXXXX`
-+rdjpgcom $1 > $CFILE
-+INITIAL=`md5sum $CFILE`
-+xterm -e "$EDITOR" "$CFILE" # customize your editor here
-+MODIFIED=`md5sum $CFILE`
-+if [[ "$INITIAL" != "$MODIFIED" ]]; then
-+ mv $1 $TMPFILE
-+ wrjpgcom -replace -cfile $CFILE $TMPFILE > $1
-+fi
-+rm $TMPFILE $CFILE $CFILE~
-diff -u -r --new-file xv-3.10a.orig/contrib/fnkey-scripts/jpeglogrot.sh xv-3.10a/contrib/fnkey-scripts/jpeglogrot.sh
---- xv-3.10a.orig/contrib/fnkey-scripts/jpeglogrot.sh 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fnkey-scripts/jpeglogrot.sh 2007-01-16 00:55:18.000000000 -0600
-@@ -0,0 +1,10 @@
-+#!/bin/bash
-+curdir="`pwd`"
-+LOG=~/photos/bin/rotscript # customize your install dir here
-+if [[ ! -e "$LOG" ]]; then
-+ echo '#!/bin/bash' >> "$LOG"
-+ chmod u+x "$LOG"
-+fi
-+echo "# following entry made on `date`" >> "$LOG"
-+# also customize the following line
-+echo ~/photos/bin/jpegrot \""$1"\" \""$curdir/$2"\" >> "$LOG"
-diff -u -r --new-file xv-3.10a.orig/contrib/fnkey-scripts/jpegrot.sh xv-3.10a/contrib/fnkey-scripts/jpegrot.sh
---- xv-3.10a.orig/contrib/fnkey-scripts/jpegrot.sh 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fnkey-scripts/jpegrot.sh 2006-07-18 23:10:43.000000000 -0500
-@@ -0,0 +1,7 @@
-+#!/bin/bash
-+TMPFILE="`mktemp "$2".tmp-jpeg-rot-XXXXXXXX`"
-+if jpegtran -perfect -optimize -progressive -rotate "$1" -copy all "$2" > "$TMPFILE"; then
-+ mv "$TMPFILE" "$2"
-+else
-+ rm "$TMPFILE"
-+fi
-diff -u -r --new-file xv-3.10a.orig/contrib/fnkey-scripts/jpegundocrop.sh xv-3.10a/contrib/fnkey-scripts/jpegundocrop.sh
---- xv-3.10a.orig/contrib/fnkey-scripts/jpegundocrop.sh 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/contrib/fnkey-scripts/jpegundocrop.sh 2006-03-11 21:30:04.000000000 -0600
-@@ -0,0 +1,8 @@
-+#!/bin/bash
-+FILE=$1
-+COUNT=`echo $FILE-uncropped | wc -c`
-+LATEST=$((`ls $FILE-uncropped* | cut -b $COUNT- | grep '^[0-9]*$' \
-+ | sed 's/^0*/'/ | sort -n | tail -n 1`))
-+if [[ -f $FILE-uncropped$LATEST ]]; then
-+ mv $FILE-uncropped$LATEST $FILE
-+fi
-diff -u -r --new-file xv-3.10a.orig/tiff/RANLIB.sh xv-3.10a/tiff/RANLIB.sh
---- xv-3.10a.orig/tiff/RANLIB.sh 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/tiff/RANLIB.sh 2004-05-11 01:31:38.000000000 -0500
-@@ -0,0 +1,22 @@
-+#!/bin/sh -f
-+#
-+# tests to see if the program 'ranlib' exists. If it does, runs ranlib on
-+# the first argument (a library name). Otherwise, does nothing, and returns
-+#
-+# written by John Bradley for the XV 3.00 release
-+# thanks to John Hagan for shell-script hackery
-+#
-+
-+echo "executing 'ranlib $1'..."
-+
-+# Is there a ranlib? Let's try and then suffer the consequences...
-+ranlib $1 >& /dev/null
-+
-+if [ $? -ne 0 ]; then
-+ echo "There doesn't seem to be a ranlib on this system..."
-+ echo "Don't worry about it."
-+fi
-+
-+echo ""
-+echo ""
-+
-diff -u -r --new-file xv-3.10a.orig/xv_mgcsfx.sample xv-3.10a/xv_mgcsfx.sample
---- xv-3.10a.orig/xv_mgcsfx.sample 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xv_mgcsfx.sample 2005-04-17 16:04:22.000000000 -0500
-@@ -0,0 +1,125 @@
-+#/*
-+# Configuration file for XV with recognition of 'Magic and Suffix'
-+#
-+#
-+# $Id: xv_mgcsfx.sample,v 1.11 95/10/03 17:00:05 tin329 Exp Locker: tin329 $
-+#
-+# Author: Tetsuya INOUE
-+#
-+#
-+# MgcSfx definition should write in one line.
-+# Format:
-+# ::::::::
-+# If you decide to not use preprocessor, comment style is allowed.
-+# #
-+#
-+# Description of your recognized image format.
-+# Type ID for recognition. (You should use 'magic'.)
-+# * magic Data of string style.
-+# `\' escape for special characters:
-+# \b \f \n \r \t \v \\ \' \" \a \?
-+# \0 ...\377 octal value
-+# \x0 ...\xff hexadecimal value
-+# * suffix Suffix of file name.
-+# This type check instead
-+# of .
-+# * [b|l]eint16 2 byte integer of [big|little] endian.
-+# * [b|l]eint32 4 byte integer of [big|little] endian.
-+# Offset of magic number in the target image file.
-+# Data(magic number) of to match at .
-+# Suffix of filename with '.'start.
-+#
-+# Input image format type (output from ).
-+# * PNM (PPM, PGM, PBM)
-+# * AUTO Recognized by xv management, and load.
-+# This is different from others, because
-+# this write file to temporary.
-+# Output image format type (input to ).
-+# * PNM_RAW (PPM_RAW, PGM_RAW, PBM_RAW)
-+# * PNM_ASCII (PPM_ASCII, PGM_ASCII, PBM_ASCII)
-+#
-+# Command to get the input image.
-+# * Command mast read stdin or file(specified by
-+# argument), and write to stdout.
-+# * Use %s to represent the file name. Without %s,
-+# get file on stdin.
-+# Command to put the output image.
-+# * Command mast read stdin and write to stdout.
-+#
-+# Any message.
-+#*/
-+
-+#/*############################################################################
-+#
-+# definition of the rule with Magic and Suffix
-+#
-+#*/
-+
-+# /* Canon View Station Image Format */
-+ViewStation(std):magic:0:VsStdImf V0.2:.vs:PNM:VStopnm %s:PNM_RAW:pnmtoVS
-+ViewStation(obj):magic:0:VsObjFormat V1.0:.vs:PNM:VSobjtopnm -:PNM_RAW:pnmtoVSobj
-+
-+# /* CERN httpd cache */
-+# /* unchc skip header of CERN httpd cache file, and write data to stdout. */
-+CERN httpd cache:magic:0:HTTP/1.0::AUTO:unchc %s::
-+
-+# /* XLD4(Q4) image format */
-+XLD(Q4):magic:11:MAJYO:.q4:PNM:q4toppm::
-+
-+# /* ML1 image format */
-+ML1:magic:0:\1\0\0\x1a:.ml1:PNM:ml1toppm %s::
-+
-+# /* Pict image format, 256 color only */
-+PICT:suffix:::.pict:PNM:picttoppm:PNM_RAW:ppmquant 256 | ppmtopict
-+PICT(gzip):suffix:::.pict.gz:PNM:gzip -dc | picttoppm:PNM_RAW:ppmquant 256 | ppmtopict | gzip
-+PICT(compress):suffix:::.pict.Z:PNM:compress -dc | picttoppm:PNM_RAW:ppmquant 256 | ppmtopict | compress
-+
-+# /* Tim image format(used by SONY PlayStation) */
-+TIM:magic:0:\x10\x00\x00\x00:.tim:PNM:timtoppm::
-+
-+# /* Cam image format(used by CASIO QV-10) */
-+# /* CAM:magic:0:\x07\x20\x4d\x4d:.cam:AUTO:camtoppm -j:PNM_RAW */
-+CAM:magic:0:\x07\x20\x4d\x4d:.cam:PNM:camtoppm::
-+
-+# /* Portable Network Graphics (PNG) format : magic is "0x89 PNG" */
-+PNG:magic:0:\x89\x50\x4e\x47:.png:PNM:pngtopnm %s:PNM_RAW:pnmtopng
-+# /* PNG(interlace):magic:0:\x89\x50\x4e\x47:.png:PNM:pngtopnm %s:PNM_RAW:pnmtopng -interlace */
-+
-+# /* DB-Z, SAURUS Freehand Memo, PV-F1 Action Board, Wiz Quick Memo format */
-+# /* Use xbm2free-1.10 or later. Old version is NOT a filter. */
-+# /* To show version of xbm2free, type "xbm2free" (with no argument). */
-+ZAURUS:magic:19:IMG1:.zau:PBM_ASCII:free2pbm:PBM:pbmtoxbm|xbm2free -s -
-+DBZ:magic:19:IMG1:.dbz:::PBM:pbmtoxbm|xbm2free -d -
-+PVF1:magic:12:IMG1:.pvf1:PBM_ASCII:free2pbm:PBM:pbmtoxbm|xbm2free -v -
-+# /* WIZ:magic:19:IMG1:.wiz:::PBM:pbmtoxbm|xbm2free -w - */
-+
-+
-+
-+# /* Compress:magic:0:\037\235:.Z:AUTO:uncompress %s:: */
-+# /* Gzip:magic:0:\037\213:.gz:AUTO:gunzip %s:: */
-+# /* Gzip(old):magic:0:\037\236:.z:AUTO:gunzip %s:: */
-+
-+# /* MAKI:magic:0:MAKI01A\040:.mki:::: */
-+# /* MAKI:magic:0:MAKI01B\040:.mki:::: */
-+# /* MAG:magic:0:MAKI02\040\040:.mag:::: */
-+# /* Pi:magic:0:Pi:.pi:::: */
-+# /* PIC:magic:0:PIC:.pic:::: */
-+# /* PIC2:magic:0:P2DT:.p2:::: */
-+# /* PhotoCD:magic:0:\xff\xff\xff\xff:.pcd:::: */
-+
-+# /* PBM(ascii):magic:0:P1:.pbm:::: */
-+# /* PGM(ascii):magic:0:P2:.pgm:::: */
-+# /* PPM(ascii):magic:0:P3:.ppm:::: */
-+# /* PBM(raw):magic:0:P4:.pbm:::: */
-+# /* PGM(raw):magic:0:P5:.pgm:::: */
-+# /* PPM(raw):magic:0:P6:.ppm:::: */
-+
-+# /* Sun raster:magic:0:\131\246\152\225:.sun:::: */
-+# /* JFIF(JPEG):magic:0:\xff\xd8\xff:.jpg:::: */
-+# /* TIFF big-endian:magic:0:\115\115:.tif:::: */
-+# /* TIFF little-endian:magic:0:\111\111:.tif:::: */
-+# /* GIF(87):magic:0:GIF87a:.gif:::: */
-+# /* GIF(89):magic:0:GIF89a:.gif:::: */
-+# /* SGI(1):magic:0:\x01\xda:.rgb:::: */
-+# /* SGI(2):magic:0:\xda\x01:.rgb:::: */
-+# /* XWD:magic:0:\0\0\0\7: :::: */
-diff -u -r --new-file xv-3.10a.orig/xvhips.c xv-3.10a/xvhips.c
---- xv-3.10a.orig/xvhips.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvhips.c 2005-05-01 01:49:14.000000000 -0500
-@@ -0,0 +1,406 @@
-+/*
-+ * xvhips.c - load routine for 'HIPS' format pictures
-+ *
-+ * LoadHIPS(fname, numcols)
-+ */
-+
-+/*
-+ * Copyright 1989, 1990 by the University of Pennsylvania
-+ *
-+ * Permission to use, copy, and distribute for non-commercial purposes,
-+ * is hereby granted without fee, providing that the above copyright
-+ * notice appear in all copies and that both the copyright notice and this
-+ * permission notice appear in supporting documentation.
-+ *
-+ * The software may be modified for your own purposes, but modified versions
-+ * may not be distributed.
-+ *
-+ * This software is provided "as is" without any express or implied warranty.
-+ */
-+
-+#include "xv.h"
-+
-+#ifdef HAVE_HIPS
-+
-+#define Boolean FREDDIE
-+#include "xvhips.h"
-+#undef Boolean
-+
-+#include
-+
-+#define LINES 100
-+#define LINELENGTH 132
-+
-+static int fread_header(int fd, struct header *hd);
-+static char *getline(int fd, char **s, int *l);
-+static int dfscanf(int fd);
-+static void make_grayscale(char *r, char *g, char *b);
-+static float hls_value (float n1, float n2, float hue);
-+static void hls_to_rgb(float h, float l, float s,
-+ float *r, float *g, float *b);
-+static void make_huescale(char *r, char *g, char *b);
-+static void make_heatscale(char *r, char *g, char *b);
-+static int load_colourmap(char *filestem, int max_colours,
-+ char *r, char *g, char *b);
-+
-+/************************************************************************
-+ *
-+ * Read Header routines
-+ *
-+ ************************************************************************/
-+
-+static char *ssave[LINES];
-+static int slmax[LINES];
-+static int lalloc = 0;
-+//extern char *calloc();
-+
-+
-+
-+static int fread_header(fd, hd)
-+ int fd;
-+ struct header *hd;
-+{
-+ int lineno, len, i;
-+ char *s;
-+
-+/*fprintf(stderr,"fread_header: entered\n");*/
-+ if(lalloc<1) {
-+ ssave[0] = calloc(LINELENGTH, sizeof (char));
-+ slmax[0] = LINELENGTH;
-+ lalloc = 1;
-+ }
-+/*fprintf(stderr,"fread_header: ssave allocated\n");*/
-+ getline(fd,&ssave[0],&slmax[0]);
-+ hd->orig_name = calloc(strlen(ssave[0])+1, sizeof (char));
-+ strcpy(hd->orig_name,ssave[0]);
-+ getline(fd,&ssave[0],&slmax[0]);
-+ hd->seq_name = calloc(strlen(ssave[0])+1, sizeof (char));
-+ strcpy(hd->seq_name,ssave[0]);
-+ hd->num_frame = dfscanf(fd);
-+ getline(fd,&ssave[0],&slmax[0]);
-+ hd->orig_date = calloc(strlen(ssave[0])+1, sizeof (char));
-+ strcpy(hd->orig_date,ssave[0]);
-+ hd->rows = dfscanf(fd);
-+ hd->cols = dfscanf(fd);
-+ hd->bits_per_pixel = dfscanf(fd);
-+ hd->bit_packing = dfscanf(fd);
-+ hd->pixel_format = dfscanf(fd);
-+ lineno = 0;
-+ len = 1;
-+ getline(fd,&ssave[0],&slmax[0]);
-+ s = ssave[0];
-+ while(*(s += strlen(s)-3) == '|') {
-+ len += strlen(ssave[lineno]);
-+ lineno++;
-+ if (lineno >= LINES)
-+ fprintf(stderr, "Too many lines in header history");
-+ if(lineno >= lalloc) {
-+ ssave[lineno] = calloc(LINELENGTH, sizeof (char));
-+ slmax[lineno] = LINELENGTH;
-+ lalloc++;
-+ }
-+ getline(fd,&ssave[lineno],&slmax[lineno]);
-+ s = ssave[lineno];
-+ }
-+ len += strlen(ssave[lineno]);
-+ hd->seq_history = calloc(len, sizeof (char));
-+ hd->seq_history[0] = '\0';
-+ for (i=0;i<=lineno;i++)
-+ strcat(hd->seq_history,ssave[i]);
-+ lineno = 0;
-+ len = 1;
-+ while(strcmp(getline(fd,&ssave[lineno],&slmax[lineno]),".\n")) {
-+ len += strlen(ssave[lineno]);
-+ lineno++;
-+ if (lineno >= LINES)
-+ fprintf(stderr, "Too many lines in header desc.");
-+ if(lineno >= lalloc) {
-+ ssave[lineno] = calloc(LINELENGTH, sizeof (char));
-+ slmax[lineno] = LINELENGTH;
-+ lalloc++;
-+ }
-+ }
-+ hd->seq_desc = calloc(len, sizeof (char));
-+ *hd->seq_desc = '\0';
-+ for (i=0;iseq_desc,ssave[i]);
-+/*fprintf(stderr,"fread_header: exiting\n");*/
-+ return 0;
-+}
-+
-+
-+
-+static char *getline(fd,s,l)
-+ int fd;
-+ char **s;
-+ int *l;
-+{
-+ int i,m;
-+ char c,*s1,*s2;
-+
-+ i = 0;
-+ s1 = *s;
-+ m = *l;
-+ while(read(fd,&c,1) == 1 && c != '\n') {
-+ if (m-- <= 2) {
-+ s2 = calloc(LINELENGTH+*l,sizeof (char));
-+ strcpy(s2,*s);
-+ *s = s2;
-+ *l += LINELENGTH;
-+ m = LINELENGTH;
-+ s1 = s2 + strlen(s2);
-+ }
-+ *s1++ = c;
-+ }
-+ if (c == '\n') {
-+ *s1++ = '\n';
-+ *s1 = '\0';
-+ return *s;
-+ }
-+ fprintf(stderr, "Unexpected EOF while reading header.");
-+ return NULL;
-+}
-+
-+
-+
-+static int dfscanf(fd)
-+ int fd;
-+{
-+ int i;
-+
-+ getline(fd,&ssave[0],&slmax[0]);
-+ sscanf(ssave[0],"%d",&i);
-+ return(i);
-+}
-+
-+
-+
-+/*******************************************/
-+int LoadHIPS(fname,pinfo)
-+ char *fname;
-+ PICINFO * pinfo;
-+/*******************************************/
-+{
-+ FILE *fp;
-+ struct header h;
-+ char * pic;
-+
-+ /* open the stream, if necesary */
-+ fp=fopen(fname,"r");
-+ if (!fp) return 0;
-+
-+ if (!fread_header(fileno(fp), &h)) {
-+ SetISTR(ISTR_WARNING,"Can't read HIPS header");
-+ return 0;
-+ }
-+
-+ pinfo->w = h.cols;
-+ pinfo->h = h.rows;
-+ pic = pinfo->pic = (byte *) malloc(h.rows * h.cols); // GRR POSSIBLE OVERFLOW / FIXME
-+ if (!pic) FatalError("couldn't malloc HIPS file");
-+
-+ if (!fread(pic, 1, h.cols*h.rows, fp)) {
-+ SetISTR(ISTR_WARNING,"Error reading HIPS data.\n");
-+ return 0;
-+ }
-+ fclose (fp);
-+
-+ pinfo->frmType = F_SUNRAS;
-+ pinfo->colType = F_FULLCOLOR;
-+ sprintf(pinfo->fullInfo, "HIPS file (%d bytes)", h.cols*h.rows);
-+ sprintf(pinfo->shrtInfo, "HIPS file.");
-+ pinfo->comment = (char *) NULL;
-+
-+ {
-+ char cmapname[256];
-+ /* Check header for colormap spec */
-+ char * s = h.seq_desc - 1;
-+ char * cmaptag = "+COLORMAP";
-+ int sl = strlen(cmaptag);
-+ cmapname[0] = 0;
-+ while (*++s)
-+ if (*s == '+')
-+ if (strncmp(s, cmaptag, sl) == 0) {
-+ char * p = s + sl;
-+ while (*p && (*p == ' ' || *p == '\n' || *p == '\t')) p++;
-+ sscanf(p, "%s", cmapname);
-+ SetISTR(ISTR_INFO, cmapname);
-+ fprintf(stderr, "Colormap = [%s]\n", cmapname);
-+ }
-+
-+ if (strcmp(cmapname, "gray") == 0 || strcmp(cmapname, "grey") == 0)
-+ make_grayscale(pinfo->r, pinfo->g, pinfo->b);
-+ else if (strcmp(cmapname, "heat") == 0)
-+ make_heatscale(pinfo->r, pinfo->g, pinfo->b);
-+ else if (strcmp(cmapname, "hues") == 0)
-+ make_huescale(pinfo->r, pinfo->g, pinfo->b);
-+ else if (!cmapname[0] || !load_colourmap(cmapname, 256, pinfo->r, pinfo->g, pinfo->b))
-+ make_grayscale(pinfo->r, pinfo->g, pinfo->b);
-+ sprintf(pinfo->fullInfo, "HIPS file (%d x %d), Colormap = [%s]", h.cols, h.rows, cmapname);
-+ }
-+
-+ return 1;
-+}
-+
-+
-+
-+static void make_grayscale(char * r, char * g, char * b)
-+{
-+ int i;
-+ /* default grayscale colors */
-+ r[0] = 40; g[0] = 150; b[0] = 100; /* "green4" background */
-+ for(i = 1; i < 256; i++)
-+ r[i] = g[i] = b[i] = i;
-+}
-+
-+
-+
-+static float hls_value (n1, n2, hue)
-+ float n1,n2,hue;
-+{
-+ if (hue>360.0)
-+ hue-=360.0 ;
-+ else if (hue<0.0)
-+ hue+=360.0 ;
-+
-+ if (hue<60.0)
-+ return( n1+(n2-n1)*hue/60.0 ) ;
-+ else if (hue<180.0)
-+ return ( n2 ) ;
-+ else if (hue<240.0)
-+ return ( n1+(n2-n1)*(240.0-hue)/60.0 ) ;
-+ else
-+ return (n1) ;
-+}
-+
-+
-+
-+static void hls_to_rgb(h,l,s, r,g,b)
-+ float h, l, s;
-+ float *r, *g, *b;
-+{
-+ static float m1, m2 ;
-+
-+ if (l<=0.5)
-+ m2=l*(1+s) ;
-+ else
-+ m2=l+s-l*s ;
-+ m1=2.0*l-m2 ;
-+ if (s==0.0) *r=*g=*b=l ;
-+ else {
-+ *r=hls_value(m1,m2,h+120.0) ;
-+ *g=hls_value(m1,m2,h) ;
-+ *b=hls_value(m1,m2,h-120.0) ;
-+ }
-+
-+}
-+
-+
-+
-+static void make_huescale(char * r, char * g, char * b)
-+{
-+ int j;
-+ r[0] = g[0] = b[0] = 0;
-+ for (j = 1; j<256; j++)
-+ {
-+ float fr, fg, fb;
-+ hls_to_rgb((double)(256.0-j)*360.0/256.0, 0.5, 1.0, &fr, &fg, &fb);
-+ r[j] = rint(255*fr);
-+ g[j] = rint(255*fg);
-+ b[j] = rint(255*fb);
-+ }
-+}
-+
-+
-+
-+static void make_heatscale(char * r, char * g, char * b)
-+{
-+ int j;
-+ r[0] = g[0] = b[0] = 0;
-+ for (j = 1; j<256; j++)
-+ {
-+ if(j<255/2)
-+ r[j] = j*255/(255/2-1);
-+ else
-+ r[j]=255;
-+ if (j>=255/2+255/3)
-+ g[j] = 255;
-+ else if (j>255/3)
-+ g[j] = (j-255/3)*255/(255/2-1);
-+ else
-+ g[j] = 0;
-+ if (j>255/2)
-+ b[j] = (j-255/2)*255/(255-255/2-1);
-+ else
-+ b[j] = 0;
-+ }
-+}
-+
-+
-+
-+static int load_colourmap(char *filestem, int max_colours,
-+ char *r, char *g, char *b)
-+{
-+ FILE * fp;
-+ int numread=0;
-+ char * filename;
-+ char str[200];
-+ int num_colors;
-+ /*
-+ * Look for palette file in local directory
-+ */
-+
-+ filename = (char*)alloca(strlen(filestem) + 5);
-+ strcpy(filename, filestem);
-+ strcat(filename, ".PAL"); /* Add the PAL suffix to the name specified */
-+ fp = fopen(filename,"r");
-+ if (!fp) {
-+ /*
-+ * If not found, try in $IM2HOME/etc/palettes
-+ */
-+ char * im2home = (char*)getenv("IM2HOME");
-+ char * palette_subdirectory = "etc/palettes";
-+ char * fullfilename;
-+ if (!im2home)
-+ {
-+ im2home = "/home/jewel/imagine2";
-+ fprintf(stderr,"IM2HOME environment variable not set -- using [%s]\n",im2home);
-+ }
-+ fullfilename = alloca(strlen(im2home)+strlen(palette_subdirectory)+strlen(filename)+5);
-+ sprintf(fullfilename, "%s/%s/%s",im2home,palette_subdirectory,filename);
-+ fp = fopen(fullfilename,"r");
-+ if (!fp)
-+ {
-+ fprintf(stderr,"Couldn't find any palette file -- looked for [%s] and [%s].\n",
-+ filename,fullfilename);
-+ perror("Last system error message was");
-+ return 0;
-+ }
-+ }
-+
-+ strcpy(str,"(null)");
-+ if (!fscanf(fp,"%s\n",str) || strncmp(str,"Palette",7) != 0) {
-+ fprintf(stderr,"error: First line of palette file should be `Palette', not [%s]\n", str);
-+ return 0;
-+ }
-+
-+ fscanf(fp,"%[^\n]",str) ; /* Scan to end of line */
-+ fscanf (fp,"%d",&num_colors);/* Read the number of colours in the file */
-+ fgets(str,120,fp) ; /* Skip the text description, and general info lines */
-+ fgets(str,120,fp) ;
-+
-+ while ((numread (B) ? (A) : (B))
-+#endif /* MAX */
-+#ifndef MIN
-+# define MIN(A,B) ((A) < (B) ? (A) : (B))
-+#endif /* MIN */
-+#ifndef ABS
-+# define ABS(A) ((A) > 0 ? (A) : (-(A)))
-+#endif /* ABS */
-+#ifndef BETWEEN
-+# define BETWEEN(A,B,C) (((A) < (B)) ? (B) : (((A) > (C)) ? (C) : (A)))
-+#endif /* BETWEEN */
-+#ifndef SIGN
-+# define SIGN(A,B) (((B) > 0) ? (A) : (-(A)))
-+#endif /* SIGN */
-diff -u -r --new-file xv-3.10a.orig/xvjp2k.c xv-3.10a/xvjp2k.c
---- xv-3.10a.orig/xvjp2k.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvjp2k.c 2007-05-13 20:04:37.000000000 -0500
-@@ -0,0 +1,1326 @@
-+/*
-+ * xvjp2k.c - I/O subroutines for JPEG 2000 format pictures
-+ *
-+ * This module is a "shim" between XV and a JPEG 2000 CODEC in the open-source
-+ * JasPer Library created by Michael D. Adams; for more information, see the URL
-+ * "http://www.ece.uvic.ca/~mdadams/jasper". We don't use most of the other
-+ * facilities in this library, so it's better to link XV with a UNIX "archive"
-+ * representation of it, not a DLL.
-+ *
-+ * JPEG 2000 files can be represented in either of two general ways: The
-+ * simplest representation is a "code stream", which often has a ".jpc" file
-+ * name suffix and is organized much like a classical JPEG file, except that
-+ * unfortunately, JPEG 2000 code streams indicate the no. of colors in an image
-+ * but no longer give any clues about its color space (e.g., RGB or YCbCr).
-+ * Instead, there is now a semantically higher-level representation, which often
-+ * has a ".jp2" file name suffix and encapsulates a "code stream" with (possibly
-+ * a lot of) color-space information, optionally including things like ICC
-+ * correction tables.
-+ *
-+ * Compared to the IJG JPEG Library used in file "xvjpeg.c", one must solve
-+ * several problems for color images when marrying JasPer to XV.
-+ *
-+ * 1. JPEG 2000 files can represent a wide range of image sizes, resolutions,
-+ * and color spaces, not all of which can be easily rendered "as is" on a
-+ * normal "X Windows" display, so we must carefully check a decoded image's
-+ * parameters in order to reject anything that we can't handle gracefully.
-+ *
-+ * 2. JasPer prefers to decode/encode images using color-plane "slices", instead
-+ * of interleaved pixels needed by "X Windows", so we must (de)interleave
-+ * copies of the image buffer here.
-+ *
-+ * XXX Things to do:
-+ *
-+ * 1. In "LoadJP{2,C}()" try to handle the "quick" option, which requests
-+ * faster loading of a reduced-size image for the visual schnauzer. The
-+ * schnauzer's icon size is currently 80x60, so the old "xvjpeg.c" module tries
-+ * to produce a 2X (160x120) image. Can we do the same?
-+ *
-+ * 2. In "StoreJP2K()", JasPer Library Version 1.701 apparently has no API to
-+ * let the XV global "picComments" string be inserted in a JPEG 2000 comment
-+ * record. If the library ever gets fixed, enhance our code accordingly.
-+ *
-+ * --Scott Marovich , Hewlett-Packard Laboratories,
-+ * January 2005.
-+ */
-+#include "copyright.h"
-+
-+#define NEEDSARGS
-+#include "xv.h"
-+
-+#ifdef HAVE_JP2K
-+
-+#include
-+/* missing prototype in 1.701.0, sigh: */
-+jas_stream_t *jas_stream_freopen PARM((const char *, const char *, FILE *));
-+
-+static const char *fbasename, /* File's base name, for error/warning msgs */
-+ bad_samp[] = "%s: can't read %d-plane %s file!",
-+ fmode[] = "rb",
-+ full_msg[] = "%s %s. (%ld bytes)",
-+ jp2_kind[] = "JP2",
-+ jpc_kind[] = "JPEG 2000",
-+ load_msg[] = "Loading %dx%d %s %s (%ld bytes)...",
-+ no_mem[] = "%s: can't read %s file - out of memory",
-+ pixel_size[] = "%s: can't display %d-bit pixels!",
-+ shrt_msg[] = "%dx%d %s %s. ",
-+ truncated[] = "%s: Unexpected end of %s file",
-+ read_err[] = "%s: I/O error reading %s file",
-+ bad_dims[] = "%s: error in JPEG-2000 header (bad image size)";
-+
-+/* We only want to override the JasPer Library's "jas_eprintf()" subroutine in
-+ order to make it a "wrapper" around XV's own error-reporting subroutine, but
-+ because of the way the former is currently packaged in JasPer Library Version
-+ 1.701, we must override everything else packaged in the "jas_debug.o" module
-+ with it, otherwise we get "duplicate definition" messages from the linker.
-+*/
-+int jas_getdbglevel(void) {return 0;}
-+int jas_setdbglevel(int n) {return 0;}
-+int jas_memdump(FILE *fp,void *data,size_t len) {return 0;}
-+
-+int jas_eprintf(const char *fmt,...) /* Handle JasPer Library message */
-+{
-+ static char error[] = "error: ", warning[]= "warning: ";
-+ va_list ap;
-+ int kind = ISTR_WARNING;
-+ char buffer[512];
-+ register char *p;
-+
-+ /* Unlike the IJG JPEG Library, the JasPer Library current has no graceful way
-+ for an application (= us!) to intercept its diagnostic messages and output
-+ them using our own subroutines, so this ugly replacement for its output
-+ subroutine will have to suffice. At Version 1.701, lthough the library's
-+ own "jas_eprintf()" is a varargs subroutine, all calls currently pass just
-+ 1 string with a Line Feed at the end and no "printf(3C)" arguments. Most
-+ strings begin with "error: " or "warning: ", although a few have neither.
-+ We try to translate these into the format preferred by XV, trimming any
-+ trailing Line Feed character (ugh!).
-+ */
-+ va_start(ap, fmt);
-+ vsnprintf(p = buffer,512,fmt,ap);
-+ va_end(ap);
-+ while (*p++);
-+ if (p[-2] == '\n') p[-2] = '\0';
-+ p = buffer;
-+ if (strncmp(p,error,sizeof error) == 0) /* "error: ... " */
-+ {
-+ kind = ISTR_WARNING;
-+ p += sizeof error;
-+ }
-+ else /* "warning: ... " */
-+ if (strncmp(p,warning,sizeof warning) == 0)
-+ {
-+ kind = ISTR_INFO;
-+ p += sizeof warning;
-+ };
-+ SetISTR(kind,"%s: %s",fbasename,p);
-+ return strlen(fmt);
-+}
-+
-+static char *SetBuf(FILE *f)
-+{
-+ char *buf;
-+ register char *p;
-+
-+ /* JPEG 2000 image files are apt to be large, but the buffer size allocated by
-+ most implementations of the "C" Standard I/O Library is still ridiculously
-+ small, typically 1 KB. We want to allocate a much larger buffer for higher
-+ I/O efficiency, but the details are unfortunately a bit platform-specific.
-+ Under UNIX systems with virtual memory, we want to encourage its internal
-+ "physio()" subroutine by making the buffer an integral number of pages,
-+ aligned on a page-multiple memory address boundary. Under HP-UX 11.1+ and
-+ perhaps other operating-systems, a Standard I/O buffer is preceded by a
-+ header whose size must also be taken into account.
-+ */
-+# ifndef IOBUFSIZ
-+# define IOBUFSIZ 65536
-+# endif /* IOBUFSIZ */
-+# ifdef __hpux
-+# define OVERHEAD sizeof(mbstate_t)
-+# endif /* __hpux */
-+# ifndef OVERHEAD
-+# define OVERHEAD 0
-+# endif /* OVERHEAD */
-+
-+# ifdef NBPG
-+ if (!(buf = p = malloc(NBPG+OVERHEAD+IOBUFSIZ))) return 0;
-+ p = (char *)((unsigned long)p+NBPG-1 & ~(NBPG-1));
-+ p -= OVERHEAD;
-+# else /* not NBPG */
-+ if (!(buf = p = malloc(OVERHEAD+IOBUFSIZ))) return 0;
-+ p += OVERHEAD;
-+# endif /* NBPG */
-+ setvbuf(f,p,_IOFBF,OVERHEAD+IOBUFSIZ);
-+ return buf;
-+# undef OVERHEAD
-+# undef IOBUFSIZ
-+}
-+
-+int LoadJPC(char *fname,register PICINFO *pinfo,int quick)
-+{
-+ jas_image_t *img;
-+ jas_stream_t *str;
-+ FILE *fp;
-+ char *iobuf;
-+ const char *s;
-+ unsigned long filesize;
-+ long w, h, npixels, bufsize;
-+ int ok = 0, vstride;
-+ register int i;
-+
-+ /* Load a JPEG 2000 "code stream" image file into a pixel buffer for XV.
-+ Unlike classical JPEG files, they have no clue about the image's color
-+ space, so we check for 8-bit data samples but make no effort to check or
-+ convert color spaces, and "what you see is what you get". For now, ignore
-+ the "quick" option to return a reduced-resolution or -size image. Return 1
-+ on success, or 0 on failure.
-+ */
-+ if (!(fp = xv_fopen(fname,fmode))) return 0;
-+ fbasename = BaseName(fname); /* Input file's base name, for message(s) */
-+ if (!(iobuf = SetBuf(fp)))
-+ {
-+ (void)fclose(fp);
-+ SetISTR(ISTR_WARNING,no_mem,fbasename,jpc_kind);
-+ goto L3;
-+ }
-+
-+ /* Before telling the JasPer Library about this file, get its size for display
-+ purposes. Non-UNIX systems don't necessarily simulate "stat(2)", so do it
-+ crudely but portably by seeking to the end, then back to the beginning.
-+ */
-+ fseek(fp,0L,2);
-+ filesize = ftell(fp);
-+ fseek(fp,0L,0);
-+
-+ /* "jas_stream_close()" will eventually close the input file, so only do it
-+ explicitly if no stream can be created:
-+ */
-+ if (!(str = jas_stream_freopen(fname,fmode,fp))) /* nice if prototype... */
-+ {
-+ (void)fclose(fp);
-+ goto L3;
-+ }
-+
-+ /* It's not clear to me whether the following represents a JasPer Library "bug"
-+ but it sure looks goofy: Unless a stream buffer is marked "read only",
-+ which only happens when the stream's "fillbuf" method is called, even though
-+ our buffers are always "read only", the library will try to flush out buffer
-+ contents when the stream is destroyed, which makes it die a horrible death.
-+ So, mark the stream buffer proactively:
-+ */
-+ str->bufmode_ |= JAS_STREAM_RDBUF; /* We will only read the stream buffer */
-+ if (!(img = jpc_decode(str,0))) goto L2;
-+ if ((vstride = jas_image_numcmpts(img))) /* num. color planes */
-+ {
-+
-+ /* After the image-component streams created, they are left in a "write"
-+ state with the streams' cursors positioned at their ends, so "seek" in
-+ order to "read" each stream from its beginning.
-+ */
-+ i = vstride;
-+ while (--i >= 0)
-+ if (jas_stream_seek(img->cmpts_[i]->stream_,0L,0))
-+ {
-+ SetISTR(ISTR_WARNING,read_err,fbasename,jpc_kind);
-+ goto L1;
-+ }
-+ }
-+ w = jas_image_width(img);
-+ h = jas_image_height(img);
-+
-+ /* avoid buffer overflow */
-+ npixels = w * h;
-+ bufsize = vstride * npixels;
-+ if (w <= 0 || h <= 0 || npixels/w != h || bufsize/vstride != npixels)
-+ {
-+ (void)fclose(fp);
-+ SetISTR(ISTR_WARNING,bad_dims,fbasename);
-+ goto L1;
-+ }
-+ pinfo->normw = pinfo->w = w;
-+ pinfo->normh = pinfo->h = h;
-+
-+ /* Sanity-check the image's color space and no. of colors. For now, accept
-+ only "generic" color spaces, not files needing image-specific color
-+ correction, but fix that someday...
-+ */
-+ switch (vstride)
-+ {
-+ default:
-+ SetISTR(ISTR_WARNING,bad_samp,fbasename,vstride,jpc_kind);
-+ goto L1;
-+ case 1:
-+ if ((i = jas_image_cmptprec(img,0)) != 8) /* not 8-bit pixels */
-+ {
-+ SetISTR(ISTR_WARNING,pixel_size,fbasename,i);
-+ goto L1;
-+ }
-+ s = "Greyscale";
-+ pinfo->type = PIC8;
-+ pinfo->colType = F_GREYSCALE;
-+ i = 256; /* Return fake indexed-color "map" */
-+ while (--i >= 0) pinfo->r[i] = pinfo->g[i] = pinfo->b[i] = i;
-+ break;
-+ case 3:
-+
-+ /* BEWARE OF KLUDGE: If the image's color space is RGB, assume that the
-+ data-sample precision for all color planes is the
-+ same. If the color space is YCbCr, assume the luminance (Y = 0th)
-+ component has the greatest precision, although the chrominance
-+ (Cr = 1st, Cb = 2nd) components are usually sub-sampled.
-+ */
-+ if ((i = jas_image_cmptprec(img,0)) != 8) /* not 24-bit pixels */
-+ {
-+ SetISTR(ISTR_WARNING,pixel_size,fbasename,i*3);
-+ goto L1;
-+ }
-+ s = "Color";
-+ pinfo->type = PIC24;
-+ pinfo->colType = F_FULLCOLOR;
-+
-+ /* XXX Unlike the IJG JPEG Library, the JasPer Library is apparently
-+ unable to quantize colors or tell us whether the image's colors
-+ were quantized by its creator, so it seems that we can't return a
-+ color map for XV to potentially use 8-bit indexed color. If there
-+ *is* an easy way to do it that escapes me, put the code here someday.
-+ */
-+ }
-+ if (!(pinfo->pic = (byte *)malloc(bufsize))) /* image buffer for XV */
-+ {
-+ SetISTR(ISTR_WARNING,no_mem,fbasename,jpc_kind);
-+ goto L1;
-+ }
-+ pinfo->frmType = F_JPC;
-+ sprintf(pinfo->fullInfo,full_msg,s,jpc_kind,filesize);
-+ sprintf(pinfo->shrtInfo,shrt_msg,pinfo->w,pinfo->h,s,jpc_kind);
-+ SetISTR(ISTR_INFO,load_msg,pinfo->normw,pinfo->normh,s,jpc_kind,filesize);
-+ if (vstride == 1) /* gray-scale image */
-+ { register jas_stream_t *c = img->cmpts_[0]->stream_;
-+ register byte *p = pinfo->pic;
-+
-+ /* Since this is a 1-plane image, avoid a lot of errant nonsense in the
-+ JasPer Library by sequentially reading all of the data into our buffer
-+ directly.
-+ */
-+ do if ((i = (*c->ops_->read_)(c->obj_,(char *)p,bufsize)) <= 0)
-+ {
-+ SetISTR(ISTR_WARNING,i < 0 ? read_err : truncated,fbasename,
-+ jpc_kind);
-+ goto L1;
-+ }
-+ while ((p += i),(bufsize -= i) > 0);
-+ }
-+ else /* RGB color image */
-+ {
-+
-+ /* Reading color images is inefficient because JPEG 2000 wants to partition
-+ file data into separate image planes (colors), while XV wants data
-+ samples from each plane to be interleaved as 3-byte pixels. Apparently
-+ the fastest method consists of 3 passes through the XV image buffer,
-+ into which we insert the bytes of each component.
-+ */
-+ i = 0;
-+ do /* each color component */
-+ { long npix = npixels;
-+ register jas_stream_t *c = img->cmpts_[i]->stream_;
-+ register byte *p = pinfo->pic + i;
-+
-+ do /* each pixel */
-+ { register int b;
-+
-+ if ((b = jas_stream_getc(c)) < 0)
-+ {
-+ SetISTR(ISTR_WARNING,
-+ (c->flags_ & JAS_STREAM_EOF) ? truncated : read_err,
-+ fbasename,jpc_kind);
-+ goto L1;
-+ }
-+ *p = b;
-+ }
-+ while ((p += 3),--npix > 0);
-+ }
-+ while (++i <= 2);
-+ }
-+ ok = 1; /* Success! */
-+L1: jas_image_destroy(img);
-+L2: (void)jas_stream_close(str);
-+ free(iobuf);
-+L3: return ok;
-+}
-+
-+int LoadJP2(char *fname,register PICINFO *pinfo,int quick)
-+{
-+ jas_image_t *img;
-+ jas_stream_t *str;
-+ FILE *fp;
-+ char *iobuf;
-+ const char *s;
-+ unsigned long filesize;
-+ long w, h, npixels, bufsize;
-+ int ok = 0, vstride;
-+ register int i;
-+
-+ /* Load a JPEG 2000 JP2 image file into a pixel buffer for XV, doing any
-+ necessary color-space conversion to end up with 8-bit gray scale or 24-bit
-+ RGB. For now, ignore the "quick" option to return a reduced-resolution
-+ or -size image. Return 1 on success, or 0 on failure.
-+ */
-+ if (!(fp = xv_fopen(fname,fmode))) return 0;
-+ fbasename = BaseName(fname); /* Input file's base name, for message(s) */
-+ if (!(iobuf = SetBuf(fp)))
-+ {
-+ (void)fclose(fp);
-+ SetISTR(ISTR_WARNING,no_mem,fbasename,jpc_kind);
-+ goto L3;
-+ }
-+
-+ /* Before telling the JasPer Library about this file, get its size for display
-+ purposes. Non-UNIX systems don't necessarily simulate "stat(2)", so do it
-+ crudely but portably by seeking to the end, then back to the beginning.
-+ */
-+ fseek(fp,0L,2);
-+ filesize = ftell(fp);
-+ fseek(fp,0L,0);
-+
-+ /* "jas_stream_close()" will eventually close the input file, so only do it
-+ explicitly if no stream can be created:
-+ */
-+ if (!(str = jas_stream_freopen(fname,fmode,fp)))
-+ {
-+ (void)fclose(fp);
-+ goto L3;
-+ }
-+
-+ /* It's not clear to me whether the following represents a JasPer Library "bug"
-+ but it sure looks goofy: Unless a stream buffer is marked "read only",
-+ which only happens when the stream's "fillbuf" method is called, even though
-+ our buffers are always "read only", the library will try to flush out buffer
-+ contents when the stream is destroyed, which makes it die a horrible death.
-+ So, mark the stream buffer proactively:
-+ */
-+ str->bufmode_ |= JAS_STREAM_RDBUF; /* We will only read the stream buffer */
-+ if (!(img = jp2_decode(str,0))) goto L2;
-+ if ((vstride = jas_image_numcmpts(img))) /* num. color planes */
-+ {
-+
-+ /* After the image-component streams created, they are left in a "write"
-+ state with the streams' cursors positioned at their ends, so "seek" in
-+ order to "read" each stream from its beginning.
-+ */
-+ i = vstride;
-+ while (--i >= 0)
-+ if (jas_stream_seek(img->cmpts_[i]->stream_,0L,0))
-+ {
-+ SetISTR(ISTR_WARNING,read_err,fbasename,jp2_kind);
-+ goto L1;
-+ }
-+ }
-+ w = jas_image_width(img);
-+ h = jas_image_height(img);
-+
-+ /* avoid buffer overflow */
-+ npixels = w * h;
-+ bufsize = vstride * npixels;
-+ if (w <= 0 || h <= 0 || npixels/w != h || bufsize/vstride != npixels)
-+ {
-+ (void)fclose(fp);
-+ SetISTR(ISTR_WARNING,bad_dims,fbasename);
-+ goto L1;
-+ }
-+ pinfo->normw = pinfo->w = w;
-+ pinfo->normh = pinfo->h = h;
-+
-+ /* Sanity-check the image's color space and no. of colors. For now, accept
-+ only "generic" color spaces, not files needing image-specific color
-+ correction, but fix that someday...
-+ */
-+ switch (vstride)
-+ { static char color_space[]={"%s: invalid color space!"};
-+
-+ default:
-+ SetISTR(ISTR_WARNING,bad_samp,fbasename,vstride,jp2_kind);
-+ goto L1;
-+ case 1:
-+ if ( !jas_clrspc_isunknown(i = jas_image_clrspc(img))
-+ && jas_clrspc_fam(i) != JAS_CLRSPC_FAM_GRAY
-+ )
-+ {
-+ SetISTR(ISTR_WARNING,color_space,fbasename);
-+ goto L1;
-+ }
-+ if ((i = jas_image_cmptprec(img,0)) != 8) /* not 8-bit pixels */
-+ {
-+ SetISTR(ISTR_WARNING,pixel_size,fbasename,i);
-+ goto L1;
-+ }
-+ s = "Greyscale";
-+ pinfo->type = PIC8;
-+ pinfo->colType = F_GREYSCALE;
-+ i = 256; /* Return fake indexed-color "map" */
-+ while (--i >= 0) pinfo->r[i] = pinfo->g[i] = pinfo->b[i] = i;
-+ break;
-+ case 3:
-+ if (jas_clrspc_isunknown(i = jas_image_clrspc(img)))
-+ {
-+ SetISTR(ISTR_WARNING,color_space,fbasename);
-+ goto L1;
-+ }
-+ if (jas_clrspc_fam(i) != JAS_CLRSPC_FAM_RGB)
-+ { jas_image_t *oimg;
-+ jas_cmprof_t *profile;
-+
-+ /* Here's where the JasPer Library really shines. The only color
-+ space that XV handles is RGB, so if that's not what our image
-+ uses, then to quote Capt. Kirk: "Make it so!"
-+ */
-+ if (!(profile = jas_cmprof_createfromclrspc(JAS_CLRSPC_SRGB)))
-+ {
-+ SetISTR(ISTR_WARNING,"%s: can't create RGB profile",
-+ fbasename);
-+ goto L1;
-+ }
-+ img = jas_image_chclrspc( oimg = img
-+ , profile
-+ , JAS_CMXFORM_INTENT_PER
-+ );
-+ jas_cmprof_destroy(profile);
-+ if (!img) /* Oops! We failed, so restore original image */
-+ {
-+ img = oimg;
-+ SetISTR(ISTR_WARNING,"%s: can't convert to RGB",fbasename);
-+ goto L1;
-+ }
-+ jas_image_destroy(oimg);
-+ }
-+
-+ /* BEWARE OF KLUDGE: If the image's color space is RGB, assume that the
-+ data-sample precision for all color planes is the
-+ same. If the color space is YCbCr, assume the luminance (Y = 0th)
-+ component has the greatest precision, although the chrominance
-+ (Cr = 1st, Cb = 2nd) components are usually sub-sampled.
-+ */
-+ if ((i = jas_image_cmptprec(img,0)) != 8) /* not 24-bit pixels */
-+ {
-+ SetISTR(ISTR_WARNING,pixel_size,fbasename,i*3);
-+ goto L1;
-+ }
-+ s = "Color";
-+ pinfo->type = PIC24;
-+ pinfo->colType = F_FULLCOLOR;
-+
-+ /* XXX Unlike the IJG JPEG Library, the JasPer Library is apparently
-+ unable to quantize colors or tell us whether the image's colors
-+ were quantized by its creator, so it seems that we can't return a
-+ color map for XV to potentially use 8-bit indexed color. If there
-+ *is* an easy way to do it that escapes me, put the code here someday.
-+ */
-+ }
-+ if (!(pinfo->pic = (byte *)malloc(bufsize))) /* image buffer for XV */
-+ {
-+ SetISTR(ISTR_WARNING,no_mem,fbasename,jp2_kind);
-+ goto L1;
-+ }
-+ pinfo->frmType = F_JP2;
-+ sprintf(pinfo->fullInfo,full_msg,s,jp2_kind,filesize);
-+ sprintf(pinfo->shrtInfo,shrt_msg,pinfo->w,pinfo->h,s,jp2_kind);
-+ SetISTR(ISTR_INFO,load_msg,pinfo->normw,pinfo->normh,s,jp2_kind,filesize);
-+ if (vstride == 1) /* gray-scale image */
-+ { register jas_stream_t *c = img->cmpts_[0]->stream_;
-+ register byte *p = pinfo->pic;
-+
-+ /* Since this is a 1-plane image, avoid a lot of errant nonsense in the
-+ JasPer Library by sequentially reading all of the data into our buffer
-+ directly.
-+ */
-+ do if ((i = (*c->ops_->read_)(c->obj_,(char *)p,bufsize)) <= 0)
-+ {
-+ SetISTR(ISTR_WARNING,i < 0 ? read_err : truncated,fbasename,
-+ jp2_kind);
-+ goto L1;
-+ }
-+ while ((p += i),(bufsize -= i) > 0);
-+ }
-+ else /* RGB color image */
-+ {
-+
-+ /* Reading color images is inefficient because JPEG 2000 wants to partition
-+ file data into separate image planes (colors), while XV wants data
-+ samples from each plane to be interleaved as 3-byte pixels. Apparently
-+ the fastest method consists of 3 passes through the XV image buffer,
-+ into which we insert the bytes of each component.
-+ */
-+ i = 0;
-+ do /* each color component */
-+ { long npix = npixels;
-+ register jas_stream_t *c = img->cmpts_[i]->stream_;
-+ register byte *p = pinfo->pic + i;
-+
-+ do /* each pixel */
-+ { register int b;
-+
-+ if ((b = jas_stream_getc(c)) < 0)
-+ {
-+ SetISTR(ISTR_WARNING,
-+ (c->flags_ & JAS_STREAM_EOF) ? truncated : read_err,
-+ fbasename,jp2_kind);
-+ goto L1;
-+ }
-+ *p = b;
-+ }
-+ while ((p += 3),--npix > 0);
-+ }
-+ while (++i <= 2);
-+ }
-+ ok = 1; /* Success! */
-+L1: jas_image_destroy(img);
-+L2: (void)jas_stream_close(str);
-+ free(iobuf);
-+L3: return ok;
-+}
-+
-+/* The following variables and subroutines are used when writing a JPEG 2000
-+ file, which is done mainly using call-backs from "X Windows" widgets. The
-+ most complicated part of this interface is: managing interactions with a
-+ window to request the boat-loads of options that the JasPer Library supports.
-+ Start by defining subwindow sizes, plus indices into several arrays of
-+ corresponding widget-state variables.
-+
-+ IMPLEMENTATION NOTES: The following dimensions create a tall, thin window
-+ which appears to have considerable empty space at the
-+ bottom. Before you complain, click the Precinct Height menu button in order
-+ to the tall pop-up subwindow that it generates. If the parent window is made
-+ shorter, then this pop-up will be clipped, which is an ugly nuisance. I
-+ don't know how to make the pop-up visible outside its parent's borders; do
-+ you? If there's some way to make "X Windows" do this, then we might consider
-+ making the parent shorter.
-+
-+ Note that there is currently no mechanism to program the no. of intermediate
-+ layers used by the encoder, or their rates. This is potentially a large and
-+ complicated data-entry problem, and perhaps someday we can invent a clever
-+ solution using the rest of the parent window's space.
-+*/
-+# define JP2KW 275 /* Window width, in pixels */
-+# define JP2KH 400 /* Window height, in pixels */
-+# define BUTTW 51 /* Button width, in pixels (odd for half-toning) */
-+# define BUTTH 20 /* Button height, in pixels */
-+# define MENUW 75 /* Menu-button width, in pixels (odd for half-toning) */
-+# define MENUH 24 /* Menu-button height, in pixels */
-+# define RBUTH 20 /* Radio button height, in pixels */
-+# define RBUTW 51 /* Radio button width, in pixels (odd for half-toning) */
-+# define TEXTH (LINEHIGH+5) /* Text subwindow height, in pixels */
-+# define TEXTW 75 /* Text subwindow width, in pixels */
-+
-+# define J_BOK 0 /* Boolean "Ok" button */
-+# define J_BCANC 1 /* Boolean "Cancel" button */
-+# define J_NBUTT 2 /* No. of regular button widgets */
-+
-+# define J_CSOP 0 /* Boolean encoding-style option buttons */
-+# define J_CEPH 1
-+# define J_CLAZY 2
-+# define J_CTERM 3
-+# define J_CSEGS 4
-+# define J_CVCAU 5
-+# define J_CPTRM 6
-+# define J_CRSTP 7
-+# define J_NCHKB 8 /* No. of check-box button widgets */
-+
-+# define J_MCBXW 0 /* 1-of-N menu-selection buttons */
-+# define J_MCBXH 1
-+# define J_MPREW 2
-+# define J_MPREH 3
-+# define J_MPROG 4
-+# define J_NMENU 5 /* No. of menu-button widgets */
-+
-+# define J_TGBIT 0 /* (Unsigned numeric) string subwindows */
-+# define J_TRES 1
-+# define J_TRATE 2
-+# define J_NTEXT 3 /* No. of text subwindows */
-+
-+static BUTT button[J_NBUTT];
-+static CBUTT chkbut[J_NCHKB];
-+static MBUTT menu[J_NMENU];
-+static RBUTT *radio;
-+static Window text[J_NTEXT];
-+static int colorType, format, textval[J_NTEXT];
-+static const char *ProgList[]={"lrcp","rlcp","rpcl","pcrl","cprl"};
-+
-+void CreateJP2KW(void)
-+{
-+ static const char EXP2_0[] ={ "1"}, /* Successive powers of 2 */
-+ EXP2_1[] ={ "2"},
-+ EXP2_2[] ={ "4"},
-+ EXP2_3[] ={ "8"},
-+ EXP2_4[] ={ "16"},
-+ EXP2_5[] ={ "32"},
-+ EXP2_6[] ={ "64"},
-+ EXP2_7[] ={ "128"},
-+ EXP2_8[] ={ "256"},
-+ EXP2_9[] ={ "512"},
-+ EXP2_10[]={ "1024"},
-+ EXP2_11[]={ "2048"},
-+ EXP2_12[]={ "4096"},
-+ EXP2_13[]={ "8192"},
-+ EXP2_14[]={"16384"},
-+ EXP2_15[]={"32768"};
-+ static const char *CBoxList[]=
-+ {
-+ EXP2_1 ,EXP2_2 ,EXP2_3 ,EXP2_4 ,EXP2_5,EXP2_6 ,EXP2_7 ,EXP2_8 ,EXP2_9,
-+ EXP2_10,EXP2_11
-+ };
-+ static const char *PrecList[]=
-+ {
-+ EXP2_0,EXP2_1,EXP2_2 ,EXP2_3 ,EXP2_4 ,EXP2_5 ,EXP2_6 ,EXP2_7 ,
-+ EXP2_8,EXP2_9,EXP2_10,EXP2_11,EXP2_12,EXP2_13,EXP2_14,EXP2_15
-+ };
-+ static const char hstr[]={"Height"}, wstr[]={"Width"};
-+
-+ if (!(jp2kW = CreateWindow( "xvjp2k"
-+ , "XVjp2k"
-+ , 0
-+ , JP2KW
-+ , JP2KH
-+ , infofg
-+ , infobg
-+ , 0
-+ )
-+ )
-+ ) FatalError("can't create JPEG 2000 window!");
-+ XSelectInput(theDisp,jp2kW,ExposureMask|ButtonPressMask|KeyPressMask);
-+
-+ /* Create a row of 2 boolean-valued, regular buttons ("Ok" and "Cancel") in the
-+ window's bottom right corner.
-+ */
-+ BTCreate(&button[J_BOK ],jp2kW,
-+ JP2KW-2*BUTTW-20,JP2KH-10-BUTTH-1,BUTTW,BUTTH,
-+ "Ok" ,infofg,infobg,hicol,locol);
-+ BTCreate(&button[J_BCANC],jp2kW,
-+ JP2KW- BUTTW-10,JP2KH-10-BUTTH-1,BUTTW,BUTTH,
-+ "Cancel",infofg,infobg,hicol,locol);
-+
-+ /* Create a vertical column of 8 boolean-valued, check-box buttons (for
-+ encoding-style options) down the window's left side.
-+ */
-+ CBCreate(&chkbut[J_CSOP] ,jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+0*BUTTH,
-+ "sop" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CEPH] ,jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+1*BUTTH,
-+ "eph" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CLAZY],jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+2*BUTTH,
-+ "lazy" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CTERM],jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+3*BUTTH,
-+ "termall" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CSEGS],jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+4*BUTTH,
-+ "segsym" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CVCAU],jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+5*BUTTH,
-+ "vcausal" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CPTRM],jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+6*BUTTH,
-+ "pterm" ,infofg,infobg,hicol,locol);
-+ CBCreate(&chkbut[J_CRSTP],jp2kW,
-+ 10,10+ASCENT+SPACING+2*LINEHIGH+7*BUTTH,
-+ "resetprob",infofg,infobg,hicol,locol);
-+ /* Create text subwindows for unsigned decimal integer values. */
-+
-+ text[J_TGBIT] = XCreateSimpleWindow(theDisp,jp2kW,
-+ JP2KW-TEXTW-10,10+ASCENT+SPACING+2*LINEHIGH+3*MENUH+0*TEXTH,TEXTW,TEXTH,
-+ 1,infofg,infobg);
-+ XSelectInput(theDisp,text[J_TGBIT],ExposureMask|KeyPressMask);
-+ text[J_TRES ] = XCreateSimpleWindow(theDisp,jp2kW,
-+ JP2KW-TEXTW-10,10+ASCENT+SPACING+2*LINEHIGH+3*MENUH+1*TEXTH,TEXTW,TEXTH,
-+ 1,infofg,infobg);
-+ XSelectInput(theDisp,text[J_TRES ],ExposureMask|KeyPressMask);
-+ text[J_TRATE] = XCreateSimpleWindow(theDisp,jp2kW,
-+ JP2KW-TEXTW-10,10+ASCENT+SPACING+2*LINEHIGH+3*MENUH+2*TEXTH,TEXTW,TEXTH,
-+ 1,infofg,infobg);
-+ XSelectInput(theDisp,text[J_TRATE],ExposureMask|KeyPressMask);
-+
-+ /* Create a row of 2 boolean-valued radio buttons (for the "Rate" subwindow
-+ value's unit of measure). The 1st button is "selected" by default.
-+ */
-+ radio = RBCreate(0,jp2kW,
-+ JP2KW-19*RBUTW/8-10,10+ASCENT+SPACING+2*LINEHIGH+3*MENUH+3*TEXTH+4,
-+ "Percent",infofg,infobg,hicol,locol);
-+ (void)RBCreate(radio,jp2kW,
-+ JP2KW-1*RBUTW-10 ,10+ASCENT+SPACING+2*LINEHIGH+3*MENUH+3*TEXTH+4,
-+ "Bytes",infofg,infobg,hicol,locol);
-+
-+ /* Create pop-up menu-selection buttons after mapping the above subwindows,
-+ since we don't want the pop-up menus mapped unless the corresponding button
-+ is selected.
-+ */
-+ XMapSubwindows(theDisp,jp2kW);
-+ MBCreate(&menu[J_MCBXW],jp2kW,
-+ JP2KW-2*MENUW-10,10+ASCENT+SPACING+2*LINEHIGH+0*MENUH,MENUW,MENUH,
-+ wstr ,CBoxList,sizeof CBoxList/sizeof *CBoxList,infofg,infobg,
-+ hicol,locol);
-+ MBCreate(&menu[J_MCBXH],jp2kW,
-+ JP2KW-2*MENUW-10,10+ASCENT+SPACING+2*LINEHIGH+1*MENUH,MENUW,MENUH,
-+ hstr ,CBoxList,sizeof CBoxList/sizeof *CBoxList,infofg,infobg,
-+ hicol,locol);
-+ MBCreate(&menu[J_MPREW],jp2kW,
-+ JP2KW-1*MENUW-10,10+ASCENT+SPACING+2*LINEHIGH+0*MENUH,MENUW,MENUH,
-+ wstr ,PrecList,sizeof PrecList/sizeof *PrecList,infofg,infobg,
-+ hicol,locol);
-+ MBCreate(&menu[J_MPREH],jp2kW,
-+ JP2KW-1*MENUW-10,10+ASCENT+SPACING+2*LINEHIGH+1*MENUH,MENUW,MENUH,
-+ hstr ,PrecList,sizeof PrecList/sizeof *PrecList,infofg,infobg,
-+ hicol,locol);
-+ MBCreate(&menu[J_MPROG],jp2kW,
-+ JP2KW-1*MENUW-10,10+ASCENT+SPACING+2*LINEHIGH+2*MENUH,MENUW,MENUH,
-+ "Order",ProgList,sizeof ProgList/sizeof *ProgList,infofg,infobg,
-+ hicol,locol);
-+
-+ /* Initialize values represented by widgets, which should correspond to default
-+ compiled into the JasPer Library. Unfortunately, as of Version 1.701 there
-+ is no easy way for an application to extract these from the library, so the
-+ following code might get out of sync over time:
-+ */
-+ menu[J_MCBXW].hascheck = 1; menu[J_MCBXW].flags[ 5] = 1;
-+ menu[J_MCBXH].hascheck = 1; menu[J_MCBXH].flags[ 5] = 1;
-+ menu[J_MPREW].hascheck = 1; menu[J_MPREW].flags[15] = 1;
-+ menu[J_MPREH].hascheck = 1; menu[J_MPREH].flags[15] = 1;
-+ menu[J_MPROG].hascheck = 1; menu[J_MPROG].flags[ 0] = 1;
-+ textval[J_TGBIT] = 2; /* No. of guard bits */
-+ textval[J_TRES ] = 6; /* Max. no. of resolution levels */
-+ textval[J_TRATE] = 100; /* Rate = 100% */
-+}
-+
-+void JP2KSaveParams(int fmt,char *fname,int col) /* Save output-file parms */
-+{
-+ format = fmt; /* Desired file format: F_JPC|F_JP2 */
-+ fbasename = fname; /* ->Output file path */
-+ colorType = col; /* Desired color space: F_GREYSCALE|... */
-+}
-+
-+static void StoreJP2K(char *options)
-+{
-+ static jas_image_cmptparm_t parm[3]= /* Image parameters */
-+ {{0,0,1,1,0,0,8,0},{0,0,1,1,0,0,8,0},{0,0,1,1,0,0,8,0}};
-+ static char nomem[]={"StoreJP2K: out of memory\n"},
-+ write[]={"w"};
-+ jas_image_t *img;
-+ jas_stream_t *str;
-+ FILE *fp, *fp2;
-+ byte *pic, *r, *g, *b;
-+ const char *filename;
-+ char *iobuf = 0;
-+ unsigned long imagesize;
-+ jas_clrspc_t color_space;
-+ int nc, w, h, pfree, ptype, error = 1;
-+ register int i;
-+
-+ /* This is a generic subroutine for writing JPEG 2000 image files using the
-+ JasPer Library. Our argument is an ASCII string, containing a Space (" ")-
-+ separated sequence of encoder options that currently aren't well documented.
-+ Most of the work is identical for both ".jpc" and ".jp2" files. Start by
-+ verifying that the output file can be opened, then get an image buffer from
-+ XV and begin crunching it into a suitable form for the JasPer Library.
-+ */
-+ if (!(fp = OpenOutFile(filename = fbasename))) return; /* Oops! */
-+ setbuf(fp,0); /* We don't really use this file pointer for I/O; see below */
-+ fbasename = BaseName(filename);
-+ WaitCursor();
-+ pic = GenSavePic(&ptype,&w,&h,&pfree,&nc,&r,&g,&b);
-+ imagesize = w*h;
-+ if (ptype == PIC24) imagesize *= 3;
-+
-+ /* As an optimization to save file space, even if our user didn't ask to store
-+ a gray-scale image, check whether we could and, if so, do it anyway.
-+ */
-+ if (colorType != F_GREYSCALE) /* can we force a gray-scale image? */
-+ {
-+ if (ptype == PIC8)
-+ {
-+ i = nc;
-+ while (--i >= 0 && r[i] == g[i] && r[i] == b[i]);
-+ }
-+ else /* PIC24 */
-+ { register byte *p = pic + imagesize;
-+
-+ while ((p -= 3) >= pic && p[0] == p[1] && p[0] == p[2]);
-+ i = p-pic;
-+ };
-+ if (i < 0) colorType = F_GREYSCALE; /* We made it all the way through */
-+ };
-+
-+ /* If XV is currently color-mapping the image, make a color-mapped copy so that
-+ the map needn't be transmitted in the output file.
-+ */
-+ if ((i = (colorType != F_GREYSCALE) << 1 | (ptype != PIC8)) != 3)
-+ { byte *tmp = pic, *last = pic + imagesize;
-+ register byte *from = tmp, *to = pic;
-+
-+ if (!(pic = (byte *)malloc(imagesize))) FatalError(nomem);
-+ switch (i)
-+ {
-+
-+ /* Color-map 8->8 bit image. */
-+
-+ case 0: do
-+ {
-+ i = *from;
-+ *to++ = MONO(r[i],g[i],b[i]);
-+ }
-+ while (++from < last);
-+ break;
-+
-+ /* Color-map 24->8 bit image. */
-+
-+ case 1: do *to++ = MONO(from[0],from[1],from[2]);
-+ while ((from += 3) < last);
-+ break;
-+
-+ /* Color-map 8->24 bit image. */
-+
-+ case 2: do
-+ {
-+ i = *from;
-+ *to++ = r[i]; *to++ = g[i]; *to++ = b[i];
-+ }
-+ while (++from < last);
-+ break;
-+ };
-+ if (pfree) free(tmp); /* Release the original image buffer if we can */
-+ pfree = 1; /* Let the modified buffer be released later */
-+ };
-+
-+ /* Initialize various image-file parameter variables. */
-+
-+ parm[0].width = w;
-+ parm[0].height = h;
-+ if (colorType == F_GREYSCALE) /* gray-scale image */
-+ {
-+ ptype = 1; /* No. of color planes */
-+ color_space = JAS_CLRSPC_SGRAY;
-+ }
-+ else /* RGB color image */
-+ {
-+ ptype = 3; /* No. of color planes */
-+ color_space = JAS_CLRSPC_SRGB;
-+ parm[2].width = parm[1].width = parm[0].width;
-+ parm[2].height = parm[1].height = parm[0].height;
-+ };
-+
-+ /* Now comes a egregious hack: The JasPer Library will eventually want to
-+ close the output file that it writes, but since XV opened the file, XV also
-+ thinks it has the right to close the file! In order to pacify them both,
-+ we duplicate the file pointer and let the JasPer Library have it, while we
-+ retain the original for XV.
-+
-+ XXX This code is very UNIX-specific; what's an equivalent hack for Windows?
-+ */
-+ if (!(fp2 = (i = dup(fileno(fp))) >= 0 ? fdopen(i,write) : 0))
-+ FatalError("StoreJP2K: can't duplicate output file pointer\n");
-+ if (!(iobuf = SetBuf(fp2)))
-+ {
-+ (void)fclose(fp2);
-+ FatalError(nomem);
-+ };
-+
-+ /* Hand our output file to the JasPer Library and create an image object.
-+ "jas_stream_close()" will eventually close our output file, so only do it
-+ explicitly if no stream can be created. If everything looks copacetic,
-+ then write our buffer contents to the image components' streams.
-+ */
-+ if (!(str = jas_stream_freopen(filename,write,fp2)))
-+ {
-+ (void)fclose(fp2);
-+ FatalError("StoreJP2K: can't open output stream\n");
-+ };
-+ if (!(img = jas_image_create(ptype,parm,color_space))) goto L2;
-+ if (ptype == 1)
-+ { register jas_stream_t *c = img->cmpts_[0]->stream_;
-+ register byte *p = pic;
-+
-+ /* Since this is a 1-plane image, avoid a lot of errant nonsense in the
-+ JasPer Library by sequentially writing all of the data directly from our
-+ buffer.
-+ */
-+ jas_image_setcmpttype(img,0,JAS_IMAGE_CT_GRAY_Y);
-+ img->cmpts_[0]->type_ = JAS_IMAGE_CT_GRAY_Y;
-+ do if ((i = (*c->ops_->write_)(c->obj_,(char *)p,imagesize)) <= 0)
-+ goto L1;
-+ while ((p += i),(imagesize -= i) > 0);
-+ if (jas_stream_flush(c) < 0) goto L1;
-+ }
-+ else /* RGB color image */
-+ {
-+
-+ /* Writing color images is inefficient because JPEG 2000 wants to partition
-+ file data into separate image planes (colors), while XV wants data
-+ samples from each plane to be interleaved as 3-byte pixels. Apparently
-+ the fastest method consists of 3 passes through the XV image buffer,
-+ from which we extract the bytes of each component.
-+ */
-+ i = 0;
-+ do /* each color component */
-+ { long npix = imagesize/3;
-+ register jas_stream_t *c = img->cmpts_[i]->stream_;
-+ register byte *p = pic + i;
-+
-+ jas_image_setcmpttype(img,i,i+JAS_IMAGE_CT_RGB_R);
-+ do if (jas_stream_putc(c,*p) < 0) goto L1;
-+ while ((p += 3),--npix > 0);
-+ if (jas_stream_flush(c) < 0) goto L1;
-+ }
-+ while (++i <= 2);
-+ };
-+ if ( (*(format == F_JPC ? jpc_encode : jp2_encode))(img,str,options) >= 0
-+ && jas_stream_flush(str) >= 0
-+ ) error = 0; /* Success! */
-+L1: jas_image_destroy(img);
-+L2: (void)jas_stream_close(str);
-+ if (iobuf) free(iobuf);
-+ if (pfree) free(pic);
-+ if (!CloseOutFile(fp,filename,error)) DirBox(0);
-+ SetCursors(-1);
-+}
-+
-+void JP2KDialog(int vis)
-+{
-+ if ((jp2kUp = vis)) CenterMapWindow(jp2kW,0,0,JP2KW,JP2KH);
-+ else XUnmapWindow(theDisp,jp2kW);
-+}
-+
-+static void TWRedraw(Window w,unsigned int val)
-+{
-+ char buf[11];
-+ register int i;
-+
-+ /* Draw a 1-line numeric text string in the specified window, representing the
-+ argument value as a left-justified unsigned decimal integer, followed by a
-+ "cursor" icon.
-+ */
-+ sprintf(buf,"%u",val);
-+ if (ctrlColor) XClearArea(theDisp,w,2,2,TEXTW-4,TEXTH-4,False);
-+ else XClearWindow(theDisp,w);
-+ Draw3dRect(w,0,0,TEXTW-1,TEXTH-1,R3D_IN,2,hicol,locol,infobg);
-+ XSetForeground(theDisp,theGC,infofg);
-+ XDrawString(theDisp,w,theGC,3,ASCENT+3,buf,i = strlen(buf));
-+
-+ /* Draw a "cursor" icon after the numeric string. */
-+
-+ i = XTextWidth(mfinfo,buf,i);
-+ XDrawLine(theDisp,w,theGC,i+3,2 ,i+3,2+CHIGH+1);
-+ XDrawLine(theDisp,w,theGC,i+3,2+CHIGH+1,i+5,2+CHIGH+3);
-+ XDrawLine(theDisp,w,theGC,i+3,2+CHIGH+1,i+1,2+CHIGH+3);
-+}
-+
-+int JP2KCheckEvent(register XEvent *xev)
-+{
-+ int ok = 0;
-+
-+ /* Check whether the argument "X Windows" event is for one of our subwindows.
-+ If it is, handle the event and return 1; otherwise, return 0.
-+ */
-+ if (!jp2kUp) return 0;
-+ switch (xev->type)
-+ { KeySym ks;
-+ int len;
-+ char buf[128];
-+ register int i;
-+
-+ /* Throw away excess "expose" events for "dumb" windows. */
-+
-+ case Expose :
-+# define E ((XExposeEvent *)xev)
-+ if (E->window == jp2kW)
-+ { XRectangle rect;
-+
-+ rect.x = E->x ; rect.y = E->y ;
-+ rect.width = E->width; rect.height = E->height;
-+ XSetClipRectangles(theDisp,theGC,0,0,&rect,1,Unsorted);
-+ XSetForeground(theDisp,theGC,infofg);
-+ XSetBackground(theDisp,theGC,infobg);
-+ i = sizeof button/sizeof *button;
-+ while (--i >= 0) BTRedraw(&button[i]);
-+ i = sizeof chkbut/sizeof *chkbut;
-+ while (--i >= 0) CBRedraw(&chkbut[i]);
-+ i = sizeof menu/sizeof *menu;
-+ while (--i >= 0) MBRedraw(&menu[i]);
-+ RBRedraw(radio,-1);
-+ DrawString(jp2kW,10,10+ASCENT,"Save JPEG 2000 File...");
-+ DrawString(jp2kW,10,10+ASCENT+2*LINEHIGH,"Style options:");
-+ DrawString(jp2kW,JP2KW-2*MENUW-10,10+ASCENT+2*LINEHIGH,
-+ "Coding Blk");
-+ DrawString(jp2kW,JP2KW-1*MENUW-10,10+ASCENT+2*LINEHIGH,
-+ " Precinct");
-+ DrawString(jp2kW,
-+ JP2KW-2*MENUW-10,10+ASCENT+SPACING+3*LINEHIGH+2*MENUH,
-+ "Progression:");
-+ DrawString(jp2kW,
-+ JP2KW-2*TEXTW-10,10+ASCENT+SPACING+3*LINEHIGH+3*MENUH+0*TEXTH,
-+ "Guard bits:");
-+ DrawString(jp2kW,
-+ JP2KW-2*TEXTW-10,10+ASCENT+SPACING+3*LINEHIGH+3*MENUH+1*TEXTH,
-+ "Res levels:");
-+ DrawString(jp2kW,
-+ JP2KW-2*TEXTW-10,10+ASCENT+SPACING+3*LINEHIGH+3*MENUH+2*TEXTH,
-+ "Rate:");
-+ XSetClipMask(theDisp,theGC,None);
-+ ok = 1;
-+ break;
-+ };
-+ i = sizeof text/sizeof *text;
-+ while (--i >= 0 && E->window != text[i]);
-+ if (i >= 0)
-+ {
-+ TWRedraw(E->window,textval[i]);
-+ ok = 1;
-+ };
-+ break;
-+# undef E
-+
-+ /* Check whether the user pressed one of our buttons. */
-+
-+ case ButtonPress:
-+# define E ((XButtonEvent *)xev)
-+ if (E->button == Button1 && E->window == jp2kW)
-+ { register int j;
-+
-+ ok = 1; /* Check whether a regular button was pressed */
-+ i = sizeof button/sizeof *button;
-+ while ( --i >= 0
-+ && !PTINRECT(E->x,E->y,button[i].x,button[i].y,button[i].w,button[i].h)
-+ );
-+ if (i >= 0) /* our button was pressed */
-+ { char options[1024];
-+ register char *p;
-+ register const char *q;
-+
-+ if (!BTTrack(&button[i])) break; /* Ignore it */
-+ if (i != J_BOK) /* must be "Cancel" button */
-+ {
-+ JP2KDialog(0);
-+ break;
-+ };
-+
-+ /* Our user hit the "Ok" button. At this point, we have an ugly
-+ job to do: JasPer Library encoder options must be specified
-+ as an ASCII string of Space (" ")-separated [=]
-+ entries, so we must collect the values of all of our widgets
-+ and subwindows, determine whether our user has requested any
-+ non-default values, then build the string only for the JasPer
-+ Library to immediately tear it apart again. Yechh!
-+ */
-+ if ((unsigned)textval[J_TGBIT]-1 > 7)
-+ {
-+ OpenAlert("No. of guard bits must be 1-8");
-+ sleep(3);
-+ CloseAlert();
-+ break;
-+ };
-+ if ((unsigned)textval[J_TRES ] <= 0)
-+ {
-+ OpenAlert("Maximum resolution levels must be >= 1");
-+ sleep(3);
-+ CloseAlert();
-+ break;
-+ };
-+
-+ /* XXX Should we check and complain if the rate is zero?
-+ JasPer Library Version 1.701 apparently accepts that
-+ value, even though it seems kinda weird.
-+ */
-+ p = options;
-+ i = 0;
-+ do if ((j = MBWhich(&menu[i])) != 5)
-+ { static const char *parm[2] =
-+ {"cblkwidth=%u", "cblkheight=%u"};
-+
-+ if (p > options) *p++ = ' ';
-+ sprintf(p,parm[i-J_MCBXW],++j);
-+ while (*++p);
-+ }
-+ while (++i <= J_MCBXH);
-+ do if ((j = MBWhich(&menu[i])) < 15)
-+ { static const char *parm[2] =
-+ {"prcwidth=%u", "prcheight=%u"};
-+
-+ if (p > options) *p++ = ' ';
-+ sprintf(p,parm[i-J_MPREW],j);
-+ while (*++p);
-+ }
-+ while (++i <= J_MPREH);
-+ if ((j = MBWhich(&menu[i])))
-+ {
-+ if (p > options) *p++ = ' ';
-+ *p++ = 'p'; *p++ = 'r'; *p++ = 'g'; *p = '=';
-+ q = ProgList[j];
-+ while ((*++p = *q++));
-+ };
-+ if ((i = textval[J_TRES ]) != 6)
-+ {
-+ if (p > options) *p++ = ' ';
-+ sprintf(p,"numrlvls=%u",i);
-+ while (*++p);
-+ };
-+ i = 0;
-+ do if (chkbut[i].val) /* append this encoding option */
-+ {
-+ if (p > options) *p++ = ' ';
-+ q = chkbut[i].str;
-+ while ((*p++ = *q++));
-+ *--p = '\000';
-+ }
-+ while (++i < sizeof chkbut/sizeof *chkbut);
-+ if ((i = textval[J_TGBIT]) != 2)
-+ {
-+ if (p > options) *p++ = ' ';
-+ sprintf(p,"numgbits=%u",i);
-+ while (*++p);
-+ };
-+ if ((i = textval[J_TRATE]) != 100)
-+ {
-+ if (p > options) *p++ = ' ';
-+ *p++ = 'r'; *p++ = 'a'; *p++ = 't'; *p++ = 'e';
-+ *p++ = '=';
-+ if (i) /* non-zero rate */
-+ {
-+ if (RBWhich(radio)) sprintf(p,"%uB",i); /* # Bytes */
-+ else /* the value is a percentage */
-+ {
-+ if (i > 100) i = 200; /* => Raw size + 1 */
-+ sprintf(p,"%u.%.2u",i/100,i%100);
-+ }
-+ while (*++p);
-+ }
-+ else /* rate = 0 */
-+ {
-+
-+ /* XXX This is apparently valid, since JasPer Library
-+ Version 1.701 doesn't complain about it.
-+ */
-+ *p++ = '0';
-+ *p = '\000';
-+ }
-+ };
-+ StoreJP2K(options); /* Finally, do the *real* work! */
-+ JP2KDialog(0);
-+ p = GetDirFullName();
-+ if (!ISPIPE(*p))
-+ {
-+ XVCreatedFile(p);
-+ StickInCtrlList(0);
-+ };
-+ break;
-+ };
-+
-+ /* See whether a check-box button was pressed. */
-+
-+ i = sizeof chkbut/sizeof *chkbut;
-+ while (--i >= 0 && !CBClick(&chkbut[i],E->x,E->y));
-+ if (i >= 0) /* our button was pressed */
-+ {
-+ (void)CBTrack(&chkbut[i]);
-+ break;
-+ };
-+
-+ /* See whether a menu button was pressed. */
-+
-+ i = sizeof menu/sizeof *menu;
-+ while (--i >= 0 && !MBClick(&menu[i],E->x,E->y));
-+ if (i >= 0) /* our button was pressed */
-+ { register int j;
-+
-+ if ((j = MBTrack(&menu[i])) >= 0)
-+ {
-+ switch (i)
-+ {
-+
-+ /* The JasPer Library constrains a coding box's area
-+ (width x height) to be <= 4096 pixels, so if this
-+ button-press would violate that condition, then
-+ quietly limit the box's orthogonal dimension by just
-+ enough to compensate.
-+ */
-+ case J_MCBXH:
-+ case J_MCBXW: if (MBWhich(&menu[!i]) + j >= 10)
-+ MBSelect(&menu[!i],10 - j);
-+ };
-+ MBSelect(&menu[i],j);
-+ MBSetActive(&menu[i],1);
-+ };
-+ break;
-+ };
-+
-+ /* See whether a radio button was pressed. */
-+
-+ if ( (i = RBClick(radio,E->x,E->y)) >= 0 /* button pressed */
-+ && RBTrack(radio,i)
-+ )
-+ {
-+ RBSelect(radio,i);
-+ RBSetActive(radio,i,1);
-+ };
-+ break;
-+ };
-+ XBell(theDisp,50);
-+ break;
-+# undef E
-+
-+ /* Translate a few key-press events into simulated button events. */
-+
-+ case KeyPress :
-+# define E ((XKeyEvent *)xev)
-+ buf[len = XLookupString(E,buf,sizeof buf,&ks,0)] = '\000';
-+ RemapKeyCheck(ks,buf,&len);
-+ if (E->window == jp2kW)
-+ {
-+ ok = 1;
-+ if (len > 0)
-+ switch (buf[0])
-+ {
-+ case '\r' :
-+ case '\n' : FakeButtonPress(&button[J_BOK ]);
-+ break;
-+ case '\033': FakeButtonPress(&button[J_BCANC]);
-+ };
-+ break;
-+ };
-+ i = sizeof text/sizeof *text;
-+ while (--i >= 0 && E->window != text[i]);
-+ if (i >= 0) /* a key was pressed in our text window */
-+ { int oldval = textval[i]; /* Save this subwindow's old value */
-+ register int c, j = 0;
-+
-+ /* This is a *very* simple text-input editing loop that assembles an
-+ an unsigned integer from successive ASCII decimal digits, typed
-+ into one of our 1-line subwindows. For convenience, the only
-+ character recognized is Backspace.
-+ */
-+ ok = 1;
-+ L: if (j >= len) break;
-+ if ((unsigned)(c = buf[j++] - '0') <= 9)
-+ {
-+ TWRedraw(text[i],textval[i] = textval[i]*10 + c);
-+ goto L;
-+ };
-+ if ((c += '0') == '\b')
-+ {
-+ TWRedraw(text[i],textval[i] = textval[i]/10);
-+ goto L;
-+ };
-+ textval[i] = oldval;
-+ };
-+ XBell(theDisp,50);
-+# undef E
-+ };
-+ return ok;
-+}
-+
-+
-+/*******************************************/
-+void
-+VersionInfoJP2K() /* GRR 20070304 */
-+{
-+ fprintf(stderr, " Compiled with libjasper %s; using libjasper %s.\n",
-+ JAS_VERSION, jas_getversion());
-+}
-+
-+#endif /* HAVE_JP2K */
-diff -u -r --new-file xv-3.10a.orig/xvmag.c xv-3.10a/xvmag.c
---- xv-3.10a.orig/xvmag.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvmag.c 2005-04-18 00:56:58.000000000 -0500
-@@ -0,0 +1,866 @@
-+/*
-+ * xvmag.c - load routine for `MAG' format pictures.
-+ *
-+ * The `MAG' format is used by many Japanese personal computer users.
-+ * This program is based on MAGBIBLE.DOC which is the specification
-+ * for `MAG' format written by Woody RINN. It is written in Japanese,
-+ * and exists in some anon-ftp sites.
-+ */
-+
-+#include "xv.h"
-+#include
-+
-+#ifdef HAVE_MAG
-+
-+typedef unsigned short data16;
-+
-+struct mag {
-+ jmp_buf jmp;
-+ FILE *fp;
-+ long fsize;
-+ int m_256, m_dig, m_8, m_200;
-+ int x1, y1, x2, y2, left_pad, right_pad;
-+ int p_width, p_height, width, height;
-+ long h_off, a_off, a_size, b_off, b_size, p_off, p_size;
-+ byte *a, *b, *p;
-+};
-+
-+static void mag_open_file PARM((struct mag*, char*));
-+static void mag_read_check_data PARM((struct mag*));
-+static void mag_read_comment PARM((struct mag*, char**));
-+static void mag_read_header PARM((struct mag*));
-+static void mag_read_palette PARM((struct mag*, byte*, byte*, byte*));
-+static void mag_read_flags PARM((struct mag*));
-+static void mag_read_pixel_data PARM((struct mag*));
-+static void mag_expand_body PARM((struct mag*, byte**));
-+
-+static void mag_compress_data PARM((struct mag*, byte*));
-+static void mag_write_check_data PARM((struct mag*));
-+static void mag_write_comment PARM((struct mag*, char *));
-+static void mag_write_palette PARM((struct mag*, int,
-+ byte*, byte*, byte*, int));
-+static void mag_write_flags PARM((struct mag*));
-+static void mag_write_pixel_data PARM((struct mag*));
-+static void mag_write_header PARM((struct mag*));
-+static void mag_set_double_word PARM((long, byte *));
-+
-+static void mag_init_info PARM((struct mag*));
-+static void mag_cleanup_mag_info PARM((struct mag*, int));
-+static void mag_cleanup_pinfo PARM((PICINFO*));
-+static void mag_memory_error PARM((char*, char*));
-+static void mag_error PARM((struct mag*, int));
-+static void mag_file_error PARM((struct mag*, int));
-+static void mag_file_warning PARM((struct mag*, int));
-+static void mag_show_struct PARM((struct mag*));
-+static void *mag_malloc PARM((size_t, char*));
-+static void *mag_realloc PARM((void*, size_t, char*));
-+
-+
-+static char *mag_id = "MAKI02 ";
-+static struct{
-+ int dx, dy;
-+}points[16] = {
-+ { 0, 0}, { 1, 0}, { 2, 0}, { 4, 0},
-+ { 0, 1}, { 1, 1},
-+ { 0, 2}, { 1, 2}, { 2, 2},
-+ { 0, 4}, { 1, 4}, { 2, 4},
-+ { 0, 8}, { 1, 8}, { 2, 8},
-+ { 0, 16},
-+};
-+static int try[15] = {1, 4, 5, 6, 7, 9, 10, 2, 8, 11, 12, 13, 14, 3, 15};
-+
-+static char *mag_msgs[] = {
-+ NULL,
-+#define MAG_OPEN 1
-+ "can't open file",
-+#define MAG_CORRUPT 2
-+ "file currupted.",
-+#define MAG_FORMAT 3
-+ "not MAG format.",
-+#define MAG_WRITE 4
-+ "write failed.",
-+};
-+
-+
-+#define H4(x) (((int) (x) >> 4) & 0x0f) /* operates on a byte */
-+#define L4(x) ((x) & 0x0f)
-+#define H8(x) (((x) >> 8) & 0xff) /* operates on a data16 */
-+#define L8(x) ((x) & 0xff)
-+
-+#define error(msgnum) longjmp(mi->jmp, msgnum)
-+
-+
-+/* The main routine to load a MAG file. */
-+int LoadMAG(fname, pinfo)
-+ char *fname;
-+ PICINFO *pinfo;
-+{
-+ struct mag mag;
-+ int e;
-+
-+ if(DEBUG) fputs("LoadMAG:\n", stderr);
-+
-+ pinfo->comment = NULL;
-+ mag_init_info(&mag);
-+ if((e = setjmp(mag.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ mag_cleanup_mag_info(&mag, 0);
-+ mag_cleanup_pinfo(pinfo);
-+ return 0;
-+ }
-+
-+ mag_open_file(&mag, fname);
-+ mag_read_check_data(&mag);
-+ mag_read_comment(&mag, &pinfo->comment);
-+ mag_read_header(&mag);
-+ mag_read_palette(&mag, pinfo->r, pinfo->g, pinfo->b);
-+ mag_read_flags(&mag);
-+ mag_read_pixel_data(&mag);
-+ mag_expand_body(&mag, &pinfo->pic);
-+
-+ pinfo->w = pinfo->normw = mag.width;
-+ pinfo->h = pinfo->normh = mag.height;
-+ pinfo->type = PIC8;
-+ pinfo->frmType = F_MAG;
-+ pinfo->colType = F_FULLCOLOR;
-+ sprintf(pinfo->fullInfo, "MAG, %d colors%s (%ld bytes)",
-+ mag.m_256 ? 256 : (mag.m_8 ? 8 : 16),
-+ mag.m_200 ? ", aspect 0.5" : "", mag.fsize);
-+ sprintf(pinfo->shrtInfo, "%dx%d MAG", mag.width, mag.height);
-+ if(mag.m_200)
-+ normaspect = 0.5;
-+
-+ mag_cleanup_mag_info(&mag, 0);
-+ return 1;
-+}
-+
-+static void mag_open_file(mi, fname)
-+ struct mag *mi;
-+ char *fname;
-+{
-+ if((mi->fp = fopen(fname, "rb")) == NULL)
-+ mag_file_error(mi, MAG_OPEN);
-+ fseek(mi->fp, (size_t) 0, SEEK_END);
-+ mi->fsize = ftell(mi->fp);
-+ fseek(mi->fp, (size_t) 0, SEEK_SET);
-+}
-+
-+static void mag_read_check_data(mi)
-+ struct mag *mi;
-+{
-+ char buffer[8];
-+
-+ if(fread(buffer, (size_t) 8, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_CORRUPT);
-+ if(strncmp(buffer, mag_id, (size_t) 8) != 0)
-+ mag_error(mi, MAG_FORMAT);
-+}
-+
-+static void mag_read_comment(mi, p)
-+ struct mag *mi;
-+ char **p;
-+{
-+ int max = -1, i = 0;
-+ int c;
-+
-+ while((c = fgetc(mi->fp)) != EOF){
-+ if(c == 0x1a)
-+ break;
-+ if(max < i){
-+ max += 16;
-+ *p = mag_realloc(*p, (size_t) max + 1, "mag_read_comment#1");
-+ }
-+ (*p)[i++] = c;
-+ }
-+
-+ if(c == EOF)
-+ mag_file_error(mi, MAG_CORRUPT);
-+
-+ if(max < i){
-+ *p = mag_realloc(*p, (size_t) max + 2, "mag_read_comment#2");
-+ }
-+ if(i > 24){
-+ (*p)[i] = '\0';
-+ strcpy(*p, &(*p)[24]);
-+ }else{
-+ (*p)[0] = '\0';
-+ }
-+}
-+
-+static void mag_read_header(mi)
-+ struct mag *mi;
-+{
-+ byte buf[32];
-+
-+ mi->h_off = ftell(mi->fp);
-+
-+ if(fread(buf, (size_t) 32, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_CORRUPT);
-+
-+ mi->m_256 = buf[3] & 0x80;
-+ mi->m_dig = buf[3] & 0x04;
-+ mi->m_8 = buf[3] & 0x02;
-+ mi->m_200 = buf[3] & 0x01;
-+
-+ mi->x1 = buf[ 4] + buf[ 5] * 256;
-+ mi->y1 = buf[ 6] + buf[ 7] * 256;
-+ mi->x2 = buf[ 8] + buf[ 9] * 256;
-+ mi->y2 = buf[10] + buf[11] * 256;
-+
-+#define get_dword(a, b, c, d) \
-+ ((long)(a) << 24 | (long)(b) << 16 | (long)(c) << 8 | (long)(d))
-+
-+ mi->a_off = get_dword(buf[15], buf[14], buf[13], buf[12]);
-+ mi->b_off = get_dword(buf[19], buf[18], buf[17], buf[16]);
-+ mi->b_size = get_dword(buf[23], buf[22], buf[21], buf[20]);
-+ mi->p_off = get_dword(buf[27], buf[26], buf[25], buf[24]);
-+ mi->p_size = get_dword(buf[31], buf[30], buf[29], buf[28]);
-+#undef get_dword
-+
-+ mi->a_size = mi->b_off - mi->a_off;
-+ mi->a_off += mi->h_off;
-+ mi->b_off += mi->h_off;
-+ mi->p_off += mi->h_off;
-+
-+ mi->width = mi->x2 - mi->x1 + 1;
-+ mi->height = mi->y2 - mi->y1 + 1;
-+ mi->left_pad = mi->x1 & 07;
-+ mi->right_pad = 07 - (mi->x2 & 07);
-+ mi->x1 -= mi->left_pad; /* x1 = 8m */
-+ mi->x2 += mi->right_pad; /* x2 = 8n+7 */
-+ mi->p_width = ((mi->x2 + 1) - mi->x1) / (mi->m_256 ? 2 : 4);
-+ mi->p_height = (mi->y2 + 1) - mi->y1;
-+
-+ if(DEBUG) mag_show_struct(mi);
-+}
-+
-+static void mag_read_palette(mi, r, g, b)
-+ struct mag *mi;
-+ byte *r, *g, *b;
-+{
-+ int num_palettes;
-+ byte *buf;
-+
-+ if(mi->m_256)
-+ num_palettes = 256;
-+ else
-+ num_palettes = 16;
-+
-+ buf = mag_malloc((size_t)num_palettes * 3, "mag_read_palette");
-+
-+ if(fread(buf, (size_t) 3, (size_t) num_palettes, mi->fp) != num_palettes){
-+ free(buf);
-+ mag_file_error(mi, MAG_CORRUPT);
-+ }
-+
-+ for(num_palettes--; num_palettes >= 0; num_palettes--){
-+ g[num_palettes] = buf[num_palettes * 3 ];
-+ r[num_palettes] = buf[num_palettes * 3 + 1];
-+ b[num_palettes] = buf[num_palettes * 3 + 2];
-+ }
-+
-+ free(buf);
-+}
-+
-+static void mag_read_flags(mi)
-+ struct mag *mi;
-+{
-+ mi->a = mag_malloc((size_t) mi->a_size, "mag_read_flags#1");
-+ mi->b = mag_malloc((size_t) mi->b_size, "mag_read_flags#2");
-+
-+ fseek(mi->fp, mi->a_off, SEEK_SET);
-+ if(fread(mi->a, (size_t) mi->a_size, (size_t) 1, mi->fp) != 1)
-+ mag_file_warning(mi, MAG_CORRUPT);
-+ if(fread(mi->b, (size_t) mi->b_size, (size_t) 1, mi->fp) != 1)
-+ mag_file_warning(mi, MAG_CORRUPT);
-+}
-+
-+static void mag_read_pixel_data(mi)
-+ struct mag *mi;
-+{
-+ mi->p = mag_malloc((size_t) mi->p_size, "mag_read_pixel_data");
-+
-+ fseek(mi->fp, mi->p_off, SEEK_SET);
-+ if(fread(mi->p, (size_t) mi->p_size, (size_t) 1, mi->fp) != 1)
-+ mag_file_warning(mi, MAG_CORRUPT);
-+}
-+
-+/* MAG expanding routine */
-+static void mag_expand_body(mi, pic0)
-+ struct mag *mi;
-+ byte **pic0;
-+{
-+ int ai, bi, fi, pi;
-+ int px, py, x, y;
-+ byte *flag;
-+ byte mask;
-+ data16 *pixel0;
-+
-+ flag = mag_malloc((size_t) mi->p_width / 2, "mag_expand_body#1");
-+ *pic0 = mag_malloc((size_t) mi->width * mi->height, "mag_expand_body#2"); // GRR POSSIBLE OVERFLOW / FIXME
-+ pixel0 = mag_malloc((size_t) 2 * mi->p_width * 17, "mag_expand_body#3"); // GRR POSSIBLE OVERFLOW / FIXME
-+
-+#define pixel(x, y) pixel0[(y) % 17 * mi->p_width + (x)]
-+
-+ ai = bi = pi = 0;
-+ mask = 0x80;
-+ for(y = py = 0; py < mi->p_height; py++){
-+ for(fi = 0; fi < mi->p_width / 2; fi++){
-+ if(py == 0){
-+ if(mi->a[ai] & mask)
-+ flag[fi] = mi->b[bi++];
-+ else
-+ flag[fi] = 0;
-+ }else{
-+ if(mi->a[ai] & mask)
-+ flag[fi] ^= mi->b[bi++];
-+ }
-+ if((mask >>= 1) == 0){
-+ mask = 0x80;
-+ ai++;
-+ }
-+ }
-+
-+ for(px = fi = 0; fi < mi->p_width / 2; fi++){
-+ int f = H4(flag[fi]);
-+ if(f == 0){
-+ pixel(px, py) = mi->p[pi] + mi->p[pi + 1] * 256;
-+ px++;
-+ pi+=2;
-+ }else{
-+ int dx = points[f].dx, dy = points[f].dy;
-+ pixel(px, py) = pixel(px - dx, py - dy);
-+ px++;
-+ }
-+
-+ f = L4(flag[fi]);
-+ if(f == 0){
-+ pixel(px, py) = mi->p[pi] + mi->p[pi + 1] * 256;
-+ px++;
-+ pi+=2;
-+ }else{
-+ int dx = points[f].dx, dy = points[f].dy;
-+ pixel(px, py) = pixel(px - dx, py - dy);
-+ px++;
-+ }
-+ }
-+
-+#define inside(x) ((unsigned int)(x) < mi->width)
-+#define pic(x, y) (*pic0)[(y) * mi->width + (x)]
-+ for(x = -mi->left_pad, px = 0; px < mi->p_width; px++){
-+ data16 p = pixel(px, py);
-+ if(mi->m_256){
-+ if(inside(x))
-+ pic(x, y) = L8(p);
-+ x++;
-+ if(inside(x))
-+ pic(x, y) = H8(p);
-+ x++;
-+ }else{
-+ if(inside(x))
-+ pic(x, y) = H4(L8(p));
-+ x++;
-+ if(inside(x))
-+ pic(x, y) = L4(L8(p));
-+ x++;
-+ if(inside(x))
-+ pic(x, y) = H4(H8(p));
-+ x++;
-+ if(inside(x))
-+ pic(x, y) = L4(H8(p));
-+ x++;
-+ }
-+ }
-+ y++;
-+ }
-+#undef pic
-+#undef inside
-+#undef pixel
-+
-+ free(flag);
-+ free(pixel0);
-+}
-+
-+
-+/* The main routine to write a MAG file. */
-+int WriteMAG(fp, pic, ptype, w, h, rmap, gmap, bmap, numcols, colorstyle,
-+ comment)
-+ FILE *fp;
-+ byte *pic;
-+ int ptype, w, h;
-+ byte *rmap, *gmap, *bmap;
-+ int numcols, colorstyle;
-+ char *comment;
-+{
-+ byte rtemp[256], gtemp[256], btemp[256];
-+ struct mag mag;
-+ int e;
-+
-+ if(DEBUG) fputs("WriteMag\n", stderr);
-+
-+ mag_init_info(&mag);
-+ mag.fp = fp;
-+
-+ if(ptype == PIC24){
-+ if(!(pic = Conv24to8(pic, w, h, 256, rtemp, gtemp, btemp)))
-+ mag_memory_error("Conv24to8", "WriteMAG");
-+ rmap = rtemp;
-+ gmap = gtemp;
-+ bmap = btemp;
-+ numcols = 256;
-+ mag.m_256 = 1;
-+ }else{
-+ if(numcols > 16)
-+ mag.m_256 = 1;
-+ }
-+
-+ if((e = setjmp(mag.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ mag_cleanup_mag_info(&mag, 1);
-+ return -1;
-+ }
-+
-+ mag.x2 = w - 1;
-+ mag.y2 = h - 1;
-+ mag.right_pad = 07 - (mag.x2 & 07);
-+ mag.p_width = (w + mag.right_pad) / (mag.m_256 ? 2 : 4);
-+ mag.p_height = h;
-+ mag.width = w;
-+ mag.height = h;
-+ mag.a_size = (mag.p_width * mag.p_height + 15) / 16; /* x/2/8 */ // GRR POSSIBLE OVERFLOW / FIXME
-+ if(mag.a_size % 2)
-+ mag.a_size++;
-+
-+ mag_compress_data(&mag, pic);
-+ mag_write_check_data(&mag);
-+ mag_write_comment(&mag, comment);
-+
-+ mag.h_off = ftell(mag.fp);
-+
-+ mag_write_palette(&mag, numcols, rmap, gmap, bmap,
-+ colorstyle == F_GREYSCALE);
-+ mag_write_flags(&mag);
-+ mag_write_pixel_data(&mag);
-+ mag_write_header(&mag);
-+
-+ mag_cleanup_mag_info(&mag, 1);
-+ return 0;
-+}
-+
-+/* MAG compressing routine */
-+static void mag_compress_data(mi, pic0)
-+ struct mag *mi;
-+ byte *pic0;
-+{
-+ int ai, bi, pi, i;
-+ int bmax, pmax;
-+ byte mask;
-+ byte *flag0;
-+ data16 *pixel0;
-+ int px, py, x, y;
-+
-+ pixel0 = mag_malloc((size_t) 2 * mi->p_width * mi->p_height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "mag_compress_data#1");
-+ flag0 = mag_malloc((size_t) mi->p_width * mi->p_height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "mag_compress_data#2");
-+
-+#define pic(x, y) pic0[(y) * mi->width + (x)]
-+ /* convert dots to pixels */
-+ i = 0;
-+ for(y = py = 0; py < mi->p_height; py++){
-+ for(x = px = 0; px < mi->p_width; px++){
-+ data16 p = 0;
-+ if(mi->m_256){
-+ if(x < mi->width)
-+ p += pic(x, y);
-+ x++;
-+ if(x < mi->width)
-+ p += pic(x, y) * 256;
-+ x++;
-+ }else{
-+ if(x < mi->width)
-+ p += pic(x, y) * 16;
-+ x++;
-+ if(x < mi->width)
-+ p += pic(x, y);
-+ x++;
-+ if(x < mi->width)
-+ p += pic(x, y) * 4096;
-+ x++;
-+ if(x < mi->width)
-+ p += pic(x, y) * 256;
-+ x++;
-+ }
-+ pixel0[i++] = p;
-+ }
-+ y++;
-+ }
-+#undef pic
-+
-+#define pixel(x, y) pixel0[(y) * mi->p_width + (x)]
-+#define flag(x, y) flag0[(y) * mi->p_width + (x)]
-+ /* get flags */
-+ pmax = pi = 0;
-+ for(py = 0; py < mi->p_height; py++){
-+ for(px = 0; px < mi->p_width; px++){
-+ int t;
-+ for(t = 0; t < 15; t++){
-+ int dx = points[try[t]].dx, dy = points[try[t]].dy;
-+ if(dx <= px && dy <= py){
-+ if(pixel(px - dx, py - dy) == pixel(px, py))
-+ break;
-+ }
-+ }
-+ if(t < 15){
-+ flag(px, py) = try[t];
-+ }else{
-+ flag(px, py) = 0;
-+ if(pmax <= pi + 1){
-+ pmax += 128;
-+ mi->p = mag_realloc(mi->p, (size_t) pmax,
-+ "mag_compress_data#3");
-+ }
-+ mi->p[pi++] = L8(pixel(px, py));
-+ mi->p[pi++] = H8(pixel(px, py));
-+ }
-+ }
-+ }
-+#undef flag
-+#undef pixel
-+
-+ /* pack 2 flags into 1 byte */
-+ for(i = 0; i < mi->p_width / 2 * mi->p_height; i++)
-+ flag0[i] = flag0[i * 2] * 16 + flag0[i * 2 + 1];
-+
-+#define flag(x, y) flag0[(y) * mi->p_width / 2 + (x)]
-+ for(py = mi->p_height - 1; py >= 1; py--){
-+ for(px = 0; px < mi->p_width / 2; px++)
-+ flag(px, py) ^= flag(px, py - 1);
-+ }
-+#undef flag
-+
-+ mask = 0x80;
-+ ai = bi = bmax = 0;
-+ mi->a = mag_malloc((size_t) mi->a_size, "mag_compress_data#4"); // GRR POSSIBLE OVERFLOW / FIXME
-+ for(i = 0; i < mi->p_width / 2 * mi->p_height; i++){
-+ if(flag0[i] == 0){
-+ mi->a[ai] &= ~mask;
-+ }else{
-+ if(bmax == bi){
-+ bmax += 128;
-+ mi->b = mag_realloc(mi->b, (size_t) bmax,
-+ "mag_compress_data#4");
-+ }
-+ mi->b[bi++] = flag0[i];
-+ mi->a[ai] |= mask;
-+ }
-+
-+ if((mask >>= 1) == 0){
-+ mask = 0x80;
-+ ai++;
-+ }
-+ }
-+
-+ if(bi % 2)
-+ bi++;
-+ mi->b_size = bi;
-+
-+ mi->p_size = pi;
-+
-+ free(pixel0);
-+ free(flag0);
-+}
-+
-+static void mag_write_check_data(mi)
-+ struct mag *mi;
-+{
-+ if(fwrite(mag_id, (size_t) 8, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_WRITE);
-+}
-+
-+static void mag_write_comment(mi, comment)
-+ struct mag *mi;
-+ char *comment;
-+{
-+ char *p;
-+ int i;
-+
-+ if(fputs("XV ", mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+
-+ if((p = (char *) getenv("USER")) == NULL)
-+ p = "????????";
-+ for(i = 5; i < 24; i++){
-+ if(*p == '\0')
-+ break;
-+ if(fputc(*p++, mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+ for( ; i < 24; i++){
-+ if(fputc(' ', mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+
-+ if(comment){
-+ int l = strlen(comment);
-+ if(l > 0){
-+ int i;
-+ for(i = 0; i < l; i++){
-+ if(comment[i] == 0x1a)
-+ comment[i] = ' ';
-+ }
-+ if(fwrite(comment, (size_t) l, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+ }
-+
-+ if(fputc(0x1a, mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+}
-+
-+static void mag_write_palette(mi, num, r, g, b, grey)
-+ struct mag *mi;
-+ int num;
-+ byte *r, *g, *b;
-+ int grey;
-+{
-+ int i, left;
-+ char buf[3];
-+
-+ fseek(mi->fp, 32L, SEEK_CUR); /* skip header area */
-+ for(i = 0; i < num; i++){
-+ buf[0] = *g++;
-+ buf[1] = *r++;
-+ buf[2] = *b++;
-+ if(grey)
-+ buf[0] = buf[1] = buf[2] = MONO(buf[1], buf[0], buf[2]);
-+ if(fwrite(buf, (size_t) 3, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+ if(num < 16){
-+ left = 16 - num;
-+ }else if(num == 16){
-+ left = 0;
-+ }else if(num < 256){
-+ left = 256 - num;
-+ }else if(num == 256){
-+ left = 0;
-+ }else
-+ left = 0; /* shouldn't happen */
-+
-+ if(left > 0){
-+ for(i = 0; i < left; i++){
-+ if(fwrite(buf, (size_t) 3, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+ }
-+}
-+
-+static void mag_write_flags(mi)
-+ struct mag *mi;
-+{
-+ int i;
-+
-+ mi->a_off = ftell(mi->fp);
-+ for(i = 0; i < mi->a_size; i++){
-+ if(fputc(mi->a[i], mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+
-+ mi->b_off = ftell(mi->fp);
-+ for(i = 0; i < mi->b_size; i++){
-+ if(fputc(mi->b[i], mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+}
-+
-+static void mag_write_pixel_data(mi)
-+ struct mag *mi;
-+{
-+ int i;
-+
-+ mi->p_off = ftell(mi->fp);
-+ for(i = 0; i < mi->p_size; i++){
-+ if(fputc(mi->p[i], mi->fp) == EOF)
-+ mag_file_error(mi, MAG_WRITE);
-+ }
-+}
-+
-+static void mag_write_header(mi)
-+ struct mag *mi;
-+{
-+ byte buf[32];
-+
-+ if(DEBUG) mag_show_struct(mi);
-+
-+ mi->a_off -= mi->h_off;
-+ mi->b_off -= mi->h_off;
-+ mi->p_off -= mi->h_off;
-+
-+ buf[ 0] = buf[1] = buf[2] = 0;
-+ buf[ 3] = (mi->m_256 ? 0x80 : 0);
-+ buf[ 4] = buf[5] = 0;
-+ buf[ 6] = buf[7] = 0;
-+ buf[ 8] = L8(mi->x2);
-+ buf[ 9] = H8(mi->x2);
-+ buf[10] = L8(mi->y2);
-+ buf[11] = H8(mi->y2);
-+ mag_set_double_word(mi->a_off, &buf[12]);
-+ mag_set_double_word(mi->b_off, &buf[16]);
-+ mag_set_double_word(mi->b_size, &buf[20]);
-+ mag_set_double_word(mi->p_off, &buf[24]);
-+ mag_set_double_word(mi->p_size, &buf[28]);
-+
-+ fseek(mi->fp, mi->h_off, SEEK_SET);
-+ if(fwrite(buf, (size_t) 32, (size_t) 1, mi->fp) != 1)
-+ mag_file_error(mi, MAG_WRITE);
-+}
-+
-+static void mag_set_double_word(n, p)
-+ long n;
-+ byte *p;
-+{
-+ p[0] = n % 256; /* ugly...anything wrong with shift/mask operations? */
-+ p[1] = n / 256 % 256; /* (n >> 8) & 0xff */
-+ p[2] = n / 256 / 256 % 256; /* (n >> 16) & 0xff */
-+ p[3] = n / 256 / 256 / 256 % 256; /* (n >> 24) & 0xff */
-+}
-+
-+/*
-+ * The routines to initialize or clean up.
-+ * mag_init_info:
-+ * initializes a mag structure.
-+ * mag_cleanup_mag_info:
-+ * cleans up a mag structure.
-+ * mag_cleanup_pinfo:
-+ * cleans up a PICINFO structure.
-+ */
-+static void mag_init_info(mi)
-+ struct mag *mi;
-+{
-+ mi->fp = NULL;
-+ mi->fsize = 0;
-+ mi->m_256 = mi->m_dig = mi->m_8 = mi->m_200 = 0;
-+ mi->x1 = mi->y1 = mi->x2 = mi->y2 = 0;
-+ mi->left_pad = mi->right_pad = 0;
-+ mi->p_width = mi->p_height = mi->width = mi->height = 0;
-+ mi->h_off = mi->p_off = mi->p_size = 0;
-+ mi->a_off = mi->a_size = mi->b_off = mi->b_size = 0;
-+ mi->a = NULL;
-+ mi->b = NULL;
-+ mi->p = NULL;
-+}
-+
-+static void mag_cleanup_mag_info(mi, writing)
-+ struct mag *mi;
-+ int writing;
-+{
-+ if(mi->fp && !writing)
-+ fclose(mi->fp);
-+ if(mi->a)
-+ free(mi->a);
-+ if(mi->b)
-+ free(mi->b);
-+ if(mi->p)
-+ free(mi->p);
-+}
-+
-+static void mag_cleanup_pinfo(pinfo)
-+ PICINFO *pinfo;
-+{
-+ if(pinfo->comment){
-+ free(pinfo->comment);
-+ pinfo->comment = NULL;
-+ }
-+ if(pinfo->pic){
-+ free(pinfo->pic);
-+ pinfo->pic = NULL;
-+ }
-+}
-+
-+/*
-+ * Error handler.
-+ * mag_memory_error:
-+ * shows an error message, and terminates.
-+ * mag_error:
-+ * shows an non-file error message, and jumps to the entry for errors.
-+ * mag_file_error:
-+ * shows an file error message, and jumps to the entry for errors.
-+ * mag_file_warning:
-+ * shows an file warning message.
-+ */
-+static void mag_memory_error(scm, fn)
-+ char *scm, *fn;
-+{
-+ char buf[128];
-+ sprintf(buf, "%s: can't allocate memory. (%s)", scm, fn);
-+ FatalError(buf);
-+}
-+
-+static void mag_error(mi, mn)
-+ struct mag *mi;
-+ int mn;
-+{
-+ SetISTR(ISTR_WARNING, "%s", mag_msgs[mn]);
-+ longjmp(mi->jmp, 1);
-+}
-+
-+static void mag_file_error(mi, mn)
-+ struct mag *mi;
-+ int mn;
-+{
-+ if(feof(mi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", mag_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", mag_msgs[mn], ERRSTR(errno));
-+ longjmp(mi->jmp, 1);
-+}
-+
-+static void mag_file_warning(mi, mn)
-+ struct mag *mi;
-+ int mn;
-+{
-+ if(feof(mi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", mag_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", mag_msgs[mn], ERRSTR(errno));
-+}
-+
-+static void mag_show_struct (mi)
-+ struct mag *mi;
-+{
-+ fprintf(stderr, " 256 colors: %s\n", mi->m_256 ? "true" : "false");
-+ fprintf(stderr, " 8 colors: %s\n", mi->m_8 ? "true" : "false");
-+ fprintf(stderr, " digital colors: %s\n", mi->m_dig ? "true" : "false");
-+ fprintf(stderr, " aspect ratio: %f\n", mi->m_200 ? 0.5 : 1.0);
-+ fprintf(stderr, " image size: %dx%d\n", mi->width, mi->height);
-+ fprintf(stderr, " left pad: %d\n", mi->left_pad);
-+ fprintf(stderr, " right pad: %d\n", mi->right_pad);
-+ fprintf(stderr, " h_off: %ld\n", mi->h_off);
-+ fprintf(stderr, " A: off:%ld, size:%ld\n", mi->a_off, mi->a_size);
-+ fprintf(stderr, " B: off:%ld, size:%ld\n", mi->b_off, mi->b_size);
-+ fprintf(stderr, " P: off:%ld, size:%ld\n", mi->p_off, mi->p_size);
-+}
-+
-+/* Memory related routines. */
-+static void *mag_malloc(n, fn)
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (void *) malloc(n);
-+ if(r == NULL)
-+ mag_memory_error("malloc", fn);
-+ return r;
-+}
-+
-+static void *mag_realloc(p, n, fn)
-+ void *p;
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (p == NULL) ? (void *) malloc(n) : (void *) realloc(p, n);
-+ if(r == NULL)
-+ mag_memory_error("realloc", fn);
-+ return r;
-+}
-+#endif /* HAVE_MAG */
-diff -u -r --new-file xv-3.10a.orig/xvmaki.c xv-3.10a/xvmaki.c
---- xv-3.10a.orig/xvmaki.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvmaki.c 2005-04-18 00:57:01.000000000 -0500
-@@ -0,0 +1,794 @@
-+/*
-+ * xvmaki.c - load routine for `MAKI' format pictures.
-+ *
-+ * The `MAKI' format was used by some Japanese personal computer users.
-+ */
-+
-+#include "xv.h"
-+#include
-+
-+#ifdef HAVE_MAKI
-+
-+typedef unsigned short data16;
-+typedef unsigned int data32;
-+
-+struct maki_info {
-+ jmp_buf jmp;
-+ FILE *fp;
-+ long fsize;
-+ int x0, y0, x1, y1;
-+ int width, height;
-+ float aspect;
-+ long fb_size;
-+ long pa_size, pb_size;
-+ int m_maki01b, m_200, m_dig8;
-+ data16 ext_flag;
-+ byte *fa, *fb, *pa, *pb;
-+ byte *vs;
-+ int numcols;
-+ byte *forma, *formb;
-+};
-+
-+
-+static void maki_open_file PARM((struct maki_info*, char*));
-+static void maki_check_id PARM((struct maki_info*));
-+static void maki_skip_comment PARM((struct maki_info*));
-+static void maki_read_header PARM((struct maki_info*));
-+static void maki_read_palette PARM((struct maki_info*,
-+ byte*, byte*, byte*));
-+static void maki_read_flags PARM((struct maki_info*));
-+static void maki_read_pixel_data PARM((struct maki_info*));
-+static void maki_expand_virtual_screen PARM((struct maki_info*));
-+static void maki_expand_pixel_data PARM((struct maki_info*, byte**));
-+static void maki_init_info PARM((struct maki_info*));
-+
-+static void maki_make_pixel_data PARM((struct maki_info*, byte*));
-+static void maki_make_virtual_screen PARM((struct maki_info*));
-+static void maki_make_flags PARM((struct maki_info*));
-+static void maki_write_check_id PARM((struct maki_info*));
-+static void maki_write_comment PARM((struct maki_info*));
-+static void maki_write_header PARM((struct maki_info*));
-+static void maki_write_palette PARM((struct maki_info*,
-+ byte*, byte*, byte*, int));
-+static void maki_write_flags PARM((struct maki_info*));
-+static void maki_write_pixel_data PARM((struct maki_info*));
-+
-+static void maki_cleanup_maki_info PARM((struct maki_info*, int));
-+static void maki_cleanup_pinfo PARM((PICINFO*));
-+static void maki_memory_error PARM((char*, char*));
-+static void maki_error PARM((struct maki_info*, int));
-+static void maki_file_error PARM((struct maki_info*, int));
-+static void maki_file_warning PARM((struct maki_info*, int));
-+static void maki_show_maki_info PARM((struct maki_info*));
-+static void *maki_malloc PARM((size_t, char*));
-+static void *maki_realloc PARM((void *, size_t, char*));
-+
-+static char maki_id_a[] = "MAKI01A ";
-+static char maki_id_b[] = "MAKI01B ";
-+
-+static char *maki_msgs[] = {
-+ NULL,
-+#define MAKI_OPEN 1
-+ "can't open file.",
-+#define MAKI_CORRUPT 2
-+ "file corrupted.",
-+#define MAKI_FORMAT 3
-+ "not MAKI format.",
-+#define MAKI_BAD_DATA 4
-+ "bad data.",
-+#define MAKI_COMMENT 5
-+ "no '^Z' after comment.",
-+#define MAKI_SIZE 6
-+ "bad size.",
-+#define MAKI_WRITE 7
-+ "write failed.",
-+};
-+
-+#define H4(b) ((b) >> 4 & 0xf)
-+#define L4(b) ((b) & 0xf)
-+#define error(msg_num) longjmp(mi->jmp, msg_num)
-+
-+int LoadMAKI(fname, pinfo)
-+ char *fname;
-+ PICINFO *pinfo;
-+{
-+ struct maki_info maki;
-+ int e;
-+
-+ if(DEBUG) fputs("LoadMAKI:\n", stderr);
-+
-+ pinfo->comment = NULL;
-+ maki_init_info(&maki);
-+ if((e = setjmp(maki.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ maki_cleanup_maki_info(&maki, 0);
-+ maki_cleanup_pinfo(pinfo);
-+ return 0;
-+ }
-+
-+ maki_open_file(&maki, fname);
-+ maki_check_id(&maki);
-+ maki_skip_comment(&maki);
-+ maki_read_header(&maki);
-+ maki_read_palette(&maki, pinfo->r, pinfo->g, pinfo->b);
-+ maki_read_flags(&maki);
-+ maki_read_pixel_data(&maki);
-+ maki_expand_virtual_screen(&maki);
-+ maki_expand_pixel_data(&maki, &pinfo->pic);
-+
-+ pinfo->w = pinfo->normw = maki.width;
-+ pinfo->h = pinfo->normh = maki.height;
-+ pinfo->type = PIC8;
-+ pinfo->frmType = F_MAKI;
-+ pinfo->colType = F_FULLCOLOR;
-+ sprintf(pinfo->fullInfo, "MAKI, 16 colors (%ld bytes)", maki.fsize);
-+ sprintf(pinfo->shrtInfo, "%dx%d MAKI", maki.width, maki.height);
-+ normaspect = maki.aspect;
-+
-+ maki_cleanup_maki_info(&maki, 0);
-+ return 1;
-+}
-+
-+static void maki_open_file(mi, fname)
-+ struct maki_info *mi;
-+ char *fname;
-+{
-+ if((mi->fp = fopen(fname, "rb")) == NULL)
-+ maki_file_error(mi, MAKI_OPEN);
-+ fseek(mi->fp, (size_t) 0, SEEK_END);
-+ mi->fsize = ftell(mi->fp);
-+ fseek(mi->fp, (size_t) 0, SEEK_SET);
-+}
-+
-+static void maki_check_id(mi)
-+ struct maki_info *mi;
-+{
-+ char buf[8];
-+ if(fread(buf, (size_t) 8, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_CORRUPT);
-+ if(strncmp(buf, maki_id_a, (size_t) 8) != 0 &&
-+ strncmp(buf, maki_id_b, (size_t) 8) != 0)
-+ maki_error(mi, MAKI_FORMAT);
-+ mi->m_maki01b = (buf[6] == 'B');
-+}
-+
-+static void maki_skip_comment(mi)
-+ struct maki_info *mi;
-+{
-+ int i;
-+ int c;
-+
-+ for(i = 0; i < 24; i++){
-+ if((c = fgetc(mi->fp)) == EOF)
-+ maki_file_error(mi, MAKI_CORRUPT);
-+ if(c == '\032') /* ^Z, 0x1a */
-+ break;
-+ }
-+ if(c != '\032')
-+ maki_file_error(mi, MAKI_COMMENT);
-+
-+ fseek(mi->fp, 32L, SEEK_SET);
-+}
-+
-+static void maki_read_header(mi)
-+ struct maki_info *mi;
-+{
-+ byte buf[16];
-+
-+ if(fread(buf, (size_t) 16, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_CORRUPT);
-+
-+ mi->fb_size = (long)buf[ 0] << 8 | (long)buf[ 1];
-+ mi->pa_size = (long)buf[ 2] << 8 | (long)buf[ 3];
-+ mi->pb_size = (long)buf[ 4] << 8 | (long)buf[ 5];
-+ mi->ext_flag = (long)buf[ 6] << 8 | (long)buf[ 7];
-+ mi->x0 = (long)buf[ 8] << 8 | (long)buf[ 9];
-+ mi->y0 = (long)buf[10] << 8 | (long)buf[11];
-+ mi->x1 = (long)buf[12] << 8 | (long)buf[13];
-+ mi->y1 = (long)buf[14] << 8 | (long)buf[15];
-+
-+ mi->width = mi->x1-- - mi->x0;
-+ mi->height = mi->y1-- - mi->y0;
-+ mi->m_200 = mi->ext_flag & 1;
-+ mi->m_dig8 = mi->ext_flag & 2;
-+ mi->aspect = mi->m_200 ? 0.5 : 1.0;
-+
-+ if(DEBUG) maki_show_maki_info(mi);
-+}
-+
-+static void maki_read_palette(mi, r, g, b)
-+ struct maki_info *mi;
-+ byte *r, *g, *b;
-+{
-+ byte buf[48], *p;
-+
-+ if(fread(buf, (size_t) 48, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_CORRUPT);
-+
-+ for(p = buf; p < &buf[48]; ){
-+ *g++ = *p++;
-+ *r++ = *p++;
-+ *b++ = *p++;
-+ }
-+}
-+
-+static void maki_read_flags(mi)
-+ struct maki_info *mi;
-+{
-+ mi->fa = maki_malloc((size_t) 1000 , "maki_read_flags#1");
-+ mi->fb = maki_malloc((size_t) mi->fb_size, "maki_read_flags#2");
-+
-+ if(fread(mi->fa, (size_t) 1000, (size_t) 1, mi->fp) != 1)
-+ maki_file_warning(mi, MAKI_CORRUPT);
-+ if(fread(mi->fb, (size_t) mi->fb_size, (size_t) 1, mi->fp) != 1)
-+ maki_file_warning(mi, MAKI_CORRUPT);
-+}
-+
-+static void maki_read_pixel_data(mi)
-+ struct maki_info *mi;
-+{
-+ mi->pa = maki_malloc((size_t) mi->pa_size, "maki_read_pixel_data#1");
-+ mi->pb = maki_malloc((size_t) mi->pb_size, "maki_read_pixel_data#2");
-+
-+ if(fread(mi->pa, (size_t) mi->pa_size, (size_t) 1, mi->fp) != 1)
-+ maki_file_warning(mi, MAKI_CORRUPT);
-+ if(fread(mi->pb, (size_t) mi->pb_size, (size_t) 1, mi->fp) != 1)
-+ maki_file_warning(mi, MAKI_CORRUPT);
-+}
-+
-+static void maki_expand_virtual_screen(mi)
-+ struct maki_info *mi;
-+{
-+ int x, y, fai, fbi;
-+ int bpl = mi->width / 2 / 8; /* bytes per line */
-+ byte mask;
-+ mi->vs = maki_malloc((size_t) bpl * mi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "maki_expand_virtual_screen");
-+
-+ fai = fbi = 0;
-+ mask = 0x80;
-+ for(y = 0; y < mi->height; y += 4){
-+ for(x = 0; x < mi->width / 2; x += 4){
-+ if(mi->fa[fai] & mask){
-+ byte bh, bl;
-+ bh = mi->fb[fbi++];
-+ bl = mi->fb[fbi++];
-+ if(x % 8 == 0){
-+ mi->vs[ y * bpl + x / 8] = H4(bh) << 4;
-+ mi->vs[(y + 1) * bpl + x / 8] = L4(bh) << 4;
-+ mi->vs[(y + 2) * bpl + x / 8] = H4(bl) << 4;
-+ mi->vs[(y + 3) * bpl + x / 8] = L4(bl) << 4;
-+ }else{
-+ mi->vs[ y * bpl + x / 8] |= H4(bh);
-+ mi->vs[(y + 1) * bpl + x / 8] |= L4(bh);
-+ mi->vs[(y + 2) * bpl + x / 8] |= H4(bl);
-+ mi->vs[(y + 3) * bpl + x / 8] |= L4(bl);
-+ }
-+ }else{
-+ if(x % 8 == 0){
-+ mi->vs[ y * bpl + x / 8] = 0;
-+ mi->vs[(y + 1) * bpl + x / 8] = 0;
-+ mi->vs[(y + 2) * bpl + x / 8] = 0;
-+ mi->vs[(y + 3) * bpl + x / 8] = 0;
-+ }else{
-+/* mi->vs[ y * bpl + x / 8] |= 0;
-+ mi->vs[(y + 1) * bpl + x / 8] |= 0;
-+ mi->vs[(y + 2) * bpl + x / 8] |= 0;
-+ mi->vs[(y + 3) * bpl + x / 8] |= 0; */
-+ }
-+ }
-+
-+ if((mask >>= 1) == 0){
-+ mask = 0x80;
-+ fai++;
-+ }
-+ }
-+ }
-+}
-+
-+static void maki_expand_pixel_data(mi, pic)
-+ struct maki_info *mi;
-+ byte **pic;
-+{
-+ int x, y;
-+ int vsi, pi, max_pi;
-+ byte *p;
-+ byte mask;
-+ int gap;
-+ *pic = maki_malloc((size_t) mi->width * mi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "maki_expand_pixel_data");
-+
-+ vsi = pi = 0;
-+ p = mi->pa;
-+ max_pi = mi->pa_size - 1;
-+ mask = 0x80;
-+ for(y = 0; y < mi->height; y++){
-+ for(x = 0; x < mi->width; x += 2){
-+ if(mi->vs[vsi] & mask){
-+ if(pi > max_pi){
-+ if(p == mi->pb)
-+ maki_error(mi, MAKI_BAD_DATA);
-+ pi = 0;
-+ p = mi->pb;
-+ max_pi = mi->pb_size - 1;
-+ }
-+ (*pic)[y * mi->width + x ] = H4(p[pi]);
-+ (*pic)[y * mi->width + x + 1] = L4(p[pi]);
-+ pi++;
-+ }else{
-+ (*pic)[y * mi->width + x ] = 0;
-+ (*pic)[y * mi->width + x + 1] = 0;
-+ }
-+
-+ if((mask >>= 1) == 0){
-+ mask = 0x80;
-+ vsi++;
-+ }
-+ }
-+ }
-+
-+ gap = mi->m_maki01b ? 4 : 2;
-+
-+ for(y = gap; y < mi->height; y++){
-+ for(x = 0; x < mi->width; x++)
-+ (*pic)[y * mi->width + x] ^= (*pic)[(y - gap) * mi->width + x];
-+ }
-+}
-+
-+
-+int WriteMAKI(fp, pic, ptype, w, h, rmap, gmap, bmap, numcols, colorstyle)
-+ FILE *fp;
-+ byte *pic;
-+ int ptype, w, h;
-+ byte *rmap, *gmap, *bmap;
-+ int numcols, colorstyle;
-+{
-+ byte rtemp[256], gtemp[256], btemp[256];
-+ struct maki_info maki, *mi = &maki;
-+ int e;
-+
-+ if(DEBUG) fputs("WriteMAKI:\n", stderr);
-+
-+ maki_init_info(&maki);
-+ if((e = setjmp(maki.jmp)) != 0){
-+ /* An error occurs */
-+ maki_cleanup_maki_info(&maki, 1);
-+ return -1;
-+ }
-+
-+ if(w != 640 || h != 400) {
-+ char str[512];
-+ sprintf(str,"MAKI: %s Should be 640x400", maki_msgs[MAKI_SIZE]);
-+ ErrPopUp(str, "\nBummer!");
-+ maki_error(mi, MAKI_SIZE);
-+ }
-+
-+ maki.fp = fp;
-+ maki.width = w;
-+ maki.height = h;
-+ maki.x1 = w - 1;
-+ maki.y1 = h - 1;
-+
-+ if(ptype == PIC24){
-+ if(!(pic = Conv24to8(pic, w, h, 16, rtemp, gtemp, btemp)))
-+ maki_memory_error("Conv24to8#1", "WriteMAKI");
-+ rmap = rtemp;
-+ gmap = gtemp;
-+ bmap = btemp;
-+ }else if(numcols > 16){
-+ if(!(pic = Conv8to24(pic, w, h, rmap, gmap, bmap)))
-+ maki_memory_error("Conv8to24", "WriteMAKI");
-+ if(!(pic = Conv24to8(pic, w, h, 16, rtemp, gtemp, btemp)))
-+ maki_memory_error("Conv24to8#2", "WriteMAKI");
-+ rmap = rtemp;
-+ gmap = gtemp;
-+ bmap = btemp;
-+ }else
-+ maki.numcols = numcols;
-+
-+ maki_make_pixel_data(&maki, pic);
-+ maki_make_virtual_screen(&maki);
-+ maki_make_flags(&maki);
-+ maki_write_check_id(&maki);
-+ maki_write_comment(&maki);
-+ maki_write_header(&maki);
-+ maki_write_palette(&maki, rmap, gmap, bmap, colorstyle == F_GREYSCALE);
-+ maki_write_flags(&maki);
-+ maki_write_pixel_data(&maki);
-+
-+ maki_cleanup_maki_info(&maki, 1);
-+ return 0;
-+}
-+
-+static void maki_make_pixel_data(mi, pic)
-+ struct maki_info *mi;
-+ byte *pic;
-+{
-+ int x, y, i;
-+ int nza, nzb;
-+
-+ mi->forma = maki_malloc((size_t) mi->width / 2 * mi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "maki_make_pixel_data#1");
-+ mi->formb = maki_malloc((size_t) mi->width / 2 * mi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "maki_make_pixel_data#2");
-+
-+ for(y = 0; y < mi->height; y++){
-+ for(x = 0; x < mi->width; x += 2){
-+ byte b;
-+ b = pic[y * mi->width + x] << 4 | pic[y * mi->width + x + 1];
-+ mi->forma[y * mi->width / 2 + x / 2] = b;
-+ mi->formb[y * mi->width / 2 + x / 2] = b;
-+ }
-+ }
-+
-+ for(y = mi->height - 1; y >= 2; y--){
-+ for(x = 0; x < mi->width / 2; x++){
-+ mi->forma[y * mi->width / 2 + x] ^=
-+ mi->forma[(y - 2) * mi->width / 2 + x];
-+ }
-+ }
-+
-+ for(y = mi->height - 1; y >= 4; y--){
-+ for(x = 0; x < mi->width / 2; x++){
-+ mi->formb[y * mi->width / 2 + x] ^=
-+ mi->formb[(y - 4) * mi->width / 2 + x];
-+ }
-+ }
-+
-+ nza = nzb = 0;
-+ for(i = 0; i < mi->width / 2 * mi->height; i++){
-+ if(mi->forma[i] != 0)
-+ nza++;
-+ if(mi->formb[i] != 0)
-+ nzb++;
-+ }
-+ if(nza > nzb){
-+ mi->m_maki01b = 1;
-+ free(mi->forma);
-+ mi->forma = NULL;
-+ }else{
-+ mi->m_maki01b = 0;
-+ free(mi->formb);
-+ mi->formb = NULL;
-+ }
-+}
-+
-+static void maki_make_virtual_screen(mi)
-+ struct maki_info *mi;
-+{
-+ int bpl = mi->width / 2 / 8;
-+ int vsi, pai, pbi, max_pai, max_pbi;
-+ byte mask;
-+ byte *pixels;
-+ int x, y;
-+
-+ mi->vs = maki_malloc((size_t) bpl * mi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "maki_make_virtual_screen#1");
-+
-+ if(mi->m_maki01b)
-+ pixels = mi->formb;
-+ else
-+ pixels = mi->forma;
-+
-+ vsi = pai = pbi = 0;
-+ max_pai = max_pbi = -1;
-+ mask = 0x80;
-+ for(y = 0; y < mi->height; y++){
-+ for(x = 0; x < mi->width / 2; x++){
-+ if(pixels[y * mi->width / 2 + x] == 0){
-+ mi->vs[vsi] &= ~mask;
-+ }else{
-+ mi->vs[vsi] |= mask;
-+ if(y < 200){
-+ if(pai > max_pai){
-+ max_pai += 1024;
-+ mi->pa = maki_realloc(mi->pa, (size_t) max_pai + 1,
-+ "maki_make_virtual_screen#2");
-+ }
-+ mi->pa[pai++] = pixels[y * mi->width / 2 + x];
-+ }else{
-+ if(pbi > max_pbi){
-+ max_pbi += 1024;
-+ mi->pb = maki_realloc(mi->pb, (size_t) max_pbi + 2,
-+ "maki_make_virtual_screen#3");
-+ }
-+ mi->pb[pbi++] = pixels[y * mi->width / 2 + x];
-+ }
-+ }
-+
-+ if((mask >>= 1) == 0){
-+ mask = 0x80;
-+ vsi++;
-+ }
-+ }
-+ }
-+
-+ mi->pa_size = pai;
-+ mi->pb_size = pbi;
-+}
-+
-+static void maki_make_flags(mi)
-+ struct maki_info *mi;
-+{
-+ int bpl = mi->width / 2 / 8;
-+ int fbi, max_fbi;
-+ int fai;
-+ int x, y;
-+ byte mask;
-+
-+ mi->fa = maki_malloc((size_t) bpl * mi->height, "maki_make_flags#1"); // GRR POSSIBLE OVERFLOW / FIXME
-+
-+ fbi = fai = 0;
-+ max_fbi = -1;
-+ mask = 0x80;
-+ for(y = 0; y < mi->height; y += 4){
-+ for(x = 0; x < mi->width / 2; x += 4){
-+ if(x % 8 == 0){
-+ if(H4(mi->vs[ y * bpl + x / 8]) == 0 &&
-+ H4(mi->vs[(y + 1) * bpl + x / 8]) == 0 &&
-+ H4(mi->vs[(y + 2) * bpl + x / 8]) == 0 &&
-+ H4(mi->vs[(y + 3) * bpl + x / 8]) == 0){
-+ mi->fa[fai] &= ~mask;
-+ }else{
-+ mi->fa[fai] |= mask;
-+ if(fbi + 1 > max_fbi){
-+ max_fbi += 1024;
-+ mi->fb = maki_realloc(mi->fb, (size_t) max_fbi + 1,
-+ "maki_make_flags#2");
-+ }
-+ mi->fb[fbi++] = H4(mi->vs[ y * bpl + x / 8]) << 4
-+ | H4(mi->vs[(y + 1) * bpl + x / 8]);
-+ mi->fb[fbi++] = H4(mi->vs[(y + 2) * bpl + x / 8]) << 4
-+ | H4(mi->vs[(y + 3) * bpl + x / 8]);
-+ }
-+ }else{
-+ if(L4(mi->vs[ y * bpl + x / 8]) == 0 &&
-+ L4(mi->vs[(y + 1) * bpl + x / 8]) == 0 &&
-+ L4(mi->vs[(y + 2) * bpl + x / 8]) == 0 &&
-+ L4(mi->vs[(y + 3) * bpl + x / 8]) == 0){
-+ mi->fa[fai] &= ~mask;
-+ }else{
-+ mi->fa[fai] |= mask;
-+ if(fbi + 1 > max_fbi){
-+ max_fbi += 1024;
-+ mi->fb = maki_realloc(mi->fb, (size_t) max_fbi + 1,
-+ "maki_make_flags#3");
-+ }
-+ mi->fb[fbi++] = L4(mi->vs[ y * bpl + x / 8]) << 4
-+ | L4(mi->vs[(y + 1) * bpl + x / 8]);
-+ mi->fb[fbi++] = L4(mi->vs[(y + 2) * bpl + x / 8]) << 4
-+ | L4(mi->vs[(y + 3) * bpl + x / 8]);
-+ }
-+ }
-+
-+ if((mask >>= 1) == 0){
-+ mask = 0x80;
-+ fai++;
-+ }
-+ }
-+ }
-+
-+ mi->fb_size = fbi;
-+}
-+
-+static void maki_write_check_id(mi)
-+ struct maki_info *mi;
-+{
-+ char *id = mi->m_maki01b ? maki_id_b : maki_id_a;
-+ if(fwrite(id, (size_t) 8, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+}
-+
-+static void maki_write_comment(mi)
-+ struct maki_info *mi;
-+{
-+ char buf[24];
-+ char *p;
-+ int i = 0;
-+
-+ strcpy(buf, "XV ");
-+
-+ if((p = (char *) getenv("USER")) == NULL)
-+ p = "????????";
-+ for(i = 5; i < 23; i++){
-+ if(*p == '\0')
-+ break;
-+ buf[i] = *p++;
-+ }
-+ for( ; i < 23; i++)
-+ buf[i] = ' ';
-+
-+ buf[i] = '\032'; /* ^Z, 0x1a */
-+
-+ if(fwrite(buf, (size_t) 24, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+}
-+
-+static void maki_write_header(mi)
-+ struct maki_info *mi;
-+{
-+ byte buf[16];
-+
-+ if(DEBUG) maki_show_maki_info(mi);
-+
-+#define set_word(i, v) {buf[i]=(v)>>8&0xff;buf[i+1]=(v)&0xff;}
-+ set_word(0, mi->fb_size);
-+ set_word(2, mi->pa_size);
-+ set_word(4, mi->pb_size);
-+ set_word(6, mi->ext_flag);
-+ set_word(8, mi->x0);
-+ set_word(10, mi->y0);
-+ set_word(12, mi->x1 + 1);
-+ set_word(14, mi->y1 + 1);
-+#undef set_word
-+
-+ if(fwrite(buf, (size_t) 16, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+}
-+
-+static void maki_write_palette(mi, r, g, b, grey)
-+ struct maki_info *mi;
-+ byte *r, *g, *b;
-+ int grey;
-+{
-+ int i;
-+ char buf[3];
-+ for(i = 0; i < mi->numcols; i++){
-+ buf[0] = *g++;
-+ buf[1] = *r++;
-+ buf[2] = *b++;
-+ if(grey)
-+ buf[0] = buf[1] = buf[2] = MONO(buf[1], buf[0], buf[2]);
-+ if(fwrite(buf, (size_t) 3, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+ }
-+ for( ; i < 16; i++){
-+ if(fwrite(buf, (size_t) 3, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+ }
-+}
-+
-+static void maki_write_flags(mi)
-+ struct maki_info *mi;
-+{
-+ int bpl = mi->width / 2 / 8;
-+ if(fwrite(mi->fa, (size_t) bpl * mi->height / 16, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+
-+ if(fwrite(mi->fb, (size_t) mi->fb_size, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+}
-+
-+static void maki_write_pixel_data(mi)
-+ struct maki_info *mi;
-+{
-+ if(fwrite(mi->pa, (size_t) mi->pa_size, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+
-+ if(fwrite(mi->pb, (size_t) mi->pb_size, (size_t) 1, mi->fp) != 1)
-+ maki_file_error(mi, MAKI_WRITE);
-+}
-+
-+
-+
-+static void maki_init_info(mi)
-+ struct maki_info *mi;
-+{
-+ xvbzero((char *)mi, sizeof(struct maki_info));
-+ mi->fp = NULL;
-+ mi->fsize = 0;
-+ mi->x0 = mi->y0 = mi->x1 = mi->y1 = 0;
-+ mi->width = mi->height = 0;
-+ mi->aspect = 1.0;
-+ mi->fb_size = mi->pa_size = mi->pb_size = 0;
-+ mi->m_maki01b = mi->m_200 = mi->m_dig8 = 0;
-+ mi->ext_flag = 0;
-+ mi->fa = mi->fb = mi->pa = mi->pb = NULL;
-+ mi->vs = NULL;
-+ mi->numcols = 16;
-+ mi->forma = mi->formb = NULL;
-+}
-+
-+static void maki_cleanup_maki_info(mi, writing)
-+ struct maki_info *mi;
-+ int writing;
-+{
-+ if(mi->fp && !writing)
-+ fclose(mi->fp);
-+ if(mi->fa)
-+ free(mi->fa);
-+ if(mi->fb)
-+ free(mi->fb);
-+ if(mi->pa)
-+ free(mi->pa);
-+ if(mi->pb)
-+ free(mi->pb);
-+ if(mi->vs)
-+ free(mi->vs);
-+ if(mi->forma)
-+ free(mi->forma);
-+ if(mi->formb)
-+ free(mi->formb);
-+}
-+
-+static void maki_cleanup_pinfo(pi)
-+ PICINFO *pi;
-+{
-+ if(pi->pic){
-+ free(pi->pic);
-+ pi->pic = NULL;
-+ }
-+}
-+
-+static void maki_memory_error(scm, fn)
-+ char *scm, *fn;
-+{
-+ char buf[128];
-+ sprintf(buf, "%s: coulndn't allocate memory. (%s)", scm, fn);
-+ FatalError(buf);
-+}
-+
-+static void maki_error(mi, mn)
-+ struct maki_info *mi;
-+ int mn;
-+{
-+ SetISTR(ISTR_WARNING, "%s", maki_msgs[mn]);
-+ longjmp(mi->jmp, 1);
-+}
-+
-+static void maki_file_error(mi, mn)
-+ struct maki_info *mi;
-+ int mn;
-+{
-+ if(feof(mi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", maki_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", maki_msgs[mn], ERRSTR(errno));
-+ longjmp(mi->jmp, 1);
-+}
-+
-+static void maki_file_warning(mi, mn)
-+ struct maki_info *mi;
-+ int mn;
-+{
-+ if(feof(mi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", maki_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", maki_msgs[mn], ERRSTR(errno));
-+}
-+
-+static void maki_show_maki_info(mi)
-+ struct maki_info *mi;
-+{
-+ fprintf(stderr, " file size: %ld.\n", mi->fsize);
-+ fprintf(stderr, " image size: %dx%d.\n", mi->width, mi->height);
-+ fprintf(stderr, " aspect: %f.\n", mi->aspect);
-+ fprintf(stderr, " flag B size: %ld.\n", mi->fb_size);
-+ fprintf(stderr, " pixel data size: A:%ld, B:%ld.\n",
-+ mi->pa_size, mi->pb_size);
-+ fprintf(stderr, " MAKI01B: %s.\n", mi->m_maki01b ? "true" : "false");
-+ fprintf(stderr, " 200 line mode: %s.\n", mi->m_200 ? "true" : "false");
-+ fprintf(stderr, " digital 8 colors: %s.\n", mi->m_dig8 ? "true" : "false");
-+}
-+
-+static void *maki_malloc(n, fn)
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (void *) malloc(n);
-+ if(r == NULL)
-+ maki_memory_error("malloc", fn);
-+ return r;
-+}
-+
-+static void *maki_realloc(p, n, fn)
-+ void *p;
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (p == NULL) ? (void *) malloc(n) : (void *) realloc(p, n);
-+ if(r == NULL)
-+ maki_memory_error("realloc", fn);
-+ return r;
-+}
-+#endif /* HAVE_MAKI */
-diff -u -r --new-file xv-3.10a.orig/xvmgcsfx.c xv-3.10a/xvmgcsfx.c
---- xv-3.10a.orig/xvmgcsfx.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvmgcsfx.c 2007-04-15 17:02:32.000000000 -0500
-@@ -0,0 +1,2276 @@
-+/*
-+ * $Id: xvmgcsfx.c,v 1.23 95/11/27 19:03:36 tin329 Exp Locker: tin329 $
-+ * xvmgcsfx.c - Use the filters as input and output method.
-+ *
-+ * Features
-+ * ========
-+ * Use the filters as input and output method for load and save unsupported
-+ * image format file. The filter command is recognized by definition of
-+ * magic number or suffix in "~/.xv_mgcsfx" .
-+ *
-+ * Bugs
-+ * ====
-+ * There are many bugs.
-+ * Let's go hunting for insects with an insect net. (it's all joke.)
-+ *
-+ * Author
-+ * ======
-+ * Tetsuya INOUE
-+ */
-+
-+/*
-+ * Known Bugs and Todo / $B$"$l$3$l5$$K$J$k$3$H(B
-+ *
-+ * ~/.xv_mgcsfx $BFb(B
-+ * $B!&Dj5A$,IT40A4$@$H%(%i!<(B (':'$B$N?t(B)$B!#(B
-+ * $B!&%G%j%_%?$H$7$F(B ':' $B$r;H$&$N$G!"%9%?!<%H%"%C%W%U%!%$%kFb$G(B
-+ * ':' $B$rMQ$$$FDj5A$O$G$-$J$$!#(B'\:'$B$G$b%@%a!#(B
-+ * $B!&(B magic $B%?%$%W$G!"#8?J?t$O#37eJ,#0!A#7$rD4$Y!"#1#6?J?t$O(B
-+ * isxdigit $B$,??$rJV$94VCf=hM}$5$l$k!#$7$+$7!"#1#b#y#t#e$H(B
-+ * $B$7$F$7$+I>2A$5$l$J$$!#(B
-+ * $B!&%W%j%W%m%;%C%5$r;H$&$H$-$O!"%3%a%s%H$N=q$-J}$KCm0U$7$J$1$l$P$J(B
-+ * $B$i$J$$!#%W%j%W%m%;%C%5$K$h$C$F$O%3%a%s%H$,%(%i!<$K$J$k!#(B
-+ * $B!&%Q%$%W$X$NF~=PNO$N%U%)!<%^%C%H$Nl9g$rG'$a$k$+!)(B
-+ * $B!&(Bcompress(gzip)$B$N%U%!%$%k$O%F%s%]%i%j$G$O(B xvtmp??? $B$H$$$&L>A0$J(B
-+ * $B$N$G(B suffix $B$G$O<1JL$G$-$J$$!#(B
-+ *
-+ * $BG'<1$9$k;~$K(B MACBINARY $B$K$OIi$1$k(B(in xv.c)$B!#(B
-+ *
-+ * $BB?=E$K(B pipe $B$rDL$9$3$H$,$G$-$J$$!#(B(pipe $B$,(B seek $B$G$-$J$$$+$i(B)
-+ * $B!&(Bsocketpair $B$G!"(Brecv $B$K(B MSG_PEEK $B%U%i%0$r$D$+$C$F6uFI$_$9$k!#(B
-+ * $B!&$3$l$r$d$k$H%U%!%$%k$NG'<1$,$a$A$c$a$A$cCY$/$J$k!#(B
-+ *
-+ * $B%j%=!<%9$G@_Dj(B
-+ * $B!&%j%=!<%9$G@_Dj$9$kJ}$,LLE]$/$5$$(B
-+ *
-+ * $B%^%8%C%/%J%s%P!<$N@_Dj$K@55,I=8=(B
-+ *
-+ * $B%;!<%VMQ%W%m%;%9$,<:GT$9$k>l9g$NBP:v$,:#0l$D(B
-+ *
-+ * DEC OSF/1 V3.0 $B$G$O!"%Q%$%W$K%G!<%?$,$^$@$J$$;~$KFI$_9~$b$&$H$9$k$H!"(B
-+ * read $B$,IT40A4$K$J$k!#(B(in xvpbm.c)
-+ * $BF1MM$K=q$-9~$_;~$K$bLdBj$,@8$8$k$+$b$7$l$J$$!#(B
-+ */
-+
-+#define NEEDSDIR /* for stat() */
-+#include "xv.h"
-+
-+
-+#ifdef HAVE_MGCSFX
-+
-+
-+#ifdef __osf__
-+# ifdef __alpha
-+# define ARCHITECTURE64 1
-+# endif /* __alpha */
-+#endif /* __osf__ */
-+
-+#ifdef ARCHITECTURE64
-+typedef short int16;
-+typedef int int32;
-+typedef long int64;
-+#else
-+typedef short int16;
-+typedef long int32;
-+#endif /* ARCHITECTURE64 */
-+
-+#ifdef sgi
-+# define vfork fork
-+#endif
-+
-+#define USE_SIGCHLD
-+#if 0
-+# undef USE_SIGCHLD
-+#endif
-+
-+#ifdef USE_SIGCHLD
-+# include
-+#endif
-+
-+typedef struct _mgcsfxtab
-+{
-+ struct _mgcsfxtab *next;
-+ char *description;
-+ int mgcsfx_type;
-+ int offset;
-+ union{
-+ int16 int16_data;
-+ int32 int32_data;
-+ char *string_data;
-+ } dt;
-+ int string_len;
-+ char *suffix;
-+ int input_image_type;
-+ char *input_command;
-+ int output_image_type;
-+ char *output_command;
-+} mgcsfxtab;
-+
-+
-+#ifndef MGCSFXDIR
-+# define MGCSFXDIR "/usr/local/lib"
-+#endif
-+#ifndef SYSCONFDIR
-+# define SYSCONFDIR MGCSFXDIR
-+#endif
-+#ifndef MGCSFX_SITE_RC
-+# define MGCSFX_SITE_RC "xv_mgcsfx"
-+#endif
-+#ifndef MGCSFX_RC
-+# define MGCSFX_RC ".xv_mgcsfx"
-+#endif
-+
-+#ifdef USE_MGCSFX_PREPROCESSOR
-+# ifndef MGCSFX_PREPROCESSOR
-+# define MGCSFX_PREPROCESSOR "/usr/lib/cpp"
-+# endif
-+#endif
-+
-+
-+/* Check type for Magic number and Suffix */
-+enum {T_UNKNOWN,
-+ T_MAGIC, T_SUFFIX,
-+ T_BEINT16, T_BEINT32, T_BEINT64,
-+ T_LEINT16, T_LEINT32, T_LEINT64};
-+
-+/* Image Type for input and output format */
-+enum {IT_UNKNOWN,
-+#ifdef HAVE_MGCSFX_AUTO
-+ IT_AUTO,
-+#endif /* HAVE_MGCSFX_AUTO */
-+ IT_PNM, IT_PPM, IT_PGM, IT_PBM,
-+ IT_PNM_RAW, IT_PPM_RAW, IT_PGM_RAW, IT_PBM_RAW,
-+ IT_PNM_ASCII, IT_PPM_ASCII, IT_PGM_ASCII, IT_PBM_ASCII,
-+ IT_GIF, IT_JPEG, IT_TIFF, IT_JFIF, /* IT_PS, IT_COMPRESS,*/
-+ IT_XBM, IT_XPM, IT_BMP, IT_SUNRAS, IT_IRIS, IT_XWD,
-+ /* IT_TARGA, IT_FITS, IT_PM, IT_UTAHRLE, IT_PCX, IT_PDSVICAR, IT_IFF, */
-+ IT_MAG, IT_MAKI, IT_PI, IT_PIC, IT_PIC2 /* , IT_PCD */};
-+
-+
-+/*--------------------------------------------------------------------------*/
-+void mgcsfx_handler PARM((int));
-+void mgcsfx_handler_setup PARM((void));
-+
-+#ifdef USE_MGCSFX_PREPROCESSOR
-+static char *get_tmp_fname PARM((void));
-+static char *make_preprocessed_file PARM((char *));
-+#endif /* USE_MGCSFX_PREPROCESSOR */
-+
-+int is_mgcsfx PARM((char *, unsigned char *, int));
-+
-+char *mgcsfx_auto_input_com PARM((char *));
-+
-+
-+static mgcsfxtab *free_mgcsfx PARM((mgcsfxtab *));
-+static char *fgettoken PARM((FILE*, int));
-+static int string_fin PARM((char *));
-+static int type_mgcsfx PARM((char *));
-+static int type_image PARM((char *));
-+
-+static void read_mgcsfx PARM((mgcsfxtab **, char *));
-+static void init_mgcsfx PARM((void));
-+static mgcsfxtab *find_mgcsfx PARM((char *, unsigned char *, int));
-+
-+int LoadMGCSFX PARM((char *, PICINFO *));
-+
-+#ifdef SVR4
-+typedef void Sigfunc(int);
-+static Sigfunc *xv_signal PARM((int , Sigfunc *));
-+#endif
-+
-+/*--------------------------------------------------------------------------*/
-+mgcsfxtab *mgcsfx_table = NULL;
-+int mgcsfx_setup_flag = 0;
-+
-+int nitem_mgcsfx = 0;
-+int desc_width = 0;
-+
-+int max_offset_mgcsfx = 0;
-+int max_length_mgcsfx = 0;
-+int need_buf_size = 0;
-+
-+static char input_command_ex[1024];
-+static int input_command_ex_flag = 0;
-+
-+#ifdef USE_SIGCHLD
-+static int w_p_fail=0;
-+#endif
-+
-+/*--------------------------------------------------------------------------*/
-+
-+/***************************************************/
-+void mgcsfx_handler(sig)
-+ int sig;
-+{
-+#ifdef USE_SIGCHLD
-+ int pid, pst;
-+#endif
-+
-+#if defined(SYSV) || defined(SVR4)
-+ sighold(sig);
-+#else
-+ sigblock(sigmask(sig));
-+#endif
-+
-+#ifdef USE_SIGCHLD
-+ if(w_p_fail == 1){
-+ /*
-+ * At this point, process write to broken pipe.
-+ * Probably external command was can't exec.
-+ */
-+ w_p_fail = 2;
-+ pid = wait(&pst);
-+ }
-+#endif
-+
-+ return;
-+
-+ /* Quit(1); */ /*exit(1);*/
-+}
-+
-+void mgcsfx_handler_setup()
-+{
-+#ifdef SVR4
-+ xv_signal(SIGPIPE, (void (*)PARM((int))) mgcsfx_handler);
-+ xv_signal(SIGCHLD, (void (*)PARM((int))) mgcsfx_handler);
-+#else
-+# ifdef SYSV
-+ sigset(SIGPIPE, (void (*)PARM((int))) mgcsfx_handler);
-+ sigset(SIGCHLD, (void (*)PARM((int))) mgcsfx_handler);
-+# else
-+ signal(SIGPIPE, (void (*)PARM((int))) mgcsfx_handler);
-+ signal(SIGCHLD, (void (*)PARM((int))) mgcsfx_handler);
-+# endif
-+#endif
-+}
-+
-+/***************************************************/
-+#ifdef USE_MGCSFX_PREPROCESSOR
-+static char *get_tmp_fname()
-+{
-+ static char tmp[MAXPATHLEN+1];
-+
-+#ifndef VMS
-+ sprintf(tmp, "%s/xvmgcsfxXXXXXX",tmpdir);
-+#else
-+ /* sprintf(tmp, "Sys$Scratch:xvmgcsfxXXXXXX"); */
-+ strcpy(tmp, "[]xvmgcsfxXXXXXX");
-+#endif /* VMS */
-+
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(tmp));
-+#else
-+ mktemp(tmp);
-+#endif
-+
-+ return tmp;
-+}
-+
-+static char *make_preprocessed_file(fname)
-+ char *fname;
-+{
-+ char buf[512];
-+ char *tmp_name;
-+
-+ tmp_name = get_tmp_fname();
-+
-+#ifndef VMS
-+ sprintf(buf,"%s %s > %s", MGCSFX_PREPROCESSOR, fname, tmp_name);
-+#else
-+ sprintf(buf,"%s %s > %s", MGCSFX_PREPROCESSOR, fname, tmp_name); /* really OK? */
-+#endif
-+
-+ SetISTR(ISTR_INFO, "Preprocessing '%s'...", BaseName(fname));
-+#ifndef VMS
-+ if (system(buf))
-+#else
-+ if (!system(buf))
-+#endif
-+ {
-+ SetISTR(ISTR_INFO, "Unable to preprocess '%s'.", BaseName(fname));
-+ Warning();
-+ return NULL;
-+ }
-+
-+ return tmp_name;
-+}
-+#endif /* USE_MGCSFX_PREPROCESSOR */
-+
-+/***************************************************/
-+/* $BG'<1$G$-$k%U%!%$%k$+$I$&$+D4$Y$k(B */
-+int is_mgcsfx(fname,buffer,size)
-+ char *fname;
-+ unsigned char *buffer;
-+ int size;
-+{
-+ mgcsfxtab *magic;
-+ FILE *fp;
-+ unsigned char *buf;
-+ int s;
-+
-+ if(nomgcsfx){
-+ return 0;
-+ }else{
-+ if(size < need_buf_size){
-+ if((buf = (unsigned char *)calloc(need_buf_size, sizeof(char)))==NULL){
-+ fprintf(stderr,"Can't allocate memory\n");
-+ return 0;
-+ }
-+ if((fp = xv_fopen(fname, "r"))==NULL){
-+ fprintf(stderr,"Can't open file %s\n", fname);
-+ free(buf);
-+ return 0;
-+ }
-+ s = fread(buf, 1, need_buf_size, fp);
-+ if((magic = find_mgcsfx(fname, buf, s))!=NULL &&
-+ magic->input_command != NULL){
-+ free(buf);
-+ fclose(fp);
-+ return 1;
-+ }else{
-+ free(buf);
-+ fclose(fp);
-+ return 0;
-+ }
-+ }else{
-+ if((magic = find_mgcsfx(fname, buffer, size))!=NULL &&
-+ magic->input_command != NULL){
-+ return 1;
-+ }else{
-+ return 0;
-+ }
-+ }
-+ }
-+}
-+
-+#ifdef HAVE_MGCSFX_AUTO
-+char *mgcsfx_auto_input_com(fname)
-+char *fname;
-+{
-+ static char command[1024];
-+ mgcsfxtab *magic;
-+ char *ptr;
-+
-+ FILE *fp;
-+ unsigned char *buf;
-+ int s;
-+
-+ if((buf = (unsigned char *)calloc(need_buf_size, sizeof(char)))==NULL){
-+ fprintf(stderr,"Can't allocate memory\n");
-+ return NULL;
-+ }
-+ if((fp = xv_fopen(fname, "r"))==NULL){
-+ fprintf(stderr,"Can't open file %s\n", fname);
-+ free(buf);
-+ return NULL;
-+ }
-+ s = fread(buf, 1, need_buf_size, fp);
-+ if((magic = find_mgcsfx(fname, buf, s))!=NULL &&
-+ magic->input_command != NULL && magic->input_image_type == IT_AUTO){
-+ if ((ptr = strstr(magic->input_command, "%s"))){
-+ sprintf(command, magic->input_command, fname);
-+ }else{
-+ sprintf(command, "%s < %s", magic->input_command, fname);
-+ }
-+ free(buf);
-+ fclose(fp);
-+ return command;
-+ }else{
-+ free(buf);
-+ fclose(fp);
-+ return NULL;
-+ }
-+}
-+#endif /* HAVE_MGCSFX_AUTO */
-+
-+/***************************************************/
-+static mgcsfxtab *free_mgcsfx(m)
-+ mgcsfxtab *m;
-+{
-+ mgcsfxtab *next;
-+ if(m == NULL) return NULL;
-+ next = m->next;
-+ if(m->description != NULL) free(m->description);
-+ if(m->mgcsfx_type == T_MAGIC && m->dt.string_data != NULL)
-+ free(m->dt.string_data);
-+ if(m->suffix != NULL) free(m->suffix);
-+ if(m->input_command != NULL) free(m->input_command);
-+ if(m->output_command != NULL) free(m->output_command);
-+ free(m);
-+ return next;
-+}
-+
-+
-+
-+/***************************************************/
-+/* char c $B$^$?$O(B '\n' $B$G6h@Z$i$l$?J8;zNs$rl9g$O(B '\n' $B$r%9%H%j!<%`$KLa$9(B)
-+ */
-+#define CBUF_SIZE 1024
-+static char *fgettoken(fp, c)
-+ FILE *fp;
-+ int c; /* Real mean is char */
-+{
-+ char *buf;
-+ char *buf2;
-+ int i;
-+ int n=0;
-+ int max=0;
-+ int count = 1;
-+
-+ char *ss;
-+ char *se;
-+
-+ if((buf = (char *)calloc(CBUF_SIZE, sizeof(char))) == NULL){
-+ fprintf(stderr,"Can't allocate memory\n");
-+ exit(1);
-+ }
-+ max = CBUF_SIZE;
-+ count = 2;
-+
-+ do{
-+ if((i = getc(fp))==EOF || i == '\n' || i == c) break;
-+
-+ buf[n] = (char)i;
-+
-+ if(i != c && n == max-1){
-+ buf[max] = '\0';
-+ if((buf2 = (char *)calloc(CBUF_SIZE * count, sizeof(char))) == NULL){
-+ fprintf(stderr,"Can't allocate memory\n");
-+ exit(1);
-+ }
-+ strcpy(buf2, buf);
-+ free(buf);
-+ buf = buf2;
-+ buf2 = NULL;
-+ max = CBUF_SIZE * count;
-+ count++;
-+ }
-+
-+ n++;
-+ }while(i != c);
-+
-+ buf[n] = '\0';
-+
-+ /* $B:G=i$H:G8e$N6uGrJ8;z$r@Z$j5M$a$k(B */
-+ ss = buf + strspn(buf, " \t\b\r\n"); /* find the first non-white space */
-+ se = buf + strlen(buf); /* find the end of the string */
-+
-+ /* strip from the end first */
-+ while ((--se >= ss) && strchr(" \t\b\r\n", *se));
-+ *(++se) = '\0';
-+
-+ if(i == EOF && strlen(ss)==0){ /* EOF $B$J$i(B NULL $B$rJV$9(B */
-+ free(buf);
-+ return NULL;
-+ }else if(i == '\n' && strlen(ss)==0){ /* $B2~9T$N$_$N>l9g(B */
-+ static char cr[2] = {'\n','\0'};
-+ buf2 = strdup(cr);
-+ free(buf);
-+ return buf2;
-+ }else{ /* $BDL>o(B */
-+ if(i == '\n' && strlen(ss)>0) ungetc(i,fp);
-+ buf2 = strdup(ss);
-+ free(buf);
-+ return buf2;
-+ }
-+}
-+
-+
-+
-+/***************************************************/
-+/* $BJ8;zNsCf$NFC= '0') && (ptr[1] <= '7')){
-+ if ((ptr[2] >= '0') && (ptr[2] <= '7')){ /* \000 ...\377 */
-+ *cptr = ((*ptr - '0') * 64) +((ptr[1] - '0') * 8) +(ptr[1] - '0');
-+ ptr += 2;
-+ }else{ /* \00 ...\77 */
-+ *cptr = ((*ptr - '0') * 8) + (ptr[1] - '0');
-+ ++ptr;
-+ }
-+ }else{ /* \0 ...\7 */
-+ *cptr = *ptr - '0';
-+ }
-+ break;
-+ case 'x': /* Hexadecimal constant \x0 .. \xff */
-+ if (isxdigit (ptr[1])){
-+ *cptr = 0;
-+ while (isxdigit (*(++ptr)))
-+ *cptr = (*cptr * 16) +
-+ (*ptr > '9' ? tolower (*ptr) - ('a' - 10) : *ptr - '0');
-+ --ptr;
-+ break;
-+ }
-+ default:
-+ /* *(cptr++) = '\\'; No use for treat '\z' as 'z' */
-+ *cptr = *ptr;
-+ break;
-+ }
-+ }
-+ ++cptr;
-+ }
-+ *cptr = '\0';
-+ length = cptr - string_data;
-+ return length;
-+}
-+
-+/***************************************************/
-+static int type_mgcsfx(str)
-+ char *str;
-+{
-+ if(str == NULL){
-+ return T_UNKNOWN;
-+ }else if(!strcmp(str, "magic") || !strcmp(str, "MAGIC")){
-+ return T_MAGIC;
-+ }else if(!strcmp(str, "string") || !strcmp(str, "STRING")){
-+ return T_MAGIC;
-+ }else if(!strcmp(str, "suffix") || !strcmp(str, "SUFFIX")){
-+ return T_SUFFIX;
-+ }else if(!strcmp(str, "beint16") || !strcmp(str, "BEINT16")){
-+ return T_BEINT16;
-+ }else if(!strcmp(str, "leint16") || !strcmp(str, "LEINT16")){
-+ return T_LEINT16;
-+ }else if(!strcmp(str, "beint32") || !strcmp(str, "BEINT32")){
-+ return T_BEINT32;
-+ }else if(!strcmp(str, "leint32") || !strcmp(str, "LEINT32")){
-+ return T_LEINT32;
-+ }else{
-+ return T_UNKNOWN;
-+ }
-+}
-+
-+/***************************************************/
-+static int type_image(str)
-+ char *str;
-+{
-+ if(str == NULL){
-+ return IT_UNKNOWN;
-+#ifdef HAVE_MGCSFX_AUTO
-+ }else if(!strcmp(str, "auto") || !strcmp(str, "AUTO")){
-+ return IT_AUTO;
-+#endif /* HAVE_MGCSFX_AUTO */
-+ }else if(!strcmp(str, "pnm") || !strcmp(str, "PNM")){
-+ return IT_PNM;
-+ }else if(!strcmp(str, "ppm") || !strcmp(str, "PPM")){
-+ return IT_PPM;
-+ }else if(!strcmp(str, "pgm") || !strcmp(str, "PGM")){
-+ return IT_PGM;
-+ }else if(!strcmp(str, "pbm") || !strcmp(str, "PBM")){
-+ return IT_PBM;
-+ }else if(!strcmp(str, "pnm_raw") || !strcmp(str, "PNM_RAW")){
-+ return IT_PNM_RAW;
-+ }else if(!strcmp(str, "ppm_raw") || !strcmp(str, "PPM_RAW")){
-+ return IT_PPM_RAW;
-+ }else if(!strcmp(str, "pgm_raw") || !strcmp(str, "PGM_RAW")){
-+ return IT_PGM_RAW;
-+ }else if(!strcmp(str, "pbm_raw") || !strcmp(str, "PBM_RAW")){
-+ return IT_PBM_RAW;
-+ }else if(!strcmp(str, "pnm_ascii") || !strcmp(str, "PNM_ASCII")){
-+ return IT_PNM_ASCII;
-+ }else if(!strcmp(str, "ppm_ascii") || !strcmp(str, "PPM_ASCII")){
-+ return IT_PPM_ASCII;
-+ }else if(!strcmp(str, "pgm_ascii") || !strcmp(str, "PGM_ASCII")){
-+ return IT_PGM_ASCII;
-+ }else if(!strcmp(str, "pbm_ascii") || !strcmp(str, "PBM_ASCII")){
-+ return IT_PBM_ASCII;
-+
-+ }else if(!strcmp(str, "gif") || !strcmp(str, "GIF")){
-+ return IT_GIF;
-+ }else if(!strcmp(str, "jpeg") || !strcmp(str, "JPEG")){
-+ return IT_JPEG;
-+ }else if(!strcmp(str, "tiff") || !strcmp(str, "TIFF")){
-+ return IT_TIFF;
-+ }else if(!strcmp(str, "jfif") || !strcmp(str, "JFIF")){
-+ return IT_JFIF;
-+
-+ }else if(!strcmp(str, "xbm") || !strcmp(str, "XBM")){
-+ return IT_XBM;
-+ }else if(!strcmp(str, "xpm") || !strcmp(str, "XPM")){
-+ return IT_XPM;
-+ }else if(!strcmp(str, "bmp") || !strcmp(str, "BMP")){
-+ return IT_BMP;
-+ }else if(!strcmp(str, "sunras") || !strcmp(str, "SUNRAS")){
-+ return IT_SUNRAS;
-+ }else if(!strcmp(str, "iris") || !strcmp(str, "IRIS")){
-+ return IT_IRIS;
-+ }else if(!strcmp(str, "xwd") || !strcmp(str, "XWD")){
-+ return IT_XWD;
-+
-+ }else if(!strcmp(str, "mag") || !strcmp(str, "MAG")){
-+ return IT_MAG;
-+ }else if(!strcmp(str, "maki") || !strcmp(str, "MAKI")){
-+ return IT_MAKI;
-+ }else if(!strcmp(str, "pi") || !strcmp(str, "PI")){
-+ return IT_PI;
-+ }else if(!strcmp(str, "pic") || !strcmp(str, "PIC")){
-+ return IT_PIC;
-+ }else if(!strcmp(str, "pic2") || !strcmp(str, "PIC2")){
-+ return IT_PIC2;
-+
-+ }else{
-+ return IT_UNKNOWN;
-+ }
-+}
-+
-+/*--------------------------------------------------------------------------*/
-+#define mgcsfx_read_error(FILENAME, LINENUM, AFTERFIELD) \
-+fprintf (stderr,\
-+"%s: line %d: missing fields of %s field\n",\
-+FILENAME, LINENUM, AFTERFIELD);
-+
-+#define magic_type_error(FILENAME, LINENUM, MAGICNUMBER) \
-+fprintf (stderr,\
-+"%s: line %d: invalid field '%s'\n",\
-+FILENAME, LINENUM, MAGICNUMBER);
-+/*--------------------------------------------------------------------------*/
-+
-+/***************************************************/
-+static void read_mgcsfx(mgcsfx_table, fname)
-+ mgcsfxtab **mgcsfx_table;
-+ char *fname;
-+{
-+ FILE *fp;
-+ char *s;
-+ int line_number = 0;
-+ int str_len;
-+ int reach_end;
-+ int def_err;
-+
-+ char *description;
-+ char *mgcsfx_type;
-+ char *offset;
-+ char *magic;
-+ char *suffix;
-+ char *i_img;
-+ char *i_com;
-+ char *o_img;
-+ char *o_com;
-+
-+ mgcsfxtab *ent;
-+ mgcsfxtab **entry;
-+
-+
-+ if((fp=fopen(fname, "r"))==NULL){
-+ /* fprintf(stderr, "Can't open %s\n",fname); */
-+ return;
-+ }
-+
-+ while(1){
-+retry:
-+ line_number++;
-+ def_err = 0;
-+
-+ s= NULL;
-+ description = mgcsfx_type = offset = magic = suffix
-+ = i_img = i_com = o_img = o_com = NULL;
-+ reach_end = 0;
-+
-+ if((s = fgettoken(fp, ':'))==NULL) break; /* EOF $B$J$i=*$j(B */
-+ if(*s == '#'){/* $B@hF,$,(B '#' $B$J$iFI$_$H$P$9(B */
-+ while((s = fgettoken(fp, '\n'))!=NULL){
-+ if(*s == '\n'){
-+ free(s);
-+ goto retry;
-+ }
-+ free(s);
-+ }
-+ if(s == NULL) break;
-+ }else if(*s == '\n'){/* $B6u9T$OL5;k(B */
-+ free(s);
-+ goto retry;
-+ }
-+ if(strlen(s) > 0) description = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "data type");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) mgcsfx_type = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "byte offset");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) offset = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "magic number");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) magic = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "suffix");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) suffix = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "input image type");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) i_img = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "input command");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) i_com = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, ':'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ if(s != NULL) free(s);
-+ mgcsfx_read_error(fname, line_number, "output image type");
-+ goto next;
-+ }
-+ if(strlen(s) > 0) o_img = s;
-+ else free(s);
-+
-+ if((s = fgettoken(fp, '#'))==NULL || *s == '\n'){/* $B2?$b$J$$$J$i@_Dj%_%9(B */
-+ /*
-+ free(s);
-+ mgcsfx_read_error(fname, line_number, "output command");
-+ goto next;
-+ */
-+ if(s != NULL){
-+ *s = '\0';
-+ reach_end = 1;
-+ }
-+ }
-+ if(s != NULL){
-+ if(strlen(s) > 0) o_com = s;
-+ else free(s);
-+ }
-+
-+ if(reach_end == 0){
-+ while((s = fgettoken(fp, '\n'))!=NULL){/* $B9TKv$N%4%_$rnext = NULL;
-+ ent->description = NULL;
-+ ent->mgcsfx_type = T_UNKNOWN;
-+ ent->offset = 0;
-+ ent->string_len = 0;
-+ ent->suffix = NULL;
-+ ent->input_image_type = IT_UNKNOWN;
-+ ent->input_command = NULL;
-+ ent->output_image_type = IT_UNKNOWN;
-+ ent->output_command = NULL;
-+
-+ if(description != NULL){
-+ ent->description = description;
-+ description = NULL;
-+ }else{
-+ fprintf (stderr,"%s: line %d: undefined field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+
-+ if(mgcsfx_type == NULL){
-+ fprintf (stderr,"%s: line %d: undefined field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+ ent->mgcsfx_type = type_mgcsfx(mgcsfx_type);
-+ switch(ent->mgcsfx_type){
-+ case T_SUFFIX:
-+ if(suffix == NULL){
-+ fprintf (stderr,
-+ "%s: line %d: conflict definition : undefined field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+ case T_BEINT16:
-+ if (sscanf(magic, "%hi", &(ent->dt.int16_data)) != 1){
-+ magic_type_error(fname, line_number, magic);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+ case T_LEINT16:
-+ if (sscanf(magic, "%hi", &(ent->dt.int16_data)) != 1){
-+ magic_type_error(fname, line_number, magic);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+#ifdef ARCHITECTURE64
-+ case T_BEINT32:
-+ if (sscanf(magic, "%i", &(ent->dt.int32_data)) != 1){
-+ magic_type_error(fname, line_number, magic);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+ case T_LEINT32:
-+ if (sscanf(magic, "%i", &(ent->dt.int32_data)) != 1){
-+ magic_type_error(fname, line_number, magic);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+#else
-+ case T_BEINT32:
-+ if (sscanf(magic, "%li", &(ent->dt.int32_data)) != 1){
-+ magic_type_error(fname, line_number, magic);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+ case T_LEINT32:
-+ if (sscanf(magic, "%li", &(ent->dt.int32_data)) != 1){
-+ magic_type_error(fname, line_number, magic);
-+ def_err ++;
-+ goto next2;
-+ }
-+ break;
-+#endif /* ARCHITECTURE64 */
-+ case T_MAGIC:
-+ if(magic == NULL){
-+ fprintf (stderr,"%s: line %d: undefined field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+ if((str_len = string_fin(magic))<=0){
-+ fprintf (stderr,"%s: line %d: invalid field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+
-+ ent->string_len = str_len;
-+ if((ent->dt.string_data = (char *)malloc(str_len + 1))==NULL){
-+ fprintf(stderr,"Can't allocate memory\n");
-+ exit(1);
-+ }
-+ memcpy(ent->dt.string_data, magic, str_len + 1);
-+ break;
-+ case T_UNKNOWN:
-+ default:
-+ fprintf (stderr,"%s: line %d: invalid field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ break;
-+ };
-+
-+
-+ if(offset == NULL){
-+ if(ent->mgcsfx_type == T_MAGIC ||
-+ ent->mgcsfx_type == T_BEINT16 ||
-+ ent->mgcsfx_type == T_LEINT16 ||
-+ ent->mgcsfx_type == T_BEINT32 ||
-+ ent->mgcsfx_type == T_LEINT32){
-+ fprintf (stderr,
-+ "%s: line %d: conflict definition : undefined field.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+ }else{
-+ if(ent->mgcsfx_type != T_SUFFIX) sscanf(offset, "%i", &(ent->offset));
-+ }
-+
-+ if(suffix != NULL){
-+ ent->suffix = suffix;
-+ suffix = NULL;
-+ }
-+
-+ if((i_img == NULL && i_com == NULL) && (o_img == NULL || o_com == NULL)){
-+ fprintf (stderr,"%s: line %d: invalid definition.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+ if((o_img == NULL && o_com == NULL) && (i_img == NULL || i_com == NULL)){
-+ fprintf (stderr,"%s: line %d: invalid definition.\n",
-+ fname, line_number);
-+ def_err ++;
-+ goto next2;
-+ }
-+
-+ if(i_img != NULL && i_com != NULL){
-+ ent->input_image_type = type_image(i_img);
-+ ent->input_command = i_com;
-+ i_com = NULL;
-+ }else{
-+ ent->input_image_type = IT_UNKNOWN;
-+ ent->input_command = NULL;
-+ }
-+
-+ if(o_img != NULL && o_com != NULL){
-+ ent->output_image_type = type_image(o_img);
-+ ent->output_command = o_com;
-+ o_com = NULL;
-+ }else{
-+ ent->output_image_type = IT_UNKNOWN;
-+ ent->output_command = NULL;
-+ }
-+ /* end of create mgcsfxtab */
-+
-+
-+next2:;
-+
-+ if(def_err != 0 || DEBUG){
-+ fprintf(stderr,"Description : %s \t -> %s\n",
-+ description ? description : "--+--",
-+ ent->description ? ent->description : "-- error --");
-+ fprintf(stderr,"Type : %s \t -> %d\n",
-+ mgcsfx_type ? mgcsfx_type : "--+--",
-+ ent->mgcsfx_type);
-+ fprintf(stderr,"Offset : %s \t -> %d\n",
-+ offset ? offset : "--+--",
-+ ent->offset);
-+
-+ fprintf(stderr,"Magic : %s", magic ? magic : "--+--");
-+ switch(ent->mgcsfx_type){
-+ case T_BEINT16:
-+ case T_LEINT16:
-+ fprintf(stderr," \t -> %d\n",ent->dt.int16_data);
-+ break;
-+ case T_BEINT32:
-+ case T_LEINT32:
-+ fprintf(stderr," \t -> %ld\n",ent->dt.int32_data);
-+ break;
-+ case T_MAGIC:
-+ fprintf(stderr," \t -> %s\n",ent->dt.string_data);
-+ break;
-+ default:
-+ fprintf(stderr,"\n");
-+ break;
-+ };
-+
-+ fprintf(stderr,"Suffix : %s \t -> %s\n",
-+ suffix ? suffix : "--+--",
-+ ent->suffix ? ent->suffix : "--+--");
-+ fprintf(stderr,"i Image : %s \t -> %d\n",
-+ i_img ? i_img : "--+--",
-+ ent->input_image_type);
-+ fprintf(stderr,"i Command : %s \t -> %s\n",
-+ i_com ? i_com : "--+--",
-+ ent->input_command ? ent->input_command : "--+--");
-+ fprintf(stderr,"o Image : %s \t -> %d\n",
-+ o_img ? o_img : "--+--",
-+ ent->output_image_type);
-+ fprintf(stderr,"o Command : %s \t -> %s\n",
-+ o_com ? o_com : "--+--",
-+ ent->output_command ? ent->output_command : "--+--");
-+ fprintf(stderr,"\n");
-+ }
-+
-+ if(description != NULL) free(description);
-+ if(mgcsfx_type != NULL) free(mgcsfx_type);
-+ if(offset != NULL) free(offset);
-+ if(magic != NULL) free(magic);
-+ if(suffix != NULL) free(suffix);
-+ if(i_img != NULL) free(i_img);
-+ if(i_com != NULL) free(i_com);
-+ if(o_img != NULL) free(o_img);
-+ if(o_com != NULL) free(o_com);
-+
-+
-+ if(def_err != 0) goto next3;
-+
-+ /* Override any existing entry for this magic number/file type */
-+ for(entry = mgcsfx_table; *entry; entry = &((*entry)->next)){
-+ if((ent->mgcsfx_type == (*entry)->mgcsfx_type) &&
-+ (
-+ ((ent->offset == (*entry)->offset) &&
-+ (((ent->mgcsfx_type == T_BEINT16) &&
-+ (ent->dt.int16_data == (*entry)->dt.int16_data)) ||
-+ ((ent->mgcsfx_type == T_BEINT32) &&
-+ (ent->dt.int32_data == (*entry)->dt.int32_data)) ||
-+ ((ent->mgcsfx_type == T_LEINT16) &&
-+ (ent->dt.int16_data == (*entry)->dt.int16_data)) ||
-+ ((ent->mgcsfx_type == T_LEINT32) &&
-+ (ent->dt.int32_data == (*entry)->dt.int32_data)) ||
-+
-+ ((ent->mgcsfx_type == T_MAGIC) &&
-+ !memcmp(ent->dt.string_data, (*entry)->dt.string_data,
-+ ent->string_len))
-+ )) ||
-+ ((ent->mgcsfx_type == T_SUFFIX) &&
-+ !strcmp(ent->suffix, (*entry)->suffix))
-+ )
-+ ){
-+
-+ free ((*entry)->description);
-+ (*entry)->description = ent->description;
-+ ent->description = NULL;
-+
-+ (*entry)->input_image_type = ent->input_image_type;
-+ if ((*entry)->input_command) free ((*entry)->input_command);
-+ (*entry)->input_command = ent->input_command;
-+ ent->input_command = NULL;
-+
-+ (*entry)->output_image_type = ent->output_image_type;
-+ if ((*entry)->output_command) free ((*entry)->output_command);
-+ (*entry)->output_command = ent->output_command;
-+ ent->output_command = NULL;
-+
-+ free_mgcsfx(ent);
-+ break;
-+ }
-+ }
-+ if (!*entry){
-+ ent->next = NULL;
-+ *entry = ent;
-+ }
-+
-+ /* if(s == NULL) break; */
-+next3:;
-+ if(def_err != 0) free_mgcsfx(ent);
-+ } /* end of while(1) */
-+}
-+
-+
-+/***************************************************/
-+/* $B%^%8%C%/%J%s%P!$rF@$F!"FI$_9~$^$;$k(B */
-+static void init_mgcsfx ()
-+{
-+ extern char *getenv ();
-+
-+ char *home_dir;
-+ char fname[1024];
-+ mgcsfxtab *entry;
-+ int len;
-+ struct stat st;
-+
-+#ifdef USE_MGCSFX_PREPROCESSOR
-+ char *pp_fname;
-+#endif /* USE_MGCSFX_PREPROCESSOR */
-+
-+ mgcsfx_table = NULL;
-+
-+ mgcsfx_handler_setup();
-+
-+ if(nomgcsfx){
-+ mgcsfx_setup_flag = 1;
-+ nitem_mgcsfx = 0;
-+ desc_width = 0;
-+ }else{
-+ sprintf (fname, "%s/%s", SYSCONFDIR, MGCSFX_SITE_RC);
-+ if(stat(fname, &st) == 0 && S_ISREG(st.st_mode)){
-+ /* Read the site MagicSuffix table into a linked list */
-+#ifdef USE_MGCSFX_PREPROCESSOR
-+ if((pp_fname = make_preprocessed_file(fname)) != NULL){
-+ read_mgcsfx (&mgcsfx_table, pp_fname);
-+ }
-+ unlink(pp_fname);
-+#else
-+ read_mgcsfx (&mgcsfx_table, fname);
-+#endif /* USE_MGCSFX_PREPROCESSOR */
-+ }
-+
-+ /* Read the personal MgcSfx table into the list overriding site entries */
-+ if ((home_dir = getenv ("HOME"))){
-+ sprintf (fname, "%s/%s", home_dir, MGCSFX_RC);
-+ if(stat(fname, &st) == 0 && S_ISREG(st.st_mode)){
-+#ifdef USE_MGCSFX_PREPROCESSOR
-+ if((pp_fname = make_preprocessed_file(fname)) != NULL){
-+ read_mgcsfx (&mgcsfx_table, pp_fname);
-+ }
-+ unlink(pp_fname);
-+#else
-+ read_mgcsfx (&mgcsfx_table, fname);
-+#endif /* USE_MGCSFX_PREPROCESSOR */
-+ }
-+ }
-+
-+ mgcsfx_setup_flag = 1;
-+
-+ nitem_mgcsfx = 0;
-+ desc_width = 0;
-+ for (entry = mgcsfx_table; entry; entry = entry->next){
-+ nitem_mgcsfx ++;
-+ len = strlen(entry->description);
-+ if(len > desc_width) desc_width = len;
-+ if(max_offset_mgcsfx < entry->offset) max_offset_mgcsfx = entry->offset;
-+ if(entry->mgcsfx_type == T_MAGIC &&
-+ max_length_mgcsfx < entry->string_len)
-+ max_length_mgcsfx = entry->string_len;
-+ }
-+ if(max_length_mgcsfx == 0) max_length_mgcsfx = sizeof(int32);
-+ need_buf_size = max_offset_mgcsfx + max_length_mgcsfx + 1;/* 1 is safety */
-+ }
-+}
-+
-+/***************************************************/
-+/* $B%^%8%C%/%J%s%P!<$rD4$Y$F!"Dj5A$7$F$$$k%F!<%V%k$r8!:w$9$k(B
-+ $B%^%8%C%/%J%s%P!<$N%F!<%V%k$rFI$_9~$s$G$$$J$$$J$iFI$_9~$`(B */
-+static mgcsfxtab *find_mgcsfx (fname, buffer, buffer_size)
-+ char *fname;
-+ unsigned char *buffer;
-+ int buffer_size;
-+{
-+ mgcsfxtab *entry;
-+ int16 buf16;
-+ int32 buf32;
-+ char *suf;
-+
-+ if (mgcsfx_setup_flag == 0) init_mgcsfx ();
-+
-+ for (entry = mgcsfx_table; entry; entry = entry->next){
-+ switch (entry->mgcsfx_type){
-+ case T_BEINT16:
-+ if ((buffer_size > 0) &&
-+ ((entry->offset + sizeof (int16)) <= buffer_size)){
-+ buf16 = ((char)*(buffer + entry->offset) << 8) |
-+ ((char)*(buffer + entry->offset +1));
-+ if(entry->dt.int16_data == buf16) return entry;
-+ }
-+ break;
-+ case T_LEINT16:
-+ if ((buffer_size > 0) &&
-+ ((entry->offset + sizeof (int16)) <= buffer_size)){
-+ buf16 = ((char)*(buffer + entry->offset +1) << 8) |
-+ ((char)*(buffer + entry->offset));
-+ if(entry->dt.int16_data == buf16) return entry;
-+ }
-+ break;
-+ case T_BEINT32:
-+ if ((buffer_size > 0) &&
-+ ((entry->offset + sizeof (int32)) <= buffer_size)){
-+ buf32 = ((char)*(buffer + entry->offset) << 24) |
-+ ((char)*(buffer + entry->offset +1) << 16) |
-+ ((char)*(buffer + entry->offset +2) << 8) |
-+ ((char)*(buffer + entry->offset +3));
-+ if(entry->dt.int32_data == buf32) return entry;
-+ }
-+ break;
-+ case T_LEINT32:
-+ if ((buffer_size > 0) &&
-+ ((entry->offset + sizeof (int32)) <= buffer_size)){
-+ buf32 = ((char)*(buffer + entry->offset +3) << 24) |
-+ ((char)*(buffer + entry->offset +2) << 16) |
-+ ((char)*(buffer + entry->offset +1) << 8) |
-+ ((char)*(buffer + entry->offset));
-+ if(entry->dt.int32_data == buf32) return entry;
-+ }
-+ break;
-+ case T_MAGIC:
-+ if ((buffer_size > 0) &&
-+ ((entry->offset + entry->string_len)
-+ <= buffer_size) &&
-+ !memcmp (entry->dt.string_data, buffer + entry->offset,
-+ entry->string_len ))
-+ return entry;
-+ break;
-+ case T_SUFFIX:
-+ if(fname != NULL && entry->suffix != NULL){
-+ if(strlen(fname) - strlen(entry->suffix) > 0){
-+ suf = fname + (strlen(fname) - strlen(entry->suffix));
-+ if(!strcmp(suf, entry->suffix)) return entry;
-+ }
-+ }
-+ break;
-+ case T_UNKNOWN:
-+ default:
-+ return NULL;
-+ break;
-+ }
-+ }
-+ return NULL;
-+}
-+
-+
-+
-+
-+
-+/***************************************************/
-+/* $B%^%8%C%/%J%s%P!<$NDj5A$rD4$Y$F!"$=$l$K$"$o$;$?%3%^%s%I$rinput_command) ||
-+ (magic == NULL && mgcsfx && input_command_ex_flag)){
-+
-+ if(magic == NULL){
-+ if (fname != NULL && (ptr = strstr(input_command_ex, "%s"))){
-+ sprintf (command, input_command_ex, fname);
-+ }else{
-+ strcpy (command, input_command_ex);
-+ fname=NULL;
-+ }
-+ }else{
-+ /* Use stdin or give file name */
-+ if (fname != NULL && (ptr = strstr(magic->input_command, "%s"))){
-+ sprintf (command, magic->input_command, fname);
-+ }else{
-+ strcpy (command, magic->input_command);
-+ fname=NULL;
-+ }
-+ }
-+
-+ /* Do the pipe/fork/exec here */
-+ if (pipe (fd) < 0){
-+ fprintf (stderr, "Can't pipe : %s\n", file_name);
-+ close(file);
-+ return 0;
-+ }
-+
-+ if ((pid = vfork ()) < 0){
-+ fprintf (stderr, "Can't vfork : %s\n", file_name);
-+ close (fd[0]);
-+ close (fd[1]);
-+ close(file);
-+ return 0;
-+ }
-+
-+ if (!pid){
-+ close(0);
-+ if (fname == NULL || (open ("/dev/null", O_RDONLY) < 0)){
-+ dup(file);
-+ }
-+ close(file);
-+ close(1);
-+ dup(fd[1]);
-+ close(2);
-+ open("/dev/null", O_WRONLY);
-+ close(fd[0]);
-+ execl("/bin/sh", "/bin/sh", "-c", command, 0);
-+ _exit(127);
-+ }
-+
-+ close (fd[1]);
-+ dup2(fd[0], file);
-+ close (fd[0]);
-+ fname = NULL;
-+ magic_cur = magic;
-+ }
-+/* } while(magic != NULL); */
-+
-+ free(buffer);
-+
-+ if(magic_cur == NULL && mgcsfx && input_command_ex_flag){
-+ i_it = IT_PNM;
-+ i_com = input_command_ex;
-+ }else{
-+ i_it = magic_cur->input_image_type;
-+ i_com = magic_cur->input_command;
-+ }
-+
-+ if((magic_cur != NULL && i_com) ||
-+ (magic_cur == NULL && mgcsfx && input_command_ex_flag)){
-+ switch(i_it){
-+ case IT_PNM:
-+ case IT_PPM:
-+ case IT_PGM:
-+ case IT_PBM:
-+ case IT_PNM_RAW:
-+ case IT_PPM_RAW:
-+ case IT_PGM_RAW:
-+ case IT_PBM_RAW:
-+ case IT_PNM_ASCII:
-+ case IT_PPM_ASCII:
-+ case IT_PGM_ASCII:
-+ case IT_PBM_ASCII:
-+ rv = LoadPBM(file_name, pinfo, file);
-+ break;
-+ case IT_GIF:
-+ case IT_JPEG:
-+ case IT_TIFF:
-+ case IT_JFIF:
-+ case IT_XBM:
-+ case IT_XPM:
-+ case IT_BMP:
-+ case IT_SUNRAS:
-+ case IT_IRIS:
-+ case IT_XWD:
-+ case IT_MAG:
-+ case IT_MAKI:
-+ case IT_PI:
-+ case IT_PIC:
-+ case IT_PIC2:
-+ SetISTR(ISTR_WARNING, "Yet supported input image type (from filter output)");
-+ rv = 0;
-+ break;
-+ case IT_UNKNOWN:
-+ SetISTR(ISTR_WARNING, "Unknown input image type (from filter output)");
-+ rv = 0;
-+ break;
-+#ifdef HAVE_MGCSFX_AUTO
-+ case IT_AUTO:
-+#endif
-+ default:
-+ SetISTR(ISTR_WARNING, "Error in input image type (from filter output)");
-+ rv = 0;
-+ break;
-+ }
-+ }else{
-+ rv = 0;
-+ }
-+
-+ /* fail if pid still == -2? */
-+ while(wait(&pst) != pid); /* FIXME? pid isn't necessarily initialized... */
-+ if( *((char *)&pst) != 0 ) rv = 0;
-+
-+ input_command_ex_flag = 0;
-+
-+ return rv;
-+
-+ /* fclose(fp); close in Load??? */
-+ /* return 0; error */
-+ /* return 1; ok */
-+}
-+
-+
-+
-+
-+
-+/*--------------------------------------------------------------------------*/
-+#ifndef MGCSFX_DEFAULT_INPUT_COMMAND
-+# define MGCSFX_DEFAULT_INPUT_COMMAND "tifftopnm"
-+#endif
-+#ifndef MGCSFX_DEFAULT_OUTPUT_COMMAND
-+# define MGCSFX_DEFAULT_OUTPUT_COMMAND "pnmtotiff"
-+#endif
-+
-+int MSWIDE = 0;
-+int MSHIGH = 0;
-+
-+#define MS_NBUTTS 2
-+#define MS_BOK 0
-+#define MS_BCANC 1
-+#define BUTTW 60 /* width of buttons (OK or Cancel) */
-+#define BUTTH 24 /* height of buttons (OK or Cancel) */
-+#define RBSIZE 15 /* width and height of RB button (select, ON or OFF)*/
-+#define CWIDE 8 /* width of character */
-+/* #define CHIGH height of character defined in xv.h */
-+#define MARGIN 3 /* margin of button and label SPACING */
-+
-+#define MSD_TITLE "Save file with external command..."
-+#define MSD_RBTITLE "Type of Magic and Suffix"
-+#define MSD_IC_TITLE "input command"
-+
-+static BUTT msbut[MS_NBUTTS];
-+static RBUTT *typeRB;
-+
-+static char output_command_ex[1024];
-+static int output_command_ex_flag = 0;
-+
-+static int colorType;
-+
-+static int w_pid;
-+static int w_pstatus;
-+
-+#define MSNAMWIDE 252 /* width of 'file name' entry window */
-+#define MAXFNLEN 256 /* max len of filename being entered */
-+static char DialogFileName[MAXFNLEN+100]; /* filename being entered */
-+static int curPos, stPos, enPos; /* filename textedit stuff */
-+
-+
-+static mgcsfxtab *get_mgcsfx PARM((int));
-+static void changeSuffix PARM((int));
-+
-+static int WriteMGCSFX PARM((FILE**,byte*,int,int,int,
-+ byte*,byte*,byte*,int,int,char*,
-+ int, int, char*));
-+void CreateMGCSFXW PARM((void));
-+void MGCSFXDialog PARM((int));
-+int MGCSFXCheckEvent PARM((XEvent *));
-+int MGCSFXSaveParams PARM((char *, int));
-+
-+static void drawMSD PARM((int,int,int,int));
-+static void clickMSD PARM((int,int));
-+static void doCmd PARM((int));
-+static int writeMGCSFX PARM((void));
-+
-+static void changeSuffix PARM((int));
-+static void redrawNamMSD PARM((void));
-+static void showFNamMSD PARM((void));
-+static int keyinMSD PARM((int));
-+
-+int getInputCom PARM((void));
-+int getOutputCom PARM((void));
-+/*--------------------------------------------------------------------------*/
-+
-+/***************************************************/
-+/* $B$I$l$rA*$s$@$+D4$Y$k!##0$O%3%^%s%I$rF~NO$9$k$b$N$H$9$k(B */
-+static mgcsfxtab *get_mgcsfx(ms_type)
-+ int ms_type;
-+{
-+ mgcsfxtab *magic;
-+ int i;
-+
-+ magic = NULL;
-+ if(ms_type != 0){
-+ i = 1;
-+ for(magic = mgcsfx_table; (magic && inext){i++;}
-+ }
-+ return magic;
-+}
-+
-+/***************************************************/
-+/* $B30It%3%^%s%I$routput_command)){
-+
-+ /* Do the pipe/fork/exec here */
-+ if (pipe (fd) < 0){
-+ fprintf (stderr, "Can't pipe : %s\n", file_name);
-+ return -1;
-+ }
-+
-+ if ((pid = vfork ()) < 0){
-+ fprintf (stderr, "Can't vfork : %s\n", file_name);
-+ close (fd[0]);
-+ close (fd[1]);
-+ return -1;
-+ }
-+
-+ if (!pid){
-+ close(1);
-+ dup(file);
-+ close(file);
-+ close(0);
-+ dup(fd[0]);
-+ close(2);
-+ open("/dev/null", O_WRONLY);
-+ close(fd[1]);
-+ if(ms_type == 0){
-+ execl("/bin/sh", "/bin/sh", "-c", output_command_ex, 0);
-+ }else{
-+ execl("/bin/sh", "/bin/sh", "-c", magic->output_command, 0);
-+ }
-+ _exit(127);
-+ }
-+
-+ close (fd[0]);
-+ dup2(fd[1], file);
-+ close (fd[1]);
-+
-+ }else{
-+ return -1;
-+ }
-+
-+
-+ *fp = fdopen(file, "w");
-+
-+ /* sleep(1); Best way is wait for checking SIGCHLD, but it's feel waist.*/
-+
-+#ifdef USE_SIGCHLD
-+ if(w_p_fail != 2){
-+#endif
-+ if(ms_type == 0){
-+ rv = WritePBM(*fp,pic,ptype,w,h,rmap,gmap,bmap,numcols,colorstyle,
-+ 1, comment);
-+ }else{
-+ switch(magic -> output_image_type){
-+ case IT_PNM:
-+ case IT_PPM:
-+ case IT_PGM:
-+ case IT_PBM:
-+ case IT_PNM_RAW:
-+ case IT_PPM_RAW:
-+ case IT_PGM_RAW:
-+ case IT_PBM_RAW:
-+ rv = WritePBM(*fp,pic,ptype,w,h,rmap,gmap,bmap,numcols,colorstyle,
-+ 1, comment);
-+ break;
-+ case IT_PNM_ASCII:
-+ case IT_PPM_ASCII:
-+ case IT_PGM_ASCII:
-+ case IT_PBM_ASCII:
-+ rv = WritePBM(*fp,pic,ptype,w,h,rmap,gmap,bmap,numcols,colorstyle,
-+ 0, comment);
-+ break;
-+ case IT_GIF:
-+ case IT_JPEG:
-+ case IT_TIFF:
-+ case IT_JFIF:
-+ case IT_XBM:
-+ case IT_XPM:
-+ case IT_BMP:
-+ case IT_SUNRAS:
-+ case IT_IRIS:
-+ case IT_XWD:
-+ case IT_MAG:
-+ case IT_MAKI:
-+ case IT_PI:
-+ case IT_PIC:
-+ case IT_PIC2:
-+ SetISTR(ISTR_WARNING, "Yet supported output image type (to filter input)");
-+ rv = -1;
-+ break;
-+ case IT_UNKNOWN:
-+ SetISTR(ISTR_WARNING, "Unknown output image type (to filter input)");
-+ rv = -1;
-+ break;
-+#ifdef HAVE_MGCSFX_AUTO
-+ case IT_AUTO:
-+#endif
-+ default:
-+ SetISTR(ISTR_WARNING, "Error in output image type (to filter input)");
-+ rv = -1;
-+ break;
-+ }
-+ }
-+#ifdef USE_SIGCHLD
-+ }else{
-+ rv = -1;
-+ }
-+#endif
-+
-+#ifdef USE_SIGCHLD
-+ if(w_p_fail != 2){
-+#endif
-+ w_pid = pid;
-+#ifdef USE_SIGCHLD
-+ w_p_fail = 0;
-+ }else{
-+ rv = -1;
-+ }
-+#endif
-+
-+ output_command_ex_flag = 0;
-+
-+ return rv;
-+
-+ /* fclose(*fp); close in CloseOutFile in writeMGCSFX */
-+ /* return 0; ok */
-+ /* return -1; error */
-+}
-+
-+/***************************************************/
-+void CreateMGCSFXW()
-+{
-+ int y;
-+ int type_num;
-+ mgcsfxtab *entry;
-+
-+ if (mgcsfx_setup_flag == 0) init_mgcsfx ();
-+
-+ if(desc_width < strlen(MSD_IC_TITLE)) desc_width = strlen(MSD_IC_TITLE);
-+ nitem_mgcsfx ++;
-+
-+ MSWIDE = desc_width * CWIDE + RBSIZE + 36; /* 36 is start of RB button */
-+ MSHIGH = nitem_mgcsfx * (RBSIZE + MARGIN);
-+
-+ if(MSWIDE < strlen(MSD_TITLE) + 20) MSWIDE = strlen(MSD_TITLE) + 20;
-+ if(MSWIDE < strlen(MSD_RBTITLE) + 16) MSWIDE = strlen(MSD_RBTITLE) + 16;
-+ if(MSWIDE < MSNAMWIDE + 10) MSWIDE = MSNAMWIDE + 10;
-+ if(MSWIDE < BUTTW * 2 + 10) MSWIDE = BUTTW * 2 + 10;
-+
-+ MSHIGH += 55 + LINEHIGH + 10 + BUTTH + 10;
-+
-+ MSWIDE += 20; /* right side margin */
-+ MSHIGH += 10; /* RB buttun down side margin */
-+
-+
-+ mgcsfxW = CreateWindow("xv mgcsfx", "XVmgcsfx", NULL,
-+ MSWIDE, MSHIGH, infofg, infobg, 0);
-+ if (!mgcsfxW) FatalError("can't create mgcsfx window!");
-+
-+ XSelectInput(theDisp, mgcsfxW,
-+ ExposureMask | ButtonPressMask | KeyPressMask);
-+
-+ mgcsfxNameW = XCreateSimpleWindow(theDisp, mgcsfxW,
-+ 10, MSHIGH-LINEHIGH-10-BUTTH-10-1,
-+ (u_int) MSNAMWIDE+6, (u_int) LINEHIGH+5,
-+ 1, infofg, infobg);
-+ if (!mgcsfxNameW) FatalError("can't create mgcsfx name window");
-+ XSelectInput(theDisp, mgcsfxNameW, ExposureMask);
-+
-+ /* Ok $B%\%?%s(B */
-+ BTCreate(&msbut[MS_BOK], mgcsfxW,
-+ MSWIDE-BUTTW-10-BUTTW-10-1, MSHIGH-BUTTH-10-1,
-+ BUTTW, BUTTH,
-+ "Ok", infofg, infobg, hicol, locol);
-+ /* Cancel $B%\%?%s(B*/
-+ BTCreate(&msbut[MS_BCANC], mgcsfxW,
-+ MSWIDE-BUTTW-10-1, MSHIGH-BUTTH-10-1,
-+ BUTTW, BUTTH,
-+ "Cancel", infofg, infobg, hicol, locol);
-+
-+ y = 55;
-+ /* User should input command to exec external command */
-+ typeRB = RBCreate(NULL, mgcsfxW, 36, y, MSD_IC_TITLE,
-+ infofg, infobg,hicol,locol);
-+ y += (RBSIZE + MARGIN); /* 18 */
-+
-+ type_num = 1;
-+ for (entry = mgcsfx_table; entry; entry = entry->next){
-+ RBCreate(typeRB, mgcsfxW, 36, y, entry->description,
-+ infofg, infobg,hicol,locol);
-+ y += (RBSIZE + MARGIN); /* 18 */
-+ if(entry->output_command == NULL){
-+ RBSetActive(typeRB, type_num, 0); /* if no command, off */
-+ }
-+ type_num++;
-+ }
-+
-+ XMapSubwindows(theDisp, mgcsfxW);
-+}
-+
-+
-+/***************************************************/
-+void MGCSFXDialog(vis)
-+ int vis;
-+{
-+ if (vis) {
-+ CenterMapWindow(mgcsfxW, msbut[MS_BOK].x + msbut[MS_BOK].w/2,
-+ msbut[MS_BOK].y + msbut[MS_BOK].h/2, MSWIDE, MSHIGH);
-+ }
-+ else XUnmapWindow(theDisp, mgcsfxW);
-+ mgcsfxUp = vis;
-+}
-+
-+
-+/***************************************************/
-+int MGCSFXCheckEvent(xev)
-+ XEvent *xev;
-+{
-+ /* check event to see if it's for one of our subwindows. If it is,
-+ deal accordingly, and return '1'. Otherwise, return '0' */
-+
-+ int rv;
-+ rv = 1;
-+
-+ if (!mgcsfxUp) return (0);
-+
-+ if (xev->type == Expose) {
-+ int x,y,w,h;
-+ XExposeEvent *e = (XExposeEvent *) xev;
-+ x = e->x; y = e->y; w = e->width; h = e->height;
-+
-+ if (e->window == mgcsfxW) drawMSD(x, y, w, h);
-+ else rv = 0;
-+ }
-+
-+ else if (xev->type == ButtonPress) {
-+ XButtonEvent *e = (XButtonEvent *) xev;
-+ int x,y;
-+ x = e->x; y = e->y;
-+
-+ if (e->button == Button1) {
-+ if (e->window == mgcsfxW) clickMSD(x,y);
-+ else rv = 0;
-+ } /* button1 */
-+ else rv = 0;
-+ } /* button press */
-+
-+ else if (xev->type == KeyPress) {
-+ XKeyEvent *e = (XKeyEvent *) xev;
-+ char buf[128]; KeySym ks; XComposeStatus status;
-+ int stlen;
-+
-+ stlen = XLookupString(e,buf,128,&ks,&status);
-+ buf[stlen] = '\0';
-+
-+ if (e->window == mgcsfxW) {
-+ if (stlen) {
-+ keyinMSD(buf[0]);
-+ }
-+ }
-+ else rv = 0;
-+ }
-+ else rv = 0;
-+
-+ if (rv == 0 && (xev->type == ButtonPress || xev->type == KeyPress)) {
-+ XBell(theDisp, 50);
-+ rv = 1; /* eat it */
-+ }
-+
-+ return (rv);
-+}
-+
-+
-+/***************************************************/
-+int MGCSFXSaveParams(fname, col)
-+ char *fname;
-+ int col;
-+{
-+ colorType = col;
-+ strcpy(DialogFileName, GetDirFName());
-+ return (0);
-+}
-+
-+/***************************************************/
-+/* $B%@%$%"%m%0$rI=<($9$k$H$-$N=hM}(B */
-+static void drawMSD(x,y,w,h)
-+ int x,y,w,h;
-+{
-+ int i;
-+ XRectangle xr;
-+
-+ xr.x = x; xr.y = y; xr.width = w; xr.height = h;
-+ XSetClipRectangles(theDisp, theGC, 0,0, &xr, 1, Unsorted);
-+
-+ XSetForeground(theDisp, theGC, infofg);
-+ XSetBackground(theDisp, theGC, infobg);
-+
-+ for (i = 0; i < MS_NBUTTS; i++) BTRedraw(&msbut[i]);
-+
-+ ULineString(mgcsfxW, typeRB->x-16, typeRB->y-3-DESCENT,
-+ MSD_RBTITLE);
-+ RBRedraw(typeRB, -1);
-+
-+ DrawString(mgcsfxW, 20, 29, MSD_TITLE);
-+
-+ XSetClipMask(theDisp, theGC, None);
-+
-+ showFNamMSD();
-+}
-+
-+/***************************************************/
-+/* $B%@%$%"%m%0$r%/%j%C%/$7$?$H$-$N=hM}(B */
-+static void clickMSD(x,y)
-+ int x,y;
-+{
-+ int i;
-+ BUTT *bp;
-+
-+ /* check BUTTs */
-+
-+ /* check the RBUTTS first, since they don't DO anything */
-+ if ((i = RBClick(typeRB, x,y)) >= 0) { /* $BA*Br(B(type)$B%\%?%s$N=hM}(B */
-+ (void) RBTrack(typeRB, i); /* $BA*Br(B(type)$B%\%?%s$r2!$7$?$H$-(B */
-+ changeSuffix(i);
-+ return;
-+ }
-+
-+ for (i = 0; i < MS_NBUTTS; i++) { /* Ok,Cancel $B%\%?%s$N=hM}(B */
-+ bp = &msbut[i];
-+ if (PTINRECT(x, y, bp->x, bp->y, bp->w, bp->h))
-+ break;
-+ }
-+ if (i < MS_NBUTTS) /* found one */ /* Ok,Cancel $B%\%?%s$r2!$7$?$H$-(B */
-+ if (BTTrack(bp)) doCmd(i);
-+}
-+
-+/***************************************************/
-+/* $B%\%?%s(B(Ok, Cancel) $B$N=hM}(B */
-+static void doCmd(cmd)
-+ int cmd;
-+{
-+ int rv;
-+
-+ switch (cmd) {
-+ case MS_BOK: /* Ok button */ {
-+ char *fullname;
-+
-+ rv = writeMGCSFX(); /* Save with filter(MGCSFX) */
-+ MGCSFXDialog(0);
-+
-+ fullname = GetDirFullName();
-+ if (!ISPIPE(fullname[0])) {
-+ XVCreatedFile(fullname);
-+ if(!rv) StickInCtrlList(0);
-+ }
-+ }
-+ break;
-+ case MS_BCANC: /* Cancel button */
-+ DialogFileName[0] = '\0';
-+ curPos = stPos = enPos = 0;
-+ MGCSFXDialog(0);
-+ break;
-+ default:
-+ break;
-+ }
-+}
-+
-+/*******************************************/
-+static int writeMGCSFX()
-+{
-+ int rv, type;
-+ int ptype, w, h, pfree, nc;
-+ byte *inpix, *rmap, *gmap, *bmap;
-+
-+ FILE *fp = NULL;
-+ int file;
-+ char *fullname;
-+
-+ rv = -1;
-+ type = RBWhich(typeRB);
-+
-+ SetDirFName(DialogFileName); /* change filename in dir dialog */
-+ fullname = GetDirFullName();
-+
-+ if(type == 0){
-+ if(getOutputCom() == 0) return rv;
-+ }
-+
-+ file = OpenOutFileDesc(fullname);
-+ if(file < 0) return rv;
-+
-+ WaitCursor();
-+ inpix = GenSavePic(&ptype, &w, &h, &pfree, &nc, &rmap, &gmap, &bmap);
-+
-+ rv = WriteMGCSFX(&fp, inpix, ptype, w, h,
-+ rmap, gmap, bmap, nc, colorType, fullname,
-+ type, file, picComments);
-+
-+ SetCursors(-1);
-+
-+ if (CloseOutFile(fp, fullname, rv) == 0) DirBox(0);
-+
-+ WaitCursor();
-+#ifdef USE_SIGCHLD
-+ if(w_p_fail == 0){
-+#endif
-+ while(wait(&w_pstatus) != w_pid); /* if( *((char *)&w_pstatus) != 0 ) ; */
-+#ifdef USE_SIGCHLD
-+ }else{
-+ w_p_fail = 0;
-+ }
-+#endif
-+ w_pid = 0;
-+ w_pstatus = 0;
-+
-+ if (pfree) free(inpix);
-+ return rv;
-+}
-+
-+
-+/***************************************/
-+static void changeSuffix(ms_type)
-+ int ms_type;
-+{
-+ /* see if there's a common suffix at the end of the DialogFileName.
-+ if there is, remember what case it was (all caps or all lower), lop
-+ it off, and replace it with a new appropriate suffix, in the
-+ same case */
-+
-+ int allcaps;
-+ char *suffix, *sp, *dp, lowsuf[512];
-+ mgcsfxtab *magic;
-+
-+ /* find the last '.' in the DialogFileName */
-+ suffix = (char *) rindex(DialogFileName, '.');
-+ if (!suffix) return;
-+ suffix++; /* point to first letter of the suffix */
-+
-+ /* check for all-caposity */
-+ for (sp = suffix, allcaps=1; *sp; sp++)
-+ if (islower(*sp)) allcaps = 0;
-+
-+ /* copy the suffix into an all-lower-case buffer */
-+ for (sp=suffix, dp=lowsuf; *sp; sp++, dp++) {
-+ *dp = (isupper(*sp)) ? tolower(*sp) : *sp;
-+ }
-+ *dp = '\0';
-+
-+
-+ magic = get_mgcsfx(ms_type);
-+ if(magic != NULL && magic->suffix != NULL){
-+ strcpy(lowsuf,(magic->suffix)+1);
-+
-+ if (allcaps) { /* upper-caseify lowsuf */
-+ for (sp=lowsuf; *sp; sp++)
-+ *sp = (islower(*sp)) ? toupper(*sp) : *sp;
-+ }
-+
-+ /* one other case: if the original suffix started with a single
-+ capital letter, make the new suffix start with a single cap */
-+ if (isupper(suffix[0])) lowsuf[0] = toupper(lowsuf[0]);
-+
-+ strcpy(suffix, lowsuf); /* tack onto DialogFileName */
-+ showFNamMSD();
-+ }
-+}
-+
-+/***************************************************/
-+/* $B%@%$%"%m%0Fb$K%U%!%$%k%M!<%`$rI=<($9$k$H$-$N=hM}(B ($B2<@A$1(B)*/
-+static void redrawNamMSD()
-+{
-+ int cpos;
-+
-+ /* draw substring DialogFileName[stPos:enPos] and cursor */
-+
-+ Draw3dRect(mgcsfxNameW, 0, 0, (u_int) MSNAMWIDE+5, (u_int) LINEHIGH+4, R3D_IN, 2,
-+ hicol, locol, infobg);
-+
-+ XSetForeground(theDisp, theGC, infofg);
-+
-+ if (stPos>0) { /* draw a "there's more over here" doowah */
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, 0,0,0,LINEHIGH+5);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, 1,0,1,LINEHIGH+5);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, 2,0,2,LINEHIGH+5);
-+ }
-+
-+ if ((size_t) enPos < strlen(DialogFileName)) {
-+ /* draw a "there's more over here" doowah */
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, MSNAMWIDE+5,0,MSNAMWIDE+5,LINEHIGH+5);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, MSNAMWIDE+4,0,MSNAMWIDE+4,LINEHIGH+5);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, MSNAMWIDE+3,0,MSNAMWIDE+3,LINEHIGH+5);
-+ }
-+
-+ XDrawString(theDisp, mgcsfxNameW, theGC,3,ASCENT+3,DialogFileName+stPos, enPos-stPos);
-+
-+ cpos = XTextWidth(mfinfo, &DialogFileName[stPos], curPos-stPos);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, 3+cpos, 2, 3+cpos, 2+CHIGH+1);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, 3+cpos, 2+CHIGH+1, 5+cpos, 2+CHIGH+3);
-+ XDrawLine(theDisp, mgcsfxNameW, theGC, 3+cpos, 2+CHIGH+1, 1+cpos, 2+CHIGH+3);
-+}
-+
-+/***************************************************/
-+/* $B%@%$%"%m%0Fb$K%U%!%$%k%M!<%`$rI=<($9$k(B */
-+static void showFNamMSD()
-+{
-+ int len;
-+
-+ len = strlen(DialogFileName);
-+
-+ if (curPosenPos) enPos = curPos;
-+
-+ if (stPos>len) stPos = (len>0) ? len-1 : 0;
-+ if (enPos>len) enPos = (len>0) ? len-1 : 0;
-+
-+ /* while substring is shorter than window, inc enPos */
-+
-+ while (XTextWidth(mfinfo, &DialogFileName[stPos], enPos-stPos) < MSNAMWIDE
-+ && enPos MSNAMWIDE) {
-+ if (enPos != curPos) enPos--;
-+ else stPos++;
-+ }
-+
-+
-+ if (ctrlColor) XClearArea(theDisp, mgcsfxNameW, 2,2, (u_int) MSNAMWIDE+5-3,
-+ (u_int) LINEHIGH+4-3, False);
-+ else XClearWindow(theDisp, mgcsfxNameW);
-+
-+ redrawNamMSD();
-+ BTSetActive(&msbut[MS_BOK], strlen(DialogFileName)!=0);
-+}
-+
-+/***************************************************/
-+/* $B%-!=' ' && c<'\177') { /* printable characters */
-+ /* note: only allow 'piped commands' in savemode... */
-+
-+ /* only allow spaces in 'piped commands', not filenames */
-+ if (c==' ' && (!ISPIPE(DialogFileName[0]) || curPos==0)) return (-1);
-+
-+ /* only allow vertbars in 'piped commands', not filenames */
-+ if (c=='|' && curPos!=0 && !ISPIPE(DialogFileName[0])) return(-1);
-+
-+ if (len >= MAXFNLEN-1) return(-1); /* max length of string */
-+ xvbcopy(&DialogFileName[curPos], &DialogFileName[curPos+1], (size_t) (len-curPos+1));
-+ DialogFileName[curPos]=c; curPos++;
-+ }
-+
-+ else if (c=='\010' || c=='\177') { /* BS or DEL */
-+ if (curPos==0) return(-1); /* at beginning of str */
-+ xvbcopy(&DialogFileName[curPos], &DialogFileName[curPos-1], (size_t) (len-curPos+1));
-+ curPos--;
-+ }
-+
-+ else if (c=='\025') { /* ^U: clear entire line */
-+ DialogFileName[0] = '\0';
-+ curPos = 0;
-+ }
-+
-+ else if (c=='\013') { /* ^K: clear to end of line */
-+ DialogFileName[curPos] = '\0';
-+ }
-+
-+ else if (c=='\001') { /* ^A: move to beginning */
-+ curPos = 0;
-+ }
-+
-+ else if (c=='\005') { /* ^E: move to end */
-+ curPos = len;
-+ }
-+
-+ else if (c=='\004') { /* ^D: delete character at curPos */
-+ if (curPos==len) return(-1);
-+ xvbcopy(&DialogFileName[curPos+1], &DialogFileName[curPos], (size_t) (len-curPos));
-+ }
-+
-+ else if (c=='\002') { /* ^B: move backwards char */
-+ if (curPos==0) return(-1);
-+ curPos--;
-+ }
-+
-+ else if (c=='\006') { /* ^F: move forwards char */
-+ if (curPos==len) return(-1);
-+ curPos++;
-+ }
-+
-+ else if (c=='\012' || c=='\015') { /* CR(\r) or LF(\n) */
-+ FakeButtonPress(&msbut[MS_BOK]);
-+ }
-+
-+ else if (c=='\033') { /* ESC = Cancel */
-+ FakeButtonPress(&msbut[MS_BCANC]);
-+ }
-+
-+ else if (c=='\011') { /* tab = filename expansion */
-+ if (1 /* !autoComplete() */) XBell(theDisp, 0);
-+ else {
-+ curPos = strlen(DialogFileName);
-+ }
-+ }
-+
-+ else return(-1); /* unhandled character */
-+
-+ showFNamMSD();
-+
-+ return(0);
-+}
-+
-+
-+/*******************************************/
-+int getInputCom()
-+{
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ int i;
-+
-+ strcpy(input_command_ex, MGCSFX_DEFAULT_INPUT_COMMAND);
-+ i = GetStrPopUp("Input External Command (Input is PNM):", labels, 2,
-+ input_command_ex, 1024, "",0);
-+ if (i == 0 && strlen(input_command_ex) != 0){
-+ input_command_ex_flag = 1;
-+ return 1;
-+ }else{
-+ input_command_ex_flag = 0;
-+ return 0;
-+ }
-+}
-+
-+int getOutputCom()
-+{
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ int i;
-+
-+ strcpy(output_command_ex, MGCSFX_DEFAULT_OUTPUT_COMMAND);
-+ i = GetStrPopUp("Input External Command (Output is PNM_RAW):", labels, 2,
-+ output_command_ex, 1024, "",0);
-+ if (i == 0 && strlen(output_command_ex) != 0){
-+ output_command_ex_flag = 1;
-+ return 1;
-+ }else{
-+ output_command_ex_flag = 0;
-+ return 0;
-+ }
-+}
-+
-+#ifdef SVR4
-+Sigfunc *
-+xv_signal(signo, func)
-+ int signo;
-+ Sigfunc *func;
-+{
-+ struct sigaction act, oact;
-+
-+ act.sa_handler = func;
-+ sigemptyset(&act.sa_mask);
-+ act.sa_flags = 0;
-+ act.sa_flags |= SA_RESTART;
-+
-+ if (sigaction(signo, &act, &oact) < 0)
-+ return SIG_ERR;
-+
-+ return oact.sa_handler;
-+}
-+#endif
-+
-+#endif /* HAVE_MGCSFX */
-diff -u -r --new-file xv-3.10a.orig/xvml.c xv-3.10a/xvml.c
---- xv-3.10a.orig/xvml.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvml.c 2005-04-18 00:57:34.000000000 -0500
-@@ -0,0 +1,989 @@
-+/*
-+ * xvml.c - makes text item structure for multi-lingual textviewer.
-+ *
-+ * Entry Points:
-+ * struct ml_text *ml_draw_text()
-+ * struct context *ml_create_context()
-+ * int ml_set_charsets()
-+ * void get_monofont_size()
-+ */
-+
-+#include "xv.h"
-+#include
-+
-+#ifdef TV_MULTILINGUAL /* whole this file. */
-+
-+#include "xvml.h"
-+#define HAVE_STRDUP 1
-+#define USE_MULE_EXTENSION
-+
-+#ifndef __STDC__
-+#define CHAR char
-+#else
-+#define CHAR int
-+#endif
-+
-+#define CODE_SI 0x0e /* LS0 */
-+#define CODE_SO 0x0f /* LS1 */
-+#define CODE_SS2 ((unsigned char) 0x8e)
-+#define CODE_SS3 ((unsigned char) 0x8f)
-+
-+int ml_tab_width = 64; /* dots */
-+
-+struct charset {
-+ int bpc; /* bytes per char */
-+ int noc; /* number of chars */
-+ char designator;
-+ char *registry;
-+ int bit7;
-+
-+ int loaded;
-+ char *fontname;
-+
-+ XFontStruct *fs;
-+} charset[] = {
-+ { 1, 94, 'B', "iso8859-1", 0, 0, NULL, NULL},
-+ { 1, 96, 'A', "iso8859-1", 1, 0, NULL, NULL},
-+ { 1, 94, '0', "omron_udc_zh-0", 0, 0, NULL, NULL},
-+ { 1, 94, '2', "mulearabic-0", 0, 0, NULL, NULL},
-+ { 1, 94, '3', "mulearabic-1", 0, 0, NULL, NULL},
-+ { 1, 94, '4', "mulearabic-2", 0, 0, NULL, NULL},
-+ { 1, 94, 'J', "jisx0201.1976-0", 0, 0, NULL, NULL},
-+ { 1, 96, '0', "muleipa-1", 1, 0, NULL, NULL},
-+ { 1, 96, '1', "viscii1.1-1", 1, 0, NULL, NULL},
-+ { 1, 96, '2', "viscii1.1-1", 1, 0, NULL, NULL},
-+ { 1, 96, 'B', "iso8859-2", 1, 0, NULL, NULL},
-+ { 1, 96, 'C', "iso8859-3", 1, 0, NULL, NULL},
-+ { 1, 96, 'D', "iso8859-4", 1, 0, NULL, NULL},
-+ { 1, 96, 'T', "tis620.1986-0", 1, 0, NULL, NULL},
-+ { 1, 96, 'F', "iso8859-7", 1, 0, NULL, NULL},
-+ { 1, 96, 'G', "iso8859-6", 1, 0, NULL, NULL},
-+ { 1, 96, 'H', "iso8859-8", 1, 0, NULL, NULL},
-+ { 1, 94, 'I', "jisx0201.1976-0", 1, 0, NULL, NULL},
-+ { 1, 96, 'L', "iso8859-5", 1, 0, NULL, NULL},
-+ { 1, 96, 'M', "iso8859-9", 1, 0, NULL, NULL},
-+ { 2, 94, '2', "ethio-0", 0, 0, NULL, NULL},
-+ { 2, 94, '@', "jisx0208.1978", 0, 0, NULL, NULL},
-+ { 2, 94, 'A', "gb2312.1980-0", 0, 0, NULL, NULL},
-+ { 2, 94, 'B', "jisx0208.1983-0", 0, 0, NULL, NULL},
-+ { 2, 94, 'C', "ksc5601.1987-0", 0, 0, NULL, NULL},
-+ { 2, 94, 'D', "jisx0212.1990-0", 0, 0, NULL, NULL},
-+ { 2, 94, '0', "big5.eten-0", 0, 0, NULL, NULL},
-+ { 2, 94, '1', "big5.hku-0", 0, 0, NULL, NULL},
-+ /* End Mark */
-+ { 0, 0, 0, NULL, 0, 0, NULL, NULL},
-+};
-+#define NR_CHARSETS ((int) (sizeof charset / sizeof charset[0]))
-+
-+static struct charset *ascii = NULL;
-+
-+struct context {
-+ struct charset *g[4];
-+ struct charset **gl, **gr;
-+ struct charset **ss;
-+ int eol; /* 0: \n, 1: \r\n, 2: \r, 3: any */
-+ int valid[4]; /* g[i] is valid? */
-+ int short_form; /* allow shortened designator sequence? */
-+ int lock_shift; /* allow locking shift? */
-+
-+ unsigned char *cbuf, *cbp;
-+ struct ml_text text;
-+ int line;
-+ int delta;
-+ int toolong;
-+
-+ Display *dpy;
-+ Screen *scr;
-+ Window root_win;
-+};
-+#define DPY (context->dpy)
-+#define SCR (context->scr)
-+#define ROOT_WIN (context->root_win)
-+
-+static unsigned char *escape_sequence PARM((unsigned char *));
-+static unsigned char *designator_sequence PARM((unsigned char *));
-+static void locking_shift PARM((unsigned CHAR));
-+static void single_shift PARM((unsigned CHAR));
-+static void put_unknown_char PARM((unsigned CHAR));
-+static struct charset *search_charset PARM((int, int, int));
-+static void pack_string PARM((struct charset *,
-+ unsigned char *, int));
-+static void init_xrm PARM((void));
-+static void init_xrm_fonts PARM((void));
-+static void init_xrm_tab PARM((void));
-+#ifndef HAVE_STRDUP
-+static char *strdup PARM((char *));
-+#endif
-+
-+static char *default_fonts[] = { /* default for xrm_fonts */
-+ "-sony-fixed-medium-r-normal--16-*-*-*-*-*-iso8859-1",
-+ "-jis-fixed-medium-r-normal--16-*-*-*-*-*-jisx0208.1983-0",
-+};
-+static int xrm_nfonts;
-+static char **xrm_fonts;
-+
-+static struct context *context; /* current context */
-+
-+struct ml_text *ml_draw_text(ctx, string, len)
-+ struct context *ctx;
-+ char *string;
-+ int len;
-+{
-+ unsigned char *str = (unsigned char *) string;
-+ unsigned char *estr = str + len;
-+
-+ context = ctx;
-+
-+ if(ascii == NULL){
-+ fputs("ml_draw_text: call ml_set_charsets, first.\n", stderr);
-+ return NULL;
-+ }
-+
-+ if(!str)
-+ return &context->text;
-+
-+ WaitCursor();
-+
-+ if (context->text.maxlines != 0) {
-+ struct ml_text *tp = &context->text;
-+ struct ml_line *lp;
-+ int i;
-+ for (i = tp->nlines, lp = tp->lines; i > 0; i--, lp++) {
-+ if (lp->maxitems != 0)
-+ free((char *) lp->items);
-+ }
-+ free((char *) tp->lines);
-+ tp->maxlines = tp->nlines = 0;
-+ }
-+ if (context->cbuf != NULL)
-+ free((char *) context->cbuf);
-+ context->cbp = (unsigned char *) malloc((size_t) len * 8);/* all \xxx */
-+ context->cbuf = context->cbp;
-+ context->line = 0;
-+ context->delta = 0;
-+ context->ss = NULL;
-+
-+ while(str < estr){
-+ if((*str & 0x80) == 0){ /* left half */
-+ struct charset *cs = context->ss ? *context->ss : *context->gl;
-+ unsigned char min_char, max_char;
-+ if (cs != NULL) {
-+ if(cs->noc == 94){
-+ min_char = 0x21;
-+ max_char = 0x7e;
-+ }else{
-+ min_char = 0x20;
-+ max_char = 0x7f;
-+ }
-+ }
-+
-+ if (cs == NULL)
-+ put_unknown_char(*str++);
-+ else if(*str < min_char || *str > max_char){ /* C1 */
-+ switch(*str){
-+ case ' ':
-+ {
-+ unsigned char *p = str + 1;
-+ while (*p == ' ' && p < estr)
-+ p++;
-+ pack_string(ascii, str, (int) (p - str));
-+ str = p;
-+ }
-+ break;
-+
-+ case '\t':
-+ pack_string(ascii, str++, 0);
-+ break;
-+
-+ case '\n':
-+ switch (context->eol) {
-+ case 0: /* unix type eol */
-+ pack_string(ascii, str, 0);
-+ WaitCursor();
-+ str++;
-+ break;
-+ case 1: /* dos type eol */
-+ case 2: /* mac type eol */
-+ put_unknown_char('\n');
-+ str++;
-+ break;
-+ case 3: /* any type eol */
-+ pack_string(ascii, str++, 0);
-+ while (*str == '\n' || *str == '\r')
-+ str++;
-+ WaitCursor();
-+ break;
-+ }
-+ break;
-+
-+ case '\r':
-+ switch (context->eol) {
-+ case 0:
-+ put_unknown_char('\r');
-+ str++;
-+ break;
-+ case 1:
-+ str++;
-+ if (*str == '\n')
-+ pack_string(ascii, str++, 0);
-+ else
-+ put_unknown_char('\r');
-+ break;
-+ case 2:
-+ pack_string(ascii, str, 0);
-+ WaitCursor();
-+ str++;
-+ break;
-+ case 3:
-+ pack_string(ascii, str++, 0);
-+ while (*str == '\n' || *str == '\r')
-+ str++;
-+ WaitCursor();
-+ break;
-+ }
-+ break;
-+
-+ case '\033':
-+ {
-+ unsigned char *p;
-+ str++;
-+ if((p = escape_sequence(str)) == str)
-+ put_unknown_char('\033');
-+ else
-+ str = p;
-+ }
-+ break;
-+
-+ case CODE_SI:
-+ case CODE_SO:
-+ if (!context->lock_shift)
-+ put_unknown_char((unsigned int) *str++);
-+ else
-+ locking_shift((unsigned int) *str++);
-+ break;
-+
-+ default:
-+ put_unknown_char((unsigned int) *str++);
-+ }
-+ }else{ /* GL */
-+ if (context->ss != NULL) {
-+ pack_string(cs, str, 1);
-+ str += cs->bpc;
-+ context->ss = NULL;
-+ } else {
-+ int n;
-+
-+ if (cs->bpc == 1) {
-+ unsigned char *p = str;
-+ for (n = 0; p < estr; n++) {
-+ if (*p < min_char || *p > max_char)
-+ break;
-+ p++;
-+ }
-+ pack_string(cs, str, n);
-+ str = p;
-+ } else {
-+ unsigned char *p = str;
-+ for (n = 0; p < estr - 1; n++) {
-+ if (*p < min_char || *p > max_char ||
-+ *(p + 1) < min_char || *(p + 1) > max_char)
-+ break;
-+ p += 2;
-+ }
-+ if (n > 0)
-+ pack_string(cs, str, n);
-+ else
-+ put_unknown_char(*p++);
-+ str = p;
-+ }
-+ }
-+ }
-+ }else{ /* right half */
-+ struct charset *cs = context->ss ? *context->ss : *context->gr;
-+ unsigned char min_char, max_char;
-+ if (cs != NULL) {
-+ if(cs->noc == 94){
-+ min_char = 0xa1;
-+ max_char = 0xfe;
-+ }else{
-+ min_char = 0xa0;
-+ max_char = 0xff;
-+ }
-+ }
-+
-+ if (cs == NULL)
-+ put_unknown_char(*str++);
-+ else if(*str < min_char || *str > max_char){ /* C2 */
-+ unsigned char c = *str++;
-+ switch(c){
-+ case CODE_SS2:
-+ case CODE_SS3:
-+ single_shift((unsigned CHAR) c);
-+ break;
-+ default:
-+ put_unknown_char(c);
-+ }
-+ }else{ /* GR */
-+ if (context->ss != NULL) {
-+ pack_string(cs, str, 1);
-+ str += cs->bpc;
-+ context->ss = NULL;
-+ } else {
-+ int n;
-+
-+ if (cs->bpc == 1) {
-+ unsigned char *p = str;
-+ for (n = 0; p < estr; n++) {
-+ if (*p < min_char || *p > max_char)
-+ break;
-+ p++;
-+ }
-+ pack_string(cs, str, n);
-+ str = p;
-+ } else {
-+ unsigned char *p = str;
-+ for (n = 0; p < estr - 1; n++) {
-+ if (*p < min_char || *p > max_char ||
-+ *(p + 1) < min_char || *(p + 1) > max_char)
-+ break;
-+ p += 2;
-+ }
-+ if (n > 0)
-+ pack_string(cs, str, n);
-+ else
-+ put_unknown_char(*p++);
-+ str = p;
-+ }
-+ }
-+ }
-+ }
-+ }
-+
-+ {
-+ struct ml_text *tp = &context->text;
-+ struct ml_line *lp;
-+ int i;
-+
-+ tp->width = 0;
-+ tp->height = 0;
-+ for (lp = tp->lines, i = tp->nlines; i > 0; lp++, i--) {
-+ if (lp->nitems == 0) {
-+ lp->ascent = ascii->fs->ascent;
-+ lp->descent = ascii->fs->descent;
-+ }
-+ if (tp->width < lp->width)
-+ tp->width = lp->width;
-+ tp->height += lp->ascent + lp->descent;
-+ }
-+ }
-+
-+ SetCursors(-1);
-+ return &context->text;
-+}
-+
-+static unsigned char *escape_sequence(str)
-+ unsigned char *str;
-+{
-+ unsigned char *p;
-+ switch(*str){
-+ case '$':
-+ case '(': case ')': case '*': case '+':
-+ case '-': case '.': case '/': case ',':
-+ if((p = designator_sequence(str)) == NULL)
-+ return str;
-+ return p;
-+ case 'n': case 'o': case '~': case '}': case '|':
-+ if (!context->lock_shift)
-+ return str;
-+ locking_shift(*str);
-+ return str + 1;
-+ case 'N': case 'O':
-+ single_shift(*str);
-+ return str + 1;
-+ }
-+ return str;
-+
-+}
-+
-+static unsigned char *designator_sequence(str)
-+ unsigned char *str;
-+{
-+ unsigned char *p = str;
-+ int noc, bpc, n_g, shortened;
-+ unsigned char des;
-+ struct charset *cs;
-+
-+ if(*p == '$'){
-+ bpc = 2;
-+ p++;
-+ }else
-+ bpc = 1;
-+
-+ switch(*p++){
-+ case '(': noc = 94; n_g = 0; des = *p++; shortened = 0; break;
-+ case ')': noc = 94; n_g = 1; des = *p++; shortened = 0; break;
-+ case '*': noc = 94; n_g = 2; des = *p++; shortened = 0; break;
-+ case '+': noc = 94; n_g = 3; des = *p++; shortened = 0; break;
-+#ifdef USE_MULE_EXTENSION
-+ case ',': noc = 96; n_g = 0; des = *p++; shortened = 0; break;
-+#endif
-+ case '-': noc = 96; n_g = 1; des = *p++; shortened = 0; break;
-+ case '.': noc = 96; n_g = 2; des = *p++; shortened = 0; break;
-+ case '/': noc = 96; n_g = 3; des = *p++; shortened = 0; break;
-+ case '@': noc = 94; n_g = 0; des = 'B'; shortened = 0; break;
-+ case 'A': noc = 94; n_g = 0; des = 'A'; shortened = 1; break;
-+ case 'B': noc = 94; n_g = 0; des = 'B'; shortened = 1; break;
-+ default: return NULL;
-+ }
-+ if (!context->short_form && shortened)
-+ return NULL;
-+
-+ if((cs = search_charset(bpc, noc, des)) == NULL){
-+ if(DEBUG){
-+ fprintf(stderr, "designator_sequence: (%d,%d,%c) not found.\n",
-+ bpc, noc, des);
-+ }
-+ return NULL;
-+ }
-+ if (!context->valid[n_g])
-+ return NULL;
-+ context->g[n_g] = cs;
-+ if(DEBUG){
-+ fprintf(stderr,
-+ "designator_sequence: G%d is `%s'.\n", n_g, cs->registry);
-+ }
-+ return p;
-+}
-+
-+static void locking_shift(c)
-+ unsigned CHAR c;
-+{
-+ switch((unsigned char) c){
-+ case CODE_SI: context->gl = &context->g[0]; break;
-+ case CODE_SO: context->gl = &context->g[1]; break;
-+ case 'n': context->gl = &context->g[2]; break;
-+ case 'o': context->gl = &context->g[3]; break;
-+ case '~': context->gr = &context->g[1]; break;
-+ case '}': context->gr = &context->g[2]; break;
-+ case '|': context->gr = &context->g[3]; break;
-+ }
-+ if(DEBUG){
-+ fprintf(stderr, "locking_shift: (%d,%d).\n",
-+ (int)(context->gl - context->g),
-+ (int)(context->gr - context->g));
-+ }
-+}
-+
-+static void single_shift(c)
-+ unsigned CHAR c;
-+{
-+ switch((unsigned char) c){
-+ case CODE_SS2: context->ss = &context->g[2]; break;
-+ case CODE_SS3: context->ss = &context->g[3]; break;
-+ }
-+}
-+
-+
-+static void put_unknown_char(chr)
-+ unsigned CHAR chr;
-+{
-+ unsigned char c = chr;
-+
-+ if(c < 0x20){
-+ unsigned char buf[2];
-+ buf[0] = '^';
-+ buf[1] = c + 0x40;
-+ pack_string(ascii, buf, 2);
-+ }else{
-+ unsigned char buf[4];
-+ buf[0] = '\\';
-+ buf[1] = ((c >> 6) & 07) + '0';
-+ buf[2] = ((c >> 3) & 07) + '0';
-+ buf[3] = ((c ) & 07) + '0';
-+ pack_string(ascii, buf, 4);
-+ }
-+}
-+
-+struct context *ml_create_context(s)
-+ Screen *s;
-+{
-+ context = (struct context *) malloc(sizeof *context);
-+
-+ context->g[0] = NULL;
-+ context->g[1] = NULL;
-+ context->g[2] = NULL;
-+ context->g[3] = NULL;
-+ context->gl = NULL;
-+ context->gr = NULL;
-+ context->ss = NULL;
-+
-+ context->cbuf = NULL;
-+ context->text.maxlines = context->text.nlines = 0;
-+ context->line = 0;
-+ context->delta = 0;
-+ context->toolong = 0;
-+
-+ DPY = DisplayOfScreen(s);
-+ SCR = s;
-+ ROOT_WIN = RootWindowOfScreen(s);
-+
-+ return context;
-+}
-+
-+
-+int ml_set_charsets(ctx, sys)
-+ struct context *ctx;
-+ struct coding_system *sys;
-+{
-+ int retval = 0;
-+ int i;
-+
-+ context = ctx;
-+
-+ if(ascii == NULL){
-+ init_xrm();
-+ if((ascii = search_charset(1, 94, 'B')) == NULL){
-+ fputs("ml_set_charsets: ascii charset not found.\n", stderr);
-+ Quit(1);
-+ }
-+ if (ascii->fs == NULL) {
-+ fputs("ml_set_charsets: iso8859-1 font not found.\n", stderr);
-+ Quit(1);
-+ }
-+ }
-+ for(i = 0; i < 4; i++){
-+ switch(sys->design[i].bpc){
-+ case -1: /* make G[i] invalid */
-+ context->valid[i] = 0;
-+ break;
-+
-+ case 0: /* don't change */
-+ break;
-+
-+ case 1: case 2: /* change it */
-+ if((context->g[i] = search_charset(sys->design[i].bpc,
-+ sys->design[i].noc,
-+ sys->design[i].des)) == NULL){
-+ fputs("ml_set_charsets: ", stderr);
-+ fprintf(stderr, "(%d,%d,%c) is specified as G%d, ",
-+ sys->design[i].bpc, sys->design[i].noc,
-+ sys->design[i].des, i);
-+ fputs("but not found. using `iso8859-1'.\n", stderr);
-+ context->g[i] = ascii;
-+ retval++;
-+ }
-+ context->valid[i] = 1;
-+ break;
-+
-+ default: /* error */
-+ fprintf(stderr,"ml_set_charsets: bad arguments of G%d. ", i);
-+ fputs("using `iso8859-1'.\n", stderr);
-+ context->g[i] = ascii;
-+ retval++;
-+ }
-+ }
-+ if((unsigned int) sys->gl < 4)
-+ context->gl = &context->g[sys->gl];
-+ else{
-+ fprintf(stderr, "ml_set_charsets: bad number as GL. using G0.\n");
-+ context->gl = &context->g[0];
-+ }
-+ if((unsigned int) sys->gr < 4)
-+ context->gr = &context->g[sys->gr];
-+ else{
-+ fprintf(stderr, "ml_set_charsets: bad number as GR. using G0.\n");
-+ context->gr = &context->g[0];
-+ }
-+ context->eol = sys->eol;
-+ context->short_form = sys->short_form;
-+ context->lock_shift = sys->lock_shift;
-+ return retval;
-+}
-+
-+static struct charset *search_charset(bpc, noc, des)
-+ int bpc, noc;
-+ int des;
-+{
-+ struct charset *cset;
-+ for(cset = charset; cset->bpc != 0; cset++){
-+ if(cset->bpc == bpc &&
-+ cset->noc == noc &&
-+ cset->designator == (char) des){
-+ if(!cset->loaded){
-+#if 0
-+ int i, l;
-+ l = strlen(cset->registry);
-+ for (i = 0; i < xrm_nfonts; i++) {
-+ int li = strlen(xrm_fonts[i]);
-+ if (li > l) {
-+ if (xrm_fonts[i][li - l - 1] == '-' &&
-+ strcmp(xrm_fonts[i] + li - l,
-+ cset->registry) == 0) {
-+ if ((cset->fs = XLoadQueryFont(DPY, xrm_fonts[i]))
-+ != NULL) {
-+ if (DEBUG) {
-+ fprintf(stderr, "%s for %s\n",
-+ xrm_fonts[i], cset->registry);
-+ }
-+ cset->fontname = xrm_fonts[i];
-+ break;
-+ } else
-+ SetISTR(ISTR_WARNING,
-+ "%s: font not found.", xrm_fonts[i]);
-+ }
-+ }
-+ }
-+#else
-+ int i, l;
-+ l = strlen(cset->registry);
-+ for (i = 0; i < xrm_nfonts && cset->fs == NULL; i++) {
-+ int j, nfnts = 0;
-+ char **fnts = XListFonts(DPY, xrm_fonts[i],
-+ 65535, &nfnts);
-+ for (j = 0 ; j < nfnts; j++) {
-+ int ll = strlen(fnts[j]);
-+ if (*(fnts[j] + ll - l - 1) == '-' &&
-+ strcmp(fnts[j] + ll - l, cset->registry)== 0) {
-+ if ((cset->fs = XLoadQueryFont(DPY, fnts[j]))
-+ != NULL) {
-+ if (DEBUG) {
-+ fprintf(stderr, "%s for %s\n",
-+ fnts[j], cset->registry);
-+ }
-+ cset->fontname = strdup(fnts[j]);
-+ break;
-+ } else
-+ SetISTR(ISTR_WARNING,
-+ "%s: font not found", fnts[j]);
-+ }
-+ }
-+ if (fnts != NULL)
-+ XFreeFontNames(fnts);
-+ }
-+#endif
-+ if(cset->fs == NULL){
-+ SetISTR(ISTR_WARNING,
-+ "font for %s not found.\nusing ascii font.",
-+ cset->registry);
-+ if (ascii != NULL)
-+ cset->fs = ascii->fs;
-+ }
-+
-+ cset->loaded = 1;
-+ }
-+ return cset;
-+ }
-+ }
-+ return NULL;
-+}
-+
-+static void pack_string(cs, str, len)
-+ struct charset *cs;
-+ unsigned char *str;
-+ int len; /* number of chars(not bytes) */
-+{
-+ struct ml_text *mt = &context->text;
-+ struct ml_line *lp;
-+ XTextItem16 *ip;
-+
-+ if (context->line == mt->maxlines) {
-+ int oldmax = mt->maxlines;
-+ if (mt->maxlines < 1)
-+ mt->maxlines = 1;
-+ else
-+ mt->maxlines = 2 * mt->maxlines;
-+ if (oldmax == 0)
-+ mt->lines = (struct ml_line *)
-+ malloc(sizeof(struct ml_line) * mt->maxlines);
-+ else {
-+ mt->lines = (struct ml_line *)
-+ realloc(mt->lines,
-+ sizeof(struct ml_line) * mt->maxlines);
-+ }
-+ }
-+ lp = &mt->lines[context->line];
-+ if (mt->nlines == context->line) {
-+ mt->nlines++;
-+ lp->maxitems = 0;
-+ lp->nitems = 0;
-+ lp->width = 0;
-+ lp->ascent = lp->descent = 0;
-+ }
-+
-+ if (len == 0) {
-+ switch (*str) {
-+ case '\n':
-+ context->line++;
-+ context->delta = 0;
-+ context->toolong = 0;
-+ break;
-+ case '\t':
-+ {
-+ int nx, x = lp->width + context->delta;
-+ nx = (x + ml_tab_width) / ml_tab_width * ml_tab_width;
-+ context->delta += nx - x;
-+ }
-+ break;
-+ }
-+ return;
-+ }
-+
-+ if (context->toolong)
-+ return;
-+ if (lp->width > 30000) {
-+ context->toolong = 1;
-+ cs = ascii;
-+ str = (unsigned char *) "...";
-+ len = 3;
-+ }
-+
-+ if (lp->nitems == lp->maxitems) {
-+ int oldmax = lp->maxitems;
-+ if (lp->maxitems < 1)
-+ lp->maxitems = 1;
-+ else
-+ lp->maxitems = 2 * lp->maxitems;
-+ if (oldmax == 0)
-+ lp->items = (XTextItem16 *)
-+ malloc(sizeof(XTextItem16) * lp->maxitems);
-+ else
-+ lp->items = (XTextItem16 *)
-+ realloc(lp->items,
-+ sizeof(XTextItem16) * lp->maxitems);
-+ }
-+ ip = &lp->items[lp->nitems++];
-+ ip->chars = (XChar2b *) context->cbp;
-+ ip->nchars = len;
-+ ip->delta = context->delta;
-+ ip->font = cs->fs->fid;
-+ context->cbp += 2 * len;
-+ context->delta = 0;
-+
-+ if (cs->bpc == 1) {
-+ XChar2b *p;
-+ unsigned char b7 = cs->bit7 ? 0x80 : 0;
-+ int i;
-+ for (i = len, p = ip->chars; i > 0; i--, p++) {
-+ p->byte1 = '\0';
-+ p->byte2 = (*str++ & 0x7f) | b7;
-+ }
-+ } else {
-+ XChar2b *p;
-+ unsigned char b7 = cs->bit7 ? 0x80 : 0;
-+ int i;
-+ for (i = len, p = ip->chars; i > 0; i--, p++) {
-+ p->byte1 = (*str++ & 0x7f) | b7;
-+ p->byte2 = (*str++ & 0x7f) | b7;
-+ }
-+ }
-+
-+ lp->width += XTextWidth16(cs->fs, ip->chars, ip->nchars);
-+ if (lp->ascent < cs->fs->ascent)
-+ lp->ascent = cs->fs->ascent;
-+ if (lp->descent < cs->fs->descent)
-+ lp->descent = cs->fs->descent;
-+}
-+
-+void get_monofont_size(wide, high)
-+ int *wide, *high;
-+{
-+ if (ascii == NULL) {
-+ fputs("ml_draw_text: call ml_set_charsets, first.\n", stderr);
-+ return;
-+ }
-+ *wide = ascii->fs->max_bounds.width;
-+ *high = ascii->fs->ascent + ascii->fs->descent;
-+}
-+
-+static void init_xrm()
-+{
-+ init_xrm_fonts();
-+ init_xrm_tab();
-+}
-+
-+static void init_xrm_fonts()
-+{
-+ char *p, *fns = XGetDefault(theDisp, "xv", "fontSet");
-+ int n;
-+ if (fns == NULL) {
-+ xrm_fonts = default_fonts;
-+ xrm_nfonts = sizeof default_fonts / sizeof *default_fonts;
-+ return;
-+ }
-+ while(*fns == ' ' || *fns == '\t')
-+ fns++;
-+ if (*fns == '\0') {
-+ xrm_fonts = default_fonts;
-+ xrm_nfonts = sizeof default_fonts / sizeof *default_fonts;
-+ return;
-+ }
-+ fns = strdup(fns);
-+
-+ n = 1;
-+ for (p = fns; *p != '\0'; p++) {
-+ if (*p == ',')
-+ n++;
-+ }
-+ xrm_nfonts = n;
-+ xrm_fonts = (char **) malloc(sizeof (char *) * xrm_nfonts);
-+ for (n = 0, p = fns; n < xrm_nfonts && *p != '\0'; ) {
-+ while (*p == ' ' || *p == '\t')
-+ p++;
-+ xrm_fonts[n++] = p;
-+ while (1) {
-+ char *q;
-+ while (*p != ' ' && *p != '\t' && *p != ',' && *p != '\0')
-+ p++;
-+ q = p;
-+ while (*q == ' ' || *q == '\t')
-+ q++;
-+ if (*q == ',' || *q == '\0') {
-+ *p = '\0';
-+ p = q + 1;
-+ break;
-+ } else
-+ p = q;
-+ }
-+ }
-+ for ( ; n < xrm_nfonts; n++)
-+ xrm_fonts[n] = "";
-+}
-+
-+static void init_xrm_tab()
-+{
-+ char *ts = XGetDefault(theDisp, "xv", "tabWidth");
-+ unsigned short tab;
-+ if (ts == NULL)
-+ tab = 64;
-+ else {
-+ char *ep;
-+ long t;
-+ int bad = 0;
-+ t = strtol(ts, &ep, 0);
-+ tab = (unsigned short) t;
-+ if (ep != NULL) {
-+ while (*ep == ' ' && *ep == '\t')
-+ ep++;
-+ if (*ep != '\0')
-+ bad = 1;
-+ }
-+ if (tab != (long) (unsigned long) t)
-+ bad = 1;
-+ if (bad) {
-+ SetISTR(ISTR_WARNING, "bad tab width.");
-+ tab = 64;
-+ }
-+ }
-+ ml_tab_width = tab;
-+}
-+
-+
-+#ifndef HAVE_STRDUP
-+static char *strdup(str)
-+ char *str;
-+{
-+ return strcpy(malloc(strlen(str) + 1), str);
-+}
-+#endif
-+
-+char *lookup_registry(d, b7)
-+ struct design d;
-+ int *b7;
-+{
-+ int i;
-+ for (i = 0; i < NR_CHARSETS; i++) {
-+ if (charset[i].bpc == d.bpc && charset[i].noc == d.noc &&
-+ charset[i].designator == d.des) {
-+ *b7 = charset[i].bit7;
-+ return charset[i].registry;
-+ }
-+ }
-+ return NULL;
-+}
-+
-+struct design lookup_design(registry, b7)
-+ char *registry;
-+ int b7;
-+{
-+ struct design d;
-+ int i;
-+ d.bpc = 0;
-+ d.noc = 0;
-+ d.des = '\0';
-+ for (i = 0; i < NR_CHARSETS; i++) {
-+ if (strcmp(charset[i].registry, registry) == 0 &&
-+ charset[i].bit7 == b7) {
-+ d.bpc = charset[i].bpc;
-+ d.noc = charset[i].noc;
-+ d.des = charset[i].designator;
-+ break;
-+ }
-+ }
-+ return d;
-+}
-+
-+char *sjis_to_jis(orig, len, newlen)
-+ char *orig;
-+ int len, *newlen;
-+{
-+ unsigned char *new;
-+ unsigned char *p, *q, *endp;
-+ if (len == 0) {
-+ *newlen = 0;
-+ return (char *) malloc((size_t) 1);
-+ }
-+ new = (unsigned char *) malloc((size_t) len * 4); /* big enough */
-+ for (p = (unsigned char *) orig, endp = p + len, q = new; p < endp; ) {
-+ if ((*p & 0x80) == 0) /* 1 byte char */
-+ *q++ = *p++;
-+ else if (*p >= 0x81 && *p <= 0x9f) { /* kanji 1st byte */
-+ unsigned char c1 = *p++;
-+ unsigned char c2 = *p++;
-+ if (c2 < 0x40 || c2 > 0xfc) { /* bad 2nd byte */
-+ *q++ = CODE_SS2;
-+ *q++ = c1;
-+ *q++ = CODE_SS2;
-+ *q++ = c2;
-+ } else { /* right 2nd byte */
-+ if (c2 <= 0x9e) {
-+ if (c2 > 0x7f)
-+ c2--;
-+ c1 = (c1 - 0x81) * 2 + 1 + 0xa0;
-+ c2 = (c2 - 0x40) + 1 + 0xa0;
-+ } else {
-+ c1 = (c1 - 0x81) * 2 + 2 + 0xa0;
-+ c2 = (c2 - 0x9f) + 1 + 0xa0;
-+ }
-+ *q++ = c1;
-+ *q++ = c2;
-+ }
-+ } else if (*p >= 0xe0 && *p <= 0xef) { /* kanji 1st byte */
-+ unsigned char c1 = *p++;
-+ unsigned char c2 = *p++;
-+ if (c2 < 0x40 || c2 > 0xfc) { /* bad 2nd byte */
-+ *q++ = CODE_SS2;
-+ *q++ = c1;
-+ *q++ = CODE_SS2;
-+ *q++ = c2;
-+ } else { /* right 2nd byte */
-+ if (c2 <= 0x9e) {
-+ c1 = (c1 - 0xe0) * 2 + 63 + 0xa0;
-+ c2 = (c2 - 0x40) + 1 + 0xa0;
-+ } else {
-+ c1 = (c1 - 0xe0) * 2 + 64 + 0xa0;
-+ c2 = (c2 - 0x9f) + 1 + 0xa0;
-+ }
-+ *q++ = c1;
-+ *q++ = c2;
-+ }
-+ } else { /* katakana or something */
-+ *q++ = CODE_SS2;
-+ *q++ = *p++;
-+ }
-+ }
-+ *newlen = q - new;
-+
-+ return (char *) realloc(new, (size_t) *newlen);
-+}
-+
-+#endif /* TV_MULTILINGUAL */
-diff -u -r --new-file xv-3.10a.orig/xvml.h xv-3.10a/xvml.h
---- xv-3.10a.orig/xvml.h 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvml.h 2005-04-18 00:57:45.000000000 -0500
-@@ -0,0 +1,96 @@
-+#ifndef MLVIEW_H
-+#define MLVIEW_H
-+
-+/*
-+ * What is this?
-+ *
-+ * It is a package to show multi-lingual text.
-+ *
-+ * How to use?
-+ *
-+ * 1. Call ml_set_screen(Screen *scr);
-+ * Tell this package the screen you use.
-+ *
-+ * 2. Call ml_set_charsets(struct char_spec spec[4], int gl, int gr);
-+ * Tell this package the initial charsets.
-+ * Gn is set to the charset specified by spec[n], respectively.
-+ * GL and GR are set to G[gl] and G[gr], respectively.
-+ * If first call, iso8859-1 font is loaded.
-+ *
-+ * 3. Call ml_draw_text(char *string);
-+ * It Creates a bitmap, and returns it to you.
-+ * If something goes wrong, it returns None.
-+ * DON'T free the returned pixmaps!!
-+ *
-+ * BUGS:
-+ * - Amharic and Tigrigna characters are strange.
-+ * - Big5 is not supported.
-+ * - Reverse direction is not supported.
-+ * - Composing is not supported.
-+ * - Cantonese can't be shown.
-+ * - Texts which have many lines are buggy.
-+ *
-+ * NOTE:
-+ * - Shifted JIS and Shifted GB must be converted to iso2022 in advance.
-+ *
-+ * Example of parameters to ml_set_charsets:
-+ * - EUC-Japan
-+ * spec = { {1, 94, 'B'}, G0 is US-ASCII
-+ * {2, 94, 'B'}, G1 is JIS X0208
-+ * {1, 94, 'J'}, G2 is (right-half of)JIS X0201
-+ * {2, 94, 'D'} }; G3 is JIS X0212
-+ * gl = 0; GL is G0
-+ * gr = 1; GR is G1
-+ *
-+ * - Compound Text
-+ * spec = { {1, 94, 'B'}, G0 is US-ASCII
-+ * {1, 96, 'A'}, G1 is Latin-1
-+ * {1, 94, 'B'}, G2 is US-ASCII (maybe unused)
-+ * {1, 94, 'B'} }; G3 is US-ASCII (maybe unused)
-+ * gl = 0; GL is G0
-+ * gr = 1; GR is G1
-+ *
-+ * - Korean Mail
-+ * spec = { {1, 94, 'B'}, G0 is US-ASCII
-+ * {2, 94, 'C'}, G1 is KSC5601
-+ * {1, 94, 'B'}, G2 is US-ASCII (maybe unused)
-+ * {1, 94, 'B'} }; G3 is US-ASCII (maybe unused)
-+ * gl = 0; GL is G0
-+ * gl = 1; GR is G1
-+ */
-+
-+struct coding_system {
-+ struct design {
-+ int bpc; /* byte per char if 1 or 2,
-+ don't touch if 0, or
-+ don't use if -1.*/
-+ int noc; /* number of chars (94 or 96) */
-+ char des; /* designator ('A', 'B', ...) */
-+ } design[4];
-+ int gl, gr;
-+ int eol;
-+ int short_form;
-+ int lock_shift;
-+};
-+
-+struct ml_text {
-+ int maxlines, nlines;
-+ struct ml_line {
-+ int maxitems, nitems;
-+ int width, ascent, descent;
-+ XTextItem16 *items;
-+ } *lines;
-+ int width, height;
-+};
-+
-+struct context;
-+struct ml_text *ml_draw_text PARM((struct context *, char *, int));
-+struct context *ml_create_context PARM((Screen *));
-+int ml_set_charsets PARM((struct context *,
-+ struct coding_system *));
-+void get_monofont_size PARM((int *, int *));
-+char *sjis_to_jis PARM((char *, int, int *));
-+char *lookup_registry PARM((struct design, int *));
-+struct design lookup_design PARM((char *, int));
-+
-+#endif
-diff -u -r --new-file xv-3.10a.orig/xvpcd.c xv-3.10a/xvpcd.c
---- xv-3.10a.orig/xvpcd.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvpcd.c 2007-05-13 20:02:13.000000000 -0500
-@@ -0,0 +1,1311 @@
-+/*
-+ * xvpcd.c - load routine for 'PhotoCD' format pictures
-+ *
-+ * LoadPCD(fname, pinfo, size) - loads a PhotoCD file
-+ *
-+ * This routine will popup a choice of which of the 5 available resolutions
-+ * the user wants to choose, then load it as a 24 bit image.
-+ *
-+ * Copyright 1993 David Clunie, Melbourne, Australia.
-+ *
-+ * The outline of this is shamelessly derived from xvpbm.c to read the
-+ * file, and xvtiffwr.c to handle the popup window and X stuff (X never
-+ * has been my forte !), and the PhotoCD format information (though not
-+ * the code) was found in Hadmut Danisch's (danisch@ira.uka.de) hpcdtoppm
-+ * program in which he has reverse engineered the format by studying
-+ * hex dumps of PhotoCDs ! After all who can afford the Kodak developer's
-+ * kit, which none of us have seen yet ? Am I even allowed to mention these
-+ * words (Kodak, PhotoCD) ? I presume they are registered trade marks.
-+ *
-+ * PS. I have no idea how Halmut worked out the YCC <-> RGB conversion
-+ * factors, but I have calculated them from his tables and the results
-+ * look good enough to me.
-+ *
-+ * Added size parameter to allow the schnautzer to create thumnails
-+ * without requesting the size every time.
-+ */
-+
-+#include "xv.h"
-+
-+#ifdef HAVE_PCD
-+
-+#include
-+#ifndef alloca
-+# include /* "not in POSIX or SUSv3" according to Linux man page */
-+#endif /* ...but required for Sun C compiler (alloca = macro) */
-+
-+#define TRACE 0
-+#if TRACE
-+# define trace(x) fprintf x
-+#else
-+# define trace(x)
-+#endif
-+
-+/* Comments on error-handling:
-+ A truncated file is not considered a Major Error. The file is loaded,
-+ and the rest of the pic is filled with 0's.
-+
-+ Not being able to malloc is a Fatal Error. The program is aborted. */
-+
-+
-+#ifdef __STDC__
-+static void magnify(int, int, int, int, int, byte *);
-+static int pcdError(const char *, const char *);
-+static int gethuffdata(byte *, byte *, byte *, int, int);
-+#else
-+static void magnify();
-+static int pcdError();
-+static int gethuffdata();
-+#endif
-+
-+#define wcurfactor 16 /* Call WaitCursor() every n rows */
-+
-+static int size; /* Set by window routines */
-+static int leaveitup;/* Cleared by docmd() when OK or CANCEL pressed */
-+static int goforit; /* Set to 1 if OK or 0 if CANCEL */
-+static FILE *fp;
-+static CBUTT lutCB;
-+
-+/*
-+ * This "beyond 100%" table is taken from ImageMagick (gamma 2.2).
-+ * Why there are 351 entries and not 346 as per Kodak documentation
-+ * is a mystery.
-+ */
-+static double rscale = 1.00,
-+ gscale = 1.00,
-+ bscale = 1.00;
-+
-+static byte Y[351] = {
-+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
-+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
-+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
-+ 30, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-+ 41, 42, 43, 45, 46, 47, 48, 49, 50, 51,
-+ 52, 53, 54, 56, 57, 58, 59, 60, 61, 62,
-+ 63, 64, 66, 67, 68, 69, 70, 71, 72, 73,
-+ 74, 76, 77, 78, 79, 80, 81, 82, 83, 84,
-+ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-+ 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
-+ 107, 108, 110, 111, 112, 113, 114, 115, 116, 117,
-+ 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-+ 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
-+ 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
-+ 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
-+ 159, 160, 161, 162, 163, 164, 165, 166, 167, 168,
-+ 169, 170, 171, 172, 173, 174, 175, 176, 176, 177,
-+ 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
-+ 188, 189, 190, 191, 192, 193, 193, 194, 195, 196,
-+ 197, 198, 199, 200, 201, 201, 202, 203, 204, 205,
-+ 206, 207, 207, 208, 209, 210, 211, 211, 212, 213,
-+ 214, 215, 215, 216, 217, 218, 218, 219, 220, 221,
-+ 221, 222, 223, 224, 224, 225, 226, 226, 227, 228,
-+ 228, 229, 230, 230, 231, 232, 232, 233, 234, 234,
-+ 235, 236, 236, 237, 237, 238, 238, 239, 240, 240,
-+ 241, 241, 242, 242, 243, 243, 244, 244, 245, 245,
-+ 245, 246, 246, 247, 247, 247, 248, 248, 248, 249,
-+ 249, 249, 249, 250, 250, 250, 250, 251, 251, 251,
-+ 251, 251, 252, 252, 252, 252, 252, 253, 253, 253,
-+ 253, 253, 253, 253, 253, 253, 253, 253, 253, 253,
-+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
-+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 255,
-+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-+ 255
-+};
-+
-+/*******************************************/
-+/* The size should be -1 for the popup to ask otherwise fast is assumed */
-+/* returns '1' on success */
-+/*******************************************/
-+int
-+LoadPCD(char *fname, PICINFO *pinfo, int theSize)
-+{
-+ long offset;
-+ int mag;
-+ int rotate;
-+ byte header[3*0x800];
-+ byte *pic24, *luma, *chroma1, *chroma2, *ptr, *lptr, *c1ptr, *c2ptr;
-+ int w, h, npixels, bufsize;
-+ int row, col;
-+ int huffplanes;
-+ const char *bname;
-+
-+ bname = BaseName(fname);
-+ pinfo->pic = NULL;
-+ pinfo->comment = NULL;
-+
-+
-+ /*
-+ * open the file
-+ */
-+ if((fp=fopen(fname,"r")) == NULL)
-+ return pcdError(bname, "can't open file");
-+
-+ /*
-+ * inspect the header
-+ */
-+ if(fread(&header[0], 1, sizeof(header), fp) != sizeof(header))
-+ return pcdError(bname, "could not load PCD header");
-+ if(strncmp((char *)&header[0x800], "PCD_", 4) != 0)
-+ return pcdError(bname, "not a PCD file");
-+ rotate = header[0x0E02] & 0x03;
-+
-+/* base/16
-+ - plain data starts at sector 1+2+1=4
-+ (numbered from 0, ie. the 5th sector)
-+ - luma 192*128 = 24576 bytes (12 sectors)
-+ + chroma1 96*64 = 6144 bytes (3 sectors)
-+ + chroma2 96*64 = 6144 bytes (3 sectors)
-+ = total 18 sectors
-+
-+ - NB. "Plain" data is interleaved - 2 luma rows 192 wide,
-+ then 1 of each of the chroma rows 96 wide !
-+
-+ base/4
-+ - plain data starts at sector 1+2+1+18+1=23
-+ - luma 384*256 = 98304 bytes (48 sectors)
-+ + chroma1 192*128 = 24576 bytes (12 sectors)
-+ + chroma2 192*128 = 24576 bytes (12 sectors)
-+ = total 72 sectors
-+
-+ - NB. "Plain" data is interleaved - 2 luma rows 384 wide,
-+ then 1 of each of the chroma rows 192 wide !
-+
-+ base
-+ - plain data starts at sector 1+2+1+18+1+72+1=96
-+
-+ - luma 768*512 = 393216 bytes (192 sectors)
-+ + chroma1 384*256 = 98304 bytes (48 sectors)
-+ + chroma2 384*256 = 98304 bytes (48 sectors)
-+ = total 288 sectors
-+
-+ - NB. "Plain" data is interleaved - 2 luma rows 768 wide,
-+ then 1 of each of the chroma rows 384 wide !
-+
-+ 4base
-+ - plain data for base is read
-+ - luma data interpolated *2
-+ - chroma data interpolated *4
-+
-+ - cd_offset is 1+2+1+18+1+72+1+288=384
-+ - at cd_offset+4 (388) is huffman table
-+ - at cd_offset+5 (389) is 4base luma plane
-+
-+ (the sector at cd_offset+3 seems to contain 256 words each of
-+ which is an offset presumably to the sector containing certain
-+ rows ? rows/4 given 1024 possible rows. The rest of this sector
-+ is filled with zeroes)
-+
-+
-+ 16base
-+ - plain data for base is read
-+ - luma data interpolated *2
-+ - chroma data interpolated *4
-+
-+ - cd_offset is 1+2+1+18+1+72+1+288=384
-+ - at cd_offset+4 (388) is huffman table for 4 base
-+ - at cd_offset+5 (389) is 4base luma plane
-+ - luma plane interpolated *2
-+
-+ - cd_offset is set to current position (should be start of sector)
-+ - at cd_offset+12 is huffman table for 16 base
-+ - at cd_offset+14 is 16 base luma & 2 chroma planes which are read
-+ (note that the luma plane comes first, with a sync pattern
-+ announcing each row from 0 to 2047, then the two chroma planes
-+ are interleaved by row, the row # being even from 0 to 2046, with
-+ each row containing 1536 values, the chroma1 row coming first,
-+ finally followed by a sync pattern with a row of 2048 announcing
-+ the end (its plane seems to be set to 3, ie. chroma2)
-+ - chroma planes interpolated *2
-+
-+ (the sector at cd_offset+10 & 11 seem to contain 1024 pairs of words
-+ the first for luma and the second for chroma, each of
-+ which is an offset presumably to the sector containing certain
-+ rows ? rows/2 given 2048 possible rows)
-+
-+Not yet implemented:
-+
-+In order to do overskip for base and 4base, one has to reach the chroma
-+data for 16 base:
-+
-+ - for 4base, after reading the 4base luma plane (and presumably
-+ skipping the chroma planes) one sets cd_offset to the start of
-+ the "current" sector
-+
-+ - for base, one has to skip the 4base data first:
-+ - cd_offset is set to 384
-+ - at (cd_offset+3 sectors)[510] is a 16 bit word high byte 1st
-+ containing an offset to the beginning of the 16base stuff
-+ though there is then a loop until >30 0xff's start a sector !
-+
-+ - being now positioned after the end of the 4base stuff,
-+ - at (cd_offset+10 sectors)[2] is a 16 bit word high byte 1st
-+ containing an offset to the chroma planes.
-+ - at cd_offset+12 is the set of huffman tables
-+
-+ - for base, the 16base chroma planes are then halved
-+*/
-+
-+ PCDSetParamOptions(bname);
-+ if (theSize == -1)
-+ {
-+ PCDDialog(1); /* Open PCD Dialog box */
-+ SetCursors(-1); /* Somebody has already set it to wait :( */
-+ leaveitup=1;
-+ goforit=0;
-+ size = 1;
-+ /* block until the popup window gets closed */
-+ while (leaveitup) {
-+ int i;
-+ XEvent event;
-+ XNextEvent(theDisp, &event);
-+ HandleEvent(&event, &i);
-+ }
-+ /* At this point goforit and size will have been set */
-+ if (!goforit) {
-+ /* nothing allocated so nothing needs freeing */
-+ return 0;
-+ }
-+ WaitCursor();
-+ }
-+ else
-+ {
-+ size = theSize;
-+ goforit = 1;
-+ }
-+
-+ if(lutCB.val)
-+ rscale = gscale = bscale = 255.0/346.0;
-+ else
-+ rscale = gscale = bscale = 1.0;
-+
-+ switch (size) {
-+ case 0:
-+ pinfo->w = 192;
-+ pinfo->h = 128;
-+ offset=4*0x800;
-+ mag=1;
-+ huffplanes=0;
-+ sprintf(pinfo->fullInfo, "PhotoCD, base/16 resolution");
-+ break;
-+
-+ case 1:
-+ pinfo->w = 384;
-+ pinfo->h = 256;
-+ offset=23*0x800;
-+ mag=1;
-+ huffplanes=0;
-+ sprintf(pinfo->fullInfo, "PhotoCD, base/4 resolution");
-+ break;
-+
-+ case 2:
-+ default:
-+ pinfo->w = 768;
-+ pinfo->h = 512;
-+ offset=96*0x800;
-+ mag=1;
-+ huffplanes=0;
-+ sprintf(pinfo->fullInfo, "PhotoCD, base resolution");
-+ break;
-+
-+ case 3:
-+ pinfo->w = 1536;
-+ pinfo->h = 1024;
-+ offset=96*0x800;
-+ mag=2;
-+ huffplanes=1;
-+ sprintf(pinfo->fullInfo, "PhotoCD, 4base resolution");
-+ break;
-+
-+ case 4:
-+ pinfo->w=3072;
-+ pinfo->h=2048;
-+ offset=96*0x800;
-+ mag=4;
-+ huffplanes=2;
-+ sprintf(pinfo->fullInfo, "PhotoCD, 16base resolution");
-+ break;
-+ }
-+
-+ /*
-+ * rotate?
-+ */
-+ w = pinfo->w;
-+ h = pinfo->h;
-+ switch(rotate) {
-+ case 0:
-+ break;
-+
-+ case 1:
-+ case 3:
-+ pinfo->w = h;
-+ pinfo->h = w;
-+ break;
-+
-+ default:
-+ fprintf(stderr, "unknown image rotate %d; assuming none\n",
-+ rotate);
-+ rotate = 0;
-+ }
-+
-+ /*
-+ * allocate 24-bit image
-+ */
-+ npixels = pinfo->w * pinfo->h;
-+ bufsize = 3 * npixels;
-+ if (pinfo->w <= 0 || pinfo->h <= 0 || npixels/pinfo->w != pinfo->h ||
-+ bufsize/3 != npixels)
-+ FatalError("image dimensions out of range");
-+
-+ pinfo->pic = (byte *)malloc((size_t) bufsize);
-+ if(!pinfo->pic)
-+ FatalError("couldn't malloc '24-bit RGB plane'");
-+
-+ pinfo->type = PIC24;
-+ sprintf(pinfo->shrtInfo, "%dx%d PhotoCD.", pinfo->w, pinfo->h);
-+ pinfo->colType = F_FULLCOLOR;
-+ pinfo->frmType = -1;
-+
-+ if(fseek(fp, offset, SEEK_SET) == -1) {
-+ free(pinfo->pic);
-+ return pcdError(bname,"Can't find start of data.");
-+ }
-+
-+ pic24 = pinfo->pic;
-+
-+ luma=(byte *)calloc(npixels,1);
-+ if(!luma) {
-+ free(pinfo->pic);
-+ FatalError("couldn't malloc 'luma plane'");
-+ }
-+
-+ chroma1=(byte *)calloc(npixels/4,1);
-+ if(!chroma1) {
-+ free(pinfo->pic);
-+ free(luma);
-+ FatalError("couldn't malloc 'chroma1 plane'");
-+ }
-+
-+ chroma2=(byte *)calloc(npixels/4,1);
-+ if(!chroma2) {
-+ free(pinfo->pic);
-+ free(luma);
-+ free(chroma1);
-+ FatalError("couldn't malloc 'chroma2 plane'");
-+ }
-+
-+ /* Read 2 luma rows length w, then one of each chroma rows w/2 */
-+ /* If a mag factor is active, the small image is read into the */
-+ /* top right hand corner of the larger allocated image */
-+
-+ trace((stderr, "base image: start @ 0x%08lx (sector %ld.%ld)\n",
-+ ftell(fp), ftell(fp)/0x800, ftell(fp) % 0x800));
-+ for(row=0,lptr=luma,c1ptr=chroma1,c2ptr=chroma2; row R'G'B' and image rotate
-+ */
-+ ptr=pic24;
-+ lptr=luma; c1ptr=chroma1; c2ptr=chroma2;
-+ for(row = 0; row < h; ++row) {
-+ byte *rowc1ptr = c1ptr,
-+ *rowc2ptr = c2ptr;
-+ int k = 0;
-+
-+ switch(rotate) {
-+ case 1:
-+ ptr = &pic24[row*3 + (w - 1)*h*3];
-+ k = -3*(h + 1);
-+ break;
-+
-+ case 3:
-+ ptr = &pic24[(h - 1 - row)*3];
-+ k = 3*(h - 1);
-+ break;
-+
-+ default:
-+ ptr = &pic24[row*w*3];
-+ k = 0;
-+ break;
-+ }
-+ for(col = 0; col < w; ++col) {
-+ double L = 1.3584*(double) *lptr++,
-+ C1 = 2.2179*(double) (*c1ptr - 156),
-+ C2 = 1.8215*(double) (*c2ptr - 137);
-+ int r = rscale*(L + C2),
-+ g = gscale*(L - 0.194*C1 - 0.509*C2),
-+ b = bscale*(L + C1);
-+
-+ if(lutCB.val) {
-+ if(r < 0) r = 0; else if(r >= 255) r = 255;
-+ if(g < 0) g = 0; else if(g >= 255) g = 255;
-+ if(b < 0) b = 0; else if(b >= 255) b = 255;
-+ } else {
-+ if(r < 0) r = 0; else if(r >= 351) r = 350;
-+ if(g < 0) g = 0; else if(g >= 351) g = 350;
-+ if(b < 0) b = 0; else if(b >= 351) b = 350;
-+ r = Y[r]; g = Y[g]; b = Y[b];
-+ }
-+ *ptr++ = r;
-+ *ptr++ = g;
-+ *ptr++ = b;
-+ ptr += k;
-+ if(col & 1) {
-+ ++c1ptr;
-+ ++c2ptr;
-+ }
-+ }
-+ if((row & 1) == 0) {
-+ c1ptr = rowc1ptr;
-+ c2ptr = rowc2ptr;
-+ }
-+ if(row%wcurfactor == 0)
-+ WaitCursor();
-+ }
-+ free(luma); free(chroma1); free(chroma2);
-+ return 1;
-+}
-+
-+/*
-+ * derived from Hadmut Danisch's interpolate()
-+ */
-+static void
-+magnify(int mag, /* power of 2 by which to magnify in place */
-+ int h, int w, /* the "start" unmag'd dimensions of the array */
-+ int mh, int mw, /* the real (maximum) dimensions of the array */
-+ byte *p) /* pointer to the data */
-+{
-+ int x,y,yi;
-+ byte *optr,*nptr,*uptr; /* MUST be unsigned, else averaging fails */
-+
-+ while (mag > 1) {
-+
-+ /* create every 2nd new row from 0 */
-+ /* even pixels being equal to the old, odd ones averaged with successor */
-+ /* special case being the last column which is just set equal to the */
-+ /* second last) ... */
-+
-+ for(y=0;y>1; /* odd averaged */
-+ }
-+ }
-+
-+ /* Fill in odd rows, as average of prior & succeeding rows, with */
-+ /* even pixels average of one column, odd pixels average of two */
-+
-+ for(y=0;y>1; /* even pixels */
-+ nptr[1]=(((int)optr[0])+
-+ ((int)optr[2])+
-+ ((int)uptr[0])+
-+ ((int)uptr[2])+2)>>2; /* odd pixels */
-+ nptr+=2; optr+=2; uptr+=2;
-+ }
-+ *(nptr++)=(((int)*(optr++))+
-+ ((int)*(uptr++))+1)>>1; /* 2nd last pixel */
-+ *(nptr++)=(((int)*(optr++))+
-+ ((int)*(uptr++))+1)>>1; /* last pixel */
-+ }
-+
-+ xvbcopy((char *)(p + (2*h-2)*mw), /* 2nd last row */
-+ (char *)(p + (2*h-1)*mw), /* the last row */
-+ 2*w); /* length of a new row */
-+
-+ h*=2; w*=2;
-+ mag>>=1; /* Obviously mag must be a power of 2 ! */
-+ }
-+}
-+
-+/*******************************************/
-+static int
-+pcdError(const char *fname, const char *st)
-+{
-+ SetISTR(ISTR_WARNING,"%s: %s", fname, st);
-+ return 0;
-+}
-+
-+
-+/**** Stuff for PCDDialog box ****/
-+
-+#define TWIDE 380
-+#define THIGH 160
-+#define T_NBUTTS 2
-+#define T_BOK 0
-+#define T_BCANC 1
-+#define BUTTH 24
-+
-+static void drawTD PARM((int, int, int, int));
-+static void clickTD PARM((int, int));
-+static void doCmd PARM((int));
-+static void PCDSetParams PARM((void));
-+
-+/* local variables */
-+static BUTT tbut[T_NBUTTS];
-+static RBUTT *resnRB;
-+
-+
-+
-+/***************************************************/
-+void CreatePCDW()
-+{
-+ int y;
-+
-+ pcdW = CreateWindow("xv pcd", "XVpcd", NULL,
-+ TWIDE, THIGH, infofg, infobg, 0);
-+ if (!pcdW) FatalError("can't create pcd window!");
-+
-+ XSelectInput(theDisp, pcdW, ExposureMask | ButtonPressMask | KeyPressMask);
-+
-+ BTCreate(&tbut[T_BOK], pcdW, TWIDE-140-1, THIGH-10-BUTTH-1, 60, BUTTH,
-+ "Ok", infofg, infobg, hicol, locol);
-+
-+ BTCreate(&tbut[T_BCANC], pcdW, TWIDE-70-1, THIGH-10-BUTTH-1, 60, BUTTH,
-+ "Cancel", infofg, infobg, hicol, locol);
-+
-+ y = 55;
-+ resnRB = RBCreate(NULL, pcdW, 36, y, "192*128 Base/16",
-+ infofg, infobg,hicol,locol);
-+ RBCreate(resnRB, pcdW, 36, y+18, "384*256 Base/4",
-+ infofg, infobg,hicol,locol);
-+ RBCreate(resnRB, pcdW, 36, y+36, "768*512 Base",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(resnRB, pcdW, TWIDE/2, y, "1536*1024 4Base",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(resnRB, pcdW, TWIDE/2, y+18, "3072*2048 16Base",
-+ infofg, infobg, hicol, locol);
-+
-+ CBCreate(&lutCB, pcdW, TWIDE/2, y+36, "Linear LUT",
-+ infofg, infobg, hicol, locol);
-+
-+ RBSelect(resnRB, 2);
-+
-+ XMapSubwindows(theDisp, pcdW);
-+}
-+
-+
-+/***************************************************/
-+void PCDDialog(vis)
-+int vis;
-+{
-+ if (vis) {
-+ CenterMapWindow(pcdW, tbut[T_BOK].x + tbut[T_BOK].w/2,
-+ tbut[T_BOK].y + tbut[T_BOK].h/2, TWIDE, THIGH);
-+ }
-+ else XUnmapWindow(theDisp, pcdW);
-+ pcdUp = vis;
-+}
-+
-+
-+/***************************************************/
-+int PCDCheckEvent(xev)
-+XEvent *xev;
-+{
-+ /* check event to see if it's for one of our subwindows. If it is,
-+ deal accordingly, and return '1'. Otherwise, return '0' */
-+
-+ int rv;
-+ rv = 1;
-+
-+ if (!pcdUp) return 0;
-+
-+ if (xev->type == Expose) {
-+ int x,y,w,h;
-+ XExposeEvent *e = (XExposeEvent *) xev;
-+ x = e->x; y = e->y; w = e->width; h = e->height;
-+
-+ if (e->window == pcdW) drawTD(x, y, w, h);
-+ else rv = 0;
-+ }
-+
-+ else if (xev->type == ButtonPress) {
-+ XButtonEvent *e = (XButtonEvent *) xev;
-+ int x,y;
-+ x = e->x; y = e->y;
-+
-+ if (e->button == Button1) {
-+ if (e->window == pcdW) clickTD(x,y);
-+ else rv = 0;
-+ } /* button1 */
-+ else rv = 0;
-+ } /* button press */
-+
-+
-+ else if (xev->type == KeyPress) {
-+ XKeyEvent *e = (XKeyEvent *) xev;
-+ char buf[128]; KeySym ks; XComposeStatus status;
-+ int stlen;
-+
-+ stlen = XLookupString(e,buf,128,&ks,&status);
-+ buf[stlen] = '\0';
-+
-+ RemapKeyCheck(ks, buf, &stlen);
-+
-+ if (e->window == pcdW) {
-+ if (stlen) {
-+ if (buf[0] == '\r' || buf[0] == '\n') { /* enter */
-+ FakeButtonPress(&tbut[T_BOK]);
-+ }
-+ else if (buf[0] == '\033') { /* ESC */
-+ FakeButtonPress(&tbut[T_BCANC]);
-+ }
-+ }
-+ }
-+ else rv = 0;
-+ }
-+ else rv = 0;
-+
-+ if (rv==0 && (xev->type == ButtonPress || xev->type == KeyPress)) {
-+ XBell(theDisp, 50);
-+ rv = 1; /* eat it */
-+ }
-+
-+ return rv;
-+}
-+
-+
-+/***************************************************/
-+void
-+PCDSetParamOptions(const char *fname)
-+{
-+ int cur;
-+ cur = RBWhich(resnRB);
-+
-+ RBSetActive(resnRB,0,1);
-+ RBSetActive(resnRB,1,1);
-+ RBSetActive(resnRB,2,1);
-+ RBSetActive(resnRB,3,1);
-+ RBSetActive(resnRB,4,1);
-+ CBSetActive(&lutCB,1);
-+}
-+
-+
-+/***************************************************/
-+static void
-+drawTD(int x, int y, int w, int h)
-+{
-+ const char *title = "Load PhotoCD file...";
-+ int i;
-+ XRectangle xr;
-+
-+ xr.x = x; xr.y = y; xr.width = w; xr.height = h;
-+ XSetClipRectangles(theDisp, theGC, 0,0, &xr, 1, Unsorted);
-+
-+ XSetForeground(theDisp, theGC, infofg);
-+ XSetBackground(theDisp, theGC, infobg);
-+
-+ for (i=0; ix-16, resnRB->y-10-DESCENT, "Resolution");
-+ RBRedraw(resnRB, -1);
-+ CBRedraw(&lutCB);
-+
-+ XDrawString(theDisp, pcdW, theGC, 20, 19, title, strlen(title));
-+
-+ XSetClipMask(theDisp, theGC, None);
-+}
-+
-+
-+/***************************************************/
-+static void clickTD(x,y)
-+int x,y;
-+{
-+ int i;
-+ BUTT *bp;
-+
-+ /* check BUTTs */
-+
-+ /* check the RBUTTS first, since they don't DO anything */
-+ if ( (i=RBClick(resnRB, x,y)) >= 0) {
-+ (void) RBTrack(resnRB, i);
-+ return;
-+ }
-+
-+ if(CBClick(&lutCB, x, y)) {
-+ (void) CBTrack(&lutCB);
-+ return;
-+ }
-+
-+ for (i=0; ix, bp->y, bp->w, bp->h)) break;
-+ }
-+
-+ if (i= 16) {
-+ fprintf(stderr,
-+ "gethufftable: improbable length @ %d/%d\n",
-+ i, num);
-+ dumphufftab(num, huf, hufftop/2, hufftab);
-+ free(hufftab);
-+ return NULL;
-+ }
-+
-+ /*
-+ * walk the whole set of codes
-+ */
-+ huffptr = 0;
-+ for(j = 0; j < 16; ++j, codeword *= 2) {
-+ /*
-+ * choose the child node
-+ */
-+ if(codeword & 0x8000)
-+ ++huffptr;
-+
-+ /*
-+ * store value at end-of-code
-+ */
-+ if(j == length) {
-+ /*
-+ * more sanity
-+ */
-+ if((codeword *= 2) & 0xffff) {
-+ fprintf(stderr,
-+ "gethufftable: "
-+ ":probable invalid code @ %d\n",
-+ i);
-+ dumphufftab(num, huf,
-+ hufftop/2, hufftab);
-+ free(hufftab);
-+ return NULL;
-+ }
-+ hufftab[huffptr] = 1 + (int) huf[4*i + 3];
-+ break;
-+ }
-+
-+ /*
-+ * otherwise, follow the tree to date
-+ */
-+ if(hufftab[huffptr] < 0) {
-+ huffptr -= hufftab[huffptr];
-+ continue;
-+ } else if(hufftab[huffptr] > 0) {
-+ fprintf(stderr, "duplicate code %d %d/%d\n",
-+ huffptr, i, num);
-+ dumphufftab(num, huf, hufftop/2, hufftab);
-+ free(hufftab);
-+ return NULL;
-+ }
-+
-+ /*
-+ * and if necessary, make the tree bigger
-+ */
-+ if((hufftop += 2) >= N) {
-+ int oldN = N;
-+#if TRACE
-+ dumphufftab(num, huf, hufftop/2, hufftab);
-+#endif
-+ N *= 2;
-+ bufsize = N*sizeof(int);
-+ if (N/2 != oldN || bufsize/N != sizeof(int)) {
-+ SetISTR(ISTR_WARNING,
-+ "new Huffman table is too large");
-+ free(hufftab);
-+ return NULL;
-+ }
-+ h = (int *)realloc(hufftab, bufsize);
-+ if(h == NULL) {
-+ fprintf(stderr,
-+ "Table overflow %d/%d\n",
-+ i, num);
-+ dumphufftab(num, huf,
-+ hufftop/2, hufftab);
-+ free(hufftab);
-+ FatalError(
-+ "couldn't realloc Huffman table");
-+ }
-+ hufftab = h;
-+ }
-+
-+ /*
-+ * then add new ptr
-+ */
-+ hufftab[huffptr] = huffptr - hufftop;
-+ huffptr = hufftop;
-+ hufftab[huffptr + 0] =
-+ hufftab[huffptr + 1] = 0;
-+ }
-+ }
-+ return hufftab;
-+}
-+
-+/* WORDTYPE & char buffer must be unsigned else */
-+/* fills with sign bit not 0 on right shifts */
-+typedef unsigned int WORDTYPE;
-+typedef int SWORDTYPE;
-+#define WORDSIZE sizeof(WORDTYPE)
-+#define NBYTESINBUF 0x800
-+
-+static byte buffer[NBYTESINBUF];
-+static int bitsleft=0;
-+static int bytesleft=0;
-+static byte *bufptr;
-+static WORDTYPE word;
-+
-+#if 0
-+static void
-+dumpbuffer(void)
-+{
-+ int i,left;
-+ byte *ptr=buffer;
-+
-+ fprintf(stderr,"dumpbuffer: bytesleft=%d bitsleft= %d word=0x%08lx\n",
-+ bytesleft,bitsleft,(unsigned long)word);
-+ for (left=NBYTESINBUF; left>0; left-=16) {
-+ fprintf(stderr,"%05d ",left);
-+ for (i=0; i<8; i++) {
-+ fprintf(stderr,"%02x",*ptr++);
-+ fprintf(stderr,"%02x ",*ptr++);
-+ }
-+ fprintf(stderr,"\n");
-+ }
-+}
-+#endif /* 0 */
-+
-+static void
-+loadbuffer(void)
-+{
-+ if ((bytesleft=fread(buffer,1,NBYTESINBUF,fp)) == 0) {
-+ fprintf(stderr,"Truncation error\n");
-+ exit(1);
-+ }
-+ bufptr=buffer;
-+ /* dumpbuffer(); */
-+}
-+
-+static void
-+loadbyte(void)
-+{
-+ if (bytesleft <= 0) loadbuffer();
-+ --bytesleft;
-+ word|=(WORDTYPE)(*bufptr++)<<(sizeof(WORDTYPE)*8-8-bitsleft);
-+ bitsleft+=8;
-+}
-+
-+static int
-+getbit(void)
-+{
-+ int bit;
-+
-+ while (bitsleft <= 0) loadbyte();
-+ --bitsleft;
-+ bit=(SWORDTYPE)(word)<0; /* assumes word is signed */
-+ /* bit=word>>(sizeof(WORDTYPE)*8-1); */
-+ word<<=1;
-+ return bit;
-+}
-+
-+static WORDTYPE
-+getnn(int nn)
-+{
-+ WORDTYPE value;
-+
-+ while (bitsleft <= nn) loadbyte();
-+ bitsleft-=nn;
-+ value=word>>(sizeof(WORDTYPE)*8-nn);
-+ word<<=nn;
-+ return value;
-+}
-+
-+static WORDTYPE
-+isnn(int nn)
-+{
-+ WORDTYPE value;
-+
-+ while (bitsleft <= nn) loadbyte();
-+ value=word>>(sizeof(WORDTYPE)*8-nn);
-+ return value;
-+}
-+
-+static void
-+skipnn(int nn)
-+{
-+ while (bitsleft <= nn) loadbyte();
-+ bitsleft-=nn;
-+ word<<=nn;
-+}
-+
-+#define get1() (getbit())
-+#define get2() (getnn(2))
-+#define get8() (getnn(8))
-+#define get13() (getnn(13))
-+#define get16() (getnn(16))
-+#define get24() (getnn(24))
-+
-+#define is24() (isnn(24))
-+
-+#define skip1() (skipnn(1))
-+#define skip24() (skipnn(24))
-+
-+static int
-+gethuffdata( byte *luma,
-+ byte *chroma1,
-+ byte *chroma2,
-+ int realrowwidth,
-+ int maxrownumber)
-+{
-+static byte clip[3*256];
-+ int *hufftable[3], *huffstart = NULL, *huffptr = NULL;
-+ int row, col, plane, i, result = 1;
-+#if TRACE
-+ int uflow = 0, oflow = 0;
-+#endif
-+ byte *pixelptr = NULL;
-+
-+ trace((stderr,"gethuffdata: start @ 0x%08lx (sector %ld.%ld)\n",
-+ ftell(fp), ftell(fp)/0x800, ftell(fp) % 0x800));
-+
-+ /*
-+ * correction clipping
-+ */
-+ if(clip[256+255] == 0) {
-+ for(i = 0; i < 256; ++i)
-+ clip[i + 0] = 0x00,
-+ clip[i + 256] = (byte) i,
-+ clip[i + 512] = 0xff;
-+ }
-+
-+ /*
-+ * should really only look for luma plane for 4base, but the
-+ * there are zeroes in the rest of the sector that give both
-+ * chroma tables 0 length
-+ */
-+ for(i = 0; i < 3; ++i)
-+ hufftable[i] = NULL;
-+ for(i = 0; i < 3; ++i) {
-+ if((hufftable[i] = gethufftable()) == NULL) {
-+ result = 0;
-+ break;
-+ }
-+ }
-+ if(result == 0)
-+ goto oops;
-+
-+ /*
-+ * skip remainder of current sector
-+ */
-+ i = (ftell(fp) | 0x7ff) + 1;
-+ if(fseek(fp, i, SEEK_SET) < 0) {
-+ fprintf(stderr, "gethuffdata: sector skip failed\n");
-+ return 0;
-+ }
-+
-+ /*
-+ * skip remainder of "sector"
-+ */
-+ i = 0;
-+ while (is24() != 0xfffffe) {
-+ (void)get24();
-+ if(++i == 1)
-+ trace((stderr,"gethuffdata: skipping for sync ..."));
-+ }
-+ if(i != 0)
-+ trace((stderr, " %d times\n", i));
-+
-+ while(result) {
-+ if(is24() == 0xfffffe) {
-+ skip24();
-+ plane = get2();
-+ row = get13(); col = 0;
-+ skip1();
-+ if(row >= maxrownumber) {
-+ trace((stderr,
-+ "gethuffdata: stopping at row %d\n",
-+ row));
-+ break;
-+ }
-+ switch (plane) {
-+ case 0:
-+ huffstart = hufftable[0];
-+ pixelptr = luma + row*realrowwidth;
-+ break;
-+
-+ case 2:
-+ huffstart = hufftable[1];
-+ pixelptr = chroma1 + row/2*realrowwidth/2;
-+ break;
-+
-+ case 3:
-+ huffstart = hufftable[2];
-+ pixelptr = chroma2 + row/2*realrowwidth/2;
-+ break;
-+
-+ default:
-+ fprintf(stderr, "gethuffdata: bad plane %d\n",
-+ plane);
-+ result = 0;
-+ break;
-+ }
-+ WaitCursor();
-+ continue;
-+ }
-+
-+ /*
-+ * locate correction in huffman tree
-+ */
-+ for(huffptr = huffstart;;) {
-+ huffptr += get1();
-+ if(*huffptr < 0) {
-+ huffptr -= *huffptr;
-+ } else if(*huffptr == 0) {
-+ fprintf(stderr,
-+ "gethuffdata: invalid code: "
-+ "image quality reduced\n");
-+ result = 0;
-+ break;
-+ } else
-+ break;
-+ }
-+ if(!result)
-+ break;
-+
-+ /*
-+ * apply correction to the pixel
-+ *
-+ * eeeek!! the corrections can sometimes over or underflow!
-+ * this strongly suggested that the 'magnify' method was in
-+ * some way wrong. however, experiments showed that the
-+ * over/under flows even occured for the pixels that are
-+ * copied through magnify without change (ie, the even
-+ * row/even column case). curiously, though, the odd
-+ * column and odd row cases were about 3x more likely to have
-+ * the over/underflow, and the odd row/odd column case was
-+ * about 5x higher, so maybe the use of a bi-linear
-+ * interpolation is not correct -- just *close*?
-+ *
-+ * the other clue in this area is that the overflows are
-+ * by far most frequenct along edges of very bright
-+ * areas -- rarely in the interior of such regions.
-+ */
-+ i = (int) *pixelptr + (signed char) (*huffptr - 1);
-+#if TRACE
-+ if(i > 255)
-+ ++oflow;
-+/* trace((stderr,
-+ "gethuffdata: oflow %d %d %d\n", row, col, i));*/
-+ else if(i < 0)
-+ ++uflow;
-+/* trace((stderr,
-+ "gethuffdata: uflow %d %d %d\n", row, col, i));*/
-+ ++col;
-+#endif
-+ *pixelptr++ = clip[i + 256];
-+ }
-+
-+oops:
-+ for(i = 0; i < 3; ++i)
-+ free(hufftable[i]);
-+ trace((stderr, "gethuffdata: uflow=%d oflow=%d\n", uflow, oflow));
-+ trace((stderr, "gethuffdata: done @ 0x%08lx (sector %ld.%d)\n",
-+ ftell(fp), ftell(fp)/0x800, 0x800 - bytesleft));
-+ return result;
-+}
-+
-+#endif /* HAVE_PCD */
-diff -u -r --new-file xv-3.10a.orig/xvpi.c xv-3.10a/xvpi.c
---- xv-3.10a.orig/xvpi.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvpi.c 2005-04-18 00:57:04.000000000 -0500
-@@ -0,0 +1,1060 @@
-+/*
-+ * xvpi.c - load routine for `Pi' format pictures.
-+ *
-+ * The `Pi' format is made by Yanagisawa.
-+ * It is common among many Japanese personal computer users.
-+ *
-+ */
-+
-+#include "xv.h"
-+#include
-+
-+#ifdef HAVE_PI
-+
-+typedef unsigned short data16;
-+typedef unsigned int data32;
-+
-+struct pi_info {
-+ jmp_buf jmp;
-+ FILE *fp;
-+ struct {
-+ int rest;
-+ byte cur;
-+ }bs;
-+ long fsize;
-+ byte mode;
-+ int width, height;
-+ float aspect;
-+ int cbits;
-+ int numcols;
-+ byte *cmap;
-+ struct ct_t{
-+ struct elt_t *top;
-+ struct elt_t{
-+ struct elt_t *old, *recent;
-+ byte val;
-+ } *elt;
-+ }*ct;
-+ int defcmap;
-+ int writing_grey;
-+};
-+
-+static void pi_open_file PARM((struct pi_info*, char*));
-+static void pi_read_header PARM((struct pi_info*, char**));
-+static void pi_check_id PARM((struct pi_info*));
-+static void pi_read_comment PARM((struct pi_info*, char**));
-+static void pi_read_palette PARM((struct pi_info*));
-+static void pi_expand PARM((struct pi_info*, byte**));
-+static byte pi_read_color PARM((struct pi_info*, int));
-+static int pi_read_position PARM((struct pi_info*));
-+static data32 pi_read_length PARM((struct pi_info*));
-+static int pi_copy_pixels PARM((struct pi_info*,
-+ byte*, int, int, data32));
-+
-+static void pi_write_header PARM((struct pi_info*,
-+ char*, byte*, byte*, byte*));
-+static void pi_write_id PARM((struct pi_info*));
-+static void pi_write_comment PARM((struct pi_info*, char*));
-+static void pi_write_palette PARM((struct pi_info*, byte*, byte*, byte*));
-+static void pi_compress PARM((struct pi_info*, byte*));
-+static void pi_write_gabage PARM((struct pi_info*));
-+static void pi_write_color PARM((struct pi_info*, int, int));
-+static int pi_test_matching PARM((struct pi_info*,
-+ byte*, int, int, data32*));
-+static void pi_write_position PARM((struct pi_info*, int));
-+static void pi_write_length PARM((struct pi_info*, data32));
-+
-+static void pi_table_create PARM((struct pi_info*));
-+static byte pi_table_get_value PARM((struct pi_info*, int, int));
-+static int pi_table_lookup_value PARM((struct pi_info*, int, int));
-+static data32 pi_read_bits PARM((struct pi_info*, int));
-+static void pi_write_bits PARM((struct pi_info*, data32, int));
-+static void pi_init_pi_info PARM((struct pi_info*));
-+static void pi_cleanup_pi_info PARM((struct pi_info*, int));
-+static void pi_cleanup_pinfo PARM((PICINFO*));
-+static void pi_memory_error PARM((char*, char*));
-+static void pi_error PARM((struct pi_info*, int));
-+static void pi_file_error PARM((struct pi_info*, int));
-+static void pi_file_warning PARM((struct pi_info*, int));
-+static void pi_show_pi_info PARM((struct pi_info*));
-+static void *pi_malloc PARM((size_t, char*));
-+static void *pi_realloc PARM((void*, size_t, char*));
-+
-+
-+static char *pi_id = "Pi";
-+static char *pi_msgs[] = {
-+ NULL,
-+#define PI_OPEN 1
-+ "couldn't open.",
-+#define PI_CORRUPT 2
-+ "file corrupted.",
-+#define PI_FORMAT 3
-+ "not PI format.",
-+#define PI_PLANES 4
-+ "bad number of planes.",
-+#define PI_WRITE 5
-+ "write failed.",
-+};
-+
-+
-+/* The main routine of `Pi' loader. */
-+int LoadPi(fname, pinfo)
-+ char *fname;
-+ PICINFO *pinfo;
-+{
-+ struct pi_info pi;
-+ int e;
-+ int i;
-+ if(DEBUG) fputs("LoadPi:\n", stderr);
-+
-+ pinfo->comment = NULL;
-+ pi_init_pi_info(&pi);
-+ if((e = setjmp(pi.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ pi_cleanup_pi_info(&pi, 0);
-+ pi_cleanup_pinfo(pinfo);
-+ if(DEBUG) fputs("\n", stderr);
-+ return 0;
-+ }
-+
-+ pi_open_file(&pi, fname);
-+ pi_read_header(&pi, &pinfo->comment);
-+ pi_expand(&pi, &pinfo->pic);
-+
-+ pinfo->normw = pinfo->w = pi.width;
-+ pinfo->normh = pinfo->h = pi.height;
-+ pinfo->type = PIC8;
-+ if(pi.numcols > 256) /* shouldn't happen. */
-+ pi.numcols = 256;
-+ for(i = 0; i < pi.numcols; i++){
-+ pinfo->r[i] = pi.cmap[i * 3 ];
-+ pinfo->g[i] = pi.cmap[i * 3 + 1];
-+ pinfo->b[i] = pi.cmap[i * 3 + 2];
-+ }
-+ pinfo->frmType = F_PI;
-+ pinfo->colType = F_FULLCOLOR;
-+ sprintf(pinfo->fullInfo, "Pi, %d colors (%ld bytes)",
-+ pi.numcols, pi.fsize);
-+ sprintf(pinfo->shrtInfo, "%dx%d Pi.", pi.width, pi.height);
-+ normaspect = pi.aspect;
-+
-+ pi_cleanup_pi_info(&pi, 0);
-+ if(DEBUG) fputs("\n", stderr);
-+ return 1;
-+}
-+
-+static void pi_open_file(pi, fname)
-+ struct pi_info *pi;
-+ char *fname;
-+{
-+ if((pi->fp = fopen(fname, "rb")) == NULL)
-+ pi_file_error(pi, PI_OPEN);
-+ fseek(pi->fp, (size_t) 0, SEEK_END);
-+ pi->fsize = ftell(pi->fp);
-+ fseek(pi->fp, (size_t) 0, SEEK_SET);
-+}
-+
-+static void pi_read_header(pi, comm)
-+ struct pi_info *pi;
-+ char **comm;
-+{
-+ byte buf[10];
-+ int mda;
-+ int i;
-+
-+ pi_check_id(pi);
-+ pi_read_comment(pi, comm);
-+
-+ if(fread(buf, (size_t) 10, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_CORRUPT);
-+
-+ pi->mode = buf[0];
-+ pi->defcmap = pi->mode & 0x80;
-+ if(buf[1] != 0 && buf[2] != 0)
-+ pi->aspect = (float) buf[2] / (int) buf[1];
-+ pi->cbits = buf[3];
-+ pi->numcols = 1 << pi->cbits;
-+
-+ if(pi->cbits != 4 && pi->cbits != 8)
-+ pi_error(pi, PI_PLANES);
-+
-+ mda = (int) buf[8] << 8 | (int) buf[9];
-+ for(i = 0; i < mda; i++){
-+ if(fgetc(pi->fp) == EOF)
-+ pi_file_error(pi, PI_CORRUPT);
-+ }
-+
-+ if(fread(buf, (size_t) 4, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_CORRUPT);
-+ pi->width = (int) buf[0] << 8 | (int) buf[1];
-+ pi->height = (int) buf[2] << 8 | (int) buf[3];
-+
-+ pi_read_palette(pi);
-+
-+ if(DEBUG) pi_show_pi_info(pi);
-+}
-+
-+static void pi_check_id(pi)
-+ struct pi_info *pi;
-+{
-+ char buf[2];
-+
-+ if(fread(buf, (size_t) 2, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_CORRUPT);
-+ if(strncmp(buf, pi_id, (size_t) 2) != 0)
-+ pi_error(pi, PI_FORMAT);
-+}
-+
-+static void pi_read_comment(pi, comm)
-+ struct pi_info *pi;
-+ char **comm;
-+{
-+/*
-+ * The comment format is like:
-+ * comment string `^Z' dummy string `\0'
-+ */
-+ int max = -1, i = 0;
-+ int c;
-+
-+ while(1){
-+ if((c = fgetc(pi->fp)) == EOF)
-+ pi_file_error(pi, PI_CORRUPT);
-+ if(c == '\032') /* 0x1a, '^Z' */
-+ break;
-+ if(max < i){
-+ max += 32;
-+ *comm = pi_realloc(*comm, (size_t) max + 1, "pi_read_comment(1)");
-+ }
-+ (*comm)[i++] = c;
-+ }
-+ if(max < i){
-+ max++;
-+ *comm = pi_realloc(*comm, (size_t) max + 1, "pi_read_comment(2)");
-+ }
-+ (*comm)[i] = '\0';
-+
-+ while((c = fgetc(pi->fp)) != '\0'){ /* skip the dummy area */
-+ if(c == EOF)
-+ pi_file_error(pi, PI_CORRUPT);
-+ }
-+}
-+
-+static void pi_read_palette(pi)
-+ struct pi_info *pi;
-+{
-+ pi->cmap = pi_malloc((size_t) pi->numcols * 3, "pi_read_palette");
-+ if(pi->mode & 0x80){
-+ if(pi->numcols == 16){
-+ int i;
-+ byte on;
-+
-+ on = 0x77;
-+ for(i = 0; i < 8; i++){
-+ pi->cmap[i * 3 ] = i & 2 ? on : 0;
-+ pi->cmap[i * 3 + 1] = i & 4 ? on : 0;
-+ pi->cmap[i * 3 + 2] = i & 1 ? on : 0;
-+ }
-+ on = 0xff;
-+ for(; i < 16; i++){
-+ pi->cmap[i * 3 ] = i & 2 ? on : 0;
-+ pi->cmap[i * 3 + 1] = i & 4 ? on : 0;
-+ pi->cmap[i * 3 + 2] = i & 1 ? on : 0;
-+ }
-+ }else{ /* pi->numcols == 256 */
-+ int i;
-+ byte r, g, b;
-+ r = g = b = 0;
-+ for(i = 0; i < 256; i++){
-+ pi->cmap[i * 3 ] = r;
-+ pi->cmap[i * 3 + 1] = g;
-+ pi->cmap[i * 3 + 2] = b;
-+ if((b += 0x40) == 0){
-+ if((r += 0x20) == 0)
-+ g += 0x20;
-+ }
-+ }
-+ }
-+ }else{
-+ if(fread(pi->cmap, (size_t) pi->numcols * 3, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_CORRUPT);
-+ }
-+}
-+
-+/* The main routine to expand `Pi' file. */
-+static void pi_expand(pi, pic)
-+ struct pi_info *pi;
-+ byte **pic;
-+{
-+ byte prev_col = 0;
-+ int prev_pos = -1;
-+ int cnt = 0, max_cnt = pi->width * pi->height;
-+
-+ *pic = pi_malloc((size_t) max_cnt, "pi_expand"); // GRR POSSIBLE OVERFLOW / FIXME
-+
-+ pi_table_create(pi);
-+
-+ if(pi->width > 2){
-+ (*pic)[0] = pi_read_color(pi, 0);
-+ (*pic)[1] = pi_read_color(pi, (*pic)[0]);
-+
-+ while(cnt < max_cnt){
-+ int pos = pi_read_position(pi);
-+ if(pos != prev_pos){
-+ data32 len = pi_read_length(pi);
-+ cnt = pi_copy_pixels(pi, *pic, cnt, pos, len);
-+ prev_col = (*pic)[cnt - 1];
-+ prev_pos = pos;
-+ }else{
-+ do{
-+ prev_col = pi_read_color(pi, (int) prev_col);
-+ (*pic)[cnt++] = prev_col;
-+ prev_col = pi_read_color(pi, (int) prev_col);
-+ (*pic)[cnt++] = prev_col;
-+ }while(pi_read_bits(pi, 1) == 1);
-+
-+ prev_pos = -1;
-+ }
-+ }
-+ }else{
-+ while(cnt < max_cnt){
-+ prev_col = pi_read_color(pi, (int) prev_col);
-+ (*pic)[cnt++] = prev_col;
-+ }
-+ }
-+}
-+
-+static byte pi_read_color(pi, prev)
-+ struct pi_info *pi;
-+ int prev;
-+{
-+ byte n;
-+ if(pi->cbits == 4){
-+ if(pi_read_bits(pi, 1) == 1)
-+ n = pi_read_bits(pi, 1); /* 1x */
-+ else{
-+ if(pi_read_bits(pi, 1) == 0)
-+ n = pi_read_bits(pi, 1) + 2; /* 00x */
-+ else{
-+ if(pi_read_bits(pi, 1) == 0)
-+ n = pi_read_bits(pi, 2) + 4; /* 010xx */
-+ else
-+ n = pi_read_bits(pi, 3) + 8; /* 011xxx */
-+ }
-+ }
-+ }else{ /* cbits == 8 */
-+ if(pi_read_bits(pi, 1) == 1)
-+ n = pi_read_bits(pi, 1);
-+ else{
-+ int bits = 0;
-+ byte base = 2;
-+ while(bits < 6){
-+ if(pi_read_bits(pi, 1) == 0)
-+ break;
-+ bits++;
-+ base <<= 1;
-+ }
-+ n = pi_read_bits(pi, bits + 1) + base;
-+ }
-+ }
-+
-+ return pi_table_get_value(pi, prev, (int) n);
-+}
-+
-+static int pi_read_position(pi)
-+ struct pi_info *pi;
-+{
-+ byte r;
-+ if((r = pi_read_bits(pi, 2)) != 3)
-+ return (int) r;
-+ else
-+ return (int) pi_read_bits(pi, 1) + 3;
-+}
-+
-+static data32 pi_read_length(pi)
-+ struct pi_info *pi;
-+{
-+ data32 r = 1;
-+ int bits = 0;
-+ while(pi_read_bits(pi, 1) == 1){
-+ r <<= 1;
-+ bits++;
-+ }
-+ if(bits > 0)
-+ return r + pi_read_bits(pi, bits);
-+ return 1;
-+}
-+
-+static int pi_copy_pixels(pi, pic, cnt, pos, len)
-+ struct pi_info *pi;
-+ byte *pic;
-+ int cnt, pos;
-+ data32 len;
-+{
-+ int s = 0, d = cnt;
-+ int max = pi->width * pi->height;
-+ switch(pos){
-+ case 0:
-+ if(cnt < 2){
-+ if(pic[0] == pic[1])
-+ s = cnt - 2;
-+ else
-+ s = cnt - 4;
-+ }else{
-+ if(pic[cnt - 2] == pic[cnt - 1])
-+ s = cnt - 2;
-+ else
-+ s = cnt - 4;
-+ }
-+ break;
-+ case 1:
-+ s = cnt - pi->width;
-+ break;
-+ case 2:
-+ s = cnt - pi->width * 2;
-+ break;
-+ case 3:
-+ s = cnt - pi->width + 1;
-+ break;
-+ case 4:
-+ s = cnt - pi->width - 1;
-+ }
-+
-+ len *= 2;
-+ while(s < 0 && len != 0 && d < max){
-+ pic[d++] = pic[-(s++) % 2];
-+ len--;
-+ }
-+ while(len != 0 && d < max){
-+ pic[d++] = pic[s++];
-+ len--;
-+ }
-+ return d;
-+}
-+
-+/* The main routine of `Pi' saver. */
-+int WritePi(fp, pic, ptype, w, h, rmap, gmap, bmap, numcols, colorstyle,
-+ comment)
-+ FILE *fp;
-+ byte *pic;
-+ int ptype, w, h;
-+ byte *rmap, *gmap, *bmap;
-+ int numcols, colorstyle;
-+ char *comment;
-+{
-+ byte rtemp[256], gtemp[256], btemp[256];
-+ struct pi_info pi;
-+ int e;
-+
-+ if(DEBUG) fputs("WritePi\n", stderr);
-+ pi_init_pi_info(&pi);
-+ pi.fp = fp;
-+ pi.width = w;
-+ pi.height = h;
-+ pi.writing_grey = (colorstyle == F_GREYSCALE);
-+ if(ptype == PIC24){
-+ if(!(pic = Conv24to8(pic, w, h, 256, rtemp, gtemp, btemp)))
-+ pi_memory_error("Conv24to8", "WritePi");
-+ rmap = rtemp;
-+ gmap = gtemp;
-+ bmap = btemp;
-+ numcols = 256;
-+ }
-+
-+ if((e = setjmp(pi.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ pi_cleanup_pi_info(&pi, 1);
-+ if(DEBUG) fputs("\n", stderr);
-+ return -1;
-+ }
-+
-+ pi.numcols = numcols;
-+ pi_write_header(&pi, comment, rmap, gmap, bmap);
-+ pi_compress(&pi, pic);
-+ pi_write_gabage(&pi);
-+
-+ pi_cleanup_pi_info(&pi, 1);
-+ if(DEBUG) fputs("\n", stderr);
-+ return 0;
-+}
-+
-+static void pi_write_header(pi, comm, r, g, b)
-+ struct pi_info *pi;
-+ char *comm;
-+ byte *r, *g, *b;
-+{
-+ byte buf[14];
-+
-+ if(DEBUG) pi_show_pi_info(pi);
-+
-+ pi_write_id(pi);
-+ pi_write_comment(pi, comm);
-+
-+ buf[0] = buf[1] = buf[2] = 0;
-+ buf[3] = pi->cbits = pi->numcols > 16 ? 8 : 4;
-+ buf[4] = 'X';
-+ buf[5] = 'V';
-+ buf[6] = ' ';
-+ buf[7] = ' ';
-+ buf[8] = buf[9] = 0;
-+ buf[10] = pi->width >> 8;
-+ buf[11] = pi->width;
-+ buf[12] = pi->height >> 8;
-+ buf[13] = pi->height;
-+ if(fwrite(buf, (size_t) 14, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_WRITE);
-+
-+ pi_write_palette(pi, r, g, b);
-+}
-+
-+static void pi_write_id(pi)
-+ struct pi_info *pi;
-+{
-+ if(fwrite(pi_id, (size_t) 2, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_WRITE);
-+}
-+
-+static void pi_write_comment(pi, comm)
-+ struct pi_info *pi;
-+ char *comm;
-+{
-+ if(comm){
-+ int i;
-+ for(i = 0; comm[i]; i++){
-+ if(comm[i] == '\032') /* 0x1a, '^Z' */
-+ comm[i] = ' ';
-+ }
-+ if(i > 0){
-+ if(fwrite(comm, (size_t) i, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_WRITE);
-+ }
-+ }
-+
-+ if(fwrite("\032\0", (size_t) 2, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_WRITE);
-+}
-+
-+static void pi_write_palette(pi, r, g, b)
-+ struct pi_info *pi;
-+ byte *r, *g, *b;
-+{
-+ int i;
-+ int pinum = 1 << pi->cbits;
-+ char buf[3];
-+
-+ for(i = 0; i < pi->numcols; i++){
-+ buf[0] = *r++;
-+ buf[1] = *g++;
-+ buf[2] = *b++;
-+ if(pi->writing_grey)
-+ buf[0] = buf[1] = buf[2] = MONO(buf[0], buf[1], buf[2]);
-+ if(fwrite(buf, (size_t) 3, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_WRITE);
-+ }
-+ for( ; i < pinum; i++){
-+ if(fwrite(buf, (size_t) 3, (size_t) 1, pi->fp) != 1)
-+ pi_file_error(pi, PI_WRITE);
-+ }
-+ pi->numcols = pinum;
-+}
-+
-+/* The main routine to compress `Pi' format. */
-+static void pi_compress(pi, pic)
-+ struct pi_info *pi;
-+ byte *pic;
-+{
-+ byte prev_col = 0;
-+ int prev_pos = -1;
-+ int cnt = 0, max_cnt = pi->width * pi->height;
-+ pi_table_create(pi);
-+
-+ if(pi->width > 2){
-+ int pos;
-+ data32 len;
-+
-+ pi_write_color(pi, 0, pic[0]);
-+ pi_write_color(pi, pic[0], pic[1]);
-+ pos = pi_test_matching(pi, pic, prev_pos, cnt, &len);
-+ while(cnt < max_cnt){
-+ if(pos >= 0){
-+ pi_write_position(pi, pos);
-+ pi_write_length(pi, len);
-+ if((cnt += len * 2) >= max_cnt)
-+ break;
-+ prev_col = pic[cnt - 1];
-+ prev_pos = pos;
-+ pos = pi_test_matching(pi, pic, prev_pos, cnt, &len);
-+ }else{
-+ pi_write_position(pi, prev_pos);
-+ prev_pos = -1;
-+ while(pos < 0){
-+ pi_write_color(pi, (int) prev_col, pic[cnt]);
-+ prev_col = pic[cnt];
-+ if(++cnt >= max_cnt)
-+ break;
-+ pi_write_color(pi, (int) prev_col, pic[cnt]);
-+ prev_col = pic[cnt];
-+ if(++cnt >= max_cnt)
-+ break;
-+ pos = pi_test_matching(pi, pic, -1, cnt, &len);
-+ if(pos < 0)
-+ pi_write_bits(pi, 1, 1);
-+ else
-+ pi_write_bits(pi, 0, 1);
-+ }
-+ }
-+ }
-+ }else{
-+ while(cnt < max_cnt){
-+ pi_write_color(pi, (int) prev_col, pic[cnt]);
-+ prev_col = pic[cnt++];
-+ }
-+ }
-+}
-+
-+static void pi_write_gabage(pi)
-+ struct pi_info *pi;
-+{
-+ pi_write_bits(pi, 0, 32);
-+}
-+
-+static void pi_write_color(pi, prev, col)
-+ struct pi_info *pi;
-+ int prev, col;
-+{
-+ int n = pi_table_lookup_value(pi, prev, col);
-+
-+ if(pi->cbits == 4){
-+ if(n < 2)
-+ pi_write_bits(pi, (data32) n | 2, 2);
-+ else if(n < 4)
-+ pi_write_bits(pi, (data32) n - 2, 3);
-+ else if(n < 8)
-+ pi_write_bits(pi, (data32) (n - 4) | 8, 5);
-+ else
-+ pi_write_bits(pi, (data32) (n - 8) | 24, 6);
-+ }else{ /* cbits == 8 */
-+ if(n < 2){
-+ pi_write_bits(pi, (data32) n | 2, 2);
-+ }else{
-+ int bits = 0;
-+ byte base = 2;
-+ while(bits < 6){
-+ if(n < (int) base * 2)
-+ break;
-+ bits++;
-+ base <<= 1;
-+ }
-+ pi_write_bits(pi, 0, 1);
-+ if(bits > 0)
-+ pi_write_bits(pi, 0xffffffff, bits);
-+ if(bits < 6)
-+ pi_write_bits(pi, 0, 1);
-+ pi_write_bits(pi, (data32) n - base, bits + 1);
-+ }
-+ }
-+}
-+
-+static int pi_test_matching(pi, pic, prev, cnt, len)
-+ struct pi_info *pi;
-+ byte *pic;
-+ int prev, cnt;
-+ data32 *len;
-+{
-+ data32 lens[5];
-+ int pos, p;
-+ int s, d = 0;
-+ int max = pi->width * pi->height;
-+
-+ for(pos = 0; pos < 5; pos++){
-+ switch(pos){
-+ case 0:
-+ if(cnt < 2){
-+ if(pic[0] == pic[1])
-+ d = cnt - 2;
-+ else
-+ d = cnt - 4;
-+ }else{
-+ if(pic[cnt - 2] == pic[cnt - 1])
-+ d = cnt - 2;
-+ else
-+ d = cnt - 4;
-+ }
-+ break;
-+ case 1:
-+ d = cnt - pi->width;
-+ break;
-+ case 2:
-+ d = cnt - pi->width * 2;
-+ break;
-+ case 3:
-+ d = cnt - pi->width + 1;
-+ break;
-+ case 4:
-+ d = cnt - pi->width - 1;
-+ }
-+ s = cnt;
-+ lens[pos] = 0;
-+
-+ if(prev == 0 && pos == 0)
-+ continue;
-+
-+ while(d < max){
-+ if(pic[(d < 0) ? (-d) % 2 : d] != pic[s])
-+ break;
-+ lens[pos]++;
-+ d++;
-+ s++;
-+ }
-+
-+ }
-+
-+ for(pos = 0, p = 1; p < 5; p++){
-+ if(lens[p] >= lens[pos])
-+ pos = p;
-+ }
-+
-+ if(lens[pos] / 2 == 0)
-+ return -1;
-+ *len = lens[pos] / 2;
-+ return pos;
-+}
-+
-+static void pi_write_position(pi, pos)
-+ struct pi_info *pi;
-+ int pos;
-+{
-+ switch(pos){
-+ case 0:
-+ pi_write_bits(pi, 0, 2);
-+ break;
-+ case 1:
-+ pi_write_bits(pi, 1, 2);
-+ break;
-+ case 2:
-+ pi_write_bits(pi, 2, 2);
-+ break;
-+ case 3:
-+ pi_write_bits(pi, 6, 3);
-+ break;
-+ case 4:
-+ pi_write_bits(pi, 7, 3);
-+ break;
-+ }
-+}
-+
-+static void pi_write_length(pi, len)
-+ struct pi_info *pi;
-+ data32 len;
-+{
-+ int bits = 0;
-+ data32 base = 1;
-+
-+ while(len >= base * 2){
-+ bits++;
-+ base <<= 1;
-+ }
-+ if(bits > 0){
-+ pi_write_bits(pi, 0xffffffff, bits);
-+ pi_write_bits(pi, 0, 1);
-+ pi_write_bits(pi, len - base, bits);
-+ }else
-+ pi_write_bits(pi, 0, 1);
-+}
-+
-+/*
-+ * These pi_table_* functions manipulate the color table.
-+ * pi_table_create:
-+ * allocates and initializes a color table.
-+ * pi_table_get_value:
-+ * get the specified value, and move it to the top of the list.
-+ * pi_table_lookup_value:
-+ * look up the specified value, and move it to the top of the list.
-+ */
-+static void pi_table_create(pi)
-+ struct pi_info *pi;
-+{
-+ struct ct_t *t;
-+ int i;
-+ byte mask = pi->numcols - 1;
-+ pi->ct = pi_malloc(sizeof *pi->ct * pi->numcols, "pi_table_create(1)");
-+ for(i = 0, t = pi->ct; i < pi->numcols; i++, t++){
-+ int j;
-+ byte v = i;
-+ t->elt = pi_malloc(sizeof *t->elt * pi->numcols, "pi_table_create(2)");
-+ t->top = &t->elt[pi->numcols - 1];
-+ for(j = 0; j < pi->numcols; j++){
-+ v = (v + 1) & mask;
-+ if(j > 0)
-+ t->elt[j].old = &t->elt[j - 1];
-+ else
-+ t->elt[0].old = t->top;
-+ if(j < pi->numcols - 1)
-+ t->elt[j].recent = &t->elt[j + 1];
-+ else
-+ t->elt[j].recent = &t->elt[0];
-+ t->elt[j].val = v;
-+ }
-+ t->elt[0].old = t->top;
-+ t->top->recent = &t->elt[0];
-+ }
-+}
-+
-+static byte pi_table_get_value(pi, left, num)
-+ struct pi_info *pi;
-+ int left, num;
-+{
-+ struct ct_t *t = &pi->ct[left];
-+ struct elt_t *e = t->top;
-+ if(left >= pi->numcols || num >= pi->numcols)
-+ abort();
-+ if(num != 0){
-+ do {
-+ e = e->old;
-+ }while(--num != 0);
-+
-+ e->old->recent = e->recent;
-+ e->recent->old = e->old;
-+
-+ e->recent = t->top->recent;
-+ e->recent->old = e;
-+ e->old = t->top;
-+ t->top->recent = e;
-+
-+ t->top = e;
-+ }
-+ return e->val;
-+}
-+
-+static int pi_table_lookup_value(pi, left, v)
-+ struct pi_info *pi;
-+ int left, v;
-+{
-+ struct ct_t *t = &pi->ct[left];
-+ struct elt_t *e = t->top;
-+ int num = 0;
-+
-+ if(left >= pi->numcols || v >= pi->numcols)
-+ abort();
-+
-+ while(e->val != v){
-+ e = e->old;
-+ num++;
-+ }
-+
-+ if(num != 0){
-+ e->old->recent = e->recent;
-+ e->recent->old = e->old;
-+
-+ e->recent = t->top->recent;
-+ e->recent->old = e;
-+ e->old = t->top;
-+ t->top->recent = e;
-+
-+ t->top = e;
-+ }
-+
-+ return num;
-+}
-+
-+/*
-+ * These 2 functions read or write to a bit stream.
-+ * pi_read_bits:
-+ * reads a specified-bit data from the bit stream.
-+ * pi_write_bits:
-+ * writes a specified-bit data to the bit stream.
-+ */
-+static data32 pi_read_bits(pi, numbits)
-+ struct pi_info *pi;
-+ int numbits;
-+{
-+ data32 r = 0;
-+
-+ while(numbits > 0){
-+ while(pi->bs.rest > 0 && numbits > 0){
-+ r = (r << 1) | (pi->bs.cur & 0x80 ? 1 : 0);
-+ pi->bs.cur <<= 1;
-+ pi->bs.rest--;
-+ numbits--;
-+ }
-+ if(numbits > 0){
-+ int c;
-+ if((c = fgetc(pi->fp)) == EOF)
-+ pi_file_warning(pi, PI_CORRUPT);
-+ pi->bs.cur = c;
-+ pi->bs.rest = 8;
-+ }
-+ }
-+
-+ return r;
-+}
-+
-+static void pi_write_bits(pi, dat, bits)
-+ struct pi_info *pi;
-+ data32 dat;
-+ int bits;
-+{
-+ data32 dat_mask = 1 << (bits - 1);
-+ while(bits > 0){
-+ while(pi->bs.rest < 8 && bits > 0){
-+ pi->bs.cur <<= 1;
-+ if(dat & dat_mask)
-+ pi->bs.cur |= 1;
-+ pi->bs.rest++;
-+ bits--;
-+ dat_mask >>= 1;
-+ }
-+ if(pi->bs.rest >= 8){
-+ if(fputc((int)pi->bs.cur, pi->fp) == EOF)
-+ pi_file_error(pi, PI_WRITE);
-+ pi->bs.cur = 0;
-+ pi->bs.rest = 0;
-+ }
-+ }
-+}
-+
-+/*
-+ * The routines to initialize or clean up.
-+ * pi_inif_pi_info:
-+ * initializes a pi_info structure.
-+ * pi_cleanup_pi_info:
-+ * cleanup pi_info structure. It frees allocated memories.
-+ * pi_cleanup_pinfo:
-+ * cleanup PICINFO structure when an error occurs.
-+ */
-+static void pi_init_pi_info(pi)
-+ struct pi_info *pi;
-+{
-+ pi->fp = NULL;
-+ pi->bs.rest = 0;
-+ pi->bs.cur = 0;
-+ pi->fsize = 0;
-+ pi->mode = 0;
-+ pi->width = pi->mode = 0;
-+ pi->aspect = 1.0;
-+ pi->cbits = 0;
-+ pi->numcols = 0;
-+ pi->cmap = NULL;
-+ pi->ct = NULL;
-+ pi->defcmap = 0;
-+ pi->writing_grey = 0;
-+}
-+
-+static void pi_cleanup_pi_info(pi, writing)
-+ struct pi_info *pi;
-+ int writing;
-+{
-+ if(pi->fp && !writing){
-+ fclose(pi->fp);
-+ pi->fp = NULL;
-+ }
-+ if(pi->cmap){
-+ free(pi->cmap);
-+ pi->cmap = NULL;
-+ }
-+ if(pi->ct){
-+ int i;
-+ for(i = 0; i < pi->numcols; i++)
-+ free(pi->ct[i].elt);
-+ free(pi->ct);
-+ pi->ct = NULL;
-+ }
-+}
-+
-+static void pi_cleanup_pinfo(pinfo)
-+ PICINFO *pinfo;
-+{
-+ if(pinfo->pic){
-+ free(pinfo->pic);
-+ pinfo->pic = NULL;
-+ }
-+ if(pinfo->comment){
-+ free(pinfo->comment);
-+ pinfo->comment = NULL;
-+ }
-+}
-+
-+/*
-+ * Error handling routins.
-+ * pi_memory_error:
-+ * shows a error message, and terminates.
-+ * pi_error:
-+ * shows a non-file error message.
-+ * pi_file_error:
-+ * shows a file error message.
-+ */
-+static void pi_memory_error(scm, fn)
-+ char *scm, *fn;
-+{
-+ char buf[128];
-+ sprintf(buf, "%s: couldn't allocate memory. (%s)", scm ,fn);
-+ FatalError(buf);
-+}
-+
-+static void pi_error(pi, mn)
-+ struct pi_info *pi;
-+ int mn;
-+{
-+ SetISTR(ISTR_WARNING, "%s", pi_msgs[mn]);
-+ longjmp(pi->jmp, 1);
-+}
-+
-+static void pi_file_error(pi, mn)
-+ struct pi_info *pi;
-+ int mn;
-+{
-+ if(feof(pi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", pi_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", pi_msgs[mn], ERRSTR(errno));
-+ longjmp(pi->jmp, 1);
-+}
-+
-+static void pi_file_warning(pi, mn)
-+ struct pi_info *pi;
-+ int mn;
-+{
-+ if(feof(pi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", pi_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", pi_msgs[mn], ERRSTR(errno));
-+}
-+
-+static void pi_show_pi_info(pi)
-+ struct pi_info *pi;
-+{
-+ fprintf(stderr, " file size: %ld.\n", pi->fsize);
-+ fprintf(stderr, " mode: 0x%02x.\n", pi->mode);
-+ fprintf(stderr, " image size: %dx%d.\n", pi->width, pi->height);
-+ fprintf(stderr, " aspect: %f.\n", pi->aspect);
-+ fprintf(stderr, " number of color bits: %d.\n", pi->cbits);
-+ fprintf(stderr, " number of colors: %d.\n", pi->numcols);
-+ fprintf(stderr, " using default colormap: %s.\n",
-+ pi->defcmap ? "true" : "false");
-+ fprintf(stderr, " writing greyscale image: %s.\n",
-+ pi->writing_grey ? "true" : "false");
-+}
-+
-+/*
-+ * Memory related routines. If failed, they calls pi_memory_error.
-+ */
-+static void *pi_malloc(n, fn)
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (void *) malloc(n);
-+ if(r == NULL)
-+ pi_memory_error("malloc", fn);
-+ return r;
-+}
-+
-+static void *pi_realloc(p, n, fn)
-+ void *p;
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (p == NULL) ? (void *) malloc(n) : (void *) realloc(p, n);
-+ if(r == NULL)
-+ pi_memory_error("realloc", fn);
-+ return r;
-+}
-+#endif /* HAVE_PI */
-diff -u -r --new-file xv-3.10a.orig/xvpic.c xv-3.10a/xvpic.c
---- xv-3.10a.orig/xvpic.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvpic.c 2005-04-18 00:57:08.000000000 -0500
-@@ -0,0 +1,1285 @@
-+/*
-+ * xvpic.c - load routine for `PIC' format pictures.
-+ *
-+ * The `PIC' format is used by many Japanese personal computer users.
-+ */
-+
-+#include "xv.h"
-+#include
-+
-+#ifdef HAVE_PIC
-+
-+typedef unsigned short data16;
-+typedef unsigned int data32;
-+
-+struct pic_info {
-+ jmp_buf jmp;
-+ FILE *fp;
-+ struct {
-+ int rest;
-+ byte cur;
-+ }bs;
-+ long fsize;
-+ int type, mode;
-+ int width, height;
-+ float aspect;
-+ int cbits;
-+ int cmapped;
-+ byte *cmap;
-+ int cached;
-+ struct cache_t {
-+ int newest;
-+ struct cachenode_t {
-+ data32 dat;
-+ int newer, older;
-+ } *node;
-+ } cache;
-+ int g_bits, r_bits, b_bits, i_bits;
-+ int inv_gr;
-+ int tiled256;
-+ int numcols;
-+ int writing_grey;
-+ data32 *data;
-+};
-+
-+static void pic_open_file PARM((struct pic_info*,char*));
-+static void pic_check_id PARM((struct pic_info*));
-+static void pic_read_comment PARM((struct pic_info*, char**));
-+static void pic_read_header PARM((struct pic_info*));
-+static void pic_expand_data PARM((struct pic_info*));
-+static int pic_expanding_read_len PARM((struct pic_info*));
-+static data32 pic_expanding_read_color PARM((struct pic_info*));
-+static void pic_expanding_read_chain
-+ PARM((struct pic_info*, int, int, data32));
-+static void pic_make_xvpic
-+ PARM((struct pic_info*, byte**, byte*, byte*, byte*));
-+
-+static void pic_write_id PARM((struct pic_info*));
-+static void pic_write_comment PARM((struct pic_info*, char*));
-+static void pic_write_header PARM((struct pic_info*));
-+static void pic_write_palette
-+ PARM((struct pic_info*, byte*, byte*, byte*));
-+static void pic_make_sparse_data PARM((struct pic_info*, byte*));
-+static void pic_write_data PARM((struct pic_info*));
-+static void pic_write_length PARM((struct pic_info*, data32));
-+static void pic_write_color PARM((struct pic_info*, data32));
-+static void pic_write_chain
-+ PARM((struct pic_info*, int, int, data32));
-+
-+static data32 pic_read_rgb PARM((struct pic_info*));
-+static data32 pic_read_color_code PARM((struct pic_info*));
-+static void pic_write_rgb PARM((struct pic_info*, data32));
-+static void pic_write_color_code PARM((struct pic_info*, data32));
-+
-+static void pic_cache_init PARM((struct pic_info*));
-+static data32 pic_cache_get_value PARM((struct pic_info*, int));
-+static void pic_cache_add_value PARM((struct pic_info*, data32));
-+static int pic_cache_lookup PARM((struct pic_info*, data32));
-+
-+static data32 pic_read_bits PARM((struct pic_info*, int));
-+static void pic_write_bits PARM((struct pic_info*, data32, int));
-+static byte pic_pad_bit PARM((int, data32));
-+
-+static void pic_init_info PARM((struct pic_info*));
-+static void pic_cleanup_pic_info PARM((struct pic_info*, int));
-+static void pic_cleanup_pinfo PARM((PICINFO*));
-+static void pic_memory_error PARM((char*, char*));
-+static void pic_error PARM((struct pic_info*, int));
-+static void pic_file_error PARM((struct pic_info*, int));
-+static void pic_file_warning PARM((struct pic_info*, int));
-+static void pic_show_pic_info PARM((struct pic_info*));
-+static void *pic_malloc PARM((size_t, char*));
-+static void *pic_realloc PARM((void*, size_t, char*));
-+
-+
-+static char *pic_id = "PIC";
-+
-+/* Error Messages */
-+static char *pic_msgs[] = {
-+ NULL,
-+#define PIC_OPEN 1
-+ "can't open file.",
-+#define PIC_CORRUPT 2
-+ "file corrupted.",
-+#define PIC_FORMAT 3
-+ "not PIC format.",
-+#define PIC_SUPPORT 4
-+ "unsupported type.",
-+#define PIC_COMMENT 5
-+ "can't read comment.",
-+#define PIC_TYPE 6
-+ "bad machine type.",
-+#define PIC_MODE 7
-+ "bad machine-dependent mode.",
-+#define PIC_NUM_COLORS 8
-+ "bad number of colors.",
-+#define PIC_SIZE 9
-+ "bad size.",
-+#define PIC_ASPECT 10
-+ "bad aspect.",
-+#define PIC_WRITE 11
-+ "write failed.",
-+};
-+
-+#define H4(b) (((b) >> 4) & 0x0f)
-+#define L4(b) ( (b) & 0x0f)
-+
-+
-+/* The main routine to load a PIC file. */
-+int LoadPIC(fname, pinfo)
-+ char *fname;
-+ PICINFO *pinfo;
-+{
-+ int e;
-+ struct pic_info pic;
-+ char buf[128];
-+
-+ if(DEBUG) fputs("LoadPIC:\n", stderr);
-+
-+ pic_init_info(&pic);
-+
-+ pinfo->comment = NULL;
-+ if((e = setjmp(pic.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ pic_cleanup_pic_info(&pic, 0);
-+ pic_cleanup_pinfo(pinfo);
-+ if(DEBUG) fputs("\n", stderr);
-+ return 0;
-+ }
-+
-+ pic_open_file(&pic, fname);
-+ pic_check_id(&pic);
-+ pic_read_comment(&pic, &pinfo->comment);
-+ pic_read_header(&pic);
-+ pic_expand_data(&pic);
-+ pic_make_xvpic(&pic, &pinfo->pic, pinfo->r, pinfo->g, pinfo->b);
-+
-+ pinfo->w = pic.width;
-+ if(pic.tiled256)
-+ pinfo->h = pic.height * 2;
-+ else
-+ pinfo->h = pic.height;
-+ pinfo->normw = pinfo->w;
-+ pinfo->normh = pinfo->h;
-+ pinfo->type = pic.cmapped ? PIC8 : PIC24;
-+ pinfo->frmType = F_PIC;
-+ pinfo->colType = F_FULLCOLOR;
-+ strcpy(pinfo->fullInfo, "PIC");
-+ switch(pic.type){
-+ case 0x0:
-+ strcat(pinfo->fullInfo, ", X68k");
-+ break;
-+ case 0x1:
-+ strcat(pinfo->fullInfo, ", PC-88VA");
-+ if(pic.mode & 1)
-+ strcat(pinfo->fullInfo, ", HR");
-+ if(pic.mode & 2)
-+ strcat(pinfo->fullInfo, ", tiled 256");
-+ break;
-+ case 0x2:
-+ strcat(pinfo->fullInfo, ", FM-TOWNS");
-+ if(pic.mode == 0x5){
-+ strcat(pinfo->fullInfo, ", low-resolution");
-+ }else{
-+ strcat(pinfo->fullInfo, ", high-resolution");
-+ }
-+ break;
-+ case 0x3:
-+ strcat(pinfo->fullInfo, ", Macintosh");
-+ break;
-+ case 0xf:
-+ ;
-+ }
-+ sprintf(buf, " (%ld bytes)", pic.fsize);
-+ strcat(pinfo->fullInfo, buf);
-+ sprintf(pinfo->shrtInfo, "%dx%d(aspect %4.2f) PIC.",
-+ pinfo->w, pinfo->h, pic.aspect);
-+ if (!nopicadjust)
-+ normaspect = pic.aspect;
-+
-+ pic_cleanup_pic_info(&pic, 0);
-+ if(DEBUG) fputs("\n", stderr);
-+ return 1;
-+}
-+
-+static void pic_open_file(pi, fname)
-+ struct pic_info *pi;
-+ char *fname;
-+{
-+ if((pi->fp = fopen(fname, "rb")) == NULL)
-+ pic_file_error(pi, PIC_OPEN);
-+ fseek(pi->fp, (size_t) 0, SEEK_END);
-+ pi->fsize = ftell(pi->fp);
-+ fseek(pi->fp, (size_t) 0, SEEK_SET);
-+}
-+
-+static void pic_check_id(pi)
-+ struct pic_info *pi;
-+{
-+ char buf[3];
-+ if(fread(buf, (size_t) 3, (size_t) 1, pi->fp) != 1)
-+ pic_file_error(pi, PIC_CORRUPT);
-+ if(strncmp(buf, pic_id, (size_t) 3) != 0)
-+ pic_error(pi, PIC_FORMAT);
-+}
-+
-+static void pic_read_comment(pi, comm)
-+ struct pic_info *pi;
-+ char **comm;
-+{
-+ /* The comment field is like:
-+ * comment-string ^Z dummy \0 \0
-+ */
-+ int max = -1, i = 0;
-+ int c;
-+
-+ while(1){
-+ if((c = fgetc(pi->fp)) == EOF)
-+ pic_file_error(pi, PIC_CORRUPT);
-+ if(c == '\032') /* 0x1a, '^Z' */
-+ break;
-+ if(max < i){
-+ max += 32;
-+ *comm = pic_realloc(*comm, (size_t) max + 1, "pic_read_comment#1");
-+ }
-+ (*comm)[i++] = c;
-+ }
-+
-+ if(max < i){
-+ max++;
-+ *comm = pic_realloc(*comm, (size_t) max + 1, "pic_read_comment#2");
-+ }
-+ (*comm)[i] = '\0';
-+
-+ while((c = fgetc(pi->fp)) != '\0'){ /* skip the dummy area */
-+ if(c == EOF)
-+ pic_file_error(pi, PIC_CORRUPT);
-+ }
-+
-+ if(fgetc(pi->fp) != '\0') /* check the reserved byte */
-+ pic_error(pi, PIC_SUPPORT);
-+}
-+
-+static void pic_read_header(pi)
-+ struct pic_info *pi;
-+{
-+ pi->mode = pic_read_bits(pi, 4);
-+ pi->type = pic_read_bits(pi, 4);
-+ pi->cbits = pic_read_bits(pi, 16);
-+ pi->width = pic_read_bits(pi, 16);
-+ pi->height = pic_read_bits(pi, 16);
-+
-+ /* machine-dependent setup. */
-+ switch(pi->type){
-+ case 0x0: /* X68K */
-+ if(pi->mode != 0)
-+ pic_error(pi, PIC_MODE);
-+ switch(pi->cbits){
-+ case 4:
-+ pi->aspect = 1.0;
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->i_bits = 1;
-+ pi->cmapped = 1;
-+ break;
-+
-+ case 8:
-+ pi->aspect = 4.0 / 3.0;
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->i_bits = 1;
-+ pi->cmapped = 1;
-+ break;
-+
-+ case 15:
-+ pi->aspect = 4.0 / 3.0;
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->cached = 1;
-+ break;
-+
-+ case 16:
-+ pi->aspect = 4.0 / 3.0;
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->i_bits = 1;
-+ pi->cached = 1;
-+ break;
-+
-+ default:
-+ pic_error(pi, PIC_NUM_COLORS);
-+ }
-+ break;
-+
-+ case 0x1: /* PC-88VA */
-+ if(pi->height > 1000)
-+ pic_error(pi, PIC_SIZE);
-+ switch(pi->width * 1000 + pi->height){
-+ case 640400:
-+ case 640204:
-+ case 640200:
-+ case 320408:
-+ case 320400:
-+ case 320200:
-+ break;
-+ default:
-+ pic_error(pi, PIC_SIZE);
-+ }
-+ pi->aspect = 400.0 / pi->height;
-+ pi->aspect *= pi->width / 640.0;
-+ if(pi->mode & 0x1) /* HR mode */
-+ pi->aspect *= 2.0;
-+ if(pi->mode & 0x2){ /* tiled 256 format */
-+ if(pi->cbits != 16)
-+ pic_error(pi, PIC_NUM_COLORS);
-+ pi->tiled256 = 1;
-+ }
-+ switch(pi->cbits){
-+ case 8:
-+ pi->g_bits = pi->r_bits = 3;
-+ pi->b_bits = 2;
-+ break;
-+
-+ case 12:
-+ pi->g_bits = pi->r_bits = pi->b_bits = 4;
-+ pi->cached = 1;
-+ break;
-+
-+ case 16:
-+ pi->g_bits = 6;
-+ pi->r_bits = pi->b_bits = 5;
-+ pi->cached = 1;
-+ break;
-+
-+ default:
-+ pic_error(pi, PIC_NUM_COLORS);
-+ }
-+ break;
-+
-+ case 0x2: /* FM-TOWNS */
-+ if(pi->cbits != 15)
-+ pic_error(pi, PIC_NUM_COLORS);
-+ switch(pi->mode){
-+ case 0x5:
-+ case 0xc:
-+ break;
-+ default:
-+ pic_error(pi, PIC_MODE);
-+ }
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->cached = 1;
-+ break;
-+
-+ case 0x3: /* MAC */
-+ if(pi->cbits != 15)
-+ pic_error(pi, PIC_NUM_COLORS);
-+ pi->r_bits = pi->g_bits = pi->b_bits = 5;
-+ pi->inv_gr = 1;
-+ break;
-+
-+ case 0xf: /* misc */
-+ {
-+ byte ah, al;
-+
-+ switch(pi->mode){
-+ case 0x0:
-+ break;
-+ case 0x1:
-+ pi->aspect = 4.0 / 3.0;
-+ break;
-+ case 0xf:
-+ break;
-+ default:
-+ pic_error(pi, PIC_MODE);
-+ }
-+ pic_read_bits(pi, 16); /* x */
-+ pic_read_bits(pi, 16); /* y */
-+ ah = pic_read_bits(pi, 8);
-+ al = pic_read_bits(pi, 8);
-+ if(ah > 0 && al > 0)
-+ pi->aspect = (float) al / (int) ah;
-+ else if(pi->mode == 0xf)
-+ pic_error(pi, PIC_ASPECT);
-+ switch(pi->cbits){
-+ case 4:
-+ case 8:
-+ pi->g_bits = pi->r_bits = pi->b_bits = pic_read_bits(pi, 8);
-+ pi->cmapped = 1;
-+ break;
-+
-+ case 12:
-+ pi->g_bits = pi->r_bits = pi->b_bits = 4;
-+ pi->cached = 1;
-+ break;
-+
-+ case 15:
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->cached = 1;
-+ break;
-+
-+ case 16:
-+ pi->g_bits = pi->r_bits = pi->b_bits = 5;
-+ pi->i_bits = 1;
-+ pi->cached = 1;
-+ break;
-+
-+ case 24:
-+ pi->g_bits = pi->r_bits = pi->b_bits = 8;
-+ pi->cached = 1;
-+ break;
-+
-+ case 32:
-+ pic_error(pi, PIC_SUPPORT);
-+ break;
-+
-+ default:
-+ pic_error(pi, PIC_NUM_COLORS);
-+ }
-+ }
-+ break;
-+
-+ default:
-+ pic_error(pi, PIC_TYPE);
-+ }
-+
-+ pi->numcols = 1 << pi->cbits;
-+
-+ /* read palette data */
-+ if(pi->cmapped){
-+ int i;
-+ pi->cmap = pic_malloc((size_t) 3 * pi->numcols, "pic_read_header#1");
-+ for(i = 0; i < pi->numcols; i++){
-+ data32 c = pic_read_rgb(pi);
-+ pi->cmap[i * 3 ] = c >> 16 & 0xff;
-+ pi->cmap[i * 3 + 1] = c >> 8 & 0xff;
-+ pi->cmap[i * 3 + 2] = c & 0xff;
-+ }
-+ }
-+
-+ /* setup color code cache */
-+ if(pi->cached)
-+ pic_cache_init(pi);
-+
-+
-+ pi->data = pic_malloc(sizeof(data32) * pi->width * pi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "pic_read_header#2");
-+ {
-+ int i;
-+ for(i = 0; i < pi->width * pi->height; i++)
-+ pi->data[i] = 0xffffffff;
-+ }
-+
-+ if(DEBUG)
-+ pic_show_pic_info(pi);
-+}
-+
-+/* The main routine to expand a PIC file. */
-+static void pic_expand_data(pi)
-+ struct pic_info *pi;
-+{
-+ int cnt;
-+ data32 c;
-+ pi->data[0] = c = 0;
-+ for(cnt = -1; cnt < pi->width * pi->height; ){
-+ int len = pic_expanding_read_len(pi);
-+ cnt += len;
-+ if(cnt < pi->width * pi->height){
-+ int x = cnt % pi->width;
-+ int y = cnt / pi->width;
-+ data32 c = pic_expanding_read_color(pi);
-+ pic_expanding_read_chain(pi, x, y, c);
-+ }
-+ }
-+}
-+
-+static int pic_expanding_read_len(pi)
-+ struct pic_info *pi;
-+{
-+ int len;
-+ byte bits;
-+ for(len = 2, bits = 1; pic_read_bits(pi, 1) == 1; bits++)
-+ len <<= 1;
-+ return len - 1 + pic_read_bits(pi, bits);
-+}
-+
-+static data32 pic_expanding_read_color(pi)
-+ struct pic_info *pi;
-+{
-+ if(pi->cached){
-+ byte b = pic_read_bits(pi, 1);
-+ if(b){
-+ return pic_cache_get_value(pi, (int) pic_read_bits(pi, 7));
-+ }else{
-+ data32 c = pic_read_color_code(pi);
-+ pic_cache_add_value(pi, c);
-+ return c;
-+ }
-+ }
-+ return pic_read_color_code(pi);
-+}
-+
-+static void pic_expanding_read_chain(pi, x, y, c)
-+ struct pic_info *pi;
-+ int x, y;
-+ data32 c;
-+{
-+ pi->data[y * pi->width + x] = c;
-+ if(pic_read_bits(pi, 1) == 1){
-+ int fin = 0;
-+ while(!fin){
-+ switch(pic_read_bits(pi, 2)){
-+ case 1: /* left */
-+ pi->data[(++y) * pi->width + (--x)] = c;
-+ break;
-+ case 2: /* middle */
-+ pi->data[(++y) * pi->width + x ] = c;
-+ break;
-+ case 3: /* right */
-+ pi->data[(++y) * pi->width + (++x)] = c;
-+ break;
-+ case 0: /* far or nothing */
-+ if(pic_read_bits(pi, 1) == 0)
-+ fin = 1;
-+ else{
-+ if(pic_read_bits(pi, 1) == 0)
-+ pi->data[(++y) * pi->width + (x -= 2)] = c;
-+ else
-+ pi->data[(++y) * pi->width + (x += 2)] = c;
-+ }
-+ }
-+ }
-+ }
-+}
-+
-+/*
-+ * Make a picture from the expanded data.
-+ */
-+static void pic_make_xvpic(pi, xp, rp, gp, bp)
-+ struct pic_info *pi;
-+ byte **xp, *rp, *gp, *bp;
-+{
-+ if(pi->cmapped){
-+ if(pi->tiled256)
-+ *xp = pic_malloc((size_t) pi->width * pi->height * 2, // GRR POSSIBLE OVERFLOW / FIXME
-+ "pic_make_xvpic#1");
-+ else
-+ *xp = pic_malloc((size_t) pi->width * pi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "pic_make_xvpic#2");
-+ }else
-+ *xp = pic_malloc((size_t) pi->width * pi->height * 3, // GRR POSSIBLE OVERFLOW / FIXME
-+ "pic_make_xvpic#3");
-+
-+ if(pi->cmapped){
-+ int i;
-+
-+ for(i = 0; i < pi->numcols; i++){
-+ rp[i] = pi->cmap[i * 3 ];
-+ gp[i] = pi->cmap[i * 3 + 1];
-+ bp[i] = pi->cmap[i * 3 + 2];
-+ }
-+
-+ if(pi->tiled256){
-+ int pic_idx = 0, dat_idx;
-+ data16 col = 0;
-+ for(dat_idx = 0; dat_idx < pi->width * pi->height; dat_idx++){
-+ if(pi->data[dat_idx] != 0xffffffff)
-+ col = pi->data[dat_idx];
-+ (*xp)[pic_idx++] = col & 0xff;
-+ (*xp)[pic_idx++] = col >> 8 & 0xff;
-+ dat_idx++;
-+ }
-+ }else{
-+ int pic_idx = 0, dat_idx;
-+ byte col = 0;
-+ for(dat_idx = 0; dat_idx < pi->width * pi->height; dat_idx++){
-+ if(pi->data[dat_idx] != 0xffffffff)
-+ col = pi->data[dat_idx];
-+ (*xp)[pic_idx++] = col;
-+ }
-+ }
-+ }else{
-+ int pic_idx = 0, dat_idx;
-+ byte r = 0, g = 0, b = 0;
-+ for(dat_idx = 0; dat_idx < pi->width * pi->height; dat_idx++){
-+ if(pi->data[dat_idx] != 0xffffffff){
-+ data32 col = pi->data[dat_idx];
-+ r = col >> 16 & 0xff;
-+ g = col >> 8 & 0xff;
-+ b = col & 0xff;
-+ }
-+ (*xp)[pic_idx++] = r;
-+ (*xp)[pic_idx++] = g;
-+ (*xp)[pic_idx++] = b;
-+ }
-+ }
-+}
-+
-+
-+/* The main routine to write PIC file. */
-+int WritePIC(fp, pic0, ptype, w, h, rmap, gmap, bmap, numcols, colorstyle,
-+ comment)
-+ FILE *fp;
-+ byte *pic0;
-+ int ptype, w, h;
-+ byte *rmap, *gmap, *bmap;
-+ int numcols, colorstyle;
-+ char *comment;
-+{
-+ struct pic_info pic;
-+ int e;
-+
-+ if(DEBUG) fputs("WritePIC:\n", stderr);
-+
-+ pic_init_info(&pic);
-+ pic.fp = fp;
-+ pic.width = w;
-+ pic.height = h;
-+ pic.writing_grey = (colorstyle == F_GREYSCALE);
-+ if(ptype != PIC24){ /* PIC8 */
-+ pic.cmapped = 1;
-+ pic.cached = 0;
-+ pic.cbits = 8;
-+ pic.g_bits =
-+ pic.r_bits =
-+ pic.b_bits = 8;
-+ pic.i_bits = 0;
-+ pic.numcols = numcols;
-+ }else{ /* PIC24 */
-+ pic.cmapped = 0;
-+ pic.cached = 1;
-+ pic.cbits = 24;
-+ pic.g_bits =
-+ pic.r_bits =
-+ pic.b_bits = 8;
-+ pic.i_bits = 0;
-+ pic.numcols = 1 << 24;
-+ pic_cache_init(&pic);
-+ }
-+
-+ if((e = setjmp(pic.jmp)) != 0){
-+ /* When an error occurs while writing, comes here. */
-+ pic_cleanup_pic_info(&pic, 1);
-+ if(DEBUG) fputs("\n", stderr);
-+ return -1;
-+ }
-+
-+ pic_write_id(&pic);
-+ pic_write_comment(&pic, comment);
-+ pic_write_header(&pic);
-+ if(pic.cmapped)
-+ pic_write_palette(&pic, rmap, gmap, bmap);
-+ pic_make_sparse_data(&pic, pic0);
-+ pic_write_data(&pic);
-+ pic_write_bits(&pic, 0, 8);
-+
-+ pic_cleanup_pic_info(&pic, 1);
-+ if(DEBUG) fputs("\n", stderr);
-+ return 0;
-+}
-+
-+static void pic_write_id(pi)
-+ struct pic_info *pi;
-+{
-+ if(fwrite("PIC", (size_t) 3, (size_t) 1, pi->fp) != 1)
-+ pic_file_error(pi, PIC_WRITE);
-+}
-+
-+static void pic_write_comment(pi, comm)
-+ struct pic_info *pi;
-+ char *comm;
-+{
-+ if(comm){
-+ while(*comm){
-+ int c = *comm;
-+ if(c == '\032')
-+ c = ' ';
-+ if(fputc(*comm, pi->fp) == EOF)
-+ pic_file_error(pi, PIC_WRITE);
-+ comm++;
-+ }
-+ }
-+ /* write ^Z, 0, and reserved. */
-+ if(fwrite("\032\0\0", (size_t)3, (size_t) 1, pi->fp) != 1)
-+ pic_file_error(pi, PIC_WRITE);
-+}
-+
-+static void pic_write_header(pi)
-+ struct pic_info *pi;
-+{
-+ if(DEBUG) pic_show_pic_info(pi);
-+ pic_write_bits(pi, (data32) 0, 4); /* mode: 1:1 */
-+ pic_write_bits(pi, (data32) 0xf, 4); /* type: misc */
-+ pic_write_bits(pi, (data32) pi->cbits, 16); /* bits */
-+ pic_write_bits(pi, (data32) pi->width, 16); /* width */
-+ pic_write_bits(pi, (data32) pi->height, 16); /* height */
-+ pic_write_bits(pi, (data32) 0xffff, 16); /* x: unused */
-+ pic_write_bits(pi, (data32) 0xffff, 16); /* y: unused */
-+ pic_write_bits(pi, (data32) 0x0101, 16); /* real aspect */
-+}
-+
-+static void pic_write_palette(pi, r, g, b)
-+ struct pic_info *pi;
-+ byte *r, *g, *b;
-+{
-+ int i;
-+ data32 rgb = 0;
-+ pic_write_bits(pi, (data32) pi->g_bits, 8);
-+ for(i = 0; i < pi->numcols; i++){
-+ rgb = (data32) *r++ << 16 | (data32) *g++ << 8 | (data32) *b++;
-+ pic_write_rgb(pi, rgb);
-+ }
-+ for( ; i < 256; i++)
-+ pic_write_rgb(pi, rgb);
-+}
-+
-+static void pic_make_sparse_data(pi, dat)
-+ struct pic_info *pi;
-+ byte *dat;
-+{
-+ int i;
-+ data32 c;
-+
-+ pi->data = pic_malloc(sizeof(data32) * pi->width * pi->height, // GRR POSSIBLE OVERFLOW / FIXME
-+ "pic_make_sparse_data");
-+
-+ if(pi->cmapped){
-+ c = 0;
-+ for(i = 0; i < pi->width * pi->height; i++){
-+ if(c != dat[i])
-+ c = pi->data[i] = dat[i];
-+ else
-+ pi->data[i] = 0xffffffff;
-+ }
-+ }else{
-+ int j = 0;
-+ c = 0;
-+ for(i = 0; i < pi->width * pi->height; i++){
-+ data32 r, g, b, t;
-+ r = dat[j++];
-+ g = dat[j++];
-+ b = dat[j++];
-+ t = r << 16 | g << 8 | b;
-+ if(c != t)
-+ c = pi->data[i] = t;
-+ else
-+ pi->data[i] = 0xffffffff;
-+ }
-+ }
-+}
-+
-+static void pic_write_data(pi)
-+ struct pic_info *pi;
-+{
-+ int i;
-+ int max = pi->width * pi->height;
-+ data32 c = 0;
-+
-+ i = -1;
-+ while(i < max){
-+ int j;
-+ for(j = i + 1; j < max; j++){
-+ if(pi->data[j] != 0xffffffff)
-+ break;
-+ }
-+ pic_write_length(pi, (data32) j - i);
-+ i = j;
-+ if(i < max){
-+ pic_write_color(pi, c = pi->data[i]);
-+ pic_write_chain(pi, i % pi->width, i / pi->width, c);
-+ }
-+ }
-+}
-+
-+static void pic_write_length(pi, len)
-+ struct pic_info *pi;
-+ data32 len;
-+{
-+ int bits = 0; /* leading 1's */
-+ int max = 2;
-+
-+ while(len > max){
-+ max = (max + 1) * 2;
-+ bits++;
-+ }
-+ pic_write_bits(pi, 0xffffffff, bits);
-+ pic_write_bits(pi, 0, 1);
-+ pic_write_bits(pi, len - max / 2, bits + 1);
-+}
-+
-+static void pic_write_color(pi, c)
-+ struct pic_info *pi;
-+ data32 c;
-+{
-+ if(pi->cached){
-+ int idx = pic_cache_lookup(pi, c);
-+ if(idx < 0){ /* not found */
-+ pic_write_bits(pi, 0, 1);
-+ pic_write_color_code(pi, c);
-+ pic_cache_add_value(pi, c);
-+ }else{ /* found */
-+ pic_write_bits(pi, (data32) 0xffffffff, 1);
-+ pic_write_bits(pi, (data32) idx, 7);
-+ }
-+ }else
-+ pic_write_color_code(pi, c);
-+}
-+
-+static void pic_write_chain(pi, x, y, c)
-+ struct pic_info *pi;
-+ int x, y;
-+ data32 c;
-+{
-+ int ctr = (y + 1) * pi->width + x;
-+
-+ if(y < pi->height - 1 &&
-+ ( pi->data[ctr ] == c ||
-+ (x > 0 && pi->data[ctr - 1] == c) ||
-+ (x < pi->width - 1 && pi->data[ctr + 1] == c) ||
-+ (x > 1 && pi->data[ctr - 2] == c) ||
-+ (x < pi->width - 2 && pi->data[ctr + 2] == c))){
-+ pic_write_bits(pi, 1, 1);
-+ while(++y < pi->height){
-+ if(pi->data[ctr] == c){ /* center */
-+ pic_write_bits(pi, 2, 2);
-+ pi->data[ctr] = 0xffffffff;
-+ ctr += pi->width;
-+ }else if(x > 0 && pi->data[ctr - 1] == c){ /* left */
-+ pic_write_bits(pi, 1, 2);
-+ pi->data[ctr - 1] = 0xffffffff;
-+ ctr += pi->width - 1;
-+ }else if(x < pi->width - 1 && pi->data[ctr + 1] == c){/* right */
-+ pic_write_bits(pi, 3, 2);
-+ pi->data[ctr + 1] = 0xffffffff;
-+ ctr += pi->width + 1;
-+ }else if(x > 1 && pi->data[ctr - 2] == c){ /* 2-left */
-+ pic_write_bits(pi, 2, 4);
-+ pi->data[ctr - 2] = 0xffffffff;
-+ ctr += pi->width - 2;
-+ }else if(x < pi->width - 2 && pi->data[ctr + 2] == c){/* 2-right */
-+ pic_write_bits(pi, 3, 4);
-+ pi->data[ctr + 2] = 0xffffffff;
-+ ctr += pi->width + 2;
-+ }else /* nothing */
-+ break;
-+ }
-+ pic_write_bits(pi, 0, 3);
-+ }else
-+ pic_write_bits(pi, 0, 1);
-+}
-+
-+
-+/*
-+ * These 4 functions read or write a color.
-+ *
-+ * pic_read_rgb:
-+ * reads an RGB. Each bit length is [rgb]_bits, but
-+ * it is expanded to 8bits when returned.
-+ *
-+ * pic_read_color_code:
-+ * reads a color code, whose length is cbits.
-+ * It is the index to the colormap or RGB itself.
-+ *
-+ * pic_write_rgb:
-+ * writes an RGB value.
-+ *
-+ * pic_write_color_code:
-+ * writes a color code.
-+ */
-+static data32 pic_read_rgb(pi)
-+ struct pic_info *pi;
-+{
-+ int rb = pi->r_bits, gb = pi->g_bits, bb = pi->b_bits;
-+ byte r, g, b;
-+ if(pi->inv_gr){
-+ r = pic_read_bits(pi, rb);
-+ g = pic_read_bits(pi, gb);
-+ }else{
-+ g = pic_read_bits(pi, gb);
-+ r = pic_read_bits(pi, rb);
-+ }
-+ b = pic_read_bits(pi, bb);
-+ if(pi->i_bits){
-+ byte i;
-+ i = pic_read_bits(pi, pi->i_bits);
-+ r = r << pi->i_bits | i;
-+ g = g << pi->i_bits | i;
-+ b = b << pi->i_bits | i;
-+ rb += pi->i_bits;
-+ gb += pi->i_bits;
-+ bb += pi->i_bits;
-+ }
-+ r = pic_pad_bit(rb, r);
-+ g = pic_pad_bit(gb, g);
-+ b = pic_pad_bit(bb, b);
-+
-+ return (data32) r << 16 | (data32) g << 8 | (data32) b;
-+}
-+
-+static data32 pic_read_color_code(pi)
-+ struct pic_info *pi;
-+{
-+ if(pi->cmapped)
-+ return pic_read_bits(pi, pi->cbits);
-+ return pic_read_rgb(pi);
-+}
-+
-+static void pic_write_rgb(pi, rgb)
-+ struct pic_info *pi;
-+ data32 rgb;
-+{
-+ byte r = rgb >> 16;
-+ byte g = rgb >> 8;
-+ byte b = rgb;
-+ if(pi->writing_grey)
-+ r = g = b = MONO(r, g, b);
-+ pic_write_bits(pi, g, pi->g_bits);
-+ pic_write_bits(pi, r, pi->r_bits);
-+ pic_write_bits(pi, b, pi->b_bits);
-+}
-+
-+static void pic_write_color_code(pi, code)
-+ struct pic_info *pi;
-+ data32 code;
-+{
-+ if(pi->cmapped){
-+ pic_write_bits(pi, code, pi->cbits);
-+ }else{
-+ pic_write_rgb(pi, code);
-+ }
-+}
-+
-+
-+/*
-+ * These pic_cache_* functions are an implementation of the color cache.
-+ *
-+ * pic_cache_init:
-+ * initializes the cache.
-+ *
-+ * pic_cache_get_value:
-+ * gets a color indexed by the argument `idx'.
-+ * It updates the `most recently used' time.
-+ *
-+ * pic_cache_add_value:
-+ * adds a color to the top of the cache list.
-+ */
-+static void pic_cache_init(pi)
-+ struct pic_info *pi;
-+{
-+ int i;
-+ pi->cache.node = pic_malloc(sizeof(struct cachenode_t) * 128,
-+ "pic_cache_init");
-+ for(i = 0; i < 128; i++){
-+ pi->cache.node[i].newer = i + 1;
-+ pi->cache.node[i].older = i - 1;
-+ pi->cache.node[i].dat = 0;
-+ }
-+ pi->cache.node[ 0].older = 127;
-+ pi->cache.node[127].newer = 0;
-+ pi->cache.newest = 0;
-+}
-+
-+static data32 pic_cache_get_value(pi, idx)
-+ struct pic_info *pi;
-+ int idx;
-+{
-+ struct cachenode_t *p = pi->cache.node;
-+ int n = pi->cache.newest;
-+ if(n != idx){
-+ p[p[idx].newer].older = p[idx].older;
-+ p[p[idx].older].newer = p[idx].newer;
-+
-+ p[p[n].newer].older = idx;
-+ p[idx].newer = p[n].newer;
-+ p[n].newer = idx;
-+ p[idx].older = n;
-+
-+ pi->cache.newest = idx;
-+ }
-+ return pi->cache.node[idx].dat;
-+}
-+
-+static void pic_cache_add_value(pi, dat)
-+ struct pic_info *pi;
-+ data32 dat;
-+{
-+ pi->cache.newest = pi->cache.node[pi->cache.newest].newer;
-+ pi->cache.node[pi->cache.newest].dat = dat;
-+}
-+
-+static int pic_cache_lookup(pi, dat)
-+ struct pic_info *pi;
-+ data32 dat;
-+{
-+ int i;
-+ for(i = 0; i < 128; i++){
-+ if(pi->cache.node[i].dat == dat){
-+ pic_cache_get_value(pi, i);
-+ return i;
-+ }
-+ }
-+ return -1;
-+}
-+
-+
-+/*
-+ * These pic_{read,write}_bits functions access the bit stream.
-+ * pic_read_bits:
-+ * reads the specified bits from the file.
-+ *
-+ * pic_write_bits:
-+ * writes the specified bits to the file.
-+ */
-+static data32 pic_read_bits(pi, bits)
-+ struct pic_info *pi;
-+ int bits;
-+{
-+ data32 r = 0;
-+
-+ while(bits > 0){
-+ while(pi->bs.rest > 0 && bits > 0){
-+ r = (r << 1) | (pi->bs.cur & 0x80 ? 1 : 0);
-+ pi->bs.cur <<= 1;
-+ pi->bs.rest--;
-+ bits--;
-+ }
-+ if(bits > 0){
-+ int c;
-+ if((c = fgetc(pi->fp)) == EOF){
-+ pic_file_warning(pi, PIC_CORRUPT);
-+ c = 0;
-+ }
-+ pi->bs.cur = c;
-+ pi->bs.rest = 8;
-+ }
-+ }
-+
-+ return r;
-+}
-+
-+static void pic_write_bits(pi, dat, bits)
-+ struct pic_info *pi;
-+ data32 dat;
-+ int bits;
-+{
-+ data32 dat_mask = 1 << (bits - 1);
-+ while(bits > 0){
-+ while(pi->bs.rest < 8 && bits > 0){
-+ pi->bs.cur <<= 1;
-+ if(dat & dat_mask)
-+ pi->bs.cur |= 1;
-+ pi->bs.rest++;
-+ bits--;
-+ dat_mask >>= 1;
-+ }
-+ if(pi->bs.rest >= 8){
-+ if(fputc((int)pi->bs.cur, pi->fp) == EOF)
-+ pic_error(pi, PIC_WRITE);
-+ pi->bs.cur = 0;
-+ pi->bs.rest = 0;
-+ }
-+ }
-+}
-+
-+
-+/*
-+ * This function extends sub-8-bit data to 8-bit data using bit-replication.
-+ */
-+static byte pic_pad_bit(bits, dat)
-+ int bits;
-+ data32 dat;
-+{
-+ switch(bits){
-+ case 1:
-+ if(dat & 1)
-+ dat = 0xff;
-+ else
-+ dat = 0;
-+ break;
-+ case 2:
-+ dat = dat << 6 | dat << 4 | dat << 2 | dat;
-+ break;
-+ case 3:
-+ dat = dat << 5 | dat << 2 | dat >> 1;
-+ break;
-+ case 4:
-+ dat = dat << 4 | dat;
-+ break;
-+ case 5:
-+ dat = dat << 3 | dat >> 2;
-+ break;
-+ case 6:
-+ dat = dat << 2 | dat >> 4;
-+ break;
-+ case 7:
-+ dat = dat << 1 | dat >> 6;
-+ }
-+
-+ return dat;
-+}
-+
-+/*
-+ * These functions initialize or clean up structures.
-+ * pic_init_info:
-+ * initializes a pic_info structure.
-+ * pic_cleanup_pic_info:
-+ * cleans up a pic_info structure.
-+ * pic_cleanup_pinfo:
-+ * cleans up a PICINFO structure.
-+ */
-+static void pic_init_info(pi)
-+ struct pic_info *pi;
-+{
-+ pi->fp = NULL;
-+ pi->bs.rest = 0;
-+ pi->bs.cur = '\0';
-+ pi->type = pi->mode = 0;
-+ pi->width = pi->height = 0;
-+ pi->aspect = 1.0;
-+ pi->cbits = 0;
-+ pi->cmapped = pi->cached = 0;
-+ pi->cache.node = NULL;
-+ pi->cmap = NULL;
-+ pi->g_bits = pi->r_bits = pi->b_bits = pi->i_bits = 0;
-+ pi->inv_gr = 0;
-+ pi->tiled256 = 0;
-+ pi->numcols = 0;
-+ pi->writing_grey = 0;
-+}
-+
-+static void pic_cleanup_pic_info(pi, writing)
-+ struct pic_info *pi;
-+ int writing;
-+{
-+ if(!writing && pi->fp)
-+ fclose(pi->fp);
-+ if(pi->cmap)
-+ free(pi->cmap);
-+ if(pi->cache.node)
-+ free(pi->cache.node);
-+ if(pi->data)
-+ free(pi->data);
-+ pi->fp = NULL;
-+ pi->cmap = NULL;
-+ pi->cache.node = NULL;
-+ pi->data = NULL;
-+}
-+
-+static void pic_cleanup_pinfo(pinfo)
-+ PICINFO *pinfo;
-+{
-+ if(pinfo->pic){
-+ free(pinfo->pic);
-+ pinfo->pic = NULL;
-+ }
-+ if(pinfo->comment){
-+ free(pinfo->comment);
-+ pinfo->comment = NULL;
-+ }
-+}
-+
-+/*
-+ * Error Handlers.
-+ * pic_memory_error:
-+ * shows an error message and terminates.
-+ * pic_error:
-+ * shows a non-file error message and jumps to the entry for errors.
-+ * pic_file_error:
-+ * shows a file error message and jumps to the entry for errors.
-+ * pic_file_warning:
-+ * shows a file warning message.
-+ */
-+static void pic_memory_error(scm, fn)
-+ char *scm, *fn;
-+{
-+ char buf[128];
-+ sprintf(buf, "%s: can't allocate memory. (%s)", scm, fn);
-+ FatalError(buf);
-+}
-+
-+static void pic_error(pi, mn)
-+ struct pic_info *pi;
-+ int mn;
-+{
-+ SetISTR(ISTR_WARNING, "%s", pic_msgs[mn]);
-+ longjmp(pi->jmp, 1);
-+}
-+
-+static void pic_file_error(pi, mn)
-+ struct pic_info *pi;
-+ int mn;
-+{
-+ if(feof(pi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", pic_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", pic_msgs[mn], ERRSTR(errno));
-+ longjmp(pi->jmp, 1);
-+}
-+
-+static void pic_file_warning(pi, mn)
-+ struct pic_info *pi;
-+ int mn;
-+{
-+ if(feof(pi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", pic_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", pic_msgs[mn], ERRSTR(errno));
-+}
-+
-+static void pic_show_pic_info(pi)
-+ struct pic_info *pi;
-+{
-+ fprintf(stderr, " file size: %ld.\n", pi->fsize);
-+
-+ fputs(" machine: ", stderr);
-+ switch(pi->type){
-+ case 0x0:
-+ fputs("X68k", stderr);
-+ break;
-+ case 0x1:
-+ fputs("PC-88VA", stderr);
-+ if(pi->mode & 1)
-+ fputs(",HR", stderr);
-+ if(pi->mode & 2)
-+ fputs(",tiled256", stderr);
-+ break;
-+ case 0x2:
-+ fprintf(stderr,
-+ "FM-TOWNS,%s-resolution", pi->mode == 5 ? "low" : "high");
-+ break;
-+ case 0x3:
-+ fputs("Macintosh", stderr);
-+ break;
-+ case 0xf:
-+ fputs("misc", stderr);
-+ }
-+ fputs("\n", stderr);
-+
-+ fprintf(stderr, " image size: %dx%d\n", pi->width, pi->height);
-+ fprintf(stderr, " aspect: %f\n", pi->aspect);
-+ fprintf(stderr, " cache: %s\n", pi->cached ? "on" : "off");
-+ fprintf(stderr, " colormap: %s\n", pi->cmapped ? "on" : "off");
-+ fprintf(stderr, " number of color bits: %d\n", pi->cbits);
-+ fprintf(stderr, " number of RGB bits: R%d,G%d,B%d,I%d\n",
-+ pi->r_bits, pi->g_bits, pi->b_bits, pi->i_bits);
-+ fprintf(stderr, " inverted G&R: %s\n", pi->inv_gr ? "true" : "false");
-+ fprintf(stderr, " number of colors: %d\n", pi->numcols);
-+}
-+
-+/* Memory related routines. */
-+static void *pic_malloc(n, fn)
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (void *) malloc(n);
-+ if(r == NULL)
-+ pic_memory_error("malloc", fn);
-+ return r;
-+}
-+
-+static void *pic_realloc(p, n, fn)
-+ void *p;
-+ size_t n;
-+ char *fn;
-+{
-+ void *r = (p == NULL) ? (void *) malloc(n) : (void *) realloc(p, n);
-+ if(r == NULL)
-+ pic_memory_error("realloc", fn);
-+ return r;
-+}
-+#endif /* HAVE_PIC */
-diff -u -r --new-file xv-3.10a.orig/xvpic2.c xv-3.10a/xvpic2.c
---- xv-3.10a.orig/xvpic2.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvpic2.c 2007-04-15 17:02:32.000000000 -0500
-@@ -0,0 +1,3608 @@
-+/*
-+ * $Id: xvpic2.c,v 2.9.1.14 1995/04/24 15:34:15 ikeyan Exp $
-+ * xvpic2.c - load and save routines for `PIC2' format pictures.
-+ *
-+ *
-+ * Outline
-+ * =======
-+ * xvpic2.c supports the PIC2 format image file. It is used some
-+ * Japanese personal computer users.
-+ *
-+ * The PIC2 format is designed by A.Yanagisawa. It is an excellent
-+ * format except for its encode/decode speed. ;-)
-+ *
-+ * The features of the PIC2 format:
-+ * - Powerful header information (included author, filename, title,
-+ * saver, product number, created date and comment).
-+ * - Reversible compression, and very high compression ratio (in many
-+ * cases, a higher compression ratio than the JPEG compression;
-+ * because of its compression method, PIC2 is especially good at
-+ * pictures like cell animation).
-+ * - Can handle full-color (24 bits) image.
-+ * - Can include multi image blocks into one PIC2 file.
-+ * - Have four different block format (P2SS, P2SF, P2BM and
-+ * P2BI). P2SS format uses arithmetic compression for storing
-+ * data. P2SF uses normal run-length compression. P2BM and P2BI is
-+ * raw image format. Select any one according to the situation.
-+ *
-+ * Explanation of the PIC2 compression:
-+
-+ * - In the first place, try to record pixel color, uses color caches
-+ * which keep some recent colors, and formed according to color's
-+ * frequency. PIC2 has some color cache spaces that are switched by
-+ * upper pixel value of current pixel. If cache is hit, record
-+ * that.
-+ * - Unfortunately, in the case of color cache didn't hit, record the
-+ * difference from the value estimated with the value of upper and
-+ * left pixel of current pixel (similar to PNG's AVG predictor).
-+ * - And extract image's color chain if exist, and record that (it
-+ * results in image's outline).
-+ * - In all cases, arithmetic compression is used in the final stage
-+ * before writing the file, which in theory produces the ideal
-+ * compression ratio (P2SS).
-+ *
-+ * Features
-+ * ========
-+ * - Support 3,6,9,12,15,18,21,24bit PIC2 format (Load/Save).
-+ * - Support all image block formats of PIC2 (Load/Save).
-+ * - Support multi block PIC2 file (Load/Save).
-+ *
-+ *
-+ * Bugs
-+ * ====
-+ * - Unsupport 8bit PIC2 image file.
-+ *
-+ * If you find other bugs (surely exist :-)), send me bug-report.
-+ *
-+ *
-+ * Author
-+ * ======
-+ * IKEMOTO Masahiro
-+ */
-+
-+#define PIC2_IGNORE_UNUSED_FUNCTIONS
-+#define NEEDSDIR
-+
-+#include "xv.h"
-+#include
-+
-+#ifdef HAVE_PIC2
-+
-+typedef unsigned long pixel;
-+
-+#define pic2_cextoshort(addr) ( \
-+ (((short) (((byte *) addr)[0])) << 8) | \
-+ ( (short) (((byte *) addr)[1])) \
-+)
-+#define pic2_cextolong(addr) ( \
-+ (((long) (((byte *) addr)[0])) << 24) | \
-+ (((long) (((byte *) addr)[1])) << 16) | \
-+ (((long) (((byte *) addr)[2])) << 8) | \
-+ ( (long) (((byte *) addr)[3])) \
-+)
-+#define pic2_shorttocex(addr, n) { \
-+ ((byte *) addr)[0] = (((unsigned short) (n) >> 8) & 0xff); \
-+ ((byte *) addr)[1] = ( (unsigned short) (n) & 0xff); \
-+}
-+#define pic2_longtocex(addr, n) { \
-+ ((byte *) addr)[0] = (((unsigned long) (n) >> 24) & 0xff); \
-+ ((byte *) addr)[1] = (((unsigned long) (n) >> 16) & 0xff); \
-+ ((byte *) addr)[2] = (((unsigned long) (n) >> 8) & 0xff); \
-+ ((byte *) addr)[3] = ( (unsigned long) (n) & 0xff); \
-+}
-+#define pic2_shift_bits(b, n) (((n) > 0) ? ((b) << (n)) : ((b) >> -(n)))
-+
-+#define PIC2_READ_MODE 0
-+#define PIC2_WRITE_MODE 1
-+
-+#define PIC2_ARITH_CACHE 32
-+#define PIC2_ARITH_CONTEXT 128
-+#define PIC2_FAST_CACHE 64
-+
-+#define PIC2_HEADER_SIZE 124
-+#define PIC2_BLOCK_HEADER_SIZE 26
-+
-+struct pic2_header {
-+ char magic[4];
-+ char name[18];
-+ char subtitle[8];
-+ char crlf0[2];
-+ char title[30];
-+ char crlf1[2];
-+ char saver[30];
-+ char crlf2[2];
-+ char eof[1];
-+ char reserve0[1];
-+ short flag;
-+ short no;
-+ long time;
-+ long size;
-+ short depth;
-+ short x_aspect;
-+ short y_aspect;
-+ short x_max;
-+ short y_max;
-+ long reserve1;
-+};
-+
-+struct pic2_block {
-+ char id[4];
-+ long size;
-+ short flag;
-+ short x_wid;
-+ short y_wid;
-+ short x_offset;
-+ short y_offset;
-+ long opaque;
-+ long reserve;
-+};
-+
-+struct pic2_info {
-+ jmp_buf jmp;
-+ FILE *fp;
-+ struct {
-+ int rest;
-+ byte cur;
-+ int bits;
-+ char zero;
-+ }bs;
-+ long fsize;
-+ struct pic2_header *header;
-+ struct pic2_block *block;
-+ int n_pal;
-+ int pal_bits;
-+ byte pal[256][3];
-+ char *comment;
-+ char mode;
-+ long next_pos;
-+ long block_pos;
-+ short x_max;
-+ short y_max;
-+ int ynow;
-+ byte *buf;
-+ pixel *vram_prev;
-+ pixel *vram_now;
-+ pixel *vram_next;
-+ short *flag_now;
-+ short *flag_next;
-+ short *flag2_now;
-+ short *flag2_next;
-+ short *flag2_next2;
-+ pixel (*cache)[PIC2_ARITH_CACHE];
-+ unsigned short *cache_pos;
-+ unsigned short *mulu_tab;
-+ long aa;
-+ long cc;
-+ long dd;
-+ char cache_hit_c;
-+ int (*next_line) PARM((struct pic2_info *, pixel **));
-+ char writing_grey;
-+ char pagebname[64];
-+ int pnum;
-+};
-+
-+static void pic2_open_file PARM((struct pic2_info*,char*));
-+static void pic2_read_header PARM((struct pic2_info*));
-+static void pic2_read_block_header1 PARM((struct pic2_info*));
-+static void pic2_read_block_header2 PARM((struct pic2_info*));
-+static short pic2_arith_decode_bit PARM((struct pic2_info*,int));
-+static short pic2_arith_decode_nn PARM((struct pic2_info*,int));
-+static void pic2_arith_expand_chain PARM((struct pic2_info*,int,int,pixel));
-+static short pic2_arith_get_number PARM((struct pic2_info*,int,int));
-+static pixel pic2_arith_read_color PARM((struct pic2_info*,int));
-+static int pic2_arith_expand_line PARM((struct pic2_info*,pixel**));
-+static int pic2_arith_loader_init PARM((struct pic2_info*));
-+static int pic2_fast_read_length PARM((struct pic2_info*));
-+static void pic2_fast_expand_chain PARM((struct pic2_info*,int,pixel));
-+static pixel pic2_fast_read_color PARM((struct pic2_info*,pixel));
-+static int pic2_fast_expand_line PARM((struct pic2_info*,pixel**));
-+static int pic2_fast_loader_init PARM((struct pic2_info*));
-+static int pic2_beta_expand_line PARM((struct pic2_info*,pixel**));
-+static int pic2_beta_loader_init PARM((struct pic2_info*));
-+static void pic2_make_xvpic PARM((struct pic2_info*,byte**,
-+ byte*,byte*,byte*));
-+static void pic2_make_pagefile PARM((struct pic2_info*,char*,int));
-+static void pic2_setup_pic2_info PARM((struct pic2_info*,
-+ char*,char*,char*,char*,
-+ int,int,int,int,int,int,char *));
-+static void pic2_append PARM((struct pic2_info*));
-+static void pic2_write_header1 PARM((struct pic2_info*));
-+static void pic2_write_header2 PARM((struct pic2_info*));
-+static void pic2_write_block_header PARM((struct pic2_info*));
-+static void pic2_arith_write_zero_bit PARM((struct pic2_info*));
-+static void pic2_arith_flush_bit_buf PARM((struct pic2_info*));
-+static void pic2_arith_carry_bit PARM((struct pic2_info*));
-+static void pic2_arith_encode_bit PARM((struct pic2_info*,int,int));
-+static void pic2_arith_encode_nbyte PARM((struct pic2_info*,int,int,int));
-+static void pic2_arith_encode_nn PARM((struct pic2_info*,int,int));
-+static void pic2_arith_press_chain PARM((struct pic2_info*,int));
-+static void pic2_arith_put_number PARM((struct pic2_info*,int,int,int));
-+static void pic2_arith_write_color PARM((struct pic2_info*,int));
-+static void pic2_arith_press_line2 PARM((struct pic2_info*));
-+static int pic2_arith_press_line PARM((struct pic2_info*,pixel**));
-+static int pic2_arith_saver_init PARM((struct pic2_info*,pixel**));
-+static void pic2_fast_write_length PARM((struct pic2_info*,int));
-+static void pic2_fast_press_chain PARM((struct pic2_info*,int));
-+static void pic2_fast_press_chain2 PARM((struct pic2_info*,int));
-+static void pic2_fast_flush_chain PARM((struct pic2_info*));
-+static void pic2_fast_write_color PARM((struct pic2_info*,int));
-+static void pic2_fast_press_line2 PARM((struct pic2_info*));
-+static int pic2_fast_press_line PARM((struct pic2_info*,pixel**));
-+static int pic2_fast_saver_init PARM((struct pic2_info*,pixel**));
-+static int pic2_beta_press_line PARM((struct pic2_info*,pixel**));
-+static int pic2_beta_saver_init PARM((struct pic2_info*,pixel**));
-+static void pic2_write_data PARM((struct pic2_info*,byte*,
-+ int,int,int,int,int,
-+ byte*,byte*,byte*,int,int));
-+static int pic2_next_line PARM((struct pic2_info*,pixel**));
-+static int pic2_next_block PARM((struct pic2_info*));
-+static int pic2_find_block PARM((struct pic2_info*));
-+static int pic2_load_block PARM((struct pic2_info*));
-+static int pic2_save_block PARM((struct pic2_info*,pixel**,
-+ int,int,int,int,char*,pixel));
-+#ifndef PIC2_IGNORE_UNUSED_FUNCTIONS
-+static void pic2_read_palette PARM((struct pic2_info*,
-+ byte*,byte*,byte*));
-+static void pic2_write_palette PARM((struct pic2_info*,int,int,
-+ byte*,byte*,byte*));
-+#endif /* !PIC2_IGNORE_UNUSED_FUNCTIONS */
-+static byte pic2_convert_color_bits PARM((int,int,int));
-+static byte pic2_pad_color_bits PARM((int,int,int));
-+static byte pic2_reduce_color_bits PARM((int,int,int));
-+static pixel pic2_exchange_rg PARM((pixel,int));
-+static void pic2_handle_para PARM((struct pic2_info*,int));
-+static int pic2_alloc_buffer PARM((struct pic2_info*));
-+static void pic2_free_buffer PARM((struct pic2_info*));
-+static long pic2_seek_file PARM((struct pic2_info*,long,int));
-+static long pic2_tell_file PARM((struct pic2_info*));
-+static int pic2_read_file PARM((struct pic2_info*,void*,size_t));
-+static long pic2_read_long PARM((struct pic2_info*));
-+static short pic2_read_short PARM((struct pic2_info*));
-+static char pic2_read_char PARM((struct pic2_info*));
-+static int pic2_write_file PARM((struct pic2_info*,void*,size_t));
-+static int pic2_write_long PARM((struct pic2_info*,long));
-+static int pic2_write_short PARM((struct pic2_info*,int));
-+static int pic2_write_char PARM((struct pic2_info*,int));
-+static unsigned long pic2_read_bits PARM((struct pic2_info*,int));
-+static void pic2_write_bits PARM((struct pic2_info*,
-+ unsigned long,int));
-+static void pic2_flush_bits PARM((struct pic2_info*));
-+static void pic2_memory_error PARM((char*,char*));
-+static void pic2_error PARM((struct pic2_info*,int));
-+static void pic2_file_error PARM((struct pic2_info*,int));
-+static void pic2_init_info PARM((struct pic2_info*));
-+static void pic2_cleanup_pic2_info PARM((struct pic2_info*,int));
-+static void pic2_cleanup_pinfo PARM((PICINFO*));
-+static void pic2_show_pic2_info PARM((struct pic2_info*));
-+static char *pic2_strncpy PARM((char*,char*,size_t));
-+static void *pic2_malloc PARM((size_t,char*));
-+static void *pic2_new PARM((size_t,char*));
-+
-+static int WritePIC2 PARM((FILE*,byte*,int,int,int,
-+ byte*,byte*,byte*,int,int,char*,
-+ int,int,int,int,int,char*));
-+
-+static char *pic2_id = "P2DT";
-+
-+/* Error Messages */
-+static char *pic2_msgs[] = {
-+ NULL,
-+#define PIC2_OPEN 1
-+ "can't open file.",
-+#define PIC2_CORRUPT 2
-+ "file corrupted.",
-+#define PIC2_FORMAT 3
-+ "not PIC2 format.",
-+#define PIC2_DEPTH 4
-+ "bit depths not divisible by 3 are unsupported.",
-+#define PIC2_TMPFILE 5
-+ "unable to create temporary filename???",
-+#define PIC2_PAGE 6
-+ "couldn't load the page.",
-+#define PIC2_APPEND 7
-+ "cannot append.",
-+#define PIC2_WRITE 8
-+ "write failed.",
-+};
-+
-+struct _form_tab {
-+ char *id;
-+ int (*loader_init) PARM((struct pic2_info *));
-+ int (*saver_init) PARM((struct pic2_info *, pixel **));
-+} form_tab[] = {
-+ { "P2SS", pic2_arith_loader_init, pic2_arith_saver_init},
-+ { "P2SF", pic2_fast_loader_init, pic2_fast_saver_init},
-+ { "P2BM", pic2_beta_loader_init, pic2_beta_saver_init},
-+ { "P2BI", pic2_beta_loader_init, pic2_beta_saver_init},
-+};
-+#define n_form_tab (sizeof(form_tab) / sizeof(struct _form_tab))
-+#define P2SS 0
-+#define P2SF 1
-+#define P2BM 2
-+#define P2BI 3
-+
-+/* The main routine to load a PIC2 file. */
-+int LoadPIC2(fname, pinfo, quick)
-+char *fname;
-+PICINFO *pinfo;
-+int quick;
-+{
-+ int e, i, block;
-+ struct pic2_info pic2;
-+
-+ if (DEBUG)
-+ fputs("LoadPIC2:\n", stderr);
-+
-+ pic2_init_info(&pic2);
-+
-+ if ((e = setjmp(pic2.jmp)) != 0){
-+ /* When an error occurs, comes here. */
-+ pic2_free_buffer(&pic2);
-+ pic2_cleanup_pic2_info(&pic2, 0);
-+ pic2_cleanup_pinfo(pinfo);
-+ if (pic2split)
-+ KillPageFiles(pic2.pagebname, pic2.pnum);
-+ SetCursors(-1);
-+ if (DEBUG)
-+ fputs("\n", stderr);
-+ return (0);
-+ }
-+ pic2_open_file(&pic2, fname);
-+ pic2_read_header(&pic2);
-+
-+ if ((i = pic2_find_block(&pic2)) == 0)
-+ pic2_file_error(&pic2, PIC2_CORRUPT);
-+
-+ block = 1;
-+ while(i == 2) {
-+ SetISTR(ISTR_WARNING, "unknown or invalid block #%d.", block);
-+ i = pic2_next_block(&pic2);
-+ block++;
-+ }
-+
-+ if (pic2split && !quick) {
-+ char firstpage[512];
-+ struct stat st;
-+#ifndef USE_MKSTEMP
-+ int tmpfd;
-+#endif
-+
-+#ifndef VMS
-+ sprintf(pic2.pagebname, "%s/xvpic2XXXXXX", tmpdir);
-+#else
-+ sprintf(pic2.pagebname, "Sys$Scratch:xvpic2XXXXXX");
-+#endif
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(pic2.pagebname));
-+#else
-+ mktemp(pic2.pagebname);
-+ tmpfd = open(pic2.pagebname, O_WRONLY|O_CREAT|O_EXCL, S_IRWUSR);
-+ if (tmpfd < 0) FatalError("LoadPIC2(): can't create temporary file");
-+ close(tmpfd);
-+#endif
-+ if (pic2.pagebname[0] == '\0')
-+ pic2_error(&pic2, PIC2_TMPFILE);
-+ strcat(pic2.pagebname, ".");
-+
-+ sprintf(firstpage, "%s%d", pic2.pagebname, 1);
-+ if (stat(firstpage, &st)) {
-+ for (pic2.pnum = 1; i >= 1; pic2.pnum++) {
-+ pic2_load_block(&pic2);
-+ pic2_make_pagefile(&pic2, pic2.pagebname, pic2.pnum);
-+ while(block++, (i = pic2_next_block(&pic2)) == 2)
-+ SetISTR(ISTR_WARNING,
-+ "unknown or invalid block #%d.", block);
-+ }
-+ pinfo->numpages = --pic2.pnum;
-+ if (!LoadPIC2(firstpage, pinfo, 1))
-+ pic2_error(&pic2, PIC2_PAGE);
-+ if (pic2.pnum == 1)
-+ unlink(firstpage);
-+ else
-+ strcpy(pinfo->pagebname, pic2.pagebname);
-+ } else
-+ if (!LoadPIC2(fname, pinfo, 1))
-+ pic2_error(&pic2, PIC2_PAGE);
-+ } else {
-+ char buf[128], format[64];
-+ int j;
-+
-+ pinfo->w = pic2.x_max;
-+ pinfo->h = pic2.y_max;
-+ pinfo->normw = pinfo->w;
-+ pinfo->normh = pinfo->h;
-+ pinfo->type = PIC24;
-+ for (j = 0; j < n_form_tab; j++) {
-+ if (xvbcmp(pic2.block->id, form_tab[j].id, (size_t) 4) == 0)
-+ break;
-+ }
-+ pinfo->frmType = F_PIC2;
-+ pinfo->colType = F_FULLCOLOR;
-+ pinfo->comment = pic2.comment;
-+
-+ if (pic2split) {
-+ pic2_make_xvpic(&pic2, &pinfo->pic, pinfo->r, pinfo->g, pinfo->b);
-+ strcpy(format, form_tab[j].id);
-+ } else {
-+ for (pic2.pnum = 1; i >= 1; pic2.pnum++) {
-+ SetISTR(ISTR_INFO, "composing block #%d", block);
-+ pic2_make_xvpic(&pic2, &pinfo->pic,
-+ pinfo->r, pinfo->g, pinfo->b);
-+ while(block++, (i = pic2_next_block(&pic2)) == 2)
-+ SetISTR(ISTR_WARNING,
-+ "unknown or invalid block #%d.", block);
-+ }
-+ if (--block > 1)
-+ if (block != --pic2.pnum)
-+ sprintf(format, "MultiBlock[%d/%d]", block, pic2.pnum);
-+ else
-+ sprintf(format, "MultiBlock[%d]", block);
-+ else
-+ strcpy(format, form_tab[j].id);
-+ }
-+ sprintf(buf, "PIC2(%s). %d colors (%ld bytes)", format,
-+ (int) 1 << pic2.header->depth, pic2.fsize);
-+ strcat(pinfo->fullInfo, buf);
-+ sprintf(pinfo->shrtInfo, "%dx%d(aspect %4.2f) PIC2(%s).",
-+ pinfo->w, pinfo->h,
-+ (float) pic2.header->x_aspect / (float) pic2.header->y_aspect,
-+ format);
-+ if (!nopicadjust)
-+ normaspect = (float) pic2.header->x_aspect
-+ / (float) pic2.header->y_aspect;
-+ }
-+ pic2_cleanup_pic2_info(&pic2, 0);
-+ SetCursors(-1);
-+ if (DEBUG)
-+ fputs("\n", stderr);
-+ return (1);
-+}
-+
-+/*
-+ * This function opens the file, and set its size.
-+ */
-+static void pic2_open_file(pi, fname)
-+ struct pic2_info *pi;
-+ char *fname;
-+{
-+ if ((pi->fp = fopen(fname, "rb")) == NULL)
-+ pic2_file_error(pi, PIC2_OPEN);
-+ fseek(pi->fp, (size_t) 0, SEEK_END);
-+ pi->fsize = ftell(pi->fp);
-+ fseek(pi->fp, (size_t) 0, SEEK_SET);
-+}
-+
-+/*
-+ * These functions read the PIC2 header informations.
-+ * pic2_read_header:
-+ * reads the PIC2 header.
-+ * pic2_read_block_header1:
-+ * reads the id number of block header and the size of block.
-+ * pic2_read_block_header2:
-+ * reads the rest of block header.
-+ */
-+static void pic2_read_header(pi)
-+struct pic2_info *pi;
-+{
-+ long s_comment;
-+
-+ pi->mode = PIC2_READ_MODE;
-+
-+ /* read header image */
-+ pic2_read_file(pi, pi->header->magic, 4);
-+ pic2_read_file(pi, pi->header->name, 18);
-+ pic2_read_file(pi, pi->header->subtitle, 8);
-+ pic2_read_file(pi, pi->header->crlf0, 2);
-+ pic2_read_file(pi, pi->header->title, 30);
-+ pic2_read_file(pi, pi->header->crlf1, 2);
-+ pic2_read_file(pi, pi->header->saver, 30);
-+ pic2_read_file(pi, pi->header->crlf2, 2);
-+ pic2_read_file(pi, pi->header->eof, 1);
-+ pic2_read_file(pi, pi->header->reserve0, 1);
-+ pi->header->flag = pic2_read_short(pi);
-+ pi->header->no = pic2_read_short(pi);
-+ pi->header->time = pic2_read_long(pi);
-+ pi->header->size = pic2_read_long(pi);
-+ pi->header->depth = pic2_read_short(pi);
-+ pi->header->x_aspect = pic2_read_short(pi);
-+ pi->header->y_aspect = pic2_read_short(pi);
-+ pi->header->x_max = pic2_read_short(pi);
-+ pi->header->y_max = pic2_read_short(pi);
-+ pi->header->reserve1 = pic2_read_long(pi);
-+
-+ /* check magic number */
-+ if (strncmp(pi->header->magic, pic2_id, (size_t) 4) != 0)
-+ pic2_error(pi, PIC2_FORMAT);
-+
-+ /* read palette data, if exists */
-+ if (pi->header->flag & 1) {
-+ pi->pal_bits = pic2_read_char(pi);
-+ pi->n_pal = pic2_read_short(pi);
-+ pic2_read_file(pi, pi->pal, (size_t) (pi->n_pal * 3));
-+ }
-+
-+ /* read comments */
-+ s_comment = pi->header->size - pic2_tell_file(pi);
-+ pi->comment = pic2_new(s_comment + 1, "pic2_read_header");
-+ pic2_read_file(pi, pi->comment, (size_t) s_comment);
-+ pi->comment[s_comment] = '\0';
-+
-+ pi->x_max = pi->header->x_max;
-+ pi->y_max = pi->header->y_max;
-+
-+ /* set initial block point */
-+ pi->next_pos = pic2_tell_file(pi);
-+}
-+
-+static void pic2_read_block_header1(pi)
-+struct pic2_info *pi;
-+{
-+ pic2_read_file(pi, pi->block->id, 4);
-+ pi->block->size = pic2_read_long(pi);
-+}
-+
-+static void pic2_read_block_header2(pi)
-+struct pic2_info *pi;
-+{
-+ pi->block->flag = pic2_read_short(pi);
-+ pi->block->x_wid = pic2_read_short(pi);
-+ pi->block->y_wid = pic2_read_short(pi);
-+ pi->block->x_offset = pic2_read_short(pi);
-+ pi->block->y_offset = pic2_read_short(pi);
-+ pi->block->opaque = pic2_read_long(pi);
-+ pi->block->reserve = pic2_read_long(pi);
-+}
-+
-+/*
-+ * These functions are arithmetic pic2 format extractor.
-+ */
-+static short pic2_arith_decode_bit(pi, c)
-+struct pic2_info *pi;
-+int c;
-+{
-+ unsigned short pp;
-+
-+ pp = pi->mulu_tab[(pi->aa & 0x7f00) / 2 + c];
-+ if (pi->dd >= (int) pp) {
-+ pi->dd -= pp;
-+ pi->aa -= pp;
-+
-+ while ((short) pi->aa >= 0) {
-+ pi->dd *= 2;
-+ if (pic2_read_bits(pi, 1))
-+ pi->dd++;
-+ pi->aa *= 2;
-+ }
-+ return (1);
-+ } else {
-+ pi->aa = pp;
-+
-+ while ((short) pi->aa >= 0) {
-+ pi->dd *= 2;
-+ if (pic2_read_bits(pi, 1))
-+ pi->dd++;
-+ pi->aa *= 2;
-+ }
-+ return (0);
-+ }
-+}
-+
-+static short pic2_arith_decode_nn(pi, c)
-+struct pic2_info *pi;
-+int c;
-+{
-+ int n;
-+
-+ if (pic2_arith_decode_bit(pi, c)) {
-+ /* n < 1 */
-+ n = 0;
-+ } else if (pic2_arith_decode_bit(pi, c + 1)) {
-+ /* n < 1 + 2 */
-+ n = 1;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ } else if (pic2_arith_decode_bit(pi, c + 2)) {
-+ /* n < 1 + 2 + 4 */
-+ n = 1 + 2;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ if (pic2_arith_decode_bit(pi, c + 9))
-+ n += 2;
-+ } else if (pic2_arith_decode_bit(pi, c + 3)) {
-+ /* n < 1 + 2 + 4 + 8 */
-+ n = 1 + 2 + 4;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ if (pic2_arith_decode_bit(pi, c + 9))
-+ n += 2;
-+ if (pic2_arith_decode_bit(pi, c + 10))
-+ n += 4;
-+ } else if (pic2_arith_decode_bit(pi, c + 4)) {
-+ /* n < 1 + 2 + 4 + 8 + 16 */
-+ n = 1 + 2 + 4 + 8;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ if (pic2_arith_decode_bit(pi, c + 9))
-+ n += 2;
-+ if (pic2_arith_decode_bit(pi, c + 10))
-+ n += 4;
-+ if (pic2_arith_decode_bit(pi, c + 11))
-+ n += 8;
-+ } else if (pic2_arith_decode_bit(pi, c + 5)) {
-+ /* n < 1 + 2 + 4 + 8 + 16 + 32 */
-+ n = 1 + 2 + 4 + 8 + 16;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ if (pic2_arith_decode_bit(pi, c + 9))
-+ n += 2;
-+ if (pic2_arith_decode_bit(pi, c + 10))
-+ n += 4;
-+ if (pic2_arith_decode_bit(pi, c + 11))
-+ n += 8;
-+ if (pic2_arith_decode_bit(pi, c + 12))
-+ n += 16;
-+
-+ } else if (pic2_arith_decode_bit(pi, c + 6)) {
-+ /* n < 1 + 2 + 4 + 8 + 16 + 32 + 64 */
-+ n = 1 + 2 + 4 + 8 + 16 + 32;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ if (pic2_arith_decode_bit(pi, c + 9))
-+ n += 2;
-+ if (pic2_arith_decode_bit(pi, c + 10))
-+ n += 4;
-+ if (pic2_arith_decode_bit(pi, c + 11))
-+ n += 8;
-+ if (pic2_arith_decode_bit(pi, c + 12))
-+ n += 16;
-+ if (pic2_arith_decode_bit(pi, c + 13))
-+ n += 32;
-+
-+ } else if (pic2_arith_decode_bit(pi, c + 7)) {
-+ /* n < 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 */
-+ n = 1 + 2 + 4 + 8 + 16 + 32 + 64;
-+ if (pic2_arith_decode_bit(pi, c + 8))
-+ n += 1;
-+ if (pic2_arith_decode_bit(pi, c + 9))
-+ n += 2;
-+ if (pic2_arith_decode_bit(pi, c + 10))
-+ n += 4;
-+ if (pic2_arith_decode_bit(pi, c + 11))
-+ n += 8;
-+ if (pic2_arith_decode_bit(pi, c + 12))
-+ n += 16;
-+ if (pic2_arith_decode_bit(pi, c + 13))
-+ n += 32;
-+ if (pic2_arith_decode_bit(pi, c + 14))
-+ n += 64;
-+
-+ } else {
-+ n = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128;
-+ }
-+ return (n);
-+}
-+
-+static void pic2_arith_expand_chain(pi, x, y, cc)
-+struct pic2_info *pi;
-+int x, y;
-+pixel cc;
-+{
-+ static const unsigned short c_tab[] = {
-+ 80 + 6 * 5, /* -5 */
-+ 80 + 6 * 4,
-+ 80 + 6 * 3,
-+ 80 + 6 * 2,
-+ 80 + 6 * 1,
-+ 80 + 6 * 0, /* 0 */
-+ 80 + 6 * 0, /* 1 */
-+ };
-+ unsigned short b;
-+
-+ b = c_tab[pi->flag_now[x] + 5];
-+ if (!pic2_arith_decode_bit(pi, b++)) {
-+ if (pic2_arith_decode_bit(pi, b++)) { /* down */
-+ pi->vram_next[x ] = cc;
-+ pi->flag_next[x ] = -1;
-+ } else if (pic2_arith_decode_bit(pi, b++)) { /* left */
-+ pi->vram_next[x - 1] = cc;
-+ pi->flag_next[x - 1] = -2;
-+ } else if (pic2_arith_decode_bit(pi, b++)) { /* right */
-+ pi->vram_next[x + 1] = cc;
-+ pi->flag_next[x + 1] = -3;
-+ } else if (pic2_arith_decode_bit(pi, b++)) { /* left2 */
-+ pi->vram_next[x - 2] = cc;
-+ pi->flag_next[x - 2] = -4;
-+ } else { /* right2 */
-+ pi->vram_next[x + 2] = cc;
-+ pi->flag_next[x + 2] = -5;
-+ }
-+ }
-+}
-+
-+static short pic2_arith_get_number(pi, c, bef)
-+struct pic2_info *pi;
-+int c, bef;
-+{
-+ unsigned short n;
-+ byte maxcol;
-+
-+ maxcol = 0xff >> (8 - pi->header->depth / 3);
-+
-+ n = pic2_arith_decode_nn(pi, c);
-+ if (bef > ((int) maxcol >> 1)) {
-+ if (n > ((int) maxcol - bef) * 2)
-+ n = maxcol - n;
-+ else if (n & 1)
-+ n = n / 2 + bef + 1;
-+ else
-+ n = bef - n / 2;
-+ } else {
-+ if ((int) n > (bef * 2))
-+ n = n;
-+ else if (n & 1)
-+ n = n / 2 + bef + 1;
-+ else
-+ n = bef - n / 2;
-+ }
-+ return (n);
-+}
-+
-+static pixel pic2_arith_read_color(pi, x)
-+struct pic2_info *pi;
-+int x;
-+{
-+ pixel c1, c2, cc;
-+ unsigned short i, j, k, m;
-+ short r, g, b, r0, g0, b0;
-+ short colbits;
-+ pixel rmask, gmask, bmask;
-+ byte maxcol;
-+
-+ colbits = pi->header->depth / 3;
-+ rmask = (0xff >> (8 - colbits)) << (colbits * 2);
-+ gmask = (0xff >> (8 - colbits)) << colbits;
-+ bmask = (0xff >> (8 - colbits));
-+ maxcol = (byte) bmask;
-+
-+ c1 = pi->vram_prev[x];
-+ k = ((c1 >> ((colbits - 3) * 3)) & 0x1c0)
-+ | ((c1 >> ((colbits - 3) * 2)) & 0x038)
-+ | ((c1 >> (colbits - 3) ) & 0x007);
-+ if (colbits == 5)
-+ k = pic2_exchange_rg(k, 3);
-+
-+ if (pic2_arith_decode_bit(pi, pi->cache_hit_c)) { /* ouch */
-+ pi->cache_hit_c = 16;
-+
-+ c2 = pi->vram_now[x - 1];
-+ r = ((c1 & rmask) + (c2 & rmask)) >> (colbits * 2 + 1);
-+ g = ((c1 & gmask) + (c2 & gmask)) >> (colbits + 1);
-+ b = ((c1 & bmask) + (c2 & bmask)) >> ( 1);
-+
-+ g0 = pic2_arith_get_number(pi, 32, g);
-+ r = r + g0 - g;
-+ if (r > (short) maxcol)
-+ r = maxcol;
-+ else if (r < 0)
-+ r = 0;
-+
-+ b = b + g0 - g;
-+ if (b > (short) maxcol)
-+ b = maxcol;
-+ else if (b < 0)
-+ b = 0;
-+
-+ r0 = pic2_arith_get_number(pi, 48, r);
-+ b0 = pic2_arith_get_number(pi, 64, b);
-+
-+ pi->cache_pos[k] = j = (pi->cache_pos[k] - 1) & (PIC2_ARITH_CACHE - 1);
-+ pi->cache[k][j] = cc = (r0 << (colbits * 2)) | (g0 << colbits) | b0;
-+ } else {
-+ pi->cache_hit_c = 15;
-+
-+ j = pic2_arith_decode_nn(pi, 17);
-+ m = pi->cache_pos[k];
-+ i = (m + j / 2) & (PIC2_ARITH_CACHE - 1);
-+ j = (m + j) & (PIC2_ARITH_CACHE - 1);
-+
-+ cc = pi->cache[k][j];
-+ pi->cache[k][j] = pi->cache[k][i];
-+ pi->cache[k][i] = pi->cache[k][m];
-+ pi->cache[k][m] = cc;
-+ }
-+ return (cc);
-+}
-+
-+static int pic2_arith_expand_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int ymax;
-+ int x, xw;
-+ pixel cc;
-+
-+ pic2_handle_para(pi, 0);
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid - 1;
-+
-+ if (pi->ynow > ymax)
-+ return (-2); /* end */
-+
-+ /* set right end of previous line before left end of current line. */
-+ if (pi->ynow == 0) {
-+ cc = 0;
-+ } else
-+ cc = pi->vram_prev[xw - 1];
-+ pi->vram_now[-1] = cc;
-+
-+ /* clear flag for change point */
-+ xvbzero((char *) pi->flag_next, xw * sizeof(pi->flag_next[0]));
-+
-+ /* clear flag for position probability space */
-+ xvbzero((char *) pi->flag2_next2, xw * sizeof(pi->flag2_next2[0]));
-+
-+ for (x = 0; x < xw; x++) {
-+ if (pi->flag_now[x] < 0) {
-+ cc = pi->vram_now[x];
-+ if (pi->ynow < ymax)
-+ pic2_arith_expand_chain(pi, x, pi->ynow, cc);
-+ } else if (pic2_arith_decode_bit(pi, pi->flag2_now[x])) {
-+ /* ajust probability space around of change point */
-+ pi->flag2_now [x + 1]++;
-+ pi->flag2_now [x + 2]++;
-+ pi->flag2_next [x - 1]++;
-+ pi->flag2_next [x ]++;
-+ pi->flag2_next [x + 1]++;
-+ pi->flag2_next2[x - 1]++;
-+ pi->flag2_next2[x ]++;
-+ pi->flag2_next2[x + 1]++;
-+
-+ pi->vram_now[x] = cc = pic2_arith_read_color(pi, x);
-+ if (pi->ynow < ymax)
-+ pic2_arith_expand_chain(pi, x, pi->ynow, cc);
-+ } else
-+ pi->vram_now[x] = cc;
-+ }
-+ if (line != NULL)
-+ *line = pi->vram_now;
-+ pi->ynow++;
-+
-+ pic2_handle_para(pi, 1);
-+
-+ return (pi->ynow - 1);
-+}
-+
-+static int pic2_arith_loader_init(pi)
-+struct pic2_info *pi;
-+{
-+ unsigned short p2b[256];
-+ int i, xw;
-+
-+ pi->ynow = 0;
-+
-+ /* check the color depth */
-+ if (pi->header->depth % 3)
-+ pic2_error(pi, PIC2_DEPTH);
-+
-+ /* set function for extract next line */
-+ pi->next_line = pic2_arith_expand_line;
-+
-+ /* clear cache and flags */
-+ xw = pi->block->x_wid;
-+ xvbzero((char *) pi->cache, 8 * 8 * 8 * sizeof(pi->cache[0]));
-+ xvbzero((char *) pi->cache_pos, 8 * 8 * 8 * sizeof(pi->cache_pos[0]));
-+
-+ xvbzero((char *) pi->flag_now, xw * sizeof(pi->flag_now[0]));
-+ xvbzero((char *) pi->flag2_now, 8 + xw * sizeof(pi->flag2_now[0]));
-+ xvbzero((char *) pi->flag2_next, 8 + xw * sizeof(pi->flag2_next[0]));
-+
-+ /* go to picture data field */
-+ pic2_seek_file(pi, pi->block_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+
-+ /* clear bit field marker */
-+ pi->bs.rest = 0;
-+ pi->bs.cur = 0;
-+
-+ /* read probability table */
-+ for (i = 0; i < PIC2_ARITH_CONTEXT; i++)
-+ p2b[i] = pic2_read_short(pi);
-+
-+ /* make multiplication table */
-+ for (i = 0; i < 16384; i++) {
-+ pi->mulu_tab[i] = (long) (i / 128 + 128) * (int) p2b[i & 127] / 256;
-+ if (pi->mulu_tab[i] == 0) pi->mulu_tab[i] = 1;
-+ }
-+ /* initialize some valuables */
-+ pi->aa = 0xffff;
-+ pi->dd = 0;
-+ for (i = 0; i < 16; i++) {
-+ pi->dd *= 2;
-+ if (pic2_read_bits(pi, 1))
-+ pi->dd |= 1;
-+ }
-+ pi->cache_hit_c = 16;
-+
-+ return (0);
-+}
-+
-+/*
-+ * These functions are fast pic2 compression extractor.
-+ */
-+static int pic2_fast_read_length(pi)
-+struct pic2_info *pi;
-+{
-+ int a;
-+
-+ a = 0;
-+ while (pic2_read_bits(pi, 1)) {
-+ a++;
-+ }
-+ if (a == 0)
-+ return (0);
-+ return (pic2_read_bits(pi, a) + (1 << a) - 1);
-+}
-+
-+static void pic2_fast_expand_chain(pi, x, cc)
-+struct pic2_info *pi;
-+int x;
-+pixel cc;
-+{
-+ if (pic2_read_bits(pi, 1) != 0) {
-+ if (pic2_read_bits(pi, 1) != 0) { /* down */
-+ pi->vram_next[x] = cc;
-+ pi->flag_next[x] = -1;
-+ } else if (pic2_read_bits(pi, 1) != 0) {
-+ if (pic2_read_bits(pi, 1) == 0) { /* left2down */
-+ pi->vram_next[x - 2] = cc;
-+ pi->flag_next[x - 2] = -1;
-+ } else { /* left1down */
-+ pi->vram_next[x - 1] = cc;
-+ pi->flag_next[x - 1] = -1;
-+ }
-+ } else {
-+ if (pic2_read_bits(pi, 1) == 0) { /* right2down */
-+ pi->vram_next[x + 2] = cc;
-+ pi->flag_next[x + 2] = -1;
-+ } else { /* left1down */
-+ pi->vram_next[x + 1] = cc;
-+ pi->flag_next[x + 1] = -1;
-+ }
-+ }
-+ }
-+}
-+
-+static pixel pic2_fast_read_color(pi, bc)
-+struct pic2_info *pi;
-+pixel bc;
-+{
-+ pixel cc;
-+ unsigned short j, k, m;
-+ short depth, colbits;
-+ pixel (*cache)[PIC2_FAST_CACHE];
-+
-+ depth = pi->header->depth;
-+ colbits = depth / 3;
-+ cache = (pixel (*)[PIC2_FAST_CACHE]) pi->cache;
-+
-+ bc = pic2_exchange_rg(bc, colbits);
-+ k = pic2_shift_bits(bc, 8 - depth);
-+ if (pic2_read_bits(pi, 1) == 0) {
-+ pi->cache_pos[k] = m = (pi->cache_pos[k] - 1) & (PIC2_FAST_CACHE - 1);
-+ cc = pic2_read_bits(pi, depth);
-+ cc = pic2_exchange_rg(cc, colbits);
-+ cache[k][m] = cc;
-+ } else {
-+ j = pic2_read_bits(pi, 6); /* 6= log2(PIC2_FAST_CACHE) */
-+ m = pi->cache_pos[k];
-+ cc = cache[k][(m + j) & (PIC2_FAST_CACHE - 1)];
-+ }
-+ return (cc);
-+}
-+
-+static int pic2_fast_expand_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int ymax;
-+ int x, xw;
-+ pixel cc;
-+
-+ pic2_handle_para(pi, 0);
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid - 1;
-+
-+ if (pi->ynow > ymax)
-+ return (-2);
-+
-+ if (pi->ynow == 0) {
-+ pi->dd = 0;
-+ pi->aa = pic2_fast_read_length(pi);
-+ if (pi->aa == 1023)
-+ pi->dd = 1023;
-+ else if (pi->aa > 1023)
-+ pi->aa--;
-+ cc = 0;
-+ } else
-+ cc = pi->vram_prev[xw - 1];
-+
-+ xvbzero((char *) pi->flag_next, xw * sizeof(pi->flag_next[0]));
-+
-+ for (x = 0; x < xw; x++) {
-+ if (pi->dd > 0) {
-+ if (pi->flag_now[x] < 0) { /* on chain ? */
-+ cc = pi->vram_now[x];
-+ pic2_fast_expand_chain(pi, x, cc);
-+ if (--pi->dd == 0) {
-+ pi->aa = pic2_fast_read_length(pi);
-+ if (pi->aa == 1023)
-+ pi->dd = 1023;
-+ else if (pi->aa > 1023)
-+ pi->aa--;
-+ }
-+ } else
-+ pi->vram_now[x] = cc;
-+ } else {
-+ if (pi->flag_now[x] < 0) { /* on chain ? */
-+ cc = pi->vram_now[x];
-+ pic2_fast_expand_chain(pi, x, cc);
-+ } else if (--pi->aa < 0) {
-+ cc = pi->vram_now[x] = pic2_fast_read_color(pi, cc);
-+ pic2_fast_expand_chain(pi, x, cc);
-+ pi->aa = pic2_fast_read_length(pi);
-+ if (pi->aa == 1023)
-+ pi->dd = 1023;
-+ else if (pi->aa > 1023)
-+ pi->aa--;
-+ } else
-+ pi->vram_now[x] = cc;
-+ }
-+ }
-+ if (line != NULL)
-+ *line = pi->vram_now;
-+ pi->ynow++;
-+
-+ pic2_handle_para(pi, 1);
-+
-+ return (pi->ynow - 1);
-+}
-+
-+static int pic2_fast_loader_init(pi)
-+struct pic2_info *pi;
-+{
-+ int xw;
-+
-+ pi->ynow = 0;
-+
-+ /* check the color depth */
-+ if (pi->header->depth % 3)
-+ pic2_error(pi, PIC2_DEPTH);
-+
-+ /* set function for extract next line */
-+ pi->next_line = pic2_fast_expand_line;
-+
-+ /* clear cache and flags */
-+ xw = pi->block->x_wid;
-+ xvbzero((char *) pi->cache, sizeof(pi->cache[0]) * 256);
-+ xvbzero((char *) pi->cache_pos, sizeof(pi->cache_pos[0]) * 8 * 8 * 8);
-+ xvbzero((char *) pi->flag_now, (xw + 8) * sizeof(pi->flag_now[0]));
-+ xvbzero((char *) pi->flag_next, (xw + 8) * sizeof(pi->flag_next[0]));
-+
-+ /* go to picture data field */
-+ pic2_seek_file(pi, pi->block_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+
-+ /* clear bit field marker */
-+ pi->bs.rest = 0;
-+ pi->bs.cur = 0;
-+
-+ return (0);
-+}
-+
-+/*
-+ * These functions are beta pic2 format extractor.
-+ */
-+static int pic2_beta_expand_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int i, xw, ymax;
-+ byte a, b, c, *p;
-+ pixel *pc;
-+ short depth, pixbyte, colbits;
-+
-+ depth = pi->header->depth;
-+ pixbyte = depth / 8 + ((depth % 8) > 0);
-+ colbits = depth / 3;
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid - 1;
-+
-+ if (pi->ynow > ymax)
-+ return (-2); /* end */
-+
-+ pc = pi->vram_now;
-+ p = (byte *) pi->vram_prev;
-+ if (pixbyte == 3) {
-+ pic2_read_file(pi, pi->vram_prev, (size_t) (xw * pixbyte));
-+ for (i = 0; i < xw; i++, pc++) {
-+ a = *p++;
-+ b = *p++;
-+ c = *p++;
-+ *pc = ((pixel) a << 16) | ((pixel) b << 8) | (pixel) c;
-+ }
-+ } else if (pixbyte == 2) {
-+ pic2_read_file(pi, pi->vram_prev, (size_t) (xw * 2));
-+ if (strncmp(pi->block->id, "P2BM", 4) == 0) {
-+ for (i = 0; i < xw; i++, pc++) {
-+ a = *p++;
-+ b = *p++;
-+ *pc = ((pixel) a << 8) | (pixel) b;
-+ if (colbits == 5) {
-+ *pc >>= 1;
-+ *pc = pic2_exchange_rg(*pc, colbits);
-+ }
-+ }
-+ } else {
-+ for (i = 0; i < xw; i++, pc++) {
-+ a = *p++;
-+ b = *p++;
-+ *pc = ((pixel) b << 8) | (pixel) a;
-+ if (colbits == 5) {
-+ *pc >>= 1;
-+ *pc = pic2_exchange_rg(*pc, colbits);
-+ }
-+ }
-+ }
-+ } else {
-+ pic2_read_file(pi, pi->vram_prev, (size_t) xw);
-+ for (i = 0; i < xw; i++)
-+ *pc++ = *p++;
-+ }
-+ if (line != NULL)
-+ *line = pi->vram_now;
-+
-+ pc = pi->vram_prev;
-+ pi->vram_prev = pi->vram_now;
-+ pi->vram_now = pi->vram_next;
-+ pi->vram_next = pc;
-+
-+ pi->ynow++;
-+ return (pi->ynow - 1);
-+}
-+
-+static int pic2_beta_loader_init(pi)
-+struct pic2_info *pi;
-+{
-+ pi->ynow = 0;
-+ pi->next_line = pic2_beta_expand_line;
-+ pic2_seek_file(pi, pi->block_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+ return (0);
-+}
-+
-+/*
-+ * Make a picture from the expanded data.
-+ */
-+static void pic2_make_xvpic(pi, xp, rp, gp, bp)
-+struct pic2_info *pi;
-+byte **xp, *rp, *gp, *bp;
-+{
-+ int line, i;
-+ pixel *linep, opaque;
-+ short colbits;
-+ byte colmask;
-+
-+ if (*xp == NULL)
-+ *xp = pic2_new((size_t) pi->x_max * pi->y_max * 3, "pic2_make_xvpic"); // GRR POSSIBLE OVERFLOW / FIXME
-+
-+ if (pi->block->flag & 1)
-+ opaque = pi->block->opaque;
-+ else
-+ opaque = 0xffffffff;
-+
-+ colbits = pi->header->depth / 3;
-+ colmask = 0xff >> (8 - colbits);
-+
-+ line = pic2_load_block(pi);
-+ for (;;) {
-+ int pic_idx;
-+
-+ line = pic2_next_line(pi, &linep);
-+ if (line < 0)
-+ break;
-+ pic_idx = ((line + pi->block->y_offset) * pi->x_max
-+ + pi->block->x_offset) * 3;
-+
-+ for (i = 0; i < pi->block->x_wid; i++, linep++) {
-+ byte r, g, b;
-+
-+ if (*linep != opaque) {
-+ r = ((*linep >> (colbits * 2)) & colmask);
-+ r = pic2_convert_color_bits(r, colbits, 8);
-+ g = ((*linep >> colbits ) & colmask);
-+ g = pic2_convert_color_bits(g, colbits, 8);
-+ b = ( *linep & colmask);
-+ b = pic2_convert_color_bits(b, colbits, 8);
-+ (*xp)[pic_idx++] = r;
-+ (*xp)[pic_idx++] = g;
-+ (*xp)[pic_idx++] = b;
-+ } else
-+ pic_idx += 3;
-+
-+ WaitCursor();
-+ }
-+ }
-+}
-+
-+/*
-+ * This function splits a multiblock PIC2 file into several pages.
-+ */
-+static void pic2_make_pagefile(pi, pagebname, pnum)
-+struct pic2_info *pi;
-+char *pagebname;
-+int pnum;
-+{
-+ struct pic2_info pic2;
-+ FILE *fp;
-+ char pagefile[64], *buf;
-+ size_t imagesize;
-+
-+ sprintf(pagefile, "%s%d", pagebname, pnum);
-+ if ((fp = fopen(pagefile, "wb")) == NULL)
-+ pic2_error(pi, PIC2_WRITE);
-+
-+ xvbcopy((char *) pi, (char *) &pic2, sizeof(struct pic2_info));
-+ pic2.fp = fp;
-+
-+ pic2_write_header1(&pic2);
-+
-+ pic2_write_block_header(&pic2);
-+
-+ imagesize = pi->block->size - PIC2_BLOCK_HEADER_SIZE;
-+ buf = (char *) pic2_malloc(imagesize, "pic2_make_pagefile");
-+
-+ pic2_seek_file(pi, pi->block_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+ if (fread(buf, (size_t) 1, imagesize, pi->fp) < imagesize) {
-+ free(buf);
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+ }
-+ if (fwrite(buf, (size_t) 1, imagesize, fp) < imagesize) {
-+ free(buf);
-+ pic2_error(pi, PIC2_WRITE);
-+ }
-+ free(buf);
-+
-+ pic2.next_pos = pic2_tell_file(&pic2);
-+ pic2_write_header2(&pic2);
-+
-+ fclose(fp);
-+}
-+
-+/* The main routine to save a PIC2 file. */
-+static int WritePIC2(fp, pic0, ptype, w, h, rmap, gmap, bmap, numcols,
-+ colorstyle, fname, type, depth, x_offset, y_offset,
-+ append, comment)
-+FILE *fp;
-+byte *pic0;
-+int ptype, w, h;
-+byte *rmap, *gmap, *bmap;
-+int numcols, colorstyle;
-+char *fname;
-+int type, depth;
-+int x_offset, y_offset;
-+int append;
-+char *comment;
-+{
-+ struct pic2_info pic2;
-+ char creator[256], title[256], saver[256];
-+ int e;
-+
-+ if (DEBUG)
-+ fputs("WritePIC2:\n", stderr);
-+
-+ pic2_init_info(&pic2);
-+ pic2.fp = fp;
-+ pic2.writing_grey = (colorstyle == F_GREYSCALE);
-+
-+ if ((e = setjmp(pic2.jmp)) != 0){
-+ /* When an error occurs while writing, comes here. */
-+ pic2_free_buffer(&pic2);
-+ pic2_cleanup_pic2_info(&pic2, 1);
-+ SetCursors(-1);
-+ if (DEBUG)
-+ fputs("\n", stderr);
-+ return (-1);
-+ }
-+ sprintf(creator, "XV Version %s", VERSTR);
-+ pic2_strncpy(title, comment, 30);
-+ sprintf(saver, "XV %s/UNIX/Bradley", VERSTR);
-+
-+ if (!append) {
-+ pic2_setup_pic2_info(&pic2, creator, fname, title, saver,
-+ 0, depth, 1, 1, w, h, comment);
-+ pic2_write_header1(&pic2);
-+ } else {
-+ pic2_read_header(&pic2);
-+ pic2_append(&pic2);
-+ free(pic2.comment);
-+ pic2_setup_pic2_info(&pic2, creator, fname, title, saver,
-+ 0, depth, 1, 1, w, h, comment);
-+ }
-+
-+ pic2_write_data(&pic2, pic0, ptype, x_offset, y_offset, w, h,
-+ rmap, gmap, bmap, type, depth);
-+ pic2_write_header2(&pic2);
-+
-+ pic2_cleanup_pic2_info(&pic2, 1);
-+ SetCursors(-1);
-+ if (DEBUG)
-+ fputs("\n", stderr);
-+ return (0);
-+}
-+
-+/*
-+ * This function initializes pic2_info.
-+ */
-+static void pic2_setup_pic2_info(pi, name, fname, title, saver, no, depth,
-+ x_aspect, y_aspect, x_max, y_max, comment)
-+struct pic2_info *pi;
-+char *name, *fname, *title, *saver;
-+int no, depth;
-+int x_aspect, y_aspect;
-+int x_max, y_max;
-+char *comment;
-+{
-+ char basename[256], *suffix;
-+
-+ pi->mode = PIC2_WRITE_MODE;
-+
-+ /* set magic number */
-+ strncpy(pi->header->magic, pic2_id, 4);
-+
-+ /* set creator's name */
-+ pic2_strncpy(pi->header->name, (char *) name, 18);
-+
-+ /* set title and subtitle */
-+ pic2_strncpy(pi->header->title, (char *) title, 30);
-+ strcpy(basename, BaseName(fname));
-+ suffix = (char *) rindex(basename, '.');
-+ if (suffix) {
-+ suffix++;
-+ if (!strcmp(suffix, "p2") || !strcmp(suffix, "P2"))
-+ *(suffix - 1) = '\0';
-+ }
-+ pic2_strncpy(pi->header->subtitle, basename, 8);
-+
-+ /* set saver */
-+ pic2_strncpy(pi->header->saver, saver, 30);
-+
-+ /* set picture number */
-+ pi->header->no = no;
-+
-+ /* import comment */
-+ pi->comment = comment;
-+
-+ /* set some picture's info */
-+ pi->header->depth = depth;
-+ pi->header->x_aspect = x_aspect;
-+ pi->header->y_aspect = y_aspect;
-+ pi->header->x_max = x_max;
-+ pi->header->y_max = y_max;
-+
-+ /* set some gaps */
-+ pi->header->crlf0[0] = pi->header->crlf1[0] = pi->header->crlf2[0] = 0x0d;
-+ pi->header->crlf0[1] = pi->header->crlf1[1] = pi->header->crlf2[1] = 0x0a;
-+
-+ pi->header->eof[0] = 0x1a;
-+ pi->header->reserve0[0] = 0;
-+ pi->header->reserve1 = 0;
-+
-+ /* set palettes */
-+ if (pi->n_pal > 0)
-+ pi->header->flag = 1;
-+ else
-+ pi->header->flag = 0;
-+}
-+
-+/*
-+ * This function appends to existing pic2 file.
-+ */
-+static void pic2_append(pi)
-+struct pic2_info *pi;
-+{
-+ int block;
-+
-+ block = pic2_find_block(pi);
-+ while (block > 0)
-+ block = pic2_next_block(pi);
-+
-+ if (block != 0)
-+ pic2_error(pi, PIC2_APPEND);
-+}
-+
-+/*
-+ * These functions write the PIC2 header.
-+ * pic2_write_header1:
-+ * write palette data and comment.
-+ * pic2_write_header2:
-+ * write the terminate block and rest header.
-+ * pic2_write_block_header:
-+ * write the block header.
-+ */
-+static void pic2_write_header1(pi)
-+struct pic2_info *pi;
-+{
-+ char *comment;
-+
-+ /* seek to block start position */
-+ pic2_seek_file(pi, PIC2_HEADER_SIZE, SEEK_SET);
-+
-+ /* write palette */
-+ if (pi->n_pal > 0) {
-+ pic2_write_char(pi, pi->pal_bits);
-+ pic2_write_short(pi, pi->n_pal);
-+ pic2_write_file(pi, pi->pal, (size_t) (pi->n_pal * 3));
-+ }
-+ /* save comment */
-+ comment = pi->comment;
-+ if (pi->comment != NULL) {
-+ for (comment = pi->comment; *comment; comment++) {
-+ if (*comment == '\n') {
-+ pic2_write_char(pi, '\r');
-+ pic2_write_char(pi, '\n');
-+ } else if (*comment != '\r')
-+ pic2_write_char(pi, *comment);
-+ }
-+ pic2_write_char(pi, 0);
-+ }
-+ /* set the next block position */
-+ pi->next_pos = pic2_tell_file(pi);
-+ pi->header->size = pi->next_pos;
-+}
-+
-+static void pic2_write_header2(pi)
-+struct pic2_info *pi;
-+{
-+ pic2_seek_file(pi, pi->next_pos, SEEK_SET);
-+
-+ /* write terminate block */
-+ pic2_write_long(pi, 0);
-+ pic2_write_long(pi, 0);
-+
-+ /* set some header information */
-+ if (pi->header->x_max < pi->x_max)
-+ pi->header->x_max = pi->x_max;
-+ if (pi->header->y_max < pi->x_max)
-+ pi->header->y_max = pi->y_max;
-+
-+ pi->header->time = time(NULL);
-+ pic2_seek_file(pi, 0, SEEK_SET);
-+
-+ /* write header image */
-+ pic2_write_file(pi, pi->header->magic, 4);
-+ pic2_write_file(pi, pi->header->name, 18);
-+ pic2_write_file(pi, pi->header->subtitle, 8);
-+ pic2_write_file(pi, pi->header->crlf0, 2);
-+ pic2_write_file(pi, pi->header->title, 30);
-+ pic2_write_file(pi, pi->header->crlf1, 2);
-+ pic2_write_file(pi, pi->header->saver, 30);
-+ pic2_write_file(pi, pi->header->crlf2, 2);
-+ pic2_write_file(pi, pi->header->eof, 1);
-+ pic2_write_file(pi, pi->header->reserve0, 1);
-+ pic2_write_short(pi, pi->header->flag);
-+ pic2_write_short(pi, pi->header->no);
-+ pic2_write_long(pi, pi->header->time);
-+ pic2_write_long(pi, pi->header->size);
-+ pic2_write_short(pi, pi->header->depth);
-+ pic2_write_short(pi, pi->header->x_aspect);
-+ pic2_write_short(pi, pi->header->y_aspect);
-+ pic2_write_short(pi, pi->header->x_max);
-+ pic2_write_short(pi, pi->header->y_max);
-+ pic2_write_long(pi, pi->header->reserve1);
-+}
-+
-+static void pic2_write_block_header(pi)
-+struct pic2_info *pi;
-+{
-+ pic2_write_file(pi, pi->block->id, 4);
-+ pic2_write_long(pi, pi->block->size);
-+ pic2_write_short(pi, pi->block->flag);
-+ pic2_write_short(pi, pi->block->x_wid);
-+ pic2_write_short(pi, pi->block->y_wid);
-+ pic2_write_short(pi, pi->block->x_offset);
-+ pic2_write_short(pi, pi->block->y_offset);
-+ pic2_write_long(pi, pi->block->opaque);
-+ pic2_write_long(pi, pi->block->reserve);
-+}
-+
-+/*
-+ * These functions implement the arithmetic-format compressor.
-+ */
-+#define pic2_arith_write_one_bit(pi) (pi->bs.bits++)
-+
-+static void pic2_arith_write_zero_bit(pi)
-+struct pic2_info *pi;
-+{
-+ if (pi->bs.zero)
-+ pic2_write_bits(pi, 0, 1);
-+
-+ while (pi->bs.bits--)
-+ pic2_write_bits(pi, 1, 1);
-+
-+ pi->bs.bits = 0;
-+ pi->bs.zero = 1;
-+}
-+
-+static void pic2_arith_flush_bit_buf(pi)
-+struct pic2_info *pi;
-+{
-+ int i;
-+
-+ for (i = 0; i < 16; i++) {
-+ if (pi->cc & 0x8000)
-+ pic2_arith_write_one_bit(pi);
-+ else
-+ pic2_arith_write_zero_bit(pi);
-+ pi->cc <<= 1;
-+ }
-+ pic2_arith_write_zero_bit(pi);
-+ pic2_flush_bits(pi);
-+}
-+
-+static void pic2_arith_carry_bit(pi)
-+struct pic2_info *pi;
-+{
-+ pic2_write_bits(pi, 1, 1);
-+
-+ if (pi->bs.bits == 0) {
-+ pi->bs.zero = 0;
-+ } else {
-+ while (--pi->bs.bits)
-+ pic2_write_bits(pi, 0, 1);
-+ pi->bs.zero = 1;
-+ }
-+}
-+
-+static void pic2_arith_encode_bit(pi, n, c)
-+struct pic2_info *pi;
-+int n, c;
-+{
-+ int pp;
-+ long *c_sum, *c_0_sum;
-+
-+ c_sum = (long *) pi->mulu_tab;
-+ c_0_sum = c_sum + PIC2_ARITH_CONTEXT + 1;
-+
-+ if (pi->dd == 0) {
-+ c_sum[c]++;
-+ if (n == 0)
-+ c_0_sum[c]++;
-+ return;
-+ }
-+ pp = pi->mulu_tab[(pi->aa & 0x7f00) / 2 + c];
-+ if (n != 0) {
-+ pi->cc = pi->cc + pp;
-+ if (pi->cc > 0xffff) {
-+ pic2_arith_carry_bit(pi);
-+ pi->cc = pi->cc & 0xffff;
-+ }
-+ pi->aa = pi->aa - pp;
-+ while (pi->aa < 0x8000) {
-+ if (pi->cc & 0x8000)
-+ pic2_arith_write_one_bit(pi);
-+ else
-+ pic2_arith_write_zero_bit(pi);
-+ pi->cc = (pi->cc * 2) & 0xffff;
-+ pi->aa = pi->aa * 2;
-+ }
-+ } else {
-+ pi->aa = pp;
-+
-+ while (pi->aa < 0x8000) {
-+ if (pi->cc & 0x8000)
-+ pic2_arith_write_one_bit(pi);
-+ else
-+ pic2_arith_write_zero_bit(pi);
-+ pi->cc = (pi->cc * 2) & 0xffff;
-+ pi->aa = pi->aa * 2;
-+ }
-+ }
-+}
-+
-+static void pic2_arith_encode_nbyte(pi, n, c, max)
-+struct pic2_info *pi;
-+int n, c, max;
-+{
-+ short i;
-+
-+ for (i = 0; i < n; i++) {
-+ pic2_arith_encode_bit(pi, 0, c + i);
-+ }
-+ if (n < max)
-+ pic2_arith_encode_bit(pi, 1, c + n);
-+}
-+
-+static void pic2_arith_encode_nn(pi, n, c)
-+struct pic2_info *pi;
-+int n, c;
-+{
-+ if (n < 1) {
-+ pic2_arith_encode_bit(pi, 1, c);
-+ } else if (n < 1 + 2) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 1, c + 1);
-+ n -= 1;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ } else if (n < 1 + 2 + 4) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 1, c + 2);
-+ n -= 1 + 2;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ pic2_arith_encode_bit(pi, n & 2, c + 9);
-+ } else if (n < 1 + 2 + 4 + 8) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 0, c + 2);
-+ pic2_arith_encode_bit(pi, 1, c + 3);
-+ n -= 1 + 2 + 4;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ pic2_arith_encode_bit(pi, n & 2, c + 9);
-+ pic2_arith_encode_bit(pi, n & 4, c + 10);
-+ } else if (n < 1 + 2 + 4 + 8 + 16) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 0, c + 2);
-+ pic2_arith_encode_bit(pi, 0, c + 3);
-+ pic2_arith_encode_bit(pi, 1, c + 4);
-+ n -= 1 + 2 + 4 + 8;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ pic2_arith_encode_bit(pi, n & 2, c + 9);
-+ pic2_arith_encode_bit(pi, n & 4, c + 10);
-+ pic2_arith_encode_bit(pi, n & 8, c + 11);
-+ } else if (n < 1 + 2 + 4 + 8 + 16 + 32) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 0, c + 2);
-+ pic2_arith_encode_bit(pi, 0, c + 3);
-+ pic2_arith_encode_bit(pi, 0, c + 4);
-+ pic2_arith_encode_bit(pi, 1, c + 5);
-+ n -= 1 + 2 + 4 + 8 + 16;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ pic2_arith_encode_bit(pi, n & 2, c + 9);
-+ pic2_arith_encode_bit(pi, n & 4, c + 10);
-+ pic2_arith_encode_bit(pi, n & 8, c + 11);
-+ pic2_arith_encode_bit(pi, n & 16, c + 12);
-+ } else if (n < 1 + 2 + 4 + 8 + 16 + 32 + 64) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 0, c + 2);
-+ pic2_arith_encode_bit(pi, 0, c + 3);
-+ pic2_arith_encode_bit(pi, 0, c + 4);
-+ pic2_arith_encode_bit(pi, 0, c + 5);
-+ pic2_arith_encode_bit(pi, 1, c + 6);
-+ n -= 1 + 2 + 4 + 8 + 16 + 32;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ pic2_arith_encode_bit(pi, n & 2, c + 9);
-+ pic2_arith_encode_bit(pi, n & 4, c + 10);
-+ pic2_arith_encode_bit(pi, n & 8, c + 11);
-+ pic2_arith_encode_bit(pi, n & 16, c + 12);
-+ pic2_arith_encode_bit(pi, n & 32, c + 13);
-+ } else if (n < 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128) {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 0, c + 2);
-+ pic2_arith_encode_bit(pi, 0, c + 3);
-+ pic2_arith_encode_bit(pi, 0, c + 4);
-+ pic2_arith_encode_bit(pi, 0, c + 5);
-+ pic2_arith_encode_bit(pi, 0, c + 6);
-+ pic2_arith_encode_bit(pi, 1, c + 7);
-+ n -= 1 + 2 + 4 + 8 + 16 + 32 + 64;
-+ pic2_arith_encode_bit(pi, n & 1, c + 8);
-+ pic2_arith_encode_bit(pi, n & 2, c + 9);
-+ pic2_arith_encode_bit(pi, n & 4, c + 10);
-+ pic2_arith_encode_bit(pi, n & 8, c + 11);
-+ pic2_arith_encode_bit(pi, n & 16, c + 12);
-+ pic2_arith_encode_bit(pi, n & 32, c + 13);
-+ pic2_arith_encode_bit(pi, n & 64, c + 14);
-+ } else {
-+ pic2_arith_encode_bit(pi, 0, c);
-+ pic2_arith_encode_bit(pi, 0, c + 1);
-+ pic2_arith_encode_bit(pi, 0, c + 2);
-+ pic2_arith_encode_bit(pi, 0, c + 3);
-+ pic2_arith_encode_bit(pi, 0, c + 4);
-+ pic2_arith_encode_bit(pi, 0, c + 5);
-+ pic2_arith_encode_bit(pi, 0, c + 6);
-+ pic2_arith_encode_bit(pi, 0, c + 7);
-+ }
-+}
-+
-+static void pic2_arith_press_chain(pi, x)
-+struct pic2_info *pi;
-+int x;
-+{
-+ int b, d;
-+ pixel c;
-+
-+ b = -(pi->flag_now[x]);
-+ c = pi->vram_now[x];
-+ d = 0;
-+
-+ if (b < 0)
-+ b = 0;
-+
-+ if (pi->flag_next[x] == 1 && pi->vram_next[x] == c) {
-+ d = 1;
-+ pi->flag_next[x] = -1;
-+ } else if (pi->flag_next[x - 1] == 1 && pi->vram_next[x - 1] == c) {
-+ d = 2;
-+ pi->flag_next[x - 1] = -2;
-+ } else if (pi->flag_next[x + 1] == 1 && pi->vram_next[x + 1] == c) {
-+ d = 3;
-+ pi->flag_next[x + 1] = -3;
-+ } else if (pi->flag_next[x - 2] == 1 && pi->vram_next[x - 2] == c) {
-+ d = 4;
-+ pi->flag_next[x - 2] = -4;
-+ } else if (pi->flag_next[x + 2] == 1 && pi->vram_next[x + 2] == c) {
-+ if ((pi->flag_now[x + 2] != 0 && pi->vram_now[x + 2] == c)
-+ || (pi->flag_now[x + 1] != 0 && pi->vram_now[x + 1] == c)
-+ || (pi->flag_now[x + 3] != 0 && pi->vram_now[x + 3] == c)) {
-+ pic2_arith_encode_nbyte(pi, 0, 80 + 6 * b, 5);
-+ return;
-+ }
-+ d = 5;
-+ pi->flag_next[x + 2] = -5;
-+ }
-+ pic2_arith_encode_nbyte(pi, d, 80 + 6 * b, 5);
-+}
-+
-+static void pic2_arith_put_number(pi, xn, xa, xb)
-+struct pic2_info *pi;
-+int xn, xa, xb;
-+{
-+ short n;
-+ byte maxcol;
-+
-+ maxcol = 0xff >> (8 - pi->header->depth / 3);
-+
-+ if (xa > ((int) maxcol >> 1)) {
-+ if (xb > xa)
-+ n = (xb - xa) * 2 - 1;
-+ else if (xa - ((int) maxcol - xa) > xb)
-+ n = maxcol - xb;
-+ else
-+ n = (xa - xb) * 2;
-+ } else {
-+ if (xb <= xa)
-+ n = (xa - xb) * 2;
-+ else if (2 * xa < xb)
-+ n = xb;
-+ else
-+ n = (xb - xa) * 2 - 1;
-+ }
-+ pic2_arith_encode_nn(pi, n, xn);
-+}
-+
-+static void pic2_arith_write_color(pi, x)
-+struct pic2_info *pi;
-+int x;
-+{
-+ pixel c1, c2, cc;
-+ short g0, r0, b0, r, g, b;
-+ int i, j;
-+ unsigned short k;
-+ pixel *p, *pp;
-+ short colbits;
-+ pixel rmask, gmask, bmask;
-+ byte maxcol;
-+
-+ colbits = pi->header->depth / 3;
-+ rmask = (0xff >> (8 - colbits)) << (colbits * 2);
-+ gmask = (0xff >> (8 - colbits)) << colbits;
-+ bmask = (0xff >> (8 - colbits));
-+ maxcol = (byte) bmask;
-+
-+ cc = pi->vram_now[x];
-+ c1 = pi->vram_prev[x];
-+ k = ((c1 >> ((colbits - 3) * 3)) & 0x1c0)
-+ | ((c1 >> ((colbits - 3) * 2)) & 0x038)
-+ | ((c1 >> (colbits - 3) ) & 0x007);
-+ if (colbits == 5)
-+ k = pic2_exchange_rg(k, 3);
-+
-+ p = pi->cache[k];
-+ for (i = 0; i < (PIC2_ARITH_CACHE - 1); i++) {
-+ if (cc == *p++)
-+ break;
-+ }
-+ if (i == (PIC2_ARITH_CACHE - 1)) {
-+ pp = p - 1;
-+ for (j = i; j > 0; j--) {
-+ *--p = *--pp;
-+ }
-+ pi->cache[k][0] = cc;
-+ pic2_arith_encode_bit(pi, 1, pi->cache_hit_c);
-+ pi->cache_hit_c = 16;
-+
-+ c2 = pi->vram_now[x - 1];
-+ r = ((c1 & rmask) + (c2 & rmask)) >> (colbits * 2 + 1);
-+ g = ((c1 & gmask) + (c2 & gmask)) >> (colbits + 1);
-+ b = ((c1 & bmask) + (c2 & bmask)) >> ( 1);
-+
-+ r0 = (cc >> (colbits * 2)) & maxcol;
-+ g0 = (cc >> colbits ) & maxcol;
-+ b0 = cc & maxcol;
-+
-+ r = r + g0 - g;
-+ if (r < 0)
-+ r = 0;
-+ else if (r > (short) maxcol)
-+ r = maxcol;
-+
-+ b = b + g0 - g;
-+ if (b < 0)
-+ b = 0;
-+ else if (b > (short) maxcol)
-+ b = maxcol;
-+
-+ pic2_arith_put_number(pi, 32, g, g0);
-+ pic2_arith_put_number(pi, 48, r, r0);
-+ pic2_arith_put_number(pi, 64, b, b0);
-+ } else {
-+ *--p = pi->cache[k][i / 2];
-+ pi->cache[k][i / 2] = pi->cache[k][0];
-+ pi->cache[k][0] = cc;
-+
-+ pic2_arith_encode_bit(pi, 0, pi->cache_hit_c);
-+ pi->cache_hit_c = 15;
-+ pic2_arith_encode_nn(pi, i, 17);
-+ }
-+}
-+
-+static void pic2_arith_press_line2(pi)
-+struct pic2_info *pi;
-+{
-+ int x, xw, ymax;
-+ pixel cc;
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid -1;
-+ cc = pi->vram_now[xw - 1]; /* last color */
-+ pi->vram_next[-1] = cc;
-+
-+ /* mark change point */
-+ for (x = 0; x < xw; x++)
-+ if (cc != pi->vram_next[x]) {
-+ pi->flag_next[x] = 1;
-+ cc = pi->vram_next[x];
-+ } else
-+ pi->flag_next[x] = 0;
-+
-+ for (x = 0; x < xw; x++) {
-+ if (pi->flag_now[x] == 1) { /* change point */
-+ pi->flag2_now [x + 1]++;
-+ pi->flag2_now [x + 2]++;
-+ pi->flag2_next [x - 1]++;
-+ pi->flag2_next [x ]++;
-+ pi->flag2_next [x + 1]++;
-+ pi->flag2_next2[x - 1]++;
-+ pi->flag2_next2[x ]++;
-+ pi->flag2_next2[x + 1]++;
-+
-+ /* write change point */
-+ pic2_arith_encode_bit(pi, 1, pi->flag2_now[x]);
-+
-+ /* write color */
-+ pic2_arith_write_color(pi, x);
-+
-+ /* if not last line, write chain */
-+ if (pi->ynow - 1 < ymax)
-+ pic2_arith_press_chain(pi, x);
-+ } else if (pi->flag_now[x] == 0) /* not on chain */
-+ /* write change point */
-+ pic2_arith_encode_bit(pi, 0, pi->flag2_now[x]);
-+ else /* on chain */
-+ /* if not on last line, write next chain */
-+ if (pi->ynow - 1 < ymax)
-+ pic2_arith_press_chain(pi, x);
-+ }
-+}
-+
-+static int pic2_arith_press_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int i, xw, ymax;
-+ long *c_sum, *c_0_sum;
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid -1;
-+ c_sum = (long *) pi->mulu_tab;
-+ c_0_sum = c_sum + PIC2_ARITH_CONTEXT +1;
-+
-+ pic2_handle_para(pi, 0);
-+
-+ xvbzero((char *) pi->flag2_next2 - 4,
-+ (8 + xw) * sizeof(pi->flag2_next2[0]));
-+
-+ if (pi->ynow == 0) { /* first line */
-+ int x;
-+ pixel cc = 0;
-+
-+ if (pi->dd != 0) { /* compress pass */
-+ unsigned short c_tab[PIC2_ARITH_CONTEXT];
-+
-+ for (i = 0; i < PIC2_ARITH_CONTEXT; i++) {
-+ unsigned long a, b;
-+ a = c_0_sum[i];
-+ b = c_sum[i];
-+ while (a > 32767) {
-+ a /= 2;
-+ b /= 2;
-+ }
-+ if (a == b)
-+ c_tab[i] = 0xffff; /* b==0 here, too */
-+ else
-+ c_tab[i] = (65536 * a) / b; /* a < b, so less 65536 */
-+ }
-+ for (i = 0; i < 16384; i++) {
-+ pi->mulu_tab[i] = (long) (i / 128 + 128) * (int) c_tab[i & 127] / 256;
-+ if (pi->mulu_tab[i] == 0)
-+ pi->mulu_tab[i] = 1; /* 0 is wrong */
-+ }
-+ for (i = 0; i < PIC2_ARITH_CONTEXT; i++)
-+ pic2_write_short(pi, c_tab[i]);
-+
-+ xvbzero((char *) pi->vram_now, xw * sizeof(pi->vram_now[0]));
-+ } else { /* statistical pass */
-+ xvbzero((char *) c_0_sum, PIC2_ARITH_CONTEXT * sizeof(c_0_sum[0]));
-+ xvbzero((char *) c_sum, PIC2_ARITH_CONTEXT * sizeof(c_sum[0]));
-+ }
-+
-+ /* initialize flags */
-+ xvbzero((char *) pi->cache, 8 * 8 * 8 * sizeof(pi->cache[0]));
-+ xvbzero((char *) pi->cache_pos, 8 * 8 * 8 * sizeof(pi->cache_pos[0]));
-+
-+ xvbzero((char *) pi->flag2_next - 4,
-+ (8 + xw) * sizeof(pi->flag2_next[0]));
-+ xvbzero((char *) pi->flag2_next2 - 4,
-+ (8 + xw) * sizeof(pi->flag2_next2[0]));
-+
-+ pi->vram_next[-1] = cc;
-+ for (x = 0; x < xw; x++)
-+ if (cc != pi->vram_next[x]) {
-+ pi->flag_next[x] = 1;
-+ cc = pi->vram_next[x];
-+ } else
-+ pi->flag_next[x] = 0;
-+
-+ pi->aa = 0xffff;
-+ cc = 0;
-+ pi->cache_hit_c = 16;
-+ } else /* after second line */
-+ pic2_arith_press_line2(pi);
-+
-+ if (pi->ynow == ymax) {
-+ pi->ynow++;
-+ pic2_handle_para(pi, 1);
-+ pic2_handle_para(pi, 0);
-+ pic2_arith_press_line2(pi);
-+ }
-+ /* line buffer for next data */
-+ if (line != NULL)
-+ *line = pi->vram_prev;
-+
-+ pi->ynow++;
-+
-+ if (pi->ynow - 1 < ymax) {
-+ pic2_handle_para(pi, 1);
-+ return (pi->ynow);
-+ } else { /* end */
-+ if (pi->dd == 0) { /* statistical pass */
-+ pi->dd = 1;
-+ pi->ynow = 0;
-+ pic2_handle_para(pi, 1);
-+ return (0);
-+ } else {
-+ pic2_handle_para(pi, 1);
-+ pic2_arith_flush_bit_buf(pi);
-+ return (-2); /* end */
-+ }
-+ }
-+}
-+
-+static int pic2_arith_saver_init(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ pi->ynow = 0;
-+
-+ /* check the color depth */
-+ if (pi->header->depth % 3)
-+ pic2_error(pi, PIC2_DEPTH);
-+
-+ /* set next line function */
-+ pi->next_line = pic2_arith_press_line;
-+
-+ if (line != NULL)
-+ *line = pi->vram_next + 4;
-+
-+ pic2_seek_file(pi, pi->next_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+
-+ /* clear bit field marker */
-+ pi->bs.rest = 0;
-+ pi->bs.cur = 0;
-+ pi->bs.zero = 0;
-+ pi->bs.bits = 0;
-+
-+ return (0);
-+}
-+
-+/*
-+ * These functions are fast pic2 format compressor.
-+ */
-+static void pic2_fast_write_length(pi, n)
-+struct pic2_info *pi;
-+int n;
-+{
-+ int a, b;
-+ static const unsigned short len_data[8][2] = {
-+ {1, 0},
-+ {1, 0},
-+ {3, 4},
-+ {3, 5},
-+ {5, 24},
-+ {5, 25},
-+ {5, 26},
-+ {5, 27},
-+ };
-+
-+ n++;
-+ if (n < 8)
-+ pic2_write_bits(pi, len_data[n][1], len_data[n][0]);
-+ else {
-+ a = 0;
-+ b = 2;
-+ while (n > b - 1) {
-+ a = a + 1;
-+ b = b * 2;
-+ }
-+ pic2_write_bits(pi, 0xfffffffe, a + 1);
-+ if (a > 0)
-+ pic2_write_bits(pi, n - b / 2, a);
-+ }
-+}
-+
-+static void pic2_fast_press_chain(pi, x)
-+struct pic2_info *pi;
-+int x;
-+{
-+ int ymax;
-+ pixel cc;
-+
-+ ymax = pi->block->y_wid -1;
-+ cc = pi->vram_now[x];
-+
-+ if (pi->ynow - 1 == ymax) {
-+ pic2_write_bits(pi, 0, 1);
-+ return;
-+ }
-+ if (pi->flag_next[x] == 1 && pi->vram_next[x] == cc) {
-+ pi->flag_next[x] = -1;
-+ pic2_write_bits(pi, 3, 2);
-+ } else if (pi->flag_next[x - 1] == 1 && pi->vram_next[x - 1] == cc) {
-+ pi->flag_next[x - 1] = -1;
-+ pic2_write_bits(pi, 11, 4);
-+ } else if (pi->flag_next[x + 1] == 1 && pi->vram_next[x + 1] == cc) {
-+ pi->flag_next[x + 1] = -1;
-+ pic2_write_bits(pi, 9, 4);
-+ } else if (pi->flag_next[x - 2] == 1 && pi->vram_next[x - 2] == cc) {
-+ pi->flag_next[x - 2] = -1;
-+ pic2_write_bits(pi, 10, 4);
-+ } else if ((pi->flag_next[x + 2] == 1 && pi->vram_next[x + 2] == cc)
-+ && !(pi->flag_now[x + 2] != 0 && pi->vram_now[x + 2] == cc)) {
-+ pi->flag_next[x + 2] = -1;
-+ pic2_write_bits(pi, 8, 4);
-+ } else
-+ pic2_write_bits(pi, 0, 1);
-+}
-+
-+static void pic2_fast_press_chain2(pi, x)
-+struct pic2_info *pi;
-+int x;
-+{
-+ int ymax;
-+ pixel cc;
-+ char *chain_buff;
-+
-+ ymax = pi->block->y_wid -1;
-+ chain_buff = (char *) pi->mulu_tab;
-+ cc = pi->vram_now[x];
-+
-+ if (pi->ynow - 1 == ymax) {
-+ chain_buff[pi->cc++] = 0;
-+ return;
-+ }
-+ if (pi->flag_next[x] == 1 && pi->vram_next[x] == cc) {
-+ pi->flag_next[x] = -1;
-+ chain_buff[pi->cc++] = 1;
-+ } else if (pi->flag_next[x - 1] == 1 && pi->vram_next[x - 1] == cc) {
-+ pi->flag_next[x - 1] = -1;
-+ chain_buff[pi->cc++] = 2;
-+ } else if (pi->flag_next[x + 1] == 1 && pi->vram_next[x + 1] == cc) {
-+ pi->flag_next[x + 1] = -1;
-+ chain_buff[pi->cc++] = 3;
-+ } else if (pi->flag_next[x - 2] == 1 && pi->vram_next[x - 2] == cc) {
-+ pi->flag_next[x - 2] = -1;
-+ chain_buff[pi->cc++] = 4;
-+ } else if ((pi->flag_next[x + 2] == 1 && pi->vram_next[x + 2] == cc)
-+ && !(pi->flag_now[x + 2] != 0 && pi->vram_now[x + 2] == cc)) {
-+ pi->flag_next[x + 2] = -1;
-+ chain_buff[pi->cc++] = 5;
-+ } else
-+ chain_buff[pi->cc++] = 0;
-+}
-+
-+static void pic2_fast_flush_chain(pi)
-+struct pic2_info *pi;
-+{
-+ int i;
-+ char *chain_buf;
-+
-+ chain_buf = (char *) pi->mulu_tab;
-+ for (i = 0; i < pi->cc; i++){
-+ switch (chain_buf[i]) {
-+ case 0:
-+ pic2_write_bits(pi, 0, 1);
-+ break;
-+ case 1:
-+ pic2_write_bits(pi, 3, 2);
-+ break;
-+ case 2:
-+ pic2_write_bits(pi, 11, 4);
-+ break;
-+ case 3:
-+ pic2_write_bits(pi, 9, 4);
-+ break;
-+ case 4:
-+ pic2_write_bits(pi, 10, 4);
-+ break;
-+ case 5:
-+ pic2_write_bits(pi, 8, 4);
-+ break;
-+ }
-+ }
-+ pi->cc = 0;
-+}
-+
-+static void pic2_fast_write_color(pi, x)
-+struct pic2_info *pi;
-+int x;
-+{
-+ pixel cc, bc;
-+ unsigned short j, k, m;
-+ short depth, colbits;
-+ pixel (*cache)[PIC2_FAST_CACHE];
-+
-+ depth = pi->header->depth;
-+ colbits = depth / 3;
-+ cache = (pixel (*)[PIC2_FAST_CACHE]) pi->cache;
-+
-+ bc = pi->vram_now[x - 1];
-+ bc = pic2_exchange_rg(bc, colbits);
-+ k = pic2_shift_bits(bc, 8 - depth);
-+ cc = pi->vram_now[x];
-+ m = pi->cache_pos[k];
-+
-+ for (j = 0; j < PIC2_FAST_CACHE; j++)
-+ if (cache[k][(m + j) & (PIC2_FAST_CACHE - 1)] == cc)
-+ break;
-+
-+ if (j == PIC2_FAST_CACHE) {
-+ m = (m - 1) & (PIC2_FAST_CACHE - 1);
-+ pi->cache_pos[k] = m;
-+ cache[k][m] = cc;
-+
-+ cc = pic2_exchange_rg(cc, colbits);
-+ pic2_write_bits(pi, 0, 1);
-+ pic2_write_bits(pi, cc, depth);
-+ } else {
-+ pic2_write_bits(pi, 1, 1);
-+ pic2_write_bits(pi, j, 6);
-+ }
-+}
-+
-+static void pic2_fast_press_line2(pi)
-+struct pic2_info *pi;
-+{
-+ int x, xw;
-+ pixel cc;
-+
-+ xw = pi->block->x_wid;
-+ cc = pi->vram_now[xw - 1]; /* last color */
-+ pi->vram_next[-1] = cc;
-+
-+ /* mark change point */
-+ for (x = 0; x < xw; x++)
-+ if (cc != pi->vram_next[x]) {
-+ pi->flag_next[x] = 1;
-+ cc = pi->vram_next[x];
-+ } else
-+ pi->flag_next[x] = 0;
-+
-+ for (x = 0; x < xw; x++)
-+ if (pi->flag_now[x] == 1) { /* change point */
-+ if (pi->aa >= 1023)
-+ pi->aa++;
-+ pic2_fast_write_length(pi, pi->aa);
-+ pic2_fast_flush_chain(pi);
-+ pi->aa = 0;
-+ pic2_fast_write_color(pi, x);
-+ pic2_fast_press_chain(pi, x);
-+ } else if (pi->flag_now[x] == 0) {
-+ pi->aa++;
-+ } else {
-+ pic2_fast_press_chain2(pi, x);
-+ if (pi->cc == 1023) {
-+ pic2_fast_write_length(pi, 1023);
-+ pic2_fast_flush_chain(pi);
-+ pi->aa = 0;
-+ }
-+ }
-+}
-+
-+static int pic2_fast_press_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int xw, ymax;
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid -1;
-+
-+ pic2_handle_para(pi, 0);
-+
-+ if (pi->ynow == 0) { /* first line */
-+ int x;
-+ pixel cc = 0;
-+
-+ /* initialize flags */
-+ xvbzero((char *) pi->cache, 256 * sizeof(pi->cache[0]));
-+ xvbzero((char *) pi->cache_pos,
-+ PIC2_FAST_CACHE * sizeof(pi->cache_pos[0]));
-+
-+ /* mark change point */
-+ pi->vram_next[-1] = cc;
-+ for (x = 0; x < xw; x++)
-+ if (cc != pi->vram_next[x]) {
-+ pi->flag_next[x] = 1;
-+ cc = pi->vram_next[x];
-+ } else
-+ pi->flag_next[x] = 0;
-+
-+ pi->cc = 0;
-+ pi->aa = 0;
-+ } else /* after second line */
-+ pic2_fast_press_line2(pi);
-+
-+ if (pi->ynow == ymax) {
-+ pi->ynow++;
-+ pic2_handle_para(pi, 1);
-+ pic2_handle_para(pi, 0);
-+ pic2_fast_press_line2(pi);
-+ }
-+ /* line buffer for next data */
-+ if (line != NULL)
-+ *line = pi->vram_prev;
-+
-+ pi->ynow++;
-+
-+ if (pi->ynow - 1 < ymax) {
-+ pic2_handle_para(pi, 1);
-+ return (pi->ynow);
-+ } else { /* end */
-+ pic2_handle_para(pi, 1);
-+ if (pi->aa >= 1023)
-+ pi->aa++;
-+ pic2_fast_write_length(pi, pi->aa);
-+ pic2_fast_flush_chain(pi);
-+ return (-2); /* end */
-+ }
-+}
-+
-+static int pic2_fast_saver_init(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ pi->ynow = 0;
-+
-+ /* check the color depth */
-+ if (pi->header->depth % 3)
-+ pic2_error(pi, PIC2_DEPTH);
-+
-+ /* set next line function */
-+ pi->next_line = pic2_fast_press_line;
-+ if (line != NULL)
-+ *line = pi->vram_next + 4;
-+
-+ pic2_seek_file(pi, pi->next_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+
-+ /* clear bit field marker */
-+ pi->bs.rest = 0;
-+ pi->bs.cur = 0;
-+
-+ return (0);
-+}
-+
-+/*
-+ * These functions are beta pic2 format compressor.
-+ */
-+static int pic2_beta_press_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int i, xw, ymax;
-+ byte *p;
-+ pixel *pc;
-+ short depth, pixbyte, colbits;
-+
-+ depth = pi->header->depth;
-+ pixbyte = depth / 8 + ((depth % 8) > 0);
-+ colbits = depth / 3;
-+
-+ xw = pi->block->x_wid;
-+ ymax = pi->block->y_wid - 1;
-+
-+ pc = pi->vram_now;
-+ p = (byte *) pi->vram_prev;
-+ if (pixbyte == 3) {
-+ for (i = 0; i < xw; i++, pc++) {
-+ *p++ = *pc >> 16;
-+ *p++ = *pc >> 8;
-+ *p++ = *pc;
-+ }
-+ pic2_write_file(pi, pi->vram_prev, (size_t) (xw * 3));
-+ } else if (pixbyte == 2) {
-+ if (strncmp(pi->block->id, "P2BM", 4) == 0)
-+ for (i = 0; i < xw; i++, pc++) {
-+ if (colbits == 5) {
-+ *pc = pic2_exchange_rg(*pc, colbits);
-+ *pc <<= 1;
-+ }
-+ *p++ = *pc >> 8;
-+ *p++ = *pc;
-+ }
-+ else
-+ for (i = 0; i < xw; i++, pc++) {
-+ if (colbits == 5) {
-+ *pc = pic2_exchange_rg(*pc, colbits);
-+ *pc <<= 1;
-+ }
-+ *p++ = *pc;
-+ *p++ = *pc >> 8;
-+ }
-+ pic2_write_file(pi, pi->vram_prev, (size_t) (xw * 2));
-+ } else {
-+ for (i = 0; i < xw; i++, pc++)
-+ *p++ = *pc;
-+ pic2_write_file(pi, pi->vram_prev, (size_t) xw);
-+ }
-+ if (line != NULL)
-+ *line = pi->vram_now;
-+
-+ pi->ynow++;
-+ if (pi->ynow > ymax)
-+ return (-2);
-+ return (pi->ynow);
-+}
-+
-+static int pic2_beta_saver_init(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ pi->ynow = 0;
-+
-+ *line = pi->vram_now;
-+ pi->next_line = pic2_beta_press_line;
-+ pic2_seek_file(pi, pi->next_pos + PIC2_BLOCK_HEADER_SIZE, SEEK_SET);
-+ return (0);
-+}
-+
-+/*
-+ * This function saves compressed data.
-+ */
-+static void pic2_write_data(pi, data, ptype, x_offset, y_offset, w, h,
-+ rmap, gmap, bmap, type, depth)
-+struct pic2_info *pi;
-+byte *data;
-+int ptype;
-+int x_offset, y_offset;
-+int w, h;
-+byte *rmap, *gmap, *bmap;
-+int type, depth;
-+{
-+ int i, line;
-+ pixel *linep;
-+ short colbits;
-+
-+ colbits = pi->header->depth / 3;
-+
-+ line = pic2_save_block(pi, &linep, x_offset, y_offset, w, h,
-+ form_tab[type].id, 0xffffffff);
-+ while (line >= 0) {
-+ byte r, g, b;
-+ int pic_idx;
-+
-+ pic_idx = line * w * ((ptype == PIC24) ? 3 : 1);
-+
-+ for (i = 0; i < w; i++) {
-+ if (ptype != PIC24) {
-+ r = rmap[data[pic_idx]];
-+ g = gmap[data[pic_idx]];
-+ b = bmap[data[pic_idx]];
-+ pic_idx++;
-+ } else {
-+ r = data[pic_idx++];
-+ g = data[pic_idx++];
-+ b = data[pic_idx++];
-+ }
-+ if (pi->writing_grey)
-+ r = g = b = MONO(r, g, b);
-+
-+ r = pic2_convert_color_bits(r, 8, colbits);
-+ g = pic2_convert_color_bits(g, 8, colbits);
-+ b = pic2_convert_color_bits(b, 8, colbits);
-+
-+ linep[i] = ((pixel) r << (colbits * 2))
-+ | ((pixel) g << colbits )
-+ | ((pixel) b );
-+ }
-+ line = pic2_next_line(pi, &linep);
-+ WaitCursor();
-+ }
-+}
-+
-+/*
-+ * This function compresses/extracts one line buffer.
-+ */
-+static int pic2_next_line(pi, line)
-+struct pic2_info *pi;
-+pixel **line;
-+{
-+ int res;
-+
-+ res = pi->next_line(pi, line);
-+ if (res == -2) {
-+ if (pi->mode == PIC2_WRITE_MODE) {
-+ long new_pos;
-+
-+ new_pos = pic2_tell_file(pi);
-+ pi->block->size = new_pos - pi->next_pos;
-+ pic2_seek_file(pi, pi->next_pos, SEEK_SET);
-+ pic2_write_block_header(pi);
-+ pi->next_pos = new_pos;
-+ if (DEBUG)
-+ pic2_show_pic2_info(pi);
-+ }
-+ pic2_free_buffer(pi);
-+ }
-+ return (res);
-+}
-+
-+/*
-+ * These functions find the pic2 image block.
-+ * pic2_next_block:
-+ * moves the file pointer to the next image block.
-+ * pic2_find_block:
-+ * finds the first image block and moves the file pointer there.
-+ */
-+static int pic2_next_block(pi)
-+struct pic2_info *pi;
-+{
-+ int i;
-+
-+ if (pi->mode != PIC2_READ_MODE)
-+ return (-1);
-+
-+ /* go to block for read */
-+ pic2_seek_file(pi, pi->next_pos, SEEK_SET);
-+
-+ /* read the head of block header */
-+ pic2_read_block_header1(pi);
-+
-+ /* end block ? */
-+ if (pi->block->id[0] == 0)
-+ return (0);
-+
-+ /* set current block */
-+ pi->block_pos = pi->next_pos;
-+
-+ /* set next block */
-+ pi->next_pos += pi->block->size;
-+
-+ /* check block id */
-+ for (i = 0; i < n_form_tab; i++) {
-+ if (xvbcmp(pi->block->id, form_tab[i].id, (size_t) 4) == 0)
-+ break;
-+ }
-+ if (i == n_form_tab)
-+ return (2);
-+
-+ /* read the rest of block header */
-+ pic2_read_block_header2(pi);
-+
-+ if (pi->block->x_offset + pi->block->x_wid > pi->x_max)
-+ pi->x_max = pi->block->x_offset + pi->block->x_wid;
-+
-+ if (pi->block->y_offset + pi->block->y_wid > pi->y_max)
-+ pi->y_max = pi->block->y_offset + pi->block->y_wid;
-+
-+ if (DEBUG)
-+ pic2_show_pic2_info(pi);
-+ return (1);
-+}
-+
-+static int pic2_find_block(pi)
-+struct pic2_info *pi;
-+{
-+ if (pi->mode != PIC2_READ_MODE)
-+ return (-1);
-+
-+ pi->next_pos = pi->header->size;
-+ return (pic2_next_block(pi));
-+}
-+
-+/*
-+ * These functions load/save the pic2 image block.
-+ * pic2_load_block:
-+ * initializes loader information with current block information.
-+ * pic2_save_block:
-+ * initializes saver information.
-+ */
-+static int pic2_load_block(pi)
-+struct pic2_info *pi;
-+{
-+ int i;
-+
-+ for (i = 0; i < n_form_tab; i++) {
-+ if (xvbcmp(pi->block->id, form_tab[i].id, (size_t) 4) == 0)
-+ break;
-+ }
-+ if (i == n_form_tab)
-+ return (2);
-+
-+ pic2_alloc_buffer(pi);
-+ return (form_tab[i].loader_init(pi));
-+}
-+
-+static int pic2_save_block(pi, line, x, y, xw, yw, id, opaque)
-+struct pic2_info *pi;
-+pixel **line;
-+int x, y, xw, yw;
-+char *id;
-+pixel opaque;
-+{
-+ int i;
-+
-+ for (i = 0; i < n_form_tab; i++) {
-+ if (xvbcmp(id, form_tab[i].id, (size_t) 4) == 0)
-+ break;
-+ }
-+ if (i == n_form_tab)
-+ return (2);
-+
-+ strncpy(pi->block->id, id, 4);
-+ pi->block->x_wid = xw;
-+ pi->block->y_wid = yw;
-+ pi->block->x_offset = x;
-+ pi->block->y_offset = y;
-+ pi->block->reserve = 0;
-+
-+ if (x < 0)
-+ x = 0;
-+ if (y < 0)
-+ y = 0;
-+ if (x + xw > pi->x_max)
-+ pi->x_max = x + xw;
-+ if (y + yw > pi->y_max)
-+ pi->y_max = y + yw;
-+
-+ if (opaque != 0xffffffff) {
-+ pi->block->flag = 1;
-+ pi->block->opaque = opaque;
-+ } else {
-+ pi->block->flag = 0;
-+ pi->block->opaque = 0;
-+ }
-+ pic2_alloc_buffer(pi);
-+
-+ return (form_tab[i].saver_init(pi, line));
-+}
-+
-+/*
-+ * These functions set/get palettes.
-+ * pic2_read_palette:
-+ * copy the palettes from pic2_info to PICINFO.
-+ * pic2_write_palette:
-+ * copy the palettes from PICINFO to pic2_info.
-+ */
-+#ifndef PIC2_IGNORE_UNUSED_FUNCTIONS
-+static void pic2_read_palette(pi, r, g, b)
-+struct pic2_info *pi;
-+byte *r, *g, *b;
-+{
-+ int i;
-+
-+ if (pi->n_pal > 256)
-+ pi->n_pal = 256;
-+
-+ if (pi->pal_bits > 8)
-+ pi->pal_bits = 8;
-+
-+ for (i = 0; i < pi->n_pal; i++) {
-+ *r++ =pic2_convert_color_bits(pi->pal[i][0] >> (8 - pi->pal_bits),
-+ pi->pal_bits, 8);
-+ *g++ =pic2_convert_color_bits(pi->pal[i][1] >> (8 - pi->pal_bits),
-+ pi->pal_bits, 8);
-+ *b++ =pic2_convert_color_bits(pi->pal[i][2] >> (8 - pi->pal_bits),
-+ pi->pal_bits, 8);
-+ }
-+}
-+
-+static void pic2_write_palette(pi, n_pal, pal_bits, r, g, b)
-+struct pic2_info *pi;
-+int n_pal, pal_bits;
-+byte *r, *g, *b;
-+{
-+ int i;
-+
-+ if (n_pal > 256)
-+ pi->n_pal = 256;
-+ else
-+ pi->n_pal = n_pal;
-+
-+ if (pal_bits > 8)
-+ pi->pal_bits = 8;
-+ else
-+ pi->pal_bits = pal_bits;
-+
-+ for (i = 0; i < n_pal; i++) {
-+ pi->pal[i][0] = pic2_convert_color_bits(*r++, 8, pal_bits)
-+ << (8 - pal_bits);
-+ pi->pal[i][1] = pic2_convert_color_bits(*g++, 8, pal_bits)
-+ << (8 - pal_bits);
-+ pi->pal[i][2] = pic2_convert_color_bits(*b++, 8, pal_bits)
-+ << (8 - pal_bits);
-+ }
-+}
-+#endif /* PIC2_IGNORE_UNUSED_FUNCTIONS */
-+
-+/*
-+ * These functions handle color bits.
-+ * pic2_convert_color_bits:
-+ * converts color bits.
-+ * pic2_pad_color_bits:
-+ * pads color bits.
-+ * pic2_reduce_color_bits:
-+ * reduces color bits.
-+ * pic2_exchange_rg:
-+ * exchanges red and green values.
-+ */
-+static byte pic2_convert_color_bits(c, from, to)
-+int c, from, to;
-+{
-+ if (from == to)
-+ return ((byte) c);
-+ else if (from < to)
-+ return (pic2_pad_color_bits(c, from, to));
-+ else
-+ return (pic2_reduce_color_bits(c, from, to));
-+}
-+
-+static byte pic2_pad_color_bits(c, from, to)
-+int c, from, to;
-+{
-+ byte p = 0;
-+
-+ do {
-+ to -= from;
-+ p |= pic2_shift_bits(c, to);
-+ } while (to >= 0);
-+ return (p);
-+}
-+
-+static byte pic2_reduce_color_bits(c, from, to)
-+int c, from, to;
-+{
-+ return ((byte) (c >> (from - to)));
-+}
-+
-+static pixel pic2_exchange_rg(p, colbits)
-+pixel p;
-+int colbits;
-+{
-+ pixel rmask, gmask, bmask;
-+
-+ rmask = (0xff >> (8 - colbits)) << (colbits * 2);
-+ gmask = (0xff >> (8 - colbits)) << colbits;
-+ bmask = (0xff >> (8 - colbits));
-+
-+ p = ((p << colbits) & rmask)
-+ | ((p >> colbits) & gmask)
-+ | ( p & bmask);
-+ return (p);
-+}
-+
-+/*
-+ * This function handles work memory buffer.
-+ */
-+static void pic2_handle_para(pi, mode)
-+struct pic2_info *pi;
-+int mode;
-+{
-+ static pixel *vram_prev, *vram_now, *vram_next;
-+ static short *flag_now, *flag_next;
-+ static short *flag2_now, *flag2_next, *flag2_next2;
-+
-+ switch (mode) {
-+ case 0:
-+ vram_prev = pi->vram_prev;
-+ vram_now = pi->vram_now;
-+ vram_next = pi->vram_next;
-+ flag_now = pi->flag_now;
-+ flag_next = pi->flag_next;
-+ flag2_now = pi->flag2_now;
-+ flag2_next = pi->flag2_next;
-+ flag2_next2 = pi->flag2_next2;
-+ pi->vram_prev += 4;
-+ pi->vram_now += 4;
-+ pi->vram_next += 4;
-+ pi->flag_now += 4;
-+ pi->flag_next += 4;
-+ pi->flag2_now += 4;
-+ pi->flag2_next += 4;
-+ pi->flag2_next2 += 4;
-+ break;
-+ case 1:
-+ pi->vram_prev = vram_now;
-+ pi->vram_now = vram_next;
-+ pi->vram_next = vram_prev;
-+ pi->flag_now = flag_next;
-+ pi->flag_next = flag_now;
-+ pi->flag2_now = flag2_next;
-+ pi->flag2_next = flag2_next2;
-+ pi->flag2_next2 = flag2_now;
-+ break;
-+ }
-+}
-+
-+/*
-+ * These functions alloc/free work memory.
-+ * pic2_alloc_buffer:
-+ * alloc work memory buffer.
-+ * pic2_free_buffer:
-+ * free work memory buffer.
-+ */
-+static int pic2_alloc_buffer(pi)
-+struct pic2_info *pi;
-+{
-+ int wid;
-+ byte *p;
-+
-+ if (pi->buf != NULL)
-+ return (-1);
-+
-+ wid = pi->block->x_wid;
-+
-+ p = pi->buf = (byte *) pic2_new((wid + 8) * sizeof(pixel) * 3 // GRR POSSIBLE OVERFLOW / FIXME
-+ + sizeof(pi->cache[0]) * 8 * 8 * 8
-+ + sizeof(pi->cache_pos[0]) * 8 * 8 * 8
-+ + sizeof(pi->mulu_tab[0]) * 16384
-+ + sizeof(pi->flag_now[0]) * ((wid+8) * 5),
-+ "pic2_alloc_buffer");
-+
-+ pi->vram_prev = (pixel *) p;
-+ p += (wid + 8) * sizeof(pixel);
-+ pi->vram_now = (pixel *) p;
-+ p += (wid + 8) * sizeof(pixel);
-+ pi->vram_next = (pixel *) p;
-+ p += (wid + 8) * sizeof(pixel);
-+ pi->cache = (pixel (*)[PIC2_ARITH_CACHE]) p;
-+ p += sizeof(pi->cache[0]) * 8 * 8 * 8;
-+ pi->cache_pos = (unsigned short *) p;
-+ p += sizeof(pi->cache_pos[0]) * 8 * 8 * 8;
-+ pi->mulu_tab = (unsigned short *) p;
-+ p += sizeof(pi->mulu_tab[0]) * 16384;
-+ pi->flag_now = (short *) p;
-+ p += sizeof(pi->flag_now[0]) * (wid + 8);
-+ pi->flag_next = (short *) p;
-+ p += sizeof(pi->flag_next[0]) * (wid + 8);
-+ pi->flag2_now = (short *) p;
-+ p += sizeof(pi->flag2_now[0]) * (wid + 8);
-+ pi->flag2_next = (short *) p;
-+ p += sizeof(pi->flag2_next[0]) * (wid + 8);
-+ pi->flag2_next2 = (short *) p;
-+ p += sizeof(pi->flag2_next2[0]) * (wid + 8);
-+ return (0);
-+}
-+
-+static void pic2_free_buffer(pi)
-+struct pic2_info *pi;
-+{
-+ free(pi->buf);
-+ pi->buf = NULL;
-+}
-+
-+/*
-+ * These functions handle the file pointer.
-+ * pic2_seek_file:
-+ * moves the file pointer.
-+ * pic2_tell_file:
-+ * tells the location of the file pointer.
-+ */
-+static long pic2_seek_file(pi, offset, whence)
-+struct pic2_info *pi;
-+long offset;
-+int whence;
-+{
-+ long n;
-+
-+ n = fseek(pi->fp, offset, whence);
-+ if (n < 0)
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+
-+ return (n);
-+}
-+
-+static long pic2_tell_file(pi)
-+struct pic2_info *pi;
-+{
-+ return (ftell(pi->fp));
-+}
-+
-+/*
-+ * These functions handle file.
-+ * pic2_read_file:
-+ * reads data from the file.
-+ * pic2_read_long:
-+ * reads long word data from the file and converts to internal expression.
-+ * pic2_read_short:
-+ * reads word data from the file and converts to internal expression.
-+ * pic2_read_char:
-+ * reads byte data from the file.
-+ * pic2_write_file:
-+ * writes data to the file.
-+ * pic2_write_long:
-+ * converts long word data to common expression and writes to the file.
-+ * pic2_write_short:
-+ * converts word data to common expression and writes to the file.
-+ * pic2_write_char:
-+ * writes byte data to the file.
-+ */
-+static int pic2_read_file(pi, buf, size)
-+struct pic2_info *pi;
-+void *buf;
-+size_t size;
-+{
-+ if (fread(buf, (size_t) 1, size, pi->fp) < size)
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+ return (0);
-+}
-+
-+static long pic2_read_long(pi)
-+struct pic2_info *pi;
-+{
-+ byte buf[4];
-+
-+ if (fread(buf, (size_t) 4, (size_t) 1, pi->fp) < 1)
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+ return (pic2_cextolong(buf));
-+}
-+
-+static short pic2_read_short(pi)
-+struct pic2_info *pi;
-+{
-+ byte buf[2];
-+
-+ if (fread(buf, (size_t) 2, (size_t) 1, pi->fp) < 1)
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+ return (pic2_cextoshort(buf));
-+}
-+
-+static char pic2_read_char(pi)
-+struct pic2_info *pi;
-+{
-+ int c;
-+
-+ if ((c = fgetc(pi->fp)) == EOF)
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+ return ((char) c);
-+}
-+
-+static int pic2_write_file(pi, buf, size)
-+struct pic2_info *pi;
-+void *buf;
-+size_t size;
-+{
-+ if (fwrite(buf, (size_t) 1, size, pi->fp) < size)
-+ pic2_error(pi, PIC2_WRITE);
-+ return (0);
-+}
-+
-+static int pic2_write_long(pi, n)
-+struct pic2_info *pi;
-+long n;
-+{
-+ byte buf[4];
-+
-+ pic2_longtocex(buf, n);
-+ if (fwrite(buf, (size_t) 4, (size_t) 1, pi->fp) < 1)
-+ pic2_error(pi, PIC2_WRITE);
-+ return (0);
-+}
-+
-+static int pic2_write_short(pi, n)
-+struct pic2_info *pi;
-+int n;
-+{
-+ byte buf[2];
-+
-+ pic2_shorttocex(buf, n);
-+ if (fwrite(buf, (size_t) 2, (size_t) 1, pi->fp) < 1)
-+ pic2_error(pi, PIC2_WRITE);
-+ return (0);
-+}
-+
-+static int pic2_write_char(pi, c)
-+struct pic2_info *pi;
-+int c;
-+{
-+ if (fputc(c, pi->fp) == EOF)
-+ pic2_error(pi, PIC2_WRITE);
-+ return (0);
-+}
-+
-+/*
-+ * These functions access the bit stream.
-+ * pic2_read_bits:
-+ * reads the specified bits from the file.
-+ * pic2_write_bits:
-+ * writes the specified bits to the file.
-+ * pic2_flush_bits:
-+ * flushes bit buffer to the file.
-+ */
-+static unsigned long pic2_read_bits(pi, bits)
-+struct pic2_info *pi;
-+int bits;
-+{
-+ unsigned long r = 0;
-+
-+ while (bits > 0) {
-+ while (pi->bs.rest > 0 && bits > 0) {
-+ r = (r << 1) | (pi->bs.cur & 0x80 ? 1 : 0);
-+ pi->bs.cur <<= 1;
-+ pi->bs.rest--;
-+ bits--;
-+ }
-+ if (bits > 0) {
-+ int c;
-+ if ((c = fgetc(pi->fp)) == EOF)
-+ pic2_file_error(pi, PIC2_CORRUPT);
-+ pi->bs.cur = (byte) c;
-+ pi->bs.rest = 8;
-+ }
-+ }
-+ return r;
-+}
-+
-+static void pic2_write_bits(pi, dat, bits)
-+struct pic2_info *pi;
-+unsigned long dat;
-+int bits;
-+{
-+ unsigned long dat_mask = 1 << (bits - 1);
-+
-+ while (bits > 0) {
-+ while (pi->bs.rest < 8 && bits > 0) {
-+ pi->bs.cur <<= 1;
-+ if (dat & dat_mask)
-+ pi->bs.cur |= 1;
-+ pi->bs.rest++;
-+ bits--;
-+ dat_mask >>= 1;
-+ }
-+ if (pi->bs.rest >= 8) {
-+ if ((fputc((int) pi->bs.cur, pi->fp)) == EOF)
-+ pic2_error(pi, PIC2_WRITE);
-+ pi->bs.cur = 0;
-+ pi->bs.rest = 0;
-+ }
-+ }
-+}
-+
-+static void pic2_flush_bits(pi)
-+struct pic2_info *pi;
-+{
-+ if (pi->bs.rest < 8) {
-+ pi->bs.cur <<= 8 - pi->bs.rest;
-+ if (fputc((int) pi->bs.cur, pi->fp) == EOF)
-+ pic2_error(pi, PIC2_WRITE);
-+ pi->bs.cur = 0;
-+ pi->bs.rest = 0;
-+ }
-+}
-+
-+/*
-+ * These functions initialize or clean up structures.
-+ * pic2_init_info:
-+ * initializes a pic2_info structure.
-+ * pic2_cleanup_pic2_info:
-+ * cleans up a pic_info structure.
-+ * pic2_cleanup_pinfo:
-+ * cleans up a PICINFO structure.
-+ */
-+static void pic2_init_info(pi)
-+struct pic2_info *pi;
-+{
-+ xvbzero((char *) pi, sizeof(struct pic2_info));
-+ pi->header = pic2_new(sizeof(struct pic2_header), "pic2_init_info#1");
-+ pi->block = pic2_new(sizeof(struct pic2_block), "pic2_init_info#2");
-+}
-+
-+static void pic2_cleanup_pic2_info(pi, writing)
-+struct pic2_info *pi;
-+int writing;
-+{
-+ if (!writing && pi->fp)
-+ fclose(pi->fp);
-+ if (pi->header)
-+ free(pi->header);
-+ if (pi->block)
-+ free(pi->block);
-+ pi->fp = NULL;
-+ pi->header = NULL;
-+ pi->block = NULL;
-+ pi->comment = NULL;
-+}
-+
-+static void pic2_cleanup_pinfo(pinfo)
-+PICINFO *pinfo;
-+{
-+ if (pinfo->pic){
-+ free(pinfo->pic);
-+ pinfo->pic = NULL;
-+ }
-+ if (pinfo->comment){
-+ free(pinfo->comment);
-+ pinfo->comment = NULL;
-+ }
-+}
-+
-+/*
-+ * Error Handlers.
-+ * pic2_memory_error:
-+ * shows an error message and terminates.
-+ * pic2_error:
-+ * shows a non-file error message and jumps to the entry for errors.
-+ * pic2_file_error:
-+ * shows a file error message and jumps to the entry for errors.
-+ */
-+static void pic2_memory_error(scm, fn)
-+char *scm, *fn;
-+{
-+ char buf[128];
-+ sprintf(buf, "%s: can't allocate memory. (%s)", scm, fn);
-+ FatalError(buf);
-+}
-+
-+static void pic2_error(pi, mn)
-+struct pic2_info *pi;
-+int mn;
-+{
-+ SetISTR(ISTR_WARNING, "%s", pic2_msgs[mn]);
-+ longjmp(pi->jmp, 1);
-+}
-+
-+static void pic2_file_error(pi, mn)
-+ struct pic2_info *pi;
-+ int mn;
-+{
-+ if (feof(pi->fp))
-+ SetISTR(ISTR_WARNING, "%s (end of file)", pic2_msgs[mn]);
-+ else
-+ SetISTR(ISTR_WARNING, "%s (%s)", pic2_msgs[mn], ERRSTR(errno));
-+ longjmp(pi->jmp, 1);
-+}
-+
-+static void pic2_show_pic2_info(pi)
-+ struct pic2_info *pi;
-+{
-+ fprintf(stderr, "file size: %ld.\n", pi->fsize);
-+ fprintf(stderr, "full image size: %dx%d\n", pi->x_max, pi->y_max);
-+ fprintf(stderr, "number of palettes: %d\n", pi->n_pal);
-+ fprintf(stderr, "depth of palettes: %d\n", pi->pal_bits);
-+ fprintf(stderr, "current block position: %ld\n", pi->block_pos);
-+ fprintf(stderr, "next block position: %ld\n\n", pi->next_pos);
-+
-+ fprintf(stderr, "header flag: %x\n", pi->header->flag);
-+ fprintf(stderr, "header size: %ld\n", pi->header->size);
-+ fprintf(stderr, "x_aspect: %d, y_aspect: %d\n",
-+ pi->header->x_aspect, pi->header->y_aspect);
-+ fprintf(stderr, "number of color bits: %d\n\n", pi->header->depth);
-+
-+ fprintf(stderr, "image block id: %s\n", pi->block->id);
-+ fprintf(stderr, "image block size: %ld\n", pi->block->size);
-+ fprintf(stderr, "block flag: %x\n", pi->block->flag);
-+
-+ fprintf(stderr, "block image size: %dx%d\n",
-+ pi->block->x_wid, pi->block->y_wid);
-+ fprintf(stderr, "x_offset: %d\n", pi->block->x_offset);
-+ fprintf(stderr, "y_offset: %d\n", pi->block->y_offset);
-+ fprintf(stderr, "opaque color: %lx\n\n", pi->block->opaque);
-+}
-+
-+/*
-+ * This function is similar to strncpy.
-+ * But this pads with whitespace after the null character.
-+ */
-+static char *pic2_strncpy(dest, src, n)
-+char *dest, *src;
-+size_t n;
-+{
-+ char *r;
-+
-+ r = dest;
-+ while (n--)
-+ if ((src != NULL) && (*src != '\r') && (*src != '\n') && *src)
-+ *dest++ = *src++;
-+ else
-+ *dest++ = ' ';
-+ return (r);
-+}
-+
-+/*
-+ * These functions create a memory block.
-+ */
-+static void *pic2_malloc(size, fn)
-+size_t size;
-+char *fn;
-+{
-+ void *p;
-+
-+ p = (void *) malloc(size);
-+ if (p == NULL)
-+ pic2_memory_error("malloc", fn);
-+ return (p);
-+}
-+
-+static void *pic2_new(size, fn)
-+size_t size;
-+char *fn;
-+{
-+ void *p;
-+
-+ p = (void *) pic2_malloc(size, fn);
-+ xvbzero((char *) p, size);
-+ return (p);
-+}
-+
-+
-+
-+
-+/**** Stuff for PIC2Dialog box ****/
-+
-+#define TWIDE 320
-+#define THIGH 178
-+#define T_NBUTTS 2
-+#define T_BOK 0
-+#define T_BCANC 1
-+#define BUTTH 24
-+
-+static void drawTD PARM((int,int,int,int));
-+static void clickTD PARM((int,int));
-+static void doCmd PARM((int));
-+static void writePIC2 PARM((void));
-+
-+/* local variables */
-+static FILE *fp;
-+static char *filename;
-+static int colorType;
-+static int append;
-+static int x_offset;
-+static int y_offset;
-+static BUTT tbut[T_NBUTTS];
-+static RBUTT *typeRB;
-+static RBUTT *depthRB;
-+
-+
-+
-+/***************************************************/
-+void CreatePIC2W()
-+{
-+ int y;
-+
-+ pic2W = CreateWindow("xv pic2", "XVpic2", NULL,
-+ TWIDE, THIGH, infofg, infobg, 0);
-+ if (!pic2W)
-+ FatalError("can't create pic2 window!");
-+
-+ XSelectInput(theDisp, pic2W,
-+ ExposureMask | ButtonPressMask | KeyPressMask);
-+
-+ BTCreate(&tbut[T_BOK], pic2W, TWIDE-140-1, THIGH-10-BUTTH-1, 60, BUTTH,
-+ "Ok", infofg, infobg, hicol, locol);
-+
-+ BTCreate(&tbut[T_BCANC], pic2W, TWIDE-70-1, THIGH-10-BUTTH-1, 60, BUTTH,
-+ "Cancel", infofg, infobg, hicol, locol);
-+
-+ y = 55;
-+ typeRB = RBCreate(NULL, pic2W, 36, y, "P2SS",
-+ infofg, infobg,hicol,locol);
-+ RBCreate(typeRB, pic2W, 36, y+18, "P2SF",
-+ infofg, infobg,hicol,locol);
-+ RBCreate(typeRB, pic2W, 36, y+36, "P2BM",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(typeRB, pic2W, 36, y+54, "P2BI",
-+ infofg, infobg, hicol, locol);
-+
-+ depthRB = RBCreate(NULL, pic2W, TWIDE/2-16, y, " 3bit",
-+ infofg, infobg,hicol,locol);
-+ RBCreate(depthRB, pic2W, TWIDE/2-16, y+18, " 6bit",
-+ infofg, infobg,hicol,locol);
-+ RBCreate(depthRB, pic2W, TWIDE/2-16, y+36, " 9bit",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(depthRB, pic2W, TWIDE/2-16, y+54, "12bit",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(depthRB, pic2W, TWIDE/4*3-16, y, "15bit",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(depthRB, pic2W, TWIDE/4*3-16, y+18, "18bit",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(depthRB, pic2W, TWIDE/4*3-16, y+36, "21bit",
-+ infofg, infobg, hicol, locol);
-+ RBCreate(depthRB, pic2W, TWIDE/4*3-16, y+54, "24bit",
-+ infofg, infobg, hicol, locol);
-+
-+ XMapSubwindows(theDisp, pic2W);
-+}
-+
-+
-+/***************************************************/
-+void PIC2Dialog(vis)
-+int vis;
-+{
-+ if (vis) {
-+ CenterMapWindow(pic2W, tbut[T_BOK].x + tbut[T_BOK].w/2,
-+ tbut[T_BOK].y + tbut[T_BOK].h/2, TWIDE, THIGH);
-+ }
-+ else XUnmapWindow(theDisp, pic2W);
-+ pic2Up = vis;
-+}
-+
-+
-+/***************************************************/
-+int PIC2CheckEvent(xev)
-+XEvent *xev;
-+{
-+ /* check event to see if it's for one of our subwindows. If it is,
-+ deal accordingly and return '1'. Otherwise, return '0'. */
-+
-+ int rv;
-+ rv = 1;
-+
-+ if (!pic2Up)
-+ return (0);
-+
-+ if (xev->type == Expose) {
-+ int x,y,w,h;
-+ XExposeEvent *e = (XExposeEvent *) xev;
-+ x = e->x; y = e->y; w = e->width; h = e->height;
-+
-+ if (e->window == pic2W) drawTD(x, y, w, h);
-+ else rv = 0;
-+ }
-+
-+ else if (xev->type == ButtonPress) {
-+ XButtonEvent *e = (XButtonEvent *) xev;
-+ int x,y;
-+ x = e->x; y = e->y;
-+
-+ if (e->button == Button1) {
-+ if (e->window == pic2W) clickTD(x,y);
-+ else rv = 0;
-+ } /* button1 */
-+ else rv = 0;
-+ } /* button press */
-+
-+
-+ else if (xev->type == KeyPress) {
-+ XKeyEvent *e = (XKeyEvent *) xev;
-+ char buf[128]; KeySym ks; XComposeStatus status;
-+ int stlen;
-+
-+ stlen = XLookupString(e,buf,128,&ks,&status);
-+ buf[stlen] = '\0';
-+
-+ if (e->window == pic2W) {
-+ if (stlen) {
-+ if (buf[0] == '\r' || buf[0] == '\n') { /* enter */
-+ FakeButtonPress(&tbut[T_BOK]);
-+ }
-+ else if (buf[0] == '\033') { /* ESC */
-+ FakeButtonPress(&tbut[T_BCANC]);
-+ }
-+ }
-+ }
-+ else rv = 0;
-+ }
-+ else rv = 0;
-+
-+ if (rv == 0 && (xev->type == ButtonPress || xev->type == KeyPress)) {
-+ XBell(theDisp, 50);
-+ rv = 1; /* eat it */
-+ }
-+
-+ return (rv);
-+}
-+
-+
-+/***************************************************/
-+int PIC2SaveParams(fname, col)
-+char *fname;
-+int col;
-+{
-+ filename = fname;
-+ colorType = col;
-+
-+ /* see if we can open the output file before proceeding */
-+ fp = pic2_OpenOutFile(filename, &append);
-+ if (!fp)
-+ return (-1);
-+
-+ RBSetActive(typeRB,0,1);
-+ RBSetActive(typeRB,1,1);
-+ RBSetActive(typeRB,2,1);
-+ RBSetActive(typeRB,3,1);
-+ RBSelect(typeRB,0);
-+
-+
-+ if (append) {
-+ struct pic2_info pic2;
-+
-+ pic2_init_info(&pic2);
-+ pic2.fp = fp;
-+ pic2_read_header(&pic2);
-+
-+ RBSetActive(depthRB,0,0);
-+ RBSetActive(depthRB,1,0);
-+ RBSetActive(depthRB,2,0);
-+ RBSetActive(depthRB,3,0);
-+ RBSetActive(depthRB,4,0);
-+ RBSetActive(depthRB,5,0);
-+ RBSetActive(depthRB,6,0);
-+ RBSetActive(depthRB,7,0);
-+
-+ switch (pic2.header->depth) {
-+ case 3:
-+ RBSetActive(depthRB,0,1);
-+ RBSelect(depthRB,0);
-+ RBSetActive(typeRB,3,0);
-+ break;
-+ case 6:
-+ RBSetActive(depthRB,1,1);
-+ RBSelect(depthRB,1);
-+ RBSetActive(typeRB,3,0);
-+ break;
-+ case 9:
-+ RBSetActive(depthRB,2,1);
-+ RBSelect(depthRB,2);
-+ break;
-+ case 12:
-+ RBSetActive(depthRB,3,1);
-+ RBSelect(depthRB,3);
-+ break;
-+ case 15:
-+ RBSetActive(depthRB,4,1);
-+ RBSelect(depthRB,4);
-+ break;
-+ case 18:
-+ RBSetActive(depthRB,5,1);
-+ RBSelect(depthRB,5);
-+ RBSetActive(typeRB,3,0);
-+ break;
-+ case 21:
-+ RBSetActive(depthRB,6,1);
-+ RBSelect(depthRB,6);
-+ RBSetActive(typeRB,3,0);
-+ break;
-+ case 24:
-+ RBSetActive(depthRB,7,1);
-+ RBSelect(depthRB,7);
-+ RBSetActive(typeRB,3,0);
-+ break;
-+ default: {
-+ char str[512];
-+ sprintf(str, "unsupported PIC2 file '%s'.", filename);
-+ ErrPopUp(str, "\nBummer");
-+ CloseOutFile(fp, filename, 0);
-+ fp = OpenOutFile(fname);
-+ if (!fp)
-+ return (-1);
-+ break;
-+ }
-+ }
-+ pic2_seek_file(&pic2, 0, SEEK_SET);
-+ pic2_cleanup_pic2_info(&pic2, 1);
-+ } else {
-+ RBSetActive(depthRB,0,1);
-+ RBSetActive(depthRB,1,1);
-+ RBSetActive(depthRB,2,1);
-+ RBSetActive(depthRB,3,1);
-+ RBSetActive(depthRB,4,1);
-+ RBSetActive(depthRB,5,1);
-+ RBSetActive(depthRB,6,1);
-+ RBSetActive(depthRB,7,1);
-+ RBSelect(depthRB,7);
-+ RBSetActive(typeRB,3,0);
-+ }
-+ return (0);
-+}
-+
-+
-+/***************************************************/
-+static void drawTD(x,y,w,h)
-+int x,y,w,h;
-+{
-+ char *title = "Save PIC2 file...";
-+ int i;
-+ XRectangle xr;
-+
-+ xr.x = x; xr.y = y; xr.width = w; xr.height = h;
-+ XSetClipRectangles(theDisp, theGC, 0,0, &xr, 1, Unsorted);
-+
-+ XSetForeground(theDisp, theGC, infofg);
-+ XSetBackground(theDisp, theGC, infobg);
-+
-+ for (i = 0; i < T_NBUTTS; i++)
-+ BTRedraw(&tbut[i]);
-+
-+ ULineString(pic2W, typeRB->x-16, typeRB->y-3-DESCENT, "FormatType");
-+ ULineString(pic2W, depthRB->x-16, depthRB->y-3-DESCENT, "ColorDepth");
-+ RBRedraw(typeRB, -1);
-+ RBRedraw(depthRB, -1);
-+
-+ DrawString(pic2W, 20, 29, title);
-+
-+ XSetClipMask(theDisp, theGC, None);
-+}
-+
-+static void clickTD(x,y)
-+int x,y;
-+{
-+ int i;
-+ BUTT *bp;
-+
-+ /* check BUTTs */
-+
-+ /* check the RBUTTS first, since they don't DO anything */
-+ if ((i = RBClick(typeRB, x,y)) >= 0) {
-+ (void) RBTrack(typeRB, i);
-+ return;
-+ } else if ((i = RBClick(depthRB, x,y)) >= 0) {
-+ (void) RBTrack(depthRB, i);
-+ if ((2 <= i) && (i <= 4))
-+ RBSetActive(typeRB,3,1);
-+ else {
-+ RBSetActive(typeRB,3,0);
-+ if (RBWhich(typeRB) == 3)
-+ RBSelect(typeRB,0);
-+ return;
-+ }
-+ }
-+ for (i = 0; i < T_NBUTTS; i++) {
-+ bp = &tbut[i];
-+ if (PTINRECT(x, y, bp->x, bp->y, bp->w, bp->h))
-+ break;
-+ }
-+ if (i < T_NBUTTS) /* found one */
-+ if (BTTrack(bp))
-+ doCmd(i);
-+}
-+
-+
-+
-+/***************************************************/
-+static void doCmd(cmd)
-+int cmd;
-+{
-+ switch (cmd) {
-+ case T_BOK: {
-+ char *fullname;
-+ char buf[64], *x_offsetp, *y_offsetp;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ XEvent event;
-+ int i;
-+
-+ strcpy(buf, "0,0");
-+ i = GetStrPopUp("Enter offset (x,y):", labels, 2, buf, 64,
-+ "01234567890,", 1);
-+
-+ if (i)
-+ return;
-+ if (strlen(buf)==0)
-+ return;
-+
-+ x_offsetp = buf;
-+ y_offsetp = index(buf, ',');
-+ if (!y_offsetp)
-+ return;
-+ *(y_offsetp++) = '\0';
-+ if ((*x_offsetp == '\0') || (*y_offsetp == '\0'))
-+ return;
-+ x_offset = atoi(x_offsetp);
-+ y_offset = atoi(y_offsetp);
-+
-+ XNextEvent(theDisp, &event);
-+ HandleEvent(&event, &i);
-+
-+ writePIC2();
-+ PIC2Dialog(0);
-+
-+ fullname = GetDirFullName();
-+ if (!ISPIPE(fullname[0])) {
-+ XVCreatedFile(fullname);
-+ StickInCtrlList(0);
-+ }
-+ }
-+ break;
-+ case T_BCANC:
-+ pic2_KillNullFile(fp);
-+ PIC2Dialog(0);
-+ break;
-+ default:
-+ break;
-+ }
-+}
-+
-+
-+/*******************************************/
-+static void writePIC2()
-+{
-+ int w, h, nc, rv, type, depth, ptype, pfree;
-+ byte *inpix, *rmap, *gmap, *bmap;
-+
-+
-+ WaitCursor();
-+ inpix = GenSavePic(&ptype, &w, &h, &pfree, &nc, &rmap, &gmap, &bmap);
-+
-+ if (colorType == F_REDUCED)
-+ colorType = F_FULLCOLOR;
-+
-+ switch (RBWhich(typeRB)) {
-+ case 0: type = P2SS; break;
-+ case 1: type = P2SF; break;
-+ case 2: type = P2BM; break;
-+ case 3: type = P2BI; break;
-+ default: type = P2SS; break;
-+ }
-+ switch (RBWhich(depthRB)) {
-+ case 0: depth = 3; break;
-+ case 1: depth = 6; break;
-+ case 2: depth = 9; break;
-+ case 3: depth = 12; break;
-+ case 4: depth = 15; break;
-+ case 5: depth = 18; break;
-+ case 6: depth = 21; break;
-+ case 7: depth = 24; break;
-+ default: depth = 24; break;
-+ }
-+ rv = WritePIC2(fp, inpix, ptype, w, h,
-+ rmap, gmap, bmap, nc, colorType, filename,
-+ type, depth, x_offset, y_offset, append, picComments);
-+
-+ if (CloseOutFile(fp, filename, rv) == 0)
-+ DirBox(0);
-+
-+ if (pfree)
-+ free(inpix);
-+}
-+#endif /* HAVE_PIC2 */
-diff -u -r --new-file xv-3.10a.orig/xvpng.c xv-3.10a/xvpng.c
---- xv-3.10a.orig/xvpng.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvpng.c 2007-05-13 19:53:28.000000000 -0500
-@@ -0,0 +1,1173 @@
-+/*
-+ * xvpng.c - load and write routines for 'PNG' format pictures
-+ *
-+ * callable functions
-+ *
-+ * CreatePNGW()
-+ * PNGDialog(vis)
-+ * PNGCheckEvent(xev)
-+ * PNGSaveParams(fname, col)
-+ * LoadPNG(fname, pinfo)
-+ * VersionInfoPNG()
-+ */
-+
-+/*#include "copyright.h"*/
-+
-+/* (c) 1995 by Alexander Lehmann
-+ * This file is a suplement to xv and is supplied under the same copying
-+ * conditions (except the shareware part).
-+ * The copyright will be passed on to JB at some future point if he
-+ * so desires.
-+ *
-+ * Modified by Andreas Dilger to fix
-+ * error handling for bad PNGs, add dialogs for interlacing and
-+ * compression selection, and upgrade to libpng-0.89.
-+ *
-+ * Modified by Greg Roelofs, TenThumbs and others to fix bugs and add
-+ * features. See README.jumbo for details.
-+ */
-+
-+#include "xv.h"
-+
-+#ifdef HAVE_PNG
-+
-+#include "png.h"
-+
-+/*** Stuff for PNG Dialog box ***/
-+#define PWIDE 318
-+#define PHIGH 215
-+
-+#define DISPLAY_GAMMA 2.20 /* default display gamma */
-+#define COMPRESSION 6 /* default zlib compression level, not max
-+ (Z_BEST_COMPRESSION) */
-+
-+#define HAVE_tRNS (info_ptr->valid & PNG_INFO_tRNS)
-+
-+#define DWIDE 86
-+#define DHIGH 104
-+#define PFX (PWIDE-93)
-+#define PFY 44
-+#define PFH 20
-+
-+#define P_BOK 0
-+#define P_BCANC 1
-+#define P_NBUTTS 2
-+
-+#define BUTTH 24
-+
-+#define LF 10 /* a.k.a. '\n' on ASCII machines */
-+#define CR 13 /* a.k.a. '\r' on ASCII machines */
-+
-+/*** local functions ***/
-+static void drawPD PARM((int, int, int, int));
-+static void clickPD PARM((int, int));
-+static void doCmd PARM((int));
-+static void writePNG PARM((void));
-+static int WritePNG PARM((FILE *, byte *, int, int, int,
-+ byte *, byte *, byte *, int));
-+
-+static void png_xv_error PARM((png_structp png_ptr,
-+ png_const_charp message));
-+static void png_xv_warning PARM((png_structp png_ptr,
-+ png_const_charp message));
-+
-+/*** local variables ***/
-+static char *filename;
-+static const char *fbasename;
-+static int colorType;
-+static int read_anything;
-+static double Display_Gamma = DISPLAY_GAMMA;
-+
-+static DIAL cDial, gDial;
-+static BUTT pbut[P_NBUTTS];
-+static CBUTT interCB;
-+static CBUTT FdefCB, FnoneCB, FsubCB, FupCB, FavgCB, FPaethCB;
-+
-+
-+#ifdef PNG_NO_STDIO
-+/* NOTE: Some sites configure their version of the PNG Library without
-+ * Standard I/O Library interfaces in order to avoid unnecessary inter-
-+ * library dependencies at link time for applications that don't need Standard
-+ * I/O. If your site is one of these, the following skeletal stubs, copied
-+ * from libpng code, should be enough for this module. --Scott B. Marovich,
-+ * Hewlett-Packard Laboratories, March 2001.
-+ */
-+static void
-+png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
-+{
-+
-+ /* fread() returns 0 on error, so it is OK to store this in a png_size_t
-+ * instead of an int, which is what fread() actually returns.
-+ */
-+ if (fread(data,1,length,(FILE *)png_ptr->io_ptr) != length)
-+ png_error(png_ptr, "Read Error");
-+}
-+
-+static void
-+png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
-+{
-+ if (fwrite(data, 1, length, (FILE *)png_ptr->io_ptr) != length)
-+ png_error(png_ptr, "Write Error");
-+}
-+#endif /* PNG_NO_STDIO */
-+
-+
-+/**************************************************************************/
-+/* PNG SAVE DIALOG ROUTINES ***********************************************/
-+/**************************************************************************/
-+
-+
-+/*******************************************/
-+void CreatePNGW()
-+{
-+ pngW = CreateWindow("xv png", "XVPNG", NULL,
-+ PWIDE, PHIGH, infofg, infobg, 0);
-+ if (!pngW) FatalError("can't create PNG window!");
-+
-+ XSelectInput(theDisp, pngW, ExposureMask | ButtonPressMask | KeyPressMask);
-+
-+ DCreate(&cDial, pngW, 12, 25, DWIDE, DHIGH, (double)Z_NO_COMPRESSION,
-+ (double)Z_BEST_COMPRESSION, COMPRESSION, 1.0, 3.0,
-+ infofg, infobg, hicol, locol, "Compression", NULL);
-+
-+ DCreate(&gDial, pngW, DWIDE+27, 25, DWIDE, DHIGH, 1.0, 3.5,DISPLAY_GAMMA,0.01,0.2,
-+ infofg, infobg, hicol, locol, "Disp. Gamma", NULL);
-+
-+ CBCreate(&interCB, pngW, DWIDE+30, DHIGH+3*LINEHIGH+2, "interlace",
-+ infofg, infobg, hicol, locol);
-+
-+ CBCreate(&FdefCB, pngW, PFX, PFY, "Default",
-+ infofg, infobg, hicol, locol);
-+ FdefCB.val = 1;
-+
-+ CBCreate(&FnoneCB, pngW, PFX, FdefCB.y + PFH + 4, "none",
-+ infofg, infobg, hicol, locol);
-+ CBCreate(&FsubCB, pngW, PFX, FnoneCB.y + PFH, "sub",
-+ infofg, infobg, hicol, locol);
-+ CBCreate(&FupCB, pngW, PFX, FsubCB.y + PFH, "up",
-+ infofg, infobg, hicol, locol);
-+ CBCreate(&FavgCB, pngW, PFX, FupCB.y + PFH, "average",
-+ infofg, infobg, hicol, locol);
-+ CBCreate(&FPaethCB, pngW, PFX, FavgCB.y + PFH, "Paeth",
-+ infofg, infobg, hicol, locol);
-+
-+ FnoneCB.val = FsubCB.val = FupCB.val = FavgCB.val = FPaethCB.val = 1;
-+ CBSetActive(&FnoneCB, !FdefCB.val);
-+ CBSetActive(&FsubCB, !FdefCB.val);
-+ CBSetActive(&FupCB, !FdefCB.val);
-+ CBSetActive(&FavgCB, !FdefCB.val);
-+ CBSetActive(&FPaethCB, !FdefCB.val);
-+
-+ BTCreate(&pbut[P_BOK], pngW, PWIDE-180-1, PHIGH-10-BUTTH-1, 80, BUTTH,
-+ "Ok", infofg, infobg, hicol, locol);
-+ BTCreate(&pbut[P_BCANC], pngW, PWIDE-90-1, PHIGH-10-BUTTH-1, 80, BUTTH,
-+ "Cancel", infofg, infobg, hicol, locol);
-+
-+ XMapSubwindows(theDisp, pngW);
-+}
-+
-+
-+/*******************************************/
-+void PNGDialog(vis)
-+ int vis;
-+{
-+ if (vis) {
-+ CenterMapWindow(pngW, pbut[P_BOK].x + (int) pbut[P_BOK].w/2,
-+ pbut[P_BOK].y + (int) pbut[P_BOK].h/2,
-+ PWIDE, PHIGH);
-+ }
-+ else XUnmapWindow(theDisp, pngW);
-+ pngUp = vis;
-+}
-+
-+
-+/*******************************************/
-+int PNGCheckEvent(xev)
-+ XEvent *xev;
-+{
-+ /* check event to see if it's for one of our subwindows. If it is,
-+ deal accordingly, and return '1'. Otherwise, return '0' */
-+
-+ int rv;
-+ rv = 1;
-+
-+ if (!pngUp) return 0;
-+
-+ if (xev->type == Expose) {
-+ int x,y,w,h;
-+ XExposeEvent *e = (XExposeEvent *) xev;
-+ x = e->x; y = e->y; w = e->width; h = e->height;
-+
-+ /* throw away excess expose events for 'dumb' windows */
-+ if (e->count > 0 && (e->window == cDial.win)) {}
-+
-+ else if (e->window == pngW) drawPD(x, y, w, h);
-+ else if (e->window == cDial.win) DRedraw(&cDial);
-+ else if (e->window == gDial.win) DRedraw(&gDial);
-+ else rv = 0;
-+ }
-+
-+ else if (xev->type == ButtonPress) {
-+ XButtonEvent *e = (XButtonEvent *) xev;
-+ int x,y;
-+ x = e->x; y = e->y;
-+
-+ if (e->button == Button1) {
-+ if (e->window == pngW) clickPD(x,y);
-+ else if (e->window == cDial.win) DTrack(&cDial,x,y);
-+ else if (e->window == gDial.win) DTrack(&gDial,x,y);
-+ else rv = 0;
-+ } /* button1 */
-+ else rv = 0;
-+ } /* button press */
-+
-+ else if (xev->type == KeyPress) {
-+ XKeyEvent *e = (XKeyEvent *) xev;
-+ char buf[128]; KeySym ks;
-+ int stlen;
-+
-+ stlen = XLookupString(e,buf,128,&ks,(XComposeStatus *) NULL);
-+ buf[stlen] = '\0';
-+
-+ RemapKeyCheck(ks, buf, &stlen);
-+
-+ if (e->window == pngW) {
-+ if (stlen) {
-+ if (buf[0] == '\r' || buf[0] == '\n') { /* enter */
-+ FakeButtonPress(&pbut[P_BOK]);
-+ }
-+ else if (buf[0] == '\033') { /* ESC */
-+ FakeButtonPress(&pbut[P_BCANC]);
-+ }
-+ }
-+ }
-+ else rv = 0;
-+ }
-+ else rv = 0;
-+
-+ if (rv==0 && (xev->type == ButtonPress || xev->type == KeyPress)) {
-+ XBell(theDisp, 50);
-+ rv = 1; /* eat it */
-+ }
-+
-+ return rv;
-+}
-+
-+
-+/*******************************************/
-+void PNGSaveParams(fname, col)
-+ char *fname;
-+ int col;
-+{
-+ filename = fname;
-+ colorType = col;
-+}
-+
-+
-+/*******************************************/
-+static void drawPD(x, y, w, h)
-+ int x, y, w, h;
-+{
-+ const char *title = "Save PNG file...";
-+
-+ char ctitle1[20];
-+ const char *ctitle2 = "Useful range";
-+ const char *ctitle3 = "is 2 - 7.";
-+ const char *ctitle4 = "Uncompressed = 0";
-+
-+ const char *ftitle = "Row Filters:";
-+
-+ char gtitle[20];
-+
-+ int i;
-+ XRectangle xr;
-+
-+ xr.x = x; xr.y = y; xr.width = w; xr.height = h;
-+ XSetClipRectangles(theDisp, theGC, 0,0, &xr, 1, Unsorted);
-+
-+ XSetForeground(theDisp, theGC, infofg);
-+ XSetBackground(theDisp, theGC, infobg);
-+
-+ for (i=0; ix, bp->y, bp->w, bp->h)) break;
-+ }
-+
-+ if (ijmpbuf)) {
-+ png_destroy_write_struct(&png_ptr, &info_ptr);
-+ return -1;
-+ }
-+
-+#ifdef PNG_NO_STDIO
-+ png_set_write_fn(png_ptr, fp, png_default_write_data, NULL);
-+ png_set_error_fn(png_ptr, NULL, png_xv_error, png_xv_warning);
-+#else
-+ png_init_io(png_ptr, fp);
-+#endif
-+
-+ png_set_compression_level(png_ptr, (int)cDial.val);
-+
-+ /* Don't bother filtering if we aren't compressing the image */
-+ if (FdefCB.val)
-+ {
-+ if ((int)cDial.val == 0)
-+ png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
-+ }
-+ else
-+ {
-+ filter = FnoneCB.val ? PNG_FILTER_NONE : 0;
-+ filter |= FsubCB.val ? PNG_FILTER_SUB : 0;
-+ filter |= FupCB.val ? PNG_FILTER_UP : 0;
-+ filter |= FavgCB.val ? PNG_FILTER_AVG : 0;
-+ filter |= FPaethCB.val ? PNG_FILTER_PAETH : 0;
-+
-+ png_set_filter(png_ptr, 0, filter);
-+ }
-+
-+ info_ptr->width = w;
-+ info_ptr->height = h;
-+ if (w <= 0 || h <= 0) {
-+ SetISTR(ISTR_WARNING, "%s: image dimensions out of range (%dx%d)",
-+ fbasename, w, h);
-+ png_destroy_write_struct(&png_ptr, &info_ptr);
-+ return -1;
-+ }
-+
-+ info_ptr->interlace_type = interCB.val ? 1 : 0;
-+
-+ linesize = 0; /* quiet a compiler warning */
-+
-+
-+ /* GRR 20070331: remap palette to eliminate duplicated colors (as in
-+ * xvgifwr.c) */
-+ if (ptype == PIC8) {
-+ for (i=0; i<256; ++i) {
-+ pc2nc[i] = r1[i] = g1[i] = b1[i] = 0;
-+ }
-+
-+ /* compute number of unique colors */
-+ numuniqcols = 0;
-+
-+ for (i=0; icolor_type = PNG_COLOR_TYPE_RGB;
-+ info_ptr->bit_depth = 8;
-+ } else /* ptype == PIC8 */ {
-+ linesize = w;
-+ info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
-+ if (numuniqcols <= 2)
-+ info_ptr->bit_depth = 1;
-+ else
-+ if (numuniqcols <= 4)
-+ info_ptr->bit_depth = 2;
-+ else
-+ if (numuniqcols <= 16)
-+ info_ptr->bit_depth = 4;
-+ else
-+ info_ptr->bit_depth = 8;
-+
-+ for (i = 0; i < numuniqcols; i++) {
-+ palette[i].red = r1[i];
-+ palette[i].green = g1[i];
-+ palette[i].blue = b1[i];
-+ }
-+ info_ptr->num_palette = numuniqcols;
-+ info_ptr->palette = palette;
-+ info_ptr->valid |= PNG_INFO_PLTE;
-+ }
-+ }
-+
-+ else if (colorType == F_GREYSCALE || colorType == F_BWDITHER) {
-+ info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
-+ if (colorType == F_BWDITHER) {
-+ /* shouldn't happen */
-+ if (ptype == PIC24) FatalError("PIC24 and B/W Stipple in WritePNG()");
-+
-+ info_ptr->bit_depth = 1;
-+ if (MONO(r1[0], g1[0], b1[0]) > MONO(r1[1], g1[1], b1[1])) {
-+ remap[0] = 1;
-+ remap[1] = 0;
-+ }
-+ else {
-+ remap[0] = 0;
-+ remap[1] = 1;
-+ }
-+ linesize = w;
-+ }
-+ else /* F_GREYSCALE */ {
-+ if (ptype == PIC24) {
-+ linesize = 3*w;
-+ if (linesize/3 < w) {
-+ SetISTR(ISTR_WARNING, "%s: image dimensions too large (%dx%d)",
-+ fbasename, w, h);
-+ png_destroy_write_struct(&png_ptr, &info_ptr);
-+ return -1;
-+ }
-+ info_ptr->bit_depth = 8;
-+ }
-+ else /* ptype == PIC8 */ {
-+ int low_precision;
-+
-+ linesize = w;
-+
-+ /* NOTE: currently remap[] is the _secondary_ remapping of "palette"
-+ * colors; its values are the final color/grayscale values, and,
-+ * like r1/g1/b1[], it is _indexed_ by pc2nc[] (which is why its
-+ * values come from r1/g1/b1[] and not from rmap/gmap/bmap[]).
-+ *
-+ * FIXME (probably): MONO() will create new duplicates; ideally should
-+ * do extra round of dup-detection (and preferably collapse all
-+ * remapping levels into single LUT). This stuff is a tad confusing.
-+ */
-+ for (i = 0; i < numuniqcols; i++)
-+ remap[i] = MONO(r1[i], g1[i], b1[i]);
-+
-+ for (; i < 256; i++)
-+ remap[i]=0; /* shouldn't be necessary, but... */
-+
-+ info_ptr->bit_depth = 8;
-+
-+ /* Note that this fails most of the time because of gamma */
-+ /* (and that would be a bug: GRR FIXME) */
-+ /* try to adjust to 4-bit precision grayscale */
-+
-+ low_precision=1;
-+
-+ for (i = 0; i < numuniqcols; i++) {
-+ if ((remap[i] & 0x0f) * 0x11 != remap[i]) {
-+ low_precision = 0;
-+ break;
-+ }
-+ }
-+
-+ if (low_precision) {
-+ for (i = 0; i < numuniqcols; i++) {
-+ remap[i] &= 0xf;
-+ }
-+ info_ptr->bit_depth = 4;
-+
-+ /* try to adjust to 2-bit precision grayscale */
-+
-+ for (i = 0; i < numuniqcols; i++) {
-+ if ((remap[i] & 0x03) * 0x05 != remap[i]) {
-+ low_precision = 0;
-+ break;
-+ }
-+ }
-+ }
-+
-+ if (low_precision) {
-+ for (i = 0; i < numuniqcols; i++) {
-+ remap[i] &= 3;
-+ }
-+ info_ptr->bit_depth = 2;
-+
-+ /* try to adjust to 1-bit precision grayscale */
-+
-+ for (i = 0; i < numuniqcols; i++) {
-+ if ((remap[i] & 0x01) * 0x03 != remap[i]) {
-+ low_precision = 0;
-+ break;
-+ }
-+ }
-+ }
-+
-+ if (low_precision) {
-+ for (i = 0; i < numuniqcols; i++) {
-+ remap[i] &= 1;
-+ }
-+ info_ptr->bit_depth = 1;
-+ }
-+ }
-+ }
-+ }
-+
-+ else
-+ png_error(png_ptr, "Unknown colorstyle in WritePNG");
-+
-+ if ((text = (png_textp)malloc(sizeof(png_text)))) {
-+ sprintf(software, "XV %s", REVDATE);
-+
-+ text->compression = -1;
-+ text->key = "Software";
-+ text->text = software;
-+ text->text_length = strlen(text->text);
-+
-+ info_ptr->max_text = 1;
-+ info_ptr->num_text = 1;
-+ info_ptr->text = text;
-+ }
-+
-+ Display_Gamma = gDial.val; /* Save the current gamma for loading */
-+
-+// GRR FIXME: add .Xdefaults option to omit writing gamma (size, cumulative errors when editing)--alternatively, modify save box to include "omit" checkbox
-+ info_ptr->gamma = 1.0/gDial.val;
-+ info_ptr->valid |= PNG_INFO_gAMA;
-+
-+ png_write_info(png_ptr, info_ptr);
-+
-+ if (info_ptr->bit_depth < 8)
-+ png_set_packing(png_ptr);
-+
-+ pass=png_set_interlace_handling(png_ptr);
-+
-+ if ((png_line = malloc(linesize)) == NULL)
-+ png_error(png_ptr, "cannot allocate temp image line");
-+ /* FIXME: should be FatalError() */
-+
-+ for (i = 0; i < pass; ++i) {
-+ int j;
-+ p = pic;
-+ for (j = 0; j < h; ++j) {
-+ if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) {
-+ int k;
-+ for (k = 0; k < w; ++k)
-+ png_line[k] = ptype==PIC24 ? MONO(p[k*3], p[k*3+1], p[k*3+2]) :
-+ remap[pc2nc[p[k]]];
-+ png_write_row(png_ptr, png_line);
-+ } else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
-+ int k;
-+ for (k = 0; k < w; ++k)
-+ png_line[k] = pc2nc[p[k]];
-+ png_write_row(png_ptr, png_line);
-+ } else { /* PNG_COLOR_TYPE_RGB */
-+ png_write_row(png_ptr, p);
-+ }
-+ if ((j & 0x1f) == 0) WaitCursor();
-+ p += linesize;
-+ }
-+ }
-+
-+ free(png_line);
-+
-+ savecmnt = NULL; /* quiet a compiler warning */
-+
-+ if (text) {
-+ if (picComments && strlen(picComments) &&
-+ (savecmnt = (char *)malloc((strlen(picComments) + 1)*sizeof(char)))) {
-+ png_textp tp;
-+ char *comment, *key;
-+
-+ strcpy(savecmnt, picComments);
-+ key = savecmnt;
-+ tp = text;
-+ info_ptr->num_text = 0;
-+
-+ comment = strchr(key, ':');
-+
-+ do {
-+ /* Allocate a larger structure for comments if necessary */
-+ if (info_ptr->num_text >= info_ptr->max_text)
-+ {
-+ if ((tp =
-+ realloc(text, (info_ptr->num_text + 2)*sizeof(png_text))) == NULL)
-+ {
-+ break;
-+ }
-+ else
-+ {
-+ text = tp;
-+ tp = &text[info_ptr->num_text];
-+ info_ptr->max_text += 2;
-+ }
-+ }
-+
-+ /* See if it looks like a PNG keyword from LoadPNG */
-+ /* GRR: should test for strictly < 80, right? (key = 1-79 chars only) */
-+ if (comment && comment[1] == ':' && comment - key <= 80) {
-+ *(comment++) = '\0';
-+ *(comment++) = '\0';
-+
-+ /* If the comment is the 'Software' chunk XV writes, we remove it,
-+ since we have already stored one */
-+ if (strcmp(key, "Software") == 0 && strncmp(comment, "XV", 2) == 0) {
-+ key = strchr(comment, '\n');
-+ if (key)
-+ key++; /* skip \n */
-+ comment = strchr(key, ':');
-+ }
-+ /* We have another keyword and/or comment to write out */
-+ else {
-+ tp->key = key;
-+ tp->text = comment;
-+
-+ /* We have to find the end of this comment, and the next keyword
-+ if there is one */
-+ for (; NULL != (key = comment = strchr(comment, ':')); comment++)
-+ if (key[1] == ':')
-+ break;
-+
-+ /* It looks like another keyword, go backward to the beginning */
-+ if (key) {
-+ while (key > tp->text && *key != '\n')
-+ key--;
-+
-+ if (key > tp->text && comment - key <= 80) {
-+ *key = '\0';
-+ key++;
-+ }
-+ }
-+
-+ tp->text_length = strlen(tp->text);
-+
-+ /* We don't have another keyword, so remove the last newline */
-+ if (!key && tp->text[tp->text_length - 1] == '\n')
-+ {
-+ tp->text[tp->text_length] = '\0';
-+ tp->text_length--;
-+ }
-+
-+ tp->compression = tp->text_length > 640 ? 0 : -1;
-+ info_ptr->num_text++;
-+ tp++;
-+ }
-+ }
-+ /* Just a generic comment: make sure line-endings are valid for PNG */
-+ else {
-+ char *p=key, *q=key; /* only deleting chars, not adding any */
-+
-+ while (*p) {
-+ if (*p == CR) { /* lone CR or CR/LF: EOL either way */
-+ *q++ = LF; /* LF is the only allowed PNG line-ending */
-+ if (p[1] == LF) /* get rid of any original LF */
-+ ++p;
-+ } else if (*p == LF) /* lone LF */
-+ *q++ = LF;
-+ else
-+ *q++ = *p;
-+ ++p;
-+ }
-+ *q = '\0'; /* unnecessary...but what the heck */
-+ tp->key = "Comment";
-+ tp->text = key;
-+ tp->text_length = q - key;
-+ tp->compression = tp->text_length > 750 ? 0 : -1;
-+ info_ptr->num_text++;
-+ key = NULL;
-+ }
-+ } while (key && *key);
-+ }
-+ else {
-+ info_ptr->num_text = 0;
-+ }
-+ }
-+ info_ptr->text = text;
-+
-+ png_convert_from_time_t(&(info_ptr->mod_time), time(NULL));
-+ info_ptr->valid |= PNG_INFO_tIME;
-+
-+ png_write_end(png_ptr, info_ptr);
-+ fflush(fp); /* just in case we core-dump before finishing... */
-+
-+ if (text) {
-+ free(text);
-+ /* must do this or png_destroy_write_struct() 0.97+ will free text again: */
-+ info_ptr->text = (png_textp)NULL;
-+ if (savecmnt)
-+ {
-+ free(savecmnt);
-+ savecmnt = (char *)NULL;
-+ }
-+ }
-+
-+ png_destroy_write_struct(&png_ptr, &info_ptr);
-+
-+ return 0;
-+}
-+
-+
-+/*******************************************/
-+int LoadPNG(fname, pinfo)
-+ char *fname;
-+ PICINFO *pinfo;
-+/*******************************************/
-+{
-+ /* returns '1' on success */
-+
-+ FILE *fp;
-+ png_struct *png_ptr;
-+ png_info *info_ptr;
-+ png_color_16 my_background;
-+ int i,j;
-+ int linesize, bufsize;
-+ int filesize;
-+ int pass;
-+ int gray_to_rgb;
-+ size_t commentsize;
-+
-+ fbasename = BaseName(fname);
-+
-+ pinfo->pic = (byte *) NULL;
-+ pinfo->comment = (char *) NULL;
-+
-+ read_anything=0;
-+
-+ /* open the file */
-+ fp = xv_fopen(fname,"r");
-+ if (!fp) {
-+ SetISTR(ISTR_WARNING,"%s: can't open file", fname);
-+ return 0;
-+ }
-+
-+ /* find the size of the file */
-+ fseek(fp, 0L, 2);
-+ filesize = ftell(fp);
-+ fseek(fp, 0L, 0);
-+
-+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
-+ png_xv_error, png_xv_warning);
-+ if (!png_ptr) {
-+ fclose(fp);
-+ FatalError("malloc failure in LoadPNG");
-+ }
-+
-+ info_ptr = png_create_info_struct(png_ptr);
-+
-+ if (!info_ptr) {
-+ fclose(fp);
-+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
-+ FatalError("malloc failure in LoadPNG");
-+ }
-+
-+ if (setjmp(png_ptr->jmpbuf)) {
-+ fclose(fp);
-+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-+ if (!read_anything) {
-+ if (pinfo->pic) {
-+ free(pinfo->pic);
-+ pinfo->pic = NULL;
-+ }
-+ if (pinfo->comment) {
-+ free(pinfo->comment);
-+ pinfo->comment = NULL;
-+ }
-+ }
-+ return read_anything;
-+ }
-+
-+#ifdef PNG_NO_STDIO
-+ png_set_read_fn(png_ptr, fp, png_default_read_data);
-+ png_set_error_fn(png_ptr, NULL, png_xv_error, png_xv_warning);
-+#else
-+ png_init_io(png_ptr, fp);
-+#endif
-+ png_read_info(png_ptr, info_ptr);
-+
-+ pinfo->w = pinfo->normw = info_ptr->width;
-+ pinfo->h = pinfo->normh = info_ptr->height;
-+ if (pinfo->w <= 0 || pinfo->h <= 0) {
-+ SetISTR(ISTR_WARNING, "%s: image dimensions out of range (%dx%d)",
-+ fbasename, pinfo->w, pinfo->h);
-+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-+ return read_anything;
-+ }
-+
-+ pinfo->frmType = F_PNG;
-+
-+ sprintf(pinfo->fullInfo, "PNG, %d bit ",
-+ info_ptr->bit_depth * info_ptr->channels);
-+
-+ switch(info_ptr->color_type) {
-+ case PNG_COLOR_TYPE_PALETTE:
-+ strcat(pinfo->fullInfo, "palette color");
-+ break;
-+
-+ case PNG_COLOR_TYPE_GRAY:
-+ strcat(pinfo->fullInfo, "grayscale");
-+ break;
-+
-+ case PNG_COLOR_TYPE_GRAY_ALPHA:
-+ strcat(pinfo->fullInfo, "grayscale+alpha");
-+ break;
-+
-+ case PNG_COLOR_TYPE_RGB:
-+ strcat(pinfo->fullInfo, "truecolor");
-+ break;
-+
-+ case PNG_COLOR_TYPE_RGB_ALPHA:
-+ strcat(pinfo->fullInfo, "truecolor+alpha");
-+ break;
-+ }
-+
-+ sprintf(pinfo->fullInfo + strlen(pinfo->fullInfo),
-+ ", %sinterlaced. (%d bytes)",
-+ info_ptr->interlace_type ? "" : "non-", filesize);
-+
-+ sprintf(pinfo->shrtInfo, "%lux%lu PNG", info_ptr->width, info_ptr->height);
-+
-+ if (info_ptr->bit_depth < 8)
-+ png_set_packing(png_ptr);
-+
-+ if (info_ptr->valid & PNG_INFO_gAMA)
-+ png_set_gamma(png_ptr, Display_Gamma, info_ptr->gamma);
-+/*
-+ *else
-+ * png_set_gamma(png_ptr, Display_Gamma, 0.45);
-+ */
-+
-+ gray_to_rgb = 0; /* quiet a compiler warning */
-+
-+ if (have_imagebg) {
-+ if (info_ptr->bit_depth == 16) {
-+ my_background.red = imagebgR;
-+ my_background.green = imagebgG;
-+ my_background.blue = imagebgB;
-+ my_background.gray = imagebgG; /* used only if all three equal... */
-+ } else {
-+ my_background.red = (imagebgR >> 8);
-+ my_background.green = (imagebgG >> 8);
-+ my_background.blue = (imagebgB >> 8);
-+ my_background.gray = my_background.green;
-+ }
-+ png_set_background(png_ptr, &my_background, PNG_BACKGROUND_GAMMA_SCREEN,
-+ 0, Display_Gamma);
-+ if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
-+ (info_ptr->color_type == PNG_COLOR_TYPE_GRAY && HAVE_tRNS)) &&
-+ (imagebgR != imagebgG || imagebgR != imagebgB)) /* i.e., colored bg */
-+ {
-+ png_set_gray_to_rgb(png_ptr);
-+ png_set_expand(png_ptr);
-+ gray_to_rgb = 1;
-+ }
-+ } else {
-+ if (info_ptr->valid & PNG_INFO_bKGD) {
-+ png_set_background(png_ptr, &info_ptr->background,
-+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
-+ } else {
-+ my_background.red = my_background.green = my_background.blue =
-+ my_background.gray = 0;
-+ png_set_background(png_ptr, &my_background, PNG_BACKGROUND_GAMMA_SCREEN,
-+ 0, Display_Gamma);
-+ }
-+ }
-+
-+ if (info_ptr->bit_depth == 16)
-+ png_set_strip_16(png_ptr);
-+
-+ if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
-+ info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-+ {
-+ if (info_ptr->bit_depth == 1)
-+ pinfo->colType = F_BWDITHER;
-+ else
-+ pinfo->colType = F_GREYSCALE;
-+ png_set_expand(png_ptr);
-+ }
-+
-+ pass=png_set_interlace_handling(png_ptr);
-+
-+ png_read_update_info(png_ptr, info_ptr);
-+
-+ if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
-+ info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA || gray_to_rgb)
-+ {
-+ linesize = 3 * pinfo->w;
-+ if (linesize/3 < pinfo->w) { /* know pinfo->w > 0 (see above) */
-+ SetISTR(ISTR_WARNING, "%s: image dimensions too large (%dx%d)",
-+ fbasename, pinfo->w, pinfo->h);
-+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-+ return read_anything;
-+ }
-+ pinfo->colType = F_FULLCOLOR;
-+ pinfo->type = PIC24;
-+ } else {
-+ linesize = pinfo->w;
-+ pinfo->type = PIC8;
-+ if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
-+ info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
-+ for (i = 0; i < 256; i++)
-+ pinfo->r[i] = pinfo->g[i] = pinfo->b[i] = i;
-+ } else {
-+ pinfo->colType = F_FULLCOLOR;
-+ for (i = 0; i < info_ptr->num_palette; i++) {
-+ pinfo->r[i] = info_ptr->palette[i].red;
-+ pinfo->g[i] = info_ptr->palette[i].green;
-+ pinfo->b[i] = info_ptr->palette[i].blue;
-+ }
-+ }
-+ }
-+
-+ bufsize = linesize * pinfo->h;
-+ if (bufsize/linesize < pinfo->h) { /* know linesize, pinfo->h > 0 (above) */
-+ SetISTR(ISTR_WARNING, "%s: image dimensions too large (%dx%d)",
-+ fbasename, pinfo->w, pinfo->h);
-+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-+ return read_anything;
-+ }
-+ pinfo->pic = calloc((size_t)bufsize, (size_t)1);
-+
-+ if (!pinfo->pic) {
-+ png_error(png_ptr, "can't allocate space for PNG image");
-+ }
-+
-+ png_start_read_image(png_ptr);
-+
-+ for (i = 0; i < pass; i++) {
-+ byte *p = pinfo->pic;
-+ for (j = 0; j < pinfo->h; j++) {
-+ png_read_row(png_ptr, p, NULL);
-+ read_anything = 1;
-+ if ((j & 0x1f) == 0) WaitCursor();
-+ p += linesize;
-+ }
-+ }
-+
-+ png_read_end(png_ptr, info_ptr);
-+
-+ if (info_ptr->num_text > 0) {
-+ commentsize = 1;
-+
-+ for (i = 0; i < info_ptr->num_text; i++)
-+ commentsize += strlen(info_ptr->text[i].key) + 1 +
-+ info_ptr->text[i].text_length + 2;
-+
-+ if ((pinfo->comment = malloc(commentsize)) == NULL) {
-+ png_warning(png_ptr,"can't allocate comment string");
-+ }
-+ else {
-+ pinfo->comment[0] = '\0';
-+ for (i = 0; i < info_ptr->num_text; i++) {
-+ strcat(pinfo->comment, info_ptr->text[i].key);
-+ strcat(pinfo->comment, "::");
-+ strcat(pinfo->comment, info_ptr->text[i].text);
-+ strcat(pinfo->comment, "\n");
-+ }
-+ }
-+ }
-+
-+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
-+
-+ fclose(fp);
-+
-+ return 1;
-+}
-+
-+
-+/*******************************************/
-+static void
-+png_xv_error(png_ptr, message)
-+ png_structp png_ptr;
-+ png_const_charp message;
-+{
-+ SetISTR(ISTR_WARNING,"%s: libpng error: %s", fbasename, message);
-+
-+ longjmp(png_ptr->jmpbuf, 1);
-+}
-+
-+
-+/*******************************************/
-+static void
-+png_xv_warning(png_ptr, message)
-+ png_structp png_ptr;
-+ png_const_charp message;
-+{
-+ if (!png_ptr)
-+ return;
-+
-+ SetISTR(ISTR_WARNING,"%s: libpng warning: %s", fbasename, message);
-+}
-+
-+
-+/*******************************************/
-+void
-+VersionInfoPNG() /* GRR 19980605 */
-+{
-+ fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
-+ PNG_LIBPNG_VER_STRING, png_libpng_ver);
-+ fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
-+ ZLIB_VERSION, zlib_version);
-+}
-+
-+#endif /* HAVE_PNG */
-diff -u -r --new-file xv-3.10a.orig/xvvd.c xv-3.10a/xvvd.c
---- xv-3.10a.orig/xvvd.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvvd.c 2007-04-15 23:30:19.000000000 -0500
-@@ -0,0 +1,1101 @@
-+
-+/*
-+ * xvvd.c - extract archived file automatically and regard it as a
-+ * (virtual) directory.
-+ */
-+
-+#define NEEDSDIR
-+
-+#include "xv.h"
-+
-+#ifdef AUTO_EXPAND
-+
-+static void vd_Dirtovd PARM((char *));
-+static void vd_Vdtodir PARM((char *));
-+static int vd_Mkvdir PARM((char *));
-+static int vd_Rmvdir PARM((char *));
-+static int vd_Movevdir PARM((char *, char *));
-+static void vd_addvdtable PARM((char *));
-+static void vd_packvdtable PARM((void));
-+static int vd_recursive_mkdir PARM((char *));
-+static int vd_recursive_rmdir PARM((char *));
-+static void vd_optimize_path PARM((char *));
-+static int vd_ftype PARM((char *));
-+static int vd_compp PARM((char *, char *));
-+static int vd_UncompressFile PARM((char *, char *));
-+static int vd_tarc PARM((char *));
-+static u_int vd_tar_sumchk PARM((char *));
-+
-+#define VD_VDTABLESIZE 100
-+
-+#define VD_ERR -2
-+#define VD_UKN -1
-+
-+static char *ext_command[] = {
-+/* KEEP 0 */
-+ NULL,
-+#define VD_ARC 1
-+ "arc xo %s",
-+#define VD_ARJ 2
-+ "unarj x %s",
-+#define VD_LZH 3
-+ "lha -xf %s",
-+#define VD_TAR 4
-+ "tar xvf %s",
-+#define VD_ZIP 5
-+ "unzip -xo %s",
-+#define VD_ZOO 6
-+ "zoo xOS %s",
-+};
-+
-+int vdcount = 0;
-+
-+static char vdroot[MAXPATHLEN+1];
-+static char *vdtable[VD_VDTABLESIZE];
-+
-+/*
-+ * These functions initialize and settle virtual directory system.
-+ * Vdinit:
-+ * creates root of virtual directory.
-+ * Vdsettle:
-+ * sweeps virtual directories.
-+ */
-+void Vdinit()
-+{
-+#ifndef VMS
-+ char tmp[MAXPATHLEN+1];
-+
-+ xv_getwd(tmp, MAXPATHLEN+1);
-+ if (chdir(tmpdir)) {
-+ fprintf(stderr, "Warning: cannot chdir to tmpdir = '%s'.\n", tmpdir);
-+ fprintf(stderr,
-+ " I will use current directory '%s' instead of tmpdir.\n",
-+ tmp);
-+ }
-+ xv_getwd(vdroot, MAXPATHLEN+1);
-+ strcat(vdroot, "/.xvvdXXXXXX");
-+ chdir(tmp);
-+#else
-+ sprintf(vdroot, "Sys$Scratch:xvvdXXXXXX");
-+#endif /* VMS */
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(vdroot));
-+#else
-+ mktemp(vdroot);
-+#endif
-+
-+ if (!vd_recursive_mkdir(vdroot))
-+ tmpdir = vdroot;
-+}
-+
-+void Vdsettle()
-+{
-+ int i;
-+
-+ for (i = 0; i < vdcount; i++)
-+ free(vdtable[i]);
-+
-+ vdcount = 0;
-+
-+ vd_recursive_rmdir(vdroot);
-+}
-+
-+/*
-+ * This function chdir to virtual directory, if specified path is in
-+ * virtual directlry.
-+ */
-+int Chvdir(dir)
-+char *dir;
-+{
-+ char buf[MAXPATHLEN+1];
-+
-+ if (Mkvdir(dir) == VD_ERR)
-+ return -1;
-+
-+ strcpy(buf, dir);
-+ Dirtovd(buf);
-+
-+ return (chdir(buf));
-+}
-+
-+/*
-+ * These functions convert directory <-> virtual directory.
-+ * Dirtovd:
-+ * front interface of vd_Dirtovd.
-+ * vd_Dirtovd:
-+ * converts directory to virtual directory.
-+ * Vdtodir:
-+ * front interface of vd_Vdtodir.
-+ * vd_Vdtodir:
-+ * converts virtual directory to normal directory.
-+ * Dirtosubst:
-+ * converts directory to substance of archive.
-+ */
-+void Dirtovd(dir)
-+char *dir;
-+{
-+ vd_optimize_path(dir);
-+
-+ vd_Dirtovd(dir);
-+}
-+
-+static void vd_Dirtovd(dir)
-+char *dir;
-+{
-+ int i;
-+
-+ for (i = 0; i < vdcount; i++)
-+ if (!strncmp(dir, vdtable[i], strlen(vdtable[i]))) {
-+ char tmp[MAXPATHLEN+1];
-+
-+ sprintf(tmp, "%s%s", vdroot, dir);
-+ strcpy(dir, tmp);
-+ Dirtovd(dir);
-+ }
-+}
-+
-+void Vdtodir(dir)
-+char *dir;
-+{
-+ vd_optimize_path(dir);
-+
-+ vd_Vdtodir(dir);
-+}
-+
-+static void vd_Vdtodir(vd)
-+char *vd;
-+{
-+ int i;
-+ char tmp[MAXPATHLEN+1];
-+
-+ for (i = vdcount-1; i >= 0; i--) {
-+ sprintf(tmp, "%s%s", vdroot, vdtable[i]);
-+ if(!strncmp(vd, tmp, strlen(tmp))) {
-+ strcpy(tmp, vd+strlen(vdroot));
-+ strcpy(vd, tmp);
-+ Vdtodir(vd);
-+ }
-+ }
-+}
-+
-+void Dirtosubst(dir)
-+char *dir;
-+{
-+ char tmp[MAXPATHLEN+1];
-+
-+ Dirtovd(dir);
-+
-+ strcpy(tmp, dir+strlen(vdroot));
-+
-+ if (Isarchive(tmp))
-+ strcpy(dir, tmp);
-+}
-+
-+/*
-+ * These functions make virtual directory and extracts archive, if
-+ * specified path is archive.
-+ * Mkvdir:
-+ * front interface of vd_Mkvdir.
-+ * vd_Mkvdir:
-+ * does real work.
-+ * Mkvdir_force: (used by makeThumbDir(in xvbrowse.c) only)
-+ * make virtual directory by force.
-+ */
-+int Mkvdir(dir)
-+char *dir;
-+{
-+ char dir1[MAXPATHLEN+1], dir2[MAXPATHLEN+1];
-+ char *d1, *d2;
-+ int rv;
-+
-+#if defined(SYSV) || defined(SVR4) || defined(__USE_XOPEN_EXTENDED)
-+ sighold(SIGHUP);
-+ sighold(SIGCHLD);
-+#else
-+ int mask;
-+ mask = sigblock(sigmask(SIGHUP)|sigmask(SIGCHLD));
-+#endif
-+
-+ strcpy(dir1, dir);
-+ vd_optimize_path(dir1);
-+
-+ if ((rv = vd_Mkvdir(dir1)) != VD_ERR)
-+ goto MKVDIR_END;
-+
-+ strcpy(dir2, dir1);
-+ d2 = dir2 + strlen(dir2);
-+ while (rv == VD_ERR) {
-+ d2--;
-+ while (*d2 != '/')
-+ d2--;
-+ *d2 = '\0';
-+ rv = vd_Mkvdir(dir2);
-+ }
-+ d1 = dir1 + strlen(dir2);
-+ while ((rv != VD_ERR) && (*d1 != '\0')) {
-+ *d2++ = *d1++;
-+ while ((*d1 != '/') && (*d1 != '\0'))
-+ *d2++ = *d1++;
-+ *d2 = '\0';
-+ rv = vd_Mkvdir(dir2);
-+ }
-+
-+MKVDIR_END:
-+#if defined(SYSV) || defined(SVR4) || defined(__USE_XOPEN_EXTENDED)
-+ sigrelse(SIGHUP);
-+ sigrelse(SIGCHLD);
-+#else
-+ sigsetmask(mask);
-+#endif
-+
-+ return rv;
-+}
-+
-+static int vd_Mkvdir(dir)
-+char *dir;
-+{
-+ char dir1[MAXPATHLEN+1], dir2[MAXPATHLEN+1], tmp[MAXPATHLEN+1];
-+ int ftype, i;
-+ struct stat st;
-+ FILE *pfp;
-+
-+ strcpy(dir1, dir);
-+ Dirtovd(dir1);
-+ strcpy(dir2, dir1);
-+
-+ WaitCursor();
-+
-+ if ((ftype = vd_ftype(dir1)) < 0) {
-+ SetCursors(-1);
-+ return ftype;
-+ }
-+ if (ftype == RFT_COMPRESS) {
-+ if (!(ftype = vd_compp(dir1, tmp))) {
-+ SetCursors(-1);
-+ return ftype;
-+ }
-+ strcpy(dir1, tmp);
-+ }
-+
-+ if (!stat(dir1, &st)) {
-+ for(i = 0; i < vdcount; i++)
-+ if (!strcmp(vdtable[i], dir2)) {
-+ SetCursors(-1);
-+ return 0;
-+ }
-+
-+ if (!S_ISDIR(st.st_mode)) {
-+ char origdir[MAXPATHLEN+1], buf[MAXPATHLEN+10], buf1[100];
-+
-+ if (vdcount >= VD_VDTABLESIZE) {
-+ ErrPopUp("Sorry, you can't make virtual directory any more.",
-+ "\nBummer!");
-+ goto VD_MKVDIR_ERR;
-+ }
-+
-+ WaitCursor();
-+
-+ xv_getwd(origdir, MAXPATHLEN+1);
-+
-+ sprintf(tmp, "%s%s", vdroot, dir2);
-+ if (vd_recursive_mkdir(tmp) || chdir(tmp)) {
-+ SetISTR(ISTR_INFO, "fail to make virtual directory.");
-+ Warning();
-+ goto VD_MKVDIR_ERR;
-+ }
-+ sprintf(buf, ext_command[ftype], dir1);
-+
-+ WaitCursor();
-+
-+ if((pfp = popen(buf, "r")) == NULL) {
-+ SetISTR(ISTR_INFO, "fail to extract archive '%s'.",
-+ BaseName(dir2));
-+ Warning();
-+ goto VD_MKVDIR_ERR;
-+ }
-+ while (1) {
-+ if (fread(buf1, 1, sizeof(buf1), pfp) < sizeof(buf1))
-+ break;
-+ WaitCursor();
-+ }
-+ if (!feof(pfp)) {
-+ SetISTR(ISTR_INFO, "Pipe was broken.");
-+ Warning();
-+ pclose(pfp);
-+ goto VD_MKVDIR_ERR;
-+ }
-+ pclose(pfp);
-+
-+ if (strcmp(dir1, dir2))
-+ unlink(dir1);
-+
-+ vd_addvdtable(dir2);
-+ Dirtovd(origdir);
-+ chdir(origdir);
-+ SetCursors(-1);
-+ return 0;
-+
-+VD_MKVDIR_ERR:
-+ if (strcmp(dir1, dir2))
-+ unlink(dir1);
-+ SetCursors(-1);
-+ return VD_ERR;
-+ }
-+ }
-+ SetCursors(-1);
-+ return VD_ERR;
-+}
-+
-+#ifdef VIRTUAL_TD
-+void Mkvdir_force(dir)
-+char *dir;
-+{
-+ char tmp[MAXPATHLEN+1];
-+
-+ if (vdcount >= VD_VDTABLESIZE) {
-+ ErrPopUp("Sorry, you can't make virtual directory any more.",
-+ "\nBummer!");
-+ return;
-+ }
-+
-+ sprintf(tmp, "%s%s", vdroot, dir);
-+ if (vd_recursive_mkdir(tmp)) {
-+ SetISTR(ISTR_INFO, "Failed to make virtual directory.");
-+ Warning();
-+ return;
-+ }
-+
-+ vd_addvdtable(dir);
-+}
-+#endif /* VIRTUAL_TD */
-+
-+/*
-+ * These functions remove virtual directory, if exists.
-+ * Rmvdir:
-+ * front interface of vd_Rmvdir.
-+ * vd_Rmvdir:
-+ * remove virtual directory function.
-+ */
-+int Rmvdir(dir)
-+char *dir;
-+{
-+ int rv;
-+ char buf[MAXPATHLEN+1];
-+
-+ strcpy(buf, dir);
-+ vd_optimize_path(buf);
-+
-+ rv = vd_Rmvdir(buf);
-+ vd_packvdtable();
-+ return rv;
-+}
-+
-+static int vd_Rmvdir(dir)
-+char *dir;
-+{
-+ int i;
-+ char tmp[MAXPATHLEN+1];
-+
-+ for(i = 0; i < vdcount; i++)
-+ if (!strncmp(dir, vdtable[i], strlen(dir))) {
-+ sprintf(tmp, "%s%s", vdroot, vdtable[i]);
-+ if (vd_Rmvdir(tmp))
-+ return 1;
-+ if (vd_recursive_rmdir(tmp))
-+ return 1;
-+ vdtable[i][0] = '\0';
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * These functions move virtual directory, if exists.
-+ * Movevdir:
-+ * front interface of move virtual directory function.
-+ * vd_Movevdir:
-+ * does real work.
-+ */
-+int Movevdir(src, dst)
-+char *src, *dst;
-+{
-+/*
-+ char sbuf[MAXPATHLEN+1], dbuf[MAXPATHLEN+1];
-+
-+ strcpy(sbuf, src);
-+ vd_optimize_path(sbuf);
-+
-+ strcpy(dbuf, dst);
-+ vd_optimize_path(dbuf);
-+
-+ return (vd_Movevdir(sbuf, dbuf));
-+*/
-+ return (vd_Movevdir(src, dst));
-+}
-+
-+static int vd_Movevdir(src, dst)
-+char *src, *dst;
-+{
-+ int i;
-+ char *p, *pp;
-+ char tmp[MAXPATHLEN+1], tmps[MAXPATHLEN+1], tmpd[MAXPATHLEN+1];
-+
-+ for (i = 0; i < vdcount; i++)
-+ if (!strncmp(src, vdtable[i], strlen(src))) {
-+ sprintf(tmps, "%s%s", vdroot, vdtable[i]);
-+ sprintf(tmp, "%s%s", dst, vdtable[i]+strlen(src));
-+ sprintf(tmpd, "%s%s", vdroot, tmp);
-+
-+ if (vd_Movevdir(tmps, tmpd))
-+ return 1;
-+
-+ pp = vdtable[i];
-+ p = (char *) malloc(strlen(tmp)+1);
-+ strcpy(p, tmp);
-+ vdtable[i] = p;
-+
-+ strcpy(tmp, tmpd);
-+ for (p = tmp+strlen(tmp); *p != '/'; p--)
-+ ;
-+ *p = '\0';
-+
-+ if (vd_recursive_mkdir(tmp))
-+ goto VD_MOVEVDIR_ERR;
-+
-+ if (rename(tmps, tmpd) < 0)
-+ goto VD_MOVEVDIR_ERR;
-+
-+ free(pp);
-+ }
-+ return 0;
-+
-+VD_MOVEVDIR_ERR:
-+ free(vdtable[i]);
-+ vdtable[i] = pp;
-+ return 1;
-+}
-+
-+/*
-+ * These functions handle table of virtual directories.
-+ * vd_addvdtable:
-+ * adds virtual directory to table.
-+ * vd_packvdtable:
-+ * removes disused virtual directories from table.
-+ */
-+static void vd_addvdtable(vd)
-+char *vd;
-+{
-+ char *p;
-+ p = (char *) malloc(strlen(vd)+1);
-+ strcpy(p, vd);
-+ vdtable[vdcount] = p;
-+ vdcount++;
-+}
-+
-+static void vd_packvdtable()
-+{
-+ int i, j;
-+
-+ for (i = j = 0; i < vdcount; i++)
-+ if (vdtable[i][0] != '\0')
-+ vdtable[j++] = vdtable[i];
-+ else
-+ free(vdtable[i]);
-+
-+ vdcount = j;
-+}
-+
-+/*
-+ * These are utility functions.
-+ * vd_recursive_mkdir:
-+ * makes directories recursively.
-+ * vd_recursive_rmdir
-+ * removes directories recursively.
-+ */
-+static int vd_recursive_mkdir(dir)
-+char *dir;
-+{
-+ char buf[MAXPATHLEN+1], *p;
-+ struct stat st;
-+
-+ strcpy(buf, dir);
-+
-+ if (buf[strlen(buf) - 1] == '/')
-+ buf[strlen(buf) - 1] = '\0';
-+
-+ p = rindex(buf, '/');
-+ *p = '\0';
-+
-+ if (stat(buf, &st) < 0)
-+ if (vd_recursive_mkdir(buf) < 0)
-+ return (-1);
-+
-+ *p = '/';
-+ if (mkdir(buf, 0700) < 0)
-+ return (-1);
-+
-+ return (0);
-+}
-+
-+static int vd_recursive_rmdir(dir)
-+char *dir;
-+{
-+ char buf[MAXPATHLEN+1], buf2[MAXPATHLEN+1];
-+ DIR *dp;
-+ struct dirent *di;
-+
-+ strcpy(buf, dir);
-+
-+ if (buf[strlen(buf) - 1] == '/')
-+ buf[strlen(buf) - 1] = '\0';
-+
-+ if ((dp = opendir(buf)) == NULL)
-+ return (-1);
-+
-+ while ((di = readdir(dp)) != NULL) {
-+ struct stat st;
-+
-+ if (!strcmp(di->d_name, ".") || !strcmp(di->d_name, ".."))
-+ continue;
-+
-+ sprintf(buf2, "%s/%s", dir, di->d_name);
-+
-+ stat(buf2, &st);
-+ if (S_ISDIR(st.st_mode)) {
-+ if (vd_recursive_rmdir(buf2) < 0)
-+ goto VD_RECURSIVE_RMDIR_ERR;
-+ } else
-+ unlink(buf2);
-+ }
-+ if (rmdir(buf) < 0)
-+ goto VD_RECURSIVE_RMDIR_ERR;
-+
-+ closedir(dp);
-+ return (0);
-+
-+VD_RECURSIVE_RMDIR_ERR:
-+ closedir(dp);
-+ return (-1);
-+}
-+
-+/*
-+ * These functions test specified path.
-+ * Isarchive:
-+ * tests whether it's an archive?
-+ * Isvdir:
-+ * tests whether it's in the virtual directory?
-+ */
-+int Isarchive(path)
-+char *path;
-+{
-+ int ftype;
-+
-+ if ((ftype = vd_ftype(path)) < 0)
-+ return 0;
-+
-+ if (ftype == RFT_COMPRESS)
-+ if (!(ftype = vd_compp(path, NULL)))
-+ return 0;
-+
-+ return ftype;
-+}
-+
-+int Isvdir(path)
-+char *path;
-+{
-+ int rv = 0;
-+ char tmp1[MAXPATHLEN+1], tmp2[MAXPATHLEN+1];
-+ int archive1, archive2;
-+
-+ strcpy(tmp1, path);
-+ strcpy(tmp2, path);
-+
-+ vd_optimize_path(tmp1);
-+ Dirtovd(tmp2);
-+
-+ archive1 = Isarchive(tmp1);
-+ archive2 = Isarchive(tmp2);
-+
-+ if (strcmp(tmp1, tmp2)) {
-+ char tmp3[MAXPATHLEN+1], tmp4[MAXPATHLEN+1];
-+ int archive3, archive4;
-+
-+ sprintf(tmp3, "%s%s", vdroot, tmp1);
-+ strcpy(tmp4, tmp2+strlen(vdroot));
-+
-+ archive3 = Isarchive(tmp3);
-+ archive4 = Isarchive(tmp4);
-+
-+ if (archive4 && !strcmp(tmp1, tmp4)) {
-+ rv |= 06;
-+ return rv;
-+ }
-+ rv |= 01;
-+ if (archive2)
-+ rv |= 02;
-+ else if (archive4)
-+ rv |= 06;
-+ return rv;
-+ }
-+ if (archive1)
-+ rv |= 02;
-+
-+ return rv;
-+}
-+
-+/*
-+ * This function optimizes given path.
-+ * Expand '~' to home directory and removes '.', and treat '..'.
-+ */
-+static void vd_optimize_path(path)
-+char *path;
-+{
-+ char *tmp, *reserve;
-+
-+ if (!strcmp(path, STDINSTR))
-+ return;
-+
-+ if (*path == '\0') {
-+ xv_getwd(path, MAXPATHLEN+1);
-+ return;
-+ }
-+ if (*path == '~')
-+ Globify(path);
-+ if (*path != '/') {
-+ char tmp[MAXPATHLEN+1];
-+
-+ strcpy(tmp, path);
-+ xv_getwd(path, MAXPATHLEN+1);
-+ strcat(path, "/");
-+ strcat(path, tmp);
-+ }
-+
-+ reserve = tmp = path;
-+ while(*path != '\0') {
-+ if (*path == '/') {
-+ *tmp++ = *path;
-+ while (*++path == '/')
-+ ;
-+ continue;
-+ }
-+ if ((*path == '.') && (*(path-1) == '/')) {
-+ if (*(path+1) == '/') {
-+ tmp--;
-+ path++;
-+ continue;
-+ } else if (*(path+1) == '\0') {
-+ tmp--;
-+ break;
-+ } else if (*(path+1) == '.') {
-+ if (*(path+2) == '/') {
-+ if ((tmp - reserve) > 1)
-+ for (tmp-=2; (*tmp != '/'); tmp--)
-+ ;
-+ else
-+ tmp = reserve;
-+ path+=2;
-+ continue;
-+ } else if (*(path+2) == '\0') {
-+ if ((tmp - reserve) > 1)
-+ for (tmp-=2; (*tmp != '/'); tmp--)
-+ ;
-+ else
-+ tmp = reserve+1;
-+ break;
-+ }
-+ }
-+ }
-+ *tmp++ = *path++;
-+ }
-+ if (((tmp - reserve) > 1) && *(tmp-1) == '/')
-+ tmp--;
-+ if (tmp == reserve)
-+ *tmp++ = '/';
-+
-+ *tmp = '\0';
-+}
-+
-+/*
-+ * These functions detect file type.
-+ */
-+static int vd_ftype(fname)
-+char *fname;
-+{
-+ /* check archive type */
-+
-+ FILE *fp;
-+ byte magicno[30]; /* first 30 bytes of file */
-+ int rv, n;
-+ struct stat st;
-+
-+ if (!fname) return VD_ERR; /* shouldn't happen */
-+
-+ if ((!stat(fname, &st)) && (st.st_mode & S_IFMT) == S_IFDIR)
-+ return VD_UKN;
-+ fp = xv_fopen(fname, "r");
-+ if (!fp) return VD_ERR;
-+
-+ n = fread(magicno, (size_t) 1, (size_t) 30, fp);
-+ fclose(fp);
-+
-+ if (n<30) return VD_UKN; /* files less than 30 bytes long... */
-+
-+ rv = VD_UKN;
-+
-+ if (magicno[0] == 0x60 && magicno[1]==0xea) rv = VD_ARJ;
-+
-+ else if (magicno[2] == '-' && magicno[3] == 'l' &&
-+ magicno[4] == 'h') rv = VD_LZH;
-+
-+ else if (strncmp((char *) magicno,"PK", (size_t) 2)==0) rv = VD_ZIP;
-+
-+ else if (magicno[20]==0xdc && magicno[21]==0xa7 &&
-+ magicno[22]==0xc4 && magicno[23]==0xfd) rv = VD_ZOO;
-+
-+ else if (vd_tarc(fname)) rv = VD_TAR;
-+
-+ else if (magicno[0]==0x1f && magicno[1]==0x9d) rv = RFT_COMPRESS;
-+
-+ else if (!strncmp((char *) &magicno[11], "MAJYO", (size_t) 5))
-+ rv = VD_UKN; /* XXX */
-+
-+ else if (magicno[0] == 26) rv = VD_ARC;
-+
-+#ifdef GUNZIP
-+ else if (magicno[0]==0x1f && magicno[1]==0x8b) rv = RFT_COMPRESS;/* gzip */
-+ else if (magicno[0]==0x1f && magicno[1]==0x9e) rv = RFT_COMPRESS;/* old */
-+ else if (magicno[0]==0x1f && magicno[1]==0x1e) rv = RFT_COMPRESS;/* pack */
-+#endif
-+
-+ return rv;
-+}
-+
-+static int vd_compp(path, newpath)
-+char *path, *newpath;
-+{
-+ /*
-+ * uncompress and check archive type.
-+ *
-+ * If newpath is NULL, uncompress only 512 byte of 'path' and
-+ * check archive type, so it is for SPEED-UP strategy.
-+ * In this case, caller this function does not have to unlink
-+ * tempoary file.
-+ * Unfortunately it does not work in VMS system.
-+ */
-+
-+ int file_type, r;
-+ char uncompname[128], basename[128];
-+ int comptype;
-+
-+ if (newpath) *newpath = '\0';
-+ strncpy(basename, path, 127);
-+ comptype = ReadFileType(path);
-+#if (defined(VMS) && !defined(GUNZIP))
-+ /* VMS decompress doesn't like the file to have a trailing .Z in fname
-+ however, GUnZip is OK with it, which we are calling UnCompress */
-+ *rindex (basename, '.') = '\0';
-+#endif
-+#ifdef VMS
-+ if (UncompressFile(basename, uncompname)) {
-+#else
-+ if (newpath == NULL)
-+ r = vd_UncompressFile(basename, uncompname);
-+ else
-+ r = UncompressFile(basename, uncompname, comptype);
-+ if (r) {
-+#endif
-+ if ((file_type = vd_ftype(uncompname)) < 0) {
-+ unlink(uncompname);
-+ return 0;
-+ }
-+ if (newpath) strcpy(newpath, uncompname);
-+ else unlink(uncompname);
-+ } else {
-+ return 0;
-+ }
-+ return file_type;
-+}
-+
-+#define HEADERSIZE 512
-+
-+static void vd_Dirtovd PARM((char *));
-+static int stderr_on PARM((void));
-+static int stderr_off PARM((void));
-+static FILE *popen_nul PARM((char *, char *));
-+
-+static int vd_UncompressFile(name, uncompname)
-+char *name, *uncompname;
-+{
-+ /* Yap, I`m nearly same as original `UncompnameFile' function, but,
-+ 1) I extract `name' file ONLY first 512 byte.
-+ 2) I'm called only from UNIX and UNIX like OS, *NOT* VMS */
-+ /* returns '1' on success, with name of uncompressed file in uncompname
-+ returns '0' on failure */
-+
-+ char namez[128], *fname, buf[512], tmp[HEADERSIZE];
-+ int n, tmpfd;
-+ FILE *pfp, *tfp;
-+
-+ fname = name;
-+ namez[0] = '\0';
-+
-+
-+#ifndef GUNZIP
-+ /* see if compressed file name ends with '.Z'. If it *doesn't*, we need
-+ to temporarily rename it so it *does*, uncompress it, and rename it
-+ *back* to what it was. necessary because uncompress doesn't handle
-+ files that don't end with '.Z' */
-+
-+ if (strlen(name) >= (size_t) 2 &&
-+ strcmp(name + strlen(name)-2,".Z")!=0 &&
-+ strcmp(name + strlen(name)-2,".z")!=0) {
-+ strcpy(namez, name);
-+ strcat(namez,".Z");
-+
-+ if (rename(name, namez) < 0) {
-+ sprintf(buf, "Error renaming '%s' to '%s': %s",
-+ name, namez, ERRSTR(errno));
-+ ErrPopUp(buf, "\nBummer!");
-+ return 0;
-+ }
-+
-+ fname = namez;
-+ }
-+#endif /* not GUNZIP */
-+
-+ sprintf(uncompname, "%s/xvuXXXXXX", tmpdir);
-+#ifdef USE_MKSTEMP
-+ tmpfd = mkstemp(uncompname);
-+#else
-+ mktemp(uncompname);
-+#endif
-+
-+ sprintf(buf,"%s -c %s", UNCOMPRESS, fname);
-+ SetISTR(ISTR_INFO, "Uncompressing Header '%s'...", BaseName(fname));
-+ if ((pfp = popen_nul(buf, "r")) == NULL) {
-+ SetISTR(ISTR_INFO, "Cannot extract for archive '%s'.",
-+ BaseName(fname));
-+ Warning();
-+#ifdef USE_MKSTEMP
-+ if (tmpfd >= 0)
-+ close(tmpfd);
-+#endif
-+ return 0;
-+ }
-+#ifdef USE_MKSTEMP
-+ if (tmpfd < 0)
-+#else
-+ if ((tmpfd = open(uncompname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR)) < 0)
-+#endif
-+ {
-+ SetISTR(ISTR_INFO, "Unable to create temporary file.",
-+ BaseName(uncompname));
-+ Warning();
-+ pclose(pfp);
-+ }
-+ if ((tfp = fdopen(tmpfd, "w")) == NULL) {
-+ SetISTR(ISTR_INFO, "Unable to create temporary file.",
-+ BaseName(uncompname));
-+ Warning();
-+ close(tmpfd);
-+ pclose(pfp);
-+ return 0;
-+ }
-+ if ((n = fread(tmp, 1, sizeof(tmp), pfp)) != HEADERSIZE) {
-+ SetISTR(ISTR_INFO, "Unable to read '%s'.",
-+ BaseName(fname));
-+ Warning();
-+ pclose(pfp);
-+ fflush(tfp);
-+ fclose(tfp);
-+ close(tmpfd);
-+ return 0;
-+ }
-+ fwrite(tmp, 1, n, tfp);
-+ fflush(tfp);
-+ fclose(tfp);
-+ close(tmpfd);
-+ pclose(pfp);
-+
-+ /* if we renamed the file to end with a .Z for the sake of 'uncompress',
-+ rename it back to what it once was... */
-+
-+ if (strlen(namez)) {
-+ if (rename(namez, name) < 0) {
-+ sprintf(buf, "Error renaming '%s' to '%s': %s",
-+ namez, name, ERRSTR(errno));
-+ ErrPopUp(buf, "\nBummer!");
-+ }
-+ }
-+
-+ return 1;
-+}
-+
-+#define TARBLOCK 512
-+#define CKSTART 148 /* XXX */
-+#define CKSIZE 8
-+
-+/*
-+ * Tar file: 1, other: 0
-+ */
-+static int vd_tarc(fname)
-+char *fname;
-+{
-+ FILE *fp;
-+ unsigned int sum;
-+ char *ckp, buf[TARBLOCK];
-+
-+ if ((fp = fopen(fname, "r")) == NULL)
-+ return 0;
-+
-+ fread(buf, TARBLOCK, 1, fp);
-+ fclose(fp);
-+
-+ for (sum = 0, ckp = buf + CKSTART;
-+ (ckp < buf + CKSTART + CKSIZE) && *ckp != '\0';
-+ ckp++) {
-+ sum *= 8;
-+ if (*ckp == ' ')
-+ continue;
-+ if (*ckp < '0' || '7' < *ckp)
-+ return 0;
-+ sum += *ckp - '0';
-+ }
-+ if (sum != vd_tar_sumchk(buf))
-+ return 0;
-+
-+ return 1;
-+}
-+
-+static unsigned int vd_tar_sumchk(buf)
-+char *buf;
-+{
-+ int i;
-+ unsigned int sum = 0;
-+
-+ for (i = 0; i < CKSTART; i++) {
-+ sum += *(buf + i);
-+ }
-+ sum += ' ' * 8;
-+ for (i += 8; i < TARBLOCK; i++) {
-+ sum += *(buf + i);
-+ }
-+ return sum;
-+}
-+
-+
-+static int stde = -1; /* fd of stderr */
-+static int nul = -1; /* fd of /dev/null */
-+
-+/*
-+ * switch off the output to stderr(bypass to /dev/null).
-+ */
-+static int stderr_off()
-+{
-+ if (nul < 0)
-+ nul = open("/dev/null", O_RDONLY);
-+ if (nul < 0) {
-+ fprintf(stderr, "/dev/null open failure\n");
-+ return -1;
-+ }
-+ if (stde < 0)
-+ stde = dup(2);
-+ if (stde < 0) {
-+ fprintf(stderr, "duplicate stderr failure\n");
-+ return -1;
-+ }
-+ close(2);
-+ dup(nul);
-+ return 0;
-+}
-+
-+/*
-+ * turn on stderr output.
-+ */
-+static int stderr_on()
-+{
-+ if ((stde < 0) || (nul < 0)) {
-+ fprintf(stderr, "stderr_on should call after stderr_off\n");
-+ return -1;
-+ }
-+ close(2);
-+ dup(stde);
-+ return 0;
-+}
-+
-+/*
-+ * popen with no output to stderr.
-+ */
-+static FILE *popen_nul(prog, mode)
-+char *prog, *mode;
-+{
-+ FILE *fp;
-+
-+ stderr_off();
-+ fp = popen(prog, mode);
-+ stderr_on();
-+ return fp;
-+}
-+
-+/*
-+ * These functions are for SIGNAL.
-+ * If XV end by C-c, there are dust of directory which name is .xvvd???,
-+ * made by xvvd. Then, I handle SIGINT, and add good finish.
-+ */
-+void vd_HUPhandler()
-+{
-+#if defined(SYSV) || defined(SVR4) || defined(__USE_XOPEN_EXTENDED)
-+ sighold(SIGHUP);
-+#else
-+ int mask;
-+ mask = sigblock(sigmask(SIGHUP));
-+#endif
-+
-+ Vdsettle();
-+
-+#if defined(SYSV) || defined(SVR4) || defined(__USE_XOPEN_EXTENDED)
-+ sigrelse(SIGHUP);
-+ signal(SIGHUP, (void (*)PARM((int))) vd_HUPhandler);
-+#else
-+ sigsetmask(mask);
-+#endif
-+}
-+
-+void vd_handler(sig)
-+int sig;
-+{
-+#if defined(SYSV) || defined(SVR4) || defined(__USE_XOPEN_EXTENDED)
-+ sighold(sig);
-+#else
-+ sigblock(sigmask(sig));
-+#endif
-+
-+ Quit(1); /*exit(1);*/
-+}
-+
-+int vd_Xhandler(disp,event)
-+Display *disp;
-+XErrorEvent *event;
-+{
-+ Quit(1); /*exit(1);*/
-+ return (1); /* Not reached */
-+}
-+
-+int vd_XIOhandler(disp)
-+Display *disp;
-+{
-+ fprintf(stderr, "XIO fatal IO error ? (?) on X server\n");
-+ fprintf(stderr, "You must exit normally in xv usage.\n");
-+ Quit(1); /*exit(1);*/
-+ return (1); /* Not reached */
-+}
-+
-+void vd_handler_setup()
-+{
-+ signal(SIGHUP, (void (*)PARM((int))) vd_HUPhandler);
-+ signal(SIGINT, (void (*)PARM((int))) vd_handler);
-+ signal(SIGTERM,(void (*)PARM((int))) vd_handler);
-+
-+ (void)XSetErrorHandler(vd_Xhandler);
-+ (void)XSetIOErrorHandler(vd_XIOhandler);
-+}
-+#endif /* AUTO_EXPAND */
-diff -u -r --new-file xv-3.10a.orig/xvwbmp.c xv-3.10a/xvwbmp.c
---- xv-3.10a.orig/xvwbmp.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvwbmp.c 2007-04-15 23:38:05.000000000 -0500
-@@ -0,0 +1,345 @@
-+/*
-+ * xvwbmp.c - i/o routings for WBMP files
-+ * defined by OMA (http://www.openmobilealliance.com)
-+ * as a standard for images for micro devices.
-+ *
-+ * exports :
-+ *
-+ * LoadWBMP(fname, numcols);
-+ * WriteWBMP(fp, pic, ptype, w, h, r, g, b, numcols, style);
-+ *
-+ * author: Pawel S. Veselov
-+ * http://manticore.2y.net/
-+ *
-+ */
-+
-+#include "xv.h"
-+
-+typedef short int16;
-+typedef unsigned char uint8;
-+typedef unsigned short uint16; /* sizeof (uint16) must == 2 */
-+#if defined(__alpha) || _MIPS_SZLONG == 64
-+typedef int int32;
-+typedef unsigned int uint32; /* sizeof (uint32) must == 4 */
-+#else
-+typedef long int32;
-+typedef unsigned long uint32; /* sizeof (uint32) must == 4 */
-+#endif
-+
-+#define MUST(a) if (!(a)) {\
-+ close(fd); \
-+ return fail(st_fname, st_err); }
-+#define READU8(fd,u) if ((read(fd, &u, 1)<1)) {\
-+ myfree(); \
-+ close(fd); \
-+ return fail(st_fname, err_ueof); }
-+#define SREADU8(fd, u) if ((read(fd, &u, 1,)<1)) {\
-+ { st_err = err_ueof; return 0; }
-+
-+#define SREADC(fd, str, l) { \
-+ str = (char*)mymalloc(l); \
-+ if (!str) { \
-+ myfree(); \
-+ FatalError("LoadWBMP: can't malloc extension buffer"); \
-+ } \
-+ if (read(fd, str, l)r[0] = 0;
-+ pinfo->g[0] = 0;
-+ pinfo->b[0] = 0;
-+ pinfo->r[1] = 255;
-+ pinfo->g[1] = 255;
-+ pinfo->b[1] = 255;
-+
-+ pinfo->pic = render1(raw, raw_size, npixels);
-+ pinfo->type = PIC8;
-+
-+ pinfo->w = pinfo->normw = width;
-+ pinfo->h = pinfo->normh = height;
-+ pinfo->frmType = F_BWDITHER;
-+
-+ sprintf(pinfo->fullInfo, "WBMP, 1 bit per pixel, %d bytes", raw_size);
-+ sprintf(pinfo->shrtInfo, "%dx%d WBMP (WAP/OMA).", width, height);
-+ pinfo->comment = (char*)NULL;
-+
-+ close(fd);
-+
-+ myfree();
-+ return 1;
-+}
-+
-+
-+int WriteWBMP(fp, pic, ptype, w, h, rmap, gmap, bmap, numcols, colorstyle)
-+ FILE *fp;
-+ byte *pic;
-+ int ptype, w, h;
-+ byte *rmap, *gmap, *bmap;
-+ int numcols, colorstyle;
-+{
-+ int count = 0;
-+ uint8 bit = 0;
-+ int i;
-+
-+ write_mb(0, fp); /* type : always 0 */
-+ putc(0, fp); /* fixed header : always 0 for type 0 */
-+ write_mb((uint32)w, fp);
-+ write_mb((uint32)h, fp);
-+
-+ /* ready to write data */
-+
-+ for (i=0; i> (no*7)) & 0x7f);
-+ putc(value, f);
-+ } while ((no--)>0);
-+
-+}
-+
-+
-+static int read_mb(dst, fd)
-+ int *dst, fd;
-+{
-+ int ac = 0;
-+ int ct = 0;
-+
-+ while (1) {
-+ uint8 bt;
-+ if ((ct++)==6) {
-+ st_err = err_inmb;
-+ return 0;
-+ }
-+
-+ if ((read(fd, &bt, 1)) < 1) {
-+ st_err = err_ueof;
-+ return 0;
-+ }
-+ ac = (ac << 7) | (bt & 0x7f); /* accumulates up to 42 bits?? FIXME */
-+ if (!(bt & 0x80))
-+ break;
-+ }
-+ *dst = ac;
-+ return 1;
-+}
-+
-+
-+static int read_ext(fd, fixed)
-+ int fd;
-+ uint8 fixed;
-+{
-+ if (!(fixed&0x7f)) { /* no extensions */
-+ return 1;
-+ }
-+
-+ /*
-+ * The only described type is WBMP 0, that must not
-+ * have extensions.
-+ */
-+
-+ st_err = err_extf;
-+ return 0;
-+
-+ /*
-+
-+ fixed = (fixed >> 5)&0x3;
-+
-+ switch (fixed) {
-+ case 0:
-+ while (true) {
-+ SREADU8(fd, fixed);
-+ if (!(fixed & 0x7f)) { break; }
-+ }
-+ break;
-+ case 0x3:
-+ {
-+ char * par;
-+ char * val;
-+ SREADU8(fd, fixed);
-+ SREADC(fd, par, (fixed>>4)&0x6);
-+ SREADC(fd, val, fixed&0xf);
-+ }
-+ break;
-+ }
-+ */
-+}
-+
-+
-+static void *mymalloc(numbytes)
-+ int numbytes;
-+{
-+ mymem = (void**)realloc(mymem, mymems+1);
-+ if (!mymem)
-+ FatalError("LoadWBMP: can't realloc buffer");
-+ return (mymem[mymems++] = malloc(numbytes));
-+}
-+
-+
-+static void myfree()
-+{
-+ int i;
-+
-+ if (mymem) {
-+ for (i=0; i>7)&1;
-+
-+ if ((++cnt)==8) {
-+ cb = *(++data);
-+ cnt = 0;
-+ } else {
-+ cb <<=1;
-+ }
-+ }
-+ return pic;
-+}
-diff -u -r --new-file xv-3.10a.orig/xvzx.c xv-3.10a/xvzx.c
---- xv-3.10a.orig/xvzx.c 1969-12-31 18:00:00.000000000 -0600
-+++ xv-3.10a/xvzx.c 2007-05-13 19:53:46.000000000 -0500
-@@ -0,0 +1,349 @@
-+/*
-+ * xvzx.c - load routine for Spectrum screen$
-+ *
-+ * John Elliott, 7 August 1998
-+ *
-+ * LoadZX(fname, pinfo) - load file
-+ * WriteZX(fp,pic,ptype,w,h,r,g,b,numcols,style,cmt,comment) - convert to
-+ * 256x192 SCREEN$ and save.
-+ */
-+
-+#include "copyright.h"
-+
-+#include "xv.h"
-+
-+
-+
-+/*
-+ * comments on error handling:
-+ * a file with a bad header checksum is a warning error.
-+ *
-+ * not being able to malloc is a Fatal Error. The program is aborted.
-+ */
-+
-+
-+#define TRUNCSTR "File appears to be truncated."
-+
-+static int zxError PARM((const char *, const char *));
-+
-+static const char *bname;
-+
-+/*******************************************/
-+int LoadZX(fname, pinfo)
-+ char *fname;
-+ PICINFO *pinfo;
-+/*******************************************/
-+{
-+ /* returns '1' on success */
-+
-+ FILE *fp;
-+ unsigned int c, c1;
-+ int x,y, trunc;
-+ byte *zxfile;
-+
-+ bname = BaseName(fname);
-+
-+ pinfo->pic = (byte *) NULL;
-+ pinfo->comment = (char *) NULL;
-+
-+ /* Allocate memory for a 256x192x8bit image */
-+
-+ pinfo->pic = (byte *)malloc(256*192);
-+ if (!pinfo->pic) FatalError("malloc failure in xvzx.c LoadZX");
-+
-+ /* Allocate 1B80h bytes and slurp the whole file into memory */
-+
-+ zxfile = (byte *)malloc(7040);
-+ if (!zxfile) FatalError("malloc failure in xvzx.c LoadZX");
-+
-+ /* open the file */
-+ fp = xv_fopen(fname,"r");
-+ if (!fp) return (zxError(bname, "can't open file"));
-+
-+ /* Load it in en bloc */
-+ memset(zxfile, 0, 7040);
-+ if (fread(zxfile, 1, 7040, fp) < 7040) trunc = 1;
-+
-+ /* Transform to 8-bit */
-+
-+ for (y = 0; y < 192; y++) for (x = 0; x < 256; x++)
-+ {
-+ /* Spectrum screen layout: three 2k segments at y=0, y=64, y=128 */
-+ /* In each segment: Scan lines 0,8,16,...,56,1,9,...,57 etc. Each
-+ scanline is 32 bytes, so line 1 is 256 bytes after line 0
-+
-+ So address of line start is ((y>>6) * 2048) + ((y & 7) * 256)
-+ + ((y & 0x38) * 4)
-+
-+ The colour byte for a cell is at screen + 6k + (y >> 3)*32 + (x>>3)
-+
-+ */
-+
-+ int offset;
-+ byte *dst = pinfo->pic + 256*y + x;
-+ byte attr, pt, mask;
-+
-+ offset = (y >> 6) * 2048;
-+ offset += (y & 7) * 256;
-+ offset += (y & 0x38) * 4;
-+ offset += (x >> 3);
-+
-+ pt = zxfile[offset + 128]; /* Ink/paper map */
-+
-+ offset = 0x1880;
-+ offset += (y >> 3) * 32;
-+ offset += (x >> 3);
-+
-+ attr = zxfile[offset]; /* Colours for cell */
-+
-+ mask = 0x80;
-+
-+ if (x & 7) mask >>= (x & 7);
-+
-+ if (pt & mask) *dst = attr & 7; /* Ink */
-+ else *dst = (attr >> 3) & 7; /* Paper */
-+
-+ if (attr & 0x40) *dst |= 8; /* High intensity */
-+ }
-+
-+ /* Picture bytes converted; now build the colour maps */
-+
-+ pinfo->normw = pinfo->w = 256;
-+ pinfo->normh = pinfo->h = 192;
-+ pinfo->type = PIC8;
-+
-+ for (c = 0; c < 16; c++)
-+ {
-+ if (c < 8) c1 = 192; else c1 = 255; /* low-intensity colours use 192 */
-+ /* high-intensity colours use 255 */
-+ pinfo->b[c] = (c & 1 ? c1 : 0);
-+ pinfo->r[c] = (c & 2 ? c1 : 0);
-+ pinfo->g[c] = (c & 4 ? c1 : 0);
-+ }
-+
-+ pinfo->colType = F_FULLCOLOR;
-+ pinfo->frmType = F_ZX; /* Save as SCREEN$ */
-+ sprintf(pinfo->fullInfo, "Spectrum SCREEN$, load address %04x",
-+ zxfile[16]+256*zxfile[17]);
-+ strcpy(pinfo->shrtInfo, "Spectrum SCREEN$.");
-+
-+ /* Almost as an afterthought, check that the +3DOS header is valid.
-+
-+ If it isn't, then odds are that the file isn't a graphic. But it
-+ had the right magic number, so it might be. Let them see it anyway.
-+
-+ The check is: Byte 127 of the header should be the 8-bit sum of bytes
-+ 0-126 of the header. The header should also have the
-+ +3DOS magic number, but we know it does or we wouldn't
-+ have got this far.
-+ */
-+
-+ c1 = 0;
-+ for (c1 = c = 0; c < 127; c++) c1 = ((c1 + zxfile[c]) & 0xFF);
-+ if (c1 != zxfile[127]) zxError(bname, "Bad header checksum.");
-+
-+ fclose(fp);
-+ free(zxfile);
-+ return 1;
-+}
-+
-+
-+
-+
-+
-+/*******************************************/
-+static int zxError(fname, st)
-+ const char *fname, *st;
-+{
-+ SetISTR(ISTR_WARNING,"%s: %s", fname, st);
-+ return 0;
-+}
-+
-+
-+/* Spectrum screen file header. The first 18 bytes are used in the magic
-+ number test */
-+
-+byte ZXheader[128] =
-+{
-+ 'P', 'L', 'U', 'S', '3', 'D', 'O', 'S', 26, /* Spectrum +3DOS file */
-+ 1, 0, /* Header type 1.0 */
-+ 128, 27, 0, 0, /* 7040 bytes */
-+ 3, /* Binary format */
-+ 0, 27, /* 6912 data bytes */
-+ 0, 64 /* load address 0x4000 */
-+};
-+
-+
-+
-+/* Get the Spectrum colour/bright byte (0-15) from a pixel */
-+
-+static int PointZX(pic, w, h, rmap, gmap, bmap, x, y)
-+ byte *pic;
-+ int w,h;
-+ byte *rmap, *gmap, *bmap;
-+ int x,y;
-+{
-+ int index, r, g, b, zxc;
-+
-+ /* If the picture is smaller than the screen, pad out the edges
-+ with "bright black" - a colour not otherwise returned */
-+
-+ if (x >= w || y >= h) return 8;
-+
-+ /* Get colour index */
-+
-+ index = pic[y*w + x];
-+
-+ /* Convert to rgb */
-+
-+ r = rmap[index];
-+ g = gmap[index];
-+ b = bmap[index];
-+ zxc = 0;
-+
-+ /* Work out Spectrum colour by a simplistic "nearest colour" method */
-+
-+ if (b >= 160) zxc |= 1; /* Blue */
-+ if (r >= 160) zxc |= 2; /* Red */
-+ if (g >= 160) zxc |= 4; /* Green */
-+ if (r > 208 || g >= 208 || b >= 208) zxc |= 8; /* High intensity */
-+
-+ return zxc;
-+}
-+
-+
-+/* Work out what colours should be used in a cell */
-+
-+static void CellZX(pic, w, h, rmap, gmap, bmap, cx, cy, zxfile)
-+ byte *pic;
-+ int w,h;
-+ byte *rmap, *gmap, *bmap;
-+ int cx,cy;
-+ byte *zxfile;
-+{
-+ byte counts[16]; /* Count of no. of colours */
-+ int offset, ink, paper, n, m, x, y, x0, y0, di, dp;
-+
-+ x0 = cx * 8; /* Convert from cell to pixel coords */
-+ y0 = cy * 8;
-+
-+ for (n = 0; n < 16; n++) counts[n] = 0; /* Reset all counts */
-+
-+ /* Count no. of pixels of various colours */
-+
-+ for (y = y0; y < y0+8; y++) for (x = x0; x < x0+8; x++)
-+ {
-+ m = PointZX(pic, w, h, rmap, gmap, bmap, x, y);
-+
-+ counts[m]++;
-+ }
-+ counts[8] = 0; /* Discard Bright Black (pixels not in the picture area)
-+ */
-+
-+ /* Assign the most popular colour as ink */
-+ for (n = m = ink = 0; n < 16; n++) if (counts[n] > m)
-+ {
-+ ink = n;
-+ m = counts[n];
-+ }
-+ counts[ink] = 0;
-+
-+ /* Assign the next most popular colour as paper */
-+ for (n = m = paper = 0; n < 16; n++) if (counts[n] > m)
-+ {
-+ paper = n;
-+ m = counts[n];
-+ }
-+ /* We have ink and paper. Set cell's attributes */
-+
-+ offset = cy*32 + cx + 0x1880;
-+
-+ /* Set the high-intensity bit if ink is high-intensity */
-+ if (ink & 8) zxfile[offset] = 0x40; else zxfile[offset] = 0;
-+ zxfile[offset] |= ((paper & 7) << 3);
-+ zxfile[offset] |= (ink & 7);
-+
-+ /* Plot the points */
-+ for (y = y0; y < y0+8; y++)
-+ {
-+ byte mask = 0x80;
-+
-+ offset = (y >> 6) * 2048;
-+ offset += (y & 7) * 256;
-+ offset += (y & 0x38) * 4;
-+ offset += (x0 >> 3);
-+
-+ for (x = x0; x < x0+8; x++)
-+ {
-+ /* Work out whether the point should be plotted as ink or
-+ paper */
-+ m = PointZX(pic, w, h, rmap, gmap, bmap, x, y);
-+
-+ di = (ink & 7) - (m & 7); /* "Difference" from ink */
-+ dp = (paper & 7) - (m & 7); /* "Difference" from paper */
-+
-+ if (di < 0) di = -di;
-+ if (dp < 0) dp = -dp;
-+
-+ if (di < dp) /* Point is more like ink */
-+ zxfile[offset+128] |= mask;
-+
-+ mask = (mask >> 1);
-+ }
-+ }
-+
-+}
-+
-+
-+
-+/*******************************************/
-+int WriteZX(fp,pic,ptype,w,h,rmap,gmap,bmap,numcols,colorstyle,comment)
-+ FILE *fp;
-+ byte *pic;
-+ int ptype, w,h;
-+ byte *rmap, *gmap, *bmap;
-+ int numcols, colorstyle;
-+ char *comment;
-+{
-+ int rv, x, y;
-+ byte *zxfile;
-+ byte *pic8;
-+ byte rtemp[256],gtemp[256],btemp[256];
-+
-+ /* To simplify matters, reduce 24-bit to 8-bit. Since the Spectrum
-+ screen is 3.5-bit anyway, it doesn't make much difference */
-+
-+ if (ptype == PIC24)
-+ {
-+ pic8 = Conv24to8(pic, w, h, 256, rtemp,gtemp,btemp);
-+ if (!pic8) FatalError("Unable to malloc in WriteZX()");
-+ rmap = rtemp; gmap = gtemp; bmap = btemp; numcols=256;
-+ }
-+ else pic8 = pic;
-+
-+ ZXheader[127] = 0x71; /* The correct checksum. */
-+
-+ /* Create a memory image of the SCREEN$ */
-+
-+ zxfile = (byte *)malloc(7040);
-+ if (!zxfile) FatalError("malloc failure in xvzx.c WriteZX");
-+
-+ memset(zxfile, 0, 7040); /* Reset all points to black */
-+ memcpy(zxfile, ZXheader, 128); /* Create +3DOS header */
-+
-+ /* Convert the image, character cell by character cell */
-+ for (y = 0; y < 24; y++) for (x = 0; x < 32; x++)
-+ {
-+ CellZX(pic8, w, h, rmap, gmap, bmap, x, y, zxfile);
-+ }
-+ rv = 0;
-+ if (fwrite(zxfile, 1, 7040, fp) < 7040) rv = -1;
-+
-+ if (ptype == PIC24) free(pic8);
-+ free(zxfile);
-+
-+ if (ferror(fp)) rv = -1;
-+
-+ return rv;
-+}
-+
diff --git a/extra/source/xv/xv-3.10a-jumbo-fix-enh-patch-20070520.txt b/extra/source/xv/xv-3.10a-jumbo-fix-enh-patch-20070520.txt
deleted file mode 100644
index 51ff30a98..000000000
--- a/extra/source/xv/xv-3.10a-jumbo-fix-enh-patch-20070520.txt
+++ /dev/null
@@ -1,42401 +0,0 @@
-diff : xv-3.10a-jumbo-fix-enh-patch-20070520.txt
-
-This is a unified diff. It should be applied (using Larry Wall's "patch"
-program) to the stock XV 3.10a sources. See the "How to build" section of
-README.jumbo, which, along with roughly 40 other new files and 3 new sub-
-directories, should have been unpacked along with this jumbo patch:
-
- README.jumbo
- README.pcd
- bits/br_bzip2
- bits/br_jp2
- bits/br_jpc
- bits/br_mag
- bits/br_maki
- bits/br_mgcsfx
- bits/br_pcd
- bits/br_pi
- bits/br_pic
- bits/br_pic2
- bits/br_png
- bits/br_zx
- contrib/
- contrib/fnkey-scripts/
- contrib/fnkey-scripts/README
- contrib/fnkey-scripts/jpegcrop.sh
- contrib/fnkey-scripts/jpegeditcom.sh
- contrib/fnkey-scripts/jpeglogrot.sh
- contrib/fnkey-scripts/jpegrot.sh
- contrib/fnkey-scripts/jpegundocrop.sh
- contrib/fedora/
- contrib/fedora/README
- contrib/fedora/Build-FC5
- docs/xvdocs.pdf
- tiff/RANLIB.sh
- xv_mgcsfx.sample
- xvhips.c
- xvhips.h
- xvjp2k.c
- xvmag.c
- xvmaki.c
- xvmgcsfx.c
- xvml.c
- xvml.h
- xvpcd.c
- xvpi.c
- xvpic.c
- xvpic2.c
- xvpng.c
- xvvd.c
- xvwbmp.c
- xvzx.c
-
-
-diffs below:
-
- Imakefile
- Makefile
- Makefile.std
- bggen.c
- bits/br_targa
- bits/icon
- cleandir
- config.h
- copyright.h
- docs/bggen.man
- docs/xcmap.man
- docs/xv.man
- docs/xvp2p.man
- tiff/Makefile
- tiff/Makefile.std
- vdcomp.c
- xcmap.c
- xv.c
- xv.h
- xv24to8.c
- xvalg.c
- xvbmp.c
- xvbrowse.c
- xvbutt.c
- xvcolor.c
- xvctrl.c
- xvcut.c
- xvdflt.c
- xvdflt.h
- xvdial.c
- xvdir.c
- xvevent.c
- xvfits.c
- xvgam.c
- xvgif.c
- xvgifwr.c
- xvgrab.c
- xvgraf.c
- xviff.c
- xvimage.c
- xvinfo.c
- xviris.c
- xvjpeg.c
- xvmisc.c
- xvpbm.c
- xvpcx.c
- xvpds.c
- xvpictoppm.c
- xvpm.c
- xvpopup.c
- xvps.c
- xvrle.c
- xvroot.c
- xvscrl.c
- xvsmooth.c
- xvsunras.c
- xvtarga.c
- xvtext.c
- xvtiff.c
- xvtiffwr.c
- xvxbm.c
- xvxpm.c
- xvxwd.c
-
-
-diff -ru xv-3.10a/Imakefile xv-3.10a-enhancements/Imakefile
---- xv-3.10a/Imakefile 1995-01-13 12:24:01.000000000 -0800
-+++ xv-3.10a-enhancements/Imakefile 2005-04-17 14:04:22.000000000 -0700
-@@ -104,6 +104,11 @@
- SGI = -Dsgi
- #endif
-
-+/* install directory of xv_mgcsfx.sample. */
-+MGCSFXDIR = $(LIBDIR)
-+/* Directory of default configuration file. */
-+MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"
-+
-
-
-
-@@ -137,6 +142,8 @@
- #if defined(SCOArchitecture)
- SCO= -Dsco -DPOSIX -DNO_RANDOM
- SYS_LIBRARIES= -lm -lc -lx
-+#elif defined(HPArchitecture)
-+SYS_LIBRARIES= -lm -lV3
- #else
- SYS_LIBRARIES= -lm
- #endif
-@@ -147,7 +154,7 @@
-
- DEFINES= $(SCO) $(UNIX) $(NODIRENT) $(VPRINTF) $(TIMERS) \
- $(HPUX7) $(JPEG) $(TIFF) $(PDS) $(DXWM) $(RAND) \
-- $(BACKING_STORE) $(BSDTYPES) $(SGI)
-+ $(BACKING_STORE) $(BSDTYPES) $(SGI) $(MGCSFX)
-
- INCLUDES = $(JPEGINCLUDE) $(TIFFINCLUDE)
-
-@@ -157,7 +164,9 @@
- xvdial.c xvgraf.c xvsunras.c xvjpeg.c xvps.c xvpopup.c xvdflt.c \
- xvtiff.c xvtiffwr.c xvpds.c xvrle.c xviris.c xvgrab.c vprintf.c \
- xvbrowse.c xvtext.c xvpcx.c xviff.c xvtarga.c xvxpm.c xvcut.c \
-- xvxwd.c xvfits.c
-+ xvxwd.c xvfits.c xvpng.c xvzx.c xvwbmp.c xvpcd.c \
-+ xvmag.c xvpic.c xvmaki.c xvpi.c xvpic2.c xvvd.c xvmgcsfx.c \
-+ xvml.c
-
- OBJS1 = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
- xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
-@@ -165,7 +174,9 @@
- xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o \
- xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o \
- xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
-- xvxwd.o xvfits.o
-+ xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o \
-+ xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
-+ xvml.o
-
- SRCS2= bggen.c
- OBJS2= bggen.o
-@@ -266,6 +277,8 @@
- InstallManPageLong(docs/xvp2p,$(MANDIR),xvpictoppm)
- InstallManPageLong(docs/vdcomp,$(MANDIR),vdcomp)
-
-+InstallNonExecFile(xv_mgcsfx.sample,$(MGCSFXDIR))
-+
- tar:
- tar cf xv.tar Makefile* Imakefile *.c *.h bits docs \
- docs unsupt vms $(JPEGDIR) $(TIFFDIR) $(MISC)
-diff -ru xv-3.10a/Makefile xv-3.10a-enhancements/Makefile
---- xv-3.10a/Makefile 1995-01-23 12:20:54.000000000 -0800
-+++ xv-3.10a-enhancements/Makefile 2007-05-20 21:17:35.000000000 -0700
-@@ -2,7 +2,11 @@
-
- # your C compiler (and options) of choice
- CC = cc
--# CC = gcc -ansi
-+#CC = gcc -ansi
-+# note that -ansi kills __USE_MISC (gcc 2.95.3), which, at least on Linux,
-+# determines whether stdlib.h includes prototypes for mktemp(), random(), etc.
-+# (i.e., if you use it, you will get unnecessary compiler warnings)
-+#CC = gcc
-
- # use this if you're using 'cc' on a DEC Alpha (OSF/1) or MIPS (Ultrix) system:
- # CC = cc -std1 -Olimit 750
-@@ -14,8 +18,20 @@
- # -Wuninitialized -Wparentheses
-
-
--CCOPTS = -O
--
-+CCOPTS = -O
-+#
-+# these are the usual optimization and warning options for gcc; all such
-+# warnings but one (mktemp() use) have been eliminated (at least on Linux):
-+#CCOPTS = -O3 -Wall
-+#
-+# slightly more warnings... older code often made non-const pointers to
-+# static strings (nothing should blow up unless something tries to write
-+# to them):
-+#CCOPTS = -O3 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wnested-externs
-+#
-+# for the next step up in gcc noise, try adding -W (but note that it adds a
-+# huge number of unused-parameter and signed/unsigned comparison warnings):
-+#CCOPTS = -O3 -Wall -W
-
- ### NOTE: Sun running OpenWindows:
- ### if you're using a SUN running OPENWINDOWS, you need to add these two
-@@ -27,50 +43,155 @@
- ### '-I' options on the CCOPTS line to tell the compiler where said files are.
-
-
-+# older Unixen don't support the -p option, but its lack may mean installation
-+# will fail (if more than one directory level is missing)
-+MKDIR = mkdir -p
-+
-+
-+# BeOS _may_ need to use a different version (below), but probably not
-+CLEANDIR = cleandir
-+
-+
- ### Installation locations
--BINDIR = /usr/local/bin
--MANDIR = /usr/local/man/man1
-+### NOTE: Users of old K&R compilers (i.e., any version not supporting C89
-+### string concatenation, such as "fub" "ar" => "fubar") should update
-+### xvtext.c:1831 (or thereabouts) if either PREFIX or DOCDIR changes:
-+PREFIX = /usr/local
-+BINDIR = $(PREFIX)/bin
-+MANDIR = $(PREFIX)/share/man/man1
- MANSUF = 1
--LIBDIR = /usr/local/lib
-+DOCDIR = $(PREFIX)/share/doc/xv
-+LIBDIR = $(PREFIX)/lib/xv
-+SYSCONFDIR = /etc
-+DESTDIR =
-
-
- buildit: all
-
-
- ########################### CONFIGURATION OPTIONS ############################
--### NOTE: be sure to check 'config.h', for a few other configuration options
-+### NOTE: be sure to check 'config.h', for a few other configuration options
- ##############################################################################
-
- ###
-+### if, for whatever reason, you're unable to get the TIFF library to compile
-+### on your machine, *COMMENT OUT* the following lines
-+###
-+### GRR 20050319: USE_TILED_TIFF_BOTLEFT_FIX enables an experimental fix for
-+### tiled TIFFs with ORIENTATION_BOTLEFT. It may break other tiled TIFFs,
-+### or it may be required for certain other TIFF types (e.g., strips with
-+### ORIENTATION_BOTLEFT). I don't have a sufficient variety of TIFF test
-+### images at hand.
-+###
-+#TIFF = -DDOTIFF
-+TIFF = -DDOTIFF -DUSE_TILED_TIFF_BOTLEFT_FIX
-+###
-+#TIFFDIR = tiff
-+TIFFDIR = /usr
-+#TIFFDIR = /usr/local
-+#TIFFDIR = ../../libtiff
-+###
-+TIFFINC = -I$(TIFFDIR)/include
-+#TIFFINC = -I$(TIFFDIR)
-+###
-+### libtiff 3.5 and up may be compiled with zlib and libjpeg, but the
-+### dependency is properly handled in LIBS line ~247 lines below
-+###
-+TIFFLIB = -L$(TIFFDIR)/lib -ltiff
-+#TIFFLIB = $(TIFFDIR)/lib/libtiff.a
-+#TIFFLIB = -L$(TIFFDIR) -ltiff
-+#TIFFLIB = $(TIFFDIR)/libtiff.a
-+###
-+### this is intended to build the ancient version (3.3.016 beta) that's
-+### included in the "tiff" subdir of XV, not an arbitrary copy of libtiff:
-+###
-+#$(TIFFLIB):
-+# ( cd $(TIFFDIR) ; make CC='$(CC)' COPTS='$(CCOPTS) $(MCHN)' )
-+
-+
-+###
- ### if, for whatever reason, you're unable to get the JPEG library to compile
- ### on your machine, *COMMENT OUT* the following lines
- ###
-+### NOTE: /usr/sfw can be used on Solaris with "Sun freeware" installed
-+###
- JPEG = -DDOJPEG
--JPEGDIR = jpeg
--JPEGINC = -I$(JPEGDIR)
--JPEGLIB = $(JPEGDIR)/libjpeg.a
--$(JPEGDIR)/jconfig.h:
-- cd $(JPEGDIR) ; ./configure CC='$(CC)'
--$(JPEGLIB): $(JPEGDIR)/jconfig.h
-- cd $(JPEGDIR) ; make
-+#JPEGDIR = jpeg
-+JPEGDIR = /usr
-+#JPEGDIR = /usr/local
-+#JPEGDIR = ../../libjpeg
-+#JPEGDIR = /usr/sfw
-+###
-+JPEGINC = -I$(JPEGDIR)/include
-+#JPEGINC = -I$(JPEGDIR)
-+###
-+JPEGLIB = -L$(JPEGDIR)/lib -ljpeg
-+#JPEGLIB = -L$(JPEGDIR) -ljpeg
-+#JPEGLIB = $(JPEGDIR)/libjpeg.a
-+###
-+### this is intended to build the ancient version (5a) that's included in the
-+### "jpeg" subdir of XV, not an arbitrary copy of libjpeg:
-+###
-+#$(JPEGDIR)/jconfig.h:
-+# cd $(JPEGDIR) ; ./configure CC='$(CC)'
-+#$(JPEGLIB): $(JPEGDIR)/jconfig.h
-+# cd $(JPEGDIR) ; make
-
-
- ###
--### if, for whatever reason, you're unable to get the TIFF library to compile
-+### if, for whatever reason, you're unable to get the PNG library to compile
- ### on your machine, *COMMENT OUT* the following lines
- ###
--TIFF = -DDOTIFF
--TIFFDIR = tiff
--TIFFINC = -I$(TIFFDIR)
--TIFFLIB = $(TIFFDIR)/libtiff.a
--$(TIFFLIB):
-- ( cd $(TIFFDIR) ; make CC='$(CC)' )
-+PNG = -DDOPNG
-+PNGDIR = /usr
-+#PNGDIR = /usr/local
-+#PNGDIR = ../../libpng
-+###
-+PNGINC = -I$(PNGDIR)/include
-+#PNGINC = -I$(PNGDIR)
-+###
-+PNGLIB = -L$(PNGDIR)/lib -lpng
-+#PNGLIB = -L$(PNGDIR) -lpng
-+#PNGLIB = $(PNGDIR)/libpng.a
-+
-+
-+###
-+### if, for whatever reason, you're unable to get both the PNG library and
-+### (newer versions of) the TIFF library to compile on your machine, *COMMENT
-+### OUT* the following lines
-+###
-+ZLIBDIR = /usr
-+#ZLIBDIR = /usr/local
-+#ZLIBDIR = ../../zlib
-+###
-+ZLIBINC = -I$(ZLIBDIR)/include
-+#ZLIBINC = -I$(ZLIBDIR)
-+###
-+ZLIBLIB = -L$(ZLIBDIR)/lib -lz
-+#ZLIBLIB = -L$(ZLIBDIR) -lz
-+#ZLIBLIB = $(ZLIBDIR)/libz.a
-+
-+
-+###
-+### if, for whatever reason, you're unable to get the JasPer JPEG-2000 library
-+### to compile on your machine, *COMMENT OUT* the following lines
-+###
-+JP2K = -DDOJP2K
-+###
-+#JP2KDIR = ../../jasper
-+JP2KDIR = /usr/local/lib
-+###
-+#JP2KINC = -I$(JP2KDIR)
-+JP2KINC = -I/usr/local/include
-+###
-+#JP2KLIB = -L$(JP2KDIR) -ljasper
-+JP2KLIB = $(JP2KDIR)/libjasper.a
-
-
- ###
- ### if, for whatever reason, you're unable to get the PDS/VICAR support
- ### to compile (xvpds.c, and vdcomp.c), *COMMENT OUT* the following line,
--### and also remove 'vdcomp' from the 'all:' dependancy
-+### and also remove 'vdcomp' from the 'all:' dependency
- ###
- PDS = -DDOPDS
-
-@@ -78,46 +199,60 @@
- #----------System V----------
-
- # if you are running on a SysV-based machine, such as HP, Silicon Graphics,
--# Solaris, etc., uncomment the following line to get mostly there.
--#UNIX = -DSVR4
-+# Solaris, etc.; uncomment one of the following lines to get you *most* of
-+# the way there. SYSV means System V R3.
-+# UNIX = -DSVR4
-+# UNIX = -DSYSV
-+
-
-+#----------Machine-Specific Configurations----------
-+
-+### If you are using a BeOS system, uncomment the following line
-+#MCHN = -DUSE_GETCWD -I/usr/X11/include -L/usr/X11/lib
-+###
-+### The stock version of cleandir now should work for BeOS, too, so try
-+### leaving this commented out:
-+#CLEANDIR = cleandir.BeOS
-
--#----------Machine Specific Configurations----------
-
- ### If you are using an SGI system, uncomment the following line
- #MCHN = -Dsgi
-
-
--### For HP-UX, uncomment the following line:
-+### For HP-UX, uncomment the following line
- #MCHN= -Dhpux -D_HPUX_SOURCE
- # To use old HP compilers (HPUX 7.0 or so), you may need
- #MCHN= -Dhpux -D_HPUX_SOURCE +Ns4000
- #
--# also, if you're using HP's compiler, add '-Aa' to whichever of those
-+# Also, if you're using HP's compiler, add '-Aa' to whichever of those
- # two lines you're using, to turn on ANSI C mode. Or so I'm told.
- #
--# note: You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
-+# Note: You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
- # to whichever of those lines you used, as HP tends to store their X11
- # include files in a non-standard place...
-+#
-+# And you probably have to add '-lV3' to the end of the LIBS def when
-+# using XV's AUTO_EXPAND option.
-
-
--### for LINUX, uncomment the following line
--#MCHN = -DLINUX
-+### for Linux, uncomment one of the following lines:
-+#MCHN = -DLINUX -L/usr/X11R6/lib
-+#MCHN = -DLINUX -L/usr/X11R6/lib64
-
-
- # For SCO 1.1 (UNIX 3.2v2) machines, uncomment the following:
- #MCHN = -Dsco -DPOSIX
- #
- # For ODT 2.0 (UNIX 3.2v4) machines, uncomment the following:
--#MCHN= -Dsco -DPOSIX -DNO_RANDOM
-+#MCHN= -Dsco -DPOSIX -DNO_RANDOM
- #
- # Also, you should add '-lc -lx' to the end of the LIBS def below
- # -lx must be after -lc so you get the right directory routines.
-
-
- # for UMAX V by Encore Computers uncomment the following line for
--# the portable c compiler, system specific definitions and
--# location of local X11 library(if site specific, modify -L option)
-+# the portable C compiler, system-specific definitions and
-+# location of local X11 library (if site-specific, modify -L option)
- # No other switches should be necessary, or so I'm told...
- #
- #MCHN = -q extensions=pcc_c -D__UMAXV__ -L/usr2/usr/lib/X11 -DSVR4
-@@ -147,8 +282,8 @@
- #TIMERS = -DUSLEEP
-
-
--# if XV locks up whenever you click on *any* of the buttons, the Timer()
--# function in xvmisc.c is going out to lunch. A simple workaround is to
-+# if XV locks up whenever you click on *any* of the buttons, the Timer()
-+# function in xvmisc.c is going out to lunch. A simple workaround is to
- # uncomment the following line:
- #TIMERS = -DNOTIMER
-
-@@ -160,7 +295,7 @@
- #DXWM = -DDXWM
-
-
--# if, during compilation, your system complains about the types
-+# if, during compilation, your system complains about the types
- # 'u_long', 'u_short', 'u_int', etc. as being undefined, uncomment the
- # following line:
- #BSDTYPES = -DBSDTYPES
-@@ -177,18 +312,38 @@
- #VPRINTF = -DNEED_VPRINTF -DLONGINT -DNOSTDHDRS
-
-
-+# if your machine puts the prototype for 'malloc()' in malloc.h rather than
-+# stdlib.h, uncomment the following line:
-+#
-+#MALLOC = -DNEED_MALLOC_H
-
-
--################ END OF CONFIGURATION OPTIONS #################
-+# if your X Window System compiled with -DX_LOCALE,
-+# uncomment the following line:
-+# TVL10N = -DX_LOCALE
-+
-+# Install directory of xv_mgcsfx.sample.
-+MGCSFXDIR = $(LIBDIR)
-+# Directory of default configuration file.
-+MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"
-+
-
-
-
-+################ END OF CONFIGURATION OPTIONS #################
-+
-
--CFLAGS = $(CCOPTS) $(JPEG) $(JPEGINC) $(TIFF) $(TIFFINC) $(PDS) \
-- $(NODIRENT) $(VPRINTF) $(TIMERS) $(UNIX) $(BSDTYPES) $(RAND) \
-- $(DXWM) $(MCHN)
-
--LIBS = -lX11 $(JPEGLIB) $(TIFFLIB) -lm
-+
-+CFLAGS = $(CCOPTS) $(PNG) $(PNGINC) $(ZLIBINC) $(JPEG) $(JPEGINC) \
-+ $(TIFF) $(TIFFINC) $(PDS) $(JP2K) $(JP2KINC) $(TVL10N) $(MGCSFX) \
-+ $(UNIX) $(BSDTYPES) $(RAND) $(MALLOC) $(DXWM) $(MCHN) $(NODIRENT) \
-+ $(VPRINTF) $(TIMERS) -DDOCDIR=\"$(DOCDIR)\" \
-+ -DSYSCONFDIR=\"$(SYSCONFDIR)\" -DXVEXECPATH=\"$(LIBDIR)\"
-+
-+### remove -lm for BeOS:
-+LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -L/usr/X11R6/lib -lX11 -lm
-+#LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -lX11
-
- OBJS = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
- xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
-@@ -196,7 +351,9 @@
- xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o \
- xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o \
- xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
-- xvxwd.o xvfits.o
-+ xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o xvhips.o \
-+ xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
-+ xvml.o xvjp2k.o
-
- MISC = README INSTALL CHANGELOG IDEAS
-
-@@ -206,10 +363,12 @@
-
-
-
--all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
-+#all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
-+all: xv bggen vdcomp xcmap xvpictoppm
-
-
--xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
-+#xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
-+xv: $(OBJS)
- $(CC) -o xv $(CFLAGS) $(OBJS) $(LIBS)
-
- bggen: bggen.c
-@@ -231,23 +390,47 @@
-
- clean: xvclean
- rm -f bggen vdcomp xcmap xvpictoppm
-- ./cleandir $(JPEGDIR)
-- rm -f $(JPEGDIR)/jconfig.h $(JPEGDIR)/Makefile
-- ./cleandir $(TIFFDIR)
-+# clean only local jpeg and tiff dirs, not user's or system's copies:
-+ ./$(CLEANDIR) jpeg
-+ rm -f jpeg/jconfig.h jpeg/Makefile
-+ ./$(CLEANDIR) tiff
-
-
-+# could also do some shell trickery here to attempt mkdir only if dir is
-+# missing (e.g., "test -d || $(MKDIR) ")
- install: all
-- cp xv bggen vdcomp xcmap xvpictoppm $(BINDIR)
-- cp docs/xv.man $(MANDIR)/xv.$(MANSUF)
-- cp docs/bggen.man $(MANDIR)/bggen.$(MANSUF)
-- cp docs/xcmap.man $(MANDIR)/xcmap.$(MANSUF)
-- cp docs/xvp2p.man $(MANDIR)/xvpictoppm.$(MANSUF)
-- cp docs/vdcomp.man $(MANDIR)/vdcomp.$(MANSUF)
-- cp docs/xvdocs.ps* $(LIBDIR)
-+ $(MKDIR) $(DESTDIR)$(BINDIR)
-+ cp xv bggen vdcomp xcmap xvpictoppm $(DESTDIR)$(BINDIR)/.
-+ chmod 755 $(DESTDIR)$(BINDIR)/xv $(DESTDIR)$(BINDIR)/bggen \
-+ $(DESTDIR)$(BINDIR)/vdcomp $(DESTDIR)$(BINDIR)/xcmap \
-+ $(DESTDIR)$(BINDIR)/xvpictoppm
-+#
-+ $(MKDIR) $(DESTDIR)$(MANDIR)
-+ cp docs/xv.man $(DESTDIR)$(MANDIR)/xv.$(MANSUF)
-+ cp docs/bggen.man $(DESTDIR)$(MANDIR)/bggen.$(MANSUF)
-+ cp docs/xcmap.man $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF)
-+ cp docs/xvp2p.man $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF)
-+ cp docs/vdcomp.man $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
-+ chmod 644 $(DESTDIR)$(MANDIR)/xv.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/bggen.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
-+#
-+ $(MKDIR) $(DESTDIR)$(DOCDIR) # or $(DESTDIR)$(LIBDIR)
-+ cp README.jumbo docs/xvdocs.pdf docs/xvdocs.ps $(DESTDIR)$(DOCDIR)/.
-+ chmod 644 $(DESTDIR)$(DOCDIR)/README.jumbo \
-+ $(DESTDIR)$(DOCDIR)/xvdocs.pdf $(DESTDIR)$(DOCDIR)/xvdocs.ps
-+#
-+ #$(MKDIR) $(DESTDIR)$(SYSCONFDIR)
-+ #cp xv_mgcsfx.sample $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
-+ #chmod 644 $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
-+
-
- tar:
-+# tar only local jpeg and tiff dirs, not user's or system's copies:
- tar cvf xv.tar Makefile* Imakefile *.c *.h bits \
-- docs unsupt vms $(JPEGDIR) $(TIFFDIR) $(MISC)
-+ docs unsupt vms jpeg tiff $(MISC)
-
- xvtar:
- tar cvf xv.tar Makefile* Imakefile *.c *.h bits
-@@ -257,26 +440,28 @@
-
- ################# bitmap dependencies ####################
-
--xv.o: bits/icon bits/iconmask bits/runicon bits/runiconm
--xv.o: bits/cboard50 bits/gray25
-+xv.o: bits/icon bits/iconmask bits/runicon bits/runiconm
-+xv.o: bits/cboard50 bits/gray25
-
- xvbrowse.o: bits/br_file bits/br_dir bits/br_exe bits/br_chr bits/br_blk
--xvbrowse.o: bits/br_sock bits/br_fifo bits/br_error bits/br_unknown
--xvbrowse.o: bits/br_cmpres bits/br_gif bits/br_pm bits/br_pbm
-+xvbrowse.o: bits/br_sock bits/br_fifo bits/br_error # bits/br_unknown
-+xvbrowse.o: bits/br_cmpres bits/br_bzip2 bits/br_gif bits/br_pm bits/br_pbm
- xvbrowse.o: bits/br_sunras bits/br_bmp bits/br_utah bits/br_iris
--xvbrowse.o: bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds
--xvbrowse.o: bits/br_ps bits/br_iff bits/br_targa bits/br_xpm
-+xvbrowse.o: bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds bits/br_pcd
-+xvbrowse.o: bits/br_ps bits/br_iff bits/br_targa bits/br_xpm bits/br_xwd
-+xvbrowse.o: bits/br_fits bits/br_png bits/br_zx bits/br_mag bits/br_maki
-+xvbrowse.o: bits/br_pic bits/br_pi bits/br_pic2 bits/br_mgcsfx
-+xvbrowse.o: bits/br_jp2 bits/br_jpc
- xvbrowse.o: bits/br_trash bits/fcurs bits/fccurs bits/fdcurs bits/fcursm
--xvbrowse.o: bits/br_xwd
-
- xvbutt.o: bits/cboard50 bits/rb_frame bits/rb_frame1 bits/rb_top
- xvbutt.o: bits/rb_bot bits/rb_dtop bits/rb_dbot bits/rb_body
- xvbutt.o: bits/rb_dot bits/cb_check bits/mb_chk
-
- xvctrl.o: bits/gray25 bits/gray50 bits/i_fifo bits/i_chr bits/i_dir
--xvctrl.o: bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
-+xvctrl.o: bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
- xvctrl.o: bits/h_rotl bits/h_rotr bits/fliph bits/flipv bits/p10
--xvctrl.o: bits/m10 bits/cut bits/copy bits/paste bits/clear
-+xvctrl.o: bits/m10 bits/cut bits/copy bits/paste bits/clear
- xvctrl.o: bits/uicon bits/oicon1 bits/oicon2 bits/icon
- xvctrl.o: bits/padimg bits/annot
-
-@@ -285,13 +470,13 @@
- xvdflt.o: bits/logo_top bits/logo_bot bits/logo_out bits/xv_jhb
- xvdflt.o: bits/xv_cpyrt bits/xv_rev bits/xv_ver
- xvdflt.o: bits/xf_left bits/xf_right bits/font5x9.h
--xvdflt.o: xvdflt.h
-+xvdflt.o: xvdflt.h
-
- xvdial.o: bits/dial_cw1 bits/dial_ccw1 bits/dial_cw2 bits/dial_ccw2
-
- xvdir.o: bits/d_load bits/d_save
-
--xvevent.o: bits/dropper bits/dropperm bits/pen bits/penm
-+xvevent.o: bits/dropper bits/dropperm bits/pen bits/penm
- xvevent.o: bits/blur bits/blurm
-
- xvgam.o: bits/h_rotl bits/h_rotr bits/h_flip bits/h_sinc bits/h_sdec
-diff -ru xv-3.10a/Makefile.std xv-3.10a-enhancements/Makefile.std
---- xv-3.10a/Makefile.std 1995-01-23 17:06:26.000000000 -0800
-+++ xv-3.10a-enhancements/Makefile.std 2007-05-20 21:17:35.000000000 -0700
-@@ -2,7 +2,11 @@
-
- # your C compiler (and options) of choice
- CC = cc
--# CC = gcc -ansi
-+#CC = gcc -ansi
-+# note that -ansi kills __USE_MISC (gcc 2.95.3), which, at least on Linux,
-+# determines whether stdlib.h includes prototypes for mktemp(), random(), etc.
-+# (i.e., if you use it, you will get unnecessary compiler warnings)
-+#CC = gcc
-
- # use this if you're using 'cc' on a DEC Alpha (OSF/1) or MIPS (Ultrix) system:
- # CC = cc -std1 -Olimit 750
-@@ -14,8 +18,20 @@
- # -Wuninitialized -Wparentheses
-
-
--CCOPTS = -O
--
-+CCOPTS = -O
-+#
-+# these are the usual optimization and warning options for gcc; all such
-+# warnings but one (mktemp() use) have been eliminated (at least on Linux):
-+#CCOPTS = -O3 -Wall
-+#
-+# slightly more warnings... older code often made non-const pointers to
-+# static strings (nothing should blow up unless something tries to write
-+# to them):
-+#CCOPTS = -O3 -Wall -Wpointer-arith -Wcast-align -Wwrite-strings -Wnested-externs
-+#
-+# for the next step up in gcc noise, try adding -W (but note that it adds a
-+# huge number of unused-parameter and signed/unsigned comparison warnings):
-+#CCOPTS = -O3 -Wall -W
-
- ### NOTE: Sun running OpenWindows:
- ### if you're using a SUN running OPENWINDOWS, you need to add these two
-@@ -27,50 +43,155 @@
- ### '-I' options on the CCOPTS line to tell the compiler where said files are.
-
-
-+# older Unixen don't support the -p option, but its lack may mean installation
-+# will fail (if more than one directory level is missing)
-+MKDIR = mkdir -p
-+
-+
-+# BeOS _may_ need to use a different version (below), but probably not
-+CLEANDIR = cleandir
-+
-+
- ### Installation locations
--BINDIR = /usr/local/bin
--MANDIR = /usr/local/man/man1
-+### NOTE: Users of old K&R compilers (i.e., any version not supporting C89
-+### string concatenation, such as "fub" "ar" => "fubar") should update
-+### xvtext.c:1831 (or thereabouts) if either PREFIX or DOCDIR changes:
-+PREFIX = /usr/local
-+BINDIR = $(PREFIX)/bin
-+MANDIR = $(PREFIX)/share/man/man1
- MANSUF = 1
--LIBDIR = /usr/local/lib
-+DOCDIR = $(PREFIX)/share/doc/xv
-+LIBDIR = $(PREFIX)/lib/xv
-+SYSCONFDIR = /etc
-+DESTDIR =
-
-
- buildit: all
-
-
- ########################### CONFIGURATION OPTIONS ############################
--### NOTE: be sure to check 'config.h', for a few other configuration options
-+### NOTE: be sure to check 'config.h', for a few other configuration options
- ##############################################################################
-
- ###
-+### if, for whatever reason, you're unable to get the TIFF library to compile
-+### on your machine, *COMMENT OUT* the following lines
-+###
-+### GRR 20050319: USE_TILED_TIFF_BOTLEFT_FIX enables an experimental fix for
-+### tiled TIFFs with ORIENTATION_BOTLEFT. It may break other tiled TIFFs,
-+### or it may be required for certain other TIFF types (e.g., strips with
-+### ORIENTATION_BOTLEFT). I don't have a sufficient variety of TIFF test
-+### images at hand.
-+###
-+#TIFF = -DDOTIFF
-+TIFF = -DDOTIFF -DUSE_TILED_TIFF_BOTLEFT_FIX
-+###
-+#TIFFDIR = tiff
-+TIFFDIR = /usr
-+#TIFFDIR = /usr/local
-+#TIFFDIR = ../../libtiff
-+###
-+TIFFINC = -I$(TIFFDIR)/include
-+#TIFFINC = -I$(TIFFDIR)
-+###
-+### libtiff 3.5 and up may be compiled with zlib and libjpeg, but the
-+### dependency is properly handled in LIBS line ~247 lines below
-+###
-+TIFFLIB = -L$(TIFFDIR)/lib -ltiff
-+#TIFFLIB = $(TIFFDIR)/lib/libtiff.a
-+#TIFFLIB = -L$(TIFFDIR) -ltiff
-+#TIFFLIB = $(TIFFDIR)/libtiff.a
-+###
-+### this is intended to build the ancient version (3.3.016 beta) that's
-+### included in the "tiff" subdir of XV, not an arbitrary copy of libtiff:
-+###
-+#$(TIFFLIB):
-+# ( cd $(TIFFDIR) ; make CC='$(CC)' COPTS='$(CCOPTS) $(MCHN)' )
-+
-+
-+###
- ### if, for whatever reason, you're unable to get the JPEG library to compile
- ### on your machine, *COMMENT OUT* the following lines
- ###
-+### NOTE: /usr/sfw can be used on Solaris with "Sun freeware" installed
-+###
- JPEG = -DDOJPEG
--JPEGDIR = jpeg
--JPEGINC = -I$(JPEGDIR)
--JPEGLIB = $(JPEGDIR)/libjpeg.a
--$(JPEGDIR)/jconfig.h:
-- cd $(JPEGDIR) ; ./configure CC='$(CC)'
--$(JPEGLIB): $(JPEGDIR)/jconfig.h
-- cd $(JPEGDIR) ; make
-+#JPEGDIR = jpeg
-+JPEGDIR = /usr
-+#JPEGDIR = /usr/local
-+#JPEGDIR = ../../libjpeg
-+#JPEGDIR = /usr/sfw
-+###
-+JPEGINC = -I$(JPEGDIR)/include
-+#JPEGINC = -I$(JPEGDIR)
-+###
-+JPEGLIB = -L$(JPEGDIR)/lib -ljpeg
-+#JPEGLIB = -L$(JPEGDIR) -ljpeg
-+#JPEGLIB = $(JPEGDIR)/libjpeg.a
-+###
-+### this is intended to build the ancient version (5a) that's included in the
-+### "jpeg" subdir of XV, not an arbitrary copy of libjpeg:
-+###
-+#$(JPEGDIR)/jconfig.h:
-+# cd $(JPEGDIR) ; ./configure CC='$(CC)'
-+#$(JPEGLIB): $(JPEGDIR)/jconfig.h
-+# cd $(JPEGDIR) ; make
-
-
- ###
--### if, for whatever reason, you're unable to get the TIFF library to compile
-+### if, for whatever reason, you're unable to get the PNG library to compile
- ### on your machine, *COMMENT OUT* the following lines
- ###
--TIFF = -DDOTIFF
--TIFFDIR = tiff
--TIFFINC = -I$(TIFFDIR)
--TIFFLIB = $(TIFFDIR)/libtiff.a
--$(TIFFLIB):
-- ( cd $(TIFFDIR) ; make CC='$(CC)' )
-+PNG = -DDOPNG
-+PNGDIR = /usr
-+#PNGDIR = /usr/local
-+#PNGDIR = ../../libpng
-+###
-+PNGINC = -I$(PNGDIR)/include
-+#PNGINC = -I$(PNGDIR)
-+###
-+PNGLIB = -L$(PNGDIR)/lib -lpng
-+#PNGLIB = -L$(PNGDIR) -lpng
-+#PNGLIB = $(PNGDIR)/libpng.a
-+
-+
-+###
-+### if, for whatever reason, you're unable to get both the PNG library and
-+### (newer versions of) the TIFF library to compile on your machine, *COMMENT
-+### OUT* the following lines
-+###
-+ZLIBDIR = /usr
-+#ZLIBDIR = /usr/local
-+#ZLIBDIR = ../../zlib
-+###
-+ZLIBINC = -I$(ZLIBDIR)/include
-+#ZLIBINC = -I$(ZLIBDIR)
-+###
-+ZLIBLIB = -L$(ZLIBDIR)/lib -lz
-+#ZLIBLIB = -L$(ZLIBDIR) -lz
-+#ZLIBLIB = $(ZLIBDIR)/libz.a
-+
-+
-+###
-+### if, for whatever reason, you're unable to get the JasPer JPEG-2000 library
-+### to compile on your machine, *COMMENT OUT* the following lines
-+###
-+JP2K = -DDOJP2K
-+###
-+#JP2KDIR = ../../jasper
-+JP2KDIR = /usr/local/lib
-+###
-+#JP2KINC = -I$(JP2KDIR)
-+JP2KINC = -I/usr/local/include
-+###
-+#JP2KLIB = -L$(JP2KDIR) -ljasper
-+JP2KLIB = $(JP2KDIR)/libjasper.a
-
-
- ###
- ### if, for whatever reason, you're unable to get the PDS/VICAR support
- ### to compile (xvpds.c, and vdcomp.c), *COMMENT OUT* the following line,
--### and also remove 'vdcomp' from the 'all:' dependancy
-+### and also remove 'vdcomp' from the 'all:' dependency
- ###
- PDS = -DDOPDS
-
-@@ -78,46 +199,60 @@
- #----------System V----------
-
- # if you are running on a SysV-based machine, such as HP, Silicon Graphics,
--# Solaris, etc., uncomment the following line to get mostly there.
--#UNIX = -DSVR4
-+# Solaris, etc.; uncomment one of the following lines to get you *most* of
-+# the way there. SYSV means System V R3.
-+# UNIX = -DSVR4
-+# UNIX = -DSYSV
-+
-
-+#----------Machine-Specific Configurations----------
-+
-+### If you are using a BeOS system, uncomment the following line
-+#MCHN = -DUSE_GETCWD -I/usr/X11/include -L/usr/X11/lib
-+###
-+### The stock version of cleandir now should work for BeOS, too, so try
-+### leaving this commented out:
-+#CLEANDIR = cleandir.BeOS
-
--#----------Machine Specific Configurations----------
-
- ### If you are using an SGI system, uncomment the following line
- #MCHN = -Dsgi
-
-
--### For HP-UX, uncomment the following line:
-+### For HP-UX, uncomment the following line
- #MCHN= -Dhpux -D_HPUX_SOURCE
- # To use old HP compilers (HPUX 7.0 or so), you may need
- #MCHN= -Dhpux -D_HPUX_SOURCE +Ns4000
- #
--# also, if you're using HP's compiler, add '-Aa' to whichever of those
-+# Also, if you're using HP's compiler, add '-Aa' to whichever of those
- # two lines you're using, to turn on ANSI C mode. Or so I'm told.
- #
--# note: You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
-+# Note: You may need to add '-I/usr/include/X11R5' (or R6, or whatever)
- # to whichever of those lines you used, as HP tends to store their X11
- # include files in a non-standard place...
-+#
-+# And you probably have to add '-lV3' to the end of the LIBS def when
-+# using XV's AUTO_EXPAND option.
-
-
--### for LINUX, uncomment the following line
--#MCHN = -DLINUX
-+### for Linux, uncomment one of the following lines:
-+#MCHN = -DLINUX -L/usr/X11R6/lib
-+#MCHN = -DLINUX -L/usr/X11R6/lib64
-
-
- # For SCO 1.1 (UNIX 3.2v2) machines, uncomment the following:
- #MCHN = -Dsco -DPOSIX
- #
- # For ODT 2.0 (UNIX 3.2v4) machines, uncomment the following:
--#MCHN= -Dsco -DPOSIX -DNO_RANDOM
-+#MCHN= -Dsco -DPOSIX -DNO_RANDOM
- #
- # Also, you should add '-lc -lx' to the end of the LIBS def below
- # -lx must be after -lc so you get the right directory routines.
-
-
- # for UMAX V by Encore Computers uncomment the following line for
--# the portable c compiler, system specific definitions and
--# location of local X11 library(if site specific, modify -L option)
-+# the portable C compiler, system-specific definitions and
-+# location of local X11 library (if site-specific, modify -L option)
- # No other switches should be necessary, or so I'm told...
- #
- #MCHN = -q extensions=pcc_c -D__UMAXV__ -L/usr2/usr/lib/X11 -DSVR4
-@@ -147,8 +282,8 @@
- #TIMERS = -DUSLEEP
-
-
--# if XV locks up whenever you click on *any* of the buttons, the Timer()
--# function in xvmisc.c is going out to lunch. A simple workaround is to
-+# if XV locks up whenever you click on *any* of the buttons, the Timer()
-+# function in xvmisc.c is going out to lunch. A simple workaround is to
- # uncomment the following line:
- #TIMERS = -DNOTIMER
-
-@@ -160,7 +295,7 @@
- #DXWM = -DDXWM
-
-
--# if, during compilation, your system complains about the types
-+# if, during compilation, your system complains about the types
- # 'u_long', 'u_short', 'u_int', etc. as being undefined, uncomment the
- # following line:
- #BSDTYPES = -DBSDTYPES
-@@ -177,18 +312,38 @@
- #VPRINTF = -DNEED_VPRINTF -DLONGINT -DNOSTDHDRS
-
-
-+# if your machine puts the prototype for 'malloc()' in malloc.h rather than
-+# stdlib.h, uncomment the following line:
-+#
-+#MALLOC = -DNEED_MALLOC_H
-
-
--################ END OF CONFIGURATION OPTIONS #################
-+# if your X Window System compiled with -DX_LOCALE,
-+# uncomment the following line:
-+# TVL10N = -DX_LOCALE
-+
-+# Install directory of xv_mgcsfx.sample.
-+MGCSFXDIR = $(LIBDIR)
-+# Directory of default configuration file.
-+MGCSFX = -DMGCSFXDIR=\"$(MGCSFXDIR)\"
-+
-
-
-
-+################ END OF CONFIGURATION OPTIONS #################
-+
-
--CFLAGS = $(CCOPTS) $(JPEG) $(JPEGINC) $(TIFF) $(TIFFINC) $(PDS) \
-- $(NODIRENT) $(VPRINTF) $(TIMERS) $(UNIX) $(BSDTYPES) $(RAND) \
-- $(DXWM) $(MCHN)
-
--LIBS = -lX11 $(JPEGLIB) $(TIFFLIB) -lm
-+
-+CFLAGS = $(CCOPTS) $(PNG) $(PNGINC) $(ZLIBINC) $(JPEG) $(JPEGINC) \
-+ $(TIFF) $(TIFFINC) $(PDS) $(JP2K) $(JP2KINC) $(TVL10N) $(MGCSFX) \
-+ $(UNIX) $(BSDTYPES) $(RAND) $(MALLOC) $(DXWM) $(MCHN) $(NODIRENT) \
-+ $(VPRINTF) $(TIMERS) -DDOCDIR=\"$(DOCDIR)\" \
-+ -DSYSCONFDIR=\"$(SYSCONFDIR)\" -DXVEXECPATH=\"$(LIBDIR)\"
-+
-+### remove -lm for BeOS:
-+LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -L/usr/X11R6/lib -lX11 -lm
-+#LIBS = $(TIFFLIB) $(JPEGLIB) $(PNGLIB) $(ZLIBLIB) $(JP2KLIB) -lX11
-
- OBJS = xv.o xvevent.o xvroot.o xvmisc.o xvimage.o xvcolor.o xvsmooth.o \
- xv24to8.o xvgif.o xvpm.o xvinfo.o xvctrl.o xvscrl.o xvalg.o \
-@@ -196,7 +351,9 @@
- xvdial.o xvgraf.o xvsunras.o xvjpeg.o xvps.o xvpopup.o xvdflt.o \
- xvtiff.o xvtiffwr.o xvpds.o xvrle.o xviris.o xvgrab.o vprintf.o \
- xvbrowse.o xvtext.o xvpcx.o xviff.o xvtarga.o xvxpm.o xvcut.o \
-- xvxwd.o xvfits.o
-+ xvxwd.o xvfits.o xvpng.o xvzx.o xvwbmp.o xvpcd.o xvhips.o \
-+ xvmag.o xvpic.o xvmaki.o xvpi.o xvpic2.o xvvd.o xvmgcsfx.o \
-+ xvml.o xvjp2k.o
-
- MISC = README INSTALL CHANGELOG IDEAS
-
-@@ -206,10 +363,12 @@
-
-
-
--all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
-+#all: $(JPEGLIB) $(TIFFLIB) xv bggen vdcomp xcmap xvpictoppm
-+all: xv bggen vdcomp xcmap xvpictoppm
-
-
--xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
-+#xv: $(OBJS) $(JPEGLIB) $(TIFFLIB)
-+xv: $(OBJS)
- $(CC) -o xv $(CFLAGS) $(OBJS) $(LIBS)
-
- bggen: bggen.c
-@@ -231,23 +390,47 @@
-
- clean: xvclean
- rm -f bggen vdcomp xcmap xvpictoppm
-- ./cleandir $(JPEGDIR)
-- rm -f $(JPEGDIR)/jconfig.h $(JPEGDIR)/Makefile
-- ./cleandir $(TIFFDIR)
-+# clean only local jpeg and tiff dirs, not user's or system's copies:
-+ ./$(CLEANDIR) jpeg
-+ rm -f jpeg/jconfig.h jpeg/Makefile
-+ ./$(CLEANDIR) tiff
-
-
-+# could also do some shell trickery here to attempt mkdir only if dir is
-+# missing (e.g., "test -d || $(MKDIR) ")
- install: all
-- cp xv bggen vdcomp xcmap xvpictoppm $(BINDIR)
-- cp docs/xv.man $(MANDIR)/xv.$(MANSUF)
-- cp docs/bggen.man $(MANDIR)/bggen.$(MANSUF)
-- cp docs/xcmap.man $(MANDIR)/xcmap.$(MANSUF)
-- cp docs/xvp2p.man $(MANDIR)/xvpictoppm.$(MANSUF)
-- cp docs/vdcomp.man $(MANDIR)/vdcomp.$(MANSUF)
-- cp docs/xvdocs.ps* $(LIBDIR)
-+ $(MKDIR) $(DESTDIR)$(BINDIR)
-+ cp xv bggen vdcomp xcmap xvpictoppm $(DESTDIR)$(BINDIR)/.
-+ chmod 755 $(DESTDIR)$(BINDIR)/xv $(DESTDIR)$(BINDIR)/bggen \
-+ $(DESTDIR)$(BINDIR)/vdcomp $(DESTDIR)$(BINDIR)/xcmap \
-+ $(DESTDIR)$(BINDIR)/xvpictoppm
-+#
-+ $(MKDIR) $(DESTDIR)$(MANDIR)
-+ cp docs/xv.man $(DESTDIR)$(MANDIR)/xv.$(MANSUF)
-+ cp docs/bggen.man $(DESTDIR)$(MANDIR)/bggen.$(MANSUF)
-+ cp docs/xcmap.man $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF)
-+ cp docs/xvp2p.man $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF)
-+ cp docs/vdcomp.man $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
-+ chmod 644 $(DESTDIR)$(MANDIR)/xv.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/bggen.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/xcmap.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/xvpictoppm.$(MANSUF) \
-+ $(DESTDIR)$(MANDIR)/vdcomp.$(MANSUF)
-+#
-+ $(MKDIR) $(DESTDIR)$(DOCDIR) # or $(DESTDIR)$(LIBDIR)
-+ cp README.jumbo docs/xvdocs.pdf docs/xvdocs.ps $(DESTDIR)$(DOCDIR)/.
-+ chmod 644 $(DESTDIR)$(DOCDIR)/README.jumbo \
-+ $(DESTDIR)$(DOCDIR)/xvdocs.pdf $(DESTDIR)$(DOCDIR)/xvdocs.ps
-+#
-+ #$(MKDIR) $(DESTDIR)$(SYSCONFDIR)
-+ #cp xv_mgcsfx.sample $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
-+ #chmod 644 $(DESTDIR)$(SYSCONFDIR)/xv_mgcsfx
-+
-
- tar:
-+# tar only local jpeg and tiff dirs, not user's or system's copies:
- tar cvf xv.tar Makefile* Imakefile *.c *.h bits \
-- docs unsupt vms $(JPEGDIR) $(TIFFDIR) $(MISC)
-+ docs unsupt vms jpeg tiff $(MISC)
-
- xvtar:
- tar cvf xv.tar Makefile* Imakefile *.c *.h bits
-@@ -257,26 +440,28 @@
-
- ################# bitmap dependencies ####################
-
--xv.o: bits/icon bits/iconmask bits/runicon bits/runiconm
--xv.o: bits/cboard50 bits/gray25
-+xv.o: bits/icon bits/iconmask bits/runicon bits/runiconm
-+xv.o: bits/cboard50 bits/gray25
-
- xvbrowse.o: bits/br_file bits/br_dir bits/br_exe bits/br_chr bits/br_blk
--xvbrowse.o: bits/br_sock bits/br_fifo bits/br_error bits/br_unknown
--xvbrowse.o: bits/br_cmpres bits/br_gif bits/br_pm bits/br_pbm
-+xvbrowse.o: bits/br_sock bits/br_fifo bits/br_error # bits/br_unknown
-+xvbrowse.o: bits/br_cmpres bits/br_bzip2 bits/br_gif bits/br_pm bits/br_pbm
- xvbrowse.o: bits/br_sunras bits/br_bmp bits/br_utah bits/br_iris
--xvbrowse.o: bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds
--xvbrowse.o: bits/br_ps bits/br_iff bits/br_targa bits/br_xpm
-+xvbrowse.o: bits/br_pcx bits/br_jfif bits/br_tiff bits/br_pds bits/br_pcd
-+xvbrowse.o: bits/br_ps bits/br_iff bits/br_targa bits/br_xpm bits/br_xwd
-+xvbrowse.o: bits/br_fits bits/br_png bits/br_zx bits/br_mag bits/br_maki
-+xvbrowse.o: bits/br_pic bits/br_pi bits/br_pic2 bits/br_mgcsfx
-+xvbrowse.o: bits/br_jp2 bits/br_jpc
- xvbrowse.o: bits/br_trash bits/fcurs bits/fccurs bits/fdcurs bits/fcursm
--xvbrowse.o: bits/br_xwd
-
- xvbutt.o: bits/cboard50 bits/rb_frame bits/rb_frame1 bits/rb_top
- xvbutt.o: bits/rb_bot bits/rb_dtop bits/rb_dbot bits/rb_body
- xvbutt.o: bits/rb_dot bits/cb_check bits/mb_chk
-
- xvctrl.o: bits/gray25 bits/gray50 bits/i_fifo bits/i_chr bits/i_dir
--xvctrl.o: bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
-+xvctrl.o: bits/i_blk bits/i_lnk bits/i_sock bits/i_exe bits/i_reg
- xvctrl.o: bits/h_rotl bits/h_rotr bits/fliph bits/flipv bits/p10
--xvctrl.o: bits/m10 bits/cut bits/copy bits/paste bits/clear
-+xvctrl.o: bits/m10 bits/cut bits/copy bits/paste bits/clear
- xvctrl.o: bits/uicon bits/oicon1 bits/oicon2 bits/icon
- xvctrl.o: bits/padimg bits/annot
-
-@@ -285,13 +470,13 @@
- xvdflt.o: bits/logo_top bits/logo_bot bits/logo_out bits/xv_jhb
- xvdflt.o: bits/xv_cpyrt bits/xv_rev bits/xv_ver
- xvdflt.o: bits/xf_left bits/xf_right bits/font5x9.h
--xvdflt.o: xvdflt.h
-+xvdflt.o: xvdflt.h
-
- xvdial.o: bits/dial_cw1 bits/dial_ccw1 bits/dial_cw2 bits/dial_ccw2
-
- xvdir.o: bits/d_load bits/d_save
-
--xvevent.o: bits/dropper bits/dropperm bits/pen bits/penm
-+xvevent.o: bits/dropper bits/dropperm bits/pen bits/penm
- xvevent.o: bits/blur bits/blurm
-
- xvgam.o: bits/h_rotl bits/h_rotr bits/h_flip bits/h_sinc bits/h_sdec
-diff -ru xv-3.10a/bggen.c xv-3.10a-enhancements/bggen.c
---- xv-3.10a/bggen.c 1994-12-22 14:34:41.000000000 -0800
-+++ xv-3.10a-enhancements/bggen.c 2005-04-17 14:04:22.000000000 -0700
-@@ -18,6 +18,11 @@
- #include
- #include
-
-+#ifdef __STDC__
-+# include /* atoi() */
-+# include /* isdigit() */
-+#endif
-+
- #ifndef M_PI
- # define M_PI 3.1415926535897932385
- #endif
-@@ -29,7 +34,7 @@
- #define MAXCOLS 128
-
- /* some VMS thing... */
--#ifdef vax11c
-+#if defined(vax11c) || (defined(__sony_news) && (defined(bsd43) || defined(__bsd43) || defined(SYSTYPE_BSD) || defined(__SYSTYPE_BSD)))
- #include
- #endif
-
-@@ -46,8 +51,8 @@
-
- typedef unsigned char byte;
-
--struct color { int r,g,b;
-- int y;
-+struct color { int r,g,b;
-+ int y;
- } colors[MAXCOLS], *cur, *nex;
-
- int numcols;
-@@ -62,7 +67,7 @@
- double computeDist PARM((int, int, int, int, int));
- void writePPM PARM((byte *, int, int, int));
-
--
-+
- /*************************************/
- int main(argc,argv)
- int argc;
-@@ -80,18 +85,18 @@
- char *geom = NULL;
- char *rptgeom = NULL;
-
--
-+
- #ifdef VMS
- getredirection(&argc, &argv);
- #endif
--
-+
-
- for (i=1; i8) usage();
--
--
-+
-+
- if (geom) {
- int x,y; unsigned int w,h;
- i = XParseGeometry(geom, &x, &y, &w, &h);
- if (i&WidthValue) { wset++; wide = (int) w; }
- if (i&HeightValue) { hset++; high = (int) h; }
- }
--
--
-+
-+
- /* attempt to connect to X server and get screen dimensions */
- if (theDisp) {
- i = DefaultScreen(theDisp);
- if (!wset) wide = DisplayWidth(theDisp, i);
- if (!hset) high = DisplayHeight(theDisp, i);
- }
--
--
-+
-+
- /* normalize 'rot' */
- while (rot< 0) rot += 360;
- while (rot>=360) rot -= 360;
--
--
-+
-+
- rptwide = wide; rpthigh = high;
- if (rptgeom) {
- int x,y; unsigned int w,h;
- i = XParseGeometry(rptgeom, &x, &y, &w, &h);
- if (i&WidthValue) rptwide = (int) w;
- if (i&HeightValue) rpthigh = (int) h;
--
-+
- RANGE(rptwide, 1, wide);
- RANGE(rpthigh, 1, high);
- }
--
--
-
--
-+
-+
-+
- rpic24 = (byte *) malloc(rptwide * rpthigh * 3 * sizeof(byte));
-- if (rptwide != wide || rpthigh != high)
-+ if (rptwide != wide || rpthigh != high)
- pic24 = (byte *) malloc(wide * high * 3 * sizeof(byte));
- else pic24 = rpic24;
-
-@@ -229,7 +234,7 @@
- exit(1);
- }
- for (i=0, pp=pic24; iy < i) { cur++; nex++; }
--
-+
- r = cur->r + ((nex->r - cur->r) * (i - cur->y)) / (nex->y - cur->y);
- g = cur->g + ((nex->g - cur->g) * (i - cur->y)) / (nex->y - cur->y);
- b = cur->b + ((nex->b - cur->b) * (i - cur->y)) / (nex->y - cur->y);
--
-+
- r = r & bmask[bits-1];
- g = g & bmask[bits-1];
- b = b & bmask[bits-1];
--
-+
- for (j=0; j1.0) rat = 1.0;
--
-+
- cval = rat * nc1;
- bc = floor(cval);
- crat = cval - bc;
--
-+
- if (bc < nc1) {
- r = colors[bc].r + crat * (colors[bc+1].r - colors[bc].r);
- g = colors[bc].g + crat * (colors[bc+1].g - colors[bc].g);
-@@ -383,7 +388,7 @@
- g = colors[nc1].g;
- b = colors[nc1].b;
- }
--
-+
- *pp++ = (byte) r; *pp++ = (byte) g; *pp++ = (byte) b;
- }
- }
-@@ -395,9 +400,9 @@
- int x,y,cx,cy,rot;
- {
- /* rot has to be in range 0-359 */
--
-- double x1, y1, x2, y2, x3, y3, d, d1, b, theta;
--
-+
-+ double x1, y1, x2, y2, x3, y3, d, d1, b;
-+
- if (rot == 0) return (double) (y - cy);
- if (rot == 180) return (double) (cy - y);
-
-@@ -407,7 +412,7 @@
- /* x2,y2 = vertical projection onto a || line that runs through cx,cy */
- x2 = x1;
- y2 = cy - (cx-x2)*tant1;
--
-+
- d1 = y2 - y1; /* vertical distance between lines */
- b = d1 * cost1;
-
-@@ -435,11 +440,11 @@
- int w,h,doascii;
- {
- /* dumps a pic24 in PPM format to stdout */
--
-+
- int x,y;
--
-+
- printf("P%s %d %d 255\n", (doascii) ? "3" : "6", w, h);
--
-+
- for (y=0; y, which I don't know all
-+ machine has or not.
-+ */
- # undef UNCOMPRESS
--# define UNCOMPRESS "/usr/bin/uncompress"
-+# define UNCOMPRESS "uncompress"
- #endif
-
- #if defined(sgi)
-@@ -70,18 +94,18 @@
- * PostScript file input support:
- *
- * if you have the 'ghostscript' package installed (version 2.6 or later),
-- * XV can use it to read and display PostScript files. To do so,
-+ * XV can use it to read and display PostScript files. To do so,
- * uncomment the '#define GS_PATH' line, below. You probably will not
- * need to modify the GS_LIB or GS_DEV lines, but if you do modify them,
- * be sure to uncomment them, as well.
- *
-- * the ghostscript package can be acquired via anonymous ftp on
-+ * the ghostscript package can be acquired via anonymous ftp on
- * prep.ai.mit.edu, in the 'pub/gnu' directory
- *
-- * GS_PATH specifies the complete path to your gs executable.
-+ * GS_PATH specifies the complete path to your gs executable.
- *
-- * GS_LIB should be set if there's some other gs libs that should be
-- * searched, but aren't by default. (In which case you should probably
-+ * GS_LIB should be set if there's some other gs libs that should be
-+ * searched, but aren't by default. (In which case you should probably
- * just fix your 'gs' so it looks in the right places without being told...)
- *
- * GS_DEV is the file format that ghostscript will convert PS into. It
-@@ -89,6 +113,7 @@
- */
-
- /* #define GS_PATH "/usr/local/bin/gs" */
-+#define GS_PATH "gs"
- /* #define GS_LIB "." */
- /* #define GS_DEV "ppmraw" */
-
-@@ -97,10 +122,10 @@
- * 'old-style' XV logo image:
- *
- * XV now has a nifty, new logo image. The downside is that it increases
-- * the size of the 'xv' executable by 250K or so, and it's possible that
-- * your compiler may choke while compiling 'xvdflt.c'. If you're compiler
-+ * the size of the 'xv' executable by 250K or so, and it's possible that
-+ * your compiler may choke while compiling 'xvdflt.c'. If your compiler
- * can't handle it, or you're running Linux on a system with minimal memory,
-- * change 'undef' to 'define' in the following line
-+ * change 'undef' to 'define' in the following line:
- */
-
- #undef USEOLDPIC
-@@ -108,8 +133,8 @@
-
- /***************************************************************************
- * Backing Store:
-- *
-- * XV can request that 'Backing Store' may be turned on ('WhenMapped') for
-+ *
-+ * XV can request that 'Backing Store' may be turned on ('WhenMapped') for
- * several of its windows, which may help performance over a slow network
- * connection. However, it has been known to behave strangely (or crash)
- * on some X servers, so it's left here as an option. If you run into trouble
-@@ -119,3 +144,218 @@
-
- #define BACKING_STORE
-
-+
-+/***************************************************************************
-+ * TIFF YCbCr-to-RGB conversion:
-+ *
-+ * Newer versions of libtiff can be compiled with libjpeg for JPEG-in-TIFF
-+ * support, and according to Scott Marovich, "the IJG JPEG Library...sometimes
-+ * seems to produce slightly more accurate results" (one known example: the
-+ * 'quad-jpeg.tif' test image). In addition, libtiff can be compiled with
-+ * "old JPEG" support, although its configure script will not enable that by
-+ * default. Change 'define' and 'undef' in the following lines as you wish,
-+ * but note that defining LIBTIFF_HAS_OLDJPEG_SUPPORT when such is _not_ the
-+ * case will result in crashes when encountering old-JPEG TIFFs:
-+ */
-+
-+#define USE_LIBJPEG_FOR_TIFF_YCbCr_RGB_CONVERSION
-+#undef LIBTIFF_HAS_OLDJPEG_SUPPORT
-+
-+
-+/***************************************************************************
-+ * PhotoCD/MAG/PIC/MAKI/Pi/PIC2/HIPS format Support:
-+ *
-+ * if, for whatever reason--say, security concerns--you don't want to
-+ * include support for one or more of the PhotoCD, MAG/MAKI/Pi/PIC/PIC2
-+ * (Japanese), or HIPS (astronomical) image formats, change the relevant
-+ * 'define' to 'undef' in the following lines. Conversely, if you *do*
-+ * want them, change 'undef' to 'define' as appropriate.
-+ */
-+
-+#define HAVE_PCD /* believed to be reasonably safe */
-+
-+#undef HAVE_MAG /* probable security issues */
-+#undef HAVE_MAKI /* probable security issues */
-+#undef HAVE_PI /* probable security issues */
-+#undef HAVE_PIC /* probable security issues */
-+#undef HAVE_PIC2 /* probable security issues */
-+
-+#undef HAVE_HIPS /* probable security issues */
-+
-+
-+/***************************************************************************
-+ * MacBinary file support:
-+ *
-+ * if you want XV to be able to handle ``MacBinary'' files (which have
-+ * 128 byte info file header at the head), change 'undef' to 'define'
-+ * in the following line.
-+ */
-+
-+#undef MACBINARY
-+
-+
-+/***************************************************************************
-+ * Auto Expand support:
-+ *
-+ * if you want to extract archived file automatically and regard it as
-+ * a directory, change 'undef' to 'define' in the AUTO_EXPAND line.
-+ *
-+ * Virtual Thumbdir support:
-+ *
-+ * if you want Virtual directory based Thumbdir(It means that XV
-+ * doesn't forget builded Icons still be quited even if the directory
-+ * is read-only), change 'undef' to 'define' the VIRTUAL_TD line.
-+ */
-+
-+#undef AUTO_EXPAND
-+#undef VIRTUAL_TD
-+
-+#if defined(VIRTUAL_TD) && !defined(AUTO_EXPAND)
-+# undef VIRTUAL_TD
-+#endif
-+
-+
-+/***************************************************************************
-+ * Adjust the aspect ratio of Icons:
-+ *
-+ * if you want to adjust the aspect ratio of the icons in Visual
-+ * Schnauzer, change 'undef' to 'define' in the following line.
-+ */
-+
-+#undef VS_ADJUST
-+
-+
-+/***************************************************************************
-+ * Restore original colormap:
-+ *
-+ * if you want to restore original colormap when icons in Visual
-+ * Shunauzer is double-clicked, change 'undef' to 'define' in the
-+ * following line.
-+ */
-+
-+#undef VS_RESCMAP
-+
-+
-+/***************************************************************************
-+ * TextViewer l10n support:
-+ *
-+ * if you want XV to show the text in Japanese on TextViewer, change
-+ * 'undef' to 'define' in the following line.
-+ */
-+
-+#undef TV_L10N
-+
-+#ifdef TV_L10N
-+/*
-+ * if you want to change the default code-set used in case that XV
-+ * fails to select correct code-set, uncomment the '#define
-+ * LOCALE_DEFAULT' line and change the 'LOCALE_DEFAULT' definition
-+ * appropriately.
-+ * (0:ASCII, 1:EUC-j, 2:JIS, 3:MS Kanji) */
-+
-+/* # define LOCALE_DEFAULT 0 */
-+
-+/*
-+ * Uncomment and edit the following lines, if your X Window System was
-+ * not compiled with -DX_LOCALE and you failed to display the Japanese
-+ * text in TextViewer. You don't have to write locale name of JIS code-set
-+ * and Microsoft code-set, if your system doesn't support those code-sets.
-+ */
-+
-+/*
-+# define LOCALE_NAME_EUC "ja_JP.EUC"
-+# define LOCALE_NAME_JIS "ja_JP.JIS"
-+# define LOCALE_NAME_MSCODE "ja_JP.SJIS"
-+*/
-+
-+/*
-+ * if your system doesn't have the Japanese fonts in the sizes,
-+ * Uncomment and edit the following font size entries.
-+ */
-+
-+/* # define TV_FONTSIZE 14,16,24 */
-+
-+/*
-+ * If you need, uncomment and modify the following font name.
-+ */
-+
-+/* # define TV_FONTSET "-*-fixed-medium-r-normal--%d-*" */
-+#endif /* TV_L10N */
-+
-+
-+/***************************************************************************
-+ * User definable filter support:
-+ *
-+ * Use the filters as input and output method for load and save unsupported
-+ * image format file. The filter command is recognized by definition of
-+ * magic number or suffix in "~/.xv_mgcsfx" .
-+ * To enable this feature, change 'undef' to 'define' in the following line.
-+ */
-+#undef HAVE_MGCSFX
-+
-+#ifdef HAVE_MGCSFX
-+/*
-+ * Support symbol 'auto' as in startup file. This type
-+ * cannot use pipe as input; it writes to a temporary file and recognizes
-+ * the actual filetype by XV processing.
-+ */
-+# define HAVE_MGCSFX_AUTO
-+
-+/*
-+ * The startup file of definition for MgcSfx. 'MGCSFX_SITE_RC' is read
-+ * first and '~/MGCSFX_RC' is second. So same definitions in both files
-+ * are overridden by '~/MGCSFX_RC'
-+ * To define startup file, see the sample of startup file 'xv_mgcsfx.sample'.
-+ */
-+# define MGCSFX_SITE_RC "xv_mgcsfx"
-+# define MGCSFX_RC ".xv_mgcsfx"
-+
-+/*
-+ * If you want startup file to pass preprocessor in reading time, then
-+ * change 'undef' to 'define' in the following line.
-+ *
-+ * WARNING : If you decide to use preprocessor, you must not write
-+ * '# ' style comment in startup file. Because,
-+ * preprocessor can't recognize. */
-+# undef USE_MGCSFX_PREPROCESSOR
-+
-+# ifdef USE_MGCSFX_PREPROCESSOR
-+/*
-+ * This is used like "system("MGCSFX_PREPROCESSOR MGCSFX_RC > tmp_name");",
-+ * and read tmp_name instead of MGCSFX_RC.
-+ */
-+# define MGCSFX_PREPROCESSOR "/usr/lib/cpp"
-+/* # define MGCSFX_PREPROCESSOR "cc -E" */
-+
-+# endif /* USE_MGCSFX_PREPROCESSOR */
-+
-+/*
-+ * Default string of command. If input command is required for undefined file,
-+ * dialog is popuped with 'MGCSFX_DEFAULT_INPUT_COMMAND'. And, if output
-+ * command is required in save dialog of MgcSfx, dialog is popuped with
-+ * 'MGCSFX_DEFAULT_OUTPUT_COMMAND'.
-+ *
-+ * WARNING : Now, supported only 'PNM' image format, when command input is
-+ * required. You should define filter which use 'PNM' image format
-+ * as input or output.
-+ */
-+# define MGCSFX_DEFAULT_INPUT_COMMAND "tifftopnm"
-+# define MGCSFX_DEFAULT_OUTPUT_COMMAND "pnmtotiff"
-+
-+#endif /* HAVE_MGCSFX */
-+
-+
-+/***************************************************************************
-+ * Multi-Lingual TextViewer
-+ *
-+ * if you want XV to show the text in multi-lingual on TextViewer, change
-+ * 'undef' to 'define' in the following line.
-+ */
-+
-+#undef TV_MULTILINGUAL
-+
-+#define TV_DEFAULT_CODESET TV_EUC_JAPAN
-+
-+#ifdef TV_MULTILINGUAL
-+# undef TV_L10N
-+#endif
-diff -ru xv-3.10a/copyright.h xv-3.10a-enhancements/copyright.h
---- xv-3.10a/copyright.h 1994-12-22 14:34:56.000000000 -0800
-+++ xv-3.10a-enhancements/copyright.h 2007-05-20 21:35:34.000000000 -0700
-@@ -1,11 +1,11 @@
- /* Copyright Notice
- * ================
- * Copyright 1989, 1994 by John Bradley
-- *
-- * Permission to copy and distribute XV in its entirety, for non-commercial
-- * purposes, is hereby granted without fee, provided that this license
-+ *
-+ * Permission to copy and distribute XV in its entirety, for non-commercial
-+ * purposes, is hereby granted without fee, provided that this license
- * information and copyright notice appear unmodified in all copies.
-- *
-+ *
- * Note that distributing XV 'bundled' in with any product is considered
- * to be a 'commercial purpose'.
- *
-@@ -13,16 +13,16 @@
- * and/or configured to be in their 'unregistered copy' mode, so that it
- * is made obvious to the user that XV is shareware, and that they should
- * consider donating, or at least reading this License Info.
-- *
-+ *
- * The software may be modified for your own purposes, but modified
- * versions may not be distributed without prior consent of the author.
-- *
-+ *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the author be held liable for any damages
- * arising from the use of this software.
-- *
-+ *
- * If you would like to do something with XV that this copyright
-- * prohibits (such as distributing it with a commercial product,
-+ * prohibits (such as distributing it with a commercial product,
- * using portions of the source in some other program, etc.), please
- * contact the author (preferably via email). Arrangements can
- * probably be worked out.
-@@ -34,13 +34,13 @@
- * larger donations are quite welcome. Folks who donate $25 or more
- * can receive a Real Nice bound copy of the XV manual for no extra
- * charge.
-- *
-+ *
- * Commercial, government, and institutional users must register their
- * copies of XV, for the price of $25 per workstation/X terminal or per
- * XV user, whichever is less. Note that it does NOT say 'simultaneous user',
-- * but rather, the total number of people who use XV on any sort of
-- * recurring basis. Site licenses are available (and recommended) for those
-- * who wish to run XV on a large (>10) number of machines.
-+ * but rather, the total number of people who use XV on any sort of
-+ * recurring basis. Site licenses are available (and recommended) for those
-+ * who wish to run XV on a large (>10) number of machines.
- * Contact the author for more details.
- *
- * The author may be contacted via:
-@@ -56,3 +56,51 @@
- * The author may not be contacted by (voice) phone. Please don't try.
- *
- */
-+
-+/*
-+ * Portions copyright 2000-2007 by Greg Roelofs and contributors:
-+ *
-+ * Andrey A. Chernov [ache]
-+ * (http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-ab)
-+ * Andreas Dilger (adilger clusterfs.com)
-+ * Alexander Lehmann (lehmann usa.net)
-+ * Alexey Spiridonov (http://www-math.mit.edu/~lesha/)
-+ * Anthony Thyssen (http://www.cit.gu.edu.au/~anthony/)
-+ * Bruno Rohee (http://bruno.rohee.com/)
-+ * David A. Clunie (http://www.dclunie.com/xv-pcd.html)
-+ * Erling A. Jacobsen (linuxcub email.dk)
-+ * Egmont Koblinger (egmont users.sourceforge.net)
-+ * Fabian Greffrath (fabian debian-unofficial.org)
-+ * Greg Roelofs (http://pobox.com/~newt/greg_contact.html)
-+ * Guido Vollbeding (http://sylvana.net/guido/)
-+ * IKEMOTO Masahiro (ikeyan airlab.cs.ritsumei.ac.jp)
-+ * John Cooper (john.cooper third-harmonic.com)
-+ * John C. Elliott (http://www.seasip.demon.co.uk/ZX/zxdload.html)
-+ * John D. Baker (http://mylinuxisp.com/~jdbaker/)
-+ * Jörgen Grahn (jgrahn algonet.se)
-+ * John H. Bradley, of course (http://www.trilon.com/xv/)
-+ * Jean-Pierre Demailly (http://www-fourier.ujf-grenoble.fr/~demailly/)
-+ * John Rochester (http://www.freebsd.org/cgi/query-pr.cgi?pr=2920)
-+ * (also http://cvsweb.freebsd.org/ports/graphics/xv/files/patch-af, -ag)
-+ * James Roberts Kirkpatrick (uwyo.edu)
-+ * Joe Zbiciak (http://spatula-city.org/~im14u2c/)
-+ * Kyoichiro Suda (http://www.coara.or.jp/~sudakyo/XV_jp.html)
-+ * Landon Curt "chongo" Noll (http://www.isthe.com/chongo/)
-+ * Larry Jones (lawrence.jones ugs.com)
-+ * Peter Jordan (http://www.ibiblio.org/pub/Linux/apps/graphics/viewers/X/)
-+ * Pawel S. Veselov (http://manticore.2y.net/wbmp.html)
-+ * Ross Combs (rocombs cs.nmsu.edu)
-+ * Robin Humble (http://www.cita.utoronto.ca/~rjh/)
-+ * Sean Borman (http://www.nd.edu/~sborman/software/xvwheelmouse.html)
-+ * TenThumbs (tenthumbs cybernex.net)
-+ * Scott B. Marovich (formerly marovich hpl.hp.com)
-+ * Tim Adye (http://hepwww.rl.ac.uk/Adye/xv-psnewstyle.html)
-+ * Tim Ramsey (tar pobox.com)
-+ * Tetsuya INOUE (tin329 chino.it.okayama-u.ac.jp)
-+ * Tavis Ormandy (taviso gentoo.org)
-+ * Werner Fink (http://www.suse.de/~werner/)
-+ *
-+ * Other credits are as listed on the XV Downloads page or in the respective
-+ * patches (e.g., the jp-extension patches or within the PNG patch).
-+ *
-+ */
-diff -ru xv-3.10a/docs/bggen.man xv-3.10a-enhancements/docs/bggen.man
---- xv-3.10a/docs/bggen.man 1994-12-22 14:35:22.000000000 -0800
-+++ xv-3.10a-enhancements/docs/bggen.man 2007-04-22 17:32:11.000000000 -0700
-@@ -1,4 +1,4 @@
--.TH bggen l
-+.TH bggen 1
- .SH NAME
- bggen \- generates colored backgrounds on X11 displays
- .SH SYNTAX
-diff -ru xv-3.10a/docs/xcmap.man xv-3.10a-enhancements/docs/xcmap.man
---- xv-3.10a/docs/xcmap.man 1994-12-22 14:35:23.000000000 -0800
-+++ xv-3.10a-enhancements/docs/xcmap.man 2007-04-22 17:32:31.000000000 -0700
-@@ -1,4 +1,4 @@
--.TH xcmap 1X
-+.TH xcmap 1
- .SH NAME
- xcmap \- displays the default colormap on X11 displays
- .SH SYNTAX
-diff -ru xv-3.10a/docs/xv.man xv-3.10a-enhancements/docs/xv.man
---- xv-3.10a/docs/xv.man 1994-12-22 14:35:22.000000000 -0800
-+++ xv-3.10a-enhancements/docs/xv.man 2007-04-22 17:32:53.000000000 -0700
-@@ -1,4 +1,4 @@
--.TH XV l "2 December 1994" "Rev. 3.10"
-+.TH XV 1 "22 April 2007" "Rev. 3.10a-jumboFix+Enh"
- .SH NAME
- \fBxv\fP \- interactive image display for the X Window System
- .SH SYNTAX
-@@ -8,14 +8,17 @@
- .SH DESCRIPTION
- The
- .I xv
--program displays images in the GIF, JPEG, TIFF,
--PBM, PGM, PPM, X11 bitmap, Utah Raster Toolkit RLE, PDS/VICAR, Sun Rasterfile,
--BMP, PCX, IRIS RGB, XPM, Targa, XWD, possibly PostScript, and PM formats on
--workstations and terminals running the X Window System, Version 11.
-+program displays images on workstations and terminals running the X Window
-+System, Version 11. Supported image formats include
-+PBM, PGM, PPM, X11 bitmap, XWD, XPM, Utah Raster Toolkit RLE, PDS/VICAR,
-+FITS, Sun Rasterfile, GIF, PCX, Targa/TGA, BMP, WBMP, IRIS RGB, Spectrum
-+SCREEN$, PM, and optionally PNG, JPEG, JPEG 2000, JP2, TIFF, PostScript,
-+PDF, G3 fax, MAG, PIC, MAKI (640x400), PI, and PIC2.
- .LP
--The documentation for XV is now distributed
-+Aside from the usage screen (available by typing 'xv -help' at the command
-+line), documentation for XV is now distributed
- .I only
--as a PostScript file, as it has gotten enormous,
-+as a PostScript (or PDF) file, as it has gotten enormous
- and is no longer very well suited to the 'man' page format.
- Print a copy of the (100-ish page) manual found in
- .IR docs/xvdocs.ps .
-@@ -26,9 +29,14 @@
- If you don't
- .I have
- the PostScript file, it is part of the standard XV distribution, the
--latest version of which can be obtained via anonymous ftp from
-+latest version of which can be obtained from
-+.IR http://www.trilon.com/xv/
-+or via anonymous ftp from
- .IR ftp.cis.upenn.edu
--in the directory pub/xv
-+in the directory pub/xv .
-+.PP
-+This version has been patched with the XV Jumbo Patches, available from
-+.IR http://pobox.com/~newt/greg_xv.html .
- .PP
- .SH AUTHOR
--John Bradley
-+John Bradley (and many contributors)
-diff -ru xv-3.10a/docs/xvp2p.man xv-3.10a-enhancements/docs/xvp2p.man
---- xv-3.10a/docs/xvp2p.man 1994-12-22 14:35:25.000000000 -0800
-+++ xv-3.10a-enhancements/docs/xvp2p.man 2007-04-22 17:33:23.000000000 -0700
-@@ -1,4 +1,4 @@
--.TH xvpictoppm 1X
-+.TH xvpictoppm 1
- .SH NAME
- xvpictoppm \- converts XV 'thumbnail' files to standard PPM format
- .SH SYNTAX
-diff -ru xv-3.10a/tiff/Makefile xv-3.10a-enhancements/tiff/Makefile
---- xv-3.10a/tiff/Makefile 1994-12-22 14:35:12.000000000 -0800
-+++ xv-3.10a-enhancements/tiff/Makefile 2005-04-17 14:45:28.000000000 -0700
-@@ -30,13 +30,15 @@
- # OF THIS SOFTWARE.
- #
-
--AR= ar
--RANLIB= ./RANLIB.csh
-+AR= ar
-+CHMOD= chmod
-+#RANLIB= ./RANLIB.csh
-+RANLIB= ./RANLIB.sh
-
- IPATH= -I.
-
- COPTS= -O
--CFLAGS= ${COPTS} ${IPATH}
-+CFLAGS= ${COPTS} ${IPATH} -D_BSD_SOURCE
-
- INCS= tiff.h tiffio.h
-
-@@ -60,6 +62,7 @@
-
- ${ALL}: ${OBJS}
- ${AR} rc libtiff.a $?
-+ ${CHMOD} +x ${RANLIB}
- ${RANLIB} libtiff.a
-
- ${OBJS}: tiffio.h tiff.h tiffcomp.h tiffiop.h tiffconf.h
-diff -ru xv-3.10a/tiff/Makefile.std xv-3.10a-enhancements/tiff/Makefile.std
---- xv-3.10a/tiff/Makefile.std 1994-12-22 14:35:16.000000000 -0800
-+++ xv-3.10a-enhancements/tiff/Makefile.std 2004-05-16 18:50:39.000000000 -0700
-@@ -30,8 +30,10 @@
- # OF THIS SOFTWARE.
- #
-
--AR= /bin/ar
--RANLIB= ./RANLIB.csh
-+AR= /bin/ar
-+CHMOD= chmod
-+#RANLIB= ./RANLIB.csh
-+RANLIB= ./RANLIB.sh
-
- IPATH= -I.
-
-@@ -60,6 +62,7 @@
-
- ${ALL}: ${OBJS}
- ${AR} rc libtiff.a $?
-+ ${CHMOD} +x ${RANLIB}
- ${RANLIB} libtiff.a
-
- ${OBJS}: tiffio.h tiff.h tiffcomp.h tiffiop.h tiffconf.h
-diff -ru xv-3.10a/vdcomp.c xv-3.10a-enhancements/vdcomp.c
---- xv-3.10a/vdcomp.c 1994-12-22 14:34:47.000000000 -0800
-+++ xv-3.10a-enhancements/vdcomp.c 2007-04-15 21:09:55.000000000 -0700
-@@ -5,8 +5,8 @@
- /* Decompresses images using Kris Becker's subroutine DECOMP.C */
- /* which is included in this program in a shortened version. */
- /* */
--/* Reads a variable length compressed PDS image and outputs a */
--/* fixed length uncompressed image file in PDS format with */
-+/* Reads a variable-length compressed PDS image and outputs a */
-+/* fixed-length uncompressed image file in PDS format with */
- /* labels, image histogram, engineering table, line header table */
- /* and an image with PDS, FITS, VICAR or no labels. If used on */
- /* a non-byte-swapped machine the image histogram is un-swapped. */
-@@ -96,40 +96,54 @@
- #include
- #include
-
--/* include a malloc.h, of some sort... */
--#ifndef VMS /* VMS hates multi-line '#if's */
--# if !defined(ibm032) && \
-- !defined(__convex__) && \
-- !(defined(vax) && !defined(ultrix)) && \
-- !defined(mips) && \
-- !defined(apollo) && \
-- !defined(pyr) && \
-- !defined(__UMAXV__) && \
-- !defined(bsd43) && \
-- !defined(aux) && \
-- !defined(__bsdi__) && \
-- !defined(sequent)
--
--# if defined(hp300) || defined(hp800) || defined(NeXT)
--# include /* it's in 'sys' on HPs and NeXT */
--# else
--# include
--# endif
--# endif
-+/* include a malloc.h of some sort (if needed...most systems use stdlib.h) */
-+#ifndef VMS /* VMS hates multi-line "#if"s */
-+ /*
-+ * I want to use BSD macro for checking if this OS is *BSD or not,
-+ * but the macro is defined in , which I don't know all
-+ * machine has or not.
-+ */
-+# if !defined(ibm032) && \
-+ !defined(__convex__) && \
-+ !(defined(vax) && !defined(ultrix)) && \
-+ !defined(mips) && \
-+ !defined(apollo) && \
-+ !defined(pyr) && \
-+ !defined(sequent) && \
-+ !defined(__UMAXV__) && \
-+ !defined(aux) && \
-+ !defined(bsd43) && \
-+ !defined(__bsd43) && \
-+ !defined(__bsdi__) && \
-+ !defined(__386BSD__) && \
-+ !defined(__FreeBSD__) && \
-+ !defined(__OpenBSD__) && \
-+ !defined(__NetBSD__) && \
-+ !defined(__DARWIN__)
-+
-+# if defined(hp300) || defined(hp800) || defined(NeXT)
-+# include /* it's in "sys" on HPs and NeXT */
-+# else
-+# include /* FIXME: should explicitly list systems that NEED this, not everyone that doesn't */
-+# endif
-+
-+# endif /* !most modern systems */
- #endif /* !VMS */
-
-
- #include
-
--#define TRUE 1
--#define FALSE 0
-+#define TRUE 1
-+#define FALSE 0
-+
-+#define NAMELEN 1024 /* inname and outname sizes */
-
-- /* pc i/o defines */
--#define O_BINARY 0x8000 /* file mode is binary */
-+ /* PC I/O defines */
-+#define O_BINARY 0x8000 /* file mode is binary */
-
-- /* vax i/o defines */
--#define RECORD_TYPE "rfm=fix" /* VAX fixed length output */
--#define CTX "ctx=bin" /* no translation of \n */
-+ /* VAX/VMS I/O defines */
-+#define RECORD_TYPE "rfm=fix" /* VAX/VMS fixed-length output */
-+#define CTX "ctx=bin" /* no translation of \n */
- #define FOP "fop=cif,sup" /* file processing ops */
-
- typedef struct leaf { struct leaf *right;
-@@ -142,9 +156,9 @@
- once the tree is created by the accompanying routine huff_tree.
- **************************************************************************/
-
-- NODE *tree;
-+static NODE *tree;
-
--/* subroutine definitions */
-+/* subroutine definitions */
-
- #undef PARM
- #ifdef __STDC__
-@@ -172,11 +186,11 @@
- void free_tree PARM((int *));
- int free_node PARM((NODE *, int));
-
--/* global variables */
-+/* global variables */
-
- int infile;
- FILE *outfile;
--char inname[1024],outname[1024];
-+char inname[NAMELEN], outname[NAMELEN];
- int output_format;
- int record_bytes, max_lines;
- int line_samples, fits_pad;
-@@ -185,8 +199,8 @@
-
- /*************************************************/
- int main(argc,argv)
-- int argc;
-- char **argv;
-+ int argc;
-+ char **argv;
- {
- unsigned char ibuf[2048],obuf[2048];
- unsigned char blank=32;
-@@ -200,12 +214,12 @@
- /* */
- /*********************************************************************/
-
-- strcpy(inname," ");
-+ strcpy(inname," ");
- strcpy(outname," ");
- output_format = 0;
-
- if (argc == 1); /* prompt user for parameters */
-- else if (argc == 2 && (strncmp(argv[1],"help",(size_t) 4) == 0 ||
-+ else if (argc == 2 && (strncmp(argv[1],"help",(size_t) 4) == 0 ||
- strncmp(argv[1],"HELP",(size_t) 4) == 0 ||
- strncmp(argv[1],"?", (size_t) 1) == 0)) {
- fprintf(stderr,
-@@ -214,18 +228,22 @@
- fprintf(stderr," infile - name of compressed image file. \n");
- fprintf(stderr," outfile - name of uncompressed output file.\n");
- fprintf(stderr," output format - selected from the following list:\n");
-- fprintf(stderr,"\n");
-- fprintf(stderr," 1 SFDU/PDS format [DEFAULT].\n");
-- fprintf(stderr," 2 FITS format. \n");
-- fprintf(stderr," 3 VICAR format. \n");
-- fprintf(stderr," 4 Unlabelled binary array. \n\n");
-+ fprintf(stderr,"\n");
-+ fprintf(stderr," 1 SFDU/PDS format [DEFAULT].\n");
-+ fprintf(stderr," 2 FITS format. \n");
-+ fprintf(stderr," 3 VICAR format. \n");
-+ fprintf(stderr," 4 Unlabelled binary array. \n\n");
- exit(1);
-- }
-+ }
- else {
-- strcpy(inname,argv[1]);
-- if (argc >= 3) strcpy(outname,argv[2]);
-+ strncpy(inname, argv[1], sizeof(inname)-1);
-+ inname[sizeof(inname)-1] = '\0';
-+ if (argc >= 3) {
-+ strncpy(outname, argv[2], sizeof(outname)-1);
-+ outname[sizeof(outname)-1] = '\0';
-+ }
- if (argc == 3) output_format = 1;
-- if (argc == 4) sscanf(argv[3],"%d",&output_format);
-+ if (argc == 4) sscanf(argv[3],"%d",&output_format);
- }
-
- host = check_host();
-@@ -244,13 +262,13 @@
- case 4: no_labels(host); break;
- }
-
-- if (record_bytes == 836) { /* set up values for image sizes */
-+ if (record_bytes == 836) { /* set up values for image sizes */
- max_lines = 800;
- fits_pad = 2240;
- line_samples = 800;
- }
- else {
-- max_lines = 1056;
-+ max_lines = 1056;
- fits_pad = 1536;
- line_samples = 1204;
- }
-@@ -394,12 +412,12 @@
- if (record_bytes == 1204) /* do checksum for viking */
- for (i=0; i 0 && line < max_lines);
-
-- if (record_bytes == 1204 && (outfile != stdout))
-+ if (record_bytes == 1204 && (outfile != stdout))
- /* print checksum for viking */
- fprintf(stderr,"\n Image label checksum = %d computed checksum = %d\n",
- label_checksum,checksum);
-@@ -425,33 +443,36 @@
- /*********************************************************************/
-
- int get_files(host)
--int host;
-+ int host;
- {
-- short shortint;
- typedef long off_t;
-+ short shortint;
-+ char *s;
-
- if (inname[0] == ' ') {
- printf("\nEnter name of file to be decompressed: ");
-- gets (inname);
-+ fgets(inname, sizeof(inname), stdin);
-+ if ((s = strchr(inname, '\n')) != NULL)
-+ *s = '\0';
- }
-
-- if (host == 1 | host == 2) {
-- if ((infile = open(inname,O_RDONLY | O_BINARY)) <= 0) {
-- fprintf(stderr,"\ncan't open input file: %s\n",inname);
-+ if (host == 1 || host == 2) {
-+ if ((infile = open(inname, O_RDONLY | O_BINARY)) <= 0) {
-+ fprintf(stderr,"\ncan't open input file: %s\n", inname);
- exit(1);
- }
- }
-- else if (host == 3 | host == 5) {
-- if ((infile = open(inname,O_RDONLY)) <= 0) {
-- fprintf(stderr,"\ncan't open input file: %s\n",inname);
-+ else if (host == 3 || host == 5) {
-+ if ((infile = open(inname, O_RDONLY)) <= 0) {
-+ fprintf(stderr,"\ncan't open input file: %s\n", inname);
- exit(1);
- }
-
- /****************************************************************/
-- /* If we are on a vax see if the file is in var length format. */
-- /* This logic is in here in case the vax file has been stored */
-+ /* If we are on a VAX see if the file is in var length format. */
-+ /* This logic is in here in case the VAX file has been stored */
- /* in fixed or undefined format. This might be necessary since */
-- /* vax variable length files can't be moved to other computer */
-+ /* VAX variable-length files can't be moved to other computer */
- /* systems with standard comm programs (kermit, for example). */
- /****************************************************************/
-
-@@ -459,9 +480,9 @@
- read(infile,&shortint, (size_t) 2);
- if (shortint > 0 && shortint < 80) {
- host = 4; /* change host to 4 */
-- printf("This is not a VAX variable length file.");
-+ printf("This is not a VAX variable-length file.");
- }
-- else printf("This is a VAX variable length file.");
-+ else printf("This is a VAX variable-length file.");
- lseek(infile,(off_t) 0,0); /* reposition to beginning of file */
- }
- }
-@@ -474,13 +495,17 @@
- printf("\n 3. VICAR format.");
- printf("\n 4. Unlabelled binary array.\n");
- printf("\n Enter format number:");
-- gets(inname);
-+ fgets(inname, sizeof(inname), stdin);
-+ if ((s = strchr(inname, '\n')) != NULL)
-+ *s = '\0';
- output_format = atoi(inname);
- } while (output_format < 1 || output_format > 4);
-
- if (outname[0] == ' ') {
- printf("\nEnter name of uncompressed output file: ");
-- gets (outname);
-+ fgets(outname, sizeof(outname), stdin);
-+ if ((s = strchr(outname, '\n')) != NULL)
-+ *s = '\0';
- }
-
- return(host);
-@@ -495,68 +520,68 @@
- /*********************************************************************/
-
- void open_files(host)
--int *host;
-+ int *host;
- {
- if (*host == 1 || *host == 2 || *host == 5) {
- if (outname[0] == '-') outfile=stdout;
-- else if ((outfile = fopen(outname,"wb"))==NULL) {
-- fprintf(stderr,"\ncan't open output file: %s\n",outname);
-+ else if ((outfile = fopen(outname, "wb"))==NULL) {
-+ fprintf(stderr,"\ncan't open output file: %s\n", outname);
- exit(1);
- }
- }
-
- else if (*host == 3 || *host == 4) {
- if (output_format == 1) { /* write PDS format blocks */
-- if (record_bytes == 836) {
-- if ((outfile=fopen(outname,"w"
-+ if (record_bytes == 836) {
-+ if ((outfile=fopen(outname, "w"
- #ifdef VMS
- ,"mrs=836",FOP,CTX,RECORD_TYPE
- #endif
- ))==NULL) {
-- fprintf(stderr,"\ncan't open output file: %s\n",outname);
-+ fprintf(stderr,"\ncan't open output file: %s\n", outname);
- exit(1);
- }
- }
- else {
-- if ((outfile=fopen(outname,"w"
-+ if ((outfile=fopen(outname, "w"
- #ifdef VMS
- ,"mrs=1204",FOP,CTX,RECORD_TYPE
- #endif
- ))==NULL) {
-- fprintf(stderr,"\ncan't open output file: %s\n",outname);
-+ fprintf(stderr,"\ncan't open output file: %s\n", outname);
- exit(1);
- }
- }
- }
- else if (output_format == 2) { /* write FITS format blocks */
-- if ((outfile=fopen(outname,"w"
-+ if ((outfile=fopen(outname, "w"
- #ifdef VMS
- ,"mrs=2880",FOP,CTX,RECORD_TYPE
- #endif
- ))==NULL) {
-- fprintf(stderr,"\ncan't open output file: %s\n",outname);
-+ fprintf(stderr,"\ncan't open output file: %s\n", outname);
- exit(1);
- }
- }
-
-- else { /* write fixed length records */
-- if (record_bytes == 836) {
-- if ((outfile=fopen(outname,"w"
-+ else { /* write fixed-length records */
-+ if (record_bytes == 836) {
-+ if ((outfile=fopen(outname, "w"
- #ifdef VMS
- ,"mrs=800",FOP,CTX,RECORD_TYPE
- #endif
- ))==NULL) {
-- fprintf(stderr,"\ncan't open output file: %s\n",outname);
-+ fprintf(stderr,"\ncan't open output file: %s\n", outname);
- exit(1);
- }
- }
- else {
-- if ((outfile=fopen(outname,"w"
-+ if ((outfile=fopen(outname, "w"
- #ifdef VMS
- ,"mrs=1204",FOP,CTX,RECORD_TYPE
- #endif
- ))==NULL) {
-- fprintf(stderr,"\ncan't open output file: %s\n",outname);
-+ fprintf(stderr,"\ncan't open output file: %s\n", outname);
- exit(1);
- }
- }
-@@ -572,11 +597,11 @@
- /*********************************************************************/
-
- void pds_labels(host)
-- int host;
-+ int host;
- {
-- char outstring[80],ibuf[2048];
-+ char ibuf[2048];
- unsigned char cr=13,lf=10,blank=32;
-- short length,nlen,total_bytes,line,i;
-+ short length,total_bytes,i;
-
-
- total_bytes = 0;
-@@ -613,11 +638,11 @@
- (size_t) 53,(size_t) 1,outfile);
- else
- fwrite("CCSD3ZF0000100000001NJPL3IF0PDS200000001 = SFDU_LABEL",
-- (size_t) 53,(size_t) 1,outfile);
-+ (size_t) 53,(size_t) 1,outfile);
-
- fprintf(outfile,"%c%c",cr,lf);
- fwrite("/* FILE FORMAT AND LENGTH */",(size_t) 37,(size_t) 1,
-- outfile);
-+ outfile);
- fprintf(outfile,"%c%c",cr,lf);
- fwrite("RECORD_TYPE = FIXED_LENGTH",(size_t) 47,
- (size_t) 1,outfile);
-@@ -710,7 +735,7 @@
- }
- else {
- strcpy(ibuf+35,"60");
-- length = length - 2;
-+ length = length - 2;
- }
-
- fwrite(ibuf,(size_t) length,(size_t) 1,outfile);
-@@ -730,7 +755,7 @@
- }
-
- else if ((i = strncmp(ibuf," ENCODING",(size_t) 9)) == 0);
--
-+
- /*****************************************************************/
- /* delete the encoding type label in the image object */
- /*****************************************************************/
-@@ -787,10 +812,10 @@
- /*********************************************************************/
-
- void fits_labels(host)
--int host;
-+ int host;
- {
- char ibuf[2048],outstring[80];
-- short length,nlen,total_bytes,line,i;
-+ short length,total_bytes,i;
- unsigned char cr=13,lf=10,blank=32;
-
- do {
-@@ -799,7 +824,7 @@
- /*****************************************************************/
- /* find the checksum and store in label_checksum */
- /*****************************************************************/
-- if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
-+ if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
- ibuf[length] = '\0';
- label_checksum = atol(ibuf+35);
- }
-@@ -842,7 +867,7 @@
-
- if (record_bytes == 836)
- strcpy(outstring,"NAXIS1 = 800");
-- else
-+ else
- strcpy(outstring,"NAXIS1 = 1204");
-
- strcat(outstring," ");
-@@ -862,7 +887,7 @@
-
- strcpy(outstring,"END ");
- strcat(outstring," ");
--
-+
- fwrite(outstring,(size_t) 78,(size_t) 1,outfile);
- fprintf(outfile,"%c%c",cr,lf);
- total_bytes = total_bytes + 80;
-@@ -871,6 +896,7 @@
- for (i=total_bytes; i<2880; i++) fputc(blank,outfile);
- }
-
-+
- /*********************************************************************/
- /* */
- /* subroutine vicar_labels - write vicar labels to output file */
-@@ -878,11 +904,10 @@
- /*********************************************************************/
-
- void vicar_labels(host)
--int host;
--
-+ int host;
- {
- char ibuf[2048],outstring[80];
-- short length,nlen,total_bytes,line,i;
-+ short length,total_bytes,i;
- unsigned char cr=13,lf=10,blank=32;
-
- do {
-@@ -890,7 +915,7 @@
- /*****************************************************************/
- /* find the checksum and store in label_checksum */
- /*****************************************************************/
-- if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
-+ if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
- ibuf[length] = '\0';
- label_checksum = atol(ibuf+35);
- }
-@@ -950,10 +975,10 @@
- /*********************************************************************/
-
- void no_labels(host)
--int host;
-+ int host;
- {
-- char ibuf[2048],outstring[80];
-- short length,nlen,total_bytes,line,i;
-+ char ibuf[2048];
-+ short length,i;
-
- do {
- length = read_var(ibuf,host);
-@@ -961,7 +986,7 @@
- /*****************************************************************/
- /* find the checksum and store in label_checksum */
- /*****************************************************************/
-- if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
-+ if ((i = strncmp(ibuf," CHECKSUM",(size_t) 9)) == 0) {
- ibuf[length] = '\0';
- label_checksum = atol(ibuf+35);
- }
-@@ -984,15 +1009,16 @@
- open_files(&host);
- }
-
-+
- /*********************************************************************/
- /* */
--/* subroutine read_var - read variable length records from input file*/
-+/* subroutine read_var - read variable-length records from input file*/
- /* */
- /*********************************************************************/
-
- int read_var(ibuf,host)
--char *ibuf;
--int host;
-+ char *ibuf;
-+ int host;
- {
- int length,result,nlen;
- char temp;
-@@ -1027,19 +1053,19 @@
- return (length);
-
- case 3: /*******************************************************/
-- /* VAX host with variable length support */
-+ /* VAX host with variable-length support */
- /*******************************************************/
- length = read(infile,ibuf,(size_t) 2048/* upper bound */);
- return (length);
-
- case 4: /*******************************************************/
-- /* VAX host, but not a variable length file */
-+ /* VAX host, but not a variable-length file */
- /*******************************************************/
- length = 0;
- result = read(infile,&length,(size_t) 2);
- nlen = read(infile,ibuf,(size_t) length+(length%2));
-
-- /* check to see if we crossed a vax record boundary */
-+ /* check to see if we crossed a VAX record boundary */
- while (nlen < length)
- nlen += read(infile,ibuf+nlen,(size_t) length+(length%2)-nlen);
- return (length);
-@@ -1061,6 +1087,7 @@
- return 0;
- }
-
-+
- /*********************************************************************/
- /* */
- /* subroutine check_host - find out what kind of machine we are on */
-@@ -1115,23 +1142,23 @@
- "Host 5 - 32 bit integers without swapping, no var len support.");
- }
-
-- if ((*outname)!='-') fprintf(stderr,"%s\n",hostname);
-+ if ((*outname) != '-') fprintf(stderr, "%s\n", hostname);
- return(host);
- }
-
-
--int swap_int(inval) /* swap 4 byte integer */
-- int inval;
-+int swap_int(inval) /* swap 4 byte integer */
-+ int inval;
- {
-- union /* this union is used to swap 16 and 32 bit integers */
-+ union /* this union is used to swap 16 and 32 bit integers */
- {
- char ichar[4];
- short slen;
- int llen;
- } onion;
- char temp;
--
-- /* byte swap the input field */
-+
-+ /* byte swap the input field */
- onion.llen = inval;
- temp = onion.ichar[0];
- onion.ichar[0]=onion.ichar[3];
-@@ -1146,17 +1173,13 @@
- /****************************************************************************
- *_TITLE decompress - decompresses image lines stored in compressed format *
- *_ARGS TYPE NAME I/O DESCRIPTION */
-- char *ibuf; /* I Compressed data buffer */
-- char *obuf; /* O Decompressed image line */
-- int *nin; /* I Number of bytes on input buffer */
-- int *nout; /* I Number of bytes in output buffer */
--
-+ char *ibuf; /* I Compressed data buffer */
-+ char *obuf; /* O Decompressed image line */
-+ int *nin; /* I Number of bytes on input buffer */
-+ int *nout; /* I Number of bytes in output buffer */
- {
-- /* The external root pointer to tree */
-- extern NODE *tree;
--
- dcmprs(ibuf,obuf,nin,nout,tree);
--
-+
- return;
- }
-
-@@ -1165,10 +1188,8 @@
- /***************************************************************************
- *_TITLE decmpinit - initializes the Huffman tree *
- *_ARGS TYPE NAME I/O DESCRIPTION */
-- int *hist; /* I First-difference histogram. */
--
-+ int *hist; /* I First-difference histogram. */
- {
-- extern NODE *tree; /* Huffman tree root pointer */
- tree = huff_tree(hist);
- return;
- }
-@@ -1178,8 +1199,7 @@
- /****************************************************************************
- *_TITLE huff_tree - constructs the Huffman tree; returns pointer to root *
- *_ARGS TYPE NAME I/O DESCRIPTION */
-- int *hist; /* I First difference histogram */
--
-+ int *hist; /* I First difference histogram */
- {
- /* Local variables used */
- int freq_list[512]; /* Histogram frequency list */
-@@ -1189,7 +1209,6 @@
- NODE **np; /* Node list pointer */
-
- int num_freq; /* Number non-zero frequencies in histogram */
-- int sum; /* Sum of all frequencies */
-
- short int num_nodes; /* Counter for DN initialization */
- short int cnt; /* Miscellaneous counter */
-@@ -1228,7 +1247,7 @@
-
- j = 0;
- for (i=4 ; --i >= 0 ; j = (j << 8) | *(cp+i));
--
-+
- /* Now make the assignment */
- *fp++ = j;
- temp = new_node(num_nodes);
-@@ -1341,7 +1360,7 @@
- l--;
- if ( j <= freq_list) break;
- }
--
-+
- }
- return;
- }
-@@ -1362,9 +1381,9 @@
- NODE *ptr = root; /* pointer to position in tree */
- unsigned char test; /* test byte for bit set */
- unsigned char idn; /* input compressed byte */
--
-+
- char odn; /* last dn value decompressed */
--
-+
- char *ilim = ibuf + *nin; /* end of compressed bytes */
- char *olim = obuf + *nout; /* end of output buffer */
-
-@@ -1406,10 +1425,9 @@
- /****************************************************************************
- *_TITLE free_tree - free memory of all allocated nodes *
- *_ARGS TYPE NAME I/O DESCRIPTION */
-- int *nfreed; /* O Return of total count of nodes *
-+ int *nfreed; /* O Return of total count of nodes *
- * freed. */
--
--/*
-+/* *
- *_DESCR This routine is supplied to the programmer to free up all the *
- * allocated memory required to build the huffman tree. The count *
- * of the nodes freed is returned in the parameter 'nfreed'. The *
-@@ -1417,16 +1435,13 @@
- * than one file per run, the program will not keep allocating new *
- * memory without first deallocating all previous nodes associated *
- * with the previous file decompression. *
--
-+* *
- *_HIST 16-AUG-89 Kris Becker USGS, Flagstaff Original Version *
- *_END *
- ****************************************************************************/
--
- {
- int total_free = 0;
-
-- extern NODE *tree; /* Huffman tree root pointer */
--
- *nfreed = free_node(tree,total_free);
-
- return;
-@@ -1435,36 +1450,33 @@
-
- int free_node(pnode,total_free)
- /***************************************************************************
--*_TITLE free_node - deallocates an allocated NODE pointer
-+*_TITLE free_node - deallocates an allocated NODE pointer *
- *_ARGS TYPE NAME I/O DESCRIPTION */
- NODE *pnode; /* I Pointer to node to free */
-- int total_free; /* I Total number of freed nodes */
--
--/*
-+ int total_free; /* I Total number of freed nodes */
-+/* *
- *_DESCR free_node will check both right and left pointers of a node *
- * and then free the current node using the free() C utility. *
- * Note that all nodes attached to the node via right or left *
- * pointers area also freed, so be sure that this is the desired *
- * result when calling this routine. *
--
-+* *
- * This routine is supplied to allow successive calls to the *
- * decmpinit routine. It will free up the memory allocated *
- * by previous calls to the decmpinit routine. The call to free *
--* a previous huffman tree is: total = free_node(tree,(int) 0); *
-+* a previous huffman tree is: total = free_node(tree,(int) 0); *
- * This call must be done by the programmer application routine *
- * and is not done by any of these routines. *
- *_HIST 16-AUG-89 Kris Becker U.S.G.S Flagstaff Original Version */
- {
- if (pnode == (NODE *) NULL) return(total_free);
--
-+
- if (pnode->right != (NODE *) NULL)
- total_free = free_node(pnode->right,total_free);
- if (pnode->left != (NODE *) NULL)
- total_free = free_node(pnode->left,total_free);
--
-+
- free((char *) pnode);
- return(total_free + 1);
- }
-
--
--
-diff -ru xv-3.10a/xcmap.c xv-3.10a-enhancements/xcmap.c
---- xv-3.10a/xcmap.c 1995-01-03 13:14:52.000000000 -0800
-+++ xv-3.10a-enhancements/xcmap.c 2007-04-15 13:12:41.000000000 -0700
-@@ -9,6 +9,9 @@
-
- /* include files */
- #include
-+#ifdef __STDC__
-+# include /* exit(), abs() */
-+#endif
- #include
- #include
-
-@@ -18,7 +21,7 @@
- #include
-
- #ifdef VMS
--#define index strchr
-+# define index strchr
- #endif
-
- typedef unsigned char byte;
-@@ -58,7 +61,7 @@
- int main PARM((int, char **));
- static void HandleEvent PARM((XEvent *));
- static void Syntax PARM((void));
--static void FatalError PARM((char *));
-+static void FatalError PARM((const char *));
- static void Quit PARM((void));
- static void CreateMainWindow PARM((char *, char *, int, char **));
- static void DrawWindow PARM((int,int,int,int));
-@@ -75,50 +78,50 @@
- int i;
- char *display, *geom;
- XEvent event;
--
-+
- cmd = argv[0];
- display = geom = NULL;
--
--
-+
-+
- /*********************Options*********************/
--
-+
- for (i = 1; i < argc; i++) {
- char *strind;
--
-+
- if (!strncmp(argv[i],"-g", (size_t)2)) { /* geometry */
- i++;
- geom = argv[i];
- continue;
- }
--
-+
- if (argv[i][0] == '=') { /* old-style geometry */
- geom = argv[i];
- continue;
- }
--
-+
- if (!strncmp(argv[i],"-d",(size_t) 2)) { /* display */
- i++;
- display = argv[i];
- continue;
- }
--
-+
- strind = (char *) index(argv[i], ':'); /* old-style display */
- if(strind != NULL) {
- display = argv[i];
- continue;
- }
--
-+
- Syntax();
- }
--
--
-+
-+
- /*****************************************************/
--
-+
- /* Open up the display. */
--
-+
- if ( (theDisp=XOpenDisplay(display)) == NULL)
- FatalError("can't open display");
--
-+
- theScreen = DefaultScreen(theDisp);
- theCmap = DefaultColormap(theDisp, theScreen);
- rootW = RootWindow(theDisp,theScreen);
-@@ -126,9 +129,9 @@
- fcol = WhitePixel(theDisp,theScreen);
- bcol = BlackPixel(theDisp,theScreen);
- theVisual = DefaultVisual(theDisp,theScreen);
--
-+
- dispcells = DisplayCells(theDisp, theScreen);
--
-+
- if (dispcells>256) {
- sprintf(tmpstr,"dispcells = %d. %s",
- dispcells, "This program can only deal with <= 8-bit displays.");
-@@ -140,27 +143,32 @@
- nxcells = nycells = 8;
- else if (dispcells>4)
- nxcells = nycells = 4;
-- else
-+ else if (dispcells>2)
- nxcells = nycells = 2;
--
-+ else
-+ {
-+ nxcells = 2;
-+ nycells = 1;
-+ }
-+
- /**************** Create/Open X Resources ***************/
- if ((mfinfo = XLoadQueryFont(theDisp,FONT))==NULL) {
- sprintf(tmpstr,"couldn't open '%s' font",FONT);
- FatalError(tmpstr);
- }
--
-+
- mfont=mfinfo->fid;
- XSetFont(theDisp,theGC,mfont);
- XSetForeground(theDisp,theGC,fcol);
- XSetBackground(theDisp,theGC,bcol);
--
-+
- CreateMainWindow(cmd,geom,argc,argv);
-- Resize(WIDE,HIGH);
--
-- XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
-+ Resize((int)WIDE,(int)HIGH);
-+
-+ XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
- | StructureNotifyMask | ButtonPressMask);
- XMapWindow(theDisp,mainW);
--
-+
- /**************** Main loop *****************/
- while (1) {
- XNextEvent(theDisp, &event);
-@@ -177,41 +185,41 @@
- switch (event->type) {
- case Expose: {
- XExposeEvent *exp_event = (XExposeEvent *) event;
--
-- if (exp_event->window==mainW)
-+
-+ if (exp_event->window==mainW)
- DrawWindow(exp_event->x,exp_event->y,
- exp_event->width, exp_event->height);
- }
- break;
--
-+
- case ButtonPress: {
- XButtonEvent *but_event = (XButtonEvent *) event;
--
-- if (but_event->window == mainW && but_event->button == Button1)
-+
-+ if (but_event->window == mainW && but_event->button == Button1)
- TrackMouse(but_event->x, but_event->y);
- }
- break;
--
-+
- case KeyPress: {
- XKeyEvent *key_event = (XKeyEvent *) event;
- KeySym ks;
- XComposeStatus status;
--
-+
- XLookupString(key_event,tmpstr,128,&ks,&status);
- if (tmpstr[0]=='q' || tmpstr[0]=='Q') Quit();
- }
- break;
--
-+
- case ConfigureNotify: {
- XConfigureEvent *conf_event = (XConfigureEvent *) event;
--
-- if (conf_event->window == mainW &&
-- (conf_event->width != WIDE || conf_event->height != HIGH))
-- Resize(conf_event->width, conf_event->height);
-+ int w = conf_event->width, h = conf_event->height;
-+
-+ if (conf_event->window == mainW && (w != WIDE || h != HIGH))
-+ Resize((int)(w ? w : WIDE), (int)(h ? h : HIGH));
- }
- break;
--
--
-+
-+
- case CirculateNotify:
- case MapNotify:
- case DestroyNotify:
-@@ -220,7 +228,7 @@
- case UnmapNotify:
- case MappingNotify:
- case ClientMessage: break;
--
-+
- default: /* ignore unexpected events */
- break;
- } /* end of switch */
-@@ -237,10 +245,10 @@
-
-
- /***********************************/
--static void FatalError (identifier)
-- char *identifier;
-+static void FatalError(identifier)
-+ const char *identifier;
- {
-- fprintf(stderr, "%s: %s\n",cmd, identifier);
-+ fprintf(stderr, "%s: %s\n", cmd, identifier);
- exit(-1);
- }
-
-@@ -262,24 +270,33 @@
- XSizeHints hints;
- int i,x,y;
- unsigned int w,h;
--
-+
- WIDE = HIGH = 256; /* default window size */
--
-+
- x=y=w=h=1;
-+ hints.flags = 0;
-+
- i=XParseGeometry(geom,&x,&y,&w,&h);
-- if (i&WidthValue) WIDE = (int) w;
-- if (i&HeightValue) HIGH = (int) h;
--
-- if (i&XValue || i&YValue) hints.flags = USPosition;
-- else hints.flags = PPosition;
--
-- hints.flags |= USSize;
--
-- if (i&XValue && i&XNegative)
-- x = XDisplayWidth(theDisp,theScreen)-WIDE-abs(x);
-- if (i&YValue && i&YNegative)
-- y = XDisplayHeight(theDisp,theScreen)-HIGH-abs(y);
--
-+ if (i&WidthValue)
-+ {
-+ WIDE = (int) w;
-+ hints.flags |= USSize;
-+ }
-+ if (i&HeightValue)
-+ {
-+ HIGH = (int) h;
-+ hints.flags |= USSize;
-+ }
-+
-+ if (i&XValue || i&YValue)
-+ {
-+ if (i&XNegative)
-+ x = XDisplayWidth(theDisp,theScreen)-WIDE-abs(x);
-+ if (i&YNegative)
-+ y = XDisplayHeight(theDisp,theScreen)-HIGH-abs(y);
-+ hints.flags |= USPosition;
-+ }
-+
- hints.x=x; hints.y=y;
- hints.width = WIDE; hints.height = HIGH;
- hints.max_width = DisplayWidth(theDisp,theScreen);
-@@ -288,22 +305,22 @@
- hints.min_height = 16;
- hints.width_inc = hints.height_inc = 16;
- hints.flags |= PMaxSize | PMinSize | PResizeInc;
--
-+
- xswa.background_pixel = bcol;
- xswa.border_pixel = fcol;
- xswa.cursor = XCreateFontCursor (theDisp, XC_top_left_arrow);
- xswamask = CWBackPixel | CWBorderPixel | CWCursor;
--
-+
- mainW = XCreateWindow(theDisp,rootW,x,y,(unsigned int) WIDE,
-- (unsigned int) HIGH, 2, 0,
-+ (unsigned int) HIGH, 2, 0,
- (unsigned int) CopyFromParent,
- CopyFromParent, xswamask, &xswa);
--
-+
- XSetStandardProperties(theDisp,mainW,"xcmap","xcmap",None,
- argv,argc,&hints);
--
-+
- if (!mainW) FatalError("Can't open main window");
--
-+
- }
-
-
-@@ -312,11 +329,11 @@
- int x,y,w,h;
- {
- int i,j,x1,y1,x2,y2;
--
-+
- x1 = x / cWIDE; y1 = y / cHIGH; /* (x1,y1) (x2,y2): bounding */
- x2 = ((x+w) + cWIDE - 1) / cWIDE; /* rect in cell coords */
- y2 = ((y+h) + cHIGH - 1) / cHIGH;
--
-+
- for (i=y1; i=WIDE) x=WIDE-1;
- if (y<0) y=0; if (y>=HIGH) y=HIGH-1;
--
-+
- if (!pvalup) { /* it's not up. make it so */
- if (y >= HIGH/2) pvaly = 0; else pvaly = HIGH - 12;
- pvalup = 1;
-@@ -378,30 +395,30 @@
- XClearArea(theDisp,mainW,0,pvaly,
- (unsigned int) WIDE, (unsigned int) 13,True);
- }
--
-+
- x /= cWIDE; y /= cHIGH;
--
-+
- pix = y * nxcells + x;
--
-+
- if (pix != lastpix) {
- XColor def;
- char *sp;
--
-+
- XSetForeground(theDisp,theGC,fcol);
- lastpix = def.pixel = pix;
- if (pix24-bit */
-+ for (i=0; i= 24)) best=i;
-+ }
-+ for (i=0; i24 && best<0) best = i;
-+ }
-+ for (i=0; i24-bit ? */
-+ if (vinfo[i].depth >= 24) best = i;
- }
- }
-
- if (best == -1) { /* look for a DirectColor, 24-bit or more (pref 24) */
- rvinfo.class = DirectColor;
- if (vinfo) XFree((char *) vinfo);
-+
- vinfo = XGetVisualInfo(theDisp, flags, &rvinfo, &numvis);
- if (vinfo) {
-- for (i=0, best = -1; i= 24)) best=i;
-+ }
-+ for (i=0; i24 && best<0) best = i;
-+ }
-+ for (i=0; i24-bit ? */
-+ if (vinfo[i].depth >= 24) best = i;
- }
- }
- }
--
-+
- if (best>=0 && best= 0) {
-+ if (vclass >= 0) {
- rvinfo.class = vclass; vinfomask = VisualClassMask;
- }
- else { rvinfo.visualid = vid; vinfomask = VisualIDMask; }
--
-+
- rvinfo.screen = theScreen;
- vinfomask |= VisualScreenMask;
-
-@@ -429,9 +539,9 @@
- /* make linear colormap for DirectColor visual */
- if (theVisual->class == DirectColor) makeDirectCmap();
-
-- defaultVis = (XVisualIDFromVisual(theVisual) ==
-+ defaultVis = (XVisualIDFromVisual(theVisual) ==
- XVisualIDFromVisual(DefaultVisual(theDisp, DefaultScreen(theDisp))));
--
-+
-
- /* turn GraphicsExposures OFF in the default GC */
- {
-@@ -441,9 +551,6 @@
- }
-
-
-- if (!useroot && limit2x) { maxWIDE *= 2; maxHIGH *= 2; }
-- if (nolimits) { maxWIDE = 65000; maxHIGH = 65000; }
--
- XSetErrorHandler(xvErrorHandler);
-
- /* always search for virtual root window */
-@@ -456,14 +563,14 @@
- Atom actual_type;
- int actual_format;
- unsigned long nitems, bytesafter;
-- Window *newRoot = NULL;
-+ byte *newRoot = NULL; /* byte instead of Window avoids type-pun warning */
- XWindowAttributes xwa;
- if (XGetWindowProperty (theDisp, children[i], __SWM_VROOT, 0L, 1L,
- False, XA_WINDOW, &actual_type, &actual_format, &nitems,
- &bytesafter, (unsigned char **) &newRoot) == Success && newRoot) {
-- vrootW = *newRoot;
-+ vrootW = *(Window *)newRoot;
- XGetWindowAttributes(theDisp, vrootW, &xwa);
-- vrWIDE = xwa.width; vrHIGH = xwa.height;
-+ maxWIDE = vrWIDE = xwa.width; maxHIGH = vrHIGH = xwa.height;
- dispDEEP = xwa.depth;
- break;
- }
-@@ -472,7 +579,8 @@
- vrootW = pseudo_root(theDisp, theScreen);
- #endif
-
--
-+ if (!useroot && limit2x) { maxWIDE *= 2; maxHIGH *= 2; }
-+ if (nolimits) { maxWIDE = 65000; maxHIGH = 65000; }
-
-
- if (clrroot || useroot) {
-@@ -486,13 +594,14 @@
- arrow = XCreateFontCursor(theDisp,(u_int) curstype);
- cross = XCreateFontCursor(theDisp,XC_crosshair);
- tcross = XCreateFontCursor(theDisp,XC_tcross);
-+ tlcorner = XCreateFontCursor(theDisp,XC_top_left_corner);
- zoom = XCreateFontCursor(theDisp,XC_sizing);
-
- {
- XColor fc, bc;
- fc.red = fc.green = fc.blue = 0xffff;
- bc.red = bc.green = bc.blue = 0x0000;
--
-+
- XRecolorCursor(theDisp, zoom, &fc, &bc);
- }
-
-@@ -541,7 +650,7 @@
-
-
- /* set up fg,bg colors */
-- fg = black; bg = white;
-+ fg = black; bg = white;
- if (fgstr && XParseColor(theDisp, theCmap, fgstr, &ecdef) &&
- xvAllocColor(theDisp, theCmap, &ecdef)) {
- fg = ecdef.pixel;
-@@ -561,6 +670,18 @@
- xvAllocColor(theDisp, theCmap, &ecdef)) rootbg = ecdef.pixel;
-
-
-+ /* GRR 19980308: set up image bg color (for transparent images) */
-+ have_imagebg = 0;
-+ if (imagebgstr && XParseColor(theDisp, theCmap, imagebgstr, &ecdef) &&
-+ xvAllocColor(theDisp, theCmap, &ecdef)) {
-+ /* imagebg = ecdef.pixel; */
-+ have_imagebg = 1;
-+ imagebgR = ecdef.red;
-+ imagebgG = ecdef.green;
-+ imagebgB = ecdef.blue;
-+ }
-+
-+
- /* set up hi/lo colors */
- i=0;
- if (dispDEEP > 1) { /* only if we're on a reasonable display */
-@@ -590,7 +711,7 @@
- if (theVisual->class == StaticGray || theVisual->class == GrayScale)
- mono = 1;
- }
--
-+
-
-
- iconPix = MakePix1(rootW, icon_bits, icon_width, icon_height);
-@@ -598,32 +719,32 @@
- riconPix = MakePix1(rootW, runicon_bits, runicon_width, runicon_height);
- riconmask= MakePix1(rootW, runiconm_bits, runiconm_width,runiconm_height);
-
-- if (!iconPix || !iconmask || !riconPix || !riconmask)
-+ if (!iconPix || !iconmask || !riconPix || !riconmask)
- FatalError("Unable to create icon pixmaps\n");
-
-- gray50Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
-+ gray50Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
- (char *) cboard50_bits,
-- cboard50_width, cboard50_height,
-+ cboard50_width, cboard50_height,
- infofg, infobg, dispDEEP);
- if (!gray50Tile) FatalError("Unable to create gray50Tile bitmap\n");
-
-- gray25Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
-+ gray25Tile = XCreatePixmapFromBitmapData(theDisp, rootW,
- (char *) gray25_bits,
-- gray25_width, gray25_height,
-+ gray25_width, gray25_height,
- infofg, infobg, dispDEEP);
- if (!gray25Tile) FatalError("Unable to create gray25Tile bitmap\n");
-
-
- /* try to load fonts */
-- if ( (mfinfo = XLoadQueryFont(theDisp,FONT1))==NULL &&
-- (mfinfo = XLoadQueryFont(theDisp,FONT2))==NULL &&
-- (mfinfo = XLoadQueryFont(theDisp,FONT3))==NULL &&
-- (mfinfo = XLoadQueryFont(theDisp,FONT4))==NULL &&
-+ if ( (mfinfo = XLoadQueryFont(theDisp,FONT1))==NULL &&
-+ (mfinfo = XLoadQueryFont(theDisp,FONT2))==NULL &&
-+ (mfinfo = XLoadQueryFont(theDisp,FONT3))==NULL &&
-+ (mfinfo = XLoadQueryFont(theDisp,FONT4))==NULL &&
- (mfinfo = XLoadQueryFont(theDisp,FONT5))==NULL) {
-- sprintf(str,
-+ sprintf(dummystr,
- "couldn't open the following fonts:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s",
- FONT1, FONT2, FONT3, FONT4, FONT5);
-- FatalError(str);
-+ FatalError(dummystr);
- }
- mfont=mfinfo->fid;
- XSetFont(theDisp,theGC,mfont);
-@@ -632,45 +753,100 @@
-
- if (monofontname) {
- monofinfo = XLoadQueryFont(theDisp, monofontname);
-- if (!monofinfo) fprintf(stderr,"xv: unable to load font '%s'\n",
-+ if (!monofinfo) fprintf(stderr,"xv: unable to load font '%s'\n",
- monofontname);
-- }
-+ }
-
- if (!monofinfo) {
-- if ((monofinfo = XLoadQueryFont(theDisp,MFONT1))==NULL &&
-- (monofinfo = XLoadQueryFont(theDisp,MFONT2))==NULL &&
-- (monofinfo = XLoadQueryFont(theDisp,MFONT3))==NULL &&
-+ if ((monofinfo = XLoadQueryFont(theDisp,MFONT1))==NULL &&
-+ (monofinfo = XLoadQueryFont(theDisp,MFONT2))==NULL &&
-+ (monofinfo = XLoadQueryFont(theDisp,MFONT3))==NULL &&
- (monofinfo = XLoadQueryFont(theDisp,MFONT4))==NULL) {
-- sprintf(str,"couldn't open %s fonts:\n\t%s\n\t%s\n\t%s\n\t%s",
-+ sprintf(dummystr,"couldn't open %s fonts:\n\t%s\n\t%s\n\t%s\n\t%s",
- "any of the following",
- MFONT1, MFONT2, MFONT3, MFONT4);
-- FatalError(str);
-+ FatalError(dummystr);
- }
- }
-
- monofont=monofinfo->fid;
--
-
--
--
-+#ifdef TV_L10N
-+ if (xlocale) {
-+ i = 0;
-+ while (mfontsize[i]) {
-+ xlocale = 1; /* True */
-+
-+ sprintf(mfontset, TV_FONTSET, mfontsize[i]);
-+/*fprintf(stderr, "FontSet: %s\n", mfontset);*/
-+
-+ monofset = XCreateFontSet(theDisp, mfontset,
-+ &misscharset, &nmisscharset, &defstr);
-+# if 0 /* not useful */
-+ if (!monofset) {
-+ /* the current locale is not supported */
-+/*fprintf(stderr, "Current locale `%s' is not supported.\n", localeList[i]);*/
-+ xlocale = 0;
-+ break;
-+ }
-+# endif
-+/*fprintf(stderr, "# of misscharset in mfontsize[%d]: %d\n", i,nmisscharset);*/
-+
-+ for (j = 0; j < nmisscharset; j++) {
-+ if (!strncmp(misscharset[j], "jisx0208", 8)) {
-+ /* font for JIS X 0208 is not found */
-+ xlocale = 0;
-+ break;
-+ }
-+ }
-+
-+ if (xlocale) {
-+ monofsetinfo = XExtentsOfFontSet(monofset);
-+ monofsetinfo->max_logical_extent.width = mfontsize[i];
-+ /* correct size of TextViewer
-+ in case that JIS X 0208 is not found */
-+ break;
-+ }
-+
-+ i++;
-+ } /* while (mfontsize[i]) */
-+
-+# if 0
-+ if (nmisscharset > 0) {
-+ sprintf(dummystr,"missing %d charset:\n", nmisscharset);
-+ for (i = 0; i < nmisscharset; i++) {
-+ sprintf(dummystr, "%s\t%s\n", dummystr, misscharset[i]);
-+ }
-+# if 0
-+ FatalError(dummystr);
-+# else
-+ fprintf(stderr, "%s", dummystr);
-+# endif
-+ }
-+# endif
-+ }
-+#endif /* TV_L10N */
-+
-+
-+
- /* if ncols wasn't set, set it to 2^dispDEEP, unless dispDEEP=1, in which
- case ncols = 0; (ncols = max number of colors allocated. on 1-bit
- displays, no colors are allocated */
--
-+
- if (ncols == -1) {
- if (dispDEEP>1) ncols = 1 << ((dispDEEP>8) ? 8 : dispDEEP);
- else ncols = 0;
- }
- else if (ncols>256) ncols = 256; /* so program doesn't blow up */
--
--
-+
-+
- GenerateFSGamma(); /* has to be done before 'OpenBrowse()' is called */
--
--
--
-+
-+
-+
- /* no filenames. build one-name (stdio) list (if stdinflag) */
- if (numnames==0) {
-- if (stdinflag) {
-+ if (stdinflag) {
- /* have to malloc namelist[0] so we can free it in deleteFromList() */
- namelist[0] = (char *) malloc(strlen(STDINSTR) + 1);
- if (!namelist[0]) FatalError("unable to to build namelist[0]");
-@@ -679,16 +855,28 @@
- }
- else namelist[0] = NULL;
- }
--
-+ else if (randomShow) {
-+ int i, j;
-+ char *tmp;
-+
-+ srandom((int)time((time_t *)0));
-+ for (i = numnames; i > 1; i--) {
-+ j = random() % i;
-+ tmp = namelist[i-1];
-+ namelist[i-1] = namelist[j];
-+ namelist[j] = tmp;
-+ }
-+ }
-+
- if (numnames) makeDispNames();
--
--
-- if (viewonly || autoquit) {
-- imap = ctrlmap = gmap = browmap = cmtmap = 0;
-+
-+
-+ if (viewonly || autoquit) {
-+ imap = ctrlmap = gmap = browmap = cmtmap = 0;
- novbrowse = 1;
- }
--
--
-+
-+
- /* create the info box window */
- CreateInfo(infogeom);
- XSelectInput(theDisp, infoW, ExposureMask | ButtonPressMask | KeyPressMask
-@@ -698,12 +886,12 @@
- RedrawInfo(0,0,1000,1000); /* explicit draw if mapped */
- XFlush(theDisp);
- }
--
--
-+
-+
- /* create the control box window */
- CreateCtrl(ctrlgeom);
- epicMode = EM_RAW; SetEpicMode();
--
-+
- XSelectInput(theDisp, ctrlW, ExposureMask | ButtonPressMask | KeyPressMask
- | StructureNotifyMask);
- if (ctrlmap < 0) { /* map iconified */
-@@ -719,22 +907,22 @@
- RedrawCtrl(0,0,1000,1000); /* explicit draw if mapped */
- XFlush(theDisp);
- }
--
-+
- fixDispNames();
- ChangedCtrlList();
--
-+
- /* disable root modes if using non-default visual */
- if (!defaultVis) {
- for (i=RMB_ROOT; ired_mask;
- gmask = theVisual->green_mask;
-@@ -849,22 +1061,22 @@
-
- if (rshift<0) rmask = rmask << (-rshift);
- else rmask = rmask >> rshift;
--
-+
- if (gshift<0) gmask = gmask << (-gshift);
- else gmask = gmask >> gshift;
--
-+
- if (bshift<0) bmask = bmask << (-bshift);
- else bmask = bmask >> bshift;
-
-
- cmaplen = theVisual->map_entries;
- if (cmaplen>256) cmaplen=256;
--
-+
-
- /* try to alloc a 'cmaplen' long grayscale colormap. May not get all
- entries for whatever reason. Build table 'directConv[]' that
- maps range [0..(cmaplen-1)] into set of colors we did get */
--
-+
- for (i=0; i<256; i++) { origgot[i] = 0; directConv[i] = 0; }
-
- for (i=numgot=0; i= 0 && !origgot[i-numbak]) numbak++;
- while ((i + numfwd) < cmaplen && !origgot[i+numfwd]) numfwd++;
--
-+
- if (i-numbak<0 || !origgot[i-numbak]) numbak = 999;
- if (i+numfwd>=cmaplen || !origgot[i+numfwd]) numfwd = 999;
--
-+
- if (numbak-8 conv.*/
- conv24 = CONV24_SLOW;
--
-+
- else if (!argcmp(argv[i],"-smooth",3,1,&autosmooth)); /* autosmooth */
-+ else if (!argcmp(argv[i],"-startgrab",3,1,&startGrab)); /* startGrab */
- else if (!argcmp(argv[i],"-stdcmap",3,1,&stdcmap)); /* use stdcmap */
-
- else if (!argcmp(argv[i],"-tgeometry",2,0,&pm)) /* textview geom */
- { if (++i 15) {
-@@ -1498,9 +1811,9 @@
- fprintf(stderr," (Valid values: 1, 2, 3, 4)\n");
-
- preset = 0;
-- }
-+ }
-
-- if (waitsec < 0) noFreeCols = 0; /* disallow nfc if not doing slideshow */
-+ if (waitsec < 0.0) noFreeCols = 0; /* disallow nfc if not doing slideshow */
- if (noFreeCols && perfect) { perfect = 0; owncmap = 1; }
-
- /* decide what default color allocation stuff we've settled on */
-@@ -1512,24 +1825,24 @@
-
- defaultCmapMode = colorMapMode; /* default mode for 8-bit images */
-
-- if (nopos) {
-- maingeom = infogeom = ctrlgeom = gamgeom = browgeom = textgeom = NULL;
-- cmtgeom = NULL;
-+ if (nopos) {
-+ maingeom = infogeom = ctrlgeom = gamgeom = browgeom = textgeom = cmtgeom =
-+ (const char *) NULL;
- }
-
- /* if -root and -maxp, disallow 'integer' tiling modes */
-- if (useroot && fixedaspect && automax && !rmodeset &&
-+ if (useroot && fixedaspect && automax && !rmodeset &&
- (rootMode == RM_TILE || rootMode == RM_IMIRROR))
- rootMode = RM_CSOLID;
- }
-
-
-
-+static int cpos = 0;
-
- /***********************************/
--static int cpos = 0;
- static void printoption(st)
-- char *st;
-+ const char *st;
- {
- if (strlen(st) + cpos > 78) {
- fprintf(stderr,"\n ");
-@@ -1540,8 +1853,26 @@
- cpos = cpos + strlen(st) + 1;
- }
-
-+
- static void cmdSyntax()
- {
-+ /* GRR 19980605: added version info for most common libraries */
-+ fprintf(stderr, "XV - %s.\n", REVDATE);
-+#ifdef HAVE_JPEG
-+ VersionInfoJPEG();
-+#endif
-+#ifdef HAVE_JP2K
-+ VersionInfoJP2K();
-+#endif
-+#ifdef HAVE_TIFF
-+ VersionInfoTIFF();
-+#endif
-+#ifdef HAVE_PNG
-+ VersionInfoPNG();
-+#endif
-+ /* pbm/pgm/ppm support is native, not via pbmplus/netpbm libraries */
-+ fprintf(stderr, "\n");
-+
- fprintf(stderr, "Usage:\n");
- printoption(cmd);
- printoption("[-]");
-@@ -1579,8 +1910,14 @@
- printoption("[-/+dither]");
- printoption("[-drift dx dy]");
- printoption("[-expand exp | hexp:vexp]");
-+#ifdef HAVE_G3
-+ printoption("[-fax]");
-+#endif
- printoption("[-fg color]");
- printoption("[-/+fixed]");
-+#ifdef ENABLE_FIXPIX_SMOOTH
-+ printoption("[-/+fixpix]");
-+#endif
- printoption("[-flist fname]");
- printoption("[-gamma val]");
- printoption("[-geometry geom]");
-@@ -1591,8 +1928,12 @@
- printoption("[-help]");
- printoption("[-/+hflip]");
- printoption("[-hi color]");
-+#ifdef HAVE_G3
-+ printoption("[-highresfax]");
-+#endif
- printoption("[-/+hist]");
- printoption("[-/+hsv]");
-+ printoption("[-ibg color]"); /* GRR 19980314 */
- printoption("[-icgeometry geom]");
- printoption("[-/+iconic]");
- printoption("[-igeometry geom]");
-@@ -1600,9 +1941,15 @@
- printoption("[-/+lbrowse]");
- printoption("[-lo color]");
- printoption("[-/+loadclear]");
-+#ifdef MACBINARY
-+ printoption("[-/+macbinary]");
-+#endif
- printoption("[-/+max]");
- printoption("[-/+maxpect]");
- printoption("[-mfn font]");
-+#ifdef HAVE_MGCSFX
-+ printoption("[-/+mgcsfx]");
-+#endif
- printoption("[-/+mono]");
- printoption("[-name str]");
- printoption("[-ncols #]");
-@@ -1610,13 +1957,25 @@
- printoption("[-/+nodecor]");
- printoption("[-/+nofreecols]");
- printoption("[-/+nolimits]");
-+#ifdef HAVE_MGCSFX
-+ printoption("[-/+nomgcsfx]");
-+#endif
-+#if defined(HAVE_PIC) || defined(HAVE_PIC2)
-+ printoption("[-/+nopicadjust]");
-+#endif
- printoption("[-/+nopos]");
- printoption("[-/+noqcheck]");
- printoption("[-/+noresetroot]");
- printoption("[-/+norm]");
- printoption("[-/+nostat]");
- printoption("[-/+owncmap]");
-+#ifdef HAVE_PCD
-+ printoption("[-pcd size(0=192*128,1,2,3,4=3072*2048)]");
-+#endif
- printoption("[-/+perfect]");
-+#ifdef HAVE_PIC2
-+ printoption("[-/+pic2split]");
-+#endif
- printoption("[-/+pkludge]");
- printoption("[-/+poll]");
- printoption("[-preset #]");
-@@ -1635,17 +1994,22 @@
- printoption("[-/+rw]");
- printoption("[-slow24]");
- printoption("[-/+smooth]");
-+ printoption("[-/+startgrab]");
- printoption("[-/+stdcmap]");
- printoption("[-tgeometry geom]");
- printoption("[-/+vflip]");
- printoption("[-/+viewonly]");
- printoption("[-visual type]");
-+#ifdef VS_ADJUST
-+ printoption("[-/+vsadjust]");
-+#endif
- printoption("[-/+vsdisable]");
- printoption("[-vsgeometry geom]");
- printoption("[-/+vsmap]");
- printoption("[-/+vsperfect]");
-- printoption("[-wait seconds]");
-+ printoption("[-wait secs[,final_secs]]");
- printoption("[-white color]");
-+ printoption("[-windowid windowid]");
- printoption("[-/+wloop]");
- printoption("[filename ...]");
- fprintf(stderr,"\n\n");
-@@ -1656,7 +2020,7 @@
- /***********************************/
- static void rmodeSyntax()
- {
-- fprintf(stderr,"%s: unknown root mode '%d'. Valid modes are:\n",
-+ fprintf(stderr,"%s: unknown root mode '%d'. Valid modes are:\n",
- cmd, rootMode);
- fprintf(stderr,"\t0: tiling\n");
- fprintf(stderr,"\t1: integer tiling\n");
-@@ -1668,6 +2032,7 @@
- fprintf(stderr,"\t7: centered on a 'brick' background\n");
- fprintf(stderr,"\t8: symmetrical tiling\n");
- fprintf(stderr,"\t9: symmetrical mirrored tiling\n");
-+ fprintf(stderr,"\t10: upper left corner\n");
- fprintf(stderr,"\n");
- Quit(1);
- }
-@@ -1675,17 +2040,15 @@
-
- /***********************************/
- static int argcmp(a1, a2, minlen, plusallowed, plusminus)
-- char *a1, *a2;
-+ const char *a1, *a2;
- int minlen, plusallowed;
- int *plusminus;
- {
-- /* does a string compare between a1 and a2. To return '0', a1 and a2
-- must match to the length of a2, and that length has to
-+ /* does a string compare between a1 and a2. To return '0', a1 and a2
-+ must match to the length of a1, and that length has to
- be at least 'minlen'. Otherwise, return non-zero. plusminus set to '1'
- if '-option', '0' if '+option' */
-
-- int i;
--
- if ((strlen(a1) < (size_t) minlen) || (strlen(a2) < (size_t) minlen))
- return 1;
- if (strlen(a1) > strlen(a2)) return 1;
-@@ -1694,7 +2057,7 @@
-
- if (a1[0]=='-' || (plusallowed && a1[0]=='+')) {
- /* only set if we match */
-- *plusminus = (a1[0] == '-');
-+ *plusminus = (a1[0] == '-');
- return 0;
- }
-
-@@ -1721,8 +2084,11 @@
- int oldCXOFF, oldCYOFF, oldCWIDE, oldCHIGH, wascropped;
- char *tmp;
- char *fullname, /* full name of the original file */
-- filename[512], /* full name of file to load (could be /tmp/xxx)*/
-- globnm[512]; /* globbed version of fullname of orig file */
-+ filename[512]; /* full name of file to load (could be /tmp/xxx)*/
-+#ifdef MACBINARY
-+ char origname[512]; /* file name of original file (NO processing) */
-+ origname[0] = '\0';
-+#endif
-
- xvbzero((char *) &pinfo, sizeof(PICINFO));
-
-@@ -1748,7 +2114,7 @@
-
- /* if we're not loading next or prev page in a multi-page doc, kill off
- page files */
-- if (strlen(pageBaseName) && filenum!=OP_PAGEDN && filenum!=OP_PAGEUP)
-+ if (strlen(pageBaseName) && filenum!=OP_PAGEDN && filenum!=OP_PAGEUP)
- killpage = 1;
-
-
-@@ -1799,14 +2165,13 @@
- }
-
- else if (filenum == PADDED) {
-- /* need fullfname (used for window/icon name),
-+ /* need fullfname (used for window/icon name),
- basefname(compute from fullfname) */
-
- i = LoadPad(&pinfo, fullfname);
- fullname = fullfname;
- strcpy(filename, fullfname);
-- tmp = BaseName(fullfname);
-- strcpy(basefname, tmp);
-+ strcpy(basefname, BaseName(fullfname));
-
- if (!i) goto FAILED; /* shouldn't happen */
-
-@@ -1855,33 +2220,48 @@
- frompipe = 1;
- }
- }
-+#ifdef AUTO_EXPAND
-+ else {
-+ fullname = (char *) malloc(MAXPATHLEN+2);
-+ strcpy(fullname, namelist[filenum]); // 1 of 2 places fullname != const
-+ freename = 1;
-+ }
-+ tmp = (char *) rindex(fullname, '/');
-+ if (tmp) {
-+ *tmp = '\0'; // 2 of 2 places fullname != const
-+ Mkvdir(fullname);
-+ *tmp = '/';
-+ }
-+ Dirtovd(fullname);
-+#else
- else fullname = namelist[filenum];
--
-+#endif
-
- strcpy(fullfname, fullname);
-- tmp = BaseName(fullname);
-- strcpy(basefname, tmp);
-+ strcpy(basefname, BaseName(fullname));
-
-
- /* chop off trailing ".Z", ".z", or ".gz" from displayed basefname, if any */
-- if (strlen(basefname) > (size_t) 2 &&
-- strcmp(basefname+strlen(basefname)-2,".Z")==0)
-+ if (strlen(basefname)>2 && strcmp(basefname+strlen(basefname)-2,".Z")==0)
- basefname[strlen(basefname)-2]='\0';
- else {
- #ifdef GUNZIP
-- if (strlen(basefname)>2 && strcmp(basefname+strlen(basefname)-2,".Z")==0)
-+ if (strlen(basefname)>2 && strcmp(basefname+strlen(basefname)-2,".z")==0)
- basefname[strlen(basefname)-2]='\0';
--
-- else if (strlen(basefname)>3 &&
-- strcmp(basefname+strlen(basefname)-3,".gz")==0)
-+ else
-+ if (strlen(basefname)>3 && strcmp(basefname+strlen(basefname)-3,".gz")==0)
- basefname[strlen(basefname)-3]='\0';
--#endif /* GUNZIP */
-+#endif
-+#ifdef BUNZIP2
-+ if (strlen(basefname)>4 && strcmp(basefname+strlen(basefname)-4,".bz2")==0)
-+ basefname[strlen(basefname)-4]='\0';
-+#endif
- }
-
-
- if (filenum == LOADPIC && ISPIPE(fullname[0])) {
- /* if we're reading from a pipe, 'filename' will have the /tmp/xvXXXXXX
-- filename, and we can skip a lot of stuff: (such as prepending
-+ filename, and we can skip a lot of stuff: (such as prepending
- 'initdir' to relative paths, dealing with reading from stdin, etc. */
-
- /* at this point, fullname = "! do some commands",
-@@ -1891,11 +2271,11 @@
-
- else { /* NOT reading from a PIPE */
-
-- /* if fullname doesn't start with a '/' (ie, it's a relative path),
-- (and it's not LOADPIC and it's not the special case '')
-+ /* if fullname doesn't start with a '/' (ie, it's a relative path),
-+ (and it's not LOADPIC and it's not the special case '')
- then we need to prepend a directory name to it:
--
-- prepend 'initdir',
-+
-+ prepend 'initdir',
- if we have a searchdir (ie, we have multiple places to look),
- see if such a file exists (via fopen()),
- if it does, we're done.
-@@ -1904,7 +2284,7 @@
- if it does, we're done.
- if it doesn't, remove all prepended directories, and fall through
- to error code below. */
--
-+
- if (filenum!=LOADPIC && fullname[0]!='/' && strcmp(fullname,STDINSTR)!=0) {
- char *tmp1;
-
-@@ -1954,28 +2334,40 @@
- }
- }
- }
--
-+
- strcpy(filename, fullname);
--
--
-+
-+
- /* if the file is STDIN, write it out to a temp file */
-
- if (strcmp(filename,STDINSTR)==0) {
-- FILE *fp;
-+ FILE *fp = NULL;
-+#ifndef USE_MKSTEMP
-+ int tmpfd;
-+#endif
-
--#ifndef VMS
-+#ifndef VMS
- sprintf(filename,"%s/xvXXXXXX",tmpdir);
- #else /* it is VMS */
- sprintf(filename, "[]xvXXXXXX");
- #endif
-+
-+#ifdef USE_MKSTEMP
-+ fp = fdopen(mkstemp(filename), "w");
-+#else
- mktemp(filename);
-+ tmpfd = open(filename,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
-+ if (tmpfd < 0) FatalError("openPic(): can't create temporary file");
-+ fp = fdopen(tmpfd,"w");
-+#endif
-+ if (!fp) FatalError("openPic(): can't write temporary file");
-
- clearerr(stdin);
-- fp = fopen(filename,"w");
-- if (!fp) FatalError("openPic(): can't write temporary file");
--
- while ( (i=getchar()) != EOF) putc(i,fp);
- fclose(fp);
-+#ifndef USE_MKSTEMP
-+ close(tmpfd);
-+#endif
-
- /* and remove it from list, since we can never reload from stdin */
- if (strcmp(namelist[0], STDINSTR)==0) deleteFromList(0);
-@@ -1990,20 +2382,26 @@
- (no pipes or stdin, though it could be compressed) to be loaded */
- filetype = ReadFileType(filename);
-
-+#ifdef HAVE_MGCSFX
-+ if (mgcsfx && filetype == RFT_UNKNOWN){ /* force use MgcSfx */
-+ if(getInputCom() != 0) filetype = RFT_MGCSFX;
-+ }
-+#endif
-
-- if (filetype == RFT_COMPRESS) { /* a compressed file. uncompress it */
-+ /* if it's a compressed file, uncompress it: */
-+ if ((filetype == RFT_COMPRESS) || (filetype == RFT_BZIP2)) {
- char tmpname[128];
-
- if (
- #ifndef VMS
-- UncompressFile(filename, tmpname)
-+ UncompressFile(filename, tmpname, filetype)
- #else
-- UncompressFile(basefname, tmpname)
-+ UncompressFile(basefname, tmpname, filetype)
- #endif
- ) {
-
- filetype = ReadFileType(tmpname); /* and try again */
--
-+
- /* if we made a /tmp file (from stdin, etc.) won't need it any more */
- if (strcmp(fullname,filename)!=0) unlink(filename);
-
-@@ -2013,7 +2411,58 @@
-
- WaitCursor();
- }
--
-+
-+#ifdef MACBINARY
-+ if (handlemacb && macb_file == True) {
-+ char tmpname[128];
-+
-+ if (RemoveMacbinary(filename, tmpname)) {
-+ if (strcmp(fullname,filename)!=0) unlink(filename);
-+ strcpy(origname, filename);
-+ strcpy(filename, tmpname);
-+ }
-+ else filetype = RFT_ERROR;
-+
-+ WaitCursor();
-+ }
-+#endif
-+
-+#ifdef HAVE_MGCSFX_AUTO
-+ if (filetype == RFT_MGCSFX) {
-+ char tmpname[128], tmp[256];
-+ char *icom;
-+
-+ if ((icom = mgcsfx_auto_input_com(filename)) != NULL) {
-+ sprintf(tmpname, "%s/xvmsautoXXXXXX", tmpdir);
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(tmpname));
-+#else
-+ mktemp(tmpname);
-+#endif
-+ SetISTR(ISTR_INFO, "Converting to known format by MgcSfx auto...");
-+ sprintf(tmp,"%s >%s", icom, tmpname);
-+ }
-+ else goto ms_auto_no;
-+
-+#ifndef VMS
-+ if (system(tmp))
-+#else
-+ if (!system(tmp))
-+#endif
-+ {
-+ SetISTR(ISTR_INFO, "Unable to convert '%s' by MgcSfx auto.",
-+ BaseName(filename));
-+ Warning();
-+ filetype = RFT_ERROR;
-+ goto ms_auto_no;
-+ }
-+
-+ filetype = ReadFileType(tmpname);
-+ if (strcmp(fullname,filename)!=0) unlink(filename);
-+ strcpy(filename, tmpname);
-+ }
-+ms_auto_no:
-+#endif /* HAVE_MGCSFX_AUTO */
-
- if (filetype == RFT_ERROR) {
- char foostr[512];
-@@ -2027,10 +2476,16 @@
-
- if (filetype == RFT_UNKNOWN) {
- /* view as a text/hex file */
-- TextView(filename);
-+#ifdef MACBINARY
-+ if (origname[0])
-+ i = TextView(origname);
-+ else
-+#endif
-+ i = TextView(filename);
- SetISTR(ISTR_INFO,"'%s' not in a recognized format.", basefname);
- /* Warning(); */
-- goto SHOWN_AS_TEXT;
-+ if (i) goto SHOWN_AS_TEXT;
-+ else goto FAILED;
- }
-
- if (filetype < RFT_ERROR) {
-@@ -2058,8 +2513,9 @@
- if (filetype == RFT_XBM && (!i || pinfo.w==0 || pinfo.h==0)) {
- /* probably just a '.h' file or something... */
- SetISTR(ISTR_INFO," ");
-- TextView(filename);
-- goto SHOWN_AS_TEXT;
-+ i = TextView(filename);
-+ if (i) goto SHOWN_AS_TEXT;
-+ else goto FAILED;
- }
-
- if (!i) {
-@@ -2084,7 +2540,7 @@
- /**************/
- /* SUCCESS!!! */
- /**************/
--
-+
-
- GOTIMAGE:
- /* successfully read this picture. No failures from here on out
-@@ -2097,7 +2553,7 @@
- if (conv24MB.flags[CONV24_LOCK]) { /* locked */
- if (pinfo.type==PIC24 && picType==PIC8) { /* 24 -> 8 bit */
- byte *pic8;
-- pic8 = Conv24to8(pinfo.pic, pinfo.w, pinfo.h, ncols,
-+ pic8 = Conv24to8(pinfo.pic, pinfo.w, pinfo.h, ncols,
- pinfo.r, pinfo.g, pinfo.b);
- free(pinfo.pic);
- pinfo.pic = pic8;
-@@ -2108,7 +2564,7 @@
-
- else if (pinfo.type!=PIC24 && picType==PIC24) { /* 8 -> 24 bit */
- byte *pic24;
-- pic24 = Conv8to24(pinfo.pic, pinfo.w, pinfo.h,
-+ pic24 = Conv8to24(pinfo.pic, pinfo.w, pinfo.h,
- pinfo.r, pinfo.g, pinfo.b);
- free(pinfo.pic);
- pinfo.pic = pic24;
-@@ -2144,7 +2600,7 @@
-
- if (mainW && !useroot) {
- /* avoid generating excess configure events while we resize the window */
-- XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
-+ XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
- | StructureNotifyMask
- | ButtonPressMask | KeyReleaseMask
- | EnterWindowMask | LeaveWindowMask);
-@@ -2162,11 +2618,13 @@
- pHIGH = pinfo.h;
- if (pinfo.frmType >=0) SetDirSaveMode(F_FORMAT, pinfo.frmType);
- if (pinfo.colType >=0) SetDirSaveMode(F_COLORS, pinfo.colType);
--
-+
- SetISTR(ISTR_FORMAT, pinfo.fullInfo);
- strcpy(formatStr, pinfo.shrtInfo);
- picComments = pinfo.comment;
- ChangeCommentText();
-+ picExifInfo = pinfo.exifInfo;
-+ picExifInfoSize = pinfo.exifInfoSize;
-
- for (i=0; i<256; i++) {
- rMap[i] = pinfo.r[i];
-@@ -2194,12 +2652,15 @@
- if (fullname && strcmp(fullname,filename)!=0) unlink(filename);
-
-
-- SetISTR(ISTR_INFO,formatStr);
--
-+ SetISTR(ISTR_INFO, "%s", formatStr);
-+
- SetInfoMode(INF_PART);
-- SetISTR(ISTR_FILENAME,
-- (filenum==DFLTPIC || filenum==GRABBED || frompipe)
-- ? "" : basefname);
-+ if (filenum==DFLTPIC || filenum==GRABBED || frompipe)
-+ SetISTR(ISTR_FILENAME, "");
-+ else if (numPages > 1)
-+ SetISTR(ISTR_FILENAME, "%s Page %d of %d", basefname, curPage+1, numPages);
-+ else
-+ SetISTR(ISTR_FILENAME, "%s", basefname);
-
- SetISTR(ISTR_RES,"%d x %d",pWIDE,pHIGH);
- SetISTR(ISTR_COLOR, "");
-@@ -2219,7 +2680,7 @@
-
-
- /* handle various 'auto-whatever' command line options
-- Note that if 'frompoll' is set, things that have to do with
-+ Note that if 'frompoll' is set, things that have to do with
- setting the expansion factor are skipped, as we'll want it to
- display in the (already-existing) window at the same size */
-
-@@ -2254,7 +2715,7 @@
- w = eWIDE; h = (w*3) / 4;
- eWIDE = w; eHIGH = h;
- }
--
-+
-
- if (eWIDE != cWIDE || eHIGH != cHIGH) epic = (byte *) NULL;
-
-@@ -2306,14 +2767,14 @@
- aspWIDE = eWIDE; aspHIGH = eHIGH; /* aspect-corrected eWIDE,eHIGH */
-
- if (hexpand < 0.0) eWIDE=(int)(aspWIDE / -hexpand); /* neg: reciprocal */
-- else eWIDE=(int)(aspWIDE * hexpand);
-+ else eWIDE=(int)(aspWIDE * hexpand);
- if (vexpand < 0.0) eHIGH=(int)(aspHIGH / -vexpand); /* neg: reciprocal */
-- else eHIGH=(int)(aspHIGH * vexpand);
-+ else eHIGH=(int)(aspHIGH * vexpand);
-
- if (maingeom) {
- /* deal with geometry spec. Note, they shouldn't have given us
- *both* an expansion factor and a geomsize. The geomsize wins out */
--
-+
- int i,x,y,gewide,gehigh; u_int w,h;
-
- gewide = eWIDE; gehigh = eHIGH;
-@@ -2321,11 +2782,11 @@
-
- if (i&WidthValue) gewide = (int) w;
- if (i&HeightValue) gehigh = (int) h;
--
-+
- /* handle case where the pinheads only specified width *or * height */
- if (( i&WidthValue && ~i&HeightValue) ||
- (~i&WidthValue && i&HeightValue)) {
--
-+
- if (i&WidthValue) { gehigh = (aspHIGH * gewide) / pWIDE; }
- else { gewide = (aspWIDE * gehigh) / pHIGH; }
- }
-@@ -2391,7 +2852,7 @@
-
- /* if we're using an integer tiled root mode, truncate eWIDE/eHIGH to
- be an integer divisor of the display size */
--
-+
- if (useroot && (rootMode == RM_TILE || rootMode == RM_IMIRROR)) {
- /* make picture size a divisor of the rootW size. round down */
- i = (dispWIDE + eWIDE-1) / eWIDE; eWIDE = (dispWIDE + i-1) / i;
-@@ -2409,7 +2870,7 @@
- if (autodither && ncols>0) epicMode = EM_DITH;
-
- /* if in CM_STDCMAP mode, and *not* in '-wait 0', then autodither */
-- if (colorMapMode == CM_STDCMAP && waitsec != 0) epicMode = EM_DITH;
-+ if (colorMapMode == CM_STDCMAP && waitsec != 0.0) epicMode = EM_DITH;
-
- /* if -smooth or image has been shrunk to fit screen */
- if (autosmooth || (pWIDE >maxWIDE || pHIGH>maxHIGH)
-@@ -2419,7 +2880,7 @@
-
- /* 'dithering' makes no sense in 24-bit mode */
- if (picType == PIC24 && epicMode == EM_DITH) epicMode = EM_RAW;
--
-+
- SetEpicMode();
- } /* end of !frompoll */
-
-@@ -2450,7 +2911,7 @@
- if (useroot) mainW = vrootW;
- if (eWIDE != cWIDE || eHIGH != cHIGH) epic = (byte *) NULL;
-
-- NewPicGetColors(autonorm, autohisteq);
-+ NewPicGetColors(autonorm, autohisteq);
-
- GenerateEpic(eWIDE, eHIGH); /* want to dither *after* color allocs */
- CreateXImage();
-@@ -2474,7 +2935,7 @@
- SetISTR(ISTR_INFO,"%s %s %s", formatStr,
- (picType==PIC8) ? "8-bit mode." : "24-bit mode.",
- tmp);
--
-+
- SetInfoMode(INF_FULL);
- if (freename) free(fullname);
-
-@@ -2495,20 +2956,24 @@
- to generate the correct exposes (particularly with 'BitGravity' turned
- on */
-
-- if (mainW && !useroot) GenExpose(mainW, 0, 0, (u_int) eWIDE, (u_int) eHIGH);
-+ /*Brian T. Schellenberger: fix for X 4.2 refresh problem*/
-+ if (mainW && !useroot) {
-+ XSync(theDisp, False);
-+ GenExpose(mainW, 0, 0, (u_int) eWIDE, (u_int) eHIGH);
-+ }
-
- return 1;
-
--
-+
- FAILED:
- SetCursors(-1);
- KillPageFiles(pinfo.pagebname, pinfo.numpages);
-
-- if (fullname && strcmp(fullname,filename)!=0)
-+ if (fullname && strcmp(fullname,filename)!=0)
- unlink(filename); /* kill /tmp file */
- if (freename) free(fullname);
-
-- if (!fromint && !polling && filenum>=0 && filenum=0 && filenum 4 &&
-+ strcasecmp(fname+strlen(fname)-5, ".wbmp")==0) rv = RFT_WBMP;
-+
-+ n = fread(magicno, (size_t) 1, sizeof(magicno), fp);
- fclose(fp);
-
-- if (n<30) return RFT_UNKNOWN; /* files less than 30 bytes long... */
-+ if (n<=0) return RFT_UNKNOWN;
-+
-+ /* it is just barely possible that a few files could legitimately be as small
-+ as 30 bytes (e.g., binary P{B,G,P}M format), so zero out rest of "magic
-+ number" buffer and don't quit immediately if we read something small but
-+ not empty */
-+ if (n<30) memset(magicno+n, 0, sizeof(magicno)-n);
-
-- rv = RFT_UNKNOWN;
-+#ifdef MACBINARY
-+ macb_file = False;
-+ while (1) {
-+#endif
-
-- if (strncmp((char *) magicno,"GIF87a", (size_t) 6)==0 ||
-- strncmp((char *) magicno,"GIF89a", (size_t) 6)==0) rv = RFT_GIF;
-+#ifdef HAVE_MGCSFX
-+ if (is_mgcsfx(fname, magicno, 30) != 0) rv = RFT_MGCSFX;
-+ else
-+#endif
-+ if (strncmp((char *) magicno,"GIF87a", (size_t) 6)==0 ||
-+ strncmp((char *) magicno,"GIF89a", (size_t) 6)==0) rv = RFT_GIF;
-
- else if (strncmp((char *) magicno,"VIEW", (size_t) 4)==0 ||
-- strncmp((char *) magicno,"WEIV", (size_t) 4)==0) rv = RFT_PM;
-+ strncmp((char *) magicno,"WEIV", (size_t) 4)==0) rv = RFT_PM;
-+
-+#ifdef HAVE_PIC2
-+ else if (magicno[0]=='P' && magicno[1]=='2' &&
-+ magicno[2]=='D' && magicno[3]=='T') rv = RFT_PIC2;
-+#endif
-
-- else if (magicno[0] == 'P' && magicno[1]>='1' &&
-- magicno[1]<='6') rv = RFT_PBM;
-+ else if (magicno[0] == 'P' && magicno[1]>='1' &&
-+ (magicno[1]<='6' || magicno[1]=='8')) rv = RFT_PBM;
-
- /* note: have to check XPM before XBM, as first 2 chars are the same */
- else if (strncmp((char *) magicno, "/* XPM */", (size_t) 9)==0) rv = RFT_XPM;
-
- else if (strncmp((char *) magicno,"#define", (size_t) 7)==0 ||
-- (magicno[0] == '/' && magicno[1] == '*')) rv = RFT_XBM;
-+ (magicno[0] == '/' && magicno[1] == '*')) rv = RFT_XBM;
-
- else if (magicno[0]==0x59 && (magicno[1]&0x7f)==0x26 &&
-- magicno[2]==0x6a && (magicno[3]&0x7f)==0x15) rv = RFT_SUNRAS;
-+ magicno[2]==0x6a && (magicno[3]&0x7f)==0x15) rv = RFT_SUNRAS;
-
-- else if (magicno[0] == 'B' && magicno[1] == 'M') rv = RFT_BMP;
-+ else if (magicno[0] == 'B' && magicno[1] == 'M') rv = RFT_BMP;
-
-- else if (magicno[0]==0x52 && magicno[1]==0xcc) rv = RFT_UTAHRLE;
-+ else if (magicno[0]==0x52 && magicno[1]==0xcc) rv = RFT_UTAHRLE;
-
- else if ((magicno[0]==0x01 && magicno[1]==0xda) ||
-- (magicno[0]==0xda && magicno[1]==0x01)) rv = RFT_IRIS;
-+ (magicno[0]==0xda && magicno[1]==0x01)) rv = RFT_IRIS;
-
-- else if (magicno[0]==0x1f && magicno[1]==0x9d) rv = RFT_COMPRESS;
-+ else if (magicno[0]==0x1f && magicno[1]==0x9d) rv = RFT_COMPRESS;
-
- #ifdef GUNZIP
-- else if (magicno[0]==0x1f && magicno[1]==0x8b) rv = RFT_COMPRESS;
-+ else if (magicno[0]==0x1f && magicno[1]==0x8b) rv = RFT_COMPRESS;
-+#endif
-+
-+#ifdef BUNZIP2
-+ else if (magicno[0]==0x42 && magicno[1]==0x5a) rv = RFT_BZIP2;
- #endif
-
-- else if (magicno[0]==0x0a && magicno[1] <= 5) rv = RFT_PCX;
-+ else if (magicno[0]==0x0a && magicno[1] <= 5) rv = RFT_PCX;
-
-- else if (strncmp((char *) magicno, "FORM", (size_t) 4)==0 &&
-- strncmp((char *) magicno+8, "ILBM", (size_t) 4)==0) rv = RFT_IFF;
-+ else if (strncmp((char *) magicno, "FORM", (size_t) 4)==0 &&
-+ strncmp((char *) magicno+8, "ILBM", (size_t) 4)==0) rv = RFT_IFF;
-
- else if (magicno[0]==0 && magicno[1]==0 &&
- magicno[2]==2 && magicno[3]==0 &&
- magicno[4]==0 && magicno[5]==0 &&
-- magicno[6]==0 && magicno[7]==0) rv = RFT_TARGA;
-+ magicno[6]==0 && magicno[7]==0) rv = RFT_TARGA;
-
- else if (magicno[4]==0x00 && magicno[5]==0x00 &&
-- magicno[6]==0x00 && magicno[7]==0x07) rv = RFT_XWD;
-+ magicno[6]==0x00 && magicno[7]==0x07) rv = RFT_XWD;
-
-- else if (strncmp((char *) magicno,"SIMPLE ", (size_t) 8)==0 &&
-- magicno[29] == 'T') rv = RFT_FITS;
--
-+ else if (strncmp((char *) magicno,"SIMPLE ", (size_t) 8)==0 &&
-+ magicno[29] == 'T') rv = RFT_FITS;
-+
-+ /* [JCE] Spectrum screen */
-+ else if (memcmp(magicno, ZXheader, (size_t) 18)==0) rv = RFT_ZX;
-
- #ifdef HAVE_JPEG
-- else if (magicno[0]==0xff && magicno[1]==0xd8 &&
-- magicno[2]==0xff) rv = RFT_JFIF;
-+ else if (magicno[0]==0xff && magicno[1]==0xd8 &&
-+ magicno[2]==0xff) rv = RFT_JFIF;
-+#endif
-+
-+#ifdef HAVE_JP2K
-+ else if (magicno[0]==0xff && magicno[1]==0x4f &&
-+ magicno[2]==0xff && magicno[3]==0x51) rv = RFT_JPC;
-+
-+ else if (memcmp(magicno, jp2k_magic, sizeof(jp2k_magic))==0) rv = RFT_JP2;
- #endif
-
- #ifdef HAVE_TIFF
- else if ((magicno[0]=='M' && magicno[1]=='M') ||
-- (magicno[0]=='I' && magicno[1]=='I')) rv = RFT_TIFF;
-+ (magicno[0]=='I' && magicno[1]=='I')) rv = RFT_TIFF;
-+#endif
-+
-+#ifdef HAVE_PNG
-+ else if (magicno[0]==0x89 && magicno[1]=='P' &&
-+ magicno[2]=='N' && magicno[3]=='G') rv = RFT_PNG;
- #endif
-
- #ifdef HAVE_PDS
-@@ -2620,11 +3130,67 @@
- rv = RFT_PDSVICAR;
- #endif
-
--#ifdef GS_PATH
-+#ifdef GS_PATH /* Ghostscript handles both PostScript and PDF */
- else if (strncmp((char *) magicno, "%!", (size_t) 2)==0 ||
-- strncmp((char *) magicno, "\004%!", (size_t) 3)==0) rv = RFT_PS;
-+ strncmp((char *) magicno, "\004%!", (size_t) 3)==0 ||
-+ strncmp((char *) magicno, "%PDF", (size_t) 4)==0) rv = RFT_PS;
-+#endif
-+
-+#ifdef HAVE_G3
-+ else if ((magicno[0]== 1 && magicno[1]== 1 &&
-+ magicno[2]== 77 && magicno[3]==154 &&
-+ magicno[4]==128 && magicno[5]== 0 &&
-+ magicno[6]== 1 && magicno[7]== 77)
-+ || highresfax || fax) /* kludge! */ rv = RFT_G3;
-+#endif
-+
-+#ifdef HAVE_MAG
-+ else if (strncmp((char *) magicno,"MAKI02 ", (size_t) 8)==0) rv = RFT_MAG;
-+#endif
-+
-+#ifdef HAVE_MAKI
-+ else if (strncmp((char *) magicno,"MAKI01A ", (size_t) 8)==0 ||
-+ strncmp((char *) magicno,"MAKI01B ", (size_t) 8)==0) rv = RFT_MAKI;
-+#endif
-+
-+#ifdef HAVE_PIC
-+ else if (magicno[0]=='P' && magicno[1]=='I'&&magicno[2]=='C') rv = RFT_PIC;
-+#endif
-+
-+#ifdef HAVE_PI
-+ else if (magicno[0]=='P' && magicno[1]=='i') rv = RFT_PI;
-+#endif
-+
-+#ifdef HAVE_HIPS
-+ else if (strstr((char *) magicno, "./digest")) rv = RFT_HIPS;
-+#endif
-+
-+#ifdef HAVE_PCD
-+ else if (magicno[0]==0xff && magicno[1]==0xff &&
-+ magicno[2]==0xff && magicno[3]==0xff) rv = RFT_PCD;
- #endif
-
-+#ifdef MACBINARY
-+ /* Now we try to handle MacBinary files, but the method is VERY dirty... */
-+ if (macbin_alrchk == True) {
-+ macb_file = True;
-+ break;
-+ }
-+
-+ if (rv != RFT_UNKNOWN)
-+ break;
-+
-+ /* Skip MACBSIZE and recheck */
-+ macbin_alrchk = True;
-+ fp = xv_fopen(fname, "r");
-+ if (!fp) return RFT_ERROR;
-+ fseek(fp, MACBSIZE, SEEK_SET);
-+ n = fread(magicno, (size_t) 1, (size_t) 30, fp);
-+ fclose(fp);
-+
-+ if (n<30) return RFT_UNKNOWN; /* files less than 30 bytes long... */
-+ }
-+#endif
- return rv;
- }
-
-@@ -2637,9 +3203,10 @@
- PICINFO *pinfo;
- {
- /* if quick is set, we're being called to generate icons, or something
-- like that. We should load the image as quickly as possible. Currently,
-- this only affects the LoadPS routine, which, if quick is set, only
-- generates the page file for the first page of the document */
-+ like that. We should load the image as quickly as possible. Previously,
-+ this affected only the LoadPS routine, which, if quick is set, only
-+ generates the page file for the first page of the document. Now it
-+ also affects PCD, which loads only a thumbnail. */
-
- int rv = 0;
-
-@@ -2650,7 +3217,11 @@
- switch (ftype) {
- case RFT_GIF: rv = LoadGIF (fname, pinfo); break;
- case RFT_PM: rv = LoadPM (fname, pinfo); break;
-+#ifdef HAVE_MGCSFX
-+ case RFT_PBM: rv = LoadPBM (fname, pinfo, -1); break;
-+#else
- case RFT_PBM: rv = LoadPBM (fname, pinfo); break;
-+#endif
- case RFT_XBM: rv = LoadXBM (fname, pinfo); break;
- case RFT_SUNRAS: rv = LoadSunRas(fname, pinfo); break;
- case RFT_BMP: rv = LoadBMP (fname, pinfo); break;
-@@ -2662,21 +3233,69 @@
- case RFT_XPM: rv = LoadXPM (fname, pinfo); break;
- case RFT_XWD: rv = LoadXWD (fname, pinfo); break;
- case RFT_FITS: rv = LoadFITS (fname, pinfo, quick); break;
-+ case RFT_ZX: rv = LoadZX (fname, pinfo); break; /* [JCE] */
-+ case RFT_WBMP: rv = LoadWBMP (fname, pinfo); break;
-+
-+#ifdef HAVE_PCD
-+ /* if quick is switched on, use the smallest image size; don't ask the user */
-+ case RFT_PCD: rv = LoadPCD (fname, pinfo, quick ? 0 : PcdSize); break;
-+#endif
-
- #ifdef HAVE_JPEG
-- case RFT_JFIF: rv = LoadJFIF (fname, pinfo, quick); break;
-+ case RFT_JFIF: rv = LoadJFIF (fname, pinfo, quick); break;
-+#endif
-+
-+#ifdef HAVE_JP2K
-+ case RFT_JPC: rv = LoadJPC (fname, pinfo, quick); break;
-+ case RFT_JP2: rv = LoadJP2 (fname, pinfo, quick); break;
- #endif
-
- #ifdef HAVE_TIFF
-- case RFT_TIFF: rv = LoadTIFF (fname, pinfo); break;
-+ case RFT_TIFF: rv = LoadTIFF (fname, pinfo, quick); break;
-+#endif
-+
-+#ifdef HAVE_PNG
-+ case RFT_PNG: rv = LoadPNG (fname, pinfo); break;
- #endif
-
- #ifdef HAVE_PDS
-- case RFT_PDSVICAR: rv = LoadPDS (fname, pinfo); break;
-+ case RFT_PDSVICAR: rv = LoadPDS (fname, pinfo); break;
-+#endif
-+
-+#ifdef HAVE_G3
-+ case RFT_G3: rv = LoadG3 (fname, pinfo); break;
- #endif
-
- #ifdef GS_PATH
-- case RFT_PS: rv = LoadPS (fname, pinfo, quick); break;
-+ case RFT_PS: rv = LoadPS (fname, pinfo, quick); break;
-+#endif
-+
-+#ifdef HAVE_MAG
-+ case RFT_MAG: rv = LoadMAG (fname, pinfo); break;
-+#endif
-+
-+#ifdef HAVE_MAKI
-+ case RFT_MAKI: rv = LoadMAKI (fname, pinfo); break;
-+#endif
-+
-+#ifdef HAVE_PIC
-+ case RFT_PIC: rv = LoadPIC (fname, pinfo); break;
-+#endif
-+
-+#ifdef HAVE_PI
-+ case RFT_PI: rv = LoadPi (fname, pinfo); break;
-+#endif
-+
-+#ifdef HAVE_PIC2
-+ case RFT_PIC2: rv = LoadPIC2 (fname, pinfo, quick); break;
-+#endif
-+
-+#ifdef HAVE_HIPS
-+ case RFT_HIPS: rv = LoadHIPS (fname, pinfo); break;
-+#endif
-+
-+#ifdef HAVE_MGCSFX
-+ case RFT_MGCSFX: rv = LoadMGCSFX (fname, pinfo); break;
- #endif
-
- }
-@@ -2685,13 +3304,17 @@
-
-
- /********************************/
--int UncompressFile(name, uncompname)
-+int UncompressFile(name, uncompname, filetype)
- char *name, *uncompname;
-+ int filetype;
- {
- /* returns '1' on success, with name of uncompressed file in uncompname
- returns '0' on failure */
-
- char namez[128], *fname, buf[512];
-+#ifndef USE_MKSTEMP
-+ int tmpfd;
-+#endif
-
- fname = name;
- namez[0] = '\0';
-@@ -2703,7 +3326,7 @@
- to what it was. necessary because uncompress doesn't handle files
- that don't end with '.Z' */
-
-- if (strlen(name) >= (size_t) 2 &&
-+ if (strlen(name) >= (size_t) 2 &&
- strcmp(name + strlen(name)-2,".Z")!=0 &&
- strcmp(name + strlen(name)-2,".z")!=0) {
- strcpy(namez, name);
-@@ -2721,34 +3344,50 @@
- #endif /* not VMS and not GUNZIP */
-
-
--
- #ifndef VMS
- sprintf(uncompname, "%s/xvuXXXXXX", tmpdir);
-- mktemp(uncompname);
-- sprintf(buf,"%s -c %s >%s", UNCOMPRESS, fname, uncompname);
--#else /* it IS VMS */
-+#else
- strcpy(uncompname, "[]xvuXXXXXX");
-+#endif
-+
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(uncompname));
-+#else
- mktemp(uncompname);
--# ifdef GUNZIP
-- sprintf(buf,"%s %s %s", UNCOMPRESS, fname, uncompname);
--# else
-- sprintf(buf,"%s %s", UNCOMPRESS, fname);
--# endif
-+ tmpfd = open(uncompname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
-+ if (tmpfd < 0) FatalError("UncompressFile(): can't create temporary file");
-+ close(tmpfd);
-+#endif
-+
-+#ifndef VMS
-+ if (filetype == RFT_COMPRESS)
-+ sprintf(buf,"%s -c '%s' > '%s'", UNCOMPRESS, fname, uncompname);
-+# ifdef BUNZIP2
-+ else if (filetype == RFT_BZIP2)
-+ sprintf(buf,"%s -c '%s' > '%s'", BUNZIP2, fname, uncompname);
-+# endif
-+#else /* it IS VMS */
-+# ifdef GUNZIP
-+ sprintf(buf,"%s '%s' '%s'", UNCOMPRESS, fname, uncompname);
-+# else
-+ sprintf(buf,"%s '%s'", UNCOMPRESS, fname);
-+# endif
- #endif
-
- SetISTR(ISTR_INFO, "Uncompressing '%s'...", BaseName(fname));
- #ifndef VMS
-- if (system(buf)) {
-+ if (system(buf))
- #else
-- if (!system(buf)) {
-+ if (!system(buf))
- #endif
-+ {
- SetISTR(ISTR_INFO, "Unable to uncompress '%s'.", BaseName(fname));
- Warning();
- return 0;
- }
-
--#ifndef VMS
-- /* if we renamed the file to end with a .Z for the sake of 'uncompress',
-+#ifndef VMS
-+ /* if we renamed the file to end with a .Z for the sake of 'uncompress',
- rename it back to what it once was... */
-
- if (strlen(namez)) {
-@@ -2769,9 +3408,65 @@
- }
- */
- #endif /* not VMS */
--
-+
-+ return 1;
-+}
-+
-+
-+#ifdef MACBINARY
-+/********************************/
-+int RemoveMacbinary(src, dst)
-+ char *src, *dst;
-+{
-+ char buffer[8192]; /* XXX */
-+ int n, eof;
-+#ifndef USE_MKSTEMP
-+ int tmpfd;
-+#endif
-+ FILE *sfp, *dfp;
-+
-+ sprintf(dst, "%s/xvmXXXXXX", tmpdir);
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(dst));
-+#else
-+ mktemp(dst);
-+ tmpfd = open(dst,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
-+ if (tmpfd < 0) FatalError("RemoveMacbinary(): can't create temporary file");
-+#endif
-+
-+ SetISTR(ISTR_INFO, "Removing MacBinary...");
-+
-+ sfp = xv_fopen(src, "r");
-+#ifdef USE_MKSTEMP
-+ dfp = xv_fopen(dst, "w");
-+#else
-+ dfp = fdopen(tmpfd, "w");
-+#endif
-+ if (!sfp || !dfp) {
-+ SetISTR(ISTR_INFO, "Unable to remove a InfoFile header form '%s'.", src);
-+ Warning();
-+ return 0;
-+ }
-+ fseek(sfp, MACBSIZE, SEEK_SET);
-+ while ((n = fread(buffer, 1, sizeof(buffer), sfp)) == 8192) /* XXX */
-+ fwrite(buffer, 1, n, dfp);
-+ if ((eof = feof(sfp)))
-+ fwrite(buffer, 1, n, dfp);
-+ fclose(sfp);
-+ fflush(dfp);
-+ fclose(dfp);
-+#ifndef USE_MKSTEMP
-+ close(tmpfd);
-+#endif
-+ if (!eof) {
-+ SetISTR(ISTR_INFO, "Unable to remove a InfoFile header form '%s'.", src);
-+ Warning();
-+ return 0;
-+ }
-+
- return 1;
- }
-+#endif
-
-
- /********************************/
-@@ -2789,6 +3484,10 @@
- sprintf(tmp, "%s%d", bname, i);
- unlink(tmp);
- }
-+
-+ /* GRR 20070506: basename file doesn't go away, at least on Linux and for
-+ * GIF and TIFF images, so explicitly unlink() it, too */
-+ unlink(bname);
- }
-
-
-@@ -2798,11 +3497,11 @@
- {
- int i;
-
-- /* some stuff that necessary whenever running an algorithm or
-+ /* some stuff that necessary whenever running an algorithm or
- installing a new 'pic' (or switching 824 modes) */
-
- numcols = 0; /* gets set by SortColormap: set to 0 for PIC24 images */
-- for (i=0; i<256; i++) cols[i]=infobg;
-+ for (i=0; i<256; i++) cols[i]=infobg;
-
- if (picType == PIC8) {
- byte trans[256];
-@@ -2811,18 +3510,18 @@
- }
-
- if (picType == PIC8) {
-- /* see if image is a b/w bitmap.
-+ /* see if image is a b/w bitmap.
- If so, use '-black' and '-white' colors */
- if (numcols == 2) {
- if ((rMap[0] == gMap[0] && rMap[0] == bMap[0] && rMap[0] == 255) &&
- (rMap[1] == gMap[1] && rMap[1] == bMap[1] && rMap[1] == 0)) {
- /* 0=wht, 1=blk */
-- rMap[0] = (whtRGB>>16)&0xff;
-- gMap[0] = (whtRGB>>8)&0xff;
-+ rMap[0] = (whtRGB>>16)&0xff;
-+ gMap[0] = (whtRGB>>8)&0xff;
- bMap[0] = whtRGB&0xff;
-
- rMap[1] = (blkRGB>>16)&0xff;
-- gMap[1] = (blkRGB>>8)&0xff;
-+ gMap[1] = (blkRGB>>8)&0xff;
- bMap[1] = blkRGB&0xff;
- }
-
-@@ -2852,10 +3551,10 @@
- }
-
- /* save the desired RGB colormap (before dicking with it) */
-- for (i=0; i /tmp/xv******" appended).
-+ * runs command (with "> /tmp/xv******" appended).
- * returns "/tmp/xv******" in fname
- * returns '0' if everything's cool, '1' on error
- */
-
- char fullcmd[512], tmpname[64], str[512];
- int i;
-+#ifndef USE_MKSTEMP
-+ int tmpfd;
-+#endif
-
- if (!cmd || (strlen(cmd) < (size_t) 2)) return 1;
-
- sprintf(tmpname,"%s/xvXXXXXX", tmpdir);
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(tmpname));
-+#else
- mktemp(tmpname);
-- if (tmpname[0] == '\0') { /* mktemp() blew up */
-+ tmpfd = open(tmpname,O_WRONLY|O_CREAT|O_EXCL,S_IRWUSR);
-+ if (tmpfd < 0) FatalError("openPic(): can't create temporary file");
-+ close(tmpfd);
-+#endif
-+ if (tmpname[0] == '\0') { /* mktemp() or mkstemp() blew up */
- sprintf(str,"Unable to create temporary filename.");
- ErrPopUp(str, "\nHow unlikely!");
- return 1;
-@@ -2939,26 +3648,21 @@
- {
- int i;
-
-+ waitsec = (numnames <= 1)? waitsec_final : waitsec_nonfinal;
-+
- if (!numnames) { openPic(DFLTPIC); return; }
-
- i = 0;
-- if (!randomShow) {
-- while (numnames>0) {
-- if (openPic(0)) return; /* success */
-- else {
-- if (polling && !i)
-- fprintf(stderr,"%s: POLLING: Waiting for file '%s' \n\tto %s\n",
-- cmd, namelist[0], "be created, or whatever...");
-- i = 1;
-- }
-+ while (numnames>0) {
-+ if (openPic(0)) return; /* success */
-+ else {
-+ if (polling && !i)
-+ fprintf(stderr,"%s: POLLING: Waiting for file '%s' \n\tto %s\n",
-+ cmd, namelist[0], "be created, or whatever...");
-+ i = 1;
- }
- }
-
-- else { /* pick random first picture */
-- for (i=findRandomPic(); i>=0; i=findRandomPic())
-- if (openPic(i)) return; /* success */
-- }
--
- if (numnames>1) FatalError("couldn't open any pictures");
- else Quit(-1);
- }
-@@ -2970,11 +3674,11 @@
- int i;
-
- if (curname>=0) i = curname+1;
-- else if (nList.selected >= 0 && nList.selected < numnames)
-+ else if (nList.selected >= 0 && nList.selected < numnames)
- i = nList.selected;
- else i = 0;
-
--
-+
- while (i=0) i = curname+1;
-- else if (nList.selected >= 0 && nList.selected < numnames)
-- i = nList.selected;
-- else i = 0;
-+ if (curname>=0) i = curname+1;
-+ else if (nList.selected >= 0 && nList.selected < numnames)
-+ i = nList.selected;
-+ else i = 0;
-
-- while (i=0; i=findRandomPic())
-- if (openPic(i)) return;
-- }
-+ waitsec = (i == numnames-1)? waitsec_final : waitsec_nonfinal;
-+
-+ while (i=0) i = curname+1;
-- else if (nList.selected >= 0 && nList.selected < numnames)
-- i = nList.selected;
-- else i = 0;
-+ if (curname>=0) i = curname+1;
-+ else if (nList.selected >= 0 && nList.selected < numnames)
-+ i = nList.selected;
-+ else i = 0;
-+
-+ if (loop) { i = 0; loop = 0; }
-
-- if (loop) { i = 0; loop = 0; }
-+ waitsec = (i == numnames-1)? waitsec_final : waitsec_nonfinal;
-
-- while (i=0; i=findRandomPic())
-- if (openPic(i)) return;
-- }
-+ while (i0) i = curname-1;
-- else if (nList.selected>0 && nList.selected < numnames)
-+ else if (nList.selected>0 && nList.selected < numnames)
- i = nList.selected - 1;
- else i = numnames-1;
-
-@@ -3063,64 +3759,24 @@
- openPic(LOADPIC);
- }
-
--
--
--
--/****************/
--static int findRandomPic()
--/****************/
--{
-- static byte *loadList;
-- static int left_to_load, listLen = -1;
-- int k;
-- time_t t;
--
-- /* picks a random name out of the list, and returns it's index. If there
-- are no more names to pick, it returns '-1' and resets itself */
--
-- if (!loadList || numnames!=listLen) {
-- if (loadList) free(loadList);
-- else {
-- time(&t);
-- srandom((unsigned int) t); /* seed the random */
-- }
--
-- left_to_load = listLen = numnames;
-- loadList = (byte *) malloc((size_t) listLen);
-- for (k=0; k= 0, a filenum to GOTO */
-
- int i;
-
-- /* if curname<0 (there is no 'current' file), 'Next' means view the
-+ /* if curname<0 (there is no 'current' file), 'Next' means view the
- selected file (or the 0th file, if no selection either), and 'Prev' means
- view the one right before the selected file */
-
-- openFirstPic(); /* find first displayable picture, exit if none */
-+ /* find first displayable picture, exit if none */
-+ if (!startGrab) openFirstPic();
-
- if (!pic) { /* must've opened a text file... display dflt pic */
-- openPic(DFLTPIC);
-+ if (!startGrab) openPic(DFLTPIC);
- if (mainW && !useroot) RaiseTextWindows();
- }
-
-@@ -3133,7 +3789,7 @@
- }
-
- else if (i==PREVPIC) {
-- if (curname>0 || (curname<0 && nList.selected>0))
-+ if (curname>0 || (curname<0 && nList.selected>0))
- openPrevPic();
- }
-
-@@ -3151,7 +3807,7 @@
-
- else if (i==THISNEXT) { /* open current sel, 'next' until success */
- int j;
-- j = nList.selected;
-+ j = nList.selected;
- if (j<0) j = 0;
- while (j vrWIDE) x = vrWIDE - eWIDE; /* keep on screen */
-+ /* keep on screen */
-+ if (x+eWIDE > vrWIDE) x = vrWIDE - eWIDE;
- if (y+eHIGH > vrHIGH) y = vrHIGH - eHIGH;
--
-+ if (x < 0) x = 0;
-+ if (y < 0) y = 0;
-
- #define VROOT_TRANS
- #ifdef VROOT_TRANS
-- if (vrootW != rootW) { /* virtual window manager running */
-+ if (vrootW != rootW && !(hints.flags & USPosition)) { /* virtual window manager running */
- int x1,y1;
- Window child;
-+
- XTranslateCoordinates(theDisp, rootW, vrootW, x, y, &x1, &y1, &child);
-- if (DEBUG) fprintf(stderr,"translate: %d,%d -> %d,%d\n",x,y,x1,y1);
-+ if (DEBUG) fprintf(stderr,"translate: %d,%d -> %d,%d\n", x, y, x1, y1);
- x = x1; y = y1;
- }
- #endif
-@@ -3218,13 +3887,13 @@
- hints.x = x; hints.y = y;
- hints.width = eWIDE; hints.height = eHIGH;
- hints.max_width = maxWIDE; hints.max_height = maxHIGH;
-- hints.flags |= USSize | PMaxSize;
--
-- xswa.bit_gravity = StaticGravity;
-+ hints.flags |= PSize | PMaxSize;
-+
-+ xswa.bit_gravity = StaticGravity;
- xswa.background_pixel = bg;
- xswa.border_pixel = fg;
- xswa.colormap = theCmap;
--
-+
- xswa.backing_store = WhenMapped;
-
- /* NOTE: I've turned 'backing-store' off on the image window, as some
-@@ -3233,9 +3902,9 @@
- improvement anyway (for the image window), unless you're on a slow
- network. In any event, I'm not *turning off* backing store, I'm
- just not explicitly turning it *on*. If your X server is set up
-- that windows, by default, have backing-store turned on, then the
-+ that windows, by default, have backing-store turned on, then the
- image window will, too */
--
-+
- xswamask = CWBackPixel | CWBorderPixel | CWColormap /* | CWBackingStore */;
- if (!clearonload) xswamask |= CWBitGravity;
-
-@@ -3244,18 +3913,18 @@
- xwa.width = eWIDE; xwa.height = eHIGH;
-
- /* try to keep the damned thing on-screen, if possible */
-- if (xwa.x + xwa.width > dispWIDE) xwa.x = dispWIDE - xwa.width;
-- if (xwa.y + xwa.height > dispHIGH) xwa.y = dispHIGH - xwa.height;
-+ if (xwa.x + xwa.width > vrWIDE) xwa.x = vrWIDE - xwa.width;
-+ if (xwa.y + xwa.height > vrHIGH) xwa.y = vrHIGH - xwa.height;
- if (xwa.x < 0) xwa.x = 0;
- if (xwa.y < 0) xwa.y = 0;
-
- SetWindowPos(&xwa);
- hints.flags = PSize | PMaxSize;
-- }
-+ }
-
- else {
- mainW = XCreateWindow(theDisp,rootW,x,y, (u_int) eWIDE, (u_int) eHIGH,
-- (u_int) bwidth, (int) dispDEEP, InputOutput,
-+ (u_int) bwidth, (int) dispDEEP, InputOutput,
- theVisual, xswamask, &xswa);
- if (!mainW) FatalError("can't create window!");
-
-@@ -3267,15 +3936,11 @@
- }
- }
-
--
-- XSetStandardProperties(theDisp,mainW,"","",None,NULL,0,&hints);
-- setWinIconNames(name);
--
- xwmh.input = True;
- xwmh.flags = InputHint;
-
-- xwmh.icon_pixmap = iconPix;
-- xwmh.icon_mask = iconmask;
-+ xwmh.icon_pixmap = iconPix;
-+ xwmh.icon_mask = iconmask;
- xwmh.flags |= (IconPixmapHint | IconMaskHint);
-
-
-@@ -3295,14 +3960,15 @@
- }
- }
- }
-- XSetWMHints(theDisp, mainW, &xwmh);
-
- classh.res_name = "xv";
- classh.res_class = "XVroot";
-- XSetClassHint(theDisp, mainW, &classh);
-
-+ XmbSetWMProperties(theDisp, mainW, NULL, NULL, NULL, 0, &hints, &xwmh,
-+ &classh);
-+ setWinIconNames(name);
-
-- if (nodecor) { /* turn of image window decorations (in MWM) */
-+ if (nodecor) { /* turn of image window decorations (in MWM) */
- Atom mwm_wm_hints;
- struct s_mwmhints {
- long flags;
-@@ -3311,7 +3977,7 @@
- u_long input_mode;
- long status;
- } mwmhints;
--
-+
- mwm_wm_hints = XInternAtom(theDisp, "_MOTIF_WM_HINTS", False);
- if (mwm_wm_hints != None) {
- xvbzero((char *) &mwmhints, sizeof(mwmhints));
-@@ -3319,20 +3985,20 @@
- mwmhints.decorations = 4;
-
- XChangeProperty(theDisp, mainW, mwm_wm_hints, mwm_wm_hints, 32,
-- PropModeReplace, (byte *) &mwmhints,
-- (int) (sizeof(mwmhints))/4);
-+ PropModeReplace, (byte *) &mwmhints,
-+ (int) (sizeof(mwmhints))/4);
- XSync(theDisp, False);
- }
- }
-
--
-+
- firstTime = 0;
- }
-
-
- /***********************************/
- static void setWinIconNames(name)
-- char *name;
-+ const char *name;
- {
- char winname[256], iconname[256];
-
-@@ -3362,12 +4028,12 @@
-
- /***********************************/
- void FixAspect(grow,w,h)
--int grow;
--int *w, *h;
-+ int grow;
-+ int *w, *h;
- {
- /* computes new values of eWIDE and eHIGH which will have aspect ratio
-- 'normaspect'. If 'grow' it will preserve aspect by enlarging,
-- otherwise, it will shrink to preserve aspect ratio.
-+ 'normaspect'. If 'grow' it will preserve aspect by enlarging,
-+ otherwise, it will shrink to preserve aspect ratio.
- Returns these values in 'w' and 'h' */
-
- float xr,yr,curaspect,a,exp;
-@@ -3380,14 +4046,14 @@
- curaspect = xr / yr;
-
- /* if too narrow & shrink, shrink height. too wide and grow, grow height */
-- if ((curaspect < normaspect && !grow) ||
-+ if ((curaspect < normaspect && !grow) ||
- (curaspect > normaspect && grow)) { /* modify height */
- exp = curaspect / normaspect;
- *h = (int) (eHIGH * exp + .5);
- }
-
- /* if too narrow & grow, grow width. too wide and shrink, shrink width */
-- if ((curaspect < normaspect && grow) ||
-+ if ((curaspect < normaspect && grow) ||
- (curaspect > normaspect && !grow)) { /* modify width */
- exp = normaspect / curaspect;
- *w = (int) (eWIDE * exp + .5);
-@@ -3423,22 +4089,22 @@
- suffix = namelist[0];
- prelen = 0; /* length of prefix to be removed */
- n = i = 0; /* shut up pesky compiler warnings */
--
-+
- done = 0;
- while (!done) {
- suffix = (char *) index(suffix,'/'); /* find next '/' in file name */
- if (!suffix) break;
--
-+
- suffix++; /* go past it */
- n = suffix - namelist[0];
- for (i=1; i (nList.w-10-16)) { /* have to trunc. */
- tmp = dname;
- while (1) {
- tmp = (char *) index(tmp,'/'); /* find next '/' in filename */
- if (!tmp) { tmp = dname; break; }
--
-+
- tmp++; /* move to char following the '/' */
- if (StringWidth(tmp) <= (nList.w-10-16)) { /* is cool now */
- j++; break;
-@@ -3484,9 +4150,9 @@
-
- name = GetDirFName();
- GetDirPath(cwd);
--
-+
- AddFNameToCtrlList(cwd, name);
--
-+
- if (select) {
- nList.selected = numnames-1;
- curname = numnames - 1;
-@@ -3498,35 +4164,35 @@
-
- /***********************************/
- void AddFNameToCtrlList(fpath,fname)
-- char *fpath, *fname;
-+ const char *fpath, *fname;
- {
- /* stick given path/name into 'namelist'. Doesn't redraw list */
--
-- char *fullname, *dname;
-+
-+ char *fullname;
- char cwd[MAXPATHLEN], globnm[MAXPATHLEN+100];
- int i;
--
-+
- if (!fpath) fpath = ""; /* bulletproofing... */
-- if (!fname) fname = "";
--
-+ if (!fname) fname = "";
-+
- if (numnames == MAXNAMES) return; /* full up */
--
-+
- /* handle globbing */
- if (fname[0] == '~') {
- strcpy(globnm, fname);
- Globify(globnm);
- fname = globnm;
- }
--
-+
- if (fname[0] != '/') { /* prepend path */
- strcpy(cwd, fpath); /* copy it to a modifiable place */
--
-+
- /* make sure fpath has a trailing '/' char */
- if (strlen(cwd)==0 || cwd[strlen(cwd)-1]!='/') strcat(cwd, "/");
--
-+
- fullname = (char *) malloc(strlen(cwd) + strlen(fname) + 2);
- if (!fullname) FatalError("couldn't alloc name in AddFNameToCtrlList()\n");
--
-+
- sprintf(fullname, "%s%s", cwd, fname);
- }
- else { /* copy name to fullname */
-@@ -3534,15 +4200,15 @@
- if (!fullname) FatalError("couldn't alloc name in AddFNameToCtrlList()\n");
- strcpy(fullname, fname);
- }
--
--
-+
-+
- /* see if this name is a duplicate. Don't add it if it is. */
- for (i=0; i0));
- }
- }
--
-+
-
- /***********************************/
- int DeleteCmd()
- {
- /* 'delete' button was pressed. Pop up a dialog box to determine
- what should be deleted, then do it.
-- returns '1' if THE CURRENTLY VIEWED entry was deleted from the list,
-- in which case the 'selected' filename on the ctrl list is now
-+ returns '1' if THE CURRENTLY VIEWED entry was deleted from the list,
-+ in which case the 'selected' filename on the ctrl list is now
- different, and should be auto-loaded, or something */
-
-- static char *bnames[] = { "\004Disk File", "\nList Entry", "\033Cancel" };
-+ static const char *bnames[] =
-+ { "\004Disk File", "\nList Entry", "\033Cancel" };
- char str[512];
- int del, i, delnum, rv;
-
-@@ -3610,15 +4277,14 @@
- delnum = nList.selected;
- if (delnum < 0 || delnum >= numnames) return 0;
-
-- sprintf(str,"Delete '%s'?\n\n%s%s",
-- namelist[delnum],
-+ sprintf(str, "Delete '%s'?\n\n%s%s", namelist[delnum],
- "'List Entry' deletes selection from list.\n",
- "'Disk File' deletes file associated with selection.");
-
- del = PopUp(str, bnames, 3);
--
-+
- if (del == 2) return 0; /* cancel */
--
-+
- if (del == 0) { /* 'Disk File' */
- char *name;
- if (namelist[delnum][0] != '/') { /* prepend 'initdir' */
-@@ -3669,13 +4335,13 @@
-
- if (delnum != numnames-1) {
- /* snip out of namelist and dispnames lists */
-- xvbcopy((char *) &namelist[delnum+1], (char *) &namelist[delnum],
-+ xvbcopy((char *) &namelist[delnum+1], (char *) &namelist[delnum],
- (numnames - delnum - 1) * sizeof(namelist[0]));
-
-- xvbcopy((char *) &dispnames[delnum+1], (char *) &dispnames[delnum],
-+ xvbcopy((char *) &dispnames[delnum+1], (char *) &dispnames[delnum],
- (numnames - delnum - 1) * sizeof(dispnames[0]));
- }
--
-+
- numnames--;
- if (numnames==0) BTSetActive(&but[BDELETE],0);
- windowMB.dim[WMB_TEXTVIEW] = (numnames==0);
-@@ -3686,7 +4352,7 @@
- if (nList.selected >= numnames) nList.selected = numnames-1;
- if (nList.selected < 0) nList.selected = 0;
-
-- SCSetRange(&nList.scrl, 0, numnames - nList.nlines,
-+ SCSetRange(&nList.scrl, 0, numnames - nList.nlines,
- nList.scrl.val, nList.nlines-1);
- ScrollToCurrent(&nList);
- DrawCtrlNumFiles();
-@@ -3753,7 +4419,7 @@
- if (useroot && resetroot) ClearRoot();
-
- if (mainW == (Window) NULL || useroot) { /* window not visible */
-- useroot = 0;
-+ useroot = 0;
-
- if (haveoldinfo) { /* just remap mainW and resize it */
- XWMHints xwmh;
-@@ -3771,8 +4437,8 @@
- xwmh.input = True;
- xwmh.flags = InputHint;
-
-- xwmh.icon_pixmap = iconPix;
-- xwmh.icon_mask = iconmask;
-+ xwmh.icon_pixmap = iconPix;
-+ xwmh.icon_mask = iconmask;
- xwmh.flags |= ( IconPixmapHint | IconMaskHint) ;
-
- xwmh.flags |= StateHint;
-@@ -3787,7 +4453,7 @@
- else { /* first time. need to create mainW */
- mainW = (Window) NULL;
- createMainWindow(maingeom, fnam);
-- XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
-+ XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
- | StructureNotifyMask | ButtonPressMask
- | KeyReleaseMask | ColormapChangeMask
- | EnterWindowMask | LeaveWindowMask );
-@@ -3802,7 +4468,7 @@
-
- else { /* mainW already visible */
- createMainWindow(maingeom, fnam);
-- XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
-+ XSelectInput(theDisp, mainW, ExposureMask | KeyPressMask
- | StructureNotifyMask | ButtonPressMask
- | KeyReleaseMask | ColormapChangeMask
- | EnterWindowMask | LeaveWindowMask );
-@@ -3845,13 +4511,13 @@
- if (LocalCmap) regen=1;
-
- /* this reallocs the colors */
-- if (colorMapMode==CM_PERFECT || colorMapMode==CM_OWNCMAP)
-+ if (colorMapMode==CM_PERFECT || colorMapMode==CM_OWNCMAP)
- ChangeCmapMode(CM_NORMAL, 0, 0);
--
--
-+
-+
- XUnmapWindow(theDisp, mainW);
- mainW = vrootW;
--
-+
- if (!ctrlUp) { /* make sure ctrl is up when going to 'root' mode */
- XWMHints xwmh;
- xwmh.input = True;
-@@ -3861,7 +4527,7 @@
- CtrlBox(1);
- }
- }
--
-+
- useroot = 1;
- rootMode = dispMode - RMB_ROOT;
- ew = eWIDE; eh = eHIGH;
-@@ -3877,7 +4543,7 @@
- GenerateEpic(ew, eh);
- CreateXImage();
- }
-- else if (regen) CreateXImage();
-+ else if (regen) CreateXImage();
-
- KillOldRootInfo();
- MakeRootPic();
-@@ -3923,7 +4589,7 @@
-
-
- if (*numn == maxn) {
-- fprintf(stderr, "%s: too many filenames. Only using first %d.\n",
-+ fprintf(stderr, "%s: too many filenames. Using only first %d.\n",
- flist, maxn);
- }
-
-@@ -3947,14 +4613,14 @@
-
- /***********************************/
- int rd_int(name)
-- char *name;
-+ const char *name;
- {
- /* returns '1' if successful. result in def_int */
-
- if (rd_str_cl(name, "", 0)) { /* sets def_str */
- if (sscanf(def_str, "%d", &def_int) == 1) return 1;
- else {
-- fprintf(stderr, "%s: couldn't read integer value for %s resource\n",
-+ fprintf(stderr, "%s: couldn't read integer value for %s resource\n",
- cmd, name);
- return 0;
- }
-@@ -3965,7 +4631,7 @@
-
- /***********************************/
- int rd_str(name)
-- char *name;
-+ const char *name;
- {
- return rd_str_cl(name, "", 0);
- }
-@@ -3973,17 +4639,17 @@
-
- /***********************************/
- int rd_flag(name)
--char *name;
-+ const char *name;
- {
- /* returns '1' if successful. result in def_int */
--
-+
- char buf[256];
-
- if (rd_str_cl(name, "", 0)) { /* sets def_str */
- strcpy(buf, def_str);
- lower_str(buf);
-
-- def_int = (strcmp(buf, "on")==0) ||
-+ def_int = (strcmp(buf, "on")==0) ||
- (strcmp(buf, "1")==0) ||
- (strcmp(buf, "true")==0) ||
- (strcmp(buf, "yes")==0);
-@@ -3992,16 +4658,16 @@
-
- else return 0;
- }
--
-+
-
-
-
- static int xrm_initted = 0;
--
-+
- /***********************************/
- int rd_str_cl (name_str, class_str, reinit)
-- char *name_str;
-- char *class_str;
-+ const char *name_str;
-+ const char *class_str;
- int reinit;
- {
- /* note: *all* X resource reading goes through this routine... */
-@@ -4043,16 +4709,30 @@
- unsigned long nitems, nleft;
- byte *data;
-
-- i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0),
-- resAtom, 0L, 1L, False,
-- XA_STRING, &actType, &actFormat, &nitems, &nleft,
-- (unsigned char **) &data);
-+ if (spec_window) {
-+ i = XGetWindowProperty(theDisp, spec_window,
-+ resAtom, 0L, 1L, False,
-+ XA_STRING, &actType, &actFormat, &nitems, &nleft,
-+ (unsigned char **) &data);
-+ } else {
-+ i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0),
-+ resAtom, 0L, 1L, False,
-+ XA_STRING, &actType, &actFormat, &nitems, &nleft,
-+ (unsigned char **) &data);
-+ }
- if (i==Success && actType==XA_STRING && actFormat==8) {
- if (nitems>0 && data) XFree(data);
-- i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0), resAtom, 0L,
-- (long) ((nleft+4+3)/4),
-- False, XA_STRING, &actType, &actFormat,
-- &nitems, &nleft, (unsigned char **) &data);
-+ if (spec_window) {
-+ i = XGetWindowProperty(theDisp, spec_window, resAtom, 0L,
-+ (long) ((nleft+4+3)/4),
-+ False, XA_STRING, &actType, &actFormat,
-+ &nitems, &nleft, (unsigned char **) &data);
-+ } else {
-+ i = XGetWindowProperty(theDisp, RootWindow(theDisp, 0), resAtom, 0L,
-+ (long) ((nleft+4+3)/4),
-+ False, XA_STRING, &actType, &actFormat,
-+ &nitems, &nleft, (unsigned char **) &data);
-+ }
- if (i==Success && actType==XA_STRING && actFormat==8 && data) {
- def_resource = XrmGetStringDatabase((char *) data);
- XFree(data);
-@@ -4064,50 +4744,51 @@
-
-
- if (!gotit) {
-- xrm_str = XResourceManagerString(theDisp);
--
-+ xrm_str = XResourceManagerString(theDisp);
-+
- if (xrm_str) {
- def_resource = XrmGetStringDatabase(xrm_str);
- if (DEBUG) fprintf(stderr,"rd_str_cl: Using RESOURCE_MANAGER prop.\n");
- }
- else { /* no RESOURCE_MANAGER prop. read from 'likely' file */
-- char foo[256], *homedir, *xenviron;
-+ char foo[256], *xenviron;
-+ const char *homedir;
- XrmDatabase res1;
--
-+
- #ifdef VMS
- strcpy(foo, "SYS$LOGIN:DECW$XDEFAULTS.DAT");
- #else
-- homedir = (char *) getenv("HOME");
-+ homedir = (const char *) getenv("HOME");
- if (!homedir) homedir = ".";
- sprintf(foo,"%s/.Xdefaults", homedir);
- #endif
--
-+
- def_resource = XrmGetFileDatabase(foo);
--
-+
- if (DEBUG) {
- fprintf(stderr,"rd_str_cl: No RESOURCE_MANAGER prop.\n");
- fprintf(stderr,"rd_str_cl: Using file '%s' (%s) ",
- foo, (def_resource) ? "success" : "failure");
- }
--
--
-+
-+
- /* merge file pointed to by XENVIRONMENT */
- xenviron = (char *) getenv("XENVIRONMENT");
- if (xenviron) {
- res1 = XrmGetFileDatabase(xenviron);
--
-+
- if (DEBUG) {
- fprintf(stderr,"merging XENVIRONMENT='%s' (%s) ",
- xenviron, (res1) ? "success" : "failure");
- }
--
-+
- if (res1) { /* merge databases */
- if (!def_resource) def_resource = res1;
- else XrmMergeDatabases(res1, &def_resource);
- }
- }
--
--
-+
-+
- if (DEBUG) fprintf(stderr,"\n\n");
- }
- }
-@@ -4120,16 +4801,15 @@
- strcpy (q_name, PROGNAME);
- strcat (q_name, ".");
- strcat (q_name, name_str);
--
-+
- strcpy (q_class, "Program");
- strcat (q_class, ".");
- strcat (q_class, class_str);
-
- (void) XrmGetResource(def_resource, q_name, q_class, &type, &result);
--
-+
- def_str = result.addr;
-- if (def_str) return (1);
-- else return (0);
-+ if (def_str) return 1;
-+ else return 0;
- }
-
--
-diff -ru xv-3.10a/xv.h xv-3.10a-enhancements/xv.h
---- xv-3.10a/xv.h 1995-01-23 12:22:23.000000000 -0800
-+++ xv-3.10a-enhancements/xv.h 2007-05-20 21:26:40.000000000 -0700
-@@ -1,6 +1,6 @@
- /*
- * xv.h - header file for xv, but you probably guessed as much
-- *
-+ *
- * Author: John Bradley (bradley@cis.upenn.edu)
- */
-
-@@ -8,8 +8,16 @@
- #include "config.h"
-
-
--#define REVDATE "Version 3.10a Rev: 12/29/94"
--#define VERSTR "3.10a"
-+/* xv 3.10a: 19941229 */
-+/* PNG patch 1.2d: 19960731 */
-+/* GRR orig jumbo fixes patch: 20000213 */
-+/* GRR orig jumbo enhancements patch: 20000220 */
-+/* GRR 1st public jumbo F+E patches: 20040531 */
-+/* GRR 2nd public jumbo F+E patches: 20050410 */
-+/* GRR 3rd public jumbo F+E patches: 20050501 */
-+/* GRR 4th public jumbo F+E patch: 20070520 */
-+#define REVDATE "version 3.10a-jumboFix+Enh of 20070520"
-+#define VERSTR "3.10a-20070520"
-
- /*
- * uncomment the following, and modify for your site, but only if you've
-@@ -43,6 +51,10 @@
- /* START OF MACHINE-DEPENDENT CONFIGURATION INFO */
- /*************************************************/
-
-+
-+#define ENABLE_FIXPIX_SMOOTH /* GRR 19980607 */
-+
-+
- /* Things to make xv more likely to just build, without the user tweaking
- the makefile */
-
-@@ -61,16 +73,38 @@
- # define SVR4
- #endif
-
-+#if defined(__sony_news) && defined(bsd43) && !defined(__bsd43)
-+# define __bsd43
-+#elif defined(__sony_news) && (defined(SYSTYPE_BSD) || defined(__SYSTYPE_BSD)) && !defined(bsd43) && !defined(__bsd43)
-+# define bsd43
-+# define __bsd43
-+#endif
-+
-+#include /* for interrupt handling */
-+
-+/* at least on Linux, the following file (1) includes sys/types.h and
-+ * (2) defines __USE_BSD (which was not defined before here), so __linux__
-+ * block is now moved after this #include */
-+#include /* need type declarations immediately */
-+
-
--#ifdef LINUX
-+#ifdef __linux__
- # ifndef _LINUX_LIMITS_H
- # include
- # endif
-+# ifndef USLEEP
-+# define USLEEP
-+# endif
-+ /* want only one or the other defined, not both: */
-+# if !defined(BSDTYPES) && !defined(__USE_BSD)
-+# define BSDTYPES
-+# endif
-+# if defined(BSDTYPES) && defined(__USE_BSD)
-+# undef BSDTYPES
-+# endif
- #endif
-
-
--#include /* need type declarations immediately */
--
- /*********************************************************/
-
-
-@@ -99,6 +133,16 @@
- #endif
-
-
-+#if defined(__sony_news) && defined(__bsd43)
-+# include
-+#endif
-+
-+
-+#if defined(__FreeBSD__)
-+# include
-+#endif
-+
-+
- /* include files */
- #include
- #include
-@@ -114,18 +158,24 @@
-
- #ifndef VMS
- # include
-- extern int errno; /* SHOULD be in errno.h, but often isn't */
- # ifndef __NetBSD__
-- extern char *sys_errlist[]; /* this too... */
-+# if !(defined __GLIBC__ && __GLIBC__ >= 2)
-+ extern int errno; /* SHOULD be in errno.h, but often isn't */
-+ extern char *sys_errlist[]; /* this too... */
-+# endif
- # endif
- #endif
-
-
- /* not everyone has the strerror() function, or so I'm told */
--#ifndef VMS
--# define ERRSTR(x) sys_errlist[x]
--#else
-+#ifdef VMS
- # define ERRSTR(x) strerror(x, vaxc$errno)
-+#else
-+# if defined(__BEOS__) || defined(__linux__) /* or all modern/glibc systems? */
-+# define ERRSTR(x) strerror(x)
-+# else
-+# define ERRSTR(x) sys_errlist[x]
-+# endif
- #endif
-
-
-@@ -146,28 +196,20 @@
- #endif
-
-
--/* lots of things don't have */
--/* A/UX systems include it from stdlib, from Xos.h */
--#ifndef VMS /* VMS hates multi-line '#if's */
--# if !defined(ibm032) && \
-- !defined(__convex__) && \
-- !(defined(vax) && !defined(ultrix)) && \
-- !defined(mips) && \
-- !defined(apollo) && \
-- !defined(pyr) && \
-- !defined(__UMAXV__) && \
-- !defined(bsd43) && \
-- !defined(aux) && \
-- !defined(__bsdi__) && \
-- !defined(sequent)
--
-+/* GRR 20070512: Very few modern systems even have a malloc.h anymore;
-+ * stdlib.h is, well, the standard. (Former explicitly listed
-+ * "don't include" systems: ibm032, __convex__, non-ultrix vax,
-+ * mips, apollo, pyr, sequent, __UMAXV__, aux, bsd43, __bsd43,
-+ * __bsdi__, __386BSD__, __FreeBSD__, __OpenBSD__, __NetBSD__,
-+ * __DARWIN__, VMS.) Anyone who _does_ need it can explicitly
-+ * define NEED_MALLOC_H in the makefile. */
-+#ifdef NEED_MALLOC_H
- # if defined(hp300) || defined(hp800) || defined(NeXT)
--# include /* it's in 'sys' on HPs and NeXT */
-+# include /* it's in "sys" on HPs and NeXT */
- # else
--# include
-+# include
- # endif
--# endif
--#endif /* !VMS */
-+#endif
-
-
-
-@@ -179,9 +221,10 @@
- #include
- #include
-
-+#ifdef TV_L10N
-+# include
-+#endif
-
--#undef SIGCHLD /* defined in both Xos.h and signal.h */
--#include /* for interrupt handling */
-
- #include
-
-@@ -205,6 +248,10 @@
- # include
- # endif
-
-+# ifdef __BEOS__
-+# include
-+# endif
-+
- /*** for select() call ***/
- # ifdef __hpux
- # define XV_FDTYPE (int *)
-@@ -259,7 +306,7 @@
- * make them if missing, along with a few fictitious ones
- * Cameron Simpson (cameron@cse.unsw.edu.au)
- */
--
-+
- #ifndef S_ISDIR /* missing POSIX-type macros */
- # define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
- # define S_ISBLK(mode) (((mode)&S_IFMT) == S_IFBLK)
-@@ -288,7 +335,9 @@
- # endif
- #endif
-
--
-+#ifndef S_IRWUSR
-+# define S_IRWUSR (S_IRUSR|S_IWUSR) /* or (S_IREAD|S_IWRITE) */
-+#endif
-
- #ifndef MAXPATHLEN
- # define MAXPATHLEN 256
-@@ -308,36 +357,90 @@
-
- #ifndef VMS /* VMS hates multi-line definitions */
- # if defined(SVR4) || defined(SYSV) || defined(sco) || \
-- defined(XENIX) || defined(__osf__)
-+ defined(XENIX) || defined(__osf__) || defined(__linux__)
- # undef USE_GETCWD
- # define USE_GETCWD /* use 'getcwd()' instead of 'getwd()' */
-+# endif /* >> SECURITY ISSUE << */
-+#endif
-+
-+
-+/* GRR 20040430: This is new and still not fully deployed. No doubt there
-+ * are other systems that have mkstemp() (SUSv3); we can add
-+ * them later. */
-+#ifndef VMS /* VMS hates multi-line definitions */
-+# if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
-+ defined(__bsdi__)
-+# ifndef USE_MKSTEMP
-+# define USE_MKSTEMP /* use 'mkstemp()' instead of 'mktemp()' */
-+# endif /* >> SECURITY ISSUE << */
- # endif
- #endif
-
-
-+/* GRR 20040503: This is new and so far tested only under Linux. But it
-+ * allows -wait to work with subsecond values as long as
-+ * times() exists and clock_t is a long int (latter matters
-+ * only if/when clocks wrap, which for Linux is multiples of
-+ * 497.11 days since the last reboot). */
-+#if defined(__linux__)
-+# define USE_TICKS /* use times()/Timer(), not time()/sleep() */
-+# include /* LONG_MAX (really want CLOCK_T_MAX) */
-+# include /* times() */
-+# ifndef CLK_TCK /* can be undefined in strict-ANSI mode */
-+# define CLK_TCK CLOCKS_PER_SEC /* claimed to be same thing in time.h */
-+# endif
-+#endif
-+
-+#if (defined(SYSV) || defined(SVR4) || defined(linux)) && !defined(USE_GETCWD)
-+# define USE_GETCWD
-+#endif
-+
-+#ifndef SEEK_SET
-+# define SEEK_SET 0
-+# define SEEK_CUR 1
-+# define SEEK_END 2
-+#endif
-+
-+#if defined(__mips) && defined(__SYSTYPE_BSD43)
-+# define strstr(A,B) pds_strstr((A),(B))
-+# undef S_IFIFO
-+#endif /* !mips_bsd */
-+
- /*****************************/
- /* END OF CONFIGURATION INFO */
- /*****************************/
-
-+
- #ifdef DOJPEG
--#define HAVE_JPEG
-+# define HAVE_JPEG
-+#endif
-+
-+#ifdef DOJP2K
-+# define HAVE_JP2K
- #endif
-
- #ifdef DOTIFF
--#define HAVE_TIFF
-+# define HAVE_TIFF
-+#endif
-+
-+#ifdef DOPNG
-+# define HAVE_PNG
- #endif
-
- #ifdef DOPDS
--#define HAVE_PDS
-+# define HAVE_PDS
- #endif
-
-+#ifdef DOG3
-+# define HAVE_G3
-+#endif
-
-
--#define PROGNAME "xv" /* used in resource database */
-+#define PROGNAME "xv" /* used in resource database */
-
--#define MAXNAMES 4096 /* max # of files in ctrlW list */
-+#define MAXNAMES 65536 /* max # of files in ctrlW list */
-
--#define MAXBRWIN 4 /* max # of vis browser windows */
-+#define MAXBRWIN 16 /* max # of vis browser windows */
-
- /* strings in the INFOBOX (used in SetISTR and GetISTR) */
- #define NISTR 10 /* number of ISTRs */
-@@ -432,7 +535,7 @@
- #define F_COLORS 0
- #define F_FORMAT 1
-
--/* the following list give indicies into saveColors[] array in xvdir.c */
-+/* the following list give indices into saveColors[] array in xvdir.c */
- #define F_FULLCOLOR 0
- #define F_GREYSCALE 1
- #define F_BWDITHER 2
-@@ -440,49 +543,115 @@
- #define F_MAXCOLORS 4 /* length of saveColors[] array */
-
-
--/* following list gives indicies into 'saveFormats[]' array in xvdir.c
-- note that JPEG and TIFF entries may or may not exist, and following
-- constants have to be adjusted accordingly. Also, don't worry about
-- duplicate cases if JPGINC or TIFINC = 0. All code that references
-- F_JPEG or F_TIFF is #ifdef'd, so it won't be a problem */
-+/* The following list gives indices into 'saveFormats[]' array in xvdir.c.
-+ Note that JPEG, TIFF, and other entries may or may not exist, so the
-+ following constants have to be adjusted accordingly. Also, don't worry
-+ about duplicate cases if, e.g., JPGINC or TIFINC = 0. All code that
-+ references F_JPEG, F_TIFF, etc., is #ifdef'd, so it won't be a problem. */
-
- #ifdef HAVE_JPEG
--#define F_JPGINC 1
-+# define F_JPGINC 1
- #else
--#define F_JPGINC 0
-+# define F_JPGINC 0
-+#endif
-+
-+#ifdef HAVE_JP2K
-+# define F_JP2INC 1 /* provides both JPC and JP2 */
-+#else
-+# define F_JP2INC 0
- #endif
-
- #ifdef HAVE_TIFF
--#define F_TIFINC 1
-+# define F_TIFINC 1
-+#else
-+# define F_TIFINC 0
-+#endif
-+
-+#ifdef HAVE_PNG
-+# define F_PNGINC 1
-+#else
-+# define F_PNGINC 0
-+#endif
-+
-+#ifdef HAVE_MAG
-+# define F_MAGINC 1
-+#else
-+# define F_MAGINC 0
-+#endif
-+
-+#ifdef HAVE_PIC
-+# define F_PICINC 1
-+#else
-+# define F_PICINC 0
-+#endif
-+
-+#ifdef HAVE_MAKI
-+# define F_MAKINC 1
-+#else
-+# define F_MAKINC 0
-+#endif
-+
-+#ifdef HAVE_PI
-+# define F_PAIINC 1
-+#else
-+# define F_PAIINC 0
-+#endif
-+
-+#ifdef HAVE_PIC2
-+# define F_PC2INC 1
- #else
--#define F_TIFINC 0
-+# define F_PC2INC 0
- #endif
-
-+#ifdef HAVE_MGCSFX
-+# define F_MGCSFXINC 1
-+#else
-+# define F_MGCSFXINC 0
-+#endif
-
--#define F_GIF 0
--#define F_JPEG ( 0 + F_JPGINC)
--#define F_TIFF ( 0 + F_JPGINC + F_TIFINC)
--#define F_PS ( 1 + F_JPGINC + F_TIFINC)
--#define F_PBMRAW ( 2 + F_JPGINC + F_TIFINC)
--#define F_PBMASCII ( 3 + F_JPGINC + F_TIFINC)
--#define F_XBM ( 4 + F_JPGINC + F_TIFINC)
--#define F_XPM ( 5 + F_JPGINC + F_TIFINC)
--#define F_BMP ( 6 + F_JPGINC + F_TIFINC)
--#define F_SUNRAS ( 7 + F_JPGINC + F_TIFINC)
--#define F_IRIS ( 8 + F_JPGINC + F_TIFINC)
--#define F_TARGA ( 9 + F_JPGINC + F_TIFINC)
--#define F_FITS (10 + F_JPGINC + F_TIFINC)
--#define F_PM (11 + F_JPGINC + F_TIFINC)
--#define F_DELIM1 (12 + F_JPGINC + F_TIFINC) /* ----- */
--#define F_FILELIST (13 + F_JPGINC + F_TIFINC)
--#define F_MAXFMTS (14 + F_JPGINC + F_TIFINC) /* 15, normally */
-+#ifdef MACBINARY
-+# define MACBSIZE 128
-+#endif
-+
-+/* NOTE: order must match saveFormats[] in xvdir.c */
-+/* [this works best when first one is always present, but...we like PNG :-) ] */
-+#define F_PNG 0
-+#define F_JPEG ( 0 + F_PNGINC)
-+#define F_JPC ( 0 + F_PNGINC + F_JPGINC)
-+#define F_JP2 ( 0 + F_PNGINC + F_JPGINC + F_JP2INC)
-+#define F_GIF ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC) /* always avail; index varies */
-+#define F_TIFF ( 0 + F_PNGINC + F_JPGINC + F_JP2INC + F_JP2INC + F_TIFINC)
-+#define F_PS ( 1 + F_TIFF)
-+#define F_PBMRAW ( 2 + F_TIFF)
-+#define F_PBMASCII ( 3 + F_TIFF)
-+#define F_XBM ( 4 + F_TIFF)
-+#define F_XPM ( 5 + F_TIFF)
-+#define F_BMP ( 6 + F_TIFF)
-+#define F_SUNRAS ( 7 + F_TIFF)
-+#define F_IRIS ( 8 + F_TIFF)
-+#define F_TARGA ( 9 + F_TIFF)
-+#define F_FITS (10 + F_TIFF)
-+#define F_PM (11 + F_TIFF)
-+#define F_ZX (12 + F_TIFF) /* [JCE] */
-+#define F_WBMP (13 + F_TIFF)
-+#define JP_EXT_F (F_WBMP)
-+#define F_MAG (JP_EXT_F + F_MAGINC)
-+#define F_PIC (JP_EXT_F + F_MAGINC + F_PICINC)
-+#define F_MAKI (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC)
-+#define F_PI (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC + F_PAIINC)
-+#define F_PIC2 (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC + F_PAIINC + F_PC2INC)
-+#define F_MGCSFX (JP_EXT_F + F_MAGINC + F_PICINC + F_MAKINC + F_PAIINC + F_PC2INC + F_MGCSFXINC)
-+#define JP_EXT_F_END (F_MGCSFX)
-+#define F_DELIM1 (JP_EXT_F_END + 1) /* ----- */
-+#define F_FILELIST (JP_EXT_F_END + 2)
-+#define F_MAXFMTS (JP_EXT_F_END + 3) /* 27, normally (with all formats) */
-
-
-
- /* return values from ReadFileType()
- * positive values are *definitely* readable formats (HAVE_*** is defined)
- * negative values are random files that XV can't read, but display as
-- * different icons in the visual browser
-+ * different icons in the visual browser
- */
- #define RFT_ERROR -1 /* couldn't open file, or whatever... */
- #define RFT_UNKNOWN 0
-@@ -505,6 +674,22 @@
- #define RFT_XPM 17
- #define RFT_XWD 18
- #define RFT_FITS 19
-+#define RFT_PNG 20
-+#define RFT_ZX 21 /* [JCE] */
-+#define RFT_WBMP 22
-+#define RFT_PCD 23
-+#define RFT_HIPS 24
-+#define RFT_BZIP2 25
-+#define RFT_JPC 26
-+#define RFT_JP2 27
-+#define RFT_G3 28
-+#define JP_EXT_RFT (RFT_G3)
-+#define RFT_MAG (JP_EXT_RFT + 1)
-+#define RFT_MAKI (JP_EXT_RFT + 2)
-+#define RFT_PIC (JP_EXT_RFT + 3)
-+#define RFT_PI (JP_EXT_RFT + 4)
-+#define RFT_PIC2 (JP_EXT_RFT + 5)
-+#define RFT_MGCSFX (JP_EXT_RFT + 6)
-
- /* definitions for page up/down, arrow up/down list control */
- #define LS_PAGEUP 0
-@@ -563,7 +748,8 @@
- #define RM_CBRICK 7 /* centered on a 'brick' bg */
- #define RM_ECENTER 8 /* symmetrical tiled */
- #define RM_ECMIRR 9 /* symmetrical mirror tiled */
--#define RM_MAX RM_ECMIRR
-+#define RM_UPLEFT 10 /* just in upper left corner */
-+#define RM_MAX RM_UPLEFT
-
-
- /* values of colorMapMode */
-@@ -613,10 +799,11 @@
- #define RMB_CBRICK 8
- #define RMB_ECENTER 9
- #define RMB_ECMIRR 10
--#define RMB_MAX 11
-+#define RMB_UPLEFT 11
-+#define RMB_MAX 12
-
-
--/* indicies into conv24MB */
-+/* indices into conv24MB */
- #define CONV24_8BIT 0
- #define CONV24_24BIT 1
- #define CONV24_SEP1 2
-@@ -631,7 +818,7 @@
- #define PIC8 CONV24_8BIT
- #define PIC24 CONV24_24BIT
-
--/* indicies into algMB */
-+/* indices into algMB */
- #define ALG_NONE 0
- #define ALG_SEP1 1 /* separator */
- #define ALG_BLUR 2
-@@ -648,7 +835,7 @@
- #define ALG_MAX 13
-
-
--/* indicies into sizeMB */
-+/* indices into sizeMB */
- #define SZMB_NORM 0
- #define SZMB_MAXPIC 1
- #define SZMB_MAXPECT 2
-@@ -663,7 +850,7 @@
- #define SZMB_INTEXP 11
- #define SZMB_MAX 12
-
--/* indicies into windowMB */
-+/* indices into windowMB */
- #define WMB_BROWSE 0
- #define WMB_COLEDIT 1
- #define WMB_INFO 2
-@@ -742,15 +929,15 @@
-
- typedef unsigned char byte;
-
--typedef struct scrl {
-+typedef struct scrl {
- Window win; /* window ID */
- int x,y,w,h; /* window coords in parent */
- int len; /* length of major axis */
- int vert; /* true if vertical, else horizontal */
- int active; /* true if scroll bar can do anything*/
-- int min,max; /* min/max values 'pos' can take */
-- int val; /* 'value' of scrollbar */
-- int page; /* amt val change on pageup/pagedown */
-+ double min,max; /* min/max values 'pos' can take */
-+ double val; /* 'value' of scrollbar */
-+ double page; /* amt val change on pageup/pagedown */
- int tpos; /* thumb pos. (pixels from tmin) */
- int tmin,tmax; /* min/max thumb offsets (from 0,0) */
- int tsize; /* size of thumb (in pixels) */
-@@ -765,11 +952,12 @@
- typedef struct { Window win; /* window ID */
- int x,y,w,h; /* window coords in parent */
- int active; /* true if can do anything*/
-- int min,max; /* min/max values 'pos' can take */
-- int val; /* 'value' of dial */
-- int page; /* amt val change on pageup/pagedown */
-- char *title; /* title for this guage */
-- char *units; /* string appended to value */
-+ double min,max; /* min/max values 'pos' can take */
-+ double val; /* 'value' of dial */
-+ double inc; /* amt val change on up/down */
-+ double page; /* amt val change on pageup/pagedown */
-+ const char *title; /* title for this gauge */
-+ const char *units; /* string appended to value */
- u_long fg,bg,hi,lo; /* colors */
- int rad, cx, cy; /* internals */
- int bx[4], by[4]; /* more internals */
-@@ -785,7 +973,7 @@
- int active; /* if false, stipple gray */
- int toggle; /* if true, clicking toggles state */
- u_long fg,bg,hi,lo; /* colors */
-- char *str; /* string in button */
-+ const char *str; /* string in button */
- Pixmap pix; /* use pixmap instead of string */
- u_int pw,ph; /* size of pixmap */
- int colorpix; /* multi-color pixmap */
-@@ -797,21 +985,23 @@
- typedef struct rbutt {
- Window win; /* parent window */
- int x,y; /* position in parent */
-- char *str; /* the message string */
-+ const char *str; /* the message string */
- int selected; /* selected or not */
- int active; /* selectable? */
- struct rbutt *next; /* pointer to next in group */
-- u_long fg,bg,hi,lo; /* colors */
-+ u_long fg,bg; /* colors */
-+ u_long hi,lo; /* colors */
- } RBUTT;
-
-
-
- typedef struct { Window win; /* parent window */
- int x,y; /* position in parent */
-- char *str; /* the message string */
-+ const char *str; /* the message string */
- int val; /* 1=selected, 0=not */
- int active; /* selectable? */
-- u_long fg,bg,hi,lo; /* colors */
-+ u_long fg,bg; /* colors */
-+ u_long hi,lo; /* colors */
- } CBUTT;
-
-
-@@ -819,11 +1009,11 @@
- typedef struct { Window win; /* parent window */
- int x,y; /* position in parent */
- unsigned int w,h;
-- char *title; /* title string in norm state */
-+ const char *title; /* title string in norm state */
- int active; /* selectable? */
-- char **list; /* list of strings in menu */
-+ const char **list; /* list of strings in menu */
- int nlist; /* # of strings in menu */
-- byte flags[MAXMBLEN]; /* checkmarks on items */
-+ byte flags[MAXMBLEN]; /* checkmarks on items */
- int hascheck; /* leave room for checkmark? */
- byte dim[MAXMBLEN]; /* dim individual choices */
- Pixmap pix; /* use pixmap instd of string */
-@@ -833,17 +1023,18 @@
- } MBUTT;
-
-
--typedef struct { Window win; /* window */
-- int x,y; /* size of window */
-+typedef struct { Window win; /* window */
-+ int x,y; /* size of window */
- unsigned int w,h;
-- u_long fg,bg,hi,lo; /* colors */
-- char **str; /* ptr to list of strings */
-- int nstr; /* number of strings */
-- int selected; /* number of 'selected' string */
-- int nlines; /* number of lines shown at once */
-- SCRL scrl; /* scrollbar that controls list */
-- int filetypes; /* true if filetype icons to be drawn*/
-- int dirsonly; /* if true, only dirs selectable */
-+ u_long fg,bg; /* colors */
-+ u_long hi,lo; /* colors */
-+ /* const? */ char **str; /* ptr to list of strings */
-+ int nstr; /* number of strings */
-+ int selected; /* number of 'selected' string */
-+ int nlines; /* number of lines shown at once */
-+ SCRL scrl; /* scrollbar that controls list */
-+ int filetypes; /* true if filetype icons to be drawn*/
-+ int dirsonly; /* if true, only dirs selectable */
- } LIST;
-
-
-@@ -865,6 +1056,9 @@
- char shrtInfo[128]; /* short format info */
- char *comment; /* comment text */
-
-+ byte *exifInfo; /* image info from digicam */
-+ int exifInfoSize; /* size of image info */
-+
- int numpages; /* # of page files, if >1 */
- char pagebname[64]; /* basename of page files */
- } PICINFO;
-@@ -881,18 +1075,18 @@
-
- #define GVMAX 8
-
--typedef struct { Window win; /* window ID */
-- Window gwin; /* graph subwindow */
-- int spline; /* spline curve or lines? */
-- int entergamma; /* currently entering gamma value */
-- int gammamode; /* currently using gamma function */
-- double gamma; /* gamma value (if gammamode) */
-- int nhands; /* current # of handles */
-- XPoint hands[MAX_GHANDS]; /* positions of handles */
-- byte func[256]; /* output function of GRAF */
-- BUTT butts[N_GFB]; /* control buttons */
-- u_long fg,bg; /* colors */
-- char *str; /* title string */
-+typedef struct { Window win; /* window ID */
-+ Window gwin; /* graph subwindow */
-+ int spline; /* spline curve or lines? */
-+ int entergamma; /* currently entering gamma value */
-+ int gammamode; /* currently using gamma function */
-+ double gamma; /* gamma value (if gammamode) */
-+ int nhands; /* current # of handles */
-+ XPoint hands[MAX_GHANDS]; /* positions of handles */
-+ byte func[256]; /* output function of GRAF */
-+ BUTT butts[N_GFB]; /* control buttons */
-+ u_long fg,bg; /* colors */
-+ const char *str; /* title string */
- char gvstr[GVMAX+1]; /* gamma value input string */
- void (*drawobj)PARM((void));
- } GRAF;
-@@ -932,18 +1126,23 @@
- /* X stuff */
- WHERE Display *theDisp;
- WHERE int theScreen;
--WHERE unsigned int ncells, dispWIDE, dispHIGH, dispDEEP;
--WHERE unsigned int vrWIDE, vrHIGH, maxWIDE, maxHIGH;
-+WHERE unsigned int ncells, dispDEEP; /* root color sizes */
-+WHERE unsigned int dispWIDE, dispHIGH; /* screen sizes */
-+WHERE unsigned int vrWIDE, vrHIGH, maxWIDE, maxHIGH; /* virtual root and max image sizes */
- WHERE Colormap theCmap, LocalCmap;
--WHERE Window rootW, mainW, vrootW;
-+WHERE Window spec_window, rootW, mainW, vrootW;
- WHERE GC theGC;
- WHERE u_long black, white, fg, bg, infofg, infobg;
- WHERE u_long hicol, locol;
- WHERE u_long blkRGB, whtRGB;
- WHERE Font mfont, monofont;
- WHERE XFontStruct *mfinfo, *monofinfo;
-+#ifdef TV_L10N
-+WHERE XFontSet monofset;
-+WHERE XFontSetExtents *monofsetinfo;
-+#endif
- WHERE Visual *theVisual;
--WHERE Cursor arrow, cross, tcross, zoom, inviso;
-+WHERE Cursor arrow, cross, tcross, zoom, inviso, tlcorner;
- WHERE Pixmap iconPix, iconmask;
- WHERE Pixmap riconPix, riconmask;
- WHERE int showzoomcursor;
-@@ -959,6 +1158,12 @@
- WHERE char formatStr[80]; /* short-form 'file format' */
- WHERE int picType; /* CONV24_8BIT,CONV24_24BIT,etc.*/
- WHERE char *picComments; /* text comments on current pic */
-+WHERE byte *picExifInfo; /* image info from digicam */
-+WHERE int picExifInfoSize; /* size of image info */
-+
-+#ifdef TV_L10N
-+WHERE int xlocale; /* true if Xlib supports locale */
-+#endif
-
- WHERE int numPages, curPage; /* for multi-page files */
- WHERE char pageBaseName[64]; /* basename for multi-page files */
-@@ -972,12 +1177,12 @@
- /* this is converted to 'theImage' */
- WHERE int eWIDE, eHIGH; /* size of epic */
-
--WHERE byte *egampic; /* expanded, gammified cpic
-+WHERE byte *egampic; /* expanded, gammified cpic
- (only used in 24-bit mode) */
-
- WHERE int p_offx, p_offy; /* offset of reparented windows */
- WHERE int ch_offx,ch_offy; /* ChngAttr ofst for reparented windows */
--WHERE int kludge_offx, /* WM kludges for SetWindowPos routine */
-+WHERE int kludge_offx, /* WM kludges for SetWindowPos routine */
- kludge_offy;
- WHERE int winCtrPosKludge; /* kludge for popup positioning... */
-
-@@ -993,6 +1198,26 @@
- WHERE unsigned long cols[256]; /* maps pic pixel values to X pixel vals */
- WHERE int fc2pcol[256]; /* maps freecols into pic pixel values */
- WHERE int numcols; /* # of desired colors in picture */
-+#ifdef MACBINARY
-+WHERE char macb_file; /* True if this file type is MacBinary */
-+WHERE int handlemacb; /* True if we want to handle MacBinary */
-+#endif
-+#if defined(HAVE_PIC) || defined(HAVE_PIC2)
-+WHERE int nopicadjust; /* True if we don't want to adjust aspect */
-+#endif
-+#ifdef HAVE_PIC2
-+WHERE int pic2split; /* True if we want to split multiblocks */
-+#endif
-+#ifdef VS_ADJUST
-+WHERE int vsadjust; /* True if we want to adjust aspect of icons */
-+#endif
-+#ifdef HAVE_MGCSFX
-+WHERE int mgcsfx; /* True if we want to force use MgcSfx */
-+WHERE int nomgcsfx; /* True if we don't want to use MgcSfx */
-+#endif
-+
-+#define FSTRMAX 12 /* Number of function keys to support. */
-+WHERE char *fkeycmds[FSTRMAX]; /* command to run when F# is pressed */
-
- /* Std Cmap stuff */
- WHERE byte stdr[256], stdg[256], stdb[256]; /* std 3/3/2 cmap */
-@@ -1025,7 +1250,7 @@
-
- WHERE int ncols; /* max # of (different) colors to alloc */
-
--WHERE char str[128]; /* dummy string used for error messages */
-+WHERE char dummystr[128]; /* dummy string used for error messages */
- WHERE char initdir[MAXPATHLEN]; /* cwd when xv was started */
- WHERE char searchdir[MAXPATHLEN]; /* '-dir' option */
- WHERE char fullfname[MAXPATHLEN]; /* full name of current file */
-@@ -1047,42 +1272,47 @@
- noFreeCols, /* don't free colors when loading new pic */
- autoquit, /* quit in '-root' or when click on win */
- xerrcode, /* errorcode of last X error */
-- grabDelay; /* # of seconds to sleep at start of Grab */
-+ grabDelay, /* # of seconds to sleep at start of Grab */
-+ startGrab; /* start immediate grab ? */
-
- WHERE int state824; /* displays warning when going 8->24 */
-
- WHERE float defaspect, /* default aspect ratio to use */
- normaspect; /* normal aspect ratio of this picture */
-
--WHERE unsigned long rootbg, rootfg; /* fg/bg for root border */
--WHERE int waitsec; /* secs btwn pics. -1=wait for event */
--WHERE int waitloop; /* loop at end of slide show? */
--WHERE int automax; /* maximize pic on open */
--WHERE int rootMode; /* mode used for -root images */
-+WHERE u_long rootbg, rootfg; /* fg/bg for root border */
-+WHERE u_short imagebgR;
-+WHERE u_short imagebgG; /* GRR 19980308: bg for transpar. images */
-+WHERE u_short imagebgB;
-+WHERE int have_imagebg;
-+WHERE double waitsec; /* secs btwn pics. -1.0=wait for event */
-+WHERE int waitloop; /* loop at end of slide show? */
-+WHERE int automax; /* maximize pic on open */
-+WHERE int rootMode; /* mode used for -root images */
-
--WHERE int nostat; /* if true, don't stat() in LdCurDir */
-+WHERE int nostat; /* if true, don't stat() in LdCurDir */
-
--WHERE int ctrlColor; /* whether or not to use colored butts */
-+WHERE int ctrlColor; /* whether or not to use colored butts */
-
--WHERE char *def_str; /* used by rd_*() routines */
-+WHERE char *def_str; /* used by rd_*() routines */
- WHERE int def_int;
--WHERE char *tmpdir; /* equal to "/tmp" or $TMPDIR env var */
--WHERE Pixmap gray25Tile, /* used for 3d effect on 1-bit disp's */
-+WHERE char *tmpdir; /* equal to "/tmp" or $TMPDIR env var */
-+WHERE Pixmap gray25Tile, /* used for 3d effect on 1-bit disp's */
- gray50Tile;
--WHERE int autoDelete; /* delete cmd-line files on exit? */
-+WHERE int autoDelete; /* delete cmd-line files on exit? */
-
- #define PRINTCMDLEN 256
--WHERE char printCmd[PRINTCMDLEN];
-+WHERE char printCmd[PRINTCMDLEN];
-
- /* stuff used for 'info' box */
- WHERE Window infoW;
--WHERE int infoUp; /* boolean: whether infobox is visible */
-+WHERE int infoUp; /* boolean: whether infobox is visible */
- WHERE int infoMode;
-
-
- /* stuff used for 'ctrl' box */
- WHERE Window ctrlW;
--WHERE int ctrlUp; /* boolean: whether ctrlbox is visible */
-+WHERE int ctrlUp; /* boolean: whether ctrlbox is visible */
- WHERE char *namelist[MAXNAMES]; /* list of file names from argv */
- WHERE char *origlist[MAXNAMES]; /* only names from argv (autoDelete)*/
- WHERE int orignumnames;
-@@ -1121,25 +1351,31 @@
-
-
- /* stuff used for 'browse' box */
--WHERE int anyBrowUp; /* whether *any* browser visible */
-+WHERE int anyBrowUp; /* whether *any* browser visible */
-+WHERE int incrementalSearchTimeout;
-
- /* stuff used for textview windows */
--WHERE int anyTextUp; /* are any text windows visible? */
--WHERE int commentUp; /* comment window up? */
-+WHERE int anyTextUp; /* are any text windows visible? */
-+WHERE int commentUp; /* comment window up? */
-
- /* stuff used for xvcut.c */
--WHERE int forceClipFile; /* don't use property clipboard */
--WHERE int clearR, clearG, clearB; /* clear color in 24-bit mode */
-+WHERE int forceClipFile; /* don't use property clipboard */
-+WHERE int clearR, clearG, clearB; /* clear color in 24-bit mode */
-
-
- /* stuff used for 'ps' box */
- WHERE Window psW;
--WHERE int psUp; /* is psW mapped, or what? */
--WHERE CBUTT encapsCB, pscompCB;
--WHERE char *gsDev, *gsGeomStr;
-+WHERE int psUp; /* is psW mapped, or what? */
-+WHERE CBUTT encapsCB, pscompCB;
-+WHERE const char *gsDev, *gsGeomStr;
- WHERE int gsRes;
-
-
-+/* stuff used for 'pcd' box */
-+WHERE Window pcdW;
-+WHERE int pcdUp; /* is pcdW mapped, or what? */
-+
-+
- #ifdef HAVE_JPEG
- /* stuff used for 'jpeg' box */
- WHERE Window jpegW;
-@@ -1147,6 +1383,13 @@
- #endif
-
-
-+#ifdef HAVE_JP2K
-+/* stuff used for 'jp2k' box */
-+WHERE Window jp2kW;
-+WHERE int jp2kUp; /* is jp2kW mapped, or what? */
-+#endif
-+
-+
- #ifdef HAVE_TIFF
- /* stuff used for 'tiff' box */
- WHERE Window tiffW;
-@@ -1154,6 +1397,91 @@
- #endif
-
-
-+#ifdef HAVE_PNG
-+/* stuff used for 'png' box */
-+WHERE Window pngW;
-+WHERE int pngUp; /* is pngW mapped, or what? */
-+#endif
-+
-+
-+#ifdef ENABLE_FIXPIX_SMOOTH
-+WHERE int do_fixpix_smooth; /* GRR 19980607: runtime FS dithering */
-+#endif
-+
-+#ifdef HAVE_PIC2
-+/* stuff used for 'pic2' box */
-+WHERE Window pic2W;
-+WHERE int pic2Up; /* is pic2W mapped, or what? */
-+#endif /* HAVE_PIC2 */
-+
-+#ifdef HAVE_PCD
-+/* stuff used for 'pcd' box */
-+WHERE Window pcdW;
-+WHERE int pcdUp; /* is pcdW mapped, or what? */
-+#endif /* HAVE_PCD */
-+
-+#ifdef HAVE_MGCSFX
-+/* stuff used for 'mgcsfx' box */
-+WHERE Window mgcsfxW;
-+WHERE Window mgcsfxNameW;
-+WHERE int mgcsfxUp; /* is mgcsfxW mapped, or what? */
-+#endif /* HAVE_MGCSFX */
-+
-+#ifdef TV_L10N
-+/* stuff used for TextViewer Japanization */
-+# define LOCALE_USASCII 0
-+# define LOCALE_EUCJ 1
-+# define LOCALE_JIS 2
-+# define LOCALE_MSCODE 3
-+
-+# ifndef LOCALE_DEFAULT
-+# define LOCALE_DEFAULT 0
-+# endif /* !LOCALE_DEFAULT */
-+
-+# ifndef MAIN
-+ extern char *localeList[];
-+# else
-+# ifndef LOCALE_NAME_EUC
-+# ifndef X_LOCALE
-+# if defined(__FreeBSD__)
-+ char *localeList[] = {"", "ja_JP.EUC", "none", "none"};
-+# elif defined(__linux__)
-+ char *localeList[] = {"", "ja_JP.eucJP", "none", "ja_JP.SJIS"};
-+# elif defined(__sun) || defined(sun)
-+ char *localeList[] = {"", "ja", "none", "none"};
-+# elif defined(__sgi) /* sgi, __sgi, __sgi__ (gcc) */
-+ char *localeList[] = {"", "ja_JP.EUC", "none", "none"};
-+# elif defined(sony_news)
-+ char *localeList[] = {"", "ja_JP.EUC", "none", "ja_JP.SJIS"};
-+# elif defined(nec)
-+ char *localeList[] = {"", "japan", "none", "none"};
-+# elif defined(__hpux)
-+ char *localeList[] = {"", "japanese.euc", "none", "japanese"};
-+# elif defined(__osf__)
-+ char *localeList[] = {"", "ja_JP.deckanji", "none", "ja_JP.SJIS"};
-+# elif defined(_AIX)
-+ char *localeList[] = {"", "ja_JP", "none", "Ja_JP" };
-+# elif defined(__bsdi)
-+ char *localeList[] = {"", "Japanese-EUC", "none", "none" };
-+# else
-+ char *localeList[] = {"", "ja_JP.EUC", "ja_JP.JIS", "ja_JP.SJIS"};
-+# endif
-+# else
-+# if (XlibSpecificationRelease > 5)
-+ char *localeList[] = {"", "ja_JP.eucJP", "ja_JP.JIS7",
-+ "ja_JP.SJIS"};
-+# else
-+ char *localeList[] = {"", "ja_JP.ujis", "ja_JP.jis7",
-+ "ja_JP.mscode"};
-+# endif
-+# endif /* X_LOCALE */
-+# else
-+ char *localeList[] = {"", LOCALE_NAME_EUC,
-+ LOCALE_NAME_JIS, LOCALE_NAME_MSCODE};
-+# endif /* LOCALE_NAME_EUC */
-+# endif /* MAIN */
-+#endif /* TV_L10N */
-+
- #undef WHERE
-
-
-@@ -1161,172 +1489,115 @@
- /* function declarations for externally-callable functions */
-
- /****************************** XV.C ****************************/
--int ReadFileType PARM((char *));
--int ReadPicFile PARM((char *, int, PICINFO *, int));
--int UncompressFile PARM((char *, char *));
--void KillPageFiles PARM((char *, int));
--
--void NewPicGetColors PARM((int, int));
--void FixAspect PARM((int, int *, int *));
--void ActivePrevNext PARM((void));
--int DeleteCmd PARM((void));
--void StickInCtrlList PARM((int));
--void AddFNameToCtrlList PARM((char *, char *));
--void ChangedCtrlList PARM((void));
--void HandleDispMode PARM((void));
--char *lower_str PARM((char *));
--int rd_int PARM((char *));
--int rd_str PARM((char *));
--int rd_flag PARM((char *));
--int rd_str_cl PARM((char *, char *, int));
-+int ReadFileType PARM((char *));
-+int ReadPicFile PARM((char *, int, PICINFO *, int));
-+int UncompressFile PARM((char *, char *, int));
-+void KillPageFiles PARM((char *, int));
-+#ifdef MACBINARY
-+int RemoveMacbinary PARM((char *, char *));
-+#endif
-+
-+void NewPicGetColors PARM((int, int));
-+void FixAspect PARM((int, int *, int *));
-+void ActivePrevNext PARM((void));
-+int DeleteCmd PARM((void));
-+void StickInCtrlList PARM((int));
-+void AddFNameToCtrlList PARM((const char *, const char *));
-+void ChangedCtrlList PARM((void));
-+void HandleDispMode PARM((void));
-+char *lower_str PARM((char *));
-+int rd_int PARM((const char *));
-+int rd_str PARM((const char *));
-+int rd_flag PARM((const char *));
-
--/****************************** XVEVENT.C ****************************/
--int EventLoop PARM((void));
--int HandleEvent PARM((XEvent *, int *));
-
--void SelectDispMB PARM((int));
--void Select24to8MB PARM((int));
--void SelectRootMB PARM((int));
--void SelectWindowMB PARM((int));
--void SelectSizeMB PARM((int));
--
--void DoPrint PARM((void));
--void NewCutBuffer PARM((char *));
--void DrawWindow PARM((int,int,int,int));
--void WResize PARM((int, int));
--void WRotate PARM((void));
--void WCrop PARM((int, int, int, int));
--void WUnCrop PARM((void));
--void GetWindowPos PARM((XWindowAttributes *));
--void SetWindowPos PARM((XWindowAttributes *));
--void SetEpicMode PARM((void));
--int xvErrorHandler PARM((Display *, XErrorEvent *));
--
--/****************************** XVROOT.C ****************************/
--void MakeRootPic PARM((void));
--void ClearRoot PARM((void));
--void SaveRootInfo PARM((void));
--void KillOldRootInfo PARM((void));
-+/*************************** XV24TO8.C **************************/
-+void Init24to8 PARM((void));
-+byte *Conv24to8 PARM((byte *, int, int, int,
-+ byte *, byte *, byte *));
-
--/*************************** XVMISC.C ***************************/
--void StoreDeleteWindowProp PARM((Window));
--Window CreateWindow PARM((char *, char *, char *, int, int,
-- u_long, u_long, int));
--void DrawString PARM((Window, int, int, char *));
--void CenterString PARM((Window, int, int, char *));
--void ULineString PARM((Window, int, int, char *));
--int StringWidth PARM((char *));
--int CursorKey PARM((KeySym, int, int));
--void FakeButtonPress PARM((BUTT *));
--void FakeKeyPress PARM((Window, KeySym));
--void GenExpose PARM((Window, int, int, u_int, u_int));
--void DimRect PARM((Window, int, int, u_int, u_int, u_long));
--
--void Draw3dRect PARM((Window, int, int, u_int, u_int, int, int,
-- u_long, u_long, u_long));
--
--void RemapKeyCheck PARM((KeySym, char *, int *));
--void xvDestroyImage PARM((XImage *));
--void SetCropString PARM((void));
--void SetSelectionString PARM((void));
--void Warning PARM((void));
--void FatalError PARM((char *));
--void Quit PARM((int));
--void LoadFishCursors PARM((void));
--void WaitCursor PARM((void));
--void SetCursors PARM((int));
--char *BaseName PARM((char *));
--
--void DrawTempGauge PARM((Window, int, int, int, int, double,
-- u_long, u_long, u_long, u_long, char *));
--void ProgressMeter PARM((int, int, int, char *));
--void XVDeletedFile PARM((char *));
--void XVCreatedFile PARM((char *));
--void xvbcopy PARM((char *, char *, size_t));
--int xvbcmp PARM((char *, char *, size_t));
--void xvbzero PARM((char *, size_t));
--void xv_getwd PARM((char *, size_t));
--char *xv_strstr PARM((char *, char *));
--FILE *xv_fopen PARM((char *, char *));
--void Timer PARM((int));
-+byte *Conv8to24 PARM((byte *, int, int, byte *, byte *, byte *));
-
--/*************************** XVCOLOR.C ***************************/
--void SortColormap PARM((byte *, int, int, int *, byte*,byte*,byte*,
-- byte *, byte *));
--void ColorCompress8 PARM((byte *));
--void AllocColors PARM((void));
--Status xvAllocColor PARM((Display *, Colormap, XColor *));
--void xvFreeColors PARM((Display *, Colormap, u_long *, int, u_long));
--void FreeColors PARM((void));
--void ApplyEditColor PARM((int));
--int MakeStdCmaps PARM((void));
--void MakeBrowCmap PARM((void));
--void ChangeCmapMode PARM((int, int, int));
-
--/*************************** XVIMAGE.C ***************************/
--void Resize PARM((int, int));
--void GenerateCpic PARM((void));
--void GenerateEpic PARM((int, int));
--void DoZoom PARM((int, int, u_int));
--void Crop PARM((void));
--void UnCrop PARM((void));
--void AutoCrop PARM((void));
--int DoAutoCrop PARM((void));
--void DoCrop PARM((int, int, int, int));
--void Rotate PARM((int));
--void DoRotate PARM((int));
--void RotatePic PARM((byte *, int, int *, int *, int));
--void Flip PARM((int));
--void FlipPic PARM((byte *, int, int, int));
--void InstallNewPic PARM((void));
--void DrawEpic PARM((void));
--void KillOldPics PARM((void));
--
--byte *FSDither PARM((byte *, int, int, int,
-- byte *, byte *, byte *, int, int));
--
--void CreateXImage PARM((void));
--XImage *Pic8ToXImage PARM((byte *, u_int, u_int, u_long *,
-- byte *, byte *, byte *));
--
--XImage *Pic24ToXImage PARM((byte *, u_int, u_int));
--
--void Set824Menus PARM((int));
--void Change824Mode PARM((int));
--void FreeEpic PARM((void));
--void InvertPic24 PARM((byte *, int, int));
-+/*************************** XVALG.C ***************************/
-+void AlgInit PARM((void));
-+void DoAlg PARM((int));
-
--byte *XVGetSubImage PARM((byte *, int, int,int, int,int,int,int));
-
--int DoPad PARM((int, char *, int, int, int, int));
--int LoadPad PARM((PICINFO *, char *));
-+/*************************** XVBROWSE.C ************************/
-+void CreateBrowse PARM((const char *, const char *, const char *,
-+ const char *, const char *));
-+void OpenBrowse PARM((void));
-+void HideBrowseWindows PARM((void));
-+void UnHideBrowseWindows PARM((void));
-+void SetBrowseCursor PARM((Cursor));
-+void KillBrowseWindows PARM((void));
-+int BrowseCheckEvent PARM((XEvent *, int *, int *));
-+int BrowseDelWin PARM((Window));
-+void SetBrowStr PARM((const char *));
-+void RegenBrowseIcons PARM((void));
-+void BRDeletedFile PARM((char *));
-+void BRCreatedFile PARM((char *));
-
--/*************************** XVALG.C ***************************/
--void AlgInit PARM((void));
--void DoAlg PARM((int));
-
--/*************************** XVSMOOTH.C ***************************/
--byte *SmoothResize PARM((byte *, int, int, int, int, byte *, byte *,
-- byte *, byte *, byte *, byte *, int));
-+/**************************** XVBUTT.C ***************************/
-+void BTCreate PARM((BUTT *, Window, int, int, u_int, u_int,
-+ const char *, u_long, u_long, u_long, u_long));
-
--byte *Smooth24 PARM((byte *, int, int, int, int, int,
-- byte *, byte *, byte *));
-+void BTSetActive PARM((BUTT *, int));
-+void BTRedraw PARM((BUTT *));
-+int BTTrack PARM((BUTT *));
-
--byte *DoColorDither PARM((byte *, byte *, int, int, byte *, byte *,
-- byte *, byte *, byte *, byte *, int));
-
--byte *Do332ColorDither PARM((byte *, byte *, int, int, byte *, byte *,
-- byte *, byte *, byte *, byte *, int));
-+RBUTT *RBCreate PARM((RBUTT *, Window, int, int, const char *,
-+ u_long, u_long, u_long, u_long));
-
--/*************************** XV24TO8.C **************************/
--void Init24to8 PARM((void));
--byte *Conv24to8 PARM((byte *, int, int, int,
-- byte *, byte *, byte *));
-+void RBRedraw PARM((RBUTT *, int));
-+void RBSelect PARM((RBUTT *, int));
-+int RBWhich PARM((RBUTT *));
-+int RBCount PARM((RBUTT *));
-+void RBSetActive PARM((RBUTT *, int, int));
-+int RBClick PARM((RBUTT *, int, int));
-+int RBTrack PARM((RBUTT *, int));
-+
-+
-+void CBCreate PARM((CBUTT *, Window, int, int, const char *,
-+ u_long, u_long, u_long, u_long));
-+
-+void CBRedraw PARM((CBUTT *));
-+void CBSetActive PARM((CBUTT *, int));
-+int CBClick PARM((CBUTT *,int,int));
-+int CBTrack PARM((CBUTT *));
-+
-+
-+void MBCreate PARM((MBUTT *, Window, int, int, u_int, u_int,
-+ const char *, const char * const *, int,
-+ u_long, u_long, u_long, u_long));
-+
-+void MBRedraw PARM((MBUTT *));
-+void MBSetActive PARM((MBUTT *, int));
-+int MBWhich PARM((MBUTT *));
-+void MBSelect PARM((MBUTT *, int));
-+int MBClick PARM((MBUTT *, int, int));
-+int MBTrack PARM((MBUTT *));
-+
-+
-+/*************************** XVCOLOR.C ***************************/
-+void SortColormap PARM((byte *, int, int, int *, byte*,byte*,byte*,
-+ byte *, byte *));
-+void ColorCompress8 PARM((byte *));
-+void AllocColors PARM((void));
-+Status xvAllocColor PARM((Display *, Colormap, XColor *));
-+void xvFreeColors PARM((Display *, Colormap, u_long *, int, u_long));
-+void FreeColors PARM((void));
-+void ApplyEditColor PARM((int));
-+int MakeStdCmaps PARM((void));
-+void MakeBrowCmap PARM((void));
-+void ChangeCmapMode PARM((int, int, int));
-
--byte *Conv8to24 PARM((byte *, int, int, byte *, byte *, byte *));
-
- /**************************** XVCTRL.C **************************/
--void CreateCtrl PARM((char *));
-+void CreateCtrl PARM((const char *));
- void SetButtPix PARM((BUTT *, Pixmap, int, int));
- Pixmap MakePix1 PARM((Window, byte *, int, int));
-
-@@ -1337,7 +1608,7 @@
- void DrawCtrlStr PARM((void));
- void ScrollToCurrent PARM((LIST *));
-
--void LSCreate PARM((LIST *, Window, int, int, int, int, int,
-+void LSCreate PARM((LIST *, Window, int, int, int, int, int,
- char **, int, u_long, u_long, u_long, u_long,
- void (*)(int, SCRL *), int, int));
-
-@@ -1346,20 +1617,56 @@
- void LSChangeData PARM((LIST *, char **, int));
- void LSNewData PARM((LIST *, char **, int));
- void LSKey PARM((LIST *, int));
-+int rd_str_cl PARM((const char *, const char *, int));
-
-
--/*************************** XVINFO.C ***************************/
--void CreateInfo PARM((char *));
--void InfoBox PARM((int));
--void RedrawInfo PARM((int, int, int, int));
--void SetInfoMode PARM((int));
--char *GetISTR PARM((int));
-+/**************************** XVCUT.C ***************************/
-+int CutAllowed PARM((void));
-+int PasteAllowed PARM((void));
-+void DoImgCopy PARM((void));
-+void DoImgCut PARM((void));
-+void DoImgClear PARM((void));
-+void DoImgPaste PARM((void));
-
--#if defined(__STDC__) && !defined(NOSTDHDRS)
--void SetISTR(int, ...);
--#else
--void SetISTR();
--#endif
-+void SaveToClip PARM((byte *));
-+void InitSelection PARM((void));
-+int HaveSelection PARM((void));
-+int GetSelType PARM((void));
-+void GetSelRCoords PARM((int *, int *, int *, int *));
-+void EnableSelection PARM((int));
-+void DrawSelection PARM((int));
-+int DoSelection PARM((XButtonEvent *));
-+void MoveGrowSelection PARM((int, int, int, int));
-+void BlinkSelection PARM((int));
-+void FlashSelection PARM((int));
-+
-+void CropRect2Rect PARM((int*,int*,int*,int*, int,int,int,int));
-+void CoordE2C PARM((int, int, int *, int *));
-+void CoordC2E PARM((int, int, int *, int *));
-+void CoordP2C PARM((int, int, int *, int *));
-+void CoordC2P PARM((int, int, int *, int *));
-+void CoordP2E PARM((int, int, int *, int *));
-+void CoordE2P PARM((int, int, int *, int *));
-+
-+
-+/*************************** XVDFLT.C ***************************/
-+void LoadDfltPic PARM((PICINFO *));
-+void xbm2pic PARM((byte *, int, int, byte *, int, int, int, int,
-+ int));
-+void DrawStr2Pic PARM((char *, int, int, byte *, int, int, int));
-+
-+
-+/*************************** XVDIAL.C ***************************/
-+void DCreate PARM((DIAL *, Window, int, int, int, int,
-+ double, double, double, double, double,
-+ u_long, u_long, u_long, u_long,
-+ const char *, const char *));
-+
-+void DSetRange PARM((DIAL *, double,double,double,double,double));
-+void DSetVal PARM((DIAL *, double));
-+void DSetActive PARM((DIAL *, int));
-+void DRedraw PARM((DIAL *));
-+int DTrack PARM((DIAL *, int, int));
-
-
- /**************************** XVDIR.C ***************************/
-@@ -1376,15 +1683,15 @@
- void TrackDDirW PARM((int,int));
- int DirKey PARM((int));
- int DoSave PARM((void));
--void SetDirFName PARM((char *));
-+void SetDirFName PARM((const char *));
- char *GetDirFName PARM((void));
- char *GetDirFullName PARM((void));
- void SetDirSaveMode PARM((int, int));
- int Globify PARM((char *));
--FILE *OpenOutFile PARM((char *));
--int CloseOutFile PARM((FILE *, char *, int));
-+FILE *OpenOutFile PARM((const char *));
-+int CloseOutFile PARM((FILE *, const char *, int));
-
--byte *GenSavePic PARM((int*, int*,int*, int*, int*,
-+byte *GenSavePic PARM((int*, int*,int*, int*, int*,
- byte**, byte**, byte**));
- void GetSaveSize PARM((int *, int *));
-
-@@ -1392,47 +1699,30 @@
- int CheckPoll PARM((int));
- void DIRDeletedFile PARM((char *));
- void DIRCreatedFile PARM((char *));
-+FILE *pic2_OpenOutFile PARM((char *, int *));
-+void pic2_KillNullFile PARM((FILE *));
-+int OpenOutFileDesc PARM((char *));
-
-
--/*************************** XVBROWSE.C ************************/
--void CreateBrowse PARM((char *, char *, char *, char *, char *));
--void OpenBrowse PARM((void));
--void HideBrowseWindows PARM((void));
--void UnHideBrowseWindows PARM((void));
--void SetBrowseCursor PARM((Cursor));
--void KillBrowseWindows PARM((void));
--int BrowseCheckEvent PARM((XEvent *, int *, int *));
--int BrowseDelWin PARM((Window));
--void SetBrowStr PARM((char *));
--void RegenBrowseIcons PARM((void));
--void BRDeletedFile PARM((char *));
--void BRCreatedFile PARM((char *));
--
--
--/*************************** XVTEXT.C ************************/
--void CreateTextWins PARM((char *, char *));
--void TextView PARM((char *));
--void OpenTextView PARM((char *, int, char *, int));
--
--void OpenCommentText PARM((void));
--void CloseCommentText PARM((void));
--void ChangeCommentText PARM((void));
--
--void ShowLicense PARM((void));
--void ShowKeyHelp PARM((void));
--
--void HideTextWindows PARM((void));
--void UnHideTextWindows PARM((void));
--void RaiseTextWindows PARM((void));
--void SetTextCursor PARM((Cursor));
--void KillTextWindows PARM((void));
--int TextCheckEvent PARM((XEvent *, int *, int *));
--int TextDelWin PARM((Window));
-+/****************************** XVEVENT.C ****************************/
-+int EventLoop PARM((void));
-+int HandleEvent PARM((XEvent *, int *));
-
-+void NewCutBuffer PARM((char *));
-+void DrawWindow PARM((int,int,int,int));
-+void WResize PARM((int, int));
-+void WRotate PARM((void));
-+void WCrop PARM((int, int, int, int));
-+void WUnCrop PARM((void));
-+void GetWindowPos PARM((XWindowAttributes *));
-+void SetWindowPos PARM((XWindowAttributes *));
-+void SetEpicMode PARM((void));
-+int xvErrorHandler PARM((Display *, XErrorEvent *));
-
-
- /**************************** XVGAM.C **************************/
--void CreateGam PARM((char *, double, double, double, double, int));
-+void CreateGam PARM((const char *, double, double, double, double,
-+ int));
- int GamCheckEvent PARM((XEvent *));
- void GamBox PARM((int));
- void NewCMap PARM((void));
-@@ -1450,173 +1740,344 @@
- byte *GammifyPic24 PARM((byte *, int, int));
- void GamSetAutoApply PARM((int));
-
--/*************************** XVSCRL.C ***************************/
--void SCCreate PARM((SCRL *, Window, int, int, int, int,
-- int, int, int, int, u_long, u_long,
-- u_long, u_long, void (*)(int, SCRL *)));
-
--void SCChange PARM((SCRL *, int, int, int, int, int,
-- int, int, int));
-+/**************************** XVGRAB.C ***************************/
-+int Grab PARM((void));
-+int LoadGrab PARM((PICINFO *));
-
--void SCSetRange PARM((SCRL *, int, int, int, int));
--int SCSetVal PARM((SCRL *, int));
--void SCRedraw PARM((SCRL *));
--void SCTrack PARM((SCRL *, int, int));
-
-+/**************************** XVGRAF.C ***************************/
-+void CreateGraf PARM((GRAF *, Window, int, int,
-+ u_long, u_long, const char *));
-
--/*************************** XVDIAL.C ***************************/
--void DCreate PARM((DIAL *, Window, int, int, int, int, int,
-- int, int, int, u_long, u_long, u_long,
-- u_long, char *, char *));
-+void InitGraf PARM((GRAF *));
-+void RedrawGraf PARM((GRAF *, int));
-+int ClickGraf PARM((GRAF *, Window, int, int));
-+int GrafKey PARM((GRAF *, char *));
-+void GenerateGrafFunc PARM((GRAF *, int));
-+void Graf2Str PARM((GRAF_STATE *, char *));
-+int Str2Graf PARM((GRAF_STATE *, const char *));
-+void GetGrafState PARM((GRAF *, GRAF_STATE *));
-+int SetGrafState PARM((GRAF *, GRAF_STATE *));
-+void InitSpline PARM((int *, int *, int, double *));
-+double EvalSpline PARM((int *, int *, double *, int, double));
-
--void DSetRange PARM((DIAL *, int, int, int, int));
--void DSetVal PARM((DIAL *, int));
--void DSetActive PARM((DIAL *, int));
--void DRedraw PARM((DIAL *));
--int DTrack PARM((DIAL *, int, int));
-
-+/*************************** XVIMAGE.C ***************************/
-+void Resize PARM((int, int));
-+void GenerateCpic PARM((void));
-+void GenerateEpic PARM((int, int));
-+void DoZoom PARM((int, int, u_int));
-+void Crop PARM((void));
-+void UnCrop PARM((void));
-+void AutoCrop PARM((void));
-+int DoAutoCrop PARM((void));
-+void DoCrop PARM((int, int, int, int));
-+void Rotate PARM((int));
-+void DoRotate PARM((int));
-+void RotatePic PARM((byte *, int, int *, int *, int));
-+void Flip PARM((int));
-+void FlipPic PARM((byte *, int, int, int));
-+void InstallNewPic PARM((void));
-+void DrawEpic PARM((void));
-+void KillOldPics PARM((void));
-
--/**************************** XVBUTT.C ***************************/
--void BTCreate PARM((BUTT *, Window, int, int, u_int, u_int,
-- char *, u_long, u_long, u_long, u_long));
-+byte *FSDither PARM((byte *, int, int, int,
-+ byte *, byte *, byte *, int, int));
-
--void BTSetActive PARM((BUTT *, int));
--void BTRedraw PARM((BUTT *));
--int BTTrack PARM((BUTT *));
-+void CreateXImage PARM((void));
-+XImage *Pic8ToXImage PARM((byte *, u_int, u_int, u_long *,
-+ byte *, byte *, byte *));
-
-+XImage *Pic24ToXImage PARM((byte *, u_int, u_int));
-
--RBUTT *RBCreate PARM((RBUTT *, Window, int, int, char *,
-- u_long, u_long, u_long, u_long));
-+void Set824Menus PARM((int));
-+void Change824Mode PARM((int));
-+void FreeEpic PARM((void));
-+void InvertPic24 PARM((byte *, int, int));
-
--void RBRedraw PARM((RBUTT *, int));
--void RBSelect PARM((RBUTT *, int));
--int RBWhich PARM((RBUTT *));
--int RBCount PARM((RBUTT *));
--void RBSetActive PARM((RBUTT *, int, int));
--int RBClick PARM((RBUTT *, int, int));
--int RBTrack PARM((RBUTT *, int));
-+byte *XVGetSubImage PARM((byte *, int, int,int, int,int,int,int));
-
-+int DoPad PARM((int, char *, int, int, int, int));
-+int LoadPad PARM((PICINFO *, char *));
-
--void CBCreate PARM((CBUTT *, Window, int, int, char *,
-- u_long, u_long, u_long, u_long));
-
--void CBRedraw PARM((CBUTT *));
--void CBSetActive PARM((CBUTT *, int));
--int CBClick PARM((CBUTT *,int,int));
--int CBTrack PARM((CBUTT *));
-+/*************************** XVINFO.C ***************************/
-+void CreateInfo PARM((const char *));
-+void InfoBox PARM((int));
-+void RedrawInfo PARM((int, int, int, int));
-+void SetInfoMode PARM((int));
-+char *GetISTR PARM((int));
-
-+#if defined(__STDC__) && !defined(NOSTDHDRS)
-+void SetISTR(int, ...);
-+#else
-+void SetISTR();
-+#endif
-
--void MBCreate PARM((MBUTT *, Window, int, int, u_int, u_int,
-- char *,
-- char **, int,u_long,u_long, u_long, u_long));
-
--void MBRedraw PARM((MBUTT *));
--void MBSetActive PARM((MBUTT *, int));
--int MBWhich PARM((MBUTT *));
--void MBSelect PARM((MBUTT *, int));
--int MBClick PARM((MBUTT *, int, int));
--int MBTrack PARM((MBUTT *));
-+/*************************** XVMISC.C ***************************/
-+void StoreDeleteWindowProp PARM((Window));
-+Window CreateWindow PARM((const char *, const char *, const char *,
-+ int, int, u_long, u_long, int));
-+void DrawString PARM((Window, int, int, const char *));
-+void CenterString PARM((Window, int, int, const char *));
-+void ULineString PARM((Window, int, int, const char *));
-+int StringWidth PARM((const char *));
-+int CursorKey PARM((KeySym, int, int));
-+void FakeButtonPress PARM((BUTT *));
-+void FakeKeyPress PARM((Window, KeySym));
-+void GenExpose PARM((Window, int, int, u_int, u_int));
-+void DimRect PARM((Window, int, int, u_int, u_int, u_long));
-+
-+void Draw3dRect PARM((Window, int, int, u_int, u_int, int, int,
-+ u_long, u_long, u_long));
-+
-+void RemapKeyCheck PARM((KeySym, char *, int *));
-+void xvDestroyImage PARM((XImage *));
-+void SetCropString PARM((void));
-+void SetSelectionString PARM((void));
-+void Warning PARM((void));
-+void FatalError PARM((const char *));
-+void Quit PARM((int));
-+void LoadFishCursors PARM((void));
-+void WaitCursor PARM((void));
-+void SetCursors PARM((int));
-+const char *BaseName PARM((const char *));
-+
-+void DrawTempGauge PARM((Window, int, int, int, int, double, u_long,
-+ u_long, u_long, u_long, const char *));
-+void ProgressMeter PARM((int, int, int, const char *));
-+void XVDeletedFile PARM((char *));
-+void XVCreatedFile PARM((char *));
-+void xvbcopy PARM((const char *, char *, size_t));
-+int xvbcmp PARM((const char *, const char *, size_t));
-+void xvbzero PARM((char *, size_t));
-+void xv_getwd PARM((char *, size_t));
-+char *xv_strstr PARM((const char *, const char *));
-+FILE *xv_fopen PARM((const char *, const char *));
-+void xv_mktemp PARM((char *, const char *));
-+void Timer PARM((int));
-
-
--/**************************** XVGRAF.C ***************************/
--void CreateGraf PARM((GRAF *, Window, int, int,
-- u_long, u_long, char *));
-+/*************************** XVPOPUP.C ***************************/
-+void CenterMapWindow PARM((Window, int, int, int, int));
-+int PopUp PARM((const char *, const char **, int));
-+void ErrPopUp PARM((const char *, const char *));
-+int GetStrPopUp PARM((const char *, const char **, int, char *, int,
-+ const char *, int));
-+int GrabPopUp PARM((int *, int *));
-+int PadPopUp PARM((int *, char **, int *, int *, int *, int *));
-+void ClosePopUp PARM((void));
-+void OpenAlert PARM((const char *));
-+void CloseAlert PARM((void));
-+int PUCheckEvent PARM((XEvent *));
-
--void InitGraf PARM((GRAF *));
--void RedrawGraf PARM((GRAF *, int));
--int ClickGraf PARM((GRAF *, Window, int, int));
--int GrafKey PARM((GRAF *, char *));
--void GenerateGrafFunc PARM((GRAF *, int));
--void Graf2Str PARM((GRAF_STATE *, char *));
--int Str2Graf PARM((GRAF_STATE *, char *));
--void GetGrafState PARM((GRAF *, GRAF_STATE *));
--int SetGrafState PARM((GRAF *, GRAF_STATE *));
--void InitSpline PARM((int *, int *, int, double *));
--double EvalSpline PARM((int *, int *, double *, int, double));
-
-+/**************************** XVROOT.C ****************************/
-+void MakeRootPic PARM((void));
-+void ClearRoot PARM((void));
-+void SaveRootInfo PARM((void));
-+void KillOldRootInfo PARM((void));
-
--/**************************** XVGIF.C ***************************/
--int LoadGIF PARM((char *, PICINFO *));
-
--/*************************** XVGIFWR.C **************************/
--int WriteGIF PARM((FILE *, byte *, int, int, int,
-- byte *, byte *, byte *, int, int, char *));
-+/*************************** XVSCRL.C ***************************/
-+void SCCreate PARM((SCRL *, Window, int, int, int, int,
-+ int, int, int, int, u_long, u_long,
-+ u_long, u_long, void (*)(int, SCRL *)));
-
--/**************************** XVPM.C ****************************/
--int LoadPM PARM((char *, PICINFO *));
--int WritePM PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte *, int, int, char *));
-+void SCChange PARM((SCRL *, int, int, int, int, int,
-+ int, int, int));
-
--/**************************** XVPBM.C ***************************/
--int LoadPBM PARM((char *, PICINFO *));
--int WritePBM PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte *, int, int, int, char *));
-+void SCSetRange PARM((SCRL *, int, int, int, int));
-+int SCSetVal PARM((SCRL *, int));
-+void SCRedraw PARM((SCRL *));
-+void SCTrack PARM((SCRL *, int, int));
-
--/**************************** XVXBM.C ***************************/
--int LoadXBM PARM((char *, PICINFO *));
--int WriteXBM PARM((FILE *, byte *, int, int, byte *, byte *,
-- byte *, char *));
-
--/**************************** XVSUNRAS.C ***************************/
--int LoadSunRas PARM((char *, PICINFO *));
--int WriteSunRas PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte*, int, int, int));
-+/*************************** XVSMOOTH.C ***************************/
-+byte *SmoothResize PARM((byte *, int, int, int, int, byte *, byte *,
-+ byte *, byte *, byte *, byte *, int));
-
--/**************************** XVBMP.C ***************************/
--int LoadBMP PARM((char *, PICINFO *));
--int WriteBMP PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte *, int, int));
-+byte *Smooth24 PARM((byte *, int, int, int, int, int,
-+ byte *, byte *, byte *));
-
--/**************************** XVRLE.C ***************************/
--int LoadRLE PARM((char *, PICINFO *));
-+byte *DoColorDither PARM((byte *, byte *, int, int, byte *, byte *,
-+ byte *, byte *, byte *, byte *, int));
-
--/**************************** XVIRIS.C ***************************/
--int LoadIRIS PARM((char *, PICINFO *));
--int WriteIRIS PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte *, int, int));
-+byte *Do332ColorDither PARM((byte *, byte *, int, int, byte *, byte *,
-+ byte *, byte *, byte *, byte *, int));
-
--/**************************** XVPCX.C ***************************/
--int LoadPCX PARM((char *, PICINFO *));
-
--/**************************** XVIFF.C ***************************/
--int LoadIFF PARM((char *, PICINFO *));
-+/*************************** XVTEXT.C ************************/
-+void CreateTextWins PARM((const char *, const char *));
-+int TextView PARM((const char *));
-+void OpenTextView PARM((const char *, int, const char *, int));
-
--/**************************** XVTARGA.C ***************************/
--int LoadTarga PARM((char *, PICINFO *));
--int WriteTarga PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte *, int, int));
-+void OpenCommentText PARM((void));
-+void CloseCommentText PARM((void));
-+void ChangeCommentText PARM((void));
-
--/**************************** XVXPM.C ***************************/
--int LoadXPM PARM((char *, PICINFO *));
--int WriteXPM PARM((FILE *, byte *, int, int, int, byte *,
-- byte *, byte *, int, int, char *, char *));
-+void ShowLicense PARM((void));
-+void ShowKeyHelp PARM((void));
-
--/**************************** XVXWD.C ***************************/
--int LoadXWD PARM((char *, PICINFO *));
-+void HideTextWindows PARM((void));
-+void UnHideTextWindows PARM((void));
-+void RaiseTextWindows PARM((void));
-+void SetTextCursor PARM((Cursor));
-+void KillTextWindows PARM((void));
-+int TextCheckEvent PARM((XEvent *, int *, int *));
-+int TextDelWin PARM((Window));
-+
-+int CharsetCheckEvent PARM((XEvent *));
-+int CharsetDelWin PARM((Window));
-+
-+
-+/**************************** XVVD.C ****************************/
-+void Vdinit PARM((void));
-+void Vdsettle PARM((void));
-+int Chvdir PARM((char *));
-+void Dirtovd PARM((char *));
-+void Vdtodir PARM((char *));
-+void Dirtosubst PARM((char *));
-+int Mkvdir PARM((char *));
-+void Mkvdir_force PARM((char *));
-+int Rmvdir PARM((char *));
-+int Movevdir PARM((char *, char *));
-+int Isarchive PARM((char *));
-+int Isvdir PARM((char *));
-+void vd_HUPhandler PARM((void));
-+void vd_handler PARM((int));
-+int vd_Xhandler PARM((Display *, XErrorEvent *));
-+int vd_XIOhandler PARM((Display *));
-+void vd_handler_setup PARM((void));
-+
-+
-+
-+/*=======================================================================*/
-+/* IMAGE FORMATS */
-+/*=======================================================================*/
-+
-+/**************************** XVBMP.C ***************************/
-+int LoadBMP PARM((char *, PICINFO *));
-+int WriteBMP PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int));
-
- /**************************** XVFITS.C ***************************/
- int LoadFITS PARM((char *, PICINFO *, int));
- int WriteFITS PARM((FILE *, byte *, int, int, int, byte *,
- byte *, byte *, int, int, char *));
-
-+/**************************** XVGIF.C ***************************/
-+int LoadGIF PARM((char *, PICINFO *));
-+
-+/**************************** XVGIFWR.C **************************/
-+int WriteGIF PARM((FILE *, byte *, int, int, int,
-+ byte *, byte *, byte *, int, int, char *));
-+
-+/**************************** XVHIPS.C ***************************/
-+int LoadHIPS PARM((char *, PICINFO *));
-+
-+/**************************** XVIFF.C ***************************/
-+int LoadIFF PARM((char *, PICINFO *));
-+
-+/**************************** XVIRIS.C ***************************/
-+int LoadIRIS PARM((char *, PICINFO *));
-+int WriteIRIS PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int));
-+
-+/**************************** XVJP2K.C ***************************/
-+int LoadJPC PARM((char *, register PICINFO *, int));
-+int LoadJP2 PARM((char *, register PICINFO *, int));
-+void CreateJP2KW PARM((void));
-+void JP2KSaveParams PARM((int, char *, int));
-+void JP2KDialog PARM((int vis));
-+int JP2KCheckEvent PARM((register XEvent *));
-+void VersionInfoJP2K PARM((void)); /* GRR 20070304 */
-+
- /**************************** XVJPEG.C ***************************/
- int LoadJFIF PARM((char *, PICINFO *, int));
- void CreateJPEGW PARM((void));
- void JPEGDialog PARM((int));
- int JPEGCheckEvent PARM((XEvent *));
- void JPEGSaveParams PARM((char *, int));
-+void VersionInfoJPEG PARM((void)); /* GRR 19980605 */
-
--/**************************** XVTIFF.C ***************************/
--int LoadTIFF PARM((char *, PICINFO *));
--void CreateTIFFW PARM((void));
--void TIFFDialog PARM((int));
--int TIFFCheckEvent PARM((XEvent *));
--void TIFFSaveParams PARM((char *, int));
-+/**************************** XVMAG.C ***************************/
-+int LoadMAG PARM((char *, PICINFO *));
-+int WriteMAG PARM((FILE *, byte *, int, int, int,
-+ byte *, byte *, byte *, int, int, char *));
-+
-+/**************************** XVMAKI.C ***************************/
-+int LoadMAKI PARM((char *, PICINFO *));
-+int WriteMAKI PARM((FILE *, byte *, int, int, int,
-+ byte *, byte *, byte *, int, int));
-+
-+/**************************** XVMGCSFX.C ***************************/
-+int is_mgcsfx PARM((char *, unsigned char *, int));
-+char *mgcsfx_auto_input_com PARM((char *));
-+int LoadMGCSFX PARM((char *, PICINFO *));
-+void CreateMGCSFXW PARM((void));
-+void MGCSFXDialog PARM((int));
-+int MGCSFXCheckEvent PARM((XEvent *));
-+int MGCSFXSaveParams PARM((char *, int));
-+
-+int getInputCom PARM((void));
-+int getOutputCom PARM((void));
-+
-+/**************************** XVPBM.C ***************************/
-+#ifdef HAVE_MGCSFX
-+int LoadPBM PARM((char *, PICINFO *, int));
-+#else
-+int LoadPBM PARM((char *, PICINFO *));
-+#endif
-+int WritePBM PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int, int, char *));
-+
-+/**************************** XVPCD.C ***************************/
-+int LoadPCD PARM((char *, PICINFO *, int));
-+void CreatePCDW PARM((void));
-+void PCDDialog PARM((int));
-+int PCDCheckEvent PARM((XEvent *));
-+void PCDSetParamOptions PARM((const char *));
-+
-+/**************************** XVPCX.C ***************************/
-+int LoadPCX PARM((char *, PICINFO *));
-
- /**************************** XVPDS.C ***************************/
- int LoadPDS PARM((char *, PICINFO *));
-
--/*************************** XVPS.C ***************************/
-+/**************************** XVPI.C ***************************/
-+int LoadPi PARM((char *, PICINFO *));
-+int WritePi PARM((FILE *, byte *, int, int, int,
-+ byte *, byte *, byte *, int, int, char *));
-+
-+/**************************** XVPIC.C ***************************/
-+int LoadPIC PARM((char *, PICINFO *));
-+int WritePIC PARM((FILE *, byte *, int, int, int,
-+ byte *, byte *, byte *, int, int, char *));
-+
-+/**************************** XVPIC2.C ***************************/
-+int LoadPIC2 PARM((char *, PICINFO *, int));
-+void CreatePIC2W PARM((void));
-+void PIC2Dialog PARM((int));
-+int PIC2CheckEvent PARM((XEvent *));
-+int PIC2SetParamOptions PARM((char *));
-+
-+/**************************** XVPM.C ****************************/
-+int LoadPM PARM((char *, PICINFO *));
-+int WritePM PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int, char *));
-+
-+/**************************** XVPNG.C ***************************/
-+int LoadPNG PARM((char *, PICINFO *));
-+void CreatePNGW PARM((void));
-+void PNGDialog PARM((int));
-+int PNGCheckEvent PARM((XEvent *));
-+void PNGSaveParams PARM((char *, int));
-+void VersionInfoPNG PARM((void)); /* GRR 19980605 */
-+
-+/**************************** XVPS.C ****************************/
- void CreatePSD PARM((char *));
- void PSDialog PARM((int));
- int PSCheckEvent PARM((XEvent *));
-@@ -1624,56 +2085,46 @@
- void PSResize PARM((void));
- int LoadPS PARM((char *, PICINFO *, int));
-
--/*************************** XVPOPUP.C ***************************/
--void CenterMapWindow PARM((Window, int, int, int, int));
--int PopUp PARM((char *, char **, int));
--void ErrPopUp PARM((char *, char *));
--int GetStrPopUp PARM((char *, char **, int, char *, int,
-- char *, int));
--int GrabPopUp PARM((int *, int *));
--int PadPopUp PARM((int *, char **, int *, int *, int *, int *));
--void ClosePopUp PARM((void));
--void OpenAlert PARM((char *));
--void CloseAlert PARM((void));
--int PUCheckEvent PARM((XEvent *));
--void TextRect PARM((Window, char *, int, int, int, int, u_long));
-+/**************************** XVRLE.C ***************************/
-+int LoadRLE PARM((char *, PICINFO *));
-
--/*************************** XVDFLT.C ***************************/
--void LoadDfltPic PARM((PICINFO *));
--void xbm2pic PARM((byte *, int, int, byte *, int, int, int, int,
-- int));
--void DrawStr2Pic PARM((char *, int, int, byte *, int, int, int));
-+/**************************** XVSUNRAS.C ***************************/
-+int LoadSunRas PARM((char *, PICINFO *));
-+int WriteSunRas PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte*, int, int, int));
-
--/**************************** XVGRAB.C ***************************/
--int Grab PARM((void));
--int LoadGrab PARM((PICINFO *));
-+/**************************** XVTARGA.C ***************************/
-+int LoadTarga PARM((char *, PICINFO *));
-+int WriteTarga PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int));
-
-+/**************************** XVTIFF.C ***************************/
-+int LoadTIFF PARM((char *, PICINFO *, int));
-+void CreateTIFFW PARM((void));
-+void TIFFDialog PARM((int));
-+int TIFFCheckEvent PARM((XEvent *));
-+void TIFFSaveParams PARM((char *, int));
-+void VersionInfoTIFF PARM((void)); /* GRR 19980605 */
-
--/**************************** XVCUT.C ***************************/
--int CutAllowed PARM((void));
--int PasteAllowed PARM((void));
--void DoImgCopy PARM((void));
--void DoImgCut PARM((void));
--void DoImgClear PARM((void));
--void DoImgPaste PARM((void));
-+/**************************** XVWBMP.C ***************************/
-+int LoadWBMP PARM((char *, PICINFO *));
-+int WriteWBMP PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int));
-
--void SaveToClip PARM((byte *));
--void InitSelection PARM((void));
--int HaveSelection PARM((void));
--int GetSelType PARM((void));
--void GetSelRCoords PARM((int *, int *, int *, int *));
--void EnableSelection PARM((int));
--void DrawSelection PARM((int));
--int DoSelection PARM((XButtonEvent *));
--void MoveGrowSelection PARM((int, int, int, int));
--void BlinkSelection PARM((int));
--void FlashSelection PARM((int));
-+/**************************** XVXBM.C ***************************/
-+int LoadXBM PARM((char *, PICINFO *));
-+int WriteXBM PARM((FILE *, byte *, int, int, byte *, byte *,
-+ byte *, char *));
-
--void CropRect2Rect PARM((int*,int*,int*,int*, int,int,int,int));
--void CoordE2C PARM((int, int, int *, int *));
--void CoordC2E PARM((int, int, int *, int *));
--void CoordP2C PARM((int, int, int *, int *));
--void CoordC2P PARM((int, int, int *, int *));
--void CoordP2E PARM((int, int, int *, int *));
--void CoordE2P PARM((int, int, int *, int *));
-+/**************************** XVXPM.C ***************************/
-+int LoadXPM PARM((char *, PICINFO *));
-+int WriteXPM PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int, char *, char *));
-
-+/**************************** XVXWD.C ***************************/
-+int LoadXWD PARM((char *, PICINFO *));
-+
-+/**************************** XVZX.C [JCE] **********************/
-+int LoadZX PARM((char *, PICINFO *));
-+int WriteZX PARM((FILE *, byte *, int, int, int, byte *,
-+ byte *, byte *, int, int, char *));
-diff -ru xv-3.10a/xv24to8.c xv-3.10a-enhancements/xv24to8.c
---- xv-3.10a/xv24to8.c 1995-01-13 11:49:21.000000000 -0800
-+++ xv-3.10a-enhancements/xv24to8.c 2007-05-12 13:56:44.000000000 -0700
-@@ -14,15 +14,15 @@
- *
- * The Conv24to8 procedure will set up the following: it will allocate, make
- * & return 'pic8', a 'w' by 'h' (passed in values) 8-bit picture.
-- * it will load up the rmap, gmap and bmap colormap arrays. it will NOT
-+ * it will load up the rmap, gmap and bmap colormap arrays. it will NOT
- * calculate numcols, since the cmap sort procedure has to be called anyway
- *
-- * Conv24to8 returns 'pic8' if successful, 'NULL' on failure (presumably on a
-+ * Conv24to8 returns 'pic8' if successful, 'NULL' on failure (presumably on a
- * malloc())
- *
-- * The 'slow' code, while still based on Heckbert's Median Cut algorithm,
-+ * The 'slow' code, while still based on Heckbert's Median Cut algorithm,
- * has been shamelessly lifted from the Independent JPEG Group's software
-- * (jquant2.c), as (for a variety of reasons) theirs was far better than
-+ * (jquant2.c), as (for a variety of reasons) theirs was far better than
- * the version I was previously using. Thanks guys!
- *
- * Also, as is my way, I've stripped out most of the IJG's well-written
-@@ -65,10 +65,10 @@
- {
- /* returns pointer to new 8-bit-per-pixel image (w*h) if successful, or
- NULL if unsuccessful */
--
-+
- int i;
- byte *pic8;
--
-+
- if (!pic24) return NULL;
-
- pic8 = (byte *) malloc((size_t) (w * h));
-@@ -79,9 +79,9 @@
-
- if (nc<=0) nc = 255; /* 'nc == 0' breaks code */
-
-- if (!noqcheck && quick_check(pic24, w,h, pic8, rm,gm,bm, nc)) {
-+ if (!noqcheck && quick_check(pic24, w,h, pic8, rm,gm,bm, nc)) {
- SetISTR(ISTR_INFO,"No color compression was necessary.\n");
-- return pic8;
-+ return pic8;
- }
-
- switch (conv24) {
-@@ -89,19 +89,19 @@
- SetISTR(ISTR_INFO,"Doing 'quick' 24-bit to 8-bit conversion.");
- i = quick_quant(pic24, w, h, pic8, rm, gm, bm, nc);
- break;
--
-+
- case CONV24_BEST:
- SetISTR(ISTR_INFO,"Doing 'best' 24-bit to 8-bit conversion.");
- i = ppm_quant(pic24, w, h, pic8, rm, gm, bm, nc);
- break;
--
-+
- case CONV24_SLOW:
- default:
- SetISTR(ISTR_INFO,"Doing 'slow' 24-bit to 8-bit conversion.");
- i = slow_quant(pic24, w, h, pic8, rm, gm, bm, nc);
- break;
- }
--
-+
- if (i) { free(pic8); pic8 = NULL; }
- return pic8;
- }
-@@ -134,7 +134,7 @@
-
- return pic24;
- }
--
-+
-
- /****************************/
- static int quick_check(pic24, w,h, pic8, rmap,gmap,bmap, maxcol)
-@@ -154,10 +154,10 @@
- if (maxcol>256) maxcol = 256;
-
- /* put the first color in the table by hand */
-- nc = 0; mid = 0;
-+ nc = 0; mid = 0;
-
- for (i=w*h,p=pic24; i; i--) {
-- col = (((u_long) *p++) << 16);
-+ col = (((u_long) *p++) << 16);
- col += (((u_long) *p++) << 8);
- col += *p++;
-
-@@ -184,7 +184,7 @@
- pic24 into colormap offsets into 'colors' */
-
- for (i=w*h,p=pic24, pix=pic8; i; i--,pix++) {
-- col = (((u_long) *p++) << 16);
-+ col = (((u_long) *p++) << 16);
- col += (((u_long) *p++) << 8);
- col += *p++;
-
-@@ -206,7 +206,7 @@
-
- /* and load up the 'desired colormap' */
- for (i=0; i>16;
-+ rmap[i] = colors[i]>>16;
- gmap[i] = (colors[i]>>8) & 0xff;
- bmap[i] = colors[i] & 0xff;
- }
-@@ -224,7 +224,7 @@
- {
- /* called after 'pic8' has been alloced, pWIDE,pHIGH set up, mono/1-bit
- checked already */
--
-+
- /* up to 256 colors: 3 bits R, 3 bits G, 2 bits B (RRRGGGBB) */
- #define RMASK 0xe0
- #define RSHIFT 0
-@@ -252,7 +252,7 @@
- gmap[i] = (((i<>RSHIFT) | ((g1&GMASK)>>GSHIFT) |
-+ val = (((r1&RMASK)>>RSHIFT) | ((g1&GMASK)>>GSHIFT) |
- ((b1&BMASK)>>BSHIFT));
- *pp = val;
--
-+
- /* compute color errors */
- r1 -= rmap[val];
- g1 -= gmap[val];
- b1 -= bmap[val];
--
-+
- /* Add fractions of errors to adjacent pixels */
- if (j!=jmax) { /* adjust RIGHT pixel */
- thisptr[0] += (r1*7) / 16;
- thisptr[1] += (g1*7) / 16;
- thisptr[2] += (b1*7) / 16;
- }
--
-+
- if (i!=imax) { /* do BOTTOM pixel */
- nextptr[0] += (r1*5) / 16;
- nextptr[1] += (g1*5) / 16;
-@@ -316,7 +316,7 @@
- }
- }
- }
--
-+
- free(thisline);
- free(nextline);
- return 0;
-@@ -329,7 +329,7 @@
- #undef BMASK
- #undef BSHIFT
- }
--
-+
-
-
-
-@@ -381,7 +381,7 @@
-
- /* Luminance macro. */
-
--/*
-+/*
- * #define PPM_LUMIN(p) \
- * ( 0.299 * PPM_GETR(p) + 0.587 * PPM_GETG(p) + 0.114 * PPM_GETB(p) )
- */
-@@ -449,18 +449,18 @@
- byte *pic24, *pic8, *rmap, *gmap, *bmap;
- int cols, rows, newcolors;
- {
-- pixel** pixels;
-- register pixel* pP;
-- int row;
-- register int col, limitcol;
-- pixval maxval, newmaxval;
-- int colors;
-- register int index;
-- chist_vec chv, colormap;
-- chash_table cht;
-- int i;
-- unsigned char *picptr;
-- static char *fn = "ppmquant()";
-+ pixel** pixels;
-+ register pixel* pP;
-+ int row;
-+ register int col, limitcol;
-+ pixval maxval, newmaxval;
-+ int colors;
-+ register int index;
-+ chist_vec chv, colormap;
-+ chash_table cht;
-+ int i;
-+ unsigned char *picptr;
-+ static const char *fn = "ppmquant()";
-
- index = 0;
- maxval = 255;
-@@ -472,7 +472,7 @@
-
- if (DEBUG) fprintf(stderr,"%s: remapping to ppm-style internal fmt\n", fn);
- WaitCursor();
--
-+
- pixels = (pixel **) malloc(rows * sizeof(pixel *));
- if (!pixels) FatalError("couldn't allocate 'pixels' array");
- for (row=0; row= bl)
- qsort((char*) &(chv[indx]), (size_t) clrs, sizeof(struct chist_item),
- greencompare );
-- else
-+ else
- qsort((char*) &(chv[indx]), (size_t) clrs, sizeof(struct chist_item),
- bluecompare );
- }
-@@ -750,7 +750,7 @@
- ++boxes;
- qsort((char*) bv, (size_t) boxes, sizeof(struct box), sumcompare);
- } /* while (boxes ... */
--
-+
- /*
- ** Ok, we've got enough boxes. Now choose a representative color for
- ** each box. There are a number of possible ways to make this choice.
-@@ -761,7 +761,7 @@
- ** method is used by switching the commenting on the REP_ defines at
- ** the beginning of this source file.
- */
--
-+
- for (bi=0; bicolor ) -
-+ return (int) PPM_GETR( ((chist_vec)p1)->color ) -
- (int) PPM_GETR( ((chist_vec)p2)->color );
- }
-
-@@ -799,7 +799,7 @@
- static int greencompare(p1, p2)
- const void *p1, *p2;
- {
-- return (int) PPM_GETG( ((chist_vec)p1)->color ) -
-+ return (int) PPM_GETG( ((chist_vec)p1)->color ) -
- (int) PPM_GETG( ((chist_vec)p2)->color );
- }
-
-@@ -807,7 +807,7 @@
- static int bluecompare(p1, p2)
- const void *p1, *p2;
- {
-- return (int) PPM_GETB( ((chist_vec)p1)->color ) -
-+ return (int) PPM_GETB( ((chist_vec)p1)->color ) -
- (int) PPM_GETB( ((chist_vec)p2)->color );
- }
-
-@@ -821,7 +821,7 @@
-
-
- /****************************************************************************/
--static chist_vec
-+static chist_vec
- ppm_computechist(pixels, cols, rows, maxcolors, colorsP)
- pixel** pixels;
- int cols, rows, maxcolors;
-@@ -840,7 +840,7 @@
-
-
- /****************************************************************************/
--static chash_table ppm_computechash(pixels, cols, rows,
-+static chash_table ppm_computechash(pixels, cols, rows,
- maxcolors, colorsP )
- pixel** pixels;
- int cols, rows, maxcolors;
-@@ -861,14 +861,14 @@
-
- for (chl = cht[hash]; chl != (chist_list) 0; chl = chl->next)
- if (PPM_EQUAL(chl->ch.color, *pP)) break;
--
-+
- if (chl != (chist_list) 0) ++(chl->ch.value);
- else {
- if ((*colorsP)++ > maxcolors) {
- ppm_freechash(cht);
- return (chash_table) 0;
- }
--
-+
- chl = (chist_list) malloc(sizeof(struct chist_list_item));
- if (!chl) FatalError("ran out of memory computing hash table");
-
-@@ -878,7 +878,7 @@
- cht[hash] = chl;
- }
- }
--
-+
- return cht;
- }
-
-@@ -1114,7 +1114,7 @@
- register int i;
- register long maxc = 0;
- boxptr which = NULL;
--
-+
- for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
- if (boxp->colorcount > maxc && boxp->volume > 0) {
- which = boxp;
-@@ -1133,7 +1133,7 @@
- register int i;
- register INT32 maxv = 0;
- boxptr which = NULL;
--
-+
- for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
- if (boxp->volume > maxv) {
- which = boxp;
-@@ -1153,11 +1153,11 @@
- int c0min,c0max,c1min,c1max,c2min,c2max;
- INT32 dist0,dist1,dist2;
- long ccount;
--
-+
- c0min = boxp->c0min; c0max = boxp->c0max;
- c1min = boxp->c1min; c1max = boxp->c1max;
- c2min = boxp->c2min; c2max = boxp->c2max;
--
-+
- if (c0max > c0min)
- for (c0 = c0min; c0 <= c0max; c0++)
- for (c1 = c1min; c1 <= c1max; c1++) {
-@@ -1229,7 +1229,7 @@
- dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
- dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
- boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
--
-+
- ccount = 0;
- for (c0 = c0min; c0 <= c0max; c0++)
- for (c1 = c1min; c1 <= c1max; c1++) {
-@@ -1315,11 +1315,11 @@
- long c0total = 0;
- long c1total = 0;
- long c2total = 0;
--
-+
- c0min = boxp->c0min; c0max = boxp->c0max;
- c1min = boxp->c1min; c1max = boxp->c1max;
- c2min = boxp->c2min; c2max = boxp->c2max;
--
-+
- for (c0 = c0min; c0 <= c0max; c0++)
- for (c1 = c1min; c1 <= c1max; c1++) {
- histp = & histogram[c0][c1][c2min];
-@@ -1332,7 +1332,7 @@
- }
- }
- }
--
-+
- sl_colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
- sl_colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
- sl_colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
-@@ -1505,12 +1505,12 @@
- bptr = bestdist;
- for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
- *bptr++ = 0x7FFFFFFFL;
--
-+
- /* Nominal steps between cell centers ("x" in Thomas article) */
- #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
- #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
- #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
--
-+
- for (i = 0; i < numcolors; i++) {
- icolor = colorlist[i];
- /* Compute (square of) distance from minc0/c1/c2 to this color */
-@@ -1576,7 +1576,7 @@
- minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
- minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
- minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
--
-+
- numcolors = find_nearby_colors(minc0, minc1, minc2, colorlist);
-
- /* Determine the actually nearest colors. */
-diff -ru xv-3.10a/xvalg.c xv-3.10a-enhancements/xvalg.c
---- xv-3.10a/xvalg.c 1994-12-22 14:34:47.000000000 -0800
-+++ xv-3.10a-enhancements/xvalg.c 2007-05-12 16:07:37.000000000 -0700
-@@ -38,7 +38,7 @@
- double, int));
- static void doPixel PARM((byte *,int,int,byte *, int,int,int,int,
- int, int));
--static void doSpread PARM((byte *,int,int,byte *, int,int,int,int,
-+static void doSpread PARM((byte *,int,int,byte *, int,int,int,int,
- int, int));
- static void doMedianFilter PARM((byte *,int,int,byte *, int,int,int,int, int));
-
-@@ -53,7 +53,7 @@
- static int start24bitAlg PARM((byte **, byte **));
- static void end24bitAlg PARM((byte *, byte *));
-
--static void printUTime PARM((char *));
-+static void printUTime PARM((const char *));
-
- static byte *origPic = (byte *) NULL;
- static int origPicType;
-@@ -70,10 +70,11 @@
-
- /***************************/
- static void printUTime(str)
-- char *str;
-+ const char *str;
- {
- #ifdef TIMING_TEST
-- int i; struct rusage ru;
-+ int i;
-+ struct rusage ru;
-
- i = getrusage(RUSAGE_SELF, &ru);
- fprintf(stderr,"%s: utime = %d.%d seconds\n",
-@@ -89,7 +90,7 @@
- /************************************************************/
- void AlgInit()
- {
-- /* called whenver an image file is loaded. disposes of origPic
-+ /* called whenver an image file is loaded. disposes of origPic
- if neccessary, and points it to null */
-
- if (origPic) free(origPic);
-@@ -160,16 +161,16 @@
- {
- /* runs a n*n convolution mask (all 1's) over 'pic',
- producing a 24-bit version. Then calls 24to8 to generate a new 8-bit
-- image, and installs it.
-+ image, and installs it.
-
- Note that 'n' must be odd for things to work properly */
-
-- byte *pic24, *tmpPic;
-- int i, sx,sy,sw,sh, n;
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char txt[256];
-- static char buf[64] = { '3', '\0' };
--
-+ byte *pic24, *tmpPic;
-+ int i, sx,sy,sw,sh, n;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char txt[256];
-+ static char buf[64] = { '3', '\0' };
-+
- sprintf(txt, "Blur: \n\n%s",
- "Enter mask size (ex. 3, 5, 7, ...)");
-
-@@ -178,7 +179,7 @@
- n = atoi(buf);
-
- if (n < 1 || (n&1)!=1) {
-- ErrPopUp("Error: The value entered must be odd and greater than zero.",
-+ ErrPopUp("Error: The value entered must be odd and greater than zero.",
- "\nOh!");
- return;
- }
-@@ -194,7 +195,7 @@
-
- if (start24bitAlg(&pic24, &tmpPic)) return;
- xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
--
-+
- doBlurConvolv(pic24, pWIDE,pHIGH, tmpPic, sx,sy,sw,sh, n);
-
- end24bitAlg(pic24, tmpPic);
-@@ -207,12 +208,12 @@
- {
- /* runs an edge-enhancment algorithm */
-
-- byte *pic24, *tmpPic;
-- int i, sx,sy,sw,sh, n;
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char txt[256];
-- static char buf[64] = { '7', '5', '\0' };
--
-+ byte *pic24, *tmpPic;
-+ int i, sx,sy,sw,sh, n;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char txt[256];
-+ static char buf[64] = { '7', '5', '\0' };
-+
- sprintf(txt, "Sharpen: \n\n%s",
- "Enter enhancement factor (0-99%)");
-
-@@ -236,7 +237,7 @@
-
- if (start24bitAlg(&pic24, &tmpPic)) return;
- xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
--
-+
- doSharpConvolv(pic24, pWIDE,pHIGH, tmpPic, sx,sy,sw,sh, n);
-
- end24bitAlg(pic24, tmpPic);
-@@ -248,7 +249,7 @@
- static void EdgeDetect()
- {
- byte *pic24, *p24, *tmpPic, *tlp;
-- char *str;
-+ const char *str;
- int i, j, v, maxv, sx,sy,sw,sh;
-
- WaitCursor();
-@@ -264,7 +265,7 @@
- xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
-
- doEdgeConvolv(pic24, pWIDE, pHIGH, tmpPic, sx,sy,sw,sh);
--
-+
- SetISTR(ISTR_INFO, "%snormalizing...", str);
-
- /* Normalize results */
-@@ -292,19 +293,19 @@
- /************************/
- static void TinFoil()
- {
-- byte *pic24, *p24, *tmpPic, *tp, *tlp;
-- char *str;
-- int i, j, v, maxv,sx,sy,sw,sh;
--
-+ byte *pic24, *tmpPic, *tp, *tlp;
-+ const char *str;
-+ int i, j, v, sx,sy,sw,sh;
-+
- WaitCursor();
--
-+
- str = "Doing cheesy embossing effect...";
- SetISTR(ISTR_INFO, str);
--
-+
- if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
- else { sx = 0; sy = 0; sw = pWIDE; sh = pHIGH; }
- CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
--
-+
- if (start24bitAlg(&pic24, &tmpPic)) return;
- xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
-
-@@ -315,9 +316,9 @@
- *tp++ = 128; *tp++ = 128; *tp++ = 128;
- }
- }
--
-+
- doAngleConvolv(pic24, pWIDE, pHIGH, tmpPic, sx,sy,sw,sh);
--
-+
- /* mono-ify selected area of tmpPic */
- for (i=sy; i0 = CCW)",
- (clr ? "Clear" : "Copy"));
-@@ -396,12 +397,12 @@
- rotval = atof(buf);
-
- if (rotval == 0.0) return;
--
-+
-
- if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
- else { sx = 0; sy = 0; sw = pWIDE; sh = pHIGH; }
- CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
--
-+
- WaitCursor();
-
- if (start24bitAlg(&pic24, &tmpPic)) return;
-@@ -416,11 +417,11 @@
- /************************/
- static void Pixelize()
- {
-- byte *pic24, *tmpPic;
-- int i,sx,sy,sw,sh, pixX,pixY,err;
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char txt[256];
-- static char buf[64] = { '4', '\0' };
-+ byte *pic24, *tmpPic;
-+ int i,sx,sy,sw,sh, pixX,pixY,err;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char txt[256];
-+ static char buf[64] = { '4', '\0' };
-
- sprintf(txt, "Pixelize:\n\nEnter new pixel size, in image pixels: %s",
- "(ex. '3', '5x8')");
-@@ -443,11 +444,11 @@
- return;
- }
-
--
-+
- if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
- else { sx = 0; sy = 0; sw = pWIDE; sh = pHIGH; }
- CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
--
-+
- WaitCursor();
-
- if (start24bitAlg(&pic24, &tmpPic)) return;
-@@ -463,11 +464,11 @@
- /************************/
- static void Spread()
- {
-- byte *pic24, *tmpPic;
-- int i,sx,sy,sw,sh, pixX,pixY,err;
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char txt[256];
-- static char buf[64] = { '5', '\0' };
-+ byte *pic24, *tmpPic;
-+ int i,sx,sy,sw,sh, pixX,pixY,err;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char txt[256];
-+ static char buf[64] = { '5', '\0' };
-
- sprintf(txt, "Spread:\n\nEnter spread factor (or x,y factors): %s",
- "(ex. '10', '1x5')");
-@@ -493,11 +494,11 @@
- return;
- }
-
--
-+
- if (HaveSelection()) GetSelRCoords(&sx,&sy,&sw,&sh);
- else { sx = 0; sy = 0; sw = pWIDE; sh = pHIGH; }
- CropRect2Rect(&sx,&sy,&sw,&sh, 0,0,pWIDE,pHIGH);
--
-+
- WaitCursor();
-
- if (start24bitAlg(&pic24, &tmpPic)) return;
-@@ -516,12 +517,12 @@
- /* runs median filter algorithm (for n*n rect centered around each pixel,
- replace with median value */
-
-- byte *pic24, *tmpPic;
-- int i, sx,sy,sw,sh, n;
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char txt[256];
-- static char buf[64] = { '3', '\0' };
--
-+ byte *pic24, *tmpPic;
-+ int i, sx,sy,sw,sh, n;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char txt[256];
-+ static char buf[64] = { '3', '\0' };
-+
- sprintf(txt, "DeSpeckle (median filter): \n\n%s",
- "Enter mask size (ex. 3, 5, 7, ...)");
-
-@@ -530,7 +531,7 @@
- n = atoi(buf);
-
- if (n < 1 || (n&1)!=1) {
-- ErrPopUp("Error: The value entered must be odd and greater than zero.",
-+ ErrPopUp("Error: The value entered must be odd and greater than zero.",
- "\nOh!");
- return;
- }
-@@ -546,7 +547,7 @@
-
- if (start24bitAlg(&pic24, &tmpPic)) return;
- xvbcopy((char *) pic24, (char *) tmpPic, (size_t) (pWIDE*pHIGH*3));
--
-+
- doMedianFilter(pic24, pWIDE,pHIGH, tmpPic, sx,sy,sw,sh, n);
-
- end24bitAlg(pic24, tmpPic);
-@@ -560,7 +561,7 @@
- int w,h, selx,sely,selw,selh, n;
- {
-
-- /* convolves with an n*n array, consisting of only 1's.
-+ /* convolves with an n*n array, consisting of only 1's.
- Operates on rectangular region 'selx,sely,selw,selh' (in pic coords)
- Region is guaranteed to be completely within pic boundaries
- 'n' must be odd */
-@@ -568,7 +569,7 @@
- register byte *p24;
- register int rsum,gsum,bsum;
- byte *rp;
-- int i,j,k,x,y,x1,y1,count,n2;
-+ int x,y,x1,y1,count,n2;
-
-
- printUTime("start of blurConvolv");
-@@ -589,7 +590,7 @@
- for (y1=y-n2; y1<=y+n2; y1++) {
-
- if (y1>=sely && y1=selx && x1=sely && i=selx && j=sely && i=selx && j fabs(dslope)) { /* y axis is major */
- ey = (dy<0) ? sely : sely+selh-1;
-@@ -1092,7 +1093,7 @@
- printUTime("end of blend");
- }
-
--
-+
-
- /************************/
- static void doRotate(pic24, w, h, results, selx,sely,selw,selh, rotval, clear)
-@@ -1104,7 +1105,7 @@
- by the amount specified in degrees (rotval), and stores the result in
- 'results', which is also a w*h 24-bit image. The rotated bits are
- clipped to fit in 'results'. If 'clear', the (unrotated) rectangular
-- region is cleared (in results) first.
-+ region is cleared (in results) first.
- sel[x,y,w,h] is guaranteed to be within image bounds */
-
- byte *pp, *dp;
-@@ -1118,7 +1119,7 @@
- printUTime("start of rotate");
-
- /*
-- * cfx,cfy - center point of sel rectangle (double)
-+ * cfx,cfy - center point of sel rectangle (double)
- * rx1,ry1 - top-left of sel, rotated
- * rx2,ry2 - bot-left of sel, rotated
- * rx3,ry3 - top-right of sel, rotated
-@@ -1174,7 +1175,7 @@
- /* now, for each pixel in rb[x,y,w,h], do the inverse rotation to see if
- it would be in the original unrotated selection rectangle. if it *is*,
- compute and store an appropriate color, otherwise skip it */
--
-+
- for (y=rby; y %7.2f %7.2f (d=%f ang=%f)\n",
-+ fprintf(stderr,"(%4d,%4d) -> %7.2f %7.2f (d=%f ang=%f)\n",
- cx,cy, *rx,*ry, d, ang);
- #endif
- }
--
-+
-
-
- /************************/
-@@ -1323,29 +1324,29 @@
- byte *pic24, *results;
- int w, h, selx,sely,selw,selh, pixX,pixY;
- {
-- /* runs 'pixelization' algorithm. replaces each pixX-by-pixY region
-+ /* runs 'pixelization' algorithm. replaces each pixX-by-pixY region
- (smaller on edges) with the average color within that region */
--
-+
- byte *pp;
- int nwide, nhigh, i,j, x,y, x1,y1, stx,sty;
- int nsum, rsum, gsum, bsum;
--
-+
- printUTime("start of pixelize");
--
-+
- /* center grid on selection */
- nwide = (selw + pixX-1) / pixX;
- nhigh = (selh + pixY-1) / pixY;
--
-+
- stx = selx - (nwide*pixX - selw)/2;
- sty = sely - (nhigh*pixY - selh)/2;
--
-+
- y = sty;
- for (i=0; i0) { /* just to be safe... */
- rsum /= nsum; gsum /= nsum; bsum /= nsum;
- RANGE(rsum,0,255); RANGE(gsum,0,255); RANGE(bsum,0,255);
- }
--
--
-+
-+
- /* STORE color in rect:[x,y,pixX,pixY] */
- for (y1=y; y1=sely && y1=selx && x10; d=d/2) {
- for (i=d; i=0 && rtab[j]>rtab[j+d]; j-=d) {
-@@ -1531,14 +1532,14 @@
- }
- }
- }
--
-+
- c2 = count/2;
- *rp++ = (byte) ( (count&1) ? rtab[c2] : (rtab[c2] + rtab[c2-1])/2);
- *rp++ = (byte) ( (count&1) ? gtab[c2] : (gtab[c2] + gtab[c2-1])/2);
- *rp++ = (byte) ( (count&1) ? btab[c2] : (btab[c2] + btab[c2-1])/2);
- }
- }
--
-+
- free(rtab); free(gtab); free(btab);
- printUTime("end of doMedianFilter");
- }
-@@ -1549,7 +1550,7 @@
- static void intsort(a, n)
- int *a, n;
- {
-- /* uses the shell-sort algorithm. for the relatively small data sets
-+ /* uses the shell-sort algorithm. for the relatively small data sets
- we'll be using, should be quicker than qsort() because of all the
- function calling overhead associated with qsort(). */
-
-@@ -1571,7 +1572,7 @@
- byte **pic24, **tmpPic;
- {
- /* generates a 24-bit version of 'pic', if neccessary, and also mallocs
-- * a pWIDE*pHIGH*3 24-bit output pic.
-+ * a pWIDE*pHIGH*3 24-bit output pic.
- *
- * Returns '1' if there's some sort of screwup, '0' if cool
- */
-@@ -1588,7 +1589,7 @@
- *tmpPic = (byte *) calloc((size_t) (pWIDE * pHIGH * 3), (size_t) 1);
- if (!(*tmpPic)) {
- SetCursors(-1);
-- ErrPopUp("Unable to malloc() tmp 24-bit image in start24bitAlg()",
-+ ErrPopUp("Unable to malloc() tmp 24-bit image in start24bitAlg()",
- "\nTough!");
- if (picType == PIC8) free(*pic24);
- return 1;
-@@ -1609,16 +1610,16 @@
- saveOrigPic(); /* also kills pic/cpic/epic/egampic/theImage, NOT pic24 */
-
- /* copy results to pic24 */
-- xvbcopy((char *) outPic, (char *) pic24, (size_t) (pWIDE*pHIGH*3));
-+ xvbcopy((char *) outPic, (char *) pic24, (size_t) (pWIDE*pHIGH*3));
- free(outPic);
-
- if (picType == PIC8) {
- pic = Conv24to8(pic24, pWIDE, pHIGH, ncols, rMap,gMap,bMap);
- free(pic24);
-- if (!pic) {
-+ if (!pic) {
- SetCursors(-1);
- ErrPopUp("Some sort of failure occured in 24to8 conversion\n","\nDamn!");
-- NoAlg();
-+ NoAlg();
- return;
- }
- }
-@@ -1632,7 +1633,7 @@
- static void saveOrigPic()
- {
- /* saves original picture into origPic, if it hasn't already been done.
-- This allows us to undo algorithms...
-+ This allows us to undo algorithms...
-
- Also, frees all pics, (except 'pic', if we're in PIC24 mode) */
-
-@@ -1649,7 +1650,7 @@
- /* make a backup copy of 'pic' */
- origPic = (byte *) malloc((size_t)(pWIDE*pHIGH*((picType==PIC8) ? 1 : 3)));
- if (!origPic) FatalError("out of memory in 'saveOrigPic()'");
-- xvbcopy((char *) pic, (char *) origPic,
-+ xvbcopy((char *) pic, (char *) origPic,
- (size_t) (pWIDE * pHIGH * ((picType==PIC8) ? 1 : 3)));
-
- origPicType = picType;
-diff -ru xv-3.10a/xvbmp.c xv-3.10a-enhancements/xvbmp.c
---- xv-3.10a/xvbmp.c 1994-12-22 14:34:42.000000000 -0800
-+++ xv-3.10a-enhancements/xvbmp.c 2007-05-13 17:46:16.000000000 -0700
-@@ -1,5 +1,5 @@
- /*
-- * xvbmp.c - i/o routines for .BMP files (MS Windows 3.x)
-+ * xvbmp.c - I/O routines for .BMP files (MS Windows 3.x and later; OS/2)
- *
- * LoadBMP(fname, numcols)
- * WriteBMP(fp, pic, ptype, w, h, r, g, b, numcols, style);
-@@ -9,30 +9,39 @@
-
- #include "xv.h"
-
--/* comments on error handling:
-- a truncated file is not considered a Major Error. The file is loaded, the
-- rest of the pic is filled with 0's.
--
-- a file with garbage characters in it is an unloadable file. All allocated
-- stuff is tossed, and LoadPBM returns non-zero
--
-- not being able to malloc is a Fatal Error. The program is aborted. */
--
--
--#define BI_RGB 0
--#define BI_RLE8 1
--#define BI_RLE4 2
-+/* Comments on error-handling:
-+ A truncated file is not considered a Major Error. The file is loaded,
-+ and the rest of the pic is filled with 0's.
-+
-+ A file with garbage characters in it is an unloadable file. All allocated
-+ stuff is tossed, and LoadBMP returns non-zero.
-+
-+ Not being able to malloc is a Fatal Error. The program is aborted. */
-+
-+
-+#define BI_RGB 0 /* a.k.a. uncompressed */
-+#define BI_RLE8 1
-+#define BI_RLE4 2
-+#define BI_BITFIELDS 3 /* BMP version 4 */
-+#define BI_JPEG 4 /* BMP version 5 (not yet supported) */
-+#define BI_PNG 5 /* BMP version 5 (not yet supported) */
-
- #define WIN_OS2_OLD 12
- #define WIN_NEW 40
- #define OS2_NEW 64
-
-+#if (defined(UINT_MAX) && UINT_MAX != 0xffffffffU)
-+# error XV's BMP code requires 32-bit unsigned integer type, but u_int isn't
-+#endif
-+
- static long filesize;
-
- static int loadBMP1 PARM((FILE *, byte *, u_int, u_int));
- static int loadBMP4 PARM((FILE *, byte *, u_int, u_int, u_int));
- static int loadBMP8 PARM((FILE *, byte *, u_int, u_int, u_int));
--static int loadBMP24 PARM((FILE *, byte *, u_int, u_int));
-+static int loadBMP16 PARM((FILE *, byte *, u_int, u_int, u_int *));
-+static int loadBMP24 PARM((FILE *, byte *, u_int, u_int, u_int));
-+static int loadBMP32 PARM((FILE *, byte *, u_int, u_int, u_int *));
- static u_int getshort PARM((FILE *));
- static u_int getint PARM((FILE *));
- static void putshort PARM((FILE *, int));
-@@ -41,7 +50,7 @@
- static void writeBMP4 PARM((FILE *, byte *, int, int));
- static void writeBMP8 PARM((FILE *, byte *, int, int));
- static void writeBMP24 PARM((FILE *, byte *, int, int));
--static int bmpError PARM((char *, char *));
-+static int bmpError PARM((const char *, const char *));
-
-
- #define FERROR(fp) (ferror(fp) || feof(fp))
-@@ -52,15 +61,15 @@
- PICINFO *pinfo;
- /*******************************************/
- {
-- FILE *fp;
-- int i, c, c1, rv;
-- unsigned int bfSize, bfOffBits, biSize, biWidth, biHeight, biPlanes;
-- unsigned int biBitCount, biCompression, biSizeImage, biXPelsPerMeter;
-- unsigned int biYPelsPerMeter, biClrUsed, biClrImportant;
-- int bPad;
-- char *cmpstr;
-- byte *pic24, *pic8;
-- char buf[512], *bname;
-+ FILE *fp;
-+ int i, c, c1, rv, bPad;
-+ u_int bfSize, bfOffBits, biSize, biWidth, biHeight, biPlanes;
-+ u_int biBitCount, biCompression, biSizeImage, biXPelsPerMeter;
-+ u_int biYPelsPerMeter, biClrUsed, biClrImportant;
-+ u_int colormask[3];
-+ char buf[512], rgb_bits[16];
-+ const char *cmpstr, *bname;
-+ byte *pic24, *pic8;
-
- /* returns '1' on success */
-
-@@ -69,7 +78,7 @@
-
- fp = xv_fopen(fname,"r");
- if (!fp) return (bmpError(bname, "couldn't open file"));
--
-+
- fseek(fp, 0L, 2); /* figure out the file size */
- filesize = ftell(fp);
- fseek(fp, 0L, 0);
-@@ -98,17 +107,16 @@
- biClrUsed = getint(fp);
- biClrImportant = getint(fp);
- }
--
- else { /* old bitmap format */
- biWidth = getshort(fp); /* Types have changed ! */
- biHeight = getshort(fp);
- biPlanes = getshort(fp);
- biBitCount = getshort(fp);
--
-- /* Not in old versions so have to compute them*/
-+
-+ /* not in old versions, so have to compute them */
- biSizeImage = (((biPlanes * biBitCount*biWidth)+31)/32)*4*biHeight;
--
-- biCompression = BI_RGB;
-+
-+ biCompression = BI_RGB;
- biXPelsPerMeter = biYPelsPerMeter = 0;
- biClrUsed = biClrImportant = 0;
- }
-@@ -126,22 +134,39 @@
- if (FERROR(fp)) { bmpError(bname,"EOF reached in file header"); goto ERROR; }
-
-
-- /* error checking */
-- if ((biBitCount!=1 && biBitCount!=4 && biBitCount!=8 && biBitCount!=24) ||
-- biPlanes!=1 || biCompression>BI_RLE4) {
-+ /* error-checking */
-+ if ((biBitCount!=1 && biBitCount!=4 && biBitCount!=8 &&
-+ biBitCount!=16 && biBitCount!=24 && biBitCount!=32) ||
-+ biPlanes!=1 || biCompression>BI_PNG ||
-+ biWidth<=0 || biHeight<=0 ||
-+ (biClrUsed && biClrUsed > (1 << biBitCount))) {
-+
-+ sprintf(buf,
-+ "Unsupported BMP type (%dx%d, Bits=%d, Colors=%d, Planes=%d, "
-+ "Compr=%d)",
-+ biWidth, biHeight, biBitCount, biClrUsed, biPlanes, biCompression);
-
-- sprintf(buf,"Bogus BMP File! (bitCount=%d, Planes=%d, Compression=%d)",
-- biBitCount, biPlanes, biCompression);
-+ bmpError(bname, buf);
-+ goto ERROR;
-+ }
-+
-+ if (biCompression>BI_BITFIELDS) {
-+ sprintf(buf, "Unsupported BMP compression method (%s)",
-+ biCompression == BI_JPEG? "JPEG" :
-+ biCompression == BI_PNG? "PNG" :
-+ "unknown/newer than v5");
-
- bmpError(bname, buf);
- goto ERROR;
- }
-
- if (((biBitCount==1 || biBitCount==24) && biCompression != BI_RGB) ||
-- (biBitCount==4 && biCompression==BI_RLE8) ||
-- (biBitCount==8 && biCompression==BI_RLE4)) {
-+ (biBitCount==4 && biCompression!=BI_RGB && biCompression!=BI_RLE4) ||
-+ (biBitCount==8 && biCompression!=BI_RGB && biCompression!=BI_RLE8) ||
-+ ((biBitCount==16 || biBitCount==32) &&
-+ biCompression!=BI_RGB && biCompression!=BI_BITFIELDS)) {
-
-- sprintf(buf,"Bogus BMP File! (bitCount=%d, Compression=%d)",
-+ sprintf(buf,"Unsupported BMP type (bitCount=%d, Compression=%d)",
- biBitCount, biCompression);
-
- bmpError(bname, buf);
-@@ -153,13 +178,21 @@
- if (biSize != WIN_OS2_OLD) {
- /* skip ahead to colormap, using biSize */
- c = biSize - 40; /* 40 bytes read from biSize to biClrImportant */
-- for (i=0; i1) {
-@@ -188,7 +221,7 @@
- if (biSize != WIN_OS2_OLD) {
- /* Waste any unused bytes between the colour map (if present)
- and the start of the actual bitmap data. */
--
-+
- while (bPad > 0) {
- (void) getc(fp);
- bPad--;
-@@ -197,31 +230,57 @@
-
- /* create pic8 or pic24 */
-
-- if (biBitCount==24) {
-- pic24 = (byte *) calloc((size_t) biWidth * biHeight * 3, (size_t) 1);
-+ if (biBitCount==16 || biBitCount==24 || biBitCount==32) {
-+ u_int npixels = biWidth * biHeight;
-+ u_int count = 3 * npixels;
-+
-+ if (biWidth == 0 || biHeight == 0 || npixels/biWidth != biHeight ||
-+ count/3 != npixels)
-+ return (bmpError(bname, "image dimensions too large"));
-+ pic24 = (byte *) calloc((size_t) count, (size_t) 1);
- if (!pic24) return (bmpError(bname, "couldn't malloc 'pic24'"));
- }
- else {
-- pic8 = (byte *) calloc((size_t) biWidth * biHeight, (size_t) 1);
-+ u_int npixels = biWidth * biHeight;
-+
-+ if (biWidth == 0 || biHeight == 0 || npixels/biWidth != biHeight)
-+ return (bmpError(bname, "image dimensions too large"));
-+ pic8 = (byte *) calloc((size_t) npixels, (size_t) 1);
- if (!pic8) return(bmpError(bname, "couldn't malloc 'pic8'"));
- }
-
- WaitCursor();
-
- /* load up the image */
-- if (biBitCount == 1) rv = loadBMP1(fp,pic8,biWidth,biHeight);
-- else if (biBitCount == 4) rv = loadBMP4(fp,pic8,biWidth,biHeight,
-- biCompression);
-- else if (biBitCount == 8) rv = loadBMP8(fp,pic8,biWidth,biHeight,
-- biCompression);
-- else rv = loadBMP24(fp,pic24,biWidth,biHeight);
-+ switch (biBitCount) {
-+ case 1:
-+ rv = loadBMP1(fp, pic8, biWidth, biHeight);
-+ break;
-+ case 4:
-+ rv = loadBMP4(fp, pic8, biWidth, biHeight, biCompression);
-+ break;
-+ case 8:
-+ rv = loadBMP8(fp, pic8, biWidth, biHeight, biCompression);
-+ break;
-+ case 16:
-+ rv = loadBMP16(fp, pic24, biWidth, biHeight, /* v-- BI_RGB */
-+ biCompression == BI_BITFIELDS? colormask : NULL);
-+ break;
-+ default:
-+ if (biBitCount == 32 && biCompression == BI_BITFIELDS)
-+ rv = loadBMP32(fp, pic24, biWidth, biHeight, colormask);
-+ else /* 24 or (32 and BI_RGB) */
-+ rv = loadBMP24(fp, pic24, biWidth, biHeight, biBitCount);
-+ break;
-+ }
-+
-+ if (rv) bmpError(bname, "File appears truncated. Winging it.");
-
-- if (rv) bmpError(bname, "File appears truncated. Winging it.\n");
-
- fclose(fp);
-
-
-- if (biBitCount == 24) {
-+ if (biBitCount > 8) {
- pinfo->pic = pic24;
- pinfo->type = PIC24;
- }
-@@ -233,6 +292,22 @@
- cmpstr = "";
- if (biCompression == BI_RLE4) cmpstr = ", RLE4 compressed";
- else if (biCompression == BI_RLE8) cmpstr = ", RLE8 compressed";
-+ else if (biCompression == BI_BITFIELDS) {
-+ int bit, c[3], i;
-+ u_int mask;
-+
-+ for (i = 0; i < 3; ++i) {
-+ mask = colormask[i];
-+ c[i] = 0;
-+ for (bit = 0; bit < 32; ++bit) {
-+ if (mask & 1)
-+ ++c[i];
-+ mask >>= 1;
-+ }
-+ }
-+ sprintf(rgb_bits, ", RGB%d%d%d", c[0], c[1], c[2]);
-+ cmpstr = rgb_bits;
-+ }
-
- pinfo->w = biWidth; pinfo->h = biHeight;
- pinfo->normw = pinfo->w; pinfo->normh = pinfo->h;
-@@ -254,7 +329,7 @@
- ERROR:
- fclose(fp);
- return 0;
--}
-+}
-
-
- /*******************************************/
-@@ -264,12 +339,13 @@
- u_int w,h;
- {
- int i,j,c,bitnum,padw;
-- byte *pp;
-+ byte *pp = pic8 + ((h - 1) * w);
-+ size_t l = w*h;
-
- c = 0;
- padw = ((w + 31)/32) * 32; /* 'w', padded to be a multiple of 32 */
-
-- for (i=h-1; i>=0; i--) {
-+ for (i=h-1; i>=0 && (pp - pic8 <= l); i--) {
- pp = pic8 + (i * w);
- if ((i&0x3f)==0) WaitCursor();
- for (j=bitnum=0; j=0; i--) {
-+
-+ for (i=h-1; i>=0 && (pp - pic8 <= l); i--) {
- pp = pic8 + (i * w);
- if ((i&0x3f)==0) WaitCursor();
--
-+
- for (j=nybnum=0; j> 4;
- c <<= 4;
-@@ -325,55 +401,55 @@
- if (FERROR(fp)) break;
- }
- }
--
-+
- else if (comp == BI_RLE4) { /* read RLE4 compressed data */
-- x = y = 0;
-+ x = y = 0;
- pp = pic8 + x + (h-y-1)*w;
--
-+
- while (y>4)&0x0f);
- }
--
-+
- else { /* c==0x00 : escape codes */
- c = getc(fp); if (c == EOF) { rv = 1; break; }
--
-+
- if (c == 0x00) { /* end of line */
- x=0; y++; pp = pic8 + x + (h-y-1)*w;
-- }
--
-+ }
-+
- else if (c == 0x01) break; /* end of pic8 */
--
-+
- else if (c == 0x02) { /* delta */
- c = getc(fp); x += c;
- c = getc(fp); y += c;
- pp = pic8 + x + (h-y-1)*w;
- }
--
-+
- else { /* absolute mode */
-- for (i=0; i>4)&0x0f);
- }
--
-+
- if (((c&3)==1) || ((c&3)==2)) getc(fp); /* read pad byte */
- }
- } /* escape processing */
- if (FERROR(fp)) break;
- } /* while */
- }
--
-+
- else {
- fprintf(stderr,"unknown BMP compression type 0x%0x\n", comp);
- }
--
-+
- if (FERROR(fp)) rv = 1;
- return rv;
--}
-+}
-
-
-
-@@ -384,14 +460,18 @@
- u_int w,h,comp;
- {
- int i,j,c,c1,padw,x,y,rv;
-- byte *pp;
--
-+ byte *pp = pic8 + ((h - 1) * w);
-+ size_t l = w*h;
-+ byte *pend;
-+
- rv = 0;
-
-+ pend = pic8 + w * h;
-+
- if (comp == BI_RGB) { /* read uncompressed data */
- padw = ((w + 3)/4) * 4; /* 'w' padded to a multiple of 4pix (32 bits) */
-
-- for (i=h-1; i>=0; i--) {
-+ for (i=h-1; i>=0 && (pp - pic8 <= l); i--) {
- pp = pic8 + (i * w);
- if ((i&0x3f)==0) WaitCursor();
-
-@@ -404,15 +484,15 @@
- }
-
- else if (comp == BI_RLE8) { /* read RLE8 compressed data */
-- x = y = 0;
-+ x = y = 0;
- pp = pic8 + x + (h-y-1)*w;
-
-- while (y>= 1;
-+ }
-+ bitshift[i+3] = bitshift[i] + 16;
-+
-+ colorbits[i] = 0;
-+ for (; bit < 32; ++bit) {
-+ if (buf & 1)
-+ ++colorbits[i];
-+ else
-+ break;
-+ buf >>= 1;
-+ }
-+ if (colorbits[i] > 8) { /* over 8-bit depth */
-+ bitshift[i] += (colorbits[i] - 8);
-+ bitshift[i+3] = bitshift[i] + 16;
-+ bitshift2[i] = bitshift2[i+3] = 0;
-+ } else
-+ bitshift2[i] = bitshift2[i+3] = 8 - colorbits[i];
-+ }
-+ }
-+
-+ if (DEBUG > 1)
-+ fprintf(stderr, "loadBMP16: bitfields\n"
-+ "\tR: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
-+ "\t (mask = %08x, shift >>%2d, <<%2d)\n"
-+ "\tG: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
-+ "\t (mask = %08x, shift >>%2d, <<%2d)\n"
-+ "\tB: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
-+ "\t (mask = %08x, shift >>%2d, <<%2d)\n",
-+ colorbits[0], colormask[0], bitshift[0], bitshift2[0],
-+ colormask[3], bitshift[3], bitshift2[3],
-+ colorbits[1], colormask[1], bitshift[1], bitshift2[1],
-+ colormask[4], bitshift[4], bitshift2[4],
-+ colorbits[2], colormask[2], bitshift[2], bitshift2[2],
-+ colormask[5], bitshift[5], bitshift2[5]);
-+
-+ for (y = h-1; y >= 0 && (pp - pic24 <= l); y--) {
-+ pp = pic24 + (3 * w * y);
-+ if ((y&0x3f)==0) WaitCursor();
-+
-+ for (x = w; x > 1; x -= 2) {
-+ buf = getint(fp);
-+ *(pp++) = (buf & colormask[0]) >> bitshift[0] << bitshift2[0];
-+ *(pp++) = (buf & colormask[1]) >> bitshift[1] << bitshift2[1];
-+ *(pp++) = (buf & colormask[2]) >> bitshift[2] << bitshift2[2];
-+ *(pp++) = (buf & colormask[3]) >> bitshift[3] << bitshift2[3];
-+ *(pp++) = (buf & colormask[4]) >> bitshift[4] << bitshift2[4];
-+ *(pp++) = (buf & colormask[5]) >> bitshift[5] << bitshift2[5];
-+ }
-+ if (w & 1) { /* padded to 2 pix */
-+ buf = getint(fp);
-+ *(pp++) = (buf & colormask[0]) >> bitshift[0];
-+ *(pp++) = (buf & colormask[1]) >> bitshift[1];
-+ *(pp++) = (buf & colormask[2]) >> bitshift[2];
-+ }
-+ }
-+
-+ return FERROR(fp)? 1 : 0;
-+}
-+
-+
-+
-+/*******************************************/
-+static int loadBMP24(fp, pic24, w, h, bits) /* also handles 32-bit BI_RGB */
- FILE *fp;
- byte *pic24;
-- u_int w,h;
-+ u_int w,h, bits;
- {
- int i,j,padb,rv;
-- byte *pp;
-+ byte *pp = pic24 + ((h - 1) * w * 3);
-+ size_t l = w*h*3;
-
- rv = 0;
-
- padb = (4 - ((w*3) % 4)) & 0x03; /* # of pad bytes to read at EOscanline */
-+ if (bits==32) padb = 0;
-
- for (i=h-1; i>=0; i--) {
- pp = pic24 + (i * w * 3);
- if ((i&0x3f)==0) WaitCursor();
--
-- for (j=0; j>= 1;
-+ }
-+
-+ colorbits[i] = 0;
-+ for (; bit < 32; ++bit) {
-+ if (buf & 1)
-+ ++colorbits[i];
-+ else
-+ break;
-+ buf >>= 1;
-+ }
-+ if (colorbits[i] > 8) { /* over 8-bit depth */
-+ bitshift[i] += (colorbits[i] - 8);
-+ bitshift2[i] = 0;
-+ } else
-+ bitshift2[i] = 8 - colorbits[i];
-+ }
-+
-+ if (DEBUG > 1)
-+ fprintf(stderr, "loadBMP32: bitfields\n"
-+ "\tR: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
-+ "\tG: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n"
-+ "\tB: bits = %2d, mask = %08x, shift >>%2d, <<%2d\n",
-+ colorbits[0], colormask[0], bitshift[0], bitshift2[0],
-+ colorbits[1], colormask[1], bitshift[1], bitshift2[1],
-+ colorbits[2], colormask[2], bitshift[2], bitshift2[2]);
-+
-+ for (y = h-1; y >= 0; y--) {
-+ pp = pic24 + (3 * w * y);
-+ if ((y&0x3f)==0) WaitCursor();
-+
-+ for(x = w; x > 0; x --) {
-+ buf = getint(fp);
-+ *(pp++) = (buf & colormask[0]) >> bitshift[0] << bitshift2[0];
-+ *(pp++) = (buf & colormask[1]) >> bitshift[1] << bitshift2[1];
-+ *(pp++) = (buf & colormask[2]) >> bitshift[2] << bitshift2[2];
-+ }
-+ }
-+
-+ return FERROR(fp)? 1 : 0;
-+}
-
-
-
- /*******************************************/
--static unsigned int getshort(fp)
-+static u_int getshort(fp)
- FILE *fp;
- {
- int c, c1;
- c = getc(fp); c1 = getc(fp);
-- return ((unsigned int) c) + (((unsigned int) c1) << 8);
-+ return ((u_int) c) + (((u_int) c1) << 8);
- }
-
-
- /*******************************************/
--static unsigned int getint(fp)
-+static u_int getint(fp)
- FILE *fp;
- {
- int c, c1, c2, c3;
- c = getc(fp); c1 = getc(fp); c2 = getc(fp); c3 = getc(fp);
-- return ((unsigned int) c) +
-- (((unsigned int) c1) << 8) +
-- (((unsigned int) c2) << 16) +
-- (((unsigned int) c3) << 24);
-+ return ((u_int) c) +
-+ (((u_int) c1) << 8) +
-+ (((u_int) c2) << 16) +
-+ (((u_int) c3) << 24);
- }
-
-
-@@ -518,7 +769,7 @@
- {
- int c, c1;
-
-- c = ((unsigned int ) i) & 0xff; c1 = (((unsigned int) i)>>8) & 0xff;
-+ c = ((u_int) i) & 0xff; c1 = (((u_int) i)>>8) & 0xff;
- putc(c, fp); putc(c1,fp);
- }
-
-@@ -529,10 +780,10 @@
- int i;
- {
- int c, c1, c2, c3;
-- c = ((unsigned int ) i) & 0xff;
-- c1 = (((unsigned int) i)>>8) & 0xff;
-- c2 = (((unsigned int) i)>>16) & 0xff;
-- c3 = (((unsigned int) i)>>24) & 0xff;
-+ c = ((u_int) i) & 0xff;
-+ c1 = (((u_int) i)>>8) & 0xff;
-+ c2 = (((u_int) i)>>16) & 0xff;
-+ c3 = (((u_int) i)>>24) & 0xff;
-
- putc(c, fp); putc(c1,fp); putc(c2,fp); putc(c3,fp);
- }
-@@ -562,11 +813,11 @@
- * 8-bit image
- * note that PIC24 and F_BWDITHER/F_REDUCED won't happen
- *
-- * if colorstyle == F_BWDITHER, it writes a 1-bit image
-+ * if colorstyle == F_BWDITHER, it writes a 1-bit image
- *
- */
-
-- int i,j, nc, nbits, bperlin, cmaplen;
-+ int i,j, nc, nbits, bperlin, cmaplen, npixels;
- byte *graypic, *sp, *dp, graymap[256];
-
- nc = nbits = cmaplen = 0;
-@@ -576,10 +827,16 @@
- /* generate a faked 8-bit per pixel image with a grayscale cmap,
- so that it can just fall through existing 8-bit code */
-
-- graypic = (byte *) malloc((size_t) w*h);
-+ npixels = w * h;
-+ if (w <= 0 || h <= 0 || npixels/w != h) {
-+ SetISTR(ISTR_WARNING, "image dimensions too large");
-+ return -1;
-+ }
-+
-+ graypic = (byte *) malloc((size_t) npixels);
- if (!graypic) FatalError("unable to malloc in WriteBMP()");
-
-- for (i=0,sp=pic824,dp=graypic; i=0; i--) {
-- pp = pic8 + (i * w);
-+ pp = pic8 + (i * w);
- if ((i&0x3f)==0) WaitCursor();
-
- for (j=bitnum=c=0; j<=padw; j++,bitnum++) {
-@@ -716,7 +973,7 @@
- putc(c,fp);
- bitnum = c = 0;
- }
--
-+
- c <<= 1;
-
- if (j /* access() */
-
- #if defined(VMS) || defined(isc)
- typedef unsigned int mode_t; /* file mode bits */
- #endif
-
-+#ifndef MAX
-+# define MAX(a,b) (((a)>(b))?(a):(b)) /* used only for wheelmouse support */
-+#endif
-+
-
- /* load up built-in icons */
- #include "bits/br_file"
-@@ -34,27 +39,40 @@
- #include "bits/br_sock"
- #include "bits/br_fifo"
- #include "bits/br_error"
--#include "bits/br_unknown"
-+/* #include "bits/br_unknown" commented out (near line 492) */
-+
- #include "bits/br_cmpres"
-+#include "bits/br_bzip2"
-
--#include "bits/br_gif"
--#include "bits/br_pm"
--#include "bits/br_pbm"
--#include "bits/br_xbm"
--#include "bits/br_sunras"
- #include "bits/br_bmp"
--#include "bits/br_utah"
-+#include "bits/br_fits"
-+#include "bits/br_gif"
-+#include "bits/br_iff"
- #include "bits/br_iris"
--#include "bits/br_pcx"
- #include "bits/br_jfif"
--#include "bits/br_tiff"
-+#include "bits/br_jp2"
-+#include "bits/br_jpc"
-+#include "bits/br_mag"
-+#include "bits/br_maki"
-+#include "bits/br_mgcsfx"
-+#include "bits/br_pbm"
-+#include "bits/br_pcd"
-+#include "bits/br_pcx"
- #include "bits/br_pds"
-+#include "bits/br_pi"
-+#include "bits/br_pic"
-+#include "bits/br_pic2"
-+#include "bits/br_pm"
-+#include "bits/br_png"
- #include "bits/br_ps"
--#include "bits/br_iff"
-+#include "bits/br_sunras"
- #include "bits/br_targa"
-+#include "bits/br_tiff"
-+#include "bits/br_utah"
-+#include "bits/br_xbm"
- #include "bits/br_xpm"
- #include "bits/br_xwd"
--#include "bits/br_fits"
-+#include "bits/br_zx" /* [JCE] The Spectrum+3 icon */
-
- #include "bits/br_trash"
- #include "bits/fcurs"
-@@ -90,17 +108,28 @@
- #define BF_COMPRESS 21
- #define BF_PS 22
- #define BF_IFF 23
--#define BF_TARGA 24
-+#define BF_TGA 24
- #define BF_XPM 25
- #define BF_XWD 26
- #define BF_FITS 27
--#define BF_MAX 28 /* # of built-in icons */
-+#define BF_PNG 28
-+#define BF_ZX 29 /* [JCE] Spectrum SCREEN$ */
-+#define BF_PCD 30
-+#define BF_BZIP2 31
-+#define BF_JP2 32
-+#define BF_JPC 33
-+#define JP_EXT_BF (BF_JPC)
-+#define BF_MAG (JP_EXT_BF + 1)
-+#define BF_MAKI (JP_EXT_BF + 2)
-+#define BF_PIC (JP_EXT_BF + 3)
-+#define BF_PI (JP_EXT_BF + 4)
-+#define BF_PIC2 (JP_EXT_BF + 5)
-+#define BF_MGCSFX (JP_EXT_BF + 6)
-+#define JP_EXT_BF_END (BF_MGCSFX)
-+#define BF_MAX (JP_EXT_BF_END + 1) /* # of built-in icons */
-
- #define ISLOADABLE(ftyp) (ftyp!=BF_DIR && ftyp!=BF_CHR && ftyp!=BF_BLK && \
-- ftyp!=BF_SOCK && ftyp!=BF_FIFO)
--
--#define DEF_BROWWIDE 615 /* default size of window */
--#define DEF_BROWHIGH 356
-+ ftyp!=BF_SOCK && ftyp!=BF_FIFO)
-
- #define SCROLLVERT 8 /* height of scroll region at top/bottom of iconw */
- #define PAGEVERT 40 /* during rect drag, if further than this, page */
-@@ -113,59 +142,93 @@
- #define BOTMARGIN 58 /* room for a row of buttons and a line of text */
- #define LRMARGINS 5 /* left and right margins */
-
--#define ISIZE_WIDE 80 /* maximum size of an icon */
--#define ISIZE_HIGH 60
-+/* some people like bigger icons; 4:3 aspect ratio is recommended
-+ * (NOTE: standard XV binaries will not be able to read larger icons!) */
-+#ifndef ISIZE_WIDE
-+# define ISIZE_WIDE 80 /* maximum size of an icon */
-+#endif
-+#ifndef ISIZE_HIGH
-+# define ISIZE_HIGH 60
-+#endif
-+
-+#ifndef ISIZE_WPAD
-+# define ISIZE_WPAD 16 /* extra horizontal padding between icons */
-+#endif
-+
-+#ifndef INUM_WIDE
-+# define INUM_WIDE 6 /* size initial window to hold this many icons */
-+#endif
-+#ifndef INUM_HIGH
-+# define INUM_HIGH 3
-+#endif
-
--#define ISPACE_WIDE (ISIZE_WIDE+16) /* icon spacing */
-+#define ISPACE_WIDE (ISIZE_WIDE+ISIZE_WPAD) /* icon spacing */
- #define ISPACE_TOP 4 /* dist btwn top of ISPACE and ISIZE */
- #define ISPACE_TTOP 4 /* dist btwn bot of icon and title */
- #define ISPACE_HIGH (ISIZE_HIGH+ISPACE_TOP+ISPACE_TTOP+16+4)
-
- #define DBLCLICKTIME 300 /* milliseconds */
-
--/* button/menu indicies */
--#define BR_CHDIR 0
--#define BR_DELETE 1
--#define BR_MKDIR 2
--#define BR_RENAME 3
--#define BR_RESCAN 4
--#define BR_UPDATE 5
--#define BR_NEWWIN 6
--#define BR_GENICON 7
--#define BR_SELALL 8
--#define BR_TEXTVIEW 9
--#define BR_RECURSUP 10
--#define BR_QUIT 11
--#define BR_CLOSE 12
--#define BR_NBUTTS 13 /* # of command buttons */
--#define BR_SEP1 13 /* separator */
--#define BR_HIDDEN 14
--#define BR_SELFILES 15
--#define BR_NCMDS 16 /* # of menu commands */
-+#define COUNT(x) (sizeof (x) / sizeof (x)[0])
-+
-+/* button/menu indices */
-+#define BR_CHDIR 0
-+#define BR_DELETE 1
-+#define BR_MKDIR 2
-+#define BR_RENAME 3
-+#define BR_RESCAN 4
-+#define BR_UPDATE 5
-+#define BR_NEWWIN 6
-+#define BR_GENICON 7
-+#define BR_SELALL 8
-+#define BR_TEXTVIEW 9
-+#define BR_RECURSUP 10
-+#define BR_QUIT 11
-+#define BR_CLOSE 12
-+#define BR_NBUTTS 13 /* # of command buttons */
-+#define BR_SEP1 13 /* separator */
-+#define BR_HIDDEN 14
-+#define BR_SELFILES 15
-+#define BR_CLIPBRD 16
-+#ifdef AUTO_EXPAND
-+# define BR_CLEARVD 17
-+# define BR_NCMDS 18 /* # of menu commands */
-+#else
-+# define BR_NCMDS 17 /* # of menu commands */
-+#endif
-
- #define BUTTW 80
- #define BUTTH 24
-
--static char *showHstr = "Show hidden files";
--static char *hideHstr = "Hide 'hidden' files";
--
--static char *cmdMList[] = { "Change directory...\t^c",
-- "Delete file(s)\t^d",
-- "New directory...\t^n",
-- "Rename file...\t^r",
-- "Rescan directory\t^s",
-- "Update icons\t^u",
-- "Open new window\t^w",
-- "Generate icon(s)\t^g",
-- "Select all files\t^a",
-- "Text view\t^t",
-- "Recursive Update\t^e",
-- "Quit xv\t^q",
-- "Close window\t^c",
-- MBSEP,
-- "Show hidden files", /* no equiv */
-- "Select files...\t^f"
-- };
-+/* original size of window was 615 x 356 (for 80x60 thumbnails in 6x3 array) */
-+#define DEF_BROWWIDE (ISPACE_WIDE * INUM_WIDE + LRMARGINS * 2 + 29)
-+#define DEF_BROWHIGH (ISPACE_HIGH * INUM_HIGH + BUTTH * 2 + 16 + 28)
-+/* last number is a fudge--e.g., extra spaces, borders, etc. -----^ */
-+
-+static const char *showHstr = "Show hidden files";
-+static const char *hideHstr = "Hide 'hidden' files";
-+
-+static const char *cmdMList[] = { "Change directory...\t^c",
-+ "Delete file(s)\t^d",
-+ "New directory...\t^n",
-+ "Rename file...\t^r",
-+ "Rescan directory\t^s",
-+ "Update icons\t^u",
-+ "Open new window\t^w",
-+ "Generate icon(s)\t^g",
-+ "Select all files\t^a",
-+ "Text view\t^t",
-+ "Recursive Update\t^e",
-+ "Quit xv\t^q",
-+ "Close window\t^c",
-+ MBSEP,
-+ "Show hidden files", /* no equiv */
-+ "Select files...\t^f",
-+ "Clipboard\t^x"
-+#ifdef AUTO_EXPAND
-+ , "Clear virtual directory"
-+#endif
-+ };
-
-
- #define MAXDEEP 30 /* maximum directory depth */
-@@ -183,32 +246,43 @@
- } BFIL;
-
- /* data needed per schnauzer window */
--typedef struct { Window win, iconW;
-- int vis, wasvis;
-+typedef struct { Window win, iconW;
-+ int vis, wasvis;
-
-- int wide, high;
-- int iwWide, iwHigh;
-- int numWide, numHigh, visHigh;
--
-- SCRL scrl;
-- BUTT but[BR_NBUTTS];
-- MBUTT dirMB, cmdMB;
-- char dispstr[256];
-- int numbutshown;
-- int showhidden;
--
-- int numlit;
-- BFIL *bfList;
-- int bfLen;
-- int lastIconClicked;
-+ int wide, high;
-+ int iwWide, iwHigh;
-+ int numWide, numHigh, visHigh;
-+
-+ SCRL scrl;
-+ BUTT but[BR_NBUTTS];
-+ MBUTT dirMB, cmdMB;
-+ char dispstr[256];
-+ int numbutshown;
-+ int showhidden;
-+
-+ int numlit;
-+ BFIL *bfList;
-+ int bfLen;
-+ int lastIconClicked;
- unsigned long lastClickTime;
-
-- int ndirs;
-- char *mblist[MAXDEEP];
-- char path[MAXPATHLEN+2]; /* '/' terminated */
-+ int ndirs;
-+ const char *mblist[MAXDEEP];
-+ char path[MAXPATHLEN+2]; /* '/' terminated */
-+
-+ char *str;
-+ int siz, len;
-+ time_t lst;
- } BROWINFO;
-
-
-+/* keep track of last icon visible in each path */
-+typedef struct IVIS IVIS;
-+ struct IVIS { IVIS *next;
-+ char *name;
-+ int icon;
-+ };
-+
- static Cursor movecurs, copycurs, delcurs;
- static BROWINFO binfo[MAXBRWIN];
- static Pixmap bfIcons[BF_MAX], trashPix;
-@@ -220,7 +294,7 @@
- static void closeBrowse PARM((BROWINFO *));
- static int brChkEvent PARM((BROWINFO *, XEvent *));
- static void resizeBrowse PARM((BROWINFO *, int, int));
--static void setBrowStr PARM((BROWINFO *, char *));
-+static void setBrowStr PARM((BROWINFO *, const char *));
- static void doCmd PARM((BROWINFO *, int));
- static void drawBrow PARM((BROWINFO *));
- static void drawNumfiles PARM((BROWINFO *));
-@@ -255,12 +329,12 @@
- static void rescanDir PARM((BROWINFO *));
- static int namcmp PARM((const void *, const void *));
- static void freeBfList PARM((BROWINFO *br));
--static char **getDirEntries PARM((char *, int *, int));
-+static char **getDirEntries PARM((const char *, int *, int));
- static void computeScrlVals PARM((BROWINFO *, int *, int *));
- static void genSelectedIcons PARM((BROWINFO *));
- static void genIcon PARM((BROWINFO *, BFIL *));
- static void loadThumbFile PARM((BROWINFO *, BFIL *));
--static void writeThumbFile PARM((BROWINFO *, BFIL *, byte *, int,
-+static void writeThumbFile PARM((BROWINFO *, BFIL *, byte *, int,
- int, char *));
-
- static void makeThumbDir PARM((BROWINFO *));
-@@ -278,14 +352,14 @@
- static void doSelFilesCmd PARM((BROWINFO *));
-
- static void doRecurseCmd PARM((BROWINFO *));
--static void recurseUpdate PARM((BROWINFO *, char *));
-+static void recurseUpdate PARM((BROWINFO *, const char *));
-
- static void rm_file PARM((BROWINFO *, char *));
- static void rm_dir PARM((BROWINFO *, char *));
- static void rm_dir1 PARM((BROWINFO *));
-
--static void dragFiles PARM((BROWINFO *, BROWINFO *, char *, char *,
-- char *, char **, int, int));
-+static void dragFiles PARM((BROWINFO *, BROWINFO *, char *, char *,
-+ const char *, char **, int, int));
- static int moveFile PARM((char *, char *));
- static int copyFile PARM((char *, char *));
- static void cp PARM((void));
-@@ -294,16 +368,25 @@
- static void cp_special PARM((struct stat *, int));
- static void cp_fifo PARM((struct stat *, int));
-
-+#ifdef AUTO_EXPAND
-+static int stat2bf PARM((u_int, char *));
-+#else
- static int stat2bf PARM((u_int));
-+#endif
-
- static int selmatch PARM((char *, char *));
- static int selmatch1 PARM((char *, char *));
-+static void recIconVisible PARM((char *, int));
-+static void restIconVisible PARM((BROWINFO *));
-+
-+static void clipChanges PARM((BROWINFO *));
-
-
-
- /***************************************************************/
- void CreateBrowse(geom, fgstr, bgstr, histr, lostr)
-- char *geom, *fgstr, *bgstr, *histr, *lostr;
-+ const char *geom;
-+ const char *fgstr, *bgstr, *histr, *lostr;
- {
- int i;
- XSizeHints hints;
-@@ -369,8 +452,8 @@
- if (gset & YNegative) gy1 = gy - i * 20;
- else gy1 = gy + i * 20;
-
-- if ((gset & WidthValue) && (gset & HeightValue))
-- sprintf(wgeom, "%dx%d%s%d%s%d", gw, gh,
-+ if ((gset & WidthValue) && (gset & HeightValue))
-+ sprintf(wgeom, "%dx%d%s%d%s%d", gw, gh,
- (gset & XNegative) ? "-" : "+", abs(gx1),
- (gset & YNegative) ? "-" : "+", abs(gy1));
- else
-@@ -402,11 +485,11 @@
-
- /* note: everything is sized and positioned in ResizeBrowse() */
-
-- br->iconW = XCreateSimpleWindow(theDisp, br->win, 1,1, 100,100,
-+ br->iconW = XCreateSimpleWindow(theDisp, br->win, 1,1, 100,100,
- 1,browfg,browbg);
- if (!br->iconW) FatalError("can't create schnauzer icon window!");
-
-- SCCreate(&(br->scrl), br->win, 0,0, 1,100, 0,0,0,0,
-+ SCCreate(&(br->scrl), br->win, 0,0, 1,100, 0,0,0,0,
- browfg, browbg, browhi, browlo, drawIconWin);
-
-
-@@ -448,10 +531,12 @@
- "Text view",browfg,browbg,browhi,browlo);
- BTCreate(&(br->but[BR_RECURSUP]), br->win, 0,0,BUTTW,BUTTH,
- "RecursUpd",browfg,browbg,browhi,browlo);
-- BTCreate(&(br->but[BR_QUIT]), br->win, 0,0,BUTTW,BUTTH,
-+ BTCreate(&(br->but[BR_QUIT]), br->win, 0,0,BUTTW,BUTTH,
- "Quit xv",browfg,browbg,browhi,browlo);
-- BTCreate(&(br->but[BR_CLOSE]), br->win, 0,0,BUTTW,BUTTH,
-+ BTCreate(&(br->but[BR_CLOSE]), br->win, 0,0,BUTTW,BUTTH,
- "Close",browfg,browbg,browhi,browlo);
-+ BTCreate(&(br->but[BR_CLIPBRD]), br->win, 0,0,BUTTW,BUTTH,
-+ "Clipboard",browfg,browbg,browhi,browlo);
-
- XMapSubwindows(theDisp, br->win);
-
-@@ -486,55 +571,62 @@
- bfIcons[BF_SOCK]=MakePix1(br->win,br_sock_bits,br_sock_width,br_sock_height);
- bfIcons[BF_FIFO]=MakePix1(br->win,br_fifo_bits,br_fifo_width,br_fifo_height);
-
-- bfIcons[BF_ERROR] = MakePix1(br->win, br_error_bits,
-+ bfIcons[BF_ERROR] = MakePix1(br->win, br_error_bits,
- br_error_width, br_error_height);
-
- /* bfIcons[BF_UNKNOWN] = MakePix1(br->win, br_unknown_bits,
- br_unknown_width, br_unknown_height); */
--
- bfIcons[BF_UNKNOWN] = bfIcons[BF_FILE];
-
-- bfIcons[BF_GIF] =MakePix1(br->win,br_gif_bits, br_gif_width, br_gif_height);
-- bfIcons[BF_PM] =MakePix1(br->win,br_pm_bits, br_pm_width, br_pm_height);
-- bfIcons[BF_PBM] =MakePix1(br->win,br_pbm_bits, br_pbm_width, br_pbm_height);
-- bfIcons[BF_XBM] =MakePix1(br->win,br_xbm_bits, br_xbm_width, br_xbm_height);
--
-- bfIcons[BF_SUNRAS] = MakePix1(br->win, br_sunras_bits,
-- br_sunras_width, br_sunras_height);
-- bfIcons[BF_BMP] = MakePix1(br->win,br_bmp_bits,
-- br_bmp_width, br_bmp_height);
-- bfIcons[BF_UTAHRLE] = MakePix1(br->win, br_utahrle_bits,
-- br_utahrle_width, br_utahrle_height);
-+ bfIcons[BF_COMPRESS] = MakePix1(br->win, br_cmpres_bits,
-+ br_cmpres_width, br_cmpres_height);
-+ bfIcons[BF_BZIP2] = MakePix1(br->win, br_bzip2_bits,
-+ br_bzip2_width, br_bzip2_height);
-
-+ bfIcons[BF_BMP] =MakePix1(br->win,br_bmp_bits, br_bmp_width, br_bmp_height);
-+ bfIcons[BF_FITS]=MakePix1(br->win,br_fits_bits,br_fits_width,br_fits_height);
-+ bfIcons[BF_GIF] =MakePix1(br->win,br_gif_bits, br_gif_width, br_gif_height);
-+ bfIcons[BF_IFF] =MakePix1(br->win,br_iff_bits, br_iff_width, br_iff_height);
- bfIcons[BF_IRIS]=MakePix1(br->win,br_iris_bits,br_iris_width,br_iris_height);
-- bfIcons[BF_PCX] =MakePix1(br->win,br_pcx_bits, br_pcx_width, br_pcx_height);
- bfIcons[BF_JFIF]=MakePix1(br->win,br_jfif_bits,br_jfif_width,br_jfif_height);
-- bfIcons[BF_TIFF]=MakePix1(br->win,br_tiff_bits,br_tiff_width,br_tiff_height);
-+ bfIcons[BF_JP2] =MakePix1(br->win,br_jp2_bits, br_jp2_width, br_jp2_height);
-+ bfIcons[BF_JPC] =MakePix1(br->win,br_jpc_bits, br_jpc_width, br_jpc_height);
-+ bfIcons[BF_MAG] =MakePix1(br->win,br_mag_bits, br_mag_width, br_mag_height);
-+ bfIcons[BF_MAKI]=MakePix1(br->win,br_maki_bits,br_maki_width,br_maki_height);
-+ bfIcons[BF_PBM] =MakePix1(br->win,br_pbm_bits, br_pbm_width, br_pbm_height);
-+ bfIcons[BF_PCD] =MakePix1(br->win,br_pcd_bits, br_pcd_width, br_pcd_height);
-+ bfIcons[BF_PCX] =MakePix1(br->win,br_pcx_bits, br_pcx_width, br_pcx_height);
- bfIcons[BF_PDS] =MakePix1(br->win,br_pds_bits, br_pds_width, br_pds_height);
--
-- bfIcons[BF_COMPRESS]= MakePix1(br->win, br_cmpres_bits,
-- br_cmpres_width, br_cmpres_height);
--
-+ bfIcons[BF_PIC2]=MakePix1(br->win,br_pic2_bits,br_pic2_width,br_pic2_height);
-+ bfIcons[BF_PIC] =MakePix1(br->win,br_pic_bits, br_pic_width, br_pic_height);
-+ bfIcons[BF_PI] =MakePix1(br->win,br_pi_bits, br_pi_width, br_pi_height);
-+ bfIcons[BF_PM] =MakePix1(br->win,br_pm_bits, br_pm_width, br_pm_height);
-+ bfIcons[BF_PNG] =MakePix1(br->win,br_png_bits, br_png_width, br_png_height);
- bfIcons[BF_PS] =MakePix1(br->win,br_ps_bits, br_ps_width, br_ps_height);
-- bfIcons[BF_IFF] =MakePix1(br->win,br_iff_bits, br_iff_width, br_iff_height);
--
-- bfIcons[BF_TARGA] = MakePix1(br->win, br_targa_bits,
-- br_targa_width, br_targa_height);
--
-+ bfIcons[BF_TGA] =MakePix1(br->win,br_tga_bits, br_tga_width, br_tga_height);
-+ bfIcons[BF_TIFF]=MakePix1(br->win,br_tiff_bits,br_tiff_width,br_tiff_height);
-+ bfIcons[BF_XBM] =MakePix1(br->win,br_xbm_bits, br_xbm_width, br_xbm_height);
- bfIcons[BF_XPM] =MakePix1(br->win,br_xpm_bits, br_xpm_width, br_xpm_height);
- bfIcons[BF_XWD] =MakePix1(br->win,br_xwd_bits, br_xwd_width, br_xwd_height);
-- bfIcons[BF_FITS]=MakePix1(br->win,br_fits_bits,br_fits_width,br_fits_height);
-+ bfIcons[BF_ZX] =MakePix1(br->win,br_zx_bits, br_zx_width, br_zx_height);
-+
-+ bfIcons[BF_SUNRAS] = MakePix1(br->win, br_sunras_bits,
-+ br_sunras_width, br_sunras_height);
-+ bfIcons[BF_UTAHRLE] = MakePix1(br->win, br_utahrle_bits,
-+ br_utahrle_width, br_utahrle_height);
-+ bfIcons[BF_MGCSFX] = MakePix1(br->win, br_mgcsfx_bits,
-+ br_mgcsfx_width, br_mgcsfx_height);
-
-
- /* check that they all got built */
- for (i=0; ivis) break;
- }
- if (i==MAXBRWIN) return; /* full up: shouldn't happen */
--
-+
- anyBrowUp = 1;
- XMapRaised(theDisp, br->win);
- br->vis = 1;
--
-+
- freeBfList(br);
-
- /* see if some browser is pointing to the same path as CWD. If so,
-@@ -645,7 +738,7 @@
- /* free all info for this browse window */
- freeBfList(br);
- sprintf(br->path, BOGUSPATH);
--
-+
- /* turn on 'open new window' command doodads */
- windowMB.dim[WMB_BROWSE] = 0;
- for (i=0; itype == Expose) {
- int x,y,w,h;
- XExposeEvent *e = (XExposeEvent *) xev;
- x = e->x; y = e->y; w = e->width; h = e->height;
-
- /* throw away excess redraws for 'dumb' windows */
-- if (e->count > 0 && (e->window == br->scrl.win)) {}
-+ if (e->count > 0 && (e->window == br->scrl.win))
-+ ;
-
-- else if (e->window == br->scrl.win) SCRedraw(&(br->scrl));
-+ else if (e->window == br->scrl.win)
-+ SCRedraw(&(br->scrl));
-
- else if (e->window == br->win || e->window == br->iconW) { /* smart wins */
- /* group individual expose rects into a single expose region */
-@@ -788,7 +897,7 @@
- fprintf(stderr,"grouped %d expose events into %d,%d %dx%d rect\n",
- count, rect.x, rect.y, rect.width, rect.height);
- }
--
-+
- if (e->window == br->win) drawBrow(br);
-
- else if (e->window == br->iconW)
-@@ -807,13 +916,55 @@
- int i,x,y;
- x = e->x; y = e->y;
-
-+#ifdef VS_RESCMAP
-+ if (browCmap && browPerfect && (_IfTempOut!=0)) {
-+ XSetWindowAttributes xswa;
-+ _IfTempOut--;
-+ xswa.colormap = browCmap;
-+ for(i=0;ibutton == Button1) {
- if (e->window == br->win) clickBrow(br,x,y);
- else if (e->window == br->scrl.win) SCTrack(&(br->scrl),x,y);
- else if (e->window == br->iconW) {
-- i = clickIconWin(br, x,y,(unsigned long) e->time,
-+ i = clickIconWin(br, x,y,(unsigned long) e->time,
- (e->state&ControlMask) || (e->state&ShiftMask));
--
-+ }
-+ else rv = 0;
-+ }
-+ else if (e->button == Button4) { /* note min vs. max, + vs. - */
-+ /* scroll regardless of where we are in the browser window */
-+ if (e->window == br->win ||
-+ e->window == br->scrl.win ||
-+ e->window == br->iconW)
-+ {
-+ SCRL *sp=&(br->scrl);
-+ int halfpage=MAX(1,sp->page/2); /* user resize to 1 line? */
-+
-+ if (sp->val > sp->min+halfpage)
-+ SCSetVal(sp,sp->val-halfpage);
-+ else
-+ SCSetVal(sp,sp->min);
-+ }
-+ else rv = 0;
-+ }
-+ else if (e->button == Button5) { /* note max vs. min, - vs. + */
-+ /* scroll regardless of where we are in the browser window */
-+ if (e->window == br->win ||
-+ e->window == br->scrl.win ||
-+ e->window == br->iconW)
-+ {
-+ SCRL *sp=&(br->scrl);
-+ int halfpage=MAX(1,sp->page/2); /* user resize to 1 line? */
-+
-+ if (sp->val < sp->max-halfpage)
-+ SCSetVal(sp,sp->val+halfpage);
-+ else
-+ SCSetVal(sp,sp->max);
- }
- else rv = 0;
- }
-@@ -837,7 +988,7 @@
-
- if (br->wide != e->width || br->high != e->height) {
- if (DEBUG) fprintf(stderr,"Forcing a redraw! (from configure)\n");
-- XClearArea(theDisp, br->win, 0, 0,
-+ XClearArea(theDisp, br->win, 0, 0,
- (u_int) e->width, (u_int) e->height, True);
- resizeBrowse(br, e->width, e->height);
- }
-@@ -877,7 +1028,7 @@
- int w,h;
- {
- XSizeHints hints;
-- int i, minv, maxv, curv, page, maxh;
-+ int i, maxv, page, maxh;
-
- if (br->wide == w && br->high == h) return; /* no change in size */
-
-@@ -895,7 +1046,7 @@
- br->iwHigh = (maxh / ISPACE_HIGH) * ISPACE_HIGH;
- if (br->iwHigh < ISPACE_HIGH) br->iwHigh = ISPACE_HIGH;
-
-- XMoveResizeWindow(theDisp, br->iconW, LRMARGINS, TOPMARGIN,
-+ XMoveResizeWindow(theDisp, br->iconW, LRMARGINS, TOPMARGIN,
- (u_int) br->iwWide, (u_int) br->iwHigh);
-
-
-@@ -907,11 +1058,11 @@
- for (i=0; inumbutshown)
-+ if (inumbutshown)
- br->but[i].x = br->wide - (1+br->numbutshown-i) * (BUTTW+5);
- else if (i==BR_CLOSE)
- br->but[i].x = br->wide - (BUTTW+5);
-- else
-+ else
- br->but[i].x = br->wide + 10; /* offscreen */
-
- br->but[i].y = br->high - BUTTH - 5;
-@@ -928,11 +1079,11 @@
- br->numWide = br->iwWide / ISPACE_WIDE;
- br->visHigh = br->iwHigh / ISPACE_HIGH;
-
-- /* compute minv,maxv,curv,page values based on new current size */
-+ /* compute maxv,page values based on new current size */
- computeScrlVals(br, &maxv, &page);
- if (br->scrl.val>maxv) br->scrl.val = maxv;
--
-- SCChange(&br->scrl, LRMARGINS+br->iwWide+1, TOPMARGIN,
-+
-+ SCChange(&br->scrl, LRMARGINS+br->iwWide+1, TOPMARGIN,
- 1, br->iwHigh, 0, maxv, br->scrl.val, page);
- }
-
-@@ -940,12 +1091,12 @@
-
- /***************************************************************/
- void SetBrowStr(str)
-- char *str;
-+ const char *str;
- {
- /* put string in *all* browse windows */
- int i;
-
-- for (i=0; idispstr, str, (size_t) 256);
-+ br->dispstr[255] = '\0';
- drawBrowStr(br);
- XFlush(theDisp);
- }
-@@ -992,7 +1144,7 @@
-
- char tmp[64];
-
-- sprintf(tmp, "Re-coloring icons: processed %d out of %d...",
-+ sprintf(tmp, "Re-coloring icons: processed %d out of %d...",
- i+1, br->bfLen);
- setBrowStr(br, tmp);
- }
-@@ -1011,14 +1163,14 @@
- {
- /* called when file 'name' has been deleted. If any of the browsers
- were showing the directory that the file was in, does a rescan() */
--
-+
- int i;
- char buf[MAXPATHLEN + 2], *tmp;
-
- strcpy(buf, name);
-- tmp = BaseName(buf);
-+ tmp = (char *) BaseName(buf); /* intentionally losing constness */
- *tmp = '\0'; /* truncate after last '/' */
--
-+
- for (i=0; ilst = 0;
-+
- switch (cmd) {
- case BR_CHDIR: doChdirCmd(br);
- break;
-@@ -1070,9 +1224,9 @@
- case BR_GENICON: genSelectedIcons(br); break;
-
- case BR_SELALL: {
-- int i; char buf[128];
-+ int i;
-
-- for (i=0; ibfLen; i++)
-+ for (i=0; ibfLen; i++)
- br->bfList[i].lit = 1;
- br->numlit = br->bfLen;
-
-@@ -1087,20 +1241,25 @@
- break;
-
- case BR_TEXTVIEW: doTextCmd(br); break;
--
-+
- case BR_QUIT: Quit(0); break;
-
- case BR_CLOSE: closeBrowse(br); break;
-
- case BR_HIDDEN: br->showhidden = !br->showhidden;
-- br->cmdMB.list[cmd] = (br->showhidden)
-- ? hideHstr : showHstr;
-+ br->cmdMB.list[cmd] = br->showhidden ? hideHstr : showHstr;
- rescanDir(br);
- break;
-
- case BR_SELFILES: doSelFilesCmd(br); break;
-
- case BR_RECURSUP: doRecurseCmd(br); break;
-+
-+ case BR_CLIPBRD: clipChanges(br); break;
-+
-+#ifdef AUTO_EXPAND
-+ case BR_CLEARVD: Vdsettle(); break;
-+#endif
- }
- }
-
-@@ -1137,16 +1296,16 @@
-
- if (br->bfLen != 1) sprintf(foo, "%d files", br->bfLen);
- else strcpy(foo, "1 file");
--
-+
- XSetForeground(theDisp, theGC, browbg);
-- XFillRectangle(theDisp,br->win, theGC, x+1,y+1,
-+ XFillRectangle(theDisp,br->win, theGC, x+1,y+1,
- (u_int) StringWidth(foo)+6, (u_int) br->dirMB.h-1);
-
- XSetForeground(theDisp,theGC,browfg);
- XDrawRectangle(theDisp,br->win, theGC, x,y,
- (u_int) StringWidth(foo)+7, (u_int) br->dirMB.h);
-
-- Draw3dRect(br->win, x+1, y+1, (u_int) StringWidth(foo)+5,
-+ Draw3dRect(br->win, x+1, y+1, (u_int) StringWidth(foo)+5,
- (u_int) br->dirMB.h-2, R3D_IN, 2, browhi, browlo, browbg);
-
- XSetForeground(theDisp,theGC,browfg);
-@@ -1163,7 +1322,7 @@
-
- if (nf != 1) sprintf(foo,"%d files",nf);
- else strcpy(foo,"1 file");
--
-+
- XClearArea(theDisp,br->win, 30, br->dirMB.y,
- (u_int) StringWidth(foo)+8, (u_int) br->dirMB.h+1, False);
- }
-@@ -1185,13 +1344,13 @@
-
- XSetForeground(theDisp,theGC,browfg);
- XDrawRectangle(theDisp,br->win, theGC, x,y, (u_int) w, (u_int) h);
-- Draw3dRect(br->win, x+1, y+1, (u_int) w-2, (u_int) h-2,
-+ Draw3dRect(br->win, x+1, y+1, (u_int) w-2, (u_int) h-2,
- R3D_IN, 2, browhi, browlo, browbg);
-
- XSetForeground(theDisp,theGC,browfg);
- XSetBackground(theDisp,theGC,browbg);
-- XCopyPlane(theDisp, trashPix, br->win, theGC,
-- 0,0,(u_int) br_trash_width, (u_int) br_trash_height,
-+ XCopyPlane(theDisp, trashPix, br->win, theGC,
-+ 0,0,(u_int) br_trash_width, (u_int) br_trash_height,
- x+(w-br_trash_width)/2, y+(h-br_trash_height)/2,
- 1L);
- }
-@@ -1222,7 +1381,7 @@
- y = br->high - (BUTTH+10) - (CHIGH + 6);
-
- XSetForeground(theDisp, theGC, browbg);
-- XFillRectangle(theDisp, br->win, theGC, 0, y+3,
-+ XFillRectangle(theDisp, br->win, theGC, 0, y+3,
- (u_int) br->wide, (u_int) CHIGH+1);
-
- XSetForeground(theDisp, theGC, browfg);
-@@ -1250,6 +1409,19 @@
- int i, allowtext;
-
- if (!nostr) setSelInfoStr(br, sel);
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(br->path)) {
-+ BTSetActive(&br->but[BR_DELETE], 0);
-+ br->cmdMB.dim[BR_DELETE] = 1;
-+
-+ BTSetActive(&br->but[BR_RENAME], 0);
-+ br->cmdMB.dim[BR_RENAME] = 1;
-+
-+ BTSetActive(&br->but[BR_MKDIR], 0);
-+ br->cmdMB.dim[BR_MKDIR] = 1;
-+ }
-+ else {
-+#endif
- BTSetActive(&br->but[BR_DELETE], br->numlit>0);
- br->cmdMB.dim[BR_DELETE] = !(br->numlit>0);
-
-@@ -1258,6 +1430,11 @@
-
- BTSetActive(&br->but[BR_GENICON], br->numlit>0);
- br->cmdMB.dim[BR_GENICON] = !(br->numlit>0);
-+#ifdef AUTO_EXPAND
-+ BTSetActive(&br->but[BR_MKDIR], 1);
-+ br->cmdMB.dim[BR_MKDIR] = 0;
-+ }
-+#endif
-
- /* turn on 'text view' cmd if exactly one non-dir is lit */
- allowtext = 0;
-@@ -1277,7 +1454,7 @@
- {
- /* sets the '# files selected' string in the brow window appropriately */
-
-- /* criteria:
-+ /* criteria:
- * if no files are lit, display ''
- * if 1 file is lit, pretend it was selected, fall through...
- * if 1 or more files are lit
-@@ -1316,10 +1493,13 @@
-
- else if (bf->ftype != BF_DIR) { /* no info. display file size */
- struct stat st;
--
-+
- sprintf(buf, "%s%s", br->path, bf->name); /* build filename */
-+#ifdef AUTO_EXPAND
-+ Dirtovd(buf);
-+#endif
- if (stat(buf, &st) == 0) {
-- sprintf(buf, "%s: %ld bytes", bf->name, st.st_size);
-+ sprintf(buf, "%s: %ld bytes", bf->name, (long)st.st_size);
- strcat(buf, buf1);
- }
- }
-@@ -1360,8 +1540,8 @@
- if (j>=0 && j < br->bfLen) drawIcon(br,j);
- }
- }
--
-- Draw3dRect(br->iconW, 0, 0, (u_int) br->iwWide-1, (u_int) br->iwHigh-1,
-+
-+ Draw3dRect(br->iconW, 0, 0, (u_int) br->iwWide-1, (u_int) br->iwHigh-1,
- R3D_IN, 2, browhi, browlo, browbg);
- }
-
-@@ -1371,10 +1551,8 @@
- int delta;
- SCRL *sptr;
- {
-- int i,indx, x,y, ix,iy, num;
-- BFIL *bf;
-+ int i,indx, num;
- BROWINFO *br;
-- char tmpstr[64], *nstr;
-
- /* figure out BROWINFO pointer from SCRL pointer */
- for (i=0; i br->iwHigh-4) h = (br->iwHigh-4)-y + 2;
- }
- XFillRectangle(theDisp, br->iconW, theGC, x, y, ISPACE_WIDE, (u_int) h);
--
-+
- if (indx>=0 && indx < br->bfLen) drawIcon(br, indx);
- }
- }
-
-- Draw3dRect(br->iconW, 0, 0, (u_int) br->iwWide-1, (u_int) br->iwHigh-1,
-+ Draw3dRect(br->iconW, 0, 0, (u_int) br->iwWide-1, (u_int) br->iwHigh-1,
- R3D_IN, 2, browhi, browlo, browbg);
- }
-
-@@ -1431,7 +1609,11 @@
- {
- int i,x,y,ix,iy,sw,sh,sx,sy;
- BFIL *bf;
-- char tmpstr[64], fixedname[64], *nstr, *str;
-+ const char *nstr, *cstr;
-+ char tmpstr[64];
-+#ifdef VMS
-+ char fixedname[64];
-+#endif
-
-
- if (num<0 || num >= br->bfLen) return;
-@@ -1463,49 +1645,51 @@
- }
-
- else if (bf->ftype == BF_HAVEIMG && bf->ximage) {
-- XPutImage(theDisp, br->iconW, theGC, bf->ximage, 0,0, ix,iy,
-+ XPutImage(theDisp, br->iconW, theGC, bf->ximage, 0,0, ix,iy,
- (u_int) bf->w, (u_int) bf->h);
- }
-
- else { /* shouldn't happen */
-- XDrawRectangle(theDisp, br->iconW, theGC, ix, iy,
-+ XDrawRectangle(theDisp, br->iconW, theGC, ix, iy,
- (u_int) bf->w, (u_int) bf->h);
- }
-
-
-- str = bf->name;
-+ cstr = bf->name;
- #ifdef VMS
- if (bf->ftype == BF_DIR) {
-+ char *vstr;
- strcpy(fixedname, bf->name);
-- str = rindex(fixedname, '.'); /* lop off '.DIR' suffix, if any */
-- if (str) *str = '\0';
-- str = fixedname;
-+ vstr = rindex(fixedname, '.'); /* lop off '.DIR' suffix, if any */
-+ if (vstr) *vstr = '\0';
-+ cstr = fixedname;
- }
- #endif /* VMS */
-
-- if (!strcmp(bf->name,"..")) str = "";
-+ if (!strcmp(bf->name,"..")) cstr = "";
-
-
- /* decide if the title is too big, and shorten if neccesary */
-- if (StringWidth(str) > ISPACE_WIDE-6) {
-- int dotpos;
-- strncpy(tmpstr, str, (size_t) 56);
-+ if (StringWidth(cstr) > ISPACE_WIDE-6) {
-+ int dotpos;
-+ strncpy(tmpstr, cstr, (size_t) 56);
-+ tmpstr[56] = '\0'; /* MR: otherwise it dies on long file names */
- dotpos = strlen(tmpstr);
- strcat(tmpstr,"...");
-
- while(StringWidth(tmpstr) > ISPACE_WIDE-6 && dotpos>0) {
- /* change last non-dot char in tmpstr to a dot, and lop off
- last dot */
--
-+
- dotpos--;
- tmpstr[dotpos] = '.';
- tmpstr[dotpos+3] = '\0';
- }
--
-+
- nstr = tmpstr;
- }
-- else nstr = str;
--
-+ else nstr = cstr;
-+
-
- /* draw the title */
- sw = StringWidth(nstr);
-@@ -1516,12 +1700,12 @@
-
- XSetForeground(theDisp, theGC,
- (bf->lit && bf->lit!=ICON_ONLY) ? browfg : browbg);
-- XFillRectangle(theDisp, br->iconW, theGC, sx, sy,
-+ XFillRectangle(theDisp, br->iconW, theGC, sx, sy,
- (u_int) sw + 4, (u_int) sh + 2);
-
- XSetForeground(theDisp, theGC,
- (bf->lit && bf->lit!=ICON_ONLY) ? browbg : browfg);
-- CenterString(br->iconW, x + ISPACE_WIDE/2,
-+ CenterString(br->iconW, x + ISPACE_WIDE/2,
- y + ISPACE_TOP + ISIZE_HIGH + ISPACE_TTOP + CHIGH/2, nstr);
- }
-
-@@ -1535,7 +1719,6 @@
-
- int i,x,y,ix,iy,w,h;
- BFIL *bf;
-- char tmpstr[64], *nstr;
-
- if (num<0 || num >= br->bfLen) return;
- bf = &(br->bfList[num]);
-@@ -1579,12 +1762,12 @@
- y = (i / br->numWide) * ISPACE_HIGH;
-
- XSetForeground(theDisp, theGC, browbg);
-- XFillRectangle(theDisp, br->iconW, theGC,
-+ XFillRectangle(theDisp, br->iconW, theGC,
- x, y + ISPACE_TOP + ISIZE_HIGH + ISPACE_TTOP - 1,
- (u_int) ISPACE_WIDE, (u_int) LINEHIGH);
-
-- if (ctrlColor)
-- Draw3dRect(br->iconW, 0, 0, (u_int) br->iwWide-1, (u_int) br->iwHigh-1,
-+ if (ctrlColor)
-+ Draw3dRect(br->iconW, 0, 0, (u_int) br->iwWide-1, (u_int) br->iwHigh-1,
- R3D_IN, 2, browhi, browlo, browbg);
- }
-
-@@ -1597,6 +1780,10 @@
- {
- int sval, first, numvis;
-
-+ /* if we know what path we have, remember last visible icon for this path */
-+ if (br->path)
-+ recIconVisible(br->path, num);
-+
- /* if icon #i isn't visible, adjust scrollbar so it *is* */
-
- sval = br->scrl.val;
-@@ -1648,29 +1835,14 @@
- return;
- }
-
--
- /***************************************************************/
--static int clickIconWin(br, mx, my, mtime, multi)
-- BROWINFO *br;
-- int mx,my,multi;
-- unsigned long mtime;
-+static int updateSel(br, sel, multi, mtime)
-+ BROWINFO *br;
-+ int sel, multi;
-+ unsigned long mtime;
- {
-- /* returns '-1' normally, returns an index into bfList[] if the user
-- double-clicks an icon */
--
-- int i,j, base, num, x,y,ix,iy, rv, sel, cpymode, dodel;
-- BROWINFO *destBr;
-- BFIL *bf;
-- char buf[256], *destFolderName;
--
-- rv = -1; /* default return value */
-- if (!br->bfList || !br->bfLen) return rv;
--
-- destBr = br; destFolderName = ".";
--
-- sel = mouseInWhichIcon(br, mx, my);
--
-- dodel = 0;
-+ int i;
-+ BFIL *bf;
-
- if (sel == -1) { /* clicked on nothing */
- if (!multi) { /* deselect all */
-@@ -1681,7 +1853,7 @@
- }
-
- changedNumLit(br, sel, 0);
-- br->lastIconClicked = -1;
-+ br->lastIconClicked = -1;
- }
-
-
-@@ -1725,14 +1897,14 @@
-
- changedNumLit(br, sel, 0);
-
--
-+
- /* see if we've double-clicked something */
-- if (sel==br->lastIconClicked && mtime-br->lastClickTime < DBLCLICKTIME) {
-- int k;
-+ if (mtime &&
-+ sel==br->lastIconClicked && mtime-br->lastClickTime < DBLCLICKTIME) {
- br->lastIconClicked = -1; /* YES */
-
- doubleClick(br, sel);
-- return rv;
-+ return -1;
- }
-
- else {
-@@ -1741,9 +1913,37 @@
- }
- }
-
--
- changedNumLit(br, -1, 0);
-+ return 0;
-+}
-+
-+
-+/***************************************************************/
-+static int clickIconWin(br, mx, my, mtime, multi)
-+ BROWINFO *br;
-+ int mx,my,multi;
-+ unsigned long mtime;
-+{
-+ /* returns '-1' normally, returns an index into bfList[] if the user
-+ double-clicks an icon */
-+
-+ int i,j, sel, cpymode, dodel;
-+ BROWINFO *destBr;
-+ BFIL *bf;
-+ char buf[256];
-+ const char *destFolderName;
-+
-+ if (!br->bfList || !br->bfLen) return -1;
-+
-+ destBr = br; destFolderName = ".";
-
-+ sel = mouseInWhichIcon(br, mx, my);
-+ dodel = 0;
-+
-+ recIconVisible(br->path, sel);
-+
-+ if (updateSel(br, sel, multi, mtime))
-+ return -1;
-
-
- { /* track mouse until button1 is released */
-@@ -1759,10 +1959,10 @@
- first = 1; hasrect = 0; cpymode = 0;
- origsval = br->scrl.val;
-
-- if ( (sel>=0 && !multi) || sel==-1) {
-+ if ( (sel>=0 && !multi) || sel==-1) {
- /* clicked on an icon, or clicked on nothing... */
-
-- while (!XQueryPointer(theDisp, rootW, &rW, &cW, &rootx, &rooty,
-+ while (!XQueryPointer(theDisp, rootW, &rW, &cW, &rootx, &rooty,
- &x,&y,&mask));
- if (mask & Button1Mask) { /* still held down */
-
-@@ -1773,7 +1973,7 @@
- else curs = movecurs;
-
- /* change cursors */
-- for (i=0; i=0) { /* see if changed copy/move status (and cursor) */
- int cmod;
--
-+
- cmod = (mask&ControlMask || mask&ShiftMask) ? 1 : 0;
-
- if (cmod != cpymode && !dodel) {
- curs = (cmod) ? copycurs : movecurs;
-- for (i=0; iiconW, rootx,rooty,
-+ XTranslateCoordinates(theDisp, rW, br->iconW, rootx,rooty,
- &iwx,&iwy, &cW);
-
- /* find deepest child that the mouse is in */
-@@ -1837,12 +2037,12 @@
- /* if it's in any icon window, and we're doing icon-dragging
- OR we're doing a rectangle-drag */
-
-- if (i=0 && (oldx!=x || oldy!=y || oldbrnum!=i)) { /* moved */
-@@ -1873,7 +2073,7 @@
- }
- }
-
--
-+
- /* if we clicked on an icon (originally), and therefore are
- showing the 'move files' cursor, see if the cursor is within
- the icon region of any folders. If so, light up *the icon
-@@ -1904,9 +2104,9 @@
-
- /* Dragging a selection rectangle. */
-
-- else {
-+ else {
- static int prevx, prevy, prevcnt;
-- int origy, top, left, wide, high, cnt;
-+ int origy, cnt;
-
- if (first) { prevx = mx; prevy = my; first=0; prevcnt = -1; }
-
-@@ -1922,18 +2122,18 @@
-
- rx = (mx < x) ? mx : x;
- ry = (origy < y) ? origy : y;
-- rw = abs(mx - x);
-+ rw = abs(mx - x);
- rh = abs(origy - y);
-
- /* figure out which icons need to be lit/unlit. Only
- redraw those that have changed state */
--
-+
- for (i=0,cnt=0, bf=br->bfList; ibfLen; i++,bf++) {
-- int ix, iy, isin, light;
-+ int ix, iy, isin;
-
-- ix = ((i%br->numWide) * ISPACE_WIDE)
-+ ix = ((i%br->numWide) * ISPACE_WIDE)
- + ISPACE_WIDE/2 - bf->w/2;
-- iy = ((i/br->numWide) * ISPACE_HIGH)
-+ iy = ((i/br->numWide) * ISPACE_HIGH)
- + ISPACE_TOP + ISIZE_HIGH - bf->h;
-
- iy = iy - br->scrl.val * ISPACE_HIGH;
-@@ -1994,7 +2194,7 @@
- }
-
- /* RELEASED BUTTON: back to normal arrow cursor */
-- for (i=0; ilit == TEMP_LIT || bf->lit == TEMP_LIT1) {
- bf->lit = 1; drawIcon(br, i);
- }
--
-+
- if (bf->lit) br->numlit++;
- }
-
-@@ -2020,7 +2220,6 @@
-
- /* if doing a copy or a move, do the thing to the files */
- if (sel >= 0) {
-- char *destFolder;
-
- if (DEBUG) {
- fprintf(stderr,"---------------\n");
-@@ -2029,7 +2228,7 @@
- fprintf(stderr,"Dest Folder: '%s'\n", destFolderName);
- }
-
--
-+
- if (!br->numlit) {
- if (DEBUG) fprintf(stderr, "no selected files. Nothing to do!\n");
- }
-@@ -2042,7 +2241,7 @@
- if (DEBUG) fprintf(stderr, "no destination. Nothing to do!\n");
- }
-
-- else if (strcmp(destFolderName,".") == 0 &&
-+ else if (strcmp(destFolderName,".") == 0 &&
- strcmp(br->path, destBr->path) == 0) {
- if (DEBUG) fprintf(stderr,"source == destination. Nothing to do!\n");
- }
-@@ -2067,20 +2266,20 @@
- }
- }
- if (DEBUG) fprintf(stderr,"\n\n");
--
-+
- #ifdef VMS
- /*
-- * For VMS, our directory file names are identifed by the
-- * special filename extension, ".DIR". Unfortunately, this
-- * needs to be stripped before we ever actually use the name
-+ * For VMS, our directory file names are identifed by the
-+ * special filename extension, ".DIR". Unfortunately, this
-+ * needs to be stripped before we ever actually use the name
- * in a copy command... :( RLD 26-FEB-1993
- */
-
-- *rindex ( destFolderName, '.' ) = '\0';
-+ *rindex ( destFolderName, '.' ) = '\0'; /* FIXME: potentially writing into static strings! */
- #endif
-
-
-- dragFiles(br, destBr, br->path, destBr->path, destFolderName, nlist,
-+ dragFiles(br, destBr, br->path, destBr->path, destFolderName, nlist,
- ncnt, cpymode);
-
- /* free namelist */
-@@ -2099,7 +2298,7 @@
- }
- } /* end of 'tracking' sub-function */
-
-- return rv;
-+ return -1;
- }
-
- /*******************************************/
-@@ -2113,6 +2312,8 @@
-
- /* called to 'open' icon #sel, which could be a file or a dir */
-
-+ br->lst = 0;
-+
- /* if sel == -1, then called via RETURN key. just use first lit item
- as thing that was double clicked on */
-
-@@ -2155,7 +2356,7 @@
- }
-
-
--
-+
- /* double-clicked something. We should do something about it */
- if (br->bfList[sel].ftype == BF_DIR) { /* try to cd */
- #ifndef VMS
-@@ -2165,15 +2366,36 @@
- else sprintf(buf, "%s%s", br->path, br->bfList[sel].name);
- #endif
-
-+#ifdef AUTO_EXPAND
-+ if (Chvdir(buf)) {
-+#else
- if (chdir(buf)) {
-+#endif
- char str[512];
- sprintf(str,"Unable to cd to '%s'\n", br->bfList[sel].name);
- setBrowStr(br, str);
- XBell(theDisp, 50);
- }
- else {
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(buf)) {
-+ BTSetActive(&br->but[BR_DELETE], 0);
-+ br->cmdMB.dim[BR_DELETE] = 1;
-+
-+ BTSetActive(&br->but[BR_RENAME], 0);
-+ br->cmdMB.dim[BR_RENAME] = 1;
-+
-+ BTSetActive(&br->but[BR_MKDIR], 0);
-+ br->cmdMB.dim[BR_MKDIR] = 1;
-+ }
-+ else {
-+ BTSetActive(&br->but[BR_MKDIR], 1);
-+ br->cmdMB.dim[BR_MKDIR] = 0;
-+ }
-+#endif
- scanDir(br);
- SCSetVal(&(br->scrl), 0); /* reset to top on a chdir */
-+ restIconVisible(br);
- }
- }
-
-@@ -2193,7 +2415,26 @@
- *event_retP = THISNEXT;
- }
- else { *event_retP = LOADPIC; SetDirFName(buf); }
--
-+
-+#ifdef VS_RESCMAP
-+ /* Change Colormap for browser */
-+ if (browPerfect && browCmap) {
-+ int i;
-+ XSetWindowAttributes xswa;
-+ if(LocalCmap) {
-+ xswa.colormap = LocalCmap;
-+ _IfTempOut=2;
-+ }
-+ else {
-+ xswa.colormap = theCmap;
-+ _IfTempOut=2;
-+ }
-+ for(i=0;istate & ShiftMask;
- ck = CursorKey(ks, shift, 1);
-- dealt = 1;
-+ dealt = 1;
-
- RemapKeyCheck(ks, buf, &stlen);
-
-@@ -2289,6 +2530,7 @@
- case '\021': doCmd(br, BR_QUIT); break; /* ^Q = Quit xv */
-
- case '\006': doCmd(br, BR_SELFILES); break; /* ^F = Select Files */
-+ case '\030': doCmd(br, BR_CLIPBRD); break; /* ^X = Copy to clipboard */
-
-
- /* case '\003': FakeButtonPress(&but[BCMTVIEW]); break; */ /* ^C */
-@@ -2299,6 +2541,9 @@
- case '\n': doubleClick(br, -1); break; /* RETURN = load selected */
-
- case ' ':
-+ if (br->lst && (time(NULL) <= br->lst + incrementalSearchTimeout))
-+ goto do_default;
-+ /* else fall through... */
- case '\010':
- case '\177': /* SPACE = load next, BS/DEL = load prev */
- if (br->bfLen && br->numlit >= 1) {
-@@ -2306,7 +2551,7 @@
- char fname[MAXPATHLEN];
-
- /* if 'shift-space' find last lit icon, select the next one after it,
-- and load it. If 'space' do the same, but lose prior lit. These
-+ and load it. If 'space' do the same, but lose prior lit. These
- are the only cases where br->numlit >1 allowed */
-
- if (br->numlit>1 && buf[0] != ' ') return;
-@@ -2314,7 +2559,7 @@
- if (buf[0]==' ' && (br->numlit>1 || (br->numlit==1 && shift))) {
- for (i=br->bfLen-1; i>=0 && !br->bfList[i].lit; i--); /* i=last lit */
- if (i==br->bfLen-1) return;
--
-+
- i++;
- if (!shift) {
- for (j=0; jbfLen; j++) {
-@@ -2348,6 +2593,9 @@
-
- /* try to open this file */
- sprintf(foo, "%s%s", br->path, br->bfList[i].name);
-+#ifdef AUTO_EXPAND
-+ Dirtovd(foo);
-+#endif
- for (j=0; jbfLen && !br->bfList[i].lit; i++); /* find lit one */
- sprintf(fname, "%s%s", br->path, br->bfList[i].name);
-+#ifdef AUTO_EXPAND
-+ Dirtovd(fname);
-+#endif
- viewsel = !(strcmp(fname, fullfname));
--
-+
- if (viewsel) {
- if (buf[0]==' ') browKey(br, CK_RIGHT);
- else browKey(br, CK_LEFT);
-@@ -2372,7 +2623,7 @@
-
- if (!br->bfList[i].lit || !viewsel) { /* changed selection */
- for (i=0; ibfLen && !br->bfList[i].lit; i++); /* find it */
-- if (br->bfList[i].ftype != BF_DIR)
-+ if (br->bfList[i].ftype != BF_DIR)
- doubleClick(br, -1);
- }
- }
-@@ -2381,7 +2632,8 @@
-
-
- default: /* unknown character. Take it as an alpha accelerator */
-- if (buf[0] > 32) browAlpha(br, buf[0]);
-+ do_default: /* (goto-label, not switch-label) */
-+ if (buf[0] >= 32) browAlpha(br, buf[0]);
- else XBell(theDisp, 0);
- break;
- }
-@@ -2401,6 +2653,8 @@
- /* an arrow key (or something like that) was pressed in icon window.
- change selection/scrollbar accordingly */
-
-+ br->lst = 0;
-+
- /* handle easy keys */
- if (key == CK_PAGEUP) SCSetVal(&br->scrl, br->scrl.val - br->scrl.page);
- if (key == CK_PAGEDOWN) SCSetVal(&br->scrl, br->scrl.val + br->scrl.page);
-@@ -2410,10 +2664,10 @@
- /* handle up/down/left/right keys
- *
- * if precisely *one* item is lit, than the up/down/left/right keys move
-- * the selection.
-+ * the selection.
- *
- * if NO items are lit, then left/right select the first/last fully-displayed
-- * icon, and up/down simply scroll window up or down, without selecting
-+ * icon, and up/down simply scroll window up or down, without selecting
- * anything
- *
- * if more than one item is lit, up/down/left/right keys BEEP
-@@ -2443,8 +2697,8 @@
- if (key == CK_DOWN) j = i + br->numWide;
- if (key == CK_LEFT) j = i - 1;
- if (key == CK_RIGHT) j = i + 1;
--
-- if (j >= 0 && j < br->bfLen) {
-+
-+ if (j >= 0 && j < br->bfLen) {
- br->bfList[i].lit = 0;
- br->bfList[j].lit = 1;
- makeIconVisible(br,j);
-@@ -2455,7 +2709,7 @@
- }
- }
-
--
-+
- if (br->numlit == 0) { /* no current selection */
- if (key == CK_UP) SCSetVal(&br->scrl, br->scrl.val - 1);
- if (key == CK_DOWN) SCSetVal(&br->scrl, br->scrl.val + 1);
-@@ -2482,15 +2736,28 @@
- /* find first 'plain' file that is lexically >= than the given ch */
-
- int i,j;
-+ time_t now = time(NULL);
-
- if (!br->bfLen) return;
-- if (ch <= ' ' || ch > '\177') return; /* ignore 'funny' keys */
-+ if (ch < ' ' || ch > '\177') return; /* ignore 'funny' keys */
-
- for (i=0; ibfLen && br->bfList[i].ftype==BF_DIR; i++);
- if (i==br->bfLen) return; /* only directories in this dir */
-
-+ if (!br->lst || (br->lst + incrementalSearchTimeout < now)) br->len = 0;
-+ br->lst = now;
-+
-+ if (br->len + 2 > br->siz)
-+ if ((br->str = (char *)realloc(br->str, (br->siz = br->len + 32))) == NULL)
-+ br->siz = br->len = 0;
-+
-+ if (br->len + 2 <= br->siz) {
-+ br->str[br->len++] = ch;
-+ br->str[br->len] = '\0';
-+ }
-+
- for ( ; ibfLen; i++) {
-- if (br->bfList[i].name[0] >= ch) break;
-+ if (strncmp(br->bfList[i].name, br->str, br->len) >= 0) break;
- }
-
- if (i==br->bfLen) i--;
-@@ -2541,20 +2808,24 @@
- * The VMS chdir always needs 2 components (device and directory),
- * so convert "/device" to "/device/000000" and convert
- * "/" to "/XV_Root_Device/000000" (XV_RootDevice will need to be
-- * a special concealed device setup to provide list of available
-+ * a special concealed device setup to provide list of available
- * disks).
- *
- * End 'tmppath' by changing trailing '/' (of dir name) to a '\0'
- */
- *rindex ( tmppath, '/') = '\0';
-- if ( ((br->ndirs-sel) == 2) && (strlen(tmppath) > 1) )
-+ if ( ((br->ndirs-sel) == 2) && (strlen(tmppath) > 1) )
- strcat ( tmppath, "/000000" ); /* add root dir for device */
- else if ((br->ndirs-sel) == 1 )
- strcpy ( tmppath, "/XV_Root_Device/000000" ); /* fake top level */
- }
- #endif
-
-+#ifdef AUTO_EXPAND
-+ if (Chvdir(tmppath)) {
-+#else
- if (chdir(tmppath)) {
-+#endif
- char str[512];
- sprintf(str,"Unable to cd to '%s'\n", tmppath);
- MBRedraw(&(br->dirMB));
-@@ -2562,8 +2833,25 @@
- XBell(theDisp, 50);
- }
- else {
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(tmppath)) {
-+ BTSetActive(&br->but[BR_DELETE], 0);
-+ br->cmdMB.dim[BR_DELETE] = 1;
-+
-+ BTSetActive(&br->but[BR_RENAME], 0);
-+ br->cmdMB.dim[BR_RENAME] = 1;
-+
-+ BTSetActive(&br->but[BR_MKDIR], 0);
-+ br->cmdMB.dim[BR_MKDIR] = 1;
-+ }
-+ else {
-+ BTSetActive(&br->but[BR_MKDIR], 1);
-+ br->cmdMB.dim[BR_MKDIR] = 0;
-+ }
-+#endif
- scanDir(br);
- SCSetVal(&br->scrl, 0); /* reset to top of window on a chdir */
-+ restIconVisible(br);
- }
- }
- }
-@@ -2582,7 +2870,11 @@
- if ((strlen(br->path) > (size_t) 2) && br->path[strlen(br->path)-1] == '/')
- br->path[strlen(br->path)-1] = '\0';
-
-+#ifdef AUTO_EXPAND
-+ rv = Chvdir(br->path);
-+#else
- rv = chdir(br->path);
-+#endif
- if (rv) {
- char str[512];
- sprintf(str, "Unable to cd to '%s'\n", br->path);
-@@ -2590,6 +2882,24 @@
- XBell(theDisp, 50);
- }
-
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(br->path)) {
-+ BTSetActive(&br->but[BR_DELETE], 0);
-+ br->cmdMB.dim[BR_DELETE] = 1;
-+
-+ BTSetActive(&br->but[BR_RENAME], 0);
-+ br->cmdMB.dim[BR_RENAME] = 1;
-+
-+ BTSetActive(&br->but[BR_MKDIR], 0);
-+ br->cmdMB.dim[BR_MKDIR] = 1;
-+ }
-+ else {
-+ BTSetActive(&br->but[BR_MKDIR], 1);
-+ br->cmdMB.dim[BR_MKDIR] = 0;
-+ }
-+#endif
-+
-+ restIconVisible(br);
- strcat(br->path, "/"); /* put trailing '/' back on */
- return rv;
- }
-@@ -2599,7 +2909,7 @@
- static void copyDirInfo(srcbr, dstbr)
- BROWINFO *srcbr, *dstbr;
- {
-- /* copies br info from an already existing browser window
-+ /* copies br info from an already existing browser window
- (ie, one that is already showing the same directory) */
-
- int i, oldnum, maxv, page;
-@@ -2611,15 +2921,19 @@
- /* copy mblist */
- dstbr->ndirs = srcbr->ndirs;
- for (i=0; indirs; i++) {
-- dstbr->mblist[i] = (char *) malloc(strlen(srcbr->mblist[i]) + 1);
-+ dstbr->mblist[i] = strdup(srcbr->mblist[i]);
- if (!dstbr->mblist[i]) FatalError("unable to malloc brMBlist[]");
-- strcpy(dstbr->mblist[i], srcbr->mblist[i]);
- }
-
-- dstbr->dirMB.list = srcbr->mblist;
-+#if 0
-+ dstbr->dirMB.list = srcbr->mblist; /* original bug..? */
- dstbr->dirMB.nlist = srcbr->ndirs;
-+#else
-+ dstbr->dirMB.list = dstbr->mblist; /* fixed by */
-+ dstbr->dirMB.nlist = dstbr->ndirs; /* jp-extension. */
-+#endif
-
-- XClearArea(theDisp, dstbr->dirMB.win, dstbr->dirMB.x, dstbr->dirMB.y,
-+ XClearArea(theDisp, dstbr->dirMB.win, dstbr->dirMB.x, dstbr->dirMB.y,
- dstbr->dirMB.w+3, dstbr->dirMB.h+3, False);
-
- i = StringWidth(dstbr->mblist[0]) + 10;
-@@ -2644,7 +2958,7 @@
-
- if ((i&0x03) == 0) drawTemp(dstbr, i, dstbr->bfLen);
- if ((i & 0x3f) == 0) WaitCursor();
--
-+
- sbf = &(srcbr->bfList[i]);
- dbf = &(dstbr->bfList[i]);
-
-@@ -2670,7 +2984,7 @@
- if (sbf->pimage) {
- dbf->pimage = (byte *) malloc((size_t) dbf->w * dbf->h);
- if (!dbf->pimage) FatalError("ran out of memory for dbf->pimage");
-- xvbcopy((char *) sbf->pimage, (char *) dbf->pimage,
-+ xvbcopy((char *) sbf->pimage, (char *) dbf->pimage,
- (size_t) (dbf->w * dbf->h));
- }
- else dbf->pimage = (byte *) NULL;
-@@ -2681,10 +2995,10 @@
- xvbcopy((char *) sbf->ximage, (char *) dbf->ximage, sizeof(XImage));
-
- if (sbf->ximage->data) {
-- dbf->ximage->data = (char *) malloc((size_t) dbf->ximage->height *
-+ dbf->ximage->data = (char *) malloc((size_t) dbf->ximage->height *
- dbf->ximage->bytes_per_line);
- if (!dbf->ximage->data) FatalError("ran out of memory for ximg data");
-- xvbcopy((char *) sbf->ximage->data, (char *) dbf->ximage->data,
-+ xvbcopy((char *) sbf->ximage->data, (char *) dbf->ximage->data,
- (size_t) dbf->ximage->height * dbf->ximage->bytes_per_line);
- }
- }
-@@ -2701,15 +3015,15 @@
- computeScrlVals(dstbr, &maxv, &page);
- if (dstbr->scrl.val > maxv) dstbr->scrl.val = maxv;
-
-- XClearArea(theDisp, dstbr->iconW, 0, 0, (u_int) dstbr->iwWide,
-+ XClearArea(theDisp, dstbr->iconW, 0, 0, (u_int) dstbr->iwWide,
- (u_int) dstbr->iwHigh, True);
- SCSetRange(&dstbr->scrl, 0, maxv, dstbr->scrl.val, page);
-
- SetCursors(-1);
- }
-
--
--
-+
-+
-
- /***************************************************************/
- static void scanDir(br)
-@@ -2726,7 +3040,7 @@
- * and it's reasonable to expect folks to want to add their own bitmaps
- */
-
-- int i,j,k,oldbflen,vmsparent;
-+ int i,j,oldbflen,vmsparent;
- BFIL *bf;
-
- DIR *dirp;
-@@ -2753,7 +3067,7 @@
- xv_getwd(path, sizeof(path));
- if (path[strlen(path)-1] != '/') strcat(path,"/"); /* add trailing '/' */
-
-- for (i=0; indirs; i++) free(br->mblist[i]); /* clear old dir names */
-+ for (i=0; indirs; i++) free((char *) br->mblist[i]); /* clear old dir names */
-
- /* path will be something like: "/u3/bradley/src/weiner/whatever/" */
-
-@@ -2775,22 +3089,24 @@
-
- /* build brMBlist */
- for (i = br->ndirs-1,j=0; i>=0; i--,j++) {
-- size_t stlen = (i<(br->ndirs-1)) ? dirnames[i+1] - dirnames[i]
-+ size_t stlen = (i<(br->ndirs-1)) ? dirnames[i+1] - dirnames[i]
- : strlen(dirnames[i]);
-+ char *copy;
-
-- br->mblist[j] = (char *) malloc(stlen+1);
-- if (!br->mblist[j]) FatalError("unable to malloc brMBlist[]");
-+ copy = malloc(stlen+1);
-+ if (!copy) FatalError("unable to malloc brMBlist[]");
-
-- strncpy(br->mblist[j], dirnames[i], stlen);
-- br->mblist[j][stlen] = '\0';
-+ strncpy(copy, dirnames[i], stlen);
-+ copy[stlen] = '\0';
-+ br->mblist[j] = copy;
- }
--
-+
-
- /* refresh the brdirMB button */
- br->dirMB.list = br->mblist;
- br->dirMB.nlist = br->ndirs;
-
-- XClearArea(theDisp, br->dirMB.win, br->dirMB.x, br->dirMB.y,
-+ XClearArea(theDisp, br->dirMB.win, br->dirMB.x, br->dirMB.y,
- br->dirMB.w+3, br->dirMB.h+3, False);
-
- i = StringWidth(br->mblist[0]) + 10;
-@@ -2815,7 +3131,7 @@
- /* count how many files are in the list */
-
- dirp = opendir(".");
-- if (!dirp) {
-+ if (!dirp) {
- endScan(br, oldbflen);
- setBrowStr(br, "Couldn't read current directory.");
- SetCursors(-1);
-@@ -2827,11 +3143,11 @@
- #endif
-
- while ( (dp = readdir(dirp)) != NULL) {
-- if (strcmp(dp->d_name, ".") &&
-+ if (strcmp(dp->d_name, ".") &&
- strcmp(dp->d_name, THUMBDIR)) {
-- if (!br->showhidden && dp->d_name[0] == '.' &&
-+ if (!br->showhidden && dp->d_name[0] == '.' &&
- strcmp(dp->d_name,"..")!=0) continue;
-- else
-+ else
- br->bfLen++;
- }
- if ((br->bfLen & 0x3f) == 0) WaitCursor();
-@@ -2877,13 +3193,13 @@
- }
- else {
- do { dp = readdir(dirp); }
-- while (dp && (strcmp(dp->d_name, ".")==0 ||
-+ while (dp && (strcmp(dp->d_name, ".")==0 ||
- strcmp(dp->d_name, THUMBDIR)==0 ||
- strcmp(dp->d_name, THUMBDIRNAME)==0 ||
- (br->ndirs==1 && strcmp(dp->d_name,"..")==0) ||
-- (!br->showhidden && dp->d_name[0] == '.' &&
-+ (!br->showhidden && dp->d_name[0] == '.' &&
- strcmp(dp->d_name,"..")!=0)));
--
-+
- if (!dp) { br->bfLen = i; break; } /* dir got shorter... */
- }
-
-@@ -2940,11 +3256,11 @@
- if (w<1) w = 1;
- if (h<1) h = 1;
-
-- XClearArea(theDisp, br->iconW, (ctrlColor) ? 2 : 0, (ctrlColor) ? 2 : 0,
-+ XClearArea(theDisp, br->iconW, (ctrlColor) ? 2 : 0, (ctrlColor) ? 2 : 0,
- (u_int) w, (u_int) h, False);
-
- SCSetRange(&br->scrl, 0, maxv, br->scrl.val, page);
--
-+
- SetCursors(-1);
- }
-
-@@ -2972,10 +3288,14 @@
- bf->pimage = (byte *) NULL;
- bf->ximage = (XImage *) NULL;
- bf->lit = 0;
--
-+
-
- if (stat(bf->name, &st)==0) {
-+#ifdef AUTO_EXPAND
-+ bf->ftype = stat2bf((u_int) st.st_mode , bf->name);
-+#else
- bf->ftype = stat2bf((u_int) st.st_mode);
-+#endif
- if (bf->ftype == BF_FILE && (st.st_mode & 0111)) bf->ftype = BF_EXE;
-
- switch (bf->ftype) {
-@@ -3007,6 +3327,7 @@
- case RFT_XBM: bf->ftype = BF_XBM; break;
- case RFT_SUNRAS: bf->ftype = BF_SUNRAS; break;
- case RFT_BMP: bf->ftype = BF_BMP; break;
-+ case RFT_WBMP: bf->ftype = BF_BMP; break;
- case RFT_UTAHRLE: bf->ftype = BF_UTAHRLE; break;
- case RFT_IRIS: bf->ftype = BF_IRIS; break;
- case RFT_PCX: bf->ftype = BF_PCX; break;
-@@ -3014,12 +3335,22 @@
- case RFT_TIFF: bf->ftype = BF_TIFF; break;
- case RFT_PDSVICAR: bf->ftype = BF_PDS; break;
- case RFT_COMPRESS: bf->ftype = BF_COMPRESS; break;
-+ case RFT_BZIP2: bf->ftype = BF_BZIP2; break;
- case RFT_PS: bf->ftype = BF_PS; break;
- case RFT_IFF: bf->ftype = BF_IFF; break;
-- case RFT_TARGA: bf->ftype = BF_TARGA; break;
-+ case RFT_TARGA: bf->ftype = BF_TGA; break;
- case RFT_XPM: bf->ftype = BF_XPM; break;
- case RFT_XWD: bf->ftype = BF_XWD; break;
- case RFT_FITS: bf->ftype = BF_FITS; break;
-+ case RFT_PNG: bf->ftype = BF_PNG; break;
-+ case RFT_ZX: bf->ftype = BF_ZX; break; /* [JCE] */
-+ case RFT_PCD: bf->ftype = BF_PCD; break;
-+ case RFT_MAG: bf->ftype = BF_MAG; break;
-+ case RFT_MAKI: bf->ftype = BF_MAKI; break;
-+ case RFT_PIC: bf->ftype = BF_PIC; break;
-+ case RFT_PI: bf->ftype = BF_PI; break;
-+ case RFT_PIC2: bf->ftype = BF_PIC2; break;
-+ case RFT_MGCSFX: bf->ftype = BF_MGCSFX; break;
- }
- }
- }
-@@ -3048,11 +3379,11 @@
- bfcompares++;
- if ((bfcompares & 0x7f)==0) WaitCursor();
-
-- /* sort critera: directories first, in alphabetical order,
-+ /* sort critera: directories first, in alphabetical order,
- followed by everything else, in alphabetical order */
--
-+
- if ((b1->ftype == BF_DIR && b2->ftype == BF_DIR) ||
-- (b1->ftype != BF_DIR && b2->ftype != BF_DIR))
-+ (b1->ftype != BF_DIR && b2->ftype != BF_DIR))
- return strcmp(b1->name, b2->name);
-
- else if (b1->ftype == BF_DIR && b2->ftype != BF_DIR) return -1;
-@@ -3108,7 +3439,7 @@
- for (i=0; ibfList[i].name) + 1);
- if (!bfnames[i]) FatalError("couldn't alloc bfnames in rescanDir()");
--
-+
- strcpy(bfnames[i], br->bfList[i].name);
- }
- }
-@@ -3121,7 +3452,7 @@
-
- /* note, either (or both) dirnames/bfnames can be NULL, in which case
- their respective 'len's will be zero */
--
-+
- /* sort the two name lists */
- if (bflen) qsort((char *) bfnames, (size_t) bflen, sizeof(char *),namcmp);
- if (dirlen) qsort((char *) dirnames, (size_t) dirlen,sizeof(char *),namcmp);
-@@ -3153,7 +3484,7 @@
- }
- }
- bflen = j;
--
-+
-
- for (i=j=0; ibfLen - bflen + dirlen; /* oldlen - #del'd + #created */
- if (newlen>0) {
-@@ -3241,7 +3572,7 @@
- if (bf->pimage) free(bf->pimage);
- if (bf->ximage) xvDestroyImage(bf->ximage);
- }
--
-+
- free(br->bfList);
- }
-
-@@ -3263,17 +3594,17 @@
-
- /***************************************************************/
- static char **getDirEntries(dir, lenP, dohidden)
-- char *dir;
-+ const char *dir;
- int *lenP;
- int dohidden;
- {
-- /* loads up all directory entries into an array. This *isn't* a great
-- way to do it, but I can't count on 'scandir()' existing on
-+ /* loads up all directory entries into an array. This *isn't* a great
-+ way to do it, but I can't count on 'scandir()' existing on
- every system. Returns 'NULL' on failure, or pointer to array of
- 'lenP' strings on success. '.' and '..' ARE included in list
- if !dohidden, all '.*' files are skipped (except . and ..) */
-
-- int i, j, dirlen;
-+ int i, dirlen;
- DIR *dirp;
- char **names;
- #ifdef NODIRENT
-@@ -3294,9 +3625,9 @@
- /* count # of entries in dir (worst case) */
- for (dirlen=0; (dp = readdir(dirp)) != NULL; dirlen++);
- if (!dirlen) {
-- closedir(dirp);
-+ closedir(dirp);
- *lenP = dirlen;
-- return (char **) NULL;
-+ return (char **) NULL;
- }
-
-
-@@ -3312,7 +3643,7 @@
-
- if (!dohidden) {
- #ifndef VMS
-- if (dp->d_name[0] == '.' &&
-+ if (dp->d_name[0] == '.' &&
- strcmp(dp->d_name,"." )!=0 &&
- strcmp(dp->d_name,"..")!=0) continue;
- #endif
-@@ -3324,7 +3655,7 @@
- strcpy(names[i], dp->d_name);
- i++;
- }
--
-+
- if (iname || bf->name[0] == '\0') return; /* shouldn't happen */
- str[0] = '\0';
- basefname[0] = '\0';
- pinfo.pic = (byte *) NULL;
- pinfo.comment = (char *) NULL;
-- readname = bf->name;
--
-+ strncpy(readname, bf->name, sizeof(readname) - 1);
-+
- /* free any old info in 'bf' */
- if (bf->imginfo) free (bf->imginfo);
- if (bf->pimage) free (bf->pimage);
- if (bf->ximage) xvDestroyImage(bf->ximage);
--
-+
- bf->imginfo = (char *) NULL;
- bf->pimage = (byte *) NULL;
- bf->ximage = (XImage *) NULL;
-@@ -3429,10 +3760,10 @@
-
- /* skip all 'special' files */
- if (!ISLOADABLE(bf->ftype)) return;
--
-+
- filetype = ReadFileType(bf->name);
--
-- if (filetype == RFT_COMPRESS) {
-+
-+ if ((filetype == RFT_COMPRESS) || (filetype == RFT_BZIP2)) {
- #if (defined(VMS) && !defined(GUNZIP))
- /* VMS decompress doesn't like the file to have a trailing .Z in fname
- however, GUnZip is OK with it, which we are calling UnCompress */
-@@ -3442,10 +3773,10 @@
- #else
- uncName = bf->name;
- #endif
--
-- if (UncompressFile(uncName, uncompname)) {
-+
-+ if (UncompressFile(uncName, uncompname, filetype)) {
- filetype = ReadFileType(uncompname);
-- readname = uncompname;
-+ strncpy(readname, uncompname, sizeof(readname) - 1);
- }
- else {
- sprintf(str, "Couldn't uncompress file '%s'", bf->name);
-@@ -3453,71 +3784,139 @@
- bf->ftype = BF_ERROR;
- }
- }
--
-+
-+#ifdef MACBINARY
-+ if (handlemacb && macb_file == True && bf->ftype != BF_ERROR) {
-+ if (RemoveMacbinary(readname, uncompname)) {
-+ if (strcmp(readname, bf->name)!=0) unlink(readname);
-+ strncpy(readname, uncompname, sizeof(readname) - 1);
-+ }
-+ else {
-+ sprintf(str, "Unable to remove a InfoFile header form '%s'.", bf->name);
-+ setBrowStr(br, str);
-+ bf->ftype = BF_ERROR;
-+ }
-+ }
-+#endif
-+
-+#ifdef HAVE_MGCSFX_AUTO
-+ if (bf->ftype != BF_ERROR) {
-+ if(filetype == RFT_MGCSFX){
-+ char tmpname[128];
-+ char *icom;
-+
-+ if((icom = mgcsfx_auto_input_com(bf->name)) != NULL){
-+ sprintf(tmpname, "%s/xvmsautoXXXXXX", tmpdir);
-+#ifdef USE_MKSTEMP
-+ close(mkstemp(tmpname));
-+#else
-+ mktemp(tmpname);
-+#endif
-+ SetISTR(ISTR_INFO, "Converting to known format by MgcSfx auto...");
-+ sprintf(str,"%s >%s", icom, tmpname);
-+ }else goto ms_auto_no;
-+
-+#ifndef VMS
-+ if (system(str))
-+#else
-+ if (!system(str))
-+#endif
-+ {
-+ sprintf(str, "Unable to convert '%s' by MgcSfx auto.", bf->name);
-+ setBrowStr(br, str);
-+ bf->ftype = BF_ERROR;
-+ }
-+ else {
-+ filetype = ReadFileType(tmpname);
-+ if (strcmp(readname, bf->name)!=0) unlink(readname);
-+ strncpy(readname, tmpname, sizeof(readname) - 1);
-+ }
-+ }
-+ }
-+ms_auto_no:
-+#endif /* HAVE_MGCSFX_AUTO */
-+
- /* get rid of comments. don't need 'em */
- if (pinfo.comment) free(pinfo.comment); pinfo.comment = (char *) NULL;
--
-- if (filetype == RFT_ERROR) {
-+
-+ if (filetype == RFT_ERROR) {
- sprintf(str,"Couldn't open file '%s'", bf->name);
- setBrowStr(br, str);
- bf->ftype = BF_ERROR;
- }
--
-+
- else if (filetype == RFT_UNKNOWN) {
- /* if it *was* an 'exe', leave it that way */
- if (bf->ftype != BF_EXE) bf->ftype = BF_UNKNOWN;
- }
--
-+
- else {
- /* otherwise it's a known filetype... do the *hard* part now... */
--
-+
-+#ifdef VS_ADJUST
-+ normaspect = defaspect;
-+#endif
- i = ReadPicFile(readname, filetype, &pinfo, 1);
- KillPageFiles(pinfo.pagebname, pinfo.numpages);
--
-+
- if (!i) bf->ftype = BF_ERROR;
--
-+
- if (i && (pinfo.w<=0 || pinfo.h<=0)) { /* bogus size */
- bf->ftype = BF_ERROR;
- free(pinfo.pic); pinfo.pic = (byte *) NULL;
- }
--
-+
- if (bf->ftype==BF_ERROR && filetype==RFT_XBM) bf->ftype = BF_UNKNOWN;
- }
--
-+
- /* get rid of comment, as we don't need it */
-- if (pinfo.comment) {
-+ if (pinfo.comment) {
- free(pinfo.comment); pinfo.comment = (char *) NULL;
- }
--
-+
- /* if we made an uncompressed file, we can rm it now */
-- if (readname != bf->name) unlink(readname);
--
--
-+ if (strcmp(readname, bf->name)!=0) unlink(readname);
-+
-+
- /* at this point either BF_ERROR, BF_UNKNOWN, BF_EXE or pic */
--
-+
- if (!pinfo.pic) {
- if (bf->ftype == BF_EXE) return; /* don't write thumbfiles for exe's */
--
-+
- bf->w = br_file_width; bf->h = br_file_height;
- writeThumbFile(br, bf, NULL, 0, 0, NULL); /* BF_ERROR, BF_UNKNOWN */
- return;
- }
--
-+
- /* at this point, we have a pic, so it must be an image file */
--
--
-+
-+
- /* compute size of icon (iwide,ihigh) */
--
-+
-+#ifdef VS_ADJUST
-+ if (!vsadjust) normaspect = 1;
-+
-+ wexpand = (double) (pinfo.w * normaspect) / (double) ISIZE_WIDE;
-+#else
- wexpand = (double) pinfo.w / (double) ISIZE_WIDE;
-+#endif /* VS_ADJUST */
- hexpand = (double) pinfo.h / (double) ISIZE_HIGH;
-
- if (wexpand >= 1.0 || hexpand >= 1.0) { /* don't expand small icons */
- if (wexpand>hexpand) {
-+#ifdef VS_ADJUST
-+ iwide = (int) ((pinfo.w * normaspect) / wexpand + 0.5);
-+#else
- iwide = (int) (pinfo.w / wexpand + 0.5);
-+#endif
- ihigh = (int) (pinfo.h / wexpand + 0.5);
- }
- else {
-+#ifdef VS_ADJUST
-+ iwide = (int) ((pinfo.w * normaspect) / hexpand + 0.5);
-+#else
- iwide = (int) (pinfo.w / hexpand + 0.5);
-+#endif
- ihigh = (int) (pinfo.h / hexpand + 0.5);
- }
- }
-@@ -3527,13 +3926,13 @@
-
-
- /* generate icon */
-- icon24 = Smooth24(pinfo.pic, pinfo.type==PIC24, pinfo.w, pinfo.h,
-+ icon24 = Smooth24(pinfo.pic, pinfo.type==PIC24, pinfo.w, pinfo.h,
- iwide, ihigh, pinfo.r,pinfo.g,pinfo.b);
- if (!icon24) { bf->ftype = BF_FILE; free(pinfo.pic); return; }
-
- sprintf(str, "%dx%d ", pinfo.normw, pinfo.normh);
- switch (filetype) {
-- case RFT_GIF: if (xv_strstr(pinfo.shrtInfo, "GIF89"))
-+ case RFT_GIF: if (xv_strstr(pinfo.shrtInfo, "GIF89"))
- strcat(str,"GIF89 file");
- else
- strcat(str,"GIF87 file");
-@@ -3543,12 +3942,12 @@
-
- case RFT_PBM: if (xv_strstr(pinfo.fullInfo, "raw")) strcat(str,"Raw ");
- else strcat(str,"Ascii ");
--
-+
- for (i=0; i<3 && (strlen(pinfo.fullInfo)>(size_t)3); i++){
- str1[0] = pinfo.fullInfo[i]; str1[1] = '\0';
- strcat(str, str1);
- }
--
-+
- strcat(str," file");
- break;
-
-@@ -3567,21 +3966,30 @@
- case RFT_XPM: strcat(str,"XPM file"); break;
- case RFT_XWD: strcat(str,"XWD file"); break;
- case RFT_FITS: strcat(str,"FITS file"); break;
-+ case RFT_PNG: strcat(str,"PNG file"); break;
-+ case RFT_ZX: strcat(str,"Spectrum SCREEN$"); break; /* [JCE] */
-+ case RFT_PCD: strcat(str,"PhotoCD file"); break;
-+ case RFT_MAG: strcat(str,"MAG file"); break;
-+ case RFT_MAKI: strcat(str,"MAKI file"); break;
-+ case RFT_PIC: strcat(str,"PIC file"); break;
-+ case RFT_PI: strcat(str,"PI file"); break;
-+ case RFT_PIC2: strcat(str,"PIC2 file"); break;
-+ case RFT_MGCSFX: strcat(str,"Magic Suffix file"); break;
- default: strcat(str,"file of unknown type"); break;
- }
--
--
-+
-+
- /* find out length of original file */
- { FILE *fp;
- long filesize;
- char buf[64];
--
-+
- fp = fopen(bf->name, "r");
- if (fp) {
- fseek(fp, 0L, 2);
- filesize = ftell(fp);
- fclose(fp);
--
-+
- sprintf(buf," (%ld bytes)", filesize);
- strcat(str, buf);
- }
-@@ -3609,17 +4017,17 @@
- bf->w = iwide;
- bf->h = ihigh;
- bf->ftype = BF_HAVEIMG;
--
-+
- bf->ximage = Pic8ToXImage(icon8, (u_int) iwide, (u_int) ihigh, browcols,
- browR, browG, browB);
--
-+
- free(icon24);
- free(pinfo.pic);
- }
-
-
-
--
-+
-
-
- /*
-@@ -3670,6 +4078,10 @@
-
- sprintf(thFname, "%s%s/%s", br->path, THUMBDIR, bf->name);
-
-+#ifdef AUTO_EXPAND
-+ Dirtovd(thFname);
-+#endif
-+
- fp = fopen(thFname, "r");
- if (!fp) return; /* nope, it doesn't have one */
-
-@@ -3682,7 +4094,7 @@
- /* read comments until we see '#END_OF_COMMENTS', or hit EOF */
- while (1) {
- if (!fgets(buf, 256, fp)) goto errexit;
--
-+
- if (!strncmp(buf, "#END_OF_COMMENTS", strlen("#END_OF_COMMENTS")))
- break;
-
-@@ -3714,7 +4126,7 @@
-
-
- /* read width, height, maxval */
-- if (!fgets(buf, 256, fp) || sscanf(buf, "%d %d %d", &w, &h, &mv) != 3)
-+ if (!fgets(buf, 256, fp) || sscanf(buf, "%d %d %d", &w, &h, &mv) != 3)
- goto errexit;
-
-
-@@ -3738,14 +4150,14 @@
- bf->h = h;
- bf->ftype = BF_HAVEIMG;
- bf->imginfo = info;
--
-- bf->ximage = Pic8ToXImage(icon8, (u_int) w, (u_int) h, browcols,
-+
-+ bf->ximage = Pic8ToXImage(icon8, (u_int) w, (u_int) h, browcols,
- browR, browG, browB);
- }
- else {
- if (info) free(info);
- }
--
-+
- fclose(fp);
- return;
-
-@@ -3757,7 +4169,7 @@
- }
-
-
--
-+
- /***************************************************************/
- static void writeThumbFile(br, bf, icon8, w, h, info)
- BROWINFO *br;
-@@ -3785,9 +4197,14 @@
-
- sprintf(thFname, "%s%s/%s", br->path, THUMBDIR, bf->name);
-
-+#ifdef AUTO_EXPAND
-+ Dirtovd(thFname);
-+#endif
-+
-+ unlink(thFname); /* just in case there's already an unwritable one */
- fp = fopen(thFname, "w");
- if (!fp) {
-- sprintf(buf, "Can't create thumbnail file '%s': %s", thFname,
-+ sprintf(buf, "Can't create thumbnail file '%s': %s", thFname,
- ERRSTR(errno));
- setBrowStr(br, buf);
- return; /* can't write... */
-@@ -3829,9 +4246,9 @@
- setBrowStr(br, buf);
- return; /* can't write... */
- }
--
-+
- fclose(fp);
--
-+
- chmod(thFname, (mode_t) perm);
- }
-
-@@ -3849,15 +4266,29 @@
-
- sprintf(thFname, "%s%s", br->path, THUMBDIRNAME);
-
-+#ifdef AUTO_EXPAND
-+ Dirtovd(thFname);
-+#endif
-+
- i = stat(thFname, &st);
- if (i) { /* failed, let's create it */
- sprintf(thFname, "%s.", br->path);
-+#ifdef AUTO_EXPAND
-+ Dirtovd(thFname);
-+#endif
- i = stat(thFname, &st); /* get permissions of parent dir */
- if (!i) perm = st.st_mode & 07777;
- else perm = 0755;
-
- sprintf(thFname, "%s%s", br->path, THUMBDIRNAME);
-- mkdir(thFname, (mode_t) perm);
-+#ifdef AUTO_EXPAND
-+ Dirtovd(thFname);
-+#endif
-+ i = mkdir(thFname, (mode_t) perm);
-+#ifdef VIRTUAL_TD
-+ if (i < 0)
-+ Mkvdir_force(thFname);
-+#endif
- }
- }
-
-@@ -3899,7 +4330,7 @@
- for (i=0, bf=br->bfList; ibfLen; i++, bf++) {
- if (bf->ftype <= BF_FILE || bf->ftype >= BF_ERROR || bf->ftype==BF_EXE) {
-
-- /* ie, not a 'special' file */
-+ /* i.e., not a 'special' file */
-
- int s1, s2;
- char thfname[256];
-@@ -3913,10 +4344,9 @@
- sprintf(thfname, "%s/%s", THUMBDIR, bf->name);
- s2 = stat(thfname, &thumbst);
-
-- if (s1 || s2 || filest.st_mtime > thumbst.st_mtime ||
-- filest.st_ctime > thumbst.st_ctime) {
-- /* either stat'ing the file or the thumbfile failed, or
-- both stat's succeeded and the file has a newer mod or creation
-+ if (s1 || s2 || filest.st_mtime > thumbst.st_mtime) {
-+ /* either stat'ing the file or the thumbfile failed, or
-+ both stat's succeeded and the file has a newer mod
- time than the thumbnail file */
-
- makeIconVisible(br, i);
-@@ -3926,11 +4356,16 @@
-
- if (bf->ftype != BF_EXE) {
- iconsBuilt++;
-- if (DEBUG)
-- fprintf(stderr,"icon made:fname='%s' thfname='%s' %d,%d,%d,%d\n",
-- bf->name, thfname, s1,s2,filest.st_mtime,thumbst.st_mtime);
-+ if (DEBUG)
-+ fprintf(stderr,"icon made:fname='%s' thfname='%s' %d,%d,%ld,%ld\n",
-+ bf->name, thfname, s1, s2,
-+ (long)filest.st_mtime, (long)thumbst.st_mtime);
- }
- }
-+ else if (filest.st_ctime > thumbst.st_ctime) {
-+ /* update protections */
-+ chmod(thfname, (mode_t) (filest.st_mode & 07777));
-+ }
- }
- statcount++;
-
-@@ -3964,7 +4399,11 @@
- sprintf(thfname, "%s/%s", THUMBDIR, dp->d_name);
- if (stat(thfname, &thumbst)==0) { /* success */
- int tmp;
-+#ifdef AUTO_EXPAND
-+ tmp = stat2bf((u_int) thumbst.st_mode , thfname);
-+#else
- tmp = stat2bf((u_int) thumbst.st_mode);
-+#endif
-
- if (tmp == BF_FILE) { /* a plain file */
- /* see if this thumbfile has an associated pic file */
-@@ -3974,7 +4413,7 @@
- }
- }
- statcount++;
--
-+
- if ((statcount % 30)==0) WaitCursor();
- }
- closedir(dirp);
-@@ -3998,16 +4437,16 @@
- {
- if (maxcnt<1) return; /* none of that naughty ol' divide by zero stuff */
-
-- DrawTempGauge(br->win, 5, br->dirMB.y,
-+ DrawTempGauge(br->win, 5, br->dirMB.y,
- (int) br->dirMB.x-10, (int) br->dirMB.h,
- (double) cnt / (double) maxcnt,
- browfg, browbg, browhi, browlo, "");
- }
--
-+
- static void clearTemp(br)
- BROWINFO *br;
- {
-- XClearArea(theDisp, br->win, 5, br->dirMB.y,
-+ XClearArea(theDisp, br->win, 5, br->dirMB.y,
- (u_int) br->dirMB.x-10+1, (u_int) br->dirMB.h + 1, True);
- }
-
-@@ -4038,17 +4477,26 @@
- pops up a 'what do you want to rename it to' box, and attempts to
- do the trick... */
-
-- int i, num;
-- char buf[128], txt[256], *origname, txt1[256];
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- struct stat st;
-+ int i, num;
-+ char buf[128], txt[256], *origname, txt1[256];
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ struct stat st;
-+
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(br->path)) {
-+ sprintf(buf,"Sorry, you can't rename file in the virtual directory, '%s'",
-+ br->path);
-+ ErrPopUp(buf, "\nBummer!");
-+ return;
-+ }
-+#endif
-
- if (cdBrow(br)) return;
-
- /* find the selected file */
- for (i=0; ibfLen && !br->bfList[i].lit; i++);
- if (i==br->bfLen) return; /* shouldn't happen */
--
-+
- origname = br->bfList[i].name; num = i;
-
- if (strcmp(origname, "..")==0) {
-@@ -4058,7 +4506,7 @@
- return;
- }
-
-- sprintf(txt, "Enter a new name for the %s '%s':",
-+ sprintf(txt, "Enter a new name for the %s '%s':",
- (br->bfList[i].ftype==BF_DIR) ? "directory" : "file",
- origname);
-
-@@ -4107,7 +4555,7 @@
- drawIcon(br, num);
-
- for (i=0; ipath)==0)
-+ if (&binfo[i] != br && strcmp(binfo[i].path, br->path)==0)
- rescanDir(&binfo[i]);
- }
-
-@@ -4125,15 +4573,24 @@
- pops up a 'what do you want to call it' box, and attempts to
- do the trick... */
-
-- int i;
-- char buf[128], txt[256];
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- struct stat st;
-+ int i;
-+ char buf[128], txt[256];
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ struct stat st;
-+
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(br->path)) {
-+ sprintf(buf,"Sorry, you can't mkdir in the virtual directory, '%s'",
-+ br->path);
-+ ErrPopUp(buf, "\nBummer!");
-+ return;
-+ }
-+#endif
-
- if (cdBrow(br)) return;
-
- buf[0] = '\0';
-- i = GetStrPopUp("Enter name for new directory:", labels, 2,
-+ i = GetStrPopUp("Enter name for new directory:", labels, 2,
- buf, 128, "/ |\'\"<>,", 0);
- if (i) return; /* cancelled */
-
-@@ -4161,7 +4618,7 @@
-
- /* rescan current br, and all other br's pointing to same directory */
- for (i=0; ipath)==0)
-+ if (strcmp(binfo[i].path, br->path)==0)
- rescanDir(&binfo[i]);
- }
-
-@@ -4176,10 +4633,10 @@
- static void doChdirCmd(br)
- BROWINFO *br;
- {
-- int i;
-- static char buf[MAXPATHLEN+100];
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char str[512];
-+ int i;
-+ static char buf[MAXPATHLEN+100];
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char str[512];
-
- buf[0] = '\0';
- i = GetStrPopUp("Change to directory:", labels, 2, buf, MAXPATHLEN, " ", 0);
-@@ -4198,14 +4655,35 @@
- if (cdBrow(br)) return; /* prints its own error message */
- }
-
-+#ifdef AUTO_EXPAND
-+ if (Chvdir(buf)) {
-+#else
- if (chdir(buf)) {
-+#endif
- sprintf(str,"Unable to cd to '%s'\n", buf);
- setBrowStr(br, str);
- XBell(theDisp, 50);
- }
- else {
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(buf)) {
-+ BTSetActive(&br->but[BR_DELETE], 0);
-+ br->cmdMB.dim[BR_DELETE] = 1;
-+
-+ BTSetActive(&br->but[BR_RENAME], 0);
-+ br->cmdMB.dim[BR_RENAME] = 1;
-+
-+ BTSetActive(&br->but[BR_MKDIR], 0);
-+ br->cmdMB.dim[BR_MKDIR] = 1;
-+ }
-+ else {
-+ BTSetActive(&br->but[BR_MKDIR], 1);
-+ br->cmdMB.dim[BR_MKDIR] = 0;
-+ }
-+#endif
- scanDir(br);
- SCSetVal(&(br->scrl), 0); /* reset to top on a chdir */
-+ restIconVisible(br);
- }
- }
-
-@@ -4225,10 +4703,19 @@
- * call 'rm_dir()' for each of the directories
- */
-
-- BFIL *bf;
-- int i, j, numdirs, numfiles, slen, firstdel;
-- char buf[512];
-- static char *yesno[] = { "\004Delete", "\033Cancel" };
-+ BFIL *bf;
-+ int i, numdirs, numfiles, slen, firstdel;
-+ char buf[512];
-+ static const char *yesno[] = { "\004Delete", "\033Cancel" };
-+
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(br->path)) {
-+ sprintf(buf,"Sorry, you can't delete file at the virtual directory, '%s'",
-+ br->path);
-+ ErrPopUp(buf, "\nBummer!");
-+ return;
-+ }
-+#endif
-
- if (!br->bfLen || !br->bfList || !br->numlit) return;
-
-@@ -4252,13 +4739,17 @@
- for (i=0, bf=br->bfList; ibfLen; i++,bf++) {
- if (bf->lit) {
- if (firstdel == -1) firstdel = i;
-- if (bf->ftype == BF_DIR) numdirs++;
-+ if (bf->ftype == BF_DIR
-+#ifdef AUTO_EXPAND
-+ && (!Isarchive(bf->name))
-+#endif
-+ ) numdirs++;
- else numfiles++;
- }
- }
-
-
-- /* if any plain files are being toasted, bring up the low-key
-+ /* if any plain files are being toasted, bring up the low-key
- confirmation box */
-
- if (numfiles) {
-@@ -4266,7 +4757,12 @@
- slen = strlen(buf);
-
- for (i=0, bf=br->bfList; ibfLen; i++,bf++) {
-+#ifdef AUTO_EXPAND
-+ if (bf->lit && (bf->ftype != BF_DIR || Isarchive(bf->name))) {
-+#else
- if (bf->lit && bf->ftype != BF_DIR) {
-+#endif
-+
- if ( (slen + strlen(bf->name) + 1) > 256) {
- strcat(buf,"...");
- break;
-@@ -4278,10 +4774,10 @@
- }
- }
-
-- i = PopUp(buf, yesno, 2);
-+ i = PopUp(buf, yesno, COUNT(yesno));
- if (i) return; /* cancelled */
- }
--
-+
-
- /* if any directories are being toasted, bring up the are you REALLY sure
- confirmation box */
-@@ -4291,7 +4787,11 @@
- slen = strlen(buf);
-
- for (i=0, bf=br->bfList; ibfLen; i++,bf++) {
-+#ifdef AUTO_EXPAND
-+ if (bf->lit && (bf->ftype == BF_DIR || !Isarchive(bf->name))) {
-+#else
- if (bf->lit && bf->ftype == BF_DIR) {
-+#endif
- if ( (slen + strlen(bf->name) + 1) > 256) {
- strcat(buf,"...");
- break;
-@@ -4303,16 +4803,20 @@
- }
- }
-
-- i = PopUp(buf, yesno, 2);
-+ i = PopUp(buf, yesno, COUNT(yesno));
- if (i) return; /* cancelled */
- }
-
-
- /* okay, at this point they've been warned. do the deletion */
--
-+
- for (i=0, bf=br->bfList; ibfLen; i++,bf++) {
- if (bf->lit) {
-- if (bf->ftype == BF_DIR) rm_dir (br, bf->name);
-+ if (bf->ftype == BF_DIR
-+#ifdef AUTO_EXPAND
-+ && !Isarchive(bf->name)
-+#endif
-+ ) rm_dir (br, bf->name);
- else rm_file(br, bf->name);
- }
- }
-@@ -4340,7 +4844,7 @@
-
- /* rescan other br's that are looking at this directory */
- for (i=0; ipath)==0)
-+ if (&binfo[i] != br && strcmp(binfo[i].path, br->path)==0)
- rescanDir(&binfo[i]);
- }
-
-@@ -4353,10 +4857,10 @@
- static void doSelFilesCmd(br)
- BROWINFO *br;
- {
-- int i;
-- static char buf[MAXPATHLEN+100];
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char str[512];
-+ int i;
-+ static char buf[MAXPATHLEN+100];
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char str[512];
-
- buf[0] = '\0';
- strcpy(str,"Select file name(s). Wildcard '*' is allowed. ");
-@@ -4394,9 +4898,9 @@
- static void doRecurseCmd(br)
- BROWINFO *br;
- {
-- int i;
-- static char *labels[] = { "\nOk", "\033Cancel" };
-- char str[512];
-+ int i;
-+ static const char *labels[] = { "\nOk", "\033Cancel" };
-+ char str[512];
-
- strcpy(str,"Recursive Update: This could take *quite* a while.\n");
- strcat(str,"Are you sure?");
-@@ -4415,9 +4919,9 @@
-
-
- /*******************************************/
--static void recurseUpdate(br, subdir)
-- BROWINFO *br;
-- char *subdir;
-+static void recurseUpdate(br, subdir)
-+ BROWINFO *br;
-+ const char *subdir;
- {
- /* note: 'br->path + subdir' is the full path to recurse down from */
-
-@@ -4430,7 +4934,7 @@
- * and for each subdir in this dir, recurse
- *
- * if cur dir != orig dir, cd back to orig dir and reload 'br'
-- */
-+ */
-
- int i;
- char orgDir[MAXPATHLEN + 2];
-@@ -4441,7 +4945,11 @@
- xv_getwd(orgDir, sizeof(orgDir));
-
- sprintf(curDir, "%s%s", br->path, subdir);
-+#ifdef AUTO_EXPAND
-+ if (Chvdir(curDir)) {
-+#else
- if (chdir(curDir)) {
-+#endif
- char str[512];
- sprintf(str, "Unable to cd to '%s'\n", curDir);
- setBrowStr(br, str);
-@@ -4449,18 +4957,28 @@
- }
-
- xv_getwd(curDir, sizeof(curDir));
--
-+
- /* have we looped? */
- for (i=0; ibfLen; i++) {
- bf = &(br->bfList[i]);
-- if (bf &&
-- bf->ftype == BF_DIR &&
-+ if (bf &&
-+ bf->ftype == BF_DIR &&
- strcmp(bf->name, ".") &&
- strcmp(bf->name, "..") &&
- strcmp(bf->name, THUMBDIRNAME) ) {
-@@ -4495,7 +5013,12 @@
-
- xv_getwd(curDir, sizeof(curDir));
- if (strcmp(orgDir, curDir)) { /* change back to orgdir */
-+#ifdef AUTO_EXPAND
-+ Chvdir(orgDir);
-+#else
- chdir(orgDir);
-+#endif
-+ restIconVisible(br);
- scanDir(br);
- }
- }
-@@ -4519,12 +5042,19 @@
- setBrowStr(br, buf);
- }
-
-+#ifdef AUTO_EXPAND
-+ if (Rmvdir(name)) {
-+ sprintf(buf, "fail to remove virturl directory: %s", name);
-+ setBrowStr(br, buf);
-+ }
-+#endif
-+
- /* try to delete a thumbnail file, as well. ignore errors */
- strcpy(buf1, name); /* tmp1 = leading path of name */
- tmp = (char *) rindex(buf1, '/');
- if (!tmp) strcpy(buf1,".");
- else *tmp = '\0';
--
-+
- sprintf(buf, "%s/%s/%s", buf1, THUMBDIR, BaseName(name));
- if (DEBUG) fprintf(stderr," (%s)\n", buf);
-
-@@ -4548,7 +5078,7 @@
- BROWINFO *br;
- {
- /* recursively delete this directory, and all things under it */
--
-+
- int i, dirlen, longpath, oldpathlen;
- char **names, *name, buf[512];
- struct stat st;
-@@ -4569,7 +5099,7 @@
- name = names[i];
-
- /* skip . and .. (not that we should ever see them... */
-- if (name[0] == '.' && (name[1]=='\0' ||
-+ if (name[0] == '.' && (name[1]=='\0' ||
- (name[1]=='.' && name[2]=='\0'))) goto done;
-
- if (strlen(name) + oldpathlen >= (MAXPATHLEN-3)) {
-@@ -4586,15 +5116,22 @@
- rmdirPath[oldpathlen] = '\0';
- goto done;
- }
--
-- if (stat2bf((u_int) st.st_mode) == BF_DIR) { /* skip, for now */
-+
-+#ifdef AUTO_EXPAND
-+ if ((stat2bf((u_int) st.st_mode , rmdirPath) == BF_DIR)
-+ && !Isarchive(rmdirPath)) /* skip, for now */
-+#else
-+
-+ if (stat2bf((u_int) st.st_mode) == BF_DIR) /* skip, for now */
-+#endif
-+ {
- rmdirPath[oldpathlen] = '\0';
- continue; /* don't remove from list */
- }
-
- rm_file(br, rmdirPath);
- rmdirPath[oldpathlen] = '\0';
--
-+
- done: /* remove name from list */
- free(name);
- names[i] = (char *) NULL;
-@@ -4640,30 +5177,35 @@
-
- static int overwrite;
- #define OWRT_ASK 0
--#define OWRT_NOASK 1
--#define OWRT_CANCEL 2
--
-+#define OWRT_ALWAYS 1
-+#define OWRT_NEVER 2
-+#define OWRT_CANCEL 3
-
- /*******************************************/
--static void dragFiles(srcBr, dstBr, srcpath, dstpath, dstdir,
-+static void dragFiles(srcBr, dstBr, srcpath, dstpath, dstdir,
- names, nlen, cpymode)
-- BROWINFO *srcBr, *dstBr;
-- char *srcpath, *dstpath, *dstdir, **names;
-- int nlen, cpymode;
-+ BROWINFO *srcBr, *dstBr;
-+ char *srcpath, *dstpath, **names;
-+ const char *dstdir;
-+ int nlen, cpymode;
- {
-- /* move or copy file(s) and their associated thumbnail files.
-+ /* move or copy file(s) and their associated thumbnail files.
- srcpath and dstpath will have trailing '/'s. dstdir is name of
- folder in dstpath (or "." or "..") to write to. names is an nlen
- long array of strings (the simple filenames of the files to move)
- if 'cpymode' copy files, otherwise move them */
-
-- int i, j, k, dothumbs, fail;
-+ int i, j, dothumbs, fail;
- char dstp[MAXPATHLEN + 1];
- char src[MAXPATHLEN+1], dst[MAXPATHLEN+1];
- char buf[128];
- struct stat st;
-
-
-+ /* if the source directory is read-only, don't move files; copy them */
-+ if (!cpymode && (access(srcpath, W_OK) != 0))
-+ cpymode = 1;
-+
- /* build real destination dir */
- strcpy(dstp, dstpath);
-
-@@ -4677,11 +5219,26 @@
- }
- else if (strcmp(dstdir,".")!=0) sprintf(dstp, "%s%s/", dstpath, dstdir);
-
-+#ifdef AUTO_EXPAND
-+ if (Isvdir(dstp)) {
-+ sprintf(buf,"Sorry, you can't %s to the virtual directory, '%s'",
-+ cpymode ? "copy" : "move", dstp);
-+ ErrPopUp(buf, "\nBummer!");
-+ SetCursors(-1);
-+ return;
-+ }
-+ if (Isvdir(srcpath))
-+ cpymode = 1;
-+#endif
-+
-
-
- /* if there is a thumbnail directory in 'srcpath', make one for dstpath */
- sprintf(src,"%s%s", srcpath, THUMBDIR);
- dothumbs = 0;
-+#ifdef AUTO_EXPAND
-+ Dirtovd(src);
-+#endif
- if (stat(src, &st)==0) {
- sprintf(dst,"%s%s", dstp, THUMBDIR);
- mkdir(dst, st.st_mode & 07777);
-@@ -4712,6 +5269,14 @@
- if (overwrite == OWRT_CANCEL) break; /* abort move */
- if (j==1) fail++;
-
-+#ifdef AUTO_EXPAND
-+ if (!cpymode && j==0)
-+ if (Movevdir(src,dst)) {
-+ sprintf(buf, "fail to move virturl directory: %s", names[i]);
-+ setBrowStr(srcBr, buf);
-+ }
-+#endif
-+
- if (dothumbs && j==0) {
- sprintf(src,"%s%s/%s", srcpath, THUMBDIR, names[i]);
- sprintf(dst,"%s%s/%s", dstp, THUMBDIR, names[i]);
-@@ -4749,8 +5314,17 @@
- }
-
-
-+ if (!cpymode) {
-+ /* clear all lit files in the source folder (as they've been moved)
-+ note: this won't be the optimal behavior if any files failed to
-+ move, but screw it, that's not going to happen too often... */
-+ for (i=0; ibfLen; i++) srcBr->bfList[i].lit = 0;
-+ srcBr->numlit = 0;
-+ }
-+
-+
- /* clear all files in the destination folder */
-- for (i=0; ibfLen; i++) {
-+ for (i=0; ibfLen; i++) {
- dstBr->bfList[i].lit = 0;
- }
- dstBr->numlit = 0;
-@@ -4760,10 +5334,10 @@
- for (i=0; ibfList;
-+ for (j=0, bf=dstBr->bfList;
- jbfLen && strcmp(name, bf->name)!=0; j++, bf++);
-- if (jbfLen) {
-- bf->lit = 1; dstBr->numlit++;
-+ if (j