#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Introducing_AUB BUG_FIXES README aub aub.1
# Wrapped by stantz@sierra on Tue Sep  8 21:04:26 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Introducing_AUB' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Introducing_AUB'\"
else
echo shar: Extracting \"'Introducing_AUB'\" \(25179 characters\)
sed "s/^X//" >'Introducing_AUB' <<'END_OF_FILE'
X
X
X			The Introducing AUB Document
X
X
X	1.	What is aub?
X
X	More and more people are posting binary files to usenet these days.
Some of these binaries are executables and audio data; a majority seem to
be pictures of various things, typically landscapes, movie stars and naked
people.  Because of limitations in the type data that usenet can accommodate, 
binaries must be encoded into text, and because binary files are commonly very 
large relative to text files usenet was designed to handle, they frequently 
must be broken up into pieces.  Programs have been developed which take a 
given binary, encode it, and automatically post it in pieces with descriptive 
subject lines.
X
X	When this data arrives at a remote site, users see subject lines
that look something like this:
X
X		12011 roadkill03.gif, part 1/4
X		12012 roadkill03.gif, part 3/4
X		12013 More pictures of tatooed children, please...
X		12014 Re: roadkill02.gif -- I love the way the eyes bulge out
X		12015 roadkill03.gif, part 4/4
X		12016 roseanne_nude.jpg, part 02 of 02
X	   	12017 Only BINARIES should be posted here, GOD DAMMIT	
X		12018 roadkill03.gif, part 2/4
X		12019 HI, I'M BIFF!!!!  THESE PIX ARE WAY COOL!!!!
X		12020 roseanne_nude.jpg, part 01 of 02
X
X	While the process of encoding and splitting up binaries for posting 
to usenet is relatively straightforward, the process of retrieving, sorting,
and decoding the pieces (which do not necessarily arrive in order) at 
receiving sites is less straightforward, tedious, time consuming, and very
prone to human error.  
X
X	aub, which stands for "assemble usenet binaries", automates this 
reassembly process for you.  aub is intended for use in newsgroups to which 
binaries are posted exclusively.  When run, it accesses news articles via
either a disk-based news spool directory, or via an NNTP news server, 
determines whether or not any new binaries have appeared in selected 
newsgroups since the last time it was run, and if so, retrieves, organizes 
and decodes them, depositing them in a configurable location.  This process 
requires no human intervention once aub has been configured.  aub also keeps 
track of binaries which it has seen some, but not all, of the pieces of.  It 
remembers how to find these old pieces, so that when new, previously missing 
pieces arrive at your site, it will build the entire binary the next time it 
is run.  It also remembers which binaries it has already seen all of the 
pieces of already, so that it does not waste time rebuilding the same binaries 
over and over again.
X
X	aub was created as a time saver; too many people at too many sites 
were spending way too much time manually unpacking binary files.  Its ability 
to identify and assemble binary images depends on people posting images with
subject lines that observe (loosely) established conventions.  aub's 
recognition capabilities have been significantly improved since the earliest 
release.
X
X
X	2.	How does aub work?
X
X	aub looks for subject lines containing strings like:
X
X		N of N
X		N / N
X		N  N
X		N | N
X
X	where N is any number composed of one or more digits, and white
space is optional.  Once it sees such a line, it tries to figure out a
name for the binary by looking at the rest of the subject line.  These names 
are relevant only to aub's internal functioning; when unpacked, binaries are 
named according to the information they were encoded with.  However, it's 
important that, whatever internal name aub decides on for the binary, that 
name be recognizable in the subject lines of all pieces.
X
X	aub ignores all news articles with null subject lines and subject
lines that begin with "Re:" regardless of other content.
X
X	aub uses two files which are maintained in each user's home directory.
One is $HOME/.aubconf, which is a configuration file that allows you to 
customize aub's behavior.  See section 5 for a detailed explanation of the
structure of configuration files.  The other file is $HOME/.aubrc.  You
should never need to modify this file; aub creates it and maintains it.  It's
used to keep track of what articles in which groups aub has resolved 
already, and what articles aub believes to be pieces of binaries that it 
hasn't seen all of the pieces of yet.  
X
X
X    	3.	What do I need on my system to run aub?
X
X	You will need Larry Wall's perl interpreter.  Older versions of aub
also required David Mack's uumerge program; this functionality has since been
folded into aub for the sake of speed.  perl is available via anonymous FTP 
from uunet.uu.net, tut.cis.ohio-state.edu, and jpl-decvax.jpl.nasa.gov.  
X
X	Your machine must also have access to news, either via the NNTP
NNTP protocol, or by being able to open raw news files on a disk somewhere.  
Previous versions of aub required that your news access be NNTP-based; this 
restriction has since been lifted.
X
X
X	4.	How do I install aub?
X
X	There's really only one thing that you might need to configure.
aub is a perl script.  The first line of the program looks like this:
X
X		#!/usr/local/bin/perl
X
X	This appears to tell your shell where to find the perl interpreter.  
If the path of perl on your system is something else, you'll need to change 
this line, or create a link called /usr/local/bin/perl which points to where
your perl executable actually resides.
X
X	If you need to change this, you'll probably see a message like:
X'aub: Bad address.' when you try to run aub.
X
X
X	5.	How do I configure aub?
X
X	Older versions of aub made use of a configuration file which was
normally called $HOME/.aubinit.  But few interesting customizations could 
be accomplished with .aubinit files, because the configuration language
was so primitive.  The configuration language has been redesigned to allow
much greater flexibility.  Old .aubinit files will no longer work, or be
recognized by aub (except inasmuch as aub will notice them and point out
to you that you need to create a new configuration file if you don't already
have one.)  The new configuration file for aub should be called $HOME/.aubconf.
X
X	Configuration files are line-oriented; each line is processed 
separately.  If any line contains the '#' character, aub concludes that 
the character begins a comment, and discards the comment character and 
everything one the line that follows it.  If for some reason you need to
put a '#' character in your configuration file and do not want it to be 
interpreted as beginning a comment, you'll have to escape it by preceding it 
with a backslash character, e.g. '\#'.
X
X	Each non-blank line in a configuration file must begin with a 
keyword recognized by aub.  The case of keywords is not significant.
As far as aub is concerned, "keyword", "KEYWORD", "Keyword" and "KeYWorD"
all mean the same thing.  Some keywords require arguments; some require no 
arguments appear, and some permit varialbe numbers of arguments.  If aub 
sees keywords it doesn't understand in your .aubconf file, it will complain 
to you about them.
X
X	One of the keywords aub understands is the GROUP keyword.  It's
used to tell aub that you want to decode binaries from the newsgroup(s)
which appear as argument(s) to the keyword.  For example:
X
X		GROUP alt.binaries.pictures.misc
X		GROUP alt.binaries.pictures.misc alt.binaries.pictures.fractals
X
X	Every configuration file must contain at least one GROUP keyword to
be correct.  
X
X	In general, aub understands two types of keywords.  One type is 
called 'position insensitive', which means that the keyword will have the
same effect no matter where in the configuration file it appears.  The
other type is called 'position sensitive', which means that the keyword 
means something different when it appears before any GROUP keywords than
it does when it appears after any given GROUP keyword.
X
X	One such position sensitive keyword is the DIRectory keyword.
This keyword is used to tell aub what directory to put binaries it decodes
in.  ("DIRectory" is spelled the way it is because only the 'DIR' part needs 
to appear in a configuration file for aub to recognize it.  In fact, aub will 
interpret any keyword beginning with the letters 'DIR' as being an instance
of the DIRectory keyword.)
X
X	When a position sensitive keyword appears _before_ any GROUP keyword,
the keyword is interpreted as being the default for all groups that appear
later.
X
X	When a position sensitive keyword appears _after_ any GROUP keyword,
it is interpreting as applying *only* to that group, overriding any previous
default which may have been established via use of the same keyword, or
by the value of environment variables (see section 8.)
X
X	Position sensitive keywords appearing after a GROUP keyword which
lists multiple groups are applied only to the last group listed, not to 
all groups appearing on the group line.
X
X	For example, the following three configuration files are equivalent:
X
X	# Sample .aubconf file no. 1 -- basic example
X	# 
X	dir /tmp/aub					# Default directory
X	group alt.binaries.pictures.misc		# Process these
X	group alt.binaries.pictures.fractals		#  two groups
X
X        # Sample .aubconf file no. 2 -- multiple group usage, mixed case
X        #
X        DiR /tmp/aub                                    # Default directory
X        gRoUp alt.binaries.pictures.misc alt.binaries.pictures.fractals
X
X        # Sample .aubconf file no. 3 -- does not use defaults
X        #
X        group alt.binaries.pictures.misc
X        directory /tmp/aub                            
X        group alt.binaries.pictures.fractals
X        direct-to /tmp/aub                           	# 'dir' is all you need
X
X	The following three configuration files are also equivalent, though
not equivalent to the previous three:
X
X        # Sample .aubconf file no. 4 -- explicit placement of binaries
X        #
X        group alt.binaries.pictures.misc
X        dir /tmp/aub/misc
X        group alt.binaries.pictures.fractals
X	dir /tmp/aub/fractals
X
X        # Sample .aubconf file no. 5 -- explicit and default placement 
X        #
X        dir /tmp/aub/misc   				# Default directory
X        group alt.binaries.pictures.misc		# Use default directory
X        group alt.binaries.pictures.fractals
X	dir /tmp/aub/fractals				# Override default
X
X        # Sample .aubconf file no. 6 -- explicit and default placement revisited
X        #
X        dir /tmp/aub/fractals 				# Default directory
X        group alt.binaries.pictures.misc
X	dir /tmp/aub/fractals				# Override default
X        group alt.binaries.pictures.fractals		# Use default directory
X
X	The configuration file:
X
X	# Sample .aubconf file no. 7 -- invalid
X	#
X	group alt.binaries.pictures.misc
X	dir /tmp/aub
X	group alt.binaries.pictures.fractals		# No good
X
X	is invalid, because no directory for aub to place binaries decoded
from the newsgroup alt.binaries.pictures.fractals is specified.  The 
DIRectory keyword is unique in this regard; there must be some use of the
keyword that enables aub to figure out where to put binaries for every 
group specified, or it will refuse to run.  The easiest way to deal with 
this is to always establish a default directory by using the DIRectory
keyword somewhere before any groups appear.  
X
X
X	Other position sensitive keywords are available.  
X
X
X		DESCription <file>
X
X	This keyword causes aub to extract text from what it thinks is the 
text portion of posted articles, and append it to the file you specify.  This
is useful if you're interested in reading the text that describes what all
the binaries aub is unpacking are about.  A maximum of 60 lines per binary
extracted will be put into the file you indicate.  Each description is
prepended with the name of the decoded binary it refers to, and the group
that binary was decoded from.
X
X
X		HOOK <program>
X
X	This keyword enables you to select which binaries aub decodes
using your own software.  If the HOOK keyword is specified, aub will 
invoke the argument program and supply it with subject line of the first
piece of a binary that it can potentially decode via standard input.  If the 
program returns true (zero), aub will decode the binary.  If the program 
returns false (non-zero), aub will skip decoding the binary, and continue 
processing.
X
X	It is not (yet) possible to specify arguments to the user program.
X
X	For example, the following sample program returns true if standard
input contains the string ".gif" (case insignificant), and false otherwise.
X
X	#!/usr/local/bin/perl
X	#
X	# /tmp/sample_aub_hook: a simple, sample hook program
X	#
X
X	$sl = <STDIN>;                  # Get standard input
X	exit(0) if ($sl =~ m/.gif/i);   # Contains ".gif"
X	exit(1);			# Didn't see ".gif"
X
X	Suppose this program were attached to aub via the configuration line:
X
X		hook /tmp/sample_aub_hook
X
X	Then aub would only decode binaries containing the string '.gif'.
X
X	You can write hook programs in any language you choose.  
X
X
X		POSTprocess <postprocessor> <extn> ...
X
X	This keyword enables you to postprocess binaries whose names end
in the string <extn> (you can list any number of these suffixes on a single
line in the configuration file.)  Case is not significant in <extn>.  Before
a POSTprocess keyword can appear, <postprocessor> must first be defined 
using the DEFine keyword, which is position insensitive.  The format of
the DEFine keyword is
X
X		DEFine	<postprocessor> <unix cmd>
X
X	<postprocessor> may be any string.  It's recommended that you
stick to alphanumerics.
X
X	<unix cmd> is any UNIX command, with arguments.  Simple substitutions
are performed on <unix cmd> before it's executed in conjunction with the
existenece of a POSTprocess keyword and the appearance of a binary whose
filename ends in one of the <extn> suffixes listed as arguments to the 
POSTprocess keyword.  This all makes perfect sense but is a little difficult
to explain.  The following example should make things much clearer.
X
X	Consider the following configuration file:
X
X	# Sample aub configuration file demonstrating use of a postprocessor
X	#
X	dir /tmp/aubdir
X	define jpg2gif djpeg -G $f > $h_.gif
X	postprocess jpg2gif .jpg .jpeg
X	group alt.binaries.pictures.misc
X
X	The first line tells aub that it should decode binaries into the
directory /tmp/aubdir.  The second line defines a postprocessor for aub.  
The name of the postprocessor is specified as "jpg2gif".  The third line 
says that the postprocessor will be invoked whenever a binary with a name 
ending in '.jpg' or '.jpeg' is decoded.  The fourth line specifies the 
group that binaries are to be decoded from.
X
X	Suppose the binary full_moon.jpeg is decoded from 
alt.binaries.pictures.misc.  The binary name "full_moon.jpeg" can be 
thought of as consisting of three parts; the head part -- everything before
the last '.' character --  the '.' character itself, and the tail part --
everything after the last '.' character.  aub uses the abbreviations 
X'$h', '$t', and '$f' to refer to the head part, tail part, and entire
filename, respectively.  (If no '.' character appears in the name of a 
decoded binary, $h equals $f, the entire name of the binary, and $t is 
empty.) 
X
X	Because the binary name "full_moon.jpeg" ends in ".jpeg", one of the
arguments specified on line two of the sample configuration file, aub 
invokes the postprocessor "jpg2gif".  aub substitutes the appropriate 
values for '$f' and '$h', in this case, "full_moon.jpeg" and "full_moon"
into the postprocessor definition, and executes the resulting UNIX command,
which in this case is 'djpeg -G full_moon.jpeg > full_moon_.gif'  Assuming 
that you have the djpeg program on your machine (this software is available 
via anonymous FTP from ftp.uu.net under the graphics/jpeg directory), this 
command will cause the .jpeg file to be automatically converted into a 
similarly named .gif file when it is decoded.
X
X	A few more examples, again, based on the configuration file above
X
X   Filename of decoded binary        $h		$t		$f
X------------------------------------------------------------------------------
X	crescent_moon.jpg	crescent_moon	jpg	crescent_moon.jpg
X	big.dog.gif		big.dog		gif	big.dog.gif
X
X   Filename of decoded binary	Postprocessed         Reason
X------------------------------------------------------------------------------
X	crescent_moon.jpg	   yes       $f ends in '.jpg'
X	big.dog.gif		   no	     $f doesn't end in '.jpg' or in
X					      '.jpeg'
X
X    Filename of decoded binary	UNIX command executed
X------------------------------------------------------------------------------
X	crescent_moon.jpg	djpeg -G crescent_moon.jpg > crescent_moon_.gif
X	big.dog.gif		(none executed)
X
X
X	We could have easily have written:
X
X		define jpg2gif djpeg -G $f > $h_.gif ; rm -f $f 
X
X	to cause aub to remove the old .jpeg version of the binary after
converting it to .gif format.
X
X	I've added the extra underscore character in this example to 
decrease the chance that djpeg, when it runs, will clobber another 
binary which aub already unpacked with the name "full_moon.gif" or
X"cresecent_moon.gif". 
X
X	Postprocessor definitions that can't be executed for some reason
may cause you (and aub) some problems at run time.  
X
X
X	The following keywords are, like DEFine, position independent:
X
X
X		NNTP <server>
X
X	This tells aub that your news access is NNTP-based, and that it
should use the specified host as an NNTP server. 
X
X
X		SPOOL <directory>
X
X	This tells aub that your news access is based on access to raw news
files, and that <directory> is the root of the news spool tree. 
X
X	A single configuration file may not contain both the NNTP and SPOOL
keywords.
X
X	If neither the NNTP keyword nor the SPOOL keyword appear in your
configuration file, aub will assume your news access is via NNTP and use
your NNTPSERVER environment variable, if it is defined, to decide what 
server to connect to.  If your NNTPSERVER environment variable is not
defined, aub will try to figure out where you normally read news from.
If it can't do that, it will ask you to supply the information.
X
X	If you ever change the mechanism by which you access news, or the
server you read news on, you'll need to remove the .aubrc file that aub
maintains to keep track of what groups you have and have not read.  Otherwise,
because articles are numbered differently on different servers, aub will get
hopelessly confused.  (It's possible, though not recommended, to switch
seamlessly back and forth between NNTP and SPOOL access to news on the 
same host.)  This is probably the only time you'll ever want to tamper with
a .aubrc file.
X
X
X		DEBUG <n>
X
X	Sets the default debugging level aub runs at to N.  N must be a 
non-negative integer.  Debugging level 0 is the default; when run at 
debugging level zero, aub produces no output unless it runs into serious
problems.  Setting the debugging level to 1 will tell you about what aub is
doing.  Setting the debugging level to 2 will tell you even more about what
aub is doing.  Setting the debugging level to 3 or higher will show you 
more than you ever wanted to know.
X
X
X		RECognize <extn> ...
X
X	The recognition code (the part of aub that identifies binaries) 
maintains a list of common suffixes that it uses to recognize binaries 
while it scans subject lines.  For example, many binaries have names ending 
in ".gif", so ".gif" is on aub's internal list of hints.  The RECognize
keyword allows you to add suffixes to this internal list of hints.
X
X	Use this capability sparinging.  You can really give aub a coronary 
by saying something like 'rec a b c d e f g ...'.  Doing something foolish 
like that will cause your aub to lose the ability to assemble things that it 
would otherwise have been able to.  
X
X	The current list of common suffixes aub maintains is:
X
X	".gif", ".jpg", ".jpeg", ".gl", ".zip", ".au", ".zoo", ".exe", ".dl", 
X	".snd", ".mpg", ".mpeg", ".tiff", ".lzh", ".wav"
X
X
X		NOXHDR
X
X	This keyword is meaningful only if your news access is NNTP-based.
It will cause aub to not use the XHDR command to access the subject lines
of news articles, even if the NNTP server you're using has XHDR capability.  
X
X
X	If the same keyword appears multiple times, and the second 
appearance is not a position sensitive override of some established default,
then aub ignores the second instance of the keyword.
X
X
X	7.	How do I use aub?
X
X	After you've built your configuration file, just run 'aub'.  
X
X	If this is the first time you've run aub since v1.1, you may 
want to undefine any AUB-related environment variables you had set.  These
variables are interpreted differently now.  See section 8.  You will not
need to remove your .aubrc file, but your .aubinit file is no longer useful
and you'll probably want to get rid of it once you've created .aubconf.
X
X	If this is the first time you've run any version of aub, ever, you 
may want to use the '-c' command line option.  Or you may not...see section 9.
X
X
X	8.	Environment variables used by aub.
X
X	$AUBDIR		Sets the default directory binaries are unpacked into.
X			Equivalent to specifying a DIRectory keyword before 
X			any GROUP keywords.  Will override any DIRectory 
X			keyword appearing before any GROUP keyword, but not 
X			those appearing after a GROUP keyword.
X
X	$AUBDESC	Analogous to $AUBDIR
X
X	$AUBHOOK	Analogous to $AUBDIR
X
X	$NNTPSERVER	Specifies an NNTP server to use for news access if
X			no NNTP keyword appears in the configuration file.
X			If an NNTP keyword does appear, $NNTPSERVER is 
X			ignored.
X
X	Note that $AUBGROUPS is no longer used as of version 2.0.3.
X
X	If aub doesn't seem to be doing what you'd expect it to do based
on your .aubconf file, it could be because your environment variables
are causing defaults you've established there to be ignored.
X
X
X	9.	Command line options supported by aub:
X
X	-c		'Catch-up' mode; aub will bring its internal 
X			pointers (and your .aubrc file) up to date, but will 
X			not actually generate any binaries.  This is useful 
X			when you run aub for the first time; it keeps it 
X			from generating megabytes and megabytes, as it scans 
X			old news articles.
X
X	-n		'No-checkpoint' mode; prohibits aub from updating
X			its internal pointers (your .aubrc file).  This option
X			is primarily useful only during debugging.
X
X	-dn		'Debug' mode; sets the debugging level to N.  This
X			overrides the debugging level set in the configuration
X			file, except that 'aub -d0' does not work...this is a 
X			bug.
X
X	-M		Causes aub to print the long form of the documentation
X			(this document.) 
X
X	-m		Causes aub to print a summary of the documentation.
X
X	-C		Lists significant changes since that last major 
X			release of aub.
X
X
X	10.	What do I do if I have problems installing or configuring aub?
X
X	See if you can figure out what the problem is.  I've only set aub
up on my local system, so it's possible you could have problems I haven't
foreseen.  If you really can't get it to work, try talking to a friend who
knows systems programming and administration type stuff.  Offer your friend
food -- systems people especially like dim sum and Heineken.
X
X	You could also send me mail.  Whether or not I answer your mail will 
depend a lot on how busy I am.  Sorry, but I have an obligation to get work 
done promptly for my client, who's paying me for my time.  I can't really deal 
with supporting aub on the side for the entire net.  Also, if your problem
has to do with peculiarities of your local site, there may not be a lot I 
can do about it.
X
X
X	11.	What else do I need to know?
X
X	In order to guarantee proper administration of the .aubrc file,
you can only run one instance of aub at a time.  In this respect aub is
similar to most newsreaders.
X
X	The first time you run aub over a given group, if you choose not to
use the -c option, it may take a long time to run.  This is because it's 
looking at all of the articles in the group, and building lots of binaries.  
After you run it for the first time, it only needs to look at new stuff in 
the group.  Things will go much faster after that.  
X
X	If aub assembles two binaries with the same name, and wants to store
them in the same place, it will compare them to see whether or not they're 
identical.  If they are identical, it will discard the newer copy.  If 
they're not identical, it will append '+' characters as necessary to the 
name of the second binary until the name is unique.
X
X	aub checkpoints its progress in the .aubrc file after processing
each group.  This keeps it from having to start all over again if it dies
of a signal, expired CPU time limit, etc...
X
X	aub takes liberties with changing around the names of binaries 
that it doesn't particularly like.  It may rename binaries to be called
X"Mangled" if people post things that are supposed to be unpacked to "." or 
X"..", or something equally obnoxious, for instance.  It will drop the 
leading "." off of binaries called ".something", and relativize pathnames
so that your binaries always wind up in the directories you want them in.
X
X	It's unfriendly to run aub so often that you occupy too much of your
news server's time.
X
X	It's pronounced "oww-buh", as in "S(au)di", not "awe-buh", as in 
X"sl(aw)".
X
X	This software is offered as-is, with no guarantees or promises made 
by me whatsoever.  I disclaim all responsibility for loss or damage caused
by the program.
X
X
X						Mark Stantz
X						stantz@sierra.stanford.edu
X						stantz@sgi.com
X						8/92
X
END_OF_FILE
if test 25179 -ne `wc -c <'Introducing_AUB'`; then
    echo shar: \"'Introducing_AUB'\" unpacked with wrong size!
