Article 12813 of alt.sources:
Newsgroups: alt.sources
Path: nntpd.lkg.dec.com!pa.dec.com!news2.digital.com!news1.digital.com!nntp-hub2.barrnet.net!hookup!tank.news.pipex.net!pipex!in2.uu.net!EU.net!Germany.EU.net!Dortmund.Germany.EU.net!ping.de!cliwe.ping.de!fdc
From: fdc@cliwe.ping.de (Frank D. Cringle)
Subject: viewfax - an X-window fax viewer, V2.2, Part01/03
Message-ID: <vt4tyfteiu.fsf@cliwe.ping.de>
Followup-To: alt.sources.d
Lines: 1668
Sender: fdc@cliwe.ping.de
Organization: No foundation. 
X-Newsreader: Gnus v5.0.1
Date: Thu, 14 Sep 1995 22:52:41 GMT


Submitted-by: fdc@cliwe.ping.de
Archive-name: viewfax-2.2/part01
Environment: X11, UNIX, ANSI-C

Viewfax is a utility for previewing fax files on an X-window display.

Input files can be raw, digifax or tiff/f, g3 or g4 format faxes.
The user can scroll through a list of pages, from one or more files,
and rotate and scale the images.

Viewfax supersedes g3view, of which versions 1.0 and 1.8 were
distributed on alt.sources.  The name was changed because the program
is no longer limited to the g3 compression algorithm.

A tar file is available for ftp at
<URL:ftp://ftp.leo.org/pub/comp/networking/communication/modem/mgetty/viewfax-2.2.tar.gz>


---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is viewfax-2.2, a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 09/14/1995 22:26 UTC by fdc@cliwe.ping.de
# Source directory /opt/gnu/src
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    547 -rw-r--r-- viewfax-2.2/README
#  17982 -rw-rw-r-- viewfax-2.2/COPYING
#   9390 -rw-r--r-- viewfax-2.2/ChangeLog
#    427 -rw-rw-r-- viewfax-2.2/Imakefile
#   2686 -rw-rw-r-- viewfax-2.2/Makefile
#  17804 -rw-rw-r-- viewfax-2.2/faxexpand.c
#   4329 -rw-rw-r-- viewfax-2.2/faxexpand.h
#  11869 -rw-rw-r-- viewfax-2.2/faxinput.c
#   6464 -rw-rw-r-- viewfax-2.2/faxinit.c
#  36678 -rw-rw-r-- viewfax-2.2/viewfax.c
#   7603 -rw-r--r-- viewfax-2.2/viewfax.man
#  17777 -rw-rw-r-- viewfax-2.2/viewfax.tif
#   4609 -rw-rw-r-- viewfax-2.2/g3hack.c
#
# ============= viewfax-2.2/README ==============
if test ! -d 'viewfax-2.2'; then
    echo 'x - creating directory viewfax-2.2'
    mkdir 'viewfax-2.2'
fi
if test -f 'viewfax-2.2/README' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/README (File already exists)'
else
echo 'x - extracting viewfax-2.2/README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/README' &&
This directory contains viewfax, a tool for displaying fax files
in an X Window.
X
Viewfax can display raw, digifax or tiff files containing g3 (T.4)
and/or g4 (T.6) coded fax pages.
X
To install viewfax you need an ansi C compiler on a machine
supporting X11.  No toolkit is required, just Xlib.
X
If you have a correctly installed imake, type:
X
X    xmkmf
X    make depend
X    make
X    make install
X    make install.man
X
If you do not want to use imake you will need to adjust the Makefile
for your environment.
X
--
Frank Cringle (fdc@cliwe.ping.de)
SHAR_EOF
chmod 0644 viewfax-2.2/README ||
echo 'restore of viewfax-2.2/README failed'
Wc_c="`wc -c < 'viewfax-2.2/README'`"
test 547 -eq "$Wc_c" ||
	echo 'viewfax-2.2/README: original size 547, current size' "$Wc_c"
