Article 13636 of alt.sources:

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	shar.forward
#	README
#	COPYING
#	macros.h
#	msg.h
#	atom.h
#	atom.c
#	center.c
#	msg.c
#	spacing.c
#	utils.c
#	version.c
#	TODO
#	Makefile
#	atom.1
#	test
#
echo x - shar.forward
sed 's/^X//' >shar.forward << 'END-of-shar.forward'
X@(#) shar.forward.
X$Header: /usr/home/kline/devel/atom/RCS/shar.forward,v 1.1 1996/09/12 20:28:12 kline Exp kline $
X
XATOM is an ASCII-to-markup filter, in its earlier incarnations called 
X``qf'', that processes ASCII typewriter quotation marks into TeX and
XHTML typeset quotes.  ATOM also does automatic italicization (given the
Xdelimiters ``*'' or ``_'' and, to indicate the passage of time or a
Xchange of topic,  does physical space-breaks.  In TeX/LaTeX markup
Xonly, ATOM will translate an ellipse indicated by ``...'' into typeset
Xquality.
X
XIf you have diligently space-centered strings in your ASCII document--
Xsay a title or section header, then with a flag, ATOM will translate
Xthe output file to perform either TeX or HTML centering.  The centering
Xoption was added as an afterthought and centers only individual lines,
Xone by one.
X
XBottom line is that you have put a lot of time into creating your ASCII
Xdocument, ATOM will do the markup basics without much effort on your 
Xpart.
X
X
X
END-of-shar.forward
echo x - README
sed 's/^X//' >README << 'END-of-README'
X#@ $Header: /home/kline/TeX/RCS/README,v 1.3 1995/07/06 00:33:09 kline Exp klin
X$Header: /usr/home/kline/devel/atom/RCS/README,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X
X
X                                   README                                         
X  
X  
X  I hacked the foundation of this filter together in the fall of 1994 
X  when trying to find a means of turning "...and " into ``...and '' 
X  for TeX and LaTex or HTML format.  Once this filtering was done, I 
X  decide to add a very basic italicization option.  My personal means 
X  of indicating italics in an ASCII message or other text is to use 
X  asterisk delimiters.  This can easily be changed in atom.h.
X
X  In the TeX  markup world, 
X
X	"I said *no*!"
X
X  becomes:
X
X	``I said {\em no\/}!''
X
X  The above output is now ready for the standard tex or latex processing.
X  It was easy to add the ellipses markup for TeX.  HTML has no markup tags
X  to indicate that three periods indicate an ellipse; at least not in
X  HTML-3.0.
X
X  atom automatically translates typewriter quote into those which are displayed 
X  as properly typeset quotation marks for Tex (and LaTeX) or HTML.
X  
X  This filter also turns italics-delimited words or phrases into italics
X  when displayed by TeX or HTML.  The default delimiter to indicate that 
X  italics be displayed is the asterisk.  This is configurable.
X  And, for TeX only, atom correctly displays ellipses.
X  
X  The default is to handle italics and ellipses under TeX, and to do
X  processes any italics-delimited word or words into HTML italics.   Given 
X  the -e and the -i flags, atom will not do this processing.
X  
X  You must specify either -h for HTML; the -t for TeX is the default.
X  
X  Any series of three dots  (...)  is, for TeX, considered to be an
X  ellipse.
X  
X  If you have a physical break of five newlines in your input file--to
X  indicate a change of topic or thought or a length of time passing by--
X  atom -p <file> will insert a physical space break into your output file.
X  For HTML, the ``-p'' flag will print five <BR> tags; for LaTeX, atom 
X  will print the markup ``\vspace*{.r}''.
X
X  atom also processes ``center'' lines that you have carefully, with spaces,
X  centered.  Such as:
X
X                             This line is Centered
X
X  But if you use the -c flag to find space-centered lines, note that atom will
X  ignore all space-indented paragraphs.  I added this last bit pretty much
X  as an after-thought.  It only took a few hours to plug in, and for the
X  rare case it might be useful.  Bear in mind that I originally hacked atom
X  together to do quote filtering only and that atom will probably be most useful
X  as simply a quotation filter, plain and simple.
X
X  atom prints very simple header and footer tags for HTML and ``%%%'' 
X  comment-lines for TeX markup.  For HTML, these begin/end tags are a
X  bit more sophisticated, but make no assumptions about the layout of
X  your HTML document: all text is contained within <BODY>, </BODY>
X  delimiters.  You plug in whatever you require within the <HEAD>, </HEAD>
X  delimiters and elsewhere.
X
X
X
X
X
X  Acknowledgments:
X  I have pulled in various free-ware and copyright code such as Kjetil Homme's
X  trace code and some 4BSD code and others, modified slightly.  Primarily
X  well-proven code rather than to re-invent such wheels and gears.
X
X  If anyone wishes to add further power or flexibility to atom without
X  turning this simple filter into yet another quasi-markup language, go
X  ahead.  I ask only that you send me any mods or bug-fixes.  Comments
X  received have given me new non-markup ideas; thanks here duly noted to
X  the dozens of people who have send mail and comments on this filter.
X  Comments still welcome, of course.
X
X  Revision 1.3:  This program now compiles under BSD, SunOS-4, and 
X  any SVR4.  It should be easily portable to other platforms.  
X
X
X  ---
X  Copyright (C), 1994, 1995, by Gary D. Kline
X  This software is placed under distribution restrictions and rights
X  according to the GNU General Public License.  See the file ``COPYING''
X  included, or write to the Free Software Foundation, Inc.,
X  675 Mass Avenue, Cambridge, MA 02139, USA
X
X  
X  Gary Kline	
X  kline@tao.thought.org  ||  kline@tera.com
END-of-README
echo x - COPYING
sed 's/^X//' >COPYING << 'END-of-COPYING'
X
X		    GNU GENERAL PUBLIC LICENSE
X		       Version 2, June 1991
X
X Copyright (C) 1989, 1991 Free Software Foundation, Inc.
X                          675 Mass Ave, Cambridge, MA 02139, USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X			    Preamble
X
X  The licenses for most software are designed to take away your
Xfreedom to share and change it.  By contrast, the GNU General Public
XLicense is intended to guarantee your freedom to share and change free
Xsoftware--to make sure the software is free for all its users.  This
XGeneral Public License applies to most of the Free Software
XFoundation's software and to any other program whose authors commit to
Xusing it.  (Some other Free Software Foundation software is covered by
Xthe GNU Library General Public License instead.)  You can apply it to
Xyour programs, too.
X
X  When we speak of free software, we are referring to freedom, not
Xprice.  Our General Public Licenses are designed to make sure that you
Xhave the freedom to distribute copies of free software (and charge for
Xthis service if you wish), that you receive source code or can get it
Xif you want it, that you can change the software or use pieces of it
Xin new free programs; and that you know you can do these things.
X
X  To protect your rights, we need to make restrictions that forbid
Xanyone to deny you these rights or to ask you to surrender the rights.
XThese restrictions translate to certain responsibilities for you if you
Xdistribute copies of the software, or if you modify it.
X
X  For example, if you distribute copies of such a program, whether
Xgratis or for a fee, you must give the recipients all the rights that
Xyou have.  You must make sure that they, too, receive or can get the
Xsource code.  And you must show them these terms so they know their
Xrights.
X
X  We protect your rights with two steps: (1) copyright the software, and
X(2) offer you this license which gives you legal permission to copy,
Xdistribute and/or modify the software.
X
X  Also, for each author's protection and ours, we want to make certain
Xthat everyone understands that there is no warranty for this free
Xsoftware.  If the software is modified by someone else and passed on, we
Xwant its recipients to know that what they have is not the original, so
Xthat any problems introduced by others will not reflect on the original
Xauthors' reputations.
X
X  Finally, any free program is threatened constantly by software
Xpatents.  We wish to avoid the danger that redistributors of a free
Xprogram will individually obtain patent licenses, in effect making the
Xprogram proprietary.  To prevent this, we have made it clear that any
Xpatent must be licensed for everyone's free use or not licensed at all.
X
X  The precise terms and conditions for copying, distribution and
Xmodification follow.
X
X		    GNU GENERAL PUBLIC LICENSE
X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X  0. This License applies to any program or other work which contains
Xa notice placed by the copyright holder saying it may be distributed
Xunder the terms of this General Public License.  The "Program", below,
Xrefers to any such program or work, and a "work based on the Program"
Xmeans either the Program or any derivative work under copyright law:
Xthat is to say, a work containing the Program or a portion of it,
Xeither verbatim or with modifications and/or translated into another
Xlanguage.  (Hereinafter, translation is included without limitation in
Xthe term "modification".)  Each licensee is addressed as "you".
X
XActivities other than copying, distribution and modification are not
Xcovered by this License; they are outside its scope.  The act of
Xrunning the Program is not restricted, and the output from the Program
Xis covered only if its contents constitute a work based on the
XProgram (independent of having been made by running the Program).
XWhether that is true depends on what the Program does.
X
X  1. You may copy and distribute verbatim copies of the Program's
Xsource code as you receive it, in any medium, provided that you
Xconspicuously and appropriately publish on each copy an appropriate
Xcopyright notice and disclaimer of warranty; keep intact all the
Xnotices that refer to this License and to the absence of any warranty;
Xand give any other recipients of the Program a copy of this License
Xalong with the Program.
X
XYou may charge a fee for the physical act of transferring a copy, and
Xyou may at your option offer warranty protection in exchange for a fee.
X
X  2. You may modify your copy or copies of the Program or any portion
Xof it, thus forming a work based on the Program, and copy and
Xdistribute such modifications or work under the terms of Section 1
Xabove, provided that you also meet all of these conditions:
X
X    a) You must cause the modified files to carry prominent notices
X    stating that you changed the files and the date of any change.
X
X    b) You must cause any work that you distribute or publish, that in
X    whole or in part contains or is derived from the Program or any
X    part thereof, to be licensed as a whole at no charge to all third
X    parties under the terms of this License.
X
X    c) If the modified program normally reads commands interactively
X    when run, you must cause it, when started running for such
X    interactive use in the most ordinary way, to print or display an
X    announcement including an appropriate copyright notice and a
X    notice that there is no warranty (or else, saying that you provide
X    a warranty) and that users may redistribute the program under
X    these conditions, and telling the user how to view a copy of this
X    License.  (Exception: if the Program itself is interactive but
X    does not normally print such an announcement, your work based on
X    the Program is not required to print an announcement.)
X
XThese requirements apply to the modified work as a whole.  If
Xidentifiable sections of that work are not derived from the Program,
Xand can be reasonably considered independent and separate works in
Xthemselves, then this License, and its terms, do not apply to those
Xsections when you distribute them as separate works.  But when you
Xdistribute the same sections as part of a whole which is a work based
Xon the Program, the distribution of the whole must be on the terms of
Xthis License, whose permissions for other licensees extend to the
Xentire whole, and thus to each and every part regardless of who wrote it.
X
XThus, it is not the intent of this section to claim rights or contest
Xyour rights to work written entirely by you; rather, the intent is to
Xexercise the right to control the distribution of derivative or
Xcollective works based on the Program.
X
XIn addition, mere aggregation of another work not based on the Program
Xwith the Program (or with a work based on the Program) on a volume of
Xa storage or distribution medium does not bring the other work under
Xthe scope of this License.
X
X  3. You may copy and distribute the Program (or a work based on it,
Xunder Section 2) in object code or executable form under the terms of
XSections 1 and 2 above provided that you also do one of the following:
X
X    a) Accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of Sections
X    1 and 2 above on a medium customarily used for software interchange; or,
X
X    b) Accompany it with a written offer, valid for at least three
X    years, to give any third party, for a charge no more than your
X    cost of physically performing source distribution, a complete
X    machine-readable copy of the corresponding source code, to be
X    distributed under the terms of Sections 1 and 2 above on a medium
X    customarily used for software interchange; or,
X
X    c) Accompany it with the information you received as to the offer
X    to distribute corresponding source code.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form with such
X    an offer, in accord with Subsection b above.)
X
XThe source code for a work means the preferred form of the work for
Xmaking modifications to it.  For an executable work, complete source
Xcode means all the source code for all modules it contains, plus any
Xassociated interface definition files, plus the scripts used to
Xcontrol compilation and installation of the executable.  However, as a
Xspecial exception, the source code distributed need not include
Xanything that is normally distributed (in either source or binary
Xform) with the major components (compiler, kernel, and so on) of the
Xoperating system on which the executable runs, unless that component
Xitself accompanies the executable.
X
XIf distribution of executable or object code is made by offering
Xaccess to copy from a designated place, then offering equivalent
Xaccess to copy the source code from the same place counts as
Xdistribution of the source code, even though third parties are not
Xcompelled to copy the source along with the object code.
X
X  4. You may not copy, modify, sublicense, or distribute the Program
Xexcept as expressly provided under this License.  Any attempt
Xotherwise to copy, modify, sublicense or distribute the Program is
Xvoid, and will automatically terminate your rights under this License.
XHowever, parties who have received copies, or rights, from you under
Xthis License will not have their licenses terminated so long as such
Xparties remain in full compliance.
X
X  5. You are not required to accept this License, since you have not
Xsigned it.  However, nothing else grants you permission to modify or
Xdistribute the Program or its derivative works.  These actions are
Xprohibited by law if you do not accept this License.  Therefore, by
Xmodifying or distributing the Program (or any work based on the
XProgram), you indicate your acceptance of this License to do so, and
Xall its terms and conditions for copying, distributing or modifying
Xthe Program or works based on it.
X
X  6. Each time you redistribute the Program (or any work based on the
XProgram), the recipient automatically receives a license from the
Xoriginal licensor to copy, distribute or modify the Program subject to
Xthese terms and conditions.  You may not impose any further
Xrestrictions on the recipients' exercise of the rights granted herein.
XYou are not responsible for enforcing compliance by third parties to
Xthis License.
X
X  7. If, as a consequence of a court judgment or allegation of patent
Xinfringement or for any other reason (not limited to patent issues),
Xconditions are imposed on you (whether by court order, agreement or
Xotherwise) that contradict the conditions of this License, they do not
Xexcuse you from the conditions of this License.  If you cannot
Xdistribute so as to satisfy simultaneously your obligations under this
XLicense and any other pertinent obligations, then as a consequence you
Xmay not distribute the Program at all.  For example, if a patent
Xlicense would not permit royalty-free redistribution of the Program by
Xall those who receive copies directly or indirectly through you, then
Xthe only way you could satisfy both it and this License would be to
Xrefrain entirely from distribution of the Program.
X
XIf any portion of this section is held invalid or unenforceable under
Xany particular circumstance, the balance of the section is intended to
Xapply and the section as a whole is intended to apply in other
Xcircumstances.
X
XIt is not the purpose of this section to induce you to infringe any
Xpatents or other property right claims or to contest validity of any
Xsuch claims; this section has the sole purpose of protecting the
Xintegrity of the free software distribution system, which is
Ximplemented by public license practices.  Many people have made
Xgenerous contributions to the wide range of software distributed
Xthrough that system in reliance on consistent application of that
Xsystem; it is up to the author/donor to decide if he or she is willing
Xto distribute software through any other system and a licensee cannot
Ximpose that choice.
X
XThis section is intended to make thoroughly clear what is believed to
Xbe a consequence of the rest of this License.
X
X  8. If the distribution and/or use of the Program is restricted in
Xcertain countries either by patents or by copyrighted interfaces, the
Xoriginal copyright holder who places the Program under this License
Xmay add an explicit geographical distribution limitation excluding
Xthose countries, so that distribution is permitted only in or among
Xcountries not thus excluded.  In such case, this License incorporates
Xthe limitation as if written in the body of this License.
X
X  9. The Free Software Foundation may publish revised and/or new versions
Xof the General Public License from time to time.  Such new versions will
Xbe similar in spirit to the present version, but may differ in detail to
Xaddress new problems or concerns.
X
XEach version is given a distinguishing version number.  If the Program
Xspecifies a version number of this License which applies to it and "any
Xlater version", you have the option of following the terms and conditions
Xeither of that version or of any later version published by the Free
XSoftware Foundation.  If the Program does not specify a version number of
Xthis License, you may choose any version ever published by the Free Software
XFoundation.
X
X  10. If you wish to incorporate parts of the Program into other free
Xprograms whose distribution conditions are different, write to the author
Xto ask for permission.  For software which is copyrighted by the Free
XSoftware Foundation, write to the Free Software Foundation; we sometimes
Xmake exceptions for this.  Our decision will be guided by the two goals
Xof preserving the free status of all derivatives of our free software and
Xof promoting the sharing and reuse of software generally.
X
X			    NO WARRANTY
X
X  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
XREPAIR OR CORRECTION.
X
X  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
XPOSSIBILITY OF SUCH DAMAGES.
X
X		     END OF TERMS AND CONDITIONS
X
X	Appendix: How to Apply These Terms to Your New Programs
X
X  If you develop a new program, and you want it to be of the greatest
Xpossible use to the public, the best way to achieve this is to make it
Xfree software which everyone can redistribute and change under these terms.
X
X  To do so, attach the following notices to the program.  It is safest
Xto attach them to the start of each source file to most effectively
Xconvey the exclusion of warranty; and each file should have at least
Xthe "copyright" line and a pointer to where the full notice is found.
X
X    <one line to give the program's name and a brief idea of what it does.>
X    Copyright (C) 19yy  <name of author>
X
X    This program is free software; you can redistribute it and/or modify
X    it under the terms of the GNU General Public License as published by
X    the Free Software Foundation; either version 2 of the License, or
X    (at your option) any later version.
X
X    This program is distributed in the hope that it will be useful,
X    but WITHOUT ANY WARRANTY; without even the implied warranty of
X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X    GNU General Public License for more details.
X
X    You should have received a copy of the GNU General Public License
X    along with this program; if not, write to the Free Software
X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XAlso add information on how to contact you by electronic and paper mail.
X
XIf the program is interactive, make it output a short notice like this
Xwhen it starts in an interactive mode:
X
X    Gnomovision version 69, Copyright (C) 19yy name of author
X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X    This is free software, and you are welcome to redistribute it
X    under certain conditions; type `show c' for details.
X
XThe hypothetical commands `show w' and `show c' should show the appropriate
Xparts of the General Public License.  Of course, the commands you use may
Xbe called something other than `show w' and `show c'; they could even be
Xmouse-clicks or menu items--whatever suits your program.
X
XYou should also get your employer (if you work as a programmer) or your
Xschool, if any, to sign a "copyright disclaimer" for the program, if
Xnecessary.  Here is a sample; alter the names:
X
X  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
X  `Gnomovision' (which makes passes at compilers) written by James Hacker.
X
X  <signature of Ty Coon>, 1 April 1989
X  Ty Coon, President of Vice
X
XThis General Public License does not permit incorporating your program into
Xproprietary programs.  If your program is a subroutine library, you may
Xconsider it more useful to permit linking proprietary applications with the
Xlibrary.  If this is what you want to do, use the GNU Library General
XPublic License instead of this License.
X
END-of-COPYING
echo x - macros.h
sed 's/^X//' >macros.h << 'END-of-macros.h'
X
X
X/*
X * this file contains brief functions that would do well
X * to be inlined or macro-ized
X * $Header: /usr/home/kline/devel/atom/RCS/macros.h,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X */
X
X#define NewlineOrTab(ch) (ch == '\n'  || ch == '\t' )
X#define GetNumberOfQuotes(s)  (get_nsymbols(s, DQUOTE)) 
X
X#ifdef NOT_YET
X
Xint
Xget_nsymbols(char *s, char symbol)
X{
X   register int count =  0;
X   while (*s)
X      {
X         if (*s == symbol)
X            count++;
X         s++;
X      }
X   return (count);
X}
X
Xint
Xget_number_isyms(char *s)
X{
X   return(get_nsymbols(s, I_DELIM));
X}
X
Xint
Xlength_to_symbol(register char *s, char symbol)
X{
X   register int len = 0;
X   while (*s)
X   {
X      if (*s != symbol) s++, len++;
X      else break;
X   }
X   return (len);
X}
X
X
Xvoid
Xusage(char *prog)
X{
X   (void)fprintf(stderr, "\tUsage %s: -ht [-eis] file(s)\n", prog);
X}
X
X
X#endif NOT_YET
END-of-macros.h
echo x - msg.h
sed 's/^X//' >msg.h << 'END-of-msg.h'
X/* msg.h - a simple replacement for fprintf for debug- and error-messages
X *  $Header: /usr/home/kline/devel/atom/RCS/msg.h,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X * Kjetil T. Homme, <kjetilho@ifi.uio.no>
X * University of Oslo, 1993. Public domain.
X */
X
X#if !defined(MSG_H)
X#define MSG_H
X
X/* Classes of messages
X * The names are arbitrary, but the last must be MSG_CATEGORIES.
X */
X
X/*
Xtypedef enum {
X    khtrace, khdebug, khwarning, kherror, khfatal, MSG_CATEGORIES
X} msg_category_t;
X*/
X
X
X#define khmsg MSG
Xtypedef enum {
X    TRACE, DEBUG, WARNING, ERROR, FATAL, MSG_CATEGORIES
X} msg_category_t;
X
Xtypedef int msg_severity_t;
X#define MSG_MAX_SEVERITY   10
X
X/* Define MSG_PARSE_ENVIR if you want parsing of the environment
X * variable MSG_LEVEL
X */
X#define MSG_PARSE_ENVIR
X
X/* Define MSG_COUNT_CALLS if you want to trap when a number of calls of
X * msg() have been executed (specified in msg_warnings[]).
X */
X#define MSG_COUNT_CALLS
X
X#if defined(MSG_COUNT_CALLS)
X   /* Execute this when the limit on warnings has been reached
X    */
X#  define MSG_EXIT(class) exit(1)
X#  include <stdlib.h> /* for the prototype of exit */
X#endif
X
X/* ______ No need to change anything below ______ */
X
X#if defined(MSG_PARSE_ENVIR)
X#    define MSG_CONST
X#else
X#    define MSG_CONST const
X#endif
X
Xextern MSG_CONST msg_severity_t msg_level[MSG_CATEGORIES];
Xextern msg_category_t msg_category;	/* used for communication */
Xextern msg_severity_t msg_severity;	/* used for communication */
X
X#if defined(MSG_COUNT_CALLS)
Xextern int msg_warnings[MSG_CATEGORIES];
X#define MSG(category, severity, args) \
X    do { \
X        if (severity >= msg_level[category]) { \
X	    msg_category = category; \
X	    msg_severity = severity; \
X            msg_printf args; \
X            if (msg_warnings[category] && --msg_warnings[category] == 0) { \
X                MSG_EXIT(category); \
X	    } \
X        } \
X    } while (0);
X#else
X#define MSG(category, severity, args) \
X    do { \
X        if (severity >= msg_level[category]) { \
X	    msg_category = category; \
X	    msg_severity = severity; \
X            msg_printf args; \
X        } \
X    } while (0);
X#endif
X
Xvoid msg_init(void);
Xvoid msg_printf(const char *fmt, ...);
X
X#endif /* MSG_H */
END-of-msg.h
echo x - atom.h
sed 's/^X//' >atom.h << 'END-of-atom.h'
X
X/*
X * header for atom.c
X * $Header: /usr/home/kline/devel/atom/RCS/atom.h,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X */
X
X/*
X		 NOTE:
X
X		 If you would rather have the italics delimiter
X		 be an underscore, make that change below
X*/
X
X
X#define clear(s) {register short __Z;for(__Z=0;__Z<sizeof(s);__Z++)s[__Z]='\0';}
X/* this probably insures either true/false or compiler will gripe */
Xtypedef enum _bool { false = 0, true = 1 } boolean;
X
X#define even(n) ((n%2)==0)
X#define odd(n) ((n%2)!=0)
X#define EVEN 4
X#define ODD  11
X#define SLUSH 128
X/*
X *  these symbols can easily be changed for differing char sets.
X */
X#define BSLASH '\\'
X#define CENTER_HTML_ERR "The -h and -c options are mutually exclusive\n"
X#define DQUOTE '"'	   /* standard typewriter-style double quote       */
X#define ELIPSE "..."
X#define ERROR 2
X#define FATAL 1
X#define LDOTS "{\\ldots}"
X#define HBEGIN "  <HEAD>\n<! your header lines here !>\n  </HEAD>\n\n  <BODY>\n"
X#define HEND   "  </BODY>"  /*goes just before </HTML>  */
X#define HHEADER "<!doctype html public '-//IETF//DTD HTML//EN'>\n\
X<!-autotranslation from ASCII by Gary Kline, kline@tao.thought.org-!>\n\
X<HTML>\n"
X#define HSPACE "<BR>\n<BR>\n<BR>\n<BR>\n<BR>\n"
X#define H_TABEQUALS(b) (b[0]=='\t'&&b[1]=='='&&b[2]=='\n') /* private markup */
X#define HTAIL "\n\n</HTML>\n"
X#define L_DQ "``"  
X/*#define I_DELIM '_'*/   /*  underscore italics delimiter, as in _this_   */
X#define I_DELIM '*'       /*  italics delimiter, as in *shoot!*            */
X#define NO_ERRS 0
X#define ONE_NEWLINE 1     /* one newline between paragraphs is the default */
X#define R_DQ "''"
X#define TATTRIBUTE " autotranslation from ASCII by Gary Kline, kline@tao.thought.org\n\n"
X#define TCOMMENT "%%%"
X#define THEADER "%%% file"
X#define TSPACE "\\vspace*{.5in}"
X#define TTAIL   "\n\n%%% end %%%\n"
X#define SLASH '/'
X#define SQUEEZE_PHYSICAL_ERR "squeeze and physical-space options are mutually exclusive\n"
X
X
Xtypedef   int word;      /* "word" used for optimal copy speed */
X#define   wsize   sizeof(word)
X#define   wmask   (wsize - 1)
X
Xstatic int get_nquotes(char *s);
Xstatic int get_nsymbols(char *s, char);
Xint InsertSubstring(char *, const char *, const char *, size_t);
Xchar *strsub(char *, const char *, const char *);
Xstatic void report_isym_err(short, char *);
Xvoid *memmove(void *, const void *, size_t);
Xvoid bcopy(const void *, void *, size_t);
Xstatic int BeginningQuote (char *s);
Xstatic int IsNewParagraph(char *buf);
Xstatic int length_to_symbol(char *s, char symbol);
Xstatic char *left ( char *, unsigned int);
Xstatic void usage (char *);
Xvoid Do_Physical_space(char *, int, int, FILE *);
Xvoid put_break(int, int, FILE *);
Xstatic int IsEmbeddedTab(char *);
Xstatic int LeadingSpaces(char *, int);
Xstatic int qfilter(int, char **, char *);
Xchar *StepPast(char *, unsigned int );
Xstatic char *strsave(const char *);
Xstatic void ProcessText(FILE *, char *, char *, int);
Xstatic char * ProcessItalicizedSymbols(char *);
Xstatic char * scan_buf_0 (char *);
Xstatic char * scan_buf_1 (char *);
Xint Squeeze(char *);
Xunsigned int NumberOfLeadingSpaces(char *);
Xunsigned int CenterStringLength(char *);
Xint DetermineCenteredness(unsigned int, int);
Xvoid DoCenterOutput(char *, FILE *, int, int);
Xint OpenForCentering(char *, int, int);
X
X/*
X * avoid local env hassles:
X */
X#ifdef WWW
X#define _A      0x00000100L             /* Alpha */
X#define _C      0x00000200L             /* Control */ 
X#define _D      0x00000400L             /* Digit */
X#define _G      0x00000800L             /* Graph */
X#define _L      0x00001000L             /* Lower */
X#define _P      0x00002000L             /* Punct */
X#define _S      0x00004000L             /* Space */
X#define _U      0x00008000L             /* Upper */
X#define _X      0x00010000L             /* X digit */
X#define _B      0x00020000L             /* Blank */
X#define _R      0x00040000L             /* Print */
X#define _I      0x00080000L             /* Ideogram */
X#define _T      0x00100000L             /* Special */
X#define _Q      0x00200000L             /* Phonogram */ 
X#define isalnum(c)      __istype((c), (_A|_D))
X#define isalpha(c)      __istype((c),     _A)
X#define iscntrl(c)      __istype((c),     _C)
X#define isdigit(c)      __isctype((c),    _D)   /* ANSI -- locale independent */
X#define isgraph(c)      __istype((c),     _G)
X#define islower(c)      __istype((c),     _L)
X#define isprint(c)      __istype((c),     _R)
X#define ispunct(c)      __istype((c),     _P)
X#define isspace(c)      __istype((c),     _S)
X#define isupper(c)      __istype((c),     _U)
X#define isxdigit(c)     __isctype((c),    _X)   /* ANSI -- locale independent */
X#define tolower(c)      __tolower(c)
X#define toupper(c)      __toupper(c)
X#endif
X
X
X
X
X
X
X
X
X/*
X * extern variables
X */
X/*extern char tempfname[];*/   /* ``TEMP<pid>'' file */
Xextern int err_tab;        /* relate that there was a TAB in centered string */
END-of-atom.h
echo x - atom.c
sed 's/^X//' >atom.c << 'END-of-atom.c'
Xint nl =0;
X/*
X * $Header: /usr/home/kline/devel/atom/RCS/atom.c,v 1.7 1996/09/17 20:08:10 kline Exp kline $
X * atom.c:  quote filter plain ASCII textfiles into TeX-formatted (default)
X * or HTML quotation marks.  Some miscellaneous markups as well.
X */
X#include <stdlib.h>
X#include <stdio.h>
X#include <signal.h>
X#include "macros.h"
X#include "msg.h"
X#include "atom.h"
X
Xextern char *version_string;  /* track */
X
Xstatic int okay = 0, /* is is okay to return our modified string to main?  */
Xqcnt,                /* keep count of the quotes handled per line/buffer   */
Xhtml =  0,           /* hypertext markup language */
Xlatex = 1,           /* LaTeX: is the default */
XNquotes;
X
Xstatic short int spaceindented_paragraph = 0; /* for future xlation to TABs */
X
Xmain(int argc, char **argv)
X{
X   char *program = argv[0];
X   int e_status;
X   void leave();
X   void usage();
X
X   signal (SIGINT, leave); signal (SIGQUIT, leave);
X
X   msg_init();  /* pull in Kjetil Homme's debug library */
X   MSG(TRACE, 1, ("In main(), argc = (%d), *argv = [%s]", argc, *argv));
X   if (argc < 2)
X   {
X      usage(program);
X      leave (1);
X   }
X   e_status = qfilter(argc, argv, program);
X   leave(e_status);
X}
X
Xstatic int
Xqfilter(int argc, char **argv, char *program)
X{
X   extern int optind;
X   register FILE *fp_in, *fp_out;
X   char buf[1024], *out_buf, outputname[128];
X   char *scan_buf_0();
X   char *scan_buf_1();
X   register short c;
X   unsigned short num = 0; /* arbitrary given number of paragraph-space indents
X			    * specified by the user.
X			    */
X   short quotes_and_centered = 0,
X       noquotes_and_centered = 0;
X
X   /* switches */
X   short centering = 0,     /* handle space-centering in ASCII: rare     */
X     ellipse = 1,           /* default is to handle ellipses             */
X     italics = 1,           /* default is to handle italics              */
X     pspace  = 0,           /* default: not add physical-space break     */
X     squeeze = 0;           /* by default, do not remove excess newlines */
X
X   int no_spaceindicated_paragraphs= 0,/* is a PP  indicated by 8 spaces */
X     to_paragraph = 0, psbreak_count = 0;
X   void usage();
X
X   while (( c = getopt (argc, argv, "0123456789ceihpstv")) != EOF)
X   {
X      switch(c)
X      {
X
X      case '0': case '1': case '2': case '3': case '4': case '5': case '6':
X      case '7': case '8': case '9':
X	num = (10 * num + c - '0');
X	 no_spaceindicated_paragraphs = 0;/* allow space-indenting       */
X	 break;
X      case 'c':
X         centering = 1;                    /* we want centering          */
X	 no_spaceindicated_paragraphs = 1; /* disallow 8 spaces == PP    */
X	 if (html)
X	 {
X	    fprintf(stderr,  CENTER_HTML_ERR);
X	    exit(1);
X	 }
X         break;
X      case 'e':
X         ellipse = 0;
X         break;
X      case 'i':
X         italics = 0;
X         break;
X      case 'h':
X         html = 1;
X	 if (centering)
X	 {
X	    fprintf(stderr,  CENTER_HTML_ERR);
X	    exit(1);
X	 }
X         latex = ellipse = 0; /* don't touch ellipse in HTML */
X         break;
X      case 'l':
X      case 't':
X         html = 0;
X         latex = 1;
X         break;
X      case 'p':  /* add <BR> tags or \vspace*{.5in} for physical space breaks */
X	 pspace = 1;
X	 if (squeeze)
X	 {
X	    fprintf(stderr, SQUEEZE_PHYSICAL_ERR);
X	    exit(1);
X	 }
X	 break;
X      case 's':  /* squeeze excess newlines from processed file */
X	 squeeze = 1;
X	 if (pspace)
X	 {
X	    fprintf(stderr, SQUEEZE_PHYSICAL_ERR);
X	    exit(1);
X	 }
X	 break;
X      case 'v':  /* print version_string to stdout             */
X         printf ("atom %s", version_string);   /* use _progname */
X	 exit(0);
X	 break;
X      case '?':
X      default:
X         usage(program);
X         break;
X      }
X   }
X   argc -= optind;
X   argv += optind;
X
X   while (argc > 0)
X   {
X      if ((fp_in = fopen (*argv, "r")) == NULL)
X      {
X         (void) fprintf(stderr, "Can't open file <%s>\n", *argv);
X	 return (FATAL);
X      }
X
X      clear(outputname);
X      if (latex)
X	 (void)sprintf(outputname, "%s.tex", *argv);
X      else if (html)
X	 (void)sprintf(outputname, "%s.html", *argv);
X
X      if ((fp_out = fopen (outputname, "w")) == NULL)
X      {
X         (void) fprintf(stderr, "Can't open file_out \n");
X	 return (FATAL);
X      }
X
X      putheader (html, latex, outputname, fp_out);
X
X      while (fgets(buf, sizeof(buf), fp_in))
X      {
X	unsigned int nlcount = 0;
X         /* 
X          *  A leading newline always indicates a paragraph at the
X          *  following line that does not lead with a newline.
X          *  True both for TeX and HTML.
X	  *
X	  *  Add a second case where the line begins with an initial
X	  *  tab and we also have a paragraph. Or eight or more leading
X	  *  spaces.
X          */
X	if (squeeze)
X	{
X
X                if (*buf == '\n' && nlcount < ONE_NEWLINE  )
X                {
X                        nlcount++;
X                }
X                if (*buf == '\n' && nlcount > 0)
X                {
X                        continue;
X                }
X                else if (*buf != '\n')
X                {
X			/**continue; */
X                }
X                if (nlcount == ONE_NEWLINE  )
X                {
X                        nlcount = 0;
X                        continue;
X                }
X	}
X	if (pspace)
X	{
X		/*
X		 * what i want to do here is print a break if there are
X		 * 5 consec newlines and not print [HT]SPACE if there
X		 * > 5 or < 5 consec newlines.
X	 	 */
X		if (H_TABEQUALS(buf))   /* === undocumented: my own use === */
X		{
X				puts("printing TABBED Break");
X				put_break(html, latex, fp_out);
X				continue;
X		}
X	        Do_Physical_space(buf, html, latex, fp_out);
X	}
X
X         Nquotes = GetNumberOfQuotes(buf);
X	 if (centering)
X	 {
X            unsigned int nleadingspaces = NumberOfLeadingSpaces(buf);
X	    char *centered = StepPast(buf, nleadingspaces);
X            unsigned int cslength = CenterStringLength(centered);
X            if (DetermineCenteredness(nleadingspaces, cslength) )
X	    {
X		if (Nquotes == 0)
X			noquotes_and_centered = 1;
X		(void) DoCenterOutput(buf, fp_out, html, latex);
X                MSG(TRACE, 3, ("\n%s\nis centered\n", buf));
X	    }
X	 }
X	 if (!no_spaceindicated_paragraphs)
X	 {
X            if (NewlineOrTab(buf[0]) || IsEmbeddedTab(buf)|| 
X		LeadingSpaces(buf, num))
X            {
X               MSG(TRACE,1,("No centering: Paragraph ahead: buf = [%s]\n",buf));
X               to_paragraph = 1;
X            }
X            else
X            {
X               MSG(TRACE,1,("No centering: No paragraph ahead: buf = [%s]\n",
X		  buf));
X               to_paragraph = 0;
X            }
X	 }
X	 else if (no_spaceindicated_paragraphs)
X	 {
X            if (NewlineOrTab(buf[0]) || IsEmbeddedTab(buf) )
X            {
X               MSG(TRACE,1,("CENTERING: Paragraph ahead: buf = [%s]\n", buf));
X               to_paragraph = 1;
X            }
X            else
X            {
X               MSG(TRACE,1,("CENTERING: Not paragraph ahead: buf = [%s]\n", 
X		  buf));
X               to_paragraph = 0;
X            }
X	 }
X
X         /*
X          * default is to handle ellipse properly
X          */
X         if (ellipse)
X         {
X            (void)InsertSubstring(buf, ELIPSE, LDOTS, strlen(buf)+SLUSH);
X         }
X
X         /*
X          * lines without quotes, including newlines,
X          * leading or otherwise
X          */
X         if (Nquotes == 0)
X         {
X	    if (noquotes_and_centered) 
X	    {
X	       noquotes_and_centered = 0;
X	       continue;
X	    }
X	    else
X	    {
X	       ProcessText (fp_out, buf, buf, to_paragraph);
X               continue;
X	    }
X         }
X
X         /*
X          * last was a '' quote; eop.  or next _must_ be
X          * `` quotes.
X          */
X         if (even(Nquotes) && !(IsNewParagraph(buf)))
X         {
X            out_buf = scan_buf_1(buf);
X	    ProcessText (fp_out, buf, out_buf, to_paragraph );
X            continue;
X         }
X         if (even(Nquotes) && (IsNewParagraph(buf)) ) 
X         {
X            out_buf = scan_buf_0(buf);
X            MSG(TRACE,1,("EVEN && NewParagraph:  out_buf = [%s]\n", out_buf));
X	    ProcessText (fp_out, buf, out_buf, to_paragraph);
X            continue;
X         }
X         if (odd(Nquotes) && IsNewParagraph(buf) )
X         {
X            out_buf = scan_buf_0(buf);
X            MSG(TRACE,1,("ODD && NewParagraph:  out_buf = [%s]\n", out_buf));
X	    ProcessText (fp_out, buf, out_buf, to_paragraph);
X            continue;
X         }
X         if (odd(Nquotes) && !(IsNewParagraph(buf)) )
X         {
X            out_buf = scan_buf_1(buf);
X            MSG(TRACE,1,("ODD && NotNewParagraph:  out_buf = [%s]\n", out_buf));
X	    ProcessText (fp_out, buf, out_buf, to_paragraph );
X            continue;
X         }
X
X      }
X
X      /*
X       * tailing tags or comment line for either markup language 
X       */
X      puttailing (html, latex, fp_out);
X
X
X      (void)fclose (fp_out);
X      (void)fclose (fp_in);
X      ++argv, argc--;
X   }
X   return (NO_ERRS);
X}
X
X
X/*
X * Check for beginning ``Quote, with a letter, digit, or ellipse following
X * on that line.''   If ss, we've got an exception, and include a LQUOTE
X * rather than a closing RQUOTE
X */
Xstatic int
XCheckForLeftException (char *s)
X{
X   extern int Nquotes;
X   int exception = 0;
X
X   if (Nquotes == 1)
X   {
X      if (BeginningQuote(s))
X      {
X         exception = 1;
X      }
X   }
X   return exception;
X}
X
X/*
X * step past n bytes; probably should be a macro...
X */
Xchar *
XStepPast(char *s, unsigned int n)
X{
X   register unsigned int i;
X   for (i = 0; i < n; i++) s++;
X   return (s);
X}
X
X
X
Xstatic char *
XProcessItalicizedSymbols(char *s)
X{
X   register unsigned short int byte_count, count =  0, i = 0;
X   char *chopped, *left(), *lhs, ibuf[1024], *rhs, *sp = s;
X   static char rbuf[1024]; 
X
X   MSG(TRACE, 4, ("Entering ProcessItalicizedSymbols: s = [%s]\n", s) );
X   while (*s)
X   {
X      if (*s == I_DELIM)
X         count++;
X      s++;
X   }
X   if (count >= 2)
X   {
X      byte_count = length_to_symbol(sp, I_DELIM);
X      rhs = chopped = StepPast(sp, byte_count+1);
X      while (*chopped)
X      {
X         if (*chopped != I_DELIM)
X            ibuf[i++] = *chopped++;
X            else
X            break;
X      }
X      ibuf[i] =  '\0';
X      /*
X             * here, get both the left-hand side (up _to_ the first '*')
X             * and the right-hand side (after the second '*');  and paste
X             * the new string together in rbuf[]
X             */
X      while (*rhs != I_DELIM)
X         rhs++;
X      rhs++;
X      lhs = left(sp, byte_count);
X      if (latex)
X      {
X         (void)sprintf(rbuf, "%s{%cem %s%c%c}%s", 
X             lhs, BSLASH, ibuf, BSLASH, SLASH, rhs );
X      }
X      else if (html)
X      {
X         (void)sprintf(rbuf, "%s<EM>%s</EM>%s", lhs, ibuf, rhs );
X
X      }
X
X   MSG(TRACE, 4, ("ProcessItalicizedSymbols() returning rbuf = [%s]\n", rbuf));
X
X      return (rbuf);
X   }
X   return (sp);
X}
X/*
Xstatic int
Xget_nquotes(char *s)
X{
X   return(get_nsymbols(s, DQUOTE));
X}
X*/
X
Xstatic int
Xget_nsymbols(char *s, char symbol)
X{
X   register int count =  0;
X   while (*s)
X      {
X         if (*s == symbol)
X            count++;
X         s++;
X      }
X   return (count);
X}
X
Xstatic int
Xget_number_isyms(char *s)
X{
X   return(get_nsymbols(s, I_DELIM));
X}
X
Xstatic int
XBeginningQuote (char *s)
X{
X   /* alnum, ellipse, apostrophe, interior [single] quotes, or ital delimitor */
X   /* or "{" which indicate a leading {\ldots} markup */
X   /* or a leading italicized word */
X
X   if (isalnum(s[1]) || s[1] == '\'' || s[1] == '`' || s[1] == I_DELIM ||
X       (s[1]== '.' && s[2] == '.' && s[3]== '.') || s[1] == '{'  )
X   {
X      return (1);
X   }
X   return(0);
X}
X
X
Xstatic int
XIsNewParagraph( char *buf)
X{
X   unsigned int byte_count, retval = 0;
X   char  *chopped_to_quote;
X   MSG(TRACE,1, ("entering IsNewParagraph: qcnt = (%d), buf = [%s]\n",  
X       qcnt, buf));
X
X   byte_count = length_to_symbol(buf, DQUOTE);
X   chopped_to_quote = StepPast(buf, byte_count);
X   if (BeginningQuote (chopped_to_quote) )
X   {
X      retval = 1;
X   }
X   else
X      retval = 0;
X   MSG(TRACE,1, ("ISNEW: returning (%d)\n", retval));
X   return (retval);
X
X}
X
X
Xstatic char *
Xleft(register char *source, register unsigned int count)
X{
X   static char st[1024]; /* Increase this as required */
X
X   (void)strncpy(st, source, count);
X   st[count] = 0; /* Shorten it. */
X   return (st);  /* And return it. */
X}
X
Xstatic int
Xlength_to_symbol(register char *s, char symbol)
X{
X   register int len = 0;
X   while (*s)
X   {
X      if (*s != symbol) s++, len++;
X      else break;
X   }
X   return (len);
X}
X
Xstatic char *
Xputleftquote(char *save, char *buf, unsigned int count)
X{
X   static char rbuf[1024]; 
X
X
X   (void)sprintf(rbuf, "%s%s%s", save, L_DQ, StepPast(buf, count+1) );
X   return (rbuf);
X}
X
Xstatic char *
Xputrightquote(char *save, char *buf, unsigned int count)
X{
X   static char rbuf[1024];
X   MSG(TRACE,2, ("putrightquote: save = [%s], buf = [%s], StepPast = [%s]\n",
X       save, buf, StepPast(buf, count)));
X
X   if (CheckForLeftException (StepPast(buf, count)) )
X   {
X      (void)sprintf(rbuf, "%s%s%s", save, L_DQ, StepPast(buf, count+1));
X      return (rbuf);
X   }
X   else
X   {
X      (void)sprintf(rbuf, "%s%s%s", save, R_DQ, StepPast(buf, count+1));
X      return (rbuf);
X   }
X}
X
X
X/* 
X * report italics-symbol errors
X */
Xstatic void
Xreport_isym_err(short int nsymbols, char *buf)
X{
X   (void)fprintf(stderr, "ERR seen on line:\n%s", buf);
X   (void)fprintf(stderr, "Odd number, %d, of italics delimitors, '%c'\n", 
X       nsymbols, I_DELIM);
X}
Xstatic char *
Xscan_buf_0 (char *buf)
X{
X   char *left(), save[1024], *savebuf;
X   register unsigned int byte_count; /***,  i = 0; */
X   static char *r_rbuf;  /* recursive return buffer */
X   char *putleftquote(), *scan_buf_1();
X   static char dead_save[1024];
X
X   MSG(TRACE,1,("entering scan_buf_0:  qcnt = (%d), buf = [%s]\n", qcnt, buf));
X
X   clear(save);
X   byte_count = length_to_symbol(buf, DQUOTE);
X   savebuf = left(buf, byte_count);
X   (void)strcpy(save, savebuf);
X   r_rbuf = putleftquote(save,buf, byte_count);
X   (void)strcpy(dead_save, r_rbuf);
X   qcnt = GetNumberOfQuotes(r_rbuf);
X   MSG(TRACE,2,("r_rbuf = [%s], qcnt = (%d)\n", r_rbuf,qcnt));
X
X   if ( qcnt == 0)
X   {
X      okay = 1;
X      return (dead_save);
X   }
X   else
X   {
X      MSG(TRACE,3,("calling scan_buf_1 with [%s], [%s]\n", r_rbuf, dead_save));
X
X      r_rbuf = scan_buf_1(dead_save);
X      if (okay == 1)
X      {
X         MSG(TRACE, 3, ("scan_buf_0::  returning [%s]\n", r_rbuf));
X         return (r_rbuf);
X      }
X   }
X
X}
Xstatic char *
Xscan_buf_1 (char *buf)
X{
X   char *left(), save[1024], *savebuf;
X   register unsigned int byte_count; /***,  i = 0;  */
X   static char *r_rbuf;  /* recursive return buffer */
X   char *putrightquote(), *scan_buf_0();
X   static char dead_save[1024];
X
X   MSG(TRACE,2,("entering scan_buf_1: qcnt = (%d),  buf = [%s]\n", qcnt, buf));
X
X   clear (save);
X   byte_count = length_to_symbol(buf, DQUOTE);
X   savebuf = left(buf, byte_count);
X   (void)strcpy(save, savebuf);
X   r_rbuf = putrightquote(save,buf, byte_count);
X   (void)strcpy(dead_save, r_rbuf);
X   qcnt = GetNumberOfQuotes(r_rbuf);
X   MSG(TRACE,3, ("Rr_rbuf = [%s], qcnt = (%d)\n", r_rbuf, qcnt));
X
X   if (qcnt == 0)
X   {
X      MSG(TRACE,3,("scan_buf_1: qcnt = 0, returning to main = [%s]\n", 
X          dead_save));
X      okay = 1;
X      return (dead_save);
X   }
X   else
X   {
X      MSG(TRACE,3,("calling scan_buf_0 with [%s], [%s]\n",r_rbuf,dead_save));
X      r_rbuf =  scan_buf_0(dead_save);
X      if (okay == 1)
X      {
X         MSG(TRACE,3,("scan_buf_1: qcnt = (%d), returning to main = [%s]\n", 
X             qcnt, r_rbuf));
X         return (r_rbuf);
X      }
X   }
X
X}
X
X#include <stddef.h>
X#include <stdlib.h>
Xstatic char *
Xstrsave(const char *str)
X{
X   register unsigned short int len;
X   register char *copy;
X
X   len = strlen(str) + 1;
X   if (!(copy = malloc((int)len)))
X      return((char *)NULL);
X   bcopy(str, copy, len);
X   return(copy);
X}
X
Xstatic void
Xusage(char *prog)
X{
X   (void)fprintf(stderr, "\tUsage %s: -ht [-eips] file...\n", prog);
X}
X
X
X
X/*
X * major processing of each line done here
X */
Xstatic void
XProcessText(FILE *fp_out, char *buf, char *out_buf, int to_paragraph)
X{
X   register short j,  number_italics_symbols = 0;
X   char *nbuf, *ProcessItalicizedSymbols();
X   char *strsave();
X
X   MSG(TRACE, 4, ("buf = [%s]\nout_buf = [%s]\n", buf, out_buf) );
X
X
X	    /*
X	     * handle italicization with or without paragraphing.
X	     */
X            number_italics_symbols = get_number_isyms(buf);
X            if (odd(number_italics_symbols))
X            {
X               report_isym_err(number_italics_symbols, buf);
X            }
X            else if (number_italics_symbols == 2) /* most often */
X            {
X               nbuf = ProcessItalicizedSymbols(out_buf); /* had been (buf) */
X               if (to_paragraph == 1)
X               {
X                  to_paragraph = 0;
X                  if (html)
X                  {
X		     /* Paragraph TAG for hypertex markup */
X                     (void)fprintf(fp_out, "<P>\n");
X                  }
X                  else if (latex)
X                  {
X		     /* In LaTeX paragraphs are denoted by newline breaks */
X                     (void)fprintf(fp_out, "\n");
X                  }
X               }
X               (void)fprintf(fp_out, "%s", nbuf);
X            }
X            else if (number_italics_symbols > 2)
X            {
X               nbuf = (char *)strsave(out_buf);
X               for (j = 0; j < (number_italics_symbols/2); j++)
X               {
X                  nbuf = ProcessItalicizedSymbols(nbuf);
X                  nbuf = (char *)strsave(nbuf);
X               }
X               if (to_paragraph == 1)
X               {
X                  to_paragraph = 0;
X                  if (html)
X                  {
X                     (void)fprintf(fp_out, "<P>\n");
X                  }
X                  else if (latex)
X                  {
X		     /* In LaTeX paragraphs are denoted by newline breaks */
X                     (void)fprintf(fp_out, "\n");
X                  }
X               }
X               (void)fprintf(fp_out, "%s", nbuf);
X
X            }
X            if (number_italics_symbols == 0)
X            {
X               if (to_paragraph == 1)
X               {
X                  to_paragraph = 0;
X                  if (html)
X                  {
X                     (void)fprintf(fp_out, "<P>\n");
X                  }
X                  else if (latex)
X                  {
X		     /* In LaTeX paragraphs are denoted by newline breaks */
X                     (void)fprintf(fp_out, "\n");
X                  }
X               }
X               (void)fprintf(fp_out, "%s", out_buf);
X            }
X	    free (nbuf); /* Memory leak sans this: 17sep96 */
X
X}
X/*
X * If we have a line with leading spaces followed by a tab, we've got a
X * paragraph
X */
Xstatic int
XIsEmbeddedTab(char *s)
X{
X	register unsigned int paragraph = 0;
X
X	while (*s)
X	{
X		if (*s == ' ')
X		{
X			s++;
X		}
X		if (*s == '\t')
X		{
X			paragraph = 1;
X			break;
X		}
X		s++;
X	}
X	return (paragraph);
X}
X
Xstatic int
XLeadingSpaces(char *s, int number_specified)
X{
X	extern short int  spaceindented_paragraph;
X	register unsigned int space_count = 0, paragraph = 0;
X	while (*s)
X	{
X		if (isalnum(*s) )
X			break;
X		if (number_specified == 0) /* none, or not specified */
X		{
X			if (*s == ' ')
X				space_count++;
X			/*
X			 * choose explicity a 5- or 8-space 
X			 * indented line as a
X			 * paragraph.  Any other number of 
X			 * leading-space indentations
X			 * do not indicate a paragraph.
X			 */
X			switch (space_count)
X			{
X				case 1:
X				case 2:
X				case 3:
X				case 4:
X					paragraph = 0;
X					break;
X				case 5:
X					paragraph = 1;
X					spaceindented_paragraph = 1;
X					break;
X				case 6:
X				case 7:
X					paragraph = 0;
X					break;
X				case 8:
X					paragraph = 1;
X					spaceindented_paragraph = 1;
X					break;
X				default:
X					paragraph = 0;
X					break;
X			}
X		}
X		else
X		{
X			if (*s == ' ')
X				space_count++;
X			if (space_count == number_specified)
X				paragraph = 1;
X		}
X		s++;
X	}
X	return (paragraph);
X}
X
Xputheader (int html, int latex, char *fname, FILE *fp)
X{
X      if (html)
X      {
X            /* header HTML tag  */
X            (void)fprintf(fp, HHEADER );
X            (void)fprintf(fp, HBEGIN );
X      }
X      else if (latex)
X      {
X            /* concluding comments for TeX-style docs  */
X            (void)fputs(THEADER, fp );
X            (void)fprintf(fp, " <<%s>> ", fname ); 
X	    (void)fputs(TCOMMENT, fp ); (void)fputs("\n", fp );
X            (void)fputs(TCOMMENT  , fp ); (void)fprintf(fp, TATTRIBUTE );
X      }
X
X}
Xputtailing (int html, int latex, FILE *fp)
X{
X      if (html)
X      {
X            /* general HTML header lines and tags  */
X            (void)fprintf(fp, HEND );
X            (void)fprintf(fp, HTAIL );
X      }
X      else if (latex)
X      {
X            /* header comments for TeX-style docs  */
X            (void)fputs(TTAIL, fp );
X      }
X}
X
X#ifdef WWW
Xlookahead (FILE *fp)
X{
X        char  lookaheadc;               /* lookahead character  */
X	short int rval = 0;
X
X	if (lookaheadc = getc (fp))
X        {
X                if (lookaheadc != '\n') 
X                {
X                        rval = 1;
X                }
X                else
X                {
X                        rval = 0;
X                }
X        }
X	ungetc(lookaheadc, fp);
X	return rval;
X}
Xput_break(int html, int latex, FILE *fp)
X{
X
X	if (html)
X	{
X		fprintf(fp, HSPACE);
X	}
X	else if (latex)
X	{
X		fprintf(fp, TSPACE);
X	}
X}
X#endif
END-of-atom.c
echo x - center.c
sed 's/^X//' >center.c << 'END-of-center.c'
X
X/* 
X * center,c
X * $Header: /usr/home/kline/devel/atom/RCS/center.c,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X */
X
X#include <stdio.h>
X#include "msg.h"
X#include "atom.h"
X
Xint err_tab = 0;
X
Xvoid
XDoCenterOutput(char *buf, FILE *fp, int html, int latex)
X{
X	/*
X	 * the formatting below ends in "\n\n" in the event that
X	 * paragraphing isn't otherwise denoted:: better safe than not.
X	 */
X	if (html)
X	{
X		fprintf(fp, "<ALIGN=CENTER>\n%s\n</ALIGN>\n\n", buf);
X	}
X	else if (latex)
X	{
X		fprintf(fp, "\\begin{center}\n%s\n\\end{center}\n\n", buf);
X	}
X}
X
X/*
X * if a string is ASCII-centered, there are nothing but blank
X * spaces to the left of the string.  This function returns the
X * number of spaces.
X */
Xunsigned int
XNumberOfLeadingSpaces(char *s)
X{
X	unsigned int scount = 0;
X	while (*s)
X	{
X		if (*s == ' ')
X		{
X			scount++;
X		}
X		if (!(*s == ' '))
X			break;
X		s++;
X	}
X	return (scount);
X}
X
X
X/*
X * Return the length of the string in the middle.
X */
X
Xunsigned int
XCenterStringLength(char *s)
X{
X	unsigned int cscount = 0;
X	while (*s)
X	{
X		if (isprint(*s) )
X		{
X			cscount++;
X		}
X		if (*s == '\t')
X		{
X			err_tab = 1;
X			break;
X		}
X		if (*s == '\n')
X		{
X			break;
X		}
X		s++;
X	}
X	return cscount;
X}
X
X
X/* 
X * formula for determining whether centerstring is really centered.
X *
X *  (note that we can be off-by-one byte: the centerstring may have an
X *   odd number of characters)
X *
X * if (80/2) - (centerlength/2) == nleadingspaces ||
X * if (80/2) - (centerlength/2)-1 == nleadingspaces.
X *
X * [[[ do we want to allow other-side offcentering? ]]]
X *
X * boolean::
X * if either of the above is true, then string marked CENTERED.
X */
X
Xint
XDetermineCenteredness(unsigned int lspaces, int length)
X{
X   MSG(TRACE, 3, ("determing eq = (%d), spaces = (%d)\n", 
X	( (80/2) - ((length)/2)-1), lspaces ));
X   MSG(TRACE, 3, ("determing eq = (%d), spaces = (%d)\n", 
X	( (80/2) - ((length)/2)), lspaces ));
X
X	if ( ( (80/2) - ((length)/2)) == lspaces  ||
X	   ( (80/2) - ((length)/2)-1) == lspaces )
X	{
X	   return 1;
X	}
X	else
X	   return 0;
X}
END-of-center.c
echo x - msg.c
sed 's/^X//' >msg.c << 'END-of-msg.c'
X/*
X * $Header: /usr/home/kline/devel/atom/RCS/msg.c,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X * msg.c - routines to handle debug and error messages
X */
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <stddef.h>
X#include <stdarg.h>
X#include <string.h>
X#include <time.h>
X#include "msg.h"
X/* 
X * Default levels for masking out messages.
X */
XMSG_CONST msg_severity_t msg_level[MSG_CATEGORIES] = {
X    5, 5, 0, 0, 0,
X};
X
X/* The string prepended to each message. You may use date directives
X * like %T for time (see strftime(3)). Extension: You can use %s for
X * the severity level.
X */
Xstatic const char *msg_preface[MSG_CATEGORIES] = {
X    "Trace\t",
X    "Debug\t",
X    "Warning [%Y-%m-%d %H:%M.%S] level %s\n\t",
X    "Error [%Y-%m-%d %H:%M.%S] level %s\n\t",
X    "Fatal [%Y-%m-%d %H:%M.%S] level %s\n\t",
X};
X
X#if defined(MSG_COUNT_CALLS)
X/* How many messages to accept in a given class before calling
X * MSG_EXIT.
X * 0 means never exit.
X */
Xint msg_warnings[MSG_CATEGORIES] = {
X    0, 0, 0, 0, 0,
X};
X#endif
X
Xmsg_category_t msg_category;	/* global used for communication from macro */
Xmsg_severity_t msg_severity;	/* global used for communication from macro */
Xstatic FILE *msg_file;
Xstatic int msg_parse_preface[MSG_CATEGORIES];	/* really Boolean */
Xstatic int msg_init_done = 0;
X
X/* Prototypes
X */
Xstatic void parse_envir(void);
Xstatic char *parse_preface(const char *);
Xstatic void msg_fatal(char *);
X
X
Xvoid
Xmsg_init()
X{
X    const char *env;
X    register short int i;
X
X    msg_init_done = 1;
X    env = getenv("MSG_FILE");
X    if (env && *env) {
X        msg_file = fopen(env, "a");
X        if (msg_file == NULL) {
X            perror(env);
X            msg_file = stderr;
X        }
X	setbuf(msg_file, NULL);
X    } else
X        msg_file = stderr;
X
X    for (i = MSG_CATEGORIES; i--;)
X	msg_parse_preface[i] = strchr(msg_preface[i], '%') ? 1 : 0;
X
X    parse_envir();
X}
X
X
Xstatic void
Xparse_envir()
X{
X#if defined(MSG_PARSE_ENVIR)
X    register short int         i = 0;
X    const char *env;
X
X    env = getenv("MSG_LEVEL");
X    /* Parse the environment variable:
X     *     "5,,-,"
X     * becomes
X     *     [ 5, OLD VALUE, MSG_MAX_SEVERITY + 1, OLD VALUE, OLD VALUE ]
X     */
X    if (env && *env) {
X        enum { fresh, number, junk } state = fresh;
X        register short int                          value = 0;
X
X        do {
X            if (*env == ',') {
X		if (state == number || state == junk)
X                    msg_level[i] = value;
X                value = 0;
X                state = fresh;
X                if (++i >= MSG_CATEGORIES)
X                    break;
X            } else if (state != junk && isdigit(*env)) {
X                value *= 10;
X                value += *env - '0';
X                if (value > MSG_MAX_SEVERITY + 1) {
X                    value = MSG_MAX_SEVERITY + 1;
X                    state = junk;
X                } else
X                    state = number;
X	    } else if (*env == '-') {
X		value = MSG_MAX_SEVERITY + 1;
X		state = junk;
X	    } else if (*env == '+') {
X		value = 0;
X		state = junk;
X            } else if (state == number) /* non-digit, change state */
X                state = junk; /* so "4k5, 7" becomes "4,7", not "45,7" */
X        } while (*++env);
X
X        if (state == number || state == junk)
X            msg_level[i] = value;
X    }
X#endif
X}
X
X
Xvoid
Xmsg_printf(const char *fmt, ...)
X{
X    char    buff[1024];
X    va_list args;
X    register short int     prelen, msglen;
X
X    if (!msg_init_done)
X	msg_init();
X
X    if (msg_parse_preface[msg_category]) {
X        struct tm *tm;
X	time_t     clock;
X	char      *fmt;
X
X        fmt = parse_preface(msg_preface[msg_category]);
X        time(&clock);
X        tm = localtime(&clock);
X        prelen = strftime(buff, sizeof(buff), fmt, tm);
X        if (prelen == 0)		/* Error condition from strftime */
X            msg_fatal("Buffer too small");
X        free(fmt);
X    } else {
X        strncpy(buff, msg_preface[msg_category], sizeof(buff));
X	prelen = strlen(msg_preface[msg_category]);
X    }
X
X    va_start(args, fmt);
X#if defined(_POSIX_SOURCE)
X    msglen = vsprintf(buff + prelen, fmt, args);
X
X    if (prelen + msglen > sizeof(buff))
X        msg_fatal("Buffer too small");
X#else
X    /* BSD vsprintf() returns the first argument - can't be used
X     * for detecting buffer over-runs.
X     */
X    (void) vsprintf(buff + prelen, fmt, args);
X#endif
X
X    va_end(args);
X    fprintf(msg_file, "%s\n", buff);
X}
X
X
Xstatic char *
Xparse_preface(const char *template) {
X    char                    *fmt;
X    size_t                   fmt_size;
X    ptrdiff_t                p = 0;
X    enum { normal, percent } state = normal;
X
X    fmt_size = strlen(template) + 1;
X    fmt = (char *) malloc(fmt_size);
X    if (fmt == NULL)
X        msg_fatal("Out of memory");
X
X    for (; *template; template++) {
X        if (p > fmt_size) {
X            fmt_size += 16;
X            fmt = realloc(fmt, fmt_size);
X            if (fmt == NULL)
X                msg_fatal("Out of memory");
X        }
X        fmt[p++] = *template;
X        if (state == percent) {
X            if (*template == 's')
X#if defined(_POSIX_SOURCE)
X                p += sprintf(fmt + p - 2, "%d", msg_severity) - 2;
X#else
X                p = strchr(sprintf(fmt + p - 2, "%d", msg_severity), 0) - fmt;
X#endif
X            state = normal;
X        } else if (*template == '%')
X            state = percent;
X    }
X    fmt[p] = 0;
X    return fmt;
X}
X
Xstatic void
Xmsg_fatal(char *msg)
X{
X    fprintf(msg_file, "Fatal error: %s\n", msg);
X    fclose(msg_file);
X    exit(1);
X}
END-of-msg.c
echo x - spacing.c
sed 's/^X//' >spacing.c << 'END-of-spacing.c'
X
X/* 
X * spacings.c
X * $Header: /usr/home/kline/devel/atom/RCS/spacing.c,v 1.4 1996/09/05 04:04:16 kline Exp kline $
X */
X
X#include <stdio.h>
X#include "msg.h"
X#include "atom.h"
X
Xvoid
XDo_Physical_space(char *buf, int html, int latex, FILE *fp)
X{
X
X	static int psbreak_count = 0;
X
X	if (*buf == '\n' && psbreak_count < 5)
X	{ 
X	/*printf("PSPACE: DEBUG: psbreak_count = (%d)\n", psbreak_count);*/
X		psbreak_count++;
X	}  
X	else if (*buf != '\n')
X	{
X		psbreak_count = 0;
X	}
X	if (psbreak_count == 5)
X	{
X		if (lookahead (fp))
X		{
X			puts("printing Do_Break");
X			if (html)
X			{
X				fprintf(fp, HSPACE);
X			}
X			else if (latex)
X			{
X				fprintf(fp, TSPACE);
X			}
X			psbreak_count = 0;
X		}
X
X
X	}
X}
Xint
Xlookahead (FILE *fp)
X{
X        char  lookaheadc;               /* lookahead character  */
X        short int rval = 0;
X
X        if (lookaheadc = getc (fp))
X        {
X                if (lookaheadc != '\n') 
X                {
X                        rval = 1;
X                }
X                else
X                {
X                        rval = 0;
X                }
X        }
X        ungetc(lookaheadc, fp);
X        return rval;
X}
Xvoid
Xput_break(int html, int latex, FILE *fp)
X{
X        if (html)
X        {   
X                fprintf(fp, HSPACE);
X        }       
X        else if (latex) 
X        {       
X                fprintf(fp, TSPACE); 
X        }   
X}
END-of-spacing.c
echo x - utils.c
sed 's/^X//' >utils.c << 'END-of-utils.c'
X
X/*
X * $Header: /usr/home/kline/devel/atom/RCS/utils.c,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X * misc atom utilities.
X */
X
X#include <stdlib.h>
X#include <stdio.h>
X#include "msg.h"
X#include "atom.h"
X
X#ifdef NOTUSED
Xchar tempfname[512];*//* ``TEMP<pid>'' /* file when squeezing excess newlines */
X#endif
X
X/*
X * memory and misc utility functions
X */
X
X
X/***
X ***
X		for bcopy() and memmove()
X ***
X ***/
X
X
X/*-
X * Copyright (c) 1990 The Regents of the University of California.
X * All rights reserved.
X *
X * This code is derived from software contributed to Berkeley by
X * Chris Torek.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *      This product includes software developed by the University of
X *      California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X
Xvoid
Xbcopy(const void *src0, register void *dst0, register size_t length)
X{
X   register char *dst = dst0;
X   register const char *src = src0;
X   register size_t t;
X
X   if (length == 0 || dst == src)      /* nothing to do */
X      goto done;
X
X   /*
X       * Macros: loop-t-times; and loop-t-times, t>0
X       */
X#define   TLOOP(s) if (t) TLOOP1(s)
X#define   TLOOP1(s) do { s; } while (--t)
X
X   if ((unsigned long)dst < (unsigned long)src) {
X      /*
X       * Copy forward.
X       */
X      t = (int)src;   /* only need low bits */
X      if ((t | (int)dst) & wmask) {
X         /*
X          * Try to align operands.  This cannot be done
X          * unless the low bits match.
X          */
X         if ((t ^ (int)dst) & wmask || length < wsize)
X            t = length;
X            else
X            t = wsize - (t & wmask);
X         length -= t;
X         TLOOP1(*dst++ = *src++);
X      }
X      /*
X       * Copy whole words, then mop up any trailing bytes.
X       */
X      t = length / wsize;
X      TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
X      t = length & wmask;
X      TLOOP(*dst++ = *src++);
X   } else {
X            /*
X             * Copy backwards.  Otherwise essentially the same.
X             * Alignment works as before, except that it takes
X             * (t&wmask) bytes to align, not wsize-(t&wmask).
X             */
X      src += length;
X      dst += length;
X      t = (int)src;
X      if ((t | (int)dst) & wmask) {
X         if ((t ^ (int)dst) & wmask || length <= wsize)
X            t = length;
X            else
X            t &= wmask;
X         length -= t;
X         TLOOP1(*--dst = *--src);
X      }
X      t = length / wsize;
X      TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
X      t = length & wmask;
X      TLOOP(*--dst = *--src);
X   }
Xdone:
X   return;
X}
X
X void *
Xmemmove(register void *dst0, const void *src0, register size_t length)
X{
X   register char *dst = dst0;
X   register const char *src = src0;
X   register size_t t;
X
X   if (length == 0 || dst == src)      /* nothing to do */
X      goto done;
X
X   /*
X       * Macros: loop-t-times; and loop-t-times, t>0
X       */
X#define   TLOOP(s) if (t) TLOOP1(s)
X#define   TLOOP1(s) do { s; } while (--t)
X
X   if ((unsigned long)dst < (unsigned long)src) {
X      /*
X             * Copy forward.
X             */
X      t = (int)src;   /* only need low bits */
X      if ((t | (int)dst) & wmask) {
X         /*
X                   * Try to align operands.  This cannot be done
X                   * unless the low bits match.
X                   */
X         if ((t ^ (int)dst) & wmask || length < wsize)
X            t = length;
X            else
X            t = wsize - (t & wmask);
X         length -= t;
X         TLOOP1(*dst++ = *src++);
X      }
X      /*
X             * Copy whole words, then mop up any trailing bytes.
X             */
X      t = length / wsize;
X      TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
X      t = length & wmask;
X      TLOOP(*dst++ = *src++);
X   } else {
X      /*
X             * Copy backwards.  Otherwise essentially the same.
X             * Alignment works as before, except that it takes
X             * (t&wmask) bytes to align, not wsize-(t&wmask).
X             */
X      src += length;
X      dst += length;
X      t = (int)src;
X      if ((t | (int)dst) & wmask) {
X         if ((t ^ (int)dst) & wmask || length <= wsize)
X            t = length;
X            else
X            t &= wmask;
X         length -= t;
X         TLOOP1(*--dst = *--src);
X      }
X      t = length / wsize;
X      TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
X      t = length & wmask;
X      TLOOP(*--dst = *--src);
X   }
Xdone:
X   return (dst0);
X}
X
X
X/*
X * strsub.c -- substitute first occurence of pattern with another string
X *
X *   Author: Lars Wirzenius, licensed by GPL
X */
X
Xchar *
Xstrsub(register char *str, const char *pat, const char *sub)
X{
X   size_t lenpat, lensub, lenstr;
X   char *strstr();
X
X   str = strstr(str, pat);
X   if (str == NULL)
X      return NULL;
X
X   lenstr = strlen(str);
X   lenpat = strlen(pat);
X   lensub = strlen(sub);
X
X   /* make room for substituted string, or remove slack after it */
X   if (lensub != lenpat)
X      (void)memmove(str + lensub, str + lenpat, lenstr + 1 - lenpat);
X
X   (void)memcpy(str, sub, lensub);
X   return str + lensub;
X}
X
X/*
X * InsertSubstring (subgstr())
X *  -- insert all occurences of pattern with another string
X *
X *   Author: Lars Wirzenius, licensed by GPL
X */
X
X
Xint
XInsertSubstring(register char *str, const char *pat, const char *sub,size_t max)
X{
X   size_t lenpat, lensub;
X   const char *p;
X   register short unsigned int n;
X   char *strstr();
X
X   /*
X    * Check that the all substitutions will fit.
X    */
X   lenpat = strlen(pat);
X   lensub = strlen(sub);
X   if (lenpat < lensub) {
X      for (n = 0, p = str; (p = strstr(p, pat)) != NULL; p += lenpat)
X         ++n;
X      if (strlen(str)+1 + n*(lensub-lenpat) > max)
X         return -1;
X   }
X
X   /*
X            * Substitute.
X            */
X   for (n = 0; (str = strsub(str, pat, sub)) != NULL; ++n)
X      continue;
X   return (int)n;
X}
X
X
X/*
X * leave
X * Clean up atom and exit.
X */
Xvoid    
Xleave (register int exit_val) 
X{
X#ifdef NO_MORE
X        extern  char    tempfname[];
X        unlink (tempfname);
X#endif /* NO_MORE */
X
X        exit (exit_val);
X}
X
END-of-utils.c
echo x - version.c
sed 's/^X//' >version.c << 'END-of-version.c'
X
X/* The version number of atom.
X * $Header: /usr/home/kline/devel/atom/RCS/version.c,v 1.1 1996/09/04 04:56:19 kline Exp kline $
X */
Xchar *version_string = "version 2.6\n";
END-of-version.c
echo x - TODO
sed 's/^X//' >TODO << 'END-of-TODO'
X/*
X * things to do
X$Header: /usr/home/kline/devel/atom/RCS/TODO,v 1.1 1996/09/04 04:59:34 kline Exp kline $
X */
X{  
XScotch extra newlines if any from the processed file. ## Done 8/1995
XAdd -<num> for number of spaces to indicate indentation. ## Done 5/1996
XAdd very basic header tags for html, comments for tex.  ## Done 8/1996
XAdd physical-break feature where 5 newlines indicates that a
X  several <BR> or \vspace*{.5in} be added to the markup file.
X}
X
X
Xscotch extra newlines if any from the processed file.
Xbreak out the qfilter routines explicitely.  Can do??
Xupdate atom.1 abt space=8 .eq. one tab for paragraphing.
Xcentering for  TeX/HTML for ASCII files space-centered initially.
END-of-TODO
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X#
X# $Header: /usr/home/kline/devel/atom/RCS/Makefile,v 1.2 1996/09/05 03:47:34 kline Exp kline $
X#
XCFLAGS        = -O -D_POSIX_SOURCE
XCI=/usr/local/bin/ci
XCO=/usr/local/bin/co -l
XCOPYING       = COPYING
XBINDIR        =  /usr/local/bin
XBINDIR        =  /usr/home/kline/bin
XDEST         = ${BINDIR}
XEXTHDRS      = /usr/include/ctype.h \
X               /usr/include/stdio.h
X#
X#  choose your own version of or path to an `install' script; or use `/bin/cp'
X#
XINSTALL      = install
XHDRS         = macros.h msg.h atom.h
XLIBS         =
XCC           = gcc
XMAKEFILE     = Makefile
XMANDIR        =  /usr/local/man/man1
XMANPAGE      =  atom.1
XRM=/bin/rm -f
X
XOBJS         = atom.o center.o msg.o spacing.o utils.o version.o
X#
X# 
X#
XPRINT        = lpr
XPROGRAM      = atom
XREADME       = README
XSHARFORWARD = shar.forward
XSRCS         = atom.c center.c msg.c spacing.c utils.c version.c
XTAR          = gtar
XTESTFILE     = test
XTOUTPUT	     = test.html test.tex
XTODO         = TODO
XUUDECODE     =uudecode
XUUENCODE     =uuencode
XUNZIP=gzip -d
XZIP=gzip -9
X
Xall:           $(PROGRAM)
X$(PROGRAM):	$(OBJS) $(LIBS)
X	       $(CC) $(OBJS) $(LIBS) -o $(PROGRAM) $(LDLIBS)
X
Xclean:;		$(RM) $(OBJS) ./core ./a.out  $(PROGRAM) $(TOUTPUT)
Xdepend:;	mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
Xindex:;                ctags -wx $(HDRS) $(SRCS)
Xinstall:       $(PROGRAM)
X		$(INSTALL) -s $(PROGRAM) $(DEST)
X		$(INSTALL) $(MANPAGE) $(MANDIR)
X
Xprint:;		$(PRINT) $(HDRS) $(SRCS)
Xprogram:	$(PROGRAM)
Xinrcs:;		$(CI) $(COPYING) $(HDRS) $(SRCS) $(TODO) \
X			       $(MAKEFILE) $(MANPAGE) $(README) $(TESTFILE)
Xoutrcs:;	$(CO) $(COPYING) $(HDRS) $(SRCS) $(TODO) \
X			       $(MANPAGE) $(README) $(TESTFILE)
Xshar:;		$(RM) atom.shar 
X		shar $(SHARFORWARD) $(README) $(COPYING) $(HDRS) \
X				$(SRCS) $(TODO)  \
X			       $(MAKEFILE) $(MANPAGE) \
X			       $(TESTFILE) > atom.shar
X
Xtags:		$(HDRS) $(SRCS); ctags $(HDRS) $(SRCS)
Xtar:;		$(RM) atom.tar atom.uu
X		$(TAR) -cvf atom.tar $(COPYING) $(HDRS) $(SRCS) $(TODO) \
X			       $(MAKEFILE) $(MANPAGE) $(README) $(TESTFILE)
X
Xuushar:		shar
X		$(ZIP) atom.shar
X		$(UUENCODE) atom.shar.gz atom.shar.gz > atom.uu 
X		$(RM) atom.shar.gz
X
Xuutar:		tar
X		$(ZIP) atom.tar
X		$(UUENCODE) atom.tar.gz atom.tar.gz > atom.uu 
X		$(RM) atom.tar.gz
X
Xuud:;		$(UUDECODE) atom.uu
X		$(UNZIP) atom.tar.gz
X		$(RM) atom.uu
X		echo "You have atom.tar"
X		ls -ls atom.tar
X
X
X
X###
Xatom.o: /usr/include/stdio.h /usr/include/ctype.h ./macros.h ./msg.h ./atom.h
END-of-Makefile
echo x - atom.1
sed 's/^X//' >atom.1 << 'END-of-atom.1'
X.TH atom 1
X.SH NAME
Xatom \- ASCII-to-markup filter
X.SH SYNOPSIS
X.B \fIatom\fP
X.RB  \-\ [<number>eipsht] \ file...
X.br
X.SH DESCRIPTION
X.I atom
Xautomatially translates typewriter quotes into those which are displayed 
Xas properly typeset quotation marks for LaTeX or HTML.
X.PP
XAdditionally, 
Xthis filter also turns italics-delimited words or phrases into italics
Xwhen displayed by LaTeX or HTML.  The default delimiter to indicate that 
Xitalics be displayed is the asterisk.  This is configurable.
XAnd, for LaTeX only, \fIatom\fP correctly sets the markup to 
Xcorrectly display elipses.
X.PP
XThe following options apply:
X.PP
X\-c   Perform simplistic centering processing.
X.PP
X\-e   Do not do elipses processing. (Affects LaTeX only.)
X.PP
X\-<number>   <number> indicates the number of space-indentations that
Xindicates a paragraph.  (This is explained further below.)
X.PP
X\-h   Process HTML output
X.PP
X\-i   Do not handle italics processing.
X.PP
X\-p   Handles physical-spacing by inserting five ``<BR>'' tags in HTML and
Xthe markup ``\\vspace*{.5in}'' for TeX and LaTex.  The option requires
Xthat you have exactly five blank lines in your manuscript.  
X.PP
X\-s   For LaTeX, do eliminate all but one newline between paragraphs; for
XHTML, allow only one <P> tag between paragraphs.  (This is
Xexplained further below.)
X.PP
X\-t   Process TeX/LaTeX output (default)
X.PP
XThe default for \fIatom\fP is to handle italics and elipses under 
XLaTeX, and to do
Xprocesses any italics-delimited word or words into HTML emphasis tags.
X.PP
XParagraphs are most easily recognized by lines of text separated by at
Xleast one newline.  Additionally, a line in which the first character is a
Xtab ('\\010') indicates a paragraph.  Lastly, and these are the least
Xpreferred means of paragraph recognition, lines in which at least
Xthe first character is a space--or the first several character 
Xare spaces--followed by tab indicates a paragraph; or lines which 
Xbegin with 5 or 8 spaces ('\\040') are recognized as paragraphs.  
X.PP
XIf you have used an ``unusual'' number of spaces to indicate paragraphs
Xin your manuscaript--say, two, three, six, or seven spaces, you must
Xindicate this to \fIatom\fP with the \-<number> flag.  If you have
Xparagraphed with seven spaces and want an HTML outfile, you must
Xtype ``atom -7h <yourfile>'' on the command line.  
X.PP
XIf you are about to prepare an ASCII file, best to stick with TABS 
Xor spaces to indicate paragraphs.
X.br
X.SH EXAMPLES
XFor example, the following 
X.nf
X
X        % atom -te speech01
X
X
X.fi
Xwill correctly format speech01 into LaTeX, and produce the output file
X\fIspeech01.tex\fP.  Quotation marks and italicization will be handled
Xin the LaTeX-markup output file; elipses will not be processed.
X.PP
XThe following:
X.nf
X
X        % atom -hi ShortStory
X
X
X.fi
Xwill produce the output \fIShortStory.html\fP in which double quotation
Xmarks will be processed but any italics-delimited words will be left alone.
X.PP
XThe following command
X.nf
X
X        % atom -h2 test
X
X
X.fi
Xwhere exactly <2> or <number> spaces indicate paragraphs within the file
X\fItest\fP, will produce a properly formatted HTML output file.
X.PP
XFor example:
X.nf
X
X
X  This is a case where there is a new
Xparagraph that is indicated by a 2-space indentation.
XThis happens occasionally.
X  And this is yet another instance of the
Xabove. For atom to turn these two paragraphs into HTML or TeX
Xformatted paragraphs, use the command: ``atom -h2 <file>'' or
X``atom -2 <file>.''
X
X
X.fi
X.PP
Xwill produce the following:
X.nf
X
X
X<P>
X  This is a case where there is a new
Xparagraph that is indicated by a 2-space indentation.
XThis happens occasionally.
X<P>
X  And this is yet another instance of the
Xabove. For atom to turn these two paragraphs into HTML or TeX
Xformatted paragraphs, use the command: ``atom -h2 <file>'' or
X``atom -2 <file>.''
X
X
X.fi
X.PP
XNote that without the ``-2'' flag in this case, the HTML or TeX output
Xwould run these two paragraphs together.
X.PP
XFinally,
X.nf
X
X        % atom story01 story02 story12
X
X.fi
Xwill produce \fIstory01.tex, story02.tex, story12.tex\fP with any 
Xquotation marks, italicization, and elipses marked up in LaTex style.
X.PP
X\fIatom\fP will do centering if and only if your original ASCII file
Xhas the strings judiciously centered by using spaces-only to the 
Xleft of the centered string.  If you use this \-c option, any paragraphs
Xthat are denoted by 5 or 8 spaces will not be seen as paragraphs and not
Xprocessed as such.  If you do have space-centered lines that you wish
Xto be centered in HTML or LaTeX  \fIand\fP you also have paragraphs
Xdenoted by 5 or 8 spaces, you will have to edit your ASCII source and 
Xreplace the spaces to tabs.  Then run \fIatom\fP to handle the centering.
X.PP
XNote that in this simple filter, centered text is best if only one
Xor two lines.  \fIatom\fP will not handle multiple lines of centering
Xefficiency.
X.PP
XUsing the \-s option, \fIatom\fP automatically removes surplus 
Xnewlines from the final, processed file of LaTeX-processed output
Xfiles.  The default is to leave in as many or as few
Xnewlines as were in the original source file---including the required one
Xnewline that LaTeX uses to distinguish paragraphs.  For HTML, this option
Xcauses a single <P> to be output per paragraph.  In most cases, this
Xoption will not make much difference.
X
X.SH NOTES
X.PP
XAny series of three dots \ (...) \ is, for LaTeX, considered to be an
Xelipse.
X.PP
X.PP
XThis program could be expanded to handle boldface markup, but this
Xwould require having another delimiter, and we are creating yet another
Xmarkup language.
X.PP
XI admittedly \fIam\fP tempted to have this filter handle a maximum of
Xtwo types of markup:  the standard _underscore_ for italics and the
X*asterisk* for bold or <STRONG>.  ...But not that tempted!
X.PP
XCopyright (C), 1994, 1995, 1996 by Gary D. Kline
X.PP
XThis software is placed under distribution restrictions and rights
Xaccording to the GNU General Public License.  See the file ``COPYING''
Xincluded, or write to the Free Software Foundation, Inc.,
X675 Mass Avenue, Cambridge, MA 02139, USA
X
X.PP
X.SH SEE ALSO
Xtex(1)
X.SH BUG REPORTS TO
XGary Kline      kline@tao.thought.org  or  kline@tera.com
END-of-atom.1
echo x - test
sed 's/^X//' >test << 'END-of-test'
X                                   Testfile
X                             This line is Centered
X
X
XThis is a test no quotes; this paragraph may have an ellipse--that is,
Xthis:..., but lacking other symbols that require typesetting.
X
X"This," he said, "is a test with quotes. Plus an ellipse... ."
X
X		"Hi," he said, "*Wow*, you look pretty!"  
X
X
X"*Hi*" and "*Wow*": this demonstrates both a double-quote and two
Xitalicized words on one line.
X
X	=
X
X
X"Hello, world," may well have been Dennis' first words.
X
X
X        This is a paragraph with eight spaces of indentation.
X     This is a second paragraph indicated as such by five spaces.
X      And this, having been indented by six spaces should not be
X      seen by *atom* as a new paragraph.
X	A TAB, (('\010')) should denote this line as a new paragraph.
XLines that are meant to indicate a paragraph by having either 5 or
X8 leading spaces will not be seen to be paragraphs if you use the
Xcentering option, -c.  This may change down the road aways... .
X
X        This is a case where there is a new
X   paragraph and where the line is not necessarily 
X   flush with the extreme left margin.
X        And this is yet another instance of the
X   above.
X
X
X"This *is*", he said.
X
X  And this has *no* quotes. 
X
X	   "*No*!" he screamed.  "Absolutely and *positively*
Xbleeping *NOT*."
X
X	"This is yet another paragraph."'
X
X	Page 17.
X
X	"This is," she said, "YAP."
X
X	And this, too, he thought.
X
X	Page 18.
X
X"Now, now," they said in unison.  "Green cow."
X
X	And here is yet another paragraph without quotes.
X	And yet another! 
X	She said, "Here is one more for good luck for
Xtoday... ."
X	One more paragraph for test purposes.
X
X
X
X        And here is yet one more paragraph sans quotes.
X        Below is a new paragraph with even quotes:
X	"Hi," she said.
X	"Well, hi, baby."  He closed his eyes against the 
Xsun and pretended that they were as they had been the night before.  "Hey..."
X        She said, "Here is one more for good luck for
Xtoday... ."
X        One last tab-indented paragraph for test purposes.
X        And one last 8-space-indented paragraph.
X
X  This is a case where there is a new
Xparagraph that is indicated by a 2-space indentation.
XThis happens occasionally.
X  And this is yet another instance of the
Xabove. For atom to turn these two paragraphs into HTML or TeX
Xformatted paragraphs, use the command: ``atom -h2 <file>'' or
X``atom -2 <file>.''  Without the -2 flag, the HTML or LaTeX 
Xoutput of these lines will result in one run-together 
Xparagraph.
X  "This is a two-space indented paragraph with *actual*, real,
XHonest-to-Pete *italicized-words*."
X  "So what?" is the general reaction.  "BFD, man... ."
X
X
X	Below is an indication of a physical space-break that traditional
Xpublishers use to indicate a change of topic or passage of time
X
X
X
X
X
Xthe above break of 5 lines means to put a space-break in HTML or Tex.
END-of-test
exit