fi
# end of 'Introducing_AUB'
fi
if test -f 'BUG_FIXES' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'BUG_FIXES'\"
else
echo shar: Extracting \"'BUG_FIXES'\" \(2262 characters\)
sed "s/^X//" >'BUG_FIXES' <<'END_OF_FILE'
X
X	Big fixes made to aub since the release of v2.0:
X
X
X				PATCH #1	(v2.0.1)
X
X	-- Fixed aub to run under versions of perl earlier than 4.035
X	   (but not earlier than 4.0.)
X	-- Lifted silly requirement that news spool directory be writable
X	-- Corrected typo in error reporting code that left part of an
X	   error message blank.
X	-- Corrected use of wrong variable in desperatation NNTP server
X	   guessing code (this code rarely used in practice.)
X
X				PATCH #2	(v2.0.2) 
X
X	-- Fixed aub to run under versions of perl earlier than 4.0
X	-- Fixed bug in NNTP protocol to keep aub from confusing the
X	   end of an NNTP transaction with the line "." in a message.
X	-- Made aub understand that the 'Minimum-OS2-Version:' header
X	   seen in comp.binaries.os2 does not mean that it should expect
X	   immediate uudecodable stuff to follow, even though the line
X	   does begin with "M".
X	-- Fixed bug that required postprocessor definitions and invocations
X	   to name the postprocessor exactly the same way (no mixed case)
X	-- Made erorrs go to stdout instead of standard error to integrate
X	   them in the debug output stream.
X	-- Fixed typo in 'aub -M' output -- description of how to escape the
X	   comment character was botched.
X
X				PATCH #3	(v2.0.3)
X
X	-- Prevented aub from generating mode 0 binaries.  RFE: 2.1 will 
X	   contain the position sensitive MODE keyword.
X	-- Fixed problems in the last resort search for systems programs code
X	-- No longer automatically try to find hook programs specified with
X	   absolute path names.
X	-- Made aub marginally smarter about finding libraries (I think)
X	-- Added a tad more debugging output
X	
X				PATCH #4	(v2.0.4)
X
X	-- Added additional verification that suspected uuencoded data really
X	   is uuencoded.  This helps aub decode binaries it previously would
X	   have choken on.
X	-- Now understands the '|' separator (ie, "foo.Z part 2|3")
X
X				PATCH #5	(v2.0.5)
X
X	-- Code introduced in 2.0.4 was too restrictive.  Some decodable
X	   binaries contain more than exactly 61 characters per line. 
X	   Relaxed the error checking somewhat.
X	-- Fixed bug that didn't break anything until 2.0.4, when the
X	   restrictive code was added.
X	-- Now mapping subject lines to lower case internally to improve
X	   recognition abilities.
END_OF_FILE
if test 2262 -ne `wc -c <'BUG_FIXES'`; then
    echo shar: \"'BUG_FIXES'\" unpacked with wrong size!