fi
# ============= viewfax-2.2/COPYING ==============
if test -f 'viewfax-2.2/COPYING' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/COPYING (File already exists)'
else
echo 'x - extracting viewfax-2.2/COPYING (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/COPYING' &&
X		    GNU GENERAL PUBLIC LICENSE
X		       Version 2, June 1991
X
X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
X                          675 Mass Ave, Cambridge, MA 02139, USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X			    Preamble
X
X  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.
X
X  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
X
X  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
X
X  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.
X
X  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
X
X  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
X
X  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
X
X  The precise terms and conditions for copying, distribution and
modification follow.
X
X		    GNU GENERAL PUBLIC LICENSE
X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".
X
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
X
X  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
X
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
X
X  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
X
X    a) You must cause the modified files to carry prominent notices
X    stating that you changed the files and the date of any change.
X
X    b) You must cause any work that you distribute or publish, that in
X    whole or in part contains or is derived from the Program or any
X    part thereof, to be licensed as a whole at no charge to all third
X    parties under the terms of this License.
X
X    c) If the modified program normally reads commands interactively
X    when run, you must cause it, when started running for such
X    interactive use in the most ordinary way, to print or display an
X    announcement including an appropriate copyright notice and a
X    notice that there is no warranty (or else, saying that you provide
X    a warranty) and that users may redistribute the program under
X    these conditions, and telling the user how to view a copy of this
X    License.  (Exception: if the Program itself is interactive but
X    does not normally print such an announcement, your work based on
X    the Program is not required to print an announcement.)
X
These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
X
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
X
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
X
X  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
X
X    a) Accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of Sections
X    1 and 2 above on a medium customarily used for software interchange; or,
X
X    b) Accompany it with a written offer, valid for at least three
X    years, to give any third party, for a charge no more than your
X    cost of physically performing source distribution, a complete
X    machine-readable copy of the corresponding source code, to be
X    distributed under the terms of Sections 1 and 2 above on a medium
X    customarily used for software interchange; or,
X
X    c) Accompany it with the information you received as to the offer
X    to distribute corresponding source code.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form with such
X    an offer, in accord with Subsection b above.)
X
The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
X
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
X
X  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
X
X  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
X
X  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
X
X  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
X
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
X
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
X
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
X
X  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.
X
X  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
X
Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
X
X  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
X
X			    NO WARRANTY
X
X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
X
X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
X
X		     END OF TERMS AND CONDITIONS
X
X	Appendix: How to Apply These Terms to Your New Programs
X
X  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
X
X  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
X
X    <one line to give the program's name and a brief idea of what it does.>
X    Copyright (C) 19yy  <name of author>
X
X    This program is free software; you can redistribute it and/or modify
X    it under the terms of the GNU General Public License as published by
X    the Free Software Foundation; either version 2 of the License, or
X    (at your option) any later version.
X
X    This program is distributed in the hope that it will be useful,
X    but WITHOUT ANY WARRANTY; without even the implied warranty of
X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X    GNU General Public License for more details.
X
X    You should have received a copy of the GNU General Public License
X    along with this program; if not, write to the Free Software
X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
Also add information on how to contact you by electronic and paper mail.
X
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
X
X    Gnomovision version 69, Copyright (C) 19yy name of author
X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X    This is free software, and you are welcome to redistribute it
X    under certain conditions; type `show c' for details.
X
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
X
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:
X
X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
X
X  <signature of Ty Coon>, 1 April 1989
X  Ty Coon, President of Vice
X
This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.
SHAR_EOF
chmod 0664 viewfax-2.2/COPYING ||
echo 'restore of viewfax-2.2/COPYING failed'
Wc_c="`wc -c < 'viewfax-2.2/COPYING'`"
test 17982 -eq "$Wc_c" ||
	echo 'viewfax-2.2/COPYING: original size 17982, current size' "$Wc_c"
fi
# ============= viewfax-2.2/ChangeLog ==============
if test -f 'viewfax-2.2/ChangeLog' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/ChangeLog (File already exists)'
else
echo 'x - extracting viewfax-2.2/ChangeLog (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/ChangeLog' &&
--------------------
Version 2.2 released
--------------------
X
Mon Sep 11 10:21:17 1995  Frank D. Cringle  <fdc@cliwe>
X
X	* viewfax.c (GetImage): this routine must return a status
X	indicating if getpage() failed.  Its callers must try again until
X	it succeeds (to deal with missing pages).
X
Sun Sep 10 17:31:39 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* viewfax.man: update to reflect new functionality.
X
X	* viewfax.c (main): TIFF is no longer optional (the help page is a
X	tiff file).
X	(ShowLoop): display help page if requested.  Accept BackSpace key
X	for previous page.  Mirror image if requested.
X	(ZoomImage): the pb1 pointer could overrun the end of the Big
X	image by one word if an odd number of Big words fit in a Small
X	line.
X	(MirrorImage): new routine.
X
X	* faxexpand.h: keep a list of strip offsets in pagenodes instead
X	of a single offset to the fax data in a file.  Add the
X	mirror-image orientation flag.  Remove WITH_TIFF.
X
X	* faxinput.c (notetiff): handle all 8 orientations.  Handle
X        multi-strip tiff images.  Remove WITH_TIFF.
X
X	* faxexpand.c (SKIP_EOL): don't set a0 = lastx after an error, it
X	is a lie that prevents the line being properly filled out.
X	(g31expand & g32expand): report incorrect line length if verbose.
X
X	* Makefile (CFLAGS): remove -DWITH_TIFF - it is no longer
X	optional.  Add g3hack and the HELPFILE.  Add -ansi -pedantic to
X	gcc flags.
X
X	* Imakefile: remove WITH_TIFF, add HELPFILE.
X
X	* README: make / make depend in wrong order.  Remove comment about
X	WITH_TIFF.
X
Wed Jun 21 09:44:25 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Updated the FSF address in all file headers.
X
--------------------
Version 2.1 released
--------------------
X
Wed Apr 12 11:24:34 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* faxexpand.c: simpified access to raw data by preprocessing it
X	into 16-bit lsb-first chunks.  Ensure all macros are either
X	expressions or statements (not blocks).
X
X	* faxinit.c: build tables for access with lsb-first bit order.
X
X	* faxinput.c: new source file containing routines moved from
X	viewfax.c.
X
X	* viewfax.c: moved the input file processing to a separate source
X	file (faxinput.c) in preparation for use with other utilities.
X	Eliminated G3desc and made the expansion routines use pagenodes.
X
----------------------------------------------------------------
Renamed again due to name conflict with hylafax/contrib/faxview.
Now call viewfax.
----------------------------------------------------------------
X
Fri Apr  7 18:10:35 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 2.0 released.
X
X	* faxexpand.c: new expansion routines g32expand() and g4expand().
X	Caller provides a pointer to the line drawing routine for future
X	flexibility.
X
X	* faxview.c (main): new options -2 and -4.
X	(drawline): moved out of faxexpand.c.
X
X	* README: Mention g4, WITH_TIFF.
X
----------------------------------------------------------------
Renamed from g3view to faxview to reflect new functionality.
----------------------------------------------------------------
X
Sat Apr  1 21:06:55 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 1.9 released to testers.
X
X	* g3view.man: mention tiff and hylafax.  Document new keys for
X	previous/next page.
X
X	* g3view.c (notetiff): new function which figures out where the
X	raw image data is in a tiff file.
X
Fri Mar 31 12:17:53 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* g3view.c (usleep): added to the list of systems which have
X	usleep in libc.
X	(SetupDisplay): restrict the initial window size to the physical
X	screen size even if the virtual root is bigger.
X	(ShowLoop): allow '-' as a synonym for previous page and '+' and
X	space as synonyms for next page.
X
Sun Feb 26 15:31:53 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 1.8 released.
X
X	* g3view.c (getpage): report memused (in verbose mode) after
X	generating the new image.
X	(SetupDisplay): fixed problems with negative geometry coordinates.
X	(ShowLoop): improved the handling of user window-movement and
X	resizing.  Maintain image position when it is zoomed in a
X	constrained window size.
X
Thu Feb 16 12:18:38 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* g3view.c: #define XLIB_ILLEGAL_ACCESS is required by SCO- (and
X	maybe other) systems in order to access the contents of the
X	Display structure.
X	(RotImage): fixed boundary problem.
X	(main): allow any abbreviation of -display and -geometry.
X	(ShowLoop): process all pending key- and button-presses before
X	updating display.  Ignore key and button presses while the window
X	is changing size, otherwise the image size and window size can get
X	out of sync.
X	(ShowLoop): don't jump to the top left if -geometry constrains
X	size but not position.
X
Wed Feb 15 13:21:36 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 1.6 released.
X
X	* g3expand.c (G3init): finally killed the gentab -> g3tables
X	precomputing step, in favour of run-time initialisation.  Time for
X	G3init is down in the profiling noise.
X
X	* g3view.c (SetupDisplay): use the size of the root window rather
X	than the size of the screen as the maximum possible geometry.
X	(ShowLoop): use the user-specified geometry (default: entire root
X	window) to constrain the area available to g3view.
X
X	* g3view.man: get rid of -x and talk about window managers.
X
Tue Feb 14 20:55:57 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* g3view.c (ShowLoop): another change to the window resizing
X	logic.  It now works as desired with all window managers except
X	fvwm.  Use g3view -x25 under fvwm until fvwm gets fixed.
X
X	* g3view.man: documented -r and -x
X
Sun Feb 12 18:45:28 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* g3view.c: added command-line-settable display and geometry
X	values, dynamic bit-reversal of input files and warning bell
X	(audible/visible) when attempting to move to non-existent page.
X	Removed -m and -x window-manager kludges.  -m now gives limit to
X	image-memory cache size.
X	(getpage): delete the mmap() version.  We now always suck the
X	input file into memory so we can optionally bit-reverse it and so
X	we can add zeros at the end to prevent the expansion algorithm
X	over-running without having to check each byte.  Also survive
X	unreadable or empty files by removing them from the file list.
X	(GetVRoot): took this function from the comp.windows.x FAQ.  I
X	can't test it 'cos I don't have the solbourne virtual WM around
X	here.
X	(SetupDisplay): process user's geometry spec.
X	(ShowLoop): try to cooperate with the window manager by tracking
X	Reparent and Configure events.  Use NewImage() and FreeImage() to
X	manage cache size.  Give warning when there is no previous/next
X	page.  Allow zooming with z/Z.
X	(RotImage): provide faster version which does 4 rows at a time.
X
X	* g3expand.c: removed the compile-time REVERSE option (we now have
X	an equivalent at run-time). Removed 2D states from debug list.
X	(G3expand): Added line number to error messages.  Tightened up
X	end-of-data detection to prevent core dumps.
X	(G3count): Continue counting after spurious EOLs (for
X	efax-mutilated digifax files).
X
X	* g3.h: removed unused 2D state definitions.
X
X	* README: recommend Imakefile.
X
X	* Makefile: $(HAVE) is no longer needed.  Added -Wno-uninitialized
X	to suppress uninteresting warnings in new RotImage() code.  Added
X	Imakefile to FILES.
X
X	* g3view.man: renamed from g3view.1 to comply with Imake
X	convention.  Added documentation of new features.
X
Mon Feb  6 12:42:14 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 1.4 released.
X
X	* Makefile: don't need _HAVE_XSETWMPROTOCOLS any more.
X
X	* g3view.c: added -m and -x flags.  Avoid using SetWMProtocols for
X	compatibility with ancient installations.  Release non-essential
X	memory and retry if a malloc or Xcall fails.
X
X	* g3view.1: documented -m and -x flags.
X
Sat Feb  4 12:43:50 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* g3expand.c (G3expand): fixed a malloc bug (not enough memory
X	requested for run-length list).
X
Fri Feb  3 11:10:48 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* g3view.c: Support a list of files on the command line rather
X	than just a single page.
X
X	* g3view.1: Updated to reflect new functionality.
X
X	* g3view.c (ZoomImage): still didn't work on little-endian
X	hosts. It now operates on 32 bit words and should be
X	architecture-independent (and faster).  Three versions are
X	available via #ifdef.
X	(SetupDisplay): it is unnecessary to constrain the minimum window
X	size.
X	(ShowLoop): changed the image scrolling method (middle mouse
X	button) to actively chew through the event queue instead of
X	waiting for motion hints.  The old method is still available if
X	USE_MOTIONHINT is defined.
X	(SetupDisplay): fix a rounding problem with the initial window
X	size.
X
Thu Feb  2 23:00:00 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 1.2 released.
X
X	* Makefile: tar and shar targets added.
X
X	* g3view.1: update to reflect changed middle button handling.
X
X	* g3view.c: added version number and "COPYING" reference to usage
X	and verbose messages.  Removed arguments from getopt() prototype
X	(there is no consensus about if, where and how it is declared).
X	Fixed problem with window size constraints when running under mwm.
X	(ZoomImage): corrected packing order on little-endian hosts.
X	(ShowLoop): improved middle button handling (now it drags the
X	image rather than making it jump).
X	
X
Tue Jan 31 18:00:00 1995  Frank D. Cringle  <fdc@cliwe.ping.de>
X
X	* Version 1.0 released.
SHAR_EOF
chmod 0644 viewfax-2.2/ChangeLog ||
echo 'restore of viewfax-2.2/ChangeLog failed'
Wc_c="`wc -c < 'viewfax-2.2/ChangeLog'`"
test 9390 -eq "$Wc_c" ||
	echo 'viewfax-2.2/ChangeLog: original size 9390, current size' "$Wc_c"
fi
# ============= viewfax-2.2/Imakefile ==============
if test -f 'viewfax-2.2/Imakefile' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/Imakefile (File already exists)'
else
echo 'x - extracting viewfax-2.2/Imakefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/Imakefile' &&
# Imakefile for viewfax
X
BINDIR = /usr/local/bin		/* where you want the binary installed */
HELPDIR = /usr/local/lib	/* where you want the help file installed */
X
DEFINES = -DHELPFILE=\"$(HELPDIR)/viewfax.tif\"
X
SRCS = viewfax.c faxinput.c faxinit.c faxexpand.c
OBJS = viewfax.o faxinput.o faxinit.o faxexpand.o
SYS_LIBRARIES = $(XLIB)
DEPLIBS = $(DEPXLIB)
X
ComplexProgramTarget(viewfax)
InstallProgram(viewfax.tif,$(HELPDIR))
SHAR_EOF
chmod 0664 viewfax-2.2/Imakefile ||
echo 'restore of viewfax-2.2/Imakefile failed'
Wc_c="`wc -c < 'viewfax-2.2/Imakefile'`"
test 427 -eq "$Wc_c" ||
	echo 'viewfax-2.2/Imakefile: original size 427, current size' "$Wc_c"
fi
# ============= viewfax-2.2/Makefile ==============
if test -f 'viewfax-2.2/Makefile' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/Makefile (File already exists)'
else
echo 'x - extracting viewfax-2.2/Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/Makefile' &&
# Makefile for viewfax
# Copyright (C) 1990, 1995  Frank D. Cringle.
X
# This file is part of viewfax - g3/g4 fax processing software.
#      
# viewfax is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#      
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#      
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
X
VERS = 2.2
X
####### Site-specific definitions #######
# Destination directories and installation program for make install
BINDIR = /usr/local/bin
LIBDIR = /usr/local/lib
MANDIR	= /usr/local/man/man1
INSTALL = /usr/ucb/install
RM = rm -f
# Location of help file
HELP = \"$(LIBDIR)/viewfax.tif\"
# optimisation level, debug etc
OPT = -g -O2 -Wno-uninitialized -ansi -pedantic
# C compiler and libraries
# vanilla sysv
#CC = cc
#CFLAGS = $(OPT) -DHELPFILE=$(HELP)
#LDFLAGS = $(OPT)
#LIBS = -lsocket
# vanilla BSD
#CC = cc
#CFLAGS = -DBSD $(OPT) -DHELPFILE=$(HELP)
#LDFLAGS = $(OPT)
#LIBS =
# sun solaris2 with gcc on supersparc:
CC=gcc
CFLAGS = -Wall $(OPT) -DHELPFILE=$(HELP) -msupersparc -I/usr/openwin/include
LDFLAGS = $(OPT) -L/usr/openwin/lib -R/usr/openwin/lib
LIBS =
X
####### End of configurable definitions #######
OBJS = viewfax.o faxinput.o faxinit.o faxexpand.o
X
viewfax:	$(OBJS)
X	$(CC) $(LDFLAGS) -o viewfax $(OBJS) -lX11 $(LIBS)
X
g3hack:		g3hack.c
X
install: viewfax
X	$(INSTALL) -s -m 755 viewfax $(BINDIR)
X	$(INSTALL) -m 644 viewfax.man $(MANDIR)/viewfax.1
X	$(INSTALL) -m 644 viewfax.tif $(LIBDIR)
X
D = viewfax-$(VERS)
FILES = $D/README $D/COPYING $D/ChangeLog $D/Imakefile $D/Makefile \
X	$D/faxexpand.c $D/faxexpand.h $D/faxinput.c $D/faxinit.c \
X	$D/viewfax.c $D/viewfax.man $D/viewfax.tif $D/g3hack.c
X
viewfax.tif:	viewfax.ps g3hack
X	gs -sDEVICE=faxg3 -sOutputFile=viewfax.g3 -dNOPAUSE -q -dSAFER viewfax.ps -c quit
X	./g3hack -n 100 -o viewfax.g3s viewfax.g3
X	fax2tiff -M -4 -o viewfax.tif viewfax.g3s
X	$(RM) viewfax.g3 viewfax.g3s
X
tar:;	(cd ..; tar cf - $(FILES) | gzip -9 >$D/$D.tar.gz)
X
shar:;	(cd ..; shar -a -n$D -M -sfdc@cliwe.ping.de -c -o $D/part -l64 $(FILES))
X
clean:;	$(RM) *.o *~ core
X
viewfax.o:	faxexpand.h
faxinput.o:	faxexpand.h
faxinit.o:	faxexpand.h
faxexpand.o:	faxexpand.h
faxcompress.o:	faxexpand.h
SHAR_EOF
chmod 0664 viewfax-2.2/Makefile ||
echo 'restore of viewfax-2.2/Makefile failed'
Wc_c="`wc -c < 'viewfax-2.2/Makefile'`"
test 2686 -eq "$Wc_c" ||
	echo 'viewfax-2.2/Makefile: original size 2686, current size' "$Wc_c"
fi
# ============= viewfax-2.2/faxexpand.c ==============
if test -f 'viewfax-2.2/faxexpand.c' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/faxexpand.c (File already exists)'
else
echo 'x - extracting viewfax-2.2/faxexpand.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/faxexpand.c' &&
/* Expand one page of fax data
X   Copyright (C) 1990, 1995  Frank D. Cringle.
X
This file is part of viewfax - g3/g4 fax processing software.
X     
viewfax is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
X     
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
X     
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
X
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include "faxexpand.h"
X
/* Note that NeedBits() only works for n <= 16 */
#define NeedBits(n) do {						\
X    if (BitsAvail < (n)) {						\
X	BitAcc |= *sp++ << BitsAvail;					\
X	BitsAvail += 16;						\
X    }									\
} while (0)
#define GetBits(n)	(BitAcc & ((1<<(n))-1))
#define ClrBits(n) do {							\
X    BitsAvail -= (n);							\
X    BitAcc >>= (n);							\
} while (0)
X
#ifdef DEBUG
#define DEBUG_SHOW putchar(BitAcc & (1 << t) ? '1' : '0')
#define LOOKUP(wid,tab)	do {						\
X    int t;								\
X    NeedBits(wid);							\
X    TabEnt = tab + GetBits(wid);					\
X    printf("%08lX/%d: %s%5d\t", BitAcc, BitsAvail,			\
X	   StateNames[TabEnt->State], TabEnt->Param);			\
X    for (t = 0; t < TabEnt->Width; t++)					\
X	DEBUG_SHOW;							\
X    putchar('\n');							\
X    fflush(stdout);							\
X    ClrBits(TabEnt->Width);						\
} while (0)
X
#define SETVAL(x) do {							\
X    *pa++ = RunLength + (x);						\
X    printf("SETVAL: %d\t%d\n", RunLength + (x), a0);			\
X    a0 += x;								\
X    RunLength = 0;							\
} while (0)
X
char *StateNames[] = {
X    "Null   ",
X    "Pass   ",
X    "Horiz  ",
X    "V0     ",
X    "VR     ",
X    "VL     ",
X    "Ext    ",
X    "TermW  ",
X    "TermB  ",
X    "MakeUpW",
X    "MakeUpB",
X    "MakeUp ",
X    "EOL    ",
};
X
#else
#define LOOKUP(wid,tab)	do {						\
X    NeedBits(wid);							\
X    TabEnt = tab + GetBits(wid);					\
X    ClrBits(TabEnt->Width);						\
} while (0)
X
#define SETVAL(x) do {							\
X    *pa++ = RunLength + (x);						\
X    a0 += x;								\
X    RunLength = 0;							\
} while (0)
#endif
X
#define dumpruns(runs) do {						\
X    printf("-------------------- %d\n", LineNum);			\
X    for (pa = runs, a0 = 0; a0 < lastx; a0 += *pa++)			\
X	printf("%4d %d\n", a0, *pa);					\
} while (0)
X
#define EndOfData(pn)	(sp >= pn->data + pn->length/sizeof(*pn->data))
X
/* This macro handles coding errors in G3 data.
X   We redefine it below for the G4 case */
#define SKIP_EOL do {							\
X    while (!EndOfData(pn)) {						\
X	NeedBits(11);							\
X	if (GetBits(11) == 0)						\
X	    break;							\
X	ClrBits(11);							\
X    }									\
X    ClrBits(11);							\
X    goto EOL;								\
} while (0)
#define eol2lab	EOL2:
X
/* the line expanders are written as macros so that they can be reused
X   (twice each) but still have direct access to the local variables of
X   the "calling" function */
#define expand1d() do {							\
X    while (a0 < lastx) {						\
X	int done = 0;							\
X	while (!done) {		/* white first */			\
X	    LOOKUP(12, WhiteTable);					\
X	    switch (TabEnt->State) {					\
X	    case S_EOL:							\
X		EOLcnt = 1;						\
X		goto EOL;						\
X	    case S_TermW:						\
X		SETVAL(TabEnt->Param);					\
X		done = 1;						\
X		break;							\
X	    case S_MakeUpW:						\
X	    case S_MakeUp:						\
X		a0 += TabEnt->Param;					\
X		RunLength += TabEnt->Param;				\
X		break;							\
X	    default:							\
X		unexpected("WhiteTable", LineNum);			\
X		SKIP_EOL;						\
X		break;							\
X	    }								\
X	}								\
X	done = 0;							\
X	while (!done) {		/* then black */			\
X	    LOOKUP(13, BlackTable);					\
X	    switch (TabEnt->State) {					\
X	    case S_EOL:							\
X		EOLcnt = 1;						\
X		goto EOL;						\
X	    case S_TermB:						\
X		SETVAL(TabEnt->Param);					\
X		done = 1;						\
X		break;							\
X	    case S_MakeUpB:						\
X	    case S_MakeUp:						\
X		a0 += TabEnt->Param;					\
X		RunLength += TabEnt->Param;				\
X		break;							\
X	    default:							\
X		unexpected("BlackTable", LineNum);			\
X		SKIP_EOL;						\
X		break;							\
X	    }								\
X	}								\
X    }									\
X EOL: ;									\
} while (0)
#define CHECK_b1 do {							\
X    if (pa != thisrun) while (b1 <= a0 && b1 < lastx) {			\
X	b1 += pb[0] + pb[1];						\
X	pb += 2;							\
X    }									\
} while (0)
X
#define expand2d(eolab) do {						\
X    while (a0 < lastx) {						\
X	LOOKUP(7, MainTable);						\
X	switch (TabEnt->State) {					\
X	case S_Pass:							\
X	    CHECK_b1;							\
X	    b1 += *pb++;						\
X	    RunLength += b1 - a0;					\
X	    a0 = b1;							\
X	    b1 += *pb++;						\
X	    break;							\
X	case S_Horiz:							\
X	    if ((pa-run0)&1) {						\
X		int done = 0;						\
X		while (!done) { /* black first */			\
X		    LOOKUP(13, BlackTable);				\
X		    switch (TabEnt->State) {				\
X		    case S_TermB:					\
X			SETVAL(TabEnt->Param);				\
X			done = 1;					\
X			break;						\
X		    case S_MakeUpB:					\
X		    case S_MakeUp:					\
X			a0 += TabEnt->Param;				\
X			RunLength += TabEnt->Param;			\
X			break;						\
X		    default:						\
X			unexpected("BlackTable", LineNum);		\
X			SKIP_EOL;					\
X			break;						\
X		    }							\
X		}							\
X		done = 0;						\
X		while (!done) { /* then white */			\
X		    LOOKUP(12, WhiteTable);				\
X		    switch (TabEnt->State) {				\
X		    case S_TermW:					\
X			SETVAL(TabEnt->Param);				\
X			done = 1;					\
X			break;						\
X		    case S_MakeUpW:					\
X		    case S_MakeUp:					\
X			a0 += TabEnt->Param;				\
X			RunLength += TabEnt->Param;			\
X			break;						\
X		    default:						\
X			unexpected("WhiteTable", LineNum);		\
X			SKIP_EOL;					\
X			break;						\
X		    }							\
X		}							\
X	    }								\
X	    else {							\
X		int done = 0;						\
X		while (!done) { /* white first */			\
X		    LOOKUP(12, WhiteTable);				\
X		    switch (TabEnt->State) {				\
X		    case S_TermW:					\
X			SETVAL(TabEnt->Param);				\
X			done = 1;					\
X			break;						\
X		    case S_MakeUpW:					\
X		    case S_MakeUp:					\
X			a0 += TabEnt->Param;				\
X			RunLength += TabEnt->Param;			\
X			break;						\
X		    default:						\
X			unexpected("WhiteTable", LineNum);		\
X			SKIP_EOL;					\
X			break;						\
X		    }							\
X		}							\
X		done = 0;						\
X		while (!done) { /* then black */			\
X		    LOOKUP(13, BlackTable);				\
X		    switch (TabEnt->State) {				\
X		    case S_TermB:					\
X			SETVAL(TabEnt->Param);				\
X			done = 1;					\
X			break;						\
X		    case S_MakeUpB:					\
X		    case S_MakeUp:					\
X			a0 += TabEnt->Param;				\
X			RunLength += TabEnt->Param;			\
X			break;						\
X		    default:						\
X			unexpected("BlackTable", LineNum);		\
X			SKIP_EOL;					\
X			break;						\
X		    }							\
X		}							\
X	    }								\
X	    CHECK_b1;							\
X	    break;							\
X	case S_V0:							\
X	    CHECK_b1;							\
X	    SETVAL(b1 - a0);						\
X	    b1 += *pb++;						\
X	    break;							\
X	case S_VR:							\
X	    CHECK_b1;							\
X	    SETVAL(b1 - a0 + TabEnt->Param);				\
X	    b1 += *pb++;						\
X	    break;							\
X	case S_VL:							\
X	    CHECK_b1;							\
X	    SETVAL(b1 - a0 - TabEnt->Param);				\
X	    b1 -= *--pb;						\
X	    break;							\
X	case S_Ext:							\
X	    *pa++ = lastx - a0;						\
X	    if (verbose)						\
X		fprintf(stderr, "Line %d: extension code\n", LineNum);	\
X	    SKIP_EOL;							\
X	    break;							\
X	case S_EOL:							\
X	    *pa++ = lastx - a0;						\
X	    NeedBits(5);						\
X	    if (GetBits(5) && verbose)					\
X		fprintf(stderr, "Line %d: Bad EOL\n", LineNum);		\
X	    EOLcnt = 1;							\
X	    goto eolab;							\
X	    break;							\
X	default:							\
X	    unexpected("MainTable", LineNum);				\
X	    SKIP_EOL;							\
X	    break;							\
X	}								\
X    }									\
X    if (RunLength) {							\
X	/* expect a final V0 */						\
X	NeedBits(1);							\
X	if (!GetBits(1)) {						\
X	    unexpected("MainTable", LineNum);				\
X	    SKIP_EOL;							\
X	}								\
X	ClrBits(1);							\
X	SETVAL(0);							\
X    }									\
X eol2lab ;								\
} while (0)
X
static void
unexpected(char *what, int LineNum)
{
X    if (verbose)
X	fprintf(stderr, "Line %d: Unexpected state in %s\n",
X		LineNum, what);
}
X
/* Expand group-3 1-dimensional data */
void
g31expand(struct pagenode *pn, drawfunc df)
{
X    int a0;			/* reference element */
X    int lastx = pn->width;	/* copy line width to register */
X    t32bits BitAcc;		/* bit accumulator */
X    int BitsAvail;		/* # valid bits in BitAcc */
X    int RunLength;		/* Length of current run */
X    t16bits *sp;		/* pointer into compressed data */
X    pixnum *pa;			/* pointer into new line */
X    int EOLcnt;			/* number of consecutive EOLs */
X    int	LineNum;		/* line number */
X    pixnum *runs;		/* list of run lengths */
X    struct tabent *TabEnt;
X
X    sp = pn->data;
X    BitAcc = 0;
X    BitsAvail = 0;
X    lastx = pn->width;
X    runs = (pixnum *) xmalloc(lastx * sizeof(pixnum));
X    EOLcnt = 0;
X    for (LineNum = 0; LineNum < pn->height; ) {
#ifdef DEBUG
X	printf("\nBitAcc=%08lX, BitsAvail = %d\n", BitAcc, BitsAvail);
X	printf("-------------------- %d\n", LineNum);
X	fflush(stdout);
#endif
X	if (EOLcnt == 0)
X	    while (!EndOfData(pn)) {
X		/* skip over garbage after a coding error */
X		NeedBits(11);
X		if (GetBits(11) == 0)
X		    break;
X		ClrBits(1);
X	    }
X	for (EOLcnt = 1; !EndOfData(pn); EOLcnt++) {
X	    /* we have seen 11 zeros, which implies EOL,
X	       skip possible fill bits too */
X	    while (1) {
X		NeedBits(8);
X		if (GetBits(8))
X		    break;
X		ClrBits(8);
X	    }
X	    while (GetBits(1) == 0)
X		ClrBits(1);
X	    ClrBits(1);		/* the eol flag */
X	    NeedBits(11);
X	    if (GetBits(11))
X		break;
X	    ClrBits(11);
X	}
X	if (EOLcnt > 1 && EOLcnt != 6 && verbose)
X	    fprintf(stderr, "Line %d: bad RTC (%d EOLs)\n", LineNum, EOLcnt);
X	if (EOLcnt >= 6 || EndOfData(pn)) {
X	    free(runs);
X	    return;
X	}
X	RunLength = 0;
X	pa = runs;
X	a0 = 0;
X	EOLcnt = 0;
X	expand1d();
X	if (RunLength)
X	    SETVAL(0);
X	if (a0 != lastx) {
X	    if (verbose)
X		fprintf(stderr, "Line %d: length is %d (expected %d)\n", LineNum, a0, lastx);
X	    while (a0 > lastx)
X		a0 -= *--pa;
X	    if (a0 < lastx) {
X		if ((pa - runs) & 1)
X		    SETVAL(0);
X		SETVAL(lastx - a0);
X	    }
X	}
X	(*df)(runs, LineNum++, pn);
X    }
X    free(runs);
}
X
/* Expand group-3 2-dimensional data */
void
g32expand(struct pagenode *pn, drawfunc df)
{
X    int RunLength;		/* Length of current run */
X    int a0;			/* reference element */
X    int b1;			/* next change on previous line */
X    int lastx = pn->width;	/* copy line width to register */
X    pixnum *run0, *run1;	/* run length arrays */
X    pixnum *thisrun, *pa, *pb;	/* pointers into runs */
X    t16bits *sp;		/* pointer into compressed data */
X    t32bits BitAcc;		/* bit accumulator */
X    int BitsAvail;		/* # valid bits in BitAcc */
X    int EOLcnt;			/* number of consecutive EOLs */
X    int	refline = 0;		/* 1D encoded reference line */
X    int	LineNum;		/* line number */
X    struct tabent *TabEnt;
X
X    sp = pn->data;
X    BitAcc = 0;
X    BitsAvail = 0;
X    /* allocate space for 2 runlength arrays */
X    run0 = (pixnum *) xmalloc(2 * ((lastx+5)&~1) * sizeof(pixnum));
X    run1 = run0 + ((lastx+5)&~1);
X    run1[0] = lastx;
X    run1[1] = 0;
X    EOLcnt = 0;
X    for (LineNum = 0; LineNum < pn->height; ) {
#ifdef DEBUG
X	printf("\nBitAcc=%08lX, BitsAvail = %d\n", BitAcc, BitsAvail);
X	printf("-------------------- %d\n", LineNum);
X	fflush(stdout);
#endif
X	if (EOLcnt == 0)
X	    while (!EndOfData(pn)) {
X		/* skip over garbage after a coding error */
X		NeedBits(11);
X		if (GetBits(11) == 0)
X		    break;
X		ClrBits(1);
X	    }
X	for (EOLcnt = 1; !EndOfData(pn); EOLcnt++) {
X	    /* we have seen 11 zeros, which implies EOL,
X	       skip possible fill bits too */
X	    while (1) {
X		NeedBits(8);
X		if (GetBits(8))
X		    break;
X		ClrBits(8);
X	    }
X	    while (GetBits(1) == 0)
X		ClrBits(1);
X	    ClrBits(1);		/* the eol flag */
X	    NeedBits(12);
X	    refline = GetBits(1); /* 1D / 2D flag */
X	    ClrBits(1);
X	    if (GetBits(11))
X		break;
X	    ClrBits(11);
X	}
X	if (EOLcnt > 1 && EOLcnt != 6 && verbose)
X	    fprintf(stderr, "Line %d: bad RTC (%d EOLs)\n", LineNum, EOLcnt);
X	if (EOLcnt >= 6 || EndOfData(pn)) {
X	    free(run0);
X	    return;
X	}
X	if (LineNum == 0 && refline == 0 && verbose)
X	    fprintf(stderr, "First line is 2-D encoded\n");
X	RunLength = 0;
X	if (LineNum & 1) {
X	    pa = run1;
X	    pb = run0;
X	}
X	else {
X	    pa = run0;
X	    pb = run1;
X	}
X	thisrun = pa;
X	EOLcnt = 0;
X	a0 = 0;
X	b1 = *pb++;
X
X	if (refline) {
X	    expand1d();
X	}
X	else {
X	    expand2d(EOL2);
X	}
X	if (RunLength)
X	    SETVAL(0);
X	if (a0 != lastx) {
X	    if (verbose)
X		fprintf(stderr, "Line %d: length is %d (expected %d)\n", LineNum, a0, lastx);
X	    while (a0 > lastx)
X		a0 -= *--pa;
X	    if (a0 < lastx) {
X		if ((pa - run0) & 1)
X		    SETVAL(0);
X		SETVAL(lastx - a0);
X	    }
X	}
X	SETVAL(0);	/* imaginary change at end of line for reference */
X	(*df)(thisrun, LineNum++, pn);
X    }
X    free(run0);
}
X
/* Redefine the "skip to eol" macro.  We cannot recover from coding
X   errors in G4 data */
#undef SKIP_EOL
#undef eol2lab
#define SKIP_EOL do {							\
X    if (verbose)							\
X	fprintf(stderr, "Line %d: G4 coding error\n", LineNum);		\
X    free(run0);								\
X    return;								\
} while (0)
#define eol2lab
X
/* Expand group-4 data */
void
g4expand(struct pagenode *pn, drawfunc df)
{
X    int RunLength;		/* Length of current run */
X    int a0;			/* reference element */
X    int b1;			/* next change on previous line */
X    int lastx = pn->width;	/* copy line width to register */
X    pixnum *run0, *run1;	/* run length arrays */
X    pixnum *thisrun, *pa, *pb;	/* pointers into runs */
X    t16bits *sp;		/* pointer into compressed data */
X    t32bits BitAcc;		/* bit accumulator */
X    int BitsAvail;		/* # valid bits in BitAcc */
X    int	LineNum;		/* line number */
X    int EOLcnt;
X    struct tabent *TabEnt;
X
X    sp = pn->data;
X    BitAcc = 0;
X    BitsAvail = 0;
X    /* allocate space for 2 runlength arrays */
X    run0 = (pixnum *) xmalloc(2 * ((lastx+5)&~1) * sizeof(pixnum));
X    run1 = run0 + ((lastx+5)&~1);
X    run1[0] = lastx;		/* initial reference line */
X    run1[1] = 0;
X
X    for (LineNum = 0; LineNum < pn->height; ) {
#ifdef DEBUG
X	printf("\nBitAcc=%08lX, BitsAvail = %d\n", BitAcc, BitsAvail);
X	printf("-------------------- %d\n", LineNum);
X	fflush(stdout);
#endif
X	RunLength = 0;
X	if (LineNum & 1) {
X	    pa = run1;
X	    pb = run0;
X	}
X	else {
X	    pa = run0;
X	    pb = run1;
X	}
X	thisrun = pa;
X	a0 = 0;
X	b1 = *pb++;
X	expand2d(EOFB);
X	if (a0 < lastx) {
X	    if ((pa - run0) & 1)
X		SETVAL(0);
X	    SETVAL(lastx - a0);
X	}
X	SETVAL(0);	/* imaginary change at end of line for reference */
X	(*df)(thisrun, LineNum++, pn);
X	continue;
X    EOFB:
X	NeedBits(13);
X	if (GetBits(13) != 0x8001 && verbose)
X	    fputs("Bad RTC\n", stderr);
X	break;
X    }
X    free(run0);
}
X
static unsigned char zerotab[256] = {
X	0x88, 0x07, 0x16, 0x06, 0x25, 0x05, 0x15, 0x05,
X	0x34, 0x04, 0x14, 0x04, 0x24, 0x04, 0x14, 0x04,
X	0x43, 0x03, 0x13, 0x03, 0x23, 0x03, 0x13, 0x03,
X	0x33, 0x03, 0x13, 0x03, 0x23, 0x03, 0x13, 0x03,
X	0x52, 0x02, 0x12, 0x02, 0x22, 0x02, 0x12, 0x02,
X	0x32, 0x02, 0x12, 0x02, 0x22, 0x02, 0x12, 0x02,
X	0x42, 0x02, 0x12, 0x02, 0x22, 0x02, 0x12, 0x02,
X	0x32, 0x02, 0x12, 0x02, 0x22, 0x02, 0x12, 0x02,
X	0x61, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x31, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x41, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x31, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x51, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x31, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x41, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x31, 0x01, 0x11, 0x01, 0x21, 0x01, 0x11, 0x01,
X	0x70, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x40, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x50, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x40, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x60, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x40, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x50, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x40, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00,
X	0x30, 0x00, 0x10, 0x00, 0x20, 0x00, 0x10, 0x00
};
X
#define check(v) do {							\
X    prezeros = zerotab[v];						\
X    postzeros = prezeros & 15;						\
X    prezeros >>= 4;							\
X    if (prezeros == 8) {						\
X	zeros += 8;							\
X	continue;							\
X    }									\
X    if (zeros + prezeros < 11) {					\
X	empty = 0;							\
X	zeros = postzeros;						\
X	continue;							\
X    }									\
X    zeros = postzeros;							\
X    if (empty)								\
X	EOLcnt++;							\
X    lines++;								\
X    empty = 1;								\
} while (0)
X
/* count fax lines */
int
G3count(struct pagenode *pn, int twoD)
{
X    t16bits *p = pn->data;
X    t16bits *end = p + pn->length/sizeof(*p);
X    int lines = 0;		/* lines seen so far */
X    int zeros = 0;		/* number of consecutive zero bits seen */
X    int EOLcnt = 0;		/* number of consecutive EOLs seen */
X    int empty = 1;		/* empty line */
X    int prezeros, postzeros;
X
X    while (p < end && EOLcnt < 6) {
X	t16bits bits = *p++;
X	check(bits&255);
X	if (twoD && (prezeros + postzeros == 7)) {
X	    if (postzeros || ((bits & 0x100) == 0))
X		zeros--;
X	}
X	check(bits>>8);
X	if (twoD && (prezeros + postzeros == 7)) {
X	    if (postzeros || ((p < end) && ((*p & 1) == 0)))
X		zeros--;
X	}
X    }
X    return lines - EOLcnt;	/* don't count trailing EOLs */
}
SHAR_EOF
chmod 0664 viewfax-2.2/faxexpand.c ||
echo 'restore of viewfax-2.2/faxexpand.c failed'
Wc_c="`wc -c < 'viewfax-2.2/faxexpand.c'`"
test 17804 -eq "$Wc_c" ||
	echo 'viewfax-2.2/faxexpand.c: original size 17804, current size' "$Wc_c"
fi
# ============= viewfax-2.2/faxexpand.h ==============
if test -f 'viewfax-2.2/faxexpand.h' -a X"$1" != X"-c"; then
	echo 'x - skipping viewfax-2.2/faxexpand.h (File already exists)'
else
echo 'x - extracting viewfax-2.2/faxexpand.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'viewfax-2.2/faxexpand.h' &&
/* Include file for fax routines
X   Copyright (C) 1990, 1995  Frank D. Cringle.
X
This file is part of viewfax - g3/g4 fax processing software.
X     
viewfax is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
X     
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
X     
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
X
#include <limits.h>
X
#if ULONG_MAX == 4294967295UL
typedef unsigned long t32bits;
#elif UINT_MAX == 4294967295UL
typedef unsigned int t32bits;
#else
#error need a 32-bit unsigned type
/* if you see the above error, add an #elif case for your architecture
X   and tell fdc@cliwe.ping.de about it */
#endif
X
#if USHRT_MAX == 65535
typedef unsigned short t16bits;
#elif UINT_MAX == 65535
typedef unsigned int t16bits;
#else
#error need a 16-bit unsigned type
/* if you see the above error, add an #elif case for your architecture
X   and tell fdc@cliwe.ping.de about it */
#endif
typedef t16bits pixnum;
X
struct pagenode;
X
/* drawfunc() points to a function which processes a line of the
X   expanded image described as a list of run lengths.
X   run is the base of an array of lengths, starting with a
X   (possibly empty) white run for line number linenum.
X   pn points to the page descriptor */
typedef void (*drawfunc)(pixnum *run, int linenum, struct pagenode *pn);
X
struct strip {			/* tiff strip descriptor */
X    struct strip *next;		/* next in list */
X    off_t offset;		/* offset in file */
X    off_t size;			/* size of this strip */
};
X
struct pagenode {		/* compressed page descriptor */
X    struct pagenode *prev, *next; /* list links */
X    char *name;			/* basename of file */
X    char *pathname;		/* full name of file */
X    struct strip *strips;	/* list of strips containing fax data in file */
X    t16bits *data;		/* in-memory copy of file */
X    off_t length;		/* length of fax data */
X    pixnum width;		/* width of page in pixels */
X    pixnum height;		/* height of page in lines */
X    int inverse;		/* black <=> white */
X    int lsbfirst;		/* bit order is lsb first */
X    int orient;			/* orientation - upsidedown, landscape */
X    int vres;			/* vertical resolution: 1 = fine  */
X    void (*expander)(struct pagenode *, drawfunc);
X    void *extra;		/* used for Ximage */
};
extern struct pagenode *firstpage, *lastpage, *thispage;
extern struct pagenode defaultpage;
X
/* page orientation flags */
#define TURN_U	1
#define TURN_L	2
#define TURN_M	4
X
extern char *ProgName;
X
/* fsm state codes */
#define S_Null		0
#define S_Pass		1
#define S_Horiz		2
#define S_V0		3
#define S_VR		4
#define S_VL		5
#define S_Ext		6
#define S_TermW		7
#define S_TermB		8
#define S_MakeUpW	9
#define S_MakeUpB	10
#define S_MakeUp	11
#define S_EOL		12
X
/* state table entry */
struct tabent {
X    unsigned char State;
X    unsigned char Width;	/* width of code in bits */
X    pixnum Param;		/* run length */
};
X
extern struct tabent MainTable[]; 	/* 2-D state table */
extern struct tabent WhiteTable[];	/* White run lengths */
extern struct tabent BlackTable[];	/* Black run lengths */
X
extern int verbose;
X
void g31expand(struct pagenode *pn, drawfunc df);
void g32expand(struct pagenode *pn, drawfunc df);
void g4expand(struct pagenode *pn, drawfunc df);
X
unsigned char * getpage(struct pagenode *pn);
struct pagenode *notefile(char *name);
int notetiff(char *name);
X
/* initialise code tables */
extern void faxinit(void);
/* count lines in image */
extern int G3count(struct pagenode *pn, int twoD);
X
/* get memory or abort if none available */
extern char *xmalloc(unsigned int size);
X
#ifdef linux
#define _HAVE_USLEEP
#endif
X
#if defined(BSD) || defined(__FreeBSD__) || defined(_BSD_SOURCE)
#define _HAVE_USLEEP
#ifndef rindex
#define rindex strrchr
#endif
#ifndef bcmp
#define memcmp bcmp
#endif
#define memclr(p,n)	bzero(p,n)
#else  /* not BSD */
#define memclr(p,n)	memset(p,0,n)
#endif
SHAR_EOF
chmod 0664 viewfax-2.2/faxexpand.h ||
echo 'restore of viewfax-2.2/faxexpand.h failed'
Wc_c="`wc -c < 'viewfax-2.2/faxexpand.h'`"
test 4329 -eq "$Wc_c" ||
	echo 'viewfax-2.2/faxexpand.h: original size 4329, current size' "$Wc_c"
fi
true || echo 'restore of viewfax-2.2/faxinput.c failed'
echo End of part 1, continue with part 2
exit 0

-- 
Frank Cringle                      | fdc@cliwe.ping.de
voice + fax                        | +49 2304 467101


