diff --git a/COPYING b/COPYING
new file mode 100644
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  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
+them 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 prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  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.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey 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;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If 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 convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU 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 that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  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.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+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.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     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
+state 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) <year>  <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 3 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, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program 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, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU 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 Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/Data/Yaml/Simple.hs b/Data/Yaml/Simple.hs
new file mode 100644
--- /dev/null
+++ b/Data/Yaml/Simple.hs
@@ -0,0 +1,67 @@
+{-
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual Generator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+-- | Simpler yaml interface
+module Data.Yaml.Simple where
+
+import Data.Yaml.Syck (YamlNode (..), YamlElem (..), unpackBuf)
+
+import qualified Data.Yaml.Syck as S
+
+import qualified Data.Map as M
+import Data.Map (Map)
+
+import Control.Arrow
+
+-- | Things that can be encoded as YAML
+class Yamlable y where
+   from_yaml :: Yaml -> IO y
+
+-- | Yaml
+data Yaml =
+   YMap (Map Yaml Yaml)
+   | YSeq [Yaml]
+   | YStr String
+   | YNil
+   deriving (Show, Eq, Ord)
+
+-- | Simplify Syck's yaml type
+simplify :: YamlNode -> Yaml
+simplify yaml = 
+   case n_elem yaml of
+      EMap l -> YMap $ M.fromList $ map (simplify *** simplify) l
+      ESeq l -> YSeq $ map simplify l
+      EStr b -> YStr $ unpackBuf b
+      ENil   -> YNil
+
+-- | Parse yaml
+parse_yaml :: String -> IO Yaml
+parse_yaml = fmap simplify . S.parseYaml
+
+-- | Parse yaml file
+parse_yaml_file :: FilePath -> IO Yaml
+parse_yaml_file = fmap simplify . S.parseYamlFile
+
+-- | Look up a yaml element referenced by a string in a yaml map
+yookup :: String -> Yaml -> Maybe Yaml
+yookup key yaml =
+   case yaml of
+      YMap m -> M.lookup (YStr key) m
+      _      -> Nothing
diff --git a/Manual.hs b/Manual.hs
new file mode 100644
--- /dev/null
+++ b/Manual.hs
@@ -0,0 +1,60 @@
+{-
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual Generator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+-- | Read and output manuals
+module Manual
+   (OutputType (..)
+   ,load_manual
+   ,write_manual
+   ,formats
+   ,text_format
+   ,xhtml_format) where
+
+import Manual.Reader
+import Manual.Emit
+import Manual.Structure
+
+import System.FilePath
+
+import Data.Map (Map)
+import qualified Data.Map as M
+
+-- | The output types
+data OutputType =
+     XHtml
+   | Text
+   deriving (Eq, Ord)
+
+
+-- | Write in a number of formats
+formats :: Map OutputType (Manual -> String, String)
+formats = M.fromList [(XHtml, xhtml_format)
+                     ,(Text, text_format)]
+
+xhtml_format :: (Manual -> String, String)
+xhtml_format = (emit_xhtml, "html")
+
+text_format :: (Manual -> String, String)
+text_format = (emit_text, "txt")
+
+-- | Write out a manual
+write_manual :: (Manual -> String) -> String -> Manual -> FilePath -> IO ()
+write_manual format ext man fil =
+   writeFile (fil `addExtension` ext) $ format man
diff --git a/Manual/Emit.hs b/Manual/Emit.hs
new file mode 100644
--- /dev/null
+++ b/Manual/Emit.hs
@@ -0,0 +1,40 @@
+{-
+
+Copyright 2010 John Morrice
+
+This source file is part of The Simple Nice Manual Generator and is distributed under the terms of the GNU General Public License
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual enerator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+-- | Emit manuals
+module Manual.Emit where
+
+import Manual.Emit.XHTML
+import Manual.Emit.Text
+import Manual.Structure
+
+import Text.Pretty
+
+-- | Emit a manual as text
+emit_text :: Manual -> String
+emit_text = pretty
+
+-- | Emit a manual as rendered xhtml
+emit_xhtml :: Manual -> String
+emit_xhtml = render_manual_xhtml 
diff --git a/Manual/Emit/Text.hs b/Manual/Emit/Text.hs
new file mode 100644
--- /dev/null
+++ b/Manual/Emit/Text.hs
@@ -0,0 +1,114 @@
+{-
+
+Copyright 2010 John Morrice
+
+This source file is part of The Simple Nice Manual Generator and is distributed under the terms of the GNU General Public License
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual enerator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+-- | Pretty print manuals as text
+module Manual.Emit.Text where
+
+import Manual.Structure
+
+import Text.Pretty
+
+import Data.List
+
+contents :: [Section] -> Contents
+contents =
+   Contents . gather_sections
+
+gather_sections :: [Section] -> [Contents]
+gather_sections ss = 
+   concatMap subsection_contents $ 
+      sortBy (\s1 s2 -> number s1 `compare` number s2) ss
+
+subsection_contents :: Section -> [Contents]
+subsection_contents s =
+   if null $ subsections s
+      then [me]
+      else [me , Contents $ gather_sections (subsections s)]
+   where
+   me = Entry (number s) (pretty $ title s) (unique s)
+
+
+instance Pretty Contents where
+   pretty' c sp =
+      case c of
+         Entry nums name _ -> pspace sp . pretty_nums nums . ((' ' : name) ++)
+         Contents cs -> pretty_list' cs $ sp + 1
+
+-- Pretty print manuals
+instance Pretty Manual where
+   pretty' man _ =
+      pretty' (header man) 0 . nl . nl . 
+         pretty' (mcontents man) (-1) . nl . nl . nl .
+            pretty_list' (sections man) 0
+
+instance Pretty Section where
+   pretty' sec _ =
+      pretty_nums (number sec) . (' ' :) . pretty' (title sec) 0 . nl . nl . 
+         pretty_list_nl' (stext sec) 0 . nl . nl . nl .
+            (if null $ subsections sec
+               then id
+               else pretty_list' (subsections sec) 0)
+
+mock_shows :: String -> ShowS
+mock_shows s = (s ++) 
+
+-- Prettify the section's number.
+pretty_nums :: [Int] -> ShowS
+pretty_nums nums = (intercalate "." (map show nums) ++) . ('.' :)
+
+instance Pretty Paragraph where
+   pretty' par _ =
+      pretty_list' (ptext par) 0
+
+-- | Copyright notice
+copy_notice :: String -> String
+copy_notice cp = "Copyright " ++ cp
+
+-- | License notice
+license_notice :: String -> String
+license_notice lic = "Distributed under terms of the " ++ lic ++ "."
+
+-- | License file notice
+license_file_notice :: String -> String
+license_file_notice fi = "See the file " ++ fi ++  " for details."
+
+instance Pretty Header where
+   pretty' head _ =
+      pretty' (mtitle head) 0 . nl . nl . nl .
+           pretty_list_nl' (banners head) 0 . nl . nl . nl .
+           pretty_list_nl' (preamble head) 0
+
+instance Pretty Banner where
+   pretty' ban _ =
+      pretty_list' (btext ban) 0
+
+instance Pretty Inline where
+   pretty' inline _ =
+      case inline of
+         IText str -> mock_shows str
+         ISectionLink text dest -> mock_shows text
+         IExternLink text dest -> mock_shows text . mock_shows " (see " . mock_shows dest . mock_shows ")"
+         -- IIndent -> mock_shows "   "
+         -- ILine -> nl
+         ILiteral t -> mock_shows t
diff --git a/Manual/Emit/XHTML.hs b/Manual/Emit/XHTML.hs
new file mode 100644
--- /dev/null
+++ b/Manual/Emit/XHTML.hs
@@ -0,0 +1,138 @@
+{-
+
+Copyright 2010 John Morrice
+
+This source file is part of The Simple Nice Manual Generator and is distributed under the terms of the GNU General Public License
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual enerator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+module Manual.Emit.XHTML where
+
+import Manual.Structure
+import Manual.Emit.Text
+
+import Text.Pretty
+
+import Text.XHtml.Strict hiding (header,title,style)
+import qualified Text.XHtml.Strict as X
+
+import Data.Char
+
+-- | Render the manual as XHTML and show as a string
+render_manual_xhtml :: Manual -> String
+render_manual_xhtml = showHtml . toHtml
+
+-- The manual can be converted to html
+instance HTML Manual where
+   toHtml man =
+      X.header (concatHtml [meta ! [httpequiv "Content-Type"
+                                   ,content "text/html;charset=utf-8"]
+                           , thetitle $ stringToHtml $ pretty $ mtitle $ header man
+                           , X.style (primHtml $ style man) ! [thetype "text/css"]]) +++ 
+         (body $ concatHtml $ toHtml (header man) : toHtml (mcontents man) : map toHtml (sections man))
+
+-- The header can be converted to html
+instance HTML Header where
+   toHtml head = concatHtml $
+      (h1 (toHtml $ mtitle head) ! intro_ban_class (mtitle head)) : map (\b -> (h2 $ toHtml b) ! intro_ban_class b) (banners head) ++ map toHtml (preamble head)
+
+-- | Get the banner class for banners in the introduction
+intro_ban_class :: Banner -> [HtmlAttr]
+intro_ban_class = ban_class "intro_banner"
+
+-- The contents
+instance HTML Contents where
+   toHtml = paragraph . hcontents (-1)
+
+nbsp :: Html
+nbsp = spaceHtml
+
+hcontents :: Int -> Contents -> Html
+hcontents i c =
+   case c of
+      Contents cs -> concatHtml $ map (hcontents $ i + 1) cs
+      Entry nums str unique ->
+         let sname = section_name nums str
+         in  concatHtml $ replicate (3 * i) nbsp ++ [section_link sname unique, br]
+
+section_title :: [Int] -> Banner -> String -> Html
+section_title nums section unique = 
+   (h2 $ (anchor $ stringToHtml (pretty_nums nums " ") +++ toHtml section) ! [name unique]) ! section_ban_class section
+
+section_name :: [Int] -> String -> String 
+section_name nums section = pretty_nums nums " " ++ section
+
+-- A section can be converted to html
+instance HTML Section where
+   toHtml sec = concatHtml $
+      section_title (number sec) (title sec) (unique sec) : map toHtml (stext sec) ++ map toHtml (subsections sec)
+
+instance HTML Paragraph where
+   toHtml para =
+      paragraph (concatHtml $ map (html_inline (wrap para)) (ptext para)) ! [theclass $ pclass para]
+
+-- Convert banners into html
+instance HTML Banner where
+   toHtml ban =
+      concatHtml $ map (html_inline True) (btext ban)
+
+-- | Banners for the sections
+section_ban_class :: Banner -> [HtmlAttr]
+section_ban_class = ban_class "banner"
+
+-- | The banner's class
+ban_class :: String -> Banner -> [HtmlAttr]
+ban_class def ban = [theclass cls]
+   where
+   cls = 
+      if null $ bclass ban
+         then def
+         else bclass ban      
+
+-- | Make an inline element into html   
+html_inline :: Bool -> Inline -> Html
+html_inline wrap inline = 
+      case inline of
+         IText str -> (if wrap then stringToHtml else literal_spaces . stringToHtmlString) str
+         ISectionLink text dest -> section_link text dest
+         IExternLink text dest  -> extern_link text dest
+     --    IIndent -> concatHtml $ replicate 3 nbsp
+   --      ILine -> br
+         ILiteral t -> primHtml t
+
+-- | Convert all spaces and newlines into literal html spaces and newlines.
+literal_spaces :: String -> Html
+literal_spaces = concatHtml . map literal_space
+   where
+   literal_space c =
+      case c of
+         ' ' -> nbsp 
+         '\t' -> concatHtml $ replicate 6 nbsp
+         '\n' -> br
+         _    -> primHtml [c]
+         
+         
+
+-- | Internal link to elsewhere in the document
+section_link :: String -> URL -> Html
+section_link text dest = toHtml $ hotlink ('#':dest) (stringToHtml text)
+
+-- | External link to something else
+extern_link :: String -> URL -> Html
+extern_link text dest = toHtml $ hotlink dest (stringToHtml text)
diff --git a/Manual/Reader.hs b/Manual/Reader.hs
new file mode 100644
--- /dev/null
+++ b/Manual/Reader.hs
@@ -0,0 +1,309 @@
+{-
+
+Copyright 2010 John Morrice
+
+This source file is part of The Simple Nice Manual Generator and is distributed under the terms of the GNU General Public License
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual enerator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+-- | Read a manual from its source files
+module Manual.Reader where
+
+import Manual.Structure
+-- You'd think it's pretty weird that the Reader would import the Emitter, but it's to manufacture the contents
+import Manual.Emit.Text
+
+import Data.Yaml.Simple
+
+import Text.Parsec
+import Text.Parsec.String
+
+import Data.Either
+import Data.Maybe
+import Data.List
+
+import Error.Report
+
+import Safe
+
+import System.FilePath
+import System.Directory
+
+import qualified Data.Set as S
+
+import Control.Monad
+import Control.Exception hiding (try)
+
+
+-- | Parse an inline element
+inline :: Parser Inline
+inline =
+   try text <|> try section_link <|> try extern_link <|> try iliteral -- <|> try iindent <|>  iline
+   where
+   iliteral = do
+      char '{'
+      spaces
+      string "literal"
+      spaces
+      text <- many1 $ noneOf "\n\t\r}"
+      spaces
+      char '}'
+      return $ ILiteral text
+
+   text :: Parser Inline
+   text = fmap IText $
+      try (many1 $ noneOf "\\{") <|> 
+         try (string "\\{" >> return "{") <|>
+            (fmap return $ char '\\')
+
+   section_link = link "section" ISectionLink
+   extern_link = link "external" IExternLink
+   link name f = do
+      char '{'
+      spaces
+      string name
+      space
+      spaces
+      fst_elem <- many1 $ noneOf " \n\t\r"
+      spaces
+      rest <- sepEndBy1 end_id (space >> spaces)
+      spaces
+      char '}'
+      let uniq = last rest
+          txt = unwords $ fst_elem : init rest
+      return $ f txt uniq
+      where
+      end_id = many1 $ noneOf " \n\t\r}"
+
+-- | Parse inline elements
+eparse_inline :: String -> Either ParseError [Inline]
+eparse_inline txt =
+   if null txt
+      then Right [IText ""]
+      else 
+         parse (do
+            is <- many1 inline
+            eof
+            return is) "" txt
+
+-- | Parse inline elements
+parse_inline :: String -> IO [Inline]
+parse_inline txt = evaluate $
+   either (throw . error_line "Error while parsing inline elements from paragraph beginning:" . error_section . 
+             error_line (unwords (take 5 $ words txt) ++ "...") . error_section . (flip error_lines empty_error) . lines . show) 
+          id
+          (eparse_inline txt)
+
+-- I say the orphan instances are okay because this is a module EXCLUSIVELY for reading in the manual
+
+-- Read a banner from a yaml description
+instance Yamlable Banner where
+   from_yaml y =
+      case y of
+         YStr s -> liftM2 Banner (parse_inline s) (return "") 
+         YMap _ -> let mcls = yookup "class" y in do
+            clss <- maybe (return "")
+                          (evaluate . fromMaybe (berror "Error parsing class field.  Must be a string.") . ystr) mcls
+            txt <- maybe (return [])
+                         (maybe (evaluate $ berror "Error parsing text field.") parse_inline . ystr) $ yookup "text" y
+
+            when (null txt) $ evaluate $ berror "Banner text cannot be empty"
+            evaluate $ Banner txt clss
+         _      -> berror "Banner must be a string or a map."
+      where
+      berror msg = throw $ 
+         error_line "Error while reading Banner: " $
+            error_section $ error_line msg $ error_section $ 
+               error_lines ["Reading yaml:", show y] $ empty_error
+
+
+-- Convert a yaml description of a paragraph into a paragraph.
+instance Yamlable Paragraph where
+   from_yaml y =
+      case y of
+         YStr s ->
+            liftM3 Paragraph (parse_inline s) (return "") (return True)
+         YMap m -> let mw = yookup "wrap" y 
+                       mcls = yookup "class" y in do
+           
+            wrap <- maybe (return True) 
+                         (evaluate . fromMaybe (perror "Error parsing wrap field.  Must be True or False.") .  
+                             (\y -> ystr y >>= (readMay :: String -> Maybe Bool))) mw
+            
+            clss <- maybe (return "")
+                          (evaluate . fromMaybe (perror "Error parsing class field.  Must be a string.") . ystr) mcls
+            
+            liftM3 Paragraph (parse_inline $ ptext "text") (evaluate clss) (evaluate wrap)
+         _      -> throw $ new_error "Paragraph must be a string or a map"
+      where
+      -- Look up paragraph text from a map
+      ptext :: String -> String
+      ptext nm =
+         yext (yookup nm y) (perror $ "Could not find field '" ++ nm ++ "' in paragraph map.  Must have members 'text' and 'class'")
+
+      perror msg = throw $ 
+         error_line "Error while reading Paragraph: " $
+            error_section $ error_line msg $ error_section $ 
+               error_lines ["Reading yaml:", show y] $ empty_error
+
+-- | Read a string from maybe a yaml
+yext :: Maybe Yaml -> String -> String
+yext y str = fromMaybe str $ y >>= ystr
+
+ystr :: Yaml -> Maybe String
+ystr y =
+   case y of
+      YStr s -> Just s
+      _      -> Nothing
+
+ymap :: (Yaml -> a) -> Yaml -> Maybe [a]
+ymap f y =
+   case y of
+      YSeq ys -> Just $ map f ys
+      _       -> Nothing
+
+instance Yamlable Section where
+   from_yaml y = do
+      mps <- paras $ yookup "text" y
+      ps <- maybe (serror "text") evaluate mps
+      liftM5 Section (evaluate [snumber $ yookup "number" y])
+              (stitle $ yookup "title" y)
+              (evaluate $ read_key (serror "unique") $ yookup "unique" y)
+              (return ps)
+              (return [])
+      where
+      snumber a = 
+         fromMaybe (serror "number")  $ a >>= ystr >>= readMay 
+
+      stitle =
+         read_mbanner (serror "title")
+
+      serror msg = throw $ 
+         error_line "Error while reading Section:" $ error_section $
+            error_line ("Section did not have a valid '" ++ msg ++ "' member.") $ error_section $
+               error_lines ["Reading yaml:", show y] empty_error
+
+-- | Read a banner from what might be some yaml
+read_mbanner :: Banner -> Maybe Yaml -> IO Banner
+read_mbanner ba =
+   maybe (evaluate ba) from_yaml
+
+read_key :: String -> Maybe Yaml -> String 
+read_key err ma = not_empty err $ yext ma err
+
+not_empty :: String -> String -> String
+not_empty nm str =
+   if null str
+      then nm
+      else str
+
+-- | Load a section and all associated subsections.
+load_section :: FilePath -> IO Section
+load_section sfp = load_section_nums sfp [] 
+
+-- | Catch errors while reading files
+catch_read_errs :: String -> IO a -> IO a
+catch_read_errs msg act =
+   act `catches` [Handler reporth, Handler anyh]
+   where
+   reporth :: Error -> a
+   reporth e = throw $ ewhere e
+   ewhere = error_line msg . error_section
+   anyh :: SomeException -> a
+   anyh e = throw $ ewhere $ error_lines (lines $ show e) empty_error
+   
+-- | Load a section and all associated subsections.
+load_section_nums :: FilePath
+             -> [Int]
+             -> IO Section
+load_section_nums fp nums = catch_read_errs ("Error in section file " ++ fp) $ do
+   root <- parse_yaml_file fp
+   un_root_section <- from_yaml root
+   let new_nums = number un_root_section ++ nums
+       root_section = un_root_section {number = reverse new_nums}
+       subsection_dir = dropExtensions fp
+   subsections_exist <- doesDirectoryExist subsection_dir
+   if subsections_exist
+      then do
+         subsect_fs <- getDirectoryFiles subsection_dir
+         subsects <- mapM (flip load_section_nums new_nums) subsect_fs
+         return $ root_section {subsections = sort_sections subsects}
+      else
+         evaluate root_section
+   where
+   dir = dropFileName fp
+
+sort_sections :: [Section] -> [Section]
+sort_sections = 
+   sortBy (\s1 s2 -> number s1 `compare` number s2)
+
+paras :: Maybe Yaml -> IO (Maybe [Paragraph])
+paras ma =
+   maybe (return Nothing) next ma
+   where
+   next :: Yaml -> IO (Maybe [Paragraph])
+   next y =
+      case y of
+         YStr t -> fmap (Just . return) $ from_yaml y
+         y -> maybe (return Nothing) (fmap Just . sequence) $ ymap from_yaml y
+
+-- Load a header file
+instance Yamlable Header where
+   from_yaml y = let mb = yookup "banners" y in do
+      bs <- maybe (return []) (\ybs ->
+         case ybs of
+            YStr _ -> fmap return $ from_yaml ybs
+            YSeq ys -> mapM from_yaml ys
+            YMap _   -> fmap return $ from_yaml ybs
+            _       -> herror "banner") mb
+      liftM3 Header title
+                    (evaluate bs)
+                    preamble
+      where
+      title = read_mbanner (herror "title") $ yookup "title" y
+      preamble = fmap (fromMaybe []) $ paras $ yookup "preamble" y
+      herror nm = throw $ 
+         error_line "Error while reading Header:" $
+            error_section $ error_line ("Header did not have valid '" ++ nm ++ "' field.") $ error_section $ 
+               error_lines ["Reading yaml:", show y] empty_error
+
+-- | Get the qualified names of files in a directory
+getDirectoryFiles :: FilePath -> IO [FilePath]
+getDirectoryFiles dir = do
+   fs <- fmap (map (combine dir) . filter (\f -> head f /= '.')) $ getDirectoryContents dir
+   filterM doesFileExist fs
+
+-- | Load a manual from a directory
+load_manual :: FilePath -> IO Manual
+load_manual man_dir = do
+   fs <- getDirectoryFiles man_dir
+   let files = S.fromList fs
+       sfs = S.delete headf $ S.delete css_file $ files 
+       headf = combine man_dir "header.yaml"
+   catch_read_errs ("Error creating manual from source directory '" ++ man_dir ++ "':") (load_data headf files sfs)
+   where
+   load_data headf files sfs = do
+      css <- if S.member css_file files then readFile css_file else return ""
+      if S.member headf files
+         then do
+            head <- parse_yaml_file headf >>= from_yaml
+            sections <- fmap sort_sections $ mapM load_section $ S.toList sfs
+            evaluate $ Manual head css (contents sections) sections
+         else throw $ new_error "Header not present"
+   css_file = man_dir `combine` "style" `addExtension` "css"
diff --git a/Manual/Structure.hs b/Manual/Structure.hs
new file mode 100644
--- /dev/null
+++ b/Manual/Structure.hs
@@ -0,0 +1,118 @@
+{-
+
+Copyright 2010 John Morrice
+
+This source file is part of The Simple Nice Manual Generator and is distributed under the terms of the GNU General Public License
+
+This file is part of The Simple Nice Manual Generator.
+
+    The Simple Nice Manual Generator 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 3 of the License, or any later version.
+
+    The Simple Nice Manual Generator 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 The Simple Nice Manual Generator.  
+    If not, see <http://www.gnu.org/licenses/>
+
+-}
+
+-- | The structure of a manual
+module Manual.Structure where
+
+import System.FilePath
+import System.Directory
+
+import Data.List
+
+-- | We just see a CSS file as a string
+type CSS = String
+
+-- | A banner for the top of the document
+data Banner = Banner 
+   {btext :: ![Inline]
+   ,bclass :: !String}
+   deriving Show
+
+-- | A manual's header file
+data Header = Header 
+   { -- | The name of the manual
+     mtitle :: !Banner
+   , -- | Banners
+     banners :: ![Banner]
+   , -- | Preamble, not linked in the manual's contents.
+     preamble :: ![Paragraph] 
+   }
+   deriving Show
+
+-- | Inline document elements may be...
+data Inline =
+     -- | A text string
+     IText String
+   | -- | A link to another section
+     ISectionLink
+     { -- | The link text.
+       ltext :: String
+     , -- | The section number
+       ldest :: String 
+     }
+   | -- | An external link.
+     IExternLink
+     { -- | The link text.
+       ltext :: String
+     , -- | The link destination.
+       ldest :: String
+     }
+   | -- | Literal text
+     ILiteral String
+   deriving Show
+
+-- | A text paragraph
+data Paragraph = Paragraph
+   { -- | The paragraph text
+     ptext :: ![Inline]
+   , -- | The paragraph's class
+     pclass :: String
+   , -- | Wrap the text
+     wrap :: Bool
+   } 
+   deriving Show
+
+-- | A manual
+data Manual = Manual
+   { -- | The manual's header file.
+     header :: Header
+   , -- | The style used in the manual.
+     style  :: CSS
+   , -- | The manual's contents.
+     mcontents :: Contents
+   , -- | The sections of a manual.
+     sections :: ![Section]
+   }
+   deriving Show
+
+-- | Sections, subsections
+data Section = Section
+   { -- | The section's number.
+     number :: [Int]
+   , -- | The title of the section
+    title :: Banner 
+   , -- | Unique name for this section
+    unique :: String
+   , -- | The section text
+    stext :: ![Paragraph]
+     -- | Subsections
+   , subsections :: ![Section]
+   }
+   deriving Show
+
+-- | Contents listing
+data Contents = 
+   Contents [Contents]
+   | Entry [Int] String String
+   deriving Show
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,3 @@
+import Distribution.Simple
+
+main = defaultMain
diff --git a/bin/snm.hs b/bin/snm.hs
new file mode 100644
--- /dev/null
+++ b/bin/snm.hs
@@ -0,0 +1,156 @@
+-- Generate simple and nice looking manuals
+
+import Manual
+
+import System.Environment
+import System.Console.GetOpt
+
+import Data.Maybe
+
+import Data.List
+
+import System.FilePath
+
+import Control.Monad
+
+import Data.Map (Map)
+import qualified Data.Map as M
+
+import Data.Maybe
+
+import System.IO
+
+-- Flags determine how we should behave
+data ManFlag =
+     Dump
+   | OutputFile (Maybe String)
+   | OutputType {out_type :: OutputType}
+   | Help
+   deriving Eq
+
+
+-- Match only output types
+only_types :: ManFlag -> Bool
+only_types (OutputType _) = True
+only_types _ = False
+
+-- Match only output flag
+only_output :: ManFlag -> Bool
+only_output (OutputFile _) = True
+only_output _ = False
+
+-- Get the output file
+output_dir :: FilePath -> ManFlag -> FilePath
+output_dir defaul flg =
+   case flg of
+      OutputFile ms -> fromMaybe defaul ms
+      _             -> error "Bug in snm.hs::output_dir!\nContact John Morrice at spoon@killersmurf.com"
+
+-- The order of the arguments
+order :: ArgOrder ManFlag 
+order = Permute
+
+-- The options we use
+options :: [OptDescr ManFlag]
+options =
+   [dump, output_file, help, text_out, xhtml_out]
+
+-- The user is requesting help
+help :: OptDescr ManFlag
+help =
+   Option "h" ["help"] (NoArg Help) "Print usage information"
+
+-- The user requests output in xhtml
+xhtml_out :: OptDescr ManFlag
+xhtml_out =
+   Option "x" ["xhtml", "html"] (NoArg $ OutputType XHtml) "Output in xhtml format." 
+
+-- The user requests output in text
+text_out :: OptDescr ManFlag
+text_out =
+   Option "t" ["text", "txt"] (NoArg $ OutputType Text) "Text output."
+
+-- The user requests ouput dumped to stdout
+dump :: OptDescr ManFlag
+dump = 
+   Option "d" ["dump"] (NoArg Dump) "Print output to stdout."
+
+-- The user requests output dumped to file
+output_file :: OptDescr ManFlag
+output_file =
+   Option "o" ["output"] (OptArg OutputFile "A file name") "Write output to a file.  Multiple outputs ignored, printing warning to stderr."
+
+-- Print usage information
+usage :: IO ()
+usage = do
+   nm <- getProgName
+   putStrLn $ usageInfo 
+      (unlines [nm ++ ": The Simple Nice-Looking Manual Generator"
+              ,"\nusage: "
+              ,"   " ++ nm ++ " documentation_source_directory options*"
+              ,"\nWhere options* stands for zero or more of the options below."
+              ,"\nNote:"
+              ,"   Only one output format is permitted per invocation."
+              ,"   If -d or --dump is used, snm will not write a file unless -o or --output is also used."
+              ,"   There can be no whitespace between -o and its argument, nor can there be whitespace between --output= and its argument"
+              ,"   If no arguments are given to -o, then the file written will have the same filename as the documentation source directory, with an appropriate extension added."
+              ,"   " ++ nm ++ " will always add an appropriate extension to output files." 
+              ,"   By default, snm will emit xhtml, and act as if the user had specified -o without an argument."])
+      options
+
+
+-- "Make it so" - Jean Luc Picard. 
+main :: IO ()
+main = do
+   -- get the args
+   as <- getArgs
+   -- get the options
+   let (unclean_flags, non, err) = getOpt order options as
+       -- clean the flags
+       flags = nub unclean_flags
+       user_output = msum $ map (flip M.lookup formats) $ map out_type $ filter only_types flags
+
+       output = fromMaybe (xhtml_format) user_output
+   -- terminate if there were errors
+   if null err
+      then do
+         case non of
+            (input:[]) -> do
+               man <- load_manual input 
+               -- did the user tell us what to do?
+               if null flags
+                  then
+                     uncurry (undirected input man) output
+                  else
+                     if elem Help flags
+                        then usage
+                        else 
+                           uncurry (directed input man flags input) output
+            _ -> usage
+      else 
+         usage
+      where
+     
+      -- The user has specified what to do
+      directed input man flags defaul format ext = do
+         let outs = filter only_output flags
+             dump = elem Dump flags 
+         -- dump the text if dump is present
+         when dump $ putStrLn $ format man
+         mout <- case outs of
+                    (out:[]) -> return $ Just out
+                    (out:n:_) -> do
+                       hPutStrLn stderr 
+                                 ("Warning: multiple outputs ignored.")
+                       return (Just out)
+                    _        -> if dump then return Nothing else return $ Just $ OutputFile Nothing
+         maybe (return ()) 
+               (\out ->
+                  write_manual format ext man $ output_dir defaul out)
+               mout
+
+      -- The default behaviour
+      undirected input man format ext =
+         write_manual format ext man (dropExtensions $ takeFileName input)
+
+
diff --git a/snm.cabal b/snm.cabal
new file mode 100644
--- /dev/null
+++ b/snm.cabal
@@ -0,0 +1,45 @@
+Name:           snm 
+Version:	0.0.1
+Cabal-Version:  >= 1.2
+License:	GPL-3
+License-File:   COPYING	
+Author:		John Morrice <spoon@killersmurf.com>
+Maintainer:	John Morrice <spoon@killersmurf.com>
+Category:	Documentation
+Synopsis:       The Simple Nice-Looking Manual Generator.
+Description:
+		snm allows you to write clean, web-friendly reports, user guides and manuals without having to edit fickle html.
+		.
+		snm allows you to structure your document in a modular fashion.
+		.
+		snm document sections are written in yaml and are easy to write and understand.
+		.
+		snm is a generator of small, valid xhtml files.
+
+Build-type:	Simple
+Homepage:	http://github.com/elginer/snm
+Cabal-version:	>=1.4
+
+Extra-source-files: 
+   snm_help.html
+
+Library
+   Build-Depends: base>=4 && < 5, parsec>=3, filepath, directory, containers, HsSyck, spoonutil, safe, xhtml
+   Exposed-modules:
+      Data.Yaml.Simple
+      Manual.Structure
+      Manual.Reader
+      Manual.Emit
+      Manual.Emit.Text
+      Manual.Emit.XHTML
+      Manual
+
+Executable snm
+   Main-is: bin/snm.hs
+   Build-Depends: base>=4, parsec>=3, filepath, directory, containers, HsSyck, spoonutil, safe
+   Other-modules:
+      Data.Yaml.Simple
+      Manual.Structure
+      Manual.Reader
+      Manual.Emit
+      Manual
diff --git a/snm_help.html b/snm_help.html
new file mode 100644
--- /dev/null
+++ b/snm_help.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>The Simple Nice-Looking Manual Generator</title><style type="text/css">/* 
+  Copyright John Morrice 2010
+  This document is part of The Simple Nice-Looking Manual Generator documentation
+  This document is released under the terms of the GNU Free Documentation Licence
+  See the file DOC-COPYING.
+*/
+.intro_banner {text-align: center;}
+.example {font-family: monospace; font-size: x-large;}
+body {font: arial; font-family: sans;}
+.boring {font-weight: bold}
+</style></head><body><h1 class="intro_banner">The Simple Nice-Looking Manual Generator</h1><h2 class="intro_banner">Copyright John Morrice 2010</h2><h2 class="intro_banner">Contact spoon@killersmurf.com</h2><p class="boring">This document is released under the terms of the GNU Free Documentation License. See the file <a href="DOC-COPYING">DOC-COPYING</a> for details</p><p class="boring">All snm source code is released under the terms of the GNU General Public Licence Version 3.  See the file <a href="COPYING">COPYING</a> for details.</p><p class="">The Simple Nice-Looking Manual Generator - A.K.A snm - generates nice looking manuals from <a href="http://www.yaml.org/">YAML</a> files.</p><p class="">Currently, it can produce XHTML and text manuals.</p><p class="">snm is <a href="http://github.com/elginer/snm">hosted on github</a></p><p><a href="#what">1. What snm does and is</a><br /><a href="#whatnot">2. What snm does not do and is not</a><br /><a href="#build">3. Building snm</a><br />&nbsp;&nbsp;&nbsp;<a href="#easy">3.1. The Easy Way</a><br />&nbsp;&nbsp;&nbsp;<a href="#hard">3.2. The Hard Way</a><br />&nbsp;&nbsp;&nbsp;<a href="#install">3.3. Install snm to /usr/bin</a><br /><a href="#invoke">4. Invoking snm</a><br /><a href="#how">5. How to use snm</a><br />&nbsp;&nbsp;&nbsp;<a href="#header">5.1. header.yaml</a><br />&nbsp;&nbsp;&nbsp;<a href="#sections">5.2. Sections</a><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#subsections">5.2.1. Subsections</a><br />&nbsp;&nbsp;&nbsp;<a href="#paragraphs">5.3. Paragraphs</a><br />&nbsp;&nbsp;&nbsp;<a href="#banners">5.4. Banners</a><br />&nbsp;&nbsp;&nbsp;<a href="#inline">5.5. Inline Elements</a><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#links">5.5.1. Hyperlinks</a><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#literal">5.5.2. Literal text</a><br />&nbsp;&nbsp;&nbsp;<a href="#style">5.6. Style: CSS</a><br /><a href="#abuse">6. Further help, misuse and shortfalls</a><br /></p><h2 class="banner"><a name="what">1. What snm does and is</a></h2><p class="">snm allows you to write clean, web-friendly reports, user guides and manuals without having to edit fickle html.</p><p class="">snm allows you to structure your document in a modular fashion.</p><p class="">snm document sections are written in yaml and are easy to write and understand.</p><p class="">snm is a generator of small, valid xhtml files.</p><h2 class="banner"><a name="whatnot">2. What snm does not do and is not</a></h2><p class="">snm is not (currently) a man-page generator.</p><p class="">snm is not a web-page creator</p><p class="">snm is not a gui based tool</p><p class="">snm is not an adult activity.</p><h2 class="banner"><a name="build">3. Building snm</a></h2><p class="">First, install <a href="http://yaml.kwiki.org/index.cgi?LibSyck">libsyck</a>.</p><p class="">Then choose to proceed to build snm in either <a href="#easy">The Easy Way</a> or <a href="#hard">The Hard Way</a>.</p><p class="">The hard way is presented to give more information to people who may need it.  The Easy Way is recommended for absolutely everyone else!</p><h2 class="banner"><a name="easy">3.1. The Easy Way</a></h2><p class="">First install <a href="http://hackage.haskell.org/platform/">The Haskell Platform</a>.</p><p class="">Then just do:</p><p class="">cabal install snm</p><p class="">Now <a href="#install">install snm to /usr/bin</a></p><h2 class="banner"><a name="hard">3.2. The Hard Way</a></h2><p class="">To build snm the hard way, you must install:</p><p class=""><a href="http://haskell.org/ghc/">The Glasgow Haskell Compiler</a>.  snm has been tested with GHC 6.10.4</p><p class="">And from <a href="http://hackage.haskell.org">Hackage</a>, the following libraries</p><p class="">base&gt;=4, parsec&gt;=3, filepath, directory, containers, HsSyck, safe, SpoonsUtilities, xhtml</p><p class="">Download the source distribution of snm from github</p><p class="">cd into its directory.</p><p class="">Run:</p><p class="example">&nbsp;&nbsp;&nbsp;cabal&nbsp;install</p><p class="">Now <a href="#install">install snm to /usr/bin</a></p><h2 class="banner"><a name="install">3.3. Install snm to /usr/bin</a></h2><p class="">cabal install typically installs snm into your local cabal directory, usually ~/.cabal/bin/snm</p><p class="">So you'll probably need to:</p><p class="example">&nbsp;&nbsp;&nbsp;sudo&nbsp;cp&nbsp;~/.cabal/bin/snm&nbsp;/usr/bin</p><p class="">Now, try to <a href="#invoke">invoke</a> snm</p><h2 class="banner"><a name="invoke">4. Invoking snm</a></h2><p class="">Once it is <a href="#install">installed</a>, try invoking snm with</p><p class="example">&nbsp;&nbsp;&nbsp;snm&nbsp;--help</p><p class="">If it was successfully installed, you will see some helpful information and a list of snm's command line options:</p><p class="example">&nbsp;&nbsp;&nbsp;snm:&nbsp;The&nbsp;Simple&nbsp;Nice-Looking&nbsp;Manual&nbsp;Generator&nbsp;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;usage:&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;snm&nbsp;documentation_source_directory&nbsp;options*&nbsp;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;Where&nbsp;options*&nbsp;stands&nbsp;for&nbsp;zero&nbsp;or&nbsp;more&nbsp;of&nbsp;the&nbsp;options&nbsp;below.&nbsp;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;Note:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Only&nbsp;one&nbsp;output&nbsp;format&nbsp;is&nbsp;permitted&nbsp;per&nbsp;invocation.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;-d&nbsp;or&nbsp;--dump&nbsp;is&nbsp;used,&nbsp;snm&nbsp;will&nbsp;not&nbsp;write&nbsp;a&nbsp;file&nbsp;unless&nbsp;-o&nbsp;or&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--output&nbsp;is&nbsp;&nbsp;used.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;There&nbsp;can&nbsp;be&nbsp;no&nbsp;whitespace&nbsp;between&nbsp;-o&nbsp;and&nbsp;its&nbsp;argument,&nbsp;nor&nbsp;can&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;there&nbsp;be&nbsp;whitespace&nbsp;between&nbsp;--output=&nbsp;and&nbsp;its&nbsp;argument.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;no&nbsp;arguments&nbsp;are&nbsp;given&nbsp;to&nbsp;-o,&nbsp;then&nbsp;the&nbsp;file&nbsp;written&nbsp;will&nbsp;have&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;same&nbsp;filename&nbsp;as&nbsp;the&nbsp;documentation&nbsp;source&nbsp;directory,&nbsp;with&nbsp;an&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;appropriate&nbsp;extension&nbsp;added.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;snm&nbsp;will&nbsp;always&nbsp;add&nbsp;an&nbsp;appropriate&nbsp;extension&nbsp;to&nbsp;output&nbsp;files.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;By&nbsp;default,&nbsp;snm&nbsp;will&nbsp;produce&nbsp;snm,&nbsp;and&nbsp;act&nbsp;as&nbsp;if&nbsp;the&nbsp;user&nbsp;had&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;specified&nbsp;-o&nbsp;without&nbsp;an&nbsp;argument.&nbsp;<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--dump&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print&nbsp;output&nbsp;to&nbsp;stdout.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-o[A&nbsp;file&nbsp;name]&nbsp;&nbsp;--output[=A&nbsp;file&nbsp;name]&nbsp;&nbsp;Write&nbsp;output&nbsp;to&nbsp;a&nbsp;file.&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Multiple&nbsp;outputs&nbsp;ignored,&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printing&nbsp;warning&nbsp;to&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stderr.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-h&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--help&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print&nbsp;usage&nbsp;information&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--text,&nbsp;--txt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;output.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--xhtml,&nbsp;--html&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Output&nbsp;in&nbsp;xhtml&nbsp;format.</p><h2 class="banner"><a name="how">5. How to use snm</a></h2><p class="">snm generates a manual from a number of yaml files, held in a documentation source directory.  In the snm source distribution, this directory is called 'snm_help'.</p><p class="">This source directory must contain a file called 'header.yaml'.  The next sub-section deals with what you put in header.yaml, and what it means.</p><h2 class="banner"><a name="header">5.1. header.yaml</a></h2><p class="">The header file has 1 required field:</p><p class="example">&nbsp;&nbsp;&nbsp;title:&nbsp;A&nbsp;<a href="#banners">banner</a>,&nbsp;the&nbsp;title&nbsp;of&nbsp;the&nbsp;manual.</p><p class="">The header file has 2 optional fields:</p><p class="example">&nbsp;&nbsp;&nbsp;banners:&nbsp;Zero&nbsp;or&nbsp;more&nbsp;<a href="#banners">banners</a>,&nbsp;used&nbsp;to&nbsp;announce&nbsp;important&nbsp;things&nbsp;at&nbsp;the&nbsp;start&nbsp;of&nbsp;a&nbsp;manual,&nbsp;for&nbsp;example,&nbsp;its&nbsp;author.&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;preamble:&nbsp;Zero&nbsp;or&nbsp;more&nbsp;<a href="#paragraph">paragraphs</a>,&nbsp;which&nbsp;are&nbsp;not&nbsp;included&nbsp;in&nbsp;the&nbsp;manual's&nbsp;<a href="#contents">contents</a>.</p><p class="">For example, here is a slightly simplified version of the header.yaml file for this document:</p><p class="example">&nbsp;&nbsp;&nbsp;title:&nbsp;&quot;The&nbsp;Simple&nbsp;Nice-Looking&nbsp;Manual&nbsp;Generator&quot;&nbsp;<br />&nbsp;&nbsp;&nbsp;banners:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&quot;Copyright&nbsp;John&nbsp;Morrice&nbsp;2010&quot;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&quot;Contact&nbsp;spoon@killersmurf.com&quot;&nbsp;<br />&nbsp;&nbsp;&nbsp;preamble:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&quot;This&nbsp;document&nbsp;is&nbsp;released&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;Free&nbsp;Documentation&nbsp;License.&nbsp;See&nbsp;the&nbsp;file&nbsp;<a href="DOC-COPYING">DOC-COPYING</a>&nbsp;for&nbsp;details&quot;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&quot;All&nbsp;snm&nbsp;source&nbsp;code&nbsp;is&nbsp;released&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;Licence&nbsp;Version&nbsp;3.&nbsp;&nbsp;See&nbsp;the&nbsp;file&nbsp;<a href="COPYING">COPYING</a>&nbsp;for&nbsp;details.&quot;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&quot;The&nbsp;Simple&nbsp;Nice-Looking&nbsp;Manual&nbsp;Generator&nbsp;-&nbsp;A.K.A&nbsp;snm&nbsp;-&nbsp;generates&nbsp;nice&nbsp;looking&nbsp;manuals&nbsp;from&nbsp;<a href="http://www.yaml.org/">YAML</a>&nbsp;files.&quot;&nbsp;<br />&nbsp;&nbsp;-&nbsp;&quot;Currently,&nbsp;it&nbsp;can&nbsp;produce&nbsp;XHTML&nbsp;and&nbsp;text&nbsp;manuals.&quot;</p><p class="">You can see how snm processes this by looking at the <a href="#">top</a> of the document.</p><p class="">When emitting xhtml, the notices displayed at the top of the page are automatically given the css class 'banner'.</p><h2 class="banner"><a name="sections">5.2. Sections</a></h2><p class="">An snm manual, much like other structured documents, is arranged into heirarchical sections and <a href="#subsections">subsections</a>.</p><p class="">Top level sections are described by yaml files in the documentation source directory.</p><p class="">A section file in the top directory can be given any filename, other than <a href="#header">header.yaml</a> and <a href="#style">style.css</a> which are reserved.  This restriction does not apply to subsections.</p><p class="">Each section has 4 required fields:</p><p class="example">&nbsp;&nbsp;&nbsp;title:&nbsp;A&nbsp;<a href="#banners">banner</a>,&nbsp;the&nbsp;title&nbsp;of&nbsp;the&nbsp;section.&nbsp;&nbsp;This&nbsp;section's&nbsp;title&nbsp;is&nbsp;'Sections'&nbsp;<br />&nbsp;&nbsp;&nbsp;number:&nbsp;the&nbsp;number&nbsp;of&nbsp;the&nbsp;section.&nbsp;&nbsp;This&nbsp;section's&nbsp;number&nbsp;is&nbsp;2.&nbsp;<br />&nbsp;&nbsp;&nbsp;unique:&nbsp;A&nbsp;one-word,&nbsp;unique&nbsp;identifier&nbsp;for&nbsp;this&nbsp;section.&nbsp;&nbsp;This&nbsp;is&nbsp;used&nbsp;in&nbsp;constructing&nbsp;<a href="#links">hyperlinks</a>.&nbsp;<br />&nbsp;&nbsp;&nbsp;text:&nbsp;Zero&nbsp;or&nbsp;more&nbsp;<a href="#paragraphs">paragraphs</a>.</p><p class="">For a concrete example, here is the beginning of the section file for this section.</p><p class="example">&nbsp;&nbsp;&nbsp;title:&nbsp;Sections&nbsp;<br />&nbsp;&nbsp;&nbsp;number:&nbsp;2&nbsp;<br />&nbsp;&nbsp;&nbsp;unique:&nbsp;sections&nbsp;<br />&nbsp;&nbsp;&nbsp;text:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;'An&nbsp;snm&nbsp;manual,&nbsp;much&nbsp;like&nbsp;other&nbsp;structured&nbsp;documents,&nbsp;is&nbsp;arranged&nbsp;into&nbsp;heirarchical&nbsp;sections...</p><h2 class="banner"><a name="subsections">5.2.1. Subsections</a></h2><p class="">A section is associated with subsections when the subsection files are located in a directory which has the same filename (excluding extensions) as its section file, in its same directory.</p><p class="">For example, here is a partial listing of this manual's source directory, snm_help:</p><p class="example">&nbsp;&nbsp;&nbsp;snm_help:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header.yaml&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;how&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;how.yaml&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...more&nbsp;files</p><p class="">Note the file 'how.yaml'.  This is the file describing <a href="#how">section 3, How to use snm,</a> of this document.</p><p class="">Note also the directory called how.  This directory contains the subsections associated with how.yaml. Inside the how directory:</p><p class="example">&nbsp;&nbsp;&nbsp;snm_help/how:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;section&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;section.yaml&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...more&nbsp;files</p><p class="">Note the 'section.yaml' file, which describes <a href="#sections">section 3.2, Sections</a> and its associated subsection directory 'section'.</p><p class="">Inside the section directory:</p><p class="example">&nbsp;&nbsp;&nbsp;snm_help/how/section:&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subsection.yaml</p><p class="">how/section/subsection.yaml is the file describing this section.</p><p class="">A subsection's number is automatically computed by snm.  Hence, according to the file describing this section, this section's number is 1.  snm has discovered it is nested within section 3.2.  It is an error to specify a subsection's whole number within a section file.  Specify one number only!</p><h2 class="banner"><a name="paragraphs">5.3. Paragraphs</a></h2><p class="">When a sequence of paragraphs is called for in a manual yaml file, either a single text element, or a yaml <a href="http://yaml.kwiki.org/index.cgi?YamlInFiveMinutesMinuteOne">sequence</a> is expected.</p><p class="">Paragraphs are not just plain text:  they may contain <a href="#inline">inline elements</a> like hyperlinks or literal text.</p><p class="">In a produced manual, a series of paragraphs are rendered with two line breaks between each of them.  This corresponds to two newline characters in a text document, and being within a &lt;p&gt; tag in an html document.  An example:</p><p class="example">&nbsp;&nbsp;&nbsp;This&nbsp;is&nbsp;a&nbsp;valid,&nbsp;although&nbsp;boring,&nbsp;paragraph.</p><p class="">Paragraphs can be associated with a class, using a yaml <a href="http://yaml.kwiki.org/index.cgi?YamlInFiveMinutesMinuteTwo">map</a>.  When rendering xhtml documents, this class is becomes the value of the class attribute for the paragraph produced.  This is useful when working using a <a href="#style">style sheet</a>.  An example:</p><p class="example">&nbsp;&nbsp;&nbsp;class:&nbsp;curved_corner&nbsp;<br />&nbsp;&nbsp;&nbsp;text:&nbsp;This&nbsp;paragraph&nbsp;is&nbsp;a&nbsp;bit&nbsp;more&nbsp;exciting,&nbsp;because&nbsp;it&nbsp;is&nbsp;being&nbsp;given&nbsp;curved&nbsp;corners&nbsp;by&nbsp;css!</p><p class="">Word wrapping can be turned on or off on a paragraph basis, by setting wrap to True or false in a map paragraph.  When emitting xhtml, if wrap is off, then all spaces are replaced by &amp;nbsp; and all new-lines replaced by &lt;br/&gt;.  By default wrapping is on. Example:</p><p class="">This paragraph...</p><p class="example">&nbsp;&nbsp;&nbsp;wrap:&nbsp;False&nbsp;<br />&nbsp;&nbsp;&nbsp;text:&nbsp;&quot;Hey&nbsp;ho,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;let's&nbsp;go!&quot;</p><p class="">Is rendered as:</p><p class="example">&nbsp;&nbsp;&nbsp;&quot;Hey&nbsp;ho,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;let's&nbsp;go!&quot;</p><p class="">But this paragraph...</p><p class="example">&nbsp;&nbsp;&nbsp;wrap:&nbsp;True&nbsp;<br />&nbsp;&nbsp;&nbsp;text:&nbsp;&quot;Hey&nbsp;ho,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;let's&nbsp;go!&quot;</p><p class="">And this paragraph...</p><p class="example">&nbsp;&nbsp;&nbsp;&quot;Hey&nbsp;ho,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;let's&nbsp;go!&quot;</p><p class="">Are rendered as:</p><p class="example">&nbsp;&nbsp;&nbsp;Hey&nbsp;ho,&nbsp;let's&nbsp;go!</p><h2 class="banner"><a name="banners">5.4. Banners</a></h2><p class="">Banners appear at the top of the manual, and at the beginning of sections.</p><p class="">Banners may contain inline elements in the same manner as a paragraph.</p><p class="">Banner defined in the <a href="#header">header</a> file are, by default, given the class 'intro_banner'.  Banners defined in <a href="#sections">sections</a> are given the class 'banner'.</p><p class="">The default banner classes can be replaced by user defined classes, in the same manner that a class can be assigned to a paragraph.</p><h2 class="banner"><a name="inline">5.5. Inline Elements</a></h2><p class="">Inline elements within paragraphs and banners allow more expressive text.  The idea of an inline snm element is roughly equivalent to an inline HTML element.  Much as an xhtml anchor can only appear within an xhtml block element, an inline element can only appear within an snm paragraph or banner.</p><p class="">Inline elements appear within curly braces { }.</p><p class="">If you need to actually write an opening brace in your document, the opening brace may be escaped with a backslash \.</p><p class="">The following inline elements are available: section links, external links and literal text.</p><h2 class="banner"><a name="links">5.5.1. Hyperlinks</a></h2><p class="">snm supports two types of links.</p><p class="">Section links are hyperlinks to a <a href="#sections">section of the document</a>, using that section's unique name.</p><p class="">External links are a more traditional link to a URL.</p><p class="">As an inline element, links begin with an opening curly brace {.</p><p class="">Then either the word 'section', which indicates a section link, or the word 'external' which indicates an external link.</p><p class="">Then the link text.  This may consist of a number of words separated by whitespace.</p><p class="">Then the destination.  No explicit syntax separates the link text from the destination - the last word is taken to be the destination.  Obviously, section links expect a section's unique name, whereas external links expect a URL.</p><p class="">As with all inline elements, a link is closed with a curly brace }.</p><p class="">Whitespace is optional throughout links.</p><p class="">Examples:</p><p class="">The link above, which is a section link to the unique identifier 'sections':</p><p class="example">&nbsp;&nbsp;&nbsp;{section&nbsp;section&nbsp;of&nbsp;the&nbsp;document&nbsp;sections}</p><p class="">The external link in <a href="#paragraphs">section 3.3 Paragraphs</a>, to the 'YAML in Five Minutes' tutorial</p><p class="example">&nbsp;&nbsp;&nbsp;{external&nbsp;sequence&nbsp;http://yaml.kwiki.org/index.cgi?YamlInFiveMinutesMinuteOne}</p><h2 class="banner"><a name="literal">5.5.2. Literal text</a></h2><p class="">Literal text can be specified through the literal inline element.</p><p class="">Literal text is not processed or transformed by snm:  it is output directly into the output document.</p><p class="">This is risky because allows it you to write invalid xhtml, for instance; but it does allow you to write html that snm does not generate.</p><p class="">However, this approach suffers from many problems and is very much a working solution for current needs.  Problems are discussed <a href="#abuse">below</a>.</p><p class="">Example:</p><p class="example">&nbsp;&nbsp;&nbsp;{literal&nbsp;&lt;table&gt;&lt;td&gt;Embed&nbsp;a&nbsp;html&nbsp;table&lt;/td&gt;&lt;/table&gt;}</p><h2 class="banner"><a name="style">5.6. Style: CSS</a></h2><p class="">When generating xhtml, snm will look for a file called 'style.css' in the documentation source directory, and embed the contents of that file into the document's header as a CSS style sheet.</p><h2 class="banner"><a name="abuse">6. Further help, misuse and shortfalls</a></h2><p class="">If you use snm and need more help than is available in this manual then do not hesitate to contact the author at spoon@killersmurf.com.</p><p class="">Please note that snm suffers from a number of shortfalls:</p><p class="">Invalid xhtml can be generated through manipulation of the <a href="#style">style sheet</a>, <a href="#literal">literal text</a>, <a href="#links">link destinations</a>, and the <a href="#sections">unique names of sections</a>.</p><p class="">While I regret that this is possible, attempting xhtml kludges through these means ill-fitting means is misuse of snm and may result in generation shoddy manuals, a telling off and early bed-times all around.  You have been warned!</p></body></html>
