summaryrefslogtreecommitdiff
path: root/avl-1.4.0
diff options
context:
space:
mode:
Diffstat (limited to 'avl-1.4.0')
-rw-r--r--avl-1.4.0/AUTHORS1
-rw-r--r--avl-1.4.0/COPYING340
-rw-r--r--avl-1.4.0/ChangeLog181
-rw-r--r--avl-1.4.0/INSTALL182
-rw-r--r--avl-1.4.0/Makefile.am28
-rw-r--r--avl-1.4.0/Makefile.in572
-rw-r--r--avl-1.4.0/NEWS98
-rw-r--r--avl-1.4.0/README37
-rw-r--r--avl-1.4.0/THANKS15
-rw-r--r--avl-1.4.0/TODO92
-rw-r--r--avl-1.4.0/aclocal.m4104
-rw-r--r--avl-1.4.0/avl.c1154
-rw-r--r--avl-1.4.0/avl.h148
-rw-r--r--avl-1.4.0/avl.html1046
-rw-r--r--avl-1.4.0/avl.info708
-rw-r--r--avl-1.4.0/avl.texinfo679
-rw-r--r--avl-1.4.0/avl.text636
-rw-r--r--avl-1.4.0/avlt.c1597
-rw-r--r--avl-1.4.0/avlt.h142
-rw-r--r--avl-1.4.0/avltr.c1538
-rw-r--r--avl-1.4.0/avltr.h142
-rwxr-xr-xavl-1.4.0/configure1297
-rw-r--r--avl-1.4.0/configure.in5
-rwxr-xr-xavl-1.4.0/install-sh251
-rwxr-xr-xavl-1.4.0/missing190
-rwxr-xr-xavl-1.4.0/mkinstalldirs40
-rw-r--r--avl-1.4.0/rb.c1083
-rw-r--r--avl-1.4.0/rb.h155
-rw-r--r--avl-1.4.0/texinfo.tex5484
-rw-r--r--avl-1.4.0/thread-test.c142
30 files changed, 18087 insertions, 0 deletions
diff --git a/avl-1.4.0/AUTHORS b/avl-1.4.0/AUTHORS
new file mode 100644
index 0000000..bcd66cd
--- /dev/null
+++ b/avl-1.4.0/AUTHORS
@@ -0,0 +1 @@
+Ben Pfaff <blp@gnu.org>
diff --git a/avl-1.4.0/COPYING b/avl-1.4.0/COPYING
new file mode 100644
index 0000000..60549be
--- /dev/null
+++ b/avl-1.4.0/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) 19yy <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/avl-1.4.0/ChangeLog b/avl-1.4.0/ChangeLog
new file mode 100644
index 0000000..e31a7c2
--- /dev/null
+++ b/avl-1.4.0/ChangeLog
@@ -0,0 +1,181 @@
+Sat Aug 7 18:32:43 1999 Ben Pfaff <blp@gnu.org>
+
+ Implemented red-black tree library.
+ * Makefile.am: Add rb.c, rb.h in appropriate places.
+ * README: Update.
+ * rb.c: New file.
+ * rb.h: Ditto.
+ * avl.texinfo: Revised.
+
+ * THANKS: Update.
+ * TODO: Update.
+
+ * avl.c: In several places, replaced usage of comma operator with
+ a proper statement block.
+ * avlt.c: Ditto.
+ * avltr.c: Ditto.
+
+ * avl.h: (AVL_TRAVERSER_INIT) New macro.
+ (avl_init_traverser) New function-like macro.
+ * avlt.h: (AVLT_TRAVERSER_INIT) New macro.
+ (avlt_init_traverser) New function-like macro.
+ * avltr.h: (AVLTR_TRAVERSER_INIT) New macro.
+ (avltr_init_traverser) New function-like macro.
+ * thread-test.c: (main) Use AVL_TRAVERSER_INIT.
+
+ * Made version 1.4.0.
+
+Sat Jul 31 12:39:54 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.texinfo: Update suggested by Jonathan Roy <roy@idle.com>.
+
+Tue May 25 12:20:43 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.c: (avl_delete) Make work properly for empty tree. Furrfu!
+ I should have noticed this before.
+
+Mon May 17 11:32:56 1999 Ben Pfaff <blp@gnu.org>
+
+ * Makefile.am: Don't require texi2html. Use $(MAKEINFO)
+ variable. Thanks to Alexandre Oliva <oliva@dcc.unicamp.br>.
+
+Sat May 15 23:47:14 1999 Ben Pfaff <blp@gnu.org>
+
+ * Updated copyright dates in several files.
+
+ * Made version 1.3.0.
+
+Sat May 15 21:44:54 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.c, avlt.c, avltr.c: In many places replaced assert (p) by
+ assert (p != NULL). Believe it or not, the former is not valid
+ ANSI C.
+
+ Thanks to "Ficarra, David W, NNAD" <dficarra@att.com> for pointing
+ out the following two sets of bugs.
+ * avl.c: (avl_probe) Fix order of assignment and assertion.
+ * avlt.c: (avlt_walk, avlt_probe, avlt_find) Ditto.
+ * avltr.c: (avltr_probe, avltr_find) Ditto.
+
+ * avlt.c: (avlt_find, avlt_delete) Check for empty tree.
+ * avltr.c: (avltr_probe) Ditto.
+
+ * avl.c, avlt.c, avltr.c, thread-test.c: Change test code to only
+ perform a limited number of iterations to facilitate automated
+ testing.
+
+ * avl.c: (avl_find_close) New function contributed by Thomas
+ Binder <binder@iue.tuwien.ac.at>.
+ * avlt.c: (avlt_find_close) Ditto.
+ * avltr.c: (avltr_find_close) Ditto.
+
+ * avl.texinfo: Update.
+
+ libavl is now automake/autoconfiscated. Contributed by Alexandre
+ Oliva <oliva@dcc.unicamp.br>.
+ * AUTHORS: New file.
+ * Makefile: Now automake-generated.
+ * INSTALL: New file.
+ * Makefile.am: New file.
+ * Makefile.in: New file.
+ * THANKS: New file.
+ * config.h.in: New file.
+ * configure.in: New file.
+ * configure: New file.
+ * install-sh: New file.
+ * missing: New file.
+ * mkinstalldirs: New file.
+ * texinfo.tex: New file.
+
+Tue May 11 13:33:20 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.texinfo: Fix typos. Thanks to onTy Toom <onty@yahoo.com>
+ for pointing these out.
+
+ * Made version 1.2.9.
+
+Sun Mar 14 13:39:16 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.c: Fixed two occurrences of = that should have been == in
+ assertions. Thanks to Girish Zambre <gzambre@sprynet.com> for
+ pointing out this problem.
+
+ * avl.c, avlt.c, avltr.c: __attribute__ must follow declarations
+ for gcc 2.7.x.
+
+ * Made version 1.2.8.
+
+Sun Mar 14 13:38:29 1999 Ben Pfaff <blp@gnu.org>
+
+ * TODO: Add some comments from David Kastrup
+ <dak@neuroinformatik.ruhr-uni-bochum.de>.
+
+ * Made version 1.2.7.
+
+Tue Jan 12 10:16:05 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.texinfo: Add skip lists as alternative to AVL trees. Thanks
+ to Ron Pfeifle <rpfeifle@aw.sgi.com>.
+
+ * Made version 1.2.6.
+
+Sun Jan 10 15:37:57 1999 Ben Pfaff <blp@gnu.org>
+
+ * avl.texinfo: Elaborated description of distinction between
+ threaded and unthreaded trees at request of several.
+
+ * Made version 1.2.5.
+
+Sun Nov 22 13:36:58 1998 Ben Pfaff <blp@gnu.org>
+
+ * avl.texinfo: Updates suggested by Jason Eisner
+ <jeisner@linc.cis.upenn.edu>.
+
+ * Made version 1.2.4.
+
+Sun Oct 18 10:26:08 1998 Ben Pfaff <pfaffben@pilot.msu.edu>
+
+ * TODO: New file.
+
+ * avl.c: (xmalloc) Don't declare xmalloc if HAVE_XMALLOC is
+ defined. By default on error, print a message to stderr and exit,
+ rather than calling abort() as before.
+ * avlt.c: (xmalloc) Same.
+ * avltr.c: (xmalloc) Same.
+
+ * Made version 1.2.3.
+
+Thu Sep 3 13:58:55 1998 Ben Pfaff <pfaffben@pilot.msu.edu>
+
+ * README: Update.
+
+ * avl.c: (avl_delete) Minor efficiency fixes; removed redundant
+ comparison.
+
+ * avlt.c: (avl_delete) Minor efficiency fix.
+ * avltr.c: (avl_delete) Same change.
+
+ * avl.texi: Update.
+
+ * Made version 1.2.2.
+
+Thu Jun 11 15:13:02 1998 Ben Pfaff <pfaffben@pilot.msu.edu>
+
+ * avl.c: Don't #define unused when PSPP is defined.
+ (force_avl_delete) Rename avl_force_delete.
+
+ * avlt.c: (force_avlt_delete) Rename avlt_force_delete.
+
+ * avltr.c: (force_avltr_delete) Rename avltr_force_delete.
+
+ * Made version 1.2.1.
+
+Thu Jun 11 14:43:30 1998 Ben Pfaff <pfaffben@pilot.msu.edu>
+
+ * Version 1.2.0: First GNU release.
+
+----------------------------------------------------------------------
+Local Variables:
+mode: change-log
+version-control: never
+End:
diff --git a/avl-1.4.0/INSTALL b/avl-1.4.0/INSTALL
new file mode 100644
index 0000000..b42a17a
--- /dev/null
+++ b/avl-1.4.0/INSTALL
@@ -0,0 +1,182 @@
+Basic Installation
+==================
+
+ These are generic installation instructions.
+
+ The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation. It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions. Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, a file
+`config.cache' that saves the results of its tests to speed up
+reconfiguring, and a file `config.log' containing compiler output
+(useful mainly for debugging `configure').
+
+ If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release. If at some point `config.cache'
+contains results you don't want to keep, you may remove or edit it.
+
+ The file `configure.in' is used to create `configure' by a program
+called `autoconf'. You only need `configure.in' if you want to change
+it or regenerate `configure' using a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+ 1. `cd' to the directory containing the package's source code and type
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
+
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
+
+ 2. Type `make' to compile the package.
+
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
+ documentation.
+
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+Compilers and Options
+=====================
+
+ Some systems require unusual options for compilation or linking that
+the `configure' script does not know about. You can give `configure'
+initial values for variables by setting them in the environment. Using
+a Bourne-compatible shell, you can do that on the command line like
+this:
+ CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+
+Or on systems that have the `env' program, you can do it like this:
+ env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+
+Compiling For Multiple Architectures
+====================================
+
+ You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script. `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+ If you have to use a `make' that does not supports the `VPATH'
+variable, you have to compile the package for one architecture at a time
+in the source code directory. After you have installed the package for
+one architecture, use `make distclean' before reconfiguring for another
+architecture.
+
+Installation Names
+==================
+
+ By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc. You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+ You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files. If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+ If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+ Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System). The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+ For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+ There may be some features `configure' can not figure out
+automatically, but needs to determine by the type of host the package
+will run on. Usually `configure' can figure that out, but if it prints
+a message saying it can not guess the host type, give it the
+`--host=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name with three fields:
+ CPU-COMPANY-SYSTEM
+
+See the file `config.sub' for the possible values of each field. If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the host type.
+
+ If you are building compiler tools for cross-compiling, you can also
+use the `--target=TYPE' option to select the type of system they will
+produce code for and the `--build=TYPE' option to select the type of
+system on which you are compiling the package.
+
+Sharing Defaults
+================
+
+ If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists. Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Operation Controls
+==================
+
+ `configure' recognizes the following options to control how it
+operates.
+
+`--cache-file=FILE'
+ Use and save the results of the tests in FILE instead of
+ `./config.cache'. Set FILE to `/dev/null' to disable caching, for
+ debugging `configure'.
+
+`--help'
+ Print a summary of the options to `configure', and exit.
+
+`--quiet'
+`--silent'
+`-q'
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
+
+`--srcdir=DIR'
+ Look for the package's source code in directory DIR. Usually
+ `configure' can determine that directory automatically.
+
+`--version'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
+`configure' also accepts some other, not widely useful, options.
diff --git a/avl-1.4.0/Makefile.am b/avl-1.4.0/Makefile.am
new file mode 100644
index 0000000..aa4754d
--- /dev/null
+++ b/avl-1.4.0/Makefile.am
@@ -0,0 +1,28 @@
+AUTOMAKE_OPTIONS = gnits
+
+include_HEADERS = avl.h avlt.h avltr.h rb.h
+
+lib_LIBRARIES = libavl.a
+libavl_a_SOURCES = avl.c avlt.c avltr.c rb.c
+
+info_TEXINFOS = avl.texinfo
+noinst_DATA = avl.html avl.text
+
+avl.text : avl.texinfo
+ $(MAKEINFO) $(srcdir)/avl.texinfo -o avl.text --no-headers
+
+avl.html: avl.texinfo
+ -texi2html -monolithic $(srcdir)/avl.texinfo
+
+EXTRA_PROGRAMS = avl-test avlt-test avltr-test thread-test rb-test
+DISTCLEANFILES = $(EXTRA_PROGRAMS) $(BUILT_SOURCES)
+
+BUILT_SOURCES = avl-test.c avlt-test.c avltr-test.c rb-test.c
+
+TESTS = avl-test avlt-test avltr-test thread-test rb-test
+avl-test.c avlt-test.c avltr-test.c rb-test.c:
+ rm -f $@
+ echo '#define SELF_TEST 1' > $@
+ echo '#include "'`echo $@ | sed s/-test//`'"' >> $@
+
+thread_test_LDADD = libavl.a
diff --git a/avl-1.4.0/Makefile.in b/avl-1.4.0/Makefile.in
new file mode 100644
index 0000000..2d041aa
--- /dev/null
+++ b/avl-1.4.0/Makefile.in
@@ -0,0 +1,572 @@
+# Makefile.in generated automatically by automake 1.4 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = .
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+CC = @CC@
+MAKEINFO = @MAKEINFO@
+PACKAGE = @PACKAGE@
+RANLIB = @RANLIB@
+VERSION = @VERSION@
+
+AUTOMAKE_OPTIONS = gnits
+
+include_HEADERS = avl.h avlt.h avltr.h rb.h
+
+lib_LIBRARIES = libavl.a
+libavl_a_SOURCES = avl.c avlt.c avltr.c rb.c
+
+info_TEXINFOS = avl.texinfo
+noinst_DATA = avl.html avl.text
+
+EXTRA_PROGRAMS = avl-test avlt-test avltr-test thread-test rb-test
+DISTCLEANFILES = $(EXTRA_PROGRAMS) $(BUILT_SOURCES)
+
+BUILT_SOURCES = avl-test.c avlt-test.c avltr-test.c rb-test.c
+
+TESTS = avl-test avlt-test avltr-test thread-test rb-test
+
+thread_test_LDADD = libavl.a
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_CLEAN_FILES =
+LIBRARIES = $(lib_LIBRARIES)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir)
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+libavl_a_LIBADD =
+libavl_a_OBJECTS = avl.o avlt.o avltr.o rb.o
+AR = ar
+avl_test_SOURCES = avl-test.c
+avl_test_OBJECTS = avl-test.o
+avl_test_LDADD = $(LDADD)
+avl_test_DEPENDENCIES =
+avl_test_LDFLAGS =
+avlt_test_SOURCES = avlt-test.c
+avlt_test_OBJECTS = avlt-test.o
+avlt_test_LDADD = $(LDADD)
+avlt_test_DEPENDENCIES =
+avlt_test_LDFLAGS =
+avltr_test_SOURCES = avltr-test.c
+avltr_test_OBJECTS = avltr-test.o
+avltr_test_LDADD = $(LDADD)
+avltr_test_DEPENDENCIES =
+avltr_test_LDFLAGS =
+thread_test_SOURCES = thread-test.c
+thread_test_OBJECTS = thread-test.o
+thread_test_DEPENDENCIES = libavl.a
+thread_test_LDFLAGS =
+rb_test_SOURCES = rb-test.c
+rb_test_OBJECTS = rb-test.o
+rb_test_LDADD = $(LDADD)
+rb_test_DEPENDENCIES =
+rb_test_LDFLAGS =
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+TEXI2DVI = texi2dvi
+INFO_DEPS = avl.info
+DVIS = avl.dvi
+TEXINFOS = avl.texinfo
+DATA = $(noinst_DATA)
+
+HEADERS = $(include_HEADERS)
+
+DIST_COMMON = README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
+Makefile.in NEWS THANKS TODO aclocal.m4 configure configure.in \
+install-sh missing mkinstalldirs texinfo.tex
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = tar
+GZIP_ENV = --best
+SOURCES = $(libavl_a_SOURCES) avl-test.c avlt-test.c avltr-test.c thread-test.c rb-test.c
+OBJECTS = $(libavl_a_OBJECTS) avl-test.o avlt-test.o avltr-test.o thread-test.o rb-test.o
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .dvi .info .o .ps .s .texi .texinfo .txi
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && $(AUTOMAKE) --gnits --include-deps Makefile
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+$(ACLOCAL_M4): configure.in
+ cd $(srcdir) && $(ACLOCAL)
+
+config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ $(SHELL) ./config.status --recheck
+$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
+ cd $(srcdir) && $(AUTOCONF)
+
+mostlyclean-libLIBRARIES:
+
+clean-libLIBRARIES:
+ -test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
+
+distclean-libLIBRARIES:
+
+maintainer-clean-libLIBRARIES:
+
+install-libLIBRARIES: $(lib_LIBRARIES)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(libdir)
+ @list='$(lib_LIBRARIES)'; for p in $$list; do \
+ if test -f $$p; then \
+ echo " $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$p"; \
+ $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$p; \
+ else :; fi; \
+ done
+ @$(POST_INSTALL)
+ @list='$(lib_LIBRARIES)'; for p in $$list; do \
+ if test -f $$p; then \
+ echo " $(RANLIB) $(DESTDIR)$(libdir)/$$p"; \
+ $(RANLIB) $(DESTDIR)$(libdir)/$$p; \
+ else :; fi; \
+ done
+
+uninstall-libLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ list='$(lib_LIBRARIES)'; for p in $$list; do \
+ rm -f $(DESTDIR)$(libdir)/$$p; \
+ done
+
+.c.o:
+ $(COMPILE) -c $<
+
+.s.o:
+ $(COMPILE) -c $<
+
+.S.o:
+ $(COMPILE) -c $<
+
+mostlyclean-compile:
+ -rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+ -rm -f *.tab.c
+
+maintainer-clean-compile:
+
+libavl.a: $(libavl_a_OBJECTS) $(libavl_a_DEPENDENCIES)
+ -rm -f libavl.a
+ $(AR) cru libavl.a $(libavl_a_OBJECTS) $(libavl_a_LIBADD)
+ $(RANLIB) libavl.a
+
+avl-test: $(avl_test_OBJECTS) $(avl_test_DEPENDENCIES)
+ @rm -f avl-test
+ $(LINK) $(avl_test_LDFLAGS) $(avl_test_OBJECTS) $(avl_test_LDADD) $(LIBS)
+
+avlt-test: $(avlt_test_OBJECTS) $(avlt_test_DEPENDENCIES)
+ @rm -f avlt-test
+ $(LINK) $(avlt_test_LDFLAGS) $(avlt_test_OBJECTS) $(avlt_test_LDADD) $(LIBS)
+
+avltr-test: $(avltr_test_OBJECTS) $(avltr_test_DEPENDENCIES)
+ @rm -f avltr-test
+ $(LINK) $(avltr_test_LDFLAGS) $(avltr_test_OBJECTS) $(avltr_test_LDADD) $(LIBS)
+
+thread-test: $(thread_test_OBJECTS) $(thread_test_DEPENDENCIES)
+ @rm -f thread-test
+ $(LINK) $(thread_test_LDFLAGS) $(thread_test_OBJECTS) $(thread_test_LDADD) $(LIBS)
+
+rb-test: $(rb_test_OBJECTS) $(rb_test_DEPENDENCIES)
+ @rm -f rb-test
+ $(LINK) $(rb_test_LDFLAGS) $(rb_test_OBJECTS) $(rb_test_LDADD) $(LIBS)
+
+avl.info: avl.texinfo
+avl.dvi: avl.texinfo
+
+
+DVIPS = dvips
+
+.texi.info:
+ @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
+ cd $(srcdir) \
+ && $(MAKEINFO) `echo $< | sed 's,.*/,,'`
+
+.texi.dvi:
+ TEXINPUTS=.:$$TEXINPUTS \
+ MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
+
+.texi:
+ @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
+ cd $(srcdir) \
+ && $(MAKEINFO) `echo $< | sed 's,.*/,,'`
+
+.texinfo.info:
+ @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
+ cd $(srcdir) \
+ && $(MAKEINFO) `echo $< | sed 's,.*/,,'`
+
+.texinfo:
+ @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
+ cd $(srcdir) \
+ && $(MAKEINFO) `echo $< | sed 's,.*/,,'`
+
+.texinfo.dvi:
+ TEXINPUTS=.:$$TEXINPUTS \
+ MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
+
+.txi.info:
+ @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
+ cd $(srcdir) \
+ && $(MAKEINFO) `echo $< | sed 's,.*/,,'`
+
+.txi.dvi:
+ TEXINPUTS=.:$$TEXINPUTS \
+ MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) $<
+
+.txi:
+ @cd $(srcdir) && rm -f $@ $@-[0-9] $@-[0-9][0-9]
+ cd $(srcdir) \
+ && $(MAKEINFO) `echo $< | sed 's,.*/,,'`
+.dvi.ps:
+ $(DVIPS) $< -o $@
+
+install-info-am: $(INFO_DEPS)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(infodir)
+ @list='$(INFO_DEPS)'; \
+ for file in $$list; do \
+ d=$(srcdir); \
+ for ifile in `cd $$d && echo $$file $$file-[0-9] $$file-[0-9][0-9]`; do \
+ if test -f $$d/$$ifile; then \
+ echo " $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile"; \
+ $(INSTALL_DATA) $$d/$$ifile $(DESTDIR)$(infodir)/$$ifile; \
+ else : ; fi; \
+ done; \
+ done
+ @$(POST_INSTALL)
+ @if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \
+ list='$(INFO_DEPS)'; \
+ for file in $$list; do \
+ echo " install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file";\
+ install-info --info-dir=$(DESTDIR)$(infodir) $(DESTDIR)$(infodir)/$$file || :;\
+ done; \
+ else : ; fi
+
+uninstall-info:
+ $(PRE_UNINSTALL)
+ @if $(SHELL) -c 'install-info --version | sed 1q | fgrep -s -v -i debian' >/dev/null 2>&1; then \
+ ii=yes; \
+ else ii=; fi; \
+ list='$(INFO_DEPS)'; \
+ for file in $$list; do \
+ test -z "$ii" \
+ || install-info --info-dir=$(DESTDIR)$(infodir) --remove $$file; \
+ done
+ @$(NORMAL_UNINSTALL)
+ list='$(INFO_DEPS)'; \
+ for file in $$list; do \
+ (cd $(DESTDIR)$(infodir) && rm -f $$file $$file-[0-9] $$file-[0-9][0-9]); \
+ done
+
+dist-info: $(INFO_DEPS)
+ list='$(INFO_DEPS)'; \
+ for base in $$list; do \
+ d=$(srcdir); \
+ for file in `cd $$d && eval echo $$base*`; do \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file; \
+ done; \
+ done
+
+mostlyclean-aminfo:
+ -rm -f avl.aux avl.cp avl.cps avl.dvi avl.fn avl.fns avl.ky avl.kys \
+ avl.ps avl.log avl.pg avl.toc avl.tp avl.tps avl.vr avl.vrs \
+ avl.op avl.tr avl.cv avl.cn
+
+clean-aminfo:
+
+distclean-aminfo:
+
+maintainer-clean-aminfo:
+ cd $(srcdir) && for i in $(INFO_DEPS); do \
+ rm -f $$i; \
+ if test "`echo $$i-[0-9]*`" != "$$i-[0-9]*"; then \
+ rm -f $$i-[0-9]*; \
+ fi; \
+ done
+
+install-includeHEADERS: $(include_HEADERS)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(includedir)
+ @list='$(include_HEADERS)'; for p in $$list; do \
+ if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
+ echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p"; \
+ $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p; \
+ done
+
+uninstall-includeHEADERS:
+ @$(NORMAL_UNINSTALL)
+ list='$(include_HEADERS)'; for p in $$list; do \
+ rm -f $(DESTDIR)$(includedir)/$$p; \
+ done
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ here=`pwd` && cd $(srcdir) \
+ && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+ -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+
+# This target untars the dist file and tries a VPATH configuration. Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+ -rm -rf $(distdir)
+ GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz
+ mkdir $(distdir)/=build
+ mkdir $(distdir)/=inst
+ dc_install_base=`cd $(distdir)/=inst && pwd`; \
+ cd $(distdir)/=build \
+ && ../configure --srcdir=.. --prefix=$$dc_install_base \
+ && $(MAKE) $(AM_MAKEFLAGS) \
+ && $(MAKE) $(AM_MAKEFLAGS) dvi \
+ && $(MAKE) $(AM_MAKEFLAGS) check \
+ && $(MAKE) $(AM_MAKEFLAGS) install \
+ && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+ && $(MAKE) $(AM_MAKEFLAGS) dist
+ -rm -rf $(distdir)
+ @banner="$(distdir).tar.gz is ready for distribution"; \
+ dashes=`echo "$$banner" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ echo "$$dashes"
+dist: distdir
+ -chmod -R a+r $(distdir)
+ GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
+ -rm -rf $(distdir)
+dist-all: distdir
+ -chmod -R a+r $(distdir)
+ GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
+ -rm -rf $(distdir)
+distdir: $(DISTFILES)
+ @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \
+ echo "NEWS not updated; not releasing" 1>&2; \
+ exit 1; \
+ fi
+ -rm -rf $(distdir)
+ mkdir $(distdir)
+ -chmod 777 $(distdir)
+ @for file in $(DISTFILES); do \
+ d=$(srcdir); \
+ if test -d $$d/$$file; then \
+ cp -pr $$d/$$file $(distdir)/$$file; \
+ else \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file || :; \
+ fi; \
+ done
+ $(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-info
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; \
+ srcdir=$(srcdir); export srcdir; \
+ for tst in $(TESTS); do \
+ if test -f $$tst; then dir=.; \
+ else dir="$(srcdir)"; fi; \
+ if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \
+ all=`expr $$all + 1`; \
+ echo "PASS: $$tst"; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ failed=`expr $$failed + 1`; \
+ echo "FAIL: $$tst"; \
+ fi; \
+ done; \
+ if test "$$failed" -eq 0; then \
+ banner="All $$all tests passed"; \
+ else \
+ banner="$$failed of $$all tests failed"; \
+ fi; \
+ dashes=`echo "$$banner" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ echo "$$dashes"; \
+ test "$$failed" -eq 0
+info-am: $(INFO_DEPS)
+info: info-am
+dvi-am: $(DVIS)
+dvi: dvi-am
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am: install-libLIBRARIES
+install-exec: install-exec-am
+
+install-data-am: install-info-am install-includeHEADERS
+install-data: install-data-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am: uninstall-libLIBRARIES uninstall-info \
+ uninstall-includeHEADERS
+uninstall: uninstall-am
+all-am: Makefile $(INFO_DEPS) $(LIBRARIES) $(DATA) $(HEADERS)
+all-redirect: all-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+ $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \
+ $(DESTDIR)$(includedir)
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+ -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+ -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
+mostlyclean-am: mostlyclean-libLIBRARIES mostlyclean-compile \
+ mostlyclean-aminfo mostlyclean-tags mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am: clean-libLIBRARIES clean-compile clean-aminfo clean-tags \
+ clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am: distclean-libLIBRARIES distclean-compile distclean-aminfo \
+ distclean-tags distclean-generic clean-am
+
+distclean: distclean-am
+ -rm -f config.status
+
+maintainer-clean-am: maintainer-clean-libLIBRARIES \
+ maintainer-clean-compile maintainer-clean-aminfo \
+ maintainer-clean-tags maintainer-clean-generic \
+ distclean-am
+ @echo "This command is intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+ -rm -f config.status
+
+.PHONY: mostlyclean-libLIBRARIES distclean-libLIBRARIES \
+clean-libLIBRARIES maintainer-clean-libLIBRARIES uninstall-libLIBRARIES \
+install-libLIBRARIES mostlyclean-compile distclean-compile \
+clean-compile maintainer-clean-compile install-info-am uninstall-info \
+mostlyclean-aminfo distclean-aminfo clean-aminfo \
+maintainer-clean-aminfo uninstall-includeHEADERS install-includeHEADERS \
+tags mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \
+distdir check-TESTS info-am info dvi-am dvi check check-am \
+installcheck-am installcheck install-exec-am install-exec \
+install-data-am install-data install-am install uninstall-am uninstall \
+all-redirect all-am all installdirs mostlyclean-generic \
+distclean-generic clean-generic maintainer-clean-generic clean \
+mostlyclean distclean maintainer-clean
+
+
+avl.text : avl.texinfo
+ $(MAKEINFO) $(srcdir)/avl.texinfo -o avl.text --no-headers
+
+avl.html: avl.texinfo
+ -texi2html -monolithic $(srcdir)/avl.texinfo
+avl-test.c avlt-test.c avltr-test.c rb-test.c:
+ rm -f $@
+ echo '#define SELF_TEST 1' > $@
+ echo '#include "'`echo $@ | sed s/-test//`'"' >> $@
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/avl-1.4.0/NEWS b/avl-1.4.0/NEWS
new file mode 100644
index 0000000..ecdc25d
--- /dev/null
+++ b/avl-1.4.0/NEWS
@@ -0,0 +1,98 @@
+libavl NEWS -- history of user-visible changes.
+Time-stamp: <1999-08-15 21:52:15 blp>
+Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+See the end for copying conditions.
+
+Please send PSPP bug reports to bug-gnu-pspp@gnu.org.
+
+Changes for version 1.4.0:
+
+ Implemented red-black trees.
+
+ New functions, *_init_traverser(), to initialize a *_traverser
+ structure. New macros *_TRAVERSER_INIT for same purpose.
+
+Changes for version 1.3.0:
+
+ Now uses Autoconf and Automake to configure. Thanks to Alexandre
+ Oliva <oliva@dcc.unicamp.br>.
+
+ New: automated testing with `make check'.
+
+ Fixes for strict ANSI C compliance.
+
+ Fixed useless assertions. Fixed bug regarding empty trees for some
+ operations with threaded and right-threaded trees. Thanks to
+ "Ficarra, David W, NNAD" <dficarra@att.com>.
+
+ New functions, avl*_find_close(), for finding a node in the tree
+ with a value close to a specified value. See documentation and
+ source code for more details. Thanks to Thomas Binder
+ <binder@iue.tuwien.ac.at>.
+
+Changes for version 1.2.9:
+
+ Fix typos in documentation. Thanks to onTy Toom <onty@yahoo.com>.
+
+Changes for version 1.2.8:
+
+ Fixed typos in assertions. Thanks to Girish Zambre
+ <gzambre@sprynet.com>.
+
+ Better support for gcc 2.7.x.
+
+Changes for versions 1.2.4, 1.2.5, 1.2.6, 1.2.7:
+
+ Documentation updates. Thanks to Ron Pfeifle <rpfeifle@aw.sgi.com>,
+ Jason Eisner <jeisner@linc.cis.upenn.edu>, and others.
+
+Changes for version 1.2.3:
+
+ The library's allocation function xmalloc() can easily be overridden
+ by the library's user. Thanks to Clayton Weaver <cgweav@eskimo.com>
+ for the idea.
+
+Changes for version 1.2.2:
+
+ Documentation fixes. Thanks to Akim Demaille <demaille@inf.enst.fr>
+ for pointing these out.
+
+Changes for version 1.2.1:
+
+ Bug fixes.
+
+Changes for version 1.2.0:
+
+ Implemented right-threaded trees.
+
+ Added functions to convert among AVL tree types.
+
+ First GNU release.
+
+Changes for version 1.1.0:
+
+ Implemented threaded trees.
+
+Changes for version 1.0:
+
+ First public release.
+
+----------------------------------------------------------------------
+Copyright information:
+
+Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ Permission is granted to anyone to make or distribute verbatim
+ copies of this document as received, in any medium, provided that
+ the copyright notice and this permission notice are preserved, thus
+ giving the recipient permission to redistribute in turn.
+
+ Permission is granted to distribute modified versions of this
+ document, or of portions of it, under the above conditions,
+ provided also that they carry prominent notices stating who last
+ changed them.
+
+Local variables:
+version-control: never
+mode: indented-text
+end:
diff --git a/avl-1.4.0/README b/avl-1.4.0/README
new file mode 100644
index 0000000..46ed6e4
--- /dev/null
+++ b/avl-1.4.0/README
@@ -0,0 +1,37 @@
+This is version 1.4 of libavl, a library in ANSI C for manipulation of
+balanced binary trees. Functions for use with three varieties of AVL
+tree and one type of red-black tree are included. There is full
+documentation, including an explanation of what AVL and red-black
+trees are and why you'd use them, in Texinfo, Info, HTML, and plain
+text formats.
+
+The library is divided into three parts, described in more detail
+below. You need only include the files for the types of trees that
+you are using.
+
+ - avl.h, avl.c: Unthreaded AVL tree library.
+ - avlt.h, avlt.c: Threaded AVL tree library.
+ - avltr.h, avltr.c: Right-threaded AVL tree library.
+ - rb.h, rb.c: Unthreaded red-black tree library.
+
+Each .c file in the library has a self-test routine built in, which
+can be invoked by compiling it with SELF_TEST set to 1. In addition,
+there is a separate program thread-test.c that tests the functions
+that convert among types of AVL trees. To automatically run these
+tests, type `make check' after you have configured the library with
+`configure'. For more information on how to configure and compile
+libavl, see the file INSTALL included in this directory.
+
+libavl is licensed under the GNU General Public License (GPL), which
+should be included in this directory in file COPYING. This is not the
+same as GNU Library General Public License (LGPL). Please read the
+license and become familiar with its terms.
+
+Please send bug reports and enhancement requests for libavl to Ben
+Pfaff <blp@gnu.org>.
+
+Share and enjoy!
+
+Local variables:
+mode: text
+End:
diff --git a/avl-1.4.0/THANKS b/avl-1.4.0/THANKS
new file mode 100644
index 0000000..cd9319a
--- /dev/null
+++ b/avl-1.4.0/THANKS
@@ -0,0 +1,15 @@
+Thanks to...
+
+* Donald Knuth for _The Art of Computer Programming_.
+
+* Thomas Cormen, Charles Leiserson, and Ron Rivest for _Introduction
+ to Algorithms_.
+
+* David MacKenzie for writing Autoconf, the automatic configuration
+ tool.
+
+* David MacKenzie and Tom Tromey for writing Automake, the tool for
+ generating `Makefile's.
+
+* All those who have contributed bug reports and enhancements. You
+ can find them listed individually in the NEWS and the ChangeLog.
diff --git a/avl-1.4.0/TODO b/avl-1.4.0/TODO
new file mode 100644
index 0000000..0231395
--- /dev/null
+++ b/avl-1.4.0/TODO
@@ -0,0 +1,92 @@
+TODO
+----
+
+* Write `bare' no-rebalancing version for comparison purposes.
+
+* In avl_delete's D9 it may be faster to move the data instead of
+ moving around all the pointers. Consider the situation carefully.
+
+* avl_traverse_{fwd,rev}; avl_find_traverse
+
+* Generalized testing framework; for instance, could compare with
+ kazlib and avllib implementations.
+
+* Merge algorithm paper into documentation.
+
+----------------------------------------------------------------------
+From: Akim Demaille <demaille@inf.enst.fr>
+Subject: Re: libavl
+To: pfaffben@pilot.msu.edu
+Date: 25 Sep 1998 16:04:03 +0200
+
+
+Sorry for the delays...
+
+Ben Pfaff <pfaffben@pilot.msu.edu> writes:
+
+> Akim Demaille <demaille@inf.enst.fr> writes:
+>
+> And finaly, for the application I want to make of libavl, I have
+> sometimes to merge two avls, say the second into the first, while
+> specifying, when conflict, whether it is always the first or the
+> second that wins.
+>
+> I can easily make this using your api, nevertheless, I wanted to ask
+> you whether you know none brute-force approaches, or even whether
+> this kind of features might appear in the future.
+>
+> Knuth describes an elegant algorithm for merging two avls, but it only
+> works if all the values in one of them is smaller than all the values
+> in the other.
+>
+> If you do think of a clever algorithm for doing this, please let me
+> know and I'll incorporate it into the API.
+
+I know none. but looking on the web, I found one in haskell :)
+I didn't look whether it was smart or not.
+
+http://www.cs.chalmers.se/pub/haskell/library/avl-tree.lgs
+
+There is not much material. I think comp.compiler is a good place to
+ask for an algorithm...
+
+Akim
+----------------------------------------------------------------------
+From: David Kastrup <dak@neuroinformatik.ruhr-uni-bochum.de>
+Subject: Re: Your AVL tree page
+To: pfaffben@pilot.msu.edu
+Date: Mon, 23 Nov 1998 18:38:55 +0100
+
+ From: Ben Pfaff <pfaffben@pilot.msu.edu>
+ Date: 23 Nov 1998 12:12:31 -0500
+
+ David Kastrup <dak@neuroinformatik.ruhr-uni-bochum.de> writes:
+
+ You might want to take a look at the texts at
+ http://www-lsi.upc.es/www/dept/techreps/1998.html
+
+ In particular the paper
+ http://www-lsi.upc.es/dept/techreps/ps/R98-12.ps.gz
+
+ might be interesting, as it gives an AVL-tree mechanism for
+ multi-threaded, distributed access.
+
+ Thanks for the pointers. It seems that connectivity to that machine
+ is really slow from here, at least right now, so I'll try to take a
+ look at them a little later. Currently there is no multithread
+ support in libavl, but it might be nice to add it later.
+
+Well, the reference will probably not be what you think it is. It is
+intended to not properly balance the tree during the access when that
+would mean locking the entire tree. Instead, it does only local
+corrections that eventually probagate to the top. One can also let a
+"garbage collect" thread run that will optimize the data structures
+at idle times, but will let them deteriorate a bit rather than fix
+them up properly under stress. This is, of course, especially
+interesting for internal data structures of an operating system, where
+full balancing at the time of access will slow operations down, but
+there will be idle times when balancing can occur without overhead.
+
+David Kastrup Phone: +49-234-700-5570
+Email: dak@neuroinformatik.ruhr-uni-bochum.de Fax: +49-234-709-4209
+Institut für Neuroinformatik, Universitätsstr. 150, 44780 Bochum, Germany
diff --git a/avl-1.4.0/aclocal.m4 b/avl-1.4.0/aclocal.m4
new file mode 100644
index 0000000..9f8add8
--- /dev/null
+++ b/avl-1.4.0/aclocal.m4
@@ -0,0 +1,104 @@
+dnl aclocal.m4 generated automatically by aclocal 1.4
+
+dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+dnl PARTICULAR PURPOSE.
+
+# Do all the work for Automake. This macro actually does too much --
+# some checks are only needed if your package does certain things.
+# But this isn't really a big deal.
+
+# serial 1
+
+dnl Usage:
+dnl AM_INIT_AUTOMAKE(package,version, [no-define])
+
+AC_DEFUN(AM_INIT_AUTOMAKE,
+[AC_REQUIRE([AC_PROG_INSTALL])
+PACKAGE=[$1]
+AC_SUBST(PACKAGE)
+VERSION=[$2]
+AC_SUBST(VERSION)
+dnl test to see if srcdir already configured
+if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
+ AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+fi
+ifelse([$3],,
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
+AC_REQUIRE([AM_SANITY_CHECK])
+AC_REQUIRE([AC_ARG_PROGRAM])
+dnl FIXME This is truly gross.
+missing_dir=`cd $ac_aux_dir && pwd`
+AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
+AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
+AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
+AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
+AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
+AC_REQUIRE([AC_PROG_MAKE_SET])])
+
+#
+# Check to make sure that the build environment is sane.
+#
+
+AC_DEFUN(AM_SANITY_CHECK,
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftestfile
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments. Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+ set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
+ if test "[$]*" = "X"; then
+ # -L didn't work.
+ set X `ls -t $srcdir/configure conftestfile`
+ fi
+ if test "[$]*" != "X $srcdir/configure conftestfile" \
+ && test "[$]*" != "X conftestfile $srcdir/configure"; then
+
+ # If neither matched, then we have a broken ls. This can happen
+ # if, for instance, CONFIG_SHELL is bash and it inherits a
+ # broken ls alias from the environment. This has actually
+ # happened. Such a system could not be considered "sane".
+ AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
+alias in your environment])
+ fi
+
+ test "[$]2" = conftestfile
+ )
+then
+ # Ok.
+ :
+else
+ AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+rm -f conftest*
+AC_MSG_RESULT(yes)])
+
+dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
+dnl The program must properly implement --version.
+AC_DEFUN(AM_MISSING_PROG,
+[AC_MSG_CHECKING(for working $2)
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf. Sigh.
+if ($2 --version) < /dev/null > /dev/null 2>&1; then
+ $1=$2
+ AC_MSG_RESULT(found)
+else
+ $1="$3/missing $2"
+ AC_MSG_RESULT(missing)
+fi
+AC_SUBST($1)])
+
diff --git a/avl-1.4.0/avl.c b/avl-1.4.0/avl.c
new file mode 100644
index 0000000..82cdb6e
--- /dev/null
+++ b/avl-1.4.0/avl.c
@@ -0,0 +1,1154 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file avl.c in libavl. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#if PSPP
+#include "common.h"
+#include "arena.h"
+#define HAVE_XMALLOC 1
+#endif
+#if SELF_TEST
+#include <limits.h>
+#include <time.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "avl.h"
+
+#if !PSPP && !__GCC__
+#define inline
+#endif
+
+#if !PSPP
+#if __GNUC__ >= 2
+#define unused __attribute__ ((unused))
+#else
+#define unused
+#endif
+#endif
+
+#ifdef HAVE_XMALLOC
+void *xmalloc (size_t);
+#else /* !HAVE_XMALLOC */
+/* Allocates SIZE bytes of space using malloc(). Aborts if out of
+ memory. */
+static void *
+xmalloc (size_t size)
+{
+ void *vp;
+
+ if (size == 0)
+ return NULL;
+ vp = malloc (size);
+
+ assert (vp != NULL);
+ if (vp == NULL)
+ {
+ fprintf (stderr, "virtual memory exhausted\n");
+ exit (EXIT_FAILURE);
+ }
+ return vp;
+}
+#endif /* !HAVE_XMALLOC */
+
+/* Creates an AVL tree in arena OWNER (which can be NULL). The arena
+ is owned by the caller, not by the AVL tree. CMP is a order
+ function for the data to be stored in the tree. PARAM is arbitrary
+ data that becomes an argument to the comparison function. */
+avl_tree *
+avl_create (MAYBE_ARENA avl_comparison_func cmp, void *param)
+{
+ avl_tree *tree;
+
+ assert (cmp != NULL);
+#if PSPP
+ if (owner)
+ tree = arena_alloc (owner, sizeof (avl_tree));
+ else
+#endif
+ tree = xmalloc (sizeof (avl_tree));
+
+#if PSPP
+ tree->owner = owner;
+#endif
+ tree->root.link[0] = NULL;
+ tree->root.link[1] = NULL;
+ tree->cmp = cmp;
+ tree->count = 0;
+ tree->param = param;
+
+ return tree;
+}
+
+/* Destroy tree TREE. Function FREE_FUNC is called for every node in
+ the tree as it is destroyed.
+
+ No effect if the tree has an arena owner and free_func is NULL.
+ The caller owns the arena and must destroy it itself.
+
+ Do not attempt to reuse the tree after it has been freed. Create a
+ new one. */
+void
+avl_destroy (avl_tree *tree, avl_node_func free_func)
+{
+ assert (tree != NULL);
+
+#if PSPP
+ if (free_func || tree->owner == NULL)
+#endif
+ {
+ /* Uses Knuth's Algorithm 2.3.1T as modified in exercise 13
+ (postorder traversal). */
+
+ /* T1. */
+ avl_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ char ab[AVL_MAX_HEIGHT]; /* Stack A: bits. */
+ int ap = 0; /* Stack A: height. */
+ avl_node *p = tree->root.link[0];
+
+ for (;;)
+ {
+ /* T2. */
+ while (p != NULL)
+ {
+ /* T3. */
+ ab[ap] = 0;
+ an[ap++] = p;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ for (;;)
+ {
+ if (ap == 0)
+ goto done;
+
+ p = an[--ap];
+ if (ab[ap] == 0)
+ {
+ ab[ap++] = 1;
+ p = p->link[1];
+ break;
+ }
+
+ if (free_func)
+ free_func (p->data, tree->param);
+#if PSPP
+ if (tree->owner == NULL)
+#endif
+ free (p);
+ }
+ }
+ }
+
+ done:
+#if PSPP
+ if (tree->owner == NULL)
+#endif
+ free (tree);
+}
+
+/* avl_destroy() with FREE_FUNC hardcoded as free(). */
+void
+avl_free (avl_tree *tree)
+{
+ avl_destroy (tree, (avl_node_func) free);
+}
+
+/* Return the number of nodes in TREE. */
+int
+avl_count (const avl_tree *tree)
+{
+ assert (tree != NULL);
+ return tree->count;
+}
+
+/* Allocates room for a new avl_node in arena OWNER, or using
+ xmalloc() if OWNER is NULL. */
+#if PSPP
+static inline avl_node *
+new_node (arena **owner)
+{
+ if (owner != NULL)
+ return arena_alloc (owner, sizeof (avl_node));
+ else
+ return xmalloc (sizeof (avl_node));
+}
+#else
+static inline avl_node *
+new_node (void)
+{
+ return xmalloc (sizeof (avl_node));
+}
+
+#define new_node(owner) \
+ new_node ()
+#endif
+
+/* Copy the contents of TREE to a new tree in arena OWNER. If COPY is
+ non-NULL, then each data item is passed to function COPY, and the
+ return values are inserted into the new tree; otherwise, the items
+ are copied verbatim from the old tree to the new tree. Returns the
+ new tree. */
+avl_tree *
+avl_copy (MAYBE_ARENA const avl_tree *tree, avl_copy_func copy)
+{
+ /* This is a combination of Knuth's Algorithm 2.3.1C (copying a
+ binary tree) and Algorithm 2.3.1T as modified by exercise 12
+ (preorder traversal). */
+
+ avl_tree *new_tree;
+
+ /* PT1. */
+ const avl_node *pa[AVL_MAX_HEIGHT]; /* Stack PA: nodes. */
+ const avl_node **pp = pa; /* Stack PA: stack pointer. */
+ const avl_node *p = &tree->root;
+
+ /* QT1. */
+ avl_node *qa[AVL_MAX_HEIGHT]; /* Stack QA: nodes. */
+ avl_node **qp = qa; /* Stack QA: stack pointer. */
+ avl_node *q;
+
+ assert (tree != NULL);
+#if PSPP
+ new_tree = avl_create (owner, tree->cmp, tree->param);
+#else
+ new_tree = avl_create (tree->cmp, tree->param);
+#endif
+ new_tree->count = tree->count;
+ q = &new_tree->root;
+
+ for (;;)
+ {
+ /* C4. */
+ if (p->link[0] != NULL)
+ {
+ avl_node *r = new_node (owner);
+ r->link[0] = r->link[1] = NULL;
+ q->link[0] = r;
+ }
+
+ /* C5: Find preorder successors of P and Q. */
+ goto start;
+ for (;;)
+ {
+ /* PT2. */
+ while (p != NULL)
+ {
+ goto escape;
+ start:
+ /* PT3. */
+ *pp++ = p;
+ *qp++ = q;
+ p = p->link[0];
+ q = q->link[0];
+ }
+
+ /* PT4. */
+ if (pp == pa)
+ {
+ assert (qp == qa);
+ return new_tree;
+ }
+
+ p = *--pp;
+ q = *--qp;
+
+ /* PT5. */
+ p = p->link[1];
+ q = q->link[1];
+ }
+ escape:
+
+ /* C2. */
+ if (p->link[1])
+ {
+ avl_node *r = new_node (owner);
+ r->link[0] = r->link[1] = NULL;
+ q->link[1] = r;
+ }
+
+ /* C3. */
+ q->bal = p->bal;
+ if (copy == NULL)
+ q->data = p->data;
+ else
+ q->data = copy (p->data, tree->param);
+ }
+}
+
+/* Walk tree TREE in inorder, calling WALK_FUNC at each node. Passes
+ PARAM to WALK_FUNC. */
+void
+avl_walk (const avl_tree *tree, avl_node_func walk_func, void *param)
+{
+ /* Uses Knuth's algorithm 2.3.1T (inorder traversal). */
+ assert (tree && walk_func);
+
+ {
+ /* T1. */
+ const avl_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ const avl_node **ap = an; /* Stack A: stack pointer. */
+ const avl_node *p = tree->root.link[0];
+
+ for (;;)
+ {
+ /* T2. */
+ while (p != NULL)
+ {
+ /* T3. */
+ *ap++ = p;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ if (ap == an)
+ return;
+ p = *--ap;
+
+ /* T5. */
+ walk_func (p->data, param);
+ p = p->link[1];
+ }
+ }
+}
+
+/* Each call to this function for a given TREE and TRAV return the
+ next item in the tree in inorder. Initialize the first element of
+ TRAV (init) to 0 before calling the first time. Returns NULL when
+ out of elements. */
+void *
+avl_traverse (const avl_tree *tree, avl_traverser *trav)
+{
+ assert (tree && trav);
+
+ /* Uses Knuth's algorithm 2.3.1T (inorder traversal). */
+ if (trav->init == 0)
+ {
+ /* T1. */
+ trav->init = 1;
+ trav->nstack = 0;
+ trav->p = tree->root.link[0];
+ }
+ else
+ /* T5. */
+ trav->p = trav->p->link[1];
+
+ for (;;)
+ {
+ /* T2. */
+ while (trav->p != NULL)
+ {
+ /* T3. */
+ trav->stack[trav->nstack++] = trav->p;
+ trav->p = trav->p->link[0];
+ }
+
+ /* T4. */
+ if (trav->nstack == 0)
+ {
+ trav->init = 0;
+ return NULL;
+ }
+ trav->p = trav->stack[--trav->nstack];
+
+ /* T5. */
+ return trav->p->data;
+ }
+}
+
+/* Search TREE for an item matching ITEM. If found, returns a pointer
+ to the address of the item. If none is found, ITEM is inserted
+ into the tree, and a pointer to the address of ITEM is returned.
+ In either case, the pointer returned can be changed by the caller,
+ or the returned data item can be directly edited, but the key data
+ in the item must not be changed. */
+void **
+avl_probe (avl_tree *tree, void *item)
+{
+ /* Uses Knuth's Algorithm 6.2.3A (balanced tree search and
+ insertion), but caches results of comparisons. In empirical
+ tests this eliminates about 25% of the comparisons seen under
+ random insertions. */
+
+ /* A1. */
+ avl_node *t;
+ avl_node *s, *p, *q, *r;
+
+ assert (tree != NULL);
+ t = &tree->root;
+ s = p = t->link[0];
+
+ if (s == NULL)
+ {
+ tree->count++;
+ assert (tree->count == 1);
+ q = t->link[0] = new_node (tree->owner);
+ q->data = item;
+ q->link[0] = q->link[1] = NULL;
+ q->bal = 0;
+ return &q->data;
+ }
+
+ for (;;)
+ {
+ /* A2. */
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ /* A3. */
+ if (diff < 0)
+ {
+ p->cache = 0;
+ q = p->link[0];
+ if (q == NULL)
+ {
+ p->link[0] = q = new_node (tree->owner);
+ break;
+ }
+ }
+ /* A4. */
+ else if (diff > 0)
+ {
+ p->cache = 1;
+ q = p->link[1];
+ if (q == NULL)
+ {
+ p->link[1] = q = new_node (tree->owner);
+ break;
+ }
+ }
+ else
+ /* A2. */
+ return &p->data;
+
+ /* A3, A4. */
+ if (q->bal != 0)
+ t = p, s = q;
+ p = q;
+ }
+
+ /* A5. */
+ tree->count++;
+ q->data = item;
+ q->link[0] = q->link[1] = NULL;
+ q->bal = 0;
+
+ /* A6. */
+ r = p = s->link[(int) s->cache];
+ while (p != q)
+ {
+ p->bal = p->cache * 2 - 1;
+ p = p->link[(int) p->cache];
+ }
+
+ /* A7. */
+ if (s->cache == 0)
+ {
+ /* a = -1. */
+ if (s->bal == 0)
+ {
+ s->bal = -1;
+ return &q->data;
+ }
+ else if (s->bal == +1)
+ {
+ s->bal = 0;
+ return &q->data;
+ }
+
+ assert (s->bal == -1);
+ if (r->bal == -1)
+ {
+ /* A8. */
+ p = r;
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ s->bal = r->bal = 0;
+ }
+ else
+ {
+ /* A9. */
+ assert (r->bal == +1);
+ p = r->link[1];
+ r->link[1] = p->link[0];
+ p->link[0] = r;
+ s->link[0] = p->link[1];
+ p->link[1] = s;
+ if (p->bal == -1)
+ s->bal = 1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == +1);
+ s->bal = 0, r->bal = -1;
+ }
+ p->bal = 0;
+ }
+ }
+ else
+ {
+ /* a == +1. */
+ if (s->bal == 0)
+ {
+ s->bal = 1;
+ return &q->data;
+ }
+ else if (s->bal == -1)
+ {
+ s->bal = 0;
+ return &q->data;
+ }
+
+ assert (s->bal == +1);
+ if (r->bal == +1)
+ {
+ /* A8. */
+ p = r;
+ s->link[1] = r->link[0];
+ r->link[0] = s;
+ s->bal = r->bal = 0;
+ }
+ else
+ {
+ /* A9. */
+ assert (r->bal == -1);
+ p = r->link[0];
+ r->link[0] = p->link[1];
+ p->link[1] = r;
+ s->link[1] = p->link[0];
+ p->link[0] = s;
+ if (p->bal == +1)
+ s->bal = -1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == -1);
+ s->bal = 0, r->bal = 1;
+ }
+ p->bal = 0;
+ }
+ }
+
+ /* A10. */
+ if (t != &tree->root && s == t->link[1])
+ t->link[1] = p;
+ else
+ t->link[0] = p;
+
+ return &q->data;
+}
+
+/* Search TREE for an item matching ITEM, and return it if found. */
+void *
+avl_find (const avl_tree *tree, const void *item)
+{
+ const avl_node *p;
+
+ assert (tree != NULL);
+ for (p = tree->root.link[0]; p; )
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ if (diff < 0)
+ p = p->link[0];
+ else if (diff > 0)
+ p = p->link[1];
+ else
+ return p->data;
+ }
+
+ return NULL;
+}
+
+/* Search TREE for an item close to the value of ITEM, and return it.
+ This function will return a null pointer only if TREE is empty. */
+void *
+avl_find_close (const avl_tree *tree, const void *item)
+{
+ const avl_node *p;
+
+ assert (tree != NULL);
+ p = tree->root.link[0];
+ if (p == NULL)
+ return NULL;
+
+ for (;;)
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+ int t;
+
+ if (diff < 0)
+ t = 0;
+ else if (diff > 0)
+ t = 1;
+ else
+ return p->data;
+
+ if (p->link[t])
+ p = p->link[t];
+ else
+ return p->data;
+ }
+}
+
+/* Searches AVL tree TREE for an item matching ITEM. If found, the
+ item is removed from the tree and the actual item found is returned
+ to the caller. If no item matching ITEM exists in the tree,
+ returns NULL. */
+void *
+avl_delete (avl_tree *tree, const void *item)
+{
+ /* Uses my Algorithm D, which can be found at
+ http://www.msu.edu/user/pfaffben/avl. Algorithm D is based on
+ Knuth's Algorithm 6.2.2D (Tree deletion) and 6.2.3A (Balanced
+ tree search and insertion), as well as the notes on pages 465-466
+ of Vol. 3. */
+
+ /* D1. */
+ avl_node *pa[AVL_MAX_HEIGHT]; /* Stack P: Nodes. */
+ char a[AVL_MAX_HEIGHT]; /* Stack P: Bits. */
+ int k = 1; /* Stack P: Pointer. */
+
+ avl_node **q;
+ avl_node *p;
+
+ assert (tree != NULL);
+
+ a[0] = 0;
+ pa[0] = &tree->root;
+ p = tree->root.link[0];
+ for (;;)
+ {
+ /* D2. */
+ int diff;
+
+ if (p == NULL)
+ return NULL;
+
+ diff = tree->cmp (item, p->data, tree->param);
+ if (diff == 0)
+ break;
+
+ /* D3, D4. */
+ pa[k] = p;
+ if (diff < 0)
+ {
+ p = p->link[0];
+ a[k] = 0;
+ }
+ else if (diff > 0)
+ {
+ p = p->link[1];
+ a[k] = 1;
+ }
+ k++;
+ }
+ tree->count--;
+
+ item = p->data;
+
+ /* D5. */
+ q = &pa[k - 1]->link[(int) a[k - 1]];
+ if (p->link[1] == NULL)
+ {
+ *q = p->link[0];
+ if (*q)
+ (*q)->bal = 0;
+ }
+ else
+ {
+ /* D6. */
+ avl_node *r = p->link[1];
+ if (r->link[0] == NULL)
+ {
+ r->link[0] = p->link[0];
+ *q = r;
+ r->bal = p->bal;
+ a[k] = 1;
+ pa[k++] = r;
+ }
+ else
+ {
+ /* D7. */
+ avl_node *s = r->link[0];
+ int l = k++;
+
+ a[k] = 0;
+ pa[k++] = r;
+
+ /* D8. */
+ while (s->link[0] != NULL)
+ {
+ r = s;
+ s = r->link[0];
+ a[k] = 0;
+ pa[k++] = r;
+ }
+
+ /* D9. */
+ a[l] = 1;
+ pa[l] = s;
+ s->link[0] = p->link[0];
+ r->link[0] = s->link[1];
+ s->link[1] = p->link[1];
+ s->bal = p->bal;
+ *q = s;
+ }
+ }
+
+#if PSPP
+ if (tree->owner == NULL)
+#endif
+ free (p);
+
+ assert (k > 0);
+ /* D10. */
+ while (--k)
+ {
+ avl_node *s = pa[k], *r;
+
+ if (a[k] == 0)
+ {
+ /* D10. */
+ if (s->bal == -1)
+ {
+ s->bal = 0;
+ continue;
+ }
+ else if (s->bal == 0)
+ {
+ s->bal = 1;
+ break;
+ }
+
+ assert (s->bal == +1);
+ r = s->link[1];
+
+ assert (r != NULL);
+ if (r->bal == 0)
+ {
+ /* D11. */
+ s->link[1] = r->link[0];
+ r->link[0] = s;
+ r->bal = -1;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ break;
+ }
+ else if (r->bal == +1)
+ {
+ /* D12. */
+ s->link[1] = r->link[0];
+ r->link[0] = s;
+ s->bal = r->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ }
+ else
+ {
+ /* D13. */
+ assert (r->bal == -1);
+ p = r->link[0];
+ r->link[0] = p->link[1];
+ p->link[1] = r;
+ s->link[1] = p->link[0];
+ p->link[0] = s;
+ if (p->bal == +1)
+ s->bal = -1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == -1);
+ s->bal = 0, r->bal = +1;
+ }
+ p->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = p;
+ }
+ }
+ else
+ {
+ assert (a[k] == 1);
+
+ /* D10. */
+ if (s->bal == +1)
+ {
+ s->bal = 0;
+ continue;
+ }
+ else if (s->bal == 0)
+ {
+ s->bal = -1;
+ break;
+ }
+
+ assert (s->bal == -1);
+ r = s->link[0];
+
+ if (r == NULL || r->bal == 0)
+ {
+ /* D11. */
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ r->bal = 1;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ break;
+ }
+ else if (r->bal == -1)
+ {
+ /* D12. */
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ s->bal = r->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ }
+ else if (r->bal == +1)
+ {
+ /* D13. */
+ p = r->link[1];
+ r->link[1] = p->link[0];
+ p->link[0] = r;
+ s->link[0] = p->link[1];
+ p->link[1] = s;
+ if (p->bal == -1)
+ s->bal = 1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == 1);
+ s->bal = 0, r->bal = -1;
+ }
+ p->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = p;
+ }
+ }
+ }
+
+ return (void *) item;
+}
+
+/* Inserts ITEM into TREE. Returns NULL if the item was inserted,
+ otherwise a pointer to the duplicate item. */
+void *
+avl_insert (avl_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = avl_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+/* If ITEM does not exist in TREE, inserts it and returns NULL. If a
+ matching item does exist, it is replaced by ITEM and the item
+ replaced is returned. The caller is responsible for freeing the
+ item returned. */
+void *
+avl_replace (avl_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = avl_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+
+/* Delete ITEM from TREE when you know that ITEM must be in TREE. For
+ debugging purposes. */
+void *
+(avl_force_delete) (avl_tree *tree, void *item)
+{
+ void *found = avl_delete (tree, item);
+ assert (found != NULL);
+ return found;
+}
+
+#if SELF_TEST
+
+/* Used to flag delayed aborting. */
+int done = 0;
+
+/* Print the structure of node NODE of an avl tree, which is LEVEL
+ levels from the top of the tree. Uses different delimiters to
+ visually distinguish levels. */
+void
+print_structure (avl_node *node, int level)
+{
+ char lc[] = "([{`/";
+ char rc[] = ")]}'\\";
+
+ assert (level <= 10);
+
+ if (node == NULL)
+ {
+ printf (" nil");
+ return;
+ }
+ printf (" %c%d", lc[level % 5], (int) node->data);
+ if (node->link[0] || node->link[1])
+ print_structure (node->link[0], level + 1);
+ if (node->link[1])
+ print_structure (node->link[1], level + 1);
+ printf ("%c", rc[level % 5]);
+}
+
+/* Compare two integers A and B and return a strcmp()-type result. */
+int
+compare_ints (const void *a, const void *b, void *param unused)
+{
+ return ((int) a) - ((int) b);
+}
+
+/* Print the value of integer A. */
+void
+print_int (void *a, void *param unused)
+{
+ printf (" %d", (int) a);
+}
+
+/* Linearly print contents of TREE. */
+void
+print_contents (avl_tree *tree)
+{
+ avl_walk (tree, print_int, NULL);
+ printf ("\n");
+}
+
+/* Examine NODE in a avl tree. *COUNT is increased by the number of
+ nodes in the tree, including the current one. If the node is the
+ root of the tree, PARENT should be INT_MIN, otherwise it should be
+ the parent node value. DIR is the direction that the current node
+ is linked from the parent: -1 for left child, +1 for right child;
+ it is not used if PARENT is INT_MIN. Returns the height of the
+ tree rooted at NODE. */
+int
+recurse_tree (avl_node *node, int *count, int parent, int dir)
+{
+ if (node)
+ {
+ int d = (int) node->data;
+ int nl = node->link[0] ? recurse_tree (node->link[0], count, d, -1) : 0;
+ int nr = node->link[1] ? recurse_tree (node->link[1], count, d, 1) : 0;
+ (*count)++;
+
+ if (nr - nl != node->bal)
+ {
+ printf (" Node %d is unbalanced: right height=%d, left height=%d, "
+ "difference=%d, but balance factor=%d.\n",
+ d, nr, nl, nr - nl, node->bal);
+ done = 1;
+ }
+
+ if (parent != INT_MIN)
+ {
+ assert (dir == -1 || dir == +1);
+ if (dir == -1 && d > parent)
+ {
+ printf (" Node %d is smaller than its left child %d.\n",
+ parent, d);
+ done = 1;
+ }
+ else if (dir == +1 && d < parent)
+ {
+ printf (" Node %d is larger than its right child %d.\n",
+ parent, d);
+ done = 1;
+ }
+ }
+ assert (node->bal >= -1 && node->bal <= 1);
+ return 1 + (nl > nr ? nl : nr);
+ }
+ else return 0;
+}
+
+/* Check that everything about TREE is kosher. */
+void
+verify_tree (avl_tree *tree)
+{
+ int count = 0;
+ recurse_tree (tree->root.link[0], &count, INT_MIN, 0);
+ if (count != tree->count)
+ {
+ printf (" Tree has %d nodes, but tree count is %d.\n",
+ count, tree->count);
+ done = 1;
+ }
+ if (done)
+ abort ();
+}
+
+/* Arrange the N elements of ARRAY in random order. */
+void
+shuffle (int *array, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ int j = i + rand () % (n - i);
+ int t = array[j];
+ array[j] = array[i];
+ array[i] = t;
+ }
+}
+
+/* Compares avl trees rooted at A and B, making sure that they are
+ identical. */
+void
+compare_trees (avl_node *a, avl_node *b)
+{
+ if (a == NULL || b == NULL)
+ {
+ assert (a == NULL && b == NULL);
+ return;
+ }
+ if (a->data != b->data || a->bal != b->bal
+ || ((a->link[0] != NULL) ^ (b->link[0] != NULL))
+ || ((a->link[1] != NULL) ^ (b->link[1] != NULL)))
+ {
+ printf (" Copied nodes differ: %d b=%d a->bal=%d b->bal=%d a:",
+ (int) a->data, (int) b->data, a->bal, b->bal);
+ if (a->link[0])
+ printf ("l");
+ if (a->link[1])
+ printf ("r");
+ printf (" b:");
+ if (b->link[0])
+ printf ("l");
+ if (b->link[1])
+ printf ("r");
+ printf ("\n");
+ abort ();
+ }
+ if (a->link[0] != NULL)
+ compare_trees (a->link[0], b->link[0]);
+ if (a->link[1] != NULL)
+ compare_trees (a->link[1], b->link[1]);
+}
+
+/* Simple stress test procedure for the AVL tree routines. Does the
+ following:
+
+ * Generate a random number seed. By default this is generated from
+ the current time. You can also pass a seed value on the command
+ line if you want to test the same case. The seed value is
+ displayed.
+
+ * Create a tree and insert the integers from 0 up to TREE_SIZE - 1
+ into it, in random order. Verify the tree structure after each
+ insertion.
+
+ * Remove each integer from the tree, in a different random order.
+ After each deletion, verify the tree structure; also, make a copy
+ of the tree into a new tree, verify the copy and compare it to the
+ original, then destroy the copy.
+
+ * Destroy the tree, increment the random seed value, and start over.
+
+ If you make any modifications to the avl tree routines, then you
+ might want to insert some calls to print_structure() at strategic
+ places in order to be able to see what's really going on. Also,
+ memory debuggers like Checker or Purify are very handy. */
+#define TREE_SIZE 1024
+#define N_ITERATIONS 16
+int
+main (int argc, char **argv)
+{
+ int array[TREE_SIZE];
+ int seed;
+ int iteration;
+
+ if (argc == 2)
+ seed = atoi (argv[1]);
+ else
+ seed = time (0) * 257 % 32768;
+
+ fputs ("Testing avl...\n", stdout);
+
+ for (iteration = 1; iteration <= N_ITERATIONS; iteration++)
+ {
+ avl_tree *tree;
+ int i;
+
+ printf ("Iteration %4d/%4d: seed=%5d", iteration, N_ITERATIONS, seed);
+ fflush (stdout);
+
+ srand (seed++);
+
+ for (i = 0; i < TREE_SIZE; i++)
+ array[i] = i;
+ shuffle (array, TREE_SIZE);
+
+ tree = avl_create (compare_ints, NULL);
+ for (i = 0; i < TREE_SIZE; i++)
+ avl_force_insert (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ shuffle (array, TREE_SIZE);
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ avl_tree *copy;
+
+ avl_delete (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ copy = avl_copy (tree, NULL);
+ verify_tree (copy);
+ compare_trees (tree->root.link[0], copy->root.link[0]);
+ avl_destroy (copy, NULL);
+
+ if (i % 128 == 0)
+ {
+ putchar ('.');
+ fflush (stdout);
+ }
+ }
+ fputs (" good.\n", stdout);
+
+ avl_destroy (tree, NULL);
+ }
+
+ return 0;
+}
+#endif /* SELF_TEST */
+
+/*
+ Local variables:
+ compile-command: "gcc -DSELF_TEST=1 -W -Wall -I. -o ./avl-test avl.c"
+ End:
+*/
+
diff --git a/avl-1.4.0/avl.h b/avl-1.4.0/avl.h
new file mode 100644
index 0000000..436a461
--- /dev/null
+++ b/avl-1.4.0/avl.h
@@ -0,0 +1,148 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file avl.h in libavl. */
+
+#if !avl_h
+#define avl_h 1
+
+/* The default maximum height of 32 allows for AVL trees having
+ between 5,704,880 and 4,294,967,295 nodes, depending on order of
+ insertion. You may change this compile-time constant as you
+ wish. */
+#ifndef AVL_MAX_HEIGHT
+#define AVL_MAX_HEIGHT 32
+#endif
+
+/* Structure for a node in an AVL tree. */
+typedef struct avl_node
+ {
+ void *data; /* Pointer to data. */
+ struct avl_node *link[2]; /* Subtrees. */
+ signed char bal; /* Balance factor. */
+ char cache; /* Used during insertion. */
+ signed char pad[2]; /* Unused. Reserved for threaded trees. */
+ }
+avl_node;
+
+/* Used for traversing an AVL tree. */
+typedef struct avl_traverser
+ {
+ int init; /* Initialized? */
+ int nstack; /* Top of stack. */
+ const avl_node *p; /* Used for traversal. */
+ const avl_node *stack[AVL_MAX_HEIGHT];/* Descended trees. */
+ }
+avl_traverser;
+
+/* Initializer for avl_traverser. */
+#define AVL_TRAVERSER_INIT {0}
+
+/* Function types. */
+#if !AVL_FUNC_TYPES
+#define AVL_FUNC_TYPES 1
+typedef int (*avl_comparison_func) (const void *a, const void *b, void *param);
+typedef void (*avl_node_func) (void *data, void *param);
+typedef void *(*avl_copy_func) (void *data, void *param);
+#endif
+
+/* Structure which holds information about an AVL tree. */
+typedef struct avl_tree
+ {
+#if PSPP
+ struct arena **owner; /* Arena to store nodes. */
+#endif
+ avl_node root; /* Tree root node. */
+ avl_comparison_func cmp; /* Used to compare keys. */
+ int count; /* Number of nodes in the tree. */
+ void *param; /* Arbitary user data. */
+ }
+avl_tree;
+
+#if PSPP
+#define MAYBE_ARENA struct arena **owner,
+#else
+#define MAYBE_ARENA /* nothing */
+#endif
+
+/* General functions. */
+avl_tree *avl_create (MAYBE_ARENA avl_comparison_func, void *param);
+void avl_destroy (avl_tree *, avl_node_func);
+void avl_free (avl_tree *);
+int avl_count (const avl_tree *);
+avl_tree *avl_copy (MAYBE_ARENA const avl_tree *, avl_copy_func);
+
+/* Walk the tree. */
+void avl_walk (const avl_tree *, avl_node_func, void *param);
+void *avl_traverse (const avl_tree *, avl_traverser *);
+#define avl_init_traverser(TRAVERSER) ((TRAVERSER)->init = 0)
+
+/* Search for a given item. */
+void **avl_probe (avl_tree *, void *);
+void *avl_delete (avl_tree *, const void *);
+void *avl_find (const avl_tree *, const void *);
+void *avl_find_close (const avl_tree *, const void *);
+
+#if __GCC__ >= 2
+extern inline void *
+avl_insert (avl_tree *tree, void *item)
+{
+ void **p = avl_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+extern inline void *
+avl_replace (avl_tree *tree, void *item)
+{
+ void **p = avl_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+#else /* not gcc */
+void *avl_insert (avl_tree *tree, void *item);
+void *avl_replace (avl_tree *tree, void *item);
+#endif /* not gcc */
+
+/* Easy assertions on insertion & deletion. */
+#ifndef NDEBUG
+#define avl_force_insert(A, B) \
+ do \
+ { \
+ void *r = avl_insert (A, B); \
+ assert (r == NULL); \
+ } \
+ while (0)
+void *avl_force_delete (avl_tree *, void *);
+#else
+#define avl_force_insert(A, B) \
+ avl_insert (A, B)
+#define avl_force_delete(A, B) \
+ avl_delete (A, B)
+#endif
+
+#endif /* avl_h */
diff --git a/avl-1.4.0/avl.html b/avl-1.4.0/avl.html
new file mode 100644
index 0000000..ef3e51e
--- /dev/null
+++ b/avl-1.4.0/avl.html
@@ -0,0 +1,1046 @@
+<HTML>
+<HEAD>
+<!-- This HTML file has been created by texi2html 1.54
+ from ./avl.texinfo on 6 October 1999 -->
+
+<TITLE>libavl manual</TITLE>
+
+</HEAD>
+<BODY>
+<H1>libavl</H1>
+<H2>A library for manipulation of balanced binary trees</H2>
+<ADDRESS>Ben Pfaff</ADDRESS>
+<P>
+<P><HR><P>
+<H1>Table of Contents</H1>
+<UL>
+<LI><A NAME="TOC1" HREF="avl.html#SEC1">Introduction to balanced binary trees</A>
+<LI><A NAME="TOC2" HREF="avl.html#SEC2">Introduction to threaded trees</A>
+<LI><A NAME="TOC3" HREF="avl.html#SEC3">Types</A>
+<LI><A NAME="TOC4" HREF="avl.html#SEC4">Functions</A>
+<LI><A NAME="TOC5" HREF="avl.html#SEC5">Tree Creation</A>
+<LI><A NAME="TOC6" HREF="avl.html#SEC6">Insertion and Deletion</A>
+<LI><A NAME="TOC7" HREF="avl.html#SEC7">Searching</A>
+<LI><A NAME="TOC8" HREF="avl.html#SEC8">Iteration</A>
+<LI><A NAME="TOC9" HREF="avl.html#SEC9">Conversion</A>
+<LI><A NAME="TOC10" HREF="avl.html#SEC10">Author</A>
+<LI><A NAME="TOC11" HREF="avl.html#SEC11">Index</A>
+</UL>
+<P><HR><P>
+
+
+<H1><A NAME="SEC1" HREF="avl.html#TOC1">Introduction to balanced binary trees</A></H1>
+
+<P>
+<A NAME="IDX1"></A>
+Consider some techniques that can be used to find a particular item in a
+data set. Typical methods include sequential searching, digital
+searching, hash tables, and binary searching.
+
+</P>
+<P>
+Sequential searching is simple, but slow (O(n)). Digital searching
+requires that the entire data set be known in advance, and memory
+efficient implementations are slow.
+
+</P>
+<P>
+Hash tables are fast (O(1)) for static data sets, but they can be
+wasteful of memory. It can be difficult to choose an effective hash
+function. Some hash tables variants also make deletion an expensive
+operation.
+
+</P>
+<P>
+<A NAME="IDX2"></A>
+Binary search techniques work almost as quickly (O(log(n)) on an ordered
+table, or on a binary tree. Binary trees also allow easy iteration over
+the data in the tree in sorted order. With hash tables it is necessary
+to sort the data before iterating, and after sorting the data is no
+longer in hash form.
+
+</P>
+<P>
+Binary trees are efficient for insertion, deletion, and searching, if
+data are inserted in random order. But, if data are inserted in order
+using a naive algorithm, binary search degenerates to sequential search.
+
+</P>
+<P>
+<A NAME="IDX3"></A>
+<A NAME="IDX4"></A>
+<A NAME="IDX5"></A>
+In turn, this problem can be solved by <STRONG>rebalancing</STRONG> the tree after
+each insertion or deletion. In rebalancing, nodes are rearranged via
+transformations called <STRONG>rotations</STRONG> using an algorithm that tends to
+minimize the tree's height.
+
+</P>
+<P>
+There are several schemes for rebalancing binary trees. The two most
+common types of balanced tree are <STRONG>AVL trees</STRONG> and <STRONG>red-black
+trees</STRONG>. libavl implements both types:
+
+</P>
+
+<UL>
+<LI>
+
+<A NAME="IDX6"></A>
+<A NAME="IDX7"></A>
+AVL trees, invented by Russian mathematicians G. M. Adel'son-Velskii and
+E. M. Landis, ensure that, for each node, the difference in height
+between its subtrees (the <STRONG>balance factor</STRONG>) is not greater than 1.
+
+<LI>
+
+Red-black trees, invented by R. Bayer and studied at length by
+L. J. Guibas and R. Sedgewick, assign each node of a tree a color (red
+or black), and specify a set of rules governing how red and black nodes
+may be arranged.
+</UL>
+
+<P>
+The table below presents a comparison among unbalanced binary trees, AVL
+trees, and red-black trees. In the table, <VAR>n</VAR> is the number of
+nodes in the tree and <VAR>h</VAR> is the tree's height before the
+operation. <STRONG>lg</STRONG> is the base-2 logarithm function.
+
+</P>
+<TABLE>
+
+<TR>Operation
+<BR>
+<TR>
+<TD> Binary Tree
+<TD> AVL Tree
+<TD> Red-Black Tree
+
+<BR>
+<TR>Time per insertion or deletion
+<BR>
+<TR>
+<TD> O(<VAR>h</VAR>)
+<TD> O(lg <VAR>n</VAR>)
+<TD> O(lg <VAR>n</VAR>)
+
+<BR>
+<TR>Time for insertion of <VAR>k</VAR> nodes having sequential values
+<BR>
+<TR>
+<TD> O(<VAR>k</VAR>^2)
+<TD> O(<VAR>n</VAR> lg <VAR>n</VAR>)
+<TD> O(<VAR>n</VAR> lg <VAR>n</VAR>)
+
+<BR>
+<TR>Time for insertion of <VAR>k</VAR> nodes having random values
+<BR>
+<TR>
+<TD> O(<VAR>n</VAR> lg <VAR>n</VAR>)
+<TD> O(<VAR>n</VAR> lg <VAR>n</VAR>)
+<TD> O(<VAR>n</VAR> lg <VAR>n</VAR>)
+
+<BR>
+<TR>Maximum number of rotations per insertion
+<BR>
+<TR>
+<TD> 0
+<TD> 1
+<TD> lg <VAR>n</VAR>
+
+<BR>
+<TR>Maximum number of rotations per deletion
+<BR>
+<TR>
+<TD> 0
+<TD> lg <VAR>n</VAR>
+<TD> lg <VAR>n</VAR>
+
+<BR>
+<TR>Maximum <VAR>h</VAR> as a function of <VAR>n</VAR>
+<BR>
+<TR>
+<TD> <VAR>n</VAR>
+<TD> 1.44 lg (<VAR>n</VAR> + 2) - .328
+<TD> 2 lg (<VAR>n</VAR> + 1)
+
+<BR>
+<TR>Minimum <VAR>n</VAR> as a function of <VAR>h</VAR>
+<BR>
+<TR>
+<TD> <VAR>h</VAR>
+<TD> 2^((<VAR>h</VAR> + .328) / 1.44) - 2
+<TD> 2^(<VAR>h</VAR> / 2) - 1
+</TABLE>
+
+There are alternatives to AVL trees that share some of their properties.
+For instance, skip lists, 2-3 trees, and splay trees all allow O(log(n))
+insertion and deletion. The main disadvantage of these methods is that
+their operations are not as well documented in the literature.
+
+
+
+<H1><A NAME="SEC2" HREF="avl.html#TOC2">Introduction to threaded trees</A></H1>
+
+<P>
+<STRONG>Threading</STRONG> is a clever method that simplifies binary tree
+traversal.
+
+</P>
+<P>
+Nodes in a unthreaded binary tree that have zero or one subnodes have
+two or one null subnode pointers, respectively. In a threaded binary
+tree, a left child pointer that would otherwise be null is used to point
+to the node's inorder<A NAME="DOCF1" HREF="avl.html#FOOT1">(1)</A>
+predecessor, and in a null right child pointer points to its inorder
+successor.
+
+</P>
+<P>
+In a threaded tree, it is always possible to find the next node and the
+previous node of a node, given only a pointer to the node in question.
+In an unthreaded tree, it's also necessary to have a list of the nodes
+between the node in question and root of the tree.
+
+</P>
+<P>
+Advantages of a threaded tree compared to an unthreaded one include:
+
+</P>
+
+<UL>
+<LI>
+
+Faster traversal and less memory usage during traversal, since no stack
+need be maintained.
+
+<LI>
+
+Greater generality, since one can go from a node to its successor or
+predecessor given only the node, simplifying algorithms that require
+moving forward and backward in a tree.
+</UL>
+
+<P>
+Some disadvantages of threaded trees are:
+
+</P>
+
+<UL>
+<LI>
+
+Slower insertion and deletion, since threads need to be maintained. In
+somes cases, this can be alleviated by constructing the tree as an
+unthreaded tree, then threading it with a special libavl function.
+
+<LI>
+
+In theory, threaded trees need two extra bits per node to indicate
+whether each child pointer points to an ordinary node or the node's
+successor/predecessor node. In libavl, however, these bits are stored
+in a byte that is used for structure alignment padding in unthreaded
+binary trees, so no extra storage is used.
+</UL>
+
+<P>
+A <STRONG>right-threaded binary tree</STRONG> is similar to a threaded binary tree,
+but threads are only maintained on the right side of each node. This
+allows for traversal to the right (toward larger values) but not to the
+left (toward smaller values). Right-threaded trees are convenient when
+the properties of a threaded tree are desirable, but traversal in
+reverse sort order is not necessary. Not threading the left links saves
+time in insertions and deletions.
+
+</P>
+<P>
+Left-threaded binary trees also exist, but they are not implemented by
+libavl. The same effect can be obtained by sorting the tree in the
+opposite order.
+
+</P>
+
+
+<H1><A NAME="SEC3" HREF="avl.html#TOC3">Types</A></H1>
+
+<P>
+The following types are defined and used by libavl:
+
+</P>
+<P>
+<DL>
+<DT><U>Data Type:</U> <B>avl_tree</B>
+<DD><A NAME="IDX8"></A>
+<DT><U>Data Type:</U> <B>avlt_tree</B>
+<DD><A NAME="IDX9"></A>
+<DT><U>Data Type:</U> <B>avltr_tree</B>
+<DD><A NAME="IDX10"></A>
+<DT><U>Data Type:</U> <B>rb_tree</B>
+<DD><A NAME="IDX11"></A>
+These are the data types used to represent a tree. Although they are
+defined in the libavl header files, it should never be necessary to
+access them directly. Instead, all accesses should take place through
+libavl functions.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Data Type:</U> <B>avl_node</B>
+<DD><A NAME="IDX12"></A>
+<DT><U>Data Type:</U> <B>avlt_node</B>
+<DD><A NAME="IDX13"></A>
+<DT><U>Data Type:</U> <B>avltr_node</B>
+<DD><A NAME="IDX14"></A>
+<DT><U>Data Type:</U> <B>rb_node</B>
+<DD><A NAME="IDX15"></A>
+These are the data types used to represent individual nodes in a tree.
+Similar cautions apply as with <CODE>avl_tree</CODE> structures.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Data Type:</U> <B>avl_traverser</B>
+<DD><A NAME="IDX16"></A>
+<DT><U>Data Type:</U> <B>avlt_traverser</B>
+<DD><A NAME="IDX17"></A>
+<DT><U>Data Type:</U> <B>avltr_traverser</B>
+<DD><A NAME="IDX18"></A>
+<DT><U>Data Type:</U> <B>rb_traverser</B>
+<DD><A NAME="IDX19"></A>
+These are the data types used by the <CODE>avl_traverse</CODE> family of
+functions to iterate across the tree. Again, these are opaque
+structures.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Data Type:</U> <B>avl_comparison_func</B>
+<DD><A NAME="IDX20"></A>
+Every tree must have an ordering defined by a function of this type. It
+must have the following signature:
+
+</P>
+
+<PRE>
+int <VAR>compare</VAR> (const void *<VAR>a</VAR>, const void *<VAR>b</VAR>, void *<VAR>param</VAR>)
+</PRE>
+
+<P>
+The return value is expected to be like that returned by <CODE>strcmp</CODE>
+in the standard C library: negative if <VAR>a</VAR> &#60; <VAR>b</VAR>, zero if
+<VAR>a</VAR> = <VAR>b</VAR>, positive if <VAR>a</VAR> &#62; <VAR>b</VAR>. <VAR>param</VAR> is an
+arbitrary value defined by the user when the tree was created.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Data Type:</U> <B>avl_node_func</B>
+<DD><A NAME="IDX21"></A>
+This is a class of function called to perform an operation on a data
+item. Functions of this type have the following signature:
+
+</P>
+
+<PRE>
+void <VAR>operate</VAR> (void *<VAR>data</VAR>, void *<VAR>param</VAR>)
+</PRE>
+
+<P>
+<VAR>data</VAR> is the data item and <VAR>param</VAR> is an arbitrary user-defined
+value set when the tree was created.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Data Type:</U> <B>avl_copy_func</B>
+<DD><A NAME="IDX22"></A>
+
+</P>
+<P>
+This is a class of function called to make a new copy of a node's data.
+Functions of this type have the following signature:
+
+</P>
+
+<PRE>
+void *<VAR>copy</VAR> (void *<VAR>data</VAR>, void *<VAR>param</VAR>)
+</PRE>
+
+<P>
+The function should return a new copy of <VAR>data</VAR>. <VAR>param</VAR> is an
+arbitrary user-defined value set when the tree was created.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Macro:</U> <B>AVL_MAX_HEIGHT</B>
+<DD><A NAME="IDX23"></A>
+This macro defines the maximum height of an AVL tree that can be handled
+by functions that maintain a stack of nodes descended. The default
+value is 32, which allows for AVL trees with a maximum number of nodes
+between 5,704,880 and 4,294,967,295, depending on order of insertion.
+This macro may be defined by the user before including any AVL tree
+header file, in which case libavl will honor that value.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Macro:</U> <B>RB_MAX_HEIGHT</B>
+<DD><A NAME="IDX24"></A>
+This macro defines the maximum height of an AVL tree that can be handled
+by functions that maintain a stack of nodes descended. The default
+value is 32, which allows for red-black trees with a maximum number of
+nodes of at least 65535. This macro may be defined by the user before
+including the red-black tree header file, in which case libavl will
+honor that value.
+</DL>
+
+</P>
+
+
+<H1><A NAME="SEC4" HREF="avl.html#TOC4">Functions</A></H1>
+
+<P>
+<A NAME="IDX25"></A>
+<A NAME="IDX26"></A>
+<A NAME="IDX27"></A>
+libavl is four libraries in one:
+
+</P>
+
+<UL>
+<LI>
+
+An unthreaded AVL tree library.
+
+<LI>
+
+A threaded AVL tree library.
+
+<LI>
+
+A right-threaded AVL tree library.
+
+<LI>
+
+A red-black tree library.
+</UL>
+
+<P>
+Identifiers in these libraries are prefixed by <CODE>avl_</CODE>,
+<CODE>avlt_</CODE>, <CODE>avltr_</CODE>, and <CODE>rb_</CODE>, with corresponding header
+files <TT>`avl.h'</TT>, <TT>`avlt.h'</TT>, <TT>`avltr.h'</TT>, and <TT>`rb.h'</TT>,
+respectively. The functions that they declare are defined in the
+<TT>`.c'</TT> files with the same names.
+
+</P>
+<P>
+Most tree functions are implemented in all three libraries, but
+threading allows more generality of operation. So, the threaded and
+right-threaded libraries offer a few additional functions for finding
+the next or previous node from a given node. In addition, they offer
+functions for converting trees from threaded or right-threaded
+representations to unthreaded, and vice versa.<A NAME="DOCF2" HREF="avl.html#FOOT2">(2)</A>
+
+</P>
+
+
+<H1><A NAME="SEC5" HREF="avl.html#TOC5">Tree Creation</A></H1>
+
+<P>
+These functions deal with creation and destruction of AVL trees.
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> avl_tree * <B>avl_create</B> <I>(avl_comparison_func <VAR>compare</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX28"></A>
+<DT><U>Function:</U> avlt_tree * <B>avlt_create</B> <I>(avlt_comparison_func <VAR>compare</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX29"></A>
+<DT><U>Function:</U> avltr_tree * <B>avltr_create</B> <I>(avltr_comparison_func <VAR>compare</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX30"></A>
+<DT><U>Function:</U> rb_tree * <B>rb_create</B> <I>(avl_comparison_func <VAR>compare</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX31"></A>
+Create a new, empty tree with comparison function <VAR>compare</VAR>.
+Arbitrary user data <VAR>param</VAR> is saved so that it can be passed to
+user callback functions.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void <B>avl_destroy</B> <I>(avl_tree *<VAR>tree</VAR>, avl_node_func <VAR>free</VAR>)</I>
+<DD><A NAME="IDX32"></A>
+<DT><U>Function:</U> void <B>avlt_destroy</B> <I>(avlt_tree *<VAR>tree</VAR>, avl_node_func <VAR>free</VAR>)</I>
+<DD><A NAME="IDX33"></A>
+<DT><U>Function:</U> void <B>avltr_destroy</B> <I>(avltr_tree *<VAR>tree</VAR>, avl_node_func <VAR>free</VAR>)</I>
+<DD><A NAME="IDX34"></A>
+<DT><U>Function:</U> void <B>rb_destroy</B> <I>(rb_tree *<VAR>tree</VAR>, avl_node_func <VAR>free</VAR>)</I>
+<DD><A NAME="IDX35"></A>
+Destroys <VAR>tree</VAR>, releasing all of its storage. If <VAR>free</VAR> is
+non-null, then it is called for every node in postorder before that node
+is freed.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void <B>avl_free</B> <I>(avl_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX36"></A>
+<DT><U>Function:</U> void <B>avlt_free</B> <I>(avlt_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX37"></A>
+<DT><U>Function:</U> void <B>avltr_free</B> <I>(avltr_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX38"></A>
+<DT><U>Function:</U> void <B>rb_free</B> <I>(rb_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX39"></A>
+Destroys <VAR>tree</VAR>, releasing all of its storage. The data in each
+node is freed with a call to the standard C library function
+<CODE>free</CODE>.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> avl_tree * <B>avl_copy</B> <I>(const avl_tree *<VAR>tree</VAR>, avl_copy_func <VAR>copy</VAR>)</I>
+<DD><A NAME="IDX40"></A>
+<DT><U>Function:</U> avlt_tree * <B>avl_copy</B> <I>(const avlt_tree *<VAR>tree</VAR>, avl_copy_func <VAR>copy</VAR>)</I>
+<DD><A NAME="IDX41"></A>
+<DT><U>Function:</U> avltr_tree * <B>avl_copy</B> <I>(const avltr_tree *<VAR>tree</VAR>, avl_copy_func <VAR>copy</VAR>)</I>
+<DD><A NAME="IDX42"></A>
+<DT><U>Function:</U> rb_tree * <B>rb_copy</B> <I>(const rb_tree *<VAR>tree</VAR>, avl_copy_func <VAR>copy</VAR>)</I>
+<DD><A NAME="IDX43"></A>
+Copies the contents of <VAR>tree</VAR> into a new tree, and returns the new
+tree. If <VAR>copy</VAR> is non-null, then it is called to make a new copy
+of each node's data; otherwise, the node data is copied verbatim into
+the new tree.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> int <B>avl_count</B> <I>(const avl_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX44"></A>
+<DT><U>Function:</U> int <B>avlt_count</B> <I>(const avlt_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX45"></A>
+<DT><U>Function:</U> int <B>avltr_count</B> <I>(const avltr_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX46"></A>
+<DT><U>Function:</U> int <B>rb_count</B> <I>(const rb_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX47"></A>
+Returns the number of nodes in <VAR>tree</VAR>.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>xmalloc</B> <I>(size_t <VAR>size</VAR>)</I>
+<DD><A NAME="IDX48"></A>
+This is not a function defined by libavl. Instead, it is a function
+that the user program can define. It must allocate <VAR>size</VAR> bytes
+using <CODE>malloc</CODE> and return it. It can handle out-of-memory errors
+however it chooses, but it may not ever return a null pointer.
+
+</P>
+<P>
+If there is an <CODE>xmalloc</CODE> function defined for use by libavl, the
+source files (<TT>`avl.c'</TT>, <TT>`avlt.c'</TT>, <TT>`avltr.c'</TT>, <TT>`rb.c'</TT>)
+must be compiled with <CODE>HAVE_XMALLOC</CODE> defined. Otherwise, the
+library will use its internal static <CODE>xmalloc</CODE>, which handles
+out-of-memory errors by printing a message <SAMP>`virtual memory
+exhausted'</SAMP> to stderr and terminating the program with exit code
+<CODE>EXIT_FAILURE</CODE>.
+</DL>
+
+</P>
+
+
+<H1><A NAME="SEC6" HREF="avl.html#TOC6">Insertion and Deletion</A></H1>
+
+<P>
+These function insert nodes, delete nodes, and search for nodes in
+trees.
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void ** <B>avl_probe</B> <I>(avl_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX49"></A>
+<DT><U>Function:</U> void ** <B>avlt_probe</B> <I>(avlt_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX50"></A>
+<DT><U>Function:</U> void ** <B>avltr_probe</B> <I>(avltr_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX51"></A>
+<DT><U>Function:</U> void ** <B>rb_probe</B> <I>(rb_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX52"></A>
+These are the workhorse functions for tree insertion. They search
+<VAR>tree</VAR> for a node with data matching <VAR>data</VAR>. If found, a
+pointer to the matching data is returned. Otherwise, a new node is
+created for <VAR>data</VAR>, and a pointer to that data is returned. In
+either case, the pointer returned can be changed by the user, but the
+key data used by the tree's comparison must not be changed<A NAME="DOCF3" HREF="avl.html#FOOT3">(3)</A>.
+
+</P>
+<P>
+It is usually easier to use one of the <CODE>avl_insert</CODE> or
+<CODE>avl_replace</CODE> functions instead of <CODE>avl_probe</CODE> directly.
+
+</P>
+<P>
+<STRONG>Please note:</STRONG> It's not a particularly good idea to insert a null
+pointer as a data item into a tree, because several libavl functions
+return a null pointer to indicate failure. You can sometimes avoid a
+problem by using functions that return a pointer to a pointer instead of
+a plain pointer. Also be wary of this when casting an arithmetic type
+to a void pointer for insertion--on typical architectures, 0's become
+null pointers when this is done.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_insert</B> <I>(avl_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX53"></A>
+<DT><U>Function:</U> void * <B>avlt_insert</B> <I>(avlt_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX54"></A>
+<DT><U>Function:</U> void * <B>avltr_insert</B> <I>(avltr_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX55"></A>
+<DT><U>Function:</U> void * <B>rb_insert</B> <I>(rb_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX56"></A>
+If a node with data matching <VAR>data</VAR> exists in <VAR>tree</VAR>, returns
+the matching data item. Otherwise, inserts <VAR>data</VAR> into <VAR>tree</VAR>
+and returns a null pointer.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void <B>avl_force_insert</B> <I>(avl_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX57"></A>
+<DT><U>Function:</U> void <B>avlt_force_insert</B> <I>(avlt_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX58"></A>
+<DT><U>Function:</U> void <B>avltr_force_insert</B> <I>(avltr_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX59"></A>
+<DT><U>Function:</U> void <B>rb_force_insert</B> <I>(rb_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX60"></A>
+Inserts <VAR>data</VAR> into <VAR>tree</VAR>. If a node with data matching
+<VAR>data</VAR> exists in <VAR>tree</VAR>, aborts the program with an assertion
+violation. This function is implemented as a macro; if it is used, the
+standard C header <CODE>assert.h</CODE> must also be included. If macro
+<CODE>NDEBUG</CODE> is defined when a libavl header is included, these
+functions are short-circuited to a direct call to <CODE>avl_insert</CODE>,
+and no check is performed.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_replace</B> <I>(avl_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX61"></A>
+<DT><U>Function:</U> void * <B>avlt_replace</B> <I>(avlt_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX62"></A>
+<DT><U>Function:</U> void * <B>avltr_replace</B> <I>(avltr_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX63"></A>
+<DT><U>Function:</U> void * <B>rb_replace</B> <I>(rb_tree *<VAR>tree</VAR>, void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX64"></A>
+If a node with data matching <VAR>data</VAR>, such that the comparison
+function returns 0, exists in <VAR>tree</VAR>, replaces the node's data with
+<VAR>data</VAR> and returns the node's former contents. Otherwise, inserts
+<VAR>data</VAR> into <VAR>tree</VAR> and returns a null pointer.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_delete</B> <I>(avl_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX65"></A>
+<DT><U>Function:</U> void * <B>avlt_delete</B> <I>(avlt_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX66"></A>
+<DT><U>Function:</U> void * <B>avltr_delete</B> <I>(avltr_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX67"></A>
+<DT><U>Function:</U> void * <B>rb_delete</B> <I>(rb_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX68"></A>
+Searches <VAR>tree</VAR> for a node with data matching <VAR>data</VAR>. If found,
+the node is deleted and its data is returned. Otherwise, returns a null
+pointer.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_force_delete</B> <I>(avl_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX69"></A>
+<DT><U>Function:</U> void * <B>avlt_force_delete</B> <I>(avlt_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX70"></A>
+<DT><U>Function:</U> void * <B>avltr_force_delete</B> <I>(avltr_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX71"></A>
+<DT><U>Function:</U> void * <B>rb_force_delete</B> <I>(rb_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX72"></A>
+Deletes a node with data matching <VAR>data</VAR> from <VAR>tree</VAR>. If no
+matching node is found, aborts the program with an assertion violation.
+If macro <CODE>NDEBUG</CODE> is declared when a libavl header is included,
+these functions are short-circuited to a direct call to
+<CODE>avl_delete</CODE>, and no check is performed.
+</DL>
+
+</P>
+
+
+<H1><A NAME="SEC7" HREF="avl.html#TOC7">Searching</A></H1>
+
+<P>
+These function search a tree for an item without making an insertion or
+a deletion.
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_find</B> <I>(avl_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX73"></A>
+<DT><U>Function:</U> void ** <B>avlt_find</B> <I>(avlt_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX74"></A>
+<DT><U>Function:</U> void ** <B>avltr_find</B> <I>(avltr_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX75"></A>
+<DT><U>Function:</U> void * <B>rb_find</B> <I>(rb_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX76"></A>
+Searches <VAR>tree</VAR> for a node with data matching <VAR>data</VAR>, If found,
+returns the node's data (for threaded and right-threaded trees, a
+pointer to the node's data). Otherwise, returns a null pointer.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_find_close</B> <I>(avl_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX77"></A>
+<DT><U>Function:</U> void ** <B>avlt_find_close</B> <I>(avlt_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX78"></A>
+<DT><U>Function:</U> void ** <B>avltr_find_close</B> <I>(avltr_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX79"></A>
+<DT><U>Function:</U> void * <B>rb_find_close</B> <I>(rb_tree *<VAR>tree</VAR>, const void *<VAR>data</VAR>)</I>
+<DD><A NAME="IDX80"></A>
+Searches <VAR>tree</VAR> for a node with data matching <VAR>data</VAR>. If found,
+returns the node's data (for threaded and right-threaded trees, a
+pointer to the node's data). If no matching item is found, then it
+finds a node whose data is "close" to <VAR>data</VAR>; either the node
+closest in value to <VAR>data</VAR>, or the node either before or after the
+node with the closest value. Returns a null pointer if the tree does
+not contain any nodes.
+</DL>
+
+</P>
+
+
+<H1><A NAME="SEC8" HREF="avl.html#TOC8">Iteration</A></H1>
+
+<P>
+These functions allow the caller to iterate across the items in a tree.
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void <B>avl_walk</B> <I>(const avl_tree *<VAR>tree</VAR>, avl_node_func <VAR>operate</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX81"></A>
+<DT><U>Function:</U> void <B>avlt_walk</B> <I>(const avlt_tree *<VAR>tree</VAR>, avl_node_func <VAR>operate</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX82"></A>
+<DT><U>Function:</U> void <B>avltr_walk</B> <I>(const avltr_tree *<VAR>tree</VAR>, avl_node_func <VAR>operate</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX83"></A>
+<DT><U>Function:</U> void <B>rb_walk</B> <I>(const rb_tree *<VAR>tree</VAR>, avl_node_func <VAR>operate</VAR>, void *<VAR>param</VAR>)</I>
+<DD><A NAME="IDX84"></A>
+Walks through all the nodes in <VAR>tree</VAR>, and calls function
+<VAR>operate</VAR> for each node in inorder. <VAR>param</VAR> overrides the value
+passed to <CODE>avl_create</CODE> (and family) for this operation only.
+<VAR>operate</VAR> must not change the key data in the nodes in a way that
+would reorder the data values or cause two values to become equal.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_traverse</B> <I>(const avl_tree *<VAR>tree</VAR>, avl_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX85"></A>
+<DT><U>Function:</U> void * <B>avlt_traverse</B> <I>(const avlt_tree *<VAR>tree</VAR>, avlt_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX86"></A>
+<DT><U>Function:</U> void * <B>avltr_traverse</B> <I>(const avltr_tree *<VAR>tree</VAR>, avltr_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX87"></A>
+<DT><U>Function:</U> void * <B>rb_traverse</B> <I>(const rb_tree *<VAR>tree</VAR>, rb_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX88"></A>
+Returns each of <VAR>tree</VAR>'s nodes' data values in sequence, then a null
+pointer to indicate the last item. <VAR>trav</VAR> must be initialized
+before the first call, either in a declaration like that below, or using
+one of the functions below.
+
+</P>
+
+<PRE>
+avl_traverser trav = AVL_TRAVERSER_INIT;
+</PRE>
+
+<P>
+Each <CODE>avl_traverser</CODE> (and family) is a separate, independent
+iterator.
+
+</P>
+<P>
+For threaded and right-threaded trees, <CODE>avlt_next</CODE> or
+<CODE>avltr_next</CODE>, respectively, are faster and more memory-efficient
+than <CODE>avlt_traverse</CODE> or <CODE>avltr_traverse</CODE>.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void * <B>avl_init_traverser</B> <I>(avl_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX89"></A>
+<DT><U>Function:</U> void * <B>avlt_init_traverser</B> <I>(avlt_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX90"></A>
+<DT><U>Function:</U> void * <B>avltr_init_traverser</B> <I>(avltr_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX91"></A>
+<DT><U>Function:</U> void * <B>rb_init_traverser</B> <I>(rb_traverser *<VAR>trav</VAR>)</I>
+<DD><A NAME="IDX92"></A>
+Initializes the specified tree traverser structure. After this function
+is called, the next call to the corresponding <CODE>*_traverse</CODE> function
+will return the smallest value in the appropriate tree.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void ** <B>avlt_next</B> <I>(const avlt_tree *<VAR>tree</VAR>, void **<VAR>data</VAR>)</I>
+<DD><A NAME="IDX93"></A>
+<DT><U>Function:</U> void ** <B>avltr_next</B> <I>(const avltr_tree *<VAR>tree</VAR>, void **<VAR>data</VAR>)</I>
+<DD><A NAME="IDX94"></A>
+<VAR>data</VAR> must be a null pointer or a pointer to a data item in AVL
+tree <VAR>tree</VAR>. Returns a pointer to the next data item after
+<VAR>data</VAR> in <VAR>tree</VAR> in inorder (this is the first item if
+<VAR>data</VAR> is a null pointer), or a null pointer if <VAR>data</VAR> was the
+last item in <VAR>tree</VAR>.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> void ** <B>avltr_prev</B> <I>(const avltr_tree *<VAR>tree</VAR>, void **<VAR>data</VAR>)</I>
+<DD><A NAME="IDX95"></A>
+<VAR>data</VAR> must be a null pointer or a pointer to a data item in AVL
+tree <VAR>tree</VAR>. Returns a pointer to the previous data item before
+<VAR>data</VAR> in <VAR>tree</VAR> in inorder (this is the last, or greatest
+valued, item if <VAR>data</VAR> is a null pointer), or a null pointer if
+<VAR>data</VAR> was the first item in <VAR>tree</VAR>.
+</DL>
+
+</P>
+
+
+<H1><A NAME="SEC9" HREF="avl.html#TOC9">Conversion</A></H1>
+
+<P>
+<DL>
+<DT><U>Function:</U> avlt_tree * <B>avlt_thread</B> <I>(avl_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX96"></A>
+<DT><U>Function:</U> avltr_tree * <B>avltr_thread</B> <I>(avl_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX97"></A>
+Adds symmetric threads or right threads, respectively, to unthreaded AVL
+tree <VAR>tree</VAR> and returns a pointer to <VAR>tree</VAR> cast to the
+appropriate type. After one of these functions is called, threaded or
+right-threaded functions, as appropriate, must be used with <VAR>tree</VAR>;
+unthreaded functions may not be used.
+</DL>
+
+</P>
+<P>
+<DL>
+<DT><U>Function:</U> avl_tree * <B>avlt_unthread</B> <I>(avlt_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX98"></A>
+<DT><U>Function:</U> avl_tree * <B>avltr_unthread</B> <I>(avltr_tree *<VAR>tree</VAR>)</I>
+<DD><A NAME="IDX99"></A>
+Cuts all threads in threaded or right-threaded, respectively, AVL tree
+<VAR>tree</VAR> and returns a pointer to <VAR>tree</VAR> cast to <CODE>avl_tree
+*</CODE>. After one of these functions is called, unthreaded functions must
+be used with <VAR>tree</VAR>; threaded or right-threaded functions may not be
+used.
+</DL>
+
+</P>
+
+
+<H1><A NAME="SEC10" HREF="avl.html#TOC10">Author</A></H1>
+
+<P>
+<A NAME="IDX100"></A>
+<A NAME="IDX101"></A>
+<A NAME="IDX102"></A>
+<A NAME="IDX103"></A>
+libavl was written by Ben Pfaff <A HREF="mailto:blp@gnu.org"><TT>blp@gnu.org</TT></A>.
+
+</P>
+<P>
+libavl's generic tree algorithms and AVL algorithms are based on those
+found in Donald Knuth's venerable <CITE>Art of Computer Programming</CITE>
+series from Addison-Wesley, primarily Volumes 1 and 3. libavl's
+red-black tree algorithms are based on those found in Cormen et al.,
+<CITE>Introduction to Algorithms</CITE>, 2nd ed., from MIT Press.
+
+</P>
+
+
+<H1><A NAME="SEC11" HREF="avl.html#TOC11">Index</A></H1>
+
+<P>
+<H2>a</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX7">Adel'son-Velskii, G. M.</A>
+<LI><A HREF="avl.html#IDX103"><CITE>Art of Computer Programming</CITE></A>
+<LI><A HREF="avl.html#IDX101">author</A>
+<LI><A HREF="avl.html#IDX4">AVL tree</A>
+<LI><A HREF="avl.html#IDX20">avl_comparison_func</A>
+<LI><A HREF="avl.html#IDX40">avl_copy</A>, <A HREF="avl.html#IDX41">avl_copy</A>, <A HREF="avl.html#IDX42">avl_copy</A>
+<LI><A HREF="avl.html#IDX22">avl_copy_func</A>
+<LI><A HREF="avl.html#IDX44">avl_count</A>
+<LI><A HREF="avl.html#IDX28">avl_create</A>
+<LI><A HREF="avl.html#IDX65">avl_delete</A>
+<LI><A HREF="avl.html#IDX32">avl_destroy</A>
+<LI><A HREF="avl.html#IDX73">avl_find</A>
+<LI><A HREF="avl.html#IDX77">avl_find_close</A>
+<LI><A HREF="avl.html#IDX69">avl_force_delete</A>
+<LI><A HREF="avl.html#IDX57">avl_force_insert</A>
+<LI><A HREF="avl.html#IDX36">avl_free</A>
+<LI><A HREF="avl.html#IDX89">avl_init_traverser</A>
+<LI><A HREF="avl.html#IDX53">avl_insert</A>
+<LI><A HREF="avl.html#IDX23">AVL_MAX_HEIGHT</A>
+<LI><A HREF="avl.html#IDX12">avl_node</A>
+<LI><A HREF="avl.html#IDX21">avl_node_func</A>
+<LI><A HREF="avl.html#IDX49">avl_probe</A>
+<LI><A HREF="avl.html#IDX61">avl_replace</A>
+<LI><A HREF="avl.html#IDX85">avl_traverse</A>
+<LI><A HREF="avl.html#IDX16">avl_traverser</A>
+<LI><A HREF="avl.html#IDX8">avl_tree</A>
+<LI><A HREF="avl.html#IDX81">avl_walk</A>
+<LI><A HREF="avl.html#IDX45">avlt_count</A>
+<LI><A HREF="avl.html#IDX29">avlt_create</A>
+<LI><A HREF="avl.html#IDX66">avlt_delete</A>
+<LI><A HREF="avl.html#IDX33">avlt_destroy</A>
+<LI><A HREF="avl.html#IDX74">avlt_find</A>
+<LI><A HREF="avl.html#IDX78">avlt_find_close</A>
+<LI><A HREF="avl.html#IDX70">avlt_force_delete</A>
+<LI><A HREF="avl.html#IDX58">avlt_force_insert</A>
+<LI><A HREF="avl.html#IDX37">avlt_free</A>
+<LI><A HREF="avl.html#IDX90">avlt_init_traverser</A>
+<LI><A HREF="avl.html#IDX54">avlt_insert</A>
+<LI><A HREF="avl.html#IDX93">avlt_next</A>
+<LI><A HREF="avl.html#IDX13">avlt_node</A>
+<LI><A HREF="avl.html#IDX50">avlt_probe</A>
+<LI><A HREF="avl.html#IDX62">avlt_replace</A>
+<LI><A HREF="avl.html#IDX96">avlt_thread</A>
+<LI><A HREF="avl.html#IDX86">avlt_traverse</A>
+<LI><A HREF="avl.html#IDX17">avlt_traverser</A>
+<LI><A HREF="avl.html#IDX9">avlt_tree</A>
+<LI><A HREF="avl.html#IDX98">avlt_unthread</A>
+<LI><A HREF="avl.html#IDX82">avlt_walk</A>
+<LI><A HREF="avl.html#IDX46">avltr_count</A>
+<LI><A HREF="avl.html#IDX30">avltr_create</A>
+<LI><A HREF="avl.html#IDX67">avltr_delete</A>
+<LI><A HREF="avl.html#IDX34">avltr_destroy</A>
+<LI><A HREF="avl.html#IDX75">avltr_find</A>
+<LI><A HREF="avl.html#IDX79">avltr_find_close</A>
+<LI><A HREF="avl.html#IDX71">avltr_force_delete</A>
+<LI><A HREF="avl.html#IDX59">avltr_force_insert</A>
+<LI><A HREF="avl.html#IDX38">avltr_free</A>
+<LI><A HREF="avl.html#IDX91">avltr_init_traverser</A>
+<LI><A HREF="avl.html#IDX55">avltr_insert</A>
+<LI><A HREF="avl.html#IDX94">avltr_next</A>
+<LI><A HREF="avl.html#IDX14">avltr_node</A>
+<LI><A HREF="avl.html#IDX95">avltr_prev</A>
+<LI><A HREF="avl.html#IDX51">avltr_probe</A>
+<LI><A HREF="avl.html#IDX63">avltr_replace</A>
+<LI><A HREF="avl.html#IDX97">avltr_thread</A>
+<LI><A HREF="avl.html#IDX87">avltr_traverse</A>
+<LI><A HREF="avl.html#IDX18">avltr_traverser</A>
+<LI><A HREF="avl.html#IDX10">avltr_tree</A>
+<LI><A HREF="avl.html#IDX99">avltr_unthread</A>
+<LI><A HREF="avl.html#IDX83">avltr_walk</A>
+</DIR>
+<H2>b</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX2">binary tree</A>
+</DIR>
+<H2>h</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX1">hash table</A>
+</DIR>
+<H2>k</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX102">Knuth, Donald Ervin</A>
+</DIR>
+<H2>l</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX6">Landis, E. M.</A>
+</DIR>
+<H2>p</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX100">Pfaff, Benjamin Levy</A>
+</DIR>
+<H2>r</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX43">rb_copy</A>
+<LI><A HREF="avl.html#IDX47">rb_count</A>
+<LI><A HREF="avl.html#IDX31">rb_create</A>
+<LI><A HREF="avl.html#IDX68">rb_delete</A>
+<LI><A HREF="avl.html#IDX35">rb_destroy</A>
+<LI><A HREF="avl.html#IDX76">rb_find</A>
+<LI><A HREF="avl.html#IDX80">rb_find_close</A>
+<LI><A HREF="avl.html#IDX72">rb_force_delete</A>
+<LI><A HREF="avl.html#IDX60">rb_force_insert</A>
+<LI><A HREF="avl.html#IDX39">rb_free</A>
+<LI><A HREF="avl.html#IDX92">rb_init_traverser</A>
+<LI><A HREF="avl.html#IDX56">rb_insert</A>
+<LI><A HREF="avl.html#IDX24">RB_MAX_HEIGHT</A>
+<LI><A HREF="avl.html#IDX15">rb_node</A>
+<LI><A HREF="avl.html#IDX52">rb_probe</A>
+<LI><A HREF="avl.html#IDX64">rb_replace</A>
+<LI><A HREF="avl.html#IDX88">rb_traverse</A>
+<LI><A HREF="avl.html#IDX19">rb_traverser</A>
+<LI><A HREF="avl.html#IDX11">rb_tree</A>
+<LI><A HREF="avl.html#IDX84">rb_walk</A>
+<LI><A HREF="avl.html#IDX5">rebalancing</A>
+<LI><A HREF="avl.html#IDX3">red-black tree</A>
+<LI><A HREF="avl.html#IDX27">right threads</A>
+</DIR>
+<H2>t</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX26">threads</A>
+</DIR>
+<H2>u</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX25">unthreaded</A>
+</DIR>
+<H2>x</H2>
+<DIR>
+<LI><A HREF="avl.html#IDX48">xmalloc</A>
+</DIR>
+
+</P>
+<P><HR><P>
+<H1>Footnotes</H1>
+<H3><A NAME="FOOT1" HREF="avl.html#DOCF1">(1)</A></H3>
+<P>In tree traversal, <STRONG>inorder</STRONG> refers
+to visiting the nodes in their sorted order from smallest to largest.
+<H3><A NAME="FOOT2" HREF="avl.html#DOCF2">(2)</A></H3>
+<P>In general, you
+should build the sort of tree that you need to use, but occasionally it
+is useful to convert between tree types.
+<H3><A NAME="FOOT3" HREF="avl.html#DOCF3">(3)</A></H3>
+<P>It
+can be changed if this would not change the ordering of the nodes in the
+tree; i.e., if this would not cause the data in the node to be less than
+or equal to the previous node's data or greater than or equal to the
+next node's data.
+<P><HR><P>
+This document was generated on 6 October 1999 using the
+<A HREF="http://wwwcn.cern.ch/dci/texi2html/">texi2html</A>
+translator version 1.51a.</P>
+</BODY>
+</HTML>
diff --git a/avl-1.4.0/avl.info b/avl-1.4.0/avl.info
new file mode 100644
index 0000000..8dd5330
--- /dev/null
+++ b/avl-1.4.0/avl.info
@@ -0,0 +1,708 @@
+This is avl.info, produced by makeinfo version 3.12n from avl.texinfo.
+
+ This file documents libavl, a library for the manipulation of
+balanced binary trees.
+
+ Copyright 1998, 1999 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that the
+entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Free Software Foundation.
+
+
+File: avl.info, Node: Top, Next: Introduction to balanced binary trees, Prev: (dir), Up: (dir)
+
+ This document describes libavl, a library for manipulation of
+balanced binary trees.
+
+ This document applies to libavl version 1.4.0.
+
+* Menu:
+
+* Introduction to balanced binary trees::
+* Introduction to threaded trees::
+* Types::
+* Functions::
+* Tree Creation::
+* Insertion::
+* Searching::
+* Iteration::
+* Conversion::
+* Author::
+* Index::
+
+
+File: avl.info, Node: Introduction to balanced binary trees, Next: Introduction to threaded trees, Prev: Top, Up: Top
+
+Introduction to balanced binary trees
+*************************************
+
+ Consider some techniques that can be used to find a particular item
+in a data set. Typical methods include sequential searching, digital
+searching, hash tables, and binary searching.
+
+ Sequential searching is simple, but slow (O(n)). Digital searching
+requires that the entire data set be known in advance, and memory
+efficient implementations are slow.
+
+ Hash tables are fast (O(1)) for static data sets, but they can be
+wasteful of memory. It can be difficult to choose an effective hash
+function. Some hash tables variants also make deletion an expensive
+operation.
+
+ Binary search techniques work almost as quickly (O(log(n)) on an
+ordered table, or on a binary tree. Binary trees also allow easy
+iteration over the data in the tree in sorted order. With hash tables
+it is necessary to sort the data before iterating, and after sorting
+the data is no longer in hash form.
+
+ Binary trees are efficient for insertion, deletion, and searching, if
+data are inserted in random order. But, if data are inserted in order
+using a naive algorithm, binary search degenerates to sequential search.
+
+ In turn, this problem can be solved by "rebalancing" the tree after
+each insertion or deletion. In rebalancing, nodes are rearranged via
+transformations called "rotations" using an algorithm that tends to
+minimize the tree's height.
+
+ There are several schemes for rebalancing binary trees. The two most
+common types of balanced tree are "AVL trees" and "red-black trees".
+libavl implements both types:
+
+ * AVL trees, invented by Russian mathematicians G. M.
+ Adel'son-Velskii and E. M. Landis, ensure that, for each node, the
+ difference in height between its subtrees (the "balance factor")
+ is not greater than 1.
+
+ * Red-black trees, invented by R. Bayer and studied at length by L.
+ J. Guibas and R. Sedgewick, assign each node of a tree a color (red
+ or black), and specify a set of rules governing how red and black
+ nodes may be arranged.
+
+ The table below presents a comparison among unbalanced binary trees,
+AVL trees, and red-black trees. In the table, N is the number of nodes
+in the tree and H is the tree's height before the operation. "lg" is
+the base-2 logarithm function.
+
+Operation
+ Binary Tree AVL Tree Red-Black Tree
+Time per insertion or deletion
+ O(H) O(lg N) O(lg N)
+Time for insertion of K nodes having sequential values
+ O(K^2) O(N lg N) O(N lg N)
+Time for insertion of K nodes having random values
+ O(N lg N) O(N lg N) O(N lg N)
+Maximum number of rotations per insertion
+ 0 1 lg N
+Maximum number of rotations per deletion
+ 0 lg N lg N
+Maximum H as a function of N
+ N 1.44 lg (N + 2) - .328 2 lg (N + 1)
+Minimum N as a function of H
+ H 2^((H + .328) / 1.44) - 2 2^(H / 2) - 1
+
+ There are alternatives to AVL trees that share some of their
+properties. For instance, skip lists, 2-3 trees, and splay trees all
+allow O(log(n)) insertion and deletion. The main disadvantage of these
+methods is that their operations are not as well documented in the
+literature.
+
+
+File: avl.info, Node: Introduction to threaded trees, Next: Types, Prev: Introduction to balanced binary trees, Up: Top
+
+Introduction to threaded trees
+******************************
+
+ "Threading" is a clever method that simplifies binary tree traversal.
+
+ Nodes in a unthreaded binary tree that have zero or one subnodes have
+two or one null subnode pointers, respectively. In a threaded binary
+tree, a left child pointer that would otherwise be null is used to point
+to the node's inorder(1) predecessor, and in a null right child pointer
+points to its inorder successor.
+
+ In a threaded tree, it is always possible to find the next node and
+the previous node of a node, given only a pointer to the node in
+question. In an unthreaded tree, it's also necessary to have a list of
+the nodes between the node in question and root of the tree.
+
+ Advantages of a threaded tree compared to an unthreaded one include:
+
+ * Faster traversal and less memory usage during traversal, since no
+ stack need be maintained.
+
+ * Greater generality, since one can go from a node to its successor
+ or predecessor given only the node, simplifying algorithms that
+ require moving forward and backward in a tree.
+
+ Some disadvantages of threaded trees are:
+
+ * Slower insertion and deletion, since threads need to be
+ maintained. In somes cases, this can be alleviated by
+ constructing the tree as an unthreaded tree, then threading it
+ with a special libavl function.
+
+ * In theory, threaded trees need two extra bits per node to indicate
+ whether each child pointer points to an ordinary node or the node's
+ successor/predecessor node. In libavl, however, these bits are
+ stored in a byte that is used for structure alignment padding in
+ unthreaded binary trees, so no extra storage is used.
+
+ A "right-threaded binary tree" is similar to a threaded binary tree,
+but threads are only maintained on the right side of each node. This
+allows for traversal to the right (toward larger values) but not to the
+left (toward smaller values). Right-threaded trees are convenient when
+the properties of a threaded tree are desirable, but traversal in
+reverse sort order is not necessary. Not threading the left links saves
+time in insertions and deletions.
+
+ Left-threaded binary trees also exist, but they are not implemented
+by libavl. The same effect can be obtained by sorting the tree in the
+opposite order.
+
+ ---------- Footnotes ----------
+
+ (1) In tree traversal, "inorder" refers to visiting the nodes in
+their sorted order from smallest to largest.
+
+
+File: avl.info, Node: Types, Next: Functions, Prev: Introduction to threaded trees, Up: Top
+
+Types
+*****
+
+ The following types are defined and used by libavl:
+
+ - Data Type: avl_tree
+ - Data Type: avlt_tree
+ - Data Type: avltr_tree
+ - Data Type: rb_tree
+ These are the data types used to represent a tree. Although they
+ are defined in the libavl header files, it should never be
+ necessary to access them directly. Instead, all accesses should
+ take place through libavl functions.
+
+ - Data Type: avl_node
+ - Data Type: avlt_node
+ - Data Type: avltr_node
+ - Data Type: rb_node
+ These are the data types used to represent individual nodes in a
+ tree. Similar cautions apply as with `avl_tree' structures.
+
+ - Data Type: avl_traverser
+ - Data Type: avlt_traverser
+ - Data Type: avltr_traverser
+ - Data Type: rb_traverser
+ These are the data types used by the `avl_traverse' family of
+ functions to iterate across the tree. Again, these are opaque
+ structures.
+
+ - Data Type: avl_comparison_func
+ Every tree must have an ordering defined by a function of this
+ type. It must have the following signature:
+
+ int COMPARE (const void *A, const void *B, void *PARAM)
+
+ The return value is expected to be like that returned by `strcmp'
+ in the standard C library: negative if A < B, zero if A = B,
+ positive if A > B. PARAM is an arbitrary value defined by the
+ user when the tree was created.
+
+ - Data Type: avl_node_func
+ This is a class of function called to perform an operation on a
+ data item. Functions of this type have the following signature:
+
+ void OPERATE (void *DATA, void *PARAM)
+
+ DATA is the data item and PARAM is an arbitrary user-defined value
+ set when the tree was created.
+
+ - Data Type: avl_copy_func
+ This is a class of function called to make a new copy of a node's
+ data. Functions of this type have the following signature:
+
+ void *COPY (void *DATA, void *PARAM)
+
+ The function should return a new copy of DATA. PARAM is an
+ arbitrary user-defined value set when the tree was created.
+
+ - Macro: AVL_MAX_HEIGHT
+ This macro defines the maximum height of an AVL tree that can be
+ handled by functions that maintain a stack of nodes descended.
+ The default value is 32, which allows for AVL trees with a maximum
+ number of nodes between 5,704,880 and 4,294,967,295, depending on
+ order of insertion. This macro may be defined by the user before
+ including any AVL tree header file, in which case libavl will
+ honor that value.
+
+ - Macro: RB_MAX_HEIGHT
+ This macro defines the maximum height of an AVL tree that can be
+ handled by functions that maintain a stack of nodes descended.
+ The default value is 32, which allows for red-black trees with a
+ maximum number of nodes of at least 65535. This macro may be
+ defined by the user before including the red-black tree header
+ file, in which case libavl will honor that value.
+
+
+File: avl.info, Node: Functions, Next: Tree Creation, Prev: Types, Up: Top
+
+Functions
+*********
+
+ libavl is four libraries in one:
+
+ * An unthreaded AVL tree library.
+
+ * A threaded AVL tree library.
+
+ * A right-threaded AVL tree library.
+
+ * A red-black tree library.
+
+ Identifiers in these libraries are prefixed by `avl_', `avlt_',
+`avltr_', and `rb_', with corresponding header files `avl.h', `avlt.h',
+`avltr.h', and `rb.h', respectively. The functions that they declare
+are defined in the `.c' files with the same names.
+
+ Most tree functions are implemented in all three libraries, but
+threading allows more generality of operation. So, the threaded and
+right-threaded libraries offer a few additional functions for finding
+the next or previous node from a given node. In addition, they offer
+functions for converting trees from threaded or right-threaded
+representations to unthreaded, and vice versa.(1)
+
+ ---------- Footnotes ----------
+
+ (1) In general, you should build the sort of tree that you need to
+use, but occasionally it is useful to convert between tree types.
+
+
+File: avl.info, Node: Tree Creation, Next: Insertion, Prev: Functions, Up: Top
+
+Tree Creation
+*************
+
+ These functions deal with creation and destruction of AVL trees.
+
+ - Function: avl_tree * avl_create (avl_comparison_func COMPARE, void
+ *PARAM)
+ - Function: avlt_tree * avlt_create (avlt_comparison_func COMPARE,
+ void *PARAM)
+ - Function: avltr_tree * avltr_create (avltr_comparison_func COMPARE,
+ void *PARAM)
+ - Function: rb_tree * rb_create (avl_comparison_func COMPARE, void
+ *PARAM)
+ Create a new, empty tree with comparison function COMPARE.
+ Arbitrary user data PARAM is saved so that it can be passed to
+ user callback functions.
+
+ - Function: void avl_destroy (avl_tree *TREE, avl_node_func FREE)
+ - Function: void avlt_destroy (avlt_tree *TREE, avl_node_func FREE)
+ - Function: void avltr_destroy (avltr_tree *TREE, avl_node_func FREE)
+ - Function: void rb_destroy (rb_tree *TREE, avl_node_func FREE)
+ Destroys TREE, releasing all of its storage. If FREE is non-null,
+ then it is called for every node in postorder before that node is
+ freed.
+
+ - Function: void avl_free (avl_tree *TREE)
+ - Function: void avlt_free (avlt_tree *TREE)
+ - Function: void avltr_free (avltr_tree *TREE)
+ - Function: void rb_free (rb_tree *TREE)
+ Destroys TREE, releasing all of its storage. The data in each
+ node is freed with a call to the standard C library function
+ `free'.
+
+ - Function: avl_tree * avl_copy (const avl_tree *TREE, avl_copy_func
+ COPY)
+ - Function: avlt_tree * avl_copy (const avlt_tree *TREE, avl_copy_func
+ COPY)
+ - Function: avltr_tree * avl_copy (const avltr_tree *TREE,
+ avl_copy_func COPY)
+ - Function: rb_tree * rb_copy (const rb_tree *TREE, avl_copy_func COPY)
+ Copies the contents of TREE into a new tree, and returns the new
+ tree. If COPY is non-null, then it is called to make a new copy
+ of each node's data; otherwise, the node data is copied verbatim
+ into the new tree.
+
+ - Function: int avl_count (const avl_tree *TREE)
+ - Function: int avlt_count (const avlt_tree *TREE)
+ - Function: int avltr_count (const avltr_tree *TREE)
+ - Function: int rb_count (const rb_tree *TREE)
+ Returns the number of nodes in TREE.
+
+ - Function: void * xmalloc (size_t SIZE)
+ This is not a function defined by libavl. Instead, it is a
+ function that the user program can define. It must allocate SIZE
+ bytes using `malloc' and return it. It can handle out-of-memory
+ errors however it chooses, but it may not ever return a null
+ pointer.
+
+ If there is an `xmalloc' function defined for use by libavl, the
+ source files (`avl.c', `avlt.c', `avltr.c', `rb.c') must be
+ compiled with `HAVE_XMALLOC' defined. Otherwise, the library will
+ use its internal static `xmalloc', which handles out-of-memory
+ errors by printing a message `virtual memory exhausted' to stderr
+ and terminating the program with exit code `EXIT_FAILURE'.
+
+
+File: avl.info, Node: Insertion, Next: Searching, Prev: Tree Creation, Up: Top
+
+Insertion and Deletion
+**********************
+
+ These function insert nodes, delete nodes, and search for nodes in
+trees.
+
+ - Function: void ** avl_probe (avl_tree *TREE, void *DATA)
+ - Function: void ** avlt_probe (avlt_tree *TREE, void *DATA)
+ - Function: void ** avltr_probe (avltr_tree *TREE, void *DATA)
+ - Function: void ** rb_probe (rb_tree *TREE, void *DATA)
+ These are the workhorse functions for tree insertion. They search
+ TREE for a node with data matching DATA. If found, a pointer to
+ the matching data is returned. Otherwise, a new node is created
+ for DATA, and a pointer to that data is returned. In either case,
+ the pointer returned can be changed by the user, but the key data
+ used by the tree's comparison must not be changed(1).
+
+ It is usually easier to use one of the `avl_insert' or
+ `avl_replace' functions instead of `avl_probe' directly.
+
+ *Please note:* It's not a particularly good idea to insert a null
+ pointer as a data item into a tree, because several libavl
+ functions return a null pointer to indicate failure. You can
+ sometimes avoid a problem by using functions that return a pointer
+ to a pointer instead of a plain pointer. Also be wary of this
+ when casting an arithmetic type to a void pointer for
+ insertion--on typical architectures, 0's become null pointers when
+ this is done.
+
+ - Function: void * avl_insert (avl_tree *TREE, void *DATA)
+ - Function: void * avlt_insert (avlt_tree *TREE, void *DATA)
+ - Function: void * avltr_insert (avltr_tree *TREE, void *DATA)
+ - Function: void * rb_insert (rb_tree *TREE, void *DATA)
+ If a node with data matching DATA exists in TREE, returns the
+ matching data item. Otherwise, inserts DATA into TREE and returns
+ a null pointer.
+
+ - Function: void avl_force_insert (avl_tree *TREE, void *DATA)
+ - Function: void avlt_force_insert (avlt_tree *TREE, void *DATA)
+ - Function: void avltr_force_insert (avltr_tree *TREE, void *DATA)
+ - Function: void rb_force_insert (rb_tree *TREE, void *DATA)
+ Inserts DATA into TREE. If a node with data matching DATA exists
+ in TREE, aborts the program with an assertion violation. This
+ function is implemented as a macro; if it is used, the standard C
+ header `assert.h' must also be included. If macro `NDEBUG' is
+ defined when a libavl header is included, these functions are
+ short-circuited to a direct call to `avl_insert', and no check is
+ performed.
+
+ - Function: void * avl_replace (avl_tree *TREE, void *DATA)
+ - Function: void * avlt_replace (avlt_tree *TREE, void *DATA)
+ - Function: void * avltr_replace (avltr_tree *TREE, void *DATA)
+ - Function: void * rb_replace (rb_tree *TREE, void *DATA)
+ If a node with data matching DATA, such that the comparison
+ function returns 0, exists in TREE, replaces the node's data with
+ DATA and returns the node's former contents. Otherwise, inserts
+ DATA into TREE and returns a null pointer.
+
+ - Function: void * avl_delete (avl_tree *TREE, const void *DATA)
+ - Function: void * avlt_delete (avlt_tree *TREE, const void *DATA)
+ - Function: void * avltr_delete (avltr_tree *TREE, const void *DATA)
+ - Function: void * rb_delete (rb_tree *TREE, const void *DATA)
+ Searches TREE for a node with data matching DATA. If found, the
+ node is deleted and its data is returned. Otherwise, returns a
+ null pointer.
+
+ - Function: void * avl_force_delete (avl_tree *TREE, const void *DATA)
+ - Function: void * avlt_force_delete (avlt_tree *TREE, const void
+ *DATA)
+ - Function: void * avltr_force_delete (avltr_tree *TREE, const void
+ *DATA)
+ - Function: void * rb_force_delete (rb_tree *TREE, const void *DATA)
+ Deletes a node with data matching DATA from TREE. If no matching
+ node is found, aborts the program with an assertion violation. If
+ macro `NDEBUG' is declared when a libavl header is included, these
+ functions are short-circuited to a direct call to `avl_delete',
+ and no check is performed.
+
+ ---------- Footnotes ----------
+
+ (1) It can be changed if this would not change the ordering of the
+nodes in the tree; i.e., if this would not cause the data in the node
+to be less than or equal to the previous node's data or greater than or
+equal to the next node's data.
+
+
+File: avl.info, Node: Searching, Next: Iteration, Prev: Insertion, Up: Top
+
+Searching
+*********
+
+ These function search a tree for an item without making an insertion
+or a deletion.
+
+ - Function: void * avl_find (avl_tree *TREE, const void *DATA)
+ - Function: void ** avlt_find (avlt_tree *TREE, const void *DATA)
+ - Function: void ** avltr_find (avltr_tree *TREE, const void *DATA)
+ - Function: void * rb_find (rb_tree *TREE, const void *DATA)
+ Searches TREE for a node with data matching DATA, If found,
+ returns the node's data (for threaded and right-threaded trees, a
+ pointer to the node's data). Otherwise, returns a null pointer.
+
+ - Function: void * avl_find_close (avl_tree *TREE, const void *DATA)
+ - Function: void ** avlt_find_close (avlt_tree *TREE, const void *DATA)
+ - Function: void ** avltr_find_close (avltr_tree *TREE, const void
+ *DATA)
+ - Function: void * rb_find_close (rb_tree *TREE, const void *DATA)
+ Searches TREE for a node with data matching DATA. If found,
+ returns the node's data (for threaded and right-threaded trees, a
+ pointer to the node's data). If no matching item is found, then it
+ finds a node whose data is "close" to DATA; either the node
+ closest in value to DATA, or the node either before or after the
+ node with the closest value. Returns a null pointer if the tree
+ does not contain any nodes.
+
+
+File: avl.info, Node: Iteration, Next: Conversion, Prev: Searching, Up: Top
+
+Iteration
+*********
+
+ These functions allow the caller to iterate across the items in a
+tree.
+
+ - Function: void avl_walk (const avl_tree *TREE, avl_node_func
+ OPERATE, void *PARAM)
+ - Function: void avlt_walk (const avlt_tree *TREE, avl_node_func
+ OPERATE, void *PARAM)
+ - Function: void avltr_walk (const avltr_tree *TREE, avl_node_func
+ OPERATE, void *PARAM)
+ - Function: void rb_walk (const rb_tree *TREE, avl_node_func OPERATE,
+ void *PARAM)
+ Walks through all the nodes in TREE, and calls function OPERATE
+ for each node in inorder. PARAM overrides the value passed to
+ `avl_create' (and family) for this operation only. OPERATE must
+ not change the key data in the nodes in a way that would reorder
+ the data values or cause two values to become equal.
+
+ - Function: void * avl_traverse (const avl_tree *TREE, avl_traverser
+ *TRAV)
+ - Function: void * avlt_traverse (const avlt_tree *TREE,
+ avlt_traverser *TRAV)
+ - Function: void * avltr_traverse (const avltr_tree *TREE,
+ avltr_traverser *TRAV)
+ - Function: void * rb_traverse (const rb_tree *TREE, rb_traverser
+ *TRAV)
+ Returns each of TREE's nodes' data values in sequence, then a null
+ pointer to indicate the last item. TRAV must be initialized
+ before the first call, either in a declaration like that below, or
+ using one of the functions below.
+
+ avl_traverser trav = AVL_TRAVERSER_INIT;
+
+ Each `avl_traverser' (and family) is a separate, independent
+ iterator.
+
+ For threaded and right-threaded trees, `avlt_next' or
+ `avltr_next', respectively, are faster and more memory-efficient
+ than `avlt_traverse' or `avltr_traverse'.
+
+ - Function: void * avl_init_traverser (avl_traverser *TRAV)
+ - Function: void * avlt_init_traverser (avlt_traverser *TRAV)
+ - Function: void * avltr_init_traverser (avltr_traverser *TRAV)
+ - Function: void * rb_init_traverser (rb_traverser *TRAV)
+ Initializes the specified tree traverser structure. After this
+ function is called, the next call to the corresponding
+ `*_traverse' function will return the smallest value in the
+ appropriate tree.
+
+ - Function: void ** avlt_next (const avlt_tree *TREE, void **DATA)
+ - Function: void ** avltr_next (const avltr_tree *TREE, void **DATA)
+ DATA must be a null pointer or a pointer to a data item in AVL
+ tree TREE. Returns a pointer to the next data item after DATA in
+ TREE in inorder (this is the first item if DATA is a null
+ pointer), or a null pointer if DATA was the last item in TREE.
+
+ - Function: void ** avltr_prev (const avltr_tree *TREE, void **DATA)
+ DATA must be a null pointer or a pointer to a data item in AVL
+ tree TREE. Returns a pointer to the previous data item before
+ DATA in TREE in inorder (this is the last, or greatest valued,
+ item if DATA is a null pointer), or a null pointer if DATA was the
+ first item in TREE.
+
+
+File: avl.info, Node: Conversion, Next: Author, Prev: Iteration, Up: Top
+
+Conversion
+**********
+
+ - Function: avlt_tree * avlt_thread (avl_tree *TREE)
+ - Function: avltr_tree * avltr_thread (avl_tree *TREE)
+ Adds symmetric threads or right threads, respectively, to
+ unthreaded AVL tree TREE and returns a pointer to TREE cast to the
+ appropriate type. After one of these functions is called,
+ threaded or right-threaded functions, as appropriate, must be used
+ with TREE; unthreaded functions may not be used.
+
+ - Function: avl_tree * avlt_unthread (avlt_tree *TREE)
+ - Function: avl_tree * avltr_unthread (avltr_tree *TREE)
+ Cuts all threads in threaded or right-threaded, respectively, AVL
+ tree TREE and returns a pointer to TREE cast to `avl_tree *'.
+ After one of these functions is called, unthreaded functions must
+ be used with TREE; threaded or right-threaded functions may not be
+ used.
+
+
+File: avl.info, Node: Author, Next: Index, Prev: Conversion, Up: Top
+
+Author
+******
+
+ libavl was written by Ben Pfaff <blp@gnu.org>.
+
+ libavl's generic tree algorithms and AVL algorithms are based on
+those found in Donald Knuth's venerable `Art of Computer Programming'
+series from Addison-Wesley, primarily Volumes 1 and 3. libavl's
+red-black tree algorithms are based on those found in Cormen et al.,
+`Introduction to Algorithms', 2nd ed., from MIT Press.
+
+
+File: avl.info, Node: Index, Prev: Author, Up: Top
+
+Index
+*****
+
+* Menu:
+
+* `Art of Computer Programming': Author.
+* Adel'son-Velskii, G. M.: Introduction to balanced binary trees.
+* author: Author.
+* AVL tree: Introduction to balanced binary trees.
+* avl_comparison_func: Types.
+* avl_copy: Tree Creation.
+* avl_copy_func: Types.
+* avl_count: Tree Creation.
+* avl_create: Tree Creation.
+* avl_delete: Insertion.
+* avl_destroy: Tree Creation.
+* avl_find: Searching.
+* avl_find_close: Searching.
+* avl_force_delete: Insertion.
+* avl_force_insert: Insertion.
+* avl_free: Tree Creation.
+* avl_init_traverser: Iteration.
+* avl_insert: Insertion.
+* AVL_MAX_HEIGHT: Types.
+* avl_node: Types.
+* avl_node_func: Types.
+* avl_probe: Insertion.
+* avl_replace: Insertion.
+* avl_traverse: Iteration.
+* avl_traverser: Types.
+* avl_tree: Types.
+* avl_walk: Iteration.
+* avlt_count: Tree Creation.
+* avlt_create: Tree Creation.
+* avlt_delete: Insertion.
+* avlt_destroy: Tree Creation.
+* avlt_find: Searching.
+* avlt_find_close: Searching.
+* avlt_force_delete: Insertion.
+* avlt_force_insert: Insertion.
+* avlt_free: Tree Creation.
+* avlt_init_traverser: Iteration.
+* avlt_insert: Insertion.
+* avlt_next: Iteration.
+* avlt_node: Types.
+* avlt_probe: Insertion.
+* avlt_replace: Insertion.
+* avlt_thread: Conversion.
+* avlt_traverse: Iteration.
+* avlt_traverser: Types.
+* avlt_tree: Types.
+* avlt_unthread: Conversion.
+* avlt_walk: Iteration.
+* avltr_count: Tree Creation.
+* avltr_create: Tree Creation.
+* avltr_delete: Insertion.
+* avltr_destroy: Tree Creation.
+* avltr_find: Searching.
+* avltr_find_close: Searching.
+* avltr_force_delete: Insertion.
+* avltr_force_insert: Insertion.
+* avltr_free: Tree Creation.
+* avltr_init_traverser: Iteration.
+* avltr_insert: Insertion.
+* avltr_next: Iteration.
+* avltr_node: Types.
+* avltr_prev: Iteration.
+* avltr_probe: Insertion.
+* avltr_replace: Insertion.
+* avltr_thread: Conversion.
+* avltr_traverse: Iteration.
+* avltr_traverser: Types.
+* avltr_tree: Types.
+* avltr_unthread: Conversion.
+* avltr_walk: Iteration.
+* binary tree: Introduction to balanced binary trees.
+* hash table: Introduction to balanced binary trees.
+* Knuth, Donald Ervin: Author.
+* Landis, E. M.: Introduction to balanced binary trees.
+* Pfaff, Benjamin Levy: Author.
+* rb_copy: Tree Creation.
+* rb_count: Tree Creation.
+* rb_create: Tree Creation.
+* rb_delete: Insertion.
+* rb_destroy: Tree Creation.
+* rb_find: Searching.
+* rb_find_close: Searching.
+* rb_force_delete: Insertion.
+* rb_force_insert: Insertion.
+* rb_free: Tree Creation.
+* rb_init_traverser: Iteration.
+* rb_insert: Insertion.
+* RB_MAX_HEIGHT: Types.
+* rb_node: Types.
+* rb_probe: Insertion.
+* rb_replace: Insertion.
+* rb_traverse: Iteration.
+* rb_traverser: Types.
+* rb_tree: Types.
+* rb_walk: Iteration.
+* rebalancing: Introduction to balanced binary trees.
+* red-black tree: Introduction to balanced binary trees.
+* right threads: Functions.
+* threads: Functions.
+* unthreaded: Functions.
+* xmalloc: Tree Creation.
+
+
+
+Tag Table:
+Node: Top891
+Node: Introduction to balanced binary trees1340
+Node: Introduction to threaded trees5260
+Ref: Introduction to threaded trees-Footnote-17757
+Node: Types7871
+Node: Functions10904
+Ref: Functions-Footnote-111877
+Node: Tree Creation12014
+Node: Insertion15035
+Ref: Insertion-Footnote-119214
+Node: Searching19458
+Node: Iteration20863
+Node: Conversion23929
+Node: Author24875
+Node: Index25345
+
+End Tag Table
diff --git a/avl-1.4.0/avl.texinfo b/avl-1.4.0/avl.texinfo
new file mode 100644
index 0000000..9d06324
--- /dev/null
+++ b/avl-1.4.0/avl.texinfo
@@ -0,0 +1,679 @@
+\input texinfo @c -*-texinfo-*-
+@c %**start of header
+@setfilename avl.info
+@settitle libavl manual
+@setchapternewpage on
+@c %**end of header
+
+@syncodeindex vr cp
+@syncodeindex fn cp
+@syncodeindex tp cp
+
+@ifinfo
+This file documents libavl, a library for the manipulation of balanced
+binary trees.
+
+Copyright 1998, 1999 Free Software Foundation, Inc.
+
+Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+@ignore
+Permission is granted to process this file through TeX and print the
+results, provided the printed document carries a copying permission
+notice identical to this one except for the removal of this paragraph
+(this paragraph not being relevant to the printed manual).
+
+@end ignore
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the
+entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+Permission is granted to copy and distribute translations of this manual
+into another language, under the above conditions for modified versions,
+except that this permission notice may be stated in a translation
+approved by the Free Software Foundation.
+@end ifinfo
+
+@titlepage
+@title libavl
+@subtitle A library for manipulation of balanced binary trees
+@author Ben Pfaff
+
+@page
+@vskip 0pt plus 1filll
+Copyright @copyright{} 1998, 1999 Free Software Foundation, Inc.
+
+Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the
+entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+Permission is granted to copy and distribute translations of this manual
+into another language, under the above conditions for modified versions,
+except that this permission notice may be stated in a translation
+approved by the Free Software Foundation.
+@end titlepage
+
+@node Top, Introduction to balanced binary trees, (dir), (dir)
+
+@ifinfo
+This document describes libavl, a library for manipulation of balanced
+binary trees.
+
+This document applies to libavl version 1.4.0.
+@end ifinfo
+
+@menu
+* Introduction to balanced binary trees::
+* Introduction to threaded trees::
+* Types::
+* Functions::
+* Tree Creation::
+* Insertion::
+* Searching::
+* Iteration::
+* Conversion::
+* Author::
+* Index::
+@end menu
+
+@node Introduction to balanced binary trees, Introduction to threaded trees, Top, Top
+@chapter Introduction to balanced binary trees
+
+@cindex hash table
+Consider some techniques that can be used to find a particular item in a
+data set. Typical methods include sequential searching, digital
+searching, hash tables, and binary searching.
+
+Sequential searching is simple, but slow (O(n)). Digital searching
+requires that the entire data set be known in advance, and memory
+efficient implementations are slow.
+
+Hash tables are fast (O(1)) for static data sets, but they can be
+wasteful of memory. It can be difficult to choose an effective hash
+function. Some hash tables variants also make deletion an expensive
+operation.
+
+@cindex binary tree
+Binary search techniques work almost as quickly (O(log(n)) on an ordered
+table, or on a binary tree. Binary trees also allow easy iteration over
+the data in the tree in sorted order. With hash tables it is necessary
+to sort the data before iterating, and after sorting the data is no
+longer in hash form.
+
+Binary trees are efficient for insertion, deletion, and searching, if
+data are inserted in random order. But, if data are inserted in order
+using a naive algorithm, binary search degenerates to sequential search.
+
+@cindex red-black tree
+@cindex AVL tree
+@cindex rebalancing
+In turn, this problem can be solved by @dfn{rebalancing} the tree after
+each insertion or deletion. In rebalancing, nodes are rearranged via
+transformations called @dfn{rotations} using an algorithm that tends to
+minimize the tree's height.
+
+There are several schemes for rebalancing binary trees. The two most
+common types of balanced tree are @dfn{AVL trees} and @dfn{red-black
+trees}. libavl implements both types:
+
+@itemize @bullet
+@item
+@cindex Landis, E. M.
+@cindex Adel'son-Velskii, G. M.
+AVL trees, invented by Russian mathematicians G. M. Adel'son-Velskii and
+E. M. Landis, ensure that, for each node, the difference in height
+between its subtrees (the @dfn{balance factor}) is not greater than 1.
+
+@item
+Red-black trees, invented by R. Bayer and studied at length by
+L. J. Guibas and R. Sedgewick, assign each node of a tree a color (red
+or black), and specify a set of rules governing how red and black nodes
+may be arranged.
+@end itemize
+
+The table below presents a comparison among unbalanced binary trees, AVL
+trees, and red-black trees. In the table, @var{n} is the number of
+nodes in the tree and @var{h} is the tree's height before the
+operation. @dfn{lg} is the base-2 logarithm function.
+
+@multitable @columnfractions .05 .30 .35 .30
+
+@need 333
+@item @w{Operation}
+@item
+@tab Binary Tree
+@tab AVL Tree
+@tab Red-Black Tree
+
+@need 333
+@item @w{Time per insertion or deletion}
+@item
+@tab O(@var{h})
+@tab O(lg @var{n})
+@tab O(lg @var{n})
+
+@need 333
+@item @w{Time for insertion of @var{k} nodes having sequential values}
+@item
+@tab O(@math{@var{k}^2})
+@tab O(@var{n} lg @var{n})
+@tab O(@var{n} lg @var{n})
+
+@need 333
+@item @w{Time for insertion of @var{k} nodes having random values}
+@item
+@tab O(@var{n} lg @var{n})
+@tab O(@var{n} lg @var{n})
+@tab O(@var{n} lg @var{n})
+
+@need 333
+@item @w{Maximum number of rotations per insertion}
+@item
+@tab 0
+@tab 1
+@tab lg @var{n}
+
+@need 333
+@item @w{Maximum number of rotations per deletion}
+@item
+@tab 0
+@tab lg @var{n}
+@tab lg @var{n}
+
+@need 333
+@item @w{Maximum @var{h} as a function of @var{n}}
+@item
+@tab @var{n}
+@tab 1.44 lg (@var{n} + 2) - .328
+@tab 2 lg (@var{n} + 1)
+
+@need 333
+@item @w{Minimum @var{n} as a function of @var{h}}
+@item
+@tab @var{h}
+@tab 2^((@var{h} + .328) / 1.44) - 2
+@tab 2^(@var{h} / 2) - 1
+@end multitable
+
+There are alternatives to AVL trees that share some of their properties.
+For instance, skip lists, 2-3 trees, and splay trees all allow O(log(n))
+insertion and deletion. The main disadvantage of these methods is that
+their operations are not as well documented in the literature.
+
+@node Introduction to threaded trees, Types, Introduction to balanced binary trees, Top
+@chapter Introduction to threaded trees
+
+@dfn{Threading} is a clever method that simplifies binary tree
+traversal.
+
+Nodes in a unthreaded binary tree that have zero or one subnodes have
+two or one null subnode pointers, respectively. In a threaded binary
+tree, a left child pointer that would otherwise be null is used to point
+to the node's inorder@footnote{In tree traversal, @dfn{inorder} refers
+to visiting the nodes in their sorted order from smallest to largest.}
+predecessor, and in a null right child pointer points to its inorder
+successor.
+
+In a threaded tree, it is always possible to find the next node and the
+previous node of a node, given only a pointer to the node in question.
+In an unthreaded tree, it's also necessary to have a list of the nodes
+between the node in question and root of the tree.
+
+Advantages of a threaded tree compared to an unthreaded one include:
+
+@itemize @bullet
+@item
+Faster traversal and less memory usage during traversal, since no stack
+need be maintained.
+
+@item
+Greater generality, since one can go from a node to its successor or
+predecessor given only the node, simplifying algorithms that require
+moving forward and backward in a tree.
+@end itemize
+
+Some disadvantages of threaded trees are:
+
+@itemize @bullet
+@item
+Slower insertion and deletion, since threads need to be maintained. In
+somes cases, this can be alleviated by constructing the tree as an
+unthreaded tree, then threading it with a special libavl function.
+
+@item
+In theory, threaded trees need two extra bits per node to indicate
+whether each child pointer points to an ordinary node or the node's
+successor/predecessor node. In libavl, however, these bits are stored
+in a byte that is used for structure alignment padding in unthreaded
+binary trees, so no extra storage is used.
+@end itemize
+
+A @dfn{right-threaded binary tree} is similar to a threaded binary tree,
+but threads are only maintained on the right side of each node. This
+allows for traversal to the right (toward larger values) but not to the
+left (toward smaller values). Right-threaded trees are convenient when
+the properties of a threaded tree are desirable, but traversal in
+reverse sort order is not necessary. Not threading the left links saves
+time in insertions and deletions.
+
+Left-threaded binary trees also exist, but they are not implemented by
+libavl. The same effect can be obtained by sorting the tree in the
+opposite order.
+
+@node Types, Functions, Introduction to threaded trees, Top
+@chapter Types
+
+The following types are defined and used by libavl:
+
+@deftp {Data Type} avl_tree
+@deftpx {Data Type} avlt_tree
+@deftpx {Data Type} avltr_tree
+@deftpx {Data Type} rb_tree
+These are the data types used to represent a tree. Although they are
+defined in the libavl header files, it should never be necessary to
+access them directly. Instead, all accesses should take place through
+libavl functions.
+@end deftp
+
+@deftp {Data Type} avl_node
+@deftpx {Data Type} avlt_node
+@deftpx {Data Type} avltr_node
+@deftpx {Data Type} rb_node
+These are the data types used to represent individual nodes in a tree.
+Similar cautions apply as with @code{avl_tree} structures.
+@end deftp
+
+@deftp {Data Type} avl_traverser
+@deftpx {Data Type} avlt_traverser
+@deftpx {Data Type} avltr_traverser
+@deftpx {Data Type} rb_traverser
+These are the data types used by the @code{avl_traverse} family of
+functions to iterate across the tree. Again, these are opaque
+structures.
+@end deftp
+
+@deftp {Data Type} avl_comparison_func
+Every tree must have an ordering defined by a function of this type. It
+must have the following signature:
+
+@smallexample
+int @var{compare} (const void *@var{a}, const void *@var{b}, void *@var{param})
+@end smallexample
+
+The return value is expected to be like that returned by @code{strcmp}
+in the standard C library: negative if @var{a} < @var{b}, zero if
+@var{a} = @var{b}, positive if @var{a} > @var{b}. @var{param} is an
+arbitrary value defined by the user when the tree was created.
+@end deftp
+
+@deftp {Data Type} avl_node_func
+This is a class of function called to perform an operation on a data
+item. Functions of this type have the following signature:
+
+@smallexample
+void @var{operate} (void *@var{data}, void *@var{param})
+@end smallexample
+
+@var{data} is the data item and @var{param} is an arbitrary user-defined
+value set when the tree was created.
+@end deftp
+
+@deftp {Data Type} avl_copy_func
+
+This is a class of function called to make a new copy of a node's data.
+Functions of this type have the following signature:
+
+@smallexample
+void *@var{copy} (void *@var{data}, void *@var{param})
+@end smallexample
+
+The function should return a new copy of @var{data}. @var{param} is an
+arbitrary user-defined value set when the tree was created.
+@end deftp
+
+@defmac AVL_MAX_HEIGHT
+This macro defines the maximum height of an AVL tree that can be handled
+by functions that maintain a stack of nodes descended. The default
+value is 32, which allows for AVL trees with a maximum number of nodes
+between 5,704,880 and 4,294,967,295, depending on order of insertion.
+This macro may be defined by the user before including any AVL tree
+header file, in which case libavl will honor that value.
+@end defmac
+
+@defmac RB_MAX_HEIGHT
+This macro defines the maximum height of an AVL tree that can be handled
+by functions that maintain a stack of nodes descended. The default
+value is 32, which allows for red-black trees with a maximum number of
+nodes of at least 65535. This macro may be defined by the user before
+including the red-black tree header file, in which case libavl will
+honor that value.
+@end defmac
+
+@node Functions, Tree Creation, Types, Top
+@chapter Functions
+
+@cindex unthreaded
+@cindex threads
+@cindex right threads
+libavl is four libraries in one:
+
+@itemize @bullet
+@item
+An unthreaded AVL tree library.
+
+@item
+A threaded AVL tree library.
+
+@item
+A right-threaded AVL tree library.
+
+@item
+A red-black tree library.
+@end itemize
+
+Identifiers in these libraries are prefixed by @code{avl_},
+@code{avlt_}, @code{avltr_}, and @code{rb_}, with corresponding header
+files @file{avl.h}, @file{avlt.h}, @file{avltr.h}, and @file{rb.h},
+respectively. The functions that they declare are defined in the
+@file{.c} files with the same names.
+
+Most tree functions are implemented in all three libraries, but
+threading allows more generality of operation. So, the threaded and
+right-threaded libraries offer a few additional functions for finding
+the next or previous node from a given node. In addition, they offer
+functions for converting trees from threaded or right-threaded
+representations to unthreaded, and vice versa.@footnote{In general, you
+should build the sort of tree that you need to use, but occasionally it
+is useful to convert between tree types.}
+
+@node Tree Creation, Insertion, Functions, Top
+@chapter Tree Creation
+
+These functions deal with creation and destruction of AVL trees.
+
+@deftypefun {avl_tree *} avl_create (avl_comparison_func @var{compare}, void *@var{param})
+@deftypefunx {avlt_tree *} avlt_create (avlt_comparison_func @var{compare}, void *@var{param})
+@deftypefunx {avltr_tree *} avltr_create (avltr_comparison_func @var{compare}, void *@var{param})
+@deftypefunx {rb_tree *} rb_create (avl_comparison_func @var{compare}, void *@var{param})
+Create a new, empty tree with comparison function @var{compare}.
+Arbitrary user data @var{param} is saved so that it can be passed to
+user callback functions.
+@end deftypefun
+
+@deftypefun {void} avl_destroy (avl_tree *@var{tree}, avl_node_func @var{free})
+@deftypefunx {void} avlt_destroy (avlt_tree *@var{tree}, avl_node_func @var{free})
+@deftypefunx {void} avltr_destroy (avltr_tree *@var{tree}, avl_node_func @var{free})
+@deftypefunx {void} rb_destroy (rb_tree *@var{tree}, avl_node_func @var{free})
+Destroys @var{tree}, releasing all of its storage. If @var{free} is
+non-null, then it is called for every node in postorder before that node
+is freed.
+@end deftypefun
+
+@deftypefun {void} avl_free (avl_tree *@var{tree})
+@deftypefunx {void} avlt_free (avlt_tree *@var{tree})
+@deftypefunx {void} avltr_free (avltr_tree *@var{tree})
+@deftypefunx {void} rb_free (rb_tree *@var{tree})
+Destroys @var{tree}, releasing all of its storage. The data in each
+node is freed with a call to the standard C library function
+@code{free}.
+@end deftypefun
+
+@deftypefun {avl_tree *} avl_copy (const avl_tree *@var{tree}, avl_copy_func @var{copy})
+@deftypefunx {avlt_tree *} avl_copy (const avlt_tree *@var{tree}, avl_copy_func @var{copy})
+@deftypefunx {avltr_tree *} avl_copy (const avltr_tree *@var{tree}, avl_copy_func @var{copy})
+@deftypefunx {rb_tree *} rb_copy (const rb_tree *@var{tree}, avl_copy_func @var{copy})
+Copies the contents of @var{tree} into a new tree, and returns the new
+tree. If @var{copy} is non-null, then it is called to make a new copy
+of each node's data; otherwise, the node data is copied verbatim into
+the new tree.
+@end deftypefun
+
+@deftypefun int avl_count (const avl_tree *@var{tree})
+@deftypefunx int avlt_count (const avlt_tree *@var{tree})
+@deftypefunx int avltr_count (const avltr_tree *@var{tree})
+@deftypefunx int rb_count (const rb_tree *@var{tree})
+Returns the number of nodes in @var{tree}.
+@end deftypefun
+
+@deftypefun {void *} xmalloc (size_t @var{size})
+This is not a function defined by libavl. Instead, it is a function
+that the user program can define. It must allocate @var{size} bytes
+using @code{malloc} and return it. It can handle out-of-memory errors
+however it chooses, but it may not ever return a null pointer.
+
+If there is an @code{xmalloc} function defined for use by libavl, the
+source files (@file{avl.c}, @file{avlt.c}, @file{avltr.c}, @file{rb.c})
+must be compiled with @code{HAVE_XMALLOC} defined. Otherwise, the
+library will use its internal static @code{xmalloc}, which handles
+out-of-memory errors by printing a message @samp{virtual memory
+exhausted} to stderr and terminating the program with exit code
+@code{EXIT_FAILURE}.
+@end deftypefun
+
+@node Insertion, Searching, Tree Creation, Top
+@chapter Insertion and Deletion
+
+These function insert nodes, delete nodes, and search for nodes in
+trees.
+
+@deftypefun {void **} avl_probe (avl_tree *@var{tree}, void *@var{data})
+@deftypefunx {void **} avlt_probe (avlt_tree *@var{tree}, void *@var{data})
+@deftypefunx {void **} avltr_probe (avltr_tree *@var{tree}, void *@var{data})
+@deftypefunx {void **} rb_probe (rb_tree *@var{tree}, void *@var{data})
+These are the workhorse functions for tree insertion. They search
+@var{tree} for a node with data matching @var{data}. If found, a
+pointer to the matching data is returned. Otherwise, a new node is
+created for @var{data}, and a pointer to that data is returned. In
+either case, the pointer returned can be changed by the user, but the
+key data used by the tree's comparison must not be changed@footnote{It
+can be changed if this would not change the ordering of the nodes in the
+tree; i.e., if this would not cause the data in the node to be less than
+or equal to the previous node's data or greater than or equal to the
+next node's data.}.
+
+It is usually easier to use one of the @code{avl_insert} or
+@code{avl_replace} functions instead of @code{avl_probe} directly.
+
+@strong{Please note:} It's not a particularly good idea to insert a null
+pointer as a data item into a tree, because several libavl functions
+return a null pointer to indicate failure. You can sometimes avoid a
+problem by using functions that return a pointer to a pointer instead of
+a plain pointer. Also be wary of this when casting an arithmetic type
+to a void pointer for insertion---on typical architectures, 0's become
+null pointers when this is done.
+@end deftypefun
+
+@deftypefun {void *} avl_insert (avl_tree *@var{tree}, void *@var{data})
+@deftypefunx {void *} avlt_insert (avlt_tree *@var{tree}, void *@var{data})
+@deftypefunx {void *} avltr_insert (avltr_tree *@var{tree}, void *@var{data})
+@deftypefunx {void *} rb_insert (rb_tree *@var{tree}, void *@var{data})
+If a node with data matching @var{data} exists in @var{tree}, returns
+the matching data item. Otherwise, inserts @var{data} into @var{tree}
+and returns a null pointer.
+@end deftypefun
+
+@deftypefun void avl_force_insert (avl_tree *@var{tree}, void *@var{data})
+@deftypefunx void avlt_force_insert (avlt_tree *@var{tree}, void *@var{data})
+@deftypefunx void avltr_force_insert (avltr_tree *@var{tree}, void *@var{data})
+@deftypefunx void rb_force_insert (rb_tree *@var{tree}, void *@var{data})
+Inserts @var{data} into @var{tree}. If a node with data matching
+@var{data} exists in @var{tree}, aborts the program with an assertion
+violation. This function is implemented as a macro; if it is used, the
+standard C header @code{assert.h} must also be included. If macro
+@code{NDEBUG} is defined when a libavl header is included, these
+functions are short-circuited to a direct call to @code{avl_insert},
+and no check is performed.
+@end deftypefun
+
+@deftypefun {void *} avl_replace (avl_tree *@var{tree}, void *@var{data})
+@deftypefunx {void *} avlt_replace (avlt_tree *@var{tree}, void *@var{data})
+@deftypefunx {void *} avltr_replace (avltr_tree *@var{tree}, void *@var{data})
+@deftypefunx {void *} rb_replace (rb_tree *@var{tree}, void *@var{data})
+If a node with data matching @var{data}, such that the comparison
+function returns 0, exists in @var{tree}, replaces the node's data with
+@var{data} and returns the node's former contents. Otherwise, inserts
+@var{data} into @var{tree} and returns a null pointer.
+@end deftypefun
+
+@deftypefun {void *} avl_delete (avl_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} avlt_delete (avlt_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} avltr_delete (avltr_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} rb_delete (rb_tree *@var{tree}, const void *@var{data})
+Searches @var{tree} for a node with data matching @var{data}. If found,
+the node is deleted and its data is returned. Otherwise, returns a null
+pointer.
+@end deftypefun
+
+@deftypefun {void *} avl_force_delete (avl_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} avlt_force_delete (avlt_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} avltr_force_delete (avltr_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} rb_force_delete (rb_tree *@var{tree}, const void *@var{data})
+Deletes a node with data matching @var{data} from @var{tree}. If no
+matching node is found, aborts the program with an assertion violation.
+If macro @code{NDEBUG} is declared when a libavl header is included,
+these functions are short-circuited to a direct call to
+@code{avl_delete}, and no check is performed.
+@end deftypefun
+
+@node Searching, Iteration, Insertion, Top
+@chapter Searching
+
+These function search a tree for an item without making an insertion or
+a deletion.
+
+@deftypefun {void *} avl_find (avl_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void **} avlt_find (avlt_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void **} avltr_find (avltr_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} rb_find (rb_tree *@var{tree}, const void *@var{data})
+Searches @var{tree} for a node with data matching @var{data}, If found,
+returns the node's data (for threaded and right-threaded trees, a
+pointer to the node's data). Otherwise, returns a null pointer.
+@end deftypefun
+
+@deftypefun {void *} avl_find_close (avl_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void **} avlt_find_close (avlt_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void **} avltr_find_close (avltr_tree *@var{tree}, const void *@var{data})
+@deftypefunx {void *} rb_find_close (rb_tree *@var{tree}, const void *@var{data})
+Searches @var{tree} for a node with data matching @var{data}. If found,
+returns the node's data (for threaded and right-threaded trees, a
+pointer to the node's data). If no matching item is found, then it
+finds a node whose data is ``close'' to @var{data}; either the node
+closest in value to @var{data}, or the node either before or after the
+node with the closest value. Returns a null pointer if the tree does
+not contain any nodes.
+@end deftypefun
+
+@node Iteration, Conversion, Searching, Top
+@chapter Iteration
+
+These functions allow the caller to iterate across the items in a tree.
+
+@deftypefun void avl_walk (const avl_tree *@var{tree}, avl_node_func @var{operate}, void *@var{param})
+@deftypefunx void avlt_walk (const avlt_tree *@var{tree}, avl_node_func @var{operate}, void *@var{param})
+@deftypefunx void avltr_walk (const avltr_tree *@var{tree}, avl_node_func @var{operate}, void *@var{param})
+@deftypefunx void rb_walk (const rb_tree *@var{tree}, avl_node_func @var{operate}, void *@var{param})
+Walks through all the nodes in @var{tree}, and calls function
+@var{operate} for each node in inorder. @var{param} overrides the value
+passed to @code{avl_create} (and family) for this operation only.
+@var{operate} must not change the key data in the nodes in a way that
+would reorder the data values or cause two values to become equal.
+@end deftypefun
+
+@deftypefun {void *} avl_traverse (const avl_tree *@var{tree}, avl_traverser *@var{trav})
+@deftypefunx {void *} avlt_traverse (const avlt_tree *@var{tree}, avlt_traverser *@var{trav})
+@deftypefunx {void *} avltr_traverse (const avltr_tree *@var{tree}, avltr_traverser *@var{trav})
+@deftypefunx {void *} rb_traverse (const rb_tree *@var{tree}, rb_traverser *@var{trav})
+Returns each of @var{tree}'s nodes' data values in sequence, then a null
+pointer to indicate the last item. @var{trav} must be initialized
+before the first call, either in a declaration like that below, or using
+one of the functions below.
+
+@smallexample
+avl_traverser trav = AVL_TRAVERSER_INIT;
+@end smallexample
+
+Each @code{avl_traverser} (and family) is a separate, independent
+iterator.
+
+For threaded and right-threaded trees, @code{avlt_next} or
+@code{avltr_next}, respectively, are faster and more memory-efficient
+than @code{avlt_traverse} or @code{avltr_traverse}.
+@end deftypefun
+
+@deftypefun {void *} avl_init_traverser (avl_traverser *@var{trav})
+@deftypefunx {void *} avlt_init_traverser (avlt_traverser *@var{trav})
+@deftypefunx {void *} avltr_init_traverser (avltr_traverser *@var{trav})
+@deftypefunx {void *} rb_init_traverser (rb_traverser *@var{trav})
+Initializes the specified tree traverser structure. After this function
+is called, the next call to the corresponding @code{*_traverse} function
+will return the smallest value in the appropriate tree.
+@end deftypefun
+
+@deftypefun {void **} avlt_next (const avlt_tree *@var{tree}, void **@var{data})
+@deftypefunx {void **} avltr_next (const avltr_tree *@var{tree}, void **@var{data})
+@var{data} must be a null pointer or a pointer to a data item in AVL
+tree @var{tree}. Returns a pointer to the next data item after
+@var{data} in @var{tree} in inorder (this is the first item if
+@var{data} is a null pointer), or a null pointer if @var{data} was the
+last item in @var{tree}.
+@end deftypefun
+
+@deftypefun {void **} avltr_prev (const avltr_tree *@var{tree}, void **@var{data})
+@var{data} must be a null pointer or a pointer to a data item in AVL
+tree @var{tree}. Returns a pointer to the previous data item before
+@var{data} in @var{tree} in inorder (this is the last, or greatest
+valued, item if @var{data} is a null pointer), or a null pointer if
+@var{data} was the first item in @var{tree}.
+@end deftypefun
+
+@node Conversion, Author, Iteration, Top
+@chapter Conversion
+
+@deftypefun {avlt_tree *} avlt_thread (avl_tree *@var{tree})
+@deftypefunx {avltr_tree *} avltr_thread (avl_tree *@var{tree})
+Adds symmetric threads or right threads, respectively, to unthreaded AVL
+tree @var{tree} and returns a pointer to @var{tree} cast to the
+appropriate type. After one of these functions is called, threaded or
+right-threaded functions, as appropriate, must be used with @var{tree};
+unthreaded functions may not be used.
+@end deftypefun
+
+@deftypefun {avl_tree *} avlt_unthread (avlt_tree *@var{tree})
+@deftypefunx {avl_tree *} avltr_unthread (avltr_tree *@var{tree})
+Cuts all threads in threaded or right-threaded, respectively, AVL tree
+@var{tree} and returns a pointer to @var{tree} cast to @code{avl_tree
+*}. After one of these functions is called, unthreaded functions must
+be used with @var{tree}; threaded or right-threaded functions may not be
+used.
+@end deftypefun
+
+@node Author, Index, Conversion, Top
+@chapter Author
+
+@cindex Pfaff, Benjamin Levy
+@cindex author
+@cindex Knuth, Donald Ervin
+@cindex @cite{Art of Computer Programming}
+libavl was written by Ben Pfaff @email{blp@@gnu.org}.
+
+libavl's generic tree algorithms and AVL algorithms are based on those
+found in Donald Knuth's venerable @cite{Art of Computer Programming}
+series from Addison-Wesley, primarily Volumes 1 and 3. libavl's
+red-black tree algorithms are based on those found in Cormen et al.,
+@cite{Introduction to Algorithms}, 2nd ed., from MIT Press.
+
+@node Index, , Author, Top
+@unnumbered Index
+
+@printindex cp
+
+@contents
+@bye
diff --git a/avl-1.4.0/avl.text b/avl-1.4.0/avl.text
new file mode 100644
index 0000000..9804050
--- /dev/null
+++ b/avl-1.4.0/avl.text
@@ -0,0 +1,636 @@
+This file documents libavl, a library for the manipulation of balanced
+binary trees.
+
+ Copyright 1998, 1999 Free Software Foundation, Inc.
+
+ Permission is granted to make and distribute verbatim copies of this
+manual provided the copyright notice and this permission notice are
+preserved on all copies.
+
+ Permission is granted to copy and distribute modified versions of
+this manual under the conditions for verbatim copying, provided that the
+entire resulting derived work is distributed under the terms of a
+permission notice identical to this one.
+
+ Permission is granted to copy and distribute translations of this
+manual into another language, under the above conditions for modified
+versions, except that this permission notice may be stated in a
+translation approved by the Free Software Foundation.
+
+This document
+describes libavl, a library for manipulation of balanced binary trees.
+
+ This document applies to libavl version 1.4.0.
+
+Introduction to balanced binary trees
+*************************************
+
+ Consider some techniques that can be used to find a particular item
+in a data set. Typical methods include sequential searching, digital
+searching, hash tables, and binary searching.
+
+ Sequential searching is simple, but slow (O(n)). Digital searching
+requires that the entire data set be known in advance, and memory
+efficient implementations are slow.
+
+ Hash tables are fast (O(1)) for static data sets, but they can be
+wasteful of memory. It can be difficult to choose an effective hash
+function. Some hash tables variants also make deletion an expensive
+operation.
+
+ Binary search techniques work almost as quickly (O(log(n)) on an
+ordered table, or on a binary tree. Binary trees also allow easy
+iteration over the data in the tree in sorted order. With hash tables
+it is necessary to sort the data before iterating, and after sorting
+the data is no longer in hash form.
+
+ Binary trees are efficient for insertion, deletion, and searching, if
+data are inserted in random order. But, if data are inserted in order
+using a naive algorithm, binary search degenerates to sequential search.
+
+ In turn, this problem can be solved by "rebalancing" the tree after
+each insertion or deletion. In rebalancing, nodes are rearranged via
+transformations called "rotations" using an algorithm that tends to
+minimize the tree's height.
+
+ There are several schemes for rebalancing binary trees. The two most
+common types of balanced tree are "AVL trees" and "red-black trees".
+libavl implements both types:
+
+ * AVL trees, invented by Russian mathematicians G. M.
+ Adel'son-Velskii and E. M. Landis, ensure that, for each node, the
+ difference in height between its subtrees (the "balance factor")
+ is not greater than 1.
+
+ * Red-black trees, invented by R. Bayer and studied at length by L.
+ J. Guibas and R. Sedgewick, assign each node of a tree a color (red
+ or black), and specify a set of rules governing how red and black
+ nodes may be arranged.
+
+ The table below presents a comparison among unbalanced binary trees,
+AVL trees, and red-black trees. In the table, N is the number of nodes
+in the tree and H is the tree's height before the operation. "lg" is
+the base-2 logarithm function.
+
+Operation
+ Binary Tree AVL Tree Red-Black Tree
+Time per insertion or deletion
+ O(H) O(lg N) O(lg N)
+Time for insertion of K nodes having sequential values
+ O(K^2) O(N lg N) O(N lg N)
+Time for insertion of K nodes having random values
+ O(N lg N) O(N lg N) O(N lg N)
+Maximum number of rotations per insertion
+ 0 1 lg N
+Maximum number of rotations per deletion
+ 0 lg N lg N
+Maximum H as a function of N
+ N 1.44 lg (N + 2) - .328 2 lg (N + 1)
+Minimum N as a function of H
+ H 2^((H + .328) / 1.44) - 2 2^(H / 2) - 1
+
+ There are alternatives to AVL trees that share some of their
+properties. For instance, skip lists, 2-3 trees, and splay trees all
+allow O(log(n)) insertion and deletion. The main disadvantage of these
+methods is that their operations are not as well documented in the
+literature.
+
+Introduction to threaded trees
+******************************
+
+ "Threading" is a clever method that simplifies binary tree traversal.
+
+ Nodes in a unthreaded binary tree that have zero or one subnodes have
+two or one null subnode pointers, respectively. In a threaded binary
+tree, a left child pointer that would otherwise be null is used to point
+to the node's inorder(1) predecessor, and in a null right child pointer
+points to its inorder successor.
+
+ In a threaded tree, it is always possible to find the next node and
+the previous node of a node, given only a pointer to the node in
+question. In an unthreaded tree, it's also necessary to have a list of
+the nodes between the node in question and root of the tree.
+
+ Advantages of a threaded tree compared to an unthreaded one include:
+
+ * Faster traversal and less memory usage during traversal, since no
+ stack need be maintained.
+
+ * Greater generality, since one can go from a node to its successor
+ or predecessor given only the node, simplifying algorithms that
+ require moving forward and backward in a tree.
+
+ Some disadvantages of threaded trees are:
+
+ * Slower insertion and deletion, since threads need to be
+ maintained. In somes cases, this can be alleviated by
+ constructing the tree as an unthreaded tree, then threading it
+ with a special libavl function.
+
+ * In theory, threaded trees need two extra bits per node to indicate
+ whether each child pointer points to an ordinary node or the node's
+ successor/predecessor node. In libavl, however, these bits are
+ stored in a byte that is used for structure alignment padding in
+ unthreaded binary trees, so no extra storage is used.
+
+ A "right-threaded binary tree" is similar to a threaded binary tree,
+but threads are only maintained on the right side of each node. This
+allows for traversal to the right (toward larger values) but not to the
+left (toward smaller values). Right-threaded trees are convenient when
+the properties of a threaded tree are desirable, but traversal in
+reverse sort order is not necessary. Not threading the left links saves
+time in insertions and deletions.
+
+ Left-threaded binary trees also exist, but they are not implemented
+by libavl. The same effect can be obtained by sorting the tree in the
+opposite order.
+
+ ---------- Footnotes ----------
+
+ (1) In tree traversal, "inorder" refers to visiting the nodes in
+their sorted order from smallest to largest.
+
+Types
+*****
+
+ The following types are defined and used by libavl:
+
+ - Data Type: avl_tree
+ - Data Type: avlt_tree
+ - Data Type: avltr_tree
+ - Data Type: rb_tree
+ These are the data types used to represent a tree. Although they
+ are defined in the libavl header files, it should never be
+ necessary to access them directly. Instead, all accesses should
+ take place through libavl functions.
+
+ - Data Type: avl_node
+ - Data Type: avlt_node
+ - Data Type: avltr_node
+ - Data Type: rb_node
+ These are the data types used to represent individual nodes in a
+ tree. Similar cautions apply as with `avl_tree' structures.
+
+ - Data Type: avl_traverser
+ - Data Type: avlt_traverser
+ - Data Type: avltr_traverser
+ - Data Type: rb_traverser
+ These are the data types used by the `avl_traverse' family of
+ functions to iterate across the tree. Again, these are opaque
+ structures.
+
+ - Data Type: avl_comparison_func
+ Every tree must have an ordering defined by a function of this
+ type. It must have the following signature:
+
+ int COMPARE (const void *A, const void *B, void *PARAM)
+
+ The return value is expected to be like that returned by `strcmp'
+ in the standard C library: negative if A < B, zero if A = B,
+ positive if A > B. PARAM is an arbitrary value defined by the
+ user when the tree was created.
+
+ - Data Type: avl_node_func
+ This is a class of function called to perform an operation on a
+ data item. Functions of this type have the following signature:
+
+ void OPERATE (void *DATA, void *PARAM)
+
+ DATA is the data item and PARAM is an arbitrary user-defined value
+ set when the tree was created.
+
+ - Data Type: avl_copy_func
+ This is a class of function called to make a new copy of a node's
+ data. Functions of this type have the following signature:
+
+ void *COPY (void *DATA, void *PARAM)
+
+ The function should return a new copy of DATA. PARAM is an
+ arbitrary user-defined value set when the tree was created.
+
+ - Macro: AVL_MAX_HEIGHT
+ This macro defines the maximum height of an AVL tree that can be
+ handled by functions that maintain a stack of nodes descended.
+ The default value is 32, which allows for AVL trees with a maximum
+ number of nodes between 5,704,880 and 4,294,967,295, depending on
+ order of insertion. This macro may be defined by the user before
+ including any AVL tree header file, in which case libavl will
+ honor that value.
+
+ - Macro: RB_MAX_HEIGHT
+ This macro defines the maximum height of an AVL tree that can be
+ handled by functions that maintain a stack of nodes descended.
+ The default value is 32, which allows for red-black trees with a
+ maximum number of nodes of at least 65535. This macro may be
+ defined by the user before including the red-black tree header
+ file, in which case libavl will honor that value.
+
+Functions
+*********
+
+ libavl is four libraries in one:
+
+ * An unthreaded AVL tree library.
+
+ * A threaded AVL tree library.
+
+ * A right-threaded AVL tree library.
+
+ * A red-black tree library.
+
+ Identifiers in these libraries are prefixed by `avl_', `avlt_',
+`avltr_', and `rb_', with corresponding header files `avl.h', `avlt.h',
+`avltr.h', and `rb.h', respectively. The functions that they declare
+are defined in the `.c' files with the same names.
+
+ Most tree functions are implemented in all three libraries, but
+threading allows more generality of operation. So, the threaded and
+right-threaded libraries offer a few additional functions for finding
+the next or previous node from a given node. In addition, they offer
+functions for converting trees from threaded or right-threaded
+representations to unthreaded, and vice versa.(1)
+
+ ---------- Footnotes ----------
+
+ (1) In general, you should build the sort of tree that you need to
+use, but occasionally it is useful to convert between tree types.
+
+Tree Creation
+*************
+
+ These functions deal with creation and destruction of AVL trees.
+
+ - Function: avl_tree * avl_create (avl_comparison_func COMPARE, void
+ *PARAM)
+ - Function: avlt_tree * avlt_create (avlt_comparison_func COMPARE,
+ void *PARAM)
+ - Function: avltr_tree * avltr_create (avltr_comparison_func COMPARE,
+ void *PARAM)
+ - Function: rb_tree * rb_create (avl_comparison_func COMPARE, void
+ *PARAM)
+ Create a new, empty tree with comparison function COMPARE.
+ Arbitrary user data PARAM is saved so that it can be passed to
+ user callback functions.
+
+ - Function: void avl_destroy (avl_tree *TREE, avl_node_func FREE)
+ - Function: void avlt_destroy (avlt_tree *TREE, avl_node_func FREE)
+ - Function: void avltr_destroy (avltr_tree *TREE, avl_node_func FREE)
+ - Function: void rb_destroy (rb_tree *TREE, avl_node_func FREE)
+ Destroys TREE, releasing all of its storage. If FREE is non-null,
+ then it is called for every node in postorder before that node is
+ freed.
+
+ - Function: void avl_free (avl_tree *TREE)
+ - Function: void avlt_free (avlt_tree *TREE)
+ - Function: void avltr_free (avltr_tree *TREE)
+ - Function: void rb_free (rb_tree *TREE)
+ Destroys TREE, releasing all of its storage. The data in each
+ node is freed with a call to the standard C library function
+ `free'.
+
+ - Function: avl_tree * avl_copy (const avl_tree *TREE, avl_copy_func
+ COPY)
+ - Function: avlt_tree * avl_copy (const avlt_tree *TREE, avl_copy_func
+ COPY)
+ - Function: avltr_tree * avl_copy (const avltr_tree *TREE,
+ avl_copy_func COPY)
+ - Function: rb_tree * rb_copy (const rb_tree *TREE, avl_copy_func COPY)
+ Copies the contents of TREE into a new tree, and returns the new
+ tree. If COPY is non-null, then it is called to make a new copy
+ of each node's data; otherwise, the node data is copied verbatim
+ into the new tree.
+
+ - Function: int avl_count (const avl_tree *TREE)
+ - Function: int avlt_count (const avlt_tree *TREE)
+ - Function: int avltr_count (const avltr_tree *TREE)
+ - Function: int rb_count (const rb_tree *TREE)
+ Returns the number of nodes in TREE.
+
+ - Function: void * xmalloc (size_t SIZE)
+ This is not a function defined by libavl. Instead, it is a
+ function that the user program can define. It must allocate SIZE
+ bytes using `malloc' and return it. It can handle out-of-memory
+ errors however it chooses, but it may not ever return a null
+ pointer.
+
+ If there is an `xmalloc' function defined for use by libavl, the
+ source files (`avl.c', `avlt.c', `avltr.c', `rb.c') must be
+ compiled with `HAVE_XMALLOC' defined. Otherwise, the library will
+ use its internal static `xmalloc', which handles out-of-memory
+ errors by printing a message `virtual memory exhausted' to stderr
+ and terminating the program with exit code `EXIT_FAILURE'.
+
+Insertion and Deletion
+**********************
+
+ These function insert nodes, delete nodes, and search for nodes in
+trees.
+
+ - Function: void ** avl_probe (avl_tree *TREE, void *DATA)
+ - Function: void ** avlt_probe (avlt_tree *TREE, void *DATA)
+ - Function: void ** avltr_probe (avltr_tree *TREE, void *DATA)
+ - Function: void ** rb_probe (rb_tree *TREE, void *DATA)
+ These are the workhorse functions for tree insertion. They search
+ TREE for a node with data matching DATA. If found, a pointer to
+ the matching data is returned. Otherwise, a new node is created
+ for DATA, and a pointer to that data is returned. In either case,
+ the pointer returned can be changed by the user, but the key data
+ used by the tree's comparison must not be changed(1).
+
+ It is usually easier to use one of the `avl_insert' or
+ `avl_replace' functions instead of `avl_probe' directly.
+
+ *Please note:* It's not a particularly good idea to insert a null
+ pointer as a data item into a tree, because several libavl
+ functions return a null pointer to indicate failure. You can
+ sometimes avoid a problem by using functions that return a pointer
+ to a pointer instead of a plain pointer. Also be wary of this
+ when casting an arithmetic type to a void pointer for
+ insertion--on typical architectures, 0's become null pointers when
+ this is done.
+
+ - Function: void * avl_insert (avl_tree *TREE, void *DATA)
+ - Function: void * avlt_insert (avlt_tree *TREE, void *DATA)
+ - Function: void * avltr_insert (avltr_tree *TREE, void *DATA)
+ - Function: void * rb_insert (rb_tree *TREE, void *DATA)
+ If a node with data matching DATA exists in TREE, returns the
+ matching data item. Otherwise, inserts DATA into TREE and returns
+ a null pointer.
+
+ - Function: void avl_force_insert (avl_tree *TREE, void *DATA)
+ - Function: void avlt_force_insert (avlt_tree *TREE, void *DATA)
+ - Function: void avltr_force_insert (avltr_tree *TREE, void *DATA)
+ - Function: void rb_force_insert (rb_tree *TREE, void *DATA)
+ Inserts DATA into TREE. If a node with data matching DATA exists
+ in TREE, aborts the program with an assertion violation. This
+ function is implemented as a macro; if it is used, the standard C
+ header `assert.h' must also be included. If macro `NDEBUG' is
+ defined when a libavl header is included, these functions are
+ short-circuited to a direct call to `avl_insert', and no check is
+ performed.
+
+ - Function: void * avl_replace (avl_tree *TREE, void *DATA)
+ - Function: void * avlt_replace (avlt_tree *TREE, void *DATA)
+ - Function: void * avltr_replace (avltr_tree *TREE, void *DATA)
+ - Function: void * rb_replace (rb_tree *TREE, void *DATA)
+ If a node with data matching DATA, such that the comparison
+ function returns 0, exists in TREE, replaces the node's data with
+ DATA and returns the node's former contents. Otherwise, inserts
+ DATA into TREE and returns a null pointer.
+
+ - Function: void * avl_delete (avl_tree *TREE, const void *DATA)
+ - Function: void * avlt_delete (avlt_tree *TREE, const void *DATA)
+ - Function: void * avltr_delete (avltr_tree *TREE, const void *DATA)
+ - Function: void * rb_delete (rb_tree *TREE, const void *DATA)
+ Searches TREE for a node with data matching DATA. If found, the
+ node is deleted and its data is returned. Otherwise, returns a
+ null pointer.
+
+ - Function: void * avl_force_delete (avl_tree *TREE, const void *DATA)
+ - Function: void * avlt_force_delete (avlt_tree *TREE, const void
+ *DATA)
+ - Function: void * avltr_force_delete (avltr_tree *TREE, const void
+ *DATA)
+ - Function: void * rb_force_delete (rb_tree *TREE, const void *DATA)
+ Deletes a node with data matching DATA from TREE. If no matching
+ node is found, aborts the program with an assertion violation. If
+ macro `NDEBUG' is declared when a libavl header is included, these
+ functions are short-circuited to a direct call to `avl_delete',
+ and no check is performed.
+
+ ---------- Footnotes ----------
+
+ (1) It can be changed if this would not change the ordering of the
+nodes in the tree; i.e., if this would not cause the data in the node
+to be less than or equal to the previous node's data or greater than or
+equal to the next node's data.
+
+Searching
+*********
+
+ These function search a tree for an item without making an insertion
+or a deletion.
+
+ - Function: void * avl_find (avl_tree *TREE, const void *DATA)
+ - Function: void ** avlt_find (avlt_tree *TREE, const void *DATA)
+ - Function: void ** avltr_find (avltr_tree *TREE, const void *DATA)
+ - Function: void * rb_find (rb_tree *TREE, const void *DATA)
+ Searches TREE for a node with data matching DATA, If found,
+ returns the node's data (for threaded and right-threaded trees, a
+ pointer to the node's data). Otherwise, returns a null pointer.
+
+ - Function: void * avl_find_close (avl_tree *TREE, const void *DATA)
+ - Function: void ** avlt_find_close (avlt_tree *TREE, const void *DATA)
+ - Function: void ** avltr_find_close (avltr_tree *TREE, const void
+ *DATA)
+ - Function: void * rb_find_close (rb_tree *TREE, const void *DATA)
+ Searches TREE for a node with data matching DATA. If found,
+ returns the node's data (for threaded and right-threaded trees, a
+ pointer to the node's data). If no matching item is found, then it
+ finds a node whose data is "close" to DATA; either the node
+ closest in value to DATA, or the node either before or after the
+ node with the closest value. Returns a null pointer if the tree
+ does not contain any nodes.
+
+Iteration
+*********
+
+ These functions allow the caller to iterate across the items in a
+tree.
+
+ - Function: void avl_walk (const avl_tree *TREE, avl_node_func
+ OPERATE, void *PARAM)
+ - Function: void avlt_walk (const avlt_tree *TREE, avl_node_func
+ OPERATE, void *PARAM)
+ - Function: void avltr_walk (const avltr_tree *TREE, avl_node_func
+ OPERATE, void *PARAM)
+ - Function: void rb_walk (const rb_tree *TREE, avl_node_func OPERATE,
+ void *PARAM)
+ Walks through all the nodes in TREE, and calls function OPERATE
+ for each node in inorder. PARAM overrides the value passed to
+ `avl_create' (and family) for this operation only. OPERATE must
+ not change the key data in the nodes in a way that would reorder
+ the data values or cause two values to become equal.
+
+ - Function: void * avl_traverse (const avl_tree *TREE, avl_traverser
+ *TRAV)
+ - Function: void * avlt_traverse (const avlt_tree *TREE,
+ avlt_traverser *TRAV)
+ - Function: void * avltr_traverse (const avltr_tree *TREE,
+ avltr_traverser *TRAV)
+ - Function: void * rb_traverse (const rb_tree *TREE, rb_traverser
+ *TRAV)
+ Returns each of TREE's nodes' data values in sequence, then a null
+ pointer to indicate the last item. TRAV must be initialized
+ before the first call, either in a declaration like that below, or
+ using one of the functions below.
+
+ avl_traverser trav = AVL_TRAVERSER_INIT;
+
+ Each `avl_traverser' (and family) is a separate, independent
+ iterator.
+
+ For threaded and right-threaded trees, `avlt_next' or
+ `avltr_next', respectively, are faster and more memory-efficient
+ than `avlt_traverse' or `avltr_traverse'.
+
+ - Function: void * avl_init_traverser (avl_traverser *TRAV)
+ - Function: void * avlt_init_traverser (avlt_traverser *TRAV)
+ - Function: void * avltr_init_traverser (avltr_traverser *TRAV)
+ - Function: void * rb_init_traverser (rb_traverser *TRAV)
+ Initializes the specified tree traverser structure. After this
+ function is called, the next call to the corresponding
+ `*_traverse' function will return the smallest value in the
+ appropriate tree.
+
+ - Function: void ** avlt_next (const avlt_tree *TREE, void **DATA)
+ - Function: void ** avltr_next (const avltr_tree *TREE, void **DATA)
+ DATA must be a null pointer or a pointer to a data item in AVL
+ tree TREE. Returns a pointer to the next data item after DATA in
+ TREE in inorder (this is the first item if DATA is a null
+ pointer), or a null pointer if DATA was the last item in TREE.
+
+ - Function: void ** avltr_prev (const avltr_tree *TREE, void **DATA)
+ DATA must be a null pointer or a pointer to a data item in AVL
+ tree TREE. Returns a pointer to the previous data item before
+ DATA in TREE in inorder (this is the last, or greatest valued,
+ item if DATA is a null pointer), or a null pointer if DATA was the
+ first item in TREE.
+
+Conversion
+**********
+
+ - Function: avlt_tree * avlt_thread (avl_tree *TREE)
+ - Function: avltr_tree * avltr_thread (avl_tree *TREE)
+ Adds symmetric threads or right threads, respectively, to
+ unthreaded AVL tree TREE and returns a pointer to TREE cast to the
+ appropriate type. After one of these functions is called,
+ threaded or right-threaded functions, as appropriate, must be used
+ with TREE; unthreaded functions may not be used.
+
+ - Function: avl_tree * avlt_unthread (avlt_tree *TREE)
+ - Function: avl_tree * avltr_unthread (avltr_tree *TREE)
+ Cuts all threads in threaded or right-threaded, respectively, AVL
+ tree TREE and returns a pointer to TREE cast to `avl_tree *'.
+ After one of these functions is called, unthreaded functions must
+ be used with TREE; threaded or right-threaded functions may not be
+ used.
+
+Author
+******
+
+ libavl was written by Ben Pfaff <blp@gnu.org>.
+
+ libavl's generic tree algorithms and AVL algorithms are based on
+those found in Donald Knuth's venerable `Art of Computer Programming'
+series from Addison-Wesley, primarily Volumes 1 and 3. libavl's
+red-black tree algorithms are based on those found in Cormen et al.,
+`Introduction to Algorithms', 2nd ed., from MIT Press.
+
+Index
+*****
+
+* Menu:
+
+* `Art of Computer Programming': Author.
+* Adel'son-Velskii, G. M.: Introduction to balanced binary trees.
+* author: Author.
+* AVL tree: Introduction to balanced binary trees.
+* avl_comparison_func: Types.
+* avl_copy: Tree Creation.
+* avl_copy_func: Types.
+* avl_count: Tree Creation.
+* avl_create: Tree Creation.
+* avl_delete: Insertion.
+* avl_destroy: Tree Creation.
+* avl_find: Searching.
+* avl_find_close: Searching.
+* avl_force_delete: Insertion.
+* avl_force_insert: Insertion.
+* avl_free: Tree Creation.
+* avl_init_traverser: Iteration.
+* avl_insert: Insertion.
+* AVL_MAX_HEIGHT: Types.
+* avl_node: Types.
+* avl_node_func: Types.
+* avl_probe: Insertion.
+* avl_replace: Insertion.
+* avl_traverse: Iteration.
+* avl_traverser: Types.
+* avl_tree: Types.
+* avl_walk: Iteration.
+* avlt_count: Tree Creation.
+* avlt_create: Tree Creation.
+* avlt_delete: Insertion.
+* avlt_destroy: Tree Creation.
+* avlt_find: Searching.
+* avlt_find_close: Searching.
+* avlt_force_delete: Insertion.
+* avlt_force_insert: Insertion.
+* avlt_free: Tree Creation.
+* avlt_init_traverser: Iteration.
+* avlt_insert: Insertion.
+* avlt_next: Iteration.
+* avlt_node: Types.
+* avlt_probe: Insertion.
+* avlt_replace: Insertion.
+* avlt_thread: Conversion.
+* avlt_traverse: Iteration.
+* avlt_traverser: Types.
+* avlt_tree: Types.
+* avlt_unthread: Conversion.
+* avlt_walk: Iteration.
+* avltr_count: Tree Creation.
+* avltr_create: Tree Creation.
+* avltr_delete: Insertion.
+* avltr_destroy: Tree Creation.
+* avltr_find: Searching.
+* avltr_find_close: Searching.
+* avltr_force_delete: Insertion.
+* avltr_force_insert: Insertion.
+* avltr_free: Tree Creation.
+* avltr_init_traverser: Iteration.
+* avltr_insert: Insertion.
+* avltr_next: Iteration.
+* avltr_node: Types.
+* avltr_prev: Iteration.
+* avltr_probe: Insertion.
+* avltr_replace: Insertion.
+* avltr_thread: Conversion.
+* avltr_traverse: Iteration.
+* avltr_traverser: Types.
+* avltr_tree: Types.
+* avltr_unthread: Conversion.
+* avltr_walk: Iteration.
+* binary tree: Introduction to balanced binary trees.
+* hash table: Introduction to balanced binary trees.
+* Knuth, Donald Ervin: Author.
+* Landis, E. M.: Introduction to balanced binary trees.
+* Pfaff, Benjamin Levy: Author.
+* rb_copy: Tree Creation.
+* rb_count: Tree Creation.
+* rb_create: Tree Creation.
+* rb_delete: Insertion.
+* rb_destroy: Tree Creation.
+* rb_find: Searching.
+* rb_find_close: Searching.
+* rb_force_delete: Insertion.
+* rb_force_insert: Insertion.
+* rb_free: Tree Creation.
+* rb_init_traverser: Iteration.
+* rb_insert: Insertion.
+* RB_MAX_HEIGHT: Types.
+* rb_node: Types.
+* rb_probe: Insertion.
+* rb_replace: Insertion.
+* rb_traverse: Iteration.
+* rb_traverser: Types.
+* rb_tree: Types.
+* rb_walk: Iteration.
+* rebalancing: Introduction to balanced binary trees.
+* red-black tree: Introduction to balanced binary trees.
+* right threads: Functions.
+* threads: Functions.
+* unthreaded: Functions.
+* xmalloc: Tree Creation.
+
diff --git a/avl-1.4.0/avlt.c b/avl-1.4.0/avlt.c
new file mode 100644
index 0000000..d050fba
--- /dev/null
+++ b/avl-1.4.0/avlt.c
@@ -0,0 +1,1597 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file avlt.c in libavl. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#if SELF_TEST
+#include <limits.h>
+#include <time.h>
+#endif
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "avlt.h"
+
+/* Tag types. */
+#define PLUS +1
+#define MINUS -1
+
+#if !__GCC__ && !defined (inline)
+#define inline
+#endif
+
+#if __GNUC__ >= 2
+#define unused __attribute__ ((unused))
+#else
+#define unused
+#endif
+
+#ifdef HAVE_XMALLOC
+void *xmalloc (size_t);
+#else /* !HAVE_XMALLOC */
+/* Allocates SIZE bytes of space using malloc(). Aborts if out of
+ memory. */
+static void *
+xmalloc (size_t size)
+{
+ void *vp;
+ if (size == 0)
+ return NULL;
+ vp = malloc (size);
+ assert (vp != NULL);
+ if (vp == NULL)
+ {
+ fprintf (stderr, "virtual memory exhausted\n");
+ exit (EXIT_FAILURE);
+ }
+ return vp;
+}
+#endif /* !HAVE_XMALLOC */
+
+/* Creates an AVL tree in arena OWNER (which can be NULL). The arena
+ is owned by the caller, not by the AVL tree. CMP is a order
+ function for the data to be stored in the tree. PARAM is arbitrary
+ data that becomes an argument to the comparison function. */
+avlt_tree *
+avlt_create (avl_comparison_func cmp, void *param)
+{
+ avlt_tree *tree;
+
+ assert (cmp != NULL);
+ tree = xmalloc (sizeof (avlt_tree));
+
+ tree->root.link[0] = tree->root.link[1] = &tree->root;
+ tree->root.tag[0] = MINUS;
+ tree->root.tag[1] = PLUS;
+ tree->cmp = cmp;
+ tree->count = 0;
+ tree->param = param;
+
+ return tree;
+}
+
+/* Destroy tree TREE. Function FREE_FUNC is called for every node in
+ the tree as it is destroyed.
+
+ No effect if the tree has an arena owner and free_func is NULL.
+ The caller owns the arena and must destroy it itself.
+
+ Do not attempt to reuse the tree after it has been freed. Create a
+ new one. */
+void
+avlt_destroy (avlt_tree *tree, avl_node_func free_func)
+{
+ assert (tree != NULL);
+
+ if (tree->root.link[0] != &tree->root)
+ {
+ /* Uses Knuth's Algorithm 2.3.1T as modified in exercise 13
+ (postorder traversal). */
+
+ /* T1. */
+ avlt_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ char ab[AVL_MAX_HEIGHT]; /* Stack A: bits. */
+ int ap = 0; /* Stack A: height. */
+ avlt_node *p = tree->root.link[0];
+
+ for (;;)
+ {
+ /* T2. */
+ for (;;)
+ {
+ /* T3. */
+ ab[ap] = 0;
+ an[ap++] = p;
+ if (p->tag[0] == MINUS)
+ break;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ for (;;)
+ {
+ if (ap == 0)
+ goto done;
+
+ p = an[--ap];
+ if (ab[ap] == 0)
+ {
+ ab[ap++] = 1;
+ if (p->tag[1] == MINUS)
+ continue;
+ p = p->link[1];
+ break;
+ }
+
+ if (free_func)
+ free_func (p->data, tree->param);
+ free (p);
+ }
+ }
+ }
+
+ done:
+ free (tree);
+}
+
+/* avlt_destroy() with FREE_FUNC hardcoded as free(). */
+void
+avlt_free (avlt_tree *tree)
+{
+ avlt_destroy (tree, (avl_node_func) free);
+}
+
+/* Return the number of nodes in TREE. */
+int
+avlt_count (const avlt_tree *tree)
+{
+ assert (tree != NULL);
+ return tree->count;
+}
+
+/* Copy the contents of TREE to a new tree in arena OWNER. If COPY is
+ non-NULL, then each data item is passed to function COPY, and the
+ return values are inserted into the new tree; otherwise, the items
+ are copied verbatim from the old tree to the new tree. Returns the
+ new tree. */
+avlt_tree *
+avlt_copy (const avlt_tree *tree, avl_copy_func copy)
+{
+ /* Knuth's Algorithm 2.3.1C (copying a binary tree). Additionally
+ uses Algorithm 2.3.1I (insertion into a threaded binary tree) and
+ Algorithm 2.3.1 exercise 17 (preorder successor in threaded
+ binary tree). */
+
+ avlt_tree *new_tree;
+
+ const avlt_node *p;
+ avlt_node *q;
+
+ assert (tree != NULL);
+ new_tree = avlt_create (tree->cmp, tree->param);
+ new_tree->count = tree->count;
+ p = &tree->root;
+ if (p->link[0] == p)
+ return new_tree;
+ q = &new_tree->root;
+
+ for (;;)
+ {
+ /* C4. This is Algorithm 2.3.1I modified for insertion to the
+ left. Step I2 is not necessary. */
+ if (p->tag[0] == PLUS)
+ {
+ avlt_node *r = xmalloc (sizeof (avlt_node));
+
+ r->link[0] = q->link[0];
+ r->tag[0] = q->tag[0];
+ q->link[0] = r;
+ q->tag[0] = PLUS;
+ r->link[1] = q;
+ r->tag[1] = MINUS;
+ }
+
+ /* C5: Find preorder successors of P and Q. This is Algorithm
+ 2.3.1 exercise 17 but applies its actions to Q as well as
+ P. */
+ if (p->tag[0] == PLUS)
+ {
+ p = p->link[0];
+ q = q->link[0];
+ }
+ else
+ {
+ while (p->tag[1] == MINUS)
+ {
+ p = p->link[1];
+ q = q->link[1];
+ }
+ p = p->link[1];
+ q = q->link[1];
+ }
+
+ /* C6. */
+ if (p == &tree->root)
+ {
+ assert (q == &new_tree->root);
+ return new_tree;
+ }
+
+ /* C2. This is Algorithm 2.3.1I. Step I2 is not necessary. */
+ if (p->tag[1] == PLUS)
+ {
+ avlt_node *r = xmalloc (sizeof (avlt_node));
+
+ r->link[1] = q->link[1];
+ r->tag[1] = q->tag[1];
+ q->link[1] = r;
+ q->tag[1] = PLUS;
+ r->link[0] = q;
+ r->tag[0] = MINUS;
+ }
+
+ /* C3. */
+ q->bal = p->bal;
+ if (copy == NULL)
+ q->data = p->data;
+ else
+ q->data = copy (p->data, tree->param);
+ }
+}
+
+/* Threads the unthreaded AVL tree TREE in-place, and returns TREE cast to
+ avlt_tree *. */
+avlt_tree *
+avlt_thread (struct avl_tree *_tree)
+{
+ /* Uses Knuth's Algorithm 2.3.1 exercise 30 (thread an unthreaded
+ tree, with Algorithm 2.3.1T (inorder traversal) for computing
+ Q$. */
+
+ avlt_tree *tree = (avlt_tree *) _tree;
+
+ /* Algorithm T's variables. */
+ avlt_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ avlt_node **ap; /* Stack A: stack pointer. */
+ avlt_node *tp; /* P. */
+
+ /* Algorithm L's variables. */
+ avlt_node *p, *q;
+
+ assert (tree != NULL);
+
+ /* T1. */
+ ap = an;
+ tp = tree->root.link[0];
+
+ /* L1. */
+ q = &tree->root;
+ q->link[1] = q;
+
+ for (;;)
+ {
+ /* L2. */
+ {
+ /* T2. */
+ while (tp != NULL)
+ {
+ /* T3. */
+ *ap++ = tp;
+ tp = tp->link[0];
+ }
+
+ /* T4. Modified to visit HEAD after fully traversing the
+ tree. */
+ if (ap == an)
+ tp = &tree->root;
+ else
+ tp = *--ap;
+
+ /* T5: Visit P. */
+ p = tp;
+ }
+
+ /* L3. */
+ if (q->link[1] == NULL)
+ {
+ q->link[1] = p;
+ q->tag[1] = MINUS;
+ }
+ else
+ q->tag[1] = PLUS;
+
+ if (p->link[0] == NULL)
+ {
+ p->link[0] = q;
+ p->tag[0] = MINUS;
+ }
+ else
+ p->tag[0] = PLUS;
+
+ /* L4. */
+ if (p == &tree->root)
+ return tree;
+ q = p;
+
+ /* T5: Next. */
+ tp = tp->link[1];
+ }
+}
+
+/* Unthreads the threaded tree TREE in-place, and returns TREE cast to
+ avl_tree *. */
+struct avl_tree *
+avlt_unthread (avlt_tree *tree)
+{
+ /* Uses Knuth's Algorithm 2.3.1T as modified in exercise 13
+ (postorder traversal). */
+
+ /* T1. */
+ avlt_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ char ab[AVL_MAX_HEIGHT]; /* Stack A: bits. */
+ int ap = 0; /* Stack A: height. */
+ avlt_node *p;
+
+ assert (tree != NULL);
+ p = tree->root.link[0];
+ if (p != &tree->root)
+ for (;;)
+ {
+ /* T2. */
+ for (;;)
+ {
+ /* T3. */
+ ab[ap] = 0;
+ an[ap++] = p;
+ if (p->tag[0] == MINUS)
+ break;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ for (;;)
+ {
+ if (ap == 0)
+ goto done;
+
+ p = an[--ap];
+ if (ab[ap] == 0)
+ {
+ ab[ap++] = 1;
+ if (p->tag[1] == MINUS)
+ continue;
+ p = p->link[1];
+ break;
+ }
+
+ if (p->tag[0] == MINUS)
+ p->link[0] = NULL;
+ if (p->tag[1] == MINUS)
+ p->link[1] = NULL;
+ }
+ }
+ else
+ tree->root.link[0] = NULL;
+
+ done:
+ tree->root.link[1] = NULL;
+ return (struct avl_tree *) tree;
+}
+
+/* Walk tree TREE in inorder, calling WALK_FUNC at each node. Passes
+ PARAM to WALK_FUNC. */
+void
+avlt_walk (const avlt_tree *tree, avl_node_func walk_func, void *param)
+{
+ const avlt_node *p;
+
+ /* Uses Knuth's algorithm 2.3.1D (threaded inorder successor). */
+ assert (tree && walk_func);
+
+ p = &tree->root;
+ for (;;)
+ {
+ if (p->tag[1] == MINUS)
+ p = p->link[1];
+ else
+ {
+ p = p->link[1];
+ while (p->tag[0] == PLUS)
+ p = p->link[0];
+ }
+
+ if (p == &tree->root)
+ return;
+
+ walk_func (p->data, param);
+ }
+}
+
+/* Each call to this function for a given TREE and TRAV return the
+ next item in the tree in inorder. Initialize the first element of
+ TRAV (init) to 0 before calling the first time. Returns NULL when
+ out of elements. */
+void *
+avlt_traverse (const avlt_tree *tree, avlt_traverser *trav)
+{
+ const avlt_node *p;
+
+ assert (tree && trav);
+
+ if (trav->init == 0)
+ {
+ p = &tree->root;
+ trav->init = 1;
+ }
+ else
+ p = trav->p;
+
+ /* Knuth's Algorithm 2.3.1S (threaded inorder successor). */
+ if (p->tag[1] == MINUS)
+ p = p->link[1];
+ else
+ {
+ p = p->link[1];
+ while (p->tag[0] == PLUS)
+ p = p->link[0];
+ }
+
+ if (p == &tree->root)
+ {
+ trav->init = 0;
+ return NULL;
+ }
+ else
+ {
+ trav->p = p;
+ return (void *) p->data;
+ }
+}
+
+/* Given ITEM, a pointer to a data item in TREE (or NULL), returns a
+ pointer to the next item in the tree in comparison order, or NULL
+ if ITEM is the last item. */
+void **
+avlt_next (const avlt_tree *tree, void **item)
+{
+ const avlt_node *p;
+
+ assert (tree != NULL);
+ if (item == NULL)
+ p = &tree->root;
+ else
+ p = (avlt_node *) (((char *) item) - offsetof (avlt_node, data));
+
+ /* Knuth's Algorithm 2.3.1S (threaded inorder successor). */
+ if (p->tag[1] == MINUS)
+ p = p->link[1];
+ else
+ {
+ p = p->link[1];
+ while (p->tag[0] == PLUS)
+ p = p->link[0];
+ }
+
+ if (p == &tree->root)
+ return NULL;
+
+ return (void **) &p->data;
+}
+
+/* Given ITEM, a pointer to a data item in TREE (or NULL), returns a
+ pointer to the previous item in the tree in comparison order, or
+ NULL if ITEM is the first item. */
+void **
+avlt_prev (const avlt_tree *tree, void **item)
+{
+ const avlt_node *p;
+
+ assert (tree != NULL);
+ if (item == NULL)
+ {
+ /* Find node with greatest value. */
+ p = tree->root.link[0];
+ if (p == &tree->root)
+ return NULL;
+ while (p->tag[1] == PLUS)
+ p = p->link[1];
+ }
+ else
+ {
+ p = (avlt_node *) (((char *) item) - offsetof (avlt_node, data));
+
+ /* Knuth's Algorithm 2.3.1S (threaded inorder successor)
+ modified to find the predecessor node. */
+ if (p->tag[0] == MINUS)
+ p = p->link[0];
+ else
+ {
+ assert (p->tag[0] == PLUS);
+ p = p->link[0];
+ while (p->tag[1] == PLUS)
+ p = p->link[1];
+ }
+ }
+
+ if (p == &tree->root)
+ return NULL;
+
+ return (void **) &p->data;
+}
+
+/* Search TREE for an item matching ITEM. If found, returns a pointer
+ to the address of the item. If none is found, ITEM is inserted
+ into the tree, and a pointer to the address of ITEM is returned.
+ In either case, the pointer returned can be changed by the caller,
+ or the returned data item can be directly edited, but the key data
+ in the item must not be changed. */
+void **
+avlt_probe (avlt_tree *tree, void *item)
+{
+ /* Uses Knuth's Algorithm 6.2.3A (balanced tree search and
+ insertion), modified for a threaded binary tree. Caches results
+ of comparisons. In empirical tests this eliminates about 25% of
+ the comparisons seen under random insertions. */
+
+ /* A1. */
+ avlt_node *t;
+ avlt_node *s, *p, *q, *r;
+
+ assert (tree != NULL);
+ t = &tree->root;
+ s = p = t->link[0];
+
+ if (t->tag[0] == MINUS)
+ {
+ tree->count++;
+ assert (tree->count == 1);
+ t->tag[0] = PLUS;
+ q = t->link[0] = xmalloc (sizeof (avlt_node));
+ q->data = item;
+ q->link[0] = q->link[1] = t;
+ q->tag[0] = q->tag[1] = MINUS;
+ q->bal = 0;
+ return &q->data;
+ }
+
+ for (;;)
+ {
+ /* A2. */
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ /* A3. */
+ if (diff < 0)
+ {
+ p->cache = 0;
+ q = p->link[0];
+ if (p->tag[0] == MINUS)
+ {
+ q = xmalloc (sizeof (avlt_node));
+ q->link[0] = p->link[0];
+ q->tag[0] = p->tag[0];
+ p->link[0] = q;
+ p->tag[0] = PLUS;
+ q->link[1] = p;
+ q->tag[1] = MINUS;
+ break;
+ }
+ }
+ /* A4. */
+ else if (diff > 0)
+ {
+ p->cache = 1;
+ q = p->link[1];
+ if (p->tag[1] == MINUS)
+ {
+ q = xmalloc (sizeof (avlt_node));
+ q->link[1] = p->link[1];
+ q->tag[1] = p->tag[1];
+ p->link[1] = q;
+ p->tag[1] = PLUS;
+ q->link[0] = p;
+ q->tag[0] = MINUS;
+ break;
+ }
+ }
+ else
+ /* A2. */
+ return &p->data;
+
+ /* A3, A4. */
+ if (q->bal != 0)
+ t = p, s = q;
+ p = q;
+ }
+
+ /* A5. */
+ tree->count++;
+ q->data = item;
+ q->bal = 0;
+
+ /* A6. */
+ r = p = s->link[(int) s->cache];
+ while (p != q)
+ {
+ p->bal = p->cache * 2 - 1;
+ p = p->link[(int) p->cache];
+ }
+
+ /* A7. */
+ if (s->cache == 0)
+ {
+ /* a = -1. */
+ if (s->bal == 0)
+ {
+ s->bal = -1;
+ return &q->data;
+ }
+ else if (s->bal == +1)
+ {
+ s->bal = 0;
+ return &q->data;
+ }
+
+ assert (s->bal == -1);
+ if (r->bal == -1)
+ {
+ /* A8. */
+ p = r;
+ s->link[0] = r->link[1];
+ s->tag[0] = r->tag[1];
+ r->link[1] = s;
+ r->tag[1] = PLUS;
+ if (s->link[0] == s)
+ {
+ s->link[0] = r;
+ s->tag[0] = MINUS;
+ }
+ r->tag[0] = r->tag[1] = PLUS;
+ s->bal = r->bal = 0;
+ }
+ else
+ {
+ /* A9. */
+ assert (r->bal == +1);
+ p = r->link[1];
+ r->link[1] = p->link[0];
+ p->link[0] = r;
+ s->link[0] = p->link[1];
+ p->link[1] = s;
+ if (p->bal == -1)
+ s->bal = 1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == +1);
+ s->bal = 0, r->bal = -1;
+ }
+ p->bal = 0;
+ p->tag[0] = p->tag[1] = PLUS;
+ if (s->link[0] == s)
+ {
+ s->link[0] = p;
+ s->tag[0] = MINUS;
+ }
+ if (r->link[1] == r)
+ {
+ r->link[1] = p;
+ r->tag[1] = MINUS;
+ }
+ }
+ }
+ else
+ {
+ /* a == +1. */
+ if (s->bal == 0)
+ {
+ s->bal = 1;
+ return &q->data;
+ }
+ else if (s->bal == -1)
+ {
+ s->bal = 0;
+ return &q->data;
+ }
+
+ assert (s->bal == +1);
+ if (r->bal == +1)
+ {
+ /* A8. */
+ p = r;
+ s->link[1] = r->link[0];
+ s->tag[1] = r->tag[0];
+ r->link[0] = s;
+ r->tag[0] = PLUS;
+ if (s->link[1] == s)
+ {
+ s->link[1] = r;
+ s->tag[1] = MINUS;
+ }
+ s->bal = r->bal = 0;
+ }
+ else
+ {
+ /* A9. */
+ assert (r->bal == -1);
+ p = r->link[0];
+ r->link[0] = p->link[1];
+ p->link[1] = r;
+ s->link[1] = p->link[0];
+ p->link[0] = s;
+ if (p->bal == +1)
+ s->bal = -1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == -1);
+ s->bal = 0, r->bal = 1;
+ }
+ p->tag[0] = p->tag[1] = PLUS;
+ if (s->link[1] == s)
+ {
+ s->link[1] = p;
+ s->tag[1] = MINUS;
+ }
+ if (r->link[0] == r)
+ {
+ r->link[0] = p;
+ r->tag[0] = MINUS;
+ }
+ p->bal = 0;
+ }
+ }
+
+ /* A10. */
+ if (t != &tree->root && s == t->link[1])
+ t->link[1] = p;
+ else
+ t->link[0] = p;
+
+ return &q->data;
+}
+
+/* Search TREE for an item matching ITEM, and return a pointer to it
+ if found. */
+void **
+avlt_find (const avlt_tree *tree, const void *item)
+{
+ const avlt_node *p;
+
+ assert (tree != NULL);
+ if (tree->root.tag[0] == MINUS)
+ /* Tree is empty. */
+ return NULL;
+
+ p = tree->root.link[0];
+ for (;;)
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+ int t;
+
+ /* A3. */
+ if (diff < 0)
+ t = 0;
+ else if (diff > 0)
+ t = 1;
+ else
+ return (void **) &p->data;
+
+ if (p->tag[t] == PLUS)
+ p = p->link[t];
+ else
+ return NULL;
+ }
+}
+
+/* Search TREE for an item close to the value of ITEM, and return it.
+ This function will return a null pointer only if TREE is empty. */
+void **
+avlt_find_close (const avlt_tree *tree, const void *item)
+{
+ const avlt_node *p;
+
+ assert (tree != NULL);
+ if (tree->root.tag[0] == MINUS)
+ /* Tree is empty. */
+ return NULL;
+
+ p = tree->root.link[0];
+ for (;;)
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+ int t;
+
+ /* A3. */
+ if (diff < 0)
+ t = 0;
+ else if (diff > 0)
+ t = 1;
+ else
+ return (void **) &p->data;
+
+ if (p->tag[t] == PLUS)
+ p = p->link[t];
+ else
+ return (void **) &p->data;
+ }
+}
+
+/* Searches AVL tree TREE for an item matching ITEM. If found, the
+ item is removed from the tree and the actual item found is returned
+ to the caller. If no item matching ITEM exists in the tree,
+ returns NULL. */
+void *
+avlt_delete (avlt_tree *tree, const void *item)
+{
+ /* Uses my Algorithm DT, which can be found at
+ http://www.msu.edu/user/pfaffben/avl. Algorithm DT is based on
+ Knuth's Algorithms 6.2.2D (Tree deletion), 6.2.3A (Balanced tree
+ search and insertion), 2.3.1I (Insertion into a threaded binary
+ trees), and the notes on pages 465-466 of Vol. 3. */
+
+ /* D1. */
+ avlt_node *pa[AVL_MAX_HEIGHT]; /* Stack P: Nodes. */
+ unsigned char a[AVL_MAX_HEIGHT]; /* Stack P: Bits. */
+ int k = 1; /* Stack P: Pointer. */
+
+ avlt_node *p;
+
+ assert (tree != NULL);
+
+ if (tree->root.tag[0] == MINUS)
+ /* Empty tree. */
+ return NULL;
+
+ a[0] = 0;
+ pa[0] = &tree->root;
+ p = tree->root.link[0];
+ for (;;)
+ {
+ /* D2. */
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ if (diff == 0)
+ break;
+
+ /* D3, D4. */
+ pa[k] = p;
+ if (diff < 0)
+ {
+ if (p->tag[0] == PLUS)
+ {
+ p = p->link[0];
+ a[k] = 0;
+ }
+ else
+ return NULL;
+ }
+ else if (diff > 0)
+ {
+ if (p->tag[1] == PLUS)
+ {
+ p = p->link[1];
+ a[k] = 1;
+ }
+ else
+ return NULL;
+ }
+
+ k++;
+ }
+ tree->count--;
+
+ item = p->data;
+
+ {
+ avlt_node *t = p;
+ avlt_node **q = &pa[k - 1]->link[(int) a[k - 1]];
+
+ /* D5. */
+ if (t->tag[1] == MINUS)
+ {
+ if (t->tag[0] == PLUS)
+ {
+ avlt_node *const x = t->link[0];
+
+ *q = x;
+ (*q)->bal = 0;
+ if (x->tag[1] == MINUS)
+ {
+ if (a[k - 1] == 1)
+ x->link[1] = t->link[1];
+ else
+ x->link[1] = pa[k - 1];
+ }
+ }
+ else
+ {
+ *q = t->link[a[k - 1]];
+ pa[k - 1]->tag[a[k - 1]] = MINUS;
+ }
+ }
+ else
+ {
+ /* D6. */
+ avlt_node *r = t->link[1];
+ if (r->tag[0] == MINUS)
+ {
+ r->link[0] = t->link[0];
+ r->tag[0] = t->tag[0];
+ r->bal = t->bal;
+ if (r->tag[0] == PLUS)
+ {
+ avlt_node *s = r->link[0];
+ while (s->tag[1] == PLUS)
+ s = s->link[1];
+ assert (s->tag[1] == MINUS);
+ s->link[1] = r;
+ }
+ *q = r;
+ a[k] = 1;
+ pa[k++] = r;
+ }
+ else
+ {
+ /* D7. */
+ avlt_node *s = r->link[0];
+
+ a[k] = 1;
+ pa[k++] = t;
+
+ a[k] = 0;
+ pa[k++] = r;
+
+ /* D8. */
+ while (s->tag[0] != MINUS)
+ {
+ r = s;
+ s = r->link[0];
+ a[k] = 0;
+ pa[k++] = r;
+ }
+
+ /* D9. */
+ t->data = s->data;
+ if (s->tag[1] == MINUS)
+ {
+ r->tag[0] = MINUS;
+ r->link[0] = t;
+ }
+ else
+ {
+ r->link[0] = s->link[1];
+ if (s->link[1]->tag[0] == MINUS)
+ s->link[1]->link[0] = t;
+ }
+ p = s;
+ }
+ }
+ }
+
+ free (p);
+
+ assert (k > 0);
+ /* D10. */
+ while (--k)
+ {
+ avlt_node *const s = pa[k];
+
+ if (a[k] == 0)
+ {
+ avlt_node *const r = s->link[1];
+
+ /* D10. */
+ if (s->bal == -1)
+ {
+ s->bal = 0;
+ continue;
+ }
+ else if (s->bal == 0)
+ {
+ s->bal = +1;
+ break;
+ }
+
+ assert (s->bal == +1);
+ if (s->tag[1] == MINUS || r->bal == 0)
+ {
+ /* D11. */
+ s->link[1] = r->link[0];
+ r->link[0] = s;
+ r->bal = -1;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ break;
+ }
+ else if (r->bal == +1)
+ {
+ /* D12. */
+ if (PLUS == (s->tag[1] = r->tag[0]))
+ s->link[1] = r->link[0];
+ r->link[0] = s;
+ r->tag[0] = PLUS;
+ s->bal = r->bal = 0;
+ pa[k - 1]->link[a[k - 1]] = r;
+ }
+ else
+ {
+ /* D13. */
+ assert (r->bal == -1);
+ p = r->link[0];
+ if (PLUS == (r->tag[0] = p->tag[1]))
+ r->link[0] = p->link[1];
+ p->link[1] = r;
+ p->tag[1] = PLUS;
+ if (MINUS == (s->tag[1] = p->tag[0]))
+ s->link[1] = p;
+ else
+ s->link[1] = p->link[0];
+ p->link[0] = s;
+ p->tag[0] = PLUS;
+ if (p->bal == +1)
+ s->bal = -1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == -1);
+ s->bal = 0, r->bal = +1;
+ }
+ p->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = p;
+ pa[k - 1]->tag[(int) a[k - 1]] = PLUS;
+ }
+ }
+ else
+ {
+ avlt_node *const r = s->link[0];
+
+ /* D10. */
+ if (s->bal == +1)
+ {
+ s->bal = 0;
+ continue;
+ }
+ else if (s->bal == 0)
+ {
+ s->bal = -1;
+ break;
+ }
+
+ assert (s->bal == -1);
+ if (s->tag[0] == MINUS || r->bal == 0)
+ {
+ /* D11. */
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ r->bal = +1;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ break;
+ }
+ else if (r->bal == -1)
+ {
+ /* D12. */
+ if (PLUS == (s->tag[0] = r->tag[1]))
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ r->tag[1] = PLUS;
+ s->bal = r->bal = 0;
+ pa[k - 1]->link[a[k - 1]] = r;
+ }
+ else
+ {
+ /* D13. */
+ assert (r->bal == +1);
+ p = r->link[1];
+ if (PLUS == (r->tag[1] = p->tag[0]))
+ r->link[1] = p->link[0];
+ p->link[0] = r;
+ p->tag[0] = PLUS;
+ if (MINUS == (s->tag[0] = p->tag[1]))
+ s->link[0] = p;
+ else
+ s->link[0] = p->link[1];
+ p->link[1] = s;
+ p->tag[1] = PLUS;
+ if (p->bal == -1)
+ s->bal = +1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == +1);
+ s->bal = 0, r->bal = -1;
+ }
+ p->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = p;
+ pa[k - 1]->tag[(int) a[k - 1]] = PLUS;
+ }
+ }
+ }
+
+ return (void *) item;
+}
+
+/* Inserts ITEM into TREE. Returns NULL if the item was inserted,
+ otherwise a pointer to the duplicate item. */
+void *
+avlt_insert (avlt_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = avlt_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+/* If ITEM does not exist in TREE, inserts it and returns NULL. If a
+ matching item does exist, it is replaced by ITEM and the item
+ replaced is returned. The caller is responsible for freeing the
+ item returned. */
+void *
+avlt_replace (avlt_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = avlt_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+
+/* Delete ITEM from TREE when you know that ITEM must be in TREE. For
+ debugging purposes. */
+void *
+(avlt_force_delete) (avlt_tree *tree, void *item)
+{
+ void *found = avlt_delete (tree, item);
+ assert (found != NULL);
+ return found;
+}
+
+#if SELF_TEST
+
+/* Size of the tree used for testing. */
+#define TREE_SIZE 1024
+
+/* Used to flag delayed aborting. */
+int done = 0;
+
+/* Count the number of nodes in TREE below and including NODE. */
+int
+count (avlt_tree *tree, avlt_node *node)
+{
+ int n = 1;
+ if (node->tag[0] == PLUS)
+ n += count (tree, node->link[0]);
+ if (node->tag[1] == PLUS)
+ n += count (tree, node->link[1]);
+ return n;
+}
+
+/* Print the structure of node NODE of an avl tree, which is LEVEL
+ levels from the top of the tree. Uses different delimiters to
+ visually distinguish levels. */
+void
+print_structure (avlt_tree *tree, avlt_node *node, int level)
+{
+ char lc[] = "([{<`";
+ char rc[] = ")]}>'";
+
+ assert (node != NULL);
+ if (level >= 10)
+ {
+ printf ("Too deep, giving up.\n");
+ done = 1;
+ return;
+ }
+ if (node == &tree->root)
+ {
+ printf (" root");
+ return;
+ }
+ printf (" %c%d", lc[level % 5], (int) node->data);
+ fflush (stdout);
+
+ {
+ int i;
+
+ for (i = 0; i <= 1; i++)
+ {
+ if (node->tag[i] == PLUS)
+ print_structure (tree, node->link[i], level + 1);
+ else if (node->link[i] != &tree->root)
+ printf (" :%d", (int) node->link[i]->data);
+ else
+ printf (" :r");
+ fflush (stdout);
+ }
+ }
+ printf ("%c", rc[level % 5]);
+ fflush (stdout);
+}
+
+/* Compare two integers A and B and return a strcmp()-type result. */
+int
+compare_ints (const void *a, const void *b, void *param unused)
+{
+ return ((int) a) - ((int) b);
+}
+
+/* Print the value of integer A. */
+void
+print_int (void *a, void *param unused)
+{
+ printf (" %d", (int) a);
+}
+
+/* Linearly print contents of TREE. */
+void
+print_contents (avlt_tree *tree)
+{
+ avlt_walk (tree, print_int, NULL);
+ printf ("\n");
+}
+
+/* Examine NODE in a avl tree. *COUNT is increased by the number of
+ nodes in the tree, including the current one. If the node is the
+ root of the tree, PARENT should be INT_MIN, otherwise it should be
+ the parent node value. DIR is the direction that the current node
+ is linked from the parent: -1 for left child, +1 for right child;
+ it is not used if PARENT is INT_MIN. Returns the height of the
+ tree rooted at NODE. */
+int
+recurse_tree (avlt_tree *tree, avlt_node *node, int *count, int parent,
+ int dir, unsigned char *nodes, unsigned char *threads)
+{
+ if (node != &tree->root)
+ {
+ int d = (int) node->data;
+ int nl = 0;
+ int nr = 0;
+
+ (*count)++;
+
+ assert (d >= 0 && d < TREE_SIZE);
+ if (nodes[d / 8] & (1 << (d % 8)))
+ {
+ printf (" Arrived at node %d by two different paths.\n", d);
+ done = 1;
+ }
+ else
+ nodes[d / 8] |= 1 << (d % 8);
+
+ if (node->tag[0] == PLUS)
+ nl = recurse_tree (tree, node->link[0], count, d, -1, nodes, threads);
+ else if (node->link[0] != &tree->root)
+ {
+ int dl = (int) node->link[0]->data;
+ assert (dl >= 0 && dl < TREE_SIZE);
+ threads[dl / 8] |= 1 << (dl % 8);
+ }
+
+ if (node->tag[1] == PLUS)
+ nr = recurse_tree (tree, node->link[1], count, d, 1, nodes, threads);
+ else if (node->link[1] != &tree->root)
+ {
+ int dr = (int) node->link[1]->data;
+ assert (dr >= 0 && dr < TREE_SIZE);
+ threads[dr / 8] |= 1 << (dr % 8);
+ }
+
+ if (nr - nl != node->bal)
+ {
+ printf (" Node %d has incorrect balance: right height=%d, "
+ "left height=%d, difference=%d, but balance factor=%d.\n",
+ d, nr, nl, nr - nl, node->bal);
+ done = 1;
+ }
+
+ if (node->bal < -1 || node->bal > 1)
+ {
+ printf (" Node %d has invalid balance factor %d.\n",
+ d, node->bal);
+ done = 1;
+ }
+
+ if (parent != INT_MIN)
+ {
+ assert (dir == -1 || dir == +1);
+ if (dir == -1 && d > parent)
+ {
+ printf (" Node %d is smaller than its left child %d.\n",
+ parent, d);
+ done = 1;
+ }
+ else if (dir == +1 && d < parent)
+ {
+ printf (" Node %d is larger than its right child %d.\n",
+ parent, d);
+ done = 1;
+ }
+ }
+ assert (node->bal >= -1 && node->bal <= 1);
+ return 1 + (nl > nr ? nl : nr);
+ }
+ else return 0;
+}
+
+/* Check that everything about TREE is kosher. */
+void
+verify_tree (avlt_tree *tree)
+{
+ {
+ unsigned char nodes[(TREE_SIZE + 7) / 8];
+ unsigned char threads[(TREE_SIZE + 7) / 8];
+
+ int count = 0;
+ int i;
+
+ memset (nodes, 0, (TREE_SIZE + 7) / 8);
+ memset (threads, 0, (TREE_SIZE + 7) / 8);
+
+ recurse_tree (tree, tree->root.link[0], &count, INT_MIN, 0, nodes,
+ threads);
+
+ if (count != tree->count)
+ {
+ printf (" Tree should have %d nodes, but tree count by recursive "
+ "descent is %d.\n", tree->count, count);
+ done = 1;
+ }
+
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ int thread = threads[i / 8] & (1 << (i % 8));
+ int node = nodes[i / 8] & (1 << (i % 8));
+
+ if (thread && !node)
+ {
+ printf (" A thread leads to ``node'' %d, which is "
+ "not in the tree.", i);
+ done = 1;
+ }
+ }
+ }
+
+ /* Check right threads. */
+ {
+ int count = 0;
+ int last = INT_MIN;
+ void **data = NULL;
+
+ while (NULL != (data = avlt_next (tree, data)))
+ {
+ if (((int) *data) < last)
+ {
+ printf (" Misordered right threads.\n");
+ abort ();
+ }
+ else if (((int) *data) == last)
+ {
+ printf (" Loop in right threads detected on %d.\n", last);
+ abort ();
+ }
+ last = (int) *data;
+ count++;
+ }
+ if (count != tree->count)
+ {
+ printf (" Tree should have %d nodes, but tree count by right threads "
+ "is %d.\n", tree->count, count);
+ done = 1;
+ }
+ }
+
+ /* Check left threads. */
+ {
+ int count = 0;
+ int last = INT_MAX;
+ void **data = NULL;
+
+ while (NULL != (data = avlt_prev (tree, data)))
+ {
+ if (((int) *data) > last)
+ {
+ printf (" Misordered left threads.\n");
+ abort ();
+ }
+ else if (((int) *data) == last)
+ {
+ printf (" Loop in left threads detected on %d.\n", last);
+ abort ();
+ }
+ last = (int) *data;
+ count++;
+ }
+ if (count != tree->count)
+ {
+ printf (" Tree should have %d nodes, but tree count by left threads "
+ "is %d.\n", tree->count, count);
+ done = 1;
+ }
+ }
+
+ if (done)
+ abort ();
+}
+
+/* Arrange the N elements of ARRAY in random order. */
+void
+shuffle (int *array, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ int j = i + rand () % (n - i);
+ int t = array[j];
+ array[j] = array[i];
+ array[i] = t;
+ }
+}
+
+/* Compares avl trees rooted at A and B, making sure that they are
+ identical. */
+void
+compare_trees (avlt_node *a, avlt_node *b)
+{
+ int diff = 0;
+
+ assert (a && b);
+
+ /* Separating these conditions makes it easier to pinpoint bad data
+ under a memory debugger like Checker because each test is a
+ separate statement. */
+ diff |= a->data != b->data;
+ diff |= a->bal != b->bal;
+ diff |= ((a->tag[0] == PLUS) ^ (b->tag[0] == PLUS));
+ diff |= ((a->tag[1] == PLUS) ^ (b->tag[1] == PLUS));
+ if (diff)
+ {
+ printf (" Copied nodes differ: %d b=%d a->bal=%d b->bal=%d a:",
+ (int) a->data, (int) b->data, a->bal, b->bal);
+ if (a->link[0])
+ printf ("l");
+ if (a->link[1])
+ printf ("r");
+ printf (" b:");
+ if (b->link[0])
+ printf ("l");
+ if (b->link[1])
+ printf ("r");
+ printf ("\n");
+ abort ();
+ }
+ if (a->tag[0] == PLUS)
+ compare_trees (a->link[0], b->link[0]);
+ if (a->tag[1] == PLUS)
+ compare_trees (a->link[1], b->link[1]);
+}
+
+/* Simple stress test procedure for the AVL tree routines. Does the
+ following:
+
+ * Generate a random number seed. By default this is generated from
+ the current time. You can also pass a seed value on the command
+ line if you want to test the same case. The seed value is
+ displayed.
+
+ * Create a tree and insert the integers from 0 up to TREE_SIZE - 1
+ into it, in random order. Verify the tree structure after each
+ insertion.
+
+ * Remove each integer from the tree, in a different random order.
+ After each deletion, verify the tree structure; also, make a copy
+ of the tree into a new tree, verify the copy and compare it to the
+ original, then destroy the copy.
+
+ * Destroy the tree, increment the random seed value, and start over.
+
+ If you make any modifications to the avl tree routines, then you
+ might want to insert some calls to print_structure() at strategic
+ places in order to be able to see what's really going on. Also,
+ memory debuggers like Checker or Purify are very handy. */
+#define N_ITERATIONS 16
+int
+main (int argc, char **argv)
+{
+ int array[TREE_SIZE];
+ int seed;
+ int iteration;
+
+ if (argc == 2)
+ seed = atoi (argv[1]);
+ else
+ seed = time (0) * 257 % 32768;
+
+ fputs ("Testing avlt...\n", stdout);
+
+ for (iteration = 1; iteration <= N_ITERATIONS; iteration++)
+ {
+ avlt_tree *tree;
+ int i;
+
+ printf ("Iteration %4d/%4d: seed=%5d", iteration, N_ITERATIONS, seed);
+ fflush (stdout);
+
+ srand (seed++);
+
+ for (i = 0; i < TREE_SIZE; i++)
+ array[i] = i;
+ shuffle (array, TREE_SIZE);
+
+ tree = avlt_create (compare_ints, NULL);
+ for (i = 0; i < TREE_SIZE; i++)
+ avlt_force_insert (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ shuffle (array, TREE_SIZE);
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ avlt_tree *copy;
+
+ avlt_delete (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ copy = avlt_copy (tree, NULL);
+ verify_tree (copy);
+ if (tree->root.link[0] != &tree->root)
+ compare_trees (tree->root.link[0], copy->root.link[0]);
+ else if (copy->root.link[1] != &copy->root)
+ printf (" Empty tree results in nonempty copy.\n"), abort ();
+ avlt_destroy (copy, NULL);
+
+ if (i % 128 == 0)
+ {
+ putchar ('.');
+ fflush (stdout);
+ }
+ }
+ fputs (" good.\n", stdout);
+
+ avlt_destroy (tree, NULL);
+ }
+
+ return 0;
+}
+#endif /* SELF_TEST */
+
+/*
+ Local variables:
+ compile-command: "gcc -DSELF_TEST=1 -W -Wall -I. -o ./avlt-test avlt.c"
+ End:
+*/
+
diff --git a/avl-1.4.0/avlt.h b/avl-1.4.0/avlt.h
new file mode 100644
index 0000000..94272b4
--- /dev/null
+++ b/avl-1.4.0/avlt.h
@@ -0,0 +1,142 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file avlt.h in libavl. */
+
+#if !avlt_h
+#define avlt_h 1
+
+/* The default maximum height of 32 allows for AVL trees having
+ between 5,704,880 and 4,294,967,295 nodes, depending on order of
+ insertion. You may change this compile-time constant as you
+ wish. */
+#ifndef AVL_MAX_HEIGHT
+#define AVL_MAX_HEIGHT 32
+#endif
+
+/* Structure for a node in a threaded AVL tree. */
+typedef struct avlt_node
+ {
+ void *data; /* Pointer to data. */
+ struct avlt_node *link[2]; /* Subtrees or threads. */
+ signed char bal; /* Balance factor. */
+ char cache; /* Used during insertion. */
+ signed char tag[2]; /* Left and right thread tags. */
+ }
+avlt_node;
+
+/* Used for traversing a threaded AVL tree. */
+typedef struct avlt_traverser
+ {
+ int init; /* Initialized? */
+ const avlt_node *p; /* Last node returned. */
+ }
+avlt_traverser;
+
+/* Initializer for avlt_traverser. */
+#define AVLT_TRAVERSER_INIT {0}
+
+/* Function types. */
+#if !AVL_FUNC_TYPES
+#define AVL_FUNC_TYPES 1
+typedef int (*avl_comparison_func) (const void *a, const void *b, void *param);
+typedef void (*avl_node_func) (void *data, void *param);
+typedef void *(*avl_copy_func) (void *data, void *param);
+#endif
+
+/* Structure which holds information about a threaded AVL tree. */
+typedef struct avlt_tree
+ {
+ avlt_node root; /* Tree root node. */
+ avl_comparison_func cmp; /* Used to compare keys. */
+ int count; /* Number of nodes in the tree. */
+ void *param; /* Arbitary user data. */
+ }
+avlt_tree;
+
+/* General functions. */
+avlt_tree *avlt_create (avl_comparison_func, void *param);
+void avlt_destroy (avlt_tree *, avl_node_func);
+void avlt_free (avlt_tree *);
+int avlt_count (const avlt_tree *);
+avlt_tree *avlt_copy (const avlt_tree *, avl_copy_func);
+struct avl_tree;
+avlt_tree *avlt_thread (struct avl_tree *);
+struct avl_tree *avlt_unthread (avlt_tree *);
+
+/* Walk the tree. */
+void avlt_walk (const avlt_tree *, avl_node_func, void *param);
+void *avlt_traverse (const avlt_tree *, avlt_traverser *);
+#define avlt_init_traverser(TRAVERSER) ((TRAVERSER)->init = 0)
+void **avlt_next (const avlt_tree *tree, void **item);
+void **avlt_prev (const avlt_tree *tree, void **item);
+
+/* Search for a given item. */
+void **avlt_probe (avlt_tree *, void *);
+void *avlt_delete (avlt_tree *, const void *);
+void **avlt_find (const avlt_tree *, const void *);
+void **avlt_find_close (const avlt_tree *, const void *);
+
+#if __GCC__ >= 2
+extern inline void *
+avlt_insert (avlt_tree *tree, void *item)
+{
+ void **p = avlt_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+extern inline void *
+avlt_replace (avlt_tree *tree, void *item)
+{
+ void **p = avlt_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+#else /* not gcc */
+void *avlt_insert (avlt_tree *tree, void *item);
+void *avlt_replace (avlt_tree *tree, void *item);
+#endif /* not gcc */
+
+/* Easy assertions on insertion & deletion. */
+#ifndef NDEBUG
+#define avlt_force_insert(A, B) \
+ do \
+ { \
+ void *r = avlt_insert (A, B); \
+ assert (r == NULL); \
+ } \
+ while (0)
+void *avlt_force_delete (avlt_tree *, void *);
+#else
+#define avlt_force_insert(A, B) \
+ avlt_insert (A, B)
+#define avlt_force_delete(A, B) \
+ avlt_delete (A, B)
+#endif
+
+#endif /* avlt_h */
diff --git a/avl-1.4.0/avltr.c b/avl-1.4.0/avltr.c
new file mode 100644
index 0000000..2831bee
--- /dev/null
+++ b/avl-1.4.0/avltr.c
@@ -0,0 +1,1538 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file avltr.c in libavl. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#if SELF_TEST
+#include <limits.h>
+#include <time.h>
+#endif
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "avltr.h"
+
+/* Tag types. */
+#define PLUS +1
+#define MINUS -1
+
+#if !__GCC__ && !defined (inline)
+#define inline
+#endif
+
+void
+print_structure (avltr_tree *tree, avltr_node *node, int level);
+
+#if __GNUC__ >= 2
+#define unused __attribute__ ((unused))
+#else
+#define unused
+#endif
+
+#ifdef HAVE_XMALLOC
+void *xmalloc (size_t);
+#else /* !HAVE_XMALLOC */
+/* Allocates SIZE bytes of space using malloc(). Aborts if out of
+ memory. */
+static void *
+xmalloc (size_t size)
+{
+ void *vp;
+ if (size == 0)
+ return NULL;
+ vp = malloc (size);
+ assert (vp != NULL);
+ if (vp == NULL)
+ {
+ fprintf (stderr, "virtual memory exhausted\n");
+ exit (EXIT_FAILURE);
+ }
+ return vp;
+}
+#endif /* !HAVE_XMALLOC */
+
+/* Creates an AVL tree in arena OWNER (which can be NULL). The arena
+ is owned by the caller, not by the AVL tree. CMP is a order
+ function for the data to be stored in the tree. PARAM is arbitrary
+ data that becomes an argument to the comparison function. */
+avltr_tree *
+avltr_create (avl_comparison_func cmp, void *param)
+{
+ avltr_tree *tree;
+
+ assert (cmp != NULL);
+ tree = xmalloc (sizeof (avltr_tree));
+
+ tree->root.link[0] = NULL;
+ tree->root.link[1] = &tree->root;
+ tree->root.rtag = PLUS;
+ tree->cmp = cmp;
+ tree->count = 0;
+ tree->param = param;
+
+ return tree;
+}
+
+/* Destroy tree TREE. Function FREE_FUNC is called for every node in
+ the tree as it is destroyed.
+
+ No effect if the tree has an arena owner and free_func is NULL.
+ The caller owns the arena and must destroy it itself.
+
+ Do not attempt to reuse the tree after it has been freed. Create a
+ new one. */
+void
+avltr_destroy (avltr_tree *tree, avl_node_func free_func)
+{
+ assert (tree != NULL);
+
+ if (tree->root.link[0] != &tree->root)
+ {
+ /* Uses Knuth's Algorithm 2.3.1T as modified in exercise 13
+ (postorder traversal), further modified for right-threaded
+ trees. */
+
+ /* T1. */
+ avltr_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ char ab[AVL_MAX_HEIGHT]; /* Stack A: bits. */
+ int ap = 0; /* Stack A: height. */
+ avltr_node *p = tree->root.link[0];
+
+ for (;;)
+ {
+ /* T2. */
+ while (p != NULL)
+ {
+ /* T3. */
+ ab[ap] = 0;
+ an[ap++] = p;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ for (;;)
+ {
+ if (ap == 0)
+ goto done;
+
+ p = an[--ap];
+ if (ab[ap] == 0)
+ {
+ ab[ap++] = 1;
+ if (p->rtag == MINUS)
+ continue;
+ p = p->link[1];
+ break;
+ }
+
+ if (free_func)
+ free_func (p->data, tree->param);
+ free (p);
+ }
+ }
+ }
+
+ done:
+ free (tree);
+}
+
+/* avltr_destroy() with FREE_FUNC hardcoded as free(). */
+void
+avltr_free (avltr_tree *tree)
+{
+ avltr_destroy (tree, (avl_node_func) free);
+}
+
+/* Return the number of nodes in TREE. */
+int
+avltr_count (const avltr_tree *tree)
+{
+ assert (tree != NULL);
+ return tree->count;
+}
+
+/* Copy the contents of TREE to a new tree in arena OWNER. If COPY is
+ non-NULL, then each data item is passed to function COPY, and the
+ return values are inserted into the new tree; otherwise, the items
+ are copied verbatim from the old tree to the new tree. Returns the
+ new tree. */
+avltr_tree *
+avltr_copy (const avltr_tree *tree, avl_copy_func copy)
+{
+ /* Knuth's Algorithm 2.3.1C (copying a binary tree). Additionally
+ uses Algorithm 2.3.1I (insertion into a threaded binary tree) and
+ Algorithm 2.3.1 exercise 17 (preorder successor in threaded
+ binary tree). */
+
+ avltr_tree *new_tree;
+
+ const avltr_node *p;
+ avltr_node *q;
+
+ assert (tree != NULL);
+ new_tree = avltr_create (tree->cmp, tree->param);
+ new_tree->count = tree->count;
+ p = &tree->root;
+ if (p->link[0] == p)
+ return new_tree;
+ q = &new_tree->root;
+
+ for (;;)
+ {
+ /* C4. This is Algorithm 2.3.1 exercise 23 for insertion to the
+ left in a right-threaded binary tree. */
+ if (p->link[0] != NULL)
+ {
+ avltr_node *r = xmalloc (sizeof (avltr_node));
+
+ q->link[0] = r;
+ r->link[0] = NULL;
+ r->link[1] = q;
+ r->rtag = MINUS;
+ }
+
+ /* C5: Find preorder successors of P and Q. This is Algorithm
+ 2.3.1 exercise 17 but applies its actions to Q as well as
+ P. */
+ if (p->link[0] != NULL)
+ {
+ p = p->link[0];
+ q = q->link[0];
+ }
+ else
+ {
+ while (p->rtag == MINUS)
+ {
+ p = p->link[1];
+ q = q->link[1];
+ }
+ p = p->link[1];
+ q = q->link[1];
+ }
+
+ /* C6. */
+ if (p == &tree->root)
+ {
+ assert (q == &new_tree->root);
+ return new_tree;
+ }
+
+ /* C2. This is Algorithm 2.3.1 exercise 23 for insertion to the
+ right in a right-threaded binary tree. */
+ if (p->rtag == PLUS)
+ {
+ avltr_node *r = xmalloc (sizeof (avltr_node));
+
+ r->link[1] = q->link[1];
+ r->rtag = q->rtag;
+ q->link[1] = r;
+ q->rtag = PLUS;
+ r->link[0] = NULL;
+ }
+
+ /* C3. */
+ q->bal = p->bal;
+ if (copy == NULL)
+ q->data = p->data;
+ else
+ q->data = copy (p->data, tree->param);
+ }
+}
+
+/* Threads the unthreaded AVL tree TREE in-place, and returns TREE cast to
+ avltr_tree *. */
+avltr_tree *
+avltr_thread (struct avl_tree *_tree)
+{
+ /* Uses Knuth's Algorithm 2.3.1 exercise 30 (thread an unthreaded
+ tree, with Algorithm 2.3.1T (inorder traversal) for computing
+ Q$. */
+
+ avltr_tree *tree = (avltr_tree *) _tree;
+
+ /* Algorithm T's variables. */
+ avltr_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ avltr_node **ap; /* Stack A: stack pointer. */
+ avltr_node *tp; /* P. */
+
+ /* Algorithm L's variables. */
+ avltr_node *p, *q;
+
+ assert (tree != NULL);
+
+ /* T1. */
+ ap = an;
+ tp = tree->root.link[0];
+
+ /* L1. */
+ q = &tree->root;
+ q->link[1] = q;
+
+ for (;;)
+ {
+ /* L2. */
+ {
+ /* T2. */
+ while (tp != NULL)
+ {
+ /* T3. */
+ *ap++ = tp;
+ tp = tp->link[0];
+ }
+
+ /* T4. Modified to visit HEAD after fully traversing the
+ tree. */
+ if (ap == an)
+ tp = &tree->root;
+ else
+ tp = *--ap;
+
+ /* T5: Visit P. */
+ p = tp;
+ }
+
+ /* L3. */
+ if (q->link[1] == NULL)
+ {
+ q->link[1] = p;
+ q->rtag = MINUS;
+ }
+ else
+ q->rtag = PLUS;
+
+ /* L4. */
+ if (p == &tree->root)
+ return tree;
+ q = p;
+
+ /* T5: Next. */
+ tp = tp->link[1];
+ }
+}
+
+/* Unthreads the threaded tree TREE in-place, and returns TREE cast to
+ avl_tree *. */
+struct avl_tree *
+avltr_unthread (avltr_tree *tree)
+{
+ /* Uses Knuth's Algorithm 2.3.1T as modified in exercise 13
+ (postorder traversal). */
+
+ /* T1. */
+ avltr_node *an[AVL_MAX_HEIGHT]; /* Stack A: nodes. */
+ char ab[AVL_MAX_HEIGHT]; /* Stack A: bits. */
+ int ap = 0; /* Stack A: height. */
+ avltr_node *p;
+
+ assert (tree != NULL);
+ p = tree->root.link[0];
+ if (p != NULL)
+ for (;;)
+ {
+ /* T2. */
+ for (;;)
+ {
+ /* T3. */
+ ab[ap] = 0;
+ an[ap++] = p;
+ if (p->link[0] == NULL)
+ break;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ for (;;)
+ {
+ if (ap == 0)
+ goto done;
+
+ p = an[--ap];
+ if (ab[ap] == 0)
+ {
+ ab[ap++] = 1;
+ if (p->rtag == MINUS)
+ continue;
+ p = p->link[1];
+ break;
+ }
+
+ if (p->rtag == MINUS)
+ p->link[1] = NULL;
+ }
+ }
+ else
+ tree->root.link[0] = NULL;
+
+ done:
+ tree->root.link[1] = NULL;
+ return (struct avl_tree *) tree;
+}
+
+/* Walk tree TREE in inorder, calling WALK_FUNC at each node. Passes
+ PARAM to WALK_FUNC. */
+void
+avltr_walk (const avltr_tree *tree, avl_node_func walk_func, void *param)
+{
+ const avltr_node *p = &tree->root;
+
+ /* Uses Knuth's algorithm 2.3.1D (threaded inorder successor). */
+ assert (tree && walk_func);
+
+ for (;;)
+ {
+ if (p->rtag == MINUS)
+ p = p->link[1];
+ else
+ {
+ p = p->link[1];
+ while (p->link[0] != NULL)
+ p = p->link[0];
+ }
+
+ if (p == &tree->root)
+ return;
+
+ walk_func (p->data, param);
+ }
+}
+
+/* Each call to this function for a given TREE and TRAV return the
+ next item in the tree in inorder. Initialize the first element of
+ TRAV (init) to 0 before calling the first time. Returns NULL when
+ out of elements. */
+void *
+avltr_traverse (const avltr_tree *tree, avltr_traverser *trav)
+{
+ const avltr_node *p;
+
+ assert (tree && trav);
+
+ if (trav->init == 0)
+ {
+ p = &tree->root;
+ trav->init = 1;
+ }
+ else
+ p = trav->p;
+
+ /* Knuth's Algorithm 2.3.1S (threaded inorder successor). */
+ if (p->rtag == MINUS)
+ p = p->link[1];
+ else
+ {
+ p = p->link[1];
+ while (p->link[0] != NULL)
+ p = p->link[0];
+ }
+
+ if (p == &tree->root)
+ {
+ trav->init = 0;
+ return NULL;
+ }
+ else
+ {
+ trav->p = p;
+ return (void *) p->data;
+ }
+}
+
+/* Given ITEM, a pointer to a data item in TREE (or NULL), returns a
+ pointer to the next item in the tree in comparison order, or NULL
+ if ITEM is the last item. */
+void **
+avltr_next (const avltr_tree *tree, void **item)
+{
+ const avltr_node *p;
+
+ assert (tree != NULL);
+ if (item == NULL)
+ p = &tree->root;
+ else
+ p = (avltr_node *) (((char *) item) - offsetof (avltr_node, data));
+
+ /* Knuth's Algorithm 2.3.1S (threaded inorder successor). */
+ if (p->rtag == MINUS)
+ p = p->link[1];
+ else
+ {
+ p = p->link[1];
+ while (p->link[0] != NULL)
+ p = p->link[0];
+ }
+
+ if (p == &tree->root)
+ return NULL;
+
+ return (void **) &p->data;
+}
+
+/* Search TREE for an item matching ITEM. If found, returns a pointer
+ to the address of the item. If none is found, ITEM is inserted
+ into the tree, and a pointer to the address of ITEM is returned.
+ In either case, the pointer returned can be changed by the caller,
+ or the returned data item can be directly edited, but the key data
+ in the item must not be changed. */
+void **
+avltr_probe (avltr_tree *tree, void *item)
+{
+ /* Uses Knuth's Algorithm 6.2.3A (balanced tree search and
+ insertion), modified for a right-threaded binary tree. Caches
+ results of comparisons. In empirical tests this eliminates about
+ 25% of the comparisons seen under random insertions. */
+
+ /* A1. */
+ avltr_node *t;
+ avltr_node *s, *p, *q, *r;
+
+ assert (tree != NULL);
+ t = &tree->root;
+ s = p = t->link[0];
+
+ if (s == NULL)
+ {
+ tree->count++;
+ assert (tree->count == 1);
+ q = t->link[0] = xmalloc (sizeof (avltr_node));
+ q->data = item;
+ q->link[0] = NULL;
+ q->link[1] = t;
+ q->rtag = MINUS;
+ q->bal = 0;
+ return &q->data;
+ }
+
+ for (;;)
+ {
+ /* A2. */
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ /* A3. */
+ if (diff < 0)
+ {
+ p->cache = 0;
+ q = p->link[0];
+ if (q == NULL)
+ {
+ /* Algorithm 2.3.1 exercise 23 for insertion to the left
+ in a right-threaded binary tree. */
+ q = xmalloc (sizeof (avltr_node));
+ p->link[0] = q;
+ q->link[0] = NULL;
+ q->link[1] = p;
+ q->rtag = MINUS;
+ break;
+ }
+ }
+ /* A4. */
+ else if (diff > 0)
+ {
+ p->cache = 1;
+ q = p->link[1];
+ if (p->rtag == MINUS)
+ {
+ /* Algorithm 2.3.1 exercise 23 for insertion to the right
+ in a right-threaded binary tree. */
+ q = xmalloc (sizeof (avltr_node));
+ q->link[1] = p->link[1];
+ q->rtag = p->rtag;
+ p->link[1] = q;
+ p->rtag = PLUS;
+ q->link[0] = NULL;
+ break;
+ }
+ assert (q != NULL);
+ }
+ else
+ /* A2. */
+ return &p->data;
+
+ /* A3, A4. */
+ if (q->bal != 0)
+ t = p, s = q;
+ p = q;
+ }
+
+ /* A5. */
+ tree->count++;
+ q->data = item;
+ q->bal = 0;
+
+ /* A6. */
+ r = p = s->link[(int) s->cache];
+ while (p != q)
+ {
+ p->bal = p->cache * 2 - 1;
+ p = p->link[(int) p->cache];
+ }
+
+ /* A7. */
+ if (s->cache == 0)
+ {
+ /* a = -1. */
+ if (s->bal == 0)
+ {
+ s->bal = -1;
+ return &q->data;
+ }
+ else if (s->bal == +1)
+ {
+ s->bal = 0;
+ return &q->data;
+ }
+
+ assert (s->bal == -1);
+ if (r->bal == -1)
+ {
+ /* A8. */
+ p = r;
+ if (r->rtag == MINUS)
+ {
+ s->link[0] = NULL;
+ r->link[1] = s;
+ r->rtag = PLUS;
+ }
+ else
+ {
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ }
+ s->bal = r->bal = 0;
+ }
+ else
+ {
+ /* A9. */
+ assert (r->bal == +1);
+ p = r->link[1];
+ r->link[1] = p->link[0];
+ p->link[0] = r;
+ s->link[0] = p->link[1];
+ p->link[1] = s;
+ if (p->bal == -1)
+ s->bal = 1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == +1);
+ s->bal = 0, r->bal = -1;
+ }
+ p->bal = 0;
+ p->rtag = PLUS;
+ if (s->link[0] == s)
+ s->link[0] = NULL;
+ if (r->link[1] == NULL)
+ {
+ r->link[1] = p;
+ r->rtag = MINUS;
+ }
+ }
+ }
+ else
+ {
+ /* a == +1. */
+ if (s->bal == 0)
+ {
+ s->bal = 1;
+ return &q->data;
+ }
+ else if (s->bal == -1)
+ {
+ s->bal = 0;
+ return &q->data;
+ }
+
+ assert (s->bal == +1);
+ if (r->bal == +1)
+ {
+ /* A8. */
+ p = r;
+ if (r->link[0] == NULL)
+ {
+ s->rtag = MINUS;
+ r->link[0] = s;
+ }
+ else
+ {
+ s->link[1] = r->link[0];
+ s->rtag = PLUS;
+ r->link[0] = s;
+ }
+ s->bal = r->bal = 0;
+ }
+ else
+ {
+ /* A9. */
+ assert (r->bal == -1);
+ p = r->link[0];
+ r->link[0] = p->link[1];
+ p->link[1] = r;
+ s->link[1] = p->link[0];
+ p->link[0] = s;
+ if (p->bal == +1)
+ s->bal = -1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == -1);
+ s->bal = 0, r->bal = 1;
+ }
+ p->rtag = PLUS;
+ if (s->link[1] == NULL)
+ {
+ s->link[1] = p;
+ s->rtag = MINUS;
+ }
+ if (r->link[0] == r)
+ r->link[0] = NULL;
+ p->bal = 0;
+ }
+ }
+
+ /* A10. */
+ if (t != &tree->root && s == t->link[1])
+ t->link[1] = p;
+ else
+ t->link[0] = p;
+
+ return &q->data;
+}
+
+/* Search TREE for an item matching ITEM, and return a pointer to it
+ if found. */
+void **
+avltr_find (const avltr_tree *tree, const void *item)
+{
+ const avltr_node *p;
+
+ assert (tree != NULL);
+ p = tree->root.link[0];
+ if (p == NULL)
+ return NULL;
+ for (;;)
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ /* A3. */
+ if (diff < 0)
+ {
+ p = p->link[0];
+ if (p == NULL)
+ return NULL;
+ }
+ else if (diff > 0)
+ {
+ if (p->rtag == MINUS)
+ return NULL;
+ p = p->link[1];
+ }
+ else
+ return (void **) &p->data;
+ }
+}
+
+/* Search TREE for an item close to the value of ITEM, and return it.
+ This function will return a null pointer only if TREE is empty. */
+void **
+avltr_find_close (const avltr_tree *tree, const void *item)
+{
+ const avltr_node *p;
+
+ assert (tree != NULL);
+ p = tree->root.link[0];
+ if (p == NULL)
+ return NULL;
+ for (;;)
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ /* A3. */
+ if (diff < 0)
+ {
+ if (p->link[0])
+ p = p->link[0];
+ else
+ return (void **) &p->data;
+ }
+ else if (diff > 0)
+ {
+ if (p->rtag == MINUS)
+ return (void **) &p->data;
+ p = p->link[1];
+ }
+ else
+ return (void **) &p->data;
+ }
+}
+
+/* Searches AVL tree TREE for an item matching ITEM. If found, the
+ item is removed from the tree and the actual item found is returned
+ to the caller. If no item matching ITEM exists in the tree,
+ returns NULL. */
+void *
+avltr_delete (avltr_tree *tree, const void *item)
+{
+ /* Uses my Algorithm DTR, which can be found at
+ http://www.msu.edu/user/pfaffben/avl. Algorithm DT is based on
+ Knuth's Algorithms 6.2.2D (Tree deletion), 6.2.3A (Balanced tree
+ search and insertion), 2.3.1I (Insertion into a threaded binary
+ trees), and the notes on pages 465-466 of Vol. 3. */
+
+ /* D1. */
+ avltr_node *pa[AVL_MAX_HEIGHT]; /* Stack P: Nodes. */
+ unsigned char a[AVL_MAX_HEIGHT]; /* Stack P: Bits. */
+ int k = 1; /* Stack P: Pointer. */
+
+ avltr_node *p;
+
+ assert (tree != NULL);
+
+ a[0] = 0;
+ pa[0] = &tree->root;
+ p = tree->root.link[0];
+ if (p == NULL)
+ return NULL;
+ for (;;)
+ {
+ /* D2. */
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ if (diff == 0)
+ break;
+
+ /* D3, D4. */
+ pa[k] = p;
+ if (diff < 0)
+ {
+ if (p->link[0] != NULL)
+ {
+ p = p->link[0];
+ a[k] = 0;
+ }
+ else
+ return NULL;
+ }
+ else if (diff > 0)
+ {
+ if (p->rtag == PLUS)
+ {
+ p = p->link[1];
+ a[k] = 1;
+ }
+ else
+ return NULL;
+ }
+
+ k++;
+ }
+ tree->count--;
+
+ item = p->data;
+
+ {
+ avltr_node *t = p;
+ avltr_node **q = &pa[k - 1]->link[(int) a[k - 1]];
+
+ /* D5. */
+ if (t->rtag == MINUS)
+ {
+ if (t->link[0] != NULL)
+ {
+ avltr_node *const x = t->link[0];
+
+ *q = x;
+ (*q)->bal = 0;
+ if (x->rtag == MINUS)
+ {
+ if (a[k - 1] == 1)
+ x->link[1] = t->link[1];
+ else
+ x->link[1] = pa[k - 1];
+ }
+ }
+ else
+ {
+ *q = t->link[a[k - 1]];
+ if (a[k - 1] == 0)
+ pa[k - 1]->link[0] = NULL;
+ else
+ pa[k - 1]->rtag = MINUS;
+ }
+ }
+ else
+ {
+ /* D6. */
+ avltr_node *r = t->link[1];
+ if (r->link[0] == NULL)
+ {
+ r->link[0] = t->link[0];
+ r->bal = t->bal;
+ if (r->link[0] != NULL)
+ {
+ avltr_node *s = r->link[0];
+ while (s->rtag == PLUS)
+ s = s->link[1];
+ assert (s->rtag == MINUS);
+ s->link[1] = r;
+ }
+ *q = r;
+ a[k] = 1;
+ pa[k++] = r;
+ }
+ else
+ {
+ /* D7. */
+ avltr_node *s = r->link[0];
+
+ a[k] = 1;
+ pa[k++] = t;
+
+ a[k] = 0;
+ pa[k++] = r;
+
+ /* D8. */
+ while (s->link[0] != NULL)
+ {
+ r = s;
+ s = r->link[0];
+ a[k] = 0;
+ pa[k++] = r;
+ }
+
+ /* D9. */
+ t->data = s->data;
+ if (s->rtag == PLUS)
+ r->link[0] = s->link[1];
+ else
+ r->link[0] = NULL;
+ p = s;
+ }
+ }
+ }
+
+ free (p);
+
+ assert (k > 0);
+ /* D10. */
+ while (--k)
+ {
+ avltr_node *const s = pa[k];
+
+ if (a[k] == 0)
+ {
+ avltr_node *const r = s->link[1];
+
+ /* D10. */
+ if (s->bal == -1)
+ {
+ s->bal = 0;
+ continue;
+ }
+ else if (s->bal == 0)
+ {
+ s->bal = +1;
+ break;
+ }
+
+ assert (s->bal == +1);
+ if (s->rtag == MINUS || r->bal == 0)
+ {
+ /* D11. */
+ s->link[1] = r->link[0];
+ r->link[0] = s;
+ r->bal = -1;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ break;
+ }
+ else if (r->bal == +1)
+ {
+ /* D12. */
+ if (r->link[0] != NULL)
+ {
+ s->rtag = PLUS;
+ s->link[1] = r->link[0];
+ }
+ else
+ s->rtag = MINUS;
+ r->link[0] = s;
+ s->bal = r->bal = 0;
+ pa[k - 1]->link[a[k - 1]] = r;
+ }
+ else
+ {
+ /* D13. */
+ assert (r->bal == -1);
+ p = r->link[0];
+ if (p->rtag == PLUS)
+ r->link[0] = p->link[1];
+ else
+ r->link[0] = NULL;
+ p->link[1] = r;
+ p->rtag = PLUS;
+ if (p->link[0] == NULL)
+ {
+ s->link[1] = p;
+ s->rtag = MINUS;
+ }
+ else
+ {
+ s->link[1] = p->link[0];
+ s->rtag = PLUS;
+ }
+ p->link[0] = s;
+ if (p->bal == +1)
+ s->bal = -1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == -1);
+ s->bal = 0, r->bal = +1;
+ }
+ p->bal = 0;
+ pa[k - 1]->link[(int) a[k - 1]] = p;
+ if (a[k - 1] == 1)
+ pa[k - 1]->rtag = PLUS;
+ }
+ }
+ else
+ {
+ avltr_node *const r = s->link[0];
+
+ /* D10. */
+ if (s->bal == +1)
+ {
+ s->bal = 0;
+ continue;
+ }
+ else if (s->bal == 0)
+ {
+ s->bal = -1;
+ break;
+ }
+
+ assert (s->bal == -1);
+ if (s->link[0] == NULL || r->bal == 0)
+ {
+ /* D11. */
+ s->link[0] = r->link[1];
+ r->link[1] = s;
+ r->bal = +1;
+ pa[k - 1]->link[(int) a[k - 1]] = r;
+ break;
+ }
+ else if (r->bal == -1)
+ {
+ /* D12. */
+ if (r->rtag == PLUS)
+ s->link[0] = r->link[1];
+ else
+ s->link[0] = NULL;
+ r->link[1] = s;
+ r->rtag = PLUS;
+ s->bal = r->bal = 0;
+ pa[k - 1]->link[a[k - 1]] = r;
+ }
+ else
+ {
+ /* D13. */
+ assert (r->bal == +1);
+ p = r->link[1];
+ if (p->link[0] != NULL)
+ {
+ r->rtag = PLUS;
+ r->link[1] = p->link[0];
+ }
+ else
+ r->rtag = MINUS;
+ p->link[0] = r;
+ if (p->rtag == MINUS)
+ s->link[0] = NULL;
+ else
+ s->link[0] = p->link[1];
+ p->link[1] = s;
+ p->rtag = PLUS;
+ if (p->bal == -1)
+ s->bal = +1, r->bal = 0;
+ else if (p->bal == 0)
+ s->bal = r->bal = 0;
+ else
+ {
+ assert (p->bal == +1);
+ s->bal = 0, r->bal = -1;
+ }
+ p->bal = 0;
+ if (a[k - 1] == 1)
+ pa[k - 1]->rtag = PLUS;
+ pa[k - 1]->link[(int) a[k - 1]] = p;
+ }
+ }
+ }
+
+ return (void *) item;
+}
+
+/* Inserts ITEM into TREE. Returns NULL if the item was inserted,
+ otherwise a pointer to the duplicate item. */
+void *
+avltr_insert (avltr_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = avltr_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+/* If ITEM does not exist in TREE, inserts it and returns NULL. If a
+ matching item does exist, it is replaced by ITEM and the item
+ replaced is returned. The caller is responsible for freeing the
+ item returned. */
+void *
+avltr_replace (avltr_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = avltr_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+
+/* Delete ITEM from TREE when you know that ITEM must be in TREE. For
+ debugging purposes. */
+void *
+(avltr_force_delete) (avltr_tree *tree, void *item)
+{
+ void *found = avltr_delete (tree, item);
+ assert (found != NULL);
+ return found;
+}
+
+#if SELF_TEST
+
+/* Size of the tree used for testing. */
+#define TREE_SIZE 1024
+
+/* Used to flag delayed aborting. */
+int done = 0;
+
+/* Count the number of nodes in TREE below and including NODE. */
+int
+count (avltr_tree *tree, avltr_node *node)
+{
+ int n = 1;
+ if (node->link[0] != NULL)
+ n += count (tree, node->link[0]);
+ if (node->rtag == PLUS)
+ n += count (tree, node->link[1]);
+ return n;
+}
+
+/* Print the structure of node NODE of an avl tree, which is LEVEL
+ levels from the top of the tree. Uses different delimiters to
+ visually distinguish levels. */
+void
+print_structure (avltr_tree *tree, avltr_node *node, int level)
+{
+ char lc[] = "([{<`";
+ char rc[] = ")]}>'";
+
+ if (node == NULL)
+ {
+ printf (" :nil");
+ return;
+ }
+ else if (level >= 10)
+ {
+ printf ("Too deep, giving up.\n");
+ done = 1;
+ return;
+ }
+ else if (node == &tree->root)
+ {
+ printf (" root");
+ return;
+ }
+ printf (" %c%d", lc[level % 5], (int) node->data);
+ fflush (stdout);
+
+ print_structure (tree, node->link[0], level + 1);
+ fflush (stdout);
+
+ if (node->rtag == PLUS)
+ print_structure (tree, node->link[1], level + 1);
+ else if (node->link[1] != &tree->root)
+ printf (" :%d", (int) node->link[1]->data);
+ else
+ printf (" :r");
+ fflush (stdout);
+
+ printf ("%c", rc[level % 5]);
+ fflush (stdout);
+}
+
+/* Compare two integers A and B and return a strcmp()-type result. */
+int
+compare_ints (const void *a, const void *b, void *param unused)
+{
+ return ((int) a) - ((int) b);
+}
+
+/* Print the value of integer A. */
+void
+print_int (void *a, void *param unused)
+{
+ printf (" %d", (int) a);
+}
+
+/* Linearly print contents of TREE. */
+void
+print_contents (avltr_tree *tree)
+{
+ avltr_walk (tree, print_int, NULL);
+ printf ("\n");
+}
+
+/* Examine NODE in a avl tree. *COUNT is increased by the number of
+ nodes in the tree, including the current one. If the node is the
+ root of the tree, PARENT should be INT_MIN, otherwise it should be
+ the parent node value. DIR is the direction that the current node
+ is linked from the parent: -1 for left child, +1 for right child;
+ it is not used if PARENT is INT_MIN. Returns the height of the
+ tree rooted at NODE. */
+int
+recurse_tree (avltr_tree *tree, avltr_node *node, int *count, int parent,
+ int dir, unsigned char *nodes, unsigned char *threads)
+{
+ if (node != NULL && node != &tree->root)
+ {
+ int d = (int) node->data;
+ int nl = 0;
+ int nr = 0;
+
+ (*count)++;
+
+ assert (d >= 0 && d < TREE_SIZE);
+ if (nodes[d / 8] & (1 << (d % 8)))
+ {
+ printf (" Arrived at node %d by two different paths.\n", d);
+ done = 1;
+ }
+ else
+ nodes[d / 8] |= 1 << (d % 8);
+
+ if (node->link[0] != NULL)
+ nl = recurse_tree (tree, node->link[0], count, d, -1, nodes, threads);
+
+ if (node->rtag == PLUS)
+ {
+ if (node->link[1] == NULL)
+ {
+ printf (" Null thread link.\n");
+ done = 1;
+ }
+ nr = recurse_tree (tree, node->link[1], count, d, 1, nodes, threads);
+ }
+ else if (node->link[1] != &tree->root)
+ {
+ int dr = (int) node->link[1]->data;
+ assert (dr >= 0 && dr < TREE_SIZE);
+ if (threads[dr / 8] & (1 << dr % 8))
+ {
+ printf (" Multiple threads to node %d.\n", d);
+ done = 1;
+ }
+ threads[dr / 8] |= 1 << (dr % 8);
+ }
+
+ if (nr - nl != node->bal)
+ {
+ printf (" Node %d has incorrect balance: right height=%d, "
+ "left height=%d, difference=%d, but balance factor=%d.\n",
+ d, nr, nl, nr - nl, node->bal);
+ done = 1;
+ }
+
+ if (node->bal < -1 || node->bal > 1)
+ {
+ printf (" Node %d has invalid balance factor %d.\n", d, node->bal);
+ done = 1;
+ }
+
+ if (parent != INT_MIN)
+ {
+ assert (dir == -1 || dir == +1);
+ if (dir == -1 && d > parent)
+ {
+ printf (" Node %d is smaller than its left child %d.\n",
+ parent, d);
+ done = 1;
+ }
+ else if (dir == +1 && d < parent)
+ {
+ printf (" Node %d is larger than its right child %d.\n",
+ parent, d);
+ done = 1;
+ }
+ }
+ assert (node->bal >= -1 && node->bal <= 1);
+ return 1 + (nl > nr ? nl : nr);
+ }
+ else return 0;
+}
+
+/* Check that everything about TREE is kosher. */
+void
+verify_tree (avltr_tree *tree)
+{
+ {
+ unsigned char nodes[(TREE_SIZE + 7) / 8];
+ unsigned char threads[(TREE_SIZE + 7) / 8];
+
+ int count = 0;
+ int i;
+
+ memset (nodes, 0, (TREE_SIZE + 7) / 8);
+ memset (threads, 0, (TREE_SIZE + 7) / 8);
+
+ recurse_tree (tree, tree->root.link[0], &count, INT_MIN, 0, nodes,
+ threads);
+
+ if (count != tree->count)
+ {
+ printf (" Tree should have %d nodes, but tree count by recursive "
+ "descent is %d.\n", tree->count, count);
+ done = 1;
+ }
+
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ int thread = threads[i / 8] & (1 << (i % 8));
+ int node = nodes[i / 8] & (1 << (i % 8));
+
+ if (thread && !node)
+ {
+ printf (" A thread leads to ``node'' %d, "
+ "which is not in the tree.", i);
+ done = 1;
+ }
+ }
+ }
+
+ /* Check threads. */
+ {
+ int count = 0;
+ int last = INT_MIN;
+ void **data = NULL;
+
+ while (NULL != (data = avltr_next (tree, data)))
+ {
+ if (((int) *data) < last)
+ {
+ printf (" Misordered right threads.\n");
+ abort ();
+ }
+ else if (((int) *data) == last)
+ {
+ printf (" Loop in right threads detected on %d.\n", last);
+ abort ();
+ }
+ last = (int) *data;
+ count++;
+ }
+
+ if (count != tree->count)
+ {
+ printf (" Tree should have %d nodes, but tree count by right threads "
+ "is %d.\n", tree->count, count);
+ done = 1;
+ }
+ }
+
+ if (done)
+ abort ();
+}
+
+/* Arrange the N elements of ARRAY in random order. */
+void
+shuffle (int *array, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ int j = i + rand () % (n - i);
+ int t = array[j];
+ array[j] = array[i];
+ array[i] = t;
+ }
+}
+
+/* Compares avl trees rooted at A and B, making sure that they are
+ identical. */
+void
+compare_trees (avltr_node *a, avltr_node *b)
+{
+ int diff = 0;
+
+ assert (a && b);
+
+ /* Separating these conditions makes it easier to pinpoint bad data
+ under a memory debugger like Checker because each test is a
+ separate statement. */
+ diff |= a->data != b->data;
+ diff |= a->bal != b->bal;
+ diff |= ((a->link[0] != NULL) ^ (b->link[0] != NULL));
+ diff |= ((a->rtag == PLUS) ^ (b->rtag == PLUS));
+ if (diff)
+ {
+ printf (" Copied nodes differ: %d b=%d a->bal=%d b->bal=%d a:",
+ (int) a->data, (int) b->data, a->bal, b->bal);
+ if (a->link[0])
+ printf ("l");
+ if (a->link[1])
+ printf ("r");
+ printf (" b:");
+ if (b->link[0])
+ printf ("l");
+ if (b->link[1])
+ printf ("r");
+ printf ("\n");
+ abort ();
+ }
+ if (a->link[0] != NULL)
+ compare_trees (a->link[0], b->link[0]);
+ if (a->rtag == PLUS)
+ compare_trees (a->link[1], b->link[1]);
+}
+
+/* Simple stress test procedure for the AVL tree routines. Does the
+ following:
+
+ * Generate a random number seed. By default this is generated from
+ the current time. You can also pass a seed value on the command
+ line if you want to test the same case. The seed value is
+ displayed.
+
+ * Create a tree and insert the integers from 0 up to TREE_SIZE - 1
+ into it, in random order. Verify the tree structure after each
+ insertion.
+
+ * Remove each integer from the tree, in a different random order.
+ After each deletion, verify the tree structure; also, make a copy
+ of the tree into a new tree, verify the copy and compare it to the
+ original, then destroy the copy.
+
+ * Destroy the tree, increment the random seed value, and start over.
+
+ If you make any modifications to the avl tree routines, then you
+ might want to insert some calls to print_structure() at strategic
+ places in order to be able to see what's really going on. Also,
+ memory debuggers like Checker or Purify are very handy. */
+#define N_ITERATIONS 16
+int
+main (int argc, char **argv)
+{
+ int array[TREE_SIZE];
+ int seed;
+ int iteration;
+
+ if (argc == 2)
+ seed = atoi (argv[1]);
+ else
+ seed = time (0) * 257 % 32768;
+
+ fputs ("Testing avltr...\n", stdout);
+
+ for (iteration = 1; iteration <= N_ITERATIONS; iteration++)
+ {
+ avltr_tree *tree;
+ int i;
+
+ printf ("Iteration %4d/%4d: seed=%5d", iteration, N_ITERATIONS, seed);
+ fflush (stdout);
+
+ srand (seed++);
+
+ for (i = 0; i < TREE_SIZE; i++)
+ array[i] = i;
+ shuffle (array, TREE_SIZE);
+
+ tree = avltr_create (compare_ints, NULL);
+ for (i = 0; i < TREE_SIZE; i++)
+ avltr_force_insert (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ shuffle (array, TREE_SIZE);
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ avltr_tree *copy;
+
+ avltr_delete (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ copy = avltr_copy (tree, NULL);
+ verify_tree (copy);
+ if (tree->root.link[0] != NULL)
+ compare_trees (tree->root.link[0], copy->root.link[0]);
+ else if (copy->root.link[0] != NULL)
+ {
+ printf (" Empty tree results in nonempty copy.\n");
+ abort ();
+ }
+ avltr_destroy (copy, NULL);
+
+ if (i % 128 == 0)
+ {
+ putchar ('.');
+ fflush (stdout);
+ }
+ }
+ fputs (" good.\n", stdout);
+
+ avltr_destroy (tree, NULL);
+ }
+
+ return 0;
+}
+#endif /* SELF_TEST */
+
+/*
+ Local variables:
+ compile-command: "gcc -DSELF_TEST=1 -W -Wall -I. -o ./avltr-test avltr.c"
+ End:
+*/
+
diff --git a/avl-1.4.0/avltr.h b/avl-1.4.0/avltr.h
new file mode 100644
index 0000000..27465ef
--- /dev/null
+++ b/avl-1.4.0/avltr.h
@@ -0,0 +1,142 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file avltr.h in libavl. */
+
+#if !avltr_h
+#define avltr_h 1
+
+/* The default maximum height of 32 allows for AVL trees having
+ between 5,704,880 and 4,294,967,295 nodes, depending on order of
+ insertion. You may change this compile-time constant as you
+ wish. */
+#ifndef AVL_MAX_HEIGHT
+#define AVL_MAX_HEIGHT 32
+#endif
+
+/* Structure for a node in a right-threaded AVL tree. */
+typedef struct avltr_node
+ {
+ void *data; /* Pointer to data. */
+ struct avltr_node *link[2]; /* Subtrees or threads. */
+ signed char bal; /* Balance factor. */
+ char cache; /* Used during insertion. */
+ char pad; /* Reserved for fully threaded trees. */
+ signed char rtag; /* Right thread tag. */
+ }
+avltr_node;
+
+/* Used for traversing a right-threaded AVL tree. */
+typedef struct avltr_traverser
+ {
+ int init; /* Initialized? */
+ const avltr_node *p; /* Last node returned. */
+ }
+avltr_traverser;
+
+/* Initializer for avltr_traverser. */
+#define AVLTR_TRAVERSER_INIT {0}
+
+/* Function types. */
+#if !AVL_FUNC_TYPES
+#define AVL_FUNC_TYPES 1
+typedef int (*avl_comparison_func) (const void *a, const void *b, void *param);
+typedef void (*avl_node_func) (void *data, void *param);
+typedef void *(*avl_copy_func) (void *data, void *param);
+#endif
+
+/* Structure which holds information about a threaded AVL tree. */
+typedef struct avltr_tree
+ {
+ avltr_node root; /* Tree root node. */
+ avl_comparison_func cmp; /* Used to compare keys. */
+ int count; /* Number of nodes in the tree. */
+ void *param; /* Arbitary user data. */
+ }
+avltr_tree;
+
+/* General functions. */
+avltr_tree *avltr_create (avl_comparison_func, void *param);
+void avltr_destroy (avltr_tree *, avl_node_func);
+void avltr_free (avltr_tree *);
+int avltr_count (const avltr_tree *);
+avltr_tree *avltr_copy (const avltr_tree *, avl_copy_func);
+struct avl_tree;
+avltr_tree *avltr_thread (struct avl_tree *);
+struct avl_tree *avltr_unthread (avltr_tree *);
+
+/* Walk the tree. */
+void avltr_walk (const avltr_tree *, avl_node_func, void *param);
+void *avltr_traverse (const avltr_tree *, avltr_traverser *);
+#define avlt_init_traverser(TRAVERSER) ((TRAVERSER)->init = 0)
+void **avltr_next (const avltr_tree *tree, void **item);
+
+/* Search for a given item. */
+void **avltr_probe (avltr_tree *, void *);
+void *avltr_delete (avltr_tree *, const void *);
+void **avltr_find (const avltr_tree *, const void *);
+void **avltr_find_close (const avltr_tree *, const void *);
+
+#if __GCC__ >= 2
+extern inline void *
+avltr_insert (avltr_tree *tree, void *item)
+{
+ void **p = avltr_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+extern inline void *
+avltr_replace (avltr_tree *tree, void *item)
+{
+ void **p = avltr_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+#else /* not gcc */
+void *avltr_insert (avltr_tree *tree, void *item);
+void *avltr_replace (avltr_tree *tree, void *item);
+#endif /* not gcc */
+
+/* Easy assertions on insertion & deletion. */
+#ifndef NDEBUG
+#define avltr_force_insert(A, B) \
+ do \
+ { \
+ void *r = avltr_insert (A, B); \
+ assert (r == NULL); \
+ } \
+ while (0)
+void *avltr_force_delete (avltr_tree *, void *);
+#else
+#define avltr_force_insert(A, B) \
+ avltr_insert (A, B)
+#define avltr_force_delete(A, B) \
+ avltr_delete (A, B)
+#endif
+
+#endif /* avltr_h */
diff --git a/avl-1.4.0/configure b/avl-1.4.0/configure
new file mode 100755
index 0000000..5b955a9
--- /dev/null
+++ b/avl-1.4.0/configure
@@ -0,0 +1,1297 @@
+#! /bin/sh
+
+# Guess values for system-dependent variables and create Makefiles.
+# Generated automatically using autoconf version 2.13
+# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+
+# Defaults:
+ac_help=
+ac_default_prefix=/usr/local
+# Any additions from configure.in:
+
+# Initialize some variables set by options.
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+build=NONE
+cache_file=./config.cache
+exec_prefix=NONE
+host=NONE
+no_create=
+nonopt=NONE
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+target=NONE
+verbose=
+x_includes=NONE
+x_libraries=NONE
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+# Initialize some other variables.
+subdirs=
+MFLAGS= MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+# Maximum number of lines to put in a shell here document.
+ac_max_here_lines=12
+
+ac_prev=
+for ac_option
+do
+
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval "$ac_prev=\$ac_option"
+ ac_prev=
+ continue
+ fi
+
+ case "$ac_option" in
+ -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) ac_optarg= ;;
+ esac
+
+ # Accept the important Cygnus configure options, so we can diagnose typos.
+
+ case "$ac_option" in
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir="$ac_optarg" ;;
+
+ -build | --build | --buil | --bui | --bu)
+ ac_prev=build ;;
+ -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+ build="$ac_optarg" ;;
+
+ -cache-file | --cache-file | --cache-fil | --cache-fi \
+ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+ ac_prev=cache_file ;;
+ -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+ cache_file="$ac_optarg" ;;
+
+ -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+ | --da=*)
+ datadir="$ac_optarg" ;;
+
+ -disable-* | --disable-*)
+ ac_feature=`echo $ac_option|sed -e 's/-*disable-//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+ fi
+ ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+ eval "enable_${ac_feature}=no" ;;
+
+ -enable-* | --enable-*)
+ ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then
+ { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; }
+ fi
+ ac_feature=`echo $ac_feature| sed 's/-/_/g'`
+ case "$ac_option" in
+ *=*) ;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "enable_${ac_feature}='$ac_optarg'" ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix="$ac_optarg" ;;
+
+ -gas | --gas | --ga | --g)
+ # Obsolete; use --with-gas.
+ with_gas=yes ;;
+
+ -help | --help | --hel | --he)
+ # Omit some internal or obsolete options to make the list less imposing.
+ # This message is too long to be a string in the A/UX 3.1 sh.
+ cat << EOF
+Usage: configure [options] [host]
+Options: [defaults in brackets after descriptions]
+Configuration:
+ --cache-file=FILE cache test results in FILE
+ --help print this message
+ --no-create do not create output files
+ --quiet, --silent do not print \`checking...' messages
+ --version print the version of autoconf that created configure
+Directory and file names:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [$ac_default_prefix]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [same as prefix]
+ --bindir=DIR user executables in DIR [EPREFIX/bin]
+ --sbindir=DIR system admin executables in DIR [EPREFIX/sbin]
+ --libexecdir=DIR program executables in DIR [EPREFIX/libexec]
+ --datadir=DIR read-only architecture-independent data in DIR
+ [PREFIX/share]
+ --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data in DIR
+ [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var]
+ --libdir=DIR object code libraries in DIR [EPREFIX/lib]
+ --includedir=DIR C header files in DIR [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include]
+ --infodir=DIR info documentation in DIR [PREFIX/info]
+ --mandir=DIR man documentation in DIR [PREFIX/man]
+ --srcdir=DIR find the sources in DIR [configure dir or ..]
+ --program-prefix=PREFIX prepend PREFIX to installed program names
+ --program-suffix=SUFFIX append SUFFIX to installed program names
+ --program-transform-name=PROGRAM
+ run sed PROGRAM on installed program names
+EOF
+ cat << EOF
+Host type:
+ --build=BUILD configure for building on BUILD [BUILD=HOST]
+ --host=HOST configure for HOST [guessed]
+ --target=TARGET configure for TARGET [TARGET=HOST]
+Features and packages:
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --x-includes=DIR X include files are in DIR
+ --x-libraries=DIR X library files are in DIR
+EOF
+ if test -n "$ac_help"; then
+ echo "--enable and --with options recognized:$ac_help"
+ fi
+ exit 0 ;;
+
+ -host | --host | --hos | --ho)
+ ac_prev=host ;;
+ -host=* | --host=* | --hos=* | --ho=*)
+ host="$ac_optarg" ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir="$ac_optarg" ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir="$ac_optarg" ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir="$ac_optarg" ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir="$ac_optarg" ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst \
+ | --locals | --local | --loca | --loc | --lo)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+ localstatedir="$ac_optarg" ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir="$ac_optarg" ;;
+
+ -nfp | --nfp | --nf)
+ # Obsolete; use --without-fp.
+ with_fp=no ;;
+
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c)
+ no_create=yes ;;
+
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+ no_recursion=yes ;;
+
+ -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+ | --oldin | --oldi | --old | --ol | --o)
+ ac_prev=oldincludedir ;;
+ -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+ oldincludedir="$ac_optarg" ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix="$ac_optarg" ;;
+
+ -program-prefix | --program-prefix | --program-prefi | --program-pref \
+ | --program-pre | --program-pr | --program-p)
+ ac_prev=program_prefix ;;
+ -program-prefix=* | --program-prefix=* | --program-prefi=* \
+ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+ program_prefix="$ac_optarg" ;;
+
+ -program-suffix | --program-suffix | --program-suffi | --program-suff \
+ | --program-suf | --program-su | --program-s)
+ ac_prev=program_suffix ;;
+ -program-suffix=* | --program-suffix=* | --program-suffi=* \
+ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+ program_suffix="$ac_optarg" ;;
+
+ -program-transform-name | --program-transform-name \
+ | --program-transform-nam | --program-transform-na \
+ | --program-transform-n | --program-transform- \
+ | --program-transform | --program-transfor \
+ | --program-transfo | --program-transf \
+ | --program-trans | --program-tran \
+ | --progr-tra | --program-tr | --program-t)
+ ac_prev=program_transform_name ;;
+ -program-transform-name=* | --program-transform-name=* \
+ | --program-transform-nam=* | --program-transform-na=* \
+ | --program-transform-n=* | --program-transform-=* \
+ | --program-transform=* | --program-transfor=* \
+ | --program-transfo=* | --program-transf=* \
+ | --program-trans=* | --program-tran=* \
+ | --progr-tra=* | --program-tr=* | --program-t=*)
+ program_transform_name="$ac_optarg" ;;
+
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ silent=yes ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir="$ac_optarg" ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir="$ac_optarg" ;;
+
+ -site | --site | --sit)
+ ac_prev=site ;;
+ -site=* | --site=* | --sit=*)
+ site="$ac_optarg" ;;
+
+ -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+ ac_prev=srcdir ;;
+ -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+ srcdir="$ac_optarg" ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir="$ac_optarg" ;;
+
+ -target | --target | --targe | --targ | --tar | --ta | --t)
+ ac_prev=target ;;
+ -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+ target="$ac_optarg" ;;
+
+ -v | -verbose | --verbose | --verbos | --verbo | --verb)
+ verbose=yes ;;
+
+ -version | --version | --versio | --versi | --vers)
+ echo "configure generated by autoconf version 2.13"
+ exit 0 ;;
+
+ -with-* | --with-*)
+ ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then
+ { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+ fi
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ case "$ac_option" in
+ *=*) ;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "with_${ac_package}='$ac_optarg'" ;;
+
+ -without-* | --without-*)
+ ac_package=`echo $ac_option|sed -e 's/-*without-//'`
+ # Reject names that are not valid shell variable names.
+ if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then
+ { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; }
+ fi
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ eval "with_${ac_package}=no" ;;
+
+ --x)
+ # Obsolete; use --with-x.
+ with_x=yes ;;
+
+ -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+ | --x-incl | --x-inc | --x-in | --x-i)
+ ac_prev=x_includes ;;
+ -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+ x_includes="$ac_optarg" ;;
+
+ -x-libraries | --x-libraries | --x-librarie | --x-librari \
+ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+ ac_prev=x_libraries ;;
+ -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+ x_libraries="$ac_optarg" ;;
+
+ -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
+ ;;
+
+ *)
+ if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
+ echo "configure: warning: $ac_option: invalid host type" 1>&2
+ fi
+ if test "x$nonopt" != xNONE; then
+ { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
+ fi
+ nonopt="$ac_option"
+ ;;
+
+ esac
+done
+
+if test -n "$ac_prev"; then
+ { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
+fi
+
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+# File descriptor usage:
+# 0 standard input
+# 1 file creation
+# 2 errors and warnings
+# 3 some systems may open it to /dev/tty
+# 4 used on the Kubota Titan
+# 6 checking for... messages and results
+# 5 compiler messages saved in config.log
+if test "$silent" = yes; then
+ exec 6>/dev/null
+else
+ exec 6>&1
+fi
+exec 5>./config.log
+
+echo "\
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+" 1>&5
+
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Also quote any args containing shell metacharacters.
+ac_configure_args=
+for ac_arg
+do
+ case "$ac_arg" in
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c) ;;
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;;
+ *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
+ ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+ *) ac_configure_args="$ac_configure_args $ac_arg" ;;
+ esac
+done
+
+# NLS nuisances.
+# Only set these to C if already set. These must not be set unconditionally
+# because not all systems understand e.g. LANG=C (notably SCO).
+# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
+# Non-C LC_CTYPE values break the ctype check.
+if test "${LANG+set}" = set; then LANG=C; export LANG; fi
+if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
+if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
+if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo > confdefs.h
+
+# A filename unique to this package, relative to the directory that
+# configure is in, which we can look for to find out if srcdir is correct.
+ac_unique_file=avl.c
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+ ac_srcdir_defaulted=yes
+ # Try the directory containing this script, then its parent.
+ ac_prog=$0
+ ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'`
+ test "x$ac_confdir" = "x$ac_prog" && ac_confdir=.
+ srcdir=$ac_confdir
+ if test ! -r $srcdir/$ac_unique_file; then
+ srcdir=..
+ fi
+else
+ ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+ if test "$ac_srcdir_defaulted" = yes; then
+ { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; }
+ else
+ { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; }
+ fi
+fi
+srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'`
+
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+ if test "x$prefix" != xNONE; then
+ CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+ else
+ CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+ fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+ if test -r "$ac_site_file"; then
+ echo "loading site script $ac_site_file"
+ . "$ac_site_file"
+ fi
+done
+
+if test -r "$cache_file"; then
+ echo "loading cache $cache_file"
+ . $cache_file
+else
+ echo "creating cache $cache_file"
+ > $cache_file
+fi
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+ac_exeext=
+ac_objext=o
+if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
+ # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
+ if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
+ ac_n= ac_c='
+' ac_t=' '
+ else
+ ac_n=-n ac_c= ac_t=
+ fi
+else
+ ac_n= ac_c='\c' ac_t=
+fi
+
+
+ac_aux_dir=
+for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+ if test -f $ac_dir/install-sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install-sh -c"
+ break
+ elif test -f $ac_dir/install.sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install.sh -c"
+ break
+ fi
+done
+if test -z "$ac_aux_dir"; then
+ { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; }
+fi
+ac_config_guess=$ac_aux_dir/config.guess
+ac_config_sub=$ac_aux_dir/config.sub
+ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
+
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# ./install, which can be erroneously created by make from ./install.sh.
+echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
+echo "configure:556: checking for a BSD compatible install" >&5
+if test -z "$INSTALL"; then
+if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":"
+ for ac_dir in $PATH; do
+ # Account for people who put trailing slashes in PATH elements.
+ case "$ac_dir/" in
+ /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ # Don't use installbsd from OSF since it installs stuff as root
+ # by default.
+ for ac_prog in ginstall scoinst install; do
+ if test -f $ac_dir/$ac_prog; then
+ if test $ac_prog = install &&
+ grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ :
+ else
+ ac_cv_path_install="$ac_dir/$ac_prog -c"
+ break 2
+ fi
+ fi
+ done
+ ;;
+ esac
+ done
+ IFS="$ac_save_IFS"
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL="$ac_cv_path_install"
+ else
+ # As a last resort, use the slow shell script. We don't cache a
+ # path for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the path is relative.
+ INSTALL="$ac_install_sh"
+ fi
+fi
+echo "$ac_t""$INSTALL" 1>&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+echo $ac_n "checking whether build environment is sane""... $ac_c" 1>&6
+echo "configure:609: checking whether build environment is sane" >&5
+# Just in case
+sleep 1
+echo timestamp > conftestfile
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments. Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+ set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
+ if test "$*" = "X"; then
+ # -L didn't work.
+ set X `ls -t $srcdir/configure conftestfile`
+ fi
+ if test "$*" != "X $srcdir/configure conftestfile" \
+ && test "$*" != "X conftestfile $srcdir/configure"; then
+
+ # If neither matched, then we have a broken ls. This can happen
+ # if, for instance, CONFIG_SHELL is bash and it inherits a
+ # broken ls alias from the environment. This has actually
+ # happened. Such a system could not be considered "sane".
+ { echo "configure: error: ls -t appears to fail. Make sure there is not a broken
+alias in your environment" 1>&2; exit 1; }
+ fi
+
+ test "$2" = conftestfile
+ )
+then
+ # Ok.
+ :
+else
+ { echo "configure: error: newly created file is older than distributed files!
+Check your system clock" 1>&2; exit 1; }
+fi
+rm -f conftest*
+echo "$ac_t""yes" 1>&6
+if test "$program_transform_name" = s,x,x,; then
+ program_transform_name=
+else
+ # Double any \ or $. echo might interpret backslashes.
+ cat <<\EOF_SED > conftestsed
+s,\\,\\\\,g; s,\$,$$,g
+EOF_SED
+ program_transform_name="`echo $program_transform_name|sed -f conftestsed`"
+ rm -f conftestsed
+fi
+test "$program_prefix" != NONE &&
+ program_transform_name="s,^,${program_prefix},; $program_transform_name"
+# Use a double $ so make ignores it.
+test "$program_suffix" != NONE &&
+ program_transform_name="s,\$\$,${program_suffix},; $program_transform_name"
+
+# sed with no file args requires a program.
+test "$program_transform_name" = "" && program_transform_name="s,x,x,"
+
+echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
+echo "configure:666: checking whether ${MAKE-make} sets \${MAKE}" >&5
+set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftestmake <<\EOF
+all:
+ @echo 'ac_maketemp="${MAKE}"'
+EOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+eval `${MAKE-make} -f conftestmake 2>/dev/null | grep temp=`
+if test -n "$ac_maketemp"; then
+ eval ac_cv_prog_make_${ac_make}_set=yes
+else
+ eval ac_cv_prog_make_${ac_make}_set=no
+fi
+rm -f conftestmake
+fi
+if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ SET_MAKE=
+else
+ echo "$ac_t""no" 1>&6
+ SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+
+PACKAGE=avl
+
+VERSION=1.4.0
+
+if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
+ { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; }
+fi
+cat >> confdefs.h <<EOF
+#define PACKAGE "$PACKAGE"
+EOF
+
+cat >> confdefs.h <<EOF
+#define VERSION "$VERSION"
+EOF
+
+
+
+missing_dir=`cd $ac_aux_dir && pwd`
+echo $ac_n "checking for working aclocal""... $ac_c" 1>&6
+echo "configure:712: checking for working aclocal" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf. Sigh.
+if (aclocal --version) < /dev/null > /dev/null 2>&1; then
+ ACLOCAL=aclocal
+ echo "$ac_t""found" 1>&6
+else
+ ACLOCAL="$missing_dir/missing aclocal"
+ echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working autoconf""... $ac_c" 1>&6
+echo "configure:725: checking for working autoconf" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf. Sigh.
+if (autoconf --version) < /dev/null > /dev/null 2>&1; then
+ AUTOCONF=autoconf
+ echo "$ac_t""found" 1>&6
+else
+ AUTOCONF="$missing_dir/missing autoconf"
+ echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working automake""... $ac_c" 1>&6
+echo "configure:738: checking for working automake" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf. Sigh.
+if (automake --version) < /dev/null > /dev/null 2>&1; then
+ AUTOMAKE=automake
+ echo "$ac_t""found" 1>&6
+else
+ AUTOMAKE="$missing_dir/missing automake"
+ echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working autoheader""... $ac_c" 1>&6
+echo "configure:751: checking for working autoheader" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf. Sigh.
+if (autoheader --version) < /dev/null > /dev/null 2>&1; then
+ AUTOHEADER=autoheader
+ echo "$ac_t""found" 1>&6
+else
+ AUTOHEADER="$missing_dir/missing autoheader"
+ echo "$ac_t""missing" 1>&6
+fi
+
+echo $ac_n "checking for working makeinfo""... $ac_c" 1>&6
+echo "configure:764: checking for working makeinfo" >&5
+# Run test in a subshell; some versions of sh will print an error if
+# an executable is not found, even if stderr is redirected.
+# Redirect stdin to placate older versions of autoconf. Sigh.
+if (makeinfo --version) < /dev/null > /dev/null 2>&1; then
+ MAKEINFO=makeinfo
+ echo "$ac_t""found" 1>&6
+else
+ MAKEINFO="$missing_dir/missing makeinfo"
+ echo "$ac_t""missing" 1>&6
+fi
+
+
+# Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:780: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_CC="gcc"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+if test -z "$CC"; then
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:810: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_prog_rejected=no
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
+ ac_prog_rejected=yes
+ continue
+ fi
+ ac_cv_prog_CC="cc"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+if test $ac_prog_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $ac_cv_prog_CC
+ shift
+ if test $# -gt 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same basename, so the bogon will be chosen
+ # first if we set CC to just the basename; use the full file name.
+ shift
+ set dummy "$ac_dir/$ac_word" "$@"
+ shift
+ ac_cv_prog_CC="$@"
+ fi
+fi
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+ if test -z "$CC"; then
+ case "`uname -s`" in
+ *win32* | *WIN32*)
+ # Extract the first word of "cl", so it can be a program name with args.
+set dummy cl; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:861: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_CC="cl"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+ echo "$ac_t""$CC" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+ ;;
+ esac
+ fi
+ test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
+fi
+
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
+echo "configure:893: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+cat > conftest.$ac_ext << EOF
+
+#line 904 "configure"
+#include "confdefs.h"
+
+main(){return(0);}
+EOF
+if { (eval echo configure:909: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ ac_cv_prog_cc_works=yes
+ # If we can't run a trivial program, we are probably using a cross compiler.
+ if (./conftest; exit) 2>/dev/null; then
+ ac_cv_prog_cc_cross=no
+ else
+ ac_cv_prog_cc_cross=yes
+ fi
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ ac_cv_prog_cc_works=no
+fi
+rm -fr conftest*
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
+
+echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
+if test $ac_cv_prog_cc_works = no; then
+ { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
+fi
+echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
+echo "configure:935: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
+cross_compiling=$ac_cv_prog_cc_cross
+
+echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
+echo "configure:940: checking whether we are using GNU C" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.c <<EOF
+#ifdef __GNUC__
+ yes;
+#endif
+EOF
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:949: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+ ac_cv_prog_gcc=yes
+else
+ ac_cv_prog_gcc=no
+fi
+fi
+
+echo "$ac_t""$ac_cv_prog_gcc" 1>&6
+
+if test $ac_cv_prog_gcc = yes; then
+ GCC=yes
+else
+ GCC=
+fi
+
+ac_test_CFLAGS="${CFLAGS+set}"
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS=
+echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
+echo "configure:968: checking whether ${CC-cc} accepts -g" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ echo 'void f(){}' > conftest.c
+if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
+ ac_cv_prog_cc_g=yes
+else
+ ac_cv_prog_cc_g=no
+fi
+rm -f conftest*
+
+fi
+
+echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
+if test "$ac_test_CFLAGS" = set; then
+ CFLAGS="$ac_save_CFLAGS"
+elif test $ac_cv_prog_cc_g = yes; then
+ if test "$GCC" = yes; then
+ CFLAGS="-g -O2"
+ else
+ CFLAGS="-g"
+ fi
+else
+ if test "$GCC" = yes; then
+ CFLAGS="-O2"
+ else
+ CFLAGS=
+ fi
+fi
+
+# Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:1002: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ if test -n "$RANLIB"; then
+ ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+ IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
+ ac_dummy="$PATH"
+ for ac_dir in $ac_dummy; do
+ test -z "$ac_dir" && ac_dir=.
+ if test -f $ac_dir/$ac_word; then
+ ac_cv_prog_RANLIB="ranlib"
+ break
+ fi
+ done
+ IFS="$ac_save_ifs"
+ test -z "$ac_cv_prog_RANLIB" && ac_cv_prog_RANLIB=":"
+fi
+fi
+RANLIB="$ac_cv_prog_RANLIB"
+if test -n "$RANLIB"; then
+ echo "$ac_t""$RANLIB" 1>&6
+else
+ echo "$ac_t""no" 1>&6
+fi
+
+trap '' 1 2 15
+cat > confcache <<\EOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs. It is not useful on other systems.
+# If it contains results you don't want to keep, you may remove or edit it.
+#
+# By default, configure uses ./config.cache as the cache file,
+# creating it if it does not exist already. You can give configure
+# the --cache-file=FILE option to use a different cache file; that is
+# what configure does when it calls configure scripts in
+# subdirectories, so they share the cache.
+# Giving --cache-file=/dev/null disables caching, for debugging configure.
+# config.status only pays attention to the cache file if you give it the
+# --recheck option to rerun configure.
+#
+EOF
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(set) 2>&1 |
+ case `(ac_space=' '; set | grep ac_space) 2>&1` in
+ *ac_space=\ *)
+ # `set' does not quote correctly, so add quotes (double-quote substitution
+ # turns \\\\ into \\, and sed turns \\ into \).
+ sed -n \
+ -e "s/'/'\\\\''/g" \
+ -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p"
+ ;;
+ *)
+ # `set' quotes correctly as required by POSIX, so do not add quotes.
+ sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p'
+ ;;
+ esac >> confcache
+if cmp -s $cache_file confcache; then
+ :
+else
+ if test -w $cache_file; then
+ echo "updating cache $cache_file"
+ cat confcache > $cache_file
+ else
+ echo "not updating unwritable cache $cache_file"
+ fi
+fi
+rm -f confcache
+
+trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Any assignment to VPATH causes Sun make to only execute
+# the first set of double-colon rules, so remove it if not needed.
+# If there is a colon in the path, we need to keep it.
+if test "x$srcdir" = x.; then
+ ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d'
+fi
+
+trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15
+
+# Transform confdefs.h into DEFS.
+# Protect against shell expansion while executing Makefile rules.
+# Protect against Makefile macro expansion.
+cat > conftest.defs <<\EOF
+s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g
+s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g
+s%\[%\\&%g
+s%\]%\\&%g
+s%\$%$$%g
+EOF
+DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '`
+rm -f conftest.defs
+
+
+# Without the "./", some shells look in PATH for config.status.
+: ${CONFIG_STATUS=./config.status}
+
+echo creating $CONFIG_STATUS
+rm -f $CONFIG_STATUS
+cat > $CONFIG_STATUS <<EOF
+#! /bin/sh
+# Generated automatically by configure.
+# Run this file to recreate the current configuration.
+# This directory was configured as follows,
+# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+#
+# $0 $ac_configure_args
+#
+# Compiler output produced by configure, useful for debugging
+# configure, is in ./config.log if it exists.
+
+ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]"
+for ac_option
+do
+ case "\$ac_option" in
+ -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+ echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
+ exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
+ -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
+ echo "$CONFIG_STATUS generated by autoconf version 2.13"
+ exit 0 ;;
+ -help | --help | --hel | --he | --h)
+ echo "\$ac_cs_usage"; exit 0 ;;
+ *) echo "\$ac_cs_usage"; exit 1 ;;
+ esac
+done
+
+ac_given_srcdir=$srcdir
+ac_given_INSTALL="$INSTALL"
+
+trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+# Protect against being on the right side of a sed subst in config.status.
+sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
+ s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
+$ac_vpsub
+$extrasub
+s%@SHELL@%$SHELL%g
+s%@CFLAGS@%$CFLAGS%g
+s%@CPPFLAGS@%$CPPFLAGS%g
+s%@CXXFLAGS@%$CXXFLAGS%g
+s%@FFLAGS@%$FFLAGS%g
+s%@DEFS@%$DEFS%g
+s%@LDFLAGS@%$LDFLAGS%g
+s%@LIBS@%$LIBS%g
+s%@exec_prefix@%$exec_prefix%g
+s%@prefix@%$prefix%g
+s%@program_transform_name@%$program_transform_name%g
+s%@bindir@%$bindir%g
+s%@sbindir@%$sbindir%g
+s%@libexecdir@%$libexecdir%g
+s%@datadir@%$datadir%g
+s%@sysconfdir@%$sysconfdir%g
+s%@sharedstatedir@%$sharedstatedir%g
+s%@localstatedir@%$localstatedir%g
+s%@libdir@%$libdir%g
+s%@includedir@%$includedir%g
+s%@oldincludedir@%$oldincludedir%g
+s%@infodir@%$infodir%g
+s%@mandir@%$mandir%g
+s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
+s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g
+s%@INSTALL_DATA@%$INSTALL_DATA%g
+s%@PACKAGE@%$PACKAGE%g
+s%@VERSION@%$VERSION%g
+s%@ACLOCAL@%$ACLOCAL%g
+s%@AUTOCONF@%$AUTOCONF%g
+s%@AUTOMAKE@%$AUTOMAKE%g
+s%@AUTOHEADER@%$AUTOHEADER%g
+s%@MAKEINFO@%$MAKEINFO%g
+s%@SET_MAKE@%$SET_MAKE%g
+s%@CC@%$CC%g
+s%@RANLIB@%$RANLIB%g
+
+CEOF
+EOF
+
+cat >> $CONFIG_STATUS <<\EOF
+
+# Split the substitutions into bite-sized pieces for seds with
+# small command number limits, like on Digital OSF/1 and HP-UX.
+ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script.
+ac_file=1 # Number of current file.
+ac_beg=1 # First line for current file.
+ac_end=$ac_max_sed_cmds # Line after last line for current file.
+ac_more_lines=:
+ac_sed_cmds=""
+while $ac_more_lines; do
+ if test $ac_beg -gt 1; then
+ sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file
+ else
+ sed "${ac_end}q" conftest.subs > conftest.s$ac_file
+ fi
+ if test ! -s conftest.s$ac_file; then
+ ac_more_lines=false
+ rm -f conftest.s$ac_file
+ else
+ if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds="sed -f conftest.s$ac_file"
+ else
+ ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file"
+ fi
+ ac_file=`expr $ac_file + 1`
+ ac_beg=$ac_end
+ ac_end=`expr $ac_end + $ac_max_sed_cmds`
+ fi
+done
+if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds=cat
+fi
+EOF
+
+cat >> $CONFIG_STATUS <<EOF
+
+CONFIG_FILES=\${CONFIG_FILES-"Makefile"}
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
+ # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+ case "$ac_file" in
+ *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+ ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+ *) ac_file_in="${ac_file}.in" ;;
+ esac
+
+ # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
+
+ # Remove last slash and all that follows it. Not all systems have dirname.
+ ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+ if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+ # The file is in a subdirectory.
+ test ! -d "$ac_dir" && mkdir "$ac_dir"
+ ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
+ # A "../" for each directory in $ac_dir_suffix.
+ ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
+ else
+ ac_dir_suffix= ac_dots=
+ fi
+
+ case "$ac_given_srcdir" in
+ .) srcdir=.
+ if test -z "$ac_dots"; then top_srcdir=.
+ else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
+ /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
+ *) # Relative path.
+ srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
+ top_srcdir="$ac_dots$ac_given_srcdir" ;;
+ esac
+
+ case "$ac_given_INSTALL" in
+ [/$]*) INSTALL="$ac_given_INSTALL" ;;
+ *) INSTALL="$ac_dots$ac_given_INSTALL" ;;
+ esac
+
+ echo creating "$ac_file"
+ rm -f "$ac_file"
+ configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
+ case "$ac_file" in
+ *Makefile*) ac_comsub="1i\\
+# $configure_input" ;;
+ *) ac_comsub= ;;
+ esac
+
+ ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+ sed -e "$ac_comsub
+s%@configure_input@%$configure_input%g
+s%@srcdir@%$srcdir%g
+s%@top_srcdir@%$top_srcdir%g
+s%@INSTALL@%$INSTALL%g
+" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file
+fi; done
+rm -f conftest.s*
+
+EOF
+cat >> $CONFIG_STATUS <<EOF
+
+EOF
+cat >> $CONFIG_STATUS <<\EOF
+
+exit 0
+EOF
+chmod +x $CONFIG_STATUS
+rm -fr confdefs* $ac_clean_files
+test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
+
diff --git a/avl-1.4.0/configure.in b/avl-1.4.0/configure.in
new file mode 100644
index 0000000..118f3c8
--- /dev/null
+++ b/avl-1.4.0/configure.in
@@ -0,0 +1,5 @@
+AC_INIT(avl.c)
+AM_INIT_AUTOMAKE(avl, 1.4.0)
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_OUTPUT(Makefile)
diff --git a/avl-1.4.0/install-sh b/avl-1.4.0/install-sh
new file mode 100755
index 0000000..e9de238
--- /dev/null
+++ b/avl-1.4.0/install-sh
@@ -0,0 +1,251 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission. M.I.T. makes no representations about the
+# suitability of this software for any purpose. It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch. It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+ case $1 in
+ -c) instcmd="$cpprog"
+ shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd="$stripprog"
+ shift
+ continue;;
+
+ -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+ shift
+ continue;;
+
+ -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+ shift
+ continue;;
+
+ *) if [ x"$src" = x ]
+ then
+ src=$1
+ else
+ # this colon is to work around a 386BSD /bin/sh bug
+ :
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if [ x"$src" = x ]
+then
+ echo "install: no input file specified"
+ exit 1
+else
+ true
+fi
+
+if [ x"$dir_arg" != x ]; then
+ dst=$src
+ src=""
+
+ if [ -d $dst ]; then
+ instcmd=:
+ chmodcmd=""
+ else
+ instcmd=mkdir
+ fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad
+# if $src (and thus $dsttmp) contains '*'.
+
+ if [ -f $src -o -d $src ]
+ then
+ true
+ else
+ echo "install: $src does not exist"
+ exit 1
+ fi
+
+ if [ x"$dst" = x ]
+ then
+ echo "install: no destination specified"
+ exit 1
+ else
+ true
+ fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+ if [ -d $dst ]
+ then
+ dst="$dst"/`basename $src`
+ else
+ true
+ fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+# this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+ pathcomp="${pathcomp}${1}"
+ shift
+
+ if [ ! -d "${pathcomp}" ] ;
+ then
+ $mkdirprog "${pathcomp}"
+ else
+ true
+ fi
+
+ pathcomp="${pathcomp}/"
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+ $doit $instcmd $dst &&
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+ if [ x"$transformarg" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ dstfile=`basename $dst $transformbasename |
+ sed $transformarg`$transformbasename
+ fi
+
+# don't allow the sed command to completely eliminate the filename
+
+ if [ x"$dstfile" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ true
+ fi
+
+# Make a temp file name in the proper directory.
+
+ dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+ $doit $instcmd $src $dsttmp &&
+
+ trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing. If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+
+# Now rename the file to the real destination.
+
+ $doit $rmcmd -f $dstdir/$dstfile &&
+ $doit $mvcmd $dsttmp $dstdir/$dstfile
+
+fi &&
+
+
+exit 0
diff --git a/avl-1.4.0/missing b/avl-1.4.0/missing
new file mode 100755
index 0000000..7789652
--- /dev/null
+++ b/avl-1.4.0/missing
@@ -0,0 +1,190 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+# Franc,ois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+if test $# -eq 0; then
+ echo 1>&2 "Try \`$0 --help' for more information"
+ exit 1
+fi
+
+case "$1" in
+
+ -h|--h|--he|--hel|--help)
+ echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+ -h, --help display this help and exit
+ -v, --version output version information and exit
+
+Supported PROGRAM values:
+ aclocal touch file \`aclocal.m4'
+ autoconf touch file \`configure'
+ autoheader touch file \`config.h.in'
+ automake touch all \`Makefile.in' files
+ bison create \`y.tab.[ch]', if possible, from existing .[ch]
+ flex create \`lex.yy.c', if possible, from existing .c
+ lex create \`lex.yy.c', if possible, from existing .c
+ makeinfo touch the output file
+ yacc create \`y.tab.[ch]', if possible, from existing .[ch]"
+ ;;
+
+ -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+ echo "missing - GNU libit 0.0"
+ ;;
+
+ -*)
+ echo 1>&2 "$0: Unknown \`$1' option"
+ echo 1>&2 "Try \`$0 --help' for more information"
+ exit 1
+ ;;
+
+ aclocal)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`acinclude.m4' or \`configure.in'. You might want
+ to install the \`Automake' and \`Perl' packages. Grab them from
+ any GNU archive site."
+ touch aclocal.m4
+ ;;
+
+ autoconf)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`configure.in'. You might want to install the
+ \`Autoconf' and \`GNU m4' packages. Grab them from any GNU
+ archive site."
+ touch configure
+ ;;
+
+ autoheader)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`acconfig.h' or \`configure.in'. You might want
+ to install the \`Autoconf' and \`GNU m4' packages. Grab them
+ from any GNU archive site."
+ files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in`
+ test -z "$files" && files="config.h"
+ touch_files=
+ for f in $files; do
+ case "$f" in
+ *:*) touch_files="$touch_files "`echo "$f" |
+ sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+ *) touch_files="$touch_files $f.in";;
+ esac
+ done
+ touch $touch_files
+ ;;
+
+ automake)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified \`Makefile.am', \`acinclude.m4' or \`configure.in'.
+ You might want to install the \`Automake' and \`Perl' packages.
+ Grab them from any GNU archive site."
+ find . -type f -name Makefile.am -print |
+ sed 's/\.am$/.in/' |
+ while read f; do touch "$f"; done
+ ;;
+
+ bison|yacc)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a \`.y' file. You may need the \`Bison' package
+ in order for those modifications to take effect. You can get
+ \`Bison' from any GNU archive site."
+ rm -f y.tab.c y.tab.h
+ if [ $# -ne 1 ]; then
+ eval LASTARG="\${$#}"
+ case "$LASTARG" in
+ *.y)
+ SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+ if [ -f "$SRCFILE" ]; then
+ cp "$SRCFILE" y.tab.c
+ fi
+ SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+ if [ -f "$SRCFILE" ]; then
+ cp "$SRCFILE" y.tab.h
+ fi
+ ;;
+ esac
+ fi
+ if [ ! -f y.tab.h ]; then
+ echo >y.tab.h
+ fi
+ if [ ! -f y.tab.c ]; then
+ echo 'main() { return 0; }' >y.tab.c
+ fi
+ ;;
+
+ lex|flex)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a \`.l' file. You may need the \`Flex' package
+ in order for those modifications to take effect. You can get
+ \`Flex' from any GNU archive site."
+ rm -f lex.yy.c
+ if [ $# -ne 1 ]; then
+ eval LASTARG="\${$#}"
+ case "$LASTARG" in
+ *.l)
+ SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+ if [ -f "$SRCFILE" ]; then
+ cp "$SRCFILE" lex.yy.c
+ fi
+ ;;
+ esac
+ fi
+ if [ ! -f lex.yy.c ]; then
+ echo 'main() { return 0; }' >lex.yy.c
+ fi
+ ;;
+
+ makeinfo)
+ echo 1>&2 "\
+WARNING: \`$1' is missing on your system. You should only need it if
+ you modified a \`.texi' or \`.texinfo' file, or any other file
+ indirectly affecting the aspect of the manual. The spurious
+ call might also be the consequence of using a buggy \`make' (AIX,
+ DU, IRIX). You might want to install the \`Texinfo' package or
+ the \`GNU make' package. Grab either from any GNU archive site."
+ file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+ if test -z "$file"; then
+ file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+ file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
+ fi
+ touch $file
+ ;;
+
+ *)
+ echo 1>&2 "\
+WARNING: \`$1' is needed, and you do not seem to have it handy on your
+ system. You might have modified some files without having the
+ proper tools for further handling them. Check the \`README' file,
+ it often tells you about the needed prerequirements for installing
+ this package. You may also peek at any GNU archive site, in case
+ some other package would contain this missing \`$1' program."
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/avl-1.4.0/mkinstalldirs b/avl-1.4.0/mkinstalldirs
new file mode 100755
index 0000000..6b3b5fc
--- /dev/null
+++ b/avl-1.4.0/mkinstalldirs
@@ -0,0 +1,40 @@
+#! /bin/sh
+# mkinstalldirs --- make directory hierarchy
+# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+# Created: 1993-05-16
+# Public domain
+
+# $Id$
+
+errstatus=0
+
+for file
+do
+ set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+ shift
+
+ pathcomp=
+ for d
+ do
+ pathcomp="$pathcomp$d"
+ case "$pathcomp" in
+ -* ) pathcomp=./$pathcomp ;;
+ esac
+
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp"
+
+ mkdir "$pathcomp" || lasterr=$?
+
+ if test ! -d "$pathcomp"; then
+ errstatus=$lasterr
+ fi
+ fi
+
+ pathcomp="$pathcomp/"
+ done
+done
+
+exit $errstatus
+
+# mkinstalldirs ends here
diff --git a/avl-1.4.0/rb.c b/avl-1.4.0/rb.c
new file mode 100644
index 0000000..b0ec05d
--- /dev/null
+++ b/avl-1.4.0/rb.c
@@ -0,0 +1,1083 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file rb.c in libavl. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#if SELF_TEST
+#include <limits.h>
+#include <time.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "rb.h"
+
+#if !PSPP && !__GCC__
+#define inline
+#endif
+
+#if __GNUC__ >= 2
+#define unused __attribute__ ((unused))
+#else
+#define unused
+#endif
+
+#ifdef HAVE_XMALLOC
+void *xmalloc (size_t);
+#else /* !HAVE_XMALLOC */
+/* Allocates SIZE bytes of space using malloc(). Aborts if out of
+ memory. */
+static void *
+xmalloc (size_t size)
+{
+ void *vp;
+
+ if (size == 0)
+ return NULL;
+ vp = malloc (size);
+
+ assert (vp != NULL);
+ if (vp == NULL)
+ {
+ fprintf (stderr, "virtual memory exhausted\n");
+ exit (EXIT_FAILURE);
+ }
+ return vp;
+}
+#endif /* !HAVE_XMALLOC */
+
+/* Creates a red-black tree in arena OWNER (which can be NULL). The
+ arena is owned by the caller, not by the red-black tree. CMP is a
+ order function for the data to be stored in the tree. PARAM is
+ arbitrary data that becomes an argument to the comparison
+ function. */
+rb_tree *
+rb_create (MAYBE_ARENA avl_comparison_func cmp, void *param)
+{
+ rb_tree *tree;
+
+ assert (cmp != NULL);
+ tree = xmalloc (sizeof (rb_tree));
+
+ tree->root.link[0] = NULL;
+ tree->root.link[1] = NULL;
+ tree->cmp = cmp;
+ tree->count = 0;
+ tree->param = param;
+
+ return tree;
+}
+
+/* Destroy tree TREE. Function FREE_FUNC is called for every node in
+ the tree as it is destroyed.
+
+ No effect if the tree has an arena owner and free_func is NULL.
+ The caller owns the arena and must destroy it itself.
+
+ Do not attempt to reuse the tree after it has been freed. Create a
+ new one. */
+void
+rb_destroy (rb_tree *tree, avl_node_func free_func)
+{
+ assert (tree != NULL);
+
+ {
+ /* Uses Knuth's Algorithm 2.3.1T as modified in exercise 13
+ (postorder traversal). */
+
+ /* T1. */
+ rb_node *an[RB_MAX_HEIGHT]; /* Stack A: nodes. */
+ unsigned long ab = 0; /* Stack A: bits. */
+ int ap = 0; /* Stack A: height. */
+ rb_node *p = tree->root.link[0];
+
+ for (;;)
+ {
+ /* T2. */
+ while (p != NULL)
+ {
+ /* T3. */
+ ab &= ~(1ul << ap);
+ an[ap++] = p;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ for (;;)
+ {
+ if (ap == 0)
+ goto done;
+
+ p = an[--ap];
+ if ((ab & (1ul << ap)) == 0)
+ {
+ ab |= (1ul << ap++);
+ p = p->link[1];
+ break;
+ }
+
+ if (free_func)
+ free_func (p->data, tree->param);
+ free (p);
+ }
+ }
+ }
+
+ done:
+ free (tree);
+}
+
+/* rb_destroy() with FREE_FUNC hardcoded as free(). */
+void
+rb_free (rb_tree *tree)
+{
+ rb_destroy (tree, (avl_node_func) free);
+}
+
+/* Return the number of nodes in TREE. */
+int
+rb_count (const rb_tree *tree)
+{
+ assert (tree != NULL);
+ return tree->count;
+}
+
+/* Copy the contents of TREE to a new tree in arena OWNER. If COPY is
+ non-NULL, then each data item is passed to function COPY, and the
+ return values are inserted into the new tree; otherwise, the items
+ are copied verbatim from the old tree to the new tree. Returns the
+ new tree. */
+rb_tree *
+rb_copy (MAYBE_ARENA const rb_tree *tree, avl_copy_func copy)
+{
+ /* This is a combination of Knuth's Algorithm 2.3.1C (copying a
+ binary tree) and Algorithm 2.3.1T as modified by exercise 12
+ (preorder traversal). */
+
+ rb_tree *new_tree;
+
+ /* PT1. */
+ const rb_node *pa[RB_MAX_HEIGHT]; /* Stack PA: nodes. */
+ const rb_node **pp = pa; /* Stack PA: stack pointer. */
+ const rb_node *p = &tree->root;
+
+ /* QT1. */
+ rb_node *qa[RB_MAX_HEIGHT]; /* Stack QA: nodes. */
+ rb_node **qp = qa; /* Stack QA: stack pointer. */
+ rb_node *q;
+
+ assert (tree != NULL);
+ new_tree = rb_create (tree->cmp, tree->param);
+ new_tree->count = tree->count;
+ q = &new_tree->root;
+
+ for (;;)
+ {
+ /* C4. */
+ if (p->link[0] != NULL)
+ {
+ rb_node *r = xmalloc (sizeof (rb_node));
+ r->link[0] = r->link[1] = NULL;
+ q->link[0] = r;
+ }
+
+ /* C5: Find preorder successors of P and Q. */
+ goto start;
+ for (;;)
+ {
+ /* PT2. */
+ while (p != NULL)
+ {
+ goto escape;
+ start:
+ /* PT3. */
+ *pp++ = p;
+ *qp++ = q;
+ p = p->link[0];
+ q = q->link[0];
+ }
+
+ /* PT4. */
+ if (pp == pa)
+ {
+ assert (qp == qa);
+ return new_tree;
+ }
+
+ p = *--pp;
+ q = *--qp;
+
+ /* PT5. */
+ p = p->link[1];
+ q = q->link[1];
+ }
+ escape:
+
+ /* C2. */
+ if (p->link[1])
+ {
+ rb_node *r = xmalloc (sizeof (rb_node));
+ r->link[0] = r->link[1] = NULL;
+ q->link[1] = r;
+ }
+
+ /* C3. */
+ q->color = p->color;
+ if (copy == NULL)
+ q->data = p->data;
+ else
+ q->data = copy (p->data, tree->param);
+ }
+}
+
+/* Walk tree TREE in inorder, calling WALK_FUNC at each node. Passes
+ PARAM to WALK_FUNC. */
+void
+rb_walk (const rb_tree *tree, avl_node_func walk_func, void *param)
+{
+ /* Uses Knuth's algorithm 2.3.1T (inorder traversal). */
+ assert (tree && walk_func);
+
+ {
+ /* T1. */
+ const rb_node *an[RB_MAX_HEIGHT]; /* Stack A: nodes. */
+ const rb_node **ap = an; /* Stack A: stack pointer. */
+ const rb_node *p = tree->root.link[0];
+
+ for (;;)
+ {
+ /* T2. */
+ while (p != NULL)
+ {
+ /* T3. */
+ *ap++ = p;
+ p = p->link[0];
+ }
+
+ /* T4. */
+ if (ap == an)
+ return;
+ p = *--ap;
+
+ /* T5. */
+ walk_func (p->data, param);
+ p = p->link[1];
+ }
+ }
+}
+
+/* Each call to this function for a given TREE and TRAV return the
+ next item in the tree in inorder. Initialize the first element of
+ TRAV (init) to 0 before calling the first time. Returns NULL when
+ out of elements. */
+void *
+rb_traverse (const rb_tree *tree, rb_traverser *trav)
+{
+ assert (tree && trav);
+
+ /* Uses Knuth's algorithm 2.3.1T (inorder traversal). */
+ if (trav->init == 0)
+ {
+ /* T1. */
+ trav->init = 1;
+ trav->nstack = 0;
+ trav->p = tree->root.link[0];
+ }
+ else
+ /* T5. */
+ trav->p = trav->p->link[1];
+
+ for (;;)
+ {
+ /* T2. */
+ while (trav->p != NULL)
+ {
+ /* T3. */
+ trav->stack[trav->nstack++] = trav->p;
+ trav->p = trav->p->link[0];
+ }
+
+ /* T4. */
+ if (trav->nstack == 0)
+ {
+ trav->init = 0;
+ return NULL;
+ }
+ trav->p = trav->stack[--trav->nstack];
+
+ /* T5. */
+ return trav->p->data;
+ }
+}
+
+/* Search TREE for an item matching ITEM. If found, returns a pointer
+ to the address of the item. If none is found, ITEM is inserted
+ into the tree, and a pointer to the address of ITEM is returned.
+ In either case, the pointer returned can be changed by the caller,
+ or the returned data item can be directly edited, but the key data
+ in the item must not be changed. */
+void **
+rb_probe (rb_tree *tree, void *item)
+{
+ /* Algorithm based on RB-Insert from section 14.3 of _Introduction
+ to Algorithms_, Cormen et al., MIT Press 1990, ISBN
+ 0-262-03141-8. */
+
+ rb_node *ap[RB_MAX_HEIGHT]; /* Stack A: Nodes. */
+ char ad[RB_MAX_HEIGHT]; /* Stack A: Directions. */
+ int ak = 1; /* Stack A: Pointer. */
+
+ rb_node *t, *x, *y, *n;
+
+ assert (tree != NULL);
+ t = &tree->root;
+ x = t->link[0];
+
+ if (x == NULL)
+ {
+ tree->count++;
+ assert (tree->count == 1);
+ x = t->link[0] = xmalloc (sizeof (rb_node));
+ x->data = item;
+ x->link[0] = x->link[1] = NULL;
+ x->color = RB_BLACK;
+ return &x->data;
+ }
+
+ ad[0] = 0;
+ ap[0] = &tree->root;
+
+ for (;;)
+ {
+ int diff = tree->cmp (item, x->data, tree->param);
+
+ if (diff < 0)
+ {
+ ap[ak] = x;
+ ad[ak++] = 0;
+ y = x->link[0];
+ if (y == NULL)
+ {
+ n = x = x->link[0] = xmalloc (sizeof (rb_node));
+ break;
+ }
+ }
+ else if (diff > 0)
+ {
+ ap[ak] = x;
+ ad[ak++] = 1;
+ y = x->link[1];
+ if (y == NULL)
+ {
+ n = x = x->link[1] = xmalloc (sizeof (rb_node));
+ break;
+ }
+ }
+ else
+ return &x->data;
+
+ x = y;
+ }
+
+ tree->count++;
+ x->data = item;
+ x->link[0] = x->link[1] = NULL;
+ x->color = RB_RED;
+
+ for (;;)
+ {
+ if (ak < 3 || ap[ak - 1]->color != RB_RED)
+ break;
+
+ if (ad[ak - 2] == 0)
+ {
+ y = ap[ak - 2]->link[1];
+ if (y != NULL && y->color == RB_RED)
+ {
+ /* Case 1. */
+ ap[ak - 1]->color = y->color = RB_BLACK;
+ ap[ak - 2]->color = RB_RED;
+ ak -= 2;
+ }
+ else
+ {
+ if (ad[ak - 1] == 1)
+ {
+ /* Case 2. */
+ x = ap[ak - 1];
+ y = x->link[1];
+ x->link[1] = y->link[0];
+ y->link[0] = x;
+ ap[ak - 2]->link[0] = y;
+ }
+ else
+ y = ap[ak - 1];
+
+ /* Case 3. */
+ x = ap[ak - 2];
+ x->color = RB_RED;
+ y->color = RB_BLACK;
+
+ x->link[0] = y->link[1];
+ y->link[1] = x;
+ ap[ak - 3]->link[(int) ad[ak - 3]] = y;
+
+ break;
+ }
+ }
+ else
+ {
+ y = ap[ak - 2]->link[0];
+ if (y != NULL && y->color == RB_RED)
+ {
+ /* Case 1. */
+ ap[ak - 1]->color = y->color = RB_BLACK;
+ ap[ak - 2]->color = RB_RED;
+ ak -= 2;
+ }
+ else
+ {
+ if (ad[ak - 1] == 0)
+ {
+ /* Case 2. */
+ x = ap[ak - 1];
+ y = x->link[0];
+ x->link[0] = y->link[1];
+ y->link[1] = x;
+ ap[ak - 2]->link[1] = y;
+ }
+ else
+ y = ap[ak - 1];
+
+ /* Case 3. */
+ x = ap[ak - 2];
+ x->color = RB_RED;
+ y->color = RB_BLACK;
+
+ x->link[1] = y->link[0];
+ y->link[0] = x;
+ ap[ak - 3]->link[(int) ad[ak - 3]] = y;
+ break;
+ }
+ }
+ }
+
+ tree->root.link[0]->color = RB_BLACK;
+
+ return &n->data;
+}
+
+/* Search TREE for an item matching ITEM, and return it if found. */
+void *
+rb_find (const rb_tree *tree, const void *item)
+{
+ const rb_node *p;
+
+ assert (tree != NULL);
+ for (p = tree->root.link[0]; p; )
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+
+ if (diff < 0)
+ p = p->link[0];
+ else if (diff > 0)
+ p = p->link[1];
+ else
+ return p->data;
+ }
+
+ return NULL;
+}
+
+/* Search TREE for an item close to the value of ITEM, and return it.
+ This function will return a null pointer only if TREE is empty. */
+void *
+rb_find_close (const rb_tree *tree, const void *item)
+{
+ const rb_node *p;
+
+ assert (tree != NULL);
+ p = tree->root.link[0];
+ if (p == NULL)
+ return NULL;
+
+ for (;;)
+ {
+ int diff = tree->cmp (item, p->data, tree->param);
+ int t;
+
+ if (diff < 0)
+ t = 0;
+ else if (diff > 0)
+ t = 1;
+ else
+ return p->data;
+
+ if (p->link[t])
+ p = p->link[t];
+ else
+ return p->data;
+ }
+}
+
+/* Searches red-black tree TREE for an item matching ITEM. If found,
+ the item is removed from the tree and the actual item found is
+ returned to the caller. If no item matching ITEM exists in the
+ tree, returns NULL. */
+void *
+rb_delete (rb_tree *tree, const void *item)
+{
+ /* Algorithm based on RB-Delete and RB-Delete-Fixup from section
+ 14.4 of _Introduction to Algorithms_, Cormen et al., MIT Press
+ 1990, ISBN 0-262-03141-8. */
+
+ rb_node *pa[RB_MAX_HEIGHT]; /* Stack P: Nodes. */
+ char a[RB_MAX_HEIGHT]; /* Stack P: Bits. */
+ int k = 1; /* Stack P: Pointer. */
+
+ rb_node *w, *x, *y, *z;
+
+ assert (tree != NULL);
+
+ a[0] = 0;
+ pa[0] = &tree->root;
+ z = tree->root.link[0];
+ for (;;)
+ {
+ int diff;
+
+ if (z == NULL)
+ return NULL;
+
+ diff = tree->cmp (item, z->data, tree->param);
+ if (diff == 0)
+ break;
+
+ pa[k] = z;
+ if (diff < 0)
+ {
+ z = z->link[0];
+ a[k] = 0;
+ }
+ else if (diff > 0)
+ {
+ z = z->link[1];
+ a[k] = 1;
+ }
+ k++;
+ }
+ tree->count--;
+
+ item = z->data;
+
+ /* RB-Delete: Line 1. */
+ if (z->link[0] == NULL || z->link[1] == NULL)
+ {
+ /* Line 2. */
+ y = z;
+
+ /* Lines 4-6. */
+ if (y->link[0] != NULL)
+ x = y->link[0];
+ else
+ x = y->link[1];
+
+ pa[k - 1]->link[(int) a[k - 1]] = x;
+ }
+ else
+ {
+ pa[k] = z;
+ a[k++] = 1;
+
+ /* Line 3. */
+ y = z->link[1];
+ while (y->link[0])
+ {
+ pa[k] = y;
+ a[k++] = 0;
+ y = y->link[0];
+ }
+
+ /* Lines 4-6. */
+ x = y->link[1];
+
+ /* Lines 13-15. */
+ z->data = y->data;
+ pa[k - 1]->link[(int) a[k - 1]] = x;
+ }
+
+ /* Line 16. */
+ if (y->color == RB_RED)
+ {
+ free (y);
+ return (void *) item;
+ }
+
+ free (y);
+
+ /* Numbers below are line numbers from RB-Delete-Fixup. */
+ while (k > 1 && (x == NULL || x->color == RB_BLACK)) /* 1 */
+ {
+ if (a[k - 1] == 0) /* 2 */
+ {
+ w = pa[k - 1]->link[1]; /* 3 */
+
+ if (w->color == RB_RED) /* 4 */
+ {
+ /* Case 1. */
+ w->color = RB_BLACK; /* 5 */
+ pa[k - 1]->color = RB_RED; /* 6 */
+
+ pa[k - 1]->link[1] = w->link[0]; /* 7 */
+ w->link[0] = pa[k - 1];
+ pa[k - 2]->link[(int) a[k - 2]] = w;
+
+ pa[k] = pa[k - 1];
+ a[k] = 0;
+ pa[k - 1] = w;
+ k++;
+
+ w = pa[k - 1]->link[1]; /* 8 */
+ }
+
+ if ((w->link[0] == NULL || w->link[0]->color == RB_BLACK) /* 9 */
+ && (w->link[1] == NULL || w->link[1]->color == RB_BLACK))
+ {
+ /* Case 2. */
+ w->color = RB_RED; /* 10 */
+
+ x = pa[k - 1]; /* 11 */
+ k--;
+ }
+ else
+ {
+ if (w->link[1] == NULL || w->link[1]->color == RB_BLACK) /* 12 */
+ {
+ /* Case 3. */
+ w->link[0]->color = RB_BLACK; /* 13 */
+ w->color = RB_RED; /* 14 */
+
+ y = w->link[0]; /* 15 */
+ w->link[0] = y->link[1];
+ y->link[1] = w;
+
+ w = pa[k - 1]->link[1] = y; /* 16 */
+ }
+
+ /* Case 4. */
+ w->color = pa[k - 1]->color; /* 17 */
+ pa[k - 1]->color = RB_BLACK; /* 18 */
+ w->link[1]->color = RB_BLACK; /* 19 */
+
+ pa[k - 1]->link[1] = w->link[0]; /* 20 */
+ w->link[0] = pa[k - 1];
+ pa[k - 2]->link[(int) a[k - 2]] = w;
+
+ x = tree->root.link[0]; /* 21 */
+ break;
+ }
+ }
+ else
+ {
+ w = pa[k - 1]->link[0];
+ if (w->color == RB_RED)
+ {
+ /* Case 1. */
+ w->color = RB_BLACK;
+ pa[k - 1]->color = RB_RED;
+
+ pa[k - 1]->link[0] = w->link[1];
+ w->link[1] = pa[k - 1];
+ pa[k - 2]->link[(int) a[k - 2]] = w;
+
+ pa[k] = pa[k - 1];
+ a[k] = 1;
+ pa[k - 1] = w;
+ k++;
+
+ w = pa[k - 1]->link[0];
+ }
+
+ if ((w->link[0] == NULL || w->link[0]->color == RB_BLACK)
+ && (w->link[1] == NULL || w->link[1]->color == RB_BLACK))
+ {
+ /* Case 2. */
+ w->color = RB_RED;
+ x = pa[k - 1];
+ k--;
+ }
+ else
+ {
+ if (w->link[0] == NULL || w->link[0]->color == RB_BLACK)
+ {
+ /* Case 3. */
+ w->link[1]->color = RB_BLACK;
+ w->color = RB_RED;
+
+ y = w->link[1];
+ w->link[1] = y->link[0];
+ y->link[0] = w;
+
+ w = pa[k - 1]->link[0] = y;
+ }
+
+ /* Case 4. */
+ w->color = pa[k - 1]->color;
+ pa[k - 1]->color = RB_BLACK;
+ w->link[0]->color = RB_BLACK;
+
+ pa[k - 1]->link[0] = w->link[1];
+ w->link[1] = pa[k - 1];
+ pa[k - 2]->link[(int) a[k - 2]] = w;
+
+ x = tree->root.link[0];
+ break;
+ }
+ }
+ }
+
+ if (x != NULL)
+ x->color = RB_BLACK; /* 23 */
+
+ return (void *) item;
+}
+
+/* Inserts ITEM into TREE. Returns NULL if the item was inserted,
+ otherwise a pointer to the duplicate item. */
+void *
+rb_insert (rb_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = rb_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+/* If ITEM does not exist in TREE, inserts it and returns NULL. If a
+ matching item does exist, it is replaced by ITEM and the item
+ replaced is returned. The caller is responsible for freeing the
+ item returned. */
+void *
+rb_replace (rb_tree *tree, void *item)
+{
+ void **p;
+
+ assert (tree != NULL);
+
+ p = rb_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+
+/* Delete ITEM from TREE when you know that ITEM must be in TREE. For
+ debugging purposes. */
+void *
+(rb_force_delete) (rb_tree *tree, void *item)
+{
+ void *found = rb_delete (tree, item);
+ assert (found != NULL);
+ return found;
+}
+
+#if SELF_TEST
+
+/* Used to flag delayed aborting. */
+int done = 0;
+
+/* Print the structure of node NODE of a red-black tree, which is
+ LEVEL levels from the top of the tree. Uses different delimiters
+ to visually distinguish levels. */
+void
+print_structure (rb_node *node, int level)
+{
+ char lc[] = "([{<`/";
+ char rc[] = ")]}>'\\";
+
+ assert (level <= 10);
+
+ if (node == NULL)
+ {
+ printf (" nil");
+ fflush (stdout);
+ return;
+ }
+ printf (" %c%d%c",
+ lc[level % 6], (int) node->data,
+ node->color == RB_BLACK ? 'b' : 'r');
+ fflush (stdout);
+ if (node->link[0] || node->link[1])
+ print_structure (node->link[0], level + 1);
+ if (node->link[1])
+ print_structure (node->link[1], level + 1);
+ printf ("%c", rc[level % 6]);
+ fflush (stdout);
+}
+
+/* Compare two integers A and B and return a strcmp()-type result. */
+int
+compare_ints (const void *a, const void *b, void *param unused)
+{
+ return ((int) a) - ((int) b);
+}
+
+/* Print the value of integer A. */
+void
+print_int (void *a, void *param unused)
+{
+ printf (" %d", (int) a);
+}
+
+/* Linearly print contents of TREE. */
+void
+print_contents (rb_tree *tree)
+{
+ rb_walk (tree, print_int, NULL);
+ printf ("\n");
+}
+
+/* Examine NODE in a red-black tree. *COUNT is increased by the
+ number of nodes in the tree, including the current one. Returns
+ the number of black nodes (including this node) in a path from this
+ node to any leaf. */
+int
+recurse_tree (rb_node *node, int *count, int ge, int le)
+{
+ if (node)
+ {
+ const int d = (int) node->data;
+ int nl = 1;
+ int nr = 1;
+
+ (*count)++;
+
+ if (!(d >= ge) || !(d <= le))
+ {
+ printf (" Node %d is out of order in the tree.\n", d);
+ done = 1;
+ }
+
+ if (node->link[0])
+ nl = recurse_tree (node->link[0], count, ge, d - 1);
+ if (node->link[1])
+ nr = recurse_tree (node->link[1], count, d + 1, le);
+
+ if (node->color != RB_RED && node->color != RB_BLACK)
+ {
+ printf (" Node %d is neither red nor black (%d).\n", d, node->color);
+ done = 1;
+ }
+
+ if (node->color == RB_RED
+ && node->link[0] && node->link[0]->color == RB_RED)
+ {
+ printf (" Red node %d has red left child %d\n",
+ d, (int) node->link[0]->data);
+ done = 1;
+ }
+
+ if (node->color == RB_RED
+ && node->link[1] && node->link[1]->color == RB_RED)
+ {
+ printf (" Red node %d has red right child %d\n",
+ d, (int) node->link[1]->data);
+ done = 1;
+ }
+
+ if (nl != nr)
+ {
+ printf (" Node %d has two different black-heights: left bh=%d, "
+ "right bh=%d\n", d, nl, nr);
+ done = 1;
+ }
+
+ return (node->color == RB_BLACK) + nl;
+ }
+ else return 1;
+}
+
+/* Check that everything about TREE is kosher. */
+void
+verify_tree (rb_tree *tree)
+{
+ int count = 0;
+ recurse_tree (tree->root.link[0], &count, INT_MIN, INT_MAX);
+ if (count != tree->count)
+ {
+ printf (" Tree has %d nodes, but tree count is %d.\n",
+ count, tree->count);
+ done = 1;
+ }
+ if (done)
+ abort ();
+}
+
+/* Arrange the N elements of ARRAY in random order. */
+void
+shuffle (int *array, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ int j = i + rand () % (n - i);
+ int t = array[j];
+ array[j] = array[i];
+ array[i] = t;
+ }
+}
+
+/* Compares red-black trees rooted at A and B, making sure that they
+ are identical. */
+void
+compare_trees (rb_node *a, rb_node *b)
+{
+ if (a == NULL || b == NULL)
+ {
+ assert (a == NULL && b == NULL);
+ return;
+ }
+ if (a->data != b->data || a->color != b->color
+ || ((a->link[0] != NULL) ^ (b->link[0] != NULL))
+ || ((a->link[1] != NULL) ^ (b->link[1] != NULL)))
+ {
+ printf (" Copied nodes differ: %d b=%d a->color=%d b->color=%d a:",
+ (int) a->data, (int) b->data, a->color, b->color);
+ if (a->link[0])
+ printf ("l");
+ if (a->link[1])
+ printf ("r");
+ printf (" b:");
+ if (b->link[0])
+ printf ("l");
+ if (b->link[1])
+ printf ("r");
+ printf ("\n");
+ abort ();
+ }
+ if (a->link[0] != NULL)
+ compare_trees (a->link[0], b->link[0]);
+ if (a->link[1] != NULL)
+ compare_trees (a->link[1], b->link[1]);
+}
+
+/* Simple stress test procedure for the red-black tree routines. Does
+ the following:
+
+ * Generate a random number seed. By default this is generated from
+ the current time. You can also pass a seed value on the command
+ line if you want to test the same case. The seed value is
+ displayed.
+
+ * Create a tree and insert the integers from 0 up to TREE_SIZE - 1
+ into it, in random order. Verify the tree structure after each
+ insertion.
+
+ * Remove each integer from the tree, in a different random order.
+ After each deletion, verify the tree structure; also, make a copy
+ of the tree into a new tree, verify the copy and compare it to the
+ original, then destroy the copy.
+
+ * Destroy the tree, increment the random seed value, and start over.
+
+ If you make any modifications to the red-black tree routines, then
+ you might want to insert some calls to print_structure() at
+ strategic places in order to be able to see what's really going on.
+ Also, memory debuggers like Checker or Purify are very handy. */
+#define TREE_SIZE 16
+#define N_ITERATIONS 1024
+int
+main (int argc, char **argv)
+{
+ int array[TREE_SIZE];
+ int seed;
+ int iteration;
+
+ if (argc == 2)
+ seed = atoi (argv[1]);
+ else
+ seed = time (0) * 257 % 32768;
+
+ fputs ("Testing rb...\n", stdout);
+
+ for (iteration = 1; iteration <= N_ITERATIONS; iteration++)
+ {
+ rb_tree *tree;
+ int i;
+
+ printf ("Iteration %4d/%4d: seed=%5d", iteration, N_ITERATIONS, seed);
+ fflush (stdout);
+
+ srand (seed++);
+
+ for (i = 0; i < TREE_SIZE; i++)
+ array[i] = i;
+ shuffle (array, TREE_SIZE);
+
+ tree = rb_create (compare_ints, NULL);
+ for (i = 0; i < TREE_SIZE; i++)
+ rb_force_insert (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ shuffle (array, TREE_SIZE);
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ rb_tree *copy;
+
+ rb_delete (tree, (void *) (array[i]));
+ verify_tree (tree);
+
+ copy = rb_copy (tree, NULL);
+ verify_tree (copy);
+ compare_trees (tree->root.link[0], copy->root.link[0]);
+ rb_destroy (copy, NULL);
+
+ if (i % 128 == 0)
+ {
+ putchar ('.');
+ fflush (stdout);
+ }
+ }
+ fputs (" good.\n", stdout);
+
+ rb_destroy (tree, NULL);
+ }
+
+ return 0;
+}
+#endif /* SELF_TEST */
+
+/*
+ Local variables:
+ compile-command: "gcc -DSELF_TEST=1 -W -Wall -I. -o ./rb-test rb.c"
+ End:
+*/
diff --git a/avl-1.4.0/rb.h b/avl-1.4.0/rb.h
new file mode 100644
index 0000000..26a9f49
--- /dev/null
+++ b/avl-1.4.0/rb.h
@@ -0,0 +1,155 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file rb.h in libavl. */
+
+#if !rb_h
+#define rb_h 1
+
+/* The default maximum height of 32 allows for red-black trees having
+ between 65,535 and 4,294,967,295 nodes, depending on order of
+ insertion. You may change this compile-time constant as you
+ wish. */
+#ifndef RB_MAX_HEIGHT
+#define RB_MAX_HEIGHT 32
+#endif
+
+/* Node colors. */
+enum
+ {
+ RB_BLACK,
+ RB_RED,
+ };
+
+/* Structure for a node in a red-black tree. */
+typedef struct rb_node
+ {
+ void *data; /* Pointer to data. */
+ struct rb_node *link[2]; /* Subtrees. */
+ signed char color; /* Color. */
+ char cache; /* Used during insertion. */
+ signed char pad[2]; /* Unused. Reserved for threaded trees. */
+ }
+rb_node;
+
+/* Used for traversing a red-black tree. */
+typedef struct rb_traverser
+ {
+ int init; /* Initialized? */
+ int nstack; /* Top of stack. */
+ const rb_node *p; /* Used for traversal. */
+ const rb_node *stack[RB_MAX_HEIGHT];/* Descended trees. */
+ }
+rb_traverser;
+
+/* Initializer for rb_traverser. */
+#define RB_TRAVERSER_INIT {0}
+
+/* Function types. */
+#if !AVL_FUNC_TYPES
+#define AVL_FUNC_TYPES 1
+typedef int (*avl_comparison_func) (const void *a, const void *b, void *param);
+typedef void (*avl_node_func) (void *data, void *param);
+typedef void *(*avl_copy_func) (void *data, void *param);
+#endif
+
+/* Structure which holds information about a red-black tree. */
+typedef struct rb_tree
+ {
+#if PSPP
+ struct arena **owner; /* Arena to store nodes. */
+#endif
+ rb_node root; /* Tree root node. */
+ avl_comparison_func cmp; /* Used to compare keys. */
+ int count; /* Number of nodes in the tree. */
+ void *param; /* Arbitary user data. */
+ }
+rb_tree;
+
+#if PSPP
+#define MAYBE_ARENA struct arena **owner,
+#else
+#define MAYBE_ARENA /* nothing */
+#endif
+
+/* General functions. */
+rb_tree *rb_create (MAYBE_ARENA avl_comparison_func, void *param);
+void rb_destroy (rb_tree *, avl_node_func);
+void rb_free (rb_tree *);
+int rb_count (const rb_tree *);
+rb_tree *rb_copy (MAYBE_ARENA const rb_tree *, avl_copy_func);
+
+/* Walk the tree. */
+void rb_walk (const rb_tree *, avl_node_func, void *param);
+void *rb_traverse (const rb_tree *, rb_traverser *);
+#define rb_init_traverser(TRAVERSER) ((TRAVERSER)->init = 0)
+
+/* Search for a given item. */
+void **rb_probe (rb_tree *, void *);
+void *rb_delete (rb_tree *, const void *);
+void *rb_find (const rb_tree *, const void *);
+void *rb_find_close (const rb_tree *, const void *);
+
+#if __GCC__ >= 2
+extern inline void *
+rb_insert (rb_tree *tree, void *item)
+{
+ void **p = rb_probe (tree, item);
+ return (*p == item) ? NULL : *p;
+}
+
+extern inline void *
+rb_replace (rb_tree *tree, void *item)
+{
+ void **p = rb_probe (tree, item);
+ if (*p == item)
+ return NULL;
+ else
+ {
+ void *r = *p;
+ *p = item;
+ return r;
+ }
+}
+#else /* not gcc */
+void *rb_insert (rb_tree *tree, void *item);
+void *rb_replace (rb_tree *tree, void *item);
+#endif /* not gcc */
+
+/* Easy assertions on insertion & deletion. */
+#ifndef NDEBUG
+#define rb_force_insert(A, B) \
+ do \
+ { \
+ void *r = rb_insert (A, B); \
+ assert (r == NULL); \
+ } \
+ while (0)
+void *rb_force_delete (rb_tree *, void *);
+#else
+#define rb_force_insert(A, B) \
+ rb_insert (A, B)
+#define rb_force_delete(A, B) \
+ rb_delete (A, B)
+#endif
+
+#endif /* rb_h */
diff --git a/avl-1.4.0/texinfo.tex b/avl-1.4.0/texinfo.tex
new file mode 100644
index 0000000..aa52853
--- /dev/null
+++ b/avl-1.4.0/texinfo.tex
@@ -0,0 +1,5484 @@
+% texinfo.tex -- TeX macros to handle Texinfo files.
+%
+% Load plain if necessary, i.e., if running under initex.
+\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
+%
+\def\texinfoversion{1999-01-05}%
+%
+% Copyright (C) 1985, 86, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98
+% Free Software Foundation, Inc.
+%
+% This texinfo.tex file is free software; you can redistribute it and/or
+% modify it under the terms of the GNU General Public License as
+% published by the Free Software Foundation; either version 2, or (at
+% your option) any later version.
+%
+% This texinfo.tex file is distributed in the hope that it will be
+% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+% General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with this texinfo.tex file; see the file COPYING. If not, write
+% to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+% Boston, MA 02111-1307, USA.
+%
+% In other words, you are welcome to use, share and improve this program.
+% You are forbidden to forbid anyone else to use, share and improve
+% what you give them. Help stamp out software-hoarding!
+%
+% Please try the latest version of texinfo.tex before submitting bug
+% reports; you can get the latest version from:
+% ftp://ftp.gnu.org/pub/gnu/texinfo.tex
+% /home/gd/gnu/doc/texinfo.tex on the GNU machines.
+% (and all GNU mirrors, see http://www.gnu.org/order/ftp.html)
+% ftp://tug.org/tex/texinfo.tex
+% ftp://ctan.org/macros/texinfo/texinfo.tex
+% (and all CTAN mirrors, finger ctan@ctan.org for a list).
+% The texinfo.tex in the texinfo distribution itself could well be out
+% of date, so if that's what you're using, please check.
+%
+% Send bug reports to bug-texinfo@gnu.org.
+% Please include a precise test case in each bug report,
+% including a complete document with which we can reproduce the problem.
+%
+% To process a Texinfo manual with TeX, it's most reliable to use the
+% texi2dvi shell script that comes with the distribution. For simple
+% manuals, however, you can get away with:
+% tex foo.texi
+% texindex foo.??
+% tex foo.texi
+% tex foo.texi
+% dvips foo.dvi -o # or whatever, to process the dvi file.
+% The extra runs of TeX get the cross-reference information correct.
+% Sometimes one run after texindex suffices, and sometimes you need more
+% than two; texi2dvi does it as many times as necessary.
+
+\message{Loading texinfo [version \texinfoversion]:}
+
+% If in a .fmt file, print the version number
+% and turn on active characters that we couldn't do earlier because
+% they might have appeared in the input file name.
+\everyjob{\message{[Texinfo version \texinfoversion]}%
+ \catcode`+=\active \catcode`\_=\active}
+
+% Save some parts of plain tex whose names we will redefine.
+
+\let\ptexb=\b
+\let\ptexbullet=\bullet
+\let\ptexc=\c
+\let\ptexcomma=\,
+\let\ptexdot=\.
+\let\ptexdots=\dots
+\let\ptexend=\end
+\let\ptexequiv=\equiv
+\let\ptexexclam=\!
+\let\ptexi=\i
+\let\ptexlbrace=\{
+\let\ptexrbrace=\}
+\let\ptexstar=\*
+\let\ptext=\t
+
+% We never want plain's outer \+ definition in Texinfo.
+% For @tex, we can use \tabalign.
+\let\+ = \relax
+
+
+\message{Basics,}
+\chardef\other=12
+
+% If this character appears in an error message or help string, it
+% starts a new line in the output.
+\newlinechar = `^^J
+
+% Set up fixed words for English if not already set.
+\ifx\putwordAppendix\undefined \gdef\putwordAppendix{Appendix}\fi
+\ifx\putwordChapter\undefined \gdef\putwordChapter{Chapter}\fi
+\ifx\putwordfile\undefined \gdef\putwordfile{file}\fi
+\ifx\putwordInfo\undefined \gdef\putwordInfo{Info}\fi
+\ifx\putwordMethodon\undefined \gdef\putwordMethodon{Method on}\fi
+\ifx\putwordon\undefined \gdef\putwordon{on}\fi
+\ifx\putwordpage\undefined \gdef\putwordpage{page}\fi
+\ifx\putwordsection\undefined \gdef\putwordsection{section}\fi
+\ifx\putwordSection\undefined \gdef\putwordSection{Section}\fi
+\ifx\putwordsee\undefined \gdef\putwordsee{see}\fi
+\ifx\putwordSee\undefined \gdef\putwordSee{See}\fi
+\ifx\putwordShortContents\undefined \gdef\putwordShortContents{Short Contents}\fi
+\ifx\putwordTableofContents\undefined\gdef\putwordTableofContents{Table of Contents}\fi
+
+% Ignore a token.
+%
+\def\gobble#1{}
+
+\hyphenation{ap-pen-dix}
+\hyphenation{mini-buf-fer mini-buf-fers}
+\hyphenation{eshell}
+\hyphenation{white-space}
+
+% Margin to add to right of even pages, to left of odd pages.
+\newdimen \bindingoffset
+\newdimen \normaloffset
+\newdimen\pagewidth \newdimen\pageheight
+
+% Sometimes it is convenient to have everything in the transcript file
+% and nothing on the terminal. We don't just call \tracingall here,
+% since that produces some useless output on the terminal.
+%
+\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
+\ifx\eTeXversion\undefined
+\def\loggingall{\tracingcommands2 \tracingstats2
+ \tracingpages1 \tracingoutput1 \tracinglostchars1
+ \tracingmacros2 \tracingparagraphs1 \tracingrestores1
+ \showboxbreadth\maxdimen\showboxdepth\maxdimen
+}%
+\else
+\def\loggingall{\tracingcommands3 \tracingstats2
+ \tracingpages1 \tracingoutput1 \tracinglostchars1
+ \tracingmacros2 \tracingparagraphs1 \tracingrestores1
+ \tracingscantokens1 \tracingassigns1 \tracingifs1
+ \tracinggroups1 \tracingnesting2
+ \showboxbreadth\maxdimen\showboxdepth\maxdimen
+}%
+\fi
+
+% For @cropmarks command.
+% Do @cropmarks to get crop marks.
+%
+\newif\ifcropmarks
+\let\cropmarks = \cropmarkstrue
+%
+% Dimensions to add cropmarks at corners.
+% Added by P. A. MacKay, 12 Nov. 1986
+%
+\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
+\newdimen\cornerlong \cornerlong=1pc
+\newdimen\cornerthick \cornerthick=.3pt
+\newdimen\topandbottommargin \topandbottommargin=.75in
+
+% Main output routine.
+\chardef\PAGE = 255
+\output = {\onepageout{\pagecontents\PAGE}}
+
+\newbox\headlinebox
+\newbox\footlinebox
+
+% \onepageout takes a vbox as an argument. Note that \pagecontents
+% does insertions, but you have to call it yourself.
+\def\onepageout#1{%
+ \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
+ %
+ \ifodd\pageno \advance\hoffset by \bindingoffset
+ \else \advance\hoffset by -\bindingoffset\fi
+ %
+ % Do this outside of the \shipout so @code etc. will be expanded in
+ % the headline as they should be, not taken literally (outputting ''code).
+ \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}%
+ \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}%
+ %
+ {%
+ % Have to do this stuff outside the \shipout because we want it to
+ % take effect in \write's, yet the group defined by the \vbox ends
+ % before the \shipout runs.
+ %
+ \escapechar = `\\ % use backslash in output files.
+ \indexdummies % don't expand commands in the output.
+ \normalturnoffactive % \ in index entries must not stay \, e.g., if
+ % the page break happens to be in the middle of an example.
+ \shipout\vbox{%
+ \ifcropmarks \vbox to \outervsize\bgroup
+ \hsize = \outerhsize
+ \vskip-\topandbottommargin
+ \vtop to0pt{%
+ \line{\ewtop\hfil\ewtop}%
+ \nointerlineskip
+ \line{%
+ \vbox{\moveleft\cornerthick\nstop}%
+ \hfill
+ \vbox{\moveright\cornerthick\nstop}%
+ }%
+ \vss}%
+ \vskip\topandbottommargin
+ \line\bgroup
+ \hfil % center the page within the outer (page) hsize.
+ \ifodd\pageno\hskip\bindingoffset\fi
+ \vbox\bgroup
+ \fi
+ %
+ \unvbox\headlinebox
+ \pagebody{#1}%
+ \ifdim\ht\footlinebox > 0pt
+ % Only leave this space if the footline is nonempty.
+ % (We lessened \vsize for it in \oddfootingxxx.)
+ % The \baselineskip=24pt in plain's \makefootline has no effect.
+ \vskip 2\baselineskip
+ \unvbox\footlinebox
+ \fi
+ %
+ \ifcropmarks
+ \egroup % end of \vbox\bgroup
+ \hfil\egroup % end of (centering) \line\bgroup
+ \vskip\topandbottommargin plus1fill minus1fill
+ \boxmaxdepth = \cornerthick
+ \vbox to0pt{\vss
+ \line{%
+ \vbox{\moveleft\cornerthick\nsbot}%
+ \hfill
+ \vbox{\moveright\cornerthick\nsbot}%
+ }%
+ \nointerlineskip
+ \line{\ewbot\hfil\ewbot}%
+ }%
+ \egroup % \vbox from first cropmarks clause
+ \fi
+ }% end of \shipout\vbox
+ }% end of group with \turnoffactive
+ \advancepageno
+ \ifnum\outputpenalty>-20000 \else\dosupereject\fi
+}
+
+\newinsert\margin \dimen\margin=\maxdimen
+
+\def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}}
+{\catcode`\@ =11
+\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
+% marginal hacks, juha@viisa.uucp (Juha Takala)
+\ifvoid\margin\else % marginal info is present
+ \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
+\dimen@=\dp#1 \unvbox#1
+\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
+\ifr@ggedbottom \kern-\dimen@ \vfil \fi}
+}
+
+% Here are the rules for the cropmarks. Note that they are
+% offset so that the space between them is truly \outerhsize or \outervsize
+% (P. A. MacKay, 12 November, 1986)
+%
+\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
+\def\nstop{\vbox
+ {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
+\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
+\def\nsbot{\vbox
+ {\hrule height\cornerlong depth\cornerthick width\cornerthick}}
+
+% Parse an argument, then pass it to #1. The argument is the rest of
+% the input line (except we remove a trailing comment). #1 should be a
+% macro which expects an ordinary undelimited TeX argument.
+%
+\def\parsearg#1{%
+ \let\next = #1%
+ \begingroup
+ \obeylines
+ \futurelet\temp\parseargx
+}
+
+% If the next token is an obeyed space (from an @example environment or
+% the like), remove it and recurse. Otherwise, we're done.
+\def\parseargx{%
+ % \obeyedspace is defined far below, after the definition of \sepspaces.
+ \ifx\obeyedspace\temp
+ \expandafter\parseargdiscardspace
+ \else
+ \expandafter\parseargline
+ \fi
+}
+
+% Remove a single space (as the delimiter token to the macro call).
+{\obeyspaces %
+ \gdef\parseargdiscardspace {\futurelet\temp\parseargx}}
+
+{\obeylines %
+ \gdef\parseargline#1^^M{%
+ \endgroup % End of the group started in \parsearg.
+ %
+ % First remove any @c comment, then any @comment.
+ % Result of each macro is put in \toks0.
+ \argremovec #1\c\relax %
+ \expandafter\argremovecomment \the\toks0 \comment\relax %
+ %
+ % Call the caller's macro, saved as \next in \parsearg.
+ \expandafter\next\expandafter{\the\toks0}%
+ }%
+}
+
+% Since all \c{,omment} does is throw away the argument, we can let TeX
+% do that for us. The \relax here is matched by the \relax in the call
+% in \parseargline; it could be more or less anything, its purpose is
+% just to delimit the argument to the \c.
+\def\argremovec#1\c#2\relax{\toks0 = {#1}}
+\def\argremovecomment#1\comment#2\relax{\toks0 = {#1}}
+
+% \argremovec{,omment} might leave us with trailing spaces, though; e.g.,
+% @end itemize @c foo
+% will have two active spaces as part of the argument with the
+% `itemize'. Here we remove all active spaces from #1, and assign the
+% result to \toks0.
+%
+% This loses if there are any *other* active characters besides spaces
+% in the argument -- _ ^ +, for example -- since they get expanded.
+% Fortunately, Texinfo does not define any such commands. (If it ever
+% does, the catcode of the characters in questionwill have to be changed
+% here.) But this means we cannot call \removeactivespaces as part of
+% \argremovec{,omment}, since @c uses \parsearg, and thus the argument
+% that \parsearg gets might well have any character at all in it.
+%
+\def\removeactivespaces#1{%
+ \begingroup
+ \ignoreactivespaces
+ \edef\temp{#1}%
+ \global\toks0 = \expandafter{\temp}%
+ \endgroup
+}
+
+% Change the active space to expand to nothing.
+%
+\begingroup
+ \obeyspaces
+ \gdef\ignoreactivespaces{\obeyspaces\let =\empty}
+\endgroup
+
+
+\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
+
+%% These are used to keep @begin/@end levels from running away
+%% Call \inENV within environments (after a \begingroup)
+\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi}
+\def\ENVcheck{%
+\ifENV\errmessage{Still within an environment; press RETURN to continue}
+\endgroup\fi} % This is not perfect, but it should reduce lossage
+
+% @begin foo is the same as @foo, for now.
+\newhelp\EMsimple{Press RETURN to continue.}
+
+\outer\def\begin{\parsearg\beginxxx}
+
+\def\beginxxx #1{%
+\expandafter\ifx\csname #1\endcsname\relax
+{\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else
+\csname #1\endcsname\fi}
+
+% @end foo executes the definition of \Efoo.
+%
+\def\end{\parsearg\endxxx}
+\def\endxxx #1{%
+ \removeactivespaces{#1}%
+ \edef\endthing{\the\toks0}%
+ %
+ \expandafter\ifx\csname E\endthing\endcsname\relax
+ \expandafter\ifx\csname \endthing\endcsname\relax
+ % There's no \foo, i.e., no ``environment'' foo.
+ \errhelp = \EMsimple
+ \errmessage{Undefined command `@end \endthing'}%
+ \else
+ \unmatchedenderror\endthing
+ \fi
+ \else
+ % Everything's ok; the right environment has been started.
+ \csname E\endthing\endcsname
+ \fi
+}
+
+% There is an environment #1, but it hasn't been started. Give an error.
+%
+\def\unmatchedenderror#1{%
+ \errhelp = \EMsimple
+ \errmessage{This `@end #1' doesn't have a matching `@#1'}%
+}
+
+% Define the control sequence \E#1 to give an unmatched @end error.
+%
+\def\defineunmatchedend#1{%
+ \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}%
+}
+
+
+% Single-spacing is done by various environments (specifically, in
+% \nonfillstart and \quotations).
+\newskip\singlespaceskip \singlespaceskip = 12.5pt
+\def\singlespace{%
+ % Why was this kern here? It messes up equalizing space above and below
+ % environments. --karl, 6may93
+ %{\advance \baselineskip by -\singlespaceskip
+ %\kern \baselineskip}%
+ \setleading \singlespaceskip
+}
+
+%% Simple single-character @ commands
+
+% @@ prints an @
+% Kludge this until the fonts are right (grr).
+\def\@{{\tt\char64}}
+
+% This is turned off because it was never documented
+% and you can use @w{...} around a quote to suppress ligatures.
+%% Define @` and @' to be the same as ` and '
+%% but suppressing ligatures.
+%\def\`{{`}}
+%\def\'{{'}}
+
+% Used to generate quoted braces.
+\def\mylbrace {{\tt\char123}}
+\def\myrbrace {{\tt\char125}}
+\let\{=\mylbrace
+\let\}=\myrbrace
+\begingroup
+ % Definitions to produce actual \{ & \} command in an index.
+ \catcode`\{ = 12 \catcode`\} = 12
+ \catcode`\[ = 1 \catcode`\] = 2
+ \catcode`\@ = 0 \catcode`\\ = 12
+ @gdef@lbracecmd[\{]%
+ @gdef@rbracecmd[\}]%
+@endgroup
+
+% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
+% Others are defined by plain TeX: @` @' @" @^ @~ @= @v @H.
+\let\, = \c
+\let\dotaccent = \.
+\def\ringaccent#1{{\accent23 #1}}
+\let\tieaccent = \t
+\let\ubaraccent = \b
+\let\udotaccent = \d
+
+% Other special characters: @questiondown @exclamdown
+% Plain TeX defines: @AA @AE @O @OE @L (and lowercase versions) @ss.
+\def\questiondown{?`}
+\def\exclamdown{!`}
+
+% Dotless i and dotless j, used for accents.
+\def\imacro{i}
+\def\jmacro{j}
+\def\dotless#1{%
+ \def\temp{#1}%
+ \ifx\temp\imacro \ptexi
+ \else\ifx\temp\jmacro \j
+ \else \errmessage{@dotless can be used only with i or j}%
+ \fi\fi
+}
+
+% Be sure we're in horizontal mode when doing a tie, since we make space
+% equivalent to this in @example-like environments. Otherwise, a space
+% at the beginning of a line will start with \penalty -- and
+% since \penalty is valid in vertical mode, we'd end up putting the
+% penalty on the vertical list instead of in the new paragraph.
+{\catcode`@ = 11
+ % Avoid using \@M directly, because that causes trouble
+ % if the definition is written into an index file.
+ \global\let\tiepenalty = \@M
+ \gdef\tie{\leavevmode\penalty\tiepenalty\ }
+}
+
+% @: forces normal size whitespace following.
+\def\:{\spacefactor=1000 }
+
+% @* forces a line break.
+\def\*{\hfil\break\hbox{}\ignorespaces}
+
+% @. is an end-of-sentence period.
+\def\.{.\spacefactor=3000 }
+
+% @! is an end-of-sentence bang.
+\def\!{!\spacefactor=3000 }
+
+% @? is an end-of-sentence query.
+\def\?{?\spacefactor=3000 }
+
+% @w prevents a word break. Without the \leavevmode, @w at the
+% beginning of a paragraph, when TeX is still in vertical mode, would
+% produce a whole line of output instead of starting the paragraph.
+\def\w#1{\leavevmode\hbox{#1}}
+
+% @group ... @end group forces ... to be all on one page, by enclosing
+% it in a TeX vbox. We use \vtop instead of \vbox to construct the box
+% to keep its height that of a normal line. According to the rules for
+% \topskip (p.114 of the TeXbook), the glue inserted is
+% max (\topskip - \ht (first item), 0). If that height is large,
+% therefore, no glue is inserted, and the space between the headline and
+% the text is small, which looks bad.
+%
+\def\group{\begingroup
+ \ifnum\catcode13=\active \else
+ \errhelp = \groupinvalidhelp
+ \errmessage{@group invalid in context where filling is enabled}%
+ \fi
+ %
+ % The \vtop we start below produces a box with normal height and large
+ % depth; thus, TeX puts \baselineskip glue before it, and (when the
+ % next line of text is done) \lineskip glue after it. (See p.82 of
+ % the TeXbook.) Thus, space below is not quite equal to space
+ % above. But it's pretty close.
+ \def\Egroup{%
+ \egroup % End the \vtop.
+ \endgroup % End the \group.
+ }%
+ %
+ \vtop\bgroup
+ % We have to put a strut on the last line in case the @group is in
+ % the midst of an example, rather than completely enclosing it.
+ % Otherwise, the interline space between the last line of the group
+ % and the first line afterwards is too small. But we can't put the
+ % strut in \Egroup, since there it would be on a line by itself.
+ % Hence this just inserts a strut at the beginning of each line.
+ \everypar = {\strut}%
+ %
+ % Since we have a strut on every line, we don't need any of TeX's
+ % normal interline spacing.
+ \offinterlineskip
+ %
+ % OK, but now we have to do something about blank
+ % lines in the input in @example-like environments, which normally
+ % just turn into \lisppar, which will insert no space now that we've
+ % turned off the interline space. Simplest is to make them be an
+ % empty paragraph.
+ \ifx\par\lisppar
+ \edef\par{\leavevmode \par}%
+ %
+ % Reset ^^M's definition to new definition of \par.
+ \obeylines
+ \fi
+ %
+ % Do @comment since we are called inside an environment such as
+ % @example, where each end-of-line in the input causes an
+ % end-of-line in the output. We don't want the end-of-line after
+ % the `@group' to put extra space in the output. Since @group
+ % should appear on a line by itself (according to the Texinfo
+ % manual), we don't worry about eating any user text.
+ \comment
+}
+%
+% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
+% message, so this ends up printing `@group can only ...'.
+%
+\newhelp\groupinvalidhelp{%
+group can only be used in environments such as @example,^^J%
+where each line of input produces a line of output.}
+
+% @need space-in-mils
+% forces a page break if there is not space-in-mils remaining.
+
+\newdimen\mil \mil=0.001in
+
+\def\need{\parsearg\needx}
+
+% Old definition--didn't work.
+%\def\needx #1{\par %
+%% This method tries to make TeX break the page naturally
+%% if the depth of the box does not fit.
+%{\baselineskip=0pt%
+%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak
+%\prevdepth=-1000pt
+%}}
+
+\def\needx#1{%
+ % Go into vertical mode, so we don't make a big box in the middle of a
+ % paragraph.
+ \par
+ %
+ % Don't add any leading before our big empty box, but allow a page
+ % break, since the best break might be right here.
+ \allowbreak
+ \nointerlineskip
+ \vtop to #1\mil{\vfil}%
+ %
+ % TeX does not even consider page breaks if a penalty added to the
+ % main vertical list is 10000 or more. But in order to see if the
+ % empty box we just added fits on the page, we must make it consider
+ % page breaks. On the other hand, we don't want to actually break the
+ % page after the empty box. So we use a penalty of 9999.
+ %
+ % There is an extremely small chance that TeX will actually break the
+ % page at this \penalty, if there are no other feasible breakpoints in
+ % sight. (If the user is using lots of big @group commands, which
+ % almost-but-not-quite fill up a page, TeX will have a hard time doing
+ % good page breaking, for example.) However, I could not construct an
+ % example where a page broke at this \penalty; if it happens in a real
+ % document, then we can reconsider our strategy.
+ \penalty9999
+ %
+ % Back up by the size of the box, whether we did a page break or not.
+ \kern -#1\mil
+ %
+ % Do not allow a page break right after this kern.
+ \nobreak
+}
+
+% @br forces paragraph break
+
+\let\br = \par
+
+% @dots{} output an ellipsis using the current font.
+% We do .5em per period so that it has the same spacing in a typewriter
+% font as three actual period characters.
+%
+\def\dots{%
+ \leavevmode
+ \hbox to 1.5em{%
+ \hskip 0pt plus 0.25fil minus 0.25fil
+ .\hss.\hss.%
+ \hskip 0pt plus 0.5fil minus 0.5fil
+ }%
+}
+
+% @enddots{} is an end-of-sentence ellipsis.
+%
+\def\enddots{%
+ \leavevmode
+ \hbox to 2em{%
+ \hskip 0pt plus 0.25fil minus 0.25fil
+ .\hss.\hss.\hss.%
+ \hskip 0pt plus 0.5fil minus 0.5fil
+ }%
+ \spacefactor=3000
+}
+
+
+% @page forces the start of a new page
+%
+\def\page{\par\vfill\supereject}
+
+% @exdent text....
+% outputs text on separate line in roman font, starting at standard page margin
+
+% This records the amount of indent in the innermost environment.
+% That's how much \exdent should take out.
+\newskip\exdentamount
+
+% This defn is used inside fill environments such as @defun.
+\def\exdent{\parsearg\exdentyyy}
+\def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}}
+
+% This defn is used inside nofill environments such as @example.
+\def\nofillexdent{\parsearg\nofillexdentyyy}
+\def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount
+\leftline{\hskip\leftskip{\rm#1}}}}
+
+% @inmargin{TEXT} puts TEXT in the margin next to the current paragraph.
+
+\def\inmargin#1{%
+\strut\vadjust{\nobreak\kern-\strutdepth
+ \vtop to \strutdepth{\baselineskip\strutdepth\vss
+ \llap{\rightskip=\inmarginspacing \vbox{\noindent #1}}\null}}}
+\newskip\inmarginspacing \inmarginspacing=1cm
+\def\strutdepth{\dp\strutbox}
+
+%\hbox{{\rm#1}}\hfil\break}}
+
+% @include file insert text of that file as input.
+% Allow normal characters that we make active in the argument (a file name).
+\def\include{\begingroup
+ \catcode`\\=12
+ \catcode`~=12
+ \catcode`^=12
+ \catcode`_=12
+ \catcode`|=12
+ \catcode`<=12
+ \catcode`>=12
+ \catcode`+=12
+ \parsearg\includezzz}
+% Restore active chars for included file.
+\def\includezzz#1{\endgroup\begingroup
+ % Read the included file in a group so nested @include's work.
+ \def\thisfile{#1}%
+ \input\thisfile
+\endgroup}
+
+\def\thisfile{}
+
+% @center line outputs that line, centered
+
+\def\center{\parsearg\centerzzz}
+\def\centerzzz #1{{\advance\hsize by -\leftskip
+\advance\hsize by -\rightskip
+\centerline{#1}}}
+
+% @sp n outputs n lines of vertical space
+
+\def\sp{\parsearg\spxxx}
+\def\spxxx #1{\vskip #1\baselineskip}
+
+% @comment ...line which is ignored...
+% @c is the same as @comment
+% @ignore ... @end ignore is another way to write a comment
+
+\def\comment{\begingroup \catcode`\^^M=\other%
+\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
+\commentxxx}
+{\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}}
+
+\let\c=\comment
+
+% @paragraphindent is defined for the Info formatting commands only.
+\let\paragraphindent=\comment
+
+% Prevent errors for section commands.
+% Used in @ignore and in failing conditionals.
+\def\ignoresections{%
+\let\chapter=\relax
+\let\unnumbered=\relax
+\let\top=\relax
+\let\unnumberedsec=\relax
+\let\unnumberedsection=\relax
+\let\unnumberedsubsec=\relax
+\let\unnumberedsubsection=\relax
+\let\unnumberedsubsubsec=\relax
+\let\unnumberedsubsubsection=\relax
+\let\section=\relax
+\let\subsec=\relax
+\let\subsubsec=\relax
+\let\subsection=\relax
+\let\subsubsection=\relax
+\let\appendix=\relax
+\let\appendixsec=\relax
+\let\appendixsection=\relax
+\let\appendixsubsec=\relax
+\let\appendixsubsection=\relax
+\let\appendixsubsubsec=\relax
+\let\appendixsubsubsection=\relax
+\let\contents=\relax
+\let\smallbook=\relax
+\let\titlepage=\relax
+}
+
+% Used in nested conditionals, where we have to parse the Texinfo source
+% and so want to turn off most commands, in case they are used
+% incorrectly.
+%
+\def\ignoremorecommands{%
+ \let\defcodeindex = \relax
+ \let\defcv = \relax
+ \let\deffn = \relax
+ \let\deffnx = \relax
+ \let\defindex = \relax
+ \let\defivar = \relax
+ \let\defmac = \relax
+ \let\defmethod = \relax
+ \let\defop = \relax
+ \let\defopt = \relax
+ \let\defspec = \relax
+ \let\deftp = \relax
+ \let\deftypefn = \relax
+ \let\deftypefun = \relax
+ \let\deftypevar = \relax
+ \let\deftypevr = \relax
+ \let\defun = \relax
+ \let\defvar = \relax
+ \let\defvr = \relax
+ \let\ref = \relax
+ \let\xref = \relax
+ \let\printindex = \relax
+ \let\pxref = \relax
+ \let\settitle = \relax
+ \let\setchapternewpage = \relax
+ \let\setchapterstyle = \relax
+ \let\everyheading = \relax
+ \let\evenheading = \relax
+ \let\oddheading = \relax
+ \let\everyfooting = \relax
+ \let\evenfooting = \relax
+ \let\oddfooting = \relax
+ \let\headings = \relax
+ \let\include = \relax
+ \let\lowersections = \relax
+ \let\down = \relax
+ \let\raisesections = \relax
+ \let\up = \relax
+ \let\set = \relax
+ \let\clear = \relax
+ \let\item = \relax
+}
+
+% Ignore @ignore ... @end ignore.
+%
+\def\ignore{\doignore{ignore}}
+
+% Ignore @ifinfo, @ifhtml, @ifnottex, @html, @menu, and @direntry text.
+%
+\def\ifinfo{\doignore{ifinfo}}
+\def\ifhtml{\doignore{ifhtml}}
+\def\ifnottex{\doignore{ifnottex}}
+\def\html{\doignore{html}}
+\def\menu{\doignore{menu}}
+\def\direntry{\doignore{direntry}}
+
+% @dircategory CATEGORY -- specify a category of the dir file
+% which this file should belong to. Ignore this in TeX.
+\let\dircategory = \comment
+
+% Ignore text until a line `@end #1'.
+%
+\def\doignore#1{\begingroup
+ % Don't complain about control sequences we have declared \outer.
+ \ignoresections
+ %
+ % Define a command to swallow text until we reach `@end #1'.
+ % This @ is a catcode 12 token (that is the normal catcode of @ in
+ % this texinfo.tex file). We change the catcode of @ below to match.
+ \long\def\doignoretext##1@end #1{\enddoignore}%
+ %
+ % Make sure that spaces turn into tokens that match what \doignoretext wants.
+ \catcode32 = 10
+ %
+ % Ignore braces, too, so mismatched braces don't cause trouble.
+ \catcode`\{ = 9
+ \catcode`\} = 9
+ %
+ % We must not have @c interpreted as a control sequence.
+ \catcode`\@ = 12
+ %
+ % Make the letter c a comment character so that the rest of the line
+ % will be ignored. This way, the document can have (for example)
+ % @c @end ifinfo
+ % and the @end ifinfo will be properly ignored.
+ % (We've just changed @ to catcode 12.)
+ \catcode`\c = 14
+ %
+ % And now expand that command.
+ \doignoretext
+}
+
+% What we do to finish off ignored text.
+%
+\def\enddoignore{\endgroup\ignorespaces}%
+
+\newif\ifwarnedobs\warnedobsfalse
+\def\obstexwarn{%
+ \ifwarnedobs\relax\else
+ % We need to warn folks that they may have trouble with TeX 3.0.
+ % This uses \immediate\write16 rather than \message to get newlines.
+ \immediate\write16{}
+ \immediate\write16{***WARNING*** for users of Unix TeX 3.0!}
+ \immediate\write16{This manual trips a bug in TeX version 3.0 (tex hangs).}
+ \immediate\write16{If you are running another version of TeX, relax.}
+ \immediate\write16{If you are running Unix TeX 3.0, kill this TeX process.}
+ \immediate\write16{ Then upgrade your TeX installation if you can.}
+ \immediate\write16{ (See ftp://ftp.gnu.org/pub/gnu/TeX.README.)}
+ \immediate\write16{If you are stuck with version 3.0, run the}
+ \immediate\write16{ script ``tex3patch'' from the Texinfo distribution}
+ \immediate\write16{ to use a workaround.}
+ \immediate\write16{}
+ \global\warnedobstrue
+ \fi
+}
+
+% **In TeX 3.0, setting text in \nullfont hangs tex. For a
+% workaround (which requires the file ``dummy.tfm'' to be installed),
+% uncomment the following line:
+%%%%%\font\nullfont=dummy\let\obstexwarn=\relax
+
+% Ignore text, except that we keep track of conditional commands for
+% purposes of nesting, up to an `@end #1' command.
+%
+\def\nestedignore#1{%
+ \obstexwarn
+ % We must actually expand the ignored text to look for the @end
+ % command, so that nested ignore constructs work. Thus, we put the
+ % text into a \vbox and then do nothing with the result. To minimize
+ % the change of memory overflow, we follow the approach outlined on
+ % page 401 of the TeXbook: make the current font be a dummy font.
+ %
+ \setbox0 = \vbox\bgroup
+ % Don't complain about control sequences we have declared \outer.
+ \ignoresections
+ %
+ % Define `@end #1' to end the box, which will in turn undefine the
+ % @end command again.
+ \expandafter\def\csname E#1\endcsname{\egroup\ignorespaces}%
+ %
+ % We are going to be parsing Texinfo commands. Most cause no
+ % trouble when they are used incorrectly, but some commands do
+ % complicated argument parsing or otherwise get confused, so we
+ % undefine them.
+ %
+ % We can't do anything about stray @-signs, unfortunately;
+ % they'll produce `undefined control sequence' errors.
+ \ignoremorecommands
+ %
+ % Set the current font to be \nullfont, a TeX primitive, and define
+ % all the font commands to also use \nullfont. We don't use
+ % dummy.tfm, as suggested in the TeXbook, because not all sites
+ % might have that installed. Therefore, math mode will still
+ % produce output, but that should be an extremely small amount of
+ % stuff compared to the main input.
+ %
+ \nullfont
+ \let\tenrm = \nullfont \let\tenit = \nullfont \let\tensl = \nullfont
+ \let\tenbf = \nullfont \let\tentt = \nullfont \let\smallcaps = \nullfont
+ \let\tensf = \nullfont
+ % Similarly for index fonts (mostly for their use in
+ % smallexample)
+ \let\indrm = \nullfont \let\indit = \nullfont \let\indsl = \nullfont
+ \let\indbf = \nullfont \let\indtt = \nullfont \let\indsc = \nullfont
+ \let\indsf = \nullfont
+ %
+ % Don't complain when characters are missing from the fonts.
+ \tracinglostchars = 0
+ %
+ % Don't bother to do space factor calculations.
+ \frenchspacing
+ %
+ % Don't report underfull hboxes.
+ \hbadness = 10000
+ %
+ % Do minimal line-breaking.
+ \pretolerance = 10000
+ %
+ % Do not execute instructions in @tex
+ \def\tex{\doignore{tex}}%
+ % Do not execute macro definitions.
+ % `c' is a comment character, so the word `macro' will get cut off.
+ \def\macro{\doignore{ma}}%
+}
+
+% @set VAR sets the variable VAR to an empty value.
+% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
+%
+% Since we want to separate VAR from REST-OF-LINE (which might be
+% empty), we can't just use \parsearg; we have to insert a space of our
+% own to delimit the rest of the line, and then take it out again if we
+% didn't need it. Make sure the catcode of space is correct to avoid
+% losing inside @example, for instance.
+%
+\def\set{\begingroup\catcode` =10
+ \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR.
+ \parsearg\setxxx}
+\def\setxxx#1{\setyyy#1 \endsetyyy}
+\def\setyyy#1 #2\endsetyyy{%
+ \def\temp{#2}%
+ \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty
+ \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted.
+ \fi
+ \endgroup
+}
+% Can't use \xdef to pre-expand #2 and save some time, since \temp or
+% \next or other control sequences that we've defined might get us into
+% an infinite loop. Consider `@set foo @cite{bar}'.
+\def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}}
+
+% @clear VAR clears (i.e., unsets) the variable VAR.
+%
+\def\clear{\parsearg\clearxxx}
+\def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax}
+
+% @value{foo} gets the text saved in variable foo.
+%
+{
+ \catcode`\_ = \active
+ %
+ % We might end up with active _ or - characters in the argument if
+ % we're called from @code, as @code{@value{foo-bar_}}. So \let any
+ % such active characters to their normal equivalents.
+ \gdef\value{\begingroup
+ \catcode`\-=12 \catcode`\_=12
+ \indexbreaks \let_\normalunderscore
+ \valuexxx}
+}
+\def\valuexxx#1{\expandablevalue{#1}\endgroup}
+
+% We have this subroutine so that we can handle at least some @value's
+% properly in indexes (we \let\value to this in \indexdummies). Ones
+% whose names contain - or _ still won't work, but we can't do anything
+% about that. The command has to be fully expandable, since the result
+% winds up in the index file. This means that if the variable's value
+% contains other Texinfo commands, it's almost certain it will fail
+% (although perhaps we could fix that with sufficient work to do a
+% one-level expansion on the result, instead of complete).
+%
+\def\expandablevalue#1{%
+ \expandafter\ifx\csname SET#1\endcsname\relax
+ {[No value for ``#1'']}%
+ \else
+ \csname SET#1\endcsname
+ \fi
+}
+
+% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
+% with @set.
+%
+\def\ifset{\parsearg\ifsetxxx}
+\def\ifsetxxx #1{%
+ \expandafter\ifx\csname SET#1\endcsname\relax
+ \expandafter\ifsetfail
+ \else
+ \expandafter\ifsetsucceed
+ \fi
+}
+\def\ifsetsucceed{\conditionalsucceed{ifset}}
+\def\ifsetfail{\nestedignore{ifset}}
+\defineunmatchedend{ifset}
+
+% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
+% defined with @set, or has been undefined with @clear.
+%
+\def\ifclear{\parsearg\ifclearxxx}
+\def\ifclearxxx #1{%
+ \expandafter\ifx\csname SET#1\endcsname\relax
+ \expandafter\ifclearsucceed
+ \else
+ \expandafter\ifclearfail
+ \fi
+}
+\def\ifclearsucceed{\conditionalsucceed{ifclear}}
+\def\ifclearfail{\nestedignore{ifclear}}
+\defineunmatchedend{ifclear}
+
+% @iftex, @ifnothtml, @ifnotinfo always succeed; we read the text
+% following, through the first @end iftex (etc.). Make `@end iftex'
+% (etc.) valid only after an @iftex.
+%
+\def\iftex{\conditionalsucceed{iftex}}
+\def\ifnothtml{\conditionalsucceed{ifnothtml}}
+\def\ifnotinfo{\conditionalsucceed{ifnotinfo}}
+\defineunmatchedend{iftex}
+\defineunmatchedend{ifnothtml}
+\defineunmatchedend{ifnotinfo}
+
+% We can't just want to start a group at @iftex (for example) and end it
+% at @end iftex, since then @set commands inside the conditional have no
+% effect (they'd get reverted at the end of the group). So we must
+% define \Eiftex to redefine itself to be its previous value. (We can't
+% just define it to fail again with an ``unmatched end'' error, since
+% the @ifset might be nested.)
+%
+\def\conditionalsucceed#1{%
+ \edef\temp{%
+ % Remember the current value of \E#1.
+ \let\nece{prevE#1} = \nece{E#1}%
+ %
+ % At the `@end #1', redefine \E#1 to be its previous value.
+ \def\nece{E#1}{\let\nece{E#1} = \nece{prevE#1}}%
+ }%
+ \temp
+}
+
+% We need to expand lots of \csname's, but we don't want to expand the
+% control sequences after we've constructed them.
+%
+\def\nece#1{\expandafter\noexpand\csname#1\endcsname}
+
+% @asis just yields its argument. Used with @table, for example.
+%
+\def\asis#1{#1}
+
+% @math means output in math mode.
+% We don't use $'s directly in the definition of \math because control
+% sequences like \math are expanded when the toc file is written. Then,
+% we read the toc file back, the $'s will be normal characters (as they
+% should be, according to the definition of Texinfo). So we must use a
+% control sequence to switch into and out of math mode.
+%
+% This isn't quite enough for @math to work properly in indices, but it
+% seems unlikely it will ever be needed there.
+%
+\let\implicitmath = $
+\def\math#1{\implicitmath #1\implicitmath}
+
+% @bullet and @minus need the same treatment as @math, just above.
+\def\bullet{\implicitmath\ptexbullet\implicitmath}
+\def\minus{\implicitmath-\implicitmath}
+
+% @refill is a no-op.
+\let\refill=\relax
+
+% If working on a large document in chapters, it is convenient to
+% be able to disable indexing, cross-referencing, and contents, for test runs.
+% This is done with @novalidate (before @setfilename).
+%
+\newif\iflinks \linkstrue % by default we want the aux files.
+\let\novalidate = \linksfalse
+
+% @setfilename is done at the beginning of every texinfo file.
+% So open here the files we need to have open while reading the input.
+% This makes it possible to make a .fmt file for texinfo.
+\def\setfilename{%
+ \iflinks
+ \readauxfile
+ \fi % \openindices needs to do some work in any case.
+ \openindices
+ \fixbackslash % Turn off hack to swallow `\input texinfo'.
+ \global\let\setfilename=\comment % Ignore extra @setfilename cmds.
+ %
+ % If texinfo.cnf is present on the system, read it.
+ % Useful for site-wide @afourpaper, etc.
+ % Just to be on the safe side, close the input stream before the \input.
+ \openin 1 texinfo.cnf
+ \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi
+ \closein1
+ \temp
+ %
+ \comment % Ignore the actual filename.
+}
+
+% Called from \setfilename.
+%
+\def\openindices{%
+ \newindex{cp}%
+ \newcodeindex{fn}%
+ \newcodeindex{vr}%
+ \newcodeindex{tp}%
+ \newcodeindex{ky}%
+ \newcodeindex{pg}%
+}
+
+% @bye.
+\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
+
+
+\message{fonts,}
+% Font-change commands.
+
+% Texinfo sort of supports the sans serif font style, which plain TeX does not.
+% So we set up a \sf analogous to plain's \rm, etc.
+\newfam\sffam
+\def\sf{\fam=\sffam \tensf}
+\let\li = \sf % Sometimes we call it \li, not \sf.
+
+% We don't need math for this one.
+\def\ttsl{\tenttsl}
+
+% Use Computer Modern fonts at \magstephalf (11pt).
+\newcount\mainmagstep
+\mainmagstep=\magstephalf
+
+% Set the font macro #1 to the font named #2, adding on the
+% specified font prefix (normally `cm').
+% #3 is the font's design size, #4 is a scale factor
+\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4}
+
+% Use cm as the default font prefix.
+% To specify the font prefix, you must define \fontprefix
+% before you read in texinfo.tex.
+\ifx\fontprefix\undefined
+\def\fontprefix{cm}
+\fi
+% Support font families that don't use the same naming scheme as CM.
+\def\rmshape{r}
+\def\rmbshape{bx} %where the normal face is bold
+\def\bfshape{b}
+\def\bxshape{bx}
+\def\ttshape{tt}
+\def\ttbshape{tt}
+\def\ttslshape{sltt}
+\def\itshape{ti}
+\def\itbshape{bxti}
+\def\slshape{sl}
+\def\slbshape{bxsl}
+\def\sfshape{ss}
+\def\sfbshape{ss}
+\def\scshape{csc}
+\def\scbshape{csc}
+
+\ifx\bigger\relax
+\let\mainmagstep=\magstep1
+\setfont\textrm\rmshape{12}{1000}
+\setfont\texttt\ttshape{12}{1000}
+\else
+\setfont\textrm\rmshape{10}{\mainmagstep}
+\setfont\texttt\ttshape{10}{\mainmagstep}
+\fi
+% Instead of cmb10, you many want to use cmbx10.
+% cmbx10 is a prettier font on its own, but cmb10
+% looks better when embedded in a line with cmr10.
+\setfont\textbf\bfshape{10}{\mainmagstep}
+\setfont\textit\itshape{10}{\mainmagstep}
+\setfont\textsl\slshape{10}{\mainmagstep}
+\setfont\textsf\sfshape{10}{\mainmagstep}
+\setfont\textsc\scshape{10}{\mainmagstep}
+\setfont\textttsl\ttslshape{10}{\mainmagstep}
+\font\texti=cmmi10 scaled \mainmagstep
+\font\textsy=cmsy10 scaled \mainmagstep
+
+% A few fonts for @defun, etc.
+\setfont\defbf\bxshape{10}{\magstep1} %was 1314
+\setfont\deftt\ttshape{10}{\magstep1}
+\def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf}
+
+% Fonts for indices and small examples (9pt).
+% We actually use the slanted font rather than the italic,
+% because texinfo normally uses the slanted fonts for that.
+% Do not make many font distinctions in general in the index, since they
+% aren't very useful.
+\setfont\ninett\ttshape{9}{1000}
+\setfont\ninettsl\ttslshape{10}{900}
+\setfont\indrm\rmshape{9}{1000}
+\setfont\indit\itshape{9}{1000}
+\setfont\indsl\slshape{9}{1000}
+\let\indtt=\ninett
+\let\indttsl=\ninettsl
+\let\indsf=\indrm
+\let\indbf=\indrm
+\setfont\indsc\scshape{10}{900}
+\font\indi=cmmi9
+\font\indsy=cmsy9
+
+% Fonts for title page:
+\setfont\titlerm\rmbshape{12}{\magstep3}
+\setfont\titleit\itbshape{10}{\magstep4}
+\setfont\titlesl\slbshape{10}{\magstep4}
+\setfont\titlett\ttbshape{12}{\magstep3}
+\setfont\titlettsl\ttslshape{10}{\magstep4}
+\setfont\titlesf\sfbshape{17}{\magstep1}
+\let\titlebf=\titlerm
+\setfont\titlesc\scbshape{10}{\magstep4}
+\font\titlei=cmmi12 scaled \magstep3
+\font\titlesy=cmsy10 scaled \magstep4
+\def\authorrm{\secrm}
+
+% Chapter (and unnumbered) fonts (17.28pt).
+\setfont\chaprm\rmbshape{12}{\magstep2}
+\setfont\chapit\itbshape{10}{\magstep3}
+\setfont\chapsl\slbshape{10}{\magstep3}
+\setfont\chaptt\ttbshape{12}{\magstep2}
+\setfont\chapttsl\ttslshape{10}{\magstep3}
+\setfont\chapsf\sfbshape{17}{1000}
+\let\chapbf=\chaprm
+\setfont\chapsc\scbshape{10}{\magstep3}
+\font\chapi=cmmi12 scaled \magstep2
+\font\chapsy=cmsy10 scaled \magstep3
+
+% Section fonts (14.4pt).
+\setfont\secrm\rmbshape{12}{\magstep1}
+\setfont\secit\itbshape{10}{\magstep2}
+\setfont\secsl\slbshape{10}{\magstep2}
+\setfont\sectt\ttbshape{12}{\magstep1}
+\setfont\secttsl\ttslshape{10}{\magstep2}
+\setfont\secsf\sfbshape{12}{\magstep1}
+\let\secbf\secrm
+\setfont\secsc\scbshape{10}{\magstep2}
+\font\seci=cmmi12 scaled \magstep1
+\font\secsy=cmsy10 scaled \magstep2
+
+% \setfont\ssecrm\bxshape{10}{\magstep1} % This size an font looked bad.
+% \setfont\ssecit\itshape{10}{\magstep1} % The letters were too crowded.
+% \setfont\ssecsl\slshape{10}{\magstep1}
+% \setfont\ssectt\ttshape{10}{\magstep1}
+% \setfont\ssecsf\sfshape{10}{\magstep1}
+
+%\setfont\ssecrm\bfshape{10}{1315} % Note the use of cmb rather than cmbx.
+%\setfont\ssecit\itshape{10}{1315} % Also, the size is a little larger than
+%\setfont\ssecsl\slshape{10}{1315} % being scaled magstep1.
+%\setfont\ssectt\ttshape{10}{1315}
+%\setfont\ssecsf\sfshape{10}{1315}
+
+%\let\ssecbf=\ssecrm
+
+% Subsection fonts (13.15pt).
+\setfont\ssecrm\rmbshape{12}{\magstephalf}
+\setfont\ssecit\itbshape{10}{1315}
+\setfont\ssecsl\slbshape{10}{1315}
+\setfont\ssectt\ttbshape{12}{\magstephalf}
+\setfont\ssecttsl\ttslshape{10}{1315}
+\setfont\ssecsf\sfbshape{12}{\magstephalf}
+\let\ssecbf\ssecrm
+\setfont\ssecsc\scbshape{10}{\magstep1}
+\font\sseci=cmmi12 scaled \magstephalf
+\font\ssecsy=cmsy10 scaled 1315
+% The smallcaps and symbol fonts should actually be scaled \magstep1.5,
+% but that is not a standard magnification.
+
+% In order for the font changes to affect most math symbols and letters,
+% we have to define the \textfont of the standard families. Since
+% texinfo doesn't allow for producing subscripts and superscripts, we
+% don't bother to reset \scriptfont and \scriptscriptfont (which would
+% also require loading a lot more fonts).
+%
+\def\resetmathfonts{%
+ \textfont0 = \tenrm \textfont1 = \teni \textfont2 = \tensy
+ \textfont\itfam = \tenit \textfont\slfam = \tensl \textfont\bffam = \tenbf
+ \textfont\ttfam = \tentt \textfont\sffam = \tensf
+}
+
+
+% The font-changing commands redefine the meanings of \tenSTYLE, instead
+% of just \STYLE. We do this so that font changes will continue to work
+% in math mode, where it is the current \fam that is relevant in most
+% cases, not the current font. Plain TeX does \def\bf{\fam=\bffam
+% \tenbf}, for example. By redefining \tenbf, we obviate the need to
+% redefine \bf itself.
+\def\textfonts{%
+ \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
+ \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
+ \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl
+ \resetmathfonts}
+\def\titlefonts{%
+ \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
+ \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
+ \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
+ \let\tenttsl=\titlettsl
+ \resetmathfonts \setleading{25pt}}
+\def\titlefont#1{{\titlefonts\rm #1}}
+\def\chapfonts{%
+ \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
+ \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
+ \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
+ \resetmathfonts \setleading{19pt}}
+\def\secfonts{%
+ \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
+ \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
+ \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl
+ \resetmathfonts \setleading{16pt}}
+\def\subsecfonts{%
+ \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
+ \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
+ \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl
+ \resetmathfonts \setleading{15pt}}
+\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf?
+\def\indexfonts{%
+ \let\tenrm=\indrm \let\tenit=\indit \let\tensl=\indsl
+ \let\tenbf=\indbf \let\tentt=\indtt \let\smallcaps=\indsc
+ \let\tensf=\indsf \let\teni=\indi \let\tensy=\indsy \let\tenttsl=\indttsl
+ \resetmathfonts \setleading{12pt}}
+
+% Set up the default fonts, so we can use them for creating boxes.
+%
+\textfonts
+
+% Define these so they can be easily changed for other fonts.
+\def\angleleft{$\langle$}
+\def\angleright{$\rangle$}
+
+% Count depth in font-changes, for error checks
+\newcount\fontdepth \fontdepth=0
+
+% Fonts for short table of contents.
+\setfont\shortcontrm\rmshape{12}{1000}
+\setfont\shortcontbf\bxshape{12}{1000}
+\setfont\shortcontsl\slshape{12}{1000}
+
+%% Add scribe-like font environments, plus @l for inline lisp (usually sans
+%% serif) and @ii for TeX italic
+
+% \smartitalic{ARG} outputs arg in italics, followed by an italic correction
+% unless the following character is such as not to need one.
+\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else\/\fi\fi\fi}
+\def\smartslanted#1{{\sl #1}\futurelet\next\smartitalicx}
+\def\smartitalic#1{{\it #1}\futurelet\next\smartitalicx}
+
+\let\i=\smartitalic
+\let\var=\smartslanted
+\let\dfn=\smartslanted
+\let\emph=\smartitalic
+\let\cite=\smartslanted
+
+\def\b#1{{\bf #1}}
+\let\strong=\b
+
+% We can't just use \exhyphenpenalty, because that only has effect at
+% the end of a paragraph. Restore normal hyphenation at the end of the
+% group within which \nohyphenation is presumably called.
+%
+\def\nohyphenation{\hyphenchar\font = -1 \aftergroup\restorehyphenation}
+\def\restorehyphenation{\hyphenchar\font = `- }
+
+\def\t#1{%
+ {\tt \rawbackslash \frenchspacing #1}%
+ \null
+}
+\let\ttfont=\t
+\def\samp#1{`\tclose{#1}'\null}
+\setfont\smallrm\rmshape{8}{1000}
+\font\smallsy=cmsy9
+\def\key#1{{\smallrm\textfont2=\smallsy \leavevmode\hbox{%
+ \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
+ \vbox{\hrule\kern-0.4pt
+ \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
+ \kern-0.4pt\hrule}%
+ \kern-.06em\raise0.4pt\hbox{\angleright}}}}
+% The old definition, with no lozenge:
+%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null}
+\def\ctrl #1{{\tt \rawbackslash \hat}#1}
+
+% @file, @option are the same as @samp.
+\let\file=\samp
+\let\option=\samp
+
+% @code is a modification of @t,
+% which makes spaces the same size as normal in the surrounding text.
+\def\tclose#1{%
+ {%
+ % Change normal interword space to be same as for the current font.
+ \spaceskip = \fontdimen2\font
+ %
+ % Switch to typewriter.
+ \tt
+ %
+ % But `\ ' produces the large typewriter interword space.
+ \def\ {{\spaceskip = 0pt{} }}%
+ %
+ % Turn off hyphenation.
+ \nohyphenation
+ %
+ \rawbackslash
+ \frenchspacing
+ #1%
+ }%
+ \null
+}
+
+% We *must* turn on hyphenation at `-' and `_' in \code.
+% Otherwise, it is too hard to avoid overfull hboxes
+% in the Emacs manual, the Library manual, etc.
+
+% Unfortunately, TeX uses one parameter (\hyphenchar) to control
+% both hyphenation at - and hyphenation within words.
+% We must therefore turn them both off (\tclose does that)
+% and arrange explicitly to hyphenate at a dash.
+% -- rms.
+{
+ \catcode`\-=\active
+ \catcode`\_=\active
+ %
+ \global\def\code{\begingroup
+ \catcode`\-=\active \let-\codedash
+ \catcode`\_=\active \let_\codeunder
+ \codex
+ }
+ %
+ % If we end up with any active - characters when handling the index,
+ % just treat them as a normal -.
+ \global\def\indexbreaks{\catcode`\-=\active \let-\realdash}
+}
+
+\def\realdash{-}
+\def\codedash{-\discretionary{}{}{}}
+\def\codeunder{\ifusingtt{\normalunderscore\discretionary{}{}{}}{\_}}
+\def\codex #1{\tclose{#1}\endgroup}
+
+%\let\exp=\tclose %Was temporary
+
+% @kbd is like @code, except that if the argument is just one @key command,
+% then @kbd has no effect.
+
+% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
+% `example' (@kbd uses ttsl only inside of @example and friends),
+% or `code' (@kbd uses normal tty font always).
+\def\kbdinputstyle{\parsearg\kbdinputstylexxx}
+\def\kbdinputstylexxx#1{%
+ \def\arg{#1}%
+ \ifx\arg\worddistinct
+ \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
+ \else\ifx\arg\wordexample
+ \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
+ \else\ifx\arg\wordcode
+ \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
+ \fi\fi\fi
+}
+\def\worddistinct{distinct}
+\def\wordexample{example}
+\def\wordcode{code}
+
+% Default is kbdinputdistinct. (Too much of a hassle to call the macro,
+% the catcodes are wrong for parsearg to work.)
+\gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}
+
+\def\xkey{\key}
+\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}%
+\ifx\one\xkey\ifx\threex\three \key{#2}%
+\else{\tclose{\kbdfont\look}}\fi
+\else{\tclose{\kbdfont\look}}\fi}
+
+% For @url, @env, @command quotes seem unnecessary, so use \code.
+\let\url=\code
+\let\env=\code
+\let\command=\code
+
+% @uref (abbreviation for `urlref') takes an optional second argument
+% specifying the text to display. First (mandatory) arg is the url.
+% Perhaps eventually put in a hypertex \special here.
+%
+\def\uref#1{\urefxxx #1,,\finish}
+\def\urefxxx#1,#2,#3\finish{%
+ \setbox0 = \hbox{\ignorespaces #2}%
+ \ifdim\wd0 > 0pt
+ \unhbox0\ (\code{#1})%
+ \else
+ \code{#1}%
+ \fi
+}
+
+% rms does not like the angle brackets --karl, 17may97.
+% So now @email is just like @uref.
+%\def\email#1{\angleleft{\tt #1}\angleright}
+\let\email=\uref
+
+% Check if we are currently using a typewriter font. Since all the
+% Computer Modern typewriter fonts have zero interword stretch (and
+% shrink), and it is reasonable to expect all typewriter fonts to have
+% this property, we can check that font parameter.
+%
+\def\ifmonospace{\ifdim\fontdimen3\font=0pt }
+
+% Typeset a dimension, e.g., `in' or `pt'. The only reason for the
+% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
+%
+\def\dmn#1{\thinspace #1}
+
+\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par}
+
+% @l was never documented to mean ``switch to the Lisp font'',
+% and it is not used as such in any manual I can find. We need it for
+% Polish suppressed-l. --karl, 22sep96.
+%\def\l#1{{\li #1}\null}
+
+% Explicit font changes: @r, @sc, undocumented @ii.
+\def\r#1{{\rm #1}} % roman font
+\def\sc#1{{\smallcaps#1}} % smallcaps font
+\def\ii#1{{\it #1}} % italic font
+
+% @acronym downcases the argument and prints in smallcaps.
+\def\acronym#1{{\smallcaps \lowercase{#1}}}
+
+% @pounds{} is a sterling sign.
+\def\pounds{{\it\$}}
+
+
+\message{page headings,}
+
+\newskip\titlepagetopglue \titlepagetopglue = 1.5in
+\newskip\titlepagebottomglue \titlepagebottomglue = 2pc
+
+% First the title page. Must do @settitle before @titlepage.
+\newif\ifseenauthor
+\newif\iffinishedtitlepage
+
+% Do an implicit @contents or @shortcontents after @end titlepage if the
+% user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage.
+%
+\newif\ifsetcontentsaftertitlepage
+ \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue
+\newif\ifsetshortcontentsaftertitlepage
+ \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
+
+\def\shorttitlepage{\parsearg\shorttitlepagezzz}
+\def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
+ \endgroup\page\hbox{}\page}
+
+\def\titlepage{\begingroup \parindent=0pt \textfonts
+ \let\subtitlerm=\tenrm
+ \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}%
+ %
+ \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines}%
+ %
+ % Leave some space at the very top of the page.
+ \vglue\titlepagetopglue
+ %
+ % Now you can print the title using @title.
+ \def\title{\parsearg\titlezzz}%
+ \def\titlezzz##1{\leftline{\titlefonts\rm ##1}
+ % print a rule at the page bottom also.
+ \finishedtitlepagefalse
+ \vskip4pt \hrule height 4pt width \hsize \vskip4pt}%
+ % No rule at page bottom unless we print one at the top with @title.
+ \finishedtitlepagetrue
+ %
+ % Now you can put text using @subtitle.
+ \def\subtitle{\parsearg\subtitlezzz}%
+ \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}%
+ %
+ % @author should come last, but may come many times.
+ \def\author{\parsearg\authorzzz}%
+ \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi
+ {\authorfont \leftline{##1}}}%
+ %
+ % Most title ``pages'' are actually two pages long, with space
+ % at the top of the second. We don't want the ragged left on the second.
+ \let\oldpage = \page
+ \def\page{%
+ \iffinishedtitlepage\else
+ \finishtitlepage
+ \fi
+ \oldpage
+ \let\page = \oldpage
+ \hbox{}}%
+% \def\page{\oldpage \hbox{}}
+}
+
+\def\Etitlepage{%
+ \iffinishedtitlepage\else
+ \finishtitlepage
+ \fi
+ % It is important to do the page break before ending the group,
+ % because the headline and footline are only empty inside the group.
+ % If we use the new definition of \page, we always get a blank page
+ % after the title page, which we certainly don't want.
+ \oldpage
+ \endgroup
+ %
+ % If they want short, they certainly want long too.
+ \ifsetshortcontentsaftertitlepage
+ \shortcontents
+ \contents
+ \global\let\shortcontents = \relax
+ \global\let\contents = \relax
+ \fi
+ %
+ \ifsetcontentsaftertitlepage
+ \contents
+ \global\let\contents = \relax
+ \global\let\shortcontents = \relax
+ \fi
+ %
+ \HEADINGSon
+}
+
+\def\finishtitlepage{%
+ \vskip4pt \hrule height 2pt width \hsize
+ \vskip\titlepagebottomglue
+ \finishedtitlepagetrue
+}
+
+%%% Set up page headings and footings.
+
+\let\thispage=\folio
+
+\newtoks\evenheadline % headline on even pages
+\newtoks\oddheadline % headline on odd pages
+\newtoks\evenfootline % footline on even pages
+\newtoks\oddfootline % footline on odd pages
+
+% Now make Tex use those variables
+\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
+ \else \the\evenheadline \fi}}
+\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
+ \else \the\evenfootline \fi}\HEADINGShook}
+\let\HEADINGShook=\relax
+
+% Commands to set those variables.
+% For example, this is what @headings on does
+% @evenheading @thistitle|@thispage|@thischapter
+% @oddheading @thischapter|@thispage|@thistitle
+% @evenfooting @thisfile||
+% @oddfooting ||@thisfile
+
+\def\evenheading{\parsearg\evenheadingxxx}
+\def\oddheading{\parsearg\oddheadingxxx}
+\def\everyheading{\parsearg\everyheadingxxx}
+
+\def\evenfooting{\parsearg\evenfootingxxx}
+\def\oddfooting{\parsearg\oddfootingxxx}
+\def\everyfooting{\parsearg\everyfootingxxx}
+
+{\catcode`\@=0 %
+
+\gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish}
+\gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{%
+\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
+
+\gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish}
+\gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{%
+\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
+
+\gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
+
+\gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish}
+\gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{%
+\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
+
+\gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish}
+\gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{%
+ \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
+ %
+ % Leave some space for the footline. Hopefully ok to assume
+ % @evenfooting will not be used by itself.
+ \global\advance\pageheight by -\baselineskip
+ \global\advance\vsize by -\baselineskip
+}
+
+\gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}}
+%
+}% unbind the catcode of @.
+
+% @headings double turns headings on for double-sided printing.
+% @headings single turns headings on for single-sided printing.
+% @headings off turns them off.
+% @headings on same as @headings double, retained for compatibility.
+% @headings after turns on double-sided headings after this page.
+% @headings doubleafter turns on double-sided headings after this page.
+% @headings singleafter turns on single-sided headings after this page.
+% By default, they are off at the start of a document,
+% and turned `on' after @end titlepage.
+
+\def\headings #1 {\csname HEADINGS#1\endcsname}
+
+\def\HEADINGSoff{
+\global\evenheadline={\hfil} \global\evenfootline={\hfil}
+\global\oddheadline={\hfil} \global\oddfootline={\hfil}}
+\HEADINGSoff
+% When we turn headings on, set the page number to 1.
+% For double-sided printing, put current file name in lower left corner,
+% chapter name on inside top of right hand pages, document
+% title on inside top of left hand pages, and page numbers on outside top
+% edge of all pages.
+\def\HEADINGSdouble{
+\global\pageno=1
+\global\evenfootline={\hfil}
+\global\oddfootline={\hfil}
+\global\evenheadline={\line{\folio\hfil\thistitle}}
+\global\oddheadline={\line{\thischapter\hfil\folio}}
+\global\let\contentsalignmacro = \chapoddpage
+}
+\let\contentsalignmacro = \chappager
+
+% For single-sided printing, chapter title goes across top left of page,
+% page number on top right.
+\def\HEADINGSsingle{
+\global\pageno=1
+\global\evenfootline={\hfil}
+\global\oddfootline={\hfil}
+\global\evenheadline={\line{\thischapter\hfil\folio}}
+\global\oddheadline={\line{\thischapter\hfil\folio}}
+\global\let\contentsalignmacro = \chappager
+}
+\def\HEADINGSon{\HEADINGSdouble}
+
+\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
+\let\HEADINGSdoubleafter=\HEADINGSafter
+\def\HEADINGSdoublex{%
+\global\evenfootline={\hfil}
+\global\oddfootline={\hfil}
+\global\evenheadline={\line{\folio\hfil\thistitle}}
+\global\oddheadline={\line{\thischapter\hfil\folio}}
+\global\let\contentsalignmacro = \chapoddpage
+}
+
+\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
+\def\HEADINGSsinglex{%
+\global\evenfootline={\hfil}
+\global\oddfootline={\hfil}
+\global\evenheadline={\line{\thischapter\hfil\folio}}
+\global\oddheadline={\line{\thischapter\hfil\folio}}
+\global\let\contentsalignmacro = \chappager
+}
+
+% Subroutines used in generating headings
+% Produces Day Month Year style of output.
+\def\today{\number\day\space
+\ifcase\month\or
+January\or February\or March\or April\or May\or June\or
+July\or August\or September\or October\or November\or December\fi
+\space\number\year}
+
+% Use this if you want the Month Day, Year style of output.
+%\def\today{\ifcase\month\or
+%January\or February\or March\or April\or May\or June\or
+%July\or August\or September\or October\or November\or December\fi
+%\space\number\day, \number\year}
+
+% @settitle line... specifies the title of the document, for headings
+% It generates no output of its own
+
+\def\thistitle{No Title}
+\def\settitle{\parsearg\settitlezzz}
+\def\settitlezzz #1{\gdef\thistitle{#1}}
+
+
+\message{tables,}
+% Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x).
+
+% default indentation of table text
+\newdimen\tableindent \tableindent=.8in
+% default indentation of @itemize and @enumerate text
+\newdimen\itemindent \itemindent=.3in
+% margin between end of table item and start of table text.
+\newdimen\itemmargin \itemmargin=.1in
+
+% used internally for \itemindent minus \itemmargin
+\newdimen\itemmax
+
+% Note @table, @vtable, and @vtable define @item, @itemx, etc., with
+% these defs.
+% They also define \itemindex
+% to index the item name in whatever manner is desired (perhaps none).
+
+\newif\ifitemxneedsnegativevskip
+
+\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
+
+\def\internalBitem{\smallbreak \parsearg\itemzzz}
+\def\internalBitemx{\itemxpar \parsearg\itemzzz}
+
+\def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz}
+\def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz}
+
+\def\internalBkitem{\smallbreak \parsearg\kitemzzz}
+\def\internalBkitemx{\itemxpar \parsearg\kitemzzz}
+
+\def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}%
+ \itemzzz {#1}}
+
+\def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}%
+ \itemzzz {#1}}
+
+\def\itemzzz #1{\begingroup %
+ \advance\hsize by -\rightskip
+ \advance\hsize by -\tableindent
+ \setbox0=\hbox{\itemfont{#1}}%
+ \itemindex{#1}%
+ \nobreak % This prevents a break before @itemx.
+ %
+ % If the item text does not fit in the space we have, put it on a line
+ % by itself, and do not allow a page break either before or after that
+ % line. We do not start a paragraph here because then if the next
+ % command is, e.g., @kindex, the whatsit would get put into the
+ % horizontal list on a line by itself, resulting in extra blank space.
+ \ifdim \wd0>\itemmax
+ %
+ % Make this a paragraph so we get the \parskip glue and wrapping,
+ % but leave it ragged-right.
+ \begingroup
+ \advance\leftskip by-\tableindent
+ \advance\hsize by\tableindent
+ \advance\rightskip by0pt plus1fil
+ \leavevmode\unhbox0\par
+ \endgroup
+ %
+ % We're going to be starting a paragraph, but we don't want the
+ % \parskip glue -- logically it's part of the @item we just started.
+ \nobreak \vskip-\parskip
+ %
+ % Stop a page break at the \parskip glue coming up. Unfortunately
+ % we can't prevent a possible page break at the following
+ % \baselineskip glue.
+ \nobreak
+ \endgroup
+ \itemxneedsnegativevskipfalse
+ \else
+ % The item text fits into the space. Start a paragraph, so that the
+ % following text (if any) will end up on the same line.
+ \noindent
+ % Do this with kerns and \unhbox so that if there is a footnote in
+ % the item text, it can migrate to the main vertical list and
+ % eventually be printed.
+ \nobreak\kern-\tableindent
+ \dimen0 = \itemmax \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
+ \unhbox0
+ \nobreak\kern\dimen0
+ \endgroup
+ \itemxneedsnegativevskiptrue
+ \fi
+}
+
+\def\item{\errmessage{@item while not in a table}}
+\def\itemx{\errmessage{@itemx while not in a table}}
+\def\kitem{\errmessage{@kitem while not in a table}}
+\def\kitemx{\errmessage{@kitemx while not in a table}}
+\def\xitem{\errmessage{@xitem while not in a table}}
+\def\xitemx{\errmessage{@xitemx while not in a table}}
+
+% Contains a kludge to get @end[description] to work.
+\def\description{\tablez{\dontindex}{1}{}{}{}{}}
+
+% @table, @ftable, @vtable.
+\def\table{\begingroup\inENV\obeylines\obeyspaces\tablex}
+{\obeylines\obeyspaces%
+\gdef\tablex #1^^M{%
+\tabley\dontindex#1 \endtabley}}
+
+\def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex}
+{\obeylines\obeyspaces%
+\gdef\ftablex #1^^M{%
+\tabley\fnitemindex#1 \endtabley
+\def\Eftable{\endgraf\afterenvbreak\endgroup}%
+\let\Etable=\relax}}
+
+\def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex}
+{\obeylines\obeyspaces%
+\gdef\vtablex #1^^M{%
+\tabley\vritemindex#1 \endtabley
+\def\Evtable{\endgraf\afterenvbreak\endgroup}%
+\let\Etable=\relax}}
+
+\def\dontindex #1{}
+\def\fnitemindex #1{\doind {fn}{\code{#1}}}%
+\def\vritemindex #1{\doind {vr}{\code{#1}}}%
+
+{\obeyspaces %
+\gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup%
+\tablez{#1}{#2}{#3}{#4}{#5}{#6}}}
+
+\def\tablez #1#2#3#4#5#6{%
+\aboveenvbreak %
+\begingroup %
+\def\Edescription{\Etable}% Necessary kludge.
+\let\itemindex=#1%
+\ifnum 0#3>0 \advance \leftskip by #3\mil \fi %
+\ifnum 0#4>0 \tableindent=#4\mil \fi %
+\ifnum 0#5>0 \advance \rightskip by #5\mil \fi %
+\def\itemfont{#2}%
+\itemmax=\tableindent %
+\advance \itemmax by -\itemmargin %
+\advance \leftskip by \tableindent %
+\exdentamount=\tableindent
+\parindent = 0pt
+\parskip = \smallskipamount
+\ifdim \parskip=0pt \parskip=2pt \fi%
+\def\Etable{\endgraf\afterenvbreak\endgroup}%
+\let\item = \internalBitem %
+\let\itemx = \internalBitemx %
+\let\kitem = \internalBkitem %
+\let\kitemx = \internalBkitemx %
+\let\xitem = \internalBxitem %
+\let\xitemx = \internalBxitemx %
+}
+
+% This is the counter used by @enumerate, which is really @itemize
+
+\newcount \itemno
+
+\def\itemize{\parsearg\itemizezzz}
+
+\def\itemizezzz #1{%
+ \begingroup % ended by the @end itemize
+ \itemizey {#1}{\Eitemize}
+}
+
+\def\itemizey #1#2{%
+\aboveenvbreak %
+\itemmax=\itemindent %
+\advance \itemmax by -\itemmargin %
+\advance \leftskip by \itemindent %
+\exdentamount=\itemindent
+\parindent = 0pt %
+\parskip = \smallskipamount %
+\ifdim \parskip=0pt \parskip=2pt \fi%
+\def#2{\endgraf\afterenvbreak\endgroup}%
+\def\itemcontents{#1}%
+\let\item=\itemizeitem}
+
+% Set sfcode to normal for the chars that usually have another value.
+% These are `.?!:;,'
+\def\frenchspacing{\sfcode46=1000 \sfcode63=1000 \sfcode33=1000
+ \sfcode58=1000 \sfcode59=1000 \sfcode44=1000 }
+
+% \splitoff TOKENS\endmark defines \first to be the first token in
+% TOKENS, and \rest to be the remainder.
+%
+\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
+
+% Allow an optional argument of an uppercase letter, lowercase letter,
+% or number, to specify the first label in the enumerated list. No
+% argument is the same as `1'.
+%
+\def\enumerate{\parsearg\enumeratezzz}
+\def\enumeratezzz #1{\enumeratey #1 \endenumeratey}
+\def\enumeratey #1 #2\endenumeratey{%
+ \begingroup % ended by the @end enumerate
+ %
+ % If we were given no argument, pretend we were given `1'.
+ \def\thearg{#1}%
+ \ifx\thearg\empty \def\thearg{1}\fi
+ %
+ % Detect if the argument is a single token. If so, it might be a
+ % letter. Otherwise, the only valid thing it can be is a number.
+ % (We will always have one token, because of the test we just made.
+ % This is a good thing, since \splitoff doesn't work given nothing at
+ % all -- the first parameter is undelimited.)
+ \expandafter\splitoff\thearg\endmark
+ \ifx\rest\empty
+ % Only one token in the argument. It could still be anything.
+ % A ``lowercase letter'' is one whose \lccode is nonzero.
+ % An ``uppercase letter'' is one whose \lccode is both nonzero, and
+ % not equal to itself.
+ % Otherwise, we assume it's a number.
+ %
+ % We need the \relax at the end of the \ifnum lines to stop TeX from
+ % continuing to look for a <number>.
+ %
+ \ifnum\lccode\expandafter`\thearg=0\relax
+ \numericenumerate % a number (we hope)
+ \else
+ % It's a letter.
+ \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
+ \lowercaseenumerate % lowercase letter
+ \else
+ \uppercaseenumerate % uppercase letter
+ \fi
+ \fi
+ \else
+ % Multiple tokens in the argument. We hope it's a number.
+ \numericenumerate
+ \fi
+}
+
+% An @enumerate whose labels are integers. The starting integer is
+% given in \thearg.
+%
+\def\numericenumerate{%
+ \itemno = \thearg
+ \startenumeration{\the\itemno}%
+}
+
+% The starting (lowercase) letter is in \thearg.
+\def\lowercaseenumerate{%
+ \itemno = \expandafter`\thearg
+ \startenumeration{%
+ % Be sure we're not beyond the end of the alphabet.
+ \ifnum\itemno=0
+ \errmessage{No more lowercase letters in @enumerate; get a bigger
+ alphabet}%
+ \fi
+ \char\lccode\itemno
+ }%
+}
+
+% The starting (uppercase) letter is in \thearg.
+\def\uppercaseenumerate{%
+ \itemno = \expandafter`\thearg
+ \startenumeration{%
+ % Be sure we're not beyond the end of the alphabet.
+ \ifnum\itemno=0
+ \errmessage{No more uppercase letters in @enumerate; get a bigger
+ alphabet}
+ \fi
+ \char\uccode\itemno
+ }%
+}
+
+% Call itemizey, adding a period to the first argument and supplying the
+% common last two arguments. Also subtract one from the initial value in
+% \itemno, since @item increments \itemno.
+%
+\def\startenumeration#1{%
+ \advance\itemno by -1
+ \itemizey{#1.}\Eenumerate\flushcr
+}
+
+% @alphaenumerate and @capsenumerate are abbreviations for giving an arg
+% to @enumerate.
+%
+\def\alphaenumerate{\enumerate{a}}
+\def\capsenumerate{\enumerate{A}}
+\def\Ealphaenumerate{\Eenumerate}
+\def\Ecapsenumerate{\Eenumerate}
+
+% Definition of @item while inside @itemize.
+
+\def\itemizeitem{%
+\advance\itemno by 1
+{\let\par=\endgraf \smallbreak}%
+\ifhmode \errmessage{In hmode at itemizeitem}\fi
+{\parskip=0in \hskip 0pt
+\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}%
+\vadjust{\penalty 1200}}%
+\flushcr}
+
+% @multitable macros
+% Amy Hendrickson, 8/18/94, 3/6/96
+%
+% @multitable ... @end multitable will make as many columns as desired.
+% Contents of each column will wrap at width given in preamble. Width
+% can be specified either with sample text given in a template line,
+% or in percent of \hsize, the current width of text on page.
+
+% Table can continue over pages but will only break between lines.
+
+% To make preamble:
+%
+% Either define widths of columns in terms of percent of \hsize:
+% @multitable @columnfractions .25 .3 .45
+% @item ...
+%
+% Numbers following @columnfractions are the percent of the total
+% current hsize to be used for each column. You may use as many
+% columns as desired.
+
+
+% Or use a template:
+% @multitable {Column 1 template} {Column 2 template} {Column 3 template}
+% @item ...
+% using the widest term desired in each column.
+%
+% For those who want to use more than one line's worth of words in
+% the preamble, break the line within one argument and it
+% will parse correctly, i.e.,
+%
+% @multitable {Column 1 template} {Column 2 template} {Column 3
+% template}
+% Not:
+% @multitable {Column 1 template} {Column 2 template}
+% {Column 3 template}
+
+% Each new table line starts with @item, each subsequent new column
+% starts with @tab. Empty columns may be produced by supplying @tab's
+% with nothing between them for as many times as empty columns are needed,
+% ie, @tab@tab@tab will produce two empty columns.
+
+% @item, @tab, @multitable or @end multitable do not need to be on their
+% own lines, but it will not hurt if they are.
+
+% Sample multitable:
+
+% @multitable {Column 1 template} {Column 2 template} {Column 3 template}
+% @item first col stuff @tab second col stuff @tab third col
+% @item
+% first col stuff
+% @tab
+% second col stuff
+% @tab
+% third col
+% @item first col stuff @tab second col stuff
+% @tab Many paragraphs of text may be used in any column.
+%
+% They will wrap at the width determined by the template.
+% @item@tab@tab This will be in third column.
+% @end multitable
+
+% Default dimensions may be reset by user.
+% @multitableparskip is vertical space between paragraphs in table.
+% @multitableparindent is paragraph indent in table.
+% @multitablecolmargin is horizontal space to be left between columns.
+% @multitablelinespace is space to leave between table items, baseline
+% to baseline.
+% 0pt means it depends on current normal line spacing.
+%
+\newskip\multitableparskip
+\newskip\multitableparindent
+\newdimen\multitablecolspace
+\newskip\multitablelinespace
+\multitableparskip=0pt
+\multitableparindent=6pt
+\multitablecolspace=12pt
+\multitablelinespace=0pt
+
+% Macros used to set up halign preamble:
+%
+\let\endsetuptable\relax
+\def\xendsetuptable{\endsetuptable}
+\let\columnfractions\relax
+\def\xcolumnfractions{\columnfractions}
+\newif\ifsetpercent
+
+% #1 is the part of the @columnfraction before the decimal point, which
+% is presumably either 0 or the empty string (but we don't check, we
+% just throw it away). #2 is the decimal part, which we use as the
+% percent of \hsize for this column.
+\def\pickupwholefraction#1.#2 {%
+ \global\advance\colcount by 1
+ \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}%
+ \setuptable
+}
+
+\newcount\colcount
+\def\setuptable#1{%
+ \def\firstarg{#1}%
+ \ifx\firstarg\xendsetuptable
+ \let\go = \relax
+ \else
+ \ifx\firstarg\xcolumnfractions
+ \global\setpercenttrue
+ \else
+ \ifsetpercent
+ \let\go\pickupwholefraction
+ \else
+ \global\advance\colcount by 1
+ \setbox0=\hbox{#1\unskip }% Add a normal word space as a separator;
+ % typically that is always in the input, anyway.
+ \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
+ \fi
+ \fi
+ \ifx\go\pickupwholefraction
+ % Put the argument back for the \pickupwholefraction call, so
+ % we'll always have a period there to be parsed.
+ \def\go{\pickupwholefraction#1}%
+ \else
+ \let\go = \setuptable
+ \fi%
+ \fi
+ \go
+}
+
+% multitable syntax
+\def\tab{&\hskip1sp\relax} % 2/2/96
+ % tiny skip here makes sure this column space is
+ % maintained, even if it is never used.
+
+% @multitable ... @end multitable definitions:
+%
+\def\multitable{\parsearg\dotable}
+\def\dotable#1{\bgroup
+ \vskip\parskip
+ \let\item\crcr
+ \tolerance=9500
+ \hbadness=9500
+ \setmultitablespacing
+ \parskip=\multitableparskip
+ \parindent=\multitableparindent
+ \overfullrule=0pt
+ \global\colcount=0
+ \def\Emultitable{\global\setpercentfalse\cr\egroup\egroup}%
+ %
+ % To parse everything between @multitable and @item:
+ \setuptable#1 \endsetuptable
+ %
+ % \everycr will reset column counter, \colcount, at the end of
+ % each line. Every column entry will cause \colcount to advance by one.
+ % The table preamble
+ % looks at the current \colcount to find the correct column width.
+ \everycr{\noalign{%
+ %
+ % \filbreak%% keeps underfull box messages off when table breaks over pages.
+ % Maybe so, but it also creates really weird page breaks when the table
+ % breaks over pages. Wouldn't \vfil be better? Wait until the problem
+ % manifests itself, so it can be fixed for real --karl.
+ \global\colcount=0\relax}}%
+ %
+ % This preamble sets up a generic column definition, which will
+ % be used as many times as user calls for columns.
+ % \vtop will set a single line and will also let text wrap and
+ % continue for many paragraphs if desired.
+ \halign\bgroup&\global\advance\colcount by 1\relax
+ \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname
+ %
+ % In order to keep entries from bumping into each other
+ % we will add a \leftskip of \multitablecolspace to all columns after
+ % the first one.
+ %
+ % If a template has been used, we will add \multitablecolspace
+ % to the width of each template entry.
+ %
+ % If the user has set preamble in terms of percent of \hsize we will
+ % use that dimension as the width of the column, and the \leftskip
+ % will keep entries from bumping into each other. Table will start at
+ % left margin and final column will justify at right margin.
+ %
+ % Make sure we don't inherit \rightskip from the outer environment.
+ \rightskip=0pt
+ \ifnum\colcount=1
+ % The first column will be indented with the surrounding text.
+ \advance\hsize by\leftskip
+ \else
+ \ifsetpercent \else
+ % If user has not set preamble in terms of percent of \hsize
+ % we will advance \hsize by \multitablecolspace.
+ \advance\hsize by \multitablecolspace
+ \fi
+ % In either case we will make \leftskip=\multitablecolspace:
+ \leftskip=\multitablecolspace
+ \fi
+ % Ignoring space at the beginning and end avoids an occasional spurious
+ % blank line, when TeX decides to break the line at the space before the
+ % box from the multistrut, so the strut ends up on a line by itself.
+ % For example:
+ % @multitable @columnfractions .11 .89
+ % @item @code{#}
+ % @tab Legal holiday which is valid in major parts of the whole country.
+ % Is automatically provided with highlighting sequences respectively marking
+ % characters.
+ \noindent\ignorespaces##\unskip\multistrut}\cr
+}
+
+\def\setmultitablespacing{% test to see if user has set \multitablelinespace.
+% If so, do nothing. If not, give it an appropriate dimension based on
+% current baselineskip.
+\ifdim\multitablelinespace=0pt
+%% strut to put in table in case some entry doesn't have descenders,
+%% to keep lines equally spaced
+\let\multistrut = \strut
+%% Test to see if parskip is larger than space between lines of
+%% table. If not, do nothing.
+%% If so, set to same dimension as multitablelinespace.
+\else
+\gdef\multistrut{\vrule height\multitablelinespace depth\dp0
+width0pt\relax} \fi
+\ifdim\multitableparskip>\multitablelinespace
+\global\multitableparskip=\multitablelinespace
+\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
+ %% than skip between lines in the table.
+\fi%
+\ifdim\multitableparskip=0pt
+\global\multitableparskip=\multitablelinespace
+\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
+ %% than skip between lines in the table.
+\fi}
+
+
+\message{indexing,}
+% Index generation facilities
+
+% Define \newwrite to be identical to plain tex's \newwrite
+% except not \outer, so it can be used within \newindex.
+{\catcode`\@=11
+\gdef\newwrite{\alloc@7\write\chardef\sixt@@n}}
+
+% \newindex {foo} defines an index named foo.
+% It automatically defines \fooindex such that
+% \fooindex ...rest of line... puts an entry in the index foo.
+% It also defines \fooindfile to be the number of the output channel for
+% the file that accumulates this index. The file's extension is foo.
+% The name of an index should be no more than 2 characters long
+% for the sake of vms.
+%
+\def\newindex#1{%
+ \iflinks
+ \expandafter\newwrite \csname#1indfile\endcsname
+ \openout \csname#1indfile\endcsname \jobname.#1 % Open the file
+ \fi
+ \expandafter\xdef\csname#1index\endcsname{% % Define @#1index
+ \noexpand\doindex{#1}}
+}
+
+% @defindex foo == \newindex{foo}
+
+\def\defindex{\parsearg\newindex}
+
+% Define @defcodeindex, like @defindex except put all entries in @code.
+
+\def\newcodeindex#1{%
+ \iflinks
+ \expandafter\newwrite \csname#1indfile\endcsname
+ \openout \csname#1indfile\endcsname \jobname.#1
+ \fi
+ \expandafter\xdef\csname#1index\endcsname{%
+ \noexpand\docodeindex{#1}}
+}
+
+\def\defcodeindex{\parsearg\newcodeindex}
+
+% @synindex foo bar makes index foo feed into index bar.
+% Do this instead of @defindex foo if you don't want it as a separate index.
+% The \closeout helps reduce unnecessary open files; the limit on the
+% Acorn RISC OS is a mere 16 files.
+\def\synindex#1 #2 {%
+ \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname
+ \expandafter\closeout\csname#1indfile\endcsname
+ \expandafter\let\csname#1indfile\endcsname=\synindexfoo
+ \expandafter\xdef\csname#1index\endcsname{% define \xxxindex
+ \noexpand\doindex{#2}}%
+}
+
+% @syncodeindex foo bar similar, but put all entries made for index foo
+% inside @code.
+\def\syncodeindex#1 #2 {%
+ \expandafter\let\expandafter\synindexfoo\expandafter=\csname#2indfile\endcsname
+ \expandafter\closeout\csname#1indfile\endcsname
+ \expandafter\let\csname#1indfile\endcsname=\synindexfoo
+ \expandafter\xdef\csname#1index\endcsname{% define \xxxindex
+ \noexpand\docodeindex{#2}}%
+}
+
+% Define \doindex, the driver for all \fooindex macros.
+% Argument #1 is generated by the calling \fooindex macro,
+% and it is "foo", the name of the index.
+
+% \doindex just uses \parsearg; it calls \doind for the actual work.
+% This is because \doind is more useful to call from other macros.
+
+% There is also \dosubind {index}{topic}{subtopic}
+% which makes an entry in a two-level index such as the operation index.
+
+\def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer}
+\def\singleindexer #1{\doind{\indexname}{#1}}
+
+% like the previous two, but they put @code around the argument.
+\def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer}
+\def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}}
+
+\def\indexdummies{%
+\def\ { }%
+% Take care of the plain tex accent commands.
+\def\"{\realbackslash "}%
+\def\`{\realbackslash `}%
+\def\'{\realbackslash '}%
+\def\^{\realbackslash ^}%
+\def\~{\realbackslash ~}%
+\def\={\realbackslash =}%
+\def\b{\realbackslash b}%
+\def\c{\realbackslash c}%
+\def\d{\realbackslash d}%
+\def\u{\realbackslash u}%
+\def\v{\realbackslash v}%
+\def\H{\realbackslash H}%
+% Take care of the plain tex special European modified letters.
+\def\oe{\realbackslash oe}%
+\def\ae{\realbackslash ae}%
+\def\aa{\realbackslash aa}%
+\def\OE{\realbackslash OE}%
+\def\AE{\realbackslash AE}%
+\def\AA{\realbackslash AA}%
+\def\o{\realbackslash o}%
+\def\O{\realbackslash O}%
+\def\l{\realbackslash l}%
+\def\L{\realbackslash L}%
+\def\ss{\realbackslash ss}%
+% Take care of texinfo commands likely to appear in an index entry.
+% (Must be a way to avoid doing expansion at all, and thus not have to
+% laboriously list every single command here.)
+\def\@{@}% will be @@ when we switch to @ as escape char.
+% Need these in case \tex is in effect and \{ is a \delimiter again.
+% But can't use \lbracecmd and \rbracecmd because texindex assumes
+% braces and backslashes are used only as delimiters.
+\let\{ = \mylbrace
+\let\} = \myrbrace
+\def\_{{\realbackslash _}}%
+\def\w{\realbackslash w }%
+\def\bf{\realbackslash bf }%
+%\def\rm{\realbackslash rm }%
+\def\sl{\realbackslash sl }%
+\def\sf{\realbackslash sf}%
+\def\tt{\realbackslash tt}%
+\def\gtr{\realbackslash gtr}%
+\def\less{\realbackslash less}%
+\def\hat{\realbackslash hat}%
+\def\TeX{\realbackslash TeX}%
+\def\dots{\realbackslash dots }%
+\def\result{\realbackslash result}%
+\def\equiv{\realbackslash equiv}%
+\def\expansion{\realbackslash expansion}%
+\def\print{\realbackslash print}%
+\def\error{\realbackslash error}%
+\def\point{\realbackslash point}%
+\def\copyright{\realbackslash copyright}%
+\def\tclose##1{\realbackslash tclose {##1}}%
+\def\code##1{\realbackslash code {##1}}%
+\def\uref##1{\realbackslash uref {##1}}%
+\def\url##1{\realbackslash url {##1}}%
+\def\env##1{\realbackslash env {##1}}%
+\def\command##1{\realbackslash command {##1}}%
+\def\option##1{\realbackslash option {##1}}%
+\def\dotless##1{\realbackslash dotless {##1}}%
+\def\samp##1{\realbackslash samp {##1}}%
+\def\,##1{\realbackslash ,{##1}}%
+\def\t##1{\realbackslash t {##1}}%
+\def\r##1{\realbackslash r {##1}}%
+\def\i##1{\realbackslash i {##1}}%
+\def\b##1{\realbackslash b {##1}}%
+\def\sc##1{\realbackslash sc {##1}}%
+\def\cite##1{\realbackslash cite {##1}}%
+\def\key##1{\realbackslash key {##1}}%
+\def\file##1{\realbackslash file {##1}}%
+\def\var##1{\realbackslash var {##1}}%
+\def\kbd##1{\realbackslash kbd {##1}}%
+\def\dfn##1{\realbackslash dfn {##1}}%
+\def\emph##1{\realbackslash emph {##1}}%
+\def\acronym##1{\realbackslash acronym {##1}}%
+%
+% Handle some cases of @value -- where the variable name does not
+% contain - or _, and the value does not contain any
+% (non-fully-expandable) commands.
+\let\value = \expandablevalue
+%
+\unsepspaces
+}
+
+% If an index command is used in an @example environment, any spaces
+% therein should become regular spaces in the raw index file, not the
+% expansion of \tie (\\leavevmode \penalty \@M \ ).
+{\obeyspaces
+ \gdef\unsepspaces{\obeyspaces\let =\space}}
+
+% \indexnofonts no-ops all font-change commands.
+% This is used when outputting the strings to sort the index by.
+\def\indexdummyfont#1{#1}
+\def\indexdummytex{TeX}
+\def\indexdummydots{...}
+
+\def\indexnofonts{%
+% Just ignore accents.
+\let\,=\indexdummyfont
+\let\"=\indexdummyfont
+\let\`=\indexdummyfont
+\let\'=\indexdummyfont
+\let\^=\indexdummyfont
+\let\~=\indexdummyfont
+\let\==\indexdummyfont
+\let\b=\indexdummyfont
+\let\c=\indexdummyfont
+\let\d=\indexdummyfont
+\let\u=\indexdummyfont
+\let\v=\indexdummyfont
+\let\H=\indexdummyfont
+\let\dotless=\indexdummyfont
+% Take care of the plain tex special European modified letters.
+\def\oe{oe}%
+\def\ae{ae}%
+\def\aa{aa}%
+\def\OE{OE}%
+\def\AE{AE}%
+\def\AA{AA}%
+\def\o{o}%
+\def\O{O}%
+\def\l{l}%
+\def\L{L}%
+\def\ss{ss}%
+\let\w=\indexdummyfont
+\let\t=\indexdummyfont
+\let\r=\indexdummyfont
+\let\i=\indexdummyfont
+\let\b=\indexdummyfont
+\let\emph=\indexdummyfont
+\let\strong=\indexdummyfont
+\let\cite=\indexdummyfont
+\let\sc=\indexdummyfont
+%Don't no-op \tt, since it isn't a user-level command
+% and is used in the definitions of the active chars like <, >, |...
+%\let\tt=\indexdummyfont
+\let\tclose=\indexdummyfont
+\let\code=\indexdummyfont
+\let\url=\indexdummyfont
+\let\uref=\indexdummyfont
+\let\env=\indexdummyfont
+\let\command=\indexdummyfont
+\let\option=\indexdummyfont
+\let\file=\indexdummyfont
+\let\samp=\indexdummyfont
+\let\kbd=\indexdummyfont
+\let\key=\indexdummyfont
+\let\var=\indexdummyfont
+\let\TeX=\indexdummytex
+\let\dots=\indexdummydots
+\def\@{@}%
+}
+
+% To define \realbackslash, we must make \ not be an escape.
+% We must first make another character (@) an escape
+% so we do not become unable to do a definition.
+
+{\catcode`\@=0 \catcode`\\=\other
+ @gdef@realbackslash{\}}
+
+\let\indexbackslash=0 %overridden during \printindex.
+\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
+
+% For \ifx comparisons.
+\def\emptymacro{\empty}
+
+% Most index entries go through here, but \dosubind is the general case.
+%
+\def\doind#1#2{\dosubind{#1}{#2}\empty}
+
+% Workhorse for all \fooindexes.
+% #1 is name of index, #2 is stuff to put there, #3 is subentry --
+% \empty if called from \doind, as we usually are. The main exception
+% is with defuns, which call us directly.
+%
+\def\dosubind#1#2#3{%
+ % Put the index entry in the margin if desired.
+ \ifx\SETmarginindex\relax\else
+ \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}%
+ \fi
+ {%
+ \count255=\lastpenalty
+ {%
+ \indexdummies % Must do this here, since \bf, etc expand at this stage
+ \escapechar=`\\
+ {%
+ \let\folio = 0% We will expand all macros now EXCEPT \folio.
+ \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now
+ % so it will be output as is; and it will print as backslash.
+ %
+ \def\thirdarg{#3}%
+ %
+ % If third arg is present, precede it with space in sort key.
+ \ifx\thirdarg\emptymacro
+ \let\subentry = \empty
+ \else
+ \def\subentry{ #3}%
+ \fi
+ %
+ % First process the index-string with all font commands turned off
+ % to get the string to sort by.
+ {\indexnofonts \xdef\indexsorttmp{#2\subentry}}%
+ %
+ % Now produce the complete index entry, with both the sort key and the
+ % original text, including any font commands.
+ \toks0 = {#2}%
+ \edef\temp{%
+ \write\csname#1indfile\endcsname{%
+ \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}%
+ }%
+ %
+ % If third (subentry) arg is present, add it to the index string.
+ \ifx\thirdarg\emptymacro \else
+ \toks0 = {#3}%
+ \edef\temp{\temp{\the\toks0}}%
+ \fi
+ %
+ % If a skip is the last thing on the list now, preserve it
+ % by backing up by \lastskip, doing the \write, then inserting
+ % the skip again. Otherwise, the whatsit generated by the
+ % \write will make \lastskip zero. The result is that sequences
+ % like this:
+ % @end defun
+ % @tindex whatever
+ % @defun ...
+ % will have extra space inserted, because the \medbreak in the
+ % start of the @defun won't see the skip inserted by the @end of
+ % the previous defun.
+ %
+ % But don't do any of this if we're not in vertical mode. We
+ % don't want to do a \vskip and prematurely end a paragraph.
+ %
+ % Avoid page breaks due to these extra skips, too.
+ %
+ \iflinks
+ \ifvmode
+ \skip0 = \lastskip
+ \ifdim\lastskip = 0pt \else \nobreak\vskip-\lastskip \fi
+ \fi
+ %
+ \temp % do the write
+ %
+ %
+ \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi
+ \fi
+ }%
+ }%
+ \penalty\count255
+ }%
+}
+
+% The index entry written in the file actually looks like
+% \entry {sortstring}{page}{topic}
+% or
+% \entry {sortstring}{page}{topic}{subtopic}
+% The texindex program reads in these files and writes files
+% containing these kinds of lines:
+% \initial {c}
+% before the first topic whose initial is c
+% \entry {topic}{pagelist}
+% for a topic that is used without subtopics
+% \primary {topic}
+% for the beginning of a topic that is used with subtopics
+% \secondary {subtopic}{pagelist}
+% for each subtopic.
+
+% Define the user-accessible indexing commands
+% @findex, @vindex, @kindex, @cindex.
+
+\def\findex {\fnindex}
+\def\kindex {\kyindex}
+\def\cindex {\cpindex}
+\def\vindex {\vrindex}
+\def\tindex {\tpindex}
+\def\pindex {\pgindex}
+
+\def\cindexsub {\begingroup\obeylines\cindexsub}
+{\obeylines %
+\gdef\cindexsub "#1" #2^^M{\endgroup %
+\dosubind{cp}{#2}{#1}}}
+
+% Define the macros used in formatting output of the sorted index material.
+
+% @printindex causes a particular index (the ??s file) to get printed.
+% It does not print any chapter heading (usually an @unnumbered).
+%
+\def\printindex{\parsearg\doprintindex}
+\def\doprintindex#1{\begingroup
+ \dobreak \chapheadingskip{10000}%
+ %
+ \indexfonts \rm
+ \tolerance = 9500
+ \indexbreaks
+ %
+ % See if the index file exists and is nonempty.
+ % Change catcode of @ here so that if the index file contains
+ % \initial {@}
+ % as its first line, TeX doesn't complain about mismatched braces
+ % (because it thinks @} is a control sequence).
+ \catcode`\@ = 11
+ \openin 1 \jobname.#1s
+ \ifeof 1
+ % \enddoublecolumns gets confused if there is no text in the index,
+ % and it loses the chapter title and the aux file entries for the
+ % index. The easiest way to prevent this problem is to make sure
+ % there is some text.
+ (Index is nonexistent)
+ \else
+ %
+ % If the index file exists but is empty, then \openin leaves \ifeof
+ % false. We have to make TeX try to read something from the file, so
+ % it can discover if there is anything in it.
+ \read 1 to \temp
+ \ifeof 1
+ (Index is empty)
+ \else
+ % Index files are almost Texinfo source, but we use \ as the escape
+ % character. It would be better to use @, but that's too big a change
+ % to make right now.
+ \def\indexbackslash{\rawbackslashxx}%
+ \catcode`\\ = 0
+ \escapechar = `\\
+ \begindoublecolumns
+ \input \jobname.#1s
+ \enddoublecolumns
+ \fi
+ \fi
+ \closein 1
+\endgroup}
+
+% These macros are used by the sorted index file itself.
+% Change them to control the appearance of the index.
+
+\def\initial#1{{%
+ % Some minor font changes for the special characters.
+ \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
+ %
+ % Remove any glue we may have, we'll be inserting our own.
+ \removelastskip
+ %
+ % We like breaks before the index initials, so insert a bonus.
+ \penalty -300
+ %
+ % Typeset the initial. Making this add up to a whole number of
+ % baselineskips increases the chance of the dots lining up from column
+ % to column. It still won't often be perfect, because of the stretch
+ % we need before each entry, but it's better.
+ %
+ % No shrink because it confuses \balancecolumns.
+ \vskip 1.67\baselineskip plus .5\baselineskip
+ \leftline{\secbf #1}%
+ \vskip .33\baselineskip plus .1\baselineskip
+ %
+ % Do our best not to break after the initial.
+ \nobreak
+}}
+
+% This typesets a paragraph consisting of #1, dot leaders, and then #2
+% flush to the right margin. It is used for index and table of contents
+% entries. The paragraph is indented by \leftskip.
+%
+\def\entry#1#2{\begingroup
+ %
+ % Start a new paragraph if necessary, so our assignments below can't
+ % affect previous text.
+ \par
+ %
+ % Do not fill out the last line with white space.
+ \parfillskip = 0in
+ %
+ % No extra space above this paragraph.
+ \parskip = 0in
+ %
+ % Do not prefer a separate line ending with a hyphen to fewer lines.
+ \finalhyphendemerits = 0
+ %
+ % \hangindent is only relevant when the entry text and page number
+ % don't both fit on one line. In that case, bob suggests starting the
+ % dots pretty far over on the line. Unfortunately, a large
+ % indentation looks wrong when the entry text itself is broken across
+ % lines. So we use a small indentation and put up with long leaders.
+ %
+ % \hangafter is reset to 1 (which is the value we want) at the start
+ % of each paragraph, so we need not do anything with that.
+ \hangindent = 2em
+ %
+ % When the entry text needs to be broken, just fill out the first line
+ % with blank space.
+ \rightskip = 0pt plus1fil
+ %
+ % A bit of stretch before each entry for the benefit of balancing columns.
+ \vskip 0pt plus1pt
+ %
+ % Start a ``paragraph'' for the index entry so the line breaking
+ % parameters we've set above will have an effect.
+ \noindent
+ %
+ % Insert the text of the index entry. TeX will do line-breaking on it.
+ #1%
+ % The following is kludged to not output a line of dots in the index if
+ % there are no page numbers. The next person who breaks this will be
+ % cursed by a Unix daemon.
+ \def\tempa{{\rm }}%
+ \def\tempb{#2}%
+ \edef\tempc{\tempa}%
+ \edef\tempd{\tempb}%
+ \ifx\tempc\tempd\ \else%
+ %
+ % If we must, put the page number on a line of its own, and fill out
+ % this line with blank space. (The \hfil is overwhelmed with the
+ % fill leaders glue in \indexdotfill if the page number does fit.)
+ \hfil\penalty50
+ \null\nobreak\indexdotfill % Have leaders before the page number.
+ %
+ % The `\ ' here is removed by the implicit \unskip that TeX does as
+ % part of (the primitive) \par. Without it, a spurious underfull
+ % \hbox ensues.
+ \ #2% The page number ends the paragraph.
+ \fi%
+ \par
+\endgroup}
+
+% Like \dotfill except takes at least 1 em.
+\def\indexdotfill{\cleaders
+ \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill}
+
+\def\primary #1{\line{#1\hfil}}
+
+\newskip\secondaryindent \secondaryindent=0.5cm
+
+\def\secondary #1#2{
+{\parfillskip=0in \parskip=0in
+\hangindent =1in \hangafter=1
+\noindent\hskip\secondaryindent\hbox{#1}\indexdotfill #2\par
+}}
+
+% Define two-column mode, which we use to typeset indexes.
+% Adapted from the TeXbook, page 416, which is to say,
+% the manmac.tex format used to print the TeXbook itself.
+\catcode`\@=11
+
+\newbox\partialpage
+\newdimen\doublecolumnhsize
+
+\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
+ % Grab any single-column material above us.
+ \output = {\global\setbox\partialpage = \vbox{%
+ %
+ % Here is a possibility not foreseen in manmac: if we accumulate a
+ % whole lot of material, we might end up calling this \output
+ % routine twice in a row (see the doublecol-lose test, which is
+ % essentially a couple of indexes with @setchapternewpage off). In
+ % that case, we must prevent the second \partialpage from
+ % simply overwriting the first, causing us to lose the page.
+ % This will preserve it until a real output routine can ship it
+ % out. Generally, \partialpage will be empty when this runs and
+ % this will be a no-op.
+ \unvbox\partialpage
+ %
+ % Unvbox the main output page.
+ \unvbox255
+ \kern-\topskip \kern\baselineskip
+ }}%
+ \eject % run that output routine to set \partialpage
+ %
+ % Use the double-column output routine for subsequent pages.
+ \output = {\doublecolumnout}%
+ %
+ % Change the page size parameters. We could do this once outside this
+ % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
+ % format, but then we repeat the same computation. Repeating a couple
+ % of assignments once per index is clearly meaningless for the
+ % execution time, so we may as well do it in one place.
+ %
+ % First we halve the line length, less a little for the gutter between
+ % the columns. We compute the gutter based on the line length, so it
+ % changes automatically with the paper format. The magic constant
+ % below is chosen so that the gutter has the same value (well, +-<1pt)
+ % as it did when we hard-coded it.
+ %
+ % We put the result in a separate register, \doublecolumhsize, so we
+ % can restore it in \pagesofar, after \hsize itself has (potentially)
+ % been clobbered.
+ %
+ \doublecolumnhsize = \hsize
+ \advance\doublecolumnhsize by -.04154\hsize
+ \divide\doublecolumnhsize by 2
+ \hsize = \doublecolumnhsize
+ %
+ % Double the \vsize as well. (We don't need a separate register here,
+ % since nobody clobbers \vsize.)
+ \advance\vsize by -\ht\partialpage
+ \vsize = 2\vsize
+}
+
+% The double-column output routine for all double-column pages except
+% the last.
+%
+\def\doublecolumnout{%
+ \splittopskip=\topskip \splitmaxdepth=\maxdepth
+ % Get the available space for the double columns -- the normal
+ % (undoubled) page height minus any material left over from the
+ % previous page.
+ \dimen@ = \vsize
+ \divide\dimen@ by 2
+ %
+ % box0 will be the left-hand column, box2 the right.
+ \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
+ \onepageout\pagesofar
+ \unvbox255
+ \penalty\outputpenalty
+}
+\def\pagesofar{%
+ % Re-output the contents of the output page -- any previous material,
+ % followed by the two boxes we just split, in box0 and box2.
+ \advance\vsize by \ht\partialpage
+ \unvbox\partialpage
+ %
+ \hsize = \doublecolumnhsize
+ \wd0=\hsize \wd2=\hsize
+ \hbox to\pagewidth{\box0\hfil\box2}%
+}
+\def\enddoublecolumns{%
+ \output = {%
+ % Split the last of the double-column material. Leave it on the
+ % current page, no automatic page break.
+ \balancecolumns
+ %
+ % If we end up splitting too much material for the current page,
+ % though, there will be another page break right after this \output
+ % invocation ends. Having called \balancecolumns once, we do not
+ % want to call it again. Therefore, reset \output to its normal
+ % definition right away. (We hope \balancecolumns will never be
+ % called on to balance too much material, but if it is, this makes
+ % the output somewhat more palatable.)
+ \global\output = {\onepageout{\pagecontents\PAGE}}%
+ }%
+ \eject
+ \endgroup % started in \begindoublecolumns
+ %
+ % \pagegoal was set to the doubled \vsize above, since we restarted
+ % the current page. We're now back to normal single-column
+ % typesetting, so reset \pagegoal to the normal \vsize (after the
+ % \endgroup where \vsize got restored).
+ \pagegoal = \vsize
+}
+\def\balancecolumns{%
+ % Called at the end of the double column material.
+ \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
+ \dimen@ = \ht0
+ \advance\dimen@ by \topskip
+ \advance\dimen@ by-\baselineskip
+ \divide\dimen@ by 2 % target to split to
+ %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}%
+ \splittopskip = \topskip
+ % Loop until we get a decent breakpoint.
+ {%
+ \vbadness = 10000
+ \loop
+ \global\setbox3 = \copy0
+ \global\setbox1 = \vsplit3 to \dimen@
+ \ifdim\ht3>\dimen@
+ \global\advance\dimen@ by 1pt
+ \repeat
+ }%
+ %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}%
+ \setbox0=\vbox to\dimen@{\unvbox1}%
+ \setbox2=\vbox to\dimen@{\unvbox3}%
+ %
+ \pagesofar
+}
+\catcode`\@ = \other
+
+
+\message{sectioning,}
+% Define chapters, sections, etc.
+
+\newcount\chapno
+\newcount\secno \secno=0
+\newcount\subsecno \subsecno=0
+\newcount\subsubsecno \subsubsecno=0
+
+% This counter is funny since it counts through charcodes of letters A, B, ...
+\newcount\appendixno \appendixno = `\@
+\def\appendixletter{\char\the\appendixno}
+
+% Each @chapter defines this as the name of the chapter.
+% page headings and footings can use it. @section does likewise.
+\def\thischapter{}
+\def\thissection{}
+
+\newcount\absseclevel % used to calculate proper heading level
+\newcount\secbase\secbase=0 % @raise/lowersections modify this count
+
+% @raisesections: treat @section as chapter, @subsection as section, etc.
+\def\raisesections{\global\advance\secbase by -1}
+\let\up=\raisesections % original BFox name
+
+% @lowersections: treat @chapter as section, @section as subsection, etc.
+\def\lowersections{\global\advance\secbase by 1}
+\let\down=\lowersections % original BFox name
+
+% Choose a numbered-heading macro
+% #1 is heading level if unmodified by @raisesections or @lowersections
+% #2 is text for heading
+\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
+\ifcase\absseclevel
+ \chapterzzz{#2}
+\or
+ \seczzz{#2}
+\or
+ \numberedsubseczzz{#2}
+\or
+ \numberedsubsubseczzz{#2}
+\else
+ \ifnum \absseclevel<0
+ \chapterzzz{#2}
+ \else
+ \numberedsubsubseczzz{#2}
+ \fi
+\fi
+}
+
+% like \numhead, but chooses appendix heading levels
+\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
+\ifcase\absseclevel
+ \appendixzzz{#2}
+\or
+ \appendixsectionzzz{#2}
+\or
+ \appendixsubseczzz{#2}
+\or
+ \appendixsubsubseczzz{#2}
+\else
+ \ifnum \absseclevel<0
+ \appendixzzz{#2}
+ \else
+ \appendixsubsubseczzz{#2}
+ \fi
+\fi
+}
+
+% like \numhead, but chooses numberless heading levels
+\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
+\ifcase\absseclevel
+ \unnumberedzzz{#2}
+\or
+ \unnumberedseczzz{#2}
+\or
+ \unnumberedsubseczzz{#2}
+\or
+ \unnumberedsubsubseczzz{#2}
+\else
+ \ifnum \absseclevel<0
+ \unnumberedzzz{#2}
+ \else
+ \unnumberedsubsubseczzz{#2}
+ \fi
+\fi
+}
+
+% @chapter, @appendix, @unnumbered.
+\def\thischaptername{No Chapter Title}
+\outer\def\chapter{\parsearg\chapteryyy}
+\def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz
+\def\chapterzzz #1{%
+\secno=0 \subsecno=0 \subsubsecno=0
+\global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}%
+\chapmacro {#1}{\the\chapno}%
+\gdef\thissection{#1}%
+\gdef\thischaptername{#1}%
+% We don't substitute the actual chapter name into \thischapter
+% because we don't want its macros evaluated now.
+\xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}%
+ {\the\chapno}}}%
+\temp
+\donoderef
+\global\let\section = \numberedsec
+\global\let\subsection = \numberedsubsec
+\global\let\subsubsection = \numberedsubsubsec
+}
+
+\outer\def\appendix{\parsearg\appendixyyy}
+\def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz
+\def\appendixzzz #1{%
+\secno=0 \subsecno=0 \subsubsecno=0
+\global\advance \appendixno by 1
+\message{\putwordAppendix\space \appendixletter}%
+\chapmacro {#1}{\putwordAppendix{} \appendixletter}%
+\gdef\thissection{#1}%
+\gdef\thischaptername{#1}%
+\xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash chapentry{\the\toks0}%
+ {\putwordAppendix{} \appendixletter}}}%
+\temp
+\appendixnoderef
+\global\let\section = \appendixsec
+\global\let\subsection = \appendixsubsec
+\global\let\subsubsection = \appendixsubsubsec
+}
+
+% @centerchap is like @unnumbered, but the heading is centered.
+\outer\def\centerchap{\parsearg\centerchapyyy}
+\def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}}
+
+% @top is like @unnumbered.
+\outer\def\top{\parsearg\unnumberedyyy}
+
+\outer\def\unnumbered{\parsearg\unnumberedyyy}
+\def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
+\def\unnumberedzzz #1{%
+\secno=0 \subsecno=0 \subsubsecno=0
+%
+% This used to be simply \message{#1}, but TeX fully expands the
+% argument to \message. Therefore, if #1 contained @-commands, TeX
+% expanded them. For example, in `@unnumbered The @cite{Book}', TeX
+% expanded @cite (which turns out to cause errors because \cite is meant
+% to be executed, not expanded).
+%
+% Anyway, we don't want the fully-expanded definition of @cite to appear
+% as a result of the \message, we just want `@cite' itself. We use
+% \the<toks register> to achieve this: TeX expands \the<toks> only once,
+% simply yielding the contents of <toks register>. (We also do this for
+% the toc entries.)
+\toks0 = {#1}\message{(\the\toks0)}%
+%
+\unnumbchapmacro {#1}%
+\gdef\thischapter{#1}\gdef\thissection{#1}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash unnumbchapentry{\the\toks0}}}%
+\temp
+\unnumbnoderef
+\global\let\section = \unnumberedsec
+\global\let\subsection = \unnumberedsubsec
+\global\let\subsubsection = \unnumberedsubsubsec
+}
+
+% Sections.
+\outer\def\numberedsec{\parsearg\secyyy}
+\def\secyyy #1{\numhead1{#1}} % normally calls seczzz
+\def\seczzz #1{%
+\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
+\gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}%
+ {\the\chapno}{\the\secno}}}%
+\temp
+\donoderef
+\nobreak
+}
+
+\outer\def\appendixsection{\parsearg\appendixsecyyy}
+\outer\def\appendixsec{\parsearg\appendixsecyyy}
+\def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz
+\def\appendixsectionzzz #1{%
+\subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
+\gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash secentry{\the\toks0}%
+ {\appendixletter}{\the\secno}}}%
+\temp
+\appendixnoderef
+\nobreak
+}
+
+\outer\def\unnumberedsec{\parsearg\unnumberedsecyyy}
+\def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz
+\def\unnumberedseczzz #1{%
+\plainsecheading {#1}\gdef\thissection{#1}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsecentry{\the\toks0}}}%
+\temp
+\unnumbnoderef
+\nobreak
+}
+
+% Subsections.
+\outer\def\numberedsubsec{\parsearg\numberedsubsecyyy}
+\def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz
+\def\numberedsubseczzz #1{%
+\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
+\subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}%
+ {\the\chapno}{\the\secno}{\the\subsecno}}}%
+\temp
+\donoderef
+\nobreak
+}
+
+\outer\def\appendixsubsec{\parsearg\appendixsubsecyyy}
+\def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz
+\def\appendixsubseczzz #1{%
+\gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
+\subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash subsecentry{\the\toks0}%
+ {\appendixletter}{\the\secno}{\the\subsecno}}}%
+\temp
+\appendixnoderef
+\nobreak
+}
+
+\outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy}
+\def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
+\def\unnumberedsubseczzz #1{%
+\plainsubsecheading {#1}\gdef\thissection{#1}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsecentry%
+ {\the\toks0}}}%
+\temp
+\unnumbnoderef
+\nobreak
+}
+
+% Subsubsections.
+\outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy}
+\def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz
+\def\numberedsubsubseczzz #1{%
+\gdef\thissection{#1}\global\advance \subsubsecno by 1 %
+\subsubsecheading {#1}
+ {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}%
+ {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}%
+\temp
+\donoderef
+\nobreak
+}
+
+\outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy}
+\def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz
+\def\appendixsubsubseczzz #1{%
+\gdef\thissection{#1}\global\advance \subsubsecno by 1 %
+\subsubsecheading {#1}
+ {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash subsubsecentry{\the\toks0}%
+ {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}}%
+\temp
+\appendixnoderef
+\nobreak
+}
+
+\outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy}
+\def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
+\def\unnumberedsubsubseczzz #1{%
+\plainsubsubsecheading {#1}\gdef\thissection{#1}%
+\toks0 = {#1}%
+\edef\temp{\noexpand\writetocentry{\realbackslash unnumbsubsubsecentry%
+ {\the\toks0}}}%
+\temp
+\unnumbnoderef
+\nobreak
+}
+
+% These are variants which are not "outer", so they can appear in @ifinfo.
+% Actually, they should now be obsolete; ordinary section commands should work.
+\def\infotop{\parsearg\unnumberedzzz}
+\def\infounnumbered{\parsearg\unnumberedzzz}
+\def\infounnumberedsec{\parsearg\unnumberedseczzz}
+\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz}
+\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz}
+
+\def\infoappendix{\parsearg\appendixzzz}
+\def\infoappendixsec{\parsearg\appendixseczzz}
+\def\infoappendixsubsec{\parsearg\appendixsubseczzz}
+\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz}
+
+\def\infochapter{\parsearg\chapterzzz}
+\def\infosection{\parsearg\sectionzzz}
+\def\infosubsection{\parsearg\subsectionzzz}
+\def\infosubsubsection{\parsearg\subsubsectionzzz}
+
+% These macros control what the section commands do, according
+% to what kind of chapter we are in (ordinary, appendix, or unnumbered).
+% Define them by default for a numbered chapter.
+\global\let\section = \numberedsec
+\global\let\subsection = \numberedsubsec
+\global\let\subsubsection = \numberedsubsubsec
+
+% Define @majorheading, @heading and @subheading
+
+% NOTE on use of \vbox for chapter headings, section headings, and such:
+% 1) We use \vbox rather than the earlier \line to permit
+% overlong headings to fold.
+% 2) \hyphenpenalty is set to 10000 because hyphenation in a
+% heading is obnoxious; this forbids it.
+% 3) Likewise, headings look best if no \parindent is used, and
+% if justification is not attempted. Hence \raggedright.
+
+
+\def\majorheading{\parsearg\majorheadingzzz}
+\def\majorheadingzzz #1{%
+{\advance\chapheadingskip by 10pt \chapbreak }%
+{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
+ \parindent=0pt\raggedright
+ \rm #1\hfill}}\bigskip \par\penalty 200}
+
+\def\chapheading{\parsearg\chapheadingzzz}
+\def\chapheadingzzz #1{\chapbreak %
+{\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
+ \parindent=0pt\raggedright
+ \rm #1\hfill}}\bigskip \par\penalty 200}
+
+% @heading, @subheading, @subsubheading.
+\def\heading{\parsearg\plainsecheading}
+\def\subheading{\parsearg\plainsubsecheading}
+\def\subsubheading{\parsearg\plainsubsubsecheading}
+
+% These macros generate a chapter, section, etc. heading only
+% (including whitespace, linebreaking, etc. around it),
+% given all the information in convenient, parsed form.
+
+%%% Args are the skip and penalty (usually negative)
+\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
+
+\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
+
+%%% Define plain chapter starts, and page on/off switching for it
+% Parameter controlling skip before chapter headings (if needed)
+
+\newskip\chapheadingskip
+
+\def\chapbreak{\dobreak \chapheadingskip {-4000}}
+\def\chappager{\par\vfill\supereject}
+\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi}
+
+\def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname}
+
+\def\CHAPPAGoff{%
+\global\let\contentsalignmacro = \chappager
+\global\let\pchapsepmacro=\chapbreak
+\global\let\pagealignmacro=\chappager}
+
+\def\CHAPPAGon{%
+\global\let\contentsalignmacro = \chappager
+\global\let\pchapsepmacro=\chappager
+\global\let\pagealignmacro=\chappager
+\global\def\HEADINGSon{\HEADINGSsingle}}
+
+\def\CHAPPAGodd{
+\global\let\contentsalignmacro = \chapoddpage
+\global\let\pchapsepmacro=\chapoddpage
+\global\let\pagealignmacro=\chapoddpage
+\global\def\HEADINGSon{\HEADINGSdouble}}
+
+\CHAPPAGon
+
+\def\CHAPFplain{
+\global\let\chapmacro=\chfplain
+\global\let\unnumbchapmacro=\unnchfplain
+\global\let\centerchapmacro=\centerchfplain}
+
+% Plain chapter opening.
+% #1 is the text, #2 the chapter number or empty if unnumbered.
+\def\chfplain#1#2{%
+ \pchapsepmacro
+ {%
+ \chapfonts \rm
+ \def\chapnum{#2}%
+ \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}%
+ \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
+ \hangindent = \wd0 \centerparametersmaybe
+ \unhbox0 #1\par}%
+ }%
+ \nobreak\bigskip % no page break after a chapter title
+ \nobreak
+}
+
+% Plain opening for unnumbered.
+\def\unnchfplain#1{\chfplain{#1}{}}
+
+% @centerchap -- centered and unnumbered.
+\let\centerparametersmaybe = \relax
+\def\centerchfplain#1{{%
+ \def\centerparametersmaybe{%
+ \advance\rightskip by 3\rightskip
+ \leftskip = \rightskip
+ \parfillskip = 0pt
+ }%
+ \chfplain{#1}{}%
+}}
+
+\CHAPFplain % The default
+
+\def\unnchfopen #1{%
+\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
+ \parindent=0pt\raggedright
+ \rm #1\hfill}}\bigskip \par\nobreak
+}
+
+\def\chfopen #1#2{\chapoddpage {\chapfonts
+\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
+\par\penalty 5000 %
+}
+
+\def\centerchfopen #1{%
+\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
+ \parindent=0pt
+ \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
+}
+
+\def\CHAPFopen{
+\global\let\chapmacro=\chfopen
+\global\let\unnumbchapmacro=\unnchfopen
+\global\let\centerchapmacro=\centerchfopen}
+
+
+% Section titles.
+\newskip\secheadingskip
+\def\secheadingbreak{\dobreak \secheadingskip {-1000}}
+\def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}}
+\def\plainsecheading#1{\sectionheading{sec}{}{#1}}
+
+% Subsection titles.
+\newskip \subsecheadingskip
+\def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}}
+\def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}}
+\def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}}
+
+% Subsubsection titles.
+\let\subsubsecheadingskip = \subsecheadingskip
+\let\subsubsecheadingbreak = \subsecheadingbreak
+\def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}}
+\def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}}
+
+
+% Print any size section title.
+%
+% #1 is the section type (sec/subsec/subsubsec), #2 is the section
+% number (maybe empty), #3 the text.
+\def\sectionheading#1#2#3{%
+ {%
+ \expandafter\advance\csname #1headingskip\endcsname by \parskip
+ \csname #1headingbreak\endcsname
+ }%
+ {%
+ % Switch to the right set of fonts.
+ \csname #1fonts\endcsname \rm
+ %
+ % Only insert the separating space if we have a section number.
+ \def\secnum{#2}%
+ \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}%
+ %
+ \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
+ \hangindent = \wd0 % zero if no section number
+ \unhbox0 #3}%
+ }%
+ \ifdim\parskip<10pt \nobreak\kern10pt\nobreak\kern-\parskip\fi \nobreak
+}
+
+
+\message{toc,}
+\newwrite\tocfile
+
+% Write an entry to the toc file, opening it if necessary.
+% Called from @chapter, etc. We supply {\folio} at the end of the
+% argument, which will end up as the last argument to the \...entry macro.
+%
+% We open the .toc file here instead of at @setfilename or any other
+% given time so that @contents can be put in the document anywhere.
+%
+\newif\iftocfileopened
+\def\writetocentry#1{%
+ \iftocfileopened\else
+ \immediate\openout\tocfile = \jobname.toc
+ \global\tocfileopenedtrue
+ \fi
+ \iflinks \write\tocfile{#1{\folio}}\fi
+}
+
+\newskip\contentsrightmargin \contentsrightmargin=1in
+\newcount\savepageno
+\newcount\lastnegativepageno \lastnegativepageno = -1
+
+% Finish up the main text and prepare to read what we've written
+% to \tocfile.
+%
+\def\startcontents#1{%
+ % If @setchapternewpage on, and @headings double, the contents should
+ % start on an odd page, unlike chapters. Thus, we maintain
+ % \contentsalignmacro in parallel with \pagealignmacro.
+ % From: Torbjorn Granlund <tege@matematik.su.se>
+ \contentsalignmacro
+ \immediate\closeout\tocfile
+ %
+ % Don't need to put `Contents' or `Short Contents' in the headline.
+ % It is abundantly clear what they are.
+ \unnumbchapmacro{#1}\def\thischapter{}%
+ \savepageno = \pageno
+ \begingroup % Set up to handle contents files properly.
+ \catcode`\\=0 \catcode`\{=1 \catcode`\}=2 \catcode`\@=11
+ % We can't do this, because then an actual ^ in a section
+ % title fails, e.g., @chapter ^ -- exponentiation. --karl, 9jul97.
+ %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
+ \raggedbottom % Worry more about breakpoints than the bottom.
+ \advance\hsize by -\contentsrightmargin % Don't use the full line length.
+ %
+ % Roman numerals for page numbers.
+ \ifnum \pageno>0 \pageno = \lastnegativepageno \fi
+}
+
+
+% Normal (long) toc.
+\def\contents{%
+ \startcontents{\putwordTableofContents}%
+ \openin 1 \jobname.toc
+ \ifeof 1 \else
+ \closein 1
+ \input \jobname.toc
+ \fi
+ \vfill \eject
+ \endgroup
+ \lastnegativepageno = \pageno
+ \pageno = \savepageno
+}
+
+% And just the chapters.
+\def\summarycontents{%
+ \startcontents{\putwordShortContents}%
+ %
+ \let\chapentry = \shortchapentry
+ \let\unnumbchapentry = \shortunnumberedentry
+ % We want a true roman here for the page numbers.
+ \secfonts
+ \let\rm=\shortcontrm \let\bf=\shortcontbf \let\sl=\shortcontsl
+ \rm
+ \hyphenpenalty = 10000
+ \advance\baselineskip by 1pt % Open it up a little.
+ \def\secentry ##1##2##3##4{}
+ \def\unnumbsecentry ##1##2{}
+ \def\subsecentry ##1##2##3##4##5{}
+ \def\unnumbsubsecentry ##1##2{}
+ \def\subsubsecentry ##1##2##3##4##5##6{}
+ \def\unnumbsubsubsecentry ##1##2{}
+ \openin 1 \jobname.toc
+ \ifeof 1 \else
+ \closein 1
+ \input \jobname.toc
+ \fi
+ \vfill \eject
+ \endgroup
+ \lastnegativepageno = \pageno
+ \pageno = \savepageno
+}
+\let\shortcontents = \summarycontents
+
+% These macros generate individual entries in the table of contents.
+% The first argument is the chapter or section name.
+% The last argument is the page number.
+% The arguments in between are the chapter number, section number, ...
+
+% Chapter-level things, for both the long and short contents.
+\def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}}
+
+% See comments in \dochapentry re vbox and related settings
+\def\shortchapentry#1#2#3{%
+ \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno{#3}}%
+}
+
+% Typeset the label for a chapter or appendix for the short contents.
+% The arg is, e.g. `Appendix A' for an appendix, or `3' for a chapter.
+% We could simplify the code here by writing out an \appendixentry
+% command in the toc file for appendices, instead of using \chapentry
+% for both, but it doesn't seem worth it.
+\setbox0 = \hbox{\shortcontrm \putwordAppendix }
+\newdimen\shortappendixwidth \shortappendixwidth = \wd0
+
+\def\shortchaplabel#1{%
+ % We typeset #1 in a box of constant width, regardless of the text of
+ % #1, so the chapter titles will come out aligned.
+ \setbox0 = \hbox{#1}%
+ \dimen0 = \ifdim\wd0 > \shortappendixwidth \shortappendixwidth \else 0pt \fi
+ %
+ % This space should be plenty, since a single number is .5em, and the
+ % widest letter (M) is 1em, at least in the Computer Modern fonts.
+ % (This space doesn't include the extra space that gets added after
+ % the label; that gets put in by \shortchapentry above.)
+ \advance\dimen0 by 1.1em
+ \hbox to \dimen0{#1\hfil}%
+}
+
+\def\unnumbchapentry#1#2{\dochapentry{#1}{#2}}
+\def\shortunnumberedentry#1#2{\tocentry{#1}{\doshortpageno{#2}}}
+
+% Sections.
+\def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}}
+\def\unnumbsecentry#1#2{\dosecentry{#1}{#2}}
+
+% Subsections.
+\def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}}
+\def\unnumbsubsecentry#1#2{\dosubsecentry{#1}{#2}}
+
+% And subsubsections.
+\def\subsubsecentry#1#2#3#4#5#6{%
+ \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}}
+\def\unnumbsubsubsecentry#1#2{\dosubsubsecentry{#1}{#2}}
+
+% This parameter controls the indentation of the various levels.
+\newdimen\tocindent \tocindent = 3pc
+
+% Now for the actual typesetting. In all these, #1 is the text and #2 is the
+% page number.
+%
+% If the toc has to be broken over pages, we want it to be at chapters
+% if at all possible; hence the \penalty.
+\def\dochapentry#1#2{%
+ \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
+ \begingroup
+ \chapentryfonts
+ \tocentry{#1}{\dopageno{#2}}%
+ \endgroup
+ \nobreak\vskip .25\baselineskip plus.1\baselineskip
+}
+
+\def\dosecentry#1#2{\begingroup
+ \secentryfonts \leftskip=\tocindent
+ \tocentry{#1}{\dopageno{#2}}%
+\endgroup}
+
+\def\dosubsecentry#1#2{\begingroup
+ \subsecentryfonts \leftskip=2\tocindent
+ \tocentry{#1}{\dopageno{#2}}%
+\endgroup}
+
+\def\dosubsubsecentry#1#2{\begingroup
+ \subsubsecentryfonts \leftskip=3\tocindent
+ \tocentry{#1}{\dopageno{#2}}%
+\endgroup}
+
+% Final typesetting of a toc entry; we use the same \entry macro as for
+% the index entries, but we want to suppress hyphenation here. (We
+% can't do that in the \entry macro, since index entries might consist
+% of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.)
+\def\tocentry#1#2{\begingroup
+ \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks
+ % Do not use \turnoffactive in these arguments. Since the toc is
+ % typeset in cmr, so characters such as _ would come out wrong; we
+ % have to do the usual translation tricks.
+ \entry{#1}{#2}%
+\endgroup}
+
+% Space between chapter (or whatever) number and the title.
+\def\labelspace{\hskip1em \relax}
+
+\def\dopageno#1{{\rm #1}}
+\def\doshortpageno#1{{\rm #1}}
+
+\def\chapentryfonts{\secfonts \rm}
+\def\secentryfonts{\textfonts}
+\let\subsecentryfonts = \textfonts
+\let\subsubsecentryfonts = \textfonts
+
+
+\message{environments,}
+
+% Since these characters are used in examples, it should be an even number of
+% \tt widths. Each \tt character is 1en, so two makes it 1em.
+% Furthermore, these definitions must come after we define our fonts.
+\newbox\dblarrowbox \newbox\longdblarrowbox
+\newbox\pushcharbox \newbox\bullbox
+\newbox\equivbox \newbox\errorbox
+
+%{\tentt
+%\global\setbox\dblarrowbox = \hbox to 1em{\hfil$\Rightarrow$\hfil}
+%\global\setbox\longdblarrowbox = \hbox to 1em{\hfil$\mapsto$\hfil}
+%\global\setbox\pushcharbox = \hbox to 1em{\hfil$\dashv$\hfil}
+%\global\setbox\equivbox = \hbox to 1em{\hfil$\ptexequiv$\hfil}
+% Adapted from the manmac format (p.420 of TeXbook)
+%\global\setbox\bullbox = \hbox to 1em{\kern.15em\vrule height .75ex width .85ex
+% depth .1ex\hfil}
+%}
+
+% @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
+\def\point{$\star$}
+\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
+\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}}
+\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
+\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}}
+
+% Adapted from the TeXbook's \boxit.
+{\tentt \global\dimen0 = 3em}% Width of the box.
+\dimen2 = .55pt % Thickness of rules
+% The text. (`r' is open on the right, `e' somewhat less so on the left.)
+\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
+
+\global\setbox\errorbox=\hbox to \dimen0{\hfil
+ \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
+ \advance\hsize by -2\dimen2 % Rules.
+ \vbox{
+ \hrule height\dimen2
+ \hbox{\vrule width\dimen2 \kern3pt % Space to left of text.
+ \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
+ \kern3pt\vrule width\dimen2}% Space to right.
+ \hrule height\dimen2}
+ \hfil}
+
+% The @error{} command.
+\def\error{\leavevmode\lower.7ex\copy\errorbox}
+
+% @tex ... @end tex escapes into raw Tex temporarily.
+% One exception: @ is still an escape character, so that @end tex works.
+% But \@ or @@ will get a plain tex @ character.
+
+\def\tex{\begingroup
+ \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
+ \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
+ \catcode `\^=7 \catcode `\_=8 \catcode `\~=13 \let~=\tie
+ \catcode `\%=14
+ \catcode 43=12 % plus
+ \catcode`\"=12
+ \catcode`\==12
+ \catcode`\|=12
+ \catcode`\<=12
+ \catcode`\>=12
+ \escapechar=`\\
+ %
+ \let\b=\ptexb
+ \let\bullet=\ptexbullet
+ \let\c=\ptexc
+ \let\,=\ptexcomma
+ \let\.=\ptexdot
+ \let\dots=\ptexdots
+ \let\equiv=\ptexequiv
+ \let\!=\ptexexclam
+ \let\i=\ptexi
+ \let\{=\ptexlbrace
+ \let\+=\tabalign
+ \let\}=\ptexrbrace
+ \let\*=\ptexstar
+ \let\t=\ptext
+ %
+ \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
+ \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
+ \def\@{@}%
+\let\Etex=\endgroup}
+
+% Define @lisp ... @endlisp.
+% @lisp does a \begingroup so it can rebind things,
+% including the definition of @endlisp (which normally is erroneous).
+
+% Amount to narrow the margins by for @lisp.
+\newskip\lispnarrowing \lispnarrowing=0.4in
+
+% This is the definition that ^^M gets inside @lisp, @example, and other
+% such environments. \null is better than a space, since it doesn't
+% have any width.
+\def\lisppar{\null\endgraf}
+
+% Make each space character in the input produce a normal interword
+% space in the output. Don't allow a line break at this space, as this
+% is used only in environments like @example, where each line of input
+% should produce a line of output anyway.
+%
+{\obeyspaces %
+\gdef\sepspaces{\obeyspaces\let =\tie}}
+
+% Define \obeyedspace to be our active space, whatever it is. This is
+% for use in \parsearg.
+{\sepspaces%
+\global\let\obeyedspace= }
+
+% This space is always present above and below environments.
+\newskip\envskipamount \envskipamount = 0pt
+
+% Make spacing and below environment symmetrical. We use \parskip here
+% to help in doing that, since in @example-like environments \parskip
+% is reset to zero; thus the \afterenvbreak inserts no space -- but the
+% start of the next paragraph will insert \parskip
+%
+\def\aboveenvbreak{{\advance\envskipamount by \parskip
+\endgraf \ifdim\lastskip<\envskipamount
+\removelastskip \penalty-50 \vskip\envskipamount \fi}}
+
+\let\afterenvbreak = \aboveenvbreak
+
+% \nonarrowing is a flag. If "set", @lisp etc don't narrow margins.
+\let\nonarrowing=\relax
+
+% @cartouche ... @end cartouche: draw rectangle w/rounded corners around
+% environment contents.
+\font\circle=lcircle10
+\newdimen\circthick
+\newdimen\cartouter\newdimen\cartinner
+\newskip\normbskip\newskip\normpskip\newskip\normlskip
+\circthick=\fontdimen8\circle
+%
+\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
+\def\ctr{{\hskip 6pt\circle\char'010}}
+\def\cbl{{\circle\char'012\hskip -6pt}}
+\def\cbr{{\hskip 6pt\circle\char'011}}
+\def\carttop{\hbox to \cartouter{\hskip\lskip
+ \ctl\leaders\hrule height\circthick\hfil\ctr
+ \hskip\rskip}}
+\def\cartbot{\hbox to \cartouter{\hskip\lskip
+ \cbl\leaders\hrule height\circthick\hfil\cbr
+ \hskip\rskip}}
+%
+\newskip\lskip\newskip\rskip
+
+\long\def\cartouche{%
+\begingroup
+ \lskip=\leftskip \rskip=\rightskip
+ \leftskip=0pt\rightskip=0pt %we want these *outside*.
+ \cartinner=\hsize \advance\cartinner by-\lskip
+ \advance\cartinner by-\rskip
+ \cartouter=\hsize
+ \advance\cartouter by 18.4pt % allow for 3pt kerns on either
+% side, and for 6pt waste from
+% each corner char, and rule thickness
+ \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
+ % Flag to tell @lisp, etc., not to narrow margin.
+ \let\nonarrowing=\comment
+ \vbox\bgroup
+ \baselineskip=0pt\parskip=0pt\lineskip=0pt
+ \carttop
+ \hbox\bgroup
+ \hskip\lskip
+ \vrule\kern3pt
+ \vbox\bgroup
+ \hsize=\cartinner
+ \kern3pt
+ \begingroup
+ \baselineskip=\normbskip
+ \lineskip=\normlskip
+ \parskip=\normpskip
+ \vskip -\parskip
+\def\Ecartouche{%
+ \endgroup
+ \kern3pt
+ \egroup
+ \kern3pt\vrule
+ \hskip\rskip
+ \egroup
+ \cartbot
+ \egroup
+\endgroup
+}}
+
+
+% This macro is called at the beginning of all the @example variants,
+% inside a group.
+\def\nonfillstart{%
+ \aboveenvbreak
+ \inENV % This group ends at the end of the body
+ \hfuzz = 12pt % Don't be fussy
+ \sepspaces % Make spaces be word-separators rather than space tokens.
+ \singlespace
+ \let\par = \lisppar % don't ignore blank lines
+ \obeylines % each line of input is a line of output
+ \parskip = 0pt
+ \parindent = 0pt
+ \emergencystretch = 0pt % don't try to avoid overfull boxes
+ % @cartouche defines \nonarrowing to inhibit narrowing
+ % at next level down.
+ \ifx\nonarrowing\relax
+ \advance \leftskip by \lispnarrowing
+ \exdentamount=\lispnarrowing
+ \let\exdent=\nofillexdent
+ \let\nonarrowing=\relax
+ \fi
+}
+
+% Define the \E... control sequence only if we are inside the particular
+% environment, so the error checking in \end will work.
+%
+% To end an @example-like environment, we first end the paragraph (via
+% \afterenvbreak's vertical glue), and then the group. That way we keep
+% the zero \parskip that the environments set -- \parskip glue will be
+% inserted at the beginning of the next paragraph in the document, after
+% the environment.
+%
+\def\nonfillfinish{\afterenvbreak\endgroup}
+
+% @lisp: indented, narrowed, typewriter font.
+\def\lisp{\begingroup
+ \nonfillstart
+ \let\Elisp = \nonfillfinish
+ \tt
+ \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
+ \gobble % eat return
+}
+
+% @example: Same as @lisp.
+\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp}
+
+% @small... is usually equivalent to the non-small (@smallbook
+% redefines). We must call \example (or whatever) last in the
+% definition, since it reads the return following the @example (or
+% whatever) command.
+%
+% This actually allows (for example) @end display inside an
+% @smalldisplay. Too bad, but makeinfo will catch the error anyway.
+%
+\def\smalldisplay{\begingroup\def\Esmalldisplay{\nonfillfinish\endgroup}\display}
+\def\smallexample{\begingroup\def\Esmallexample{\nonfillfinish\endgroup}\lisp}
+\def\smallformat{\begingroup\def\Esmallformat{\nonfillfinish\endgroup}\format}
+\def\smalllisp{\begingroup\def\Esmalllisp{\nonfillfinish\endgroup}\lisp}
+
+% Real @smallexample and @smalllisp (when @smallbook): use smaller fonts.
+% Originally contributed by Pavel@xerox.
+\def\smalllispx{\begingroup
+ \def\Esmalllisp{\nonfillfinish\endgroup}%
+ \def\Esmallexample{\nonfillfinish\endgroup}%
+ \indexfonts
+ \lisp
+}
+
+% @display: same as @lisp except keep current font.
+%
+\def\display{\begingroup
+ \nonfillstart
+ \let\Edisplay = \nonfillfinish
+ \gobble
+}
+
+% @smalldisplay (when @smallbook): @display plus smaller fonts.
+%
+\def\smalldisplayx{\begingroup
+ \def\Esmalldisplay{\nonfillfinish\endgroup}%
+ \indexfonts \rm
+ \display
+}
+
+% @format: same as @display except don't narrow margins.
+%
+\def\format{\begingroup
+ \let\nonarrowing = t
+ \nonfillstart
+ \let\Eformat = \nonfillfinish
+ \gobble
+}
+
+% @smallformat (when @smallbook): @format plus smaller fonts.
+%
+\def\smallformatx{\begingroup
+ \def\Esmallformat{\nonfillfinish\endgroup}%
+ \indexfonts \rm
+ \format
+}
+
+% @flushleft (same as @format).
+%
+\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format}
+
+% @flushright.
+%
+\def\flushright{\begingroup
+ \let\nonarrowing = t
+ \nonfillstart
+ \let\Eflushright = \nonfillfinish
+ \advance\leftskip by 0pt plus 1fill
+ \gobble
+}
+
+% @quotation does normal linebreaking (hence we can't use \nonfillstart)
+% and narrows the margins.
+%
+\def\quotation{%
+ \begingroup\inENV %This group ends at the end of the @quotation body
+ {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
+ \singlespace
+ \parindent=0pt
+ % We have retained a nonzero parskip for the environment, since we're
+ % doing normal filling. So to avoid extra space below the environment...
+ \def\Equotation{\parskip = 0pt \nonfillfinish}%
+ %
+ % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
+ \ifx\nonarrowing\relax
+ \advance\leftskip by \lispnarrowing
+ \advance\rightskip by \lispnarrowing
+ \exdentamount = \lispnarrowing
+ \let\nonarrowing = \relax
+ \fi
+}
+
+
+\message{defuns,}
+% Define formatter for defuns
+% First, allow user to change definition object font (\df) internally
+\def\setdeffont #1 {\csname DEF#1\endcsname}
+
+\newskip\defbodyindent \defbodyindent=.4in
+\newskip\defargsindent \defargsindent=50pt
+\newskip\deftypemargin \deftypemargin=12pt
+\newskip\deflastargmargin \deflastargmargin=18pt
+
+\newcount\parencount
+% define \functionparens, which makes ( and ) and & do special things.
+% \functionparens affects the group it is contained in.
+\def\activeparens{%
+\catcode`\(=\active \catcode`\)=\active \catcode`\&=\active
+\catcode`\[=\active \catcode`\]=\active}
+
+% Make control sequences which act like normal parenthesis chars.
+\let\lparen = ( \let\rparen = )
+
+{\activeparens % Now, smart parens don't turn on until &foo (see \amprm)
+
+% Be sure that we always have a definition for `(', etc. For example,
+% if the fn name has parens in it, \boldbrax will not be in effect yet,
+% so TeX would otherwise complain about undefined control sequence.
+\global\let(=\lparen \global\let)=\rparen
+\global\let[=\lbrack \global\let]=\rbrack
+
+\gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 }
+\gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
+% This is used to turn on special parens
+% but make & act ordinary (given that it's active).
+\gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr}
+
+% Definitions of (, ) and & used in args for functions.
+% This is the definition of ( outside of all parentheses.
+\gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested
+ \global\advance\parencount by 1
+}
+%
+% This is the definition of ( when already inside a level of parens.
+\gdef\opnested{\char`\(\global\advance\parencount by 1 }
+%
+\gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0.
+ % also in that case restore the outer-level definition of (.
+ \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi
+ \global\advance \parencount by -1 }
+% If we encounter &foo, then turn on ()-hacking afterwards
+\gdef\amprm#1 {{\rm\&#1}\let(=\oprm \let)=\clrm\ }
+%
+\gdef\normalparens{\boldbrax\let&=\ampnr}
+} % End of definition inside \activeparens
+%% These parens (in \boldbrax) actually are a little bolder than the
+%% contained text. This is especially needed for [ and ]
+\def\opnr{{\sf\char`\(}\global\advance\parencount by 1 }
+\def\clnr{{\sf\char`\)}\global\advance\parencount by -1 }
+\def\ampnr{\&}
+\def\lbrb{{\bf\char`\[}}
+\def\rbrb{{\bf\char`\]}}
+
+% First, defname, which formats the header line itself.
+% #1 should be the function name.
+% #2 should be the type of definition, such as "Function".
+
+\def\defname #1#2{%
+% Get the values of \leftskip and \rightskip as they were
+% outside the @def...
+\dimen2=\leftskip
+\advance\dimen2 by -\defbodyindent
+\noindent
+\setbox0=\hbox{\hskip \deflastargmargin{\rm #2}\hskip \deftypemargin}%
+\dimen0=\hsize \advance \dimen0 by -\wd0 % compute size for first line
+\dimen1=\hsize \advance \dimen1 by -\defargsindent %size for continuations
+\parshape 2 0in \dimen0 \defargsindent \dimen1
+% Now output arg 2 ("Function" or some such)
+% ending at \deftypemargin from the right margin,
+% but stuck inside a box of width 0 so it does not interfere with linebreaking
+{% Adjust \hsize to exclude the ambient margins,
+% so that \rightline will obey them.
+\advance \hsize by -\dimen2
+\rlap{\rightline{{\rm #2}\hskip -1.25pc }}}%
+% Make all lines underfull and no complaints:
+\tolerance=10000 \hbadness=10000
+\advance\leftskip by -\defbodyindent
+\exdentamount=\defbodyindent
+{\df #1}\enskip % Generate function name
+}
+
+% Actually process the body of a definition
+% #1 should be the terminating control sequence, such as \Edefun.
+% #2 should be the "another name" control sequence, such as \defunx.
+% #3 should be the control sequence that actually processes the header,
+% such as \defunheader.
+
+\def\defparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody
+\medbreak %
+% Define the end token that this defining construct specifies
+% so that it will exit this group.
+\def#1{\endgraf\endgroup\medbreak}%
+\def#2{\begingroup\obeylines\activeparens\spacesplit#3}%
+\parindent=0in
+\advance\leftskip by \defbodyindent
+\exdentamount=\defbodyindent
+\begingroup %
+\catcode 61=\active % 61 is `='
+\obeylines\activeparens\spacesplit#3}
+
+% #1 is the \E... control sequence to end the definition (which we define).
+% #2 is the \...x control sequence for consecutive fns (which we define).
+% #3 is the control sequence to call to resume processing.
+% #4, delimited by the space, is the class name.
+%
+\def\defmethparsebody#1#2#3#4 {\begingroup\inENV %
+\medbreak %
+% Define the end token that this defining construct specifies
+% so that it will exit this group.
+\def#1{\endgraf\endgroup\medbreak}%
+\def#2##1 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}}}%
+\parindent=0in
+\advance\leftskip by \defbodyindent
+\exdentamount=\defbodyindent
+\begingroup\obeylines\activeparens\spacesplit{#3{#4}}}
+
+% @deftypemethod has an extra argument that nothing else does. Sigh.
+% #1 is the \E... control sequence to end the definition (which we define).
+% #2 is the \...x control sequence for consecutive fns (which we define).
+% #3 is the control sequence to call to resume processing.
+% #4, delimited by the space, is the class name.
+% #5 is the method's return type.
+%
+\def\deftypemethparsebody#1#2#3#4 #5 {\begingroup\inENV %
+\medbreak %
+% Define the end token that this defining construct specifies
+% so that it will exit this group.
+\def#1{\endgraf\endgroup\medbreak}%
+\def#2##1 ##2 {\begingroup\obeylines\activeparens\spacesplit{#3{##1}{##2}}}%
+\parindent=0in
+\advance\leftskip by \defbodyindent
+\exdentamount=\defbodyindent
+\begingroup\obeylines\activeparens\spacesplit{#3{#4}{#5}}}
+
+\def\defopparsebody #1#2#3#4#5 {\begingroup\inENV %
+\medbreak %
+% Define the end token that this defining construct specifies
+% so that it will exit this group.
+\def#1{\endgraf\endgroup\medbreak}%
+\def#2##1 ##2 {\def#4{##1}%
+\begingroup\obeylines\activeparens\spacesplit{#3{##2}}}%
+\parindent=0in
+\advance\leftskip by \defbodyindent
+\exdentamount=\defbodyindent
+\begingroup\obeylines\activeparens\spacesplit{#3{#5}}}
+
+% These parsing functions are similar to the preceding ones
+% except that they do not make parens into active characters.
+% These are used for "variables" since they have no arguments.
+
+\def\defvarparsebody #1#2#3{\begingroup\inENV% Environment for definitionbody
+\medbreak %
+% Define the end token that this defining construct specifies
+% so that it will exit this group.
+\def#1{\endgraf\endgroup\medbreak}%
+\def#2{\begingroup\obeylines\spacesplit#3}%
+\parindent=0in
+\advance\leftskip by \defbodyindent
+\exdentamount=\defbodyindent
+\begingroup %
+\catcode 61=\active %
+\obeylines\spacesplit#3}
+
+% This is used for \def{tp,vr}parsebody. It could probably be used for
+% some of the others, too, with some judicious conditionals.
+%
+\def\parsebodycommon#1#2#3{%
+ \begingroup\inENV %
+ \medbreak %
+ % Define the end token that this defining construct specifies
+ % so that it will exit this group.
+ \def#1{\endgraf\endgroup\medbreak}%
+ \def#2##1 {\begingroup\obeylines\spacesplit{#3{##1}}}%
+ \parindent=0in
+ \advance\leftskip by \defbodyindent
+ \exdentamount=\defbodyindent
+ \begingroup\obeylines
+}
+
+\def\defvrparsebody#1#2#3#4 {%
+ \parsebodycommon{#1}{#2}{#3}%
+ \spacesplit{#3{#4}}%
+}
+
+% This loses on `@deftp {Data Type} {struct termios}' -- it thinks the
+% type is just `struct', because we lose the braces in `{struct
+% termios}' when \spacesplit reads its undelimited argument. Sigh.
+% \let\deftpparsebody=\defvrparsebody
+%
+% So, to get around this, we put \empty in with the type name. That
+% way, TeX won't find exactly `{...}' as an undelimited argument, and
+% won't strip off the braces.
+%
+\def\deftpparsebody #1#2#3#4 {%
+ \parsebodycommon{#1}{#2}{#3}%
+ \spacesplit{\parsetpheaderline{#3{#4}}}\empty
+}
+
+% Fine, but then we have to eventually remove the \empty *and* the
+% braces (if any). That's what this does.
+%
+\def\removeemptybraces\empty#1\relax{#1}
+
+% After \spacesplit has done its work, this is called -- #1 is the final
+% thing to call, #2 the type name (which starts with \empty), and #3
+% (which might be empty) the arguments.
+%
+\def\parsetpheaderline#1#2#3{%
+ #1{\removeemptybraces#2\relax}{#3}%
+}%
+
+\def\defopvarparsebody #1#2#3#4#5 {\begingroup\inENV %
+\medbreak %
+% Define the end token that this defining construct specifies
+% so that it will exit this group.
+\def#1{\endgraf\endgroup\medbreak}%
+\def#2##1 ##2 {\def#4{##1}%
+\begingroup\obeylines\spacesplit{#3{##2}}}%
+\parindent=0in
+\advance\leftskip by \defbodyindent
+\exdentamount=\defbodyindent
+\begingroup\obeylines\spacesplit{#3{#5}}}
+
+% Split up #2 at the first space token.
+% call #1 with two arguments:
+% the first is all of #2 before the space token,
+% the second is all of #2 after that space token.
+% If #2 contains no space token, all of it is passed as the first arg
+% and the second is passed as empty.
+
+{\obeylines
+\gdef\spacesplit#1#2^^M{\endgroup\spacesplitfoo{#1}#2 \relax\spacesplitfoo}%
+\long\gdef\spacesplitfoo#1#2 #3#4\spacesplitfoo{%
+\ifx\relax #3%
+#1{#2}{}\else #1{#2}{#3#4}\fi}}
+
+% So much for the things common to all kinds of definitions.
+
+% Define @defun.
+
+% First, define the processing that is wanted for arguments of \defun
+% Use this to expand the args and terminate the paragraph they make up
+
+\def\defunargs #1{\functionparens \sl
+% Expand, preventing hyphenation at `-' chars.
+% Note that groups don't affect changes in \hyphenchar.
+\hyphenchar\tensl=0
+#1%
+\hyphenchar\tensl=45
+\ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi%
+\interlinepenalty=10000
+\advance\rightskip by 0pt plus 1fil
+\endgraf\nobreak\vskip -\parskip\nobreak
+}
+
+\def\deftypefunargs #1{%
+% Expand, preventing hyphenation at `-' chars.
+% Note that groups don't affect changes in \hyphenchar.
+% Use \boldbraxnoamp, not \functionparens, so that & is not special.
+\boldbraxnoamp
+\tclose{#1}% avoid \code because of side effects on active chars
+\interlinepenalty=10000
+\advance\rightskip by 0pt plus 1fil
+\endgraf\nobreak\vskip -\parskip\nobreak
+}
+
+% Do complete processing of one @defun or @defunx line already parsed.
+
+% @deffn Command forward-char nchars
+
+\def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader}
+
+\def\deffnheader #1#2#3{\doind {fn}{\code{#2}}%
+\begingroup\defname {#2}{#1}\defunargs{#3}\endgroup %
+\catcode 61=\other % Turn off change made in \defparsebody
+}
+
+% @defun == @deffn Function
+
+\def\defun{\defparsebody\Edefun\defunx\defunheader}
+
+\def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
+\begingroup\defname {#1}{Function}%
+\defunargs {#2}\endgroup %
+\catcode 61=\other % Turn off change made in \defparsebody
+}
+
+% @deftypefun int foobar (int @var{foo}, float @var{bar})
+
+\def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader}
+
+% #1 is the data type. #2 is the name and args.
+\def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax}
+% #1 is the data type, #2 the name, #3 the args.
+\def\deftypefunheaderx #1#2 #3\relax{%
+\doind {fn}{\code{#2}}% Make entry in function index
+\begingroup\defname {\defheaderxcond#1\relax$$$#2}{Function}%
+\deftypefunargs {#3}\endgroup %
+\catcode 61=\other % Turn off change made in \defparsebody
+}
+
+% @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar})
+
+\def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader}
+
+% \defheaderxcond#1\relax$$$
+% puts #1 in @code, followed by a space, but does nothing if #1 is null.
+\def\defheaderxcond#1#2$$${\ifx#1\relax\else\code{#1#2} \fi}
+
+% #1 is the classification. #2 is the data type. #3 is the name and args.
+\def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax}
+% #1 is the classification, #2 the data type, #3 the name, #4 the args.
+\def\deftypefnheaderx #1#2#3 #4\relax{%
+\doind {fn}{\code{#3}}% Make entry in function index
+\begingroup
+\normalparens % notably, turn off `&' magic, which prevents
+% at least some C++ text from working
+\defname {\defheaderxcond#2\relax$$$#3}{#1}%
+\deftypefunargs {#4}\endgroup %
+\catcode 61=\other % Turn off change made in \defparsebody
+}
+
+% @defmac == @deffn Macro
+
+\def\defmac{\defparsebody\Edefmac\defmacx\defmacheader}
+
+\def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
+\begingroup\defname {#1}{Macro}%
+\defunargs {#2}\endgroup %
+\catcode 61=\other % Turn off change made in \defparsebody
+}
+
+% @defspec == @deffn Special Form
+
+\def\defspec{\defparsebody\Edefspec\defspecx\defspecheader}
+
+\def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
+\begingroup\defname {#1}{Special Form}%
+\defunargs {#2}\endgroup %
+\catcode 61=\other % Turn off change made in \defparsebody
+}
+
+% This definition is run if you use @defunx
+% anywhere other than immediately after a @defun or @defunx.
+
+\def\deffnx #1 {\errmessage{@deffnx in invalid context}}
+\def\defunx #1 {\errmessage{@defunx in invalid context}}
+\def\defmacx #1 {\errmessage{@defmacx in invalid context}}
+\def\defspecx #1 {\errmessage{@defspecx in invalid context}}
+\def\deftypefnx #1 {\errmessage{@deftypefnx in invalid context}}
+\def\deftypemethodx #1 {\errmessage{@deftypemethodx in invalid context}}
+\def\deftypefunx #1 {\errmessage{@deftypefunx in invalid context}}
+
+% @defmethod, and so on
+
+% @defop CATEGORY CLASS OPERATION ARG...
+
+\def\defop #1 {\def\defoptype{#1}%
+\defopparsebody\Edefop\defopx\defopheader\defoptype}
+
+\def\defopheader #1#2#3{%
+\dosubind {fn}{\code{#2}}{\putwordon\ #1}% Make entry in function index
+\begingroup\defname {#2}{\defoptype{} on #1}%
+\defunargs {#3}\endgroup %
+}
+
+% @deftypemethod CLASS RETURN-TYPE METHOD ARG...
+%
+\def\deftypemethod{%
+ \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader}
+%
+% #1 is the class name, #2 the data type, #3 the method name, #4 the args.
+\def\deftypemethodheader#1#2#3#4{%
+ \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
+ \begingroup
+ \defname{\defheaderxcond#2\relax$$$#3}{\putwordMethodon\ \code{#1}}%
+ \deftypefunargs{#4}%
+ \endgroup
+}
+
+% @defmethod == @defop Method
+%
+\def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader}
+%
+% #1 is the class name, #2 the method name, #3 the args.
+\def\defmethodheader#1#2#3{%
+ \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index
+ \begingroup
+ \defname{#2}{\putwordMethodon\ \code{#1}}%
+ \defunargs{#3}%
+ \endgroup
+}
+
+% @defcv {Class Option} foo-class foo-flag
+
+\def\defcv #1 {\def\defcvtype{#1}%
+\defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype}
+
+\def\defcvarheader #1#2#3{%
+\dosubind {vr}{\code{#2}}{of #1}% Make entry in var index
+\begingroup\defname {#2}{\defcvtype{} of #1}%
+\defvarargs {#3}\endgroup %
+}
+
+% @defivar == @defcv {Instance Variable}
+
+\def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader}
+
+\def\defivarheader #1#2#3{%
+\dosubind {vr}{\code{#2}}{of #1}% Make entry in var index
+\begingroup\defname {#2}{Instance Variable of #1}%
+\defvarargs {#3}\endgroup %
+}
+
+% These definitions are run if you use @defmethodx, etc.,
+% anywhere other than immediately after a @defmethod, etc.
+
+\def\defopx #1 {\errmessage{@defopx in invalid context}}
+\def\defmethodx #1 {\errmessage{@defmethodx in invalid context}}
+\def\defcvx #1 {\errmessage{@defcvx in invalid context}}
+\def\defivarx #1 {\errmessage{@defivarx in invalid context}}
+
+% Now @defvar
+
+% First, define the processing that is wanted for arguments of @defvar.
+% This is actually simple: just print them in roman.
+% This must expand the args and terminate the paragraph they make up
+\def\defvarargs #1{\normalparens #1%
+\interlinepenalty=10000
+\endgraf\nobreak\vskip -\parskip\nobreak}
+
+% @defvr Counter foo-count
+
+\def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader}
+
+\def\defvrheader #1#2#3{\doind {vr}{\code{#2}}%
+\begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup}
+
+% @defvar == @defvr Variable
+
+\def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader}
+
+\def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
+\begingroup\defname {#1}{Variable}%
+\defvarargs {#2}\endgroup %
+}
+
+% @defopt == @defvr {User Option}
+
+\def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader}
+
+\def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
+\begingroup\defname {#1}{User Option}%
+\defvarargs {#2}\endgroup %
+}
+
+% @deftypevar int foobar
+
+\def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader}
+
+% #1 is the data type. #2 is the name, perhaps followed by text that
+% is actually part of the data type, which should not be put into the index.
+\def\deftypevarheader #1#2{%
+\dovarind#2 \relax% Make entry in variables index
+\begingroup\defname {\defheaderxcond#1\relax$$$#2}{Variable}%
+\interlinepenalty=10000
+\endgraf\nobreak\vskip -\parskip\nobreak
+\endgroup}
+\def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}}
+
+% @deftypevr {Global Flag} int enable
+
+\def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader}
+
+\def\deftypevrheader #1#2#3{\dovarind#3 \relax%
+\begingroup\defname {\defheaderxcond#2\relax$$$#3}{#1}
+\interlinepenalty=10000
+\endgraf\nobreak\vskip -\parskip\nobreak
+\endgroup}
+
+% This definition is run if you use @defvarx
+% anywhere other than immediately after a @defvar or @defvarx.
+
+\def\defvrx #1 {\errmessage{@defvrx in invalid context}}
+\def\defvarx #1 {\errmessage{@defvarx in invalid context}}
+\def\defoptx #1 {\errmessage{@defoptx in invalid context}}
+\def\deftypevarx #1 {\errmessage{@deftypevarx in invalid context}}
+\def\deftypevrx #1 {\errmessage{@deftypevrx in invalid context}}
+
+% Now define @deftp
+% Args are printed in bold, a slight difference from @defvar.
+
+\def\deftpargs #1{\bf \defvarargs{#1}}
+
+% @deftp Class window height width ...
+
+\def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader}
+
+\def\deftpheader #1#2#3{\doind {tp}{\code{#2}}%
+\begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup}
+
+% This definition is run if you use @deftpx, etc
+% anywhere other than immediately after a @deftp, etc.
+
+\def\deftpx #1 {\errmessage{@deftpx in invalid context}}
+
+
+\message{macros,}
+% @macro.
+
+% To do this right we need a feature of e-TeX, \scantokens,
+% which we arrange to emulate with a temporary file in ordinary TeX.
+\ifx\eTeXversion\undefined
+ \newwrite\macscribble
+ \def\scanmacro#1{%
+ \begingroup \newlinechar`\^^M
+ \immediate\openout\macscribble=\jobname.tmp
+ \immediate\write\macscribble{#1}%
+ \immediate\closeout\macscribble
+ \let\xeatspaces\eatspaces
+ \input \jobname.tmp
+ \endgroup
+}
+\else
+\def\scanmacro#1{%
+\begingroup \newlinechar`\^^M
+\let\xeatspaces\eatspaces\scantokens{#1}\endgroup}
+\fi
+
+\newcount\paramno % Count of parameters
+\newtoks\macname % Macro name
+\newif\ifrecursive % Is it recursive?
+
+% Utility routines.
+% Thisdoes \let #1 = #2, except with \csnames.
+\def\cslet#1#2{%
+\expandafter\expandafter
+\expandafter\let
+\expandafter\expandafter
+\csname#1\endcsname
+\csname#2\endcsname}
+
+% Trim leading and trailing spaces off a string.
+% Concepts from aro-bend problem 15 (see CTAN).
+{\catcode`\@=11
+\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
+\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
+\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
+\def\unbrace#1{#1}
+\unbrace{\gdef\trim@@@ #1 } #2@{#1}
+}
+
+% Trim a single trailing ^^M off a string.
+{\catcode`\^^M=12\catcode`\Q=3%
+\gdef\eatcr #1{\eatcra #1Q^^MQ}%
+\gdef\eatcra#1^^MQ{\eatcrb#1Q}%
+\gdef\eatcrb#1Q#2Q{#1}%
+}
+
+% Macro bodies are absorbed as an argument in a context where
+% all characters are catcode 10, 11 or 12, except \ which is active
+% (as in normal texinfo). It is necessary to change the definition of \.
+
+% It's necessary to have hard CRs when the macro is executed. This is
+% done by making ^^M (\endlinechar) catcode 12 when reading the macro
+% body, and then making it the \newlinechar in \scanmacro.
+
+\def\macrobodyctxt{%
+ \catcode`\~=12
+ \catcode`\^=12
+ \catcode`\_=12
+ \catcode`\|=12
+ \catcode`\<=12
+ \catcode`\>=12
+ \catcode`\+=12
+ \catcode`\{=12
+ \catcode`\}=12
+ \catcode`\@=12
+ \catcode`\^^M=12
+ \usembodybackslash}
+
+\def\macroargctxt{%
+ \catcode`\~=12
+ \catcode`\^=12
+ \catcode`\_=12
+ \catcode`\|=12
+ \catcode`\<=12
+ \catcode`\>=12
+ \catcode`\+=12
+ \catcode`\@=12
+ \catcode`\\=12}
+
+% \mbodybackslash is the definition of \ in @macro bodies.
+% It maps \foo\ => \csname macarg.foo\endcsname => #N
+% where N is the macro parameter number.
+% We define \csname macarg.\endcsname to be \realbackslash, so
+% \\ in macro replacement text gets you a backslash.
+
+{\catcode`@=0 @catcode`@\=@active
+ @gdef@usembodybackslash{@let\=@mbodybackslash}
+ @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
+}
+\expandafter\def\csname macarg.\endcsname{\realbackslash}
+
+\def\macro{\recursivefalse\parsearg\macroxxx}
+\def\rmacro{\recursivetrue\parsearg\macroxxx}
+
+\def\macroxxx#1{%
+ \getargs{#1}% now \macname is the macname and \argl the arglist
+ \ifx\argl\empty % no arguments
+ \paramno=0%
+ \else
+ \expandafter\parsemargdef \argl;%
+ \fi
+ \expandafter\ifx \csname macsave.\the\macname\endcsname \relax
+ \cslet{macsave.\the\macname}{\the\macname}%
+ \else
+ \message{Warning: redefining \the\macname}%
+ \fi
+ \begingroup \macrobodyctxt
+ \ifrecursive \expandafter\parsermacbody
+ \else \expandafter\parsemacbody
+ \fi}
+
+\def\unmacro{\parsearg\unmacroxxx}
+\def\unmacroxxx#1{%
+ \expandafter\ifx \csname macsave.\the\macname\endcsname \relax
+ \errmessage{Macro \the\macname\ not defined.}%
+ \else
+ \cslet{#1}{macsave.#1}%
+ \expandafter\let \csname macsave.\the\macname\endcsname \undefined
+ \fi
+}
+
+% This makes use of the obscure feature that if the last token of a
+% <parameter list> is #, then the preceding argument is delimited by
+% an opening brace, and that opening brace is not consumed.
+\def\getargs#1{\getargsxxx#1{}}
+\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
+\def\getmacname #1 #2\relax{\macname={#1}}
+\def\getmacargs#1{\def\argl{#1}}
+
+% Parse the optional {params} list. Set up \paramno and \paramlist
+% so \defmacro knows what to do. Define \macarg.blah for each blah
+% in the params list, to be ##N where N is the position in that list.
+% That gets used by \mbodybackslash (above).
+
+% We need to get `macro parameter char #' into several definitions.
+% The technique used is stolen from LaTeX: let \hash be something
+% unexpandable, insert that wherever you need a #, and then redefine
+% it to # just before using the token list produced.
+%
+% The same technique is used to protect \eatspaces till just before
+% the macro is used.
+
+\def\parsemargdef#1;{\paramno=0\def\paramlist{}%
+ \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,}
+\def\parsemargdefxxx#1,{%
+ \if#1;\let\next=\relax
+ \else \let\next=\parsemargdefxxx
+ \advance\paramno by 1%
+ \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
+ {\xeatspaces{\hash\the\paramno}}%
+ \edef\paramlist{\paramlist\hash\the\paramno,}%
+ \fi\next}
+
+% These two commands read recursive and nonrecursive macro bodies.
+% (They're different since rec and nonrec macros end differently.)
+
+\long\def\parsemacbody#1@end macro%
+{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
+\long\def\parsermacbody#1@end rmacro%
+{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
+
+% This defines the macro itself. There are six cases: recursive and
+% nonrecursive macros of zero, one, and many arguments.
+% Much magic with \expandafter here.
+% \xdef is used so that macro definitions will survive the file
+% they're defined in; @include reads the file inside a group.
+\def\defmacro{%
+ \let\hash=##% convert placeholders to macro parameter chars
+ \ifrecursive
+ \ifcase\paramno
+ % 0
+ \expandafter\xdef\csname\the\macname\endcsname{%
+ \noexpand\scanmacro{\temp}}%
+ \or % 1
+ \expandafter\xdef\csname\the\macname\endcsname{%
+ \bgroup\noexpand\macroargctxt
+ \noexpand\braceorline\csname\the\macname xxx\endcsname}%
+ \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
+ \egroup\noexpand\scanmacro{\temp}}%
+ \else % many
+ \expandafter\xdef\csname\the\macname\endcsname{%
+ \bgroup\noexpand\macroargctxt
+ \noexpand\csname\the\macname xx\endcsname}
+ \expandafter\xdef\csname\the\macname xx\endcsname##1{%
+ \csname\the\macname xxx\endcsname ##1,}%
+ \expandafter\expandafter
+ \expandafter\xdef
+ \expandafter\expandafter
+ \csname\the\macname xxx\endcsname
+ \paramlist{\egroup\noexpand\scanmacro{\temp}}%
+ \fi
+ \else
+ \ifcase\paramno
+ % 0
+ \expandafter\xdef\csname\the\macname\endcsname{%
+ \noexpand\norecurse{\the\macname}%
+ \noexpand\scanmacro{\temp}\egroup}%
+ \or % 1
+ \expandafter\xdef\csname\the\macname\endcsname{%
+ \bgroup\noexpand\macroargctxt
+ \noexpand\braceorline\csname\the\macname xxx\endcsname}%
+ \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
+ \egroup
+ \noexpand\norecurse{\the\macname}%
+ \noexpand\scanmacro{\temp}\egroup}%
+ \else % many
+ \expandafter\xdef\csname\the\macname\endcsname{%
+ \bgroup\noexpand\macroargctxt
+ \noexpand\csname\the\macname xx\endcsname}
+ \expandafter\xdef\csname\the\macname xx\endcsname##1{%
+ \csname\the\macname xxx\endcsname ##1,}%
+ \expandafter\expandafter
+ \expandafter\xdef
+ \expandafter\expandafter
+ \csname\the\macname xxx\endcsname
+ \paramlist{%
+ \egroup
+ \noexpand\norecurse{\the\macname}%
+ \noexpand\scanmacro{\temp}\egroup}%
+ \fi
+ \fi}
+
+\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
+
+% \braceorline decides whether the next nonwhitespace character is a
+% {. If so it reads up to the closing }, if not, it reads the whole
+% line. Whatever was read is then fed to the next control sequence
+% as an argument (by \parsebrace or \parsearg)
+\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx}
+\def\braceorlinexxx{%
+ \ifx\nchar\bgroup\else
+ \expandafter\parsearg
+ \fi \next}
+
+
+\message{cross references,}
+\newwrite\auxfile
+
+\newif\ifhavexrefs % True if xref values are known.
+\newif\ifwarnedxrefs % True if we warned once that they aren't known.
+
+% @inforef is relatively simple.
+\def\inforef #1{\inforefzzz #1,,,,**}
+\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
+ node \samp{\ignorespaces#1{}}}
+
+% @node's job is to define \lastnode.
+\def\node{\ENVcheck\parsearg\nodezzz}
+\def\nodezzz#1{\nodexxx [#1,]}
+\def\nodexxx[#1,#2]{\gdef\lastnode{#1}}
+\let\nwnode=\node
+\let\lastnode=\relax
+
+% The sectioning commands (@chapter, etc.) call these.
+\def\donoderef{%
+ \ifx\lastnode\relax\else
+ \expandafter\expandafter\expandafter\setref{\lastnode}%
+ {Ysectionnumberandtype}%
+ \global\let\lastnode=\relax
+ \fi
+}
+\def\unnumbnoderef{%
+ \ifx\lastnode\relax\else
+ \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}%
+ \global\let\lastnode=\relax
+ \fi
+}
+\def\appendixnoderef{%
+ \ifx\lastnode\relax\else
+ \expandafter\expandafter\expandafter\setref{\lastnode}%
+ {Yappendixletterandtype}%
+ \global\let\lastnode=\relax
+ \fi
+}
+
+
+% @anchor{NAME} -- define xref target at arbitrary point.
+%
+\def\anchor#1{\setref{#1}{Ynothing}}
+
+
+% \setref{NAME}{SNT} defines a cross-reference point NAME, namely
+% NAME-title, NAME-pg, and NAME-SNT. Called from \foonoderef. We have
+% to set \indexdummies so commands such as @code in a section title
+% aren't expanded. It would be nicer not to expand the titles in the
+% first place, but there's so many layers that that is hard to do.
+%
+\def\setref#1#2{{%
+ \indexdummies
+ \dosetq{#1-title}{Ytitle}%
+ \dosetq{#1-pg}{Ypagenumber}%
+ \dosetq{#1-snt}{#2}
+}}
+
+% @xref, @pxref, and @ref generate cross-references. For \xrefX, #1 is
+% the node name, #2 the name of the Info cross-reference, #3 the printed
+% node name, #4 the name of the Info file, #5 the name of the printed
+% manual. All but the node name can be omitted.
+%
+\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]}
+\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]}
+\def\ref#1{\xrefX[#1,,,,,,,]}
+\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
+ \def\printedmanual{\ignorespaces #5}%
+ \def\printednodename{\ignorespaces #3}%
+ \setbox1=\hbox{\printedmanual}%
+ \setbox0=\hbox{\printednodename}%
+ \ifdim \wd0 = 0pt
+ % No printed node name was explicitly given.
+ \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
+ % Use the node name inside the square brackets.
+ \def\printednodename{\ignorespaces #1}%
+ \else
+ % Use the actual chapter/section title appear inside
+ % the square brackets. Use the real section title if we have it.
+ \ifdim \wd1 > 0pt
+ % It is in another manual, so we don't have it.
+ \def\printednodename{\ignorespaces #1}%
+ \else
+ \ifhavexrefs
+ % We know the real title if we have the xref values.
+ \def\printednodename{\refx{#1-title}{}}%
+ \else
+ % Otherwise just copy the Info node name.
+ \def\printednodename{\ignorespaces #1}%
+ \fi%
+ \fi
+ \fi
+ \fi
+ %
+ % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
+ % insert empty discretionaries after hyphens, which means that it will
+ % not find a line break at a hyphen in a node names. Since some manuals
+ % are best written with fairly long node names, containing hyphens, this
+ % is a loss. Therefore, we give the text of the node name again, so it
+ % is as if TeX is seeing it for the first time.
+ \ifdim \wd1 > 0pt
+ \putwordsection{} ``\printednodename'' in \cite{\printedmanual}%
+ \else
+ % _ (for example) has to be the character _ for the purposes of the
+ % control sequence corresponding to the node, but it has to expand
+ % into the usual \leavevmode...\vrule stuff for purposes of
+ % printing. So we \turnoffactive for the \refx-snt, back on for the
+ % printing, back off for the \refx-pg.
+ {\normalturnoffactive
+ % Only output a following space if the -snt ref is nonempty; for
+ % @unnumbered and @anchor, it won't be.
+ \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
+ \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
+ }%
+ % [mynode],
+ [\printednodename],\space
+ % page 3
+ \turnoffactive \putwordpage\tie\refx{#1-pg}{}%
+ \fi
+\endgroup}
+
+% \dosetq is the interface for calls from other macros
+
+% Use \normalturnoffactive so that punctuation chars such as underscore
+% and backslash work in node names. (\turnoffactive doesn't do \.)
+\def\dosetq#1#2{%
+ {\let\folio=0
+ \normalturnoffactive
+ \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}%
+ \iflinks
+ \next
+ \fi
+ }%
+}
+
+% \internalsetq {foo}{page} expands into
+% CHARACTERS 'xrdef {foo}{...expansion of \Ypage...}
+% When the aux file is read, ' is the escape character
+
+\def\internalsetq #1#2{'xrdef {#1}{\csname #2\endcsname}}
+
+% Things to be expanded by \internalsetq
+
+\def\Ypagenumber{\folio}
+
+\def\Ytitle{\thissection}
+
+\def\Ynothing{}
+
+\def\Ysectionnumberandtype{%
+\ifnum\secno=0 \putwordChapter\xreftie\the\chapno %
+\else \ifnum \subsecno=0 \putwordSection\xreftie\the\chapno.\the\secno %
+\else \ifnum \subsubsecno=0 %
+\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno %
+\else %
+\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno %
+\fi \fi \fi }
+
+\def\Yappendixletterandtype{%
+\ifnum\secno=0 \putwordAppendix\xreftie'char\the\appendixno{}%
+\else \ifnum \subsecno=0 \putwordSection\xreftie'char\the\appendixno.\the\secno %
+\else \ifnum \subsubsecno=0 %
+\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno %
+\else %
+\putwordSection\xreftie'char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno %
+\fi \fi \fi }
+
+\gdef\xreftie{'tie}
+
+% Use TeX 3.0's \inputlineno to get the line number, for better error
+% messages, but if we're using an old version of TeX, don't do anything.
+%
+\ifx\inputlineno\thisisundefined
+ \let\linenumber = \empty % Non-3.0.
+\else
+ \def\linenumber{\the\inputlineno:\space}
+\fi
+
+% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
+% If its value is nonempty, SUFFIX is output afterward.
+
+\def\refx#1#2{%
+ \expandafter\ifx\csname X#1\endcsname\relax
+ % If not defined, say something at least.
+ \angleleft un\-de\-fined\angleright
+ \iflinks
+ \ifhavexrefs
+ \message{\linenumber Undefined cross reference `#1'.}%
+ \else
+ \ifwarnedxrefs\else
+ \global\warnedxrefstrue
+ \message{Cross reference values unknown; you must run TeX again.}%
+ \fi
+ \fi
+ \fi
+ \else
+ % It's defined, so just use it.
+ \csname X#1\endcsname
+ \fi
+ #2% Output the suffix in any case.
+}
+
+% This is the macro invoked by entries in the aux file.
+%
+\def\xrdef#1{\begingroup
+ % Reenable \ as an escape while reading the second argument.
+ \catcode`\\ = 0
+ \afterassignment\endgroup
+ \expandafter\gdef\csname X#1\endcsname
+}
+
+% Read the last existing aux file, if any. No error if none exists.
+\def\readauxfile{\begingroup
+ \catcode`\^^@=\other
+ \catcode`\^^A=\other
+ \catcode`\^^B=\other
+ \catcode`\^^C=\other
+ \catcode`\^^D=\other
+ \catcode`\^^E=\other
+ \catcode`\^^F=\other
+ \catcode`\^^G=\other
+ \catcode`\^^H=\other
+ \catcode`\^^K=\other
+ \catcode`\^^L=\other
+ \catcode`\^^N=\other
+ \catcode`\^^P=\other
+ \catcode`\^^Q=\other
+ \catcode`\^^R=\other
+ \catcode`\^^S=\other
+ \catcode`\^^T=\other
+ \catcode`\^^U=\other
+ \catcode`\^^V=\other
+ \catcode`\^^W=\other
+ \catcode`\^^X=\other
+ \catcode`\^^Z=\other
+ \catcode`\^^[=\other
+ \catcode`\^^\=\other
+ \catcode`\^^]=\other
+ \catcode`\^^^=\other
+ \catcode`\^^_=\other
+ \catcode`\@=\other
+ \catcode`\^=\other
+ % It was suggested to define this as 7, which would allow ^^e4 etc.
+ % in xref tags, i.e., node names. But since ^^e4 notation isn't
+ % supported in the main text, it doesn't seem desirable. Furthermore,
+ % that is not enough: for node names that actually contain a ^
+ % character, we would end up writing a line like this: 'xrdef {'hat
+ % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
+ % argument, and \hat is not an expandable control sequence. It could
+ % all be worked out, but why? Either we support ^^ or we don't.
+ %
+ % The other change necessary for this was to define \auxhat:
+ % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
+ % and then to call \auxhat in \setq.
+ %
+ \catcode`\~=\other
+ \catcode`\[=\other
+ \catcode`\]=\other
+ \catcode`\"=\other
+ \catcode`\_=\other
+ \catcode`\|=\other
+ \catcode`\<=\other
+ \catcode`\>=\other
+ \catcode`\$=\other
+ \catcode`\#=\other
+ \catcode`\&=\other
+ \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
+ % Make the characters 128-255 be printing characters
+ {%
+ \count 1=128
+ \def\loop{%
+ \catcode\count 1=\other
+ \advance\count 1 by 1
+ \ifnum \count 1<256 \loop \fi
+ }%
+ }%
+ % The aux file uses ' as the escape (for now).
+ % Turn off \ as an escape so we do not lose on
+ % entries which were dumped with control sequences in their names.
+ % For example, 'xrdef {$\leq $-fun}{page ...} made by @defun ^^
+ % Reference to such entries still does not work the way one would wish,
+ % but at least they do not bomb out when the aux file is read in.
+ \catcode`\{=1
+ \catcode`\}=2
+ \catcode`\%=\other
+ \catcode`\'=0
+ \catcode`\\=\other
+ %
+ \openin 1 \jobname.aux
+ \ifeof 1 \else
+ \closein 1
+ \input \jobname.aux
+ \global\havexrefstrue
+ \global\warnedobstrue
+ \fi
+ % Open the new aux file. TeX will close it automatically at exit.
+ \openout\auxfile=\jobname.aux
+\endgroup}
+
+
+% Footnotes.
+
+\newcount \footnoteno
+
+% The trailing space in the following definition for supereject is
+% vital for proper filling; pages come out unaligned when you do a
+% pagealignmacro call if that space before the closing brace is
+% removed. (Generally, numeric constants should always be followed by a
+% space to prevent strange expansion errors.)
+\def\supereject{\par\penalty -20000\footnoteno =0 }
+
+% @footnotestyle is meaningful for info output only.
+\let\footnotestyle=\comment
+
+\let\ptexfootnote=\footnote
+
+{\catcode `\@=11
+%
+% Auto-number footnotes. Otherwise like plain.
+\gdef\footnote{%
+ \global\advance\footnoteno by \@ne
+ \edef\thisfootno{$^{\the\footnoteno}$}%
+ %
+ % In case the footnote comes at the end of a sentence, preserve the
+ % extra spacing after we do the footnote number.
+ \let\@sf\empty
+ \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi
+ %
+ % Remove inadvertent blank space before typesetting the footnote number.
+ \unskip
+ \thisfootno\@sf
+ \footnotezzz
+}%
+
+% Don't bother with the trickery in plain.tex to not require the
+% footnote text as a parameter. Our footnotes don't need to be so general.
+%
+% Oh yes, they do; otherwise, @ifset and anything else that uses
+% \parseargline fail inside footnotes because the tokens are fixed when
+% the footnote is read. --karl, 16nov96.
+%
+\long\gdef\footnotezzz{\insert\footins\bgroup
+ % We want to typeset this text as a normal paragraph, even if the
+ % footnote reference occurs in (for example) a display environment.
+ % So reset some parameters.
+ \interlinepenalty\interfootnotelinepenalty
+ \splittopskip\ht\strutbox % top baseline for broken footnotes
+ \splitmaxdepth\dp\strutbox
+ \floatingpenalty\@MM
+ \leftskip\z@skip
+ \rightskip\z@skip
+ \spaceskip\z@skip
+ \xspaceskip\z@skip
+ \parindent\defaultparindent
+ %
+ % Hang the footnote text off the number.
+ \hang
+ \textindent{\thisfootno}%
+ %
+ % Don't crash into the line above the footnote text. Since this
+ % expands into a box, it must come within the paragraph, lest it
+ % provide a place where TeX can split the footnote.
+ \footstrut
+ \futurelet\next\fo@t
+}
+\def\fo@t{\ifcat\bgroup\noexpand\next \let\next\f@@t
+ \else\let\next\f@t\fi \next}
+\def\f@@t{\bgroup\aftergroup\@foot\let\next}
+\def\f@t#1{#1\@foot}
+\def\@foot{\strut\egroup}
+
+}%end \catcode `\@=11
+
+% Set the baselineskip to #1, and the lineskip and strut size
+% correspondingly. There is no deep meaning behind these magic numbers
+% used as factors; they just match (closely enough) what Knuth defined.
+%
+\def\lineskipfactor{.08333}
+\def\strutheightpercent{.70833}
+\def\strutdepthpercent {.29167}
+%
+\def\setleading#1{%
+ \normalbaselineskip = #1\relax
+ \normallineskip = \lineskipfactor\normalbaselineskip
+ \normalbaselines
+ \setbox\strutbox =\hbox{%
+ \vrule width0pt height\strutheightpercent\baselineskip
+ depth \strutdepthpercent \baselineskip
+ }%
+}
+
+% @| inserts a changebar to the left of the current line. It should
+% surround any changed text. This approach does *not* work if the
+% change spans more than two lines of output. To handle that, we would
+% have adopt a much more difficult approach (putting marks into the main
+% vertical list for the beginning and end of each change).
+%
+\def\|{%
+ % \vadjust can only be used in horizontal mode.
+ \leavevmode
+ %
+ % Append this vertical mode material after the current line in the output.
+ \vadjust{%
+ % We want to insert a rule with the height and depth of the current
+ % leading; that is exactly what \strutbox is supposed to record.
+ \vskip-\baselineskip
+ %
+ % \vadjust-items are inserted at the left edge of the type. So
+ % the \llap here moves out into the left-hand margin.
+ \llap{%
+ %
+ % For a thicker or thinner bar, change the `1pt'.
+ \vrule height\baselineskip width1pt
+ %
+ % This is the space between the bar and the text.
+ \hskip 12pt
+ }%
+ }%
+}
+
+% For a final copy, take out the rectangles
+% that mark overfull boxes (in case you have decided
+% that the text looks ok even though it passes the margin).
+%
+\def\finalout{\overfullrule=0pt}
+
+% @image. We use the macros from epsf.tex to support this.
+% If epsf.tex is not installed and @image is used, we complain.
+%
+% Check for and read epsf.tex up front. If we read it only at @image
+% time, we might be inside a group, and then its definitions would get
+% undone and the next image would fail.
+\openin 1 = epsf.tex
+\ifeof 1 \else
+ \closein 1
+ % Do not bother showing banner with post-v2.7 epsf.tex (available in
+ % doc/epsf.tex until it shows up on ctan).
+ \def\epsfannounce{\toks0 = }%
+ \input epsf.tex
+\fi
+%
+\newif\ifwarnednoepsf
+\newhelp\noepsfhelp{epsf.tex must be installed for images to
+ work. It is also included in the Texinfo distribution, or you can get
+ it from ftp://ftp.tug.org/tex/epsf.tex.}
+%
+% Only complain once about lack of epsf.tex.
+\def\image#1{%
+ \ifx\epsfbox\undefined
+ \ifwarnednoepsf \else
+ \errhelp = \noepsfhelp
+ \errmessage{epsf.tex not found, images will be ignored}%
+ \global\warnednoepsftrue
+ \fi
+ \else
+ \imagexxx #1,,,\finish
+ \fi
+}
+%
+% Arguments to @image:
+% #1 is (mandatory) image filename; we tack on .eps extension.
+% #2 is (optional) width, #3 is (optional) height.
+% #4 is just the usual extra ignored arg for parsing this stuff.
+\def\imagexxx#1,#2,#3,#4\finish{%
+ % \epsfbox itself resets \epsf?size at each figure.
+ \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
+ \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
+ % If the image is by itself, center it.
+ \ifvmode
+ \nobreak\medskip
+ \nobreak
+ \centerline{\epsfbox{#1.eps}}%
+ \bigbreak
+ \else
+ \epsfbox{#1.eps}%
+ \fi
+}
+
+
+\message{paper sizes,}
+% And other related parameters.
+
+\newdimen\defaultparindent \defaultparindent = 15pt
+
+\chapheadingskip = 15pt plus 4pt minus 2pt
+\secheadingskip = 12pt plus 3pt minus 2pt
+\subsecheadingskip = 9pt plus 2pt minus 2pt
+
+% Prevent underfull vbox error messages.
+\vbadness = 10000
+
+% Don't be so finicky about underfull hboxes, either.
+\hbadness = 2000
+
+% Following George Bush, just get rid of widows and orphans.
+\widowpenalty=10000
+\clubpenalty=10000
+
+% Use TeX 3.0's \emergencystretch to help line breaking, but if we're
+% using an old version of TeX, don't do anything. We want the amount of
+% stretch added to depend on the line length, hence the dependence on
+% \hsize. This makes it come to about 9pt for the 8.5x11 format. We
+% call this whenever the paper size is set.
+%
+\def\setemergencystretch{%
+ \ifx\emergencystretch\thisisundefined
+ % Allow us to assign to \emergencystretch anyway.
+ \def\emergencystretch{\dimen0}%
+ \else
+ \emergencystretch = \hsize
+ \divide\emergencystretch by 45
+ \fi
+}
+
+% Parameters in order: 1) textheight; 2) textwidth; 3) voffset;
+% 4) hoffset; 5) binding offset; 6) topskip. Then whoever calls us can
+% set \parskip and call \setleading for \baselineskip.
+%
+\def\internalpagesizes#1#2#3#4#5#6{%
+ \voffset = #3\relax
+ \topskip = #6\relax
+ \splittopskip = \topskip
+ %
+ \vsize = #1\relax
+ \advance\vsize by \topskip
+ \outervsize = \vsize
+ \advance\outervsize by 2\topandbottommargin
+ \pageheight = \vsize
+ %
+ \hsize = #2\relax
+ \outerhsize = \hsize
+ \advance\outerhsize by 0.5in
+ \pagewidth = \hsize
+ %
+ \normaloffset = #4\relax
+ \bindingoffset = #5\relax
+ %
+ \parindent = \defaultparindent
+ \setemergencystretch
+}
+
+% @letterpaper (the default).
+\def\letterpaper{{\globaldefs = 1
+ \parskip = 3pt plus 2pt minus 1pt
+ \setleading{13.2pt}%
+ %
+ % If page is nothing but text, make it come out even.
+ \internalpagesizes{46\baselineskip}{6in}{\voffset}{.25in}{\bindingoffset}{36pt}%
+}}
+
+% Use @smallbook to reset parameters for 7x9.5 (or so) format.
+\def\smallbook{{\globaldefs = 1
+ \parskip = 2pt plus 1pt
+ \setleading{12pt}%
+ %
+ \internalpagesizes{7.5in}{5.in}{\voffset}{.25in}{\bindingoffset}{16pt}%
+ %
+ \lispnarrowing = 0.3in
+ \tolerance = 700
+ \hfuzz = 1pt
+ \contentsrightmargin = 0pt
+ \deftypemargin = 0pt
+ \defbodyindent = .5cm
+ %
+ \let\smalldisplay = \smalldisplayx
+ \let\smallexample = \smalllispx
+ \let\smallformat = \smallformatx
+ \let\smalllisp = \smalllispx
+}}
+
+% Use @afourpaper to print on European A4 paper.
+\def\afourpaper{{\globaldefs = 1
+ \setleading{12pt}%
+ \parskip = 3pt plus 2pt minus 1pt
+ %
+ \internalpagesizes{53\baselineskip}{160mm}{\voffset}{4mm}{\bindingoffset}{44pt}%
+ %
+ \tolerance = 700
+ \hfuzz = 1pt
+}}
+
+% A specific text layout, 24x15cm overall, intended for A4 paper. Top margin
+% 29mm, hence bottom margin 28mm, nominal side margin 3cm.
+\def\afourlatex{{\globaldefs = 1
+ \setleading{13.6pt}%
+ %
+ \afourpaper
+ \internalpagesizes{237mm}{150mm}{3.6mm}{3.6mm}{3mm}{7mm}%
+ %
+ \globaldefs = 0
+}}
+
+% Use @afourwide to print on European A4 paper in wide format.
+\def\afourwide{%
+ \afourpaper
+ \internalpagesizes{9.5in}{6.5in}{\hoffset}{\normaloffset}{\bindingoffset}{7mm}%
+ %
+ \globaldefs = 0
+}
+
+% @pagesizes TEXTHEIGHT[,TEXTWIDTH]
+% Perhaps we should allow setting the margins, \topskip, \parskip,
+% and/or leading, also. Or perhaps we should compute them somehow.
+%
+\def\pagesizes{\parsearg\pagesizesxxx}
+\def\pagesizesxxx#1{\pagesizesyyy #1,,\finish}
+\def\pagesizesyyy#1,#2,#3\finish{{%
+ \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
+ \globaldefs = 1
+ %
+ \parskip = 3pt plus 2pt minus 1pt
+ \setleading{13.2pt}%
+ %
+ \internalpagesizes{#1}{\hsize}{\voffset}{\normaloffset}{\bindingoffset}{44pt}%
+}}
+
+% Set default to letter.
+%
+\letterpaper
+
+\message{and turning on texinfo input format.}
+
+% Define macros to output various characters with catcode for normal text.
+\catcode`\"=\other
+\catcode`\~=\other
+\catcode`\^=\other
+\catcode`\_=\other
+\catcode`\|=\other
+\catcode`\<=\other
+\catcode`\>=\other
+\catcode`\+=\other
+\def\normaldoublequote{"}
+\def\normaltilde{~}
+\def\normalcaret{^}
+\def\normalunderscore{_}
+\def\normalverticalbar{|}
+\def\normalless{<}
+\def\normalgreater{>}
+\def\normalplus{+}
+
+% This macro is used to make a character print one way in ttfont
+% where it can probably just be output, and another way in other fonts,
+% where something hairier probably needs to be done.
+%
+% #1 is what to print if we are indeed using \tt; #2 is what to print
+% otherwise. Since all the Computer Modern typewriter fonts have zero
+% interword stretch (and shrink), and it is reasonable to expect all
+% typewriter fonts to have this, we can check that font parameter.
+%
+\def\ifusingtt#1#2{\ifdim \fontdimen3\the\font=0pt #1\else #2\fi}
+
+% Turn off all special characters except @
+% (and those which the user can use as if they were ordinary).
+% Most of these we simply print from the \tt font, but for some, we can
+% use math or other variants that look better in normal text.
+
+\catcode`\"=\active
+\def\activedoublequote{{\tt\char34}}
+\let"=\activedoublequote
+\catcode`\~=\active
+\def~{{\tt\char126}}
+\chardef\hat=`\^
+\catcode`\^=\active
+\def^{{\tt \hat}}
+
+\catcode`\_=\active
+\def_{\ifusingtt\normalunderscore\_}
+% Subroutine for the previous macro.
+\def\_{\leavevmode \kern.06em \vbox{\hrule width.3em height.1ex}}
+
+\catcode`\|=\active
+\def|{{\tt\char124}}
+\chardef \less=`\<
+\catcode`\<=\active
+\def<{{\tt \less}}
+\chardef \gtr=`\>
+\catcode`\>=\active
+\def>{{\tt \gtr}}
+\catcode`\+=\active
+\def+{{\tt \char 43}}
+%\catcode 27=\active
+%\def^^[{$\diamondsuit$}
+
+% Set up an active definition for =, but don't enable it most of the time.
+{\catcode`\==\active
+\global\def={{\tt \char 61}}}
+
+\catcode`+=\active
+\catcode`\_=\active
+
+% If a .fmt file is being used, characters that might appear in a file
+% name cannot be active until we have parsed the command line.
+% So turn them off again, and have \everyjob (or @setfilename) turn them on.
+% \otherifyactive is called near the end of this file.
+\def\otherifyactive{\catcode`+=\other \catcode`\_=\other}
+
+\catcode`\@=0
+
+% \rawbackslashxx output one backslash character in current font
+\global\chardef\rawbackslashxx=`\\
+%{\catcode`\\=\other
+%@gdef@rawbackslashxx{\}}
+
+% \rawbackslash redefines \ as input to do \rawbackslashxx.
+{\catcode`\\=\active
+@gdef@rawbackslash{@let\=@rawbackslashxx }}
+
+% \normalbackslash outputs one backslash in fixed width font.
+\def\normalbackslash{{\tt\rawbackslashxx}}
+
+% Say @foo, not \foo, in error messages.
+\escapechar=`\@
+
+% \catcode 17=0 % Define control-q
+\catcode`\\=\active
+
+% Used sometimes to turn off (effectively) the active characters
+% even after parsing them.
+@def@turnoffactive{@let"=@normaldoublequote
+@let\=@realbackslash
+@let~=@normaltilde
+@let^=@normalcaret
+@let_=@normalunderscore
+@let|=@normalverticalbar
+@let<=@normalless
+@let>=@normalgreater
+@let+=@normalplus}
+
+@def@normalturnoffactive{@let"=@normaldoublequote
+@let\=@normalbackslash
+@let~=@normaltilde
+@let^=@normalcaret
+@let_=@normalunderscore
+@let|=@normalverticalbar
+@let<=@normalless
+@let>=@normalgreater
+@let+=@normalplus}
+
+% Make _ and + \other characters, temporarily.
+% This is canceled by @fixbackslash.
+@otherifyactive
+
+% If a .fmt file is being used, we don't want the `\input texinfo' to show up.
+% That is what \eatinput is for; after that, the `\' should revert to printing
+% a backslash.
+%
+@gdef@eatinput input texinfo{@fixbackslash}
+@global@let\ = @eatinput
+
+% On the other hand, perhaps the file did not have a `\input texinfo'. Then
+% the first `\{ in the file would cause an error. This macro tries to fix
+% that, assuming it is called before the first `\' could plausibly occur.
+% Also back turn on active characters that might appear in the input
+% file name, in case not using a pre-dumped format.
+%
+@gdef@fixbackslash{@ifx\@eatinput @let\ = @normalbackslash @fi
+ @catcode`+=@active @catcode`@_=@active}
+
+% These look ok in all fonts, so just make them not special. The @rm below
+% makes sure that the current font starts out as the newly loaded cmr10
+@catcode`@$=@other @catcode`@%=@other @catcode`@&=@other @catcode`@#=@other
+
+@textfonts
+@rm
+
+@c Local variables:
+@c eval: (add-hook 'write-file-hooks 'time-stamp)
+@c page-delimiter: "^\\\\message"
+@c time-stamp-start: "def\\\\texinfoversion{"
+@c time-stamp-format: "%:y-%02m-%02d"
+@c time-stamp-end: "}"
+@c End:
diff --git a/avl-1.4.0/thread-test.c b/avl-1.4.0/thread-test.c
new file mode 100644
index 0000000..20eead4
--- /dev/null
+++ b/avl-1.4.0/thread-test.c
@@ -0,0 +1,142 @@
+/* libavl - manipulates AVL trees.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The author may be contacted at <pfaffben@pilot.msu.edu> on the
+ Internet, or as Ben Pfaff, 12167 Airport Rd, DeWitt MI 48820, USA
+ through more mundane means. */
+
+/* This is file thread-test.c in libavl. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "avl.h"
+#include "avlt.h"
+#include "avltr.h"
+
+#if __GNUC__ >= 2
+#define unused __attribute__ ((unused))
+#else
+#define unused
+#endif
+
+/* Compare two integers A and B and return a strcmp()-type result. */
+int
+compare_ints (const void *a, const void *b, void unused *param)
+{
+ return ((int) a) - ((int) b);
+}
+
+/* Arrange the N elements of ARRAY in random order. */
+void
+shuffle (int *array, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ int j = i + rand () % (n - i);
+ int t = array[j];
+ array[j] = array[i];
+ array[i] = t;
+ }
+}
+
+
+/* Simple stress test procedure for the AVL tree threading/unthreading
+ routines. */
+#define TREE_SIZE 1024
+#define N_ITERATIONS 16
+int
+main (int argc, char **argv)
+{
+ int array[TREE_SIZE];
+ int seed;
+ int iteration;
+
+ if (argc == 2)
+ seed = atoi (argv[1]);
+ else
+ seed = time (0) * 257 % 32768;
+
+ fputs ("Testing threading and unthreading...\n", stdout);
+ for (iteration = 1; iteration <= N_ITERATIONS; iteration++)
+ {
+ avl_tree *tree;
+ avl_traverser trav = AVL_TRAVERSER_INIT;
+ void **nodep = NULL;
+ void *node;
+ int i;
+
+ printf ("Iteration %4d/%4d: seed=%5d", iteration, N_ITERATIONS, seed);
+ fflush (stdout);
+
+ srand (seed++);
+
+ for (i = 0; i < TREE_SIZE; i++)
+ array[i] = i + 1;
+ shuffle (array, TREE_SIZE);
+
+ tree = avl_create (compare_ints, NULL);
+ for (i = 0; i < TREE_SIZE; i++)
+ avl_force_insert (tree, (void *) (array[i]));
+
+ shuffle (array, TREE_SIZE);
+ for (i = 0; i < TREE_SIZE; i++)
+ {
+ avlt_tree *t;
+ avltr_tree *tr;
+
+ avl_delete (tree, (void *) (array[i]));
+
+ while ((node = avl_traverse (tree, &trav)) != NULL);
+
+ t = avlt_thread (tree);
+ while ((nodep = avlt_next (t, nodep)) != NULL);
+ while ((nodep = avlt_prev (t, nodep)) != NULL);
+ avlt_unthread (t);
+
+ tr = avltr_thread (tree);
+ while ((nodep = avltr_next (tr, nodep)) != NULL);
+ avltr_unthread (tr);
+
+ while ((node = avl_traverse (tree, &trav)) != NULL);
+
+ if (i % 128 == 0)
+ {
+ putchar ('.');
+ fflush (stdout);
+ }
+ }
+ fputs (" good.\n", stdout);
+
+ avl_destroy (tree, NULL);
+ }
+
+ return 0;
+}
+
+/*
+ Local variables:
+ compile-command: "gcc -W -Wall -I. -o ./thread-test thread-test.c avl.c avlt.c avltr.c"
+ End:
+*/