fi
# end of 'BUG_FIXES'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(501 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X	Shipping list:
X
X	aub 			-- executable perl script.  v2.0 of aub.
X	aub.1			-- man page for aub.
X	Introducing_aub		-- documentation for aub.
X	BUG_FIXES		-- changes since release 2.0
X	README			-- this file
X
X	The "Introducing_aub" document is exactly the output of 'aub -M'.
This is packaged separately in case you want to read the documentation but
don't have perl on your system.  If you do have perl on your system, there's
no reason not to delete this file; you can always generate it again.
X
X	-mfs
END_OF_FILE
if test 501 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'aub' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'aub'\"
else
echo shar: Extracting \"'aub'\" \(85834 characters\)
sed "s/^X//" >'aub' <<'END_OF_FILE'
X#!/usr/local/bin/perl
X#
X#
X#
X# aub: assemble usenet binaries
X#
X#  Mark Stantz, stantz@sgi.com, stantz@sierra.stanford.edu
X#
X#  aub v1.0 1/92	Basic functionality only.  Buggy.
X#      v1.1 3/92	Cleaned up, documented, released, added functionality.
X#      v2.0 8/92.	Major rewrite, numerous enhancements, speed hacks.
X#			Now requires a formal configuration file.
X#
X# This code is offered as-is.  Anyone is welcome to make improvements, 
X# provided that my notice of authorship is retained.  I accept no 
X# responsibility for loss or damage caused by this program, nor do I accept
X# responsibility for supporting it.
X#
X# Most of the documentation for this program is self-contained.
X#
X# 	aub -m			Prints the short form of the documentation
X#	aub -M			Prints the long form
X#	aub -C 			Lists changes made since previous version
X#
X#
X# DEPENDENCIES:
X#
X# /bin/echo			-- &find_pg will look for these for you if
X# /bin/sum			    they aren't in the usual place.  Though
X# /bin/cat			    I don't know of any *NIX so bizarre...
X# /bin/mv
X# which 			-- These had better be in your path;
X# whereis			    I'm not looking for them.  But they
X#				    only help you if your other stuff isn't
X#				    in the standard place.
X
X$ECHO = "/bin/echo"; &find_pg("echo", 0) unless (-x $ECHO);
X$SUM = "/bin/sum";   &find_pg("sum", 0)  unless (-x $SUM);
X$CAT = "/bin/cat";   &find_pg("cat", 0)  unless (-x $CAT);
X$MV = "/bin/mv";     &find_pg("mv", 0)   unless (-x $MV);
X
X# CONSTANTS: 	most likely you want to leave these alone.  
X#
X#
X# $aub_rcfile			Keeps track of what groups we assemble 
X#				binaries in, and what articles there we've
X#				not yet resolved.
X#
X# $aub_lock			A lockfile, used to ensure that only one
X#				instance of aub runs at a time.
X#
X# $aub_tmp			A temporary file, used in the construction
X#				of $aub_rcfile
X#
X# $general 			Magic cookie for accessing general aub
X#				parameters.  Must be an invalid newsgroup
X#				name.
X#
X# $aub_dir			If the AUBDIR environment variable is set, it
X#				will override the general (but not specific)
X#				aub directory specified in the configuration
X#				file.
X# 
X# $aub_desc			Specifies the general description file.
X#
X# $aub_hook			Specified the general hook program.
X#
X# $mini_aub_config		Unqualified name of our configuration file.
X#
X# $aub_config			Qualified name of our configuration file.
X#
X#
X# $timeout_interval		How long we'll wait for a response from an 
X# 				NNTP server before deciding it's died on us.
X#
X# $version			Version number of this program.
X#
X# $last_version			Version number of previous release.
X# 
X# $temp_decode_file		Another temporary file; binaries are actually
X#				assembled here before being moved into an
X#				aub directory.
X#
X# $nntpserver_file		A place aub can find the name of the NNTP 
X# 				server it's supposed to use.  This is ignored
X#				if the user's NNTPSERVER environment variable
X#				is set, or if an NNTP server is specified in
X#				the configuration file.
X#
X# $obsolete_init		Name of obsolete v1.1 pre-warp-drive proto-
X#				configuration file.
X#
X# @sigs				List of signals that might interrupt our 
X#				progress.
X#
X# @extn_hints			Extensions which help us recognize binary
X#				images in subject lines.
X
X$aub_rcfile 	    = join("/", $ENV{"HOME"}, ".aubrc");
X$aub_lock   	    = join("/", $ENV{"HOME"}, ".aub_lock");
X$aub_tmp    	    = join("/", $ENV{"HOME"}, ".aubtmp");
X
X$general 	    = ".";
X$aub_dir{$general}  = $ENV{"AUBDIR"};
X$aub_desc{$general} = $ENV{"AUBDESC"};
X$aub_hook{$general} = $ENV{"AUBHOOK"};
X
X$mini_aub_config    = ".aubconf";
X$aub_config 	    = join("/", $ENV{"HOME"}, $mini_aub_config);
X
X$timeout_interval   = 60;
X$version	    = "2.0.5";
X$last_version	    = "1.1";
X$temp_decode_file   = "/usr/tmp/aub.decode$$";
X$nntpserver_file    = "/usr/local/lib/rn/nntpserver";
X$obsolete_init	    = join("/", $ENV{"HOME"}, ".aubinit");
X
X@sigs		    = ('HUP', 'INT', 'QUIT', 'ILL', 'TRAP', 'IOT', 'EMT', 'FPE',
X		       'BUS', 'SEGV', 'SYS', 'TERM', 'USR1', 'USR2', 'XCPU', 
X		       'XFSZ', 'PIPE');
X
X@extn_hints 	    = (".gif", ".jpg", ".jpeg", ".gl", ".zip", ".au", ".zoo", 
X                       ".exe", ".dl", ".snd", ".mpg", ".mpeg", ".tiff", ".lzh",
X			".wav");
X
X#
X# GLOBAL variables
X#
X#
X# There are zillions of 'em, and I don't have the energy to document them all
X# just now.  If you see something that's not explicitly defined as local(),
X# assume it's global.
X#
X
X#
X# Main program  -- Setup code.
X#
X
X#
X# Parse arguments.  If only documentation is requested, deal with it ASAP
X# and bail out.
X#
X# I probably should have an argument that lets you specify an alternate 
X# configuration file, but if I do that, there'll be some bozo who won't
X# realize I've broken compatibility with the v1.1 configuration file and
X# will just use the argument to point v2.0 at his obsolete .aubinit file.
X# Then I'll get mail when it doesn't work.  I don't want to deal with that,
X# so I'm delaying the command line option until v2.2.  (Almost certainly
X# v2.1 will be bug fixes for v2.0.)
X#
X
X(&Getopts("cd:nCMm")) || (exit(1));
X
X&long_manual if ($opt_M);			# None of these subroutines
X&short_manual if ($opt_m);			#  will return...
X&changes if ($opt_C);
X
X# Make sure we clean up when we catch an unexpected signal
X
foreach (@sigs) {
X  $SIG{$_} = 'handler';
X}
X
X# Make a first guess at what file we want to use as our NNTP server.  If the
X# user's NNTPSERVER environment variable is defined, we'll use what's in it.
X# Otherwise, if $nntpserver_file exists, we'll take a hint from it.
X
if ($ENV{"NNTPSERVER"}) {
X  $server = $ENV{"NNTPSERVER"};
X} elsif (-r $nntpserver_file) {
X  chop($defserver = `$CAT $nntpserver_file 2>/dev/null`);
X  $defserver = $1 if ($defserver =~ m/^([^\n]+)\n/);
X}
X
X# Load the configuration file.
X
X&load_config_file;
X
X#
X# At this point, we should know for certain whether or not we're using
X# disk-based news access or NNTP access.  If we're going to use NNTP,
X# we have to have figured out what our server is.
X#
X# If our news access is NNTP-based, we need the &AF_INET and &SOCK_STREAM
X# subroutines defined.  These must come from sys/socket.ph, a perl include
X# file.  The user's system may not have this file on it if no-one's run
X# h2ph there.  We'll explain all this to them if we have to.
X#
X# We don't want to depend on &AF_INET and &SOCK_STREAM being defined if
X# we don't have to, so we'll only try to load them if we're running NNTP-
X# based.
X
if ($spooldir) {
X  print "Using disk-based news access; spool directory is $spooldir\n"
X    if ($opt_d);
X} else {
X  &abort("Can't find an NNTP server; please define your NNTPSERVER " .
X         "environment variable\nor specify an NNTP server or disk based " .
X         "news access in your configuration file.") unless ($server);
X
X  if ($opt_d > 1) {
X    print "Searching library directories:";
X    foreach $libr (@INC) {
X      print " $libr";
X    }
X    print " for sys/socket.ph...\n";
X  } 
X
X  &need_to_run_h2ph unless (eval("require <sys/socket.ph>"));
X
X  print "Using NNTP-based news access; server is $server\n"
X    if ($opt_d);
X
X# For NNTP access, we'll need to figure out the remote NNTP service port 
X# number (119 is standard)
X
X  ($name, $junk, $port, $junk) = getservbyname("nntp", "tcp");
X  &abort("Can't find port number for NNTP service") unless ($name);
X
X# Open up a connection to the remote nntp server.  
X  &connect_tcp(SOCKET, $server, $port, 1);	# Connect or bust
X  $connected_to_server++;			# For cleanup routines
X  &setup_socket_io(SOCKET);			# Necessary I/O setup stuff
X  &get_nntp_header(SOCKET);			# Discard server greeting banner
X}
X
X#
X# Make sure we're the only instance of aub running for this user (actually,
X# for the set of all users having the same home directory as this user.)
X#
X
X&get_lock;
X
X#
X# All the skanky code that used to be here to pre-validate groups has been
X# removed for speed purposes.  We can validate on the fly.  
X#
X
X# Load in all the old group information.  
X&load_aub_rcfile;
X
X#
X# Main Loop -- iterate over groups we're interested in decoding binaries from
X#
X
foreach (@Groups) {
X  $main_loop_group = $_;			# Isn't this ugly?
X
X  $aubdir = ($aub_dir{$_}) ? $aub_dir{$_} : $aub_dir{$general};
X  if (!chdir($aubdir)) {
X    &warn("Could not cd to directory $aubdir...skipping group $_");
X    next;
X  }
X  print "Assembling binaries from $_\n" if ($opt_d);
X  print " Unpacking into directory $aubdir\n" if ($opt_d > 1);
X
X  $aub_desc = ($aub_desc{$_}) ? $aub_desc{$_} : $aub_desc{$general};
X  close(DESC);					# Can't hurt if not open 
X   
X  if (($aub_desc) && (!open(DESC, ">> $aub_desc"))) {
X    &warn("Could not open (to append) description file $aub_desc...\n" .
X          "...Skipping group $_");
X    next;
X  }
X
X  $aub_hook = ($aub_hook{$_}) ? $aub_hook{$_} : $aub_hook{$general};
X
X  @aub_pp = split(" ", ($postprocessor{$_} ? $postprocessor{$_} 
X			                   : $postprocessor{$general}));
X
X# Get the first and last article numbers in the group we're interested in.
X
X  ($first, $last) = &set_group($_);
X  if ((!$first) && (!$last)) {			# This group is bogus
X    $_ = "";					# Don't checkpoint this
X    next;
X  } 
X
X# We'll need to known next time what the last article we saw this time around
X# was.
X
X# Look at the list of unresolved articles for this group which was loaded
X# from $aub_rcfile.  Any unresolved articles that are no longer stored on
X# the nntp server must be discarded.  We load all other articles into memory.
X
X  print "Previously unresolved articles: $unresolved_list{$_}\n" if ($opt_d);
X  foreach (split(" ", $unresolved_list{$_})) {
X    &load_article($_) unless ($_ < $first);
X  } 
X  $unresolved_list{$_} = "";
X
X# We've also loaded from $aub_rcfile the article number of the last article
X# we saw in this group the last time we ran.  If for some reason this has
X# wound up undefined (it shouldn't be), or if the first article in the
X# newsgroup is now bigger than the last article we've seen (newsgroup has
X# been reset), we initialize this value.
X#
X# Note that when a new group is loaded for the first time, this is set to
X# zero, which is most likely smaller than the first article in the group.
X#
X
X  $last_article_seen{$_} = $first - 1 
X    if ((!$last_article_seen{$_}) || ($last_article_seen{$_} < $first));
X
X  print "Last seen $last_article_seen{$_}, first $first, last $last\n"
X    if ($opt_d);
X
X# Load all of the new articles in the group into image queues
X
X    &load_article(++$last_article_seen{$_}) 
X      while ($last_article_seen{$_} < $last);
X
X# We use the concept of 'pictures' (ie, binary images) and pieces of 
X# pictures while naming our variables, but really we're just putting together
X# the pieces of binary files...
X#
X# Each image queue (image queues are built by &load_article; see the
X# discussion there) potentially contains a picture.
X#
X# For each potential picture, extract the name of the picture and the number
X# of pieces that are known to be in it.  Build an array, @pairs, containing
X# N items, where N is the number of pieces of the picture that we actually
X# have, and where each item contains (encoded) the article number of the ith 
X# piece.
X
X  foreach $picture (keys %image_queues) {
X    print "Image $picture..." if ($opt_d);
X    ($picture_name, $picture_pieces) = split(":", $picture);
X    @pairs = split("%", $image_queues{$picture});
X
X# If we don't yet have all of the pieces of the picture, then this picture
X# is unresolved.  We want to keep track of the pieces we do have in 
X# a list, which we'll use later in creating our new $aub_rcfile.  We write
X# out the information about unused pieces of images to our $aub_tmp file.
X
X    if ($#pairs+1 < $picture_pieces) {		# Don't have all pieces yet
X      print "incomplete\nNoting unresolved article(s) " if ($opt_d); 
X      foreach $pair (@pairs) {
X        ($piece, $article_no) = split(";", $pair);
X        $unresolved_list{$_} = join(" ", $unresolved_list{$_}, $article_no);
X        print "$article_no " if ($opt_d);
X      }
X      print "\n" if ($opt_d);
X      next;
X    }
X
X# We've found a new, complete binary image.  Build a list of all of the
X# article numbers in it, then pass this list to the &assemble_picture code,
X# which creates the binary.
X
X    undef @articles_this_picture;
X    print "Complete\n" if ($opt_d);
X    foreach $pair (@pairs) {
X      ($piece, @articles_this_picture[++$#articles_this_picture]) = 
X        split(";", $pair);
X    }
X
X# If the user has stuck a hook into aub, now's the time to ask it whether or
X# not it really wants us to do the decoding.
X
X    if ($aub_hook) {
X      $sl = &get_subj_line(@articles_this_picture[0]);
X
X      `$ECHO "$sl" 2>/dev/null | $aub_hook >/dev/null 2>/dev/null`;
X
X      $hook_result = $?;
X      print (($hook_result) ? "Hook $aub_hook returned FALSE; not decoding\n"
X			   : "Hook $aub_hook returned TRUE; decoding\n")
X        if ($opt_d);
X    } else {
X      $hook_result = 0;
X    }
X
X    if (!$hook_result) {
X      (($newsgroupdir = $_) =~ y/\./\//) if ($spooldir);
X      &assemble_picture(@articles_this_picture);
X
X# Invoke a postprocessor, if necessary.
X
X      @pp = @aub_pp;
X      while ($#pp > -1) {
X        if ($real_name =~ m/$pp[0]$/i) {
X	  &post_process($real_name, $postprocessor_def{$pp[1]});
X	  last;
X        } else {
X	  shift @pp;
X	  shift @pp;
X        }
X      }
X    }
X  }
X
X# Checkpoint the $aub_rcfile file.  Blow away our current %image_queues 
X# array, which could well mess us up the next time around the loop.
X
X  &checkpoint;
X  undef %image_queues;	
X}
X
X#
X# Cleanup code -- leave things in an orderly state
X#
X
close(DESC) if ($aub_desc);
X&cleanup;
exit(0);
X
X#
X# Subroutines -- the first bunch handle decoding images (recognition code)
X#
X# Things have gotten pretty ugly in here lately, with global variables
X# in use all over the place...
X#
X# If you are hacking around in here improving aub's ability to recognize
X# binary images, and you come up with something clever, let me know.
X# Except, I'm not interested in hacks that modify &get_subj_line to scan
X# the _body_ of the article to look for lines of the form 'begin X NNN' --
X# you have to assume that people have some amount of common sense.
X#
X
sub load_article {
X#
X# Given an article number, we grab the subject line of the article and
X# look to see if it might be something we're interested in.  If it's not,
X# we return.
X#
X#  We are certainly not interested in: 
X#
X#  -- Articles with no subject line
X#  -- Articles beginning with "Re:"
X#
X#  We are interested in:
X#
X#  -- Articles containing a string of the form:
X#      (all white space is optional, case not significant)
X#	- N of N			(N is any number)
X#	- N fo N			(bad typist not using posting software)
X#	- N / N	
X#	- N \ N				(dyslexic poster?)
X#	- N | N				(dyslexic poster?)
X#
X# Given something sufficiently interesting, we guess that it's a piece of a 
X# binary image. 
X# 
X# Given such a beast, we note how many pieces there are all together and
X# which piece of the image this is, then try to deduce the name of the 
X# entire image.  
X#
X# If we have no better guess, we use all the stuff preceding the 
X# interesting part (described above) as the name of the image.  However,
X# if we find a string containing ".gif", ".jpg" or something like that -- 
X# a string containing any one of the extensions in the list of hints -- 
X# we use that as the name of the image instead.
X#
X# It really doesn't matter what we use as the name, so long as it's the
X# same for all of the pieces of the image, and so long as it's not the 
X# same as any pieces of other images.  But people reposting articles
X# with the same names will screw us up if we're too naive.  See below.
X#
X# We map colons in the name of the image to "X's", since they can really
X# mess us up later in life (we use ":" as one of our delimiters, internally.)
X#
X# Each identified image piece is inserted into an image queue.  Image
X# queues are named "PICTURE_NAME:NUMBER_OF_PIECES_IN_PICTURE".  They are
X# priority queues; the priority associated with each piece of an image is
X# the piece number, and the data is the image piece article number.
X#
X# Note that later while scanning all of the pieces in a given image queue,
X# this use of priority values will cause us to see the pieces (article 
X# numbers) in the correct order.  So we're doing some implicit sorting here.
X#
X# All numerical values derived from article subject lines are padded with
X# a (rather large) number of zeros, so that we never get confused and think
X# that piece "02 of 3" should follow piece "1 of 3".
X#
X# To keep from mixing pieces of reposted binaries up with the original 
X# postings, we stick the string "reposted." in front of the name.
X#
X# There are some more smarts buried in the &insert_q routine.
X#
X# Our decoding ability is substantially greater than that of v1.1 now.
X# 
X
X
X  local($article) = @_[0];
X  local($sl, $hint, $piece, $pieces, $name);
X
X  $sl = &get_subj_line($article);
X  print " Got article $sl\n" if ($opt_d > 1);
X
X  return if (($sl eq "") || ($sl =~ m/^\s*Re:/i));
X  $sl =~ y/A-Z/a-z/;
X
X  return unless (($sl =~ m/^(.*\D)(\d+)\s*o\s*f\s*(\d+)/i) ||
X                 ($sl =~ m/^(.*\D)(\d+)\s*f\s*o\s*(\d+)/i) ||
X                 ($sl =~ m/^(.*\D)(\d+)\s*\/\s*(\d+)/) ||
X                 ($sl =~ m/^(.*\D)(\d+)\s*\|\s*(\d+)/) ||
X                 ($sl =~ m/^(.*\D)(\d+)\s*\\\s*(\d+)/));
X
X  $piece  = &pad($2);
X  $pieces = &pad($3);
X  $name = $1;
X
X  foreach $hint (@extn_hints) {
X    if ($sl =~ m/\S+$hint/) {
X      $name = $&;
X      last;
X    }
X  } 
X
X  $name = "reposted.$name" if ($sl =~ m/repost/i);
X  $name =~ s/:/X/g;				# Avoid nasty, subtle bug
X
X  print " Recognized piece $piece of $pieces, binary $name\n" if ($opt_d > 1);
X  &insert_q(join(":", $name, $pieces), $piece, $article);
X}
X
X  
sub assemble_picture {
X#
X# Given a list of article numbers which make up a given image, we want to
X# produce the complete, uudecoded file.
X#
X# For each article, we use a state machine to ensure that we only uudecode
X# binary data, not news envelope or text or .sig garbage that the poster
X# may have included.  
X#
X# The state machine is discussed a little in the &process_line subroutine.
X# How it works is neither immediately obvious nor completely documented.
X# You can mess things up really good by tinkering with it, too.  Unless you
X# can rewrite uumerge or uucat from memory, better not tinker with this stuff.
X#
X# This could be made more readable, but it would be a performance trade-off,
X# and good performance is highly desirable, since we're doing a lot of 
X# interaction with the NNTP server / news files in here.
X#
X# We take care not to generate images which exactly match previously generated
X# images with similar names.
X
X  local($state, $last_piece, $rawfile);
X
X#
X# If we're in catch up mode, we don't want to do much.  We will go as far
X# as to list the article numbers we would have assembled had we been really
X# decoding articles.  This information can be very useful during debugging.
X#
X
X  if ($opt_c) {
X    return unless ($opt_d);
X    print "Catch-up mode...skipping assembly of articles ";
X    foreach (@_) {
X      print "$_ ";
X    } 
X    print "\n";
X    return;
X  }
X
X# Yes, all of these are global...
X
X  $state = 0;					# Initialize state machine
X  $last_piece = 0;				# Set for last piece of image
X  $desc_text  = "";				# Text describing this image
X  $desc_lines = 0;				# Running count $desc_text lines
X  $real_name = "";				# Name of binary actually made
X  $possible_duplicate = "";			# This is a global
X
X  print " Assembling articles " if ($opt_d > 1);
X  if (!$spooldir) {				# ***Using NNTP***
X
X    foreach (@_) {				# For each piece...
X      print "$_ " if ($opt_d > 1);
X      $state = 2 if ($state);			# This is black magic
X      $last_piece++ if ($_ eq $_[$#_]);		# Set on last piece of image
X
X      &putline(SOCKET, "body $_");		# Ask for article text
X      $data = &getline(SOCKET);			# Get header response
X
X      if ($data !~ m/^222\s/) {
X        &warn("Could not get body of article $_");
X        close(DECODE);				# Abandon ship
X        unlink($temp_decode_file);
X        return;					# Perhaps it just got expired
X      }
X
X      while (1) {  				# Not infinite, just fast
X        $data = &getline(SOCKET);		# Get a line of the article
X        last if ($last_nntp_line);		# Last line this article
X        next if ($state == 3);			# Dump remainder of article
X        $state = &process_line($data, $state);	# One step thru state machine
X      } 
X    }
X  } else {					# ***Using raw disk files***
X
X    foreach (@_) {				# For each piece
X      print "$_ " if ($opt_d > 1);
X      $state = 2 if ($state);			# Black magic again...
X      $last_piece++ if ($_ eq $_[$#_]);		# Set on last piece of image
X      $rawfile = "$spooldir/$newsgroupdir/$_";	# Filename of the article
X
X      if (!open(RAWNEWS, "< $rawfile")) {	# Can't read the article?
X        &warn("Could not open $rawfile for reading");
X        close(DECODE);
X        close(RAWNEWS);
X        unlink($temp_decode_file);
X        return;
X      }
X
X      do {					# Discard the news envelope
X        chop($data = <RAWNEWS>);
X        print "  Discard: $data\n" if ($opt_d > 2); 
X      } while ($data !~ m/^\s*$/);
X
X      foreach $data (<RAWNEWS>) {
X        last if ($state == 3);
X        chop $data;
X        print "  Read: $data\n" if ($opt_d > 2);
X        $state = &process_line($data, $state);
X      }
X      close(RAWNEWS);
X    }
X  }
X  close(DECODE);				# Temporary file
X
X  if ($possible_duplicate) {
X    while ($possible_duplicate ne $real_name) {
X      if (&identical($temp_decode_file, $possible_duplicate)) {
X        print "\n" if ($opt_d > 1);
X        print "Suppressing $real_name; would duplicate $possible_duplicate\n"
X	  if ($opt_d);
X	unlink($temp_decode_file);
X        $suppressed++;
X        return;
X      }
X      $possible_duplicate .= "+";
X    }
X  }
X
X  `$MV '$temp_decode_file' '$real_name' >/dev/null 2>&1`;
X  print DESC $desc_text if ($aub_desc);		# Print only if we decode
X  print "\nActual image name is $real_name\n" if ($opt_d > 1);
X}
X
X
sub process_line {
X#
X# State machine for processing data from articles:
X#
X# This isn't the best explanation possible, I realize.
X#
X# We process states in order of frequency of their occurrence, to make things
X# go fast...
X#
X#  STATE		MEANING
X#
X#    0			Processing first article, "begin" line not yet seen.
X#    1			Processing a not-last article, data lines should
X#			begin with "M"
X#    2			Processing non-first article, scanning for 
X#			continuation of binary data (M-lines)
X#    3			Through with an article; further data from this
X#			article should be discarded.
X#    4			Processing last article, data lines should be copied
X#			until 'end' seen.
X#
X#
X# There is now a terrible hack in here to make things work for the group
X# comp.binaries.os2, where people like to post stuff that contains lines
X# beginning with 'Minimum-OS2-Version:' before the uuencoded data continues
X# in pieces 2+ of the binary.  aub was seeing the leading 'M' and expecting 
X# uuencoded data to immediately follow, then dropping into state 3 when it 
X# didn't appear.  Instant lobotomy.
X#
X# Too bad we can't dump anything beginning with /M\S+: /, but alas, that's 
X# perfectly legal...
X# 
X
X  local($data, $state) = @_;
X  local($begin, $mode, $rest);
X  local($dashes) = "-------";
X
X  if ($state == 1) {			# State 1 == most common state
X    return 3 unless ($data =~ m/^M/);	# End of binary data this piece
X    print DECODE unpack("u", "$data\n");# This is uuencoded data; decode it
X    return 1;				# Expect to copy more binary data
X  }
X
X  if ($state == 4) {			# State 4 == 2nd most common state
X    return 3 if ($data =~ m/^end/);	# Discontinue decoding when 'end' seen
X    print DECODE unpack("u", "$data\n");# Decode this data, except for 'end'
X    return 4;				# Continue this state until 'end'
X  }
X    
X  if (!$state) {			# State 0 == 3rd most common state
X    if ($data !~ m/^begin [0-9]/) {	# Looking for "begin"; not seen yet?
X      return 0 if ($data =~ m/\-\-\-/); # HACK -- keep ugliness out of $aub_desc
X      return 0 if ($desc_lines++ > 60); # HACK -- some morons post sh archives
X      chop $desc_text if ($spooldir);	# HACK -- dump trailing \n when non-NNTP
X      $desc_text = join("\n", $desc_text, $data) if ($aub_desc);
X      return 0;				# Copy to desc file if $aub_desc defn.
X    }
X
X    ($begin, $mode, $real_name, $rest) = split(/\s+/, $data, 4);
X
X# Sanity check binary names...we don't like things posted with pathname
X# components in the name, weird characters, names beginning with ".", or 
X# binaries names "." or ".."
X
X    $real_name = $1 if ($real_name =~ m/\/([^\/]+)$/);
X    $real_name = $1 if ($real_name =~ m/^\.(.*)$/);
X    $real_name =~ tr/[A-Z][a-z][0-9]+-=_:;.,//dc;
X    $real_name = "Mangled" if (($real_name eq ".") || ($real_name eq "..") ||
X			       ($real_name eq ""));
X
X    $mode = 644 if (!$mode);		# We don't like mode zero binaries
X
X   if (-e $real_name) {
X      $possible_duplicate = $real_name;	# Would collide with this...
X      $real_name .= "+" while (-e $real_name);
X    }
X
X    
X    $desc_text = 			# Stuff group, name into desc info
X      "$dashes <$main_loop_group:$real_name> $dashes\n$desc_text\n\n"
X      if ($aub_desc);
X
X    unlink($temp_decode_file);
X    (open(DECODE, "> $temp_decode_file")) || 
X      &abort("Could not open temporary file $temp_decode_file for writing");
X    chmod(oct($mode), $temp_decode_file);
X
X    return 1 if (!$last_piece);		# If 1-N-1, -> state 1, else -> state 4
X    return 4;
X  }
X
X  if ($state == 2) {			# Looking for beginning of >1st piece
X    return 2 unless ($data =~ m/^M/);	# Haven't found it yet.
X
X    return 2 if (length($data) < 61);	# Want uuencoded data, not just anything
X    return 2 if ($data =~ m/^Minimum-OS2-Version:/); 	# What next?  
X    print DECODE unpack("u", "$data\n");# Found it, need to decode it
X    return 1 if (!$last_piece);		# Not last piece -> state 1
X    return 4;				# Copy last piece data from state 4.
X  }
X
X# We should not be called when in state 3; all other states are undefined.
X  &abort("Logic error in state machine");
X}
X
X
sub insert_q {
X#
X# Insert item $item with priority $priority into an image queue $queue.
X#
X# Both the priority and the item are actually stored in the queue as
X# the string "$priority;$item".
X#
X# A queue is just a string; values in the queue are separated by 
X# "%" characters.
X#
X# Since our items are made entirely of numbers, we don't need to worry
X# about getting confused by queue data that happens to coincide with the
X# characters we use as delimiters.
X#
X# Sometimes we find ourselves in the position of trying to add an item 
X# of priority P to a queue which already contains an item with priority P.
X# We know that if we go ahead and do this, it will likely hose us, since
X# there should be one and only one piece P of Q in any given binary.  Since
X# we are called by code that processes articles in sequential order of 
X# subject lines, as a heuristic, we'll assume that the later article should
X# supersede the previous article.  This is reasonable; although it is 
X# clearly not _defined_ to be the case that article X is more recent than
X# article Y when the article number of X is larger than that of Y, such is
X# often the case in practice.  Besides, there's no perfect way to decide 
X# which of the two articles is to be preferred.  It turns out that this helps
X# us a lot more often than it hurts us.
X# 
X# Things here should have been sped up slightly since v1.1.
X
X
X  ($queue, $priority, $item) = @_;
X  local(@a_queue) = split("%", $image_queues{$queue});
X
X  for ($i=0; $i <= $#a_queue; $i++) {
X    last if $a_queue[$i] >= $priority;
X  }
X
X  if ($a_queue[$i] =~ m/^${priority};/) {
X    $a_queue[$i] = "$priority;$item";
X    print " Replacing piece $priority of $queue with (presumably) newer data\n" 
X      if ($opt_d> 1);
X  } else {
X    splice(@a_queue, $i, 0, "$priority;$item");
X  }
X
X  $image_queues{$queue} = join("%", @a_queue);
X}
X
X
X#
X# More subroutines -- These deal with accessing news articles.
X#
X
sub get_subj_line {
X#
X# Gets the header information of the specified article, and returns the 
X# subject line, removing the "Subject:" portion.
X#
X# If we are using NNTP and the server understands the XHDR NNTP enhancement, 
X# we use it, unless the NOHXDR keyword appeared in the configuration file.
X#
X
X  local($article_no) = pop(@_);
X  local($sub_line) = "";
X  local($resp);
X
X# If $spooldir is defined, we're accessing articles directly instead of 
X# using the NNTP protocol.
X
X  if ($spooldir) {
X    return "" unless (open(SUBJECT, "$spooldir/$newsgroupdir/$article_no"));
X    while (!eof(SUBJECT)) {
X      $sub_line = <SUBJECT>;
X      next unless ($sub_line =~ m/Subject:\s*(.*)$/);
X      close(SUBJECT);
X      return $1;
X    } 
X    close(SUBJECT);
X    return "";
X  }
X
X# At this point we know we're using NNTP.  See whether or not we've already
X# decided if XHDR works or not.  If we haven't decided yet, we decide now.
X
X  if (!$have_gotten_subj_line_before) {		# Another global variable
X    $have_gotten_subj_line_before++;
X    &putline(SOCKET, "xhdr subject $article_no");
X    $resp = &getline(SOCKET);
X
X    if ($resp =~ m/^221\s/) {			# XHDR is supported!
X      $xhdr_supported++;			# Yup, this is global too
X      do {
X        $resp = &getline(SOCKET);		# Data's pending, so we use it
X        $sub_line = $1 if ($resp =~ m/^\d+\s+(.*)$/);
X      } until ($resp eq "\.");
X      return $sub_line;				# There's the answer
X    } 
X  }
X
X# How we make the NNTP query for the subject line depends on whether or not
X# we can use XHDR.
X
X  &putline(SOCKET, ($xhdr_supported) ? "xhdr subject $article_no" 
X				     : "head $article_no");
X  $resp = &getline(SOCKET);
X  return "" unless ($resp =~ m/^221\s/);	# Not the expected response 
X
X  do {
X    $resp = &getline(SOCKET);
X    if ($xhdr_supported) {
X      $sub_line = $1 if ($resp =~ m/^\d+\s+(.*)$/);
X    } else {
X      $sub_line = $1 if ($resp =~ m/^Subject:\s*(.*)$/);
X    }
X  } until ($last_nntp_line);
X
X  return $sub_line;
X}
X
X
sub set_group {
X#
X# Return the first and last article numbers of the group we're interested in.
X# If we're using NNTP, we'll use the 'GROUP' command to set the group we're
X# talking about and return the data the remote nntpd gives to us.  If we're
X# using raw disk files, we'll have to do a little more work than this...
X#
X# When processing raw spool directories, $newsgroupdir is set as a side-effect.
X#
X# We return a list (f,l) where f is the first available article in the
X# group and l is the last available article.  (0,0) indicates we've run
X# into a problem.
X#
X
X  local($group_to_examine) = @_[0];
X  local($data, $file);
X  local($min) = "first_time";
X  local($max) = 0;
X
X  if ($spooldir) {				# Disk based spool data
X    ($newsgroupdir = $group_to_examine) =~ y/\./\/\//;
X    if (!opendir(DIRECTORY, "$spooldir/$newsgroupdir")) {
X        &warn((-d "$spooldir/$newsgroupdir") ? 
X              "Cannot open $spooldir/$newsgroupdir; skipping it." :
X              "Invalid group: $group_to_examine...ignoring");
X        return (0,0);
X    }
X
X    foreach $file (readdir(DIRECTORY)) {
X      next if (($file eq ".") || ($file eq ".."));
X      next unless ($file =~ m/^\d+$/);
X      
X      $min = $file if (($min eq "first_time") || ($file < $min));
X      $max = $file if ($file > $max);
X    }
X    close(DIRECTORY);
X
X    return ($min eq "first_time" ? 0 : $min, $max);
X  }
X
X  &putline(SOCKET,"group $group_to_examine");
X  $data = &getline(SOCKET);
X
X  if ($data !~ m/^211\s/) {			# No such group
X    &warn("Invalid group: $group_to_examine...ignoring");
X    return (0,0);
X  }
X
X  $data =~ m/^211\s+\d+\s+(\d+)\s+(\d+)\s/;
X  return ($1,$2);
X}
X
X
sub get_nntp_header {
X#
X# Grab the nntp banner line from the server, sanity check it, and return.
X# This code is only useful if we're doing NNTP.
X#
X
X  local($sock) = pop(@_);
X  local($line) = &getline($sock);
X
X  return if (($line =~ m/^200\s/) || ($line =~ m/^201\s/));
X  &abort("Remote nntp service doesn't look like nntp service to me.");
X} 
X
X
sub setup_socket_io {
X#
X# Make the passed socket unbuffered, and invoke a timeout routine if we 
X# don't hear something within finite time.
X# 
X# I don't really have an 'initialization' section, so this is the next
X# best place for this...
X#
X
X
X  local($sockname) = pop(@_);
X  local($old_def_fh) = select($sockname);
X
X  $SIG{"ALRM"} = 'getline_timeout';
X  $|=1;
X  select($old_def_fh);
X}
X
X
sub getline {
X#
X# Get a line of data from a socket.  This code is used only if our news
X# access is NNTP-based.
X#
X# Note that $socket_stuff is a global variable
X#
X
X  local($sockname) = pop(@_);
X  local($data) = "";
X  local($inp);
X
X  $timeout_flag = 0;				# Not a local variable
X  alarm($timeout_interval);			# Can't wait forever.
X
X  while ($socket_stuff !~ m/\n/) {		# No complete line in buffer
X    recv($sockname, $inp, 256, 0);		# Need more data
X    $socket_stuff .= $inp;			# Append to our buffer.
X  }
X  alarm(0);					# Got data.  Shut off alarm.
X
X  &abort("Line from server was too long") if    # Still not end of line?
X    ($socket_stuff !~ m/\r\n/);
X  
X  ($data, $socket_stuff) = split("\r\n", $socket_stuff, 2);
X  $last_nntp_line = ($data eq "\.");		# Can't confuse with ".."
X  $data =~ s?\.?? if ($data =~ m/^\.\./);	# NNTP doubles leading "."
X
X  print "  Received: $data\n" if ($opt_d > 2);
X  return $data;					
X}
X
X
sub getline_timeout {
X#
X# What can we do if our server isn't talking?  Not much.
X#
X
X  &abort("NNTP server not responding after $timeout_interval seconds.");
X}
X
X
sub putline {
X#
X# Send a line of data over a socket.
X#
X
X  local($line) = pop(@_);
X  local($sockname) = pop(@_);
X
X  print $sockname "$line\r\n";
X  print "  Sent: $line\n" if ($opt_d > 2);
X} 
X
X
sub connect_tcp {
X#
X# Connect to a tcp port on some host.  This code is useful in more places
X# than just in aub.
X
X  local($e) = pop(@_);	      # 0=return on err, >0 = print error, abort on err
X  local($port) = pop(@_);     # port to connect to
X  local($server) = pop(@_);   # name of server to connect to
X  local($sockname) = pop(@_); # socket to use
X
X  local($packing_template) = "S n a4 x8";
X  local($protocol) = "tcp";
X  local($thishost, $problem, $junk);
X
X  $thishost = `hostname`; chop $thishost;
X
X# Figure out our address...
X  ($name, $junk, $junk, $junk, $ouraddr) = gethostbyname($thishost);
X  if ($name eq "") {
X    $problem="Can't get address of this host (\"$thishost\")";
X    &abort($problem) if $e;
X    return $e;
X  }
X 
X# And the address of the host we want to connect to
X  ($name, $junk, $junk, $junk, $theiraddr) = gethostbyname($server);
X  if ($name eq "") {
X    $problem = "Can't find address of server $server";
X    &abort($problem) if $e;
X    return $e;
X  }
X
X# Get the number of the protocol we're to use
X  ($name, $junk, $proto) = getprotobyname($protocol);
X  if ($name eq "") {
X    $problem="Unrecognized protocol: $protocol";
X    &abort($problem) if $e;
X    return $e;
X  }
X
X  $us = pack($packing_template, &AF_INET, 0, $ouraddr);
X  $them = pack($packing_template, &AF_INET, $port, $theiraddr);
X
X# Get a socket filehandle
X  if (!(socket($sockname, &AF_INET, &SOCK_STREAM, $proto))) {
X    $problem="Could not create socket";
X    &abort($problem) if $e;
X    return $e;
X  }
X
X  if (!connect($sockname, $them)) {
X    $problem="Could not connect to server";
X    &abort($problem) if $e;
X    return $e;
X  }
X}
X
X
X#
X# Subroutines -- dedicated to supporting postprocessors
X#
X
sub post_process {
X#
X# Invoke postprocessor command $cmd on $file.
X#
X# The error checking here is pretty minimal...
X#
X
X  local($file, $cmd) = @_;
X  local($head, $tail);
X
X  if ($file =~ m/\./) {
X    $head = $`;					# Though $' and $` look similar
X    $tail = $';					#  one's forward, one's backward
X  } else {
X    $head = $file;				# If no "." in image name, 
X    $tail = "";					#  there is no tail
X  }
X
X  $cmd =~ s/([^\\])\$h/$1$head/g;		# I'm sure there's a more 
X  $cmd =~ s/([^\\])\$t/$1$tail/g;		#  graceful way of doing this,
X  $cmd =~ s/([^\\])\$f/$1$file/g;		#  but I'm lazy.
X  $cmd =~ s/\\\$h/\$h/g;
X  $cmd =~ s/\\\$t/\$t/g;
X  $cmd =~ s/\\\$f/\$f/g;
X
X  print "Postprocessing: $cmd\n" if ($opt_d);
X  
X  `$cmd`;
X}
X
X
X#
X# Subroutines -- dedicated to loading and parsing configuration files and 
X#		 files maintained by aub.
X#
X
sub load_config_file {
X#
X# Load the configuration file, which is now line-oriented.
X#
X# We provide the user with some helpful hints if we run into problems opening
X# processing his configuration file.
X#
X# $current_group is a global variable used to keep track of which group 
X# current keywords are to be applied to.
X#
X# &parse_line does most of the work; we also use it to verify that anything
X# from the environment we'll be using is legitimate.
X#
X
X  local($extn, $cmd, $rest, $grp);
X
X  if (!open(CONFIG, $aub_config)) {
X    if (-f $obsolete_init) {
X      print <<"EOF";
X
X        Hi there.  It looks like you're running aub version $version for
the first time.
X
X        The format of aub's configuration file has changed since the
version of aub you last ran.  You need to create a new one.  It's very
easy, and you can get all the details from this program.  You'll want 
to call your new configuration file \$HOME/$mini_aub_config.
X 
X        You can print the short form of the documentation by executing
X'aub -m', and the long form by executing 'aub -M'.  Also, you can read
about changes made since the last version of aub by executing 'aub -C'.
X
X	If you yet read the new documentation for aub v$version, it would really
be a good idea to go over the whole thing again.  Many things have changed.
X
X                                                Mark Stantz
X
XEOF
X      exit(1);
X    }
X
X    &abort("Couldn't open your configuration file \"$aub_config\".\n" .
X           "Execute 'aub -m' (short form) or 'aub -M' (long form) if you " .
X           "need help\nfiguring out how to create a configuration file");
X  }
X
X# Validate any information which might be given to us via the environment
X
X  $current_group = $general;
X  &parse_line("directory", split(/\s+/, $aub_dir{$general}), 
X              "environment variable \$AUBDIR") if ($aub_dir{$general});
X  &parse_line("desc", split(/\s+/, $aub_desc{$general}), 
X              "environment variable \$AUBDESC") if ($aub_desc{$general});
X  &parse_line("hook", split(/\s+/, $aub_hook{$general}), 
X              "environment variable \$AUBHOOK") if ($aub_hook{$general});
X
X# Load and validate the configuration file
X
X  foreach (<CONFIG>) {
X    chop;                                       # Trim <CR>
X    s/^#.*$//;                                  # Remove comments
X    s/[^\\]#.*$//;
X    s/\\#/#/g;					# Unescape escaped comments
X    next if m/^\s*$/;                           # Skip blank lines
X    s/\s+/ /;                                   # Fold white space into 1 <SP>
X    s/^ //;                                     # Drop leading and trailing
X    s/ $//;                                     #  white space
X
X    ($cmd, $rest) = split(/\s+/, $_, 2);
X    &parse_line($cmd, $rest, "configuration file $aub_config");
X  }
X
X# Make sure that certain things we need to know have been defined
X
X  &conf_err("configuration file $aub_config", 
X            "Configuration file doesn't specify any groups to access")
X    if ($#Groups < 0);
X
X  if (!$aub_dir{$general}) {
X    foreach $grp (@Groups) {
X      next if ($aub_dir{$grp});
X
X      &conf_err("configuration file $aub_config", 
X                "No directory to put decoded binaries in specified.\n Please " .
X                "set the AUBDIR environment variable or modify your " .
X                "configuration file");
X    }
X  }
X
X# Use configuration file NNTP server if specified.  Otherwise use NNTP 
X# environment variable.  Otherwise use deduced NNTP server, if any.
X# All of this is ignored if $spooldir is ever set, in which case disk-based
X# access will be used.
X
X  $server = $nntpserver if ($nntpserver);
X  $server = $defserver unless ($server);
X
X  if (($server eq "") && ($spooldir eq "")) {
X    &conf_err("configuration file $aub_config", 
X              "No news spool directory or NNTP server specified or " .
X              "locatable.\n Please specify where to access news in the " .
X              "configuration file, or by\n setting the NNTPSERVER " . 
X	      "environment variable");
X  }
X
X  foreach (@extn_hints) {			# dispel regexp magic (Tom
X    s/(\W)/\\$1/g;				#  Christiansen's term)
X  }
X}
X
X
sub parse_line {
X#
X# Handle a given line from the configuration file.
X#
X# This is pretty straightforward, but tedious.  Almost certainly there's a 
X# bug or two in here, but I don't see anything wrong with it at the moment.
X#
X
X  local($cmd, $args, $err_type) = @_;
X  local(@args) = split(/\s+/, $args);
X  local($extn, $group, $pp_name, $pp_cmd);
X
X  if ($cmd =~ m/^dir/i) {			# Directory keyword
X    &conf_err($err_type, "No directory specified with DIRectory keyword")
X      if ($#args < 0);
X    &conf_err($err_type, "Too many arguments specified with DIRectory keyword")
X      if ($#args > 0);
X
X    &conf_err($err_type, "Supposed directory $args is not a directory") 
X      unless (-d $args);
X    &conf_err($err_type, "Directory $args is not writable")
X      unless (-w $args);
X    &conf_err($err_type, "Directory $args is not searchable (executable)")
X      unless (-x $args);
X	               
X    $aub_dir{$current_group} = $args unless ($aub_dir{$current_group});
X    return;
X  }
X
X  if ($cmd =~ m/^desc/i) {			# Description file argument
X    &conf_err($err_type, 
X              "No description file specified with DESCription keyword")
X      if ($#args < 0);
X    &conf_err($err_type, 
X	      "Too many arguments specified with DESCription keyword")
X      if ($#args > 0);
X
X    &conf_err($err_type, "Could not append to description file $args") 
X      unless (open(TEST, ">> $args"));
X    close(TEST);
X
X    $aub_desc{$current_group} = $args unless ($aub_desc{$current_group});
X    return;
X  }
X
X  if ($cmd =~ m/^hook/i) {			# Hook program
X    &conf_err($err_type, "No hook program specified with HOOK keyword")
X      if ($#args < 0);
X    &conf_err($err_type, "Too many arguments specified with HOOK keyword")
X      if ($#args > 0);
X
X    $args = &find_pg($args, 1);
X    &conf_err($err_type, 
X             "Supposed hook program $args nonexistent or not a plain file")
X      unless (-f $args);
X
X    &conf_err($err_type, "Supposed hook program $args is not executable")
X      unless (-x $args);
X
X    $aub_hook{$current_group} = $args unless ($aub_hook{$current_group}); 
X    return;
X  }
X
X  if ($cmd =~ m/^def/i) {			# Postprocessor definition
X    &conf_err($err_type, "No postprocessor named with DEFine keyword")
X      if ($#args < 0);
X
X    $args[0] =~ y/[A-Z]/[a-z]/;
X
X    if (!$#args) {
X      $args[0] =~ y/[A-Z]/[a-z]/;
X      &conf_err($err_type, "No command associated with postprocessor $args[0]");
X    }
X
X    ($pp_name, $pp_cmd)  = split(/\s+/, $args, 2);
X    $pp_name =~ y/[A-Z]/[a-z]/;
X    $postprocessor_def{$pp_name} = $pp_cmd;
X    return;
X  }
X
X  if ($cmd =~ m/^post/i) {			# Postprocessor usage
X    &conf_err($err_type, "No postprocessor named with POSTprocess keyword")
X      if ($#args < 0);
X
X    $args[0] =~ y/[A-Z]/[a-z]/;
X    &conf_err($err_type, "Postprocessor $args[0] used while undefined")
X      unless ($postprocessor_def{$args[0]});
X    &conf_err($err_type, "Postprocessor $args[0] applied to no extensions")
X      if (!$#args);
X
X    $pp_name = shift(@args);
X    foreach $extn (@args) {
X      $extn =~ s/(\W)/\\$1/g;
X      $postprocessor{$current_group} .= "$extn $pp_name ";
X    }
X    return;
X  }
X
X  if ($cmd =~ m/^rec/i) {			# Recognize an extension
X    &conf_err($err_type, "No extensions named with RECognize keyword")
X      if ($#args < 0);
X
X    foreach $extn (@args) {			# We'll dispel regexps later
X      push(@extn_hints, $extn) unless (grep(($_ eq $extn), @extn_hints));
X    }
X    return;
X  } 
X
X  if ($cmd =~ m/^noxhdr/i) {			# NOXHDR keyword
X    &conf_err($err_type, "Argument specified with NOXHDR keyword")
X      unless($#args == -1);
X
X    $have_gotten_subj_line_before++;		# Don't bother trying XHDR
X    return;
X  }
X
X  if ($cmd =~ m/^spool/i) {			# Spool directory
X    &conf_err($err_type, "No argument specified with SPOOL keyword")
X      if ($#args < 0);
X    &conf_err($err_type, "Too many arguments specified with SPOOL keyword")
X      if ($#args > 0);
X
X    &conf_err($err_type, "Cannot both NNTP and spooled news files as input")
X      if ($nntpserver);
X
X    &conf_err($err_type, "Supposed spool directory $args is not a directory")
X      unless (-d $args);
X    &conf_err($err_type, "Spool directory $args is not searchable (executable)")
X      unless (-x $args);
X
X    $spooldir = $args unless ($spooldir);
X    return;
X   } 
X
X  if ($cmd =~ m/^nntp/i) {			# NNTP server
X    &conf_err($err_type, "No argument specified with NNTPserver keyword")
X      if ($#args < 0);
X    &conf_err($err_type, "Too many arguments specified with NNTPserver keyword")
X      if ($#args > 0);
X
X    $nntpserver = $args unless ($nntpserver);	# We'll validate this later
X    return;
X  }
X
X  if ($cmd =~ m/^debug/i) {			# Turn on debugging
X    &conf_err($err_type, "No argument specified with DEBUG keyword")
X      if ($#args < 0);
X    &conf_err($err_type, "Too many arguments specified with DEBUG keyword")
X      if ($#args > 0);
X
X    &conf_err($err_type, "Debug level is not a number")
X      unless ($args =~ m/^\d+$/);
X
X    $opt_d = scalar($args) unless ($opt_d);
X    return;
X  }
X
X  if ($cmd =~ m/^group/i) {			# A group, or group list
X    &conf_err($err_type, "No argument specified with GROUP keyword")
X      if ($#args < 0);
X
X    foreach $group (@args) {
X      $group =~ y/[A-Z]/[a-z]/;
X      push(@Groups, $group) unless (grep(($_ eq $group), @Groups));
X    }
X    $current_group = $args[$#args];
X    return;
X  }
X
X  &conf_err($err_type, "Unrecognized keyword: $cmd");
X}
X
X
sub conf_err {
X#
X# Pretty-print configuration file errors.
X#
X
X  local($a, $b) = @_;
X
X  print "Error in $a:\n $b.\n";
X  exit(1);
X}
X    
sub load_aub_rcfile {
X#
X# Load the aub_rcfile.  This file contains the last article seen in all
X# groups we were reading the last time we were invoked, as well as a list
X# articles which were unresolved in that group.
X#
X# We build the %last_article_seen and %unresolved_list associative arrays
X# from this information.
X
X
X  local($group) = "";
X
X  if (! -e $aub_rcfile) {				# No $aub_rc file?
X    foreach (@Groups) {					# Initialize stuff
X      next if ($_ eq "");
X      $last_article_seen{$_} = 0;			# Nothing seen yet
X      $unresolved_list{$_} = "";			# No unresolved articles
X    }
X    return;
X  }
X
X  &abort("Can't open $aub_rcfile") if (!open(RCFILE, $aub_rcfile));
X  chop(@Rc = <RCFILE>);
X  close(RCFILE);
X
X  foreach (@Rc) {
X    if (m/^([^:]+):(.+)$/) {				# Info for a new group
X      $group = $1;					# Name of group
X      $last_article_seen{$group} = $2;			# Last seen in group
X      $Groups_known[++$#Groups_known] = $1;		
X      next;
X    }
X
X    &abort("$aub_rcfile mangled...please fix or discard")
X      if (($group eq "") || (!m/^\d+$/));		# Else must be a number
X    $unresolved_list{$group} = join(" ", $unresolved_list{$group}, $_);
X  }
X}
X    
X
sub checkpoint {
X#
X# We've just processed all of the new articles in a given group.  We want
X# to create a new $aub_rcfile in case someone decides to interrupt us, so
X# that all our pointers won't be lost.
X#
X# When aub is run with the -n option, all checkpointing is suppressed and
X# the $aub_rcfile is never modified.  This is useful if you want to 'peek 
X# ahead' and see what you'll be getting later -- not something you probably
X# want to do very often, but it's useful in debugging...especially in 
X# conjunction with -c.
X#
X# Anything in @Groups_known -- that is, anything that was in the $aubrc_file
X# when it was first read in -- will be copied to all subsequent versions
X# of the $aubrc_file.  However, anything invalid groups introduced by new 
X# data in the configuration file will have been discovered by the time this 
X# code is run and the entry in @Groups removed.  So while it's true that we'll
X# forever be copying old pointers for groups we used to follow but no longer
X# follow, and for groups which were once valid but no longer are valid, we'll
X# never introduce any currently invalid group in this code.
X#
X# We really don't want to get interrupted while running this code.  If we
X# catch a signal we can't block in here, it could mangle the configuration
X# file.  Buffered I/O might safe us from that in a pinch, but don't count
X# on it.  Nobody should be sending us uncatchable signals anyways.
X#
X
X  local(@Checkpointed, $known);
X
X  return if ($opt_n);				# No checkpointing
X
X  foreach (@sigs) {				# Don't allow interruptions
X    $SIG{$_} = 'IGNORE';
X  }
X
X  (open(CHECKPOINT, "> $aub_tmp")) ||		# This is just temporary...
X    &abort("Could not open temporary file $aub_tmp for writing");
X
X  foreach $known (@Groups_known, @Groups) {	
X    next if ($known eq "");			# Possible, if group invalidated
X    next if (grep(($_ eq $known), @Checkpointed)); # Did this one already
X    push(@Checkpointed, $known); 		# Don't do this again
X
X# Now, theoretically, it's supposed to be impossible for $last_article_seen{}
X# to have something undefined in it.  But I want to be really sure, because
X# this happened to me once.  I may be imagining things, or I may just be 
X# fixing a bug with a band-aid instead of getting at the real cause.  Not
X# sure which...
X
X    $last_article_seen{$known} = "0" if ($last_article_seen{$known} eq "");
X
X    print CHECKPOINT "$known:$last_article_seen{$known}\n";
X    foreach (split(" ", $unresolved_list{$known})) {
X      print CHECKPOINT "$_\n";
X    }
X    print "  Checkpointed: $known ($unresolved_list{$known} )\n" 
X      if ($opt_d > 1);
X  }
X
X  close(CHECKPOINT);
X  &abort("Could not replace $aub_rcfile with updated data")
X    unless (rename($aub_tmp, $aub_rcfile)); 	# This should be atomic...
X
X  foreach (@sigs) {
X    $SIG{$_} = 'handler';			# Restore normal signal handling
X  }
X}
X
X
X#
X# Subroutines -- Miscellaneous other stuff...
X#
X
sub get_lock {
X#
X# Primitive (but effective) locking mechanism, used to guarantee that only
X# one instance of aub is running at a given time for a given user.
X#
X# We write out PID to a file using echo/append.  If the first line of the
X# file is our PID, we have the lock.
X#
X# If the first line of the file is someone else's PID, we don't have the
X# lock.  We check to see if that process is still around; if it isn't,
X# we'll seize the lock.
X#
X
X  `$ECHO "$$" >> $aub_lock 2>/dev/null`;
X
X  &abort("Can't write $aub_lock") unless (-e $aub_lock);
X  if (!open(LOCK, $aub_lock)) {
X    unlink($aub_lock);
X    &abort("Couldn't open $aub_lock for reading");
X  }
X
X  chop($first_line = <LOCK>);
X  close(LOCK);
X
X  if ($first_line == $$) {
X    $have_lock = 1;
X    return;
X  }
X
X  print "Process $first_line seems to be already running aub.\n";
X  &abort("You may not have two instance of aub running at once.  Sorry")
X    if (kill(0, $first_line));
X
X  print "That process does not seem to exist any more...\n";
X  unlink($aub_lock);
X  &get_lock;
X}
X
X
sub identical {
X#
X# Return true if two files are identical to one another; false otherwise
X# I'm lazy and count on sum being around to do this for me.  
X#
X
X  local($f1, $f2) = @_;
X  local($s1, $s2) = @_;
X
X  chop($s1 = `$SUM '$f1'`);			# Compute checksums
X  chop($s2 = `$SUM '$f2'`);
X
X  $f1 =~ s/(\W)/\\$1/g;				# Dispel regexp magic 
X  $f2 =~ s/(\W)/\\$1/g;
X
X  $s1 =~ s/$f1//;				# Remove filenames from strs
X  $s2 =~ s/$f2//;
X
X  return ($s1 eq $s2);
X}
X    
X
sub find_pg {
X#
X# find_pg: find the specified executable on this machine, if possible.
X#
X# We try using which first, assuming that if the desired executable is in
X# our path, it's the one we want.
X#
X# If it's not in our path, we try whereis, returning the first program
X# whereis names for us which is executable.
X#
X# If we can't find what we need, we just return our argument back if our
X# second argument is true.  If it's false, we assume that it's crucial that
X# we find the program specified, and blow up.
X#
X
X  local($pg, $crucial) = @_;
X  local($ex) = 1;
X  local($try, @found);
X
X  return $pg if ($pg =~ m/^\//);		# Absolute paths know best
X  chop($try = `which $pg`);
X  return $try if ($try =~ m/^\//);
X
X  chop($try = `whereis $pg`);
X  if ($try =~ m/^$pg:\s+\//) {
X    @found = split(/\s/, $try);
X    $ex++ while (! -x $found[$ex]);
X    return $found[$ex] unless ($found[$ex] eq "");
X  }
X
X  return $pg if (!$crucial);
X  &abort("Could not locate executable \"$pg\"");
X}
X
X
sub abort {
X# 
X# Print an error message and exit.  This is for problems we can't recover
X# from.
X#
X
X  &cleanup;
X  print STDERR "@_[0].\n";
X  exit(1);
X}
X
X
sub warn {
X# 
X# Print an error message and return.  This is for things which really 
X# perplex us but which we can recover from.  This might get invoked if
X# articles are expired between the time we find out they're around and 
X# the time we try to access them, for instance, or if we can't open a 
X# file we need to be able to open.
X#
X
X  print "@_[0].\n";
X}
X
X
sub cleanup {
X#
X# Cleanup code.  This could probably be improved/added-to.
X#
X
X  &putline(SOCKET, "quit") if ($connected_to_server);
X
X  close(DESC);
X  close(DECODE);
X  close(SUBJECT);
X  unlink($aub_lock) if ($have_lock);
X  unlink($temp_decode_file);
X  unlink($aub_tmp);
X
X  close(SOCKET);
X}
X
X
sub handler {
X#
X# Die gracefully if interrupted by a signal.
X#
X
X  print STDERR "Dying on signal @_[0]\n";
X  &cleanup;
X  exit(1);
X}
X
X
sub pad {
X#
X# Pad a number to six characters (rather excessive, for our needs) with zeros.
X#
X
X  local($n) = pop(@_);
X  local($i);
X
X  $i = sprintf("%6d", $n); 
X  $i =~ s/ /0/g;
X  return $i;
X}
X
X
sub Getopts {
X#
X# This code was adapted (read that, stolen) from perl's getopt.pl library.
X#
X
X    local($argumentative) = @_;
X    local(@args,$_,$first,$rest,$errs);
X    local($[) = 0;
X
X    @args = split( / */, $argumentative );
X    while(($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
X        ($first,$rest) = ($1,$2);
X        $pos = index($argumentative,$first);
X        if($pos >= $[) {
X            if($args[$pos+1] eq ':') {
X                shift(@ARGV);
X                if($rest eq '') {
X                  $rest = shift(@ARGV);
X                }
X                eval "\$opt_$first = \$rest;";
X            }
X            else {
X                eval "\$opt_$first = 1";
X                if($rest eq '') {
X                    shift(@ARGV);
X            }
X                else {
X                    $ARGV[0] = "-$rest";
X                }
X            }
X        }
X        else {
X            print STDERR "Unknown option: $first\n";
X            ++$errs;
X            if($rest ne '') {
X                $ARGV[0] = "-$rest";
X            }
X            else {
X                shift(@ARGV);
X            }
X        }
X    }
X    $errs == 0;
X}
X
X
X#
X# Subroutines -- long, boring subroutines that print out lots of text.
X#
X# You can't lose the documentation any more.  Beware: variable values get 
X# interpolated in here...  It may be occasionally necessary to escape things.
X#
X
sub need_to_run_h2ph {
X#
X# I can't tell you how many mail messages I got about the perl "Can't locate
X# sys/socket.ph in @INC" message when aub v1.1 was released.  I don't want
X# to deal with that any more.
X#
X
X  print <<"EOF";
X
X	Your system is missing the library file sys/socket.ph, which is
required by aub.  This file can't be distributed with aub because its
contents are system-dependent.
X
X	sys/socket.ph is generated by h2ph, which is distributed with perl.
h2ph takes your systems /usr/include/sys/socket.h file and generates an
analogous header file, probably /usr/local/lib/perl/sys/socket.ph.  aub
needs this file because it works with sockets.  
X
X	h2ph is very straightforward -- read the man page.  Supposing that
your perl library directory is /usr/local/lib/perl, all you need to do is
run 'h2ph < /usr/include/sys/socket.h > /usr/local/lib/perl/sys/socket.ph'.  
You may need need to create the directory /usr/local/lib/perl/sys before 
you do this.  Also, it's not uncommon for the perl library to be /usr/lib/perl
instead of /usr/local/lib/perl.
X
X	aub doesn't need this file if you set up your configuration file
to use disk-based spool files instead of the NNTP protocol.  But that's
really not recommended if NNTP is available to you; NNTP-based access to
news is much faster, and it really shouldn't be hard for you to figure this
out.
X
X					Mark Stantz
X
XEOF
X	exit(1);
X}
X
sub changes {
X#
X# Print changes to aub since last version.  We hit only the high points.
X#
X
X  print <<"EOF";
X
X	Changes to aub since v$last_version:
X
X	o	Added support for disk-based (non-NNTP) access to news 
X	o	Made aub configuration file-oriented
X	o	Added code to suppress generation of identical binaries
X	o	Added .aubrc checkpointing code
X	o	Added postprocessor functionality 
X	o	Added hook functionality (allows selective decoding)
X	o	Added support for NNTP/XHDR
X	o	Improved binary recognition abilities significantly
X	o 	Removed unnecessary newsgroup pre-validation (speed hack)
X	o	Folded uudecode functionality into aub itself (speed hack)
X	o	Folded documentation into program (convenience hack)
X	o	Added 'catchup' and 'no-checkpoint' command line options
X	o	Fixed bugs in recognition code, NNTP protocol implementation,
X		 signal handling
X
X	Known bugs in this version:
X
X	o	-d0 on command line does not override 'debug N' in 
X		 configuration file.
X
X	Unknown bugs in this version:
X
X	o	Rather likely.  But you still really want to run this
X		 instead of v$last_version.  Trust me.
X	
XEOF
X  exit(0);
X
X}
X
X
sub short_manual {
X#
X# Print out the short form of the manual...memory refresh mode...
X#
X
X  print <<"EOF";
X
X  Command line options:
X
X	aub -c		Catch up on all groups, but do not assemble binaries
X	aub -n		No checkpointing; don't update .aubrc
X	aub -dN		Set debugging level to N
X	aub -M		Print the aub manual
X	aub -m		Print this summary of the manual 
X	aub -C		List changes since previous release of aub
X
X  Configuration keywords (for \$HOME/.aubconf):
X
X	GROUP <GROUP> ...	Causes aub to process the newsgroup(s) listed
X	SPOOL <DIR>		Use directory <DIR> as the root of the news 
X				 spool tree (4)
X	NNTP <HOST>		Use <HOST> as an NNTP news server (4)
X	DIRectory <DIR>		Assemble binaries into the specified 
X				 directory (1)
X	DESCription <FILE> 	Store descriptions of assembled binaries in the 
X				 specified file (1)
X	HOOK <PGM>		Decode binaries only when the specified program
X				 exits returning status true (zero) (1,2)
X	DEFine <NAME> <CMD>	Define a postprocessor called <NAME>, which
X				 will invoke the command <CMD> (3)
X	POSTprocess <NAME> <EXTN> ...
X				Apply postprocessor <NAME> to binaries whose
X				 filenames end in any listed <EXTN> suffix (1,3)
X	RECognize <EXTN> ...  	Add the suffixes listed to aub's internal 
X				 table of common suffixes
X	NOXHDR			Do not use the NNTP XHDR command, even if it 
X				 is understood by the NNTP server
X	DEBUG <N>		Set the default debugging level to N
X
X  	Notes:
X
X	(1) -- If this keyword appears before any GROUP keyword, it applies to 
X	       all groups binaries are assembled from by default.  If the 
X	       keyword appears after a given GROUP keyword, it applies to that 
X	       group only, and overrides any default which may earlier have 
X	       been established with the same keyword.
X
X	(2) -- The hook program will be passed the subject line of the lowest-
X	       numbered piece of the binary image on standard input.  It
X	       cannot be invoked with arguments (yet).
X
X 	(3) -- If the string "\$h" appears unescaped in the command, it will be 
X	       replaced before the command is invoked with the "head" of 
X	       the filename of the binary.  Similarly, "\$t" will be replaced 
X	       with the "tail", and "\$f" will be replaced with the entire 
X	       filename.  The head and tail of "foo.gif" are "foo" and "gif", 
X	       respectively.
X
X	(4) -- The SPOOL and NNTP keywords may not both appear in the same
X	       configuration file.
X
XEOF
X
X  exit(0);
X}
X
X
sub long_manual {
X#
X#
X#
X
X  print <<"EOF";
X
X
X			The Introducing AUB Document
X
X
X	1.	What is aub?
X
X	More and more people are posting binary files to usenet these days.
Some of these binaries are executables and audio data; a majority seem to
be pictures of various things, typically landscapes, movie stars and naked
people.  Because of limitations in the type data that usenet can accommodate, 
binaries must be encoded into text, and because binary files are commonly very 
large relative to text files usenet was designed to handle, they frequently 
must be broken up into pieces.  Programs have been developed which take a 
given binary, encode it, and automatically post it in pieces with descriptive 
subject lines.
X
X	When this data arrives at a remote site, users see subject lines
that look something like this:
X
X		12011 roadkill03.gif, part 1/4
X		12012 roadkill03.gif, part 3/4
X		12013 More pictures of tatooed children, please...
X		12014 Re: roadkill02.gif -- I love the way the eyes bulge out
X		12015 roadkill03.gif, part 4/4
X		12016 roseanne_nude.jpg, part 02 of 02
X	   	12017 Only BINARIES should be posted here, GOD DAMMIT	
X		12018 roadkill03.gif, part 2/4
X		12019 HI, I'M BIFF!!!!  THESE PIX ARE WAY COOL!!!!
X		12020 roseanne_nude.jpg, part 01 of 02
X
X	While the process of encoding and splitting up binaries for posting 
to usenet is relatively straightforward, the process of retrieving, sorting,
and decoding the pieces (which do not necessarily arrive in order) at 
receiving sites is less straightforward, tedious, time consuming, and very
prone to human error.  
X
X	aub, which stands for "assemble usenet binaries", automates this 
reassembly process for you.  aub is intended for use in newsgroups to which 
binaries are posted exclusively.  When run, it accesses news articles via
either a disk-based news spool directory, or via an NNTP news server, 
determines whether or not any new binaries have appeared in selected 
newsgroups since the last time it was run, and if so, retrieves, organizes 
and decodes them, depositing them in a configurable location.  This process 
requires no human intervention once aub has been configured.  aub also keeps 
track of binaries which it has seen some, but not all, of the pieces of.  It 
remembers how to find these old pieces, so that when new, previously missing 
pieces arrive at your site, it will build the entire binary the next time it 
is run.  It also remembers which binaries it has already seen all of the 
pieces of already, so that it does not waste time rebuilding the same binaries 
over and over again.
X
X	aub was created as a time saver; too many people at too many sites 
were spending way too much time manually unpacking binary files.  Its ability 
to identify and assemble binary images depends on people posting images with
subject lines that observe (loosely) established conventions.  aub's 
recognition capabilities have been significantly improved since the earliest 
release.
X
X
X	2.	How does aub work?
X
X	aub looks for subject lines containing strings like:
X
X		N of N
X		N / N
X		N \ N
X		N | N
X
X	where N is any number composed of one or more digits, and white
space is optional.  Once it sees such a line, it tries to figure out a
name for the binary by looking at the rest of the subject line.  These names 
are relevant only to aub's internal functioning; when unpacked, binaries are 
named according to the information they were encoded with.  However, it's 
important that, whatever internal name aub decides on for the binary, that 
name be recognizable in the subject lines of all pieces.
X
X	aub ignores all news articles with null subject lines and subject
lines that begin with "Re:" regardless of other content.
X
X	aub uses two files which are maintained in each user's home directory.
One is \$HOME/.aubconf, which is a configuration file that allows you to 
customize aub's behavior.  See section 5 for a detailed explanation of the
structure of configuration files.  The other file is \$HOME/.aubrc.  You
should never need to modify this file; aub creates it and maintains it.  It's
used to keep track of what articles in which groups aub has resolved 
already, and what articles aub believes to be pieces of binaries that it 
hasn't seen all of the pieces of yet.  
X
X
X    	3.	What do I need on my system to run aub?
X
X	You will need Larry Wall's perl interpreter.  Older versions of aub
also required David Mack's uumerge program; this functionality has since been
folded into aub for the sake of speed.  perl is available via anonymous FTP 
from uunet.uu.net, tut.cis.ohio-state.edu, and jpl-decvax.jpl.nasa.gov.  
X
X	Your machine must also have access to news, either via the NNTP
NNTP protocol, or by being able to open raw news files on a disk somewhere.  
Previous versions of aub required that your news access be NNTP-based; this 
restriction has since been lifted.
X
X
X	4.	How do I install aub?
X
X	There's really only one thing that you might need to configure.
aub is a perl script.  The first line of the program looks like this:
X
X		#!/usr/local/bin/perl
X
X	This appears to tell your shell where to find the perl interpreter.  
If the path of perl on your system is something else, you'll need to change 
this line, or create a link called /usr/local/bin/perl which points to where
your perl executable actually resides.
X
X	If you need to change this, you'll probably see a message like:
X'aub: Bad address.' when you try to run aub.
X
X
X	5.	How do I configure aub?
X
X	Older versions of aub made use of a configuration file which was
normally called \$HOME/.aubinit.  But few interesting customizations could 
be accomplished with .aubinit files, because the configuration language
was so primitive.  The configuration language has been redesigned to allow
much greater flexibility.  Old .aubinit files will no longer work, or be
recognized by aub (except inasmuch as aub will notice them and point out
to you that you need to create a new configuration file if you don't already
have one.)  The new configuration file for aub should be called \$HOME/.aubconf.
X
X	Configuration files are line-oriented; each line is processed 
separately.  If any line contains the '#' character, aub concludes that 
the character begins a comment, and discards the comment character and 
everything one the line that follows it.  If for some reason you need to
put a '#' character in your configuration file and do not want it to be 
interpreted as beginning a comment, you'll have to escape it by preceding it 
with a backslash character, e.g. '\\#'.
X
X	Each non-blank line in a configuration file must begin with a 
keyword recognized by aub.  The case of keywords is not significant.
As far as aub is concerned, "keyword", "KEYWORD", "Keyword" and "KeYWorD"
all mean the same thing.  Some keywords require arguments; some require no 
arguments appear, and some permit varialbe numbers of arguments.  If aub 
sees keywords it doesn't understand in your .aubconf file, it will complain 
to you about them.
X
X	One of the keywords aub understands is the GROUP keyword.  It's
used to tell aub that you want to decode binaries from the newsgroup(s)
which appear as argument(s) to the keyword.  For example:
X
X		GROUP alt.binaries.pictures.misc
X		GROUP alt.binaries.pictures.misc alt.binaries.pictures.fractals
X
X	Every configuration file must contain at least one GROUP keyword to
be correct.  
X
X	In general, aub understands two types of keywords.  One type is 
called 'position insensitive', which means that the keyword will have the
same effect no matter where in the configuration file it appears.  The
other type is called 'position sensitive', which means that the keyword 
means something different when it appears before any GROUP keywords than
it does when it appears after any given GROUP keyword.
X
X	One such position sensitive keyword is the DIRectory keyword.
This keyword is used to tell aub what directory to put binaries it decodes
in.  ("DIRectory" is spelled the way it is because only the 'DIR' part needs 
to appear in a configuration file for aub to recognize it.  In fact, aub will 
interpret any keyword beginning with the letters 'DIR' as being an instance
of the DIRectory keyword.)
X
X	When a position sensitive keyword appears _before_ any GROUP keyword,
the keyword is interpreted as being the default for all groups that appear
later.
X
X	When a position sensitive keyword appears _after_ any GROUP keyword,
it is interpreting as applying *only* to that group, overriding any previous
default which may have been established via use of the same keyword, or
by the value of environment variables (see section 8.)
X
X	Position sensitive keywords appearing after a GROUP keyword which
lists multiple groups are applied only to the last group listed, not to 
all groups appearing on the group line.
X
X	For example, the following three configuration files are equivalent:
X
X	# Sample .aubconf file no. 1 -- basic example
X	# 
X	dir /tmp/aub					# Default directory
X	group alt.binaries.pictures.misc		# Process these
X	group alt.binaries.pictures.fractals		#  two groups
X
X        # Sample .aubconf file no. 2 -- multiple group usage, mixed case
X        #
X        DiR /tmp/aub                                    # Default directory
X        gRoUp alt.binaries.pictures.misc alt.binaries.pictures.fractals
X
X        # Sample .aubconf file no. 3 -- does not use defaults
X        #
X        group alt.binaries.pictures.misc
X        directory /tmp/aub                            
X        group alt.binaries.pictures.fractals
X        direct-to /tmp/aub                           	# 'dir' is all you need
X
X	The following three configuration files are also equivalent, though
not equivalent to the previous three:
X
X        # Sample .aubconf file no. 4 -- explicit placement of binaries
X        #
X        group alt.binaries.pictures.misc
X        dir /tmp/aub/misc
X        group alt.binaries.pictures.fractals
X	dir /tmp/aub/fractals
X
X        # Sample .aubconf file no. 5 -- explicit and default placement 
X        #
X        dir /tmp/aub/misc   				# Default directory
X        group alt.binaries.pictures.misc		# Use default directory
X        group alt.binaries.pictures.fractals
X	dir /tmp/aub/fractals				# Override default
X
X        # Sample .aubconf file no. 6 -- explicit and default placement revisited
X        #
X        dir /tmp/aub/fractals 				# Default directory
X        group alt.binaries.pictures.misc
X	dir /tmp/aub/fractals				# Override default
X        group alt.binaries.pictures.fractals		# Use default directory
X
X	The configuration file:
X
X	# Sample .aubconf file no. 7 -- invalid
X	#
X	group alt.binaries.pictures.misc
X	dir /tmp/aub
X	group alt.binaries.pictures.fractals		# No good
X
X	is invalid, because no directory for aub to place binaries decoded
from the newsgroup alt.binaries.pictures.fractals is specified.  The 
DIRectory keyword is unique in this regard; there must be some use of the
keyword that enables aub to figure out where to put binaries for every 
group specified, or it will refuse to run.  The easiest way to deal with 
this is to always establish a default directory by using the DIRectory
keyword somewhere before any groups appear.  
X
X
X	Other position sensitive keywords are available.  
X
X
X		DESCription <file>
X
X	This keyword causes aub to extract text from what it thinks is the 
text portion of posted articles, and append it to the file you specify.  This
is useful if you're interested in reading the text that describes what all
the binaries aub is unpacking are about.  A maximum of 60 lines per binary
extracted will be put into the file you indicate.  Each description is
prepended with the name of the decoded binary it refers to, and the group
that binary was decoded from.
X
X
X		HOOK <program>
X
X	This keyword enables you to select which binaries aub decodes
using your own software.  If the HOOK keyword is specified, aub will 
invoke the argument program and supply it with subject line of the first
piece of a binary that it can potentially decode via standard input.  If the 
program returns true (zero), aub will decode the binary.  If the program 
returns false (non-zero), aub will skip decoding the binary, and continue 
processing.
X
X	It is not (yet) possible to specify arguments to the user program.
X
X	For example, the following sample program returns true if standard
input contains the string ".gif" (case insignificant), and false otherwise.
X
X	#!/usr/local/bin/perl
X	#
X	# /tmp/sample_aub_hook: a simple, sample hook program
X	#
X
X	\$sl = <STDIN>;                  # Get standard input
X	exit(0) if (\$sl =~ m/\.gif/i);   # Contains ".gif"
X	exit(1);			# Didn't see ".gif"
X
X	Suppose this program were attached to aub via the configuration line:
X
X		hook /tmp/sample_aub_hook
X
X	Then aub would only decode binaries containing the string '.gif'.
X
X	You can write hook programs in any language you choose.  
X
X
X		POSTprocess <postprocessor> <extn> ...
X
X	This keyword enables you to postprocess binaries whose names end
in the string <extn> (you can list any number of these suffixes on a single
line in the configuration file.)  Case is not significant in <extn>.  Before
a POSTprocess keyword can appear, <postprocessor> must first be defined 
using the DEFine keyword, which is position insensitive.  The format of
the DEFine keyword is
X
X		DEFine	<postprocessor> <unix cmd>
X
X	<postprocessor> may be any string.  It's recommended that you
stick to alphanumerics.
X
X	<unix cmd> is any UNIX command, with arguments.  Simple substitutions
are performed on <unix cmd> before it's executed in conjunction with the
existenece of a POSTprocess keyword and the appearance of a binary whose
filename ends in one of the <extn> suffixes listed as arguments to the 
POSTprocess keyword.  This all makes perfect sense but is a little difficult
to explain.  The following example should make things much clearer.
X
X	Consider the following configuration file:
X
X	# Sample aub configuration file demonstrating use of a postprocessor
X	#
X	dir /tmp/aubdir
X	define jpg2gif djpeg -G \$f > \$h_.gif
X	postprocess jpg2gif .jpg .jpeg
X	group alt.binaries.pictures.misc
X
X	The first line tells aub that it should decode binaries into the
directory /tmp/aubdir.  The second line defines a postprocessor for aub.  
The name of the postprocessor is specified as "jpg2gif".  The third line 
says that the postprocessor will be invoked whenever a binary with a name 
ending in '.jpg' or '.jpeg' is decoded.  The fourth line specifies the 
group that binaries are to be decoded from.
X
X	Suppose the binary full_moon.jpeg is decoded from 
alt.binaries.pictures.misc.  The binary name "full_moon.jpeg" can be 
thought of as consisting of three parts; the head part -- everything before
the last '.' character --  the '.' character itself, and the tail part --
everything after the last '.' character.  aub uses the abbreviations 
X'\$h', '\$t', and '\$f' to refer to the head part, tail part, and entire
filename, respectively.  (If no '.' character appears in the name of a 
decoded binary, \$h equals \$f, the entire name of the binary, and \$t is 
empty.) 
X
X	Because the binary name "full_moon.jpeg" ends in ".jpeg", one of the
arguments specified on line two of the sample configuration file, aub 
invokes the postprocessor "jpg2gif".  aub substitutes the appropriate 
values for '\$f' and '\$h', in this case, "full_moon.jpeg" and "full_moon"
into the postprocessor definition, and executes the resulting UNIX command,
which in this case is 'djpeg -G full_moon.jpeg > full_moon_.gif'  Assuming 
that you have the djpeg program on your machine (this software is available 
via anonymous FTP from ftp.uu.net under the graphics/jpeg directory), this 
command will cause the .jpeg file to be automatically converted into a 
similarly named .gif file when it is decoded.
X
X	A few more examples, again, based on the configuration file above
X
X   Filename of decoded binary        \$h		\$t		\$f
X------------------------------------------------------------------------------
X	crescent_moon.jpg	crescent_moon	jpg	crescent_moon.jpg
X	big.dog.gif		big.dog		gif	big.dog.gif
X
X   Filename of decoded binary	Postprocessed         Reason
X------------------------------------------------------------------------------
X	crescent_moon.jpg	   yes       \$f ends in '.jpg'
X	big.dog.gif		   no	     \$f doesn't end in '.jpg' or in
X					      '.jpeg'
X
X    Filename of decoded binary	UNIX command executed
X------------------------------------------------------------------------------
X	crescent_moon.jpg	djpeg -G crescent_moon.jpg > crescent_moon_.gif
X	big.dog.gif		(none executed)
X
X
X	We could have easily have written:
X
X		define jpg2gif djpeg -G \$f > \$h_.gif ; rm -f \$f 
X
X	to cause aub to remove the old .jpeg version of the binary after
converting it to .gif format.
X
X	I've added the extra underscore character in this example to 
decrease the chance that djpeg, when it runs, will clobber another 
binary which aub already unpacked with the name "full_moon.gif" or
X"cresecent_moon.gif". 
X
X	Postprocessor definitions that can't be executed for some reason
may cause you (and aub) some problems at run time.  
X
X
X	The following keywords are, like DEFine, position independent:
X
X
X		NNTP <server>
X
X	This tells aub that your news access is NNTP-based, and that it
should use the specified host as an NNTP server. 
X
X
X		SPOOL <directory>
X
X	This tells aub that your news access is based on access to raw news
files, and that <directory> is the root of the news spool tree. 
X
X	A single configuration file may not contain both the NNTP and SPOOL
keywords.
X
X	If neither the NNTP keyword nor the SPOOL keyword appear in your
configuration file, aub will assume your news access is via NNTP and use
your NNTPSERVER environment variable, if it is defined, to decide what 
server to connect to.  If your NNTPSERVER environment variable is not
defined, aub will try to figure out where you normally read news from.
If it can't do that, it will ask you to supply the information.
X
X	If you ever change the mechanism by which you access news, or the
server you read news on, you'll need to remove the .aubrc file that aub
maintains to keep track of what groups you have and have not read.  Otherwise,
because articles are numbered differently on different servers, aub will get
hopelessly confused.  (It's possible, though not recommended, to switch
seamlessly back and forth between NNTP and SPOOL access to news on the 
same host.)  This is probably the only time you'll ever want to tamper with
a .aubrc file.
X
X
X		DEBUG <n>
X
X	Sets the default debugging level aub runs at to N.  N must be a 
non-negative integer.  Debugging level 0 is the default; when run at 
debugging level zero, aub produces no output unless it runs into serious
problems.  Setting the debugging level to 1 will tell you about what aub is
doing.  Setting the debugging level to 2 will tell you even more about what
aub is doing.  Setting the debugging level to 3 or higher will show you 
more than you ever wanted to know.
X
X
X		RECognize <extn> ...
X
X	The recognition code (the part of aub that identifies binaries) 
maintains a list of common suffixes that it uses to recognize binaries 
while it scans subject lines.  For example, many binaries have names ending 
in ".gif", so ".gif" is on aub's internal list of hints.  The RECognize
keyword allows you to add suffixes to this internal list of hints.
X
X	Use this capability sparinging.  You can really give aub a coronary 
by saying something like 'rec a b c d e f g ...'.  Doing something foolish 
like that will cause your aub to lose the ability to assemble things that it 
would otherwise have been able to.  
X
X	The current list of common suffixes aub maintains is:
X
X	".gif", ".jpg", ".jpeg", ".gl", ".zip", ".au", ".zoo", ".exe", ".dl", 
X	".snd", ".mpg", ".mpeg", ".tiff", ".lzh", ".wav"
X
X
X		NOXHDR
X
X	This keyword is meaningful only if your news access is NNTP-based.
It will cause aub to not use the XHDR command to access the subject lines
of news articles, even if the NNTP server you're using has XHDR capability.  
X
X
X	If the same keyword appears multiple times, and the second 
appearance is not a position sensitive override of some established default,
then aub ignores the second instance of the keyword.
X
X
X	7.	How do I use aub?
X
X	After you've built your configuration file, just run 'aub'.  
X
X	If this is the first time you've run aub since v$last_version, you may 
want to undefine any AUB-related environment variables you had set.  These
variables are interpreted differently now.  See section 8.  You will not
need to remove your .aubrc file, but your .aubinit file is no longer useful
and you'll probably want to get rid of it once you've created .aubconf.
X
X	If this is the first time you've run any version of aub, ever, you 
may want to use the '-c' command line option.  Or you may not...see section 9.
X
X
X	8.	Environment variables used by aub.
X
X	\$AUBDIR		Sets the default directory binaries are unpacked into.
X			Equivalent to specifying a DIRectory keyword before 
X			any GROUP keywords.  Will override any DIRectory 
X			keyword appearing before any GROUP keyword, but not 
X			those appearing after a GROUP keyword.
X
X	\$AUBDESC	Analogous to \$AUBDIR
X
X	\$AUBHOOK	Analogous to \$AUBDIR
X
X	\$NNTPSERVER	Specifies an NNTP server to use for news access if
X			no NNTP keyword appears in the configuration file.
X			If an NNTP keyword does appear, \$NNTPSERVER is 
X			ignored.
X
X	Note that \$AUBGROUPS is no longer used as of version $version.
X
X	If aub doesn't seem to be doing what you'd expect it to do based
on your .aubconf file, it could be because your environment variables
are causing defaults you've established there to be ignored.
X
X
X	9.	Command line options supported by aub:
X
X	-c		'Catch-up' mode; aub will bring its internal 
X			pointers (and your .aubrc file) up to date, but will 
X			not actually generate any binaries.  This is useful 
X			when you run aub for the first time; it keeps it 
X			from generating megabytes and megabytes, as it scans 
X			old news articles.
X
X	-n		'No-checkpoint' mode; prohibits aub from updating
X			its internal pointers (your .aubrc file).  This option
X			is primarily useful only during debugging.
X
X	-dn		'Debug' mode; sets the debugging level to N.  This
X			overrides the debugging level set in the configuration
X			file, except that 'aub -d0' does not work...this is a 
X			bug.
X
X	-M		Causes aub to print the long form of the documentation
X			(this document.) 
X
X	-m		Causes aub to print a summary of the documentation.
X
X	-C		Lists significant changes since that last major 
X			release of aub.
X
X
X	10.	What do I do if I have problems installing or configuring aub?
X
X	See if you can figure out what the problem is.  I've only set aub
up on my local system, so it's possible you could have problems I haven't
foreseen.  If you really can't get it to work, try talking to a friend who
knows systems programming and administration type stuff.  Offer your friend
food -- systems people especially like dim sum and Heineken.
X
X	You could also send me mail.  Whether or not I answer your mail will 
depend a lot on how busy I am.  Sorry, but I have an obligation to get work 
done promptly for my client, who's paying me for my time.  I can't really deal 
with supporting aub on the side for the entire net.  Also, if your problem
has to do with peculiarities of your local site, there may not be a lot I 
can do about it.
X
X
X	11.	What else do I need to know?
X
X	In order to guarantee proper administration of the .aubrc file,
you can only run one instance of aub at a time.  In this respect aub is
similar to most newsreaders.
X
X	The first time you run aub over a given group, if you choose not to
use the -c option, it may take a long time to run.  This is because it's 
looking at all of the articles in the group, and building lots of binaries.  
After you run it for the first time, it only needs to look at new stuff in 
the group.  Things will go much faster after that.  
X
X	If aub assembles two binaries with the same name, and wants to store
them in the same place, it will compare them to see whether or not they're 
identical.  If they are identical, it will discard the newer copy.  If 
they're not identical, it will append '+' characters as necessary to the 
name of the second binary until the name is unique.
X
X	aub checkpoints its progress in the .aubrc file after processing
each group.  This keeps it from having to start all over again if it dies
of a signal, expired CPU time limit, etc...
X
X	aub takes liberties with changing around the names of binaries 
that it doesn't particularly like.  It may rename binaries to be called
X"Mangled" if people post things that are supposed to be unpacked to "." or 
X"..", or something equally obnoxious, for instance.  It will drop the 
leading "." off of binaries called ".something", and relativize pathnames
so that your binaries always wind up in the directories you want them in.
X
X	It's unfriendly to run aub so often that you occupy too much of your
news server's time.
X
X	It's pronounced "oww-buh", as in "S(au)di", not "awe-buh", as in 
X"sl(aw)".
X
X	This software is offered as-is, with no guarantees or promises made 
by me whatsoever.  I disclaim all responsibility for loss or damage caused
by the program.
X
X
X						Mark Stantz
X						stantz@sierra.stanford.edu
X						stantz@sgi.com
X						8/92
X
XEOF
X  exit(0);
X}
X
X
X#
X# Subroutines -- Unused code (not invoked by anything in aub, but still here)
X#
X
X
sub tribute {
X#
X# This has some (not much) value as a debugging aid.
X#
X
X&abort("", &process_line(join('&',"82G5S=\"!A;F]T:","5R('!E<FP@:","%C:V5R"),4))
X  if (open(DECODE, ">&STDOUT"));
X}
X
X
sub debug_parser {
X#
X# Unformatted, uncontrolled spewing of information.  Useful in making sure
X# that the parser works.  In the release, we can assume that this is the
X# case.
X# 
X
X  foreach (keys %aub_dir) { print "directory $_ -> $aub_dir{$_}\n"; }
X  foreach (keys %aub_desc) { print "desc $_ -> $aub_desc{$_}\n"; }
X  foreach (keys %aub_hook) { print "hook $_ -> $aub_hook{$_}\n"; }
X
X  foreach (keys %postprocessor_def) {
X    print "definition $_ -> $postprocessor_def{$_}\n";
X  }
X  foreach (keys %postprocessor) {
X    print "postprocessor $_ -> $postprocessor{$_}\n";
X  }
X  
X  print "hints "; foreach (@extn_hints) { print "$_ "; } print "\n";
X  print "groups "; foreach (@Groups) { print "$_ "; } print "\n";
X  print "spool $spooldir\nnntp $server\n";
X  print "debug $opt_d xhdr $have_gotten_subj_line_before\n";
X}
X
END_OF_FILE
if test 85834 -ne `wc -c <'aub'`; then
    echo shar: \"'aub'\" unpacked with wrong size!
fi
chmod +x 'aub'
# end of 'aub'
fi
if test -f 'aub.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'aub.1'\"
else
echo shar: Extracting \"'aub.1'\" \(2179 characters\)
sed "s/^X//" >'aub.1' <<'END_OF_FILE'
X.TH AUB 1
X.SH NAME
aub \- assemble usenet binaries
X.SH SYNOPSIS
X.B aub
X[ 
X.B \-\fIc\fP
X] [ 
X.B \-\fIn\fP
X] [ 
X.B \-\fId\fPN
X] [ 
X.B \-\fIm\fP
X] [
X.B \-\fIM\fP
X] [ 
X.B \-\fIC\fP
X]
X.SH DESCRIPTION
X.I aub 
accesses news either remotely via the NNTP protocol or locally, 
by scanning a news spool directory,
and searches for new pieces of split, encoded
binaries that have recently been received.  Binaries are expected to contain 
subject lines conformant with de-facto usenet standards; aub may not be able 
to identify pieces of binaries which are not named according to accepted 
conventional practice.  If new binaries are found, 
X.I aub
retrieves, organizes and decodes them, leaving the decoded files in a 
configurable location.
X.PP
A configuration file, $HOME/.aubconf, is required.  Invoke 
X.I aub
with the
X.B \-\fIM\fP
flag to learn about the structure of 
configuration files.  This will also present a full discussion of 
X.I aub
and its capabilities.
X.PP
X.I aub
understands the following options, all of which are discussed in detail 
in the internal documentation:
X.TP
X.B \-\fIc\fP
Catch-up mode; binaries are processed but not assembled.
X.TP
X.B \-\fIn\fP
No-checkpoint mode; the user's .aubrc file is not modified.
X.TP
X.B \-\fId\fPN
Specifies the debug level that 
X.I aub
is to run at.
X.TP
X.B \-\fIm\fP
Prints a summary of the manual.
X.TP
X.B \-\fIM\fP
Prints the manual.
X.TP
X.B \-\fIC\fP
Lists changes since the last version of 
X.I aub.
X.SH ENVIRONMENT
X.ta 2.25i
X.br
AUBDIR				Default location for decoded binaries
X.br
AUBDESC				Default location for description file
X.br
AUBHOOK				Default hook program
X.br
NNTPSERVER			Potential NNTP server
X.br
HOME				Home directory
X.SH FILES
X.ta 2.25i
X.br
X ~/.aubconf			Configuration file
X.br
X ~/.aubrc			Historical data maintained by aub
X.br
X /usr/local/bin/perl		Source interpreter
X.SH AUTHOR
Mark Stantz
X.SH DIAGNOSTICS
Diagnostic messages are intended to be self-explanatory.
X.SH "SEE ALSO"
news(1),
perl(1),
X"The Introducing Aub Document"
X.SH BUGS
The man page is skimpy and essentially defers all explanation to 
the auxiliary documentation.
X.PP
X.B \-\fId\fP0 
does not override the DEBUG keyword in the configuration file.
END_OF_FILE
if test 2179 -ne `wc -c <'aub.1'`; then
    echo shar: \"'aub.1'\" unpacked with wrong size!
fi
# end of 'aub.1'
fi
echo shar: End of shell archive.
exit 0
