+Unles otherwise stated, this package is licensed according to the following
+terms and conditions:
+
The Simplified BSD License
Copyright (c) 2009, Charles McGarvey
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+------------------------------------------------------------------------------
+
+The "yajl" library is statically linked under the following terms and
+conditions:
+
+Copyright 2007-2009, Lloyd Hilaiel.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ 3. Neither the name of Lloyd Hilaiel nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+------------------------------------------------------------------------------
+
+The "fastevents" code is statically linked, unmodified, under the following
+terms and conditions:
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+\f
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+\f
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+\f
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+\f
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser 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 Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "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
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY 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
+LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+\f
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
--- /dev/null
+# Doxyfile 1.5.8
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+# TAG = value [value, ...]
+# For lists items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME = Yoink
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY =
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek,
+# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish,
+# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene,
+# Spanish, Swedish, and Ukrainian.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF = YES
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 8
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it parses.
+# With this tag you can assign which parser to use for a given extension.
+# Doxygen has a built-in mapping, but you can override or extend it using this tag.
+# The format is ext=language, where ext is a file extension, and language is one of
+# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP,
+# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat
+# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran),
+# use: inc=Fortran f=C
+
+EXTENSION_MAPPING =
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate getter
+# and setter methods for a property. Setting this option to YES (the default)
+# will make doxygen to replace the get and set methods by a property in the
+# documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING = YES
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penality.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will rougly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols
+
+SYMBOL_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespace are hidden.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES = NO
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.
+# This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by
+# doxygen. The layout file controls the global structure of the generated output files
+# in an output format independent way. The create the layout file that represents
+# doxygen's defaults, run doxygen with the -l option. You can optionally specify a
+# file name after the option, if omitted DoxygenLayout.xml will be used as the name
+# of the layout file.
+
+LAYOUT_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = src
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
+
+FILE_PATTERNS =
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+# If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.
+# Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.
+# The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = YES
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code.
+# Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = doc/doxygen
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET =
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
+# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information.
+
+GENERATE_DOCSET = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER
+# are set, an additional index file will be generated that can be used as input for
+# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated
+# HTML documentation.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE =
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add.
+# For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION =
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE = 4
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to FRAME, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
+# probably better off using the HTML help feature. Other possible values
+# for this tag are: HIERARCHIES, which will generate the Groups, Directories,
+# and Class Hierarchy pages using a tree view instead of an ordered list;
+# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which
+# disables this behavior completely. For backwards compatibility with previous
+# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE
+# respectively.
+
+GENERATE_TREEVIEW = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE = 10
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = NO
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.
+# This is useful
+# if you want to understand what is going on.
+# On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
+# the parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+#
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
+# powerful graphs.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = YES
+
+# By default doxygen will write a font called FreeSans.ttf to the output
+# directory and reference it in all dot files that doxygen generates. This
+# font does not include all possible unicode characters however, so when you need
+# these (or just want a differently looking font) you can specify the font name
+# using DOT_FONTNAME. You need need to make sure dot is able to find the font,
+# which can be done by putting it in a standard location or by setting the
+# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory
+# containing the font.
+
+DOT_FONTNAME = FreeSans
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the output directory to look for the
+# FreeSans.ttf font (which doxygen will put there itself). If you specify a
+# different font using DOT_FONTNAME you can set the path where dot
+# can find it using this tag.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK = YES
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT = YES
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
+
+#---------------------------------------------------------------------------
+# Options related to the search engine
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE = NO
-SUBDIRS = src
+SUBDIRS = yajl src
original resources are provided under the zlib/libpng License. See COPYING
for complete details.
+External Dependencies:
+
+GL
+SDL
+SDL_image
+boost
+
AC_PREREQ(2.60)
AC_INIT([yoink],[0.1],[chaz@dogcows.com])
AM_INIT_AUTOMAKE
-AC_CONFIG_SRCDIR([src/yoink.cc])
+AC_CONFIG_SRCDIR([src/YoinkApp.cc])
+AC_PROG_CC
AC_PROG_CXX
-AC_PROG_LIBTOOL
+AC_PROG_RANLIB
AC_PROG_INSTALL
-
AM_PROG_CC_C_O
+
+AC_HEADER_STDC
+
+AC_SEARCH_LIBS([glClear], [GL], [have_opengl=yes])
+if test ! "x${have_opengl}" = xyes
+then
+ AC_MSG_ERROR([libGL is required])
+fi
+
+AC_SEARCH_LIBS([SDL_Init], [SDL], [have_sdl=yes])
+if test ! "x${have_sdl}" = xyes
+then
+ AC_MSG_ERROR([libSDL is required])
+fi
+
+AC_SEARCH_LIBS([IMG_Load], [SDL_image], [have_sdlimage=yes])
+if test ! "x${have_sdlimage}" = xyes
+then
+ AC_MSG_ERROR([libSDL_image is required])
+fi
+
+AC_SEARCH_LIBS([clock_gettime], [rt], [have_librt=yes])
+if test "x${have_librt}" = xyes
+then
+ AC_DEFINE([HAVE_LIBRT], 1, [high-resolution timer enabled])
+fi
+
AC_CONFIG_FILES([Makefile
+ yajl/Makefile
src/Makefile])
AC_OUTPUT
current=`pwd`
cd /
find "$current" \
--iname "*.cc" -o \
--iname "*.h" |sed '/ / s/^\(.*\)/"\1"/' >"$current/cscope.files"
+-iname "*.c" -o \
+-iname "*.h" -o \
+-iname "*.cc" -o \
+-iname "*.hh" |sed '/ / s/^\(.*\)/"\1"/' >"$current/cscope.files"
cd "$current"
--- /dev/null
+<?xml version="1.0" standalone="yes"?>
+<animation name="AlienWarrior" texture="AlienWarrior">
+ <sequence name="Stand" type="Stand" delay="1">
+ <frame index="0" duration="2"/>
+ <frame index="1" duration="0.25"/>
+ <frame index="2" duration="2"/>
+ <frame index="1" duration="0.25"/>
+ </sequence>
+
+ <sequence name="Run" type="Run" delay="0.25">
+ <frame index="3"/>
+ <frame index="4"/>
+ <frame index="5"/>
+ <frame index="6"/>
+ </sequence>
+
+ <sequence name="StopRunning" type="Stand" delay="10" loop="false" next="Stand">
+ <frame index="7"/>
+ </sequence>
+
+ <sequence name="Jump" type="Jump" delay="0.25" next="FlyDiagonallyUp">
+ <frame index="17"/>
+ </sequence>
+
+ <sequence name="Land" type="Stand" delay="1" loop="false" next="Stand">
+ <frame index="13"duration="0.25"/>
+ </sequence>
+
+ <sequence name="FlyDiagonallyUp" type="Fly" delay="0.1">
+ <frame index="18"/>
+ </sequence>
+
+ <sequence name="FlyDiagonallyDown" type="Fly" delay="0.1">
+ <frame index="19"/>
+ </sequence>
+
+ <sequence name="FlyStraightUp" type="Fly" delay="0.1">
+ <frame index="19"/>
+ </sequence>
+
+ <sequence name="FlyHorizontally" type="Fly">
+ <frame index="3"/>
+ </sequence>
+
+ <sequence name="Punch" type="Attack" delay="0.2">
+ <frame index="8"/>
+ <frame index="9"/>
+ </sequence>
+
+ <sequence name="StartFiring" type="Attack" delay="0.1" next="Fire">
+ <frame index="0"/>
+ <frame index="8"/>
+ </sequence>
+
+ <sequence name="Fire" type="Attack" delay="1">
+ <frame index="10" duration="0.2"/>
+ <frame index="11" duration="0.2"/>
+ </sequence>
+
+ <sequence name="StopFiring" type="Attack" delay="0.1" next="Stand">
+ <frame index="8"/>
+ <frame index="0"/>
+ </sequence>
+
+ <sequence name="KnockedDown" type="Hit" delay="0.1" loop="false">
+ <frame index="16"/>
+ <frame index="15"/>
+ </sequence>
+
+ <sequence name="Flattened" type="Hit" delay="1">
+ <frame index="13"/>
+ </sequence>
+</animation>
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="BigExplosion" texture="BigExplosion">\r <sequence name="BigExplosion" delay="0.1" loop="false">\r <frame index="0"/>\r <frame index="1"/>\r <frame index="2"/>\r <frame index="3"/>\r <frame index="4"/>\r <frame index="5"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="Bonuses" texture="Bonuses">\r <sequence name="SmallHealth" delay="0.1">\r <frame index="0"/>\r <frame index="1"/>\r <frame index="2"/>\r <frame index="1"/>\r </sequence>\r\r <sequence name="LargeHealth" delay="0.1">\r <frame index="3"/>\r <frame index="4"/>\r <frame index="5"/>\r <frame index="4"/>\r </sequence>\r\r <sequence name="SmallRedPotion" delay="0.1">\r <frame index="6"/>\r <frame index="7"/>\r <frame index="8"/>\r <frame index="7"/>\r </sequence>\r\r <sequence name="SmallBluePotion" delay="0.1">\r <frame index="9"/>\r <frame index="10"/>\r <frame index="11"/>\r <frame index="10"/>\r </sequence>\r\r <sequence name="FirstAidKit" delay="1.0">\r <frame index="12"/>\r </sequence>\r\r <sequence name="AlienFirstAidKit" delay="1.0">\r <frame index="13"/>\r </sequence>\r\r <sequence name="Cake" delay="1.0">\r <frame index="14"/>\r </sequence>\r\r <sequence name="FizzyDrink" delay="1.0">\r <frame index="15"/>\r </sequence>\r\r <sequence name="Cheese" delay="1.0">\r <frame index="16"/>\r </sequence>\r\r <sequence name="Chocolate" delay="1.0">\r <frame index="17"/>\r </sequence>\r\r <sequence name="MilkBottle" delay="1.0">\r <frame index="18"/>\r </sequence>\r\r <sequence name="OneSadCookie" delay="1.0">\r <frame index="19"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="Bullet" texture="Particles">\r <sequence name="Punch" delay="1.0">\r <!-- This punch sequence is highly bogus. Should be possible to have a sprite with no animation -->\r\r <frame index="31"/>\r </sequence>\r\r <sequence name="SmallBullet" delay="0.05">\r <frame index="16"/>\r <frame index="17"/>\r </sequence>\r\r <sequence name="MediumBullet" delay="0.05">\r <frame index="17"/>\r <frame index="18"/>\r </sequence>\r\r <sequence name="SmallFireball" delay="0.05">\r <frame index="0"/>\r <frame index="1"/>\r </sequence>\r\r <sequence name="MediumFireball" delay="0.05">\r <frame index="2"/>\r <frame index="1"/>\r </sequence>\r\r <sequence name="LargeFireball" delay="0.05">\r <frame index="21"/>\r <frame index="2"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="Effects" texture="Particles">\r <sequence name="Fireball" delay="0.1">\r <frame index="0"/>\r <frame index="1"/>\r <frame index="2"/>\r <frame index="1"/>\r <frame index="0"/>\r </sequence>\r\r <sequence name="Smoke" delay="0.05" loop="false">\r <frame index="4"/>\r <frame index="5"/>\r <frame index="6"/>\r </sequence>\r\r <sequence name="GreenDiamond" delay="0.05">\r <frame index="7"/>\r <frame index="8"/>\r <frame index="9"/>\r <frame index="10"/>\r <frame index="11"/>\r </sequence>\r\r <sequence name="ChargeParticle" delay="0.03" loop="false">\r <frame index="12"/>\r <frame index="13"/>\r <frame index="1"/>\r <frame index="3"/>\r <frame index="14"/>\r <frame index="13"/>\r <frame index="12"/>\r </sequence>\r\r <sequence name="Poof" delay="0.05" loop="false">\r <frame index="23"/>\r <frame index="24"/>\r <frame index="25"/>\r <frame index="26"/>\r <frame index="27"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="Heroine" texture="Heroine">\r <sequence name="Stand" type="Stand" delay="1">\r <frame index="1" duration="4.0"/>\r\r <frame index="3" duration="0.1"/>\r <frame index="1" duration="0.1"/>\r <frame index="3" duration="0.1"/>\r\r <frame index="1" duration="2.0"/>\r\r <frame index="0" duration="2.0"/>\r <frame index="1" duration="0.1"/>\r <frame index="2" duration="2.0"/>\r\r <frame index="1" duration="3.0"/>\r\r <frame index="3" duration="0.1"/>\r <frame index="1" duration="0.1"/>\r <frame index="3" duration="0.1"/>\r\r <frame index="1" duration="2.0"/>\r\r <frame index="0" duration="4.0"/>\r <frame index="1" duration="0.1"/>\r <frame index="2" duration="3.0"/>\r <frame index="1" duration="0.1"/>\r <frame index="0" duration="1.0"/>\r <frame index="1" duration="2.0"/>\r\r <frame index="3" duration="0.1"/>\r <frame index="1" duration="0.1"/>\r <frame index="3" duration="0.1"/>\r </sequence>\r\r <sequence name="Blink" type="Stand" delay="0.25" next="Stand">\r <frame index="3" duration="0.25"/>\r </sequence>\r\r <sequence name="Run" type="Run" delay="0.25">\r <frame index="4"/>\r <frame index="5"/>\r <frame index="6"/>\r <frame index="7"/>\r </sequence>\r\r <sequence name="StopRunning" type="Stand" delay="10" loop="false" next="Stand">\r <frame index="8"/>\r </sequence>\r\r <sequence name="Jump" type="Jump" delay="0.25" next="FlyDiagonallyUp">\r <frame index="9" duration="0.25"/>\r </sequence>\r\r <sequence name="Land" type="Stand" delay="0.5" next="StopRunning">\r <frame index="9" duration="0.25"/>\r </sequence>\r\r <sequence name="FlyDiagonallyUp" type="Fly" delay="0.1">\r <frame index="10"/>\r <frame index="11"/>\r </sequence>\r\r <sequence name="FlyDiagonallyDown" type="Fly" delay="0.1">\r <frame index="12"/>\r <frame index="13"/>\r </sequence>\r\r <sequence name="FlyStraightUp" type="Fly" delay="0.1">\r <frame index="0"/>\r </sequence>\r\r <sequence name="FlyHorizontally" type="Fly" delay="0.1">\r <frame index="4"/>\r <frame index="14"/>\r </sequence>\r\r <sequence name="KnockedDown" type="Hit" delay="0.1">\r <frame index="17"/>\r <frame index="18"/>\r </sequence>\r\r <sequence name="Flattened" type="Hit" delay="1.0">\r <frame index="19"/>\r </sequence>\r\r <sequence name="StartCharging" type="Charge" delay="0.2" next="Charge">\r <frame index="21"/>\r </sequence>\r\r <sequence name="Charge" type="Charge" delay="0.2" loop="false">\r <frame index="22"/>\r </sequence>\r\r <sequence name="FireCharge" type="Charge" delay="0.2">\r <frame index="23"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="Jetbot" texture="Jetbot">\r <sequence name="Stand" type="Stand" delay="1">\r <frame index="0" duration="2"/>\r <frame index="1" duration="0.25"/>\r <frame index="2" duration="2"/>\r <frame index="1" duration="0.25"/>\r </sequence>\r\r <sequence name="Run" type="Run" delay="0.1">\r <frame index="3"/>\r <frame index="4"/>\r </sequence>\r\r <sequence name="StopRunning" type="Stand" delay="10" loop="false" next="Stand">\r <frame index="6"/>\r </sequence>\r\r <sequence name="Jump" type="Jump" delay="0.25" next="FlyDiagonallyUp">\r <frame index="6"/>\r </sequence>\r\r <sequence name="Land" type="Stand" delay="1" loop="false" next="Stand">\r <frame index="6"duration="0.25"/>\r <frame index="0"duration="0.25"/>\r </sequence>\r\r <sequence name="FlyDiagonallyUp" type="Fly" delay="0.1">\r <frame index="3"/>\r <frame index="4"/>\r </sequence>\r\r <sequence name="FlyDiagonallyDown" type="Fly" delay="0.1">\r <frame index="3"/>\r <frame index="4"/>\r </sequence>\r\r <sequence name="FlyStraightUp" type="Fly" delay="0.1">\r <frame index="3"/>\r <frame index="4"/>\r </sequence>\r\r <sequence name="FlyHorizontally" type="Fly" delay="0.1">\r <frame index="3"/>\r <frame index="4"/>\r </sequence>\r\r <sequence name="Punch" type="Attack" delay="0.05" next="Stand">\r <frame index="3"/>\r </sequence>\r\r <sequence name="StartFiring" type="Attack" delay="0.1" next="Fire">\r <frame index="3"/>\r </sequence>\r\r <sequence name="Fire" type="Attack" delay="1.0">\r <frame index="3" duration="0.2"/>\r </sequence>\r\r <sequence name="StopFiring" type="Attack" delay="0.1" next="Stand">\r <frame index="3"/>\r </sequence>\r\r <sequence name="KnockedDown" type="Hit" delay="1.0">\r <frame index="5"/>\r </sequence>\r\r <sequence name="Flattened" type="Hit" delay="1.0">\r <frame index="6"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?> \r<animation name="RobotTrooper" texture="RobotTrooper">\r <sequence name="Stand" type="Stand" delay="1">\r <frame index="0" duration="2"/>\r <frame index="1" duration="0.25"/>\r <frame index="2" duration="2"/>\r <frame index="1" duration="0.25"/>\r </sequence>\r\r <sequence name="Run" type="Run" delay="0.25">\r <frame index="4"/>\r <frame index="5"/>\r <frame index="6"/>\r <frame index="7"/>\r </sequence>\r\r <sequence name="StopRunning" type="Stand" delay="10" loop="false" next="Stand">\r <frame index="5"/>\r </sequence>\r\r <sequence name="Jump" type="Jump" delay="0.25" next="FlyDiagonallyUp">\r <frame index="17"/>\r </sequence>\r\r <sequence name="Land" type="Stand" delay="1" loop="false" next="Stand">\r <frame index="19"duration="0.25"/>\r <frame index="14"duration="0.25"/>\r </sequence>\r\r <sequence name="FlyDiagonallyUp" type="Fly" delay="0.1">\r <frame index="18"/>\r </sequence>\r\r <sequence name="FlyDiagonallyDown" type="Fly" delay="0.1">\r <frame index="18"/>\r </sequence>\r\r <sequence name="FlyStraightUp" type="Fly" delay="0.1">\r <frame index="18"/>\r </sequence>\r\r <sequence name="FlyHorizontally" type="Fly">\r <frame index="18"/>\r </sequence>\r\r <sequence name="Punch" type="Attack" delay="0.05" next="Stand">\r <frame index="8"/>\r <frame index="9"/>\r <frame index="10"/>\r <frame index="11"/>\r <frame index="12"/>\r <frame index="13"/>\r </sequence>\r\r <sequence name="StartFiring" type="Attack" delay="0.1" next="Fire">\r <frame index="14"/>\r <frame index="15"/>\r <frame index="16"/>\r </sequence>\r\r <sequence name="Fire" type="Attack" delay="1.0">\r <frame index="17" duration="0.2"/>\r <frame index="16" duration="0.2"/>\r </sequence>\r\r <sequence name="StopFiring" type="Attack" delay="0.1" next="Stand">\r <frame index="16"/>\r <frame index="15"/>\r <frame index="14"/>\r </sequence>\r\r <sequence name="KnockedDown" type="Hit" delay="1.0">\r <frame index="18"/>\r </sequence>\r\r <sequence name="Flattened" type="Hit" delay="1.0">\r <frame index="19"/>\r </sequence>\r</animation>\r
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" standalone="yes"?>
+<scene name="Test" playfield_bounds="0 0 -100 1280 500 100"
+ maximum_bounds="-800 0 -300 2400 1000 600">
+
+<!-- Left end tower block -->
+
+ <!-- Front -->
+
+ <reset_transform/>
+ <translate>-5 0 5</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap width="5">
+ 2 2 2 2 2
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 1 0 0 1 0
+ 4 4 4 4 4
+ </tilemap>
+
+ <!-- Right side -->
+
+ <reset_transform/>
+ <rotate axis="y">90</rotate>
+ <translate>0 0 5</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="right" width="5">
+ 2 2 2 2 2
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 6
+ 4 5 5 5 4
+ </tilemap>
+
+ <!-- Top -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>-5 15 0</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="top" width="5">
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ </tilemap>
+
+<!-- Leftmost background tower block -->
+
+ <!-- Front -->
+
+ <reset_transform/>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap width="7" detail_level="1">
+ 2 2 2 2 2 2 2
+ 0 1 0 0 0 1 0
+ 0 1 0 0 0 1 0
+ 0 1 0 0 6 1 0
+ 0 1 0 0 0 1 0
+ 0 1 0 0 0 1 0
+ 0 1 0 0 0 1 0
+ 4 4 5 5 5 4 4
+ </tilemap>
+
+ <!-- Right side -->
+
+ <reset_transform/>
+ <rotate axis="y">90</rotate>
+ <translate>7 0 0</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap width="6" detail_level="1">
+ 2 2 2 2 2 2
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 4 4 4 4 4 4
+ </tilemap>
+
+ <!-- Top -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>-2 8 -6</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap width="9" detail_level="1">
+ 3 3 3 3 3 3 3 3 3
+ 3 3 3 3 3 3 3 3 3
+ 3 3 3 3 3 3 3 3 3
+ 3 3 3 3 3 3 3 3 3
+ 3 3 3 3 3 3 3 3 3
+ 3 3 3 3 3 3 3 3 3
+ </tilemap>
+
+<!-- Foreground building with pitched roof -->
+
+ <!-- Left wall -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <translate>10 0 1</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap surface_type="left" width="4">
+ -1 9 11 -1
+ 9 10 12 11
+ 15 7 7 16
+ 3 5 6 4
+ 3 6 5 4
+ </tilemap>
+
+ <!-- Right wall -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <translate>13 0 1</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap surface_type="right" width="4">
+ -1 9 11 -1
+ 9 10 12 11
+ 15 7 7 16
+ 3 5 6 4
+ 3 8 5 4
+ </tilemap>
+
+ <!-- Front wall -->
+
+ <reset_transform/>
+ <translate>10 0 5</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="3">
+ 15 7 16
+ 3 5 4
+ 3 6 4
+ </tilemap>
+
+ <!-- Pitched roof -->
+
+ <reset_transform/>
+ <rotate axis="x">135</rotate>
+ <scale>1 1.5 1.5</scale>
+ <translate>10 5 3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="3">
+ 13 13 13
+ 13 13 13
+ </tilemap>
+
+ <!-- Finial -->
+
+ <reset_transform/>
+ <translate>10 5 3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="3">
+ 18 18 18
+ </tilemap>
+
+ <!-- Cheaty invisible platform -->
+
+ <reset_transform/>
+ <translate>10 4 3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap surface_type="top" width="3">
+ -1 -1 -1
+ </tilemap>
+
+<!-- The ground -->
+
+ <!-- Courtyard -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>-3 0 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap surface_type="top" width="13">
+ 1 1 1 1 1 1 1 1 1 1 1 1 1
+ 1 1 1 1 1 1 1 1 1 1 1 1 1
+ -1 -1 -1 1 0 0 0 0 0 0 0 0 1
+ -1 -1 -1 1 0 0 0 0 0 0 0 0 1
+ -1 -1 -1 1 0 0 0 0 0 0 0 0 1
+ -1 -1 -1 1 0 0 0 0 0 0 0 0 1
+ -1 -1 -1 1 1 1 1 1 1 1 1 1 1
+ </tilemap>
+
+ <!-- Front grass -->
+
+ <reset_transform/>
+ <scale>8 1 1</scale>
+ <translate>1 -0.5 5</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="8" detail_level="2"/>
+
+ <!-- Back grass -->
+
+ <reset_transform/>
+ <scale>8 1 1</scale>
+ <translate>1 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="8" detail_level="2"/>
+
+ <!-- Left grass -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>1 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="4" detail_level="2"/>
+
+ <!-- Right grass -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>9 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="4" detail_level="2"/>
+
+ <!-- Fence behind house -->
+
+ <reset_transform/>
+ <scale>11 1 1</scale>
+ <translate>7 0 0</translate>
+ <scale>32</scale>
+
+ <texture>Scenery</texture>
+ <billboard tile="4" u_scale="11" detail_level="2"/>
+
+<!-- Background building with pitched roof -->
+
+ <!-- Front wall -->
+
+ <reset_transform/>
+ <translate>19 0 0</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="4" detail_level="1">
+ -1 9 11 -1
+ 9 10 12 11
+ 15 7 7 16
+ 3 6 5 4
+ 3 5 6 4
+ 3 8 5 4
+ </tilemap>
+
+ <!-- Left wall -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <translate>19 0 -3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap surface_type="left" width="3" detail_level="1">
+ 15 1 16
+ 3 7 4
+ 3 5 4
+ 3 0 4
+ </tilemap>
+
+ <!-- Right wall -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <translate>23 0 -3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap surface_type="right" width="3" detail_level="1">
+ 15 0 16
+ 3 7 4
+ 3 6 4
+ 3 2 4
+ </tilemap>
+
+ <!-- Left pitched roof -->
+
+ <reset_transform/>
+ <rotate axis="x">135</rotate>
+ <scale>1 1.5 1.5</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>21 6 -3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="3" detail_level="1">
+ 13 13 13
+ 13 13 13
+ </tilemap>
+
+ <!-- Right pitched roof -->
+
+ <reset_transform/>
+ <rotate axis="x">-135</rotate>
+ <scale>1 1.5 1.5</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>21 6 -3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="3" detail_level="1">
+ 13 13 13
+ 13 13 13
+ </tilemap>
+
+ <!-- Finial -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <translate>21 6 -3</translate>
+ <scale>32</scale>
+
+ <texture>Building</texture>
+ <tilemap width="3" detail_level="1">
+ 18 18 18
+ </tilemap>
+
+<!-- More ground to the right -->
+
+ <!-- Ground under house -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>10 0 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap surface_type="top" width="3">
+ 1 1 1
+ 1 1 1
+ -1 -1 -1
+ -1 -1 -1
+ -1 -1 -1
+ -1 -1 -1
+ 1 1 1
+ </tilemap>
+
+ <!-- Left part of centre courtyard -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>13 0 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap surface_type="top" width="8">
+ 1 1 1 1 1 1 1 1
+ 1 1 1 1 1 1 1 1
+ 1 0 0 0 0 0 0 0
+ 1 0 0 0 0 0 1 1
+ 0 0 0 0 0 0 1 1
+ 1 0 0 0 0 0 0 0
+ 1 1 1 1 1 0 0 0
+ </tilemap>
+
+ <!-- Front grass -->
+
+ <reset_transform/>
+ <scale>12 1 1</scale>
+ <translate>14 -0.5 5</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="12" detail_level="2"/>
+
+ <!-- Back grass -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <translate>14 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="4" detail_level="2"/>
+
+ <!-- Front grass next to door -->
+
+ <reset_transform/>
+ <scale>1 1 1</scale>
+ <translate>13 -0.5 3</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="1" detail_level="2"/>
+
+ <!-- Back grass next to door -->
+
+ <reset_transform/>
+ <scale>1 1 1</scale>
+ <translate>13 -0.5 2</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="1" detail_level="2"/>
+
+ <!-- Left grass -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <translate>14 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap width="4" detail_level="2">
+ 2 -1 2 2
+ </tilemap>
+
+ <!-- Grass left of house -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <scale>1 1 1</scale>
+ <translate>18 -0.5 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="1" detail_level="2"/>
+
+ <!-- Grass right of house -->
+
+ <reset_transform/>
+ <rotate axis="y">-90</rotate>
+ <scale>1 1 1</scale>
+ <translate>24 -0.5 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="1" detail_level="2"/>
+
+ <!-- Front grass in centre -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <translate>19 -0.5 4</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="4" detail_level="2"/>
+
+ <!-- Back grass in centre -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <translate>19 -0.5 2</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="4" detail_level="2"/>
+
+ <!-- Left grass in centre -->
+
+ <reset_transform/>
+ <scale>2 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>19 -0.5 2</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="2" detail_level="2"/>
+
+ <!-- Right grass in centre -->
+
+ <reset_transform/>
+ <scale>2 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>23 -0.5 2</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="2" detail_level="2"/>
+
+<!-- Still more ground -->
+
+ <!-- Right part of centre courtyard -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>21 0 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap surface_type="top" width="7">
+ 1 1 1 1 1 0 0
+ 1 1 1 1 1 0 0
+ 0 0 0 0 0 0 0
+ 1 1 0 0 0 0 0
+ 1 1 0 0 0 0 0
+ 0 0 0 0 0 0 0
+ 0 0 0 1 1 1 1
+ </tilemap>
+
+ <!-- Fence to right of back house -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <translate>24 0 0</translate>
+ <scale>32</scale>
+
+ <texture>Scenery</texture>
+ <billboard tile="4" u_scale="4" detail_level="2"/>
+
+ <!-- Grass in front of fence -->
+
+ <reset_transform/>
+ <scale>4 1 1</scale>
+ <translate>24 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="4" detail_level="2"/>
+
+ <!-- Grass to left of tower block -->
+
+ <reset_transform/>
+ <scale>2 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>26 -0.5 5</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="2" detail_level="2"/>
+
+ <!-- Grass to right of tower block -->
+
+ <reset_transform/>
+ <scale>2 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>35 -0.5 5</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="2" detail_level="2"/>
+
+ <!-- Next bit of grass -->
+
+ <reset_transform/>
+ <scale>5 1 1</scale>
+ <translate>35 -0.5 5</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="5" detail_level="2"/>
+
+ <!-- Back grass -->
+
+ <reset_transform/>
+ <scale>6 1 1</scale>
+ <translate>34 -0.5 1</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="6" detail_level="2"/>
+
+ <!-- Extra bit of back grass -->
+
+ <reset_transform/>
+ <scale>1 1 1</scale>
+ <rotate axis="y">-90</rotate>
+ <translate>34 -0.5 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <billboard tile="2" u_scale="1" detail_level="2"/>
+
+ <!-- Ground around tower block -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>28 0 4</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap surface_type="top" width="5">
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ </tilemap>
+
+ <!-- Rightmost ground -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>33 0 0</translate>
+ <scale>32</scale>
+ <texture>Scenery</texture>
+ <tilemap surface_type="top" width="10">
+ 0 0 1 1 1 1 1 1 1 1
+ 0 0 1 1 1 1 1 1 1 1
+ 0 0 0 0 0 0 0 -1 -1 -1
+ 0 0 0 0 0 0 0 -1 -1 -1
+ 0 0 0 0 0 0 0 -1 -1 -1
+ 0 0 0 0 0 0 0 -1 -1 -1
+ 0 1 1 1 1 1 1 -1 -1 -1
+ </tilemap>
+
+<!-- Right foreground tower block -->
+
+ <!-- Front -->
+
+ <reset_transform/>
+ <translate>28 0 4</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap width="5">
+ 2 2 2 2 2
+ 0 0 0 0 0
+ 0 0 0 0 6
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 6 0
+ 4 4 4 4 4
+ </tilemap>
+
+ <!-- Right side -->
+
+ <reset_transform/>
+ <rotate axis="y">90</rotate>
+ <translate>33 0 4</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="right" width="6">
+ 2 2 2 2 2 2
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 5 4 5 5 4 5
+ </tilemap>
+
+ <!-- Left side -->
+
+ <reset_transform/>
+ <rotate axis="y">90</rotate>
+ <translate>28 0 4</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="left" width="6">
+ 2 2 2 2 2 2
+ 0 1 6 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 0 1 0 0 1 0
+ 5 4 5 5 4 5
+ </tilemap>
+
+ <!-- Top -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>28 7 -2</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="top" width="5">
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ </tilemap>
+
+<!-- Right end tower block -->
+
+ <!-- Front -->
+
+ <reset_transform/>
+ <translate>40 0 5</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap width="5">
+ 2 2 2 2 2
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 6 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 6 1 0 0 1
+ 0 1 0 0 1
+ 0 1 0 0 1
+ 4 4 4 4 4
+ </tilemap>
+
+ <!-- Left side -->
+
+ <reset_transform/>
+ <rotate axis="y">90</rotate>
+ <translate>40 0 5</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="left" width="5">
+ 2 2 2 2 2
+ 6 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 6 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 6 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 0 0 0 0 0
+ 4 5 5 5 4
+ </tilemap>
+
+ <!-- Top -->
+
+ <reset_transform/>
+ <rotate axis="x">90</rotate>
+ <translate>40 15 0</translate>
+ <scale>32</scale>
+
+ <texture>TowerBlock1</texture>
+ <tilemap surface_type="top" width="5">
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ 3 3 3 3 3
+ </tilemap>
+
+<!-- Background -->
+
+ <reset_transform/>
+ <translate>-0.3 -0.17 -900</translate>
+ <scale>3200 1600 1</scale>
+ <texture>BackgroundFar</texture>
+ <billboard fog="false"/>
+
+ <translate>0 0 300</translate>
+ <texture>BackgroundNear</texture>
+ <billboard blend="true" fog="false"/>
+
+<!-- Trees -->
+
+ <texture>Trees</texture>
+
+ <!-- Left courtyard -->
+
+ <reset_transform/>
+ <scale>96</scale>
+ <translate>250 -2.5 16</translate>
+
+ <billboard tile="1" detail_level="1"/>
+
+ <!-- Centre courtyard -->
+
+ <reset_transform/>
+ <scale>96</scale>
+ <translate>610 -2.5 85</translate>
+
+ <billboard tile="0"/>
+
+ <reset_transform/>
+ <scale>96</scale>
+ <translate>650 -2.5 115</translate>
+
+ <billboard tile="1"/>
+
+ <!-- Right courtyard -->
+
+ <reset_transform/>
+ <scale>96</scale>
+ <translate>1080 -2.5 10</translate>
+
+ <billboard tile="1" detail_level="1"/>
+
+ <reset_transform/>
+ <scale>96</scale>
+ <translate>1120 -2.5 -15</translate>
+
+ <billboard tile="0" detail_level="1"/>
+
+ <reset_transform/>
+ <scale>96</scale>
+ <translate>1220 -2.5 -30</translate>
+
+ <billboard tile="1" detail_level="1"/>
+</scene>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": Nearest,
+ "MagFilter": Nearest
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 1,
+ "TilesV": 1,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>1</string>
+ <key>TilesV</key>
+ <string>1</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 1,
+ "TilesV": 1,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "Wrap",
+ "WrapV": "Wrap"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>1</string>
+ <key>TilesV</key>
+ <string>1</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>WrapU</key>
+ <string>Wrap</string>
+ <key>WrapV</key>
+ <string>Wrap</string>
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 1,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>1</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Nearest",
+ "MagFilter": "Nearest",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>Repeat</string>
+ <key>WrapV</key>
+ <string>Repeat</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 8,
+ "InvertAlpha": 0,
+ "MinFilter": "Nearest",
+ "MagFilter": "Nearest"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>8</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Nearest",
+ "MagFilter": "Nearest"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 4,
+ "TilesV": 2,
+ "InvertAlpha": 0,
+ "MinFilter": "Nearest",
+ "MagFilter": "Nearest"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>4</string>
+ <key>TilesV</key>
+ <string>2</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 8,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Nearest",
+ "MagFilter": "Nearest"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>8</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 4,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "Wrap",
+ "WrapV": "Wrap"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>4</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>Wrap</string>
+ <key>WrapV</key>
+ <string>Wrap</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 4,
+ "TilesV": 1,
+ "InvertAlpha": 0,
+ "MinFilter": "Nearest",
+ "MagFilter": "Nearest"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>4</string>
+ <key>TilesV</key>
+ <string>1</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 4,
+ "TilesV": 4,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>4</string>
+ <key>TilesV</key>
+ <string>4</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+{
+ "TilesU": 2,
+ "TilesV": 1,
+ "InvertAlpha": 0,
+ "MinFilter": "Linear",
+ "MagFilter": "Linear",
+ "WrapU": "ClampToEdge",
+ "WrapV": "ClampToEdge"
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+ <key>TilesU</key>
+ <string>2</string>
+ <key>TilesV</key>
+ <string>1</string>
+ <key>InvertAlpha</key>
+ <string>0</string>
+
+ <key>MinFilter</key>
+ <string>Linear</string>
+ <key>MagFilter</key>
+ <string>Linear</string>
+ <key>WrapU</key>
+ <string>ClampToEdge</string>
+ <key>WrapV</key>
+ <string>ClampToEdge</string>
+ <key>MinFilter</key>
+ <string>Nearest</string>
+ <key>MagFilter</key>
+ <string>Nearest</string>
+</dict>
+</plist>
--- /dev/null
+/*
+ * Copyright 2001-2004 Unicode, Inc.
+ *
+ * Disclaimer
+ *
+ * This source code is provided as is by Unicode, Inc. No claims are
+ * made as to fitness for any particular purpose. No warranties of any
+ * kind are expressed or implied. The recipient agrees to determine
+ * applicability of information provided. If this file has been
+ * purchased on magnetic or optical media from Unicode, Inc., the
+ * sole remedy for any claim will be exchange of defective media
+ * within 90 days of receipt.
+ *
+ * Limitations on Rights to Redistribute This Code
+ *
+ * Unicode, Inc. hereby grants the right to freely use the information
+ * supplied in this file in the creation of products supporting the
+ * Unicode Standard, and to make copies of this file in any form
+ * for internal or external distribution as long as this notice
+ * remains attached.
+ */
+
+/* ---------------------------------------------------------------------
+
+ Conversions between UTF32, UTF-16, and UTF-8. Source code file.
+ Author: Mark E. Davis, 1994.
+ Rev History: Rick McGowan, fixes & updates May 2001.
+ Sept 2001: fixed const & error conditions per
+ mods suggested by S. Parent & A. Lillich.
+ June 2002: Tim Dodd added detection and handling of incomplete
+ source sequences, enhanced error detection, added casts
+ to eliminate compiler warnings.
+ July 2003: slight mods to back out aggressive FFFE detection.
+ Jan 2004: updated switches in from-UTF8 conversions.
+ Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.
+
+ See the header file "ConvertUTF.h" for complete documentation.
+
+------------------------------------------------------------------------ */
+
+
+#include "ConvertUTF.h"
+#ifdef CVTUTF_DEBUG
+#include <stdio.h>
+#endif
+
+static const int halfShift = 10; /* used for shifting by 10 bits */
+
+static const UTF32 halfBase = 0x0010000UL;
+static const UTF32 halfMask = 0x3FFUL;
+
+#define UNI_SUR_HIGH_START (UTF32)0xD800
+#define UNI_SUR_HIGH_END (UTF32)0xDBFF
+#define UNI_SUR_LOW_START (UTF32)0xDC00
+#define UNI_SUR_LOW_END (UTF32)0xDFFF
+#define false 0
+#define true 1
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF32toUTF16 (
+ const UTF32** sourceStart, const UTF32* sourceEnd,
+ UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
+ ConversionResult result = conversionOK;
+ const UTF32* source = *sourceStart;
+ UTF16* target = *targetStart;
+ while (source < sourceEnd) {
+ UTF32 ch;
+ if (target >= targetEnd) {
+ result = targetExhausted; break;
+ }
+ ch = *source++;
+ if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
+ /* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+ if (flags == strictConversion) {
+ --source; /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ } else {
+ *target++ = UNI_REPLACEMENT_CHAR;
+ }
+ } else {
+ *target++ = (UTF16)ch; /* normal case */
+ }
+ } else if (ch > UNI_MAX_LEGAL_UTF32) {
+ if (flags == strictConversion) {
+ result = sourceIllegal;
+ } else {
+ *target++ = UNI_REPLACEMENT_CHAR;
+ }
+ } else {
+ /* target is a character in range 0xFFFF - 0x10FFFF. */
+ if (target + 1 >= targetEnd) {
+ --source; /* Back up source pointer! */
+ result = targetExhausted; break;
+ }
+ ch -= halfBase;
+ *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
+ *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
+ }
+ }
+ *sourceStart = source;
+ *targetStart = target;
+ return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF16toUTF32 (
+ const UTF16** sourceStart, const UTF16* sourceEnd,
+ UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
+ ConversionResult result = conversionOK;
+ const UTF16* source = *sourceStart;
+ UTF32* target = *targetStart;
+ UTF32 ch, ch2;
+ while (source < sourceEnd) {
+ const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
+ ch = *source++;
+ /* If we have a surrogate pair, convert to UTF32 first. */
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
+ /* If the 16 bits following the high surrogate are in the source buffer... */
+ if (source < sourceEnd) {
+ ch2 = *source;
+ /* If it's a low surrogate, convert to UTF32. */
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
+ ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
+ + (ch2 - UNI_SUR_LOW_START) + halfBase;
+ ++source;
+ } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
+ --source; /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ }
+ } else { /* We don't have the 16 bits following the high surrogate. */
+ --source; /* return to the high surrogate */
+ result = sourceExhausted;
+ break;
+ }
+ } else if (flags == strictConversion) {
+ /* UTF-16 surrogate values are illegal in UTF-32 */
+ if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
+ --source; /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ }
+ }
+ if (target >= targetEnd) {
+ source = oldSource; /* Back up source pointer! */
+ result = targetExhausted; break;
+ }
+ *target++ = ch;
+ }
+ *sourceStart = source;
+ *targetStart = target;
+#ifdef CVTUTF_DEBUG
+if (result == sourceIllegal) {
+ fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
+ fflush(stderr);
+}
+#endif
+ return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Index into the table below with the first byte of a UTF-8 sequence to
+ * get the number of trailing bytes that are supposed to follow it.
+ * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
+ * left as-is for anyone who may want to do such conversion, which was
+ * allowed in earlier algorithms.
+ */
+static const char trailingBytesForUTF8[256] = {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
+};
+
+/*
+ * Magic values subtracted from a buffer value during UTF8 conversion.
+ * This table contains as many values as there might be trailing bytes
+ * in a UTF-8 sequence.
+ */
+static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
+ 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
+
+/*
+ * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
+ * into the first byte, depending on how many bytes follow. There are
+ * as many entries in this table as there are UTF-8 sequence types.
+ * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
+ * for *legal* UTF-8 will be 4 or fewer bytes total.
+ */
+static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
+
+/* --------------------------------------------------------------------- */
+
+/* The interface converts a whole buffer to avoid function-call overhead.
+ * Constants have been gathered. Loops & conditionals have been removed as
+ * much as possible for efficiency, in favor of drop-through switches.
+ * (See "Note A" at the bottom of the file for equivalent code.)
+ * If your compiler supports it, the "isLegalUTF8" call can be turned
+ * into an inline function.
+ */
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF16toUTF8 (
+ const UTF16** sourceStart, const UTF16* sourceEnd,
+ UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
+ ConversionResult result = conversionOK;
+ const UTF16* source = *sourceStart;
+ UTF8* target = *targetStart;
+ while (source < sourceEnd) {
+ UTF32 ch;
+ unsigned short bytesToWrite = 0;
+ const UTF32 byteMask = 0xBF;
+ const UTF32 byteMark = 0x80;
+ const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
+ ch = *source++;
+ /* If we have a surrogate pair, convert to UTF32 first. */
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
+ /* If the 16 bits following the high surrogate are in the source buffer... */
+ if (source < sourceEnd) {
+ UTF32 ch2 = *source;
+ /* If it's a low surrogate, convert to UTF32. */
+ if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
+ ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
+ + (ch2 - UNI_SUR_LOW_START) + halfBase;
+ ++source;
+ } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
+ --source; /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ }
+ } else { /* We don't have the 16 bits following the high surrogate. */
+ --source; /* return to the high surrogate */
+ result = sourceExhausted;
+ break;
+ }
+ } else if (flags == strictConversion) {
+ /* UTF-16 surrogate values are illegal in UTF-32 */
+ if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
+ --source; /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ }
+ }
+ /* Figure out how many bytes the result will require */
+ if (ch < (UTF32)0x80) { bytesToWrite = 1;
+ } else if (ch < (UTF32)0x800) { bytesToWrite = 2;
+ } else if (ch < (UTF32)0x10000) { bytesToWrite = 3;
+ } else if (ch < (UTF32)0x110000) { bytesToWrite = 4;
+ } else { bytesToWrite = 3;
+ ch = UNI_REPLACEMENT_CHAR;
+ }
+
+ target += bytesToWrite;
+ if (target > targetEnd) {
+ source = oldSource; /* Back up source pointer! */
+ target -= bytesToWrite; result = targetExhausted; break;
+ }
+ switch (bytesToWrite) { /* note: everything falls through. */
+ case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+ case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+ case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+ case 1: *--target = (UTF8)(ch | firstByteMark[bytesToWrite]);
+ }
+ target += bytesToWrite;
+ }
+ *sourceStart = source;
+ *targetStart = target;
+ return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Utility routine to tell whether a sequence of bytes is legal UTF-8.
+ * This must be called with the length pre-determined by the first byte.
+ * If not calling this from ConvertUTF8to*, then the length can be set by:
+ * length = trailingBytesForUTF8[*source]+1;
+ * and the sequence is illegal right away if there aren't that many bytes
+ * available.
+ * If presented with a length > 4, this returns false. The Unicode
+ * definition of UTF-8 goes up to 4-byte sequences.
+ */
+
+static bool isLegalUTF8(const UTF8 *source, int length) {
+ UTF8 a;
+ const UTF8 *srcptr = source+length;
+ switch (length) {
+ default: return false;
+ /* Everything else falls through when "true"... */
+ case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+ case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+ case 2: if ((a = (*--srcptr)) > 0xBF) return false;
+
+ switch (*source) {
+ /* no fall-through in this inner switch */
+ case 0xE0: if (a < 0xA0) return false; break;
+ case 0xED: if (a > 0x9F) return false; break;
+ case 0xF0: if (a < 0x90) return false; break;
+ case 0xF4: if (a > 0x8F) return false; break;
+ default: if (a < 0x80) return false;
+ }
+
+ case 1: if (*source >= 0x80 && *source < 0xC2) return false;
+ }
+ if (*source > 0xF4) return false;
+ return true;
+}
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Exported function to return whether a UTF-8 sequence is legal or not.
+ * This is not used here; it's just exported.
+ */
+bool isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
+ int length = trailingBytesForUTF8[*source]+1;
+ if (source+length > sourceEnd) {
+ return false;
+ }
+ return isLegalUTF8(source, length);
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF8toUTF16 (
+ const UTF8** sourceStart, const UTF8* sourceEnd,
+ UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
+ ConversionResult result = conversionOK;
+ const UTF8* source = *sourceStart;
+ UTF16* target = *targetStart;
+ while (source < sourceEnd) {
+ UTF32 ch = 0;
+ unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
+ if (source + extraBytesToRead >= sourceEnd) {
+ result = sourceExhausted; break;
+ }
+ /* Do this check whether lenient or strict */
+ if (! isLegalUTF8(source, extraBytesToRead+1)) {
+ result = sourceIllegal;
+ break;
+ }
+ /*
+ * The cases all fall through. See "Note A" below.
+ */
+ switch (extraBytesToRead) {
+ case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
+ case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
+ case 3: ch += *source++; ch <<= 6;
+ case 2: ch += *source++; ch <<= 6;
+ case 1: ch += *source++; ch <<= 6;
+ case 0: ch += *source++;
+ }
+ ch -= offsetsFromUTF8[extraBytesToRead];
+
+ if (target >= targetEnd) {
+ source -= (extraBytesToRead+1); /* Back up source pointer! */
+ result = targetExhausted; break;
+ }
+ if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
+ /* UTF-16 surrogate values are illegal in UTF-32 */
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+ if (flags == strictConversion) {
+ source -= (extraBytesToRead+1); /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ } else {
+ *target++ = UNI_REPLACEMENT_CHAR;
+ }
+ } else {
+ *target++ = (UTF16)ch; /* normal case */
+ }
+ } else if (ch > UNI_MAX_UTF16) {
+ if (flags == strictConversion) {
+ result = sourceIllegal;
+ source -= (extraBytesToRead+1); /* return to the start */
+ break; /* Bail out; shouldn't continue */
+ } else {
+ *target++ = UNI_REPLACEMENT_CHAR;
+ }
+ } else {
+ /* target is a character in range 0xFFFF - 0x10FFFF. */
+ if (target + 1 >= targetEnd) {
+ source -= (extraBytesToRead+1); /* Back up source pointer! */
+ result = targetExhausted; break;
+ }
+ ch -= halfBase;
+ *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
+ *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
+ }
+ }
+ *sourceStart = source;
+ *targetStart = target;
+ return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF32toUTF8 (
+ const UTF32** sourceStart, const UTF32* sourceEnd,
+ UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
+ ConversionResult result = conversionOK;
+ const UTF32* source = *sourceStart;
+ UTF8* target = *targetStart;
+ while (source < sourceEnd) {
+ UTF32 ch;
+ unsigned short bytesToWrite = 0;
+ const UTF32 byteMask = 0xBF;
+ const UTF32 byteMark = 0x80;
+ ch = *source++;
+ if (flags == strictConversion ) {
+ /* UTF-16 surrogate values are illegal in UTF-32 */
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+ --source; /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ }
+ }
+ /*
+ * Figure out how many bytes the result will require. Turn any
+ * illegally large UTF32 things (> Plane 17) into replacement chars.
+ */
+ if (ch < (UTF32)0x80) { bytesToWrite = 1;
+ } else if (ch < (UTF32)0x800) { bytesToWrite = 2;
+ } else if (ch < (UTF32)0x10000) { bytesToWrite = 3;
+ } else if (ch <= UNI_MAX_LEGAL_UTF32) { bytesToWrite = 4;
+ } else { bytesToWrite = 3;
+ ch = UNI_REPLACEMENT_CHAR;
+ result = sourceIllegal;
+ }
+
+ target += bytesToWrite;
+ if (target > targetEnd) {
+ --source; /* Back up source pointer! */
+ target -= bytesToWrite; result = targetExhausted; break;
+ }
+ switch (bytesToWrite) { /* note: everything falls through. */
+ case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+ case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+ case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+ case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
+ }
+ target += bytesToWrite;
+ }
+ *sourceStart = source;
+ *targetStart = target;
+ return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF8toUTF32 (
+ const UTF8** sourceStart, const UTF8* sourceEnd,
+ UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
+ ConversionResult result = conversionOK;
+ const UTF8* source = *sourceStart;
+ UTF32* target = *targetStart;
+ while (source < sourceEnd) {
+ UTF32 ch = 0;
+ unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
+ if (source + extraBytesToRead >= sourceEnd) {
+ result = sourceExhausted; break;
+ }
+ /* Do this check whether lenient or strict */
+ if (! isLegalUTF8(source, extraBytesToRead+1)) {
+ result = sourceIllegal;
+ break;
+ }
+ /*
+ * The cases all fall through. See "Note A" below.
+ */
+ switch (extraBytesToRead) {
+ case 5: ch += *source++; ch <<= 6;
+ case 4: ch += *source++; ch <<= 6;
+ case 3: ch += *source++; ch <<= 6;
+ case 2: ch += *source++; ch <<= 6;
+ case 1: ch += *source++; ch <<= 6;
+ case 0: ch += *source++;
+ }
+ ch -= offsetsFromUTF8[extraBytesToRead];
+
+ if (target >= targetEnd) {
+ source -= (extraBytesToRead+1); /* Back up the source pointer! */
+ result = targetExhausted; break;
+ }
+ if (ch <= UNI_MAX_LEGAL_UTF32) {
+ /*
+ * UTF-16 surrogate values are illegal in UTF-32, and anything
+ * over Plane 17 (> 0x10FFFF) is illegal.
+ */
+ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+ if (flags == strictConversion) {
+ source -= (extraBytesToRead+1); /* return to the illegal value itself */
+ result = sourceIllegal;
+ break;
+ } else {
+ *target++ = UNI_REPLACEMENT_CHAR;
+ }
+ } else {
+ *target++ = ch;
+ }
+ } else { /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
+ result = sourceIllegal;
+ *target++ = UNI_REPLACEMENT_CHAR;
+ }
+ }
+ *sourceStart = source;
+ *targetStart = target;
+ return result;
+}
+
+/* ---------------------------------------------------------------------
+
+ Note A.
+ The fall-through switches in UTF-8 reading code save a
+ temp variable, some decrements & conditionals. The switches
+ are equivalent to the following loop:
+ {
+ int tmpBytesToRead = extraBytesToRead+1;
+ do {
+ ch += *source++;
+ --tmpBytesToRead;
+ if (tmpBytesToRead) ch <<= 6;
+ } while (tmpBytesToRead > 0);
+ }
+ In UTF-8 writing code, the switches on "bytesToWrite" are
+ similarly unrolled loops.
+
+ --------------------------------------------------------------------- */
--- /dev/null
+
+#ifndef _CONVERTUTF_H_
+#define _CONVERTUTF_H_
+
+/*
+ * Copyright 2001-2004 Unicode, Inc.
+ *
+ * Disclaimer
+ *
+ * This source code is provided as is by Unicode, Inc. No claims are
+ * made as to fitness for any particular purpose. No warranties of any
+ * kind are expressed or implied. The recipient agrees to determine
+ * applicability of information provided. If this file has been
+ * purchased on magnetic or optical media from Unicode, Inc., the
+ * sole remedy for any claim will be exchange of defective media
+ * within 90 days of receipt.
+ *
+ * Limitations on Rights to Redistribute This Code
+ *
+ * Unicode, Inc. hereby grants the right to freely use the information
+ * supplied in this file in the creation of products supporting the
+ * Unicode Standard, and to make copies of this file in any form
+ * for internal or external distribution as long as this notice
+ * remains attached.
+ */
+
+/* ---------------------------------------------------------------------
+
+ Conversions between UTF32, UTF-16, and UTF-8. Header file.
+
+ Several funtions are included here, forming a complete set of
+ conversions between the three formats. UTF-7 is not included
+ here, but is handled in a separate source file.
+
+ Each of these routines takes pointers to input buffers and output
+ buffers. The input buffers are const.
+
+ Each routine converts the text between *sourceStart and sourceEnd,
+ putting the result into the buffer between *targetStart and
+ targetEnd. Note: the end pointers are *after* the last item: e.g.
+ *(sourceEnd - 1) is the last item.
+
+ The return result indicates whether the conversion was successful,
+ and if not, whether the problem was in the source or target buffers.
+ (Only the first encountered problem is indicated.)
+
+ After the conversion, *sourceStart and *targetStart are both
+ updated to point to the end of last text successfully converted in
+ the respective buffers.
+
+ Input parameters:
+ sourceStart - pointer to a pointer to the source buffer.
+ The contents of this are modified on return so that
+ it points at the next thing to be converted.
+ targetStart - similarly, pointer to pointer to the target buffer.
+ sourceEnd, targetEnd - respectively pointers to the ends of the
+ two buffers, for overflow checking only.
+
+ These conversion functions take a ConversionFlags argument. When this
+ flag is set to strict, both irregular sequences and isolated surrogates
+ will cause an error. When the flag is set to lenient, both irregular
+ sequences and isolated surrogates are converted.
+
+ Whether the flag is strict or lenient, all illegal sequences will cause
+ an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
+ or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
+ must check for illegal sequences.
+
+ When the flag is set to lenient, characters over 0x10FFFF are converted
+ to the replacement character; otherwise (when the flag is set to strict)
+ they constitute an error.
+
+ Output parameters:
+ The value "sourceIllegal" is returned from some routines if the input
+ sequence is malformed. When "sourceIllegal" is returned, the source
+ value will point to the illegal value that caused the problem. E.g.,
+ in UTF-8 when a sequence is malformed, it points to the start of the
+ malformed sequence.
+
+ Author: Mark E. Davis, 1994.
+ Rev History: Rick McGowan, fixes & updates May 2001.
+ Fixes & updates, Sept 2001.
+
+------------------------------------------------------------------------ */
+
+/* ---------------------------------------------------------------------
+ The following 4 definitions are compiler-specific.
+ The C standard does not guarantee that wchar_t has at least
+ 16 bits, so wchar_t is no less portable than unsigned short!
+ All should be unsigned values to avoid sign extension during
+ bit mask & shift operations.
+------------------------------------------------------------------------ */
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef uint32_t UTF32; /* exactly 32 bits */
+typedef uint16_t UTF16; /* exactly 16 bits */
+typedef uint8_t UTF8; /* exactly 8 bits */
+
+/* Some fundamental constants */
+#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
+#define UNI_MAX_BMP (UTF32)0x0000FFFF
+#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
+#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
+#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
+
+typedef enum {
+ conversionOK, /* conversion successful */
+ sourceExhausted, /* partial character in source, but hit end */
+ targetExhausted, /* insuff. room in target for conversion */
+ sourceIllegal /* source sequence is illegal/malformed */
+} ConversionResult;
+
+typedef enum {
+ strictConversion = 0,
+ lenientConversion
+} ConversionFlags;
+
+/* This is for C++ and does no harm in C */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ConversionResult ConvertUTF8toUTF16 (
+ const UTF8** sourceStart, const UTF8* sourceEnd,
+ UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF16toUTF8 (
+ const UTF16** sourceStart, const UTF16* sourceEnd,
+ UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF8toUTF32 (
+ const UTF8** sourceStart, const UTF8* sourceEnd,
+ UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF32toUTF8 (
+ const UTF32** sourceStart, const UTF32* sourceEnd,
+ UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF16toUTF32 (
+ const UTF16** sourceStart, const UTF16* sourceEnd,
+ UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF32toUTF16 (
+ const UTF32** sourceStart, const UTF32* sourceEnd,
+ UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
+
+bool isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* --------------------------------------------------------------------- */
+
+#endif // _CONVERTUTF_H_
+
-bin_PROGRAMS = yoink
+noinst_LIBRARIES = libdc.a
-yoink_SOURCES = yoink.cc
-yoink_LDFLAGS = -lstdc++
+libdc_a_SOURCES = \
+ ConvertUTF.c \
+ ConvertUTF.h \
+ deserializer.cc \
+ deserializer.hh \
+ dispatcher.cc \
+ dispatcher.hh \
+ engine.cc \
+ engine.hh \
+ fastevents.c \
+ fastevents.h \
+ math.cc \
+ math.hh \
+ matrix.hh \
+ opengl.hh \
+ quaternion.hh \
+ random.cc \
+ random.hh \
+ rectangle.cc \
+ rectangle.hh \
+ serializable.cc \
+ serializable.hh \
+ serializer.cc \
+ serializer.hh \
+ settings.cc \
+ settings.hh \
+ singleton.hh \
+ stringtools.cc \
+ stringtools.hh \
+ texture.cc \
+ texture.hh \
+ thread.hh \
+ timer.cc \
+ timer.hh \
+ vector.hh \
+ video.cc \
+ video.hh \
+ $(ENDLIST)
+
+libdc_a_CPPFLAGS = -I/usr/include/SDL -I$(top_srcdir)/yajl/src -O3
+#libdc_a_LDFLAGS = -lstdc++ -lSDL_image -lSDL_sound
+libdc_a_LIBADD = $(top_srcdir)/yajl/libyajl.a
+
+
+bin_PROGRAMS = yoink
+
+yoink_SOURCES = \
+ YoinkApp.cc \
+ YoinkApp.hh \
+ $(ENDLIST)
+
+yoink_CPPFLAGS = -I/usr/include/SDL -O3
+#yoink_LDFLAGS = -lstdc++ -lSDL_image -lSDL_sound
+yoink_LDADD = libdc.a ../yajl/libyajl.a
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <iostream>
+#include <string>
+
+#include <boost/bind.hpp>
+
+#include "opengl.hh"
+#include "video.hh"
+
+#include "vector.hh"
+
+#include "YoinkApp.hh"
+
+
+YoinkApp::YoinkApp(int argc, char* argv[])
+ : dc::engine("Yoink "VERSION, argc, argv, "yoinkrc")
+{
+ std::cout << "Yoink "VERSION << std::endl
+ << "Compiled " << __TIME__ " " __DATE__ << std::endl
+ << "Send requests, patches, and bug reports to <" PACKAGE_BUGREPORT
+ << ">." << std::endl << std::endl;
+
+ state = 0.0;
+
+ glEnable(GL_TEXTURE_2D);
+
+ heroineTexture = new dc::texture("Heroine.png");
+
+ glShadeModel(GL_SMOOTH);
+ //glEnable(GL_DEPTH_TEST);
+
+ // Enable transparency:
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glLoadIdentity();
+
+}
+
+YoinkApp::~YoinkApp()
+{
+ delete heroineTexture;
+ std::cout << "Goodbye..." << std::endl;
+}
+
+
+void YoinkApp::update(double t, double dt)
+{
+ //dt *= 0.1;
+
+ prevstate = state;
+ state += dt;
+}
+
+void drawrect(dc::scalar a, dc::scalar b, dc::scalar c, dc::scalar d)
+{
+ glBegin(GL_QUADS);
+ glTexCoord2f(1.0, 1.0);
+ glVertex3d(a, d, 0.0);
+ glTexCoord2f(1.0, 0.0);
+ glVertex3d(a, b, 0.0);
+ glTexCoord2f(0.0, 0.0);
+ glVertex3d(c, b, 0.0);
+ glTexCoord2f(0.0, 1.0);
+ glVertex3d(c, d, 0.0);
+ glEnd();
+}
+
+void YoinkApp::draw(double alpha)
+{
+ static dc::vector3 c1 = dc::vector3::random(0.0, 1.0);
+ static dc::vector3 c2 = dc::vector3::random(0.0, 1.0);
+
+ glClearColor(1.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+
+ double drawstate = state * alpha + prevstate * (1.0 - alpha);
+ double sinstate = std::sin(drawstate);
+ double cosstate = std::cos(drawstate);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ glColor3dv(c1.array);
+ drawrect(-cosstate, -sinstate, sinstate, cosstate);
+ glColor3dv(c2.array);
+ drawrect(0.0, 0.0, sinstate, cosstate);
+
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+
+ heroineTexture->bind();
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0.0, 0.0);
+ glVertex3f(0.0, 0.0, 0.0);
+ glTexCoord2f(1.0/8.0, 0.0);
+ glVertex3f(1.0, 0.0, 0.0);
+ glTexCoord2f(1.0/8.0, 1.0/4.0);
+ glVertex3f(1.0, 1.0, 0.0);
+ glTexCoord2f(0.0, 1.0/4.0);
+ glVertex3f(0.0, 1.0, 0.0);
+ glEnd();
+
+ glFlush();
+}
+
+void YoinkApp::dispatchEvent(const SDL_Event& event)
+{
+ switch (event.type)
+ {
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE)
+ {
+ stop();
+ }
+ else if (event.key.keysym.sym == SDLK_f)
+ {
+ getVideo().toggleFull();
+ }
+ break;
+
+ case SDL_QUIT:
+ stop();
+ break;
+ }
+}
+
+
+#include "dispatcher.hh"
+
+class Foo : public dc::notification
+{
+public:
+ static void func(const dc::notification& meh)
+ {
+ std::cout << "func: " << std::endl;
+ }
+
+ void snap(int zzz, const dc::notification& nice, float lean)
+ {
+ std::cout << "snap: " << zzz << "," << lean << std::endl;
+ }
+};
+
+void MyHandler(const dc::notification& cool)
+{
+ std::cout << "MyHandler with a notification" << std::endl;
+}
+
+
+int main(int argc, char* argv[])
+{
+ YoinkApp app(argc, argv);
+ return app.run();
+}
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _YOINKAPP_HH_
+#define _YOINKAPP_HH_
+
+#include <iostream>
+#include <string>
+
+#include "engine.hh"
+
+#include "texture.hh"
+
+
+class YoinkApp : public dc::engine
+{
+public:
+ YoinkApp(int argc, char* argv[]);
+ ~YoinkApp();
+
+private:
+ void update(double t, double dt);
+ void draw(double alpha);
+ void dispatchEvent(const SDL_Event& event);
+
+ dc::texture* heroineTexture;
+
+ double state;
+ double prevstate;
+};
+
+
+#endif // _YOINKAPP_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <fstream>
+#include <queue>
+
+#include <yajl/yajl_parse.h>
+
+#include "serializable.hh"
+#include "deserializer.hh"
+
+
+namespace dc {
+
+
+class deserializer_impl
+{
+public:
+ deserializer_impl(const std::string& filePath, bool comments = false,
+ bool check = false)
+ {
+ std::ifstream* input = new std::ifstream(filePath.c_str());
+ init(*input, true, comments, check);
+ }
+
+ deserializer_impl(std::istream& input, bool comments = false,
+ bool check = false)
+ {
+ init(input, false, comments, check);
+ }
+
+ ~deserializer_impl()
+ {
+ while (!parsed.empty())
+ {
+ delete parsed.front();
+ parsed.pop();
+ }
+
+ if (deleteWhenDone)
+ {
+ delete in;
+ }
+ yajl_free(hand);
+ }
+
+ void throwError()
+ {
+ unsigned char* errorMsg = yajl_get_error(hand, 0, 0, 0);
+ deserializer::parser_error error((char*)errorMsg);
+ yajl_free_error(hand, errorMsg);
+ throw error;
+ }
+
+
+ static int parsedNull(void* ctx)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(new null);
+ return 1;
+ }
+
+ static int parsedBoolean(void* ctx, int value)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(new wrapped_boolean(value));
+ return 1;
+ }
+
+ static int parsedInteger(void* ctx, long value)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(new wrapped_integer(value));
+ return 1;
+ }
+
+ static int parsedFloat(void* ctx, double value)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(new wrapped_real(value));
+ return 1;
+ }
+
+ static int parsedString(void* ctx, const unsigned char* value,
+ unsigned length)
+ {
+ wrapped_string* parsed = new wrapped_string(std::string((char*)value,
+ length));
+ ((deserializer_impl*)ctx)->parsed.push(parsed);
+ return 1;
+ }
+
+ static int parsedBeginMap(void* ctx)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(new wrapped_dictionary);
+ }
+
+ static int parsedMapKey(void* ctx, const unsigned char* value,
+ unsigned length)
+ {
+ return parsedString(ctx, value, length);
+ }
+
+ static int parsedEndMap(void* ctx)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(0);
+ return 1;
+ }
+
+ static int parsedBeginArray(void* ctx)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(new wrapped_array);
+ return 1;
+ }
+
+ static int parsedEndArray(void* ctx)
+ {
+ ((deserializer_impl*)ctx)->parsed.push(0);
+ return 1;
+ }
+
+
+ void parse()
+ {
+ unsigned char buffer[4096];
+
+ yajl_status stat;
+
+ while (parsed.empty() && in->good())
+ {
+ in->read((char*)buffer, sizeof(buffer));
+ unsigned readIn = in->gcount();
+
+ if (readIn > 0)
+ {
+ stat = yajl_parse(hand, buffer, readIn);
+ }
+ else
+ {
+ stat = yajl_parse_complete(hand);
+ }
+
+ if (stat != yajl_status_ok &&
+ stat != yajl_status_insufficient_data)
+ {
+ throwError();
+ }
+ }
+ }
+
+
+ yajl_handle hand;
+
+ std::istream* in;
+ bool deleteWhenDone;
+
+ std::queue<serializable*> parsed;
+
+private:
+ void init(std::istream& input, bool deleteIn, bool comments, bool check)
+ {
+ const yajl_callbacks callbacks =
+ {
+ deserializer_impl::parsedNull,
+ deserializer_impl::parsedBoolean,
+ deserializer_impl::parsedInteger,
+ deserializer_impl::parsedFloat,
+ 0,
+ deserializer_impl::parsedString,
+ deserializer_impl::parsedBeginMap,
+ deserializer_impl::parsedMapKey,
+ deserializer_impl::parsedEndMap,
+ deserializer_impl::parsedBeginArray,
+ deserializer_impl::parsedEndArray
+ };
+
+ in = &input;
+ deleteWhenDone = deleteIn;
+
+ yajl_parser_config config = {comments, check};
+ hand = yajl_alloc(&callbacks, &config, NULL, this);
+ }
+};
+
+
+deserializer::deserializer(const std::string& filePath, bool comments,
+ bool check) : impl(new deserializer_impl(filePath, comments, check)) {}
+
+deserializer::deserializer(std::istream& input, bool comments, bool check) :
+ impl(new deserializer_impl(input, comments, check)) {}
+
+
+serializable_ptr deserializer::deserialize()
+{
+ serializable* ptr = pullNext();
+ if (ptr)
+ {
+ ptr->deserialize(*this);
+ }
+ return serializable_ptr(ptr);
+}
+
+
+serializable* deserializer::pullNext()
+{
+ impl->parse();
+ if (!impl->parsed.empty())
+ {
+ serializable* ptr = impl->parsed.front();
+ return ptr;
+ }
+ return 0;
+}
+
+void deserializer::pop()
+{
+ impl->parsed.pop();
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _DESERIALIZER_HH_
+#define _DESERIALIZER_HH_
+
+/**
+ * @file deserializer.hh
+ * Deserialize structures and types from input on a stream.
+ */
+
+#include <istream>
+#include <string>
+#include <stdexcept>
+
+#include <boost/shared_ptr.hpp>
+
+
+namespace dc {
+
+
+class serializable;
+typedef boost::shared_ptr<serializable> serializable_ptr;
+
+class deserializer_impl;
+
+class deserializer
+{
+public:
+ deserializer(const std::string& filePath, bool comments = false,
+ bool check = false);
+ deserializer(std::istream& input, bool comments = false, bool check = false);
+
+ serializable_ptr deserialize();
+
+ serializable* pullNext();
+ void pop();
+
+ struct parser_error : std::runtime_error
+ {
+ explicit parser_error(const std::string& what_arg) :
+ std::runtime_error(what_arg) {}
+ };
+
+private:
+ boost::shared_ptr<deserializer_impl> impl;
+};
+
+
+} // namespace dc
+
+
+#endif // _DESERIALIZER_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <map>
+
+#include "dispatcher.hh"
+
+
+namespace dc {
+
+
+notification::~notification() {}
+
+
+class dispatcher_impl
+{
+public:
+ dispatcher_impl() : id(1) {}
+
+ dispatcher::handler getNewHandlerID()
+ {
+ id += 4;
+ return (dispatcher::handler)id;
+ }
+
+ typedef std::pair<dispatcher::handler,dispatcher::function> callback_t;
+ typedef std::multimap<std::string,callback_t> callback_lookup_t;
+ typedef callback_lookup_t::iterator callback_it_t;
+
+ typedef std::multimap<dispatcher::handler,std::string> handler_lookup_t;
+ typedef handler_lookup_t::iterator handler_it_t;
+
+ unsigned long long id;
+
+ callback_lookup_t callbacks;
+ handler_lookup_t handlers;
+};
+
+
+dispatcher::dispatcher() : impl(new dispatcher_impl) {}
+
+
+dispatcher::handler dispatcher::addHandler(const std::string& message,
+ const function& callback)
+{
+ return addHandler(message, callback, impl->getNewHandlerID());
+}
+
+dispatcher::handler dispatcher::addHandler(const std::string& message,
+ const function& callback, handler id)
+{
+ std::pair<std::string,dispatcher_impl::callback_t>
+ callbackPair(message, dispatcher_impl::callback_t(id, callback));
+
+ std::pair<handler,std::string> handlerPair(id, message);
+
+ impl->callbacks.insert(callbackPair);
+ impl->handlers.insert(handlerPair);
+
+ return id;
+}
+
+
+void dispatcher::removeHandler(handler id)
+{
+ std::pair<dispatcher_impl::handler_it_t,dispatcher_impl::handler_it_t>
+ handlers(impl->handlers.equal_range(id));
+
+ dispatcher_impl::handler_it_t i;
+ for (i = handlers.first; i != handlers.second; i++)
+ {
+ dispatcher_impl::callback_it_t it = impl->callbacks.find((*i).second);
+ dispatcher_impl::callback_it_t last = impl->callbacks.end();
+
+ dispatcher_impl::callback_it_t j;
+ for (j = it; j != last; j++)
+ {
+ if (((*j).second).first == id)
+ {
+ impl->callbacks.erase(j);
+ break;
+ }
+ }
+ }
+
+ impl->handlers.erase(id);
+}
+
+
+void dispatcher::dispatch(const std::string& message)
+{
+ dispatch(message, notification());
+}
+
+void dispatcher::dispatch(const std::string& message, const notification& param)
+{
+ std::pair<dispatcher_impl::callback_it_t,dispatcher_impl::callback_it_t>
+ callbacks(impl->callbacks.equal_range(message));
+
+ dispatcher_impl::callback_it_t i;
+ for (i = callbacks.first; i != callbacks.second; i++)
+ {
+ function callback = ((*i).second).second;
+ callback(param);
+ }
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _DISPATCHER_HH_
+#define _DISPATCHER_HH_
+
+/**
+ * @file dispatcher.hh
+ * Dispatching of information.
+ */
+
+#include <string>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
+
+#include "singleton.hh"
+
+
+namespace dc {
+
+
+// Subclass this to create more specific notes to dispatch.
+class notification
+{
+public:
+ virtual ~notification();
+};
+
+
+class dispatcher_impl;
+
+class dispatcher : public singleton<dispatcher>
+{
+public:
+ typedef void* handler;
+
+ dispatcher();
+
+ typedef boost::function<void(const notification&)> function;
+
+ handler addHandler(const std::string& message, const function& callback);
+ handler addHandler(const std::string& message, const function& callback,
+ handler id);
+
+ void removeHandler(handler id);
+
+ void dispatch(const std::string& message);
+ void dispatch(const std::string& message, const notification& param);
+
+private:
+ boost::shared_ptr<dispatcher_impl> impl;
+};
+
+
+} // namespace dc
+
+#endif // _DISPATCHER_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <iostream>
+#include <cstdlib> // exit
+#include <string>
+#include <stdexcept>
+
+#include <SDL/SDL.h>
+#include "fastevents.h"
+
+#include "random.hh"
+#include "timer.hh"
+#include "video.hh"
+#include "settings.hh"
+#include "dispatcher.hh"
+
+#include "engine.hh"
+
+
+namespace dc {
+
+
+class engine_impl
+{
+public:
+ engine_impl(const std::string& name, int argc, char* argv[],
+ const std::string& configFile, engine* outer) : config(argc, argv),
+ interface(outer)
+ {
+ if (SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD) != 0)
+ {
+ throw std::runtime_error(SDL_GetError());
+ }
+ if (FE_Init() != 0)
+ {
+ throw std::runtime_error(FE_GetError());
+ }
+
+ rng::seed();
+
+ config.loadFromFile(configFile);
+
+ screen = video_ptr(new video(name));
+ screen->makeActive();
+
+ timestep = 0.01;
+ config.get("engine.timestep", timestep);
+
+ long maxfps = 40;
+ config.get("engine.maxfps", maxfps);
+ drawrate = 1.0 / scalar(maxfps);
+
+ printfps = false;
+ config.get("engine.printfps", printfps);
+ }
+
+ ~engine_impl()
+ {
+ // The video object must be destroyed before we can shutdown SDL.
+ screen.reset();
+
+ FE_Quit();
+ SDL_Quit();
+ }
+
+
+ int run()
+ {
+ scalar ticksNow = ticks();
+
+ scalar nextStep = ticksNow;
+ scalar nextDraw = ticksNow;
+ scalar nextFPSUpdate = ticksNow + 1.0;
+
+ scalar totalTime = 0.0;
+ scalar accumulator = 0.0;
+
+ fps = 0.0;
+ int frameAccum = 0.0;
+
+ running = true;
+ do
+ {
+ dispatchEvents();
+
+ scalar newTicks = ticks();
+ accumulator += newTicks - ticksNow;
+ ticksNow = newTicks;
+
+ if (ticksNow >= nextStep)
+ {
+ interface->update(totalTime, timestep);
+
+ totalTime += timestep;
+ accumulator -= timestep;
+
+ nextStep += timestep;
+ if (ticksNow >= nextStep) nextStep = ticksNow + timestep;
+ }
+
+ if (ticksNow >= nextDraw)
+ {
+ frameAccum++;
+
+ if (ticksNow >= nextFPSUpdate)
+ {
+ fps = frameAccum;// + (ticksNow - nextFPSUpdate) / 1.0;
+ frameAccum = 0;
+
+ nextFPSUpdate += 1.0;
+ if (ticksNow >= nextFPSUpdate) nextFPSUpdate = ticksNow + 1.0;
+
+ if (printfps)
+ {
+ std::cout << "FPS: " << fps << std::endl;
+ }
+ }
+
+ interface->draw(accumulator / timestep);
+ screen->swap();
+
+ nextDraw += drawrate;
+ if (ticksNow >= nextDraw) nextDraw = ticksNow + drawrate;
+ }
+
+ sleep(std::min(nextStep, nextDraw), true);
+ }
+ while (running);
+ }
+
+
+ void dispatchEvents()
+ {
+ SDL_Event event;
+
+ while (FE_PollEvent(&event) == 1)
+ {
+ switch (event.type)
+ {
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE &&
+ (SDL_GetModState() & KMOD_CTRL) )
+ {
+ exit(0);
+ }
+ break;
+
+ case SDL_VIDEORESIZE:
+ screen->resize(event.resize.w, event.resize.h);
+ break;
+ }
+
+ interface->dispatchEvent(event);
+ }
+ }
+
+
+ settings config;
+ dispatcher relay;
+ video_ptr screen;
+
+ bool running;
+
+ scalar timestep;
+ scalar drawrate;
+
+ long fps;
+ bool printfps;
+
+ engine* interface;
+};
+
+engine::engine(const std::string& name, int argc, char* argv[],
+ const std::string& configFile)
+ : impl(new engine_impl(name, argc, argv, configFile, this)) {}
+
+engine::~engine() {}
+
+
+int engine::run()
+{
+ impl->run();
+}
+
+void engine::stop()
+{
+ impl->running = false;
+}
+
+
+void engine::setTimestep(scalar ts)
+{
+ impl->timestep = ts;
+}
+
+scalar engine::getTimestep()
+{
+ return impl->timestep;
+}
+
+void engine::setMaxFPS(long maxfps)
+{
+ impl->drawrate = 1.0 / scalar(maxfps);
+}
+
+long engine::getMaxFPS()
+{
+ return long(1.0 / impl->drawrate);
+}
+
+
+video& engine::getVideo()
+{
+ return *impl->screen;
+}
+
+long engine::getFPS()
+{
+ return impl->fps;
+}
+
+
+void engine::update(scalar t, scalar dt) {}
+void engine::draw(scalar alpha) {}
+void engine::dispatchEvent(const SDL_Event& event) {}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _ENGINE_HH_
+#define _ENGINE_HH_
+
+#include <boost/shared_ptr.hpp>
+#include <SDL/SDL.h>
+
+#include "singleton.hh"
+#include "dispatcher.hh"
+
+
+namespace dc {
+
+
+class engine_impl;
+class video;
+
+class engine : public singleton<engine>
+{
+public:
+ engine(const std::string& name, int argc, char* argv[],
+ const std::string& configFile);
+ virtual ~engine();
+
+ int run();
+ void stop();
+
+ void setTimestep(scalar ts);
+ scalar getTimestep();
+ void setMaxFPS(long maxfps);
+ long getMaxFPS();
+
+ video& getVideo();
+ long getFPS();
+
+ // Override these if you want.
+ virtual void update(scalar t, scalar dt);
+ virtual void draw(scalar alpha);
+ virtual void dispatchEvent(const SDL_Event& event);
+
+private:
+ boost::shared_ptr<engine_impl> impl;
+};
+
+
+} // namespace dc
+
+#endif // _ENGINE_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _EVENT_HH_
+#define _EVENT_HH_
+
+#include "bz/date.h"
+#include "bz/object.h"
+
+
+namespace bz {
+
+
+class event
+{
+public:
+ typedef enum
+ {
+ left_click_down = 1<<1,
+ left_click_up = 1<<2,
+ right_click_down = 1<<3,
+ right_click_up = 1<<4,
+ other_click_down = 1<<5,
+ other_click_up = 1<<6,
+ mouse_moved = 1<<7,
+ mouse_entered = 1<<8,
+ mouse_exited = 1<<9,
+ key_down = 1<<10,
+ key_up = 1<<11,
+ activated = 1<<12,
+ iconified = 1<<13,
+ deactivated = 1<<14,
+
+ file_new = 1<<20,
+ file_open = 1<<21,
+ file_revert = 1<<22,
+ file_save = 1<<23,
+ file_save_as = 1<<24,
+ edit_undo = 1<<25,
+ edit_redo = 1<<26,
+ edit_copy = 1<<27,
+ edit_cut = 1<<28,
+ edit_paste = 1<<29,
+ edit_select_all = 1<<30,
+ app_quit = 1<<31,
+ any = 0xffffffffU
+ } type;
+
+ // This constructor is for keyboard events:
+ event( type theType, // What happened?
+ unsigned char keycode, // The ASCII value.
+ int modifiers, // Ctrl, Shift, Opt, etc...
+ bool isRepeat ) : // Is the key held down?
+ type_(theType), keycode_(keycode), modifiers_(modifiers),
+ isRepeat_(isRepeat)
+ {
+ timestamp_ = date();
+ id_ = getIdentifier();
+ }
+
+ // This constructor is for mouse events:
+ event( type theType, // What happened?
+ vec2d location, // Where? (window coordinates)
+ vec2d delta, // How far has it moved?
+ int nClick, // How many consecutive clicks?
+ float pressure ) : // How hard was it pushed?
+ type_(theType), location_(location), delta_(delta), nClick_(nClick),
+ pressure_(pressure)
+ {
+ timestamp_ = date();
+ id_ = getIdentifier();
+ }
+
+ // This constructor is for other event types:
+ event( type theType ) : type_(theType) // What happened?
+ {
+ timestamp_ = date();
+ id_ = getIdentifier();
+ }
+
+ // Accessors for all event types:
+ type kind() const { return type_; }
+ const date& timestamp() const { return timestamp_; }
+ unsigned int identifier() const { return id_; }
+
+ void *userInfo() const { return userInfo_; }
+ void setUserInfo( void* userInfo ) { userInfo_ = userInfo; }
+ unsigned int tag() const { return tag_; }
+ void setTag( unsigned int tag ) { tag_ = tag; }
+
+ // Accessors for keyboard events:
+ unsigned char keycode() const { return keycode_; }
+ int modifiers() const { return modifiers_; }
+ bool isRepeat() const { return isRepeat_; }
+
+ // Accessors for mouse events:
+ const vec2d& location() const { return location_; }
+ const vec2d& delta() const { return delta_; }
+ int clicks() const { return nClick_; }
+ float pressure() const { return pressure_; }
+
+private:
+ unsigned int getIdentifier() {
+ static unsigned int identifier = 1;
+ return identifier++;
+ }
+
+ type type_;
+ date timestamp_;
+ unsigned int id_;
+ void *userInfo_;
+ unsigned int tag_;
+
+ unsigned char keycode_;
+ unsigned char modifiers_;
+ bool isRepeat_;
+
+ vec2d location_;
+ vec2d delta_;
+ int nClick_;
+ float pressure_;
+};
+
+} // namespace dc
+
+#endif // _EVENT_HH_
+
--- /dev/null
+/*
+ NET2 is a threaded, event based, network IO library for SDL.
+ Copyright (C) 2002 Bob Pendleton
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 2.1
+ of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+
+ If you do not wish to comply with the terms of the LGPL please
+ contact the author as other terms are available for a fee.
+
+ Bob Pendleton
+ Bob@Pendleton.com
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+#include "SDL_thread.h"
+
+#include "fastevents.h"
+
+//----------------------------------------
+//
+// error handling code
+//
+
+static char* error = NULL;
+
+static __inline__ void setError(char *err)
+{
+ error = err;
+}
+
+char *FE_GetError()
+{
+ return error;
+}
+
+//----------------------------------------
+//
+// Threads, mutexs, thread utils, and
+// thread safe wrappers
+//
+
+static SDL_mutex *eventLock = NULL;
+static SDL_cond *eventWait = NULL;
+static SDL_TimerID eventTimer = 0;
+
+//----------------------------------------
+//
+//
+//
+
+int FE_PushEvent(SDL_Event *ev)
+{
+ SDL_LockMutex(eventLock);
+ while (-1 == SDL_PushEvent(ev))
+ {
+ SDL_CondWait(eventWait, eventLock);
+ }
+ SDL_UnlockMutex(eventLock);
+ SDL_CondSignal(eventWait);
+
+ return 1;
+}
+
+//----------------------------------------
+//
+//
+//
+
+void FE_PumpEvents()
+{
+ SDL_LockMutex(eventLock);
+ SDL_PumpEvents();
+ SDL_UnlockMutex(eventLock);
+}
+
+//----------------------------------------
+//
+//
+//
+
+int FE_PollEvent(SDL_Event *event)
+{
+ int val = 0;
+
+ SDL_LockMutex(eventLock);
+ val = SDL_PollEvent(event);
+ SDL_UnlockMutex(eventLock);
+
+ if (0 < val)
+ {
+ SDL_CondSignal(eventWait);
+ }
+
+ return val;
+}
+
+//----------------------------------------
+//
+// Replacement for SDL_WaitEvent();
+//
+
+int FE_WaitEvent(SDL_Event *event)
+{
+ int val = 0;
+
+ SDL_LockMutex(eventLock);
+ while (0 >= (val = SDL_PollEvent(event)))
+ {
+ SDL_CondWait(eventWait, eventLock);
+ }
+ SDL_UnlockMutex(eventLock);
+ SDL_CondSignal(eventWait);
+
+ return val;
+}
+
+//----------------------------------------
+//
+//
+//
+
+static Uint32 timerCallback(Uint32 interval, void *param)
+{
+ SDL_CondBroadcast(eventWait);
+
+ return interval;
+}
+
+//----------------------------------------
+//
+//
+//
+
+int FE_Init()
+{
+ if (0 == (SDL_INIT_TIMER & SDL_WasInit(SDL_INIT_TIMER)))
+ {
+ SDL_InitSubSystem(SDL_INIT_TIMER);
+ }
+
+ eventLock = SDL_CreateMutex();
+ if (NULL == eventLock)
+ {
+ setError("FE: can't create a mutex");
+ return -1;
+ }
+
+ eventWait = SDL_CreateCond();
+ if (NULL == eventWait)
+ {
+ setError("FE: can't create a condition variable");
+ return -1;
+ }
+
+ eventTimer = SDL_AddTimer(10, timerCallback, NULL);
+ if (NULL == eventTimer)
+ {
+ setError("FE: can't add a timer");
+ return -1;
+ }
+
+ return 0;
+}
+
+//----------------------------------------
+//
+//
+//
+
+void FE_Quit()
+{
+ SDL_DestroyMutex(eventLock);
+ eventLock = NULL;
+
+ SDL_DestroyCond(eventWait);
+ eventWait = NULL;
+
+ SDL_RemoveTimer(eventTimer);
+}
--- /dev/null
+#ifndef _FASTEVENTS_H_
+#define _FASTEVENTS_H_
+/*
+ NET2 is a threaded, event based, network IO library for SDL.
+ Copyright (C) 2002 Bob Pendleton
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 2.1
+ of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+
+ If you do not wish to comply with the terms of the LGPL please
+ contact the author as other terms are available for a fee.
+
+ Bob Pendleton
+ Bob@Pendleton.com
+*/
+
+#include "SDL.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ int FE_Init(); // Initialize FE
+ void FE_Quit(); // shutdown FE
+
+ void FE_PumpEvents(); // replacement for SDL_PumpEvents
+ int FE_PollEvent(SDL_Event *event); // replacement for SDL_PollEvent
+ int FE_WaitEvent(SDL_Event *event); // replacement for SDL_WaitEvent
+ int FE_PushEvent(SDL_Event *event); // replacement for SDL_PushEvent
+
+ char *FE_GetError(); // get the last error
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include "math.hh"
+#include "vector.hh"
+#include "matrix.hh"
+
+
+namespace dc {
+
+
+vector2 vector2::zero(0.0, 0.0);
+vector3 vector3::zero(0.0, 0.0, 0.0);
+
+matrix3 matrix3::zero(0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0);
+matrix3 matrix3::identity(1.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 0.0, 1.0);
+
+matrix4 matrix4::zero(0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0,
+ 0.0, 0.0, 0.0, 0.0);
+matrix4 matrix4::identity(1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+/**
+ * @file math.hh
+ * General math-related types and functions.
+ */
+
+#ifndef _MATH_HH_
+#define _MATH_HH_
+
+#include <cmath>
+
+
+namespace dc {
+
+
+typedef double scalar; ///< Scalar variable.
+
+
+// Here's a simple way to check the equality of floating-point variables more
+// reliably using approximation.
+
+const scalar default_epsilon = 0.00001; ///< @see equals()
+
+
+/**
+ * Check the equality of scalars with a certain degree of error allowed.
+ */
+
+inline bool equals(scalar a, scalar b, scalar epsilon = default_epsilon)
+{
+ return std::abs(a - b) < epsilon;
+}
+
+
+} // namespace dc
+
+
+#endif // _MATH_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _MATRIX_HH_
+#define _MATRIX_HH_
+
+/**
+ * @file matrix.hh
+ * Matrix classes.
+ */
+
+#include <cassert>
+
+#include "math.hh"
+
+
+namespace dc {
+
+/**
+ * 3x3 matrix.
+ */
+
+struct matrix3
+{
+ matrix3() {}
+ matrix3(scalar M11, scalar M12, scalar M13,
+ scalar M21, scalar M22, scalar M23,
+ scalar M31, scalar M32, scalar M33)
+ {
+ m11 = M11; m12 = M12; m13 = M13;
+ m21 = M21; m22 = M22; m23 = M23;
+ m31 = M31; m32 = M32; m33 = M33;
+ }
+ matrix3(scalar m[9])
+ {
+ array[0] = m[0]; array[1] = m[1]; array[2] = m[2];
+ array[3] = m[3]; array[4] = m[4]; array[5] = m[5];
+ array[6] = m[6]; array[7] = m[7]; array[8] = m[8];
+ }
+
+ const scalar& operator[](int i) const
+ {
+ assert(i >= 0 && i <= 8 && "Index into matrix3 out of bounds.");
+ return array[i];
+ }
+ scalar& operator[](int i)
+ {
+ assert(i >= 0 && i <= 8 && "Index into matrix3 out of bounds.");
+ return array[i];
+ }
+
+ matrix3 operator+(const matrix3& m) const
+ {
+ return matrix3(m11 + m.m11, m12 + m.m12, m13 + m.m13,
+ m21 + m.m21, m22 + m.m22, m23 + m.m23,
+ m31 + m.m31, m32 + m.m32, m33 + m.m33);
+ }
+ matrix3 operator-(const matrix3& m) const
+ {
+ return matrix3(m11 - m.m11, m12 - m.m12, m13 - m.m13,
+ m21 - m.m21, m22 - m.m22, m23 - m.m23,
+ m31 - m.m31, m32 - m.m32, m33 - m.m33);
+ }
+ matrix3 operator*(const matrix3& m) const
+ {
+ return matrix3(m11 * m.m11 + m12 * m.m21 + m13 * m.m31,
+ m11 * m.m12 + m12 * m.m22 + m13 * m.m32,
+ m11 * m.m13 + m12 * m.m23 + m13 * m.m33,
+ m21 * m.m11 + m22 * m.m21 + m23 * m.m31,
+ m21 * m.m12 + m22 * m.m22 + m23 * m.m32,
+ m21 * m.m13 + m22 * m.m23 + m23 * m.m33,
+ m31 * m.m11 + m32 * m.m21 + m33 * m.m31,
+ m31 * m.m12 + m32 * m.m22 + m33 * m.m32,
+ m32 * m.m13 + m32 * m.m23 + m33 * m.m33);
+ }
+ matrix3 operator*(scalar s) const
+ {
+ return matrix3(m11 * s, m12 * s, m13 * s,
+ m21 * s, m22 * s, m23 * s,
+ m31 * s, m32 * s, m33 * s);
+ }
+ matrix3 operator/(scalar s) const
+ {
+ return matrix3(m11 / s, m12 / s, m13 / s,
+ m21 / s, m22 / s, m23 / s,
+ m31 / s, m32 / s, m33 / s);
+ }
+
+ matrix3& operator+=(const matrix3& m)
+ {
+ m11 += m.m11; m12 += m.m12; m13 += m.m13;
+ m21 += m.m21; m22 += m.m22; m23 += m.m23;
+ m31 += m.m31; m32 += m.m32; m33 += m.m33;
+ return *this;
+ }
+ matrix3& operator-=(const matrix3& m)
+ {
+ m11 -= m.m11; m12 -= m.m12; m13 -= m.m13;
+ m21 -= m.m21; m22 -= m.m22; m23 -= m.m23;
+ m31 -= m.m31; m32 -= m.m32; m33 -= m.m33;
+ return *this;
+ }
+ matrix3& operator*=(const matrix3& m)
+ {
+ return *this = *this * m;
+ }
+ matrix3& operator*=(scalar s)
+ {
+ m11 *= s; m12 *= s; m13 *= s;
+ m21 *= s; m22 *= s; m23 *= s;
+ m31 *= s; m32 *= s; m33 *= s;
+ return *this;
+ }
+ matrix3& operator/=(scalar s)
+ {
+ m11 /= s; m12 /= s; m13 /= s;
+ m21 /= s; m22 /= s; m23 /= s;
+ m31 /= s; m32 /= s; m33 /= s;
+ return *this;
+ }
+
+ matrix3 operator-() const
+ {
+ return matrix3(-m11, -m12, -m13,
+ -m21, -m22, -m23,
+ -m31, -m32, -m33);
+ }
+
+ bool operator==(const matrix3& m) const
+ {
+ return equals(m11,m.m11) && equals(m12,m.m12) && equals(m13,m.m13) &&
+ equals(m21,m.m21) && equals(m22,m.m22) && equals(m23,m.m23) &&
+ equals(m31,m.m31) && equals(m32,m.m32) && equals(m33,m.m33);
+ }
+ bool operator!=(const matrix3& m) const
+ {
+ return !(*this == m);
+ }
+
+
+ union
+ {
+ struct
+ {
+ scalar m11, m21, m31;
+ scalar m12, m22, m32;
+ scalar m13, m23, m33; ///< scalars
+ };
+ scalar array[9]; ///< array
+ };
+
+ static matrix3 zero; ///< zero matrix
+ static matrix3 identity; ///< identity matrix
+};
+
+inline matrix3 operator*(scalar s, const matrix3& m)
+{
+ return m * s;
+}
+inline matrix3 operator/(scalar s, const matrix3& m)
+{
+ return matrix3(s / m.m11, s / m.m12, s / m.m13,
+ s / m.m21, s / m.m22, s / m.m23,
+ s / m.m31, s / m.m32, s / m.m33);
+}
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+/**
+ * 4x4 matrix.
+ */
+
+struct matrix4
+{
+ matrix4() {}
+ matrix4(scalar M11, scalar M12, scalar M13, scalar M14,
+ scalar M21, scalar M22, scalar M23, scalar M24,
+ scalar M31, scalar M32, scalar M33, scalar M34,
+ scalar M41, scalar M42, scalar M43, scalar M44)
+ {
+ m11 = M11; m12 = M12; m13 = M13; m14 = M14;
+ m21 = M21; m22 = M22; m23 = M23; m24 = M24;
+ m31 = M31; m32 = M32; m33 = M33; m34 = M34;
+ m41 = M41; m42 = M42; m43 = M43; m44 = M44;
+ }
+ matrix4(scalar m[15])
+ {
+ array[0] = m[0]; array[1] = m[1]; array[2] = m[2]; array[3] = m[3];
+ array[4] = m[4]; array[5] = m[5]; array[6] = m[6]; array[7] = m[7];
+ array[8] = m[8]; array[9] = m[9]; array[10] = m[10]; array[11] = m[11];
+ array[12] = m[12]; array[13] = m[13]; array[14] = m[14]; array[15] = m[15];
+ }
+
+ const scalar& operator[](int i) const
+ {
+ assert(i >= 0 && i <= 15 && "Index into matrix4 out of bounds.");
+ return array[i];
+ }
+ scalar& operator[](int i)
+ {
+ assert(i >= 0 && i <= 15 && "Index into matrix4 out of bounds.");
+ return array[i];
+ }
+
+ matrix4 operator+(const matrix4& m) const
+ {
+ return matrix4(m11 + m.m11, m12 + m.m12, m13 + m.m13, m14 + m.m14,
+ m21 + m.m21, m22 + m.m22, m23 + m.m23, m24 + m.m24,
+ m31 + m.m31, m32 + m.m32, m33 + m.m33, m34 + m.m34,
+ m41 + m.m41, m42 + m.m42, m43 + m.m43, m44 + m.m44);
+ }
+ matrix4 operator-(const matrix4& m) const
+ {
+ return matrix4(m11 - m.m11, m12 - m.m12, m13 - m.m13, m14 - m.m14,
+ m21 - m.m21, m22 - m.m22, m23 - m.m23, m24 - m.m24,
+ m31 - m.m31, m32 - m.m32, m33 - m.m33, m34 - m.m34,
+ m41 - m.m41, m42 - m.m42, m43 - m.m43, m44 - m.m44);
+ }
+ matrix4 operator*(const matrix4& m) const // TODO ??
+ {
+ return matrix4(m11 * m.m11 + m12 * m.m21 + m13 * m.m31 + m14 * m.m41,
+ m11 * m.m12 + m12 * m.m22 + m13 * m.m32 + m14 * m.m42,
+ m11 * m.m13 + m12 * m.m23 + m13 * m.m33 + m14 * m.m43,
+ m11 * m.m14 + m12 * m.m24 + m13 * m.m34 + m14 * m.m44,
+ m21 * m.m11 + m22 * m.m21 + m23 * m.m31 + m24 * m.m41,
+ m21 * m.m12 + m22 * m.m22 + m23 * m.m32 + m24 * m.m42,
+ m21 * m.m13 + m22 * m.m23 + m23 * m.m33 + m24 * m.m43,
+ m21 * m.m14 + m22 * m.m24 + m23 * m.m34 + m24 * m.m44,
+ m31 * m.m11 + m32 * m.m21 + m33 * m.m31 + m34 * m.m41,
+ m31 * m.m12 + m32 * m.m22 + m33 * m.m32 + m34 * m.m42,
+ m31 * m.m13 + m32 * m.m23 + m33 * m.m33 + m34 * m.m43,
+ m31 * m.m14 + m32 * m.m24 + m33 * m.m34 + m34 * m.m44,
+ m41 * m.m11 + m42 * m.m21 + m43 * m.m31 + m44 * m.m41,
+ m41 * m.m12 + m42 * m.m22 + m43 * m.m32 + m44 * m.m42,
+ m41 * m.m13 + m42 * m.m23 + m43 * m.m33 + m44 * m.m43,
+ m41 * m.m14 + m42 * m.m24 + m43 * m.m34 + m44 * m.m44);
+ }
+ matrix4 operator*(scalar s) const
+ {
+ return matrix4(m11 * s, m12 * s, m13 * s, m14 * s,
+ m21 * s, m22 * s, m23 * s, m24 * s,
+ m31 * s, m32 * s, m33 * s, m34 * s,
+ m41 * s, m42 * s, m43 * s, m44 * s);
+ }
+ matrix4 operator/(scalar s) const
+ {
+ return matrix4(m11 / s, m12 / s, m13 / s, m14 / s,
+ m21 / s, m22 / s, m23 / s, m24 / s,
+ m31 / s, m32 / s, m33 / s, m34 / s,
+ m41 / s, m42 / s, m43 / s, m44 / s);
+ }
+
+ matrix4& operator+=(const matrix4& m)
+ {
+ m11 += m.m11; m12 += m.m12; m13 += m.m13; m14 += m.m14;
+ m21 += m.m21; m22 += m.m22; m23 += m.m23; m24 += m.m24;
+ m31 += m.m31; m32 += m.m32; m33 += m.m33; m34 += m.m34;
+ m41 += m.m41; m42 += m.m42; m43 += m.m43; m44 += m.m44;
+ return *this;
+ }
+ matrix4& operator-=(const matrix4& m)
+ {
+ m11 -= m.m11; m12 -= m.m12; m13 -= m.m13; m14 -= m.m14;
+ m21 -= m.m21; m22 -= m.m22; m23 -= m.m23; m24 -= m.m24;
+ m31 -= m.m31; m32 -= m.m32; m33 -= m.m33; m34 -= m.m34;
+ m41 -= m.m41; m42 -= m.m42; m43 -= m.m43; m44 -= m.m44;
+ return *this;
+ }
+ matrix4& operator*=(const matrix4& m)
+ {
+ *this = *this * m;
+ return *this;
+ }
+ matrix4& operator*=(scalar s)
+ {
+ m11 *= s; m12 *= s; m13 *= s; m14 *= s;
+ m21 *= s; m22 *= s; m23 *= s; m24 *= s;
+ m31 *= s; m32 *= s; m33 *= s; m34 *= s;
+ m41 *= s; m42 *= s; m43 *= s; m44 *= s;
+ return *this;
+ }
+ matrix4& operator/=(scalar s)
+ {
+ m11 /= s; m12 /= s; m13 /= s; m14 /= s;
+ m21 /= s; m22 /= s; m23 /= s; m24 /= s;
+ m31 /= s; m32 /= s; m33 /= s; m34 /= s;
+ m41 /= s; m42 /= s; m43 /= s; m44 /= s;
+ return *this;
+ }
+
+ matrix4 operator-() const
+ {
+ return matrix4(-m11, -m12, -m13, -m14,
+ -m21, -m22, -m23, -m24,
+ -m31, -m32, -m33, -m34,
+ -m41, -m42, -m43, -m44);
+ }
+
+ bool operator==(const matrix4& m) const
+ {
+ return equals(m11,m.m11) && equals(m12,m.m12) && equals(m13,m.m13) &&
+ equals(m14,m.m14) && equals(m21,m.m21) && equals(m22,m.m22) &&
+ equals(m23,m.m23) && equals(m24,m.m24) && equals(m31,m.m31) &&
+ equals(m32,m.m32) && equals(m33,m.m33) && equals(m34,m.m34) &&
+ equals(m41,m.m41) && equals(m42,m.m42) && equals(m43,m.m43) &&
+ equals(m44,m.m44);
+ }
+ bool operator!=(const matrix4& m) const
+ {
+ return !(*this == m);
+ }
+
+
+ union
+ {
+ struct
+ {
+ scalar m11, m21, m31, m41;
+ scalar m12, m22, m32, m42;
+ scalar m13, m23, m33, m43;
+ scalar m14, m24, m34, m44; ///< scalars
+ };
+ scalar array[16]; ///< array
+ };
+
+ static matrix4 zero; ///< zero matrix
+ static matrix4 identity; ///< identity matrix
+};
+
+inline matrix4 operator*(scalar s, const matrix4& m)
+{
+ return m * s;
+}
+inline matrix4 operator/(scalar s, const matrix4& m)
+{
+ return matrix4(s / m.m11, s / m.m12, s / m.m13, s / m.m14,
+ s / m.m21, s / m.m22, s / m.m23, s / m.m24,
+ s / m.m31, s / m.m32, s / m.m33, s / m.m34,
+ s / m.m41, s / m.m42, s / m.m43, s / m.m44);
+}
+
+
+} // namespace dc
+
+
+#endif // _MATRIX_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _GL_HH_
+#define _GL_HH_
+
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#include <OpenGL/glu.h>
+#include <OpenGL/glext.h>
+#else
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <GL/glext.h>
+#endif
+
+#endif // _GL_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _PROFILER_HH_
+#define _PROFILER_HH_
+
+/**
+ * @file profiler.hh
+ * Braindead-simple profiler.
+ */
+
+#include <ctime>
+
+
+namespace dc {
+
+class profiler
+{
+public:
+ profiler(const char* name = "")
+ {
+ start(name);
+ }
+ ~profiler()
+ {
+ stop();
+ }
+
+ void start(const char* name = "")
+ {
+ begin = std::clock();
+ std::cout << "Profiling " << name << "... ";
+ }
+
+ void stop()
+ {
+ if (begin == -1) return;
+ double elapsed = double(std::clock() - begin) / double(CLOCKS_PER_SEC);
+ std::cout << elapsed << " sec" << std::endl;
+ begin = -1;
+ }
+
+ void cancel()
+ {
+ begin = -1;
+ }
+
+private:
+ std::clock_t begin;
+};
+
+} // namespace dc
+
+
+#endif // _PROFILER_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _QUATERNION_HH_
+#define _QUATERNION_HH_
+
+#include <cassert>
+
+#include "math.hh"
+#include "matrix.hh"
+#include "vector.hh"
+
+
+//
+// Quaternion -> 3x3 Matrix
+//
+// | w^2 + x^2 - y^2 - z^2 2xy - 2wz 2xz + 2yw |
+// | 2xy + 2wz w^2 - x^2 + y^2 - z^2 2yz - 2wx |
+// | 2xz - 2wy 2yz - 2wx w^2 - x^2 - y^2 + z^2 |
+//
+
+namespace dc {
+
+
+class quaternion
+{
+public:
+ // Constructors.
+ quaternion() {}
+ quaternion(scalar X, scalar Y, scalar Z, scalar W) {
+ vec.x = X; vec.y = Y; vec.z = Z; w = W;
+ }
+ quaternion(vector3 v, scalar W = 1.0) {
+ vec = v; w = W;
+ }
+ quaternion(scalar q[4]) {
+ vec.x = q[0]; vec.y = q[1]; vec.z = q[2]; w = q[3];
+ }
+
+ // Accessible by index.
+ const scalar& operator [] (int i) const {
+ assert(i >= 0 && i <= 3 && "Index into quaternion out of bounds.");
+ return *((&vec.x) + i);
+ }
+ scalar& operator [] (int i) {
+ assert(i >= 0 && i <= 3 && "Index into quaternion out of bounds.");
+ //return vec[i];
+ return *((&vec.x) + i);
+ }
+
+ // Basic maths.
+ quaternion operator + (const quaternion& q) const {
+ return quaternion(vec + q.vec, w + q.w);
+ }
+ quaternion operator - (const quaternion& q) const {
+ return quaternion(vec - q.vec, w - q.w);
+ }
+ quaternion operator * (const quaternion& q) const {
+ return quaternion(q.w * vec + w * q.vec + q.vec.cross(vec),
+ w * q.w - q.vec.dot(vec));
+ }
+ quaternion operator * (scalar s) const {
+ return quaternion(vec * s, w * s);
+ }
+ quaternion operator / (scalar s) const {
+ return quaternion(vec / s, w / s);
+ }
+
+ quaternion& operator += (const quaternion& q) {
+ vec += q.vec; w += q.w;
+ return *this;
+ }
+ quaternion& operator -= (const quaternion& q) {
+ vec -= q.vec; w -= q.w;
+ return *this;
+ }
+ quaternion& operator *= (const quaternion& q) {
+ scalar W = w;
+ w = W * q.w - q.vec.dot(vec);
+ vec = q.w * vec + W * q.vec + q.vec.cross(vec);
+ return *this;
+ }
+ quaternion& operator *= (scalar s) {
+ vec *= s; w *= s;
+ return *this;
+ }
+ quaternion& operator /= (scalar s) {
+ vec /= s; w /= s;
+ return *this;
+ }
+
+ // Unary operators.
+ quaternion operator - () const {
+ return quaternion(-vec, -w);
+ }
+
+ // Quaternion operations.
+ quaternion conjugate() const {
+ return quaternion(-vec, w);
+ }
+ void normalize(const vector3& v)
+ {
+ scalar len = length();
+ if (len != 0.0) { *this /= len; }
+ }
+
+ scalar length2() const {
+ return vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + w * w;
+ }
+ scalar length() const {
+ return std::sqrt(length2());
+ }
+
+ // Converting to other types.
+ matrix3 matrix() const {
+ scalar x2 = vec.x * vec.x;
+ scalar y2 = vec.y * vec.y;
+ scalar z2 = vec.z * vec.z;
+ scalar w2 = w * w;
+ scalar xy = vec.x * vec.y;
+ scalar xz = vec.x * vec.z;
+ scalar yzwx = 2 * (vec.y * vec.z - w * vec.x);
+ scalar wy = w * vec.y;
+ scalar wz = w * vec.z;
+ return matrix3(x2 - y2 - z2 + w2, 2 * (xy - wz), 2 * (xz + wy),
+ 2 * (xy + wz), w2 - x2 + y2 - z2, yzwx,
+ 2 * (xz - wy), yzwx, w2 - x2 - y2 + z2);
+ }
+ vector3 axis(scalar& angle) { // Axis of rotation, w/ angle of rotation.
+ vector3 axisVec = axis();
+ angle = 2 * std::acos(w);
+ return axisVec;
+ }
+ vector3 axis() {
+ scalar sa = std::sqrt(1 - w * w);
+ return vec / sa;
+ }
+
+ // Checking equality.
+ bool operator == (const quaternion& q) const {
+ return vec == q.vec && equals(w,q.w);
+ }
+ bool operator != (const quaternion& q) const {
+ return !(*this == q);
+ }
+
+ // Data.
+ vector3 vec;
+ scalar w;
+};
+
+inline quaternion operator * (scalar s, const quaternion& q) {
+ return q * s;
+}
+inline quaternion operator / (scalar s, const quaternion& q) {
+ return quaternion(s / q.vec, s / q.w);
+}
+
+} // namespace dc
+
+
+#endif // _QUATERNION_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <cstdlib> // srand, rand, RAND_MAX
+#include <ctime> // time
+#include <cmath> // log
+#include <climits> // ULONG_MAX
+
+#include "random.hh"
+
+
+namespace rng {
+
+unsigned seed(unsigned theSeed)
+{
+ srand(theSeed);
+ return theSeed;
+}
+
+unsigned seed()
+{
+ return seed(time(0));
+}
+
+
+template <typename T>
+T get()
+{
+ const float ln2 = 0.693147;
+ static const unsigned bitsPerPiece = std::log(float(RAND_MAX)) / ln2;
+ static const unsigned sizeOfType = sizeof(T) * 8;
+ static const unsigned pieces = sizeOfType / bitsPerPiece +
+ ((sizeOfType % bitsPerPiece) ? 1 : 0);
+
+ T bits = 0;
+
+ // we need to call rand() multiple times if it won't provide enough random
+ // bits to fill the size of the given type
+ for (unsigned i = 0; i < pieces; i++)
+ {
+ long piece = rand();
+ bits |= piece << (i * bitsPerPiece);
+ }
+
+ return bits;
+}
+
+
+template <>
+bool get<bool>()
+{
+ return rand() % 2;
+}
+
+template <typename T>
+T get(T lower, T upper)
+{
+ unsigned short randInt = get<unsigned int>();
+ return lower + T(randInt % (upper - lower + 1));
+}
+
+template <>
+float get(float lower, float upper)
+{
+ unsigned long randInt = get<unsigned long>();
+ return (float(randInt) / float(ULONG_MAX)) * (upper - lower) + lower;
+}
+
+template <>
+double get(double lower, double upper)
+{
+ unsigned long long randInt = get<unsigned long long>();
+ return (double(randInt) / double(ULLONG_MAX)) * (upper - lower) + lower;
+}
+
+template <>
+float get()
+{
+ return get<float>(0.0, 1.0);
+}
+
+template <>
+double get()
+{
+ return get<double>(0.0, 1.0);
+}
+
+
+}; // namespace rng
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _RNG_RANDOM_HH_
+#define _RNG_RANDOM_HH_
+
+/**
+ * @file random.hh
+ * Simple pseudo-random number generators.
+ */
+
+
+namespace rng {
+
+/**
+ * Provide the RNG with a seed.
+ * @param theSeed
+ * @return theSeed
+ */
+
+unsigned seed(unsigned theSeed);
+
+/**
+ * Seed the RNG with the current time. This is good enough in most cases.
+ * @return The seed used.
+ */
+
+unsigned seed();
+
+
+/**
+ * The most generic generator gets enough random bits to fill the integer type.
+ * @return Random value of maximum domain for type T.
+ */
+
+template <typename T>
+T get();
+
+
+/**
+ * Get a random boolean value.
+ * @return True or false.
+ */
+
+template <>
+bool get<bool>();
+
+
+/**
+ * Get a random integer value with a limited domain.
+ * @param lower Smallest possible value.
+ * @param upper Largest possible value.
+ * @return Integer between lower and upper, inclusive.
+ */
+
+template <typename T>
+T get(T lower, T upper);
+
+
+/**
+ * Get a random float with a limited domain.
+ * @param lower Smallest possible value.
+ * @param upper Largest possible value.
+ * @return Float between lower and upper, inclusive.
+ */
+
+template <>
+float get(float lower, float upper);
+
+/**
+ * Get a random double with a limited domain.
+ * @param lower Smallest possible value.
+ * @param upper Largest possible value.
+ * @return Double between lower and upper, inclusive.
+ */
+
+template <>
+double get(double lower, double upper);
+
+/**
+ * Get a random float with a domain limited to [0.0, 1.0].
+ * @return Float between 0.0 and 1.0, inclusive.
+ */
+
+template <>
+float get();
+
+/**
+ * Get a random double with a domain limited to [0.0, 1.0].
+ * @return Double between 0.0 and 1.0, inclusive.
+ */
+
+template <>
+double get();
+
+
+}; // namespace rng
+
+
+#endif // _RNG_RANDOM_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <algorithm>
+
+#include "rectangle.hh"
+
+
+namespace dc {
+
+
+bool rectangle::containsRect(const rectangle& r) const
+{
+ point o = r.origin;
+ point s = r.size;
+ if (origin.x <= o.x && origin.y <= o.y)
+ {
+ scalar a = origin.x + size.x;
+ scalar b = origin.y + size.y;
+ scalar c = o.x + s.x;
+ scalar d = o.y + s.y;
+ return o.x <= a && o.y <= b && origin.x <= c &&
+ origin.y <= d && c <= a && d <= b;
+ }
+ return false;
+}
+
+bool rectangle::intersectsRect(const rectangle& r) const
+{
+ // TODO - Perhaps this could be optimized if it proves to be a bottleneck.
+ rectangle rect = intersectionWith(r);
+ return rect.isValid();
+}
+
+rectangle rectangle::unionWith(const rectangle& r) const
+{
+ point o = r.origin;
+ point s = r.size;
+ scalar a = std::min(origin.x, o.x);
+ scalar b = std::min(origin.y, o.y);
+ return rectangle(point(a, b),
+ point(std::max(origin.x + size.x, o.x + s.x) - a,
+ std::max(origin.y + size.y, o.y + s.y) - b));
+}
+
+rectangle rectangle::intersectionWith(const rectangle& r) const
+{
+ point o = r.origin;
+ point s = r.size;
+ scalar a = std::max(origin.x, o.x);
+ scalar b = std::max(origin.y, o.y);
+ return rectangle(point(a, b),
+ point(std::min(origin.x + size.x, o.x + s.x) - a,
+ std::min(origin.y + size.y, o.y + s.y) - b));
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _RECTANGLE_HH_
+#define _RECTANGLE_HH_
+
+#include "math.hh"
+#include "vector.hh"
+
+
+namespace dc {
+
+//
+// A rectangle is a 2d shape defined by point (origin) and size (width & height)
+// vectors. The usual rectangle maths are available. Valid rectangles have
+// positive width and height. Invalid rectangles will be returned for invalid
+// operations such as trying to get the intersection of two rectangles which
+// don't intersect. Using an invalid rectangle is undefined, but it may be used
+// after "fixing" it using the fix method which will cause the size to be
+// positive and adjust the origin to be the bottom-left point. Check the
+// validity of a rectangle using the isValid method especially if the rectangle
+// is a result of an operation which could fail.
+//
+
+class rectangle
+{
+public:
+ // Constructors.
+ rectangle() {}
+ rectangle(point o, point s) {
+ origin = o;
+ size = s;
+ }
+
+ // Rectangle validity.
+ bool isValid() const { return size.x >= 0.0 && size.y >= 0.0; }
+ void fix()
+ {
+ if (size.x <= 0.0)
+ {
+ size.x = 0.0 - size.x;
+ origin.x -= size.x;
+ }
+ if (size.y <= 0.0)
+ {
+ size.y = 0.0 - size.y;
+ origin.y -= size.y;
+ }
+ }
+
+ // Rectangle operations.
+ scalar area() const { return size.x * size.y; }
+ scalar perimeter() const {
+ return size.x + size.x + size.y + size.y;
+ }
+
+ bool containsPoint(point pt) const
+ {
+ return origin.x <= pt.x && origin.y <= pt.y &&
+ pt.x <= origin.x + size.x && pt.y <= origin.y + size.y;
+ }
+
+ void inset(scalar h, scalar v)
+ {
+ origin.x += h;
+ origin.y += v;
+ size.x -= h + h;
+ size.y -= v + v;
+ }
+ void offset(scalar h, scalar v)
+ {
+ origin.x -= h;
+ origin.y -= v;
+ size.x += h + h;
+ size.y += v + v;
+ }
+
+ bool containsRect(const rectangle& r) const;
+ bool intersectsRect(const rectangle& r) const;
+ rectangle unionWith(const rectangle& r) const;
+ rectangle intersectionWith(const rectangle& r) const;
+
+ // Checking equality.
+ bool operator == (const rectangle& r) const {
+ return origin == r.origin && size == r.size;
+ }
+ bool operator != (const rectangle& r) const {
+ return !(*this == r);
+ }
+
+ // Data.
+ point origin, size;
+};
+
+} // namespace dc
+
+
+#endif // _RECTANGLE_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include "serializable.hh"
+
+
+namespace dc {
+
+
+serializable::~serializable()
+{
+}
+
+
+bool serializable::get(long& value)
+{
+ return false;
+}
+
+bool serializable::get(double& value)
+{
+ return false;
+}
+
+bool serializable::get(bool& value)
+{
+ return false;
+}
+
+bool serializable::get(std::string& value)
+{
+ return false;
+}
+
+bool serializable::get(std::wstring& value)
+{
+ return false;
+}
+
+bool serializable::get(std::vector<serializable_ptr>& value)
+{
+ return false;
+}
+
+bool serializable::get(std::map<std::string,serializable_ptr>& value)
+{
+ return false;
+}
+
+bool serializable::isNull()
+{
+ return false;
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _SERIALIZABLE_HH_
+#define _SERIALIZABLE_HH_
+
+#include <iostream>
+#include <string>
+#include <map>
+#include <vector>
+
+#include "serializer.hh"
+#include "deserializer.hh"
+#include "stringtools.hh"
+
+
+namespace dc {
+
+
+class serializable
+{
+public:
+ virtual ~serializable();
+
+ virtual void serialize(serializer& out) const = 0;
+ virtual void deserialize(deserializer& in) = 0;
+
+ virtual void print() const = 0;
+
+ virtual bool get(long& value);
+ virtual bool get(double& value);
+ virtual bool get(bool& value);
+ virtual bool get(std::string& value);
+ virtual bool get(std::wstring& value);
+ virtual bool get(std::vector<serializable_ptr>& value);
+ virtual bool get(std::map<std::string,serializable_ptr>& value);
+ virtual bool isNull();
+};
+
+
+template <class T>
+class wrapper : public serializable
+{
+public:
+ wrapper() {}
+ wrapper(const T& var) : variable(var) {}
+
+ void serialize(serializer& out) const;
+ void deserialize(deserializer& in);
+
+ void print() const;
+ bool get(T& value);
+
+public:
+ T variable;
+};
+
+
+class null : public serializable
+{
+public:
+ null() {}
+ void serialize(serializer& out) const;
+ void deserialize(deserializer& in);
+
+ void print() const;
+ bool isNull();
+};
+
+
+typedef wrapper<long> wrapped_integer;
+typedef wrapper<double> wrapped_real;
+typedef wrapper<bool> wrapped_boolean;
+typedef wrapper<std::string> wrapped_string;
+typedef wrapper<std::wstring> wrapped_wstring;
+typedef wrapper<std::vector<serializable_ptr> > wrapped_array;
+typedef wrapper<std::map<std::string,serializable_ptr> > wrapped_dictionary;
+
+
+
+template <class T>
+inline void wrapper<T>::serialize(serializer& out) const
+{
+ out.push(variable);
+}
+
+template <>
+inline void
+wrapper<std::vector<serializable_ptr> >::serialize(serializer& out) const
+{
+ out.pushArrayHead();
+
+ std::vector<serializable_ptr>::const_iterator i;
+ for (i = variable.begin(); i < variable.end(); i++)
+ {
+ (*i)->serialize(out);
+ }
+
+ out.pushArrayTail();
+}
+
+template <>
+inline void
+wrapper<std::map<std::string,serializable_ptr> >::serialize(serializer& out) const
+{
+ out.pushMapHead();
+
+ std::map<std::string,serializable_ptr>::const_iterator i;
+ for (i = variable.begin(); i != variable.end(); i++)
+ {
+ out.push((*i).first);
+ (*i).second->serialize(out);
+ }
+
+ out.pushMapTail();
+}
+
+inline void null::serialize(serializer& out) const
+{
+ out.pushNull();
+}
+
+
+template <class T>
+inline void wrapper<T>::deserialize(deserializer& in)
+{
+ in.pop();
+}
+
+template <>
+inline void wrapper<std::vector<serializable_ptr> >::deserialize(deserializer& in)
+{
+ serializable_ptr obj;
+
+ in.pop();
+
+ while (obj = in.deserialize())
+ {
+ variable.push_back(serializable_ptr(obj));
+ }
+
+ in.pop();
+}
+
+template <>
+inline void
+wrapper<std::map<std::string,serializable_ptr> >::deserialize(deserializer& in)
+{
+ serializable_ptr obj;
+
+ in.pop();
+
+ while (obj = in.deserialize())
+ {
+ std::string key;
+ if (obj->get(key))
+ {
+ variable[key] = in.deserialize();
+ }
+ }
+
+ in.pop();
+}
+
+inline void null::deserialize(deserializer& in)
+{
+ in.pop();
+}
+
+
+template <class T>
+inline void wrapper<T>::print() const
+{
+ std::cout << std::boolalpha << typeid(T).name() << "(" << variable << ")";
+}
+
+template <>
+inline void wrapper<std::wstring>::print() const
+{
+ std::wcout << variable;
+}
+
+template <>
+inline void wrapper<std::vector<serializable_ptr> >::print() const
+{
+ std::cout << "array";
+}
+
+template <>
+inline void wrapper<std::map<std::string,serializable_ptr> >::print() const
+{
+ std::cout << "dictionary";
+}
+
+inline void null::print() const
+{
+ std::cout << "null";
+}
+
+
+template <class T>
+inline bool wrapper<T>::get(T& value)
+{
+ value = variable;
+ return true;
+}
+
+inline bool null::isNull()
+{
+ return true;
+}
+
+
+} // namespace dc
+
+#endif // _SERIALIZABLE_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <fstream>
+
+#include <yajl/yajl_gen.h>
+
+#include "stringtools.hh"
+#include "serializer.hh"
+
+
+namespace dc {
+
+
+class serializer_impl
+{
+public:
+ serializer_impl(const std::string& filePath, const std::string& indent = "")
+ {
+ std::ofstream* output = new std::ofstream(filePath.c_str());
+ init(*output, true, indent);
+ }
+
+ serializer_impl(std::ostream& output, const std::string& indent = "")
+ {
+ init(output, false, indent);
+ }
+
+ ~serializer_impl()
+ {
+ if (deleteWhenDone)
+ {
+ delete out;
+ }
+ yajl_gen_free(gen);
+ }
+
+ static void throwError(yajl_gen_status err)
+ {
+ switch (err)
+ {
+ case yajl_gen_generation_complete:
+ throw serializer::generator_error("the archive has already terminated");
+ case yajl_gen_keys_must_be_strings:
+ throw serializer::generator_error("map keys must be strings");
+ case yajl_max_depth_exceeded:
+ throw serializer::generator_error("maximum archive depth exceeded");
+ case yajl_gen_in_error_state:
+ throw serializer::generator_error("serializer already in error state");
+ }
+ }
+
+ yajl_gen gen;
+
+ std::ostream* out;
+ bool deleteWhenDone;
+
+private:
+ void init(std::ostream& output, bool deleteOut, const std::string& indent)
+ {
+ yajl_gen_config config;
+
+ out = &output;
+ deleteWhenDone = deleteOut;
+
+ if (indent != "")
+ {
+ config.beautify = true;
+ config.indentString = 0;
+ // FIXME: a yajl bug prevents using heap-allocated strings
+ //config.indentString = indent.c_str();
+ }
+ else
+ {
+ config.beautify = false;
+ }
+ gen = yajl_gen_alloc(&config, 0);
+ }
+};
+
+
+serializer::serializer(const std::string& filePath, const std::string& indent) :
+ impl(new serializer_impl(filePath, indent)) {}
+
+serializer::serializer(std::ostream& output, const std::string& indent) :
+ impl(new serializer_impl(output, indent)) {}
+
+serializer::~serializer()
+{
+ flush();
+}
+
+
+void serializer::push(long value)
+{
+ yajl_gen_status stat = yajl_gen_integer(impl->gen, value);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::push(double value)
+{
+ yajl_gen_status stat = yajl_gen_double(impl->gen, value);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::push(bool value)
+{
+ yajl_gen_status stat = yajl_gen_bool(impl->gen, value);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::push(const std::string& value)
+{
+ yajl_gen_status stat = yajl_gen_string(impl->gen,
+ (const unsigned char*)value.c_str(), value.length());
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::push(const std::wstring& value)
+{
+ push(wideToMulti(value));
+}
+
+void serializer::pushNull()
+{
+ yajl_gen_status stat = yajl_gen_null(impl->gen);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+
+void serializer::pushMapHead()
+{
+ yajl_gen_status stat = yajl_gen_map_open(impl->gen);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::pushMapTail()
+{
+ yajl_gen_status stat = yajl_gen_map_close(impl->gen);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::pushArrayHead()
+{
+ yajl_gen_status stat = yajl_gen_array_open(impl->gen);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+void serializer::pushArrayTail()
+{
+ yajl_gen_status stat = yajl_gen_array_close(impl->gen);
+ if (stat != yajl_gen_status_ok) serializer_impl::throwError(stat);
+}
+
+
+void serializer::flush()
+{
+ const unsigned char* buffer;
+ unsigned length;
+
+ yajl_gen_get_buf(impl->gen, &buffer, &length);
+ impl->out->write((const char*)buffer, length);
+ yajl_gen_clear(impl->gen);
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _SERIALIZER_HH_
+#define _SERIALIZER_HH_
+
+/**
+ * @file serializer.hh
+ * Serialize structures and types for output on a stream.
+ */
+
+#include <ostream>
+#include <string>
+#include <stdexcept>
+
+#include <boost/shared_ptr.hpp>
+
+
+namespace dc {
+
+
+class serializer_impl;
+
+class serializer
+{
+public:
+ serializer(const std::string& filePath, const std::string& indent = "");
+ serializer(std::ostream& output, const std::string& indent = "");
+
+ ~serializer();
+
+ void push(long value);
+ void push(double value);
+ void push(bool value);
+ void push(const std::string& value);
+ void push(const std::wstring& value);
+ void pushNull();
+
+ void pushMapHead();
+ void pushMapTail();
+
+ void pushArrayHead();
+ void pushArrayTail();
+
+ void flush();
+
+ struct generator_error : std::runtime_error
+ {
+ explicit generator_error(const std::string& what_arg) :
+ std::runtime_error(what_arg) {}
+ };
+
+private:
+ boost::shared_ptr<serializer_impl> impl;
+};
+
+} // namespace dc
+
+
+#endif // _SERIALIZER_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <sstream>
+#include <cstring>
+
+#include "settings.hh"
+
+
+namespace dc {
+
+
+settings::settings(int argc, char* argv[])
+{
+ parseArgs(argc, argv);
+}
+
+
+void settings::parseArgs(int argc, char* argv[])
+{
+ for (int i = 1; i < argc; i++)
+ {
+ char* where = strchr(argv[i], (int)'=');
+
+ if (where)
+ {
+ std::string key(argv[i], (size_t)(where - argv[i]));
+ std::string stringValue(where + 1);
+
+ std::stringstream stream;
+ stream << stringValue << std::endl;
+
+ deserializer in(stream);
+
+ try
+ {
+ serializable_ptr value(in.deserialize());
+ map[key] = value;
+ }
+ catch (std::exception e)
+ {
+ map[key] = serializable_ptr(new wrapped_string(stringValue));
+ }
+ }
+ }
+}
+
+void settings::loadFromFile(std::string filePath)
+{
+ deserializer in(filePath, true);
+
+ try
+ {
+ serializable_ptr obj = in.deserialize();
+ std::map<std::string,serializable_ptr> dict;
+ if (obj && obj->get(dict))
+ {
+ map.insert(dict.begin(), dict.end());
+ }
+ else
+ {
+ std::cerr << "The settings file " << filePath <<
+ " does not contain any valid settings." << std::endl;
+ }
+ }
+ catch (deserializer::parser_error e)
+ {
+ std::cerr << "Cannot load settings from " << filePath <<
+ " because an exception was thrown: " << e.what() << std::endl;
+ }
+}
+
+
+} // namepsace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _SETTINGS_HH_
+#define _SETTINGS_HH_
+
+/**
+ * @file settings.hh
+ * Load, store, save program settings.
+ */
+
+#include <string>
+#include <map>
+
+#include "singleton.hh"
+#include "serializable.hh"
+
+
+namespace dc {
+
+
+class settings : public singleton<settings>
+{
+public:
+ settings() {}
+ settings(int argc, char* argv[]);
+
+ void parseArgs(int argc, char* argv[]);
+ void loadFromFile(std::string filePath);
+
+ template <typename T>
+ bool get(const std::string& key, T& value);
+
+private:
+ std::map<std::string,serializable_ptr> map;
+};
+
+
+template <typename T>
+bool settings::get(const std::string& key, T& value)
+{
+ std::map<std::string,serializable_ptr>::const_iterator i = map.find(key);
+
+ if (i != map.end())
+ {
+ serializable_ptr obj = (*i).second;
+ return obj->get(value);
+ }
+ else
+ {
+ return false;
+ }
+}
+
+
+} // namepsace dc
+
+#endif // _SETTINGS_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _SINGLETON_HH_
+#define _SINGLETON_HH_
+
+#include <stdexcept>
+
+
+template <typename T>
+class singleton
+{
+ static T* ptr;
+
+public:
+ singleton()
+ {
+ if (!ptr)
+ {
+ // This hack is from Game Programming Gems.
+ long long offset = (long long)(T*)1 - (long long)(singleton<T>*)(T*)1;
+ ptr = (T*)((long long)this + offset);
+ }
+ }
+ ~singleton()
+ {
+ long long offset = (long long)(T*)1 - (long long)(singleton<T>*)(T*)1;
+ if (ptr == (T*)((long long)this + offset))
+ {
+ ptr = 0;
+ }
+ }
+
+ static T& instance()
+ {
+ if (!ptr)
+ {
+ throw std::runtime_error("accessing uninstantiated singleton");
+ }
+ return *ptr;
+ }
+
+ static T* instancePtr()
+ {
+ return ptr;
+ }
+};
+
+template <typename T> T* singleton<T>::ptr = 0;
+
+
+#endif // _SINGLETON_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <stdexcept>
+
+#include "ConvertUTF.h"
+
+#include "stringtools.hh"
+
+
+namespace dc {
+
+
+std::wstring multiToWide(const std::string& multiStr)
+{
+ size_t length = multiStr.length();
+
+ if (sizeof(wchar_t) == 2)
+ {
+ wchar_t* wideStr = new wchar_t[length + 1];
+
+ const UTF8* srcStart = reinterpret_cast<const UTF8*>(multiStr.c_str());
+ const UTF8* srcEnd = srcStart + length;
+ UTF16* targetStart = reinterpret_cast<UTF16*>(wideStr);
+ UTF16* targetEnd = targetStart + length+1;
+
+ ConversionResult res = ConvertUTF8toUTF16(&srcStart, srcEnd,
+ &targetStart, targetEnd, lenientConversion);
+ if (res != conversionOK)
+ {
+ delete[] wideStr;
+ throw std::runtime_error("bad conversion from multi to wide characters");
+ }
+
+ *targetStart = 0;
+ std::wstring convertedStr(wideStr);
+ delete[] wideStr;
+ return convertedStr;
+ }
+ else if (sizeof(wchar_t) == 4)
+ {
+ wchar_t* wideStr = new wchar_t[length];
+
+ const UTF8* srcStart = reinterpret_cast<const UTF8*>(multiStr.c_str());
+ const UTF8* srcEnd = srcStart + length;
+ UTF32* targetStart = reinterpret_cast<UTF32*>(wideStr);
+ UTF32* targetEnd = targetStart + length;
+
+ ConversionResult res = ConvertUTF8toUTF32(&srcStart, srcEnd,
+ &targetStart, targetEnd, lenientConversion);
+ if (res != conversionOK)
+ {
+ delete[] wideStr;
+ throw std::runtime_error("bad conversion from multi to wide characters");
+ }
+
+ *targetStart = 0;
+ std::wstring convertedStr(wideStr);
+ delete[] wideStr;
+ return convertedStr;
+ }
+ else
+ {
+ throw std::runtime_error("unknown size of wide characters");
+ }
+ return L"";
+}
+
+std::string wideToMulti(const std::wstring& wideStr)
+{
+ size_t length = wideStr.length();
+
+ if (sizeof(wchar_t) == 2)
+ {
+ size_t multiLength = 3 * length + 1;
+ char* multiStr = new char[multiLength];
+
+ const UTF16* srcStart = reinterpret_cast<const UTF16*>(wideStr.c_str());
+ const UTF16* srcEnd = srcStart + length;
+ UTF8* targetStart = reinterpret_cast<UTF8*>(multiStr);
+ UTF8* targetEnd = targetStart + multiLength;
+
+ ConversionResult res = ConvertUTF16toUTF8(&srcStart, srcEnd,
+ &targetStart, targetEnd, lenientConversion);
+ if (res != conversionOK)
+ {
+ delete[] multiStr;
+ throw std::runtime_error("bad conversion from wide to multi-characters");
+ }
+
+ *targetStart = 0;
+ std::string convertedStr(multiStr);
+ delete[] multiStr;
+ return convertedStr;
+ }
+ else if (sizeof(wchar_t) == 4)
+ {
+ size_t multiLength = 4 * length + 1;
+ char* multiStr = new char[multiLength];
+
+ const UTF32* srcStart = reinterpret_cast<const UTF32*>(wideStr.c_str());
+ const UTF32* srcEnd = srcStart + length;
+ UTF8* targetStart = reinterpret_cast<UTF8*>(multiStr);
+ UTF8* targetEnd = targetStart + multiLength;
+
+ ConversionResult res = ConvertUTF32toUTF8(&srcStart, srcEnd,
+ &targetStart, targetEnd, lenientConversion);
+ if (res != conversionOK)
+ {
+ delete[] multiStr;
+ throw std::runtime_error("bad conversion from wide to multi-characters");
+ }
+
+ *targetStart = 0;
+ std::string convertedStr(multiStr);
+ delete[] multiStr;
+ return convertedStr;
+ }
+ else
+ {
+ throw std::runtime_error("unknown size of wide characters");
+ }
+ return "";
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _STRINGTOOLS_HH_
+#define _STRINGTOOLS_HH_
+
+#include <string>
+
+
+namespace dc {
+
+std::wstring multiToWide(const std::string& multiStr);
+std::string wideToMulti(const std::wstring& wideStr);
+
+} // namespace dc
+
+
+#endif // _STRINGTOOLS_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <stdexcept>
+#include <cstdlib>
+
+#include <boost/bind.hpp>
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+
+#include "dispatcher.hh"
+#include "opengl.hh"
+
+#include "texture.hh"
+
+
+namespace dc {
+
+
+class texture_impl
+{
+ void unloadFromGL()
+ {
+ if (object)
+ {
+ glDeleteTextures(1, &object);
+ object = 0;
+ }
+ }
+
+ void contextRecreated(const notification& note)
+ {
+ unloadFromGL();
+ uploadToGL();
+ }
+
+public:
+ texture_impl(const std::string& filePath, bool keepInMemory)
+ : object(0), imageData(0), imagePath(filePath), keepData(keepInMemory)
+ {
+ dispatcher::instance().addHandler("video.context_recreated",
+ boost::bind(&texture_impl::contextRecreated, this, _1),
+ this);
+ }
+
+ ~texture_impl()
+ {
+ dispatcher::instance().removeHandler(this);
+
+ if (imageData)
+ {
+ SDL_FreeSurface(imageData);
+ }
+ unloadFromGL();
+ }
+
+
+ static int powerOfTwo(int input)
+ {
+ int value = 1;
+
+ while (value < input)
+ {
+ value <<= 1;
+ }
+ return value;
+ }
+
+ // Adapted from some public domain code. This code is common enough that it
+ // really should be included in SDL_image...
+ static SDL_Surface* prepareImageForGL(SDL_Surface* surface)
+ {
+ /* Use the surface width and height expanded to powers of 2 */
+ int w = powerOfTwo(surface->w);
+ int h = powerOfTwo(surface->h);
+
+ SDL_Surface* image = SDL_CreateRGBSurface
+ (
+ SDL_SWSURFACE,
+ w, h,
+ 32,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000
+#else
+ 0xFF000000,
+ 0x00FF0000,
+ 0x0000FF00,
+ 0x000000FF
+#endif
+ );
+
+ if (!image)
+ {
+ return 0;
+ }
+
+ // Save the alpha blending attributes.
+ Uint32 savedFlags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+ Uint8 savedAlpha = surface->format->alpha;
+ if (savedFlags & SDL_SRCALPHA)
+ {
+ SDL_SetAlpha(surface, 0, 0);
+ }
+
+ SDL_Rect srcArea, destArea;
+ /* Copy the surface into the GL texture image */
+ srcArea.x = 0; destArea.x = 0;
+ /* Copy it in at the bottom, because we're going to flip
+ this image upside-down in a moment
+ */
+ srcArea.y = 0; destArea.y = h - surface->h;
+ srcArea.w = surface->w;
+ srcArea.h = surface->h;
+ SDL_BlitSurface(surface, &srcArea, image, &destArea);
+
+ /* Restore the alpha blending attributes */
+ if (savedFlags & SDL_SRCALPHA)
+ {
+ SDL_SetAlpha(surface, savedFlags, savedAlpha);
+ }
+
+ /* Turn the image upside-down, because OpenGL textures
+ start at the bottom-left, instead of the top-left
+ */
+ Uint8 line[image->pitch];
+
+ /* These two make the following more readable */
+ Uint8 *pixels = static_cast<Uint8*>(image->pixels);
+ Uint16 pitch = image->pitch;
+ int ybegin = 0;
+ int yend = image->h - 1;
+
+ // TODO: consider if this lock is legal/appropriate
+ if (SDL_MUSTLOCK(image)) { SDL_LockSurface(image); }
+ while (ybegin < yend)
+ {
+ memcpy(line, pixels + pitch*ybegin, pitch);
+ memcpy(pixels + pitch*ybegin, pixels + pitch*yend, pitch);
+ memcpy(pixels + pitch*yend, line, pitch);
+ ybegin++;
+ yend--;
+ }
+ if (SDL_MUSTLOCK(image)) { SDL_UnlockSurface(image); }
+
+ return image;
+ }
+
+
+ void loadImageData()
+ {
+ SDL_Surface* surface;
+
+ surface = IMG_Load(imagePath.c_str());
+
+ if (!surface)
+ {
+ throw std::runtime_error("could not load image data from file");
+ }
+
+ imageData = prepareImageForGL(surface);
+ SDL_FreeSurface(surface);
+
+ if (!imageData)
+ {
+ throw std::runtime_error("error in preparing image data for GL");
+ }
+
+ if (imageData->format->BytesPerPixel == 3)
+ {
+ mode = GL_RGB;
+ }
+ else if (imageData->format->BytesPerPixel == 4)
+ {
+ mode = GL_RGBA;
+ }
+ else
+ {
+ SDL_FreeSurface(imageData);
+ throw std::runtime_error("image must be 24 or 32 bpp");
+ }
+
+ width = imageData->w;
+ height = imageData->h;
+ }
+
+
+ void uploadToGL()
+ {
+ if (object)
+ {
+ // Already loaded.
+ return;
+ }
+
+ if (!imageData)
+ {
+ loadImageData();
+ }
+
+ glGenTextures(1, &object);
+
+ glBindTexture(GL_TEXTURE_2D, object);
+
+ glTexImage2D
+ (
+ GL_TEXTURE_2D,
+ 0,
+ mode,
+ imageData->w,
+ imageData->h,
+ 0,
+ mode,
+ GL_UNSIGNED_BYTE,
+ imageData->pixels
+ );
+
+ // These default filters can be changed later...
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ if (!keepData)
+ {
+ SDL_FreeSurface(imageData);
+ imageData = 0;
+ }
+ }
+
+
+ unsigned width;
+ unsigned height;
+ int mode;
+ GLuint object;
+
+ std::string imagePath;
+ bool keepData;
+ SDL_Surface* imageData;
+};
+
+
+texture::texture(const std::string& filePath, bool keepInMemory)
+ : impl(new texture_impl(filePath, keepInMemory)) {}
+
+
+const std::string& texture::filePath()
+{
+ return impl->imagePath;
+}
+
+
+void texture::bind()
+{
+ glBindTexture(GL_TEXTURE_2D, object());
+}
+
+GLuint texture::object()
+{
+ if (!impl->object)
+ {
+ impl->uploadToGL();
+ }
+
+ return impl->object;
+}
+
+
+unsigned texture::width()
+{
+ return impl->width;
+}
+
+unsigned texture::height()
+{
+ return impl->height;
+}
+
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _TEXTURE_HH_
+#define _TEXTURE_HH_
+
+#include <boost/shared_ptr.hpp>
+
+#include "opengl.hh"
+
+
+namespace dc {
+
+
+class texture_impl;
+
+class texture
+{
+public:
+ texture(const std::string& filePath, bool keepInMemory = false);
+
+ const std::string& filePath();
+
+ void bind();
+ GLuint object();
+
+ unsigned width();
+ unsigned height();
+
+private:
+ boost::shared_ptr<texture_impl> impl;
+};
+
+
+} // namespace dc
+
+#endif // _TEXTURE_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _THREAD_HH_
+#define _THREAD_HH_
+
+/**
+ * @file thread.hh
+ * Light C++ wrapper around SDL threads.
+ */
+
+#include <boost/function.hpp>
+#include <SDL/SDL.h>
+
+
+namespace dc {
+namespace thread {
+
+//
+// The detach function detaches a separate thread by calling 'func' with
+// the 'arg' parameter.
+//
+
+typedef SDL_Thread* thread;
+
+typedef boost::function<int(void)> function;
+
+
+int detach_(void* arg)
+{
+ function func = *(function*)arg;
+ int ret = func();
+
+ delete (function*)arg;
+ return ret;
+}
+
+thread detach(const function& func)
+{
+ thread t;
+ function* fcopy = new function(func);
+
+ t = SDL_CreateThread(detach_, (void*)fcopy);
+ if (t == 0) delete fcopy;
+ return t;
+}
+
+
+int wait(thread t)
+{
+ int i;
+ SDL_WaitThread(t, &i);
+ return i;
+}
+
+void kill(thread t)
+{
+ SDL_KillThread(t);
+}
+
+
+//
+// The identifier function returns a unique integer for the calling thread.
+//
+
+unsigned int identifier()
+{
+ return SDL_ThreadID();
+}
+
+unsigned int identifier(thread t)
+{
+ return SDL_GetThreadID(t);
+}
+
+
+// =============================================================================
+
+class mutex
+{
+ friend class condition;
+
+public:
+ mutex() { mutex_ = SDL_CreateMutex(); }
+ ~mutex() { SDL_DestroyMutex(mutex_); }
+
+ bool acquireLock() { return (SDL_LockMutex(mutex_) == 0); }
+ bool releaseLock() { return (SDL_UnlockMutex(mutex_) == 0); }
+
+ class lock
+ {
+ friend class condition;
+
+ public:
+ lock(mutex& m) { mutex_ = &m; isLocked_ = false; }
+ ~lock() { if (isLocked_) release(); }
+
+ bool acquire() { return (isLocked_ = mutex_->acquireLock()); }
+ bool release() { return mutex_->releaseLock(); isLocked_ = false; }
+ bool isLocked() const { return isLocked_; }
+
+ protected:
+ mutex* mutex_;
+ bool isLocked_;
+ };
+
+ class scoped_lock : public lock
+ {
+ public:
+ scoped_lock(mutex& m) : lock(m) { acquire(); }
+ };
+
+private:
+ SDL_mutex* mutex_;
+};
+
+// =============================================================================
+
+class condition
+{
+public:
+ condition() { condition_ = SDL_CreateCond(); }
+ ~condition() { SDL_DestroyCond(condition_); }
+
+ bool wait(mutex::lock& l)
+ {
+ return (SDL_CondWait(condition_, l.mutex_->mutex_) == 0);
+ }
+ bool wait(mutex::lock& l, unsigned ms)
+ {
+ // TODO: For consistency, this function should take seconds, not ms.
+ return (SDL_CondWaitTimeout(condition_, l.mutex_->mutex_, ms) == 0);
+ }
+
+ bool notify() { return (SDL_CondSignal(condition_) == 0); }
+ bool notifyAll() { return (SDL_CondBroadcast(condition_) == 0); }
+
+private:
+ SDL_cond* condition_;
+};
+
+// =============================================================================
+
+class semaphore
+{
+public:
+ semaphore(unsigned int value) { semaphore_ = SDL_CreateSemaphore(value); }
+ ~semaphore() { SDL_DestroySemaphore(semaphore_); }
+
+ bool acquireLock() { return (SDL_SemWait(semaphore_) == 0); }
+ bool tryLock() { return (SDL_SemTryWait(semaphore_) == 0); }
+ bool tryLock(unsigned ms)
+ {
+ // TODO: For consistency, this function should take seconds, not ms.
+ return (SDL_SemWaitTimeout(semaphore_, ms) == 0);
+ }
+ bool releaseLock() { return (SDL_SemPost(semaphore_) == 0); }
+
+ class lock
+ {
+ public:
+ lock(semaphore& m) { semaphore_ = &m; isLocked_ = false; }
+ ~lock() { if (isLocked_) release(); }
+
+ bool acquire() { return (isLocked_ = semaphore_->acquireLock()); }
+ bool release() { return semaphore_->releaseLock(); isLocked_ = false; }
+ bool isLocked() const { return isLocked_; }
+
+ protected:
+ semaphore* semaphore_;
+ bool isLocked_;
+ };
+
+ class scoped_lock : public lock
+ {
+ public:
+ scoped_lock(semaphore& m) : lock(m) { acquire(); }
+ };
+
+private:
+ SDL_sem* semaphore_;
+};
+
+
+} // namespace thread
+} // namespace dc
+
+
+#endif // _THREAD_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <stdexcept>
+#include <ctime>
+#include <cerrno>
+
+#include <SDL/SDL.h>
+
+#include "timer.hh"
+
+
+namespace dc {
+
+
+#if HAVE_LIBRT
+
+scalar ticks()
+{
+ struct timespec ts;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+ {
+ throw std::runtime_error("cannot access monotonic clock");
+ }
+
+ return scalar(ts.tv_sec) + scalar(ts.tv_nsec) / 1000000000.0;
+}
+
+void sleep(scalar seconds, bool absolute)
+{
+ struct timespec ts;
+ int ret;
+
+ if (!absolute) seconds += ticks();
+ ts.tv_sec = time_t(seconds);
+ ts.tv_nsec = time_t((seconds - scalar(ts.tv_sec)) * 1000000000.0);
+
+ do
+ {
+ ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, 0);
+ }
+ while (ret == -1 && errno == EINTR);
+}
+
+#else // ! HAVE_LIBRT
+
+// If we don't have librt, we'll have to use different timing methods.
+
+scalar ticks()
+{
+ unsigned ms = SDL_GetTicks();
+ return scalar(ms / 1000) + scalar(ms % 1000) / 1000.0;
+}
+
+void sleep(scalar seconds, bool absolute)
+{
+ struct timespec ts;
+ int ret;
+
+ if (absolute) seconds -= ticks();
+ ts.tv_sec = time_t(seconds);
+ ts.tv_nsec = time_t((seconds - scalar(ts.tv_sec)) * 1000000000.0);
+
+ do
+ {
+ ret = nanosleep(&ts, &ts);
+ }
+ while (ret == -1 && errno == EINTR);
+}
+
+#endif // HAVE_LIBRT
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _TIMER_HH_
+#define _TIMER_HH_
+
+/**
+ * @file timer.hh
+ * Functions for measuring time in a friendly unit.
+ */
+
+#include "math.hh"
+
+
+namespace dc {
+
+
+/**
+ * Get the number of seconds since a fixed, arbitrary point in the past.
+ * @return Seconds.
+ */
+
+scalar ticks();
+
+
+/**
+ * Put the thread to sleep for a certain period of time. If absolute is true,
+ * then it will sleep until seconds after the fixed time in the past. If
+ * absolute is false, it will sleep for seconds starting now. Unlike system
+ * sleep functions, this one automatically resumes sleep if sleep was
+ * interrupted by a signal. Therefore, calling this function is guaranteed to
+ * sleep for the requested amount of time.
+ */
+
+void sleep(scalar seconds, bool absolute = false);
+
+
+} // namespace dc
+
+
+#endif // _TIMER_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _VECTOR_HH_
+#define _VECTOR_HH_
+
+/**
+ * @file vector.hh
+ * Vector classes.
+ */
+
+#include <iostream>
+#include <cassert>
+
+#include "math.hh"
+#include "random.hh"
+
+
+// TODO: project, reflect, random, normal (of plane), orthonormal
+
+namespace dc {
+
+/**
+ * 2-dimensional vector.
+ */
+
+struct vector2
+{
+ vector2() {}
+ vector2(scalar X, scalar Y) : x(X), y(Y) {}
+ vector2(scalar v[2]) : x(v[0]), y(v[1]) {}
+
+ const scalar& operator[](int i) const
+ {
+ assert(i >= 0 && i <= 1 && "Index into vector2 out of bounds.");
+ return array[i];
+ }
+ scalar& operator[](int i)
+ {
+ assert(i >= 0 && i <= 1 && "Index into vector2 out of bounds.");
+ return array[i];
+ }
+
+ vector2 operator+(const vector2& v) const
+ {
+ return vector2(x + v.x, y + v.y);
+ }
+ vector2 operator-(const vector2& v) const
+ {
+ return vector2(x - v.x, y - v.y);
+ }
+ vector2 operator*(scalar s) const
+ {
+ return vector2(x * s, y * s);
+ }
+ vector2 operator/(scalar s) const
+ {
+ return vector2(x / s, y / s);
+ }
+
+ vector2& operator+=(const vector2& v)
+ {
+ x += v.x; y += v.y;
+ return *this;
+ }
+ vector2& operator-=(const vector2& v)
+ {
+ x -= v.x; y -= v.y;
+ return *this;
+ }
+ vector2& operator*=(scalar s)
+ {
+ x *= s; y *= s;
+ return *this;
+ }
+ vector2& operator/=(scalar s)
+ {
+ x /= s; y /= s;
+ return *this;
+ }
+
+ vector2 operator-() const
+ {
+ return vector2(-x, -y);
+ }
+
+ scalar dot(const vector2& v) const /// dot product
+ {
+ return x * v.x + y * v.y;
+ }
+ scalar angleBetween(const vector2& v) const
+ {
+ scalar lens = length() * v.length();
+ if (lens == 0.0) { return HUGE_VAL; }
+ return std::acos(dot(v) / lens);
+ }
+
+ void normalize() /// scale such that length is one
+ {
+ scalar len = length();
+ if (len != 0.0) { *this /= len; }
+ }
+ vector2 normalized() const
+ {
+ scalar len = length();
+ if (len != 0.0) { return *this / len; }
+ return vector2(0.0, 0.0);
+ }
+
+ scalar length2() const /// magnitude squared
+ {
+ return dot(*this);
+ }
+ scalar length() const /// magnitude
+ {
+ return std::sqrt(length2());
+ }
+
+ bool operator==(const vector2& v) const
+ {
+ return equals(x, v.x) && equals(y, v.y);
+ }
+ bool operator!=(const vector2& v) const
+ {
+ return !(*this == v);
+ }
+
+
+ static vector2 random()
+ {
+ vector2 v = random(-1.0, 1.0);
+ v.normalize();
+ return v;
+ }
+
+ static vector2 random(scalar lower, scalar upper)
+ {
+ return vector2(rng::get<scalar>(lower, upper),
+ rng::get<scalar>(lower, upper));
+ }
+
+
+ union
+ {
+ struct
+ {
+ scalar x, y; ///< euler coordinates
+ };
+ scalar array[2]; ///< array
+ };
+
+ static vector2 zero; ///< zero vector
+};
+
+inline vector2 operator*(scalar s, const vector2& v)
+{
+ return v * s;
+}
+inline vector2 operator/(scalar s, const vector2& v)
+{
+ return vector2(s / v.x, s / v.y);
+}
+
+inline std::ostream& operator<<(std::ostream& output, const vector2& v)
+{
+ output << "(" << v.x << "," << v.y << ")";
+ return output;
+}
+
+
+typedef vector2 point;
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+/**
+ * 3-dimensional vector.
+ */
+
+struct vector3
+{
+ vector3() {}
+ vector3(scalar X, scalar Y, scalar Z) : x(X), y(Y), z(Z) {}
+ vector3(scalar v[3]) : x(v[0]), y(v[1]), z(v[2]) {}
+
+ const scalar& operator[](int i) const
+ {
+ assert(i >= 0 && i <= 2 && "Index into vector3 out of bounds.");
+ return array[i];
+ }
+ scalar& operator[](int i)
+ {
+ assert(i >= 0 && i <= 2 && "Index into vector3 out of bounds.");
+ return array[i];
+ }
+
+ vector3 operator+(const vector3& v) const
+ {
+ return vector3(x + v.x, y + v.y, z + v.z);
+ }
+ vector3 operator-(const vector3& v) const
+ {
+ return vector3(x - v.x, y - v.y, z - v.z);
+ }
+ vector3 operator*(scalar s) const
+ {
+ return vector3(x * s, y * s, z * s);
+ }
+ vector3 operator/(scalar s) const
+ {
+ return vector3(x / s, y / s, z / s);
+ }
+
+ vector3& operator+=(const vector3& v)
+ {
+ x += v.x; y += v.y; z += v.z;
+ return *this;
+ }
+ vector3& operator-=(const vector3& v)
+ {
+ x -= v.x; y -= v.y; z -= v.z;
+ return *this;
+ }
+ vector3& operator*=(scalar s)
+ {
+ x *= s; y *= s; z *= s;
+ return *this;
+ }
+ vector3& operator/=(scalar s)
+ {
+ x /= s; y /= s; z /= s;
+ return *this;
+ }
+
+ vector3 operator-() const
+ {
+ return vector3(-x, -y, -z);
+ }
+
+ scalar dot(const vector3& v) const /// dot product
+ {
+ return x * v.x + y * v.y + z * v.z;
+ }
+ vector3 cross(const vector3& v) const /// cross product
+ {
+ return vector3(y * v.z - z * v.y,
+ z * v.x - x * v.z,
+ x * v.y - y * v.x);
+ }
+
+ scalar angleBetween(const vector3& v) const
+ {
+ scalar lens = length() * v.length();
+ if (lens == 0.0) { return HUGE_VAL; }
+ return std::acos(dot(v) / lens);
+ }
+
+ void normalize() /// scale such that length is one
+ {
+ scalar len = length();
+ if (len != 0.0) { *this /= len; }
+ }
+ vector3 normalized() const
+ {
+ scalar len = length();
+ if (len != 0.0) { return *this / len; }
+ return vector3(0.0, 0.0, 0.0);
+ }
+
+ scalar length2() const /// magnitude squared
+ {
+ return dot(*this);
+ }
+ scalar length() const /// magnitude
+ {
+ return std::sqrt(length2());
+ }
+
+ bool operator==(const vector3& v) const
+ {
+ return equals(x, v.x) && equals(y, v.y) && equals(z, v.z);
+ }
+ bool operator!=(const vector3& v) const
+ {
+ return !(*this == v);
+ }
+
+
+ static vector3 random()
+ {
+ vector3 v = random(-1.0, 1.0);
+ v.normalize();
+ return v;
+ }
+
+ static vector3 random(scalar lower, scalar upper)
+ {
+ return vector3(rng::get<scalar>(lower, upper),
+ rng::get<scalar>(lower, upper),
+ rng::get<scalar>(lower, upper));
+ }
+
+
+ union
+ {
+ struct
+ {
+ scalar x, y, z; ///< euler coordinates
+ };
+ struct
+ {
+ scalar u, v, w; ///< texture coordinates
+ };
+ struct
+ {
+ scalar r, g, b; ///< color intensities
+ };
+ scalar array[3]; ///< array
+ };
+
+ static vector3 zero; ///< zero vector
+};
+
+inline vector3 operator*(scalar s, const vector3& v)
+{
+ return v * s;
+}
+inline vector3 operator/(scalar s, const vector3& v)
+{
+ return vector3(s / v.x, s / v.y, s / v.z);
+}
+
+inline std::ostream& operator<<(std::ostream& output, const vector3& v)
+{
+ output << "(" << v.x << "," << v.y << "," << v.z << ")";
+ return output;
+}
+
+
+typedef vector3 color;
+
+
+} // namespace dc
+
+
+#endif // _VECTOR_HH_
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#include <stdexcept>
+
+#include "serializable.hh"
+#include "settings.hh"
+
+#include "video.hh"
+
+
+namespace dc {
+
+
+video::video()
+{
+ std::string caption;
+ if (settings::instance().get("video.caption", caption))
+ {
+ init(attribs_, caption);
+ }
+ else
+ {
+ init(attribs_, "Untitled");
+ }
+}
+
+video::video(const attributes& attribs, const std::string& caption)
+{
+ init(attribs, caption);
+}
+
+video::video(const attributes& attribs)
+{
+ std::string caption;
+ if (settings::instance().get("video.caption", caption))
+ {
+ init(attribs, caption);
+ }
+ else
+ {
+ init(attribs, "Untitled");
+ }
+}
+
+video::video(const std::string& caption)
+{
+ init(attribs_, caption);
+}
+
+void video::init(const attributes& attribs, const std::string& caption)
+{
+ context_ = 0;
+ flags_ = 0;
+ attribs_ = attribs;
+
+ setFull(attribs.fullscreen);
+ setResizable(attribs.resizable);
+ setOpenGLAttributes();
+ setCaption(caption);
+ setCursorVisible(attribs.cursorVisible);
+ setCursorGrab(attribs.cursorGrab);
+ setVideoMode(attribs.mode);
+}
+
+void video::recreateContext()
+{
+ SDL_FreeSurface(context_);
+ context_ = 0;
+ setVideoMode(attribs_.mode);
+}
+
+void video::setOpenGLAttributes()
+{
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, attribs_.colorBuffer[0]);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, attribs_.colorBuffer[1]);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, attribs_.colorBuffer[2]);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, attribs_.colorBuffer[3]);
+ SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, attribs_.frameBuffer);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, attribs_.doubleBuffer);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, attribs_.depthBuffer);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, attribs_.stencilBuffer);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, attribs_.accumBuffer[0]);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, attribs_.accumBuffer[1]);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, attribs_.accumBuffer[2]);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, attribs_.accumBuffer[3]);
+ SDL_GL_SetAttribute(SDL_GL_STEREO, attribs_.stereo);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, attribs_.multisampleBuffers);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, attribs_.multisampleSamples);
+ SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, attribs_.swapControl);
+ SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, attribs_.hardwareonly);
+}
+
+
+video::~video()
+{
+ SDL_FreeSurface(context_);
+}
+
+
+void video::setVideoMode(const long mode[3])
+{
+ if (mode != attribs_.mode || !context_)
+ {
+ if (context_) SDL_FreeSurface(context_);
+
+ context_ = SDL_SetVideoMode(mode[0], mode[1], mode[2],
+ SDL_OPENGL | flags_);
+
+ if (context_)
+ {
+ attribs_.mode[0] = mode[0];
+ attribs_.mode[1] = mode[1];
+ attribs_.mode[2] = mode[2];
+ }
+ else throw std::runtime_error(SDL_GetError());
+ }
+}
+
+video::attributes video::getAttributes() const
+{
+ return attribs_;
+}
+
+
+void video::resize(int width, int height)
+{
+ long mode[] = {width, height, attribs_.mode[2]};
+ setVideoMode(mode);
+}
+
+bool video::iconify()
+{
+ return SDL_WM_IconifyWindow();
+}
+
+
+void video::setCaption(const std::string& caption)
+{
+ SDL_WM_SetCaption(caption.c_str(), 0);
+}
+
+std::string video::getCaption() const
+{
+ char* str;
+ SDL_WM_GetCaption(&str, 0);
+ return std::string(str);
+}
+
+
+void video::setFull(bool full)
+{
+ if (full != isFull() || !context_)
+ {
+ if (context_)
+ {
+ flags_ ^= SDL_FULLSCREEN;
+
+#if defined(linux) || defined(__linux) || defined(__linux__)
+ if (SDL_WM_ToggleFullScreen(context_) == 0)
+#endif
+ recreateContext();
+ }
+ else
+ {
+ if (full) flags_ |= SDL_FULLSCREEN;
+ else flags_ &= ~SDL_FULLSCREEN;
+ }
+ }
+}
+
+void video::toggleFull()
+{
+ setFull(!isFull());
+}
+
+bool video::isFull() const
+{
+ return flags_ & SDL_FULLSCREEN;
+}
+
+
+void video::setCursorVisible(bool hasCursor)
+{
+ SDL_ShowCursor(hasCursor? SDL_ENABLE : SDL_DISABLE);
+}
+
+void video::toggleCursorVisible()
+{
+ setCursorVisible(!isCursorVisible());
+}
+
+bool video::isCursorVisible() const
+{
+ return (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE);
+}
+
+
+void video::setResizable(bool resizable)
+{
+ if (resizable != isResizable() || !context_)
+ {
+ if (context_)
+ {
+ flags_ ^= SDL_RESIZABLE;
+ recreateContext();
+ }
+ else
+ {
+ if (resizable) flags_ |= SDL_RESIZABLE;
+ else flags_ &= ~SDL_RESIZABLE;
+ }
+ }
+}
+
+void video::toggleResizable()
+{
+ setResizable(!isResizable());
+}
+
+bool video::isResizable() const
+{
+ return flags_ & SDL_RESIZABLE;
+}
+
+
+bool video::isCursorGrab() const
+{
+ return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);
+}
+
+void video::toggleCursorGrab()
+{
+ setCursorGrab(!isCursorGrab());
+}
+
+void video::setCursorGrab(bool cursorGrab)
+{
+ SDL_WM_GrabInput(cursorGrab? SDL_GRAB_ON : SDL_GRAB_OFF);
+}
+
+
+void video::makeActive()
+{
+ // NOP until the day SDL supports more than only one window.
+ // Still waiting...
+}
+
+void video::swap()
+{
+ SDL_GL_SwapBuffers();
+}
+
+
+video::attributes::attributes()
+{
+ // Set some sane GL and window defaults (see SDL_video.c:217)
+ colorBuffer[0] = 3;
+ colorBuffer[1] = 3;
+ colorBuffer[2] = 2;
+ colorBuffer[3] = 0;
+ frameBuffer = 0;
+ doubleBuffer = true;
+ depthBuffer = 16;
+ stencilBuffer = 0;
+ accumBuffer[0] = 0;
+ accumBuffer[1] = 0;
+ accumBuffer[2] = 0;
+ accumBuffer[3] = 0;
+ stereo = false;
+ multisampleBuffers = 0;
+ multisampleSamples = 0;
+ swapControl = false;
+ hardwareonly = false;
+ mode[0] = 640;
+ mode[1] = 480;
+ mode[2] = 0;
+ fullscreen = false;
+ resizable = false;
+ cursorVisible = true;
+ cursorGrab = false;
+
+ std::vector<serializable_ptr> colors;
+ settings::instance().get("video.colorbuffers", colors);
+ if (colors.size() > 0) colors[0]->get(colorBuffer[0]);
+ if (colors.size() > 1) colors[1]->get(colorBuffer[1]);
+ if (colors.size() > 2) colors[2]->get(colorBuffer[2]);
+ if (colors.size() > 3) colors[3]->get(colorBuffer[3]);
+
+ settings::instance().get("video.framebuffer", frameBuffer);
+ settings::instance().get("video.doublebuffer", doubleBuffer);
+ settings::instance().get("video.depthbuffer", depthBuffer);
+ settings::instance().get("video.stencilbuffer", stencilBuffer);
+
+ std::vector<serializable_ptr> accum;
+ settings::instance().get("video.accumbuffers", accum);
+ if (accum.size() > 0) accum[0]->get(accumBuffer[0]);
+ if (accum.size() > 1) accum[1]->get(accumBuffer[1]);
+ if (accum.size() > 2) accum[2]->get(accumBuffer[2]);
+ if (accum.size() > 3) accum[3]->get(accumBuffer[3]);
+
+ settings::instance().get("video.stereo", stereo);
+ settings::instance().get("video.multiesamplebuffers", multisampleBuffers);
+ settings::instance().get("video.multiesamplesamples", multisampleSamples);
+ settings::instance().get("video.swapcontrol", swapControl);
+ settings::instance().get("video.hardwareonly", hardwareonly);
+
+ std::vector<serializable_ptr> dimensions;
+ settings::instance().get("video.mode", dimensions);
+ if (dimensions.size() > 0) dimensions[0]->get(mode[0]);
+ if (dimensions.size() > 1) dimensions[1]->get(mode[1]);
+ if (dimensions.size() > 2) dimensions[2]->get(mode[2]);
+
+ settings::instance().get("video.fullscreen", fullscreen);
+ settings::instance().get("video.resizable", resizable);
+ settings::instance().get("video.cursor", cursorVisible);
+ settings::instance().get("video.grab", cursorGrab);
+}
+
+
+} // namespace dc
+
--- /dev/null
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _VIDEO_HH_
+#define _VIDEO_HH_
+
+#include <string>
+
+#include <boost/shared_ptr.hpp>
+
+#include <SDL/SDL.h>
+
+
+namespace dc {
+
+
+class video
+{
+public:
+ struct attributes
+ {
+ // OpenGL attributes
+ long colorBuffer[4]; // rgba
+ long frameBuffer;
+ bool doubleBuffer;
+ long depthBuffer;
+ long stencilBuffer;
+ long accumBuffer[4]; // rgba
+ bool stereo;
+ long multisampleBuffers;
+ long multisampleSamples;
+ bool swapControl;
+ bool hardwareonly;
+
+ // Window attributes
+ long mode[3]; // width, height, bpp
+ bool fullscreen;
+ bool resizable;
+ bool cursorVisible;
+ bool cursorGrab;
+
+ attributes();
+ };
+
+ video();
+ video(const attributes& attribs);
+ video(const attributes& attribs, const std::string& caption);
+ video(const std::string& caption);
+ ~video();
+
+ void setVideoMode(const long mode[3]);
+ attributes getAttributes() const;
+
+ void resize(int width, int height);
+ bool iconify();
+
+ void setCaption(const std::string& caption);
+ std::string getCaption() const;
+
+ void setFull(bool full);
+ void toggleFull();
+ bool isFull() const;
+
+ void setCursorVisible(bool hasCursor);
+ void toggleCursorVisible();
+ bool isCursorVisible() const;
+
+ void setResizable(bool resizable);
+ void toggleResizable();
+ bool isResizable() const;
+
+ void setCursorGrab(bool cursorGrab);
+ void toggleCursorGrab();
+ bool isCursorGrab() const;
+
+ void makeActive();
+ void swap();
+
+private:
+ void init(const attributes& attribs, const std::string& caption);
+ void recreateContext();
+ void setOpenGLAttributes();
+
+ SDL_Surface* context_;
+ unsigned flags_;
+ attributes attribs_;
+};
+
+typedef boost::shared_ptr<video> video_ptr;
+
+
+} // namespace dc
+
+#endif // _VIDEO_HH_
+
+++ /dev/null
-
-#include <iostream>
-
-using namespace std;
-
-
-int main(int argc, char* argv[])
-{
- cout << "Hello, world!" << endl;
- return 0;
-}
-
--- /dev/null
+/* C-style comments are allowed. */
+{
+ "video.fullscreen": false,
+ "video.resizable": true,
+ "video.mode": [800, 600],
+ "video.colorbuffers": [8, 8, 8, 8],
+ //"video.multisamplebuffers": 6,
+ //"video.multisamplesamples": 6,
+ "video.cursor": true,
+ "video.grab": false,
+ "video.doublebuffer": true,
+ "video.swapcontrol": true,
+ "engine.maxfps": 40
+}
--- /dev/null
+Short story (If you already have ruby and cmake):
+
+./configure && make install
+
+When things go wrong:
+
+attain CMake (http://www.cmake.org) and ruby (http://ruby-lang.org) and
+try again.
+
+OR, attain CMake and build by hand:
+
+1. mkdir build
+2. cd build
+3. cmake ..
+4. make
+5. build output left in yajl-X.Y.Z
+
+best,
+lloyd
--- /dev/null
+YAJL has been successfully built using Visual Studio 8. CMake is used to
+build the software and by specifying a generator explicitly at cmake:
+
+1. acquire cmake (http://www.cmake.org)
+2. mkdir build
+3. cd build
+4. cmake ..
+5. devenv YetAnotherJSONParser.sln
+6. build the ALL_BUILD target
+7. build output is left in build/yajl-X.Y.Z
+
+Earlier versions of visual studio have not been tested, but should
+work without any major issues.
--- /dev/null
+# Copyright 2007-2009, Lloyd Hilaiel.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Neither the name of Lloyd Hilaiel nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+PROJECT(YetAnotherJSONParser)
+
+SET (YAJL_MAJOR 1)
+SET (YAJL_MINOR 0)
+SET (YAJL_MICRO 5)
+
+SET (YAJL_DIST_NAME "yajl-${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO}")
+
+IF (NOT CMAKE_BUILD_TYPE)
+ SET(CMAKE_BUILD_TYPE "Release")
+ENDIF (NOT CMAKE_BUILD_TYPE)
+
+SET(CMAKE_C_FLAGS "-Wall")
+IF (WIN32)
+ SET(linkFlags "/PDB:NONE /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
+ SET(CMAKE_EXE_LINKER_FLAGS "${linkFlags}"
+ CACHE STRING "YAJL linker flags" FORCE)
+ SET(CMAKE_EXE_LINKER_FLAGS_DEBUG ""
+ CACHE STRING "YAJL debug linker flags" FORCE)
+ SET(CMAKE_EXE_LINKER_FLAGS_RELEASE
+ CACHE STRING "YAJL release linker flags" FORCE)
+ SET(CMAKE_SHARED_LINKER_FLAGS "${linkFlags}"
+ CACHE STRING "YAJL shared linker flags" FORCE)
+ SET(CMAKE_MODULE_LINKER_FLAGS "${linkFlags}"
+ CACHE STRING "YAJL module linker flags" FORCE)
+
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /wd4255 /wd4130 /wd4100 /wd4711")
+ SET(CMAKE_C_FLAGS_DEBUG "/D DEBUG /Od /Z7")
+ SET(CMAKE_C_FLAGS_RELEASE "/D NDEBUG /O2")
+ELSE (WIN32)
+ SET(CMAKE_C_FLAGS
+ "${CMAKE_C_FLAGS} -fPIC -ansi -pedantic -Wpointer-arith -Wno-format-y2k -Wstrict-prototypes -Wmissing-declarations -Wnested-externs -Wextra -Wundef -Wwrite-strings -Wold-style-definition -Wno-missing-field-initializers -Wredundant-decls -Wno-unused-parameter -Wno-sign-compare -Wmissing-prototypes")
+
+ SET(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
+ SET(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2 -Wuninitialized")
+ENDIF (WIN32)
+
+
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(reformatter)
+ADD_SUBDIRECTORY(verify)
+
+INCLUDE(YAJLDoc.cmake)
+
+# a test target
+ADD_CUSTOM_TARGET(test
+ ./run_tests.sh
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
+
--- /dev/null
+
+# To make yajl works as a convenience library, the directory src/api must be
+# renamed to src/yajl, and any sources or headers which refer to headers in in
+# that directory will need to be modified to look in the new directory.
+
+noinst_LIBRARIES = libyajl.a
+
+libyajl_a_SOURCES = \
+ src/yajl.c \
+ src/yajl_alloc.c \
+ src/yajl_alloc.h \
+ src/yajl_buf.c \
+ src/yajl_buf.h \
+ src/yajl_bytestack.h \
+ src/yajl_encode.c \
+ src/yajl_encode.h \
+ src/yajl_gen.c \
+ src/yajl_lex.c \
+ src/yajl_lex.h \
+ src/yajl_parser.c \
+ src/yajl_parser.h \
+ $(ENDLIST)
+
+noinst_HEADERS = \
+ src/yajl/yajl_common.h \
+ src/yajl/yajl_gen.h \
+ src/yajl/yajl_parse.h \
+ $(ENDLIST)
+
+libyajl_a_CPPFLAGS = -Isrc
+
--- /dev/null
+* add a test for 0x1F bug
+* numeric overflow in integers and double
+* line and char offsets in the lexer and in error messages
+* testing:
+ a. the permuter
+ b. some performance comparison against json_checker.
+* investigate pull instead of push parsing
+* Handle memory allocation failures gracefully
+* cygwin/msys support on win32
--- /dev/null
+FIND_PROGRAM(doxygenPath doxygen)
+
+IF (doxygenPath)
+ SET (YAJL_VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})
+ SET(yajlDirName yajl-${YAJL_VERSION})
+ SET(docPath
+ "${CMAKE_CURRENT_BINARY_DIR}/${yajlDirName}/share/doc/${yajlDirName}")
+ MESSAGE("** using doxygen at: ${doxygenPath}")
+ MESSAGE("** documentation output to: ${docPath}")
+
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/YAJL.dxy
+ ${CMAKE_CURRENT_BINARY_DIR}/YAJL.dxy @ONLY)
+
+ FILE(MAKE_DIRECTORY "${docPath}")
+
+ ADD_CUSTOM_TARGET(doc
+ ${doxygenPath} YAJL.dxy
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+
+ELSE (doxygenPath)
+ MESSAGE("!! doxygen not found, not generating documentation")
+ ADD_CUSTOM_TARGET(
+ doc
+ echo doxygen not installed, not generating documentation
+ )
+ENDIF (doxygenPath)
--- /dev/null
+# Copyright 2007-2009, Lloyd Hilaiel.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Neither the name of Lloyd Hilaiel nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# set up a paths
+SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/bin)
+
+# create a directories
+FILE(MAKE_DIRECTORY ${binDir})
+
+SET (SRCS json_reformat.c)
+
+# use the library we build, duh.
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
+
+ADD_EXECUTABLE(json_reformat ${SRCS})
+
+TARGET_LINK_LIBRARIES(json_reformat yajl_s)
+
+# copy the binary into the output directory
+GET_TARGET_PROPERTY(binPath json_reformat LOCATION)
+
+ADD_CUSTOM_COMMAND(TARGET json_reformat POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir})
+
+IF (NOT WIN32)
+ INSTALL(TARGETS json_reformat RUNTIME DESTINATION bin)
+ENDIF ()
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <yajl/yajl_parse.h>
+#include <yajl/yajl_gen.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int reformat_null(void * ctx)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_null(g);
+ return 1;
+}
+
+static int reformat_boolean(void * ctx, int boolean)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_bool(g, boolean);
+ return 1;
+}
+
+static int reformat_number(void * ctx, const char * s, unsigned int l)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_number(g, s, l);
+ return 1;
+}
+
+static int reformat_string(void * ctx, const unsigned char * stringVal,
+ unsigned int stringLen)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_string(g, stringVal, stringLen);
+ return 1;
+}
+
+static int reformat_map_key(void * ctx, const unsigned char * stringVal,
+ unsigned int stringLen)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_string(g, stringVal, stringLen);
+ return 1;
+}
+
+static int reformat_start_map(void * ctx)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_map_open(g);
+ return 1;
+}
+
+
+static int reformat_end_map(void * ctx)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_map_close(g);
+ return 1;
+}
+
+static int reformat_start_array(void * ctx)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_array_open(g);
+ return 1;
+}
+
+static int reformat_end_array(void * ctx)
+{
+ yajl_gen g = (yajl_gen) ctx;
+ yajl_gen_array_close(g);
+ return 1;
+}
+
+static yajl_callbacks callbacks = {
+ reformat_null,
+ reformat_boolean,
+ NULL,
+ NULL,
+ reformat_number,
+ reformat_string,
+ reformat_start_map,
+ reformat_map_key,
+ reformat_end_map,
+ reformat_start_array,
+ reformat_end_array
+};
+
+static void
+usage(const char * progname)
+{
+ fprintf(stderr, "usage: %s <filename>\n"
+ " -m minimize json rather than beautify (default)\n"
+ " -u allow invalid UTF8 inside strings during parsing\n",
+ progname);
+ exit(1);
+
+}
+
+int
+main(int argc, char ** argv)
+{
+ yajl_handle hand;
+ static unsigned char fileData[65536];
+ /* generator config */
+ yajl_gen_config conf = { 1, " " };
+ yajl_gen g;
+ yajl_status stat;
+ size_t rd;
+ /* allow comments */
+ yajl_parser_config cfg = { 1, 1 };
+ int done = 0;
+
+ /* check arguments. We expect exactly one! */
+ if (argc == 2) {
+ if (!strcmp("-m", argv[1])) {
+ conf.beautify = 0;
+
+ } else if (!strcmp("-u", argv[1])) {
+ cfg.checkUTF8 = 0;
+ } else {
+ usage(argv[0]);
+ }
+ } else if (argc != 1) {
+ usage(argv[0]);
+ }
+
+ g = yajl_gen_alloc(&conf, NULL);
+
+ /* ok. open file. let's read and parse */
+ hand = yajl_alloc(&callbacks, &cfg, NULL, (void *) g);
+
+ while (!done) {
+ rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
+
+ if (rd == 0) {
+ if (!feof(stdin)) {
+ fprintf(stderr, "error on file read.\n");
+ break;
+ }
+ done = 1;
+ }
+ fileData[rd] = 0;
+
+ if (done)
+ /* parse any remaining buffered data */
+ stat = yajl_parse_complete(hand);
+ else
+ /* read file data, pass to parser */
+ stat = yajl_parse(hand, fileData, rd);
+
+ if (stat != yajl_status_ok &&
+ stat != yajl_status_insufficient_data)
+ {
+ unsigned char * str = yajl_get_error(hand, 1, fileData, rd);
+ fprintf(stderr, (const char *) str);
+ yajl_free_error(hand, str);
+ } else {
+ const unsigned char * buf;
+ unsigned int len;
+ yajl_gen_get_buf(g, &buf, &len);
+ fwrite(buf, 1, len, stdout);
+ yajl_gen_clear(g);
+ }
+ }
+
+ yajl_gen_free(g);
+ yajl_free(hand);
+
+ return 0;
+}
--- /dev/null
+
+
+
+
+
+
+Network Working Group D. Crockford
+Request for Comments: 4627 JSON.org
+Category: Informational July 2006
+
+
+ The application/json Media Type for JavaScript Object Notation (JSON)
+
+Status of This Memo
+
+ This memo provides information for the Internet community. It does
+ not specify an Internet standard of any kind. Distribution of this
+ memo is unlimited.
+
+Copyright Notice
+
+ Copyright (C) The Internet Society (2006).
+
+Abstract
+
+ JavaScript Object Notation (JSON) is a lightweight, text-based,
+ language-independent data interchange format. It was derived from
+ the ECMAScript Programming Language Standard. JSON defines a small
+ set of formatting rules for the portable representation of structured
+ data.
+
+1. Introduction
+
+ JavaScript Object Notation (JSON) is a text format for the
+ serialization of structured data. It is derived from the object
+ literals of JavaScript, as defined in the ECMAScript Programming
+ Language Standard, Third Edition [ECMA].
+
+ JSON can represent four primitive types (strings, numbers, booleans,
+ and null) and two structured types (objects and arrays).
+
+ A string is a sequence of zero or more Unicode characters [UNICODE].
+
+ An object is an unordered collection of zero or more name/value
+ pairs, where a name is a string and a value is a string, number,
+ boolean, null, object, or array.
+
+ An array is an ordered sequence of zero or more values.
+
+ The terms "object" and "array" come from the conventions of
+ JavaScript.
+
+ JSON's design goals were for it to be minimal, portable, textual, and
+ a subset of JavaScript.
+
+
+
+Crockford Informational [Page 1]
+\f
+RFC 4627 JSON July 2006
+
+
+1.1. Conventions Used in This Document
+
+ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
+ "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
+ document are to be interpreted as described in [RFC2119].
+
+ The grammatical rules in this document are to be interpreted as
+ described in [RFC4234].
+
+2. JSON Grammar
+
+ A JSON text is a sequence of tokens. The set of tokens includes six
+ structural characters, strings, numbers, and three literal names.
+
+ A JSON text is a serialized object or array.
+
+ JSON-text = object / array
+
+ These are the six structural characters:
+
+ begin-array = ws %x5B ws ; [ left square bracket
+
+ begin-object = ws %x7B ws ; { left curly bracket
+
+ end-array = ws %x5D ws ; ] right square bracket
+
+ end-object = ws %x7D ws ; } right curly bracket
+
+ name-separator = ws %x3A ws ; : colon
+
+ value-separator = ws %x2C ws ; , comma
+
+ Insignificant whitespace is allowed before or after any of the six
+ structural characters.
+
+ ws = *(
+ %x20 / ; Space
+ %x09 / ; Horizontal tab
+ %x0A / ; Line feed or New line
+ %x0D ; Carriage return
+ )
+
+2.1. Values
+
+ A JSON value MUST be an object, array, number, or string, or one of
+ the following three literal names:
+
+ false null true
+
+
+
+Crockford Informational [Page 2]
+\f
+RFC 4627 JSON July 2006
+
+
+ The literal names MUST be lowercase. No other literal names are
+ allowed.
+
+ value = false / null / true / object / array / number / string
+
+ false = %x66.61.6c.73.65 ; false
+
+ null = %x6e.75.6c.6c ; null
+
+ true = %x74.72.75.65 ; true
+
+2.2. Objects
+
+ An object structure is represented as a pair of curly brackets
+ surrounding zero or more name/value pairs (or members). A name is a
+ string. A single colon comes after each name, separating the name
+ from the value. A single comma separates a value from a following
+ name. The names within an object SHOULD be unique.
+
+ object = begin-object [ member *( value-separator member ) ]
+ end-object
+
+ member = string name-separator value
+
+2.3. Arrays
+
+ An array structure is represented as square brackets surrounding zero
+ or more values (or elements). Elements are separated by commas.
+
+ array = begin-array [ value *( value-separator value ) ] end-array
+
+2.4. Numbers
+
+ The representation of numbers is similar to that used in most
+ programming languages. A number contains an integer component that
+ may be prefixed with an optional minus sign, which may be followed by
+ a fraction part and/or an exponent part.
+
+ Octal and hex forms are not allowed. Leading zeros are not allowed.
+
+ A fraction part is a decimal point followed by one or more digits.
+
+ An exponent part begins with the letter E in upper or lowercase,
+ which may be followed by a plus or minus sign. The E and optional
+ sign are followed by one or more digits.
+
+ Numeric values that cannot be represented as sequences of digits
+ (such as Infinity and NaN) are not permitted.
+
+
+
+Crockford Informational [Page 3]
+\f
+RFC 4627 JSON July 2006
+
+
+ number = [ minus ] int [ frac ] [ exp ]
+
+ decimal-point = %x2E ; .
+
+ digit1-9 = %x31-39 ; 1-9
+
+ e = %x65 / %x45 ; e E
+
+ exp = e [ minus / plus ] 1*DIGIT
+
+ frac = decimal-point 1*DIGIT
+
+ int = zero / ( digit1-9 *DIGIT )
+
+ minus = %x2D ; -
+
+ plus = %x2B ; +
+
+ zero = %x30 ; 0
+
+2.5. Strings
+
+ The representation of strings is similar to conventions used in the C
+ family of programming languages. A string begins and ends with
+ quotation marks. All Unicode characters may be placed within the
+ quotation marks except for the characters that must be escaped:
+ quotation mark, reverse solidus, and the control characters (U+0000
+ through U+001F).
+
+ Any character may be escaped. If the character is in the Basic
+ Multilingual Plane (U+0000 through U+FFFF), then it may be
+ represented as a six-character sequence: a reverse solidus, followed
+ by the lowercase letter u, followed by four hexadecimal digits that
+ encode the character's code point. The hexadecimal letters A though
+ F can be upper or lowercase. So, for example, a string containing
+ only a single reverse solidus character may be represented as
+ "\u005C".
+
+ Alternatively, there are two-character sequence escape
+ representations of some popular characters. So, for example, a
+ string containing only a single reverse solidus character may be
+ represented more compactly as "\\".
+
+ To escape an extended character that is not in the Basic Multilingual
+ Plane, the character is represented as a twelve-character sequence,
+ encoding the UTF-16 surrogate pair. So, for example, a string
+ containing only the G clef character (U+1D11E) may be represented as
+ "\uD834\uDD1E".
+
+
+
+Crockford Informational [Page 4]
+\f
+RFC 4627 JSON July 2006
+
+
+ string = quotation-mark *char quotation-mark
+
+ char = unescaped /
+ escape (
+ %x22 / ; " quotation mark U+0022
+ %x5C / ; \ reverse solidus U+005C
+ %x2F / ; / solidus U+002F
+ %x62 / ; b backspace U+0008
+ %x66 / ; f form feed U+000C
+ %x6E / ; n line feed U+000A
+ %x72 / ; r carriage return U+000D
+ %x74 / ; t tab U+0009
+ %x75 4HEXDIG ) ; uXXXX U+XXXX
+
+ escape = %x5C ; \
+
+ quotation-mark = %x22 ; "
+
+ unescaped = %x20-21 / %x23-5B / %x5D-10FFFF
+
+3. Encoding
+
+ JSON text SHALL be encoded in Unicode. The default encoding is
+ UTF-8.
+
+ Since the first two characters of a JSON text will always be ASCII
+ characters [RFC0020], it is possible to determine whether an octet
+ stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
+ at the pattern of nulls in the first four octets.
+
+ 00 00 00 xx UTF-32BE
+ 00 xx 00 xx UTF-16BE
+ xx 00 00 00 UTF-32LE
+ xx 00 xx 00 UTF-16LE
+ xx xx xx xx UTF-8
+
+4. Parsers
+
+ A JSON parser transforms a JSON text into another representation. A
+ JSON parser MUST accept all texts that conform to the JSON grammar.
+ A JSON parser MAY accept non-JSON forms or extensions.
+
+ An implementation may set limits on the size of texts that it
+ accepts. An implementation may set limits on the maximum depth of
+ nesting. An implementation may set limits on the range of numbers.
+ An implementation may set limits on the length and character contents
+ of strings.
+
+
+
+
+Crockford Informational [Page 5]
+\f
+RFC 4627 JSON July 2006
+
+
+5. Generators
+
+ A JSON generator produces JSON text. The resulting text MUST
+ strictly conform to the JSON grammar.
+
+6. IANA Considerations
+
+ The MIME media type for JSON text is application/json.
+
+ Type name: application
+
+ Subtype name: json
+
+ Required parameters: n/a
+
+ Optional parameters: n/a
+
+ Encoding considerations: 8bit if UTF-8; binary if UTF-16 or UTF-32
+
+ JSON may be represented using UTF-8, UTF-16, or UTF-32. When JSON
+ is written in UTF-8, JSON is 8bit compatible. When JSON is
+ written in UTF-16 or UTF-32, the binary content-transfer-encoding
+ must be used.
+
+ Security considerations:
+
+ Generally there are security issues with scripting languages. JSON
+ is a subset of JavaScript, but it is a safe subset that excludes
+ assignment and invocation.
+
+ A JSON text can be safely passed into JavaScript's eval() function
+ (which compiles and executes a string) if all the characters not
+ enclosed in strings are in the set of characters that form JSON
+ tokens. This can be quickly determined in JavaScript with two
+ regular expressions and calls to the test and replace methods.
+
+ var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
+ text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
+ eval('(' + text + ')');
+
+ Interoperability considerations: n/a
+
+ Published specification: RFC 4627
+
+
+
+
+
+
+
+
+Crockford Informational [Page 6]
+\f
+RFC 4627 JSON July 2006
+
+
+ Applications that use this media type:
+
+ JSON has been used to exchange data between applications written
+ in all of these programming languages: ActionScript, C, C#,
+ ColdFusion, Common Lisp, E, Erlang, Java, JavaScript, Lua,
+ Objective CAML, Perl, PHP, Python, Rebol, Ruby, and Scheme.
+
+ Additional information:
+
+ Magic number(s): n/a
+ File extension(s): .json
+ Macintosh file type code(s): TEXT
+
+ Person & email address to contact for further information:
+ Douglas Crockford
+ douglas@crockford.com
+
+ Intended usage: COMMON
+
+ Restrictions on usage: none
+
+ Author:
+ Douglas Crockford
+ douglas@crockford.com
+
+ Change controller:
+ Douglas Crockford
+ douglas@crockford.com
+
+7. Security Considerations
+
+ See Security Considerations in Section 6.
+
+8. Examples
+
+ This is a JSON object:
+
+ {
+ "Image": {
+ "Width": 800,
+ "Height": 600,
+ "Title": "View from 15th Floor",
+ "Thumbnail": {
+ "Url": "http://www.example.com/image/481989943",
+ "Height": 125,
+ "Width": "100"
+ },
+ "IDs": [116, 943, 234, 38793]
+
+
+
+Crockford Informational [Page 7]
+\f
+RFC 4627 JSON July 2006
+
+
+ }
+ }
+
+ Its Image member is an object whose Thumbnail member is an object
+ and whose IDs member is an array of numbers.
+
+ This is a JSON array containing two objects:
+
+ [
+ {
+ "precision": "zip",
+ "Latitude": 37.7668,
+ "Longitude": -122.3959,
+ "Address": "",
+ "City": "SAN FRANCISCO",
+ "State": "CA",
+ "Zip": "94107",
+ "Country": "US"
+ },
+ {
+ "precision": "zip",
+ "Latitude": 37.371991,
+ "Longitude": -122.026020,
+ "Address": "",
+ "City": "SUNNYVALE",
+ "State": "CA",
+ "Zip": "94085",
+ "Country": "US"
+ }
+ ]
+
+9. References
+
+9.1. Normative References
+
+ [ECMA] European Computer Manufacturers Association, "ECMAScript
+ Language Specification 3rd Edition", December 1999,
+ <http://www.ecma-international.org/publications/files/
+ ecma-st/ECMA-262.pdf>.
+
+ [RFC0020] Cerf, V., "ASCII format for network interchange", RFC 20,
+ October 1969.
+
+ [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
+ Requirement Levels", BCP 14, RFC 2119, March 1997.
+
+ [RFC4234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
+ Specifications: ABNF", RFC 4234, October 2005.
+
+
+
+Crockford Informational [Page 8]
+\f
+RFC 4627 JSON July 2006
+
+
+ [UNICODE] The Unicode Consortium, "The Unicode Standard Version 4.0",
+ 2003, <http://www.unicode.org/versions/Unicode4.1.0/>.
+
+Author's Address
+
+ Douglas Crockford
+ JSON.org
+ EMail: douglas@crockford.com
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Crockford Informational [Page 9]
+\f
+RFC 4627 JSON July 2006
+
+
+Full Copyright Statement
+
+ Copyright (C) The Internet Society (2006).
+
+ This document is subject to the rights, licenses and restrictions
+ contained in BCP 78, and except as set forth therein, the authors
+ retain all their rights.
+
+ This document and the information contained herein are provided on an
+ "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
+ OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
+ ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
+ INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
+ INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
+ WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+
+Intellectual Property
+
+ The IETF takes no position regarding the validity or scope of any
+ Intellectual Property Rights or other rights that might be claimed to
+ pertain to the implementation or use of the technology described in
+ this document or the extent to which any license under such rights
+ might or might not be available; nor does it represent that it has
+ made any independent effort to identify any such rights. Information
+ on the procedures with respect to rights in RFC documents can be
+ found in BCP 78 and BCP 79.
+
+ Copies of IPR disclosures made to the IETF Secretariat and any
+ assurances of licenses to be made available, or the result of an
+ attempt made to obtain a general license or permission for the use of
+ such proprietary rights by implementers or users of this
+ specification can be obtained from the IETF on-line IPR repository at
+ http://www.ietf.org/ipr.
+
+ The IETF invites any interested party to bring to its attention any
+ copyrights, patents or patent applications, or other proprietary
+ rights that may cover technology that may be required to implement
+ this standard. Please address the information to the IETF at
+ ietf-ipr@ietf.org.
+
+Acknowledgement
+
+ Funding for the RFC Editor function is provided by the IETF
+ Administrative Support Activity (IASA).
+
+
+
+
+
+
+
+Crockford Informational [Page 10]
+\f
--- /dev/null
+# Copyright 2007-2009, Lloyd Hilaiel.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Neither the name of Lloyd Hilaiel nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+SET (SRCS yajl.c yajl_lex.c yajl_parser.c yajl_buf.c
+ yajl_encode.c yajl_gen.c yajl_alloc.c)
+SET (HDRS yajl_parser.h yajl_lex.h yajl_buf.h yajl_encode.h yajl_alloc.h)
+SET (PUB_HDRS api/yajl_parse.h api/yajl_gen.h api/yajl_common.h)
+
+# useful when fixing lexer bugs.
+#ADD_DEFINITIONS(-DYAJL_LEXER_DEBUG)
+
+# set up some paths
+SET (libDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
+SET (incDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include/yajl)
+
+# set the output path for libraries
+SET(LIBRARY_OUTPUT_PATH ${libDir})
+
+ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
+
+ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
+
+#### setup shared library version number
+SET_TARGET_PROPERTIES(yajl PROPERTIES
+ SOVERSION ${YAJL_MAJOR}
+ VERSION ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO})
+
+#### build up an sdk as a post build step
+
+# create some directories
+FILE(MAKE_DIRECTORY ${libDir})
+FILE(MAKE_DIRECTORY ${incDir})
+
+# copy public headers to output directory
+FOREACH (header ${PUB_HDRS})
+ SET (header ${CMAKE_CURRENT_SOURCE_DIR}/${header})
+
+ EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different ${header} ${incDir})
+
+ ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir})
+ENDFOREACH (header ${PUB_HDRS})
+
+INCLUDE_DIRECTORIES(${incDir}/..)
+
+IF(NOT WIN32)
+ INSTALL(TARGETS yajl LIBRARY DESTINATION lib)
+ INSTALL(TARGETS yajl_s ARCHIVE DESTINATION lib)
+ INSTALL(DIRECTORY api/ DESTINATION include/yajl
+ FILES_MATCHING PATTERN "*.h")
+ENDIF()
--- /dev/null
+# Doxyfile 1.5.2
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+# TAG = value [value, ...]
+# For lists items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file that
+# follow. The default is UTF-8 which is also the encoding used for all text before
+# the first occurrence of this tag. Doxygen uses libiconv (or the iconv built into
+# libc) for the transcoding. See http://www.gnu.org/software/libiconv for the list of
+# possible encodings.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME = YAJL
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER = @YAJL_VERSION@
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = yajl-@YAJL_VERSION@/share
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian,
+# Italian, Japanese, Japanese-en (Japanese with English messages), Korean,
+# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian,
+# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like the Qt-style comments (thus requiring an
+# explicit @brief command for a brief description.
+
+JAVADOC_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the DETAILS_AT_TOP tag is set to YES then Doxygen
+# will output the detailed description near the top, like JavaDoc.
+# If set to NO, the detailed description appears after the member
+# documentation.
+
+DETAILS_AT_TOP = YES
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE = 4
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for Java.
+# For instance, namespaces will be presented as packages, qualified scopes
+# will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to
+# include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT = NO
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING = NO
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE = YES
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC = YES
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = YES
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES = NO
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES = NO
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from the
+# version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET = YES
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT = ../src/yajl ../src/api
+
+# This tag can be used to specify the character encoding of the source files that
+# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default
+# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding.
+# See http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py
+
+FILE_PATTERNS = *.h
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the output.
+# The symbol name can be a fully qualified name, a word, or if the wildcard * is used,
+# a substring. Examples: ANamespace, AClass, AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output. If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES (the default)
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES (the default)
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION = YES
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code. Otherwise they will link to the documentstion.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT = doc/yajl-@YAJL_VERSION@
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET =
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND = NO
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
+# generated containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+,
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are
+# probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS = NO
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN = YES
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader. This is useful
+# if you want to understand what is going on. On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
+# the parser if not removed.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
+# powerful graphs.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to
+# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to
+# specify the directory where the mscgen tool resides. If left empty the tool is assumed to
+# be found in the default search path.
+
+MSCGEN_PATH =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT = NO
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will
+# generate a call dependency graph for every global function or class method.
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will
+# generate a caller dependency graph for every global function or class method.
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS =
+
+# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen will always
+# show the root nodes and its direct children regardless of this setting.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, which results in a white background.
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE = NO
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "yajl/yajl_parse.h"
+#include "yajl_lex.h"
+#include "yajl_parser.h"
+#include "yajl_alloc.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+const char *
+yajl_status_to_string(yajl_status stat)
+{
+ const char * statStr = "unknown";
+ switch (stat) {
+ case yajl_status_ok:
+ statStr = "ok, no error";
+ break;
+ case yajl_status_client_canceled:
+ statStr = "client canceled parse";
+ break;
+ case yajl_status_insufficient_data:
+ statStr = "eof was met before the parse could complete";
+ break;
+ case yajl_status_error:
+ statStr = "parse error";
+ break;
+ }
+ return statStr;
+}
+
+yajl_handle
+yajl_alloc(const yajl_callbacks * callbacks,
+ const yajl_parser_config * config,
+ const yajl_alloc_funcs * afs,
+ void * ctx)
+{
+ unsigned int allowComments = 0;
+ unsigned int validateUTF8 = 0;
+ yajl_handle hand = NULL;
+ yajl_alloc_funcs afsBuffer;
+
+ /* first order of business is to set up memory allocation routines */
+ if (afs != NULL) {
+ if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
+ {
+ return NULL;
+ }
+ } else {
+ yajl_set_default_alloc_funcs(&afsBuffer);
+ afs = &afsBuffer;
+ }
+
+ hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));
+
+ /* copy in pointers to allocation routines */
+ memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
+
+ if (config != NULL) {
+ allowComments = config->allowComments;
+ validateUTF8 = config->checkUTF8;
+ }
+
+ hand->callbacks = callbacks;
+ hand->ctx = ctx;
+ hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8);
+ hand->errorOffset = 0;
+ hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
+ yajl_bs_init(hand->stateStack, &(hand->alloc));
+
+ yajl_bs_push(hand->stateStack, yajl_state_start);
+
+ return hand;
+}
+
+void
+yajl_free(yajl_handle handle)
+{
+ yajl_bs_free(handle->stateStack);
+ yajl_buf_free(handle->decodeBuf);
+ yajl_lex_free(handle->lexer);
+ YA_FREE(&(handle->alloc), handle);
+}
+
+yajl_status
+yajl_parse(yajl_handle hand, const unsigned char * jsonText,
+ unsigned int jsonTextLen)
+{
+ unsigned int offset = 0;
+ yajl_status status;
+ status = yajl_do_parse(hand, &offset, jsonText, jsonTextLen);
+ return status;
+}
+
+yajl_status
+yajl_parse_complete(yajl_handle hand)
+{
+ /* The particular case we want to handle is a trailing number.
+ * Further input consisting of digits could cause our interpretation
+ * of the number to change (buffered "1" but "2" comes in).
+ * A very simple approach to this is to inject whitespace to terminate
+ * any number in the lex buffer.
+ */
+ return yajl_parse(hand, (const unsigned char *)" ", 1);
+}
+
+unsigned char *
+yajl_get_error(yajl_handle hand, int verbose,
+ const unsigned char * jsonText, unsigned int jsonTextLen)
+{
+ return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose);
+}
+
+void
+yajl_free_error(yajl_handle hand, unsigned char * str)
+{
+ /* use memory allocation functions if set */
+ YA_FREE(&(hand->alloc), str);
+}
+
+/* XXX: add utility routines to parse from file */
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __YAJL_COMMON_H__
+#define __YAJL_COMMON_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define YAJL_MAX_DEPTH 128
+
+/* msft dll export gunk. To build a DLL on windows, you
+ * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
+ * DLL, you must define YAJL_SHARED and WIN32 */
+#if defined(WIN32) && defined(YAJL_SHARED)
+# ifdef YAJL_BUILD
+# define YAJL_API __declspec(dllexport)
+# else
+# define YAJL_API __declspec(dllimport)
+# endif
+#else
+# define YAJL_API
+#endif
+
+/** pointer to a malloc function, supporting client overriding memory
+ * allocation routines */
+typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz);
+
+/** pointer to a free function, supporting client overriding memory
+ * allocation routines */
+typedef void (*yajl_free_func)(void *ctx, void * ptr);
+
+/** pointer to a realloc function which can resize an allocation. */
+typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, unsigned int sz);
+
+/** A structure which can be passed to yajl_*_alloc routines to allow the
+ * client to specify memory allocation functions to be used. */
+typedef struct
+{
+ /** pointer to a function that can allocate uninitialized memory */
+ yajl_malloc_func malloc;
+ /** pointer to a function that can resize memory allocations */
+ yajl_realloc_func realloc;
+ /** pointer to a function that can free memory allocated using
+ * reallocFunction or mallocFunction */
+ yajl_free_func free;
+ /** a context pointer that will be passed to above allocation routines */
+ void * ctx;
+} yajl_alloc_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file yajl_gen.h
+ * Interface to YAJL's JSON generation facilities.
+ */
+
+#include <yajl/yajl_common.h>
+
+#ifndef __YAJL_GEN_H__
+#define __YAJL_GEN_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ /** generator status codes */
+ typedef enum {
+ /** no error */
+ yajl_gen_status_ok = 0,
+ /** at a point where a map key is generated, a function other than
+ * yajl_gen_string was called */
+ yajl_gen_keys_must_be_strings,
+ /** YAJL's maximum generation depth was exceeded. see
+ * YAJL_MAX_DEPTH */
+ yajl_max_depth_exceeded,
+ /** A generator function (yajl_gen_XXX) was called while in an error
+ * state */
+ yajl_gen_in_error_state,
+ /** A complete JSON document has been generated */
+ yajl_gen_generation_complete
+ } yajl_gen_status;
+
+ /** an opaque handle to a generator */
+ typedef struct yajl_gen_t * yajl_gen;
+
+ /** configuration structure for the generator */
+ typedef struct {
+ /** generate indented (beautiful) output */
+ unsigned int beautify;
+ /** an opportunity to define an indent string. such as \\t or
+ * some number of spaces. default is four spaces ' '. This
+ * member is only relevant when beautify is true */
+ const char * indentString;
+ } yajl_gen_config;
+
+ /** allocate a generator handle
+ * \param config a pointer to a structure containing parameters which
+ * configure the behavior of the json generator
+ * \param allocFuncs an optional pointer to a structure which allows
+ * the client to overide the memory allocation
+ * used by yajl. May be NULL, in which case
+ * malloc/free/realloc will be used.
+ *
+ * \returns an allocated handle on success, NULL on failure (bad params)
+ */
+ yajl_gen YAJL_API yajl_gen_alloc(const yajl_gen_config * config,
+ const yajl_alloc_funcs * allocFuncs);
+
+ /** free a generator handle */
+ void YAJL_API yajl_gen_free(yajl_gen handle);
+
+ yajl_gen_status YAJL_API yajl_gen_integer(yajl_gen hand, long int number);
+ yajl_gen_status YAJL_API yajl_gen_double(yajl_gen hand, double number);
+ yajl_gen_status YAJL_API yajl_gen_number(yajl_gen hand,
+ const char * num,
+ unsigned int len);
+ yajl_gen_status YAJL_API yajl_gen_string(yajl_gen hand,
+ const unsigned char * str,
+ unsigned int len);
+ yajl_gen_status YAJL_API yajl_gen_null(yajl_gen hand);
+ yajl_gen_status YAJL_API yajl_gen_bool(yajl_gen hand, int boolean);
+ yajl_gen_status YAJL_API yajl_gen_map_open(yajl_gen hand);
+ yajl_gen_status YAJL_API yajl_gen_map_close(yajl_gen hand);
+ yajl_gen_status YAJL_API yajl_gen_array_open(yajl_gen hand);
+ yajl_gen_status YAJL_API yajl_gen_array_close(yajl_gen hand);
+
+ /** access the null terminated generator buffer. If incrementally
+ * outputing JSON, one should call yajl_gen_clear to clear the
+ * buffer. This allows stream generation. */
+ yajl_gen_status YAJL_API yajl_gen_get_buf(yajl_gen hand,
+ const unsigned char ** buf,
+ unsigned int * len);
+
+ /** clear yajl's output buffer, but maintain all internal generation
+ * state. This function will not "reset" the generator state, and is
+ * intended to enable incremental JSON outputing. */
+ void YAJL_API yajl_gen_clear(yajl_gen hand);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file yajl_parse.h
+ * Interface to YAJL's JSON parsing facilities.
+ */
+
+#include <yajl/yajl_common.h>
+
+#ifndef __YAJL_PARSE_H__
+#define __YAJL_PARSE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ /** error codes returned from this interface */
+ typedef enum {
+ /** no error was encountered */
+ yajl_status_ok,
+ /** a client callback returned zero, stopping the parse */
+ yajl_status_client_canceled,
+ /** The parse cannot yet complete because more json input text
+ * is required, call yajl_parse with the next buffer of input text.
+ * (pertinent only when stream parsing) */
+ yajl_status_insufficient_data,
+ /** An error occured during the parse. Call yajl_get_error for
+ * more information about the encountered error */
+ yajl_status_error
+ } yajl_status;
+
+ /** attain a human readable, english, string for an error */
+ const char * YAJL_API yajl_status_to_string(yajl_status code);
+
+ /** an opaque handle to a parser */
+ typedef struct yajl_handle_t * yajl_handle;
+
+ /** yajl is an event driven parser. this means as json elements are
+ * parsed, you are called back to do something with the data. The
+ * functions in this table indicate the various events for which
+ * you will be called back. Each callback accepts a "context"
+ * pointer, this is a void * that is passed into the yajl_parse
+ * function which the client code may use to pass around context.
+ *
+ * All callbacks return an integer. If non-zero, the parse will
+ * continue. If zero, the parse will be canceled and
+ * yajl_status_client_canceled will be returned from the parse.
+ *
+ * Note about handling of numbers:
+ * yajl will only convert numbers that can be represented in a double
+ * or a long int. All other numbers will be passed to the client
+ * in string form using the yajl_number callback. Furthermore, if
+ * yajl_number is not NULL, it will always be used to return numbers,
+ * that is yajl_integer and yajl_double will be ignored. If
+ * yajl_number is NULL but one of yajl_integer or yajl_double are
+ * defined, parsing of a number larger than is representable
+ * in a double or long int will result in a parse error.
+ */
+ typedef struct {
+ int (* yajl_null)(void * ctx);
+ int (* yajl_boolean)(void * ctx, int boolVal);
+ int (* yajl_integer)(void * ctx, long integerVal);
+ int (* yajl_double)(void * ctx, double doubleVal);
+ /** A callback which passes the string representation of the number
+ * back to the client. Will be used for all numbers when present */
+ int (* yajl_number)(void * ctx, const char * numberVal,
+ unsigned int numberLen);
+
+ /** strings are returned as pointers into the JSON text when,
+ * possible, as a result, they are _not_ null padded */
+ int (* yajl_string)(void * ctx, const unsigned char * stringVal,
+ unsigned int stringLen);
+
+ int (* yajl_start_map)(void * ctx);
+ int (* yajl_map_key)(void * ctx, const unsigned char * key,
+ unsigned int stringLen);
+ int (* yajl_end_map)(void * ctx);
+
+ int (* yajl_start_array)(void * ctx);
+ int (* yajl_end_array)(void * ctx);
+ } yajl_callbacks;
+
+ /** configuration structure for the generator */
+ typedef struct {
+ /** if nonzero, javascript style comments will be allowed in
+ * the json input, both slash star and slash slash */
+ unsigned int allowComments;
+ /** if nonzero, invalid UTF8 strings will cause a parse
+ * error */
+ unsigned int checkUTF8;
+ } yajl_parser_config;
+
+ /** allocate a parser handle
+ * \param callbacks a yajl callbacks structure specifying the
+ * functions to call when different JSON entities
+ * are encountered in the input text. May be NULL,
+ * which is only useful for validation.
+ * \param config configuration parameters for the parse.
+ * \param ctx a context pointer that will be passed to callbacks.
+ */
+ yajl_handle YAJL_API yajl_alloc(const yajl_callbacks * callbacks,
+ const yajl_parser_config * config,
+ const yajl_alloc_funcs * allocFuncs,
+ void * ctx);
+
+ /** free a parser handle */
+ void YAJL_API yajl_free(yajl_handle handle);
+
+ /** Parse some json!
+ * \param hand - a handle to the json parser allocated with yajl_alloc
+ * \param jsonText - a pointer to the UTF8 json text to be parsed
+ * \param jsonTextLength - the length, in bytes, of input text
+ */
+ yajl_status YAJL_API yajl_parse(yajl_handle hand,
+ const unsigned char * jsonText,
+ unsigned int jsonTextLength);
+
+ /** Parse any remaining buffered json.
+ * Since yajl is a stream-based parser, without an explicit end of
+ * input, yajl sometimes can't decide if content at the end of the
+ * stream is valid or not. For example, if "1" has been fed in,
+ * yajl can't know whether another digit is next or some character
+ * that would terminate the integer token.
+ *
+ * \param hand - a handle to the json parser allocated with yajl_alloc
+ */
+ yajl_status yajl_parse_complete(yajl_handle hand);
+
+ /** get an error string describing the state of the
+ * parse.
+ *
+ * If verbose is non-zero, the message will include the JSON
+ * text where the error occured, along with an arrow pointing to
+ * the specific char.
+ *
+ * A dynamically allocated string will be returned which should
+ * be freed with yajl_free_error
+ */
+ unsigned char * YAJL_API yajl_get_error(yajl_handle hand, int verbose,
+ const unsigned char * jsonText,
+ unsigned int jsonTextLength);
+
+ /** free an error returned from yajl_get_error */
+ void YAJL_API yajl_free_error(yajl_handle hand, unsigned char * str);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file yajl_alloc.h
+ * default memory allocation routines for yajl which use malloc/realloc and
+ * free
+ */
+
+#include "yajl_alloc.h"
+#include <stdlib.h>
+
+static void * yajl_internal_malloc(void *ctx, unsigned int sz)
+{
+ return malloc(sz);
+}
+
+static void * yajl_internal_realloc(void *ctx, void * previous,
+ unsigned int sz)
+{
+ return realloc(previous, sz);
+}
+
+static void yajl_internal_free(void *ctx, void * ptr)
+{
+ free(ptr);
+}
+
+void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf)
+{
+ yaf->malloc = yajl_internal_malloc;
+ yaf->free = yajl_internal_free;
+ yaf->realloc = yajl_internal_realloc;
+ yaf->ctx = NULL;
+}
+
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file yajl_alloc.h
+ * default memory allocation routines for yajl which use malloc/realloc and
+ * free
+ */
+
+#ifndef __YAJL_ALLOC_H__
+#define __YAJL_ALLOC_H__
+
+#include "yajl/yajl_common.h"
+
+#define YA_MALLOC(afs, sz) (afs)->malloc((afs)->ctx, (sz))
+#define YA_FREE(afs, ptr) (afs)->free((afs)->ctx, (ptr))
+#define YA_REALLOC(afs, ptr, sz) (afs)->realloc((afs)->ctx, (ptr), (sz))
+
+void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf);
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "yajl_buf.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define YAJL_BUF_INIT_SIZE 2048
+
+struct yajl_buf_t {
+ unsigned int len;
+ unsigned int used;
+ unsigned char * data;
+ yajl_alloc_funcs * alloc;
+};
+
+static
+void yajl_buf_ensure_available(yajl_buf buf, unsigned int want)
+{
+ unsigned int need;
+
+ assert(buf != NULL);
+
+ /* first call */
+ if (buf->data == NULL) {
+ buf->len = YAJL_BUF_INIT_SIZE;
+ buf->data = (unsigned char *) YA_MALLOC(buf->alloc, buf->len);
+ buf->data[0] = 0;
+ }
+
+ need = buf->len;
+
+ while (want >= (need - buf->used)) need <<= 1;
+
+ if (need != buf->len) {
+ buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need);
+ buf->len = need;
+ }
+}
+
+yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc)
+{
+ yajl_buf b = YA_MALLOC(alloc, sizeof(struct yajl_buf_t));
+ memset((void *) b, 0, sizeof(struct yajl_buf_t));
+ b->alloc = alloc;
+ return b;
+}
+
+void yajl_buf_free(yajl_buf buf)
+{
+ assert(buf != NULL);
+ if (buf->data) YA_FREE(buf->alloc, buf->data);
+ YA_FREE(buf->alloc, buf);
+}
+
+void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len)
+{
+ yajl_buf_ensure_available(buf, len);
+ if (len > 0) {
+ assert(data != NULL);
+ memcpy(buf->data + buf->used, data, len);
+ buf->used += len;
+ buf->data[buf->used] = 0;
+ }
+}
+
+void yajl_buf_clear(yajl_buf buf)
+{
+ buf->used = 0;
+ if (buf->data) buf->data[buf->used] = 0;
+}
+
+const unsigned char * yajl_buf_data(yajl_buf buf)
+{
+ return buf->data;
+}
+
+unsigned int yajl_buf_len(yajl_buf buf)
+{
+ return buf->used;
+}
+
+void
+yajl_buf_truncate(yajl_buf buf, unsigned int len)
+{
+ assert(len <= buf->used);
+ buf->used = len;
+}
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __YAJL_BUF_H__
+#define __YAJL_BUF_H__
+
+#include "yajl/yajl_common.h"
+#include "yajl_alloc.h"
+
+/*
+ * Implementation/performance notes. If this were moved to a header
+ * only implementation using #define's where possible we might be
+ * able to sqeeze a little performance out of the guy by killing function
+ * call overhead. YMMV.
+ */
+
+/**
+ * yajl_buf is a buffer with exponential growth. the buffer ensures that
+ * you are always null padded.
+ */
+typedef struct yajl_buf_t * yajl_buf;
+
+/* allocate a new buffer */
+yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc);
+
+/* free the buffer */
+void yajl_buf_free(yajl_buf buf);
+
+/* append a number of bytes to the buffer */
+void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len);
+
+/* empty the buffer */
+void yajl_buf_clear(yajl_buf buf);
+
+/* get a pointer to the beginning of the buffer */
+const unsigned char * yajl_buf_data(yajl_buf buf);
+
+/* get the length of the buffer */
+unsigned int yajl_buf_len(yajl_buf buf);
+
+/* truncate the buffer */
+void yajl_buf_truncate(yajl_buf buf, unsigned int len);
+
+#endif
--- /dev/null
+/*
+ * Copyright 2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * A header only implementation of a simple stack of bytes, used in YAJL
+ * to maintain parse state.
+ */
+
+#ifndef __YAJL_BYTESTACK_H__
+#define __YAJL_BYTESTACK_H__
+
+#include "yajl/yajl_common.h"
+
+#define YAJL_BS_INC 128
+
+typedef struct yajl_bytestack_t
+{
+ unsigned char * stack;
+ unsigned int size;
+ unsigned int used;
+ yajl_alloc_funcs * yaf;
+} yajl_bytestack;
+
+/* initialize a bytestack */
+#define yajl_bs_init(obs, _yaf) { \
+ (obs).stack = NULL; \
+ (obs).size = 0; \
+ (obs).used = 0; \
+ (obs).yaf = (_yaf); \
+ } \
+
+
+/* initialize a bytestack */
+#define yajl_bs_free(obs) \
+ if ((obs).stack) (obs).yaf->free((obs).yaf->ctx, (obs).stack);
+
+#define yajl_bs_current(obs) \
+ (assert((obs).used > 0), (obs).stack[(obs).used - 1])
+
+#define yajl_bs_push(obs, byte) { \
+ if (((obs).size - (obs).used) == 0) { \
+ (obs).size += YAJL_BS_INC; \
+ (obs).stack = (obs).yaf->realloc((obs).yaf->ctx,\
+ (void *) (obs).stack, (obs).size);\
+ } \
+ (obs).stack[((obs).used)++] = (byte); \
+}
+
+/* removes the top item of the stack, returns nothing */
+#define yajl_bs_pop(obs) { ((obs).used)--; }
+
+#define yajl_bs_set(obs, byte) \
+ (obs).stack[((obs).used) - 1] = (byte);
+
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "yajl_encode.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+static void CharToHex(unsigned char c, char * hexBuf)
+{
+ const char * hexchar = "0123456789ABCDEF";
+ hexBuf[0] = hexchar[c >> 4];
+ hexBuf[1] = hexchar[c & 0x0F];
+}
+
+void
+yajl_string_encode(yajl_buf buf, const unsigned char * str,
+ unsigned int len)
+{
+ unsigned int beg = 0;
+ unsigned int end = 0;
+ char hexBuf[7];
+ hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0';
+ hexBuf[6] = 0;
+
+ while (end < len) {
+ const char * escaped = NULL;
+ switch (str[end]) {
+ case '\r': escaped = "\\r"; break;
+ case '\n': escaped = "\\n"; break;
+ case '\\': escaped = "\\\\"; break;
+ /* case '/': escaped = "\\/"; break; */
+ case '"': escaped = "\\\""; break;
+ case '\f': escaped = "\\f"; break;
+ case '\b': escaped = "\\b"; break;
+ case '\t': escaped = "\\t"; break;
+ default:
+ if ((unsigned char) str[end] < 32) {
+ CharToHex(str[end], hexBuf + 4);
+ escaped = hexBuf;
+ }
+ break;
+ }
+ if (escaped != NULL) {
+ yajl_buf_append(buf, str + beg, end - beg);
+ yajl_buf_append(buf, escaped, strlen(escaped));
+ beg = ++end;
+ } else {
+ ++end;
+ }
+ }
+ yajl_buf_append(buf, str + beg, end - beg);
+}
+
+static void hexToDigit(unsigned int * val, const unsigned char * hex)
+{
+ unsigned int i;
+ for (i=0;i<4;i++) {
+ unsigned char c = hex[i];
+ if (c >= 'A') c = (c & ~0x20) - 7;
+ c -= '0';
+ assert(!(c & 0xF0));
+ *val = (*val << 4) | c;
+ }
+}
+
+static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf)
+{
+ if (codepoint < 0x80) {
+ utf8Buf[0] = (char) codepoint;
+ utf8Buf[1] = 0;
+ } else if (codepoint < 0x0800) {
+ utf8Buf[0] = (char) ((codepoint >> 6) | 0xC0);
+ utf8Buf[1] = (char) ((codepoint & 0x3F) | 0x80);
+ utf8Buf[2] = 0;
+ } else if (codepoint < 0x10000) {
+ utf8Buf[0] = (char) ((codepoint >> 12) | 0xE0);
+ utf8Buf[1] = (char) (((codepoint >> 6) & 0x3F) | 0x80);
+ utf8Buf[2] = (char) ((codepoint & 0x3F) | 0x80);
+ utf8Buf[3] = 0;
+ } else if (codepoint < 0x200000) {
+ utf8Buf[0] =(char)((codepoint >> 18) | 0xF0);
+ utf8Buf[1] =(char)(((codepoint >> 12) & 0x3F) | 0x80);
+ utf8Buf[2] =(char)(((codepoint >> 6) & 0x3F) | 0x80);
+ utf8Buf[3] =(char)((codepoint & 0x3F) | 0x80);
+ utf8Buf[4] = 0;
+ } else {
+ utf8Buf[0] = '?';
+ utf8Buf[1] = 0;
+ }
+}
+
+void yajl_string_decode(yajl_buf buf, const unsigned char * str,
+ unsigned int len)
+{
+ unsigned int beg = 0;
+ unsigned int end = 0;
+
+ while (end < len) {
+ if (str[end] == '\\') {
+ char utf8Buf[5];
+ const char * unescaped = "?";
+ yajl_buf_append(buf, str + beg, end - beg);
+ switch (str[++end]) {
+ case 'r': unescaped = "\r"; break;
+ case 'n': unescaped = "\n"; break;
+ case '\\': unescaped = "\\"; break;
+ case '/': unescaped = "/"; break;
+ case '"': unescaped = "\""; break;
+ case 'f': unescaped = "\f"; break;
+ case 'b': unescaped = "\b"; break;
+ case 't': unescaped = "\t"; break;
+ case 'u': {
+ unsigned int codepoint = 0;
+ hexToDigit(&codepoint, str + ++end);
+ end+=3;
+ /* check if this is a surrogate */
+ if ((codepoint & 0xFC00) == 0xD800) {
+ end++;
+ if (str[end] == '\\' && str[end + 1] == 'u') {
+ unsigned int surrogate = 0;
+ hexToDigit(&surrogate, str + end + 2);
+ codepoint =
+ (((codepoint & 0x3F) << 10) |
+ ((((codepoint >> 6) & 0xF) + 1) << 16) |
+ (surrogate & 0x3FF));
+ end += 5;
+ } else {
+ unescaped = "?";
+ break;
+ }
+ }
+
+ Utf32toUtf8(codepoint, utf8Buf);
+ unescaped = utf8Buf;
+ break;
+ }
+ default:
+ assert("this should never happen" == NULL);
+ }
+ yajl_buf_append(buf, unescaped, strlen(unescaped));
+ beg = ++end;
+ } else {
+ end++;
+ }
+ }
+ yajl_buf_append(buf, str + beg, end - beg);
+}
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __YAJL_ENCODE_H__
+#define __YAJL_ENCODE_H__
+
+#include "yajl_buf.h"
+
+void yajl_string_encode(yajl_buf buf, const unsigned char * str,
+ unsigned int length);
+
+void yajl_string_decode(yajl_buf buf, const unsigned char * str,
+ unsigned int length);
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "yajl/yajl_gen.h"
+#include "yajl_buf.h"
+#include "yajl_encode.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+typedef enum {
+ yajl_gen_start,
+ yajl_gen_map_start,
+ yajl_gen_map_key,
+ yajl_gen_map_val,
+ yajl_gen_array_start,
+ yajl_gen_in_array,
+ yajl_gen_complete,
+ yajl_gen_error
+} yajl_gen_state;
+
+struct yajl_gen_t
+{
+ unsigned int depth;
+ unsigned int pretty;
+ const char * indentString;
+ yajl_gen_state state[YAJL_MAX_DEPTH];
+ yajl_buf buf;
+ /* memory allocation routines */
+ yajl_alloc_funcs alloc;
+};
+
+yajl_gen
+yajl_gen_alloc(const yajl_gen_config * config,
+ const yajl_alloc_funcs * afs)
+{
+ yajl_gen g = NULL;
+ yajl_alloc_funcs afsBuffer;
+
+ /* first order of business is to set up memory allocation routines */
+ if (afs != NULL) {
+ if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
+ {
+ return NULL;
+ }
+ } else {
+ yajl_set_default_alloc_funcs(&afsBuffer);
+ afs = &afsBuffer;
+ }
+
+ g = (yajl_gen) YA_MALLOC(afs, sizeof(struct yajl_gen_t));
+ memset((void *) g, 0, sizeof(struct yajl_gen_t));
+ /* copy in pointers to allocation routines */
+ memcpy((void *) &(g->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
+
+ if (config) {
+ g->pretty = config->beautify;
+ g->indentString = config->indentString ? config->indentString : " ";
+ }
+ g->buf = yajl_buf_alloc(&(g->alloc));
+
+ return g;
+}
+
+void
+yajl_gen_free(yajl_gen g)
+{
+ yajl_buf_free(g->buf);
+ YA_FREE(&(g->alloc), g);
+}
+
+#define INSERT_SEP \
+ if (g->state[g->depth] == yajl_gen_map_key || \
+ g->state[g->depth] == yajl_gen_in_array) { \
+ yajl_buf_append(g->buf, ",", 1); \
+ if (g->pretty) yajl_buf_append(g->buf, "\n", 1); \
+ } else if (g->state[g->depth] == yajl_gen_map_val) { \
+ yajl_buf_append(g->buf, ":", 1); \
+ if (g->pretty) yajl_buf_append(g->buf, " ", 1); \
+ }
+
+#define INSERT_WHITESPACE \
+ if (g->pretty) { \
+ if (g->state[g->depth] != yajl_gen_map_val) { \
+ unsigned int _i; \
+ for (_i=0;_i<g->depth;_i++) \
+ yajl_buf_append(g->buf, g->indentString, \
+ strlen(g->indentString)); \
+ } \
+ }
+
+#define ENSURE_NOT_KEY \
+ if (g->state[g->depth] == yajl_gen_map_key) { \
+ return yajl_gen_keys_must_be_strings; \
+ } \
+
+/* check that we're not complete, or in error state. in a valid state
+ * to be generating */
+#define ENSURE_VALID_STATE \
+ if (g->state[g->depth] == yajl_gen_error) { \
+ return yajl_gen_in_error_state;\
+ } else if (g->state[g->depth] == yajl_gen_complete) { \
+ return yajl_gen_generation_complete; \
+ }
+
+#define INCREMENT_DEPTH \
+ if (++(g->depth) >= YAJL_MAX_DEPTH) return yajl_max_depth_exceeded;
+
+#define APPENDED_ATOM \
+ switch (g->state[g->depth]) { \
+ case yajl_gen_start: \
+ g->state[g->depth] = yajl_gen_complete; \
+ break; \
+ case yajl_gen_map_start: \
+ case yajl_gen_map_key: \
+ g->state[g->depth] = yajl_gen_map_val; \
+ break; \
+ case yajl_gen_array_start: \
+ g->state[g->depth] = yajl_gen_in_array; \
+ break; \
+ case yajl_gen_map_val: \
+ g->state[g->depth] = yajl_gen_map_key; \
+ break; \
+ default: \
+ break; \
+ } \
+
+#define FINAL_NEWLINE \
+ if (g->pretty && g->state[g->depth] == yajl_gen_complete) \
+ yajl_buf_append(g->buf, "\n", 1);
+
+yajl_gen_status
+yajl_gen_integer(yajl_gen g, long int number)
+{
+ char i[32];
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ sprintf(i, "%ld", number);
+ yajl_buf_append(g->buf, i, strlen(i));
+ APPENDED_ATOM;
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_double(yajl_gen g, double number)
+{
+ char i[32];
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ sprintf(i, "%g", number);
+ yajl_buf_append(g->buf, i, strlen(i));
+ APPENDED_ATOM;
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_number(yajl_gen g, const char * s, unsigned int l)
+{
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ yajl_buf_append(g->buf, s, l);
+ APPENDED_ATOM;
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_string(yajl_gen g, const unsigned char * str,
+ unsigned int len)
+{
+ ENSURE_VALID_STATE; INSERT_SEP; INSERT_WHITESPACE;
+ yajl_buf_append(g->buf, "\"", 1);
+ yajl_string_encode(g->buf, str, len);
+ yajl_buf_append(g->buf, "\"", 1);
+ APPENDED_ATOM;
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_null(yajl_gen g)
+{
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ yajl_buf_append(g->buf, "null", strlen("null"));
+ APPENDED_ATOM;
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_bool(yajl_gen g, int boolean)
+{
+ const char * val = boolean ? "true" : "false";
+
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ yajl_buf_append(g->buf, val, strlen(val));
+ APPENDED_ATOM;
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_map_open(yajl_gen g)
+{
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ INCREMENT_DEPTH;
+
+ g->state[g->depth] = yajl_gen_map_start;
+ yajl_buf_append(g->buf, "{", 1);
+ if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_map_close(yajl_gen g)
+{
+ ENSURE_VALID_STATE;
+ (g->depth)--;
+ if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
+ APPENDED_ATOM;
+ INSERT_WHITESPACE;
+ yajl_buf_append(g->buf, "}", 1);
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_array_open(yajl_gen g)
+{
+ ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE;
+ INCREMENT_DEPTH;
+ g->state[g->depth] = yajl_gen_array_start;
+ yajl_buf_append(g->buf, "[", 1);
+ if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_array_close(yajl_gen g)
+{
+ ENSURE_VALID_STATE;
+ if (g->pretty) yajl_buf_append(g->buf, "\n", 1);
+ (g->depth)--;
+ APPENDED_ATOM;
+ INSERT_WHITESPACE;
+ yajl_buf_append(g->buf, "]", 1);
+ FINAL_NEWLINE;
+ return yajl_gen_status_ok;
+}
+
+yajl_gen_status
+yajl_gen_get_buf(yajl_gen g, const unsigned char ** buf,
+ unsigned int * len)
+{
+ *buf = yajl_buf_data(g->buf);
+ *len = yajl_buf_len(g->buf);
+ return yajl_gen_status_ok;
+}
+
+void
+yajl_gen_clear(yajl_gen g)
+{
+ yajl_buf_clear(g->buf);
+}
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "yajl_lex.h"
+#include "yajl_buf.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#ifdef YAJL_LEXER_DEBUG
+static const char *
+tokToStr(yajl_tok tok)
+{
+ switch (tok) {
+ case yajl_tok_bool: return "bool";
+ case yajl_tok_colon: return "colon";
+ case yajl_tok_comma: return "comma";
+ case yajl_tok_eof: return "eof";
+ case yajl_tok_error: return "error";
+ case yajl_tok_left_brace: return "brace";
+ case yajl_tok_left_bracket: return "bracket";
+ case yajl_tok_null: return "null";
+ case yajl_tok_integer: return "integer";
+ case yajl_tok_double: return "double";
+ case yajl_tok_right_brace: return "brace";
+ case yajl_tok_right_bracket: return "bracket";
+ case yajl_tok_string: return "string";
+ case yajl_tok_string_with_escapes: return "string_with_escapes";
+ }
+ return "unknown";
+}
+#endif
+
+/* Impact of the stream parsing feature on the lexer:
+ *
+ * YAJL support stream parsing. That is, the ability to parse the first
+ * bits of a chunk of JSON before the last bits are available (still on
+ * the network or disk). This makes the lexer more complex. The
+ * responsibility of the lexer is to handle transparently the case where
+ * a chunk boundary falls in the middle of a token. This is
+ * accomplished is via a buffer and a character reading abstraction.
+ *
+ * Overview of implementation
+ *
+ * When we lex to end of input string before end of token is hit, we
+ * copy all of the input text composing the token into our lexBuf.
+ *
+ * Every time we read a character, we do so through the readChar function.
+ * readChar's responsibility is to handle pulling all chars from the buffer
+ * before pulling chars from input text
+ */
+
+struct yajl_lexer_t {
+ /* the overal line and char offset into the data */
+ unsigned int lineOff;
+ unsigned int charOff;
+
+ /* error */
+ yajl_lex_error error;
+
+ /* a input buffer to handle the case where a token is spread over
+ * multiple chunks */
+ yajl_buf buf;
+
+ /* in the case where we have data in the lexBuf, bufOff holds
+ * the current offset into the lexBuf. */
+ unsigned int bufOff;
+
+ /* are we using the lex buf? */
+ unsigned int bufInUse;
+
+ /* shall we allow comments? */
+ unsigned int allowComments;
+
+ /* shall we validate utf8 inside strings? */
+ unsigned int validateUTF8;
+
+ yajl_alloc_funcs * alloc;
+};
+
+#define readChar(lxr, txt, off) \
+ (((lxr)->bufInUse && yajl_buf_len((lxr)->buf) && lxr->bufOff < yajl_buf_len((lxr)->buf)) ? \
+ (*((const unsigned char *) yajl_buf_data((lxr)->buf) + ((lxr)->bufOff)++)) : \
+ ((txt)[(*(off))++]))
+
+#define unreadChar(lxr, off) ((*(off) > 0) ? (*(off))-- : ((lxr)->bufOff--))
+
+yajl_lexer
+yajl_lex_alloc(yajl_alloc_funcs * alloc,
+ unsigned int allowComments, unsigned int validateUTF8)
+{
+ yajl_lexer lxr = (yajl_lexer) YA_MALLOC(alloc, sizeof(struct yajl_lexer_t));
+ memset((void *) lxr, 0, sizeof(struct yajl_lexer_t));
+ lxr->buf = yajl_buf_alloc(alloc);
+ lxr->allowComments = allowComments;
+ lxr->validateUTF8 = validateUTF8;
+ lxr->alloc = alloc;
+ return lxr;
+}
+
+void
+yajl_lex_free(yajl_lexer lxr)
+{
+ yajl_buf_free(lxr->buf);
+ YA_FREE(lxr->alloc, lxr);
+ return;
+}
+
+/* a lookup table which lets us quickly determine three things:
+ * VEC - valid escaped conrol char
+ * IJC - invalid json char
+ * VHC - valid hex char
+ * note. the solidus '/' may be escaped or not.
+ * note. the
+ */
+#define VEC 1
+#define IJC 2
+#define VHC 4
+static const char charLookupTable[256] =
+{
+/*00*/ IJC , IJC , IJC , IJC , IJC , IJC , IJC , IJC ,
+/*08*/ IJC , IJC , IJC , IJC , IJC , IJC , IJC , IJC ,
+/*10*/ IJC , IJC , IJC , IJC , IJC , IJC , IJC , IJC ,
+/*18*/ IJC , IJC , IJC , IJC , IJC , IJC , IJC , IJC ,
+
+/*20*/ 0 , 0 , VEC|IJC, 0 , 0 , 0 , 0 , 0 ,
+/*28*/ 0 , 0 , 0 , 0 , 0 , 0 , 0 , VEC ,
+/*30*/ VHC , VHC , VHC , VHC , VHC , VHC , VHC , VHC ,
+/*38*/ VHC , VHC , 0 , 0 , 0 , 0 , 0 , 0 ,
+
+/*40*/ 0 , VHC , VHC , VHC , VHC , VHC , VHC , 0 ,
+/*48*/ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+/*50*/ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+/*58*/ 0 , 0 , 0 , 0 , VEC|IJC, 0 , 0 , 0 ,
+
+/*60*/ 0 , VHC , VEC|VHC, VHC , VHC , VHC , VEC|VHC, 0 ,
+/*68*/ 0 , 0 , 0 , 0 , 0 , 0 , VEC , 0 ,
+/*70*/ 0 , 0 , VEC , 0 , VEC , 0 , 0 , 0 ,
+/*78*/ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+
+/* include these so we don't have to always check the range of the char */
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
+};
+
+/** process a variable length utf8 encoded codepoint.
+ *
+ * returns:
+ * yajl_tok_string - if valid utf8 char was parsed and offset was
+ * advanced
+ * yajl_tok_eof - if end of input was hit before validation could
+ * complete
+ * yajl_tok_error - if invalid utf8 was encountered
+ *
+ * NOTE: on error the offset will point to the first char of the
+ * invalid utf8 */
+#define UTF8_CHECK_EOF if (*offset >= jsonTextLen) { return yajl_tok_eof; }
+
+static yajl_tok
+yajl_lex_utf8_char(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int * offset,
+ unsigned char curChar)
+{
+ if (curChar <= 0x7f) {
+ /* single byte */
+ return yajl_tok_string;
+ } else if ((curChar >> 5) == 0x6) {
+ /* two byte */
+ UTF8_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if ((curChar >> 6) == 0x2) return yajl_tok_string;
+ } else if ((curChar >> 4) == 0x0e) {
+ /* three byte */
+ UTF8_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if ((curChar >> 6) == 0x2) {
+ UTF8_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if ((curChar >> 6) == 0x2) return yajl_tok_string;
+ }
+ } else if ((curChar >> 3) == 0x1e) {
+ /* four byte */
+ UTF8_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if ((curChar >> 6) == 0x2) {
+ UTF8_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if ((curChar >> 6) == 0x2) {
+ UTF8_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if ((curChar >> 6) == 0x2) return yajl_tok_string;
+ }
+ }
+ }
+
+ return yajl_tok_error;
+}
+
+/* lex a string. input is the lexer, pointer to beginning of
+ * json text, and start of string (offset).
+ * a token is returned which has the following meanings:
+ * yajl_tok_string: lex of string was successful. offset points to
+ * terminating '"'.
+ * yajl_tok_eof: end of text was encountered before we could complete
+ * the lex.
+ * yajl_tok_error: embedded in the string were unallowable chars. offset
+ * points to the offending char
+ */
+#define STR_CHECK_EOF \
+if (*offset >= jsonTextLen) { \
+ tok = yajl_tok_eof; \
+ goto finish_string_lex; \
+}
+
+static yajl_tok
+yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int * offset)
+{
+ yajl_tok tok = yajl_tok_error;
+ int hasEscapes = 0;
+
+ for (;;) {
+ unsigned char curChar;
+
+ STR_CHECK_EOF;
+
+ curChar = readChar(lexer, jsonText, offset);
+
+ /* quote terminates */
+ if (curChar == '"') {
+ tok = yajl_tok_string;
+ break;
+ }
+ /* backslash escapes a set of control chars, */
+ else if (curChar == '\\') {
+ hasEscapes = 1;
+ STR_CHECK_EOF;
+
+ /* special case \u */
+ curChar = readChar(lexer, jsonText, offset);
+ if (curChar == 'u') {
+ unsigned int i = 0;
+
+ for (i=0;i<4;i++) {
+ STR_CHECK_EOF;
+ curChar = readChar(lexer, jsonText, offset);
+ if (!(charLookupTable[curChar] & VHC)) {
+ /* back up to offending char */
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_string_invalid_hex_char;
+ goto finish_string_lex;
+ }
+ }
+ } else if (!(charLookupTable[curChar] & VEC)) {
+ /* back up to offending char */
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_string_invalid_escaped_char;
+ goto finish_string_lex;
+ }
+ }
+ /* when not validating UTF8 it's a simple table lookup to determine
+ * if the present character is invalid */
+ else if(charLookupTable[curChar] & IJC) {
+ /* back up to offending char */
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_string_invalid_json_char;
+ goto finish_string_lex;
+ }
+ /* when in validate UTF8 mode we need to do some extra work */
+ else if (lexer->validateUTF8) {
+ yajl_tok t = yajl_lex_utf8_char(lexer, jsonText, jsonTextLen,
+ offset, curChar);
+
+ if (t == yajl_tok_eof) {
+ tok = yajl_tok_eof;
+ goto finish_string_lex;
+ } else if (t == yajl_tok_error) {
+ lexer->error = yajl_lex_string_invalid_utf8;
+ goto finish_string_lex;
+ }
+ }
+ /* accept it, and move on */
+ }
+ finish_string_lex:
+ /* tell our buddy, the parser, wether he needs to process this string
+ * again */
+ if (hasEscapes && tok == yajl_tok_string) {
+ tok = yajl_tok_string_with_escapes;
+ }
+
+ return tok;
+}
+
+#define RETURN_IF_EOF if (*offset >= jsonTextLen) return yajl_tok_eof;
+
+static yajl_tok
+yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int * offset)
+{
+ /** XXX: numbers are the only entities in json that we must lex
+ * _beyond_ in order to know that they are complete. There
+ * is an ambiguous case for integers at EOF. */
+
+ unsigned char c;
+
+ yajl_tok tok = yajl_tok_integer;
+
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+
+ /* optional leading minus */
+ if (c == '-') {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ }
+
+ /* a single zero, or a series of integers */
+ if (c == '0') {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ } else if (c >= '1' && c <= '9') {
+ do {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ } while (c >= '0' && c <= '9');
+ } else {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_missing_integer_after_minus;
+ return yajl_tok_error;
+ }
+
+ /* optional fraction (indicates this is floating point) */
+ if (c == '.') {
+ int numRd = 0;
+
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+
+ while (c >= '0' && c <= '9') {
+ numRd++;
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ }
+
+ if (!numRd) {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_missing_integer_after_decimal;
+ return yajl_tok_error;
+ }
+ tok = yajl_tok_double;
+ }
+
+ /* optional exponent (indicates this is floating point) */
+ if (c == 'e' || c == 'E') {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+
+ /* optional sign */
+ if (c == '+' || c == '-') {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ }
+
+ if (c >= '0' && c <= '9') {
+ do {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ } while (c >= '0' && c <= '9');
+ } else {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_missing_integer_after_exponent;
+ return yajl_tok_error;
+ }
+ tok = yajl_tok_double;
+ }
+
+ /* we always go "one too far" */
+ unreadChar(lexer, offset);
+
+ return tok;
+}
+
+static yajl_tok
+yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int * offset)
+{
+ unsigned char c;
+
+ yajl_tok tok = yajl_tok_comment;
+
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+
+ /* either slash or star expected */
+ if (c == '/') {
+ /* now we throw away until end of line */
+ do {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ } while (c != '\n');
+ } else if (c == '*') {
+ /* now we throw away until end of comment */
+ for (;;) {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ if (c == '*') {
+ RETURN_IF_EOF;
+ c = readChar(lexer, jsonText, offset);
+ if (c == '/') {
+ break;
+ } else {
+ unreadChar(lexer, offset);
+ }
+ }
+ }
+ } else {
+ lexer->error = yajl_lex_invalid_char;
+ tok = yajl_tok_error;
+ }
+
+ return tok;
+}
+
+yajl_tok
+yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int * offset,
+ const unsigned char ** outBuf, unsigned int * outLen)
+{
+ yajl_tok tok = yajl_tok_error;
+ unsigned char c;
+ unsigned int startOffset = *offset;
+
+ *outBuf = NULL;
+ *outLen = 0;
+
+ for (;;) {
+ assert(*offset <= jsonTextLen);
+
+ if (*offset >= jsonTextLen) {
+ tok = yajl_tok_eof;
+ goto lexed;
+ }
+
+ c = readChar(lexer, jsonText, offset);
+
+ switch (c) {
+ case '{':
+ tok = yajl_tok_left_bracket;
+ goto lexed;
+ case '}':
+ tok = yajl_tok_right_bracket;
+ goto lexed;
+ case '[':
+ tok = yajl_tok_left_brace;
+ goto lexed;
+ case ']':
+ tok = yajl_tok_right_brace;
+ goto lexed;
+ case ',':
+ tok = yajl_tok_comma;
+ goto lexed;
+ case ':':
+ tok = yajl_tok_colon;
+ goto lexed;
+ case '\t': case '\n': case '\v': case '\f': case '\r': case ' ':
+ startOffset++;
+ break;
+ case 't': {
+ const char * want = "rue";
+ do {
+ if (*offset >= jsonTextLen) {
+ tok = yajl_tok_eof;
+ goto lexed;
+ }
+ c = readChar(lexer, jsonText, offset);
+ if (c != *want) {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_invalid_string;
+ tok = yajl_tok_error;
+ goto lexed;
+ }
+ } while (*(++want));
+ tok = yajl_tok_bool;
+ goto lexed;
+ }
+ case 'f': {
+ const char * want = "alse";
+ do {
+ if (*offset >= jsonTextLen) {
+ tok = yajl_tok_eof;
+ goto lexed;
+ }
+ c = readChar(lexer, jsonText, offset);
+ if (c != *want) {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_invalid_string;
+ tok = yajl_tok_error;
+ goto lexed;
+ }
+ } while (*(++want));
+ tok = yajl_tok_bool;
+ goto lexed;
+ }
+ case 'n': {
+ const char * want = "ull";
+ do {
+ if (*offset >= jsonTextLen) {
+ tok = yajl_tok_eof;
+ goto lexed;
+ }
+ c = readChar(lexer, jsonText, offset);
+ if (c != *want) {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_invalid_string;
+ tok = yajl_tok_error;
+ goto lexed;
+ }
+ } while (*(++want));
+ tok = yajl_tok_null;
+ goto lexed;
+ }
+ case '"': {
+ tok = yajl_lex_string(lexer, (const unsigned char *) jsonText,
+ jsonTextLen, offset);
+ goto lexed;
+ }
+ case '-':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9': {
+ /* integer parsing wants to start from the beginning */
+ unreadChar(lexer, offset);
+ tok = yajl_lex_number(lexer, (const unsigned char *) jsonText,
+ jsonTextLen, offset);
+ goto lexed;
+ }
+ case '/':
+ /* hey, look, a probable comment! If comments are disabled
+ * it's an error. */
+ if (!lexer->allowComments) {
+ unreadChar(lexer, offset);
+ lexer->error = yajl_lex_unallowed_comment;
+ tok = yajl_tok_error;
+ goto lexed;
+ }
+ /* if comments are enabled, then we should try to lex
+ * the thing. possible outcomes are
+ * - successful lex (tok_comment, which means continue),
+ * - malformed comment opening (slash not followed by
+ * '*' or '/') (tok_error)
+ * - eof hit. (tok_eof) */
+ tok = yajl_lex_comment(lexer, (const unsigned char *) jsonText,
+ jsonTextLen, offset);
+ if (tok == yajl_tok_comment) {
+ /* "error" is silly, but that's the initial
+ * state of tok. guilty until proven innocent. */
+ tok = yajl_tok_error;
+ yajl_buf_clear(lexer->buf);
+ lexer->bufInUse = 0;
+ startOffset = *offset;
+ break;
+ }
+ /* hit error or eof, bail */
+ goto lexed;
+ default:
+ lexer->error = yajl_lex_invalid_char;
+ tok = yajl_tok_error;
+ goto lexed;
+ }
+ }
+
+
+ lexed:
+ /* need to append to buffer if the buffer is in use or
+ * if it's an EOF token */
+ if (tok == yajl_tok_eof || lexer->bufInUse) {
+ if (!lexer->bufInUse) yajl_buf_clear(lexer->buf);
+ lexer->bufInUse = 1;
+ yajl_buf_append(lexer->buf, jsonText + startOffset, *offset - startOffset);
+ lexer->bufOff = 0;
+
+ if (tok != yajl_tok_eof) {
+ *outBuf = yajl_buf_data(lexer->buf);
+ *outLen = yajl_buf_len(lexer->buf);
+ lexer->bufInUse = 0;
+ }
+ } else if (tok != yajl_tok_error) {
+ *outBuf = jsonText + startOffset;
+ *outLen = *offset - startOffset;
+ }
+
+ /* special case for strings. skip the quotes. */
+ if (tok == yajl_tok_string || tok == yajl_tok_string_with_escapes)
+ {
+ assert(*outLen >= 2);
+ (*outBuf)++;
+ *outLen -= 2;
+ }
+
+
+#ifdef YAJL_LEXER_DEBUG
+ if (tok == yajl_tok_error) {
+ printf("lexical error: %s\n",
+ yajl_lex_error_to_string(yajl_lex_get_error(lexer)));
+ } else if (tok == yajl_tok_eof) {
+ printf("EOF hit\n");
+ } else {
+ printf("lexed %s: '", tokToStr(tok));
+ fwrite(*outBuf, 1, *outLen, stdout);
+ printf("'\n");
+ }
+#endif
+
+ return tok;
+}
+
+const char *
+yajl_lex_error_to_string(yajl_lex_error error)
+{
+ switch (error) {
+ case yajl_lex_e_ok:
+ return "ok, no error";
+ case yajl_lex_string_invalid_utf8:
+ return "invalid bytes in UTF8 string.";
+ case yajl_lex_string_invalid_escaped_char:
+ return "inside a string, '\\' occurs before a character "
+ "which it may not.";
+ case yajl_lex_string_invalid_json_char:
+ return "invalid character inside string.";
+ case yajl_lex_string_invalid_hex_char:
+ return "invalid (non-hex) character occurs after '\\u' inside "
+ "string.";
+ case yajl_lex_invalid_char:
+ return "invalid char in json text.";
+ case yajl_lex_invalid_string:
+ return "invalid string in json text.";
+ case yajl_lex_missing_integer_after_exponent:
+ return "malformed number, a digit is required after the exponent.";
+ case yajl_lex_missing_integer_after_decimal:
+ return "malformed number, a digit is required after the "
+ "decimal point.";
+ case yajl_lex_missing_integer_after_minus:
+ return "malformed number, a digit is required after the "
+ "minus sign.";
+ case yajl_lex_unallowed_comment:
+ return "probable comment found in input text, comments are "
+ "not enabled.";
+ }
+ return "unknown error code";
+}
+
+
+/** allows access to more specific information about the lexical
+ * error when yajl_lex_lex returns yajl_tok_error. */
+yajl_lex_error
+yajl_lex_get_error(yajl_lexer lexer)
+{
+ if (lexer == NULL) return (yajl_lex_error) -1;
+ return lexer->error;
+}
+
+unsigned int yajl_lex_current_line(yajl_lexer lexer)
+{
+ return lexer->lineOff;
+}
+
+unsigned int yajl_lex_current_char(yajl_lexer lexer)
+{
+ return lexer->charOff;
+}
+
+yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int offset)
+{
+ const unsigned char * outBuf;
+ unsigned int outLen;
+ unsigned int bufLen = yajl_buf_len(lexer->buf);
+ unsigned int bufOff = lexer->bufOff;
+ unsigned int bufInUse = lexer->bufInUse;
+ yajl_tok tok;
+
+ tok = yajl_lex_lex(lexer, jsonText, jsonTextLen, &offset,
+ &outBuf, &outLen);
+
+ lexer->bufOff = bufOff;
+ lexer->bufInUse = bufInUse;
+ yajl_buf_truncate(lexer->buf, bufLen);
+
+ return tok;
+}
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __YAJL_LEX_H__
+#define __YAJL_LEX_H__
+
+#include "yajl/yajl_common.h"
+
+typedef enum {
+ yajl_tok_bool,
+ yajl_tok_colon,
+ yajl_tok_comma,
+ yajl_tok_eof,
+ yajl_tok_error,
+ yajl_tok_left_brace,
+ yajl_tok_left_bracket,
+ yajl_tok_null,
+ yajl_tok_right_brace,
+ yajl_tok_right_bracket,
+
+ /* we differentiate between integers and doubles to allow the
+ * parser to interpret the number without re-scanning */
+ yajl_tok_integer,
+ yajl_tok_double,
+
+ /* we differentiate between strings which require further processing,
+ * and strings that do not */
+ yajl_tok_string,
+ yajl_tok_string_with_escapes,
+
+ /* comment tokens are not currently returned to the parser, ever */
+ yajl_tok_comment
+} yajl_tok;
+
+typedef struct yajl_lexer_t * yajl_lexer;
+
+yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc,
+ unsigned int allowComments,
+ unsigned int validateUTF8);
+
+void yajl_lex_free(yajl_lexer lexer);
+
+/**
+ * run/continue a lex. "offset" is an input/output parameter.
+ * It should be initialized to zero for a
+ * new chunk of target text, and upon subsetquent calls with the same
+ * target text should passed with the value of the previous invocation.
+ *
+ * the client may be interested in the value of offset when an error is
+ * returned from the lexer. This allows the client to render useful
+n * error messages.
+ *
+ * When you pass the next chunk of data, context should be reinitialized
+ * to zero.
+ *
+ * Finally, the output buffer is usually just a pointer into the jsonText,
+ * however in cases where the entity being lexed spans multiple chunks,
+ * the lexer will buffer the entity and the data returned will be
+ * a pointer into that buffer.
+ *
+ * This behavior is abstracted from client code except for the performance
+ * implications which require that the client choose a reasonable chunk
+ * size to get adequate performance.
+ */
+yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int * offset,
+ const unsigned char ** outBuf, unsigned int * outLen);
+
+/** have a peek at the next token, but don't move the lexer forward */
+yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText,
+ unsigned int jsonTextLen, unsigned int offset);
+
+
+typedef enum {
+ yajl_lex_e_ok = 0,
+ yajl_lex_string_invalid_utf8,
+ yajl_lex_string_invalid_escaped_char,
+ yajl_lex_string_invalid_json_char,
+ yajl_lex_string_invalid_hex_char,
+ yajl_lex_invalid_char,
+ yajl_lex_invalid_string,
+ yajl_lex_missing_integer_after_decimal,
+ yajl_lex_missing_integer_after_exponent,
+ yajl_lex_missing_integer_after_minus,
+ yajl_lex_unallowed_comment
+} yajl_lex_error;
+
+const char * yajl_lex_error_to_string(yajl_lex_error error);
+
+/** allows access to more specific information about the lexical
+ * error when yajl_lex_lex returns yajl_tok_error. */
+yajl_lex_error yajl_lex_get_error(yajl_lexer lexer);
+
+/** get the current offset into the most recently lexed json string. */
+unsigned int yajl_lex_current_offset(yajl_lexer lexer);
+
+/** get the number of lines lexed by this lexer instance */
+unsigned int yajl_lex_current_line(yajl_lexer lexer);
+
+/** get the number of chars lexed by this lexer instance since the last
+ * \n or \r */
+unsigned int yajl_lex_current_char(yajl_lexer lexer);
+
+#endif
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "yajl_lex.h"
+#include "yajl_parser.h"
+#include "yajl_encode.h"
+#include "yajl_bytestack.h"
+
+#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+#include <math.h>
+
+unsigned char *
+yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
+ unsigned int jsonTextLen, int verbose)
+{
+ unsigned int offset = hand->errorOffset;
+ unsigned char * str;
+ const char * errorType = NULL;
+ const char * errorText = NULL;
+ char text[72];
+ const char * arrow = " (right here) ------^\n";
+
+ if (yajl_bs_current(hand->stateStack) == yajl_state_parse_error) {
+ errorType = "parse";
+ errorText = hand->parseError;
+ } else if (yajl_bs_current(hand->stateStack) == yajl_state_lexical_error) {
+ errorType = "lexical";
+ errorText = yajl_lex_error_to_string(yajl_lex_get_error(hand->lexer));
+ } else {
+ errorType = "unknown";
+ }
+
+ {
+ unsigned int memneeded = 0;
+ memneeded += strlen(errorType);
+ memneeded += strlen(" error");
+ if (errorText != NULL) {
+ memneeded += strlen(": ");
+ memneeded += strlen(errorText);
+ }
+ str = (unsigned char *) YA_MALLOC(&(hand->alloc), memneeded + 2);
+ str[0] = 0;
+ strcat((char *) str, errorType);
+ strcat((char *) str, " error");
+ if (errorText != NULL) {
+ strcat((char *) str, ": ");
+ strcat((char *) str, errorText);
+ }
+ strcat((char *) str, "\n");
+ }
+
+ /* now we append as many spaces as needed to make sure the error
+ * falls at char 41, if verbose was specified */
+ if (verbose) {
+ unsigned int start, end, i;
+ unsigned int spacesNeeded;
+
+ spacesNeeded = (offset < 30 ? 40 - offset : 10);
+ start = (offset >= 30 ? offset - 30 : 0);
+ end = (offset + 30 > jsonTextLen ? jsonTextLen : offset + 30);
+
+ for (i=0;i<spacesNeeded;i++) text[i] = ' ';
+
+ for (;start < end;start++, i++) {
+ if (jsonText[start] != '\n' && jsonText[start] != '\r')
+ {
+ text[i] = jsonText[start];
+ }
+ else
+ {
+ text[i] = ' ';
+ }
+ }
+ assert(i <= 71);
+ text[i++] = '\n';
+ text[i] = 0;
+ {
+ char * newStr = (char *)
+ YA_MALLOC(&(hand->alloc), (strlen((char *) str) +
+ strlen((char *) text) +
+ strlen(arrow) + 1));
+ newStr[0] = 0;
+ strcat((char *) newStr, (char *) str);
+ strcat((char *) newStr, text);
+ strcat((char *) newStr, arrow);
+ YA_FREE(&(hand->alloc), str);
+ str = (unsigned char *) newStr;
+ }
+ }
+ return str;
+}
+
+/* check for client cancelation */
+#define _CC_CHK(x) \
+ if (!(x)) { \
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error); \
+ hand->parseError = \
+ "client cancelled parse via callback return value"; \
+ return yajl_status_client_canceled; \
+ }
+
+
+yajl_status
+yajl_do_parse(yajl_handle hand, unsigned int * offset,
+ const unsigned char * jsonText, unsigned int jsonTextLen)
+{
+ yajl_tok tok;
+ const unsigned char * buf;
+ unsigned int bufLen;
+
+ around_again:
+ switch (yajl_bs_current(hand->stateStack)) {
+ case yajl_state_parse_complete:
+ return yajl_status_ok;
+ case yajl_state_lexical_error:
+ case yajl_state_parse_error:
+ hand->errorOffset = *offset;
+ return yajl_status_error;
+ case yajl_state_start:
+ case yajl_state_map_need_val:
+ case yajl_state_array_need_val:
+ case yajl_state_array_start: {
+ /* for arrays and maps, we advance the state for this
+ * depth, then push the state of the next depth.
+ * If an error occurs during the parsing of the nesting
+ * enitity, the state at this level will not matter.
+ * a state that needs pushing will be anything other
+ * than state_start */
+ yajl_state stateToPush = yajl_state_start;
+
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+ offset, &buf, &bufLen);
+
+ switch (tok) {
+ case yajl_tok_eof:
+ return yajl_status_insufficient_data;
+ case yajl_tok_error:
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+ goto around_again;
+ case yajl_tok_string:
+ if (hand->callbacks && hand->callbacks->yajl_string) {
+ _CC_CHK(hand->callbacks->yajl_string(hand->ctx,
+ buf, bufLen));
+ }
+ break;
+ case yajl_tok_string_with_escapes:
+ if (hand->callbacks && hand->callbacks->yajl_string) {
+ yajl_buf_clear(hand->decodeBuf);
+ yajl_string_decode(hand->decodeBuf, buf, bufLen);
+ _CC_CHK(hand->callbacks->yajl_string(
+ hand->ctx, yajl_buf_data(hand->decodeBuf),
+ yajl_buf_len(hand->decodeBuf)));
+ }
+ break;
+ case yajl_tok_bool:
+ if (hand->callbacks && hand->callbacks->yajl_boolean) {
+ _CC_CHK(hand->callbacks->yajl_boolean(hand->ctx,
+ *buf == 't'));
+ }
+ break;
+ case yajl_tok_null:
+ if (hand->callbacks && hand->callbacks->yajl_null) {
+ _CC_CHK(hand->callbacks->yajl_null(hand->ctx));
+ }
+ break;
+ case yajl_tok_left_bracket:
+ if (hand->callbacks && hand->callbacks->yajl_start_map) {
+ _CC_CHK(hand->callbacks->yajl_start_map(hand->ctx));
+ }
+ stateToPush = yajl_state_map_start;
+ break;
+ case yajl_tok_left_brace:
+ if (hand->callbacks && hand->callbacks->yajl_start_array) {
+ _CC_CHK(hand->callbacks->yajl_start_array(hand->ctx));
+ }
+ stateToPush = yajl_state_array_start;
+ break;
+ case yajl_tok_integer:
+ /*
+ * note. strtol does not respect the length of
+ * the lexical token. in a corner case where the
+ * lexed number is a integer with a trailing zero,
+ * immediately followed by the end of buffer,
+ * sscanf could run off into oblivion and cause a
+ * crash. for this reason we copy the integer
+ * (and doubles), into our parse buffer (the same
+ * one used for unescaping strings), before
+ * calling strtol. yajl_buf ensures null padding,
+ * so we're safe.
+ */
+ if (hand->callbacks) {
+ if (hand->callbacks->yajl_number) {
+ _CC_CHK(hand->callbacks->yajl_number(
+ hand->ctx,(const char *) buf, bufLen));
+ } else if (hand->callbacks->yajl_integer) {
+ long int i = 0;
+ yajl_buf_clear(hand->decodeBuf);
+ yajl_buf_append(hand->decodeBuf, buf, bufLen);
+ buf = yajl_buf_data(hand->decodeBuf);
+ i = strtol((const char *) buf, NULL, 10);
+ if ((i == LONG_MIN || i == LONG_MAX) &&
+ errno == ERANGE)
+ {
+ yajl_bs_set(hand->stateStack,
+ yajl_state_parse_error);
+ hand->parseError = "integer overflow" ;
+ /* try to restore error offset */
+ if (*offset >= bufLen) *offset -= bufLen;
+ else *offset = 0;
+ goto around_again;
+ }
+ _CC_CHK(hand->callbacks->yajl_integer(hand->ctx,
+ i));
+ }
+ }
+ break;
+ case yajl_tok_double:
+ if (hand->callbacks) {
+ if (hand->callbacks->yajl_number) {
+ _CC_CHK(hand->callbacks->yajl_number(
+ hand->ctx, (const char *) buf, bufLen));
+ } else if (hand->callbacks->yajl_double) {
+ double d = 0.0;
+ yajl_buf_clear(hand->decodeBuf);
+ yajl_buf_append(hand->decodeBuf, buf, bufLen);
+ buf = yajl_buf_data(hand->decodeBuf);
+ d = strtod((char *) buf, NULL);
+ if ((d == HUGE_VAL || d == -HUGE_VAL) &&
+ errno == ERANGE)
+ {
+ yajl_bs_set(hand->stateStack,
+ yajl_state_parse_error);
+ hand->parseError = "numeric (floating point) "
+ "overflow";
+ /* try to restore error offset */
+ if (*offset >= bufLen) *offset -= bufLen;
+ else *offset = 0;
+ goto around_again;
+ }
+ _CC_CHK(hand->callbacks->yajl_double(hand->ctx,
+ d));
+ }
+ }
+ break;
+ case yajl_tok_right_brace: {
+ if (yajl_bs_current(hand->stateStack) ==
+ yajl_state_array_start)
+ {
+ if (hand->callbacks &&
+ hand->callbacks->yajl_end_array)
+ {
+ _CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
+ }
+ yajl_bs_pop(hand->stateStack);
+ goto around_again;
+ }
+ /* intentional fall-through */
+ }
+ case yajl_tok_colon:
+ case yajl_tok_comma:
+ case yajl_tok_right_bracket:
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+ hand->parseError =
+ "unallowed token at this point in JSON text";
+ goto around_again;
+ default:
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+ hand->parseError = "invalid token, internal error";
+ goto around_again;
+ }
+ /* got a value. transition depends on the state we're in. */
+ {
+ yajl_state s = yajl_bs_current(hand->stateStack);
+ if (s == yajl_state_start) {
+ yajl_bs_set(hand->stateStack, yajl_state_parse_complete);
+ } else if (s == yajl_state_map_need_val) {
+ yajl_bs_set(hand->stateStack, yajl_state_map_got_val);
+ } else {
+ yajl_bs_set(hand->stateStack, yajl_state_array_got_val);
+ }
+ }
+ if (stateToPush != yajl_state_start) {
+ yajl_bs_push(hand->stateStack, stateToPush);
+ }
+
+ goto around_again;
+ }
+ case yajl_state_map_start:
+ case yajl_state_map_need_key: {
+ /* only difference between these two states is that in
+ * start '}' is valid, whereas in need_key, we've parsed
+ * a comma, and a string key _must_ follow */
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+ offset, &buf, &bufLen);
+ switch (tok) {
+ case yajl_tok_eof:
+ return yajl_status_insufficient_data;
+ case yajl_tok_error:
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+ goto around_again;
+ case yajl_tok_string_with_escapes:
+ if (hand->callbacks && hand->callbacks->yajl_map_key) {
+ yajl_buf_clear(hand->decodeBuf);
+ yajl_string_decode(hand->decodeBuf, buf, bufLen);
+ buf = yajl_buf_data(hand->decodeBuf);
+ bufLen = yajl_buf_len(hand->decodeBuf);
+ }
+ /* intentional fall-through */
+ case yajl_tok_string:
+ if (hand->callbacks && hand->callbacks->yajl_map_key) {
+ _CC_CHK(hand->callbacks->yajl_map_key(hand->ctx, buf,
+ bufLen));
+ }
+ yajl_bs_set(hand->stateStack, yajl_state_map_sep);
+ goto around_again;
+ case yajl_tok_right_bracket:
+ if (yajl_bs_current(hand->stateStack) ==
+ yajl_state_map_start)
+ {
+ if (hand->callbacks && hand->callbacks->yajl_end_map) {
+ _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
+ }
+ yajl_bs_pop(hand->stateStack);
+ goto around_again;
+ }
+ default:
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+ hand->parseError =
+ "invalid object key (must be a string)";
+ goto around_again;
+ }
+ }
+ case yajl_state_map_sep: {
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+ offset, &buf, &bufLen);
+ switch (tok) {
+ case yajl_tok_colon:
+ yajl_bs_set(hand->stateStack, yajl_state_map_need_val);
+ goto around_again;
+ case yajl_tok_eof:
+ return yajl_status_insufficient_data;
+ case yajl_tok_error:
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+ goto around_again;
+ default:
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+ hand->parseError = "object key and value must "
+ "be separated by a colon (':')";
+ goto around_again;
+ }
+ }
+ case yajl_state_map_got_val: {
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+ offset, &buf, &bufLen);
+ switch (tok) {
+ case yajl_tok_right_bracket:
+ if (hand->callbacks && hand->callbacks->yajl_end_map) {
+ _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
+ }
+ yajl_bs_pop(hand->stateStack);
+ goto around_again;
+ case yajl_tok_comma:
+ yajl_bs_set(hand->stateStack, yajl_state_map_need_key);
+ goto around_again;
+ case yajl_tok_eof:
+ return yajl_status_insufficient_data;
+ case yajl_tok_error:
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+ goto around_again;
+ default:
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+ hand->parseError = "after key and value, inside map, "
+ "I expect ',' or '}'";
+ /* try to restore error offset */
+ if (*offset >= bufLen) *offset -= bufLen;
+ else *offset = 0;
+ goto around_again;
+ }
+ }
+ case yajl_state_array_got_val: {
+ tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
+ offset, &buf, &bufLen);
+ switch (tok) {
+ case yajl_tok_right_brace:
+ if (hand->callbacks && hand->callbacks->yajl_end_array) {
+ _CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
+ }
+ yajl_bs_pop(hand->stateStack);
+ goto around_again;
+ case yajl_tok_comma:
+ yajl_bs_set(hand->stateStack, yajl_state_array_need_val);
+ goto around_again;
+ case yajl_tok_eof:
+ return yajl_status_insufficient_data;
+ case yajl_tok_error:
+ yajl_bs_set(hand->stateStack, yajl_state_lexical_error);
+ goto around_again;
+ default:
+ yajl_bs_set(hand->stateStack, yajl_state_parse_error);
+ hand->parseError =
+ "after array element, I expect ',' or ']'";
+ goto around_again;
+ }
+ }
+ }
+
+ abort();
+ return yajl_status_error;
+}
+
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __YAJL_PARSER_H__
+#define __YAJL_PARSER_H__
+
+#include "yajl/yajl_parse.h"
+#include "yajl_bytestack.h"
+#include "yajl_buf.h"
+
+
+typedef enum {
+ yajl_state_start = 0,
+ yajl_state_parse_complete,
+ yajl_state_parse_error,
+ yajl_state_lexical_error,
+ yajl_state_map_start,
+ yajl_state_map_sep,
+ yajl_state_map_need_val,
+ yajl_state_map_got_val,
+ yajl_state_map_need_key,
+ yajl_state_array_start,
+ yajl_state_array_got_val,
+ yajl_state_array_need_val
+} yajl_state;
+
+struct yajl_handle_t {
+ const yajl_callbacks * callbacks;
+ void * ctx;
+ yajl_lexer lexer;
+ const char * parseError;
+ unsigned int errorOffset;
+ /* temporary storage for decoded strings */
+ yajl_buf decodeBuf;
+ /* a stack of states. access with yajl_state_XXX routines */
+ yajl_bytestack stateStack;
+ /* memory allocation routines */
+ yajl_alloc_funcs alloc;
+};
+
+yajl_status
+yajl_do_parse(yajl_handle handle, unsigned int * offset,
+ const unsigned char * jsonText, unsigned int jsonTextLen);
+
+unsigned char *
+yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
+ unsigned int jsonTextLen, int verbose);
+
+
+#endif
--- /dev/null
+# Copyright 2007-2009, Lloyd Hilaiel.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Neither the name of Lloyd Hilaiel nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+SET (SRCS yajl_test.c)
+
+# use the library we build, duh.
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
+
+ADD_EXECUTABLE(yajl_test ${SRCS})
+
+TARGET_LINK_LIBRARIES(yajl_test yajl_s)
--- /dev/null
+["foo",
+ "bar", "baz",
+ true,false,null,{"key":"value"},
+ [null,null,null,[]],
+ "\n\r\\"
+]
--- /dev/null
+array open '['
+string: 'foo'
+string: 'bar'
+string: 'baz'
+bool: true
+bool: false
+null
+map open '{'
+key: 'key'
+string: 'value'
+map close '}'
+array open '['
+null
+null
+null
+array open '['
+array close ']'
+array close ']'
+string: '
+\r\'
+array close ']'
+memory leaks: 0
--- /dev/null
+parse error: unallowed token at this point in JSON text
+memory leaks: 0
--- /dev/null
+array open '['
+memory leaks: 0
--- /dev/null
+["this","is","what","should","be",
+ "a happy bit of json",
+ "but someone, misspelled \"true\"", ture,
+ "who says JSON is easy for humans to generate?"]
--- /dev/null
+array open '['
+string: 'this'
+string: 'is'
+string: 'what'
+string: 'should'
+string: 'be'
+string: 'a happy bit of json'
+string: 'but someone, misspelled "true"'
+lexical error: invalid string in json text.
+memory leaks: 0
--- /dev/null
+"\u004d\u0430\u4e8c\ud800\udf02"
--- /dev/null
+string: 'Mа二𐌂'
+memory leaks: 0
--- /dev/null
+{
+ "this": "is", // ignore this
+ "really": "simple",
+ /* ignore
+this
+too * /
+** //
+(/
+******/
+ "json": "right?"
+}
--- /dev/null
+map open '{'
+key: 'this'
+string: 'is'
+lexical error: probable comment found in input text, comments are not enabled.
+memory leaks: 0
--- /dev/null
+[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
\ No newline at end of file
--- /dev/null
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array open '['
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+array close ']'
+memory leaks: 0
--- /dev/null
+{ "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": [ { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML", "markup"] } ] } } }
--- /dev/null
+map open '{'
+key: 'glossary'
+map open '{'
+key: 'title'
+string: 'example glossary'
+key: 'GlossDiv'
+map open '{'
+key: 'title'
+string: 'S'
+key: 'GlossList'
+array open '['
+map open '{'
+key: 'ID'
+string: 'SGML'
+key: 'SortAs'
+string: 'SGML'
+key: 'GlossTerm'
+string: 'Standard Generalized Markup Language'
+key: 'Acronym'
+string: 'SGML'
+key: 'Abbrev'
+string: 'ISO 8879:1986'
+key: 'GlossDef'
+string: 'A meta-markup language, used to create markup languages such as DocBook.'
+key: 'GlossSeeAlso'
+array open '['
+string: 'GML'
+string: 'XML'
+string: 'markup'
+array close ']'
+map close '}'
+array close ']'
+map close '}'
+map close '}'
+map close '}'
+memory leaks: 0
--- /dev/null
+{ "glossary": { /* you */ "title": /**/ "example glossary", /*should*/"GlossDiv": { "title": /*never*/"S", /*ever*/"GlossList": [ { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": "A meta-markup language, used to create markup languages such as DocBook.", /*see*/"GlossSeeAlso"/*this*/:/*coming*/[/*out*/"GML"/*of*/,/*the*/"XML"/*parser!*/, "markup"] /*hey*/}/*ho*/]/*hey*/}/*ho*/} } // and the parser won't even get this far, so chill. /* hah!
--- /dev/null
+map open '{'
+key: 'glossary'
+map open '{'
+key: 'title'
+string: 'example glossary'
+key: 'GlossDiv'
+map open '{'
+key: 'title'
+string: 'S'
+key: 'GlossList'
+array open '['
+map open '{'
+key: 'ID'
+string: 'SGML'
+key: 'SortAs'
+string: 'SGML'
+key: 'GlossTerm'
+string: 'Standard Generalized Markup Language'
+key: 'Acronym'
+string: 'SGML'
+key: 'Abbrev'
+string: 'ISO 8879:1986'
+key: 'GlossDef'
+string: 'A meta-markup language, used to create markup languages such as DocBook.'
+key: 'GlossSeeAlso'
+array open '['
+string: 'GML'
+string: 'XML'
+string: 'markup'
+array close ']'
+map close '}'
+array close ']'
+map close '}'
+map close '}'
+map close '}'
+memory leaks: 0
--- /dev/null
+[ 0.1e2, 1e1, 3.141569, 10000000000000e-10]
--- /dev/null
+array open '['
+double: 10
+double: 10
+double: 3.14157
+double: 1000
+array close ']'
+memory leaks: 0
--- /dev/null
+[]
\ No newline at end of file
--- /dev/null
+array open '['
+array close ']'
+memory leaks: 0
--- /dev/null
+string: ''
+memory leaks: 0
--- /dev/null
+["\u0414\u0430",
+ "\u041c\u0443",
+ "\u0415\u0431\u0430",
+ "\u041c\u0430\u0439\u043a\u0430\u0442\u0430"]
--- /dev/null
+array open '['
+string: 'Да'
+string: 'Му'
+string: 'Еба'
+string: 'Майката'
+array close ']'
+memory leaks: 0
--- /dev/null
+"\u0066\u006f\u006f\u0062\u0061\u0072"
--- /dev/null
+string: 'foobar'
+memory leaks: 0
--- /dev/null
+bool: false
+memory leaks: 0
--- /dev/null
+falsex
\ No newline at end of file
--- /dev/null
+bool: false
+memory leaks: 0
--- /dev/null
+{ "U+10ABCD": "" }
+
--- /dev/null
+map open '{'
+key: 'U+10ABCD'
+string: ''
+map close '}'
+memory leaks: 0
--- /dev/null
+[ 1,2,3,4,5,6,7,
+ 123456789 , -123456789,
+ 2147483647, -2147483647,
+ 2147483648 ]
--- /dev/null
+array open '['
+integer: 1
+integer: 2
+integer: 3
+integer: 4
+integer: 5
+integer: 6
+integer: 7
+integer: 123456789
+integer: -123456789
+integer: 2147483647
+integer: -2147483647
+parse error: integer overflow
+memory leaks: 0
--- /dev/null
+["Ð\94а Ð\9cÑ Ð\95ба Ð\9cайкаÑ\82а"]
--- /dev/null
+array open '['
+lexical error: invalid bytes in UTF8 string.
+memory leaks: 0
--- /dev/null
+string: '?'
+memory leaks: 0
--- /dev/null
+{ "bad thing": 01 }
--- /dev/null
+map open '{'
+key: 'bad thing'
+integer: 0
+parse error: after key and value, inside map, I expect ',' or '}'
+memory leaks: 0
--- /dev/null
+[
+ "foo", true,
+ true, "blue",
+ "baby where are you?", "oh boo hoo!",
+ -
+]
+
--- /dev/null
+array open '['
+string: 'foo'
+bool: true
+bool: true
+string: 'blue'
+string: 'baby where are you?'
+string: 'oh boo hoo!'
+lexical error: malformed number, a digit is required after the minus sign.
+memory leaks: 0
--- /dev/null
+123456789
\ No newline at end of file
--- /dev/null
+integer: 123456789
+memory leaks: 0
--- /dev/null
+parse error: unallowed token at this point in JSON text
+memory leaks: 0
--- /dev/null
+map open '{'
+memory leaks: 0
--- /dev/null
+lexical error: malformed number, a digit is required after the decimal point.
+memory leaks: 0
--- /dev/null
+lexical error: malformed number, a digit is required after the exponent.
+memory leaks: 0
--- /dev/null
+{"CoreletAPIVersion":2,"CoreletType":"standalone","documentation":"A corelet that provides the capability to upload a folder\92s contents into a user\92s locker.","functions":[{"documentation":"Displays a dialog box that allows user to select a folder on the local system.","name":"ShowBrowseDialog","parameters":[{"documentation":"The callback function for results.","name":"callback","required":true,"type":"callback"}]},{"documentation":"Uploads all mp3 files in the folder provided.","name":"UploadFolder","parameters":[{"documentation":"The path to upload mp3 files from.","name":"path","required":true,"type":"string"},{"documentation":"The callback function for progress.","name":"callback","required":true,"type":"callback"}]},{"documentation":"Returns the server name to the current locker service.","name":"GetLockerService","parameters":[]},{"documentation":"Changes the name of the locker service.","name":"SetLockerService","parameters":[{"documentation":"The value of the locker service to set active.","name":"LockerService","required":true,"type":"string"}]},{"documentation":"Downloads locker files to the suggested folder.","name":"DownloadFile","parameters":[{"documentation":"The origin path of the locker file.","name":"path","required":true,"type":"string"},{"documentation":"The Window destination path of the locker file.","name":"destination","required":true,"type":"integer"},{"documentation":"The callback function for progress.","name":"callback","required":true,"type":"callback"}]}],"name":"LockerUploader","version":{"major":0,"micro":1,"minor":0},"versionString":"0.0.1"}
\ No newline at end of file
--- /dev/null
+map open '{'
+key: 'CoreletAPIVersion'
+integer: 2
+key: 'CoreletType'
+string: 'standalone'
+key: 'documentation'
+lexical error: invalid bytes in UTF8 string.
+memory leaks: 0
--- /dev/null
+null
+memory leaks: 0
--- /dev/null
+null
+memory leaks: 0
--- /dev/null
+{
+ "boolean, true": true,
+ "boolean, false": false,
+ "null": null
+}
--- /dev/null
+map open '{'
+key: 'boolean, true'
+bool: true
+key: 'boolean, false'
+bool: false
+key: 'null'
+null
+map close '}'
+memory leaks: 0
--- /dev/null
+{
+ "this": "is",
+ "really": "simple",
+ "json": "right?"
+}
--- /dev/null
+map open '{'
+key: 'this'
+string: 'is'
+key: 'really'
+string: 'simple'
+key: 'json'
+string: 'right?'
+map close '}'
+memory leaks: 0
--- /dev/null
+{
+ "this": "is", // ignore this
+ "really": "simple",
+ /* ignore
+this
+too * /
+** //
+(/
+******/
+ "json": "right?"
+}
--- /dev/null
+map open '{'
+key: 'this'
+string: 'is'
+key: 'really'
+string: 'simple'
+key: 'json'
+string: 'right?'
+map close '}'
+memory leaks: 0
--- /dev/null
+["\n foo \/ bar \r\f\\\uffff\t\b\"\\ and you can't escape thi\s"]
--- /dev/null
+array open '['
+lexical error: inside a string, '\' occurs before a character which it may not.
+memory leaks: 0
--- /dev/null
+"foo foo, blah blah \u0123 \u4567 \u89ab \uc/ef \uABCD \uEFFE bar baz bing"
--- /dev/null
+lexical error: invalid (non-hex) character occurs after '\u' inside string.
+memory leaks: 0
--- /dev/null
+["\n foo \/ bar \r\f\\\uffff\t\b\"\\",
+ "\"and this string has an escape at the beginning",
+ "and this string has no escapes" ]
--- /dev/null
+array open '['
+string: '
+ foo / bar \r\f\ \b"\'
+string: '"and this string has an escape at the beginning'
+string: 'and this string has no escapes'
+array close ']'
+memory leaks: 0
--- /dev/null
+"la di dah. this is a string, and I can do this, \n, but not this
+"
--- /dev/null
+lexical error: invalid character inside string.
+memory leaks: 0
--- /dev/null
+{"matzue": "松江", "asakusa": "浅草"}
--- /dev/null
+map open '{'
+key: 'matzue'
+string: '松江'
+key: 'asakusa'
+string: '浅草'
+map close '}'
+memory leaks: 0
--- /dev/null
+bool: true
+memory leaks: 0
--- /dev/null
+truex
\ No newline at end of file
--- /dev/null
+bool: true
+memory leaks: 0
--- /dev/null
+["Да Му Еба Майката"]
--- /dev/null
+array open '['
+string: 'Да Му Еба Майката'
+array close ']'
+memory leaks: 0
--- /dev/null
+#!/usr/bin/env bash
+
+DIFF_FLAGS="-u"
+if [[ `uname` == *W32* ]] ; then
+ DIFF_FLAGS="-wu"
+fi
+
+# find test binary on both platforms. allow the caller to force a
+# particular test binary (useful for non-cmake build systems).
+if [ -z "$testBin" ]; then
+ testBin="../build/test/Debug/yajl_test.exe"
+ if [[ ! -x $testBin ]] ; then
+ testBin="../build/test/yajl_test"
+ if [[ ! -x $testBin ]] ; then
+ echo "cannot execute test binary: '$testBin'"
+ exit 1;
+ fi
+ fi
+fi
+
+echo "using test binary: $testBin"
+
+let testsSucceeded=0
+let testsTotal=0
+
+for file in cases/*.json ; do
+ allowComments="-c"
+
+ # if the filename starts with dc_, we disallow comments for this test
+ if [[ $(basename $file) == dc_* ]] ; then
+ allowComments=""
+ fi
+ echo -n " test case: '$file': "
+ let iter=1
+ success="success"
+
+ # parse with a read buffer size ranging from 1-31 to stress stream parsing
+ while (( $iter < 32 )) && [ $success == "success" ] ; do
+ $testBin $allowComments -b $iter < $file > ${file}.test 2>&1
+ diff ${DIFF_FLAGS} ${file}.gold ${file}.test
+ if [[ $? == 0 ]] ; then
+ if (( $iter == 31 )) ; then let testsSucceeded+=1 ; fi
+ else
+ success="FAILURE"
+ let iter=32
+ fi
+ let iter+=1
+ rm ${file}.test
+ done
+
+ echo $success
+ let testsTotal+=1
+done
+
+echo $testsSucceeded/$testsTotal tests successful
+
+if [[ $testsSucceeded != $testsTotal ]] ; then
+ exit 1
+fi
+
+exit 0
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <yajl/yajl_parse.h>
+#include <yajl/yajl_gen.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <assert.h>
+
+/* memory debugging routines */
+typedef struct
+{
+ unsigned int numFrees;
+ unsigned int numMallocs;
+ /* XXX: we really need a hash table here with per-allocation
+ * information */
+} yajlTestMemoryContext;
+
+/* cast void * into context */
+#define TEST_CTX(vptr) ((yajlTestMemoryContext *) (vptr))
+
+static void yajlTestFree(void * ctx, void * ptr)
+{
+ assert(ptr != NULL);
+ TEST_CTX(ctx)->numFrees++;
+ free(ptr);
+}
+
+static void * yajlTestMalloc(void * ctx, unsigned int sz)
+{
+ assert(sz != 0);
+ TEST_CTX(ctx)->numMallocs++;
+ return malloc(sz);
+}
+
+static void * yajlTestRealloc(void * ctx, void * ptr, unsigned int sz)
+{
+ if (ptr == NULL) {
+ assert(sz != 0);
+ TEST_CTX(ctx)->numMallocs++;
+ } else if (sz == 0) {
+ TEST_CTX(ctx)->numFrees++;
+ }
+
+ return realloc(ptr, sz);
+}
+
+
+/* begin parsing callback routines */
+#define BUF_SIZE 2048
+
+static int test_yajl_null(void *ctx)
+{
+ printf("null\n");
+ return 1;
+}
+
+static int test_yajl_boolean(void * ctx, int boolVal)
+{
+ printf("bool: %s\n", boolVal ? "true" : "false");
+ return 1;
+}
+
+static int test_yajl_integer(void *ctx, long integerVal)
+{
+ printf("integer: %ld\n", integerVal);
+ return 1;
+}
+
+static int test_yajl_double(void *ctx, double doubleVal)
+{
+ printf("double: %g\n", doubleVal);
+ return 1;
+}
+
+static int test_yajl_string(void *ctx, const unsigned char * stringVal,
+ unsigned int stringLen)
+{
+ printf("string: '");
+ fwrite(stringVal, 1, stringLen, stdout);
+ printf("'\n");
+ return 1;
+}
+
+static int test_yajl_map_key(void *ctx, const unsigned char * stringVal,
+ unsigned int stringLen)
+{
+ char * str = (char *) malloc(stringLen + 1);
+ str[stringLen] = 0;
+ memcpy(str, stringVal, stringLen);
+ printf("key: '%s'\n", str);
+ free(str);
+ return 1;
+}
+
+static int test_yajl_start_map(void *ctx)
+{
+ printf("map open '{'\n");
+ return 1;
+}
+
+
+static int test_yajl_end_map(void *ctx)
+{
+ printf("map close '}'\n");
+ return 1;
+}
+
+static int test_yajl_start_array(void *ctx)
+{
+ printf("array open '['\n");
+ return 1;
+}
+
+static int test_yajl_end_array(void *ctx)
+{
+ printf("array close ']'\n");
+ return 1;
+}
+
+static yajl_callbacks callbacks = {
+ test_yajl_null,
+ test_yajl_boolean,
+ test_yajl_integer,
+ test_yajl_double,
+ NULL,
+ test_yajl_string,
+ test_yajl_start_map,
+ test_yajl_map_key,
+ test_yajl_end_map,
+ test_yajl_start_array,
+ test_yajl_end_array
+};
+
+static void usage(const char * progname)
+{
+ fprintf(stderr,
+ "usage: %s [options] <filename>\n"
+ " -c allow comments\n"
+ " -b set the read buffer size\n",
+ progname);
+ exit(1);
+}
+
+int
+main(int argc, char ** argv)
+{
+ yajl_handle hand;
+ const char * fileName;
+ static unsigned char * fileData = NULL;
+ unsigned int bufSize = BUF_SIZE;
+ yajl_status stat;
+ size_t rd;
+ yajl_parser_config cfg = { 0, 1 };
+ int i, j, done;
+
+ /* memory allocation debugging: allocate a structure which collects
+ * statistics */
+ yajlTestMemoryContext memCtx = { 0,0 };
+
+ /* memory allocation debugging: allocate a structure which holds
+ * allocation routines */
+ yajl_alloc_funcs allocFuncs = {
+ yajlTestMalloc,
+ yajlTestRealloc,
+ yajlTestFree,
+ (void *) NULL
+ };
+
+ allocFuncs.ctx = (void *) &memCtx;
+
+ /* check arguments. We expect exactly one! */
+ for (i=1;i<argc;i++) {
+ if (!strcmp("-c", argv[i])) {
+ cfg.allowComments = 1;
+ } else if (!strcmp("-b", argv[i])) {
+ if (++i >= argc) usage(argv[0]);
+
+ /* validate integer */
+ for (j=0;j<(int)strlen(argv[i]);j++) {
+ if (argv[i][j] <= '9' && argv[i][j] >= '0') continue;
+ fprintf(stderr, "-b requires an integer argument. '%s' "
+ "is invalid\n", argv[i]);
+ usage(argv[0]);
+ }
+
+ bufSize = atoi(argv[i]);
+ if (!bufSize) {
+ fprintf(stderr, "%d is an invalid buffer size\n",
+ bufSize);
+ }
+ } else {
+ fprintf(stderr, "invalid command line option: '%s'\n",
+ argv[i]);
+ usage(argv[0]);
+ }
+ }
+
+ fileData = (unsigned char *) malloc(bufSize);
+
+ if (fileData == NULL) {
+ fprintf(stderr,
+ "failed to allocate read buffer of %u bytes, exiting.",
+ bufSize);
+ exit(2);
+ }
+
+ fileName = argv[argc-1];
+
+ /* ok. open file. let's read and parse */
+ hand = yajl_alloc(&callbacks, &cfg, &allocFuncs, NULL);
+
+ done = 0;
+ while (!done) {
+ rd = fread((void *) fileData, 1, bufSize, stdin);
+
+ if (rd == 0) {
+ if (!feof(stdin)) {
+ fprintf(stderr, "error reading from '%s'\n", fileName);
+ break;
+ }
+ done = 1;
+ }
+
+ if (done)
+ /* parse any remaining buffered data */
+ stat = yajl_parse_complete(hand);
+ else
+ /* read file data, pass to parser */
+ stat = yajl_parse(hand, fileData, rd);
+
+ if (stat != yajl_status_insufficient_data &&
+ stat != yajl_status_ok)
+ {
+ unsigned char * str = yajl_get_error(hand, 0, fileData, rd);
+ fflush(stdout);
+ fprintf(stderr, (char *) str);
+ yajl_free_error(hand, str);
+ break;
+ }
+ }
+
+ yajl_free(hand);
+ free(fileData);
+
+ /* finally, print out some memory statistics */
+
+/* (lth) only print leaks here, as allocations and frees may vary depending
+ * on read buffer size, causing false failures.
+ *
+ * printf("allocations:\t%u\n", memCtx.numMallocs);
+ * printf("frees:\t\t%u\n", memCtx.numFrees);
+*/
+ fflush(stderr);
+ fflush(stdout);
+ printf("memory leaks:\t%u\n", memCtx.numMallocs - memCtx.numFrees);
+
+ return 0;
+}
--- /dev/null
+# Copyright 2007-2009, Lloyd Hilaiel.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Neither the name of Lloyd Hilaiel nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# set up some paths
+SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/bin)
+
+# create some directories
+FILE(MAKE_DIRECTORY ${binDir})
+
+SET (SRCS json_verify.c)
+
+# use the library we build, duh.
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
+
+ADD_EXECUTABLE(json_verify ${SRCS})
+
+TARGET_LINK_LIBRARIES(json_verify yajl_s)
+
+# copy in the binary
+GET_TARGET_PROPERTY(binPath json_verify LOCATION)
+
+ADD_CUSTOM_COMMAND(TARGET json_verify POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir})
+
+IF (NOT WIN32)
+ INSTALL(TARGETS json_verify RUNTIME DESTINATION bin)
+ENDIF ()
--- /dev/null
+/*
+ * Copyright 2007-2009, Lloyd Hilaiel.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. Neither the name of Lloyd Hilaiel nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <yajl/yajl_parse.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+usage(const char * progname)
+{
+ fprintf(stderr, "%s: validate json from stdin\n"
+ "usage: json_verify [options]\n"
+ " -q quiet mode\n"
+ " -c allow comments\n"
+ " -u allow invalid utf8 inside strings\n",
+ progname);
+ exit(1);
+}
+
+int
+main(int argc, char ** argv)
+{
+ yajl_status stat;
+ size_t rd;
+ yajl_handle hand;
+ static unsigned char fileData[65536];
+ int quiet = 0;
+ int retval = 0, done = 0;
+ yajl_parser_config cfg = { 0, 1 };
+
+ /* check arguments.*/
+ if (argc > 1 && argc < 4) {
+ int i;
+
+ for (i=1; i < argc;i++) {
+ if (!strcmp("-q", argv[i])) {
+ quiet = 1;
+ } else if (!strcmp("-c", argv[i])) {
+ cfg.allowComments = 1;
+ } else if (!strcmp("-u", argv[i])) {
+ cfg.checkUTF8 = 0;
+ } else {
+ fprintf(stderr, "unrecognized option: '%s'\n\n", argv[i]);
+ usage(argv[0]);
+ }
+ }
+ } else if (argc != 1) {
+ usage(argv[0]);
+ }
+
+ /* allocate a parser */
+ hand = yajl_alloc(NULL, &cfg, NULL, NULL);
+
+ while (!done) {
+ rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
+
+ retval = 0;
+
+ if (rd == 0) {
+ if (!feof(stdin)) {
+ if (!quiet) {
+ fprintf(stderr, "error encountered on file read\n");
+ }
+ retval = 1;
+ break;
+ }
+ done = 1;
+ }
+ fileData[rd] = 0;
+
+ if (done)
+ /* parse any remaining buffered data */
+ stat = yajl_parse_complete(hand);
+ else
+ /* read file data, pass to parser */
+ stat = yajl_parse(hand, fileData, rd);
+
+ if (stat != yajl_status_ok &&
+ stat != yajl_status_insufficient_data)
+ {
+ if (!quiet) {
+ unsigned char * str = yajl_get_error(hand, 1, fileData, rd);
+ fprintf(stderr, (const char *) str);
+ yajl_free_error(hand, str);
+ }
+ retval = 1;
+ break;
+ }
+ }
+
+ yajl_free(hand);
+
+ if (!quiet) {
+ printf("JSON is %s\n", retval ? "invalid" : "valid");
+ }
+
+ return retval;
+